@medplum/react 3.0.12 → 3.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +2 -2
- package/package.json +7 -7
package/dist/esm/index.mjs
CHANGED
|
@@ -62,7 +62,7 @@ var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropD
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}`.replace(/\s+/g," ")}function getResourcesFromResponse(response,query){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),sortByRelevance(dedupeResources(resources),query).slice(0,5)}function dedupeResources(resources){let ids=new Set,result=[];for(let resource of resources)ids.has(resource.id)||(ids.add(resource.id),result.push(resource));return result}function sortByRelevance(resources,query){return resources.sort((a2,b2)=>getResourceScore(b2,query)-getResourceScore(a2,query))}function getResourceScore(resource,query){let bestScore=0;if(resource.identifier)for(let identifier of resource.identifier)bestScore=Math.max(bestScore,getStringScore(identifier.value,query));if(resource.resourceType==="Patient"&&resource.name)for(let name of resource.name)bestScore=Math.max(bestScore,getStringScore(formatHumanName2(name),query));return bestScore}function getStringScore(str,query){if(!str)return 0;let index=str.toLowerCase().indexOf(query.toLowerCase());return index<0?0:100-index}import{jsx as jsx12,jsxs as jsxs5}from"react/jsx-runtime";function Header(props){let profile=W(),[userMenuOpened,setUserMenuOpened]=useState4(!1);return jsx12(MantineAppShell.Header,{p:8,style:{zIndex:101},children:jsxs5(Group5,{justify:"space-between",children:[jsxs5(Group5,{gap:"xs",children:[jsx12(UnstyledButton,{className:Header_default.logoButton,onClick:props.navbarToggle,children:props.logo}),!props.headerSearchDisabled&&jsx12(HeaderSearchInput,{pathname:props.pathname,searchParams:props.searchParams})]}),jsxs5(Group5,{gap:"lg",pr:"sm",children:[props.notifications,jsxs5(Menu2,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:userMenuOpened,onClose:()=>setUserMenuOpened(!1),children:[jsx12(Menu2.Target,{children:jsx12(UnstyledButton,{className:clsx_default(Header_default.user,{[Header_default.userActive]:userMenuOpened}),onClick:()=>setUserMenuOpened(o=>!o),children:jsxs5(Group5,{gap:7,children:[jsx12(ResourceAvatar,{value:profile,radius:"xl",size:24}),jsx12(Text3,{size:"sm",className:Header_default.userName,children:formatHumanName3(profile?.name?.[0])}),jsx12(IconChevronDown,{size:12,stroke:1.5})]})})}),jsx12(Menu2.Dropdown,{children:jsx12(HeaderDropdown,{version:props.version})})]})]})]})})}import{Button as Button2,AppShell as MantineAppShell2,ScrollArea,Space,Text as Text5}from"@mantine/core";import{Fragment as Fragment4,useState as useState7}from"react";import{Button,Group as Group6,Modal,NativeSelect as NativeSelect2,Stack as Stack2,TextInput as TextInput3}from"@mantine/core";import{showNotification as showNotification2}from"@mantine/notifications";import{deepClone,normalizeErrorString as normalizeErrorString3}from"@medplum/core";function parseForm(form){let result={};for(let element of Array.from(form.elements))element instanceof HTMLInputElement?parseInputElement(result,element):element instanceof HTMLTextAreaElement?result[element.name]=element.value:element instanceof HTMLSelectElement&&parseSelectElement(result,element);return result}function parseInputElement(result,el){el.disabled||(el.type==="checkbox"||el.type==="radio")&&!el.checked||(result[el.name]=el.value)}function parseSelectElement(result,el){result[el.name]=el.value}import{jsx as jsx13}from"react/jsx-runtime";function Form(props){return jsx13("form",{style:props.style,"data-testid":props.testid,onSubmit:e=>{e.preventDefault();let formData=parseForm(e.target);props.onSubmit&&props.onSubmit(formData)},children:props.children})}import{jsx as jsx14,jsxs as jsxs6}from"react/jsx-runtime";function BookmarkDialog(props){let medplum=a(),config=medplum.getUserConfiguration();function submitHandler(formData){let{menuname,bookmarkname:name}=formData,target=`${props.pathname}?${props.searchParams.toString()}`,newConfig=deepClone(config);newConfig.menu?.find(({title})=>title===menuname)?.link?.push({name,target}),medplum.updateResource(newConfig).then(res=>{config.menu=res.menu,medplum.dispatchEvent({type:"change"}),showNotification2({color:"green",message:"Success"}),props.onOk()}).catch(err=>{showNotification2({color:"red",message:normalizeErrorString3(err)})})}return jsx14(Modal,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:props.visible,onClose:props.onCancel,children:jsx14(Form,{onSubmit:submitHandler,children:jsxs6(Stack2,{children:[jsx14(SelectMenu,{config}),jsx14(TextInput3,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),jsx14(Group6,{justify:"flex-end",children:jsx14(Button,{mt:"sm",type:"submit",children:"OK"})})]})})})}function SelectMenu(props){function userConfigToMenu(config){return config?.menu?.map(menu=>menu.title)}let menus=userConfigToMenu(props.config);return jsx14(NativeSelect2,{name:"menuname",defaultValue:menus[0],label:"Select Menu Option",data:menus,withAsterisk:!0})}import{useCallback as useCallback4,useState as useState6}from"react";import{useState as useState5}from"react";import{Group as Group7,Text as Text4}from"@mantine/core";import{forwardRef as forwardRef3,useCallback as useCallback3}from"react";import{jsx as jsx15,jsxs as jsxs7}from"react/jsx-runtime";function toKey(element){return typeof element.code=="string"?element.code:JSON.stringify(element)}function getDisplay(item){return typeof item.display=="string"?item.display:toKey(item)}function toOption2(element){return{value:toKey(element),label:getDisplay(element),resource:element}}function createValue(input){return{code:input,display:input}}function ValueSetAutocomplete(props){let medplum=a(),{binding,creatable,clearable,expandParams,withHelpText,...rest}=props,loadValues=useCallback3(async(input,signal)=>{if(!binding)return[];let valueSetElements=(await medplum.valueSetExpand({...expandParams,url:binding,filter:input},{signal})).expansion?.contains,newData=[];for(let valueSetElement of valueSetElements)valueSetElement.code&&!newData.some(item=>item.code===valueSetElement.code)&&newData.push(valueSetElement);return newData},[medplum,expandParams,binding]);return jsx15(AsyncAutocomplete,{...rest,creatable:creatable??!0,clearable:clearable??!0,toOption:toOption2,loadOptions:loadValues,onCreate:createValue,itemComponent:withHelpText?ItemComponent2:void 0})}var ItemComponent2=forwardRef3(({label,resource,...others},ref)=>jsx15("div",{ref,...others,children:jsx15(Group7,{wrap:"nowrap",children:jsxs7("div",{children:[jsx15(Text4,{children:label}),jsx15(Text4,{size:"xs",c:"dimmed",children:`${resource.system}#${resource.code}`})]})})}));import{jsx as jsx16}from"react/jsx-runtime";function CodeInput(props){let{defaultValue:defaultValue2,onChange,withHelpText,...rest}=props,[value,setValue]=useState5(defaultValue2);function handleChange(newValues){let newValue=newValues[0],newCode=valueSetElementToCode(newValue);setValue(newCode),onChange&&onChange(newCode)}return jsx16(ValueSetAutocomplete,{defaultValue:codeToValueSetElement(value),onChange:handleChange,withHelpText:withHelpText??!0,...rest})}function codeToValueSetElement(code){return code?{code}:void 0}function valueSetElementToCode(element){return element?.code}import{jsx as jsx17}from"react/jsx-runtime";function ResourceTypeInput(props){let[resourceType,setResourceType]=useState6(props.defaultValue),onChange=props.onChange,setResourceTypeWrapper=useCallback4(newResourceType=>{setResourceType(newResourceType),onChange&&onChange(newResourceType)},[onChange]);return jsx17(CodeInput,{"data-autofocus":props.autoFocus,"data-testid":props.testId,defaultValue:resourceType,onChange:setResourceTypeWrapper,name:props.name,placeholder:props.placeholder,binding:"https://medplum.com/fhir/ValueSet/resource-types",creatable:!1,maxValues:props.maxValues??1,clearable:!1,withHelpText:!1})}var Navbar_default={menuTitle:"Navbar_menuTitle",link:"Navbar_link",linkActive:"Navbar_linkActive"};import{Fragment as Fragment5,jsx as jsx18,jsxs as jsxs8}from"react/jsx-runtime";function Navbar(props){let navigate=V(),activeLink=getActiveLink(props.pathname,props.searchParams,props.menus),[bookmarkDialogVisible,setBookmarkDialogVisible]=useState7(!1);function onLinkClick(e,to){e.stopPropagation(),e.preventDefault(),navigate(to),window.innerWidth<768&&props.closeNavbar()}function navigateResourceType(resourceType){resourceType&&navigate(`/${resourceType}`)}return jsxs8(Fragment5,{children:[jsx18(MantineAppShell2.Navbar,{children:jsxs8(ScrollArea,{p:"xs",children:[!props.resourceTypeSearchDisabled&&jsx18(MantineAppShell2.Section,{mb:"sm",children:jsx18(ResourceTypeInput,{name:"resourceType",placeholder:"Resource Type",maxValues:0,onChange:newValue=>navigateResourceType(newValue)},window.location.pathname)}),jsxs8(MantineAppShell2.Section,{grow:!0,children:[props.menus?.map(menu=>jsxs8(Fragment4,{children:[jsx18(Text5,{className:Navbar_default.menuTitle,children:menu.title}),menu.links?.map(link=>jsxs8(NavbarLink,{to:link.href,active:link.href===activeLink?.href,onClick:e=>onLinkClick(e,link.href),children:[jsx18(NavLinkIcon,{to:link.href,icon:link.icon}),jsx18("span",{children:link.label})]},link.href))]},`menu-${menu.title}`)),props.displayAddBookmark&&jsx18(Button2,{variant:"subtle",size:"xs",mt:"xl",leftSection:jsx18(IconPlus,{size:"0.75rem"}),onClick:()=>setBookmarkDialogVisible(!0),children:"Add Bookmark"})]})]})}),props.pathname&&props.searchParams&&jsx18(BookmarkDialog,{pathname:props.pathname,searchParams:props.searchParams,visible:bookmarkDialogVisible,onOk:()=>setBookmarkDialogVisible(!1),onCancel:()=>setBookmarkDialogVisible(!1)})]})}function NavbarLink(props){return jsx18(MedplumLink,{onClick:props.onClick,to:props.to,className:clsx_default(Navbar_default.link,{[Navbar_default.linkActive]:props.active}),children:props.children})}function NavLinkIcon(props){return props.icon?props.icon:jsx18(Space,{w:30})}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)&¤tSearchParams.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 jsx19,jsxs as jsxs9}from"react/jsx-runtime";function AppShell(props){let[navbarOpen,setNavbarOpen]=useState8(localStorage.navbarOpen==="true"),medplum=a(),profile=W();useEffect2(()=>{function eventListener(){showNotification3({color:"red",message:"No connection to server",autoClose:!1})}return medplum.addEventListener("offline",eventListener),()=>medplum.removeEventListener("offline",eventListener)},[medplum]);function setNavbarOpenWrapper(open){localStorage.navbarOpen=open.toString(),setNavbarOpen(open)}function closeNavbar(){setNavbarOpenWrapper(!1)}function toggleNavbar(){setNavbarOpenWrapper(!navbarOpen)}return medplum.isLoading()?jsx19(Loading,{}):jsxs9(MantineAppShell3,{header:{height:60},navbar:{width:250,breakpoint:"sm",collapsed:{desktop:!profile||!navbarOpen,mobile:!profile||!navbarOpen}},padding:0,children:[profile&&jsx19(Header,{pathname:props.pathname,searchParams:props.searchParams,headerSearchDisabled:props.headerSearchDisabled,logo:props.logo,version:props.version,navbarToggle:toggleNavbar,notifications:props.notifications}),profile&&navbarOpen?jsx19(Navbar,{pathname:props.pathname,searchParams:props.searchParams,menus:props.menus,closeNavbar,displayAddBookmark:props.displayAddBookmark,resourceTypeSearchDisabled:props.resourceTypeSearchDisabled}):void 0,jsx19(MantineAppShell3.Main,{className:AppShell_default.main,children:jsx19(ErrorBoundary,{children:jsx19(Suspense,{fallback:jsx19(Loading,{}),children:props.children})})})]})}import{Anchor as Anchor2}from"@mantine/core";import{jsx as jsx20,jsxs as jsxs10}from"react/jsx-runtime";function AttachmentDisplay(props){let{contentType,url:uncachedUrl,title}=props.value??{},url=oe(uncachedUrl);return url?jsxs10("div",{"data-testid":"attachment-display",children:[contentType?.startsWith("image/")&&jsx20("img",{"data-testid":"attachment-image",style:{maxWidth:props.maxWidth},src:url,alt:title}),contentType?.startsWith("video/")&&jsx20("video",{"data-testid":"attachment-video",style:{maxWidth:props.maxWidth},controls:!0,children:jsx20("source",{type:contentType,src:url})}),contentType==="application/pdf"&&jsx20("div",{"data-testid":"attachment-pdf",style:{maxWidth:props.maxWidth,minHeight:400},children:jsx20("iframe",{width:"100%",height:"400",src:url+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),jsx20("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:jsx20(Anchor2,{href:url,"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}var DescriptionList_default={root:"DescriptionList_root",compact:"DescriptionList_compact"};import{Fragment as Fragment6,jsx as jsx21,jsxs as jsxs11}from"react/jsx-runtime";function DescriptionList(props){let{children,compact}=props;return jsx21("dl",{className:clsx_default(DescriptionList_default.root,{[DescriptionList_default.compact]:compact}),children})}function DescriptionListEntry(props){return jsxs11(Fragment6,{children:[jsx21("dt",{children:props.term}),jsx21("dd",{children:props.children})]})}import{getPathDisplayName,isPopulated}from"@medplum/core";import{Fragment as Fragment7,jsx as jsx22}from"react/jsx-runtime";function AttachmentArrayDisplay(props){let attachmentElements=props.values?.map((v2,index)=>jsx22("div",{children:jsx22(AttachmentDisplay,{value:v2,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(!isPopulated(props.path))throw new Error("props.path is required when includeDescriptionListEntry is true");let key=props.path.split(".").pop();content=jsx22(DescriptionListEntry,{term:getPathDisplayName(key),children:attachmentElements})}else content=jsx22(Fragment7,{children:attachmentElements});return content}import{ActionIcon}from"@mantine/core";import{useRef as useRef4,useState as useState9}from"react";import{normalizeOperationOutcome}from"@medplum/core";import{useRef as useRef3}from"react";import{Fragment as Fragment8,jsx as jsx23,jsxs as jsxs12}from"react/jsx-runtime";function AttachmentButton(props){let medplum=a(),fileInputRef=useRef3(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 jsxs12(Fragment8,{children:[jsx23("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:fileInputRef,onChange:e=>onFileChange(e)}),props.children({onClick})]})}import{jsx as jsx24,jsxs as jsxs13}from"react/jsx-runtime";function AttachmentArrayInput(props){let[values,setValues]=useState9(props.defaultValue??[]),valuesRef=useRef4();valuesRef.current=values;function setValuesWrapper(newValues){setValues(newValues),props.onChange&&props.onChange(newValues)}return jsxs13("table",{style:{width:"100%"},children:[jsxs13("colgroup",{children:[jsx24("col",{width:"97%"}),jsx24("col",{width:"3%"})]}),jsxs13("tbody",{children:[values.map((v2,index)=>jsxs13("tr",{children:[jsx24("td",{children:jsx24(AttachmentDisplay,{value:v2,maxWidth:200})}),jsx24("td",{children:jsx24(ActionIcon,{title:"Remove",variant:"subtle",size:"sm",color:"gray",onClick:e=>{killEvent(e);let copy=values.slice();copy.splice(index,1),setValuesWrapper(copy)},children:jsx24(IconCircleMinus,{})})})]},`${index}-${values.length}`)),jsxs13("tr",{children:[jsx24("td",{}),jsx24("td",{children:jsx24(AttachmentButton,{onUpload:attachment=>{setValuesWrapper([...valuesRef.current,attachment])},children:props2=>jsx24(ActionIcon,{...props2,title:"Add",variant:"subtle",size:"sm",color:"green",children:jsx24(IconCloudUpload,{})})})})]})]})]})}import{Button as Button3}from"@mantine/core";import{useState as useState10}from"react";import{Fragment as Fragment9,jsx as jsx25,jsxs as jsxs14}from"react/jsx-runtime";function AttachmentInput(props){let[value,setValue]=useState10(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return value?jsxs14(Fragment9,{children:[jsx25(AttachmentDisplay,{value,maxWidth:200}),jsx25(Button3,{onClick:e=>{killEvent(e),setValueWrapper(void 0)},children:"Remove"})]}):jsx25(AttachmentButton,{securityContext:props.securityContext,onUpload:setValueWrapper,children:props2=>jsx25(Button3,{...props2,children:"Upload..."})})}import{buildElementsContext as buildElementsContext2,getPathDisplayName as getPathDisplayName3,isEmpty as isEmpty2,tryGetDataType}from"@medplum/core";var DEFAULT_IGNORED_PROPERTIES=["meta","implicitRules","contained","extension","modifierExtension"],DEFAULT_IGNORED_NON_NESTED_PROPERTIES=["language","text"];import{ActionIcon as ActionIcon2,Box,CopyButton,Tooltip}from"@mantine/core";import{PropertyType,formatDateTime,formatPeriod,formatTiming,isEmpty}from"@medplum/core";import{formatCodeableConcept}from"@medplum/core";import{Fragment as Fragment10,jsx as jsx26}from"react/jsx-runtime";function CodeableConceptDisplay(props){return jsx26(Fragment10,{children:formatCodeableConcept(props.value)})}import{formatCoding}from"@medplum/core";import{Fragment as Fragment11,jsx as jsx27}from"react/jsx-runtime";function CodingDisplay(props){return jsx27(Fragment11,{children:formatCoding(props.value)})}import{Fragment as Fragment12,jsx as jsx28}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("]")),jsx28(Fragment12,{children:builder.join("").trim()})}import{Fragment as Fragment13,jsx as jsx29,jsxs as jsxs15}from"react/jsx-runtime";function ContactDetailDisplay(props){let contactDetail=props.value;return contactDetail?jsxs15(Fragment13,{children:[contactDetail.name,contactDetail.name&&": ",contactDetail.telecom?.map(telecom=>jsx29(ContactPointDisplay,{value:telecom},`telecom-${contactDetail.name}-${telecom.value}`))]}):null}import{jsxs as jsxs16}from"react/jsx-runtime";function IdentifierDisplay(props){return jsxs16("div",{children:[props.value?.system,": ",props.value?.value]})}import{formatMoney}from"@medplum/core";import{Fragment as Fragment14,jsx as jsx30}from"react/jsx-runtime";function MoneyDisplay(props){return jsx30(Fragment14,{children:formatMoney(props.value)})}import{formatQuantity}from"@medplum/core";import{Fragment as Fragment15,jsx as jsx31}from"react/jsx-runtime";function QuantityDisplay(props){return jsx31(Fragment15,{children:formatQuantity(props.value)})}import{formatRange}from"@medplum/core";import{Fragment as Fragment16,jsx as jsx32}from"react/jsx-runtime";function RangeDisplay(props){return jsx32(Fragment16,{children:formatRange(props.value)})}import{Fragment as Fragment17,jsx as jsx33,jsxs as jsxs17}from"react/jsx-runtime";function RatioDisplay(props){let value=props.value;return value?jsxs17(Fragment17,{children:[jsx33(QuantityDisplay,{value:value.numerator}),"\xA0/\xA0",jsx33(QuantityDisplay,{value:value.denominator})]}):null}import{stringify}from"@medplum/core";import{Fragment as Fragment18,jsx as jsx34}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?jsx34(MedplumLink,{to:props.value,children:displayString}):jsx34(Fragment18,{children:displayString})}import{getPathDisplayName as getPathDisplayName2,isPopulated as isPopulated4}from"@medplum/core";import{useState as useState11,useContext as useContext2,useEffect as useEffect3,useMemo as useMemo2}from"react";import React from"react";var ElementsContext=React.createContext({path:"",profileUrl:void 0,elements:Object.create(null),elementsByPath:Object.create(null),debugMode:!1});ElementsContext.displayName="ElementsContext";import{getValueSliceName,isPopulated as isPopulated2,isSliceDefinitionWithTypes,tryGetProfile}from"@medplum/core";function assignValuesIntoSlices(values,slices,slicing,profileUrl){if(!isPopulated2(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;isPopulated2(slice.elements)||(profileUrl=slice.type[0]?.profile?.[0]),supportedSlices.push(slice),profileUrls.push(profileUrl),profileUrl?promises.push(medplum.requestProfileSchema(profileUrl)):promises.push(Promise.resolve([]))}Promise.all(promises).then(()=>{for(let i=0;i<supportedSlices.length;i++){let slice=supportedSlices[i],profileUrl=profileUrls[i];if(profileUrl){let typeSchema=tryGetProfile(profileUrl);slice.typeSchema=typeSchema}}resolve(supportedSlices)}).catch(reject)})}import{buildElementsContext,isPopulated as isPopulated3}from"@medplum/core";import{useContext,useMemo}from"react";import{jsx as jsx35}from"react/jsx-runtime";function maybeWrapWithContext(ContextProvider,contextValue,contents){return contextValue!==void 0?jsx35(ContextProvider,{value:contextValue,children:contents}):contents}import{Fragment as Fragment19,jsx as jsx36}from"react/jsx-runtime";function SliceDisplay(props){let{slice,property}=props,sliceElements=slice.typeSchema?.elements??slice.elements,parentContext=useContext(ElementsContext),contextValue=useMemo(()=>{if(isPopulated3(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,jsx36(Fragment19,{children:props.value.map((value,valueIndex)=>jsx36("div",{children:jsx36(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 Fragment20,jsx as jsx37,jsxs as jsxs18}from"react/jsx-runtime";function ResourceArrayDisplay(props){let{property,propertyType}=props,medplum=a(),values=useMemo2(()=>Array.isArray(props.values)?props.values:[],[props.values]),[loading,setLoading]=useState11(!0),[slices,setSlices]=useState11([]),[slicedValues,setSlicedValues]=useState11(()=>[values]),ctx=useContext2(ElementsContext);if(useEffect3(()=>{prepareSlices({medplum,property}).then(slices2=>{setSlices(slices2);let slicedValues2=assignValuesIntoSlices(values,slices2,property.slicing,ctx.profileUrl);setSlicedValues(slicedValues2),setLoading(!1)}).catch(reason=>{console.error(reason),setLoading(!1)})},[medplum,property,ctx.profileUrl,setSlicedValues,values]),loading)return jsx37("div",{children:"Loading..."});let nonSliceContent;if(property.type[0]?.code!=="Extension"){let nonSliceValues=slicedValues[slices.length],nonSliceElements=nonSliceValues.map((value,valueIndex)=>jsx37("div",{children:jsx37(ResourcePropertyDisplay,{path:props.path,arrayElement:!0,property,propertyType,value,ignoreMissingValues:props.ignoreMissingValues,link:props.link})},`${valueIndex}-${nonSliceValues.length}`));if(props.includeDescriptionListEntry){if(!isPopulated4(props.path))throw new Error("props.path is required when includeDescriptionListEntry is true");let key=props.path.split(".").pop();nonSliceContent=jsx37(DescriptionListEntry,{term:getPathDisplayName2(key),children:nonSliceElements})}else nonSliceContent=jsx37(Fragment20,{children:nonSliceElements})}return jsxs18(Fragment20,{children:[slices.map((slice,sliceIndex)=>{if(!props.path)throw Error(`Displaying a resource property with slices of type ${props.propertyType} requires path`);let sliceDisplay=jsx37(SliceDisplay,{path:props.path,slice,property,value:slicedValues[sliceIndex],ignoreMissingValues:props.ignoreMissingValues,link:props.link},slice.name);return props.includeDescriptionListEntry&&(sliceDisplay=jsx37(DescriptionListEntry,{term:getPathDisplayName2(slice.name),children:sliceDisplay},slice.name)),sliceDisplay}),nonSliceContent]})}import{getDataType,isPopulated as isPopulated5,isProfileLoaded,tryGetProfile as tryGetProfile2}from"@medplum/core";import{useContext as useContext3,useEffect as useEffect4,useMemo as useMemo3,useState as useState12}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 jsx38}from"react/jsx-runtime";function ExtensionDisplay(props){let{elementDefinitionType}=props,medplum=a(),ctx=useContext3(ElementsContext),[typeSchema,setTypeSchema]=useState12(getDataType("Extension")),profileUrl=useMemo3(()=>{if(isPopulated5(elementDefinitionType?.profile))return elementDefinitionType.profile[0]},[elementDefinitionType]),[loadingProfile,setLoadingProfile]=useState12(profileUrl!==void 0);if(useEffect4(()=>{profileUrl&&(setLoadingProfile(!0),medplum.requestProfileSchema(profileUrl).then(()=>{let profile=tryGetProfile2(profileUrl);setLoadingProfile(!1),profile&&setTypeSchema(profile)}).catch(reason=>{setLoadingProfile(!1),console.warn(reason)}))},[medplum,profileUrl]),profileUrl&&(loadingProfile||!isProfileLoaded(profileUrl)))return jsx38("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 jsx38(ResourcePropertyDisplay,{propertyType,value:propertyValue})}return jsx38(BackboneElementDisplay,{path:props.path,value:{type:typeSchema.name,value:props.value},compact:props.compact,ignoreMissingValues:props.ignoreMissingValues,link:props.link,profileUrl})}import{Fragment as Fragment21,jsx as jsx39,jsxs as jsxs19}from"react/jsx-runtime";function ResourcePropertyDisplay(props){let{property,propertyType,value}=props;if(property?.path?.endsWith(".id"))return jsxs19(Box,{component:"div",style:{display:"flex",gap:3,alignItems:"center"},children:[value,!isEmpty(value)&&jsx39(CopyButton,{value,timeout:2e3,children:({copied,copy})=>jsx39(Tooltip,{label:copied?"Copied":"Copy",withArrow:!0,position:"right",children:jsx39(ActionIcon2,{variant:"subtle",color:copied?"teal":"gray",onClick:copy,children:copied?jsx39(IconCheck,{size:"1rem"}):jsx39(IconCopy,{size:"1rem"})})})})]});let isArrayElement=!!props.arrayElement;if(property?.max&&property.max>1&&!isArrayElement)return propertyType===PropertyType.Attachment?jsx39(AttachmentArrayDisplay,{values:value,maxWidth:props.maxWidth,includeDescriptionListEntry:props.includeArrayDescriptionListEntry,property,path:props.path}):jsx39(ResourceArrayDisplay,{path:props.path,property,propertyType,values:value,includeDescriptionListEntry:props.includeArrayDescriptionListEntry,ignoreMissingValues:props.ignoreMissingValues,link:props.link});switch(propertyType){case PropertyType.boolean:return jsx39(Fragment21,{children:value===void 0?"":(!!value).toString()});case PropertyType.SystemString:case PropertyType.string:return jsx39("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:return jsx39(Fragment21,{children:value});case PropertyType.canonical:return jsx39(ReferenceDisplay,{value:{reference:value},link:props.link});case PropertyType.dateTime:case PropertyType.instant:return jsx39(Fragment21,{children:formatDateTime(value)});case PropertyType.markdown:return jsx39("pre",{children:value});case PropertyType.Address:return jsx39(AddressDisplay,{value});case PropertyType.Annotation:return jsx39(Fragment21,{children:value?.text});case PropertyType.Attachment:return jsx39(AttachmentDisplay,{value,maxWidth:props.maxWidth});case PropertyType.CodeableConcept:return jsx39(CodeableConceptDisplay,{value});case PropertyType.Coding:return jsx39(CodingDisplay,{value});case PropertyType.ContactDetail:return jsx39(ContactDetailDisplay,{value});case PropertyType.ContactPoint:return jsx39(ContactPointDisplay,{value});case PropertyType.HumanName:return jsx39(HumanNameDisplay,{value});case PropertyType.Identifier:return jsx39(IdentifierDisplay,{value});case PropertyType.Money:return jsx39(MoneyDisplay,{value});case PropertyType.Period:return jsx39(Fragment21,{children:formatPeriod(value)});case PropertyType.Quantity:case PropertyType.Duration:return jsx39(QuantityDisplay,{value});case PropertyType.Range:return jsx39(RangeDisplay,{value});case PropertyType.Ratio:return jsx39(RatioDisplay,{value});case PropertyType.Reference:return jsx39(ReferenceDisplay,{value,link:props.link});case PropertyType.Timing:return jsx39(Fragment21,{children:formatTiming(value)});case PropertyType.Dosage:case PropertyType.UsageContext:if(!props.path)throw Error(`Displaying property of type ${props.propertyType} requires path`);return jsx39(BackboneElementDisplay,{path:props.path,value:{type:propertyType,value},compact:!0,ignoreMissingValues:props.ignoreMissingValues});case PropertyType.Extension:if(!props.path)throw Error(`Displaying property of type ${props.propertyType} requires path`);return jsx39(ExtensionDisplay,{path:props.path,value,compact:!0,ignoreMissingValues:props.ignoreMissingValues,elementDefinitionType:props.elementDefinitionType});default:if(!property)throw Error(`Displaying property of type ${props.propertyType} requires element schema`);if(!props.path)throw Error(`Displaying property of type ${props.propertyType} requires path`);return jsx39(BackboneElementDisplay,{path:props.path,value:{type:property.type[0].code,value},compact:!0,ignoreMissingValues:props.ignoreMissingValues})}}import{useContext as useContext4,useMemo as useMemo4}from"react";import{jsx as jsx40,jsxs as jsxs20}from"react/jsx-runtime";var EXTENSION_KEYS=["extension","modifierExtension"],IGNORED_PROPERTIES=DEFAULT_IGNORED_PROPERTIES.filter(prop=>!EXTENSION_KEYS.includes(prop));function BackboneElementDisplay(props){let typedValue=props.value,{value,type:typeName}=typedValue,parentElementsContext=useContext4(ElementsContext),profileUrl=props.profileUrl??parentElementsContext?.profileUrl,typeSchema=useMemo4(()=>tryGetDataType(typeName,profileUrl),[profileUrl,typeName]),newElementsContext=useMemo4(()=>{if(typeSchema)return buildElementsContext2({parentContext:parentElementsContext,elements:typeSchema.elements,path:props.path,profileUrl:typeSchema.url})},[typeSchema,props.path,parentElementsContext]);if(isEmpty2(value))return null;if(!typeSchema)return jsxs20("div",{children:[typeName,"\xA0not implemented"]});if(typeof value=="object"&&"name"in value&&Object.keys(value).length===1&&typeof value.name=="string")return jsx40("div",{children:value.name});let elementsContext=newElementsContext??parentElementsContext;return maybeWrapWithContext(ElementsContext.Provider,newElementsContext,jsx40(DescriptionList,{compact:props.compact,children:Object.entries(elementsContext.elements).map(([key,property])=>{if(EXTENSION_KEYS.includes(key)&&isEmpty2(property.slicing?.slices))return null;if(IGNORED_PROPERTIES.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=jsx40(ResourcePropertyDisplay,{property,propertyType,path:props.path+"."+key,value:propertyValue,ignoreMissingValues:props.ignoreMissingValues,includeArrayDescriptionListEntry:isArrayProperty,link:props.link},key);return isArrayProperty?resourcePropertyDisplay:jsx40(DescriptionListEntry,{term:getPathDisplayName3(key),children:resourcePropertyDisplay},key)})}))}import{buildElementsContext as buildElementsContext4,tryGetDataType as tryGetDataType2}from"@medplum/core";import{useContext as useContext13,useMemo as useMemo12,useState as useState33}from"react";import{Stack as Stack6}from"@mantine/core";import{getPathDisplayName as getPathDisplayName5,isPopulated as isPopulated11}from"@medplum/core";import{useContext as useContext12,useMemo as useMemo11,useState as useState32}from"react";import{Group as Group8,Input}from"@mantine/core";import{useContext as useContext5}from"react";import{jsx as jsx41,jsxs as jsxs21}from"react/jsx-runtime";function CheckboxFormSection(props){let{debugMode}=useContext5(ElementsContext),label;return debugMode&&props.fhirPath?label=`${props.title} - ${props.fhirPath}`:label=props.title,jsxs21(Group8,{wrap:"nowrap","data-testid":props.testId,children:[jsx41("div",{children:props.children}),jsx41("div",{children:jsx41(Input.Wrapper,{id:props.htmlFor,label,description:props.description,withAsterisk:props.withAsterisk,children:null})})]})}import{Input as Input2}from"@mantine/core";import{useContext as useContext6}from"react";function getErrorsForInput(outcome,expression){return outcome?.issue?.filter(issue=>isExpressionMatch(issue.expression?.[0],expression))?.map(issue=>issue.details?.text)?.join(`
|
|
65
|
-
`)}function getIssuesForExpression(outcome,expression){return outcome?.issue?.filter(issue=>isExpressionMatch(issue.expression?.[0],expression))}function isExpressionMatch(expr1,expr2){if(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{jsx as jsx42}from"react/jsx-runtime";function FormSection(props){let{debugMode}=useContext6(ElementsContext),label;return debugMode&&props.fhirPath?label=`${props.title} - ${props.fhirPath}`:label=props.title,jsx42(Input2.Wrapper,{id:props.htmlFor,label,description:props.description,withAsterisk:props.withAsterisk,error:getErrorsForInput(props.outcome,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 obj[propName]=value,obj}function isSupportedProfileStructureDefinition(profile){return!!profile&&!isEmpty3(profile.url)&&!isEmpty3(profile.name)}import{Checkbox,Group as Group22,NativeSelect as NativeSelect9,Textarea as Textarea2,TextInput as TextInput12}from"@mantine/core";import{applyDefaultValuesToElement,capitalize as capitalize2,getPathDifference,HTTP_HL7_ORG,isComplexTypeCode,isEmpty as isEmpty6,isPopulated as isPopulated10,PropertyType as PropertyType2}from"@medplum/core";import{useContext as useContext11,useMemo as useMemo10,useState as useState31}from"react";import{useState as useState13}from"react";import{jsx as jsx43}from"react/jsx-runtime";function CodeableConceptInput(props){let{defaultValue:defaultValue2,onChange,withHelpText,...rest}=props,[value,setValue]=useState13(defaultValue2);function handleChange(newValues){let newConcept=valueSetElementToCodeableConcept(newValues);setValue(newConcept),onChange&&onChange(newConcept)}return jsx43(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 useState14}from"react";import{jsx as jsx44}from"react/jsx-runtime";function CodingInput(props){let{defaultValue:defaultValue2,onChange,withHelpText,...rest}=props,[value,setValue]=useState14(defaultValue2);function handleChange(newValues){let newValue=newValues[0],newConcept=newValue&&valueSetElementToCoding(newValue);setValue(newConcept),onChange&&onChange(newConcept)}return jsx44(ValueSetAutocomplete,{defaultValue:value&&codingToValueSetElement(value),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 Group10,TextInput as TextInput5}from"@mantine/core";import{useRef as useRef6,useState as useState16}from"react";import{Group as Group9,NativeSelect as NativeSelect3,TextInput as TextInput4}from"@mantine/core";import{useContext as useContext7,useMemo as useMemo5,useRef as useRef5,useState as useState15}from"react";import{jsx as jsx45,jsxs as jsxs22}from"react/jsx-runtime";function ContactPointInput(props){let{path,outcome}=props,{elementsByPath}=useContext7(ElementsContext),[contactPoint,setContactPoint]=useState15(props.defaultValue),ref=useRef5();ref.current=contactPoint;let[systemElement,useElement,valueElement]=useMemo5(()=>["system","use","value"].map(field=>elementsByPath[path+"."+field]),[elementsByPath,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)}return jsxs22(Group9,{gap:"xs",grow:!0,wrap:"nowrap",align:"flex-start",children:[jsx45(NativeSelect3,{"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,path+".system")}),jsx45(NativeSelect3,{"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,path+".use")}),jsx45(TextInput4,{placeholder:"Value",defaultValue:contactPoint?.value,required:(valueElement?.min??0)>0,onChange:e=>setValue(e.currentTarget.value),error:getErrorsForInput(outcome,path+".value")})]})}import{jsx as jsx46,jsxs as jsxs23}from"react/jsx-runtime";function ContactDetailInput(props){let[contactPoint,setContactDetail]=useState16(props.defaultValue),ref=useRef6();ref.current=contactPoint;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 jsxs23(Group10,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx46(TextInput5,{"data-testid":props.name+"-name",name:props.name+"-name",placeholder:"Name",style:{width:180},defaultValue:contactPoint?.name,onChange:e=>setName(e.currentTarget.value)}),jsx46(ContactPointInput,{name:props.name+"-telecom",path:props.path+".telecom",defaultValue:contactPoint?.telecom?.[0],onChange:setTelecom,outcome:props.outcome})]})}import{TextInput as TextInput6}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 jsx47}from"react/jsx-runtime";function DateTimeInput(props){return jsx47(TextInput6,{id:props.name,name:props.name,label:props.label,"data-autofocus":props.autoFocus,"data-testid":props.name,placeholder:props.placeholder,required:props.required,type:getInputType(),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{tryGetProfile as tryGetProfile3,isProfileLoaded as isProfileLoaded2,isPopulated as isPopulated6}from"@medplum/core";import{useEffect as useEffect5,useMemo as useMemo6,useState as useState17}from"react";import{jsx as jsx48}from"react/jsx-runtime";function ExtensionInput(props){let{propertyType}=props,medplum=a(),[typeSchema,setTypeSchema]=useState17(),profileUrl=useMemo6(()=>{if(isPopulated6(propertyType.profile))return propertyType.profile[0]},[propertyType]),[loadingProfile,setLoadingProfile]=useState17(profileUrl!==void 0);return useEffect5(()=>{profileUrl&&(setLoadingProfile(!0),medplum.requestProfileSchema(profileUrl).then(()=>{let profile=tryGetProfile3(profileUrl);setLoadingProfile(!1),setTypeSchema(profile)}).catch(reason=>{setLoadingProfile(!1),console.warn(reason)}))},[medplum,profileUrl]),profileUrl&&(loadingProfile||!isProfileLoaded2(profileUrl))?jsx48("div",{children:"Loading..."}):jsx48(BackboneElementInput,{profileUrl,path:props.path,typeName:typeSchema?.name??"Extension",defaultValue:props.defaultValue,onChange:props.onChange})}import{Group as Group11,NativeSelect as NativeSelect4,TextInput as TextInput7}from"@mantine/core";import{useState as useState18}from"react";import{jsx as jsx49,jsxs as jsxs24}from"react/jsx-runtime";function HumanNameInput(props){let{outcome,path}=props,[value,setValue]=useState18(props.defaultValue);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})}return jsxs24(Group11,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx49(NativeSelect4,{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,path+".use")}),jsx49(TextInput7,{placeholder:"Prefix",name:props.name+"-prefix",defaultValue:value?.prefix?.join(" "),onChange:e=>setPrefix(e.currentTarget.value),error:getErrorsForInput(outcome,path+".prefix")}),jsx49(TextInput7,{placeholder:"Given",name:props.name+"-given",defaultValue:value?.given?.join(" "),onChange:e=>setGiven(e.currentTarget.value),error:getErrorsForInput(outcome,path+".given")}),jsx49(TextInput7,{name:props.name+"-family",placeholder:"Family",defaultValue:value?.family,onChange:e=>setFamily(e.currentTarget.value),error:getErrorsForInput(outcome,path+".family")}),jsx49(TextInput7,{placeholder:"Suffix",name:props.name+"-suffix",defaultValue:value?.suffix?.join(" "),onChange:e=>setSuffix(e.currentTarget.value),error:getErrorsForInput(outcome,path+".suffix")})]})}import{Group as Group12,TextInput as TextInput8}from"@mantine/core";import{useContext as useContext8,useMemo as useMemo7,useState as useState19}from"react";import{jsx as jsx50,jsxs as jsxs25}from"react/jsx-runtime";function IdentifierInput(props){let{path,outcome}=props,[value,setValue]=useState19(props.defaultValue),{elementsByPath}=useContext8(ElementsContext),[systemElement,valueElement]=useMemo7(()=>["system","value"].map(field=>elementsByPath[path+"."+field]),[elementsByPath,path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs25(Group12,{gap:"xs",grow:!0,wrap:"nowrap",align:"flex-start",children:[jsx50(TextInput8,{placeholder:"System",required:(systemElement?.min??0)>0,defaultValue:value?.system,onChange:e=>setValueWrapper({...value,system:e.currentTarget.value}),error:getErrorsForInput(outcome,path+".system")}),jsx50(TextInput8,{placeholder:"Value",required:(valueElement?.min??0)>0,defaultValue:value?.value,onChange:e=>setValueWrapper({...value,value:e.currentTarget.value}),error:getErrorsForInput(outcome,path+".value")})]})}import{NativeSelect as NativeSelect5,TextInput as TextInput9}from"@mantine/core";import{useCallback as useCallback5,useState as useState20}from"react";import{jsx as jsx51}from"react/jsx-runtime";var data=["USD","EUR","CAD","GBP","AUD"];function MoneyInput(props){let{onChange}=props,[value,setValue]=useState20(props.defaultValue),setValueWrapper=useCallback5(newValue=>{setValue(newValue),onChange&&onChange(newValue)},[onChange]),handleCurrencyChange=useCallback5(e=>{setValueWrapper({...value,currency:e.currentTarget.value})},[value,setValueWrapper]),handleValueChange=useCallback5(e=>{setValueWrapper({...value,value:e.currentTarget.valueAsNumber})},[value,setValueWrapper]),select=jsx51(NativeSelect5,{defaultValue:value?.currency,data,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:handleCurrencyChange});return jsx51(TextInput9,{type:"number",name:props.name,label:props.label,placeholder:props.placeholder??"Value",defaultValue:value?.value?.toString()??"USD",leftSection:jsx51(IconCurrencyDollar,{size:14}),rightSection:select,rightSectionWidth:92,onChange:handleValueChange})}import{Group as Group13}from"@mantine/core";import{useState as useState21}from"react";import{jsx as jsx52,jsxs as jsxs26}from"react/jsx-runtime";function PeriodInput(props){let[value,setValue]=useState21(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs26(Group13,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx52(DateTimeInput,{name:props.name+".start",placeholder:"Start",defaultValue:value?.start,onChange:newValue=>setValueWrapper({...value,start:newValue})}),jsx52(DateTimeInput,{name:props.name+".end",placeholder:"End",defaultValue:value?.end,onChange:newValue=>setValueWrapper({...value,end:newValue})})]})}import{Group as Group14,NativeSelect as NativeSelect6,TextInput as TextInput10}from"@mantine/core";import{useState as useState22}from"react";import{jsx as jsx53,jsxs as jsxs27}from"react/jsx-runtime";function QuantityInput(props){let[value,setValue]=useState22(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs27(Group14,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx53(NativeSelect6,{style:{width:80},"data-testid":props.name+"-comparator",defaultValue:value?.comparator,data:["","<","<=",">=",">"],onChange:e=>setValueWrapper({...value,comparator:e.currentTarget.value})}),jsx53(TextInput10,{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)})}}),jsx53(TextInput10,{placeholder:"Unit","data-testid":props.name+"-unit",defaultValue:value?.unit,onChange:e=>setValueWrapper({...value,unit:e.currentTarget.value})})]})}function tryParseNumber(str){if(str)return parseFloat(str)}import{Group as Group15}from"@mantine/core";import{useState as useState23}from"react";import{jsx as jsx54,jsxs as jsxs28}from"react/jsx-runtime";function RangeInput(props){let[value,setValue]=useState23(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs28(Group15,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx54(QuantityInput,{name:props.name+"-low",defaultValue:value?.low,onChange:v2=>setValueWrapper({...value,low:v2})}),jsx54(QuantityInput,{name:props.name+"-high",defaultValue:value?.high,onChange:v2=>setValueWrapper({...value,high:v2})})]})}import{Group as Group16}from"@mantine/core";import{useState as useState24}from"react";import{jsx as jsx55,jsxs as jsxs29}from"react/jsx-runtime";function RatioInput(props){let[value,setValue]=useState24(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs29(Group16,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx55(QuantityInput,{name:props.name+"-numerator",defaultValue:value?.numerator,onChange:v2=>setValueWrapper({...value,numerator:v2})}),jsx55(QuantityInput,{name:props.name+"-denominator",defaultValue:value?.denominator,onChange:v2=>setValueWrapper({...value,denominator:v2})})]})}import{Group as Group18,NativeSelect as NativeSelect7}from"@mantine/core";import{LRUCache,ReadablePromise,createReference as createReference2,isEmpty as isEmpty4,isPopulated as isPopulated8,tryGetProfile as tryGetProfile4}from"@medplum/core";import{useCallback as useCallback7,useEffect as useEffect6,useMemo as useMemo8,useRef as useRef7,useState as useState26}from"react";import{Group as Group17,Text as Text6}from"@mantine/core";import{getDisplayString as getDisplayString3,getReferenceString as getReferenceString3,isPopulated as isPopulated7}from"@medplum/core";import{forwardRef as forwardRef4,useCallback as useCallback6,useState as useState25}from"react";import{jsx as jsx56,jsxs as jsxs30}from"react/jsx-runtime";var SEARCH_CODES={Observation:"code",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","RiskEvidenceSynthesis","SearchParameter","StructureDefinition","StructureMap","TerminologyCapabilities","TestScript","UserConfiguration","ValueSet"];function toOption3(resource){return{value:getReferenceString3(resource),label:getDisplayString3(resource),resource}}function ResourceInput(props){let medplum=a(),{resourceType,searchCriteria}=props,[outcome,setOutcome]=useState25(),defaultValue2=pe(props.defaultValue,setOutcome),onChange=props.onChange,loadValues=useCallback6(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=useCallback6(newResources=>{onChange&&onChange(newResources[0])},[onChange]);return isPopulated7(props.defaultValue)&&!outcome&&!defaultValue2?null:jsx56(AsyncAutocomplete,{name:props.name,required:props.required,itemComponent:ItemComponent3,defaultValue:defaultValue2,placeholder:props.placeholder,maxValues:1,toOption:toOption3,loadOptions:loadValues,onChange:handleChange,clearable:!0})}var ItemComponent3=forwardRef4(({label,resource,...others},ref)=>jsx56("div",{ref,...others,children:jsxs30(Group17,{wrap:"nowrap",children:[jsx56(ResourceAvatar,{value:resource}),jsxs30("div",{children:[jsx56(Text6,{children:label}),jsx56(Text6,{size:"xs",c:"dimmed",children:resource.birthDate})]})]})}));function getSearchParamForResourceType(resourceType){return SEARCH_CODES[resourceType]??(NAME_RESOURCE_TYPES.includes(resourceType)?"name":"_id")}import{jsx as jsx57,jsxs as jsxs31}from"react/jsx-runtime";function ReferenceInput(props){let{onChange}=props,medplum=a(),[value,setValue]=useState26(props.defaultValue),[targetTypes,setTargetTypes]=useState26(()=>createTargetTypes(props.targetTypes)),[targetType,setTargetType]=useState26(()=>getInitialTargetType(props.defaultValue,targetTypes)),promiseCache=useRef7(new LRUCache),searchCriteria=useMemo8(()=>targetType?.type==="profile"?{...props.searchCriteria,_profile:targetType.value}:props.searchCriteria,[props.searchCriteria,targetType]);useEffect6(()=>{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?isPopulated8(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=useCallback7(item=>{let newValue=item?createReference2(item):void 0;setValue(newValue),onChange&&onChange(newValue)},[onChange]),typeSelectOptions=useMemo8(()=>targetTypes?targetTypes.map(tt=>({value:tt.value,label:tt.type==="profile"?tt.title??tt.name??tt.resourceType??tt.value:tt.value})):[],[targetTypes]);return jsxs31(Group18,{gap:"xs",grow:!0,wrap:"nowrap",children:[targetTypes&&targetTypes.length>1&&jsx57(NativeSelect7,{"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&&jsx57(ResourceTypeInput,{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"}),jsx57(ResourceInput,{resourceType:targetType?.resourceType,name:props.name+"-id",required:props.required,placeholder:props.placeholder,defaultValue:value,searchCriteria,onChange:setValueHelper})]})}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=tryGetProfile4(profileUrl);if(profile)return{type:profile.type,name:profile.name,title:profile.title};let query=`{
|
|
65
|
+
`)}function getIssuesForExpression(outcome,expression){return outcome?.issue?.filter(issue=>isExpressionMatch(issue.expression?.[0],expression))}function isExpressionMatch(expr1,expr2){if(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{jsx as jsx42}from"react/jsx-runtime";function FormSection(props){let{debugMode}=useContext6(ElementsContext),label;return debugMode&&props.fhirPath?label=`${props.title} - ${props.fhirPath}`:label=props.title,jsx42(Input2.Wrapper,{id:props.htmlFor,label,description:props.description,withAsterisk:props.withAsterisk,error:getErrorsForInput(props.outcome,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 obj[propName]=value,obj}function isSupportedProfileStructureDefinition(profile){return!!profile&&!isEmpty3(profile.url)&&!isEmpty3(profile.name)}import{Checkbox,Group as Group22,NativeSelect as NativeSelect9,Textarea as Textarea2,TextInput as TextInput12}from"@mantine/core";import{applyDefaultValuesToElement,capitalize as capitalize2,getPathDifference,HTTP_HL7_ORG,isComplexTypeCode,isEmpty as isEmpty6,isPopulated as isPopulated10,PropertyType as PropertyType2}from"@medplum/core";import{useContext as useContext11,useMemo as useMemo10,useState as useState31}from"react";import{useState as useState13}from"react";import{jsx as jsx43}from"react/jsx-runtime";function CodeableConceptInput(props){let{defaultValue:defaultValue2,onChange,withHelpText,...rest}=props,[value,setValue]=useState13(defaultValue2);function handleChange(newValues){let newConcept=valueSetElementToCodeableConcept(newValues);setValue(newConcept),onChange&&onChange(newConcept)}return jsx43(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 useState14}from"react";import{jsx as jsx44}from"react/jsx-runtime";function CodingInput(props){let{defaultValue:defaultValue2,onChange,withHelpText,...rest}=props,[value,setValue]=useState14(defaultValue2);function handleChange(newValues){let newValue=newValues[0],newConcept=newValue&&valueSetElementToCoding(newValue);setValue(newConcept),onChange&&onChange(newConcept)}return jsx44(ValueSetAutocomplete,{defaultValue:value&&codingToValueSetElement(value),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 Group10,TextInput as TextInput5}from"@mantine/core";import{useRef as useRef6,useState as useState16}from"react";import{Group as Group9,NativeSelect as NativeSelect3,TextInput as TextInput4}from"@mantine/core";import{useContext as useContext7,useMemo as useMemo5,useRef as useRef5,useState as useState15}from"react";import{jsx as jsx45,jsxs as jsxs22}from"react/jsx-runtime";function ContactPointInput(props){let{path,outcome}=props,{elementsByPath}=useContext7(ElementsContext),[contactPoint,setContactPoint]=useState15(props.defaultValue),ref=useRef5();ref.current=contactPoint;let[systemElement,useElement,valueElement]=useMemo5(()=>["system","use","value"].map(field=>elementsByPath[path+"."+field]),[elementsByPath,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)}return jsxs22(Group9,{gap:"xs",grow:!0,wrap:"nowrap",align:"flex-start",children:[jsx45(NativeSelect3,{"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,path+".system")}),jsx45(NativeSelect3,{"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,path+".use")}),jsx45(TextInput4,{placeholder:"Value",defaultValue:contactPoint?.value,required:(valueElement?.min??0)>0,onChange:e=>setValue(e.currentTarget.value),error:getErrorsForInput(outcome,path+".value")})]})}import{jsx as jsx46,jsxs as jsxs23}from"react/jsx-runtime";function ContactDetailInput(props){let[contactPoint,setContactDetail]=useState16(props.defaultValue),ref=useRef6();ref.current=contactPoint;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 jsxs23(Group10,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx46(TextInput5,{"data-testid":props.name+"-name",name:props.name+"-name",placeholder:"Name",style:{width:180},defaultValue:contactPoint?.name,onChange:e=>setName(e.currentTarget.value)}),jsx46(ContactPointInput,{name:props.name+"-telecom",path:props.path+".telecom",defaultValue:contactPoint?.telecom?.[0],onChange:setTelecom,outcome:props.outcome})]})}import{TextInput as TextInput6}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 jsx47}from"react/jsx-runtime";function DateTimeInput(props){return jsx47(TextInput6,{id:props.name,name:props.name,label:props.label,"data-autofocus":props.autoFocus,"data-testid":props.name,placeholder:props.placeholder,required:props.required,type:getInputType(),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{tryGetProfile as tryGetProfile3,isProfileLoaded as isProfileLoaded2,isPopulated as isPopulated6}from"@medplum/core";import{useEffect as useEffect5,useMemo as useMemo6,useState as useState17}from"react";import{jsx as jsx48}from"react/jsx-runtime";function ExtensionInput(props){let{propertyType}=props,medplum=a(),[typeSchema,setTypeSchema]=useState17(),profileUrl=useMemo6(()=>{if(isPopulated6(propertyType.profile))return propertyType.profile[0]},[propertyType]),[loadingProfile,setLoadingProfile]=useState17(profileUrl!==void 0);return useEffect5(()=>{profileUrl&&(setLoadingProfile(!0),medplum.requestProfileSchema(profileUrl).then(()=>{let profile=tryGetProfile3(profileUrl);setLoadingProfile(!1),setTypeSchema(profile)}).catch(reason=>{setLoadingProfile(!1),console.warn(reason)}))},[medplum,profileUrl]),profileUrl&&(loadingProfile||!isProfileLoaded2(profileUrl))?jsx48("div",{children:"Loading..."}):jsx48(BackboneElementInput,{profileUrl,path:props.path,typeName:typeSchema?.name??"Extension",defaultValue:props.defaultValue,onChange:props.onChange})}import{Group as Group11,NativeSelect as NativeSelect4,TextInput as TextInput7}from"@mantine/core";import{useState as useState18}from"react";import{jsx as jsx49,jsxs as jsxs24}from"react/jsx-runtime";function HumanNameInput(props){let{outcome,path}=props,[value,setValue]=useState18(props.defaultValue);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})}return jsxs24(Group11,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx49(NativeSelect4,{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,path+".use")}),jsx49(TextInput7,{placeholder:"Prefix",name:props.name+"-prefix",defaultValue:value?.prefix?.join(" "),onChange:e=>setPrefix(e.currentTarget.value),error:getErrorsForInput(outcome,path+".prefix")}),jsx49(TextInput7,{placeholder:"Given",name:props.name+"-given",defaultValue:value?.given?.join(" "),onChange:e=>setGiven(e.currentTarget.value),error:getErrorsForInput(outcome,path+".given")}),jsx49(TextInput7,{name:props.name+"-family",placeholder:"Family",defaultValue:value?.family,onChange:e=>setFamily(e.currentTarget.value),error:getErrorsForInput(outcome,path+".family")}),jsx49(TextInput7,{placeholder:"Suffix",name:props.name+"-suffix",defaultValue:value?.suffix?.join(" "),onChange:e=>setSuffix(e.currentTarget.value),error:getErrorsForInput(outcome,path+".suffix")})]})}import{Group as Group12,TextInput as TextInput8}from"@mantine/core";import{useContext as useContext8,useMemo as useMemo7,useState as useState19}from"react";import{jsx as jsx50,jsxs as jsxs25}from"react/jsx-runtime";function IdentifierInput(props){let{path,outcome}=props,[value,setValue]=useState19(props.defaultValue),{elementsByPath}=useContext8(ElementsContext),[systemElement,valueElement]=useMemo7(()=>["system","value"].map(field=>elementsByPath[path+"."+field]),[elementsByPath,path]);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs25(Group12,{gap:"xs",grow:!0,wrap:"nowrap",align:"flex-start",children:[jsx50(TextInput8,{placeholder:"System",required:(systemElement?.min??0)>0,defaultValue:value?.system,onChange:e=>setValueWrapper({...value,system:e.currentTarget.value}),error:getErrorsForInput(outcome,path+".system")}),jsx50(TextInput8,{placeholder:"Value",required:(valueElement?.min??0)>0,defaultValue:value?.value,onChange:e=>setValueWrapper({...value,value:e.currentTarget.value}),error:getErrorsForInput(outcome,path+".value")})]})}import{NativeSelect as NativeSelect5,TextInput as TextInput9}from"@mantine/core";import{useCallback as useCallback5,useState as useState20}from"react";import{jsx as jsx51}from"react/jsx-runtime";var data=["USD","EUR","CAD","GBP","AUD"];function MoneyInput(props){let{onChange}=props,[value,setValue]=useState20(props.defaultValue),setValueWrapper=useCallback5(newValue=>{setValue(newValue),onChange&&onChange(newValue)},[onChange]),handleCurrencyChange=useCallback5(e=>{setValueWrapper({...value,currency:e.currentTarget.value})},[value,setValueWrapper]),handleValueChange=useCallback5(e=>{setValueWrapper({...value,value:e.currentTarget.valueAsNumber})},[value,setValueWrapper]),select=jsx51(NativeSelect5,{defaultValue:value?.currency,data,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:handleCurrencyChange});return jsx51(TextInput9,{type:"number",name:props.name,label:props.label,placeholder:props.placeholder??"Value",defaultValue:value?.value?.toString()??"USD",leftSection:jsx51(IconCurrencyDollar,{size:14}),rightSection:select,rightSectionWidth:92,onChange:handleValueChange})}import{Group as Group13}from"@mantine/core";import{useState as useState21}from"react";import{jsx as jsx52,jsxs as jsxs26}from"react/jsx-runtime";function PeriodInput(props){let[value,setValue]=useState21(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs26(Group13,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx52(DateTimeInput,{name:props.name+".start",placeholder:"Start",defaultValue:value?.start,onChange:newValue=>setValueWrapper({...value,start:newValue})}),jsx52(DateTimeInput,{name:props.name+".end",placeholder:"End",defaultValue:value?.end,onChange:newValue=>setValueWrapper({...value,end:newValue})})]})}import{Group as Group14,NativeSelect as NativeSelect6,TextInput as TextInput10}from"@mantine/core";import{useState as useState22}from"react";import{jsx as jsx53,jsxs as jsxs27}from"react/jsx-runtime";function QuantityInput(props){let[value,setValue]=useState22(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs27(Group14,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx53(NativeSelect6,{style:{width:80},"data-testid":props.name+"-comparator",defaultValue:value?.comparator,data:["","<","<=",">=",">"],onChange:e=>setValueWrapper({...value,comparator:e.currentTarget.value})}),jsx53(TextInput10,{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)})}}),jsx53(TextInput10,{placeholder:"Unit","data-testid":props.name+"-unit",defaultValue:value?.unit,onChange:e=>setValueWrapper({...value,unit:e.currentTarget.value})})]})}function tryParseNumber(str){if(str)return parseFloat(str)}import{Group as Group15}from"@mantine/core";import{useState as useState23}from"react";import{jsx as jsx54,jsxs as jsxs28}from"react/jsx-runtime";function RangeInput(props){let[value,setValue]=useState23(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs28(Group15,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx54(QuantityInput,{name:props.name+"-low",defaultValue:value?.low,onChange:v2=>setValueWrapper({...value,low:v2})}),jsx54(QuantityInput,{name:props.name+"-high",defaultValue:value?.high,onChange:v2=>setValueWrapper({...value,high:v2})})]})}import{Group as Group16}from"@mantine/core";import{useState as useState24}from"react";import{jsx as jsx55,jsxs as jsxs29}from"react/jsx-runtime";function RatioInput(props){let[value,setValue]=useState24(props.defaultValue);function setValueWrapper(newValue){setValue(newValue),props.onChange&&props.onChange(newValue)}return jsxs29(Group16,{gap:"xs",grow:!0,wrap:"nowrap",children:[jsx55(QuantityInput,{name:props.name+"-numerator",defaultValue:value?.numerator,onChange:v2=>setValueWrapper({...value,numerator:v2})}),jsx55(QuantityInput,{name:props.name+"-denominator",defaultValue:value?.denominator,onChange:v2=>setValueWrapper({...value,denominator:v2})})]})}import{Group as Group18,NativeSelect as NativeSelect7}from"@mantine/core";import{LRUCache,ReadablePromise,createReference as createReference2,isEmpty as isEmpty4,isPopulated as isPopulated8,tryGetProfile as tryGetProfile4}from"@medplum/core";import{useCallback as useCallback7,useEffect as useEffect6,useMemo as useMemo8,useRef as useRef7,useState as useState26}from"react";import{Group as Group17,Text as Text6}from"@mantine/core";import{getDisplayString as getDisplayString3,getReferenceString as getReferenceString3,isPopulated as isPopulated7}from"@medplum/core";import{forwardRef as forwardRef4,useCallback as useCallback6,useState as useState25}from"react";import{jsx as jsx56,jsxs as jsxs30}from"react/jsx-runtime";var SEARCH_CODES={Device:"device-name",Observation:"code",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","RiskEvidenceSynthesis","SearchParameter","StructureDefinition","StructureMap","TerminologyCapabilities","TestScript","UserConfiguration","ValueSet"];function toOption3(resource){return{value:getReferenceString3(resource),label:getDisplayString3(resource),resource}}function ResourceInput(props){let medplum=a(),{resourceType,searchCriteria}=props,[outcome,setOutcome]=useState25(),defaultValue2=pe(props.defaultValue,setOutcome),onChange=props.onChange,loadValues=useCallback6(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=useCallback6(newResources=>{onChange&&onChange(newResources[0])},[onChange]);return isPopulated7(props.defaultValue)&&!outcome&&!defaultValue2?null:jsx56(AsyncAutocomplete,{name:props.name,required:props.required,itemComponent:ItemComponent3,defaultValue:defaultValue2,placeholder:props.placeholder,maxValues:1,toOption:toOption3,loadOptions:loadValues,onChange:handleChange,clearable:!0})}var ItemComponent3=forwardRef4(({label,resource,...others},ref)=>jsx56("div",{ref,...others,children:jsxs30(Group17,{wrap:"nowrap",children:[jsx56(ResourceAvatar,{value:resource}),jsxs30("div",{children:[jsx56(Text6,{children:label}),jsx56(Text6,{size:"xs",c:"dimmed",children:resource.birthDate})]})]})}));function getSearchParamForResourceType(resourceType){return SEARCH_CODES[resourceType]??(NAME_RESOURCE_TYPES.includes(resourceType)?"name":"_id")}import{jsx as jsx57,jsxs as jsxs31}from"react/jsx-runtime";function ReferenceInput(props){let{onChange}=props,medplum=a(),[value,setValue]=useState26(props.defaultValue),[targetTypes,setTargetTypes]=useState26(()=>createTargetTypes(props.targetTypes)),[targetType,setTargetType]=useState26(()=>getInitialTargetType(props.defaultValue,targetTypes)),promiseCache=useRef7(new LRUCache),searchCriteria=useMemo8(()=>targetType?.type==="profile"?{...props.searchCriteria,_profile:targetType.value}:props.searchCriteria,[props.searchCriteria,targetType]);useEffect6(()=>{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?isPopulated8(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=useCallback7(item=>{let newValue=item?createReference2(item):void 0;setValue(newValue),onChange&&onChange(newValue)},[onChange]),typeSelectOptions=useMemo8(()=>targetTypes?targetTypes.map(tt=>({value:tt.value,label:tt.type==="profile"?tt.title??tt.name??tt.resourceType??tt.value:tt.value})):[],[targetTypes]);return jsxs31(Group18,{gap:"xs",grow:!0,wrap:"nowrap",children:[targetTypes&&targetTypes.length>1&&jsx57(NativeSelect7,{"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&&jsx57(ResourceTypeInput,{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"}),jsx57(ResourceInput,{resourceType:targetType?.resourceType,name:props.name+"-id",required:props.required,placeholder:props.placeholder,defaultValue:value,searchCriteria,onChange:setValueHelper})]})}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=tryGetProfile4(profileUrl);if(profile)return{type:profile.type,name:profile.name,title:profile.title};let query=`{
|
|
66
66
|
StructureDefinitionList(url: "${profileUrl}", _sort: "_lastUpdated", _count: 1) {
|
|
67
67
|
type,
|
|
68
68
|
name,
|