@medplum/react 5.0.12 → 5.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __commonJS=(cb,mod)=>function(){return mod||(0,cb[__getOwnPropNames(cb)[0]])((mod={exports:{}}).exports,mod),mod.exports};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod));var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var require_pointer=__commonJS({"../../node_modules/rfc6902/pointer.js"(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.Pointer=exports.escapeToken=exports.unescapeToken=void 0;function unescapeToken(token){return token.replace(/~1/g,"/").replace(/~0/g,"~")}exports.unescapeToken=unescapeToken;function escapeToken(token){return token.replace(/~/g,"~0").replace(/\//g,"~1")}exports.escapeToken=escapeToken;var Pointer=(function(){function Pointer2(tokens){tokens===void 0&&(tokens=[""]),this.tokens=tokens}return Pointer2.fromJSON=function(path){var tokens=path.split("/").map(unescapeToken);if(tokens[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(path));return new Pointer2(tokens)},Pointer2.prototype.toString=function(){return this.tokens.map(escapeToken).join("/")},Pointer2.prototype.evaluate=function(object){for(var parent=null,key="",value=object,i=1,l=this.tokens.length;i<l;i++)parent=value,key=this.tokens[i],!(key=="__proto__"||key=="constructor"||key=="prototype")&&(value=(parent||{})[key]);return{parent,key,value}},Pointer2.prototype.get=function(object){return this.evaluate(object).value},Pointer2.prototype.set=function(object,value){var endpoint=this.evaluate(object);endpoint.parent&&(endpoint.parent[endpoint.key]=value)},Pointer2.prototype.push=function(token){this.tokens.push(token)},Pointer2.prototype.add=function(token){var tokens=this.tokens.concat(String(token));return new Pointer2(tokens)},Pointer2})();exports.Pointer=Pointer}});var require_util=__commonJS({"../../node_modules/rfc6902/util.js"(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.clone=exports.objectType=exports.hasOwnProperty=void 0;exports.hasOwnProperty=Object.prototype.hasOwnProperty;function objectType(object){return object===void 0?"undefined":object===null?"null":Array.isArray(object)?"array":typeof object}exports.objectType=objectType;function isNonPrimitive(value){return value!=null&&typeof value=="object"}function clone(source){if(!isNonPrimitive(source))return source;if(source.constructor==Array){for(var length_1=source.length,arrayTarget=new Array(length_1),i=0;i<length_1;i++)arrayTarget[i]=clone(source[i]);return arrayTarget}if(source.constructor==Date){var dateTarget=new Date(+source);return dateTarget}var objectTarget={};for(var key in source)exports.hasOwnProperty.call(source,key)&&(objectTarget[key]=clone(source[key]));return objectTarget}exports.clone=clone}});var require_diff=__commonJS({"../../node_modules/rfc6902/diff.js"(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.diffAny=exports.diffObjects=exports.diffArrays=exports.intersection=exports.subtract=exports.isDestructive=void 0;var util_1=require_util();function isDestructive(_a){var op=_a.op;return op==="remove"||op==="replace"||op==="copy"||op==="move"}exports.isDestructive=isDestructive;function subtract(minuend,subtrahend){var obj={};for(var add_key in minuend)util_1.hasOwnProperty.call(minuend,add_key)&&minuend[add_key]!==void 0&&(obj[add_key]=1);for(var del_key in subtrahend)util_1.hasOwnProperty.call(subtrahend,del_key)&&subtrahend[del_key]!==void 0&&delete obj[del_key];return Object.keys(obj)}exports.subtract=subtract;function intersection(objects){for(var length=objects.length,counter={},i=0;i<length;i++){var object=objects[i];for(var key in object)util_1.hasOwnProperty.call(object,key)&&object[key]!==void 0&&(counter[key]=(counter[key]||0)+1)}for(var key in counter)counter[key]<length&&delete counter[key];return Object.keys(counter)}exports.intersection=intersection;function isArrayAdd(array_operation){return array_operation.op==="add"}function isArrayRemove(array_operation){return array_operation.op==="remove"}function appendArrayOperation(base,operation){return{operations:base.operations.concat(operation),cost:base.cost+1}}function diffArrays(input,output,ptr,diff2){diff2===void 0&&(diff2=diffAny);var memo2={"0,0":{operations:[],cost:0}};function dist(i,j){var memo_key="".concat(i,",").concat(j),memoized=memo2[memo_key];if(memoized===void 0){if(i>0&&j>0&&!diff2(input[i-1],output[j-1],ptr.add(String(i-1))).length)memoized=dist(i-1,j-1);else{var alternatives=[];if(i>0){var remove_base=dist(i-1,j),remove_operation={op:"remove",index:i-1};alternatives.push(appendArrayOperation(remove_base,remove_operation))}if(j>0){var add_base=dist(i,j-1),add_operation={op:"add",index:i-1,value:output[j-1]};alternatives.push(appendArrayOperation(add_base,add_operation))}if(i>0&&j>0){var replace_base=dist(i-1,j-1),replace_operation={op:"replace",index:i-1,original:input[i-1],value:output[j-1]};alternatives.push(appendArrayOperation(replace_base,replace_operation))}var best=alternatives.sort(function(a,b){return a.cost-b.cost})[0];memoized=best}memo2[memo_key]=memoized}return memoized}var input_length=isNaN(input.length)||input.length<=0?0:input.length,output_length=isNaN(output.length)||output.length<=0?0:output.length,array_operations=dist(input_length,output_length).operations,padded_operations=array_operations.reduce(function(_a,array_operation){var operations=_a[0],padding=_a[1];if(isArrayAdd(array_operation)){var padded_index=array_operation.index+1+padding,index_token=padded_index<input_length+padding?String(padded_index):"-",operation={op:array_operation.op,path:ptr.add(index_token).toString(),value:array_operation.value};return[operations.concat(operation),padding+1]}else if(isArrayRemove(array_operation)){var operation={op:array_operation.op,path:ptr.add(String(array_operation.index+padding)).toString()};return[operations.concat(operation),padding-1]}else{var replace_ptr=ptr.add(String(array_operation.index+padding)),replace_operations=diff2(array_operation.original,array_operation.value,replace_ptr);return[operations.concat.apply(operations,replace_operations),padding]}},[[],0])[0];return padded_operations}exports.diffArrays=diffArrays;function diffObjects(input,output,ptr,diff2){diff2===void 0&&(diff2=diffAny);var operations=[];return subtract(input,output).forEach(function(key){operations.push({op:"remove",path:ptr.add(key).toString()})}),subtract(output,input).forEach(function(key){operations.push({op:"add",path:ptr.add(key).toString(),value:output[key]})}),intersection([input,output]).forEach(function(key){operations.push.apply(operations,diff2(input[key],output[key],ptr.add(key)))}),operations}exports.diffObjects=diffObjects;function diffAny(input,output,ptr,diff2){if(diff2===void 0&&(diff2=diffAny),input===output)return[];var input_type=(0,util_1.objectType)(input),output_type=(0,util_1.objectType)(output);return input_type=="array"&&output_type=="array"?diffArrays(input,output,ptr,diff2):input_type=="object"&&output_type=="object"?diffObjects(input,output,ptr,diff2):[{op:"replace",path:ptr.toString(),value:output}]}exports.diffAny=diffAny}});var require_patch=__commonJS({"../../node_modules/rfc6902/patch.js"(exports){"use strict";var __extends=exports&&exports.__extends||(function(){var extendStatics=function(d,b){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d2,b2){d2.__proto__=b2}||function(d2,b2){for(var p in b2)Object.prototype.hasOwnProperty.call(b2,p)&&(d2[p]=b2[p])},extendStatics(d,b)};return function(d,b){if(typeof b!="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}})();Object.defineProperty(exports,"__esModule",{value:!0});exports.apply=exports.InvalidOperationError=exports.test=exports.copy=exports.move=exports.replace=exports.remove=exports.add=exports.TestError=exports.MissingError=void 0;var pointer_1=require_pointer(),util_1=require_util(),diff_1=require_diff(),MissingError=(function(_super){__extends(MissingError2,_super);function MissingError2(path){var _this=_super.call(this,"Value required at path: ".concat(path))||this;return _this.path=path,_this.name="MissingError",_this}return MissingError2})(Error);exports.MissingError=MissingError;var TestError=(function(_super){__extends(TestError2,_super);function TestError2(actual,expected){var _this=_super.call(this,"Test failed: ".concat(actual," != ").concat(expected))||this;return _this.actual=actual,_this.expected=expected,_this.name="TestError",_this}return TestError2})(Error);exports.TestError=TestError;function _add(object,key,value){if(Array.isArray(object))if(key=="-")object.push(value);else{var index=parseInt(key,10);object.splice(index,0,value)}else object[key]=value}function _remove(object,key){if(Array.isArray(object)){var index=parseInt(key,10);object.splice(index,1)}else delete object[key]}function add(object,operation){var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return endpoint.parent===void 0?new MissingError(operation.path):(_add(endpoint.parent,endpoint.key,(0,util_1.clone)(operation.value)),null)}exports.add=add;function remove(object,operation){var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return endpoint.value===void 0?new MissingError(operation.path):(_remove(endpoint.parent,endpoint.key),null)}exports.remove=remove;function replace(object,operation){var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);if(endpoint.parent===null)return new MissingError(operation.path);if(Array.isArray(endpoint.parent)){if(parseInt(endpoint.key,10)>=endpoint.parent.length)return new MissingError(operation.path)}else if(endpoint.value===void 0)return new MissingError(operation.path);return endpoint.parent[endpoint.key]=(0,util_1.clone)(operation.value),null}exports.replace=replace;function move(object,operation){var from_endpoint=pointer_1.Pointer.fromJSON(operation.from).evaluate(object);if(from_endpoint.value===void 0)return new MissingError(operation.from);var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return endpoint.parent===void 0?new MissingError(operation.path):(_remove(from_endpoint.parent,from_endpoint.key),_add(endpoint.parent,endpoint.key,from_endpoint.value),null)}exports.move=move;function copy(object,operation){var from_endpoint=pointer_1.Pointer.fromJSON(operation.from).evaluate(object);if(from_endpoint.value===void 0)return new MissingError(operation.from);var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return endpoint.parent===void 0?new MissingError(operation.path):(_add(endpoint.parent,endpoint.key,(0,util_1.clone)(from_endpoint.value)),null)}exports.copy=copy;function test(object,operation){var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return(0,diff_1.diffAny)(endpoint.value,operation.value,new pointer_1.Pointer).length?new TestError(endpoint.value,operation.value):null}exports.test=test;var InvalidOperationError=(function(_super){__extends(InvalidOperationError2,_super);function InvalidOperationError2(operation){var _this=_super.call(this,"Invalid operation: ".concat(operation.op))||this;return _this.operation=operation,_this.name="InvalidOperationError",_this}return InvalidOperationError2})(Error);exports.InvalidOperationError=InvalidOperationError;function apply(object,operation){switch(operation.op){case"add":return add(object,operation);case"remove":return remove(object,operation);case"replace":return replace(object,operation);case"move":return move(object,operation);case"copy":return copy(object,operation);case"test":return test(object,operation)}return new InvalidOperationError(operation)}exports.apply=apply}});var require_rfc6902=__commonJS({"../../node_modules/rfc6902/index.js"(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.createTests=exports.createPatch=exports.applyPatch=exports.Pointer=void 0;var pointer_1=require_pointer();Object.defineProperty(exports,"Pointer",{enumerable:!0,get:function(){return pointer_1.Pointer}});var patch_1=require_patch(),diff_1=require_diff();function applyPatch(object,patch){return patch.map(function(operation){return(0,patch_1.apply)(object,operation)})}exports.applyPatch=applyPatch;function wrapVoidableDiff(diff2){function wrappedDiff(input,output,ptr){var custom_patch=diff2(input,output,ptr);return Array.isArray(custom_patch)?custom_patch:(0,diff_1.diffAny)(input,output,ptr,wrappedDiff)}return wrappedDiff}function createPatch2(input,output,diff2){var ptr=new pointer_1.Pointer;return(diff2?wrapVoidableDiff(diff2):diff_1.diffAny)(input,output,ptr)}exports.createPatch=createPatch2;function createTest(input,path){var endpoint=pointer_1.Pointer.fromJSON(path).evaluate(input);if(endpoint!==void 0)return{op:"test",path,value:endpoint.value}}function createTests(input,patch){var tests=new Array;return patch.filter(diff_1.isDestructive).forEach(function(operation){var pathTest=createTest(input,operation.path);if(pathTest&&tests.push(pathTest),"from"in operation){var fromTest=createTest(input,operation.from);fromTest&&tests.push(fromTest)}}),tests}exports.createTests=createTests}});export*from"@medplum/react-hooks";import{formatAddress}from"@medplum/core";import{Fragment,jsx}from"react/jsx-runtime";function AddressDisplay(props){let address=props.value;return address?jsx(Fragment,{children:formatAddress(address)}):null}import{Group,NativeSelect,TextInput}from"@mantine/core";import{trimTrailingEmptyElements}from"@medplum/core";import{useContext,useMemo,useRef,useState}from"react";import{isPopulated}from"@medplum/core";import{createContext}from"react";var DEFAULT_IGNORED_PROPERTIES=["meta","implicitRules","contained","extension","modifierExtension"],DEFAULT_IGNORED_NON_NESTED_PROPERTIES=["language","text"];var ElementsContext=createContext({path:"",profileUrl:void 0,elements:Object.create(null),elementsByPath:Object.create(null),getExtendedProps:()=>({readonly:!1,hidden:!1}),accessPolicyResource:void 0,debugMode:!1,isDefaultContext:!0});ElementsContext.displayName="ElementsContext";var EXTENSION_KEYS=["extension","modifierExtension"],IGNORED_PROPERTIES=["id",...DEFAULT_IGNORED_PROPERTIES].filter(prop=>!EXTENSION_KEYS.includes(prop));function getElementsToRender(inputElements){return Object.entries(inputElements).filter(([key,element])=>!isPopulated(element.type)||element.max===0||element.path.toLowerCase().endsWith("extension.url")&&element.fixed||EXTENSION_KEYS.includes(key)&&!isPopulated(element.slicing?.slices)||IGNORED_PROPERTIES.includes(key)?!1:!(DEFAULT_IGNORED_NON_NESTED_PROPERTIES.includes(key)&&element.path.split(".").length===2||key.includes(".")))}import{jsx as jsx2,jsxs}from"react/jsx-runtime";function getLine(address,index){return address.line&&address.line.length>index?address.line[index]:""}function setLine(address,index,str){let line=address.line||[];for(;line.length<=index;)line.push("");return line[index]=str,{...address,line:trimTrailingEmptyElements(line)}}function AddressInput(props){let[value,setValue]=useState(props.defaultValue||{}),valueRef=useRef(value);valueRef.current=value;let{getExtendedProps}=useContext(ElementsContext),[useProps,typeProps,line1Props,line2Props,cityProps,stateProps,postalCodeProps]=useMemo(()=>["use","type","line1","line2","city","state","postalCode"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}function setUse(use){setValueWrapper({...valueRef.current,use})}function setType(type){setValueWrapper({...valueRef.current,type})}function setLine1(line1){setValueWrapper(setLine(valueRef.current||{},0,line1))}function setLine2(line2){setValueWrapper(setLine(valueRef.current||{},1,line2))}function setCity(city){setValueWrapper({...valueRef.current,city})}function setState(state){setValueWrapper({...valueRef.current,state})}function setPostalCode(postalCode){setValueWrapper({...valueRef.current,postalCode})}return jsxs(Group,{gap:"xs",wrap:"nowrap",grow:!0,children:[jsx2(NativeSelect,{disabled:props.disabled||useProps?.readonly,"data-testid":"address-use",defaultValue:value.use,onChange:e=>setUse(e.currentTarget.value),data:["","home","work","temp","old","billing"]}),jsx2(NativeSelect,{disabled:props.disabled||typeProps?.readonly,"data-testid":"address-type",defaultValue:value.type,onChange:e=>setType(e.currentTarget.value),data:["","postal","physical","both"]}),jsx2(TextInput,{disabled:props.disabled||line1Props?.readonly,placeholder:"Line 1",defaultValue:getLine(value,0),onChange:e=>setLine1(e.currentTarget.value)}),jsx2(TextInput,{disabled:props.disabled||line2Props?.readonly,placeholder:"Line 2",defaultValue:getLine(value,1),onChange:e=>setLine2(e.currentTarget.value)}),jsx2(TextInput,{disabled:props.disabled||cityProps?.readonly,placeholder:"City",defaultValue:value.city,onChange:e=>setCity(e.currentTarget.value)}),jsx2(TextInput,{disabled:props.disabled||stateProps?.readonly,placeholder:"State",defaultValue:value.state,onChange:e=>setState(e.currentTarget.value)}),jsx2(TextInput,{disabled:props.disabled||postalCodeProps?.readonly,placeholder:"Postal Code",defaultValue:value.postalCode,onChange:e=>setPostalCode(e.currentTarget.value)})]})}import{TextInput as TextInput2}from"@mantine/core";import{createReference}from"@medplum/core";import{useMedplumProfile}from"@medplum/react-hooks";import{useState as useState2}from"react";import{jsx as jsx3}from"react/jsx-runtime";function AnnotationInput(props){let author=useMedplumProfile(),[value,setValue]=useState2(props.defaultValue||{});function setText(text){let newValue=text?{text,authorReference:author&&createReference(author),time:new Date().toISOString()}:{};setValue(newValue),props.onChange&&props.onChange(newValue)}return jsx3(TextInput2,{disabled:props.disabled,name:props.name,placeholder:"Annotation text",defaultValue:value.text,onChange:e=>setText(e.currentTarget.value)})}import{AppShell as MantineAppShell3}from"@mantine/core";import{useMedplum as useMedplum5,useMedplumProfile as useMedplumProfile4}from"@medplum/react-hooks";import{Suspense,useState as useState11}from"react";import{Alert}from"@mantine/core";import{locationUtils,normalizeErrorString}from"@medplum/core";import{forwardRef,createElement}from"react";var defaultAttributes={outline:{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"},filled:{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none"}};var createReactComponent=(type,iconName,iconNamePascal,iconNode)=>{let Component2=forwardRef(({color="currentColor",size=24,stroke=2,title,className,children,...rest},ref)=>createElement("svg",{ref,...defaultAttributes[type],width:size,height:size,className:["tabler-icon",`tabler-icon-${iconName}`,className].join(" "),...type==="filled"?{fill:color}:{strokeWidth:stroke,stroke:color},...rest},[title&&createElement("title",{key:"svg-title"},title),...iconNode.map(([tag,attrs])=>createElement(tag,attrs)),...Array.isArray(children)?children:[children]]));return Component2.displayName=`${iconNamePascal}`,Component2};var __iconNode=[["path",{d:"M12 6a2 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:"M6 12a2 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:"M15 18a2 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"}]],IconAdjustmentsHorizontal=createReactComponent("outline","adjustments-horizontal","AdjustmentsHorizontal",__iconNode);var __iconNode2=[["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"}]],IconAlertCircle=createReactComponent("outline","alert-circle","AlertCircle",__iconNode2);var __iconNode3=[["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"}]],IconArrowDown=createReactComponent("outline","arrow-down","ArrowDown",__iconNode3);var __iconNode4=[["path",{d:"M5 12l14 0",key:"svg-0"}],["path",{d:"M13 18l6 -6",key:"svg-1"}],["path",{d:"M13 6l6 6",key:"svg-2"}]],IconArrowRight=createReactComponent("outline","arrow-right","ArrowRight",__iconNode4);var __iconNode5=[["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"}]],IconArrowUp=createReactComponent("outline","arrow-up","ArrowUp",__iconNode5);var __iconNode6=[["path",{d:"M6 20a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-0"}],["path",{d:"M16 4a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-1"}],["path",{d:"M16 20a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-2"}],["path",{d:"M11 12a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-3"}],["path",{d:"M21 12a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-4"}],["path",{d:"M5.058 18.306l2.88 -4.606",key:"svg-5"}],["path",{d:"M10.061 10.303l2.877 -4.604",key:"svg-6"}],["path",{d:"M10.065 13.705l2.876 4.6",key:"svg-7"}],["path",{d:"M15.063 5.7l2.881 4.61",key:"svg-8"}]],IconBinaryTree=createReactComponent("outline","binary-tree","BinaryTree",__iconNode6);var __iconNode7=[["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"}]],IconBleachOff=createReactComponent("outline","bleach-off","BleachOff",__iconNode7);var __iconNode8=[["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"}]],IconBleach=createReactComponent("outline","bleach","Bleach",__iconNode8);var __iconNode9=[["path",{d:"M18 7v14l-6 -4l-6 4v-14a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4",key:"svg-0"}]],IconBookmark=createReactComponent("outline","bookmark","Bookmark",__iconNode9);var __iconNode10=[["path",{d:"M7 5a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2l0 -10",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"}]],IconBoxMultiple=createReactComponent("outline","box-multiple","BoxMultiple",__iconNode10);var __iconNode11=[["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"}]],IconBracketsContain=createReactComponent("outline","brackets-contain","BracketsContain",__iconNode11);var __iconNode12=[["path",{d:"M3 9a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2l0 -9",key:"svg-0"}],["path",{d:"M8 7v-2a2 2 0 0 1 2 -2h4a2 2 0 0 1 2 2v2",key:"svg-1"}],["path",{d:"M12 12l0 .01",key:"svg-2"}],["path",{d:"M3 13a20 20 0 0 0 18 0",key:"svg-3"}]],IconBriefcase=createReactComponent("outline","briefcase","Briefcase",__iconNode12);var __iconNode13=[["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"}]],IconBucketOff=createReactComponent("outline","bucket-off","BucketOff",__iconNode13);var __iconNode14=[["path",{d:"M4 7a8 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"}]],IconBucket=createReactComponent("outline","bucket","Bucket",__iconNode14);var __iconNode15=[["path",{d:"M3 20h18v-8a3 3 0 0 0 -3 -3h-12a3 3 0 0 0 -3 3v8",key:"svg-0"}],["path",{d:"M3 14.803c.312 .135 .654 .204 1 .197a2.4 2.4 0 0 0 2 -1a2.4 2.4 0 0 1 2 -1a2.4 2.4 0 0 1 2 1a2.4 2.4 0 0 0 2 1a2.4 2.4 0 0 0 2 -1a2.4 2.4 0 0 1 2 -1a2.4 2.4 0 0 1 2 1a2.4 2.4 0 0 0 2 1c.35 .007 .692 -.062 1 -.197",key:"svg-1"}],["path",{d:"M12 4l1.465 1.638a2 2 0 1 1 -3.015 .099l1.55 -1.737",key:"svg-2"}]],IconCake=createReactComponent("outline","cake","Cake",__iconNode15);var __iconNode16=[["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-12",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"}]],IconCalendar=createReactComponent("outline","calendar","Calendar",__iconNode16);var __iconNode17=[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]],IconCheck=createReactComponent("outline","check","Check",__iconNode17);var __iconNode18=[["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"}]],IconCheckbox=createReactComponent("outline","checkbox","Checkbox",__iconNode18);var __iconNode19=[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]],IconChevronDown=createReactComponent("outline","chevron-down","ChevronDown",__iconNode19);var __iconNode20=[["path",{d:"M9 6l6 6l-6 6",key:"svg-0"}]],IconChevronRight=createReactComponent("outline","chevron-right","ChevronRight",__iconNode20);var __iconNode21=[["path",{d:"M6 15l6 -6l6 6",key:"svg-0"}]],IconChevronUp=createReactComponent("outline","chevron-up","ChevronUp",__iconNode21);var __iconNode22=[["path",{d:"M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0",key:"svg-0"}],["path",{d:"M9 12l6 0",key:"svg-1"}]],IconCircleMinus=createReactComponent("outline","circle-minus","CircleMinus",__iconNode22);var __iconNode23=[["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"}]],IconCirclePlus=createReactComponent("outline","circle-plus","CirclePlus",__iconNode23);var __iconNode24=[["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"}]],IconCloudUpload=createReactComponent("outline","cloud-upload","CloudUpload",__iconNode24);var __iconNode25=[["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"}]],IconColumns=createReactComponent("outline","columns","Columns",__iconNode25);var __iconNode26=[["path",{d:"M7 9.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.667l0 -8.666",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"}]],IconCopy=createReactComponent("outline","copy","Copy",__iconNode26);var __iconNode27=[["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"}]],IconCurrencyDollar=createReactComponent("outline","currency-dollar","CurrencyDollar",__iconNode27);var __iconNode28=[["path",{d:"M4 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-0"}],["path",{d:"M11 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-1"}],["path",{d:"M18 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-2"}]],IconDots=createReactComponent("outline","dots","Dots",__iconNode28);var __iconNode29=[["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.415",key:"svg-1"}],["path",{d:"M16 5l3 3",key:"svg-2"}]],IconEdit=createReactComponent("outline","edit","Edit",__iconNode29);var __iconNode30=[["path",{d:"M9.5 5.5a2.5 2.5 0 1 0 5 0a2.5 2.5 0 1 0 -5 0",key:"svg-0"}],["path",{d:"M12 21.368l5.095 -5.096a3.088 3.088 0 1 0 -4.367 -4.367l-.728 .727l-.728 -.727a3.088 3.088 0 1 0 -4.367 4.367l5.095 5.096",key:"svg-1"}]],IconEmpathize=createReactComponent("outline","empathize","Empathize",__iconNode30);var __iconNode31=[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}],["path",{d:"M5 19l14 -14",key:"svg-2"}]],IconEqualNot=createReactComponent("outline","equal-not","EqualNot",__iconNode31);var __iconNode32=[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]],IconEqual=createReactComponent("outline","equal","Equal",__iconNode32);var __iconNode33=[["path",{d:"M10.585 10.587a2 2 0 0 0 2.829 2.828",key:"svg-0"}],["path",{d:"M16.681 16.673a8.717 8.717 0 0 1 -4.681 1.327c-3.6 0 -6.6 -2 -9 -6c1.272 -2.12 2.712 -3.678 4.32 -4.674m2.86 -1.146a9.055 9.055 0 0 1 1.82 -.18c3.6 0 6.6 2 9 6c-.666 1.11 -1.379 2.067 -2.138 2.87",key:"svg-1"}],["path",{d:"M3 3l18 18",key:"svg-2"}]],IconEyeOff=createReactComponent("outline","eye-off","EyeOff",__iconNode33);var __iconNode34=[["path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0",key:"svg-0"}],["path",{d:"M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6",key:"svg-1"}]],IconEye=createReactComponent("outline","eye","Eye",__iconNode34);var __iconNode35=[["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 2",key:"svg-1"}],["path",{d:"M12 17l.01 0",key:"svg-2"}],["path",{d:"M12 11l0 3",key:"svg-3"}]],IconFileAlert=createReactComponent("outline","file-alert","FileAlert",__iconNode35);var __iconNode36=[["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 2",key:"svg-1"}],["path",{d:"M12 11l0 6",key:"svg-2"}],["path",{d:"M9 14l6 0",key:"svg-3"}]],IconFilePlus=createReactComponent("outline","file-plus","FilePlus",__iconNode36);var __iconNode37=[["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.227",key:"svg-0"}]],IconFilter=createReactComponent("outline","filter","Filter",__iconNode37);var __iconNode38=[["path",{d:"M9 6.371c0 4.418 -2.239 6.629 -5 6.629",key:"svg-0"}],["path",{d:"M4 6.371h7",key:"svg-1"}],["path",{d:"M5 9c0 2.144 2.252 3.908 6 4",key:"svg-2"}],["path",{d:"M12 20l4 -9l4 9",key:"svg-3"}],["path",{d:"M19.1 18h-6.2",key:"svg-4"}],["path",{d:"M6.694 3l.793 .582",key:"svg-5"}]],IconLanguage=createReactComponent("outline","language","Language",__iconNode38);var __iconNode39=[["path",{d:"M4 6a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2l0 -12",key:"svg-0"}],["path",{d:"M9 4l0 16",key:"svg-1"}]],IconLayoutSidebar=createReactComponent("outline","layout-sidebar","LayoutSidebar",__iconNode39);var __iconNode40=[["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"}]],IconLogout=createReactComponent("outline","logout","Logout",__iconNode40);var __iconNode41=[["path",{d:"M9 11a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",key:"svg-0"}],["path",{d:"M17.657 16.657l-4.243 4.243a2 2 0 0 1 -2.827 0l-4.244 -4.243a8 8 0 1 1 11.314 0",key:"svg-1"}]],IconMapPin=createReactComponent("outline","map-pin","MapPin",__iconNode41);var __iconNode42=[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]],IconMathGreater=createReactComponent("outline","math-greater","MathGreater",__iconNode42);var __iconNode43=[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]],IconMathLower=createReactComponent("outline","math-lower","MathLower",__iconNode43);var __iconNode44=[["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 -3h12",key:"svg-2"}]],IconMessage=createReactComponent("outline","message","Message",__iconNode44);var __iconNode45=[["path",{d:"M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4",key:"svg-0"}],["path",{d:"M13.5 6.5l4 4",key:"svg-1"}]],IconPencil=createReactComponent("outline","pencil","Pencil",__iconNode45);var __iconNode46=[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]],IconPlus=createReactComponent("outline","plus","Plus",__iconNode46);var __iconNode47=[["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"}]],IconRefresh=createReactComponent("outline","refresh","Refresh",__iconNode47);var __iconNode48=[["path",{d:"M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M21 21l-6 -6",key:"svg-1"}]],IconSearch=createReactComponent("outline","search","Search",__iconNode48);var __iconNode49=[["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.065",key:"svg-0"}],["path",{d:"M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",key:"svg-1"}]],IconSettings=createReactComponent("outline","settings","Settings",__iconNode49);var __iconNode50=[["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"}]],IconSortAscending=createReactComponent("outline","sort-ascending","SortAscending",__iconNode50);var __iconNode51=[["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"}]],IconSortDescending=createReactComponent("outline","sort-descending","SortDescending",__iconNode51);var __iconNode52=[["path",{d:"M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14",key:"svg-0"}]],IconSquare=createReactComponent("outline","square","Square",__iconNode52);var __iconNode53=[["path",{d:"M6 4h-1a2 2 0 0 0 -2 2v3.5a5.5 5.5 0 0 0 11 0v-3.5a2 2 0 0 0 -2 -2h-1",key:"svg-0"}],["path",{d:"M8 15a6 6 0 1 0 12 0v-3",key:"svg-1"}],["path",{d:"M11 3v2",key:"svg-2"}],["path",{d:"M6 3v2",key:"svg-3"}],["path",{d:"M18 10a2 2 0 1 0 4 0a2 2 0 1 0 -4 0",key:"svg-4"}]],IconStethoscope=createReactComponent("outline","stethoscope","Stethoscope",__iconNode53);var __iconNode54=[["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"}]],IconSwitchHorizontal=createReactComponent("outline","switch-horizontal","SwitchHorizontal",__iconNode54);var __iconNode55=[["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"}]],IconTableExport=createReactComponent("outline","table-export","TableExport",__iconNode55);var __iconNode56=[["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"}]],IconTrash=createReactComponent("outline","trash","Trash",__iconNode56);var __iconNode57=[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]],IconX=createReactComponent("outline","x","X",__iconNode57);import{Component}from"react";import{jsx as jsx4}from"react/jsx-runtime";var ErrorBoundary=class extends Component{constructor(props){super(props);__publicField(this,"state");this.state={lastLocation:locationUtils.getLocation()}}static getDerivedStateFromError(error){return{error,lastLocation:locationUtils.getLocation()}}componentDidUpdate(_prevProps,_prevState){locationUtils.getLocation()!==this.state.lastLocation&&this.setState({lastLocation:locationUtils.getLocation(),error:void 0})}shouldComponentUpdate(nextProps,nextState){return!!(this.props.children!==nextProps.children||nextState.error&&!this.state.error||this.state.lastLocation!==locationUtils.getLocation())}componentDidCatch(error,errorInfo){console.error("Uncaught error:",error,errorInfo)}render(){return this.state.error?jsx4(Alert,{icon:jsx4(IconAlertCircle,{size:16}),title:"Something went wrong",color:"red",children:normalizeErrorString(this.state.error)}):this.props.children}};import{Center,Loader}from"@mantine/core";import{jsx as jsx5}from"react/jsx-runtime";function Loading(){return jsx5(Center,{style:{width:"100%",height:"100vh"},children:jsx5(Loader,{})})}var AppShell_default={main:"AppShell_main"};import{Group as Group5,AppShell as MantineAppShell,Menu as Menu2,Text as Text3,UnstyledButton}from"@mantine/core";import{formatHumanName as formatHumanName3}from"@medplum/core";import{useMedplumProfile as useMedplumProfile2}from"@medplum/react-hooks";import{useState as useState5}from"react";import{Avatar}from"@mantine/core";import{getDisplayString,getImageSrc}from"@medplum/core";import{useCachedBinaryUrl,useResource}from"@medplum/react-hooks";import{Anchor}from"@mantine/core";import{isReference,isResource}from"@medplum/core";import{useMedplumNavigate}from"@medplum/react-hooks";import{ContentType}from"@medplum/core";function killEvent(e){e.preventDefault(),e.stopPropagation()}function isAuxClick(e){return e.button===1||e.ctrlKey||e.metaKey}function isCheckboxCell(el){if(isCheckboxElement(el))return!0;if(el instanceof HTMLTableCellElement){let children=el.children;if(children.length===1&&isCheckboxElement(children[0]))return!0}return!1}function isCheckboxElement(el){return el instanceof HTMLInputElement&&el.type==="checkbox"}async function sendCommand(frame,command){return new Promise((resolve,reject)=>{let channel=new MessageChannel;channel.port1.onmessage=({data:data2})=>{channel.port1.close(),data2.error?reject(data2.error):resolve(data2.result)},frame.contentWindow?.postMessage(command,new URL(frame.src).origin,[channel.port2])})}function exportJsonFile(jsonString,fileName){let blobForExport=new Blob([jsonString],{type:ContentType.JSON}),url=URL.createObjectURL(blobForExport),link=document.createElement("a");link.href=url;let linkName=fileName??new Date().toISOString().replaceAll(/\D/g,"");link.download=`${linkName}.json`,document.body.appendChild(link),link.click(),URL.revokeObjectURL(url)}import{jsx as jsx6}from"react/jsx-runtime";function MedplumLink(props){let navigate=useMedplumNavigate(),{to,suffix,label,onClick,children,...rest}=props,href=getHref(to);return suffix&&(href+="/"+suffix),jsx6(Anchor,{href,"aria-label":label,onAuxClick:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation(),onClick?(e.preventDefault(),onClick(e)):to&&(isAuxClick(e)||(e.preventDefault(),navigate(href)))},...rest,children})}function getHref(to){if(to){if(typeof to=="string")return getStringHref(to);if(isResource(to))return getResourceHref(to);if(isReference(to))return getReferenceHref(to)}return"#"}function getStringHref(to){return to.startsWith("http://")||to.startsWith("https://")||to.startsWith("/")?to:"/"+to}function getResourceHref(to){return`/${to.resourceType}/${to.id}`}function getReferenceHref(to){return`/${to.reference}`}function getInitials(input){let words=input.split(" ").filter(Boolean);return words.length>1?words[0][0]+words.at(-1)?.at(0):words.length===1?words[0][0]:""}import{jsx as jsx7}from"react/jsx-runtime";function ResourceAvatar(props){let resource=useResource(props.value),text=resource?getDisplayString(resource):props.alt??"",initials=getInitials(text),uncachedImageUrl=(resource&&getImageSrc(resource))??props.src,imageUrl=useCachedBinaryUrl(uncachedImageUrl??void 0),radius=props.radius??"xl",avatarProps={...props,value:void 0,link:void 0};return props.link?jsx7(MedplumLink,{to:resource,children:jsx7(Avatar,{src:imageUrl,alt:text,radius,...avatarProps,children:initials})}):jsx7(Avatar,{src:imageUrl,alt:text,radius,...avatarProps,children:initials})}var Header_default={logoButton:"Header_logoButton",user:"Header_user",userName:"Header_userName"};import{Avatar as Avatar2,Group as Group2,Menu,SegmentedControl,Stack,Text,useMantineColorScheme}from"@mantine/core";import{getReferenceString,locationUtils as locationUtils2}from"@medplum/core";import{useMedplumContext}from"@medplum/react-hooks";import{useState as useState3}from"react";import{formatHumanName}from"@medplum/core";import{Fragment as Fragment2,jsx as jsx8}from"react/jsx-runtime";function HumanNameDisplay(props){let name=props.value;return name?jsx8(Fragment2,{children:formatHumanName(name,props.options)}):null}function getAppName(){return import.meta.env.MEDPLUM_APP_NAME||"Medplum"}import{Fragment as Fragment3,jsx as jsx9,jsxs as jsxs2}from"react/jsx-runtime";function HeaderDropdown(props){let context=useMedplumContext(),{medplum,profile,navigate}=context,logins=medplum.getLogins(),{colorScheme,setColorScheme}=useMantineColorScheme(),[layoutVersion]=useState3(localStorage.appShellLayoutVersion??"v1");function setAppShellVersion(version){localStorage.appShellLayoutVersion=version,locationUtils2.reload()}return jsxs2(Fragment3,{children:[jsxs2(Stack,{align:"center",p:"xl",children:[jsx9(ResourceAvatar,{size:"xl",radius:100,value:context.profile}),jsx9(HumanNameDisplay,{value:context.profile?.name?.[0]}),jsx9(Text,{c:"dimmed",size:"xs",children:medplum.getActiveLogin()?.project.display})]}),logins.length>1&&jsx9(Menu.Divider,{}),logins.map(login=>login.profile.reference!==getReferenceString(context.profile)&&jsx9(Menu.Item,{onClick:()=>{medplum.setActiveLogin(login).then(()=>locationUtils2.reload()).catch(console.log)},children:jsxs2(Group2,{children:[jsx9(Avatar2,{radius:"xl"}),jsxs2("div",{style:{flex:1},children:[jsx9(Text,{size:"sm",fw:500,children:login.profile.display}),jsx9(Text,{c:"dimmed",size:"xs",children:login.project.display})]})]})},login.profile.reference)),jsx9(Menu.Divider,{}),jsx9(Menu.Item,{leftSection:jsx9(IconSwitchHorizontal,{size:14,stroke:1.5}),onClick:()=>navigate("/signin"),children:"Switch to another project"}),jsx9(Menu.Divider,{}),jsxs2(Group2,{justify:"center",children:[jsx9(SegmentedControl,{size:"xs",value:colorScheme,onChange:newValue=>setColorScheme(newValue),data:[{label:"Light",value:"light"},{label:"Dark",value:"dark"},{label:"Auto",value:"auto"}]}),jsx9(SegmentedControl,{size:"xs",value:layoutVersion,onChange:newValue=>setAppShellVersion(newValue),data:[{label:"v1",value:"v1"},{label:"v2",value:"v2"}]})]}),jsx9(Menu.Divider,{}),jsx9(Menu.Item,{leftSection:jsx9(IconSettings,{size:14,stroke:1.5}),onClick:()=>navigate(`/${getReferenceString(profile)}`),children:"Account settings"}),jsx9(Menu.Item,{leftSection:jsx9(IconLogout,{size:14,stroke:1.5}),onClick:async()=>{await medplum.signOut(),navigate("/signin")},children:"Sign out"}),jsxs2(Text,{size:"xs",c:"dimmed",my:"sm",ta:"center",children:[getAppName()," ",props.version]})]})}import{Group as Group4,Text as Text2}from"@mantine/core";import{formatHumanName as formatHumanName2,getDisplayString as getDisplayString2,getReferenceString as getReferenceString2,isUUID}from"@medplum/core";import{useMedplum,useMedplumNavigate as useMedplumNavigate2}from"@medplum/react-hooks";import{forwardRef as forwardRef2,useCallback as useCallback2}from"react";import{Combobox,Group as Group3,Loader as Loader2,Pill,PillsInput,ScrollAreaAutosize,useCombobox}from"@mantine/core";import{showNotification}from"@mantine/notifications";import{normalizeErrorString as normalizeErrorString2}from"@medplum/core";import{useCallback,useEffect,useMemo as useMemo2,useRef as useRef2,useState as useState4}from"react";var AsyncAutocompleteTestIds={selectedItems:"selected-items",options:"options"};import{jsx as jsx10,jsxs as jsxs3}from"react/jsx-runtime";function AsyncAutocomplete(props){let combobox=useCombobox({onDropdownClose:()=>combobox.resetSelectedOption(),onDropdownOpen:()=>combobox.updateSelectedOptionIndex("active")}),{name,label,description,error,defaultValue:defaultValue2,toOption:toOption4,loadOptions,itemComponent,pillComponent,emptyComponent,onChange,onCreate,creatable,clearable,required,placeholder,leftSection,maxValues,optionsDropdownMaxHeight=320,minInputLength=0,...rest}=props,disabled=rest.disabled,defaultItems=toDefaultItems(defaultValue2),[search,setSearch]=useState4(""),[timer,setTimer]=useState4(),[abortController,setAbortController]=useState4(),[autoSubmit,setAutoSubmit]=useState4(),[selected,setSelected]=useState4(defaultItems.map(toOption4)),[options,setOptions]=useState4([]),ItemComponent3=itemComponent??DefaultItemComponent,PillComponent=pillComponent??DefaultPillComponent,EmptyComponent=emptyComponent??DefaultEmptyComponent,searchRef=useRef2(search);searchRef.current=search;let lastLoadOptionsRef=useRef2(void 0),lastValueRef=useRef2(void 0),timerRef=useRef2(timer);timerRef.current=timer;let abortControllerRef=useRef2(abortController);abortControllerRef.current=abortController;let autoSubmitRef=useRef2(autoSubmit);autoSubmitRef.current=autoSubmit;let optionsRef=useRef2(options);optionsRef.current=options;let handleTimer=useCallback(()=>{if(setTimer(void 0),searchRef.current===lastValueRef.current&&loadOptions===lastLoadOptionsRef.current||(searchRef.current?.length??0)<minInputLength)return;lastValueRef.current=searchRef.current,lastLoadOptionsRef.current=loadOptions;let newAbortController=new AbortController;setAbortController(newAbortController),loadOptions(searchRef.current??"",newAbortController.signal).then(newValues=>{newAbortController.signal.aborted||(setOptions(newValues.map(toOption4)),autoSubmitRef.current?(newValues.length>0&&onChange(newValues.slice(0,1)),setAutoSubmit(!1)):newValues.length>0&&combobox.openDropdown())}).catch(err=>{newAbortController.signal.aborted||err.message.includes("aborted")||showNotification({color:"red",message:normalizeErrorString2(err)})}).finally(()=>{newAbortController.signal.aborted||setAbortController(void 0)})},[combobox,loadOptions,onChange,toOption4,minInputLength]),handleSearchChange=useCallback(e=>{(options&&options.length>0||creatable)&&combobox.openDropdown(),combobox.updateSelectedOptionIndex(),setSearch(e.currentTarget.value),abortControllerRef.current&&(abortControllerRef.current.abort(),setAbortController(void 0)),timerRef.current!==void 0&&window.clearTimeout(timerRef.current);let newTimer=window.setTimeout(()=>handleTimer(),100);setTimer(newTimer)},[combobox,options,creatable,handleTimer]),addSelected=useCallback(newValue=>{let alreadySelected=selected.some(v=>v.value===newValue),newSelected=alreadySelected?selected.filter(v=>v.value!==newValue):[...selected],option=options?.find(option2=>option2.value===newValue);if(!option&&creatable!==!1&&onCreate){let createdResource=onCreate(newValue);option=toOption4(createdResource)}if(option){if(maxValues===0){onChange([option.resource]),selected.length>0&&setSelected([]);return}alreadySelected||newSelected.push(option)}if(maxValues!==void 0)for(;newSelected.length>maxValues;)newSelected.shift();onChange(newSelected.map(v=>v.resource)),setSelected(newSelected)},[creatable,options,selected,maxValues,onChange,onCreate,toOption4]),handleValueSelect=useMemo2(()=>{if(!disabled)return val=>{disabled||(maxValues===1&&(setSearch(""),setOptions([]),combobox.closeDropdown()),lastValueRef.current=void 0,val==="$create"?(setSearch(""),addSelected(search)):addSelected(val))}},[addSelected,combobox,disabled,maxValues,search]),handleValueRemove=useCallback(item=>{let newSelected=selected.filter(v=>v.value!==item.value);onChange(newSelected.map(v=>v.resource)),setSelected(newSelected)},[selected,onChange]),handleKeyDown=useCallback(e=>{e.key==="Enter"?(timer||abortController)&&setAutoSubmit(!0):e.key==="Backspace"&&search.length===0&&(killEvent(e),handleValueRemove(selected[selected.length-1]))},[abortController,handleValueRemove,search.length,selected,timer]);useEffect(()=>()=>{abortControllerRef.current&&abortControllerRef.current.abort()},[]);let clearButton=!disabled&&clearable&&selected.length>0&&jsx10(Combobox.ClearButton,{title:"Clear all",size:"sm",onClear:()=>{setSearch(""),setSelected([]),onChange([]),combobox.closeDropdown()}}),createVisible=creatable&&search.trim().length>0,comboboxVisible=options.length>0||createVisible;return jsxs3(Combobox,{store:combobox,onOptionSubmit:handleValueSelect,withinPortal:!0,shadow:"xl",...rest,children:[jsx10(Combobox.DropdownTarget,{children:jsx10(PillsInput,{label,description,error,className:props.className,leftSection,rightSection:abortController?jsx10(Loader2,{size:16}):clearButton,required,disabled,children:jsxs3(Pill.Group,{"data-testid":AsyncAutocompleteTestIds.selectedItems,children:[selected.map(item=>jsx10(PillComponent,{item,disabled,onRemove:()=>handleValueRemove(item)},item.value)),!disabled&&(maxValues===void 0||maxValues===0||selected.length<maxValues)&&jsx10(Combobox.EventsTarget,{children:jsx10(PillsInput.Field,{role:"searchbox",name,value:search,placeholder,onFocus:handleSearchChange,onBlur:()=>{combobox.closeDropdown(),setSearch("")},onKeyDown:handleKeyDown,onChange:handleSearchChange})})]})})}),jsx10(Combobox.Dropdown,{hidden:!comboboxVisible,"data-testid":AsyncAutocompleteTestIds.options,children:jsx10(Combobox.Options,{children:jsxs3(ScrollAreaAutosize,{type:"scroll",mah:optionsDropdownMaxHeight,children:[options.map(item=>{let active=selected.some(v=>v.value===item.value);return jsx10(Combobox.Option,{value:item.value,active,children:jsx10(ItemComponent3,{...item,active})},item.value)}),createVisible&&jsxs3(Combobox.Option,{value:"$create",children:["+ Create ",search]}),!creatable&&search.trim().length>0&&options.length===0&&jsx10(EmptyComponent,{search})]})})})]})}function toDefaultItems(defaultValue2){return defaultValue2?Array.isArray(defaultValue2)?defaultValue2:[defaultValue2]:[]}function DefaultItemComponent(props){return jsxs3(Group3,{gap:"xs",children:[props.active&&jsx10(IconCheck,{size:12}),jsx10("span",{children:props.label})]})}function DefaultPillComponent({item,disabled,onRemove}){return jsx10(Pill,{withRemoveButton:!disabled,onRemove,children:item.label})}function DefaultEmptyComponent(){return jsx10(Combobox.Empty,{children:"Nothing found"})}var HeaderSearchInput_default={searchInput:"HeaderSearchInput_searchInput"};import{jsx as jsx11,jsxs as jsxs4}from"react/jsx-runtime";function toOption(resource){return{value:resource.id,label:getDisplayString2(resource),resource}}function HeaderSearchInput(props){let navigate=useMedplumNavigate2(),medplum=useMedplum(),loadData=useCallback2(async(input,signal)=>{let query=buildGraphQLQuery(input),options={signal},response=await medplum.graphql(query,void 0,void 0,options);return getResourcesFromResponse(response,input)},[medplum]),handleSelect=useCallback2(item=>{item.length>0&&navigate(`/${getReferenceString2(item[0])}`)},[navigate]);return jsx11(AsyncAutocomplete,{size:"sm",radius:"md",className:HeaderSearchInput_default.searchInput,leftSection:jsx11(IconSearch,{size:16}),placeholder:"Search",itemComponent:ItemComponent,toOption,onChange:handleSelect,loadOptions:loadData,maxValues:0,clearable:!1},`${props.pathname}?${props.searchParams}`)}var ItemComponent=forwardRef2(({resource,active:_active,...others},ref)=>{let helpText;return resource.resourceType==="Patient"?helpText=resource.birthDate:resource.resourceType==="ServiceRequest"&&(helpText=resource.subject?.display),jsx11("div",{ref,...others,children:jsxs4(Group4,{wrap:"nowrap",children:[jsx11(ResourceAvatar,{value:resource}),jsxs4("div",{children:[jsx11(Text2,{children:getDisplayString2(resource)}),jsx11(Text2,{size:"xs",c:"dimmed",children:helpText})]})]})})});function buildGraphQLQuery(input){let escaped=JSON.stringify(input);return isUUID(input)?`{
1
+ var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __commonJS=(cb,mod)=>function(){return mod||(0,cb[__getOwnPropNames(cb)[0]])((mod={exports:{}}).exports,mod),mod.exports};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod));var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var require_pointer=__commonJS({"../../node_modules/rfc6902/pointer.js"(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.Pointer=exports.escapeToken=exports.unescapeToken=void 0;function unescapeToken(token){return token.replace(/~1/g,"/").replace(/~0/g,"~")}exports.unescapeToken=unescapeToken;function escapeToken(token){return token.replace(/~/g,"~0").replace(/\//g,"~1")}exports.escapeToken=escapeToken;var Pointer=(function(){function Pointer2(tokens){tokens===void 0&&(tokens=[""]),this.tokens=tokens}return Pointer2.fromJSON=function(path){var tokens=path.split("/").map(unescapeToken);if(tokens[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(path));return new Pointer2(tokens)},Pointer2.prototype.toString=function(){return this.tokens.map(escapeToken).join("/")},Pointer2.prototype.evaluate=function(object){for(var parent=null,key="",value=object,i=1,l=this.tokens.length;i<l;i++)parent=value,key=this.tokens[i],!(key=="__proto__"||key=="constructor"||key=="prototype")&&(value=(parent||{})[key]);return{parent,key,value}},Pointer2.prototype.get=function(object){return this.evaluate(object).value},Pointer2.prototype.set=function(object,value){var endpoint=this.evaluate(object);endpoint.parent&&(endpoint.parent[endpoint.key]=value)},Pointer2.prototype.push=function(token){this.tokens.push(token)},Pointer2.prototype.add=function(token){var tokens=this.tokens.concat(String(token));return new Pointer2(tokens)},Pointer2})();exports.Pointer=Pointer}});var require_util=__commonJS({"../../node_modules/rfc6902/util.js"(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.clone=exports.objectType=exports.hasOwnProperty=void 0;exports.hasOwnProperty=Object.prototype.hasOwnProperty;function objectType(object){return object===void 0?"undefined":object===null?"null":Array.isArray(object)?"array":typeof object}exports.objectType=objectType;function isNonPrimitive(value){return value!=null&&typeof value=="object"}function clone(source){if(!isNonPrimitive(source))return source;if(source.constructor==Array){for(var length_1=source.length,arrayTarget=new Array(length_1),i=0;i<length_1;i++)arrayTarget[i]=clone(source[i]);return arrayTarget}if(source.constructor==Date){var dateTarget=new Date(+source);return dateTarget}var objectTarget={};for(var key in source)exports.hasOwnProperty.call(source,key)&&(objectTarget[key]=clone(source[key]));return objectTarget}exports.clone=clone}});var require_diff=__commonJS({"../../node_modules/rfc6902/diff.js"(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.diffAny=exports.diffObjects=exports.diffArrays=exports.intersection=exports.subtract=exports.isDestructive=void 0;var util_1=require_util();function isDestructive(_a){var op=_a.op;return op==="remove"||op==="replace"||op==="copy"||op==="move"}exports.isDestructive=isDestructive;function subtract(minuend,subtrahend){var obj={};for(var add_key in minuend)util_1.hasOwnProperty.call(minuend,add_key)&&minuend[add_key]!==void 0&&(obj[add_key]=1);for(var del_key in subtrahend)util_1.hasOwnProperty.call(subtrahend,del_key)&&subtrahend[del_key]!==void 0&&delete obj[del_key];return Object.keys(obj)}exports.subtract=subtract;function intersection(objects){for(var length=objects.length,counter={},i=0;i<length;i++){var object=objects[i];for(var key in object)util_1.hasOwnProperty.call(object,key)&&object[key]!==void 0&&(counter[key]=(counter[key]||0)+1)}for(var key in counter)counter[key]<length&&delete counter[key];return Object.keys(counter)}exports.intersection=intersection;function isArrayAdd(array_operation){return array_operation.op==="add"}function isArrayRemove(array_operation){return array_operation.op==="remove"}function appendArrayOperation(base,operation){return{operations:base.operations.concat(operation),cost:base.cost+1}}function diffArrays(input,output,ptr,diff2){diff2===void 0&&(diff2=diffAny);var memo2={"0,0":{operations:[],cost:0}};function dist(i,j){var memo_key="".concat(i,",").concat(j),memoized=memo2[memo_key];if(memoized===void 0){if(i>0&&j>0&&!diff2(input[i-1],output[j-1],ptr.add(String(i-1))).length)memoized=dist(i-1,j-1);else{var alternatives=[];if(i>0){var remove_base=dist(i-1,j),remove_operation={op:"remove",index:i-1};alternatives.push(appendArrayOperation(remove_base,remove_operation))}if(j>0){var add_base=dist(i,j-1),add_operation={op:"add",index:i-1,value:output[j-1]};alternatives.push(appendArrayOperation(add_base,add_operation))}if(i>0&&j>0){var replace_base=dist(i-1,j-1),replace_operation={op:"replace",index:i-1,original:input[i-1],value:output[j-1]};alternatives.push(appendArrayOperation(replace_base,replace_operation))}var best=alternatives.sort(function(a,b){return a.cost-b.cost})[0];memoized=best}memo2[memo_key]=memoized}return memoized}var input_length=isNaN(input.length)||input.length<=0?0:input.length,output_length=isNaN(output.length)||output.length<=0?0:output.length,array_operations=dist(input_length,output_length).operations,padded_operations=array_operations.reduce(function(_a,array_operation){var operations=_a[0],padding=_a[1];if(isArrayAdd(array_operation)){var padded_index=array_operation.index+1+padding,index_token=padded_index<input_length+padding?String(padded_index):"-",operation={op:array_operation.op,path:ptr.add(index_token).toString(),value:array_operation.value};return[operations.concat(operation),padding+1]}else if(isArrayRemove(array_operation)){var operation={op:array_operation.op,path:ptr.add(String(array_operation.index+padding)).toString()};return[operations.concat(operation),padding-1]}else{var replace_ptr=ptr.add(String(array_operation.index+padding)),replace_operations=diff2(array_operation.original,array_operation.value,replace_ptr);return[operations.concat.apply(operations,replace_operations),padding]}},[[],0])[0];return padded_operations}exports.diffArrays=diffArrays;function diffObjects(input,output,ptr,diff2){diff2===void 0&&(diff2=diffAny);var operations=[];return subtract(input,output).forEach(function(key){operations.push({op:"remove",path:ptr.add(key).toString()})}),subtract(output,input).forEach(function(key){operations.push({op:"add",path:ptr.add(key).toString(),value:output[key]})}),intersection([input,output]).forEach(function(key){operations.push.apply(operations,diff2(input[key],output[key],ptr.add(key)))}),operations}exports.diffObjects=diffObjects;function diffAny(input,output,ptr,diff2){if(diff2===void 0&&(diff2=diffAny),input===output)return[];var input_type=(0,util_1.objectType)(input),output_type=(0,util_1.objectType)(output);return input_type=="array"&&output_type=="array"?diffArrays(input,output,ptr,diff2):input_type=="object"&&output_type=="object"?diffObjects(input,output,ptr,diff2):[{op:"replace",path:ptr.toString(),value:output}]}exports.diffAny=diffAny}});var require_patch=__commonJS({"../../node_modules/rfc6902/patch.js"(exports){"use strict";var __extends=exports&&exports.__extends||(function(){var extendStatics=function(d,b){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d2,b2){d2.__proto__=b2}||function(d2,b2){for(var p in b2)Object.prototype.hasOwnProperty.call(b2,p)&&(d2[p]=b2[p])},extendStatics(d,b)};return function(d,b){if(typeof b!="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}})();Object.defineProperty(exports,"__esModule",{value:!0});exports.apply=exports.InvalidOperationError=exports.test=exports.copy=exports.move=exports.replace=exports.remove=exports.add=exports.TestError=exports.MissingError=void 0;var pointer_1=require_pointer(),util_1=require_util(),diff_1=require_diff(),MissingError=(function(_super){__extends(MissingError2,_super);function MissingError2(path){var _this=_super.call(this,"Value required at path: ".concat(path))||this;return _this.path=path,_this.name="MissingError",_this}return MissingError2})(Error);exports.MissingError=MissingError;var TestError=(function(_super){__extends(TestError2,_super);function TestError2(actual,expected){var _this=_super.call(this,"Test failed: ".concat(actual," != ").concat(expected))||this;return _this.actual=actual,_this.expected=expected,_this.name="TestError",_this}return TestError2})(Error);exports.TestError=TestError;function _add(object,key,value){if(Array.isArray(object))if(key=="-")object.push(value);else{var index=parseInt(key,10);object.splice(index,0,value)}else object[key]=value}function _remove(object,key){if(Array.isArray(object)){var index=parseInt(key,10);object.splice(index,1)}else delete object[key]}function add(object,operation){var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return endpoint.parent===void 0?new MissingError(operation.path):(_add(endpoint.parent,endpoint.key,(0,util_1.clone)(operation.value)),null)}exports.add=add;function remove(object,operation){var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return endpoint.value===void 0?new MissingError(operation.path):(_remove(endpoint.parent,endpoint.key),null)}exports.remove=remove;function replace(object,operation){var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);if(endpoint.parent===null)return new MissingError(operation.path);if(Array.isArray(endpoint.parent)){if(parseInt(endpoint.key,10)>=endpoint.parent.length)return new MissingError(operation.path)}else if(endpoint.value===void 0)return new MissingError(operation.path);return endpoint.parent[endpoint.key]=(0,util_1.clone)(operation.value),null}exports.replace=replace;function move(object,operation){var from_endpoint=pointer_1.Pointer.fromJSON(operation.from).evaluate(object);if(from_endpoint.value===void 0)return new MissingError(operation.from);var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return endpoint.parent===void 0?new MissingError(operation.path):(_remove(from_endpoint.parent,from_endpoint.key),_add(endpoint.parent,endpoint.key,from_endpoint.value),null)}exports.move=move;function copy(object,operation){var from_endpoint=pointer_1.Pointer.fromJSON(operation.from).evaluate(object);if(from_endpoint.value===void 0)return new MissingError(operation.from);var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return endpoint.parent===void 0?new MissingError(operation.path):(_add(endpoint.parent,endpoint.key,(0,util_1.clone)(from_endpoint.value)),null)}exports.copy=copy;function test(object,operation){var endpoint=pointer_1.Pointer.fromJSON(operation.path).evaluate(object);return(0,diff_1.diffAny)(endpoint.value,operation.value,new pointer_1.Pointer).length?new TestError(endpoint.value,operation.value):null}exports.test=test;var InvalidOperationError=(function(_super){__extends(InvalidOperationError2,_super);function InvalidOperationError2(operation){var _this=_super.call(this,"Invalid operation: ".concat(operation.op))||this;return _this.operation=operation,_this.name="InvalidOperationError",_this}return InvalidOperationError2})(Error);exports.InvalidOperationError=InvalidOperationError;function apply(object,operation){switch(operation.op){case"add":return add(object,operation);case"remove":return remove(object,operation);case"replace":return replace(object,operation);case"move":return move(object,operation);case"copy":return copy(object,operation);case"test":return test(object,operation)}return new InvalidOperationError(operation)}exports.apply=apply}});var require_rfc6902=__commonJS({"../../node_modules/rfc6902/index.js"(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.createTests=exports.createPatch=exports.applyPatch=exports.Pointer=void 0;var pointer_1=require_pointer();Object.defineProperty(exports,"Pointer",{enumerable:!0,get:function(){return pointer_1.Pointer}});var patch_1=require_patch(),diff_1=require_diff();function applyPatch(object,patch){return patch.map(function(operation){return(0,patch_1.apply)(object,operation)})}exports.applyPatch=applyPatch;function wrapVoidableDiff(diff2){function wrappedDiff(input,output,ptr){var custom_patch=diff2(input,output,ptr);return Array.isArray(custom_patch)?custom_patch:(0,diff_1.diffAny)(input,output,ptr,wrappedDiff)}return wrappedDiff}function createPatch2(input,output,diff2){var ptr=new pointer_1.Pointer;return(diff2?wrapVoidableDiff(diff2):diff_1.diffAny)(input,output,ptr)}exports.createPatch=createPatch2;function createTest(input,path){var endpoint=pointer_1.Pointer.fromJSON(path).evaluate(input);if(endpoint!==void 0)return{op:"test",path,value:endpoint.value}}function createTests(input,patch){var tests=new Array;return patch.filter(diff_1.isDestructive).forEach(function(operation){var pathTest=createTest(input,operation.path);if(pathTest&&tests.push(pathTest),"from"in operation){var fromTest=createTest(input,operation.from);fromTest&&tests.push(fromTest)}}),tests}exports.createTests=createTests}});export*from"@medplum/react-hooks";import{formatAddress}from"@medplum/core";import{Fragment,jsx}from"react/jsx-runtime";function AddressDisplay(props){let address=props.value;return address?jsx(Fragment,{children:formatAddress(address)}):null}import{Group,NativeSelect,TextInput}from"@mantine/core";import{trimTrailingEmptyElements}from"@medplum/core";import{useContext,useMemo,useRef,useState}from"react";import{isPopulated}from"@medplum/core";import{createContext}from"react";var DEFAULT_IGNORED_PROPERTIES=["meta","implicitRules","contained","extension","modifierExtension"],DEFAULT_IGNORED_NON_NESTED_PROPERTIES=["language","text"];var ElementsContext=createContext({path:"",profileUrl:void 0,elements:Object.create(null),elementsByPath:Object.create(null),getExtendedProps:()=>({readonly:!1,hidden:!1}),accessPolicyResource:void 0,debugMode:!1,isDefaultContext:!0});ElementsContext.displayName="ElementsContext";var EXTENSION_KEYS=["extension","modifierExtension"],IGNORED_PROPERTIES=["id",...DEFAULT_IGNORED_PROPERTIES].filter(prop=>!EXTENSION_KEYS.includes(prop));function getElementsToRender(inputElements){return Object.entries(inputElements).filter(([key,element])=>!isPopulated(element.type)||element.max===0||element.path.toLowerCase().endsWith("extension.url")&&element.fixed||EXTENSION_KEYS.includes(key)&&!isPopulated(element.slicing?.slices)||IGNORED_PROPERTIES.includes(key)?!1:!(DEFAULT_IGNORED_NON_NESTED_PROPERTIES.includes(key)&&element.path.split(".").length===2||key.includes(".")))}import{jsx as jsx2,jsxs}from"react/jsx-runtime";function getLine(address,index){return address.line&&address.line.length>index?address.line[index]:""}function setLine(address,index,str){let line=address.line||[];for(;line.length<=index;)line.push("");return line[index]=str,{...address,line:trimTrailingEmptyElements(line)}}function AddressInput(props){let[value,setValue]=useState(props.defaultValue||{}),valueRef=useRef(value);valueRef.current=value;let{getExtendedProps}=useContext(ElementsContext),[useProps,typeProps,line1Props,line2Props,cityProps,stateProps,postalCodeProps]=useMemo(()=>["use","type","line1","line2","city","state","postalCode"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}function setUse(use){setValueWrapper({...valueRef.current,use})}function setType(type){setValueWrapper({...valueRef.current,type})}function setLine1(line1){setValueWrapper(setLine(valueRef.current||{},0,line1))}function setLine2(line2){setValueWrapper(setLine(valueRef.current||{},1,line2))}function setCity(city){setValueWrapper({...valueRef.current,city})}function setState(state){setValueWrapper({...valueRef.current,state})}function setPostalCode(postalCode){setValueWrapper({...valueRef.current,postalCode})}return jsxs(Group,{gap:"xs",wrap:"nowrap",grow:!0,children:[jsx2(NativeSelect,{disabled:props.disabled||useProps?.readonly,"data-testid":"address-use",defaultValue:value.use,onChange:e=>setUse(e.currentTarget.value),data:["","home","work","temp","old","billing"]}),jsx2(NativeSelect,{disabled:props.disabled||typeProps?.readonly,"data-testid":"address-type",defaultValue:value.type,onChange:e=>setType(e.currentTarget.value),data:["","postal","physical","both"]}),jsx2(TextInput,{disabled:props.disabled||line1Props?.readonly,placeholder:"Line 1",defaultValue:getLine(value,0),onChange:e=>setLine1(e.currentTarget.value)}),jsx2(TextInput,{disabled:props.disabled||line2Props?.readonly,placeholder:"Line 2",defaultValue:getLine(value,1),onChange:e=>setLine2(e.currentTarget.value)}),jsx2(TextInput,{disabled:props.disabled||cityProps?.readonly,placeholder:"City",defaultValue:value.city,onChange:e=>setCity(e.currentTarget.value)}),jsx2(TextInput,{disabled:props.disabled||stateProps?.readonly,placeholder:"State",defaultValue:value.state,onChange:e=>setState(e.currentTarget.value)}),jsx2(TextInput,{disabled:props.disabled||postalCodeProps?.readonly,placeholder:"Postal Code",defaultValue:value.postalCode,onChange:e=>setPostalCode(e.currentTarget.value)})]})}import{TextInput as TextInput2}from"@mantine/core";import{createReference}from"@medplum/core";import{useMedplumProfile}from"@medplum/react-hooks";import{useState as useState2}from"react";import{jsx as jsx3}from"react/jsx-runtime";function AnnotationInput(props){let author=useMedplumProfile(),[value,setValue]=useState2(props.defaultValue||{});function setText(text){let newValue=text?{text,authorReference:author&&createReference(author),time:new Date().toISOString()}:{};setValue(newValue),props.onChange&&props.onChange(newValue)}return jsx3(TextInput2,{disabled:props.disabled,name:props.name,placeholder:"Annotation text",defaultValue:value.text,onChange:e=>setText(e.currentTarget.value)})}import{AppShell as MantineAppShell3}from"@mantine/core";import{useMedplum as useMedplum5,useMedplumProfile as useMedplumProfile4}from"@medplum/react-hooks";import{Suspense,useState as useState11}from"react";import{Alert}from"@mantine/core";import{locationUtils,normalizeErrorString}from"@medplum/core";import{forwardRef,createElement}from"react";var defaultAttributes={outline:{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"},filled:{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none"}};var createReactComponent=(type,iconName,iconNamePascal,iconNode)=>{let Component2=forwardRef(({color="currentColor",size=24,stroke=2,title,className,children,...rest},ref)=>createElement("svg",{ref,...defaultAttributes[type],width:size,height:size,className:["tabler-icon",`tabler-icon-${iconName}`,className].join(" "),...type==="filled"?{fill:color}:{strokeWidth:stroke,stroke:color},...rest},[title&&createElement("title",{key:"svg-title"},title),...iconNode.map(([tag,attrs])=>createElement(tag,attrs)),...Array.isArray(children)?children:[children]]));return Component2.displayName=`${iconNamePascal}`,Component2};var __iconNode=[["path",{d:"M12 6a2 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:"M6 12a2 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:"M15 18a2 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"}]],IconAdjustmentsHorizontal=createReactComponent("outline","adjustments-horizontal","AdjustmentsHorizontal",__iconNode);var __iconNode2=[["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"}]],IconAlertCircle=createReactComponent("outline","alert-circle","AlertCircle",__iconNode2);var __iconNode3=[["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"}]],IconArrowDown=createReactComponent("outline","arrow-down","ArrowDown",__iconNode3);var __iconNode4=[["path",{d:"M5 12l14 0",key:"svg-0"}],["path",{d:"M13 18l6 -6",key:"svg-1"}],["path",{d:"M13 6l6 6",key:"svg-2"}]],IconArrowRight=createReactComponent("outline","arrow-right","ArrowRight",__iconNode4);var __iconNode5=[["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"}]],IconArrowUp=createReactComponent("outline","arrow-up","ArrowUp",__iconNode5);var __iconNode6=[["path",{d:"M6 20a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-0"}],["path",{d:"M16 4a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-1"}],["path",{d:"M16 20a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-2"}],["path",{d:"M11 12a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-3"}],["path",{d:"M21 12a2 2 0 1 0 -4 0a2 2 0 0 0 4 0",key:"svg-4"}],["path",{d:"M5.058 18.306l2.88 -4.606",key:"svg-5"}],["path",{d:"M10.061 10.303l2.877 -4.604",key:"svg-6"}],["path",{d:"M10.065 13.705l2.876 4.6",key:"svg-7"}],["path",{d:"M15.063 5.7l2.881 4.61",key:"svg-8"}]],IconBinaryTree=createReactComponent("outline","binary-tree","BinaryTree",__iconNode6);var __iconNode7=[["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"}]],IconBleachOff=createReactComponent("outline","bleach-off","BleachOff",__iconNode7);var __iconNode8=[["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"}]],IconBleach=createReactComponent("outline","bleach","Bleach",__iconNode8);var __iconNode9=[["path",{d:"M18 7v14l-6 -4l-6 4v-14a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4",key:"svg-0"}]],IconBookmark=createReactComponent("outline","bookmark","Bookmark",__iconNode9);var __iconNode10=[["path",{d:"M7 5a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2l0 -10",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"}]],IconBoxMultiple=createReactComponent("outline","box-multiple","BoxMultiple",__iconNode10);var __iconNode11=[["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"}]],IconBracketsContain=createReactComponent("outline","brackets-contain","BracketsContain",__iconNode11);var __iconNode12=[["path",{d:"M3 9a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2l0 -9",key:"svg-0"}],["path",{d:"M8 7v-2a2 2 0 0 1 2 -2h4a2 2 0 0 1 2 2v2",key:"svg-1"}],["path",{d:"M12 12l0 .01",key:"svg-2"}],["path",{d:"M3 13a20 20 0 0 0 18 0",key:"svg-3"}]],IconBriefcase=createReactComponent("outline","briefcase","Briefcase",__iconNode12);var __iconNode13=[["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"}]],IconBucketOff=createReactComponent("outline","bucket-off","BucketOff",__iconNode13);var __iconNode14=[["path",{d:"M4 7a8 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"}]],IconBucket=createReactComponent("outline","bucket","Bucket",__iconNode14);var __iconNode15=[["path",{d:"M3 20h18v-8a3 3 0 0 0 -3 -3h-12a3 3 0 0 0 -3 3v8",key:"svg-0"}],["path",{d:"M3 14.803c.312 .135 .654 .204 1 .197a2.4 2.4 0 0 0 2 -1a2.4 2.4 0 0 1 2 -1a2.4 2.4 0 0 1 2 1a2.4 2.4 0 0 0 2 1a2.4 2.4 0 0 0 2 -1a2.4 2.4 0 0 1 2 -1a2.4 2.4 0 0 1 2 1a2.4 2.4 0 0 0 2 1c.35 .007 .692 -.062 1 -.197",key:"svg-1"}],["path",{d:"M12 4l1.465 1.638a2 2 0 1 1 -3.015 .099l1.55 -1.737",key:"svg-2"}]],IconCake=createReactComponent("outline","cake","Cake",__iconNode15);var __iconNode16=[["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-12",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"}]],IconCalendar=createReactComponent("outline","calendar","Calendar",__iconNode16);var __iconNode17=[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]],IconCheck=createReactComponent("outline","check","Check",__iconNode17);var __iconNode18=[["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"}]],IconCheckbox=createReactComponent("outline","checkbox","Checkbox",__iconNode18);var __iconNode19=[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]],IconChevronDown=createReactComponent("outline","chevron-down","ChevronDown",__iconNode19);var __iconNode20=[["path",{d:"M9 6l6 6l-6 6",key:"svg-0"}]],IconChevronRight=createReactComponent("outline","chevron-right","ChevronRight",__iconNode20);var __iconNode21=[["path",{d:"M6 15l6 -6l6 6",key:"svg-0"}]],IconChevronUp=createReactComponent("outline","chevron-up","ChevronUp",__iconNode21);var __iconNode22=[["path",{d:"M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0",key:"svg-0"}],["path",{d:"M9 12l6 0",key:"svg-1"}]],IconCircleMinus=createReactComponent("outline","circle-minus","CircleMinus",__iconNode22);var __iconNode23=[["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"}]],IconCirclePlus=createReactComponent("outline","circle-plus","CirclePlus",__iconNode23);var __iconNode24=[["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"}]],IconCloudUpload=createReactComponent("outline","cloud-upload","CloudUpload",__iconNode24);var __iconNode25=[["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"}]],IconColumns=createReactComponent("outline","columns","Columns",__iconNode25);var __iconNode26=[["path",{d:"M7 9.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.667l0 -8.666",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"}]],IconCopy=createReactComponent("outline","copy","Copy",__iconNode26);var __iconNode27=[["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"}]],IconCurrencyDollar=createReactComponent("outline","currency-dollar","CurrencyDollar",__iconNode27);var __iconNode28=[["path",{d:"M4 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-0"}],["path",{d:"M11 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-1"}],["path",{d:"M18 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-2"}]],IconDots=createReactComponent("outline","dots","Dots",__iconNode28);var __iconNode29=[["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.415",key:"svg-1"}],["path",{d:"M16 5l3 3",key:"svg-2"}]],IconEdit=createReactComponent("outline","edit","Edit",__iconNode29);var __iconNode30=[["path",{d:"M9.5 5.5a2.5 2.5 0 1 0 5 0a2.5 2.5 0 1 0 -5 0",key:"svg-0"}],["path",{d:"M12 21.368l5.095 -5.096a3.088 3.088 0 1 0 -4.367 -4.367l-.728 .727l-.728 -.727a3.088 3.088 0 1 0 -4.367 4.367l5.095 5.096",key:"svg-1"}]],IconEmpathize=createReactComponent("outline","empathize","Empathize",__iconNode30);var __iconNode31=[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}],["path",{d:"M5 19l14 -14",key:"svg-2"}]],IconEqualNot=createReactComponent("outline","equal-not","EqualNot",__iconNode31);var __iconNode32=[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]],IconEqual=createReactComponent("outline","equal","Equal",__iconNode32);var __iconNode33=[["path",{d:"M10.585 10.587a2 2 0 0 0 2.829 2.828",key:"svg-0"}],["path",{d:"M16.681 16.673a8.717 8.717 0 0 1 -4.681 1.327c-3.6 0 -6.6 -2 -9 -6c1.272 -2.12 2.712 -3.678 4.32 -4.674m2.86 -1.146a9.055 9.055 0 0 1 1.82 -.18c3.6 0 6.6 2 9 6c-.666 1.11 -1.379 2.067 -2.138 2.87",key:"svg-1"}],["path",{d:"M3 3l18 18",key:"svg-2"}]],IconEyeOff=createReactComponent("outline","eye-off","EyeOff",__iconNode33);var __iconNode34=[["path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0",key:"svg-0"}],["path",{d:"M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6",key:"svg-1"}]],IconEye=createReactComponent("outline","eye","Eye",__iconNode34);var __iconNode35=[["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 2",key:"svg-1"}],["path",{d:"M12 17l.01 0",key:"svg-2"}],["path",{d:"M12 11l0 3",key:"svg-3"}]],IconFileAlert=createReactComponent("outline","file-alert","FileAlert",__iconNode35);var __iconNode36=[["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 2",key:"svg-1"}],["path",{d:"M12 11l0 6",key:"svg-2"}],["path",{d:"M9 14l6 0",key:"svg-3"}]],IconFilePlus=createReactComponent("outline","file-plus","FilePlus",__iconNode36);var __iconNode37=[["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.227",key:"svg-0"}]],IconFilter=createReactComponent("outline","filter","Filter",__iconNode37);var __iconNode38=[["path",{d:"M9 6.371c0 4.418 -2.239 6.629 -5 6.629",key:"svg-0"}],["path",{d:"M4 6.371h7",key:"svg-1"}],["path",{d:"M5 9c0 2.144 2.252 3.908 6 4",key:"svg-2"}],["path",{d:"M12 20l4 -9l4 9",key:"svg-3"}],["path",{d:"M19.1 18h-6.2",key:"svg-4"}],["path",{d:"M6.694 3l.793 .582",key:"svg-5"}]],IconLanguage=createReactComponent("outline","language","Language",__iconNode38);var __iconNode39=[["path",{d:"M4 6a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2l0 -12",key:"svg-0"}],["path",{d:"M9 4l0 16",key:"svg-1"}]],IconLayoutSidebar=createReactComponent("outline","layout-sidebar","LayoutSidebar",__iconNode39);var __iconNode40=[["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"}]],IconLogout=createReactComponent("outline","logout","Logout",__iconNode40);var __iconNode41=[["path",{d:"M9 11a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",key:"svg-0"}],["path",{d:"M17.657 16.657l-4.243 4.243a2 2 0 0 1 -2.827 0l-4.244 -4.243a8 8 0 1 1 11.314 0",key:"svg-1"}]],IconMapPin=createReactComponent("outline","map-pin","MapPin",__iconNode41);var __iconNode42=[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]],IconMathGreater=createReactComponent("outline","math-greater","MathGreater",__iconNode42);var __iconNode43=[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]],IconMathLower=createReactComponent("outline","math-lower","MathLower",__iconNode43);var __iconNode44=[["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 -3h12",key:"svg-2"}]],IconMessage=createReactComponent("outline","message","Message",__iconNode44);var __iconNode45=[["path",{d:"M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4",key:"svg-0"}],["path",{d:"M13.5 6.5l4 4",key:"svg-1"}]],IconPencil=createReactComponent("outline","pencil","Pencil",__iconNode45);var __iconNode46=[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]],IconPlus=createReactComponent("outline","plus","Plus",__iconNode46);var __iconNode47=[["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"}]],IconRefresh=createReactComponent("outline","refresh","Refresh",__iconNode47);var __iconNode48=[["path",{d:"M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M21 21l-6 -6",key:"svg-1"}]],IconSearch=createReactComponent("outline","search","Search",__iconNode48);var __iconNode49=[["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.065",key:"svg-0"}],["path",{d:"M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",key:"svg-1"}]],IconSettings=createReactComponent("outline","settings","Settings",__iconNode49);var __iconNode50=[["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"}]],IconSortAscending=createReactComponent("outline","sort-ascending","SortAscending",__iconNode50);var __iconNode51=[["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"}]],IconSortDescending=createReactComponent("outline","sort-descending","SortDescending",__iconNode51);var __iconNode52=[["path",{d:"M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14",key:"svg-0"}]],IconSquare=createReactComponent("outline","square","Square",__iconNode52);var __iconNode53=[["path",{d:"M6 4h-1a2 2 0 0 0 -2 2v3.5a5.5 5.5 0 0 0 11 0v-3.5a2 2 0 0 0 -2 -2h-1",key:"svg-0"}],["path",{d:"M8 15a6 6 0 1 0 12 0v-3",key:"svg-1"}],["path",{d:"M11 3v2",key:"svg-2"}],["path",{d:"M6 3v2",key:"svg-3"}],["path",{d:"M18 10a2 2 0 1 0 4 0a2 2 0 1 0 -4 0",key:"svg-4"}]],IconStethoscope=createReactComponent("outline","stethoscope","Stethoscope",__iconNode53);var __iconNode54=[["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"}]],IconSwitchHorizontal=createReactComponent("outline","switch-horizontal","SwitchHorizontal",__iconNode54);var __iconNode55=[["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"}]],IconTableExport=createReactComponent("outline","table-export","TableExport",__iconNode55);var __iconNode56=[["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"}]],IconTrash=createReactComponent("outline","trash","Trash",__iconNode56);var __iconNode57=[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]],IconX=createReactComponent("outline","x","X",__iconNode57);import{Component}from"react";import{jsx as jsx4}from"react/jsx-runtime";var ErrorBoundary=class extends Component{constructor(props){super(props);__publicField(this,"state");this.state={lastLocation:locationUtils.getLocation()}}static getDerivedStateFromError(error){return{error,lastLocation:locationUtils.getLocation()}}componentDidUpdate(_prevProps,_prevState){locationUtils.getLocation()!==this.state.lastLocation&&this.setState({lastLocation:locationUtils.getLocation(),error:void 0})}shouldComponentUpdate(nextProps,nextState){return!!(this.props.children!==nextProps.children||nextState.error&&!this.state.error||this.state.lastLocation!==locationUtils.getLocation())}componentDidCatch(error,errorInfo){console.error("Uncaught error:",error,errorInfo)}render(){return this.state.error?jsx4(Alert,{icon:jsx4(IconAlertCircle,{size:16}),title:"Something went wrong",color:"red",children:normalizeErrorString(this.state.error)}):this.props.children}};import{Center,Loader}from"@mantine/core";import{jsx as jsx5}from"react/jsx-runtime";function Loading(){return jsx5(Center,{style:{width:"100%",height:"100vh"},children:jsx5(Loader,{})})}var AppShell_default={main:"AppShell_main"};import{Group as Group5,AppShell as MantineAppShell,Menu as Menu2,Text as Text3,UnstyledButton}from"@mantine/core";import{formatHumanName as formatHumanName3}from"@medplum/core";import{useMedplumProfile as useMedplumProfile2}from"@medplum/react-hooks";import{useState as useState5}from"react";import{Avatar}from"@mantine/core";import{getDisplayString,getImageSrc}from"@medplum/core";import{useCachedBinaryUrl,useResource}from"@medplum/react-hooks";import{Anchor}from"@mantine/core";import{isReference,isResource}from"@medplum/core";import{useMedplumNavigate}from"@medplum/react-hooks";import{ContentType}from"@medplum/core";function killEvent(e){e.preventDefault(),e.stopPropagation()}function isAuxClick(e){return e.button===1||e.ctrlKey||e.metaKey}function isCheckboxCell(el){if(isCheckboxElement(el))return!0;if(el instanceof HTMLTableCellElement){let children=el.children;if(children.length===1&&isCheckboxElement(children[0]))return!0}return!1}function isCheckboxElement(el){return el instanceof HTMLInputElement&&el.type==="checkbox"}async function sendCommand(frame,command){return new Promise((resolve,reject)=>{let channel=new MessageChannel;channel.port1.onmessage=({data:data2})=>{channel.port1.close(),data2.error?reject(data2.error):resolve(data2.result)},frame.contentWindow?.postMessage(command,new URL(frame.src).origin,[channel.port2])})}function exportJsonFile(jsonString,fileName){let blobForExport=new Blob([jsonString],{type:ContentType.JSON}),url=URL.createObjectURL(blobForExport),link=document.createElement("a");link.href=url;let linkName=fileName??new Date().toISOString().replaceAll(/\D/g,"");link.download=`${linkName}.json`,document.body.appendChild(link),link.click(),URL.revokeObjectURL(url)}import{jsx as jsx6}from"react/jsx-runtime";function MedplumLink(props){let navigate=useMedplumNavigate(),{to,suffix,label,onClick,children,...rest}=props,href=getHref(to);return suffix&&(href+="/"+suffix),jsx6(Anchor,{href,"aria-label":label,onAuxClick:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation(),onClick?(e.preventDefault(),onClick(e)):to&&(isAuxClick(e)||(e.preventDefault(),navigate(href)))},...rest,children})}function getHref(to){if(to){if(typeof to=="string")return getStringHref(to);if(isResource(to))return getResourceHref(to);if(isReference(to))return getReferenceHref(to)}return"#"}function getStringHref(to){return to.startsWith("http://")||to.startsWith("https://")||to.startsWith("/")?to:"/"+to}function getResourceHref(to){return`/${to.resourceType}/${to.id}`}function getReferenceHref(to){return`/${to.reference}`}function getInitials(input){let words=input.split(" ").filter(Boolean);return words.length>1?words[0][0]+words.at(-1)?.at(0):words.length===1?words[0][0]:""}import{jsx as jsx7}from"react/jsx-runtime";function ResourceAvatar(props){let resource=useResource(props.value),text=resource?getDisplayString(resource):props.alt??"",initials=getInitials(text),uncachedImageUrl=(resource&&getImageSrc(resource))??props.src,imageUrl=useCachedBinaryUrl(uncachedImageUrl??void 0),radius=props.radius??"xl",avatarProps={...props,value:void 0,link:void 0};return props.link?jsx7(MedplumLink,{to:resource,children:jsx7(Avatar,{src:imageUrl,alt:text,radius,...avatarProps,children:initials})}):jsx7(Avatar,{src:imageUrl,alt:text,radius,...avatarProps,children:initials})}var Header_default={logoButton:"Header_logoButton",user:"Header_user",userName:"Header_userName"};import{Avatar as Avatar2,Group as Group2,Menu,SegmentedControl,Stack,Text,useMantineColorScheme}from"@mantine/core";import{getReferenceString,locationUtils as locationUtils2}from"@medplum/core";import{useMedplumContext}from"@medplum/react-hooks";import{useState as useState3}from"react";import{formatHumanName}from"@medplum/core";import{Fragment as Fragment2,jsx as jsx8}from"react/jsx-runtime";function HumanNameDisplay(props){let name=props.value;return name?jsx8(Fragment2,{children:formatHumanName(name,props.options)}):null}function getAppName(){return import.meta.env.MEDPLUM_APP_NAME||"Medplum"}import{Fragment as Fragment3,jsx as jsx9,jsxs as jsxs2}from"react/jsx-runtime";function HeaderDropdown(props){let context=useMedplumContext(),{medplum,profile,navigate}=context,logins=medplum.getLogins(),{colorScheme,setColorScheme}=useMantineColorScheme(),[layoutVersion]=useState3(localStorage.appShellLayoutVersion??"v1"),showLayoutToggle=props.showLayoutVersionToggle??!0;function setAppShellVersion(version){localStorage.appShellLayoutVersion=version,locationUtils2.reload()}return jsxs2(Fragment3,{children:[jsxs2(Stack,{align:"center",p:"xl",children:[jsx9(ResourceAvatar,{size:"xl",radius:100,value:context.profile}),jsx9(HumanNameDisplay,{value:context.profile?.name?.[0]}),jsx9(Text,{c:"dimmed",size:"xs",children:medplum.getActiveLogin()?.project.display})]}),logins.length>1&&jsx9(Menu.Divider,{}),logins.map(login=>login.profile.reference!==getReferenceString(context.profile)&&jsx9(Menu.Item,{onClick:()=>{medplum.setActiveLogin(login).then(()=>locationUtils2.reload()).catch(console.log)},children:jsxs2(Group2,{children:[jsx9(Avatar2,{radius:"xl"}),jsxs2("div",{style:{flex:1},children:[jsx9(Text,{size:"sm",fw:500,children:login.profile.display}),jsx9(Text,{c:"dimmed",size:"xs",children:login.project.display})]})]})},login.profile.reference)),jsx9(Menu.Divider,{}),jsx9(Menu.Item,{leftSection:jsx9(IconSwitchHorizontal,{size:14,stroke:1.5}),onClick:()=>navigate("/signin"),children:"Switch to another project"}),jsx9(Menu.Divider,{}),jsxs2(Group2,{justify:"center",children:[jsx9(SegmentedControl,{size:"xs",value:colorScheme,onChange:newValue=>setColorScheme(newValue),data:[{label:"Light",value:"light"},{label:"Dark",value:"dark"},{label:"Auto",value:"auto"}]}),showLayoutToggle&&jsx9(SegmentedControl,{size:"xs",value:layoutVersion,onChange:newValue=>setAppShellVersion(newValue),data:[{label:"v1",value:"v1"},{label:"v2",value:"v2"}]})]}),jsx9(Menu.Divider,{}),jsx9(Menu.Item,{leftSection:jsx9(IconSettings,{size:14,stroke:1.5}),onClick:()=>navigate(`/${getReferenceString(profile)}`),children:"Account settings"}),jsx9(Menu.Item,{leftSection:jsx9(IconLogout,{size:14,stroke:1.5}),onClick:async()=>{await medplum.signOut(),navigate("/signin")},children:"Sign out"}),jsxs2(Text,{size:"xs",c:"dimmed",my:"sm",ta:"center",children:[getAppName()," ",props.version]})]})}import{Group as Group4,Text as Text2}from"@mantine/core";import{formatHumanName as formatHumanName2,getDisplayString as getDisplayString2,getReferenceString as getReferenceString2,isUUID}from"@medplum/core";import{useMedplum,useMedplumNavigate as useMedplumNavigate2}from"@medplum/react-hooks";import{forwardRef as forwardRef2,useCallback as useCallback2}from"react";import{Combobox,Group as Group3,Loader as Loader2,Pill,PillsInput,ScrollAreaAutosize,useCombobox}from"@mantine/core";import{showNotification}from"@mantine/notifications";import{normalizeErrorString as normalizeErrorString2}from"@medplum/core";import{useCallback,useEffect,useMemo as useMemo2,useRef as useRef2,useState as useState4}from"react";var AsyncAutocompleteTestIds={selectedItems:"selected-items",options:"options"};import{jsx as jsx10,jsxs as jsxs3}from"react/jsx-runtime";function AsyncAutocomplete(props){let combobox=useCombobox({onDropdownClose:()=>combobox.resetSelectedOption(),onDropdownOpen:()=>combobox.updateSelectedOptionIndex("active")}),{name,label,description,error,defaultValue:defaultValue2,toOption:toOption4,loadOptions,itemComponent,pillComponent,emptyComponent,onChange,onCreate,creatable,clearable,required,placeholder,leftSection,maxValues,optionsDropdownMaxHeight=320,minInputLength=0,...rest}=props,disabled=rest.disabled,defaultItems=toDefaultItems(defaultValue2),[search,setSearch]=useState4(""),[timer,setTimer]=useState4(),[abortController,setAbortController]=useState4(),[autoSubmit,setAutoSubmit]=useState4(),[selected,setSelected]=useState4(defaultItems.map(toOption4)),[options,setOptions]=useState4([]),ItemComponent3=itemComponent??DefaultItemComponent,PillComponent=pillComponent??DefaultPillComponent,EmptyComponent=emptyComponent??DefaultEmptyComponent,searchRef=useRef2(search);searchRef.current=search;let lastLoadOptionsRef=useRef2(void 0),lastValueRef=useRef2(void 0),timerRef=useRef2(timer);timerRef.current=timer;let abortControllerRef=useRef2(abortController);abortControllerRef.current=abortController;let autoSubmitRef=useRef2(autoSubmit);autoSubmitRef.current=autoSubmit;let optionsRef=useRef2(options);optionsRef.current=options;let handleTimer=useCallback(()=>{if(setTimer(void 0),searchRef.current===lastValueRef.current&&loadOptions===lastLoadOptionsRef.current||(searchRef.current?.length??0)<minInputLength)return;lastValueRef.current=searchRef.current,lastLoadOptionsRef.current=loadOptions;let newAbortController=new AbortController;setAbortController(newAbortController),loadOptions(searchRef.current??"",newAbortController.signal).then(newValues=>{newAbortController.signal.aborted||(setOptions(newValues.map(toOption4)),autoSubmitRef.current?(newValues.length>0&&onChange(newValues.slice(0,1)),setAutoSubmit(!1)):newValues.length>0&&combobox.openDropdown())}).catch(err=>{newAbortController.signal.aborted||err.message.includes("aborted")||showNotification({color:"red",message:normalizeErrorString2(err)})}).finally(()=>{newAbortController.signal.aborted||setAbortController(void 0)})},[combobox,loadOptions,onChange,toOption4,minInputLength]),handleSearchChange=useCallback(e=>{(options&&options.length>0||creatable)&&combobox.openDropdown(),combobox.updateSelectedOptionIndex(),setSearch(e.currentTarget.value),abortControllerRef.current&&(abortControllerRef.current.abort(),setAbortController(void 0)),timerRef.current!==void 0&&window.clearTimeout(timerRef.current);let newTimer=window.setTimeout(()=>handleTimer(),100);setTimer(newTimer)},[combobox,options,creatable,handleTimer]),addSelected=useCallback(newValue=>{let alreadySelected=selected.some(v=>v.value===newValue),newSelected=alreadySelected?selected.filter(v=>v.value!==newValue):[...selected],option=options?.find(option2=>option2.value===newValue);if(!option&&creatable!==!1&&onCreate){let createdResource=onCreate(newValue);option=toOption4(createdResource)}if(option){if(maxValues===0){onChange([option.resource]),selected.length>0&&setSelected([]);return}alreadySelected||newSelected.push(option)}if(maxValues!==void 0)for(;newSelected.length>maxValues;)newSelected.shift();onChange(newSelected.map(v=>v.resource)),setSelected(newSelected)},[creatable,options,selected,maxValues,onChange,onCreate,toOption4]),handleValueSelect=useMemo2(()=>{if(!disabled)return val=>{disabled||(maxValues===1&&(setSearch(""),setOptions([]),combobox.closeDropdown()),lastValueRef.current=void 0,val==="$create"?(setSearch(""),addSelected(search)):addSelected(val))}},[addSelected,combobox,disabled,maxValues,search]),handleValueRemove=useCallback(item=>{let newSelected=selected.filter(v=>v.value!==item.value);onChange(newSelected.map(v=>v.resource)),setSelected(newSelected)},[selected,onChange]),handleKeyDown=useCallback(e=>{e.key==="Enter"?(timer||abortController)&&setAutoSubmit(!0):e.key==="Backspace"&&search.length===0&&(killEvent(e),handleValueRemove(selected[selected.length-1]))},[abortController,handleValueRemove,search.length,selected,timer]);useEffect(()=>()=>{abortControllerRef.current&&abortControllerRef.current.abort()},[]);let clearButton=!disabled&&clearable&&selected.length>0&&jsx10(Combobox.ClearButton,{title:"Clear all",size:"sm",onClear:()=>{setSearch(""),setSelected([]),onChange([]),combobox.closeDropdown()}}),createVisible=creatable&&search.trim().length>0,comboboxVisible=options.length>0||createVisible;return jsxs3(Combobox,{store:combobox,onOptionSubmit:handleValueSelect,withinPortal:!0,shadow:"xl",...rest,children:[jsx10(Combobox.DropdownTarget,{children:jsx10(PillsInput,{label,description,error,className:props.className,leftSection,rightSection:abortController?jsx10(Loader2,{size:16}):clearButton,required,disabled,children:jsxs3(Pill.Group,{"data-testid":AsyncAutocompleteTestIds.selectedItems,children:[selected.map(item=>jsx10(PillComponent,{item,disabled,onRemove:()=>handleValueRemove(item)},item.value)),!disabled&&(maxValues===void 0||maxValues===0||selected.length<maxValues)&&jsx10(Combobox.EventsTarget,{children:jsx10(PillsInput.Field,{role:"searchbox",name,value:search,placeholder,onFocus:handleSearchChange,onBlur:()=>{combobox.closeDropdown(),setSearch("")},onKeyDown:handleKeyDown,onChange:handleSearchChange})})]})})}),jsx10(Combobox.Dropdown,{hidden:!comboboxVisible,"data-testid":AsyncAutocompleteTestIds.options,children:jsx10(Combobox.Options,{children:jsxs3(ScrollAreaAutosize,{type:"scroll",mah:optionsDropdownMaxHeight,children:[options.map(item=>{let active=selected.some(v=>v.value===item.value);return jsx10(Combobox.Option,{value:item.value,active,children:jsx10(ItemComponent3,{...item,active})},item.value)}),createVisible&&jsxs3(Combobox.Option,{value:"$create",children:["+ Create ",search]}),!creatable&&search.trim().length>0&&options.length===0&&jsx10(EmptyComponent,{search})]})})})]})}function toDefaultItems(defaultValue2){return defaultValue2?Array.isArray(defaultValue2)?defaultValue2:[defaultValue2]:[]}function DefaultItemComponent(props){return jsxs3(Group3,{gap:"xs",children:[props.active&&jsx10(IconCheck,{size:12}),jsx10("span",{children:props.label})]})}function DefaultPillComponent({item,disabled,onRemove}){return jsx10(Pill,{withRemoveButton:!disabled,onRemove,children:item.label})}function DefaultEmptyComponent(){return jsx10(Combobox.Empty,{children:"Nothing found"})}var HeaderSearchInput_default={searchInput:"HeaderSearchInput_searchInput"};import{jsx as jsx11,jsxs as jsxs4}from"react/jsx-runtime";function toOption(resource){return{value:resource.id,label:getDisplayString2(resource),resource}}function HeaderSearchInput(props){let navigate=useMedplumNavigate2(),medplum=useMedplum(),loadData=useCallback2(async(input,signal)=>{let query=buildGraphQLQuery(input),options={signal},response=await medplum.graphql(query,void 0,void 0,options);return getResourcesFromResponse(response,input)},[medplum]),handleSelect=useCallback2(item=>{item.length>0&&navigate(`/${getReferenceString2(item[0])}`)},[navigate]);return jsx11(AsyncAutocomplete,{size:"sm",radius:"md",className:HeaderSearchInput_default.searchInput,leftSection:jsx11(IconSearch,{size:16}),placeholder:"Search",itemComponent:ItemComponent,toOption,onChange:handleSelect,loadOptions:loadData,maxValues:0,clearable:!1},`${props.pathname}?${props.searchParams}`)}var ItemComponent=forwardRef2(({resource,active:_active,...others},ref)=>{let helpText;return resource.resourceType==="Patient"?helpText=resource.birthDate:resource.resourceType==="ServiceRequest"&&(helpText=resource.subject?.display),jsx11("div",{ref,...others,children:jsxs4(Group4,{wrap:"nowrap",children:[jsx11(ResourceAvatar,{value:resource}),jsxs4("div",{children:[jsx11(Text2,{children:getDisplayString2(resource)}),jsx11(Text2,{size:"xs",c:"dimmed",children:helpText})]})]})})});function buildGraphQLQuery(input){let escaped=JSON.stringify(input);return isUUID(input)?`{
2
2
  Patients1: PatientList(_id: ${escaped}, _count: 1) {
3
3
  resourceType
4
4
  id
@@ -99,7 +99,7 @@ var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropD
99
99
  identifier { system value }
100
100
  subject { display }
101
101
  }
102
- }`.replaceAll(/\s+/g," ")}function getResourcesFromResponse2(response){let resources=[];return response.data.Patients1&&resources.push(...response.data.Patients1),response.data.Patients2&&resources.push(...response.data.Patients2),response.data.ServiceRequestList&&resources.push(...response.data.ServiceRequestList),dedupeResources2(resources)}function dedupeResources2(resources){let ids=new Set,result=[];for(let resource of resources)resource.id&&!ids.has(resource.id)&&(ids.add(resource.id),result.push(resource));return result}function patientsToActions(patients,navigate){let patientActions=patients.filter(p=>!!p.id).map(patient=>({id:patient.id,label:patient.name?formatHumanName4(patient.name[0]):patient.id,description:patient.birthDate,leftSection:jsx19(ResourceAvatar,{value:patient,radius:"xl",size:24}),onClick:()=>navigate(`/Patient/${patient.id}`)}));return patientActions.length>0?[{group:"Patients",actions:patientActions}]:[]}function resourcesToActions(resources,resourceTypes,navigate){let result=[],resourceTypeActions=resourceTypes.map(rt=>({id:`resource-type-${rt.code}`,label:rt.display??rt.code??"",description:"Resource Type",onClick:()=>navigate(`/${rt.code}`)}));resourceTypeActions.length>0&&result.push({group:"Resource Types",actions:resourceTypeActions});let patientActions=[],serviceRequestActions=[];for(let resource of resources)resource.resourceType==="Patient"&&resource.id?patientActions.push({id:resource.id,label:resource.name?formatHumanName4(resource.name[0]):resource.id,description:resource.birthDate,leftSection:jsx19(ResourceAvatar,{value:resource,radius:"xl",size:24}),onClick:()=>navigate(`/Patient/${resource.id}`)}):resource.resourceType==="ServiceRequest"&&resource.id&&serviceRequestActions.push({id:resource.id,label:resource.id,description:resource.subject?.display,onClick:()=>navigate(`/ServiceRequest/${resource.id}`)});return patientActions.length>0&&result.push({group:"Patients",actions:patientActions}),serviceRequestActions.length>0&&result.push({group:"Service Requests",actions:serviceRequestActions}),result}import{Fragment as Fragment5,jsx as jsx20,jsxs as jsxs9}from"react/jsx-runtime";function Navbar(props){let navigate=useMedplumNavigate4(),profile=useMedplumProfile3(),activeLink=getActiveLink(props.pathname,props.searchParams,props.menus),[userMenuOpened,setUserMenuOpened]=useState10(!1),[bookmarkDialogVisible,setBookmarkDialogVisible]=useState10(!1);function onLinkClick2(e,to){e.stopPropagation(),e.preventDefault(),navigate(to),window.innerWidth<768&&props.closeNavbar()}function navigateResourceType(resourceType){resourceType&&navigate(`/${resourceType}`)}let opened=props.opened??!0;return jsxs9(Fragment5,{children:[jsxs9(MantineAppShell2.Navbar,{id:"navbar",className:Navbar_default.navbar,children:[props.logo&&jsx20(MantineAppShell2.Section,{px:"xs",pt:"xs",pb:"4px",children:jsx20(UnstyledButton2,{className:Navbar_default.logoButton,onClick:props.navbarToggle,"aria-expanded":opened,"aria-controls":"navbar",children:props.logo})}),jsx20(ScrollArea,{px:"xs",pb:"xs",pt:"sm",h:"100%",children:jsxs9(MantineAppShell2.Section,{grow:!0,children:[props.spotlightEnabled&&jsx20(Box,{mb:2,children:jsx20(Tooltip,{label:"Search",position:"right",transitionProps:{duration:0},disabled:opened,children:jsxs9(UnstyledButton2,{className:Navbar_default.link,onClick:()=>spotlight.open(),children:[jsx20(IconSearch,{size:"1.2rem"}),jsx20("span",{className:Navbar_default.linkLabel,"data-opened":opened||void 0,children:"Search"})]})})}),props.spotlightEnabled&&jsx20(Spotlight,{patientsOnly:props.patientsOnly}),!props.resourceTypeSearchDisabled&&jsx20(MantineAppShell2.Section,{mb:"sm",children:jsx20(ResourceTypeInput,{name:"resourceType",placeholder:"Resource Type",maxValues:0,onChange:newValue=>navigateResourceType(newValue)},window.location.pathname)}),props.menus?.map((menu,index)=>jsxs9(Fragment4,{children:[menu.title&&jsx20(Text6,{className:Navbar_default.menuTitle,"data-opened":opened||void 0,children:menu.title}),jsx20(Stack4,{gap:"2",children:menu.links?.map(link=>jsx20(NavbarLink,{to:link.href,active:link.href===activeLink?.href,onClick:e=>onLinkClick2(e,link.href),icon:link.icon,label:link.label??"",opened},link.href))})]},`menu-${menu.title??index}`)),props.displayAddBookmark&&jsx20(Tooltip,{label:"Add Bookmark",position:"right",transitionProps:{duration:0},disabled:opened,children:jsxs9(UnstyledButton2,{className:`${Navbar_default.link} ${Navbar_default.addBookmarkLink}`,onClick:()=>setBookmarkDialogVisible(!0),children:[jsx20(IconCirclePlus,{}),jsx20("span",{className:Navbar_default.linkLabel,"data-opened":opened||void 0,children:"Add Bookmark"})]})})]})}),props.userMenuEnabled&&jsxs9(MantineAppShell2.Section,{px:"xs",py:"xs",children:[jsx20(Tooltip,{label:opened?"Close Sidebar":"Open Sidebar",position:"right",transitionProps:{duration:0},children:jsx20(UnstyledButton2,{className:Navbar_default.toggleButton,"aria-label":opened?"Close Sidebar":"Open Sidebar",onClick:props.navbarToggle,"aria-expanded":opened,"aria-controls":"navbar",children:jsx20(IconLayoutSidebar,{})})}),jsx20(Divider,{my:"xs",mx:6,className:Navbar_default.divider}),jsxs9(Menu3,{width:260,shadow:"xl",position:"top-start",transitionProps:{transition:"fade-up"},opened:userMenuOpened,onClose:()=>setUserMenuOpened(!1),children:[jsx20(Menu3.Target,{children:jsxs9(UnstyledButton2,{className:Navbar_default.link,pl:"7","aria-label":"User menu","data-active":userMenuOpened||void 0,onClick:()=>setUserMenuOpened(o=>!o),bd:"1px 0 0 0 solid var(--mantine-color-gray-200)",children:[jsx20(ResourceAvatar,{value:profile,radius:"xl",size:24}),jsx20("span",{className:Navbar_default.linkLabel,"data-opened":opened||void 0,children:formatHumanName5(profile?.name?.[0])})]})}),jsx20(Menu3.Dropdown,{children:jsx20(HeaderDropdown,{version:props.version})})]})]})]}),props.pathname&&props.searchParams&&jsx20(BookmarkDialog,{pathname:props.pathname,searchParams:props.searchParams,visible:bookmarkDialogVisible,onOk:()=>setBookmarkDialogVisible(!1),onCancel:()=>setBookmarkDialogVisible(!1)})]})}function NavbarLink(props){let{to,icon,label,onClick,active}=props;return jsx20(Tooltip,{label,position:"right",transitionProps:{duration:0},disabled:props.opened,children:jsxs9(MedplumLink,{to,onClick,className:Navbar_default.link,"data-active":active||void 0,children:[icon??jsx20(IconBookmark,{}),jsx20("span",{className:Navbar_default.linkLabel,"data-opened":props.opened||void 0,children:label})]})})}function getActiveLink(currentPathname,currentSearchParams,menus){if(!currentPathname||!currentSearchParams||!menus)return;let bestLink,bestScore=0;for(let menu of menus)if(menu.links)for(let link of menu.links){let score=getLinkScore(currentPathname,currentSearchParams,link.href);score>bestScore&&(bestScore=score,bestLink=link)}return bestLink}function getLinkScore(currentPathname,currentSearchParams,linkHref){let linkUrl=new URL(linkHref,"https://example.com");if(currentPathname!==linkUrl.pathname)return 0;let ignoredParams=["_count","_offset"];for(let[key,value]of linkUrl.searchParams.entries())if(!ignoredParams.includes(key)&&currentSearchParams.get(key)!==value)return 0;let count=1;for(let[key,value]of currentSearchParams.entries())ignoredParams.includes(key)||linkUrl.searchParams.get(key)===value&&count++;return count}import{jsx as jsx21,jsxs as jsxs10}from"react/jsx-runtime";var OPEN_WIDTH=250,CLOSED_WIDTH=59;function AppShell(props){let[navbarOpen,setNavbarOpen]=useState11(localStorage.navbarOpen==="true"),[layoutVersion]=useState11(props.layoutVersion??localStorage.appShellLayoutVersion??"v1"),medplum=useMedplum5(),profile=useMedplumProfile4();function setNavbarOpenWrapper(open){localStorage.navbarOpen=open.toString(),setNavbarOpen(open)}function closeNavbar(){setNavbarOpenWrapper(!1)}function toggleNavbar(){setNavbarOpenWrapper(!navbarOpen)}if(medplum.isLoading())return jsx21(Loading,{});let headerProp,navbarProp,headerComponent,navbarComponent;return layoutVersion==="v2"?(headerProp={height:0},navbarProp={width:navbarOpen?OPEN_WIDTH:CLOSED_WIDTH,breakpoint:0,collapsed:{desktop:!profile,mobile:!profile}},headerComponent=void 0,navbarComponent=profile?jsx21(Navbar,{logo:props.logo,pathname:props.pathname,searchParams:props.searchParams,menus:props.menus,navbarToggle:toggleNavbar,closeNavbar,displayAddBookmark:props.displayAddBookmark,resourceTypeSearchDisabled:!0,opened:navbarOpen,spotlightEnabled:!0,patientsOnly:props.spotlightPatientsOnly,userMenuEnabled:!0,version:props.version}):void 0):(headerProp={height:60},navbarProp={width:OPEN_WIDTH,breakpoint:"sm",collapsed:{desktop:!profile||!navbarOpen,mobile:!profile||!navbarOpen}},headerComponent=profile&&jsx21(Header,{pathname:props.pathname,searchParams:props.searchParams,headerSearchDisabled:props.headerSearchDisabled,logo:props.logo,version:props.version,navbarOpen,navbarToggle:toggleNavbar,notifications:props.notifications}),navbarComponent=profile&&navbarOpen?jsx21(Navbar,{pathname:props.pathname,searchParams:props.searchParams,menus:props.menus,navbarToggle:toggleNavbar,closeNavbar,displayAddBookmark:props.displayAddBookmark,resourceTypeSearchDisabled:props.resourceTypeSearchDisabled,patientsOnly:props.spotlightPatientsOnly}):void 0),jsxs10(MantineAppShell3,{header:headerProp,navbar:navbarProp,padding:0,children:[headerComponent,navbarComponent,jsx21(MantineAppShell3.Main,{className:AppShell_default.main,children:jsx21(ErrorBoundary,{children:jsx21(Suspense,{fallback:jsx21(Loading,{}),children:props.children})})})]})}import{getPathDisplayName,isPopulated as isPopulated2}from"@medplum/core";import{Anchor as Anchor2}from"@mantine/core";import{ContentType as ContentType2}from"@medplum/core";import{useCachedBinaryUrl as useCachedBinaryUrl2}from"@medplum/react-hooks";import{Button as Button2}from"@mantine/core";import{useEffect as useEffect2,useRef as useRef3,useState as useState12}from"react";import{Fragment as Fragment6,jsx as jsx22,jsxs as jsxs11}from"react/jsx-runtime";var CCDA_VIEWER_URL="https://ccda.medplum.com",BASE_VALIDATION_URL="https://ccda-validator.medplum.com/";function CcdaDisplay(props){let{url}=props,[shouldSend,setShouldSend]=useState12(!1),iframeRef=useRef3(null),[validationResult,setValidationResult]=useState12(),[validating,setValidating]=useState12(!1);useEffect2(()=>{url&&shouldSend&&iframeRef.current&&(sendCommand(iframeRef.current,{command:"loadCcdaXml",value:url}).catch(console.error),setShouldSend(!1))},[url,shouldSend]);let validateCcda=async()=>{if(url)try{setValidating(!0);let ccdaContent=await(await fetch(url)).text(),formData=new FormData;formData.append("ccdaFile",new Blob([ccdaContent],{type:"text/xml"}),"ccda.xml");let validationUrl=`${BASE_VALIDATION_URL}referenceccdaservice/?validationObjective=C-CDA_IG_Plus_Vocab&referenceFileName=No%20scenario%20File&curesUpdate=true&severityLevel=WARNING`,validationResponse=await fetch(validationUrl,{method:"POST",body:formData,credentials:"omit",redirect:"manual"});if(!validationResponse.ok)throw new Error(`Validation failed: ${validationResponse.status} ${validationResponse.statusText}`);let validationResult2=await validationResponse.json();setValidationResult(validationResult2)}catch(error){setValidationResult(void 0),console.error("CCDA validation error:",error)}finally{setValidating(!1)}},downloadResults=()=>{if(!validationResult)return;let resultsJson=JSON.stringify(validationResult,null,2);exportJsonFile(resultsJson,"ccda-validation-results")},getErrorCount=()=>validationResult?validationResult.resultsMetaData.resultMetaData.filter(item=>item?.type.includes("Error")).reduce((sum,item)=>sum+(item.count||0),0):0;return url?jsxs11("div",{"data-testid":"ccda-iframe",style:{maxWidth:props.maxWidth},children:[jsx22("div",{style:{minHeight:400},children:jsx22("iframe",{title:"C-CDA Viewer",width:"100%",height:"400",ref:iframeRef,src:CCDA_VIEWER_URL,allowFullScreen:!0,frameBorder:0,seamless:!0,onLoad:()=>setShouldSend(!0)})}),jsxs11("div",{style:{marginTop:"10px",marginBottom:"10px",display:"flex",alignItems:"center"},children:[jsx22(Button2,{type:"button",onClick:validateCcda,disabled:validating,children:validating?"Validating...":"Validate"}),validationResult&&jsxs11(Fragment6,{children:[jsxs11("div",{style:{marginLeft:"15px"},children:[jsx22("strong",{children:"Validation Results:"})," ",getErrorCount()," errors found"]}),jsx22(Button2,{type:"button",onClick:downloadResults,color:"green",style:{marginLeft:"auto"},children:"Download Full Results"})]})]})]}):null}import{jsx as jsx23,jsxs as jsxs12}from"react/jsx-runtime";function AttachmentDisplay(props){let{contentType,url:uncachedUrl,title}=props.value??{},url=useCachedBinaryUrl2(uncachedUrl);return url?jsxs12("div",{"data-testid":"attachment-display",children:[contentType?.startsWith("image/")&&jsx23("img",{"data-testid":"attachment-image",style:{maxWidth:props.maxWidth},src:url,alt:title}),contentType?.startsWith("video/")&&jsx23("video",{"data-testid":"attachment-video",style:{maxWidth:props.maxWidth},controls:!0,children:jsx23("source",{type:contentType,src:url})}),(contentType?.startsWith("text/")||contentType==="application/json"||contentType==="application/pdf")&&jsx23("div",{"data-testid":"attachment-iframe",style:{maxWidth:props.maxWidth,minHeight:400},children:jsx23("iframe",{title:"Attachment",width:"100%",height:"400",src:url+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),contentType===ContentType2.CDA_XML&&jsx23(CcdaDisplay,{url}),jsx23("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:jsx23(Anchor2,{href:uncachedUrl,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:getDownloadName(title),children:title||"Download"})})]}):null}function getDownloadName(title){return title?.includes(".")?title:void 0}function r(e){var t,f,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f)}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}var clsx_default=clsx;var DescriptionList_default={root:"DescriptionList_root",compact:"DescriptionList_compact"};import{Fragment as Fragment7,jsx as jsx24,jsxs as jsxs13}from"react/jsx-runtime";function DescriptionList(props){let{children,compact}=props;return jsx24("dl",{className:clsx_default(DescriptionList_default.root,{[DescriptionList_default.compact]:compact}),children})}function DescriptionListEntry(props){return jsxs13(Fragment7,{children:[jsx24("dt",{children:props.term}),jsx24("dd",{children:props.children})]})}import{Fragment as Fragment8,jsx as jsx25}from"react/jsx-runtime";function AttachmentArrayDisplay(props){let attachmentElements=props.values?.map((v,index)=>jsx25("div",{children:jsx25(AttachmentDisplay,{value:v,maxWidth:props.maxWidth})},"attatchment-"+index)),content;if(props.includeDescriptionListEntry){if(props.property===void 0)throw new Error("props.property is required when includeDescriptionListEntry is true");if(!isPopulated2(props.path))throw new Error("props.path is required when includeDescriptionListEntry is true");let key=props.path.split(".").pop();content=jsx25(DescriptionListEntry,{term:getPathDisplayName(key),children:attachmentElements})}else content=jsx25(Fragment8,{children:attachmentElements});return content}import{ActionIcon}from"@mantine/core";import{useRef as useRef5,useState as useState13}from"react";import{normalizeOperationOutcome}from"@medplum/core";import{useMedplum as useMedplum6}from"@medplum/react-hooks";import{useRef as useRef4}from"react";import{Fragment as Fragment9,jsx as jsx26,jsxs as jsxs14}from"react/jsx-runtime";function AttachmentButton(props){let medplum=useMedplum6(),fileInputRef=useRef4(null);function onClick(e){killEvent(e),fileInputRef.current?.click()}function onFileChange(e){killEvent(e);let files=e.target.files;files&&Array.from(files).forEach(processFile)}function processFile(file){!file||!file.name||(props.onUploadStart&&props.onUploadStart(),medplum.createAttachment({data:file,contentType:file.type||"application/octet-stream",filename:file.name,securityContext:props.securityContext,onProgress:props.onUploadProgress}).then(attachment=>props.onUpload(attachment)).catch(err=>{props.onUploadError&&props.onUploadError(normalizeOperationOutcome(err))}))}return jsxs14(Fragment9,{children:[jsx26("input",{disabled:props.disabled,type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:fileInputRef,onChange:e=>onFileChange(e)}),props.children({onClick,disabled:props.disabled})]})}import{jsx as jsx27,jsxs as jsxs15}from"react/jsx-runtime";function AttachmentArrayInput(props){let[values,setValues]=useState13(props.defaultValue??[]),valuesRef=useRef5(values);valuesRef.current=values;function setValuesWrapper(newValues){setValues(newValues),props.onChange&&props.onChange(newValues)}return jsxs15("table",{style:{width:"100%"},children:[jsxs15("colgroup",{children:[jsx27("col",{width:"97%"}),jsx27("col",{width:"3%"})]}),jsxs15("tbody",{children:[values.map((v,index)=>jsxs15("tr",{children:[jsx27("td",{children:jsx27(AttachmentDisplay,{value:v,maxWidth:200})}),jsx27("td",{children:jsx27(ActionIcon,{disabled:props.disabled,title:"Remove",variant:"subtle",size:"sm",color:"gray",onClick:e=>{killEvent(e);let copy=values.slice();copy.splice(index,1),setValuesWrapper(copy)},children:jsx27(IconCircleMinus,{})})})]},`${index}-${values.length}`)),jsxs15("tr",{children:[jsx27("td",{}),jsx27("td",{children:jsx27(AttachmentButton,{disabled:props.disabled,onUpload:attachment=>{setValuesWrapper([...valuesRef.current,attachment])},children:props2=>jsx27(ActionIcon,{...props2,title:"Add",variant:"subtle",size:"sm",color:props2.disabled?"gray":"green",children:jsx27(IconCloudUpload,{})})})})]})]})]})}import{Button as Button3}from"@mantine/core";import{useState as useState14}from"react";import{Fragment as Fragment10,jsx as jsx28,jsxs as jsxs16}from"react/jsx-runtime";function AttachmentInput(props){let[value,setValue]=useState14(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return value?jsxs16(Fragment10,{children:[jsx28(AttachmentDisplay,{value,maxWidth:200}),jsx28(Button3,{disabled:props.disabled,onClick:e=>{killEvent(e),setValueWrapper(void 0)},children:"Remove"})]}):jsx28(AttachmentButton,{disabled:props.disabled,securityContext:props.securityContext,onUpload:setValueWrapper,children:props2=>jsx28(Button3,{...props2,children:"Upload..."})})}import{Alert as Alert2,Center as Center2,Image as Image2,Stack as Stack5,Text as Text7,TextInput as TextInput4,Title}from"@mantine/core";import{normalizeErrorString as normalizeErrorString4}from"@medplum/core";import{useState as useState15}from"react";import{jsx as jsx29,jsxs as jsxs17}from"react/jsx-runtime";function Logo(props){let overrideUrl=import.meta.env.MEDPLUM_LOGO_URL;return overrideUrl?jsx29("img",{src:overrideUrl,alt:"Logo",style:{maxHeight:props.size}}):jsxs17("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 180 180",style:{width:props.size,height:props.size},children:[jsx29("title",{children:"Medplum Logo"}),jsx29("path",{fill:props.fill??"#9c36b5",d:"M84 56c-3-15-15-24-23-28l5-10c8 2 14 8 20 14 0-12 1-16 5-21 8-9 13-9 41-9 0 7 1 18-3 24-7 9-16 7-41 8 5 8 7 14 8 22 36-24 74-7 74 39 0 42-40 83-80 83s-80-41-80-83c0-46 38-63 74-39Zm-3 43H65c-4 0-7 3-7 7v4c0 4 3 7 7 7h16v16c0 4 3 7 7 7h4c4 0 7-3 7-7v-16h16c4 0 7-3 7-7v-4c0-4-3-7-7-7H99V83c0-4-3-7-7-7h-4c-4 0-7 3-7 7z"})]})}import{jsx as jsx30,jsxs as jsxs18}from"react/jsx-runtime";function MfaForm(props){let[errorMessage,setErrorMessage]=useState15();return jsxs18(Form,{onSubmit:formData=>{setErrorMessage(void 0),props.onSubmit(formData)?.catch(err=>setErrorMessage(normalizeErrorString4(err)))},children:[jsxs18(Center2,{style:{flexDirection:"column"},children:[jsx30(Logo,{size:32}),jsx30(Title,{order:3,py:"lg",children:props.title}),!props.qrCodeUrl&&props.description&&jsx30(Text7,{c:"dimmed",mb:"lg",mt:"-lg",children:props.description})]}),errorMessage&&jsx30(Alert2,{icon:jsx30(IconAlertCircle,{size:16}),title:"Error",color:"red",mb:"lg",children:errorMessage}),props.qrCodeUrl&&jsx30(Center2,{children:jsxs18(Stack5,{mb:"xl",children:[props.description&&jsx30(Text7,{c:"dimmed",mb:"md",mt:"-lg",ta:"center",children:props.description}),jsx30(Image2,{src:props.qrCodeUrl,alt:"Multi Factor Auth QR Code",w:"60%",mx:"auto",radius:"md",p:"xs",bg:"var(--mantine-color-white)",style:{border:"1px solid light-dark(var(--mantine-color-gray-2), var(--mantine-color-dark-4))"}})]})}),jsx30(Stack5,{gap:"sm",children:jsx30(TextInput4,{name:"token",label:"MFA code",autoComplete:"one-time-code",required:!0,autoFocus:!0})}),jsx30(Stack5,{gap:"xs",pt:"md",children:jsx30(SubmitButton,{fullWidth:!0,children:props.buttonText})})]})}import{normalizeOperationOutcome as normalizeOperationOutcome4}from"@medplum/core";import{useMedplum as useMedplum9}from"@medplum/react-hooks";import{useEffect as useEffect5,useState as useState19}from"react";import{Container as MantineContainer}from"@mantine/core";var Container_default={root:"Container_root"};import{jsx as jsx31}from"react/jsx-runtime";function Container(props){let{children,...others}=props;return jsx31(MantineContainer,{className:Container_default.root,...others,children})}import{Paper}from"@mantine/core";var Panel_default={paper:"Panel_paper",fill:"Panel_fill"};import{jsx as jsx32}from"react/jsx-runtime";function Panel(props){let{width,fill,className,children,...rest}=props,style=width?{maxWidth:width}:void 0;return jsx32(Paper,{className:clsx_default(Panel_default.paper,fill&&Panel_default.fill,className),style,shadow:"sm",radius:"sm",withBorder:!0,...rest,children})}import{jsx as jsx33}from"react/jsx-runtime";function Document(props){let{children,...others}=props;return jsx33(Container,{children:jsx33(Panel,{...others,children})})}import{Alert as Alert3}from"@mantine/core";import{operationOutcomeIssueToString}from"@medplum/core";import{jsx as jsx34}from"react/jsx-runtime";function OperationOutcomeAlert(props){let{outcome,issues:issuesProp,...spacingProps}=props,issues=outcome?.issue||issuesProp;return!issues||issues.length===0?null:jsx34(Alert3,{icon:jsx34(IconAlertCircle,{size:16}),color:"red",...spacingProps,children:issues.map(issue=>jsx34("div",{"data-testid":"text-field-error",children:operationOutcomeIssueToString(issue)},issue.details?.text))})}function getErrorsForInput(outcome,expression){return outcome?.issue?.filter(issue=>isExpressionMatch(issue.expression?.[0],expression))?.map(issue=>issue.details?.text)?.join(`
102
+ }`.replaceAll(/\s+/g," ")}function getResourcesFromResponse2(response){let resources=[];return response.data.Patients1&&resources.push(...response.data.Patients1),response.data.Patients2&&resources.push(...response.data.Patients2),response.data.ServiceRequestList&&resources.push(...response.data.ServiceRequestList),dedupeResources2(resources)}function dedupeResources2(resources){let ids=new Set,result=[];for(let resource of resources)resource.id&&!ids.has(resource.id)&&(ids.add(resource.id),result.push(resource));return result}function patientsToActions(patients,navigate){let patientActions=patients.filter(p=>!!p.id).map(patient=>({id:patient.id,label:patient.name?formatHumanName4(patient.name[0]):patient.id,description:patient.birthDate,leftSection:jsx19(ResourceAvatar,{value:patient,radius:"xl",size:24}),onClick:()=>navigate(`/Patient/${patient.id}`)}));return patientActions.length>0?[{group:"Patients",actions:patientActions}]:[]}function resourcesToActions(resources,resourceTypes,navigate){let result=[],resourceTypeActions=resourceTypes.map(rt=>({id:`resource-type-${rt.code}`,label:rt.display??rt.code??"",description:"Resource Type",onClick:()=>navigate(`/${rt.code}`)}));resourceTypeActions.length>0&&result.push({group:"Resource Types",actions:resourceTypeActions});let patientActions=[],serviceRequestActions=[];for(let resource of resources)resource.resourceType==="Patient"&&resource.id?patientActions.push({id:resource.id,label:resource.name?formatHumanName4(resource.name[0]):resource.id,description:resource.birthDate,leftSection:jsx19(ResourceAvatar,{value:resource,radius:"xl",size:24}),onClick:()=>navigate(`/Patient/${resource.id}`)}):resource.resourceType==="ServiceRequest"&&resource.id&&serviceRequestActions.push({id:resource.id,label:resource.id,description:resource.subject?.display,onClick:()=>navigate(`/ServiceRequest/${resource.id}`)});return patientActions.length>0&&result.push({group:"Patients",actions:patientActions}),serviceRequestActions.length>0&&result.push({group:"Service Requests",actions:serviceRequestActions}),result}import{Fragment as Fragment5,jsx as jsx20,jsxs as jsxs9}from"react/jsx-runtime";function Navbar(props){let navigate=useMedplumNavigate4(),profile=useMedplumProfile3(),activeLink=getActiveLink(props.pathname,props.searchParams,props.menus),[userMenuOpened,setUserMenuOpened]=useState10(!1),[bookmarkDialogVisible,setBookmarkDialogVisible]=useState10(!1);function onLinkClick2(e,to){e.stopPropagation(),e.preventDefault(),navigate(to),window.innerWidth<768&&props.closeNavbar()}function navigateResourceType(resourceType){resourceType&&navigate(`/${resourceType}`)}let opened=props.opened??!0;return jsxs9(Fragment5,{children:[jsxs9(MantineAppShell2.Navbar,{id:"navbar",className:Navbar_default.navbar,children:[props.logo&&jsx20(MantineAppShell2.Section,{px:"xs",pt:"xs",pb:"4px",children:jsx20(UnstyledButton2,{className:Navbar_default.logoButton,onClick:props.navbarToggle,"aria-expanded":opened,"aria-controls":"navbar","aria-label":"Medplum Logo",children:props.logo})}),jsx20(ScrollArea,{px:"xs",pb:"xs",pt:"sm",h:"100%",children:jsxs9(MantineAppShell2.Section,{grow:!0,children:[props.spotlightEnabled&&jsx20(Box,{mb:2,children:jsx20(Tooltip,{label:"Search",position:"right",transitionProps:{duration:0},disabled:opened,children:jsxs9(UnstyledButton2,{className:Navbar_default.link,onClick:()=>spotlight.open(),"aria-label":"Search",children:[jsx20(IconSearch,{size:"1.2rem"}),jsx20("span",{className:Navbar_default.linkLabel,"data-opened":opened||void 0,children:"Search"})]})})}),props.spotlightEnabled&&jsx20(Spotlight,{patientsOnly:props.patientsOnly}),!props.resourceTypeSearchDisabled&&jsx20(MantineAppShell2.Section,{mb:"sm",children:jsx20(ResourceTypeInput,{name:"resourceType",placeholder:"Resource Type",maxValues:0,onChange:newValue=>navigateResourceType(newValue)},window.location.pathname)}),props.menus?.map((menu,index)=>jsxs9(Fragment4,{children:[menu.title&&jsx20(Text6,{className:Navbar_default.menuTitle,"data-opened":opened||void 0,children:menu.title}),jsx20(Stack4,{gap:"2",children:menu.links?.map(link=>jsx20(NavbarLink,{to:link.href,active:link.href===activeLink?.href,onClick:e=>onLinkClick2(e,link.href),icon:link.icon,label:link.label??"",opened},link.href))})]},`menu-${menu.title??index}`)),props.displayAddBookmark&&jsx20(Tooltip,{label:"Add Bookmark",position:"right",transitionProps:{duration:0},disabled:opened,children:jsxs9(UnstyledButton2,{className:`${Navbar_default.link} ${Navbar_default.addBookmarkLink}`,onClick:()=>setBookmarkDialogVisible(!0),children:[jsx20(IconCirclePlus,{}),jsx20("span",{className:Navbar_default.linkLabel,"data-opened":opened||void 0,children:"Add Bookmark"})]})})]})}),props.userMenuEnabled&&jsxs9(MantineAppShell2.Section,{px:"xs",py:"xs",children:[jsx20(Tooltip,{label:opened?"Close Sidebar":"Open Sidebar",position:"right",transitionProps:{duration:0},children:jsx20(UnstyledButton2,{className:Navbar_default.toggleButton,"aria-label":opened?"Close Sidebar":"Open Sidebar",onClick:props.navbarToggle,"aria-expanded":opened,"aria-controls":"navbar",children:jsx20(IconLayoutSidebar,{})})}),jsx20(Divider,{my:"xs",mx:6,className:Navbar_default.divider}),jsxs9(Menu3,{width:260,shadow:"xl",position:"top-start",transitionProps:{transition:"fade-up"},opened:userMenuOpened,onClose:()=>setUserMenuOpened(!1),children:[jsx20(Menu3.Target,{children:jsxs9(UnstyledButton2,{className:Navbar_default.link,pl:"7","aria-label":"User menu","data-active":userMenuOpened||void 0,onClick:()=>setUserMenuOpened(o=>!o),bd:"1px 0 0 0 solid var(--mantine-color-gray-200)",children:[jsx20(ResourceAvatar,{value:profile,radius:"xl",size:24}),jsx20("span",{className:Navbar_default.linkLabel,"data-opened":opened||void 0,children:formatHumanName5(profile?.name?.[0])})]})}),jsx20(Menu3.Dropdown,{children:jsx20(HeaderDropdown,{version:props.version,showLayoutVersionToggle:props.showLayoutVersionToggle})})]})]})]}),props.pathname&&props.searchParams&&jsx20(BookmarkDialog,{pathname:props.pathname,searchParams:props.searchParams,visible:bookmarkDialogVisible,onOk:()=>setBookmarkDialogVisible(!1),onCancel:()=>setBookmarkDialogVisible(!1)})]})}function NavbarLink(props){let{to,icon,label,onClick,active}=props;return jsx20(Tooltip,{label,position:"right",transitionProps:{duration:0},disabled:props.opened,children:jsxs9(MedplumLink,{to,onClick,className:Navbar_default.link,"data-active":active||void 0,children:[icon??jsx20(IconBookmark,{}),jsx20("span",{className:Navbar_default.linkLabel,"data-opened":props.opened||void 0,children:label})]})})}function getActiveLink(currentPathname,currentSearchParams,menus){if(!currentPathname||!currentSearchParams||!menus)return;let bestLink,bestScore=0;for(let menu of menus)if(menu.links)for(let link of menu.links){let score=getLinkScore(currentPathname,currentSearchParams,link.href);score>bestScore&&(bestScore=score,bestLink=link)}return bestLink}function getLinkScore(currentPathname,currentSearchParams,linkHref){let linkUrl=new URL(linkHref,"https://example.com");if(currentPathname!==linkUrl.pathname)return 0;let ignoredParams=["_count","_offset"];for(let[key,value]of linkUrl.searchParams.entries())if(!ignoredParams.includes(key)&&currentSearchParams.get(key)!==value)return 0;let count=1;for(let[key,value]of currentSearchParams.entries())ignoredParams.includes(key)||linkUrl.searchParams.get(key)===value&&count++;return count}import{jsx as jsx21,jsxs as jsxs10}from"react/jsx-runtime";var OPEN_WIDTH=250,CLOSED_WIDTH=59;function AppShell(props){let[navbarOpen,setNavbarOpen]=useState11(localStorage.navbarOpen==="true"),[layoutVersion]=useState11(props.layoutVersion??localStorage.appShellLayoutVersion??"v1"),medplum=useMedplum5(),profile=useMedplumProfile4();function setNavbarOpenWrapper(open){localStorage.navbarOpen=open.toString(),setNavbarOpen(open)}function closeNavbar(){setNavbarOpenWrapper(!1)}function toggleNavbar(){setNavbarOpenWrapper(!navbarOpen)}if(medplum.isLoading())return jsx21(Loading,{});let headerProp,navbarProp,headerComponent,navbarComponent;return layoutVersion==="v2"?(headerProp={height:0},navbarProp={width:navbarOpen?OPEN_WIDTH:CLOSED_WIDTH,breakpoint:0,collapsed:{desktop:!profile,mobile:!profile}},headerComponent=void 0,navbarComponent=profile?jsx21(Navbar,{logo:props.logo,pathname:props.pathname,searchParams:props.searchParams,menus:props.menus,navbarToggle:toggleNavbar,closeNavbar,displayAddBookmark:props.displayAddBookmark,resourceTypeSearchDisabled:!0,opened:navbarOpen,spotlightEnabled:!0,patientsOnly:props.spotlightPatientsOnly,userMenuEnabled:!0,version:props.version,showLayoutVersionToggle:props.showLayoutVersionToggle}):void 0):(headerProp={height:60},navbarProp={width:OPEN_WIDTH,breakpoint:"sm",collapsed:{desktop:!profile||!navbarOpen,mobile:!profile||!navbarOpen}},headerComponent=profile&&jsx21(Header,{pathname:props.pathname,searchParams:props.searchParams,headerSearchDisabled:props.headerSearchDisabled,logo:props.logo,version:props.version,navbarOpen,navbarToggle:toggleNavbar,notifications:props.notifications}),navbarComponent=profile&&navbarOpen?jsx21(Navbar,{pathname:props.pathname,searchParams:props.searchParams,menus:props.menus,navbarToggle:toggleNavbar,closeNavbar,displayAddBookmark:props.displayAddBookmark,resourceTypeSearchDisabled:props.resourceTypeSearchDisabled,patientsOnly:props.spotlightPatientsOnly}):void 0),jsxs10(MantineAppShell3,{header:headerProp,navbar:navbarProp,padding:0,children:[headerComponent,navbarComponent,jsx21(MantineAppShell3.Main,{className:AppShell_default.main,children:jsx21(ErrorBoundary,{children:jsx21(Suspense,{fallback:jsx21(Loading,{}),children:props.children})})})]})}import{getPathDisplayName,isPopulated as isPopulated2}from"@medplum/core";import{Anchor as Anchor2}from"@mantine/core";import{ContentType as ContentType2}from"@medplum/core";import{useCachedBinaryUrl as useCachedBinaryUrl2}from"@medplum/react-hooks";import{Button as Button2}from"@mantine/core";import{useEffect as useEffect2,useRef as useRef3,useState as useState12}from"react";import{Fragment as Fragment6,jsx as jsx22,jsxs as jsxs11}from"react/jsx-runtime";var CCDA_VIEWER_URL="https://ccda.medplum.com",BASE_VALIDATION_URL="https://ccda-validator.medplum.com/";function CcdaDisplay(props){let{url}=props,[shouldSend,setShouldSend]=useState12(!1),iframeRef=useRef3(null),[validationResult,setValidationResult]=useState12(),[validating,setValidating]=useState12(!1);useEffect2(()=>{url&&shouldSend&&iframeRef.current&&(sendCommand(iframeRef.current,{command:"loadCcdaXml",value:url}).catch(console.error),setShouldSend(!1))},[url,shouldSend]);let validateCcda=async()=>{if(url)try{setValidating(!0);let ccdaContent=await(await fetch(url)).text(),formData=new FormData;formData.append("ccdaFile",new Blob([ccdaContent],{type:"text/xml"}),"ccda.xml");let validationUrl=`${BASE_VALIDATION_URL}referenceccdaservice/?validationObjective=C-CDA_IG_Plus_Vocab&referenceFileName=No%20scenario%20File&curesUpdate=true&severityLevel=WARNING`,validationResponse=await fetch(validationUrl,{method:"POST",body:formData,credentials:"omit",redirect:"manual"});if(!validationResponse.ok)throw new Error(`Validation failed: ${validationResponse.status} ${validationResponse.statusText}`);let validationResult2=await validationResponse.json();setValidationResult(validationResult2)}catch(error){setValidationResult(void 0),console.error("CCDA validation error:",error)}finally{setValidating(!1)}},downloadResults=()=>{if(!validationResult)return;let resultsJson=JSON.stringify(validationResult,null,2);exportJsonFile(resultsJson,"ccda-validation-results")},getErrorCount=()=>validationResult?validationResult.resultsMetaData.resultMetaData.filter(item=>item?.type.includes("Error")).reduce((sum,item)=>sum+(item.count||0),0):0;return url?jsxs11("div",{"data-testid":"ccda-iframe",style:{maxWidth:props.maxWidth},children:[jsx22("div",{style:{minHeight:400},children:jsx22("iframe",{title:"C-CDA Viewer",width:"100%",height:"400",ref:iframeRef,src:CCDA_VIEWER_URL,allowFullScreen:!0,frameBorder:0,seamless:!0,onLoad:()=>setShouldSend(!0)})}),jsxs11("div",{style:{marginTop:"10px",marginBottom:"10px",display:"flex",alignItems:"center"},children:[jsx22(Button2,{type:"button",onClick:validateCcda,disabled:validating,children:validating?"Validating...":"Validate"}),validationResult&&jsxs11(Fragment6,{children:[jsxs11("div",{style:{marginLeft:"15px"},children:[jsx22("strong",{children:"Validation Results:"})," ",getErrorCount()," errors found"]}),jsx22(Button2,{type:"button",onClick:downloadResults,color:"green",style:{marginLeft:"auto"},children:"Download Full Results"})]})]})]}):null}import{jsx as jsx23,jsxs as jsxs12}from"react/jsx-runtime";function AttachmentDisplay(props){let{contentType,url:uncachedUrl,title}=props.value??{},url=useCachedBinaryUrl2(uncachedUrl);return url?jsxs12("div",{"data-testid":"attachment-display",children:[contentType?.startsWith("image/")&&jsx23("img",{"data-testid":"attachment-image",style:{maxWidth:props.maxWidth},src:url,alt:title}),contentType?.startsWith("video/")&&jsx23("video",{"data-testid":"attachment-video",style:{maxWidth:props.maxWidth},controls:!0,children:jsx23("source",{type:contentType,src:url})}),(contentType?.startsWith("text/")||contentType==="application/json"||contentType==="application/pdf")&&jsx23("div",{"data-testid":"attachment-iframe",style:{maxWidth:props.maxWidth,minHeight:400},children:jsx23("iframe",{title:"Attachment",width:"100%",height:"400",src:url+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),contentType===ContentType2.CDA_XML&&jsx23(CcdaDisplay,{url}),jsx23("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:jsx23(Anchor2,{href:uncachedUrl,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:getDownloadName(title),children:title||"Download"})})]}):null}function getDownloadName(title){return title?.includes(".")?title:void 0}function r(e){var t,f,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f)}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}var clsx_default=clsx;var DescriptionList_default={root:"DescriptionList_root",compact:"DescriptionList_compact"};import{Fragment as Fragment7,jsx as jsx24,jsxs as jsxs13}from"react/jsx-runtime";function DescriptionList(props){let{children,compact}=props;return jsx24("dl",{className:clsx_default(DescriptionList_default.root,{[DescriptionList_default.compact]:compact}),children})}function DescriptionListEntry(props){return jsxs13(Fragment7,{children:[jsx24("dt",{children:props.term}),jsx24("dd",{children:props.children})]})}import{Fragment as Fragment8,jsx as jsx25}from"react/jsx-runtime";function AttachmentArrayDisplay(props){let attachmentElements=props.values?.map((v,index)=>jsx25("div",{children:jsx25(AttachmentDisplay,{value:v,maxWidth:props.maxWidth})},"attatchment-"+index)),content;if(props.includeDescriptionListEntry){if(props.property===void 0)throw new Error("props.property is required when includeDescriptionListEntry is true");if(!isPopulated2(props.path))throw new Error("props.path is required when includeDescriptionListEntry is true");let key=props.path.split(".").pop();content=jsx25(DescriptionListEntry,{term:getPathDisplayName(key),children:attachmentElements})}else content=jsx25(Fragment8,{children:attachmentElements});return content}import{ActionIcon}from"@mantine/core";import{useRef as useRef5,useState as useState13}from"react";import{normalizeOperationOutcome}from"@medplum/core";import{useMedplum as useMedplum6}from"@medplum/react-hooks";import{useRef as useRef4}from"react";import{Fragment as Fragment9,jsx as jsx26,jsxs as jsxs14}from"react/jsx-runtime";function AttachmentButton(props){let medplum=useMedplum6(),fileInputRef=useRef4(null);function onClick(e){killEvent(e),fileInputRef.current?.click()}function onFileChange(e){killEvent(e);let files=e.target.files;files&&Array.from(files).forEach(processFile)}function processFile(file){!file||!file.name||(props.onUploadStart&&props.onUploadStart(),medplum.createAttachment({data:file,contentType:file.type||"application/octet-stream",filename:file.name,securityContext:props.securityContext,onProgress:props.onUploadProgress}).then(attachment=>props.onUpload(attachment)).catch(err=>{props.onUploadError&&props.onUploadError(normalizeOperationOutcome(err))}))}return jsxs14(Fragment9,{children:[jsx26("input",{disabled:props.disabled,type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:fileInputRef,onChange:e=>onFileChange(e)}),props.children({onClick,disabled:props.disabled})]})}import{jsx as jsx27,jsxs as jsxs15}from"react/jsx-runtime";function AttachmentArrayInput(props){let[values,setValues]=useState13(props.defaultValue??[]),valuesRef=useRef5(values);valuesRef.current=values;function setValuesWrapper(newValues){setValues(newValues),props.onChange&&props.onChange(newValues)}return jsxs15("table",{style:{width:"100%"},children:[jsxs15("colgroup",{children:[jsx27("col",{width:"97%"}),jsx27("col",{width:"3%"})]}),jsxs15("tbody",{children:[values.map((v,index)=>jsxs15("tr",{children:[jsx27("td",{children:jsx27(AttachmentDisplay,{value:v,maxWidth:200})}),jsx27("td",{children:jsx27(ActionIcon,{disabled:props.disabled,title:"Remove",variant:"subtle",size:"sm",color:"gray",onClick:e=>{killEvent(e);let copy=values.slice();copy.splice(index,1),setValuesWrapper(copy)},children:jsx27(IconCircleMinus,{})})})]},`${index}-${values.length}`)),jsxs15("tr",{children:[jsx27("td",{}),jsx27("td",{children:jsx27(AttachmentButton,{disabled:props.disabled,onUpload:attachment=>{setValuesWrapper([...valuesRef.current,attachment])},children:props2=>jsx27(ActionIcon,{...props2,title:"Add",variant:"subtle",size:"sm",color:props2.disabled?"gray":"green",children:jsx27(IconCloudUpload,{})})})})]})]})]})}import{Button as Button3}from"@mantine/core";import{useState as useState14}from"react";import{Fragment as Fragment10,jsx as jsx28,jsxs as jsxs16}from"react/jsx-runtime";function AttachmentInput(props){let[value,setValue]=useState14(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return value?jsxs16(Fragment10,{children:[jsx28(AttachmentDisplay,{value,maxWidth:200}),jsx28(Button3,{disabled:props.disabled,onClick:e=>{killEvent(e),setValueWrapper(void 0)},children:"Remove"})]}):jsx28(AttachmentButton,{disabled:props.disabled,securityContext:props.securityContext,onUpload:setValueWrapper,children:props2=>jsx28(Button3,{...props2,children:"Upload..."})})}import{Alert as Alert2,Center as Center2,Image as Image2,Stack as Stack5,Text as Text7,TextInput as TextInput4,Title}from"@mantine/core";import{normalizeErrorString as normalizeErrorString4}from"@medplum/core";import{useState as useState15}from"react";import{jsx as jsx29,jsxs as jsxs17}from"react/jsx-runtime";function Logo(props){let overrideUrl=import.meta.env.MEDPLUM_LOGO_URL;return overrideUrl?jsx29("img",{src:overrideUrl,alt:"Logo",style:{maxHeight:props.size}}):jsxs17("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 180 180",style:{width:props.size,height:props.size},children:[jsx29("title",{children:"Medplum Logo"}),jsx29("path",{fill:props.fill??"#9c36b5",d:"M84 56c-3-15-15-24-23-28l5-10c8 2 14 8 20 14 0-12 1-16 5-21 8-9 13-9 41-9 0 7 1 18-3 24-7 9-16 7-41 8 5 8 7 14 8 22 36-24 74-7 74 39 0 42-40 83-80 83s-80-41-80-83c0-46 38-63 74-39Zm-3 43H65c-4 0-7 3-7 7v4c0 4 3 7 7 7h16v16c0 4 3 7 7 7h4c4 0 7-3 7-7v-16h16c4 0 7-3 7-7v-4c0-4-3-7-7-7H99V83c0-4-3-7-7-7h-4c-4 0-7 3-7 7z"})]})}import{jsx as jsx30,jsxs as jsxs18}from"react/jsx-runtime";function MfaForm(props){let[errorMessage,setErrorMessage]=useState15();return jsxs18(Form,{onSubmit:formData=>{setErrorMessage(void 0),props.onSubmit(formData)?.catch(err=>setErrorMessage(normalizeErrorString4(err)))},children:[jsxs18(Center2,{style:{flexDirection:"column"},children:[jsx30(Logo,{size:32}),jsx30(Title,{order:3,py:"lg",children:props.title}),!props.qrCodeUrl&&props.description&&jsx30(Text7,{c:"dimmed",mb:"lg",mt:"-lg",children:props.description})]}),errorMessage&&jsx30(Alert2,{icon:jsx30(IconAlertCircle,{size:16}),title:"Error",color:"red",mb:"lg",children:errorMessage}),props.qrCodeUrl&&jsx30(Center2,{children:jsxs18(Stack5,{mb:"xl",children:[props.description&&jsx30(Text7,{c:"dimmed",mb:"md",mt:"-lg",ta:"center",children:props.description}),jsx30(Image2,{src:props.qrCodeUrl,alt:"Multi Factor Auth QR Code",w:"60%",mx:"auto",radius:"md",p:"xs",bg:"var(--mantine-color-white)",style:{border:"1px solid light-dark(var(--mantine-color-gray-2), var(--mantine-color-dark-4))"}})]})}),jsx30(Stack5,{gap:"sm",children:jsx30(TextInput4,{name:"token",label:"MFA code",autoComplete:"one-time-code",required:!0,autoFocus:!0})}),jsx30(Stack5,{gap:"xs",pt:"md",children:jsx30(SubmitButton,{fullWidth:!0,children:props.buttonText})})]})}import{normalizeOperationOutcome as normalizeOperationOutcome4}from"@medplum/core";import{useMedplum as useMedplum9}from"@medplum/react-hooks";import{useEffect as useEffect5,useState as useState19}from"react";import{Container as MantineContainer}from"@mantine/core";var Container_default={root:"Container_root"};import{jsx as jsx31}from"react/jsx-runtime";function Container(props){let{children,...others}=props;return jsx31(MantineContainer,{className:Container_default.root,...others,children})}import{Paper}from"@mantine/core";var Panel_default={paper:"Panel_paper",fill:"Panel_fill"};import{jsx as jsx32}from"react/jsx-runtime";function Panel(props){let{width,fill,className,children,...rest}=props,style=width?{maxWidth:width}:void 0;return jsx32(Paper,{className:clsx_default(Panel_default.paper,fill&&Panel_default.fill,className),style,shadow:"sm",radius:"sm",withBorder:!0,...rest,children})}import{jsx as jsx33}from"react/jsx-runtime";function Document(props){let{children,...others}=props;return jsx33(Container,{children:jsx33(Panel,{...others,children})})}import{Alert as Alert3}from"@mantine/core";import{operationOutcomeIssueToString}from"@medplum/core";import{jsx as jsx34}from"react/jsx-runtime";function OperationOutcomeAlert(props){let{outcome,issues:issuesProp,...spacingProps}=props,issues=outcome?.issue||issuesProp;return!issues||issues.length===0?null:jsx34(Alert3,{icon:jsx34(IconAlertCircle,{size:16}),color:"red",...spacingProps,children:issues.map(issue=>jsx34("div",{"data-testid":"text-field-error",children:operationOutcomeIssueToString(issue)},issue.details?.text))})}function getErrorsForInput(outcome,expression){return outcome?.issue?.filter(issue=>isExpressionMatch(issue.expression?.[0],expression))?.map(issue=>issue.details?.text)?.join(`
103
103
  `)}function getIssuesForExpression(outcome,expression){return outcome?.issue?.filter(issue=>isExpressionMatch(issue.expression?.[0],expression))}var ARRAY_INDEX_REGEX=/\[\d+\]/;function isExpressionMatch(expr1,expr2){let isExpr1Indexed=typeof expr1=="string"&&ARRAY_INDEX_REGEX.test(expr1),isExpr2Indexed=typeof expr2=="string"&&ARRAY_INDEX_REGEX.test(expr2);if(isExpr1Indexed!==isExpr2Indexed&&(expr1=expr1?.replace(ARRAY_INDEX_REGEX,""),expr2=expr2?.replace(ARRAY_INDEX_REGEX,"")),expr1===expr2)return!0;if(!expr1||!expr2)return!1;let dot1=expr1.indexOf(".");if(dot1>=0&&expr1.substring(dot1+1)===expr2)return!0;let dot2=expr2.indexOf(".");return dot2>=0&&expr2.substring(dot2+1)===expr1}import{Anchor as Anchor3,Flex,Stack as Stack6,Text as Text8,TextInput as TextInput5,Title as Title2}from"@mantine/core";import{normalizeOperationOutcome as normalizeOperationOutcome2}from"@medplum/core";import{useMedplum as useMedplum7}from"@medplum/react-hooks";import{useState as useState16}from"react";import{jsx as jsx35,jsxs as jsxs19}from"react/jsx-runtime";function NewProjectForm(props){let medplum=useMedplum7(),[outcome,setOutcome]=useState16(),issues=getIssuesForExpression(outcome,void 0);return jsxs19(Form,{onSubmit:async formData=>{try{props.handleAuthResponse(await medplum.startNewProject({login:props.login,projectName:formData.projectName}))}catch(err){setOutcome(normalizeOperationOutcome2(err))}},children:[jsxs19(Flex,{direction:"column",align:"center",justify:"center",children:[jsx35(Logo,{size:32}),jsx35(Title2,{order:3,py:"lg",children:"Create a new project"})]}),jsx35(OperationOutcomeAlert,{issues,mb:"lg"}),jsx35(Stack6,{gap:"sm",children:jsx35(TextInput5,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:getErrorsForInput(outcome,"projectName")})}),jsxs19(Stack6,{gap:"xs",mt:"md",children:[jsx35(SubmitButton,{fullWidth:!0,children:"Create Project"}),jsxs19(Text8,{c:"dimmed",size:"xs",pt:"lg",ta:"center",children:['By clicking "Create Project" you agree to the Medplum'," ",jsx35(Anchor3,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",jsx35(Anchor3,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]})]})}import{Anchor as Anchor4,Box as Box3,Checkbox,Divider as Divider2,Flex as Flex2,PasswordInput,Stack as Stack7,Text as Text9,TextInput as TextInput6}from"@mantine/core";import{normalizeOperationOutcome as normalizeOperationOutcome3}from"@medplum/core";import{useMedplum as useMedplum8}from"@medplum/react-hooks";import{useEffect as useEffect4,useState as useState18}from"react";import{Box as Box2}from"@mantine/core";import{useEffect as useEffect3,useRef as useRef6,useState as useState17}from"react";function createScriptTag(src,onload){let head=document.getElementsByTagName("head")[0],script=document.createElement("script");script.async=!0,script.src=src,script.onload=onload??null,head.appendChild(script)}import{jsx as jsx36}from"react/jsx-runtime";function GoogleButton(props){let{googleClientId,handleGoogleCredential}=props,parentRef=useRef6(null),[scriptLoaded,setScriptLoaded]=useState17(typeof google<"u"),initializedRef=useRef6(!1),buttonRenderedRef=useRef6(!1);return useEffect3(()=>{if(typeof google>"u"){createScriptTag("https://accounts.google.com/gsi/client",()=>setScriptLoaded(!0));return}initializedRef.current||(google.accounts.id.initialize({client_id:googleClientId,callback:handleGoogleCredential}),initializedRef.current=!0),parentRef.current&&!buttonRenderedRef.current&&(google.accounts.id.renderButton(parentRef.current,{type:"standard",logo_alignment:"center",width:parentRef.current.clientWidth}),buttonRenderedRef.current=!0)},[googleClientId,scriptLoaded,handleGoogleCredential]),googleClientId?jsx36(Box2,{ref:parentRef,w:"100%",h:40,display:"flex",style:{justifyContent:"center"}}):null}import{locationUtils as locationUtils3}from"@medplum/core";function getGoogleClientId(clientId){if(clientId)return clientId;let origin=locationUtils3.getOrigin();if(origin&&("undefined"?.split(",")??[]).includes(origin))return"__GOOGLE_CLIENT_ID__"}function initRecaptcha(siteKey){typeof grecaptcha>"u"&&createScriptTag("https://www.google.com/recaptcha/api.js?render="+siteKey)}function getRecaptcha(siteKey){return new Promise((resolve,reject)=>{grecaptcha.ready(async()=>{try{resolve(await grecaptcha.execute(siteKey,{action:"submit"}))}catch(err){reject(err)}})})}import{Fragment as Fragment11,jsx as jsx37,jsxs as jsxs20}from"react/jsx-runtime";function NewUserForm(props){let googleClientId=getGoogleClientId(props.googleClientId),recaptchaSiteKey=props.recaptchaSiteKey,medplum=useMedplum8(),[outcome,setOutcome]=useState18(),issues=getIssuesForExpression(outcome,void 0);return useEffect4(()=>{recaptchaSiteKey&&initRecaptcha(recaptchaSiteKey)},[recaptchaSiteKey]),jsxs20(Form,{onSubmit:async formData=>{setOutcome(void 0);try{let recaptchaToken="";recaptchaSiteKey&&(recaptchaToken=await getRecaptcha(recaptchaSiteKey)),props.handleAuthResponse(await medplum.startNewUser({projectId:props.projectId,clientId:props.clientId,firstName:formData.firstName,lastName:formData.lastName,email:formData.email,password:formData.password,remember:formData.remember==="true",recaptchaSiteKey,recaptchaToken}))}catch(err){setOutcome(normalizeOperationOutcome3(err))}},children:[jsx37(Flex2,{direction:"column",align:"center",justify:"center",children:props.children}),jsx37(OperationOutcomeAlert,{issues,mb:"lg"}),googleClientId&&jsxs20(Fragment11,{children:[jsx37(Box3,{style:{minHeight:40},children:jsx37(GoogleButton,{googleClientId,handleGoogleCredential:async response=>{try{props.handleAuthResponse(await medplum.startGoogleLogin({googleClientId:response.clientId,googleCredential:response.credential,projectId:props.projectId,createUser:!0}))}catch(err){setOutcome(normalizeOperationOutcome3(err))}}})}),jsx37(Divider2,{label:"or",labelPosition:"center",my:"lg"})]}),jsxs20(Stack7,{gap:"sm",children:[jsx37(TextInput6,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:getErrorsForInput(outcome,"firstName")}),jsx37(TextInput6,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:getErrorsForInput(outcome,"lastName")}),jsx37(TextInput6,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:getErrorsForInput(outcome,"email")}),jsx37(PasswordInput,{name:"password",label:"Password",autoComplete:"off",required:!0,error:getErrorsForInput(outcome,"password")})]}),jsxs20(Stack7,{gap:"xs",children:[jsx37(Checkbox,{id:"remember",name:"remember",label:"Remember me",size:"xs",style:{lineHeight:1},pt:"md",pb:"xs"}),jsx37(SubmitButton,{fullWidth:!0,children:"Register Account"}),jsxs20(Text9,{c:"dimmed",size:"xs",pt:"lg",ta:"center",children:['By clicking "Register Account" you agree to the Medplum'," ",jsx37(Anchor4,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",jsx37(Anchor4,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),jsxs20(Text9,{c:"dimmed",size:"xs",ta:"center",children:["This site is protected by reCAPTCHA and the Google"," ",jsx37(Anchor4,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",jsx37(Anchor4,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]})]})}import{jsx as jsx38,jsxs as jsxs21}from"react/jsx-runtime";function RegisterForm(props){let{type,projectId,clientId,googleClientId,recaptchaSiteKey,onSuccess}=props,medplum=useMedplum9(),[login,setLogin]=useState19(),[outcome,setOutcome]=useState19();useEffect5(()=>{type==="patient"&&login&&medplum.startNewPatient({login,projectId}).then(response=>medplum.processCode(response.code)).then(()=>onSuccess()).catch(err=>setOutcome(normalizeOperationOutcome4(err)))},[medplum,type,projectId,login,onSuccess]);function handleAuthResponse(response){response.code?medplum.processCode(response.code).then(()=>onSuccess()).catch(err=>setOutcome(normalizeOperationOutcome4(err))):response.login&&setLogin(response.login)}let issues=getIssuesForExpression(outcome,void 0);return jsxs21(Document,{width:400,px:"xl",py:"xl",bdrs:"md",children:[jsx38(OperationOutcomeAlert,{issues,mb:"lg"}),!login&&jsx38(NewUserForm,{projectId,clientId,googleClientId,recaptchaSiteKey,handleAuthResponse,children:props.children}),login&&type==="project"&&jsx38(NewProjectForm,{login,handleAuthResponse})]})}import{showNotification as showNotification3}from"@mantine/notifications";import{normalizeErrorString as normalizeErrorString5}from"@medplum/core";import{useMedplum as useMedplum13}from"@medplum/react-hooks";import{useCallback as useCallback6,useEffect as useEffect6,useRef as useRef7,useState as useState22}from"react";import{ActionIcon as ActionIcon2,Anchor as Anchor5,Box as Box4,Checkbox as Checkbox2,Divider as Divider3,Flex as Flex3,PasswordInput as PasswordInput2,Stack as Stack8,Text as Text10,TextInput as TextInput7}from"@mantine/core";import{locationUtils as locationUtils4,normalizeOperationOutcome as normalizeOperationOutcome5}from"@medplum/core";import{useMedplum as useMedplum10}from"@medplum/react-hooks";import{useCallback as useCallback5,useState as useState20}from"react";import{Fragment as Fragment12,jsx as jsx39,jsxs as jsxs22}from"react/jsx-runtime";function AuthenticationForm(props){let[email,setEmail]=useState20();return email?jsx39(PasswordForm,{email,resetEmail:()=>setEmail(void 0),...props}):jsx39(EmailForm,{setEmail,...props})}function EmailForm(props){let{setEmail,onRegister,handleAuthResponse,children,disableEmailAuth,...baseLoginRequest}=props,medplum=useMedplum10(),googleClientId=!props.disableGoogleAuth&&getGoogleClientId(props.googleClientId),[outcome,setOutcome]=useState20(),issues=getIssuesForExpression(outcome,void 0),isExternalAuth=useCallback5(async authMethod=>{if(!authMethod.authorizeUrl)return!1;let state=JSON.stringify({...await medplum.ensureCodeChallenge(baseLoginRequest),domain:authMethod.domain}),url=new URL(authMethod.authorizeUrl);return url.searchParams.set("state",state),locationUtils4.assign(url.toString()),!0},[medplum,baseLoginRequest]),handleSubmit=useCallback5(async formData=>{let authMethod=await medplum.post("auth/method",{email:formData.email});await isExternalAuth(authMethod)||setEmail(formData.email)},[medplum,isExternalAuth,setEmail]),handleGoogleCredential=useCallback5(async response=>{try{let authResponse=await medplum.startGoogleLogin({...baseLoginRequest,googleCredential:response.credential});await isExternalAuth(authResponse)||handleAuthResponse(authResponse)}catch(err){setOutcome(normalizeOperationOutcome5(err))}},[medplum,baseLoginRequest,isExternalAuth,handleAuthResponse]);return jsxs22(Form,{onSubmit:handleSubmit,children:[jsx39(Flex3,{direction:"column",align:"center",justify:"center",children}),jsx39(OperationOutcomeAlert,{issues,mb:"lg"}),googleClientId&&jsxs22(Fragment12,{children:[jsx39(Box4,{style:{minHeight:40},children:jsx39(GoogleButton,{googleClientId,handleGoogleCredential})}),!disableEmailAuth&&jsx39(Divider3,{label:"or",labelPosition:"center",my:"lg"})]}),!disableEmailAuth&&jsx39(TextInput7,{name:"email",type:"email",label:"Email",mb:"md",placeholder:"name@domain.com",required:!0,autoFocus:!0,error:getErrorsForInput(outcome,"email"),"data-testid":"auth.email"}),jsxs22(Stack8,{gap:"xs",children:[!disableEmailAuth&&jsx39(SubmitButton,{fullWidth:!0,children:"Continue"}),onRegister&&jsxs22(Text10,{size:"sm",mt:"lg",c:"dimmed",style:{textAlign:"center"},"data-dashlane-ignore":"true","data-lp-ignore":"true","data-no-autofill":"true","data-form-type":"navigation",children:["Don\u2019t have an account? ",jsx39(Anchor5,{onClick:onRegister,children:"Register"})]})]})]})}function PasswordForm(props){let{onForgotPassword,handleAuthResponse,children,...baseLoginRequest}=props,medplum=useMedplum10(),[outcome,setOutcome]=useState20(),issues=getIssuesForExpression(outcome,void 0),handleSubmit=useCallback5(formData=>{medplum.startLogin({...baseLoginRequest,password:formData.password,remember:formData.remember==="on"}).then(handleAuthResponse).catch(err=>setOutcome(normalizeOperationOutcome5(err)))},[medplum,baseLoginRequest,handleAuthResponse]);return jsxs22(Form,{onSubmit:handleSubmit,children:[jsx39(Flex3,{direction:"column",align:"center",justify:"center",children}),jsx39(OperationOutcomeAlert,{issues,mb:"lg"}),jsxs22(Stack8,{gap:"sm",children:[jsx39(TextInput7,{label:"Email",value:props.email,disabled:!0,rightSectionWidth:36,rightSection:jsx39(ActionIcon2,{variant:"subtle",color:"gray",onClick:props.resetEmail,"aria-label":"Change email",children:jsx39(IconPencil,{size:"1rem",stroke:1.5})})}),jsx39(PasswordInput2,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:getErrorsForInput(outcome,"password"),"data-testid":"auth.password"})]}),jsxs22(Stack8,{gap:"xs",children:[jsx39(Checkbox2,{id:"remember",name:"remember",label:"Remember me",size:"xs",style:{lineHeight:1},pt:"md",pb:"xs"}),jsx39(SubmitButton,{children:"Sign In"}),onForgotPassword&&jsx39(Text10,{size:"sm",mt:"lg",c:"dimmed",style:{textAlign:"center"},"data-dashlane-ignore":"true","data-lp-ignore":"true","data-no-autofill":"true","data-form-type":"navigation",children:jsx39(Anchor5,{onClick:onForgotPassword,children:"Reset Password"})})]})]})}import{Anchor as Anchor6,Box as Box5,Combobox as Combobox2,Flex as Flex4,Group as Group8,Stack as Stack9,Text as Text11,TextInput as TextInput8,Title as Title3,useCombobox as useCombobox2}from"@mantine/core";import{normalizeOperationOutcome as normalizeOperationOutcome6}from"@medplum/core";import{useMedplum as useMedplum11}from"@medplum/react-hooks";import{useState as useState21}from"react";var ChooseProfileForm_default={option:"ChooseProfileForm_option",iconBox:"ChooseProfileForm_iconBox"};import{jsx as jsx40,jsxs as jsxs23}from"react/jsx-runtime";function ChooseProfileForm(props){let medplum=useMedplum11(),combobox=useCombobox2(),[search,setSearch]=useState21(""),[outcome,setOutcome]=useState21();function filterDisplay(display){return!!display?.toLowerCase()?.includes(search.toLowerCase())}function filterMembership(membership){return filterDisplay(membership.profile?.display)||filterDisplay(membership.project?.display)}function handleValueSelect(membershipId){medplum.post("auth/profile",{login:props.login,profile:membershipId}).then(props.handleAuthResponse).catch(err=>setOutcome(normalizeOperationOutcome6(err)))}let options=props.memberships.filter(filterMembership).slice(0,10).map(item=>jsx40(Combobox2.Option,{value:item.id,className:ChooseProfileForm_default.option,children:jsx40(SelectOption,{...item})},item.id));return jsxs23(Stack9,{gap:"0",children:[jsxs23(Flex4,{justify:"center",align:"center",direction:"column",wrap:"nowrap",children:[jsx40(Logo,{size:32}),jsx40(Title3,{order:3,py:"lg",children:"Choose a Project"})]}),jsx40(OperationOutcomeAlert,{outcome,mb:"lg"}),jsxs23(Combobox2,{store:combobox,onOptionSubmit:handleValueSelect,children:[jsx40(Combobox2.EventsTarget,{children:jsx40(TextInput8,{placeholder:"Search",value:search,mb:"md",autoFocus:!0,leftSection:jsx40(IconSearch,{size:16}),onChange:event=>{setSearch(event.currentTarget.value),combobox.updateSelectedOptionIndex()}})}),jsx40("div",{children:jsx40(Combobox2.Options,{style:{marginLeft:"-10px",marginRight:"-10px",marginBottom:"-10px"},children:options.length>0?options:jsx40(Combobox2.Empty,{children:"Nothing found..."})})})]}),jsx40(Text11,{size:"sm",ta:"center",mt:"md",children:jsx40(Anchor6,{component:"button",type:"button",onClick:()=>{window.location.href=`/signin?project=new&login=${props.login}`},children:"Create a new project"})})]})}function getMembershipLabel(membership){return membership.identifier?.find(i=>i.system==="https://medplum.com/identifier/label")?.value}function SelectOption(membership){let label=getMembershipLabel(membership);return jsxs23(Group8,{gap:"xs",align:"center",children:[jsx40(Box5,{className:ChooseProfileForm_default.iconBox,children:jsx40(IconBriefcase,{size:16,stroke:2})}),jsxs23("div",{children:[jsxs23(Text11,{size:"sm",fw:500,children:[membership.project?.display," ",label?` - ${label}`:""]}),jsx40(Text11,{size:"xs",c:"dimmed",children:membership.profile?.display})]})]})}import{Checkbox as Checkbox3,Flex as Flex5,Group as Group9,Stack as Stack10,Title as Title4}from"@mantine/core";import{useMedplum as useMedplum12}from"@medplum/react-hooks";import{Fragment as Fragment13}from"react/jsx-runtime";import{jsx as jsx41,jsxs as jsxs24}from"react/jsx-runtime";var openConditionScope=/^patient\/Condition\.(?:\*|c?r?u?d?s?)$/,encounterDiagnosis="?category=http://terminology.hl7.org/CodeSystem/condition-category|encounter-diagnosis",problemListItem="?category=http://terminology.hl7.org/CodeSystem/condition-category|problem-list-item",healthConcern="?category=http://hl7.org/fhir/us/core/CodeSystem/condition-category|health-concern",openObservationScope=/^patient\/Observation\.(?:\*|c?r?u?d?s?)$/,clinicalTest="?category=http://hl7.org/fhir/us/core/CodeSystem/us-core-observation-category|clinical-test",laboratory="?category=http://terminology.hl7.org/CodeSystem/observation-category|laboratory",socialHistory="?category=http://terminology.hl7.org/CodeSystem/observation-category|social-history",sdoh="?category=http://hl7.org/fhir/us/core/CodeSystem/us-core-category|sdoh",survey="?category=http://terminology.hl7.org/CodeSystem/observation-category|survey",vitalSigns="?category=http://terminology.hl7.org/CodeSystem/observation-category|vital-signs";function ChooseScopeForm(props){let medplum=useMedplum12();return jsx41(Form,{onSubmit:formData=>{medplum.post("auth/scope",{login:props.login,scope:Object.keys(formData).join(" ")}).then(props.handleAuthResponse).catch(console.log)},children:jsxs24(Stack10,{children:[jsxs24(Flex5,{direction:"column",align:"center",justify:"center",children:[jsx41(Logo,{size:32}),jsx41(Title4,{order:3,py:"lg",children:"Choose scope"})]}),jsx41(Stack10,{children:(props.scope??"openid").split(" ").map(scopeName=>{let additionalScopes;return openConditionScope.test(scopeName)?additionalScopes=[scopeName+encounterDiagnosis,scopeName+problemListItem,scopeName+healthConcern]:openObservationScope.test(scopeName)&&(additionalScopes=[scopeName+clinicalTest,scopeName+laboratory,scopeName+socialHistory,scopeName+sdoh,scopeName+survey,scopeName+vitalSigns]),jsxs24(Fragment13,{children:[jsx41(Checkbox3,{id:scopeName,name:scopeName,label:scopeName,defaultChecked:!0},scopeName),additionalScopes?.map(scope=>jsx41(Checkbox3,{id:scope,name:scope,label:scope},scope))]},scopeName+"_group")})}),jsx41(Group9,{justify:"flex-end",mt:"xl",children:jsx41(SubmitButton,{fullWidth:!0,children:"Set Scope"})})]})})}import{jsx as jsx42}from"react/jsx-runtime";function SignInForm(props){let{login:loginCode,chooseScopes,onSuccess,onForgotPassword,onRegister,onCode,...baseLoginRequest}=props,medplum=useMedplum13(),[login,setLogin]=useState22(),loginRequested=useRef7(!1),[mfaEnrollRequired,setMfaEnrollRequired]=useState22(!1),[enrollQrCode,setEnrollQrCode]=useState22(),[mfaRequired,setMfaRequired]=useState22(!1),[memberships,setMemberships]=useState22(),handleCode=useCallback6(code=>{onCode?onCode(code):medplum.processCode(code).then(()=>{onSuccess&&onSuccess()}).catch(err=>showNotification3({color:"red",message:normalizeErrorString5(err)}))},[medplum,onCode,onSuccess]),handleAuthResponse=useCallback6(response=>{setMfaEnrollRequired(!!response.mfaEnrollRequired),setEnrollQrCode(response.enrollQrCode),setMfaRequired(!!response.mfaRequired),response.login&&setLogin(response.login),response.memberships&&setMemberships(response.memberships),response.code&&(chooseScopes?setMemberships(void 0):handleCode(response.code))},[chooseScopes,handleCode]),handleScopeResponse=useCallback6(response=>{handleCode(response.code)},[handleCode]);return useEffect6(()=>{loginCode&&!loginRequested.current&&!login&&(loginRequested.current=!0,medplum.get("auth/login/"+loginCode).then(handleAuthResponse).catch(err=>showNotification3({color:"red",message:normalizeErrorString5(err)})))},[medplum,loginCode,loginRequested,login,handleAuthResponse]),jsx42(Document,{width:400,px:"xl",py:"xl",bdrs:"md",children:login?mfaEnrollRequired&&enrollQrCode?jsx42(MfaForm,{title:"Enroll in MFA",description:"Scan this QR code with your authenticator app.",buttonText:"Enroll",qrCodeUrl:enrollQrCode,onSubmit:async fields=>{let res=await medplum.post("auth/mfa/login-enroll",{login,token:fields.token});handleAuthResponse(res)}}):mfaRequired?jsx42(MfaForm,{title:"Enter MFA code",description:"Enter the code from your authenticator app.",buttonText:"Submit Code",onSubmit:async fields=>{let res=await medplum.post("auth/mfa/verify",{login,token:fields.token});handleAuthResponse(res)}}):props.projectId==="new"?jsx42(NewProjectForm,{login,handleAuthResponse}):memberships?jsx42(ChooseProfileForm,{login,memberships,handleAuthResponse}):props.chooseScopes?jsx42(ChooseScopeForm,{login,scope:props.scope,handleAuthResponse:handleScopeResponse}):jsx42("div",{children:"Success"}):jsx42(AuthenticationForm,{onForgotPassword,onRegister,handleAuthResponse,disableGoogleAuth:props.disableGoogleAuth,disableEmailAuth:props.disableEmailAuth,...baseLoginRequest,children:props.children})})}import{buildElementsContext as buildElementsContext2,getPathDisplayName as getPathDisplayName3,isEmpty as isEmpty2,tryGetDataType}from"@medplum/core";import{useContext as useContext6,useMemo as useMemo6}from"react";import{ActionIcon as ActionIcon3,CopyButton,Flex as Flex6,Tooltip as Tooltip2}from"@mantine/core";import{PropertyType,formatDateTime,formatPeriod,formatTiming,formatWallTime,isEmpty}from"@medplum/core";import{useState as useState25}from"react";import{formatCodeableConcept}from"@medplum/core";import{Fragment as Fragment14,jsx as jsx43}from"react/jsx-runtime";function CodeableConceptDisplay(props){return jsx43(Fragment14,{children:formatCodeableConcept(props.value)})}import{formatCoding}from"@medplum/core";import{Fragment as Fragment15,jsx as jsx44}from"react/jsx-runtime";function CodingDisplay(props){return jsx44(Fragment15,{children:formatCoding(props.value)})}import{Fragment as Fragment16,jsx as jsx45}from"react/jsx-runtime";function ContactPointDisplay(props){let contactPoint=props.value;if(!contactPoint)return null;let builder=[];return contactPoint.value&&builder.push(contactPoint.value),(contactPoint.use||contactPoint.system)&&(builder.push(" ["),contactPoint.use&&builder.push(contactPoint.use),contactPoint.use&&contactPoint.system&&builder.push(" "),contactPoint.system&&builder.push(contactPoint.system),builder.push("]")),jsx45(Fragment16,{children:builder.join("").trim()})}import{Fragment as Fragment17,jsx as jsx46,jsxs as jsxs25}from"react/jsx-runtime";function ContactDetailDisplay(props){let contactDetail=props.value;return contactDetail?jsxs25(Fragment17,{children:[contactDetail.name,contactDetail.name&&": ",contactDetail.telecom?.map(telecom=>jsx46(ContactPointDisplay,{value:telecom},`telecom-${contactDetail.name}-${telecom.value}`))]}):null}import{getDataType,isPopulated as isPopulated3,isProfileLoaded,tryGetProfile}from"@medplum/core";import{useMedplum as useMedplum14}from"@medplum/react-hooks";import{useContext as useContext3,useEffect as useEffect7,useMemo as useMemo3,useState as useState23}from"react";import{getTypedPropertyValue,getTypedPropertyValueWithSchema}from"@medplum/core";function getValueAndType(context,path,profileUrl){let typedResult=getTypedPropertyValue(context,path,{profileUrl});return typedResult?Array.isArray(typedResult)?[typedResult.map(e=>e.value),typedResult[0].type]:[typedResult.value,typedResult.type]:[void 0,"undefined"]}function getValueAndTypeFromElement(typedValue,path,element){let typedResult=getTypedPropertyValueWithSchema(typedValue,path,element);return typedResult?Array.isArray(typedResult)?[typedResult.map(e=>e.value),typedResult[0].type]:[typedResult.value,typedResult.type]:[void 0,"undefined"]}import{jsx as jsx47}from"react/jsx-runtime";function ExtensionDisplay(props){let{elementDefinitionType}=props,medplum=useMedplum14(),ctx=useContext3(ElementsContext),[typeSchema,setTypeSchema]=useState23(getDataType("Extension")),profileUrl=useMemo3(()=>{if(isPopulated3(elementDefinitionType?.profile))return elementDefinitionType.profile[0]},[elementDefinitionType]),[loadingProfile,setLoadingProfile]=useState23(profileUrl!==void 0);if(useEffect7(()=>{profileUrl&&(setLoadingProfile(!0),medplum.requestProfileSchema(profileUrl).then(()=>{let profile=tryGetProfile(profileUrl);setLoadingProfile(!1),profile&&setTypeSchema(profile)}).catch(reason=>{setLoadingProfile(!1),console.warn(reason)}))},[medplum,profileUrl]),profileUrl&&(loadingProfile||!isProfileLoaded(profileUrl)))return jsx47("div",{children:"Loading..."});if(typeSchema.elements["value[x]"]?.max!==0){let[propertyValue,propertyType]=getValueAndType({type:"Extension",value:props.value},"value[x]",profileUrl??ctx.profileUrl);return jsx47(ResourcePropertyDisplay,{propertyType,value:propertyValue})}return jsx47(BackboneElementDisplay,{path:props.path,value:{type:typeSchema.type,value:props.value},compact:props.compact,ignoreMissingValues:props.ignoreMissingValues,link:props.link,profileUrl})}import{jsxs as jsxs26}from"react/jsx-runtime";function IdentifierDisplay(props){return jsxs26("div",{children:[props.value?.system,": ",props.value?.value]})}import{formatMoney}from"@medplum/core";import{Fragment as Fragment18,jsx as jsx48}from"react/jsx-runtime";function MoneyDisplay(props){return jsx48(Fragment18,{children:formatMoney(props.value)})}import{formatQuantity}from"@medplum/core";import{Fragment as Fragment19,jsx as jsx49}from"react/jsx-runtime";function QuantityDisplay(props){return jsx49(Fragment19,{children:formatQuantity(props.value)})}import{formatRange}from"@medplum/core";import{Fragment as Fragment20,jsx as jsx50}from"react/jsx-runtime";function RangeDisplay(props){return jsx50(Fragment20,{children:formatRange(props.value)})}import{Fragment as Fragment21,jsx as jsx51,jsxs as jsxs27}from"react/jsx-runtime";function RatioDisplay(props){let value=props.value;return value?jsxs27(Fragment21,{children:[jsx51(QuantityDisplay,{value:value.numerator}),"\xA0/\xA0",jsx51(QuantityDisplay,{value:value.denominator})]}):null}import{stringify}from"@medplum/core";import{Fragment as Fragment22,jsx as jsx52}from"react/jsx-runtime";function ReferenceDisplay(props){if(!props.value)return null;let displayString=props.value.display||props.value.reference||stringify(props.value);return props.link!==!1&&props.value.reference?jsx52(MedplumLink,{to:props.value,children:displayString}):jsx52(Fragment22,{children:displayString})}import{Group as Group10,Text as Text12}from"@mantine/core";import{getPathDisplayName as getPathDisplayName2,isPopulated as isPopulated6}from"@medplum/core";import{useMedplum as useMedplum15}from"@medplum/react-hooks";import{useContext as useContext5,useEffect as useEffect8,useMemo as useMemo5,useState as useState24}from"react";import{getValueSliceName,isPopulated as isPopulated4,isSliceDefinitionWithTypes,tryGetProfile as tryGetProfile2}from"@medplum/core";function assignValuesIntoSlices(values,slices,slicing,profileUrl){if(!isPopulated4(slicing?.slices))return[values];let slicedValues=new Array(slices.length+1);for(let i=0;i<slicedValues.length;i++)slicedValues[i]=[];for(let value of values){let sliceName=getValueSliceName(value,slices,slicing.discriminator,profileUrl),sliceIndex=sliceName?slices.findIndex(slice=>slice.name===sliceName):-1;sliceIndex===-1&&(sliceIndex=slices.length),slicedValues[sliceIndex].push(value)}return slicedValues}async function prepareSlices({medplum,property}){return new Promise((resolve,reject)=>{if(!property.slicing){resolve([]);return}let supportedSlices=[],profileUrls=[],promises=[];for(let slice of property.slicing.slices){if(!isSliceDefinitionWithTypes(slice)){console.debug("Unsupported slice definition",slice);continue}let profileUrl;isPopulated4(slice.elements)||(profileUrl=slice.type[0]?.profile?.[0]),supportedSlices.push(slice),profileUrls.push(profileUrl),profileUrl&&promises.push(medplum.requestProfileSchema(profileUrl))}Promise.all(promises).then(()=>{for(let i=0;i<supportedSlices.length;i++){let slice=supportedSlices[i],profileUrl=profileUrls[i];if(profileUrl){let typeSchema=tryGetProfile2(profileUrl);slice.typeSchema=typeSchema}}resolve(supportedSlices)}).catch(reject)})}import{buildElementsContext,isPopulated as isPopulated5}from"@medplum/core";import{useContext as useContext4,useMemo as useMemo4}from"react";import{jsx as jsx53}from"react/jsx-runtime";function maybeWrapWithContext(ContextProvider,contextValue,contents){return contextValue!==void 0?jsx53(ContextProvider,{value:contextValue,children:contents}):contents}import{Fragment as Fragment23,jsx as jsx54}from"react/jsx-runtime";function SliceDisplay(props){let{slice,property}=props,sliceElements=slice.typeSchema?.elements??slice.elements,parentContext=useContext4(ElementsContext),contextValue=useMemo4(()=>{if(isPopulated5(sliceElements))return buildElementsContext({parentContext,elements:sliceElements,path:props.path,profileUrl:slice.typeSchema?.url})},[parentContext,props.path,slice.typeSchema?.url,sliceElements]);return maybeWrapWithContext(ElementsContext.Provider,contextValue,jsx54(Fragment23,{children:props.value.map((value,valueIndex)=>jsx54("div",{children:jsx54(ResourcePropertyDisplay,{property,path:props.path,arrayElement:!0,elementDefinitionType:slice.type[0],propertyType:slice.type[0].code,value,ignoreMissingValues:props.ignoreMissingValues,link:props.link})},`${valueIndex}-${props.value.length}`))}))}import{Fragment as Fragment24,jsx as jsx55,jsxs as jsxs28}from"react/jsx-runtime";var MAX_ARRAY_SIZE=50;function ResourceArrayDisplay(props){let{property,propertyType}=props,medplum=useMedplum15(),values=useMemo5(()=>Array.isArray(props.values)?props.values:[],[props.values]),[loading,setLoading]=useState24(!0),[slices,setSlices]=useState24([]),[slicedValues,setSlicedValues]=useState24(()=>[values]),[valuesLength,setValuesLength]=useState24(0),ctx=useContext5(ElementsContext);if(useEffect8(()=>{prepareSlices({medplum,property}).then(slices2=>{setValuesLength(values.length),setSlices(slices2);let limitedValues=values.slice(0,MAX_ARRAY_SIZE),slicedValues2=assignValuesIntoSlices(limitedValues,slices2,property.slicing,ctx.profileUrl);setSlicedValues(slicedValues2),setLoading(!1)}).catch(reason=>{console.error(reason),setLoading(!1)})},[medplum,property,ctx.profileUrl,setSlicedValues,values]),loading)return jsx55("div",{children:"Loading..."});let nonSliceContent;if(property.type[0]?.code!=="Extension"){let nonSliceValues=slicedValues[slices.length],nonSliceElements=nonSliceValues.map((value,valueIndex)=>jsx55("div",{children:jsx55(ResourcePropertyDisplay,{path:props.path,arrayElement:!0,property,propertyType,value,ignoreMissingValues:props.ignoreMissingValues,link:props.link})},`${valueIndex}-${nonSliceValues.length}`));if(props.includeDescriptionListEntry){if(!isPopulated6(props.path))throw new Error("props.path is required when includeDescriptionListEntry is true");let key=props.path.split(".").pop();nonSliceContent=jsx55(DescriptionListEntry,{term:getPathDisplayName2(key),children:nonSliceElements})}else nonSliceContent=jsx55(Fragment24,{children:nonSliceElements})}return jsxs28(Fragment24,{children:[slices.map((slice,sliceIndex)=>{if(!props.path)throw new Error(`Displaying a resource property with slices of type ${props.propertyType} requires path`);let sliceDisplay=jsx55(SliceDisplay,{path:props.path,slice,property,value:slicedValues[sliceIndex],ignoreMissingValues:props.ignoreMissingValues,link:props.link},slice.name);return props.includeDescriptionListEntry&&(sliceDisplay=jsx55(DescriptionListEntry,{term:getPathDisplayName2(slice.name),children:sliceDisplay},slice.name)),sliceDisplay}),nonSliceContent,valuesLength>MAX_ARRAY_SIZE&&jsx55(Group10,{justify:"right",children:jsxs28(Text12,{children:["... ",valuesLength," total values"]})})]})}import{Fragment as Fragment25,jsx as jsx56,jsxs as jsxs29}from"react/jsx-runtime";function ResourcePropertyDisplay(props){let{property,propertyType,value}=props;if(property?.path?.endsWith(".id"))return jsxs29(Flex6,{gap:3,align:"center",children:[value,!isEmpty(value)&&jsx56(CopyButton,{value,timeout:2e3,children:({copied,copy})=>jsx56(Tooltip2,{label:copied?"Copied":"Copy",withArrow:!0,position:"right",children:jsx56(ActionIcon3,{variant:"subtle",color:copied?"teal":"gray",onClick:copy,children:copied?jsx56(IconCheck,{size:"1rem"}):jsx56(IconCopy,{size:"1rem"})})})})]});if(property&&(property.isArray||property.max>1)&&!props.arrayElement)return propertyType===PropertyType.Attachment?jsx56(AttachmentArrayDisplay,{values:value,maxWidth:props.maxWidth,includeDescriptionListEntry:props.includeArrayDescriptionListEntry,property,path:props.path}):jsx56(ResourceArrayDisplay,{path:props.path,property,propertyType,values:value,includeDescriptionListEntry:props.includeArrayDescriptionListEntry,ignoreMissingValues:props.ignoreMissingValues,link:props.link});switch(propertyType){case PropertyType.boolean:return jsx56(Fragment25,{children:value===void 0?"":(!!value).toString()});case PropertyType.SystemString:case PropertyType.string:return props.property?.path?.toLowerCase().includes("secret")?jsx56(SecretFieldDisplay,{value}):jsx56("div",{style:{whiteSpace:"pre-wrap"},children:value});case PropertyType.code:case PropertyType.date:case PropertyType.decimal:case PropertyType.id:case PropertyType.integer:case PropertyType.positiveInt:case PropertyType.unsignedInt:case PropertyType.uri:case PropertyType.url:case PropertyType.xhtml:return jsx56(Fragment25,{children:value});case PropertyType.canonical:return jsx56(ReferenceDisplay,{value:{reference:value},link:props.link});case PropertyType.dateTime:case PropertyType.instant:return jsx56(Fragment25,{children:formatDateTime(value)});case PropertyType.time:return jsx56(Fragment25,{children:formatWallTime(value)});case PropertyType.markdown:return jsx56("pre",{children:value});case PropertyType.Address:return jsx56(AddressDisplay,{value});case PropertyType.Annotation:return jsx56(Fragment25,{children:value?.text});case PropertyType.Attachment:return jsx56(AttachmentDisplay,{value,maxWidth:props.maxWidth});case PropertyType.CodeableConcept:return jsx56(CodeableConceptDisplay,{value});case PropertyType.Coding:return jsx56(CodingDisplay,{value});case PropertyType.ContactDetail:return jsx56(ContactDetailDisplay,{value});case PropertyType.ContactPoint:return jsx56(ContactPointDisplay,{value});case PropertyType.HumanName:return jsx56(HumanNameDisplay,{value});case PropertyType.Identifier:return jsx56(IdentifierDisplay,{value});case PropertyType.Money:return jsx56(MoneyDisplay,{value});case PropertyType.Period:return jsx56(Fragment25,{children:formatPeriod(value)});case PropertyType.Quantity:case PropertyType.Duration:return jsx56(QuantityDisplay,{value});case PropertyType.Range:return jsx56(RangeDisplay,{value});case PropertyType.Ratio:return jsx56(RatioDisplay,{value});case PropertyType.Reference:return jsx56(ReferenceDisplay,{value,link:props.link});case PropertyType.Timing:return jsx56(Fragment25,{children:formatTiming(value)});case PropertyType.Dosage:case PropertyType.UsageContext:if(!props.path)throw new Error(`Displaying property of type ${props.propertyType} requires path`);return jsx56(BackboneElementDisplay,{path:props.path,value:{type:propertyType,value},compact:!0,ignoreMissingValues:props.ignoreMissingValues});case PropertyType.Extension:if(!props.path)throw new Error(`Displaying property of type ${props.propertyType} requires path`);return jsx56(ExtensionDisplay,{path:props.path,value,compact:!0,ignoreMissingValues:props.ignoreMissingValues,elementDefinitionType:props.elementDefinitionType});default:if(!property)throw new Error(`Displaying property of type ${props.propertyType} requires element schema`);if(!props.path)throw new Error(`Displaying property of type ${props.propertyType} requires path`);return jsx56(BackboneElementDisplay,{path:props.path,value:{type:property.type[0].code,value},compact:!0,ignoreMissingValues:props.ignoreMissingValues})}}function SecretFieldDisplay(props){let[isVisible,setIsVisible]=useState25(!1),secretValue=props.value??"",hasValue=!isEmpty(secretValue),MASK="\u2022".repeat(8);return jsxs29(Flex6,{gap:3,align:"center",children:[isVisible?jsx56("div",{style:{whiteSpace:"pre-wrap"},children:secretValue}):jsx56("div",{style:{whiteSpace:"pre-wrap"},"aria-hidden":"true",children:hasValue?MASK:""}),hasValue&&jsxs29(Fragment25,{children:[jsx56(CopyButton,{value:props.value,timeout:2e3,children:({copied,copy})=>jsx56(Tooltip2,{label:copied?"Copied":"Copy secret",withArrow:!0,position:"right",children:jsx56(ActionIcon3,{variant:"subtle",color:copied?"teal":"gray",onClick:copy,"aria-label":copied?"Copied":"Copy secret",children:copied?jsx56(IconCheck,{size:"1rem"}):jsx56(IconCopy,{size:"1rem"})})})}),jsx56(Tooltip2,{label:isVisible?"Hide secret":"Show secret",withArrow:!0,position:"right",children:jsx56(ActionIcon3,{variant:"subtle",color:"gray",onClick:()=>setIsVisible(!isVisible),"aria-label":isVisible?"Hide secret":"Show secret",children:isVisible?jsx56(IconEyeOff,{size:"1rem"}):jsx56(IconEye,{size:"1rem"})})})]})]})}import{jsx as jsx57,jsxs as jsxs30}from"react/jsx-runtime";var EXTENSION_KEYS2=["extension","modifierExtension"],IGNORED_PROPERTIES2=DEFAULT_IGNORED_PROPERTIES.filter(prop=>!EXTENSION_KEYS2.includes(prop));function BackboneElementDisplay(props){let typedValue=props.value,{value,type:typeName}=typedValue,parentElementsContext=useContext6(ElementsContext),profileUrl=props.profileUrl??parentElementsContext?.profileUrl,typeSchema=useMemo6(()=>tryGetDataType(typeName,profileUrl),[profileUrl,typeName]),newElementsContext=useMemo6(()=>{if(typeSchema)return buildElementsContext2({parentContext:parentElementsContext,elements:typeSchema.elements,path:props.path,profileUrl:typeSchema.url,accessPolicyResource:props.accessPolicyResource})},[typeSchema,parentElementsContext,props.path,props.accessPolicyResource]);if(isEmpty2(value))return null;if(!typeSchema)return jsxs30("div",{children:[typeName,"\xA0not implemented"]});if(typeof value=="object"&&"name"in value&&Object.keys(value).length===1&&typeof value.name=="string")return jsx57("div",{children:value.name});let elementsContext=newElementsContext??parentElementsContext;return maybeWrapWithContext(ElementsContext.Provider,newElementsContext,jsx57(DescriptionList,{compact:props.compact,children:Object.entries(elementsContext.elements).map(([key,property])=>{if(EXTENSION_KEYS2.includes(key)&&isEmpty2(property.slicing?.slices))return null;if(IGNORED_PROPERTIES2.includes(key))return null;if(DEFAULT_IGNORED_NON_NESTED_PROPERTIES.includes(key)&&property.path.split(".").length===2||key.includes("."))return null;let[propertyValue,propertyType]=getValueAndType(typedValue,key,elementsContext.profileUrl);if((props.ignoreMissingValues||property.max===0)&&isEmpty2(propertyValue)||props.path.endsWith(".extension")&&(key==="url"||key==="id"))return null;let isArrayProperty=property.max>1||property.isArray,resourcePropertyDisplay=jsx57(ResourcePropertyDisplay,{property,propertyType,path:props.path+"."+key,value:propertyValue,ignoreMissingValues:props.ignoreMissingValues,includeArrayDescriptionListEntry:isArrayProperty,link:props.link},key);return isArrayProperty?resourcePropertyDisplay:jsx57(DescriptionListEntry,{term:getPathDisplayName3(key),children:resourcePropertyDisplay},key)})}))}import{Box as Box7}from"@mantine/core";import{buildElementsContext as buildElementsContext4,tryGetDataType as tryGetDataType2}from"@medplum/core";import{useContext as useContext23,useMemo as useMemo22,useState as useState46}from"react";import{Stack as Stack14}from"@mantine/core";import{getPathDisplayName as getPathDisplayName5}from"@medplum/core";import{useContext as useContext22,useMemo as useMemo21,useState as useState45}from"react";import{Group as Group11,Input}from"@mantine/core";import{useContext as useContext7}from"react";var FormSection_default={dimmed:"FormSection_dimmed",preserveBreaks:"FormSection_preserveBreaks"};import{Tooltip as Tooltip3}from"@mantine/core";import{jsx as jsx58}from"react/jsx-runtime";var READ_ONLY_TOOLTIP_TEXT="Read Only";function maybeWrapWithTooltip(tooltipText,children){return tooltipText?jsx58(Tooltip3.Floating,{label:tooltipText,children}):children}import{jsx as jsx59,jsxs as jsxs31}from"react/jsx-runtime";function CheckboxFormSection(props){let{debugMode}=useContext7(ElementsContext),label;return debugMode&&props.fhirPath?label=`${props.title} - ${props.fhirPath}`:label=props.title,maybeWrapWithTooltip(props?.readonly?READ_ONLY_TOOLTIP_TEXT:void 0,jsxs31(Group11,{wrap:"nowrap","data-testid":props.testId,children:[jsx59("div",{children:props.children}),jsx59("div",{children:jsx59(Input.Wrapper,{id:props.htmlFor,label,classNames:{label:props?.readonly?FormSection_default.dimmed:void 0},description:props.description,withAsterisk:props.withAsterisk,children:null})})]}))}import{Input as Input2}from"@mantine/core";import{useContext as useContext8}from"react";import{jsx as jsx60}from"react/jsx-runtime";function FormSection(props){let{debugMode}=useContext8(ElementsContext),label;return debugMode&&props.fhirPath?label=`${props.title} - ${props.fhirPath}`:label=props.title,maybeWrapWithTooltip(props?.readonly?READ_ONLY_TOOLTIP_TEXT:void 0,jsx60(Input2.Wrapper,{id:props.htmlFor,label,classNames:{label:clsx_default({[FormSection_default.dimmed]:props?.readonly},FormSection_default.preserveBreaks)},description:props.description,withAsterisk:props.withAsterisk,error:getErrorsForInput(props.outcome,props.errorExpression??props.htmlFor),"data-testid":props.testId,children:props.children}))}import{capitalize,isEmpty as isEmpty3}from"@medplum/core";function setPropertyValue(obj,key,propName,elementDefinition,value){let types=elementDefinition.type;if(types.length>1)for(let type of types){let compoundKey=key.replace("[x]",capitalize(type.code));compoundKey in obj&&delete obj[compoundKey]}return isEmpty3(value)?obj[propName]=void 0:obj[propName]=value,obj}function isSupportedProfileStructureDefinition(profile){return!!profile&&!isEmpty3(profile.url)&&!isEmpty3(profile.name)}import{Checkbox as Checkbox4,Group as Group25,NativeSelect as NativeSelect9,Textarea as Textarea2,TextInput as TextInput17}from"@mantine/core";import{applyDefaultValuesToElement,capitalize as capitalize2,getPathDifference,HTTP_HL7_ORG,isComplexTypeCode,isEmpty as isEmpty6,isPopulated as isPopulated11,PropertyType as PropertyType2}from"@medplum/core";import{useContext as useContext21,useMemo as useMemo20,useState as useState44}from"react";import{useState as useState26}from"react";import{jsx as jsx61}from"react/jsx-runtime";function CodeableConceptInput(props){let{defaultValue:defaultValue2,onChange,withHelpText,outcome:_outcome,path:_path,valuePath:_valuePath,...rest}=props,[value,setValue]=useState26(defaultValue2);function handleChange(newValues){let newConcept=valueSetElementToCodeableConcept(newValues);setValue(newConcept),onChange&&onChange(newConcept)}return jsx61(ValueSetAutocomplete,{defaultValue:value&&codeableConceptToValueSetElement(value),onChange:handleChange,withHelpText:withHelpText??!0,...rest})}function codeableConceptToValueSetElement(concept){return concept.coding?.map(c=>({system:c.system,code:c.code,display:c.display}))}function valueSetElementToCodeableConcept(elements){if(elements.length!==0)return{coding:elements.map(e=>({system:e.system,code:e.code,display:e.display}))}}import{useState as useState27}from"react";import{jsx as jsx62}from"react/jsx-runtime";function CodingInput(props){let{defaultValue:defaultValue2,onChange,withHelpText,response,...rest}=props,[value,setValue]=useState27(response?.answer?.[0]?.valueCoding??defaultValue2);function handleChange(newValues){let newValue=newValues[0],newConcept=newValue&&valueSetElementToCoding(newValue);setValue(newConcept),onChange&&onChange(newConcept)}return jsx62(ValueSetAutocomplete,{defaultValue:value?codingToValueSetElement(value):void 0,maxValues:1,onChange:handleChange,withHelpText:withHelpText??!0,...rest})}function codingToValueSetElement(coding){return{system:coding.system,code:coding.code,display:coding.display}}function valueSetElementToCoding(element){return{system:element.system,code:element.code,display:element.display}}import{Group as Group13,TextInput as TextInput10}from"@mantine/core";import{useContext as useContext10,useMemo as useMemo8,useRef as useRef9,useState as useState29}from"react";import{Group as Group12,NativeSelect as NativeSelect3,TextInput as TextInput9}from"@mantine/core";import{useContext as useContext9,useMemo as useMemo7,useRef as useRef8,useState as useState28}from"react";import{jsx as jsx63,jsxs as jsxs32}from"react/jsx-runtime";function ContactPointInput(props){let{path,outcome}=props,{elementsByPath,getExtendedProps}=useContext9(ElementsContext),[contactPoint,setContactPoint]=useState28(props.defaultValue),ref=useRef8(contactPoint);ref.current=contactPoint;let[systemElement,useElement,valueElement]=useMemo7(()=>["system","use","value"].map(field=>elementsByPath[path+"."+field]),[elementsByPath,path]),[systemProps,useProps,valueProps]=useMemo7(()=>["system","use","value"].map(field=>getExtendedProps(path+"."+field)),[getExtendedProps,path]);function setContactPointWrapper(newValue){newValue&&Object.keys(newValue).length===0&&(newValue=void 0),setContactPoint(newValue),props.onChange&&props.onChange(newValue)}function setSystem(system){let newValue={...ref.current,system};system||delete newValue.system,setContactPointWrapper(newValue)}function setUse(use){let newValue={...ref.current,use};use||delete newValue.use,setContactPointWrapper(newValue)}function setValue(value){let newValue={...ref.current,value};value||delete newValue.value,setContactPointWrapper(newValue)}let errorPath=props.valuePath??path;return jsxs32(Group12,{gap:"xs",grow:!0,wrap:"nowrap",align:"flex-start",children:[jsx63(NativeSelect3,{disabled:props.disabled||systemProps?.readonly,"data-testid":"system",defaultValue:contactPoint?.system,required:(systemElement?.min??0)>0,onChange:e=>setSystem(e.currentTarget.value),data:["","email","phone","fax","pager","sms","other"],error:getErrorsForInput(outcome,errorPath+".system")}),jsx63(NativeSelect3,{disabled:props.disabled||useProps?.readonly,"data-testid":"use",defaultValue:contactPoint?.use,required:(useElement?.min??0)>0,onChange:e=>setUse(e.currentTarget.value),data:["","home","work","temp","old","mobile"],error:getErrorsForInput(outcome,errorPath+".use")}),jsx63(TextInput9,{disabled:props.disabled||valueProps?.readonly,placeholder:"Value",defaultValue:contactPoint?.value,required:(valueElement?.min??0)>0,onChange:e=>setValue(e.currentTarget.value),error:getErrorsForInput(outcome,errorPath+".value")})]})}import{jsx as jsx64,jsxs as jsxs33}from"react/jsx-runtime";function ContactDetailInput(props){let[contactDetail,setContactDetail]=useState29(props.defaultValue),ref=useRef9(contactDetail);ref.current=contactDetail;let{getExtendedProps}=useContext10(ElementsContext),[nameProps,telecomProps]=useMemo8(()=>["name","telecom"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]);function setContactDetailWrapper(newValue){setContactDetail(newValue),props.onChange&&props.onChange(newValue)}function setName(name){let newValue={...ref.current,name};name||delete newValue.name,setContactDetailWrapper(newValue)}function setTelecom(telecom){let newValue={...ref.current,telecom:telecom&&[telecom]};telecom||delete newValue.telecom,setContactDetailWrapper(newValue)}return jsxs33(Group13,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx64(TextInput10,{disabled:props.disabled||nameProps?.readonly,"data-testid":props.name+"-name",name:props.name+"-name",placeholder:"Name",style:{width:180},defaultValue:contactDetail?.name,onChange:e=>setName(e.currentTarget.value)}),jsx64(ContactPointInput,{disabled:props.disabled||telecomProps?.readonly,name:props.name+"-telecom",path:props.path+".telecom",defaultValue:contactDetail?.telecom?.[0],onChange:setTelecom,outcome:props.outcome})]})}import{TextInput as TextInput11}from"@mantine/core";import{isValidDate}from"@medplum/core";function convertIsoToLocal(isoString){if(!isoString)return"";let date=new Date(isoString);return isValidDate(date)?date.toLocaleDateString("sv")+"T"+date.toLocaleTimeString("sv"):""}function convertLocalToIso(localString){if(!localString)return"";let date=new Date(localString);return isValidDate(date)?date.toISOString():""}import{jsx as jsx65}from"react/jsx-runtime";function DateTimeInput(props){return jsx65(TextInput11,{id:props.name,name:props.name,label:props.label,"data-autofocus":props.autoFocus,"data-testid":props["data-testid"]??props.name,placeholder:props.placeholder,required:props.required,disabled:props.disabled,type:getInputType(),step:1,defaultValue:convertIsoToLocal(props.defaultValue),autoFocus:props.autoFocus,error:getErrorsForInput(props.outcome,props.name),onChange:e=>{if(props.onChange){let newValue=e.currentTarget.value;props.onChange(convertLocalToIso(newValue))}}})}function getInputType(){return"datetime-local"}import{isPopulated as isPopulated7,isProfileLoaded as isProfileLoaded2}from"@medplum/core";import{useMedplum as useMedplum16}from"@medplum/react-hooks";import{useEffect as useEffect9,useMemo as useMemo9,useState as useState30}from"react";import{jsx as jsx66}from"react/jsx-runtime";function ExtensionInput(props){let{propertyType}=props,medplum=useMedplum16(),profileUrl=useMemo9(()=>{if(isPopulated7(propertyType.profile))return propertyType.profile[0]},[propertyType]),[loadingProfile,setLoadingProfile]=useState30(profileUrl!==void 0);return useEffect9(()=>{profileUrl&&(setLoadingProfile(!0),medplum.requestProfileSchema(profileUrl).then(()=>setLoadingProfile(!1)).catch(reason=>{setLoadingProfile(!1),console.warn(reason)}))},[medplum,profileUrl]),profileUrl&&(loadingProfile||!isProfileLoaded2(profileUrl))?jsx66("div",{children:"Loading..."}):jsx66(BackboneElementInput,{profileUrl,path:props.path,typeName:"Extension",defaultValue:props.defaultValue,onChange:props.onChange})}import{Group as Group14,NativeSelect as NativeSelect4,TextInput as TextInput12}from"@mantine/core";import{useContext as useContext11,useMemo as useMemo10,useState as useState31}from"react";import{jsx as jsx67,jsxs as jsxs34}from"react/jsx-runtime";function HumanNameInput(props){let{outcome,path}=props,[value,setValue]=useState31(props.defaultValue),{getExtendedProps}=useContext11(ElementsContext),[useProps,prefixProps,givenProps,familyProps,suffixProps]=useMemo10(()=>["use","prefix","given","family","suffix"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}function setUse(use){setValueWrapper({...value,use:use||void 0})}function setPrefix(prefix){setValueWrapper({...value,prefix:prefix?prefix.split(" "):void 0})}function setGiven(given){setValueWrapper({...value,given:given?given.split(" "):void 0})}function setFamily(family){setValueWrapper({...value,family:family||void 0})}function setSuffix(suffix){setValueWrapper({...value,suffix:suffix?suffix.split(" "):void 0})}let errorPath=props.valuePath??path;return jsxs34(Group14,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx67(NativeSelect4,{disabled:props.disabled||useProps?.readonly,defaultValue:value?.use,name:props.name+"-use","data-testid":"use",onChange:e=>setUse(e.currentTarget.value),data:["","temp","old","usual","official","nickname","anonymous","maiden"],error:getErrorsForInput(outcome,errorPath+".use")}),jsx67(TextInput12,{disabled:props.disabled||prefixProps?.readonly,placeholder:"Prefix",name:props.name+"-prefix",defaultValue:value?.prefix?.join(" "),onChange:e=>setPrefix(e.currentTarget.value),error:getErrorsForInput(outcome,errorPath+".prefix")}),jsx67(TextInput12,{disabled:props.disabled||givenProps?.readonly,placeholder:"Given",name:props.name+"-given",defaultValue:value?.given?.join(" "),onChange:e=>setGiven(e.currentTarget.value),error:getErrorsForInput(outcome,errorPath+".given")}),jsx67(TextInput12,{disabled:props.disabled||familyProps?.readonly,name:props.name+"-family",placeholder:"Family",defaultValue:value?.family,onChange:e=>setFamily(e.currentTarget.value),error:getErrorsForInput(outcome,errorPath+".family")}),jsx67(TextInput12,{disabled:props.disabled||suffixProps?.readonly,placeholder:"Suffix",name:props.name+"-suffix",defaultValue:value?.suffix?.join(" "),onChange:e=>setSuffix(e.currentTarget.value),error:getErrorsForInput(outcome,errorPath+".suffix")})]})}import{Group as Group15,TextInput as TextInput13}from"@mantine/core";import{useContext as useContext12,useMemo as useMemo11,useState as useState32}from"react";import{jsx as jsx68,jsxs as jsxs35}from"react/jsx-runtime";function IdentifierInput(props){let[value,setValue]=useState32(props.defaultValue),{elementsByPath,getExtendedProps}=useContext12(ElementsContext),[systemElement,valueElement]=useMemo11(()=>["system","value"].map(field=>elementsByPath[props.path+"."+field]),[elementsByPath,props.path]),[systemProps,valueProps]=useMemo11(()=>["system","value"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}let errorPath=props.valuePath??props.path;return jsxs35(Group15,{gap:"xs",grow:!0,wrap:"nowrap",align:"flex-start",children:[jsx68(TextInput13,{disabled:props.disabled||systemProps?.readonly,placeholder:"System",required:(systemElement?.min??0)>0,defaultValue:value?.system,onChange:e=>setValueWrapper({...value,system:e.currentTarget.value}),error:getErrorsForInput(props.outcome,errorPath+".system")}),jsx68(TextInput13,{disabled:props.disabled||valueProps?.readonly,placeholder:"Value",required:(valueElement?.min??0)>0,defaultValue:value?.value,onChange:e=>setValueWrapper({...value,value:e.currentTarget.value}),error:getErrorsForInput(props.outcome,errorPath+".value")})]})}import{NativeSelect as NativeSelect5,TextInput as TextInput14}from"@mantine/core";import{useCallback as useCallback7,useContext as useContext13,useMemo as useMemo12,useState as useState33}from"react";import{jsx as jsx69}from"react/jsx-runtime";var data=["USD","EUR","CAD","GBP","AUD"];function MoneyInput(props){let{onChange}=props,[value,setValue]=useState33(props.defaultValue),{getExtendedProps}=useContext13(ElementsContext),[currencyProps,valueProps]=useMemo12(()=>["currency","value"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]),setValueWrapper=useCallback7(newValue=>{setValue(newValue),onChange&&onChange(newValue)},[onChange]),handleCurrencyChange=useCallback7(e=>{setValueWrapper({...value,currency:e.currentTarget.value})},[value,setValueWrapper]),handleValueChange=useCallback7(e=>{setValueWrapper({...value,value:e.currentTarget.valueAsNumber})},[value,setValueWrapper]),select=jsx69(NativeSelect5,{disabled:props.disabled||currencyProps?.readonly,defaultValue:value?.currency,data,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:handleCurrencyChange});return jsx69(TextInput14,{disabled:props.disabled||valueProps?.readonly,type:"number",name:props.name,label:props.label,placeholder:props.placeholder??"Value",defaultValue:value?.value?.toString()??"USD",leftSection:jsx69(IconCurrencyDollar,{size:14}),rightSection:select,rightSectionWidth:92,onChange:handleValueChange})}import{Group as Group16}from"@mantine/core";import{useContext as useContext14,useMemo as useMemo13,useState as useState34}from"react";import{jsx as jsx70,jsxs as jsxs36}from"react/jsx-runtime";function PeriodInput(props){let[value,setValue]=useState34(props.defaultValue),{getExtendedProps}=useContext14(ElementsContext),[startProps,endProps]=useMemo13(()=>["start","end"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs36(Group16,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx70(DateTimeInput,{disabled:props.disabled||startProps?.readonly,name:props.name+".start",placeholder:"Start",defaultValue:value?.start,onChange:newValue=>setValueWrapper({...value,start:newValue})}),jsx70(DateTimeInput,{disabled:props.disabled||endProps?.readonly,name:props.name+".end",placeholder:"End",defaultValue:value?.end,onChange:newValue=>setValueWrapper({...value,end:newValue})})]})}import{Group as Group17,NativeSelect as NativeSelect6,TextInput as TextInput15}from"@mantine/core";import{useContext as useContext15,useMemo as useMemo14,useState as useState35}from"react";import{jsx as jsx71,jsxs as jsxs37}from"react/jsx-runtime";function QuantityInput(props){let[value,setValue]=useState35(props.defaultValue),{getExtendedProps}=useContext15(ElementsContext),[comparatorProps,valueProps,unitProps]=useMemo14(()=>["comparator","value","unit"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs37(Group17,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx71(NativeSelect6,{disabled:props.disabled||comparatorProps?.readonly,style:{width:80},"data-testid":props.name+"-comparator",defaultValue:value?.comparator,data:["","<","<=",">=",">"],onChange:e=>setValueWrapper({...value,comparator:e.currentTarget.value})}),jsx71(TextInput15,{disabled:props.disabled||valueProps?.readonly,id:props.name,name:props.name,required:props.required,"data-autofocus":props.autoFocus,"data-testid":props.name+"-value",type:"number",placeholder:"Value",defaultValue:value?.value,autoFocus:props.autoFocus,step:"any",onWheel:e=>{props.disableWheel&&e.currentTarget.blur()},onChange:e=>{setValueWrapper({...value,value:tryParseNumber(e.currentTarget.value)})}}),jsx71(TextInput15,{disabled:props.disabled||unitProps?.readonly,placeholder:"Unit","data-testid":props.name+"-unit",defaultValue:value?.unit,onChange:e=>setValueWrapper({...value,unit:e.currentTarget.value})})]})}function tryParseNumber(str){if(str)return Number.parseFloat(str)}import{Group as Group18}from"@mantine/core";import{useContext as useContext16,useMemo as useMemo15,useState as useState36}from"react";import{jsx as jsx72,jsxs as jsxs38}from"react/jsx-runtime";function RangeInput(props){let[value,setValue]=useState36(props.defaultValue),{getExtendedProps}=useContext16(ElementsContext),[lowProps,highProps]=useMemo15(()=>["low","high"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs38(Group18,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx72(QuantityInput,{path:props.path+".low",disabled:props.disabled||lowProps?.readonly,name:props.name+"-low",defaultValue:value?.low,onChange:v=>setValueWrapper({...value,low:v})}),jsx72(QuantityInput,{path:props.path+".high",disabled:props.disabled||highProps?.readonly,name:props.name+"-high",defaultValue:value?.high,onChange:v=>setValueWrapper({...value,high:v})})]})}import{Group as Group19}from"@mantine/core";import{useContext as useContext17,useMemo as useMemo16,useState as useState37}from"react";import{jsx as jsx73,jsxs as jsxs39}from"react/jsx-runtime";function RatioInput(props){let[value,setValue]=useState37(props.defaultValue),{getExtendedProps}=useContext17(ElementsContext),[numeratorProps,denominatorProps]=useMemo16(()=>["numerator","denominator"].map(field=>getExtendedProps(props.path+"."+field)),[getExtendedProps,props.path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs39(Group19,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx73(QuantityInput,{path:props.path+".numerator",disabled:props.disabled||numeratorProps?.readonly,name:props.name+"-numerator",defaultValue:value?.numerator,onChange:v=>setValueWrapper({...value,numerator:v})}),jsx73(QuantityInput,{path:props.path+".denominator",disabled:props.disabled||denominatorProps?.readonly,name:props.name+"-denominator",defaultValue:value?.denominator,onChange:v=>setValueWrapper({...value,denominator:v})})]})}import{Group as Group21,NativeSelect as NativeSelect7}from"@mantine/core";import{LRUCache,ReadablePromise,createReference as createReference2,isEmpty as isEmpty4,isPopulated as isPopulated9,tryGetProfile as tryGetProfile3}from"@medplum/core";import{useMedplum as useMedplum18}from"@medplum/react-hooks";import{useCallback as useCallback9,useEffect as useEffect10,useMemo as useMemo17,useRef as useRef10,useState as useState39}from"react";import{Group as Group20,Text as Text13}from"@mantine/core";import{getDisplayString as getDisplayString3,getReferenceString as getReferenceString3,isPopulated as isPopulated8}from"@medplum/core";import{useMedplum as useMedplum17,useResource as useResource2}from"@medplum/react-hooks";import{forwardRef as forwardRef4,useCallback as useCallback8,useState as useState38}from"react";import{jsx as jsx74,jsxs as jsxs40}from"react/jsx-runtime";var SEARCH_CODES={Device:"device-name",Observation:"code",Subscription:"criteria",User:"email:contains"},NAME_RESOURCE_TYPES=["AccessPolicy","Account","ActivityDefinition","Bot","CapabilityStatement","CareTeam","ClientApplication","CodeSystem","CompartmentDefinition","ConceptMap","EffectEvidenceSynthesis","Endpoint","EventDefinition","Evidence","EvidenceVariable","ExampleScenario","GraphDefinition","Group","HealthcareService","ImplementationGuide","InsurancePlan","Library","Location","Measure","MedicinalProduct","MessageDefinition","NamingSystem","OperationDefinition","Organization","Patient","Person","PlanDefinition","Practitioner","Project","Questionnaire","RelatedPerson","ResearchDefinition","ResearchElementDefinition","ResearchStudy","RiskEvidenceSynthesis","SearchParameter","StructureDefinition","StructureMap","TerminologyCapabilities","TestScript","UserConfiguration","ValueSet"];function toOption3(resource){return{value:getReferenceString3(resource)??"",label:getDisplayString3(resource),resource}}function ResourceInput(props){let medplum=useMedplum17(),{resourceType,searchCriteria}=props,[outcome,setOutcome]=useState38(),defaultValue2=useResource2(props.defaultValue,setOutcome),ItemComponent3=props.itemComponent??DefaultItemComponent2,onChange=props.onChange,loadValues=useCallback8(async(input,signal)=>{let searchCode=getSearchParamForResourceType(resourceType),searchParams=new URLSearchParams({[searchCode]:input??"",_count:"10",...searchCriteria});return await medplum.searchResources(resourceType,searchParams,{signal})},[medplum,resourceType,searchCriteria]),handleChange=useCallback8(newResources=>{onChange&&onChange(newResources[0])},[onChange]);return isPopulated8(props.defaultValue)&&!outcome&&!defaultValue2?null:jsx74(AsyncAutocomplete,{disabled:props.disabled,name:props.name,label:props.label,error:props.error,required:props.required,itemComponent:ItemComponent3,defaultValue:defaultValue2,placeholder:props.placeholder,maxValues:1,toOption:toOption3,loadOptions:loadValues,onChange:handleChange,clearable:!0})}var DefaultItemComponent2=forwardRef4(({label,resource,active:_active,...others},ref)=>jsx74("div",{ref,...others,children:jsxs40(Group20,{wrap:"nowrap",children:[jsx74(ResourceAvatar,{value:resource}),jsxs40("div",{children:[jsx74(Text13,{children:label}),jsx74(Text13,{size:"xs",c:"dimmed",children:resource.birthDate||resource.id})]})]})}));function getSearchParamForResourceType(resourceType){return SEARCH_CODES[resourceType]??(NAME_RESOURCE_TYPES.includes(resourceType)?"name":"_id")}import{Fragment as Fragment26,jsx as jsx75,jsxs as jsxs41}from"react/jsx-runtime";function ReferenceInput(props){let{onChange}=props,medplum=useMedplum18(),[value,setValue]=useState39(props.defaultValue),[targetTypes,setTargetTypes]=useState39(()=>createTargetTypes(props.targetTypes)),[targetType,setTargetType]=useState39(()=>getInitialTargetType(props.defaultValue,targetTypes)),promiseCache=useRef10(new LRUCache),searchCriteria=useMemo17(()=>targetType?.type==="profile"?{...props.searchCriteria,_profile:targetType.value}:props.searchCriteria,[props.searchCriteria,targetType]);useEffect10(()=>{let anyToFetch=!1,newTargetTypePromises=targetTypes?.map(tt=>{if(!shouldFetchResourceType(tt))return Promise.resolve(tt);anyToFetch=!0;let cacheKey=tt.value,cached=promiseCache.current.get(cacheKey);if(cached)return cached;let promise=fetchResourceTypeOfProfile(medplum,tt.value).then(profile=>{let newTargetType={...tt};return profile?isPopulated9(profile.type)?(newTargetType.resourceType=profile.type,newTargetType.name=profile.name,newTargetType.title=profile.title):(console.error(`StructureDefinition.type missing for ${tt.value}`),newTargetType.error="StructureDefinition.type missing"):(console.error(`StructureDefinition not found for ${tt.value}`),newTargetType.error="StructureDefinition not found"),newTargetType}).catch(reason=>(console.error(reason),{...tt,error:reason})),readablePromise=new ReadablePromise(promise);return promiseCache.current.set(cacheKey,readablePromise),readablePromise});!newTargetTypePromises||!anyToFetch||Promise.all(newTargetTypePromises).then(newTargetTypes=>{if(setTargetTypes(newTargetTypes),!targetType)return;let index=newTargetTypes.findIndex(tt=>tt.value===targetType.value||tt.resourceType===targetType.resourceType);if(index===-1){console.debug(`defaultValue had unexpected resourceType: ${targetType.resourceType}`);return}setTargetType(newTargetTypes[index])}).catch(console.error)},[medplum,targetType,targetTypes]);let setValueHelper=useCallback9(item=>{let newValue=item?createReference2(item):void 0;setValue(newValue),onChange&&onChange(newValue)},[onChange]),typeSelectOptions=useMemo17(()=>targetTypes?targetTypes.map(tt=>({value:tt.value,label:tt.type==="profile"?tt.title??tt.name??tt.resourceType??tt.value:tt.value})):[],[targetTypes]);return jsxs41(Fragment26,{children:[props.name&&jsx75("input",{type:"hidden",name:props.name,value:value?.reference??""}),jsxs41(Group21,{gap:"xs",grow:!0,wrap:"nowrap",children:[targetTypes&&targetTypes.length>1&&jsx75(NativeSelect7,{name:props.name+"-resourceType",disabled:props.disabled,"data-autofocus":props.autoFocus,"data-testid":"reference-input-resource-type-select",defaultValue:targetType?.resourceType,autoFocus:props.autoFocus,onChange:e=>{let newValue=e.currentTarget.value,newTargetType=targetTypes.find(tt=>tt.value===newValue);setTargetType(newTargetType)},data:typeSelectOptions}),!targetTypes&&jsx75(ResourceTypeInput,{disabled:props.disabled,autoFocus:props.autoFocus,testId:"reference-input-resource-type-input",defaultValue:targetType?.resourceType,onChange:newResourceType=>{setTargetType(newResourceType?{type:"resourceType",value:newResourceType,resourceType:newResourceType}:void 0)},name:props.name+"-resourceType",placeholder:"Resource Type"}),jsx75(ResourceInput,{resourceType:targetType?.resourceType,name:props.name+"-id",required:props.required,placeholder:props.placeholder,defaultValue:value,searchCriteria,onChange:setValueHelper,disabled:props.disabled})]})]})}function createTargetTypes(resourceTypesAndProfileUrls){if(!resourceTypesAndProfileUrls||resourceTypesAndProfileUrls.length===0||resourceTypesAndProfileUrls.length===1&&resourceTypesAndProfileUrls[0]==="Resource")return;let results=[];for(let value of resourceTypesAndProfileUrls)value.includes("/")?results.push({type:"profile",value}):results.push({type:"resourceType",value,resourceType:value});return results}function getInitialTargetType(defaultValue2,targetTypes){let defaultValueResourceType=defaultValue2?.reference?.split("/")[0];if(defaultValueResourceType){let targetType=targetTypes?.find(tt=>tt.resourceType===defaultValueResourceType);return targetType||{type:"resourceType",value:defaultValueResourceType,resourceType:defaultValueResourceType}}if(targetTypes&&targetTypes.length>0)return targetTypes[0]}async function fetchResourceTypeOfProfile(medplum,profileUrl){let profile=tryGetProfile3(profileUrl);if(profile)return{type:profile.type,name:profile.name,title:profile.title};let query=`{
104
104
  StructureDefinitionList(url: "${profileUrl}", _sort: "_lastUpdated", _count: 1) {
105
105
  type,