@openmrs/esm-implementer-tools-app 11.0.1-pre.6018 → 11.0.1-pre.6028

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/4823.js CHANGED
@@ -12,7 +12,7 @@ If you're the maintainer: the 'elements' key only works with '_type' equal to 'A
12
12
  ${t}`)}return o}let eX=(e,t)=>{let n=structuredClone(t);if(!e)return n;for(let t of Object.keys(e)){let o=n[t],r=e[t];if(r&&(r.hasOwnProperty("_type")||r.hasOwnProperty("_default"))){n.hasOwnProperty(t)||(n[t]=r._default);let e=r._elements;if(o&&eY(e)){if(r._type===z.Array&&Array.isArray(o)){let r=o.map(t=>eX(e,t));n[t]=r}else if(r._type===z.Object)for(let t of Object.keys(o))o[t]=eX(e,o[t])}}else if(eZ(r)){let e=o??{};eZ(e)&&(n[t]=eX(r,e))}}return n};function eY(e){return!!e&&Object.keys(e).filter(e=>!["_default","_validators"].includes(e)).length>0}function eZ(e){return"object"==typeof e&&!Array.isArray(e)&&null!==e}function eQ(e,t){let n=`${e}:::${t}`;ex.has(n)||(console.error(t),ex.add(n))}function e0(e){e?ex.forEach(t=>{t.startsWith(e)&&ex.delete(t)}):ex.clear()}function e1(){eb.forEach(e=>e()),eb.length=0,eC.clear(),eD.clear(),eB.clear(),eU.clear(),eS=null,ej=new WeakMap,ek()}let e2={"Translation overrides":{_description:"Per-language overrides for frontend translations should be keyed by language code and each language dictionary contains the translation key and the display value",_type:z.Object,_default:{},_validators:[G(e=>Object.keys(e).every(e=>/^[a-z]{2,3}(-[A-Z]{2,3})?$/.test(e)),e=>{let t=Object.keys(e).filter(e=>!/^[a-z]{2,3}(-[A-Z]{2,3})?$/.test(e));return`The 'Translation overrides' object should have language codes for keys. Language codes must be in the form of a two-to-three letter language code optionally followed by a hyphen and a two-to-three letter country code. The following keys do not conform: ${t.join(", ")}.`})]}},e5={"Display conditions":{privileges:{_description:"The privilege(s) the user must have to use this extension",_type:z.Array,_default:[]},expression:{_description:"The expression that determines whether the extension is displayed",_type:z.String,_default:void 0}},...e2},e6=(e,t)=>G(n=>e<=n&&n<=t,`must be between ${e} and ${t}`),e8=e=>{let t=e.concat(["openmrsBase","openmrsSpaBase"]);return G(e=>{if(!e||"string"!=typeof e)return!1;let n=/\${(.*?)}/g,o=n.exec(e);for(;o;){if(!t.includes(o[1]))return!1;o=n.exec(e)}return!0},"Should be a URL or path. The allowed template parameters are "+t.map(e=>"${"+e+"}").join(", "))},e4=e8([]),e3=e=>G(t=>e.includes(t),`Must be one of the following: '${e.join("', '")}'.`),e7={inRange:e6,isUrl:e4,isUrlWithTemplateParameters:e8,oneOf:e3};var e9=n(4913);let te=R("breadcrumbs",[]);function tt(e){return tn([e])}function tn(e){let t=[...to(),...e.map(e=>({matcher:e.matcher instanceof RegExp?e.matcher:"string"==typeof e.matcher?(0,e9.pathToRegexp)(e.matcher).regexp:(0,e9.pathToRegexp)(e.path).regexp,settings:e}))];te.setState(t,!0)}function to(){return te.getState()}function tr(e,t){if(t)return function(e,t){let[n]=e.filter(e=>e.matcher.test(t));return n}(e,t)||function(e,t){let n=t.split("/");for(;n.length>1;){n.pop();let t=tr(e,n.join("/"));if(t)return t}}(e,t)}function ti(e,t){if(e.length>0){let n=tr(e,t);if(n){let t=[n],o=tr(e,n.settings.parent);for(;void 0!==o;)t.push(o),o=tr(e,o.settings.parent);return t.reverse()}}return[]}function ts(e){return ti(to(),e)}var ta=n(2267),tl=n(2279);let tc={address1:"Address line 1",address2:"Address line 2",address3:"Address line 3",address4:"Address line 4",address5:"Address line 5",address6:"Address line 6",city:"City",cityVillage:"City",country:"Country",countyDistrict:"District",district:"District",postalCode:"Postal code",state:"State",stateProvince:"State",closeAllOpenedWorkspaces:"Discard changes in {{count}} workspaces",closingAllWorkspacesPromptBody:"There may be unsaved changes in the following workspaces. Do you want to discard changes in the following workspaces? {{workspaceNames}}",closingAllWorkspacesPromptTitle:"You have unsaved changes",discard:"Discard",hide:"Hide",maximize:"Maximize",minimize:"Minimize",openAnyway:"Open anyway",unsavedChangesInOpenedWorkspace:"You may have unsaved changes in the opened workspace. Do you want to discard these changes?",unsavedChangesInWorkspace:'There may be unsaved changes in "{{workspaceName}}". Please save them before opening another workspace.',unsavedChangesTitleText:"Unsaved changes",workspaceHeader:"Workspace header",discardUnsavedChangesPromptBodyMultiple:"{{count}} workspaces have unsaved changes. Closing them will discard the changes:",discardUnsavedChangesPromptBodySingle:"<strong>{{workspaceTitle}}</strong> has unsaved changes. Closing it will discard them.",discardUnsavedChangesPromptTitle:"Discard unsaved changes?",keepEditing:"Keep editing",abnormalValue:"Abnormal value",actions:"Actions",actionableNotification:"Actionable notification",address:"Address",age:"Age",applicationError:"Application Error",batchActionItemSelected:"{{totalSelected}} item selected",batchActionsItemsSelected:"{{totalSelected}} items selected",cancel:"Cancel",change:"Change",Clinic:"Clinic",clearDevOverrides:"Clear dev overrides",close:"Close",closesActionableNotification:"Close actionable notification",closeSnackbar:"Close snackbar",confirm:"Confirm",contactAdministratorIfIssuePersists:"Contact your system administrator if the problem persists.",contactDetails:"Contact details",copied:"Copied!",copyToClipboard:"Copy to clipboard",delete:"Delete",discardChanges:"Discard changes",edit:"Edit",emptyStateText:"There are no {{displayText}} to display",error:"Error",errorCopy:"Sorry, there was a problem displaying this information. You can try to reload this page, or contact the site administrator and quote the error code above.",errorLoadingLoginLocations:"Unable to load login locations. Please try again or contact support if the problem persists.",female:"Female",leftNavigation:"Left navigation",loading:"Loading",localVersion:"Local Build",male:"Male",navigateNonHttp:"Could not navigate to the requested page as it is not a safe URL",noResultsToDisplay:"No results to display",notAvailable:"Not available",other:"Other",paginationItemsCount:"{{pageItemsCount}} / {{totalItems}} items",paginationOfPages:"of {{count}} pages",patientAvatarAlt:"Avatar for {{patientName}}",patientIdentifierSticker:"Patient identifier sticker",patientLists:"Patient lists",patientPhotoAlt:"Profile photo of {{patientName}}",patientPhotoPlaceholder:"Photo placeholder for {{patientName}}",prereleaseVersion:"Prerelease",print:"Print",printError:"Print error",printErrorExplainer:"An error occurred in {{errorLocation}}",printIdentifierSticker:"Print identifier sticker",printing:"Printing",provisional:"Provisional",recordNewEntry:"Record {{displayText}}",relationships:"Relationships",reload:"Reload",resetOverrides:"Reset overrides",save:"Save",scriptLoadingFailed:"Error: Script failed to load",scriptLoadingError:"Failed to load overridden script from {{url}}. Please check that the bundled script is available at the expected URL. Click the button below to reset all import map overrides.",searchForLocation:"Search for a location",seeAll:"See all",seeMoreLists:"See {{count}} more lists",selectAll:"Select all",serverStartingUp:"The server is starting",serverStartingUpExplainer:"This can take a few minutes. OpenMRS will open automatically when the server is ready.",serverStartingUpSlowExplainer:"This is taking longer than usual. First startup after an upgrade can take 10 minutes or more. You can leave this page open.",sex:"Sex",showLess:"Show less",showMore:"Show more",snackbarNotification:"Snackbar notification",somethingWentWrongTryReloading:"Something went wrong. Please try reloading.",toggleDevTools:"Toggle dev tools",unknown:"Unknown",viewSetupProgress:"View setup progress",waitingForServer:"Waiting for the server",yearAbbreviation:"yr",yearsAbbreviation:"yrs"},tu=tl.Ay.default||tl.Ay,td="___",tm=new Map,tp=!1;function tf(){tp=!0,tu.emit("languageChanged",tu.language)}function tg(){tp=!1,tm.clear()}function th(){return tp}function tw(e){if(!tp)return;let t=tm.get(e.value);if(!t){tm.size>=2e4&&tm.delete(tm.keys().next().value),tm.set(e.value,[{...e}]);return}let n=t.find(t=>t.key===e.key&&t.namespace===e.namespace&&t.extensionNamespace===e.extensionNamespace);n?n.hasCount||(n.hasCount=e.hasCount):t.push({...e}),tm.delete(e.value),tm.set(e.value,t)}function t_(e){return e&&tp?(tm.get(e)??tm.get(e.trim())??[]).map(e=>({...e})):[]}let ty=tl.Ay.default||tl.Ay;function tv(e,t,n,o){return ty.t(t,{ns:e,defaultValue:n,...o})}function tb(e,t,n){return tc[e]?tv("core",e,t??tc[e],n):(console.error(`O3 Core Translations does not provide key '${e}'. The key itself is being rendered as text.`),e)}function tx(e,t){let n=window.getOpenmrsSpaBase().replace(/\/$/,""),o=tS(e,{openmrsBase:window.openmrsBase,openmrsSpaBase:n,...t});return e.startsWith("//")?o:o.replace(/^\/\//,"/")}function tS(e,t){return Object.keys(t).reduce((e,n)=>e.split("${"+n+"}").join(t[n]),e)}function tj({to:e,templateParams:t}){let n=window.getOpenmrsSpaBase().replace(/\/$/,""),o=tx(e,t).replace(window.location.origin,""),r=new URL(o,window.location.origin);if("http:"!=r.protocol&&"https:"!=r.protocol)throw console.error(`Received request to navigate to non-http URL: ${r.toString()}`),Error(tb("navigateNonHttp"));o.startsWith(n)?(0,ta.EH)(o):window.location.assign(o)}ty.on("initialized",function(){window.i18next.loadNamespaces(["core"])});let tk="openmrs:history";function tN(e){let t=JSON.parse(sessionStorage.getItem(tk)??"[]")||[];t.push(e),t.length>50&&(t=t.slice(-50)),sessionStorage.setItem(tk,JSON.stringify(t))}function tC(){0===JSON.parse(sessionStorage.getItem(tk)??"[]").length&&document.referrer&&tN(document.referrer),window.addEventListener("single-spa:routing-event",e=>{let t=tE();e.detail.originalEvent?.singleSpaTrigger=="replaceState"?(t[t.length-1]=window.location.href,sessionStorage.setItem(tk,JSON.stringify(t))):!e.detail.originalEvent?.singleSpa&&t.includes(window.location.href)?tP({toUrl:window.location.href}):t[t.length-1]!==window.location.href&&tN(window.location.href)})}function tE(){return JSON.parse(sessionStorage.getItem(tk)??"[]")}function tP({toUrl:e}){let t=tE(),n=t.lastIndexOf(e);if(-1!=n){let e=t.slice(0,n+1);tj({to:t[n]}),sessionStorage.setItem(tk,JSON.stringify(e))}else throw Error(`URL ${e} not found in history; cannot go back to it.`)}function tI(){sessionStorage.removeItem(tk)}let tO="${openmrsSpaBase}/login",tA={redirectAuthFailure:{enabled:{_type:z.Boolean,_default:!0,_description:"Whether to redirect logged-out users to `redirectAuthFailure.url`"},url:{_type:z.String,_default:tO,_validators:[e7.isUrl],_description:"The url to which users will be redirected when they are logged out. If set to blank, the `location` header from the response will be used."},errors:{_type:z.Array,_default:[401],_elements:{_type:z.Number,_validators:[e7.inRange(100,600)]},_description:"The HTTP error codes for which users will be redirected"},resolvePromise:{_type:z.Boolean,_default:!1,_description:"Changes how requests that fail authentication are handled. Try messing with this if redirects to the login page aren't working correctly."}},followRedirects:{_type:z.Boolean,_default:!0,_description:"Whether openmrsFetch should support redirects returned from the backend"}};function tR(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let tT="/ws/rest/v1",t$="/ws/fhir2/R4",tM=`${tT}/session`;function tL(e){return e&&e.startsWith("http")?e:("/"!==e[0]&&(e="/"+e),window.openmrsBase+e)}function tW(e,t={}){if("string"!=typeof e)throw Error("The first argument to @openmrs/api's openmrsFetch function must be a url string");if("object"!=typeof t)throw Error("The second argument to @openmrs/api's openmrsFetch function must be a plain object.");if(!window.openmrsBase)throw Error("@openmrs/api is running in a browser that doesn't have window.openmrsBase, which is provided by openmrs-module-spa's HTML file.");let n=tL(e);t.headers||(t.headers={}),(0,U.A)(t.body)&&(t.body=JSON.stringify(t.body)),void 0===t.headers.Accept&&(t.headers.Accept="application/json"),null===t.headers.Accept&&delete t.headers.Accept;let o=!1;try{let e=new URL(n,window.location.href),t=new URL(tL(tT),window.location.href),r=e.pathname.replace(/\/{2,}/g,"/"),i=t.pathname.replace(/\/{2,}/g,"/");o=e.origin===t.origin&&(r===i||r.startsWith(`${i}/`))}catch{}if(o){let e=!1;for(let[n,o]of Object.entries(t.headers))"disable-www-authenticate"===n.toLowerCase()&&(void 0===o?delete t.headers[n]:e=!0);e||(t.headers["Disable-WWW-Authenticate"]="true")}if(e.startsWith(t$)){let e=new URL(n,window.location.toString());e.searchParams.has("_summary")||(e.searchParams.set("_summary","data"),n=e.toString())}let r=Error();return window.fetch(n,t).then(async e=>{let{redirectAuthFailure:o,followRedirects:i}=await eM("@openmrs/esm-api");if(e.ok){let t=e.headers.get("location");return(i&&t&&(n===tL(tM)||204===e.status)&&tj({to:t}),204===e.status)?(e.data=null,e):e.clone().text().then(t=>{try{t&&(e.data=JSON.parse(t))}catch(e){}return e})}return(n===tL(tM)&&403===e.status||o.enabled&&o.errors.includes(e.status))&&(tI(),tj({to:o.url||e.headers.get("location")||tO}),!0!==t.rejectAuthFailure)?o.resolvePromise?Promise.resolve():new Promise(()=>{}):e.clone().text().then(t=>{let o=t;try{o=JSON.parse(t)}catch(e){}throw new tD(n,e,o,r)},()=>{throw new tD(n,e,null,r)})})}class tD extends Error{constructor(e,t,n,o){super(),tR(this,"response",void 0),tR(this,"responseBody",void 0),this.message=`Server responded with ${t.status} (${t.statusText}) for url ${e}. Check err.responseBody or network tab in dev tools for more info`,o.message=this.message,this.responseBody=n,this.response=t,this.stack=`Stacktrace for outgoing request:
13
13
  ${o.stack}
14
14
  Stacktrace for incoming response:
15
- ${this.stack}`}}let tU=R("session",{loaded:!1,session:null}),tB=0,tF=null;function tH(){return tF||(tU.getState().loaded&&tB>=Date.now()-6e4?null:tq())}function tV(e){let t=e?.includeAuthStatus??!0,n=e=>t?e:e.user,o=tH();return o?new Promise(e=>{let t=()=>{let t=tU.getState();t.loaded&&(r(),e(n(t.session)))},r=tU.subscribe(t);o.then(t,t)}):Promise.resolve(n(tU.getState().session))}function tz(){return tH(),tU}function tG(e){let t=e.locale??e.user?.userProperties?.defaultLocale;t&&t.includes("_")&&(t=t.replaceAll("_","-")),function(e){if(void 0===e||"string"!=typeof e)return!1;try{new Intl.Locale(e)}catch(e){return!1}return!0}(t)&&t!==document.documentElement.getAttribute("lang")&&document.documentElement.setAttribute("lang",t)}function tq(e,t){tB=Date.now(),r??(r=tB);let n={};e&&t&&(n.Authorization=`Basic ${window.btoa(`${e}:${t}`)}`);let o=t5(tW(tM,{headers:n,rejectAuthFailure:!0})),i=()=>{tF===o&&(tF=null)};return o.then(i,i),tF=o,o}function tJ(){tU.setState({loaded:!0,session:{authenticated:!1,sessionId:""}},!0)}function tK(e,t){var n,o;if(void 0===t)return!e;if(!e)return!0;return n=e,o=t,("string"==typeof n?!(0,D.A)(o.privileges.find(e=>n===e.display)):Array.isArray(n)?n.every(e=>!(0,D.A)(o.privileges.find(t=>e===t.display))):((0,D.A)(n)||console.error(`Could not understand privileges "${n}"`),!0))||!(0,D.A)(t.roles.find(e=>"System Developer"===e.display))}function tX(){let e,t;return new Promise(n=>{let o=o=>{o.loaded&&o.session.user&&(e=o.session.user,n(o.session.user),t&&t())};o(tU.getState()),e||(t=tU.subscribe(o))})}async function tY(){return(await tV()).sessionLocation}async function tZ(e,t){return t5(tW(tM,{method:"POST",body:{sessionLocation:e},headers:{"Content-Type":"application/json"},rejectAuthFailure:!0,signal:t?.signal}))}async function tQ(e,t){return await tW(tM,{method:"POST",body:{locale:e},headers:{"Content-Type":"application/json"},signal:t?.signal}),tq()}async function t0(e,t,n){return n||(n=new AbortController),await tW(`${tT}/user/${e}`,{method:"POST",body:{userProperties:t},headers:{"Content-Type":"application/json"},signal:n.signal}),tq()}async function t1(e,t=!1){let n=await tW(t?`${tM}?rememberMe=true`:tM,{headers:{"X-Totp-Code":e}});return n.data?.authenticated?(await tq()).session:n.data}async function t2(){try{await tW(tM,{method:"DELETE",rejectAuthFailure:!0})}catch(e){if(!t6(e))throw e}tJ(),await tq().catch(()=>{})}function t5(e){return new Promise((t,n)=>{e.then(e=>{if("object"==typeof e?.data){let n={loaded:!0,session:e.data};tU.setState(n,!0),t(n)}else!function(e){if(!e?.redirected||!e.url)return!1;try{return new URL(e.url,window.location.href).pathname.replace(/\/+$/,"").endsWith("/initialsetup")}catch{return!1}}(e)?n(t8(Error("The session endpoint did not respond with a session"))):n(t8(Error("The server is still starting up"),!0))}).catch(e=>{var o,i;if(t6(e)){"object"==typeof(o=e.responseBody)&&null!==o&&!1===o.authenticated?tU.setState({loaded:!0,session:e.responseBody},!0):tJ(),t(tU.getState());return}(i=e)instanceof tD&&502===i.response.status&&!tU.getState().loaded&&void 0!==r&&Date.now()-r<18e4?n(t8(e,!0)):(y(`Failed to fetch new session information: ${e}`),n(t8(e)))})})}function t6(e){return e instanceof tD&&(401===e.response.status||403===e.response.status)}function t8(e,t=!1){return tU.getState().loaded||tU.setState({loaded:!1,session:null,error:e instanceof Error?e:Error(String(e)),initializing:t},!0),tU.getState()}function t4(){return"development"===window.spaEnv||"true"===localStorage.getItem("openmrs:devtools")}tU.subscribe(e=>{e.loaded&&e.session&&tG(e.session)});let t3={"webservices.rest":"2.24.0",fhir2:"1.0.0-SNAPSHOT"};function t7(){eP("@openmrs/esm-api",tA),tq()}let t9="import-map-override:",ne="import-map-overrides-disabled",nt="import-map-overrides:change",nn=!1,no=null,nr=null;async function ni(){return nr??(nr=ns().then(({map:e,complete:t})=>(t||(nr=null),e))),nr}async function ns(){let e=document.querySelectorAll('script[type="systemjs-importmap"]'),t=[],n=!0;for(let o=0;o<e.length;o++){let r=e[o];try{if(r.src){let e=await fetch(r.src);if(!e.ok)throw Error(`Request for ${r.src} returned ${e.status} ${e.statusText}`);t.push(await e.json())}else r.textContent&&t.push(JSON.parse(r.textContent))}catch(e){n=!1,console.warn(`[import-maps] Failed to parse import map from script tag at index ${o}`,e)}}return{map:na(t),complete:n}}function na(e){let t={imports:{}};for(let n of e)n?.imports&&Object.assign(t.imports,n.imports);return t}function nl(){let e={};try{let t=np();for(let n=0;n<localStorage.length;n++){let o=localStorage.key(n);if(o?.startsWith(t9)){let n=o.slice(t9.length);if(!t.includes(n)){let t=localStorage.getItem(o);t&&(e[n]=t)}}}}catch(e){console.warn("[import-maps] Failed to read import-map overrides from localStorage",e)}return{imports:e}}async function nc(){let e=await ni();return nn?na([e,no??nl()]):e}async function nu(){return ni()}async function nd(){return nn?na([await ni(),nl()]):ni()}function nm(e){if(!nn)return{imports:{}};if(e){let e={};for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);if(n?.startsWith(t9)){let t=localStorage.getItem(n);t&&(e[n.slice(t9.length)]=t)}}return{imports:e}}return nl()}function np(){if(!nn)return[];try{let e=localStorage.getItem(ne);if(e){let t=JSON.parse(e);if(Array.isArray(t))return t}}catch{}return[]}function nf(e){return!!nn&&np().includes(e)}function ng(e,t){if(!nn)return void console.warn("[Security] Import map overrides are disabled in production mode.");try{localStorage.setItem(t9+e,t),window.dispatchEvent(new CustomEvent(nt))}catch(e){console.warn("[import-maps] Failed to write import-map override to localStorage",e)}}function nh(e){if(!nn)return void console.warn("[Security] Import map overrides are disabled in production mode.");try{localStorage.removeItem(t9+e);let t=np().filter(t=>t!==e);t.length>0?localStorage.setItem(ne,JSON.stringify(t)):localStorage.removeItem(ne),window.dispatchEvent(new CustomEvent(nt))}catch(e){console.warn("[import-maps] Failed to update import-map overrides in localStorage",e)}}function nw(){if(!nn)return void console.warn("[Security] Import map overrides are disabled in production mode.");try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n?.startsWith(t9)&&e.push(n)}e.forEach(e=>localStorage.removeItem(e)),localStorage.removeItem(ne),window.dispatchEvent(new CustomEvent(nt))}catch(e){console.warn("[import-maps] Failed to clear import-map overrides from localStorage",e)}}function n_(e){if(!nn)return void console.warn("[Security] Import map overrides are disabled in production mode.");try{let t=np().filter(t=>t!==e);t.length>0?localStorage.setItem(ne,JSON.stringify(t)):localStorage.removeItem(ne),window.dispatchEvent(new CustomEvent(nt))}catch(e){console.warn("[import-maps] Failed to update import-map overrides in localStorage",e)}}let ny=!1;function nv(){!ny&&(ny=!0,(nn="development"===window.spaEnv)&&(no=nl()))}function nb(e){return e.replace(/[\/\-@]/g,"_")}async function nx(e,t="./start",o){var r;let i,s=!o?.maxLoadingTime||o.maxLoadingTime<=0?6e5:o.maxLoadingTime;await Promise.race([nS(e,o?.importMap),new Promise((t,n)=>{i=setTimeout(()=>{var t;n(Error(`Could not resolve requested script, ${e}, within ${(t=s)<1e3?`${t} milliseconds`:t<6e4?`${Math.floor(t/1e3)} seconds`:t<36e5?`${Math.floor(t/6e4)} minutes`:t<864e5?`${Math.floor(t/36e5)} hours`:`${Math.floor(t/864e5)} days`}.`))},s)})]),i&&clearTimeout(i);let a=nb(e),l=window[a];if(!("object"==typeof(r=l)&&null!==r&&"init"in r&&"function"==typeof r.init&&"get"in r&&"function"==typeof r.get)){let e=`The global variable ${a} does not refer to a federated module`;throw console.error(e),Error(e)}l.init(n.S.default);let c=(await l.get(t))();if("object"!=typeof c||null===c){let t=`Container for ${e} did not return an ESM module as expected`;throw console.error(t),Error(t)}return c}async function nS(e,t){if("string"!=typeof e||0===e.trim().length){let e="Attempted to call importDynamic() without supplying a package to load";throw console.error(e),Error(e)}let n=nb(e);if(!window[n]){let n=t??await nj();if(!n.imports.hasOwnProperty(e)){let t=`Could not find the package ${e} defined in the current importmap`;throw console.error(t),Error(t)}let o=n.imports[e];o.startsWith("./")&&(o=window.spaBase+o.substring(1));let r=e in nm().imports;try{return await function(e){var t;let n=(t=window)[nk]??(t[nk]=new Map),o=n.get(e);if(o)return o;if(document.head.querySelector(`script[src="${e}"]`))return console.warn(`Script at ${e} already loaded. Not loading it again.`),Promise.resolve();let r=document.createElement("script");r.src=e,r.type="text/javascript",r.async=!0;let i=new Promise((t,o)=>{let i=setTimeout(()=>{console.error(`The script at ${e} did not load within 5 seconds. This may indicate an issue with the imports in the script's entry-point file or with the script's bundler configuration.`)},5e3);function s(){clearTimeout(i),r.removeEventListener("load",a),r.removeEventListener("error",l)}function a(){s(),t()}function l(t){s(),n.delete(e),r.remove();let i=`Failed to load script from ${e}`;console.error(i,t),o(t.message??i)}r.addEventListener("load",a),r.addEventListener("error",l),document.head.appendChild(r)});return n.set(e,i),i}(o)}catch(e){return r&&p({kind:"error",title:tb("scriptLoadingFailed","Error: Script failed to load"),description:tb("scriptLoadingError","Failed to load overridden script from {{- url}}. Please check that the bundled script is available at the expected URL. Click the button below to reset all import map overrides.",{url:o}),actionButtonLabel:tb("resetOverrides","Reset overrides"),onActionButtonClick(){nw(),window.location.reload()}}),Promise.reject(e)}}return Promise.resolve()}async function nj(){return nc()}let nk=Symbol.for("__openmrs_script_loading");function nN(e){return!!e&&"object"==typeof e&&!(Object.hasOwn(e,"pages")&&(!e.pages||!Array.isArray(e.pages))||Object.hasOwn(e,"extensions")&&(!e.extensions||!Array.isArray(e.extensions))||Object.hasOwn(e,"modals")&&(!e.modals||!Array.isArray(e.modals))||Object.hasOwn(e,"workspaces2")&&(!e.workspaces2||!Array.isArray(e.workspaces2))||Object.hasOwn(e,"workspaceWindows2")&&(!e.workspaceWindows2||!Array.isArray(e.workspaceWindows2))||Object.hasOwn(e,"workspaceGroups2")&&(!e.workspaceGroups2||!Array.isArray(e.workspaceGroups2)))}function nC(e){return!!e&&"object"==typeof e&&"routes"in e&&!!e.routes&&"object"==typeof e.routes&&Object.entries(e.routes).every(([e,t])=>"string"==typeof e&&nN(t))}let nE="openmrs-routes:",nP="openmrs-routes:change",nI=!1,nO=null,nA=null;async function nR(){return nA??(nA=nT().then(({map:e,complete:t})=>(t||(nA=null),e))),nA}async function nT(){let e=document.querySelectorAll("script[type='openmrs-routes']"),t=[],n=!0;for(let o=0;o<e.length;o++){let r=e[o];try{let e;if(r.src){let t=await fetch(r.src);if(!t.ok)throw Error(`Request for ${r.src} returned ${t.status} ${t.statusText}`);e=await t.json()}else r.textContent&&(e=JSON.parse(r.textContent));e&&nC(e)&&t.push(e)}catch(e){n=!1,console.warn(`[route-maps] Failed to parse routes from script tag at index ${o}`,e)}}return{map:n$(t),complete:n}}function n$(e){let t={routes:{}};for(let n of e)n&&"object"==typeof n&&!Array.isArray(n)&&(Object.assign(t.routes,n.routes),void 0===t.version&&void 0!==n.version&&(t.version=n.version));return t}async function nM(){let e={version:void 0,routes:{}};try{let t=[];for(let e=0;e<localStorage.length;e++){let n=localStorage.key(e);if(n?.startsWith(nE)){let e=localStorage.getItem(n);e&&t.push({moduleName:n.slice(nE.length),raw:e})}}for(let n of(await Promise.allSettled(t.map(async({moduleName:e,raw:t})=>{let n=JSON.parse(t);if(nN(n))return{moduleName:e,routes:n};if("string"==typeof n&&n.startsWith("http")){let t=await fetch(n),o=await t.json();if(nN(o))return{moduleName:e,routes:o};throw Error(`${n} did not resolve to a valid OpenmrsAppRoutes object`)}throw Error(`Override for ${e} is neither a valid routes object nor a URL`)}))))"fulfilled"===n.status?e.routes[n.value.moduleName]=n.value.routes:console.warn("[route-maps] Failed to load route override",n.reason)}catch(e){console.warn("[route-maps] Failed to read route overrides from localStorage",e)}return e}async function nL(){let e=await nR();return nI?n$([e,nO??await nM()]):e}async function nW(){return nR()}async function nD(){return nI?n$([await nR(),await nM()]):nR()}function nU(){if(!nI)return{};let e={};try{for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);if(n?.startsWith(nE)){let t=localStorage.getItem(n);t&&(e[n.slice(nE.length)]=t)}}}catch(e){console.warn("[route-maps] Failed to read route overrides from localStorage",e)}return e}function nB(e,t){if(!nI)return void console.warn("[Security] Route overrides are disabled outside development mode.");try{if("string"==typeof t)if(t.startsWith("http"))localStorage.setItem(nE+e,JSON.stringify(t));else{let n=JSON.parse(t);if(!nN(n))return void console.error(`The supplied routes for ${e} is not a valid OpenmrsAppRoutes object`,t);localStorage.setItem(nE+e,JSON.stringify(n))}else if(t instanceof URL)localStorage.setItem(nE+e,JSON.stringify(t.toString()));else{if(!nN(t))return void console.error(`Override for ${e} is not in a valid format. Expected either a Javascript Object, a JSON string of a Javascript object, or a URL`,t);localStorage.setItem(nE+e,JSON.stringify(t))}window.dispatchEvent(new CustomEvent(nP))}catch(e){console.warn("[route-maps] Failed to write route override to localStorage",e)}}function nF(e){if(!nI)return void console.warn("[Security] Route overrides are disabled outside development mode.");try{localStorage.removeItem(nE+e),window.dispatchEvent(new CustomEvent(nP))}catch(e){console.warn("[route-maps] Failed to remove route override from localStorage",e)}}function nH(){if(!nI)return void console.warn("[Security] Route overrides are disabled outside development mode.");try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n?.startsWith(nE)&&e.push(n)}e.forEach(e=>localStorage.removeItem(e)),window.dispatchEvent(new CustomEvent(nP))}catch(e){console.warn("[route-maps] Failed to clear route overrides from localStorage",e)}}let nV=null;function nz(){return nV||(nV=(nI="development"===window.spaEnv)?nM().then(e=>{nO=e}):Promise.resolve())}let nG=`${tT}/attachment`;function nq(e,t){return tW(`${nG}/${e}`,{signal:t.signal})}function nJ(e,t,n,o){return tW(nK(e,t,o),{signal:n.signal})}function nK(e,t,n){return n?`${nG}?patient=${e}&encounter=${n}`:`${nG}?patient=${e}&includeEncounterless=${t}`}async function nX(e,t,n){let o=new FormData;return o.append("fileCaption",t.fileDescription),o.append("patient",e),n&&o.append("encounter",n),t.file?o.append("file",t.file,t.fileName):(o.append("file",new File([""],t.fileName),t.fileName),o.append("base64Content",t.base64Content)),tW(`${nG}`,{method:"POST",body:o})}function nY(e,t){return tW(`${nG}/${e}`,{method:"DELETE",signal:t.signal})}async function nZ(e,t){return e?(await tW(`${t$}/Patient/${e}`,t)).data:null}function nQ(e,t){let n=new CustomEvent(`openmrs:${e}`,{detail:t??void 0,cancelable:!0,bubbles:!0});return window.dispatchEvent(n)}function n0(e,t){let n=e=>{t("detail"in e&&null!==e.detail?e.detail:void 0)};return window.addEventListener(`openmrs:${e}`,n),()=>{window.removeEventListener(`openmrs:${e}`,n)}}function n1(e){return{uuid:e.uuid,display:e.display}}function n2(e=null,t=null){let n=new URLSearchParams;e&&n.set("tag",e),t&&n.set("q",t);let o=n.toString();return tW(`${tT}/location${o?"?"+o:""}`).then(e=>e.data.results.map(n1))}function n5(e){return{uuid:e.uuid,display:e.display,name:e.name}}let n6=`${tT}/visittype`;function n8(e=n6){return tW(e).then(e=>e.data.results.map(n5))}var n4=((j={}).NEWVISIT="startVisit",j.EDITVISIT="editVisit",j.LOADING="loadingVisit",j),n3=((k={}).NOTSTARTED="notStarted",k.ONGOING="ongoing",k);let n7="custom:(uuid,display,voided,indication,startDatetime,stopDatetime,encounters:(uuid,display,encounterDatetime,form:(uuid,name),location:ref,encounterType:ref,encounterProviders:(uuid,display,provider:(uuid,display))),patient:(uuid,display),visitType:(uuid,name,display),attributes:(uuid,display,attributeType:(name,datatypeClassname,uuid),value),location:(uuid,name,display))",n9=function(){try{return JSON.parse(sessionStorage.getItem("openmrs:visitStoreState")||"null")}catch(e){return null}}()||{patientUuid:null,manuallySetVisitUuid:null};function oe(){return M("visit",n9)}function ot(e,t){oe().setState({patientUuid:e,manuallySetVisitUuid:t})}function on(e,t){return tW(`${tT}/visit`,{signal:t.signal,method:"POST",headers:{"Content-type":"application/json"},body:e})}function oo(e,t,n){return tW(`${tT}/visit/${e}`,{signal:n.signal,method:"POST",headers:{"Content-type":"application/json"},body:t})}function or(e,t,n){return tW(`${tT}/visit?patient=${e}&v=${n??n7}`,{signal:t.signal,method:"GET",headers:{"Content-type":"application/json"}})}oe().subscribe(e=>{var t;t=e,sessionStorage.setItem("openmrs:visitStoreState",JSON.stringify(t))});var oi=n(9225),os=n(6881),oa=n(6828),ol=n(1956),oc=n(3635),ou=n(7839),od=n(2298);let om={Array,Boolean,Symbol,Infinity,NaN,Math,Number,BigInt,String,RegExp,JSON,isFinite,isNaN,parseFloat,parseInt,decodeURI,encodeURI,encodeURIComponent,Object:{__proto__:void 0,assign:Object.assign.bind(null),fromEntries:Object.fromEntries.bind(null),hasOwn:Object.hasOwn.bind(null),keys:Object.keys.bind(null),is:Object.is.bind(null),values:Object.values.bind(null)}},op={...om,Promise};function of(e,t={}){return ov(e,t,oS)}async function og(e,t={}){return ob(e,t,oS)}function oh(e,t={}){return ov(e,t,oj)}function ow(e,t={}){return ob(e,t,oj)}function o_(e,t={}){return ov(e,t,ok)}function oy(e,t={}){return ob(e,t,ok)}function ov(e,t={},n){if("string"!=typeof e&&("object"!=typeof e||!e||!("type"in e)))throw`Unknown expression type ${e}. Expressions must either be a string or pre-compiled string.`;if("string"==typeof e&&0===e.trim().length)throw{type:"Empty expression",message:"Expression cannot be an empty string"};null==t&&(t={});let o=oI(t,om),r=oN("string"==typeof e?(0,oi.A)(e):e,o);if(n(r))return r;throw{type:"Invalid result",message:"string"==typeof e?`The expression ${e} did not produce a valid result`:"The expression did not produce a valid result"}}async function ob(e,t={},n){if("string"!=typeof e&&("object"!=typeof e||!e||!("type"in e)))return Promise.reject(`Unknown expression type ${e}. Expressions must either be a string or pre-compiled string.`);if("string"==typeof e&&0===e.trim().length)throw{type:"Empty expression",message:"Expression cannot be an empty string"};null==t&&(t={});let o=oI(t,op);return Promise.resolve(oN("string"==typeof e?(0,oi.A)(e):e,o)).then(t=>{if(n(t))return t;throw{type:"Invalid result",message:"string"==typeof e?`The expression ${e} did not produce a valid result`:"The expression did not produce a valid result"}})}function ox(e){return(0,oi.A)(e)}function oS(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||null==e||e instanceof Date}function oj(e){return"boolean"==typeof e}function ok(e){return"number"==typeof e}function oN(e,t){switch(e.type){case"UnaryExpression":var n,o,r,i,s,a,l,c,u,d,m,p,f,g=e,h=t;let w=oN(g.argument,h);switch(g.operator){case"+":return+w;case"-":return-w;case"~":return~w;case"!":return!w;default:throw`Expression evaluator does not support operator '${g.operator}''`}case"BinaryExpression":var _=e,y=t;switch(_.operator){case"&&":return oN(_.left,y)&&oN(_.right,y);case"||":return oN(_.left,y)||oN(_.right,y);case"??":return oN(_.left,y)??oN(_.right,y)}let v=oN(_.left,y),b=oN(_.right,y);switch(_.operator){case"+":return v+b;case"-":return v-b;case"*":return v*b;case"/":return v/b;case"%":return v%b;case"**":return v**b;case"==":return v==b;case"===":return v===b;case"!=":return v!=b;case"!==":return v!==b;case">":return v>b;case">=":return v>=b;case"<":return v<b;case"<=":return v<=b;case"in":return v in b;default:throw`Expression evaluator does not support operator '${_.operator}' operator`}case"ConditionalExpression":return n=e,o=t,oN(n.test,o)?oN(n.consequent,o):oN(n.alternate,o);case"CallExpression":return oR(oE(e,t));case"ArrowFunctionExpression":let x;return r=e,i=t,x=r.params?.map(e=>{if("Identifier"===e.type)return e.name;throw`Cannot handle parameter of type ${e.type}`})??[],(function(...e){if(e.length<x.length)throw`Required argument(s) ${x.slice(e.length,-1).join(", ")} were not provided`;let t=Object.fromEntries(x.reduce((t,n,o)=>{let r=e[o];return function e(t){if("string"==typeof t||"number"==typeof t||"boolean"==typeof t||"function"==typeof t||null===t||t instanceof RegExp)return!0;if("object"==typeof t){for(let n of Object.keys(t))if(!e(t[n]))return!1;return!0}if(Array.isArray(t)){for(let n of t)if(!e(n))break}return!1}(r)&&t.push([n,r]),t},[]));return oN(r.body,i.addVariables(t))}).bind(null);case"MemberExpression":return oR(oP(e,t));case"ArrayExpression":return s=e,a=t,s.elements?.map(oT(a));case"SequenceExpression":let S;return l=e,c=t,(S=l.expressions.map(oT(c)))[S.length-1];case"NewExpression":var j=e,k=t;if(j.callee&&"Identifier"===j.callee.type){let e=j.arguments?.map(oT(k));switch(j.callee.name){case"Date":return new Date(...e);case"RegExp":return new RegExp(...e);default:throw`Cannot instantiate object of type ${j.callee.name}`}}if(j.callee)throw"new must be called with either Date or RegExp";throw'Could not handle "new" without a specified class';case"Literal":return e.value;case"Identifier":return u=e,d=t,(o$(u.name),d.variables&&Object.hasOwn(d.variables,u.name))?d.variables[u.name]:Object.hasOwn(d.globals,u.name)?d.globals[u.name]:void 0;case"TemplateLiteral":let N,C;return m=e,p=t,N=m.expressions?.map(oT(p))??[],(C=m.quasis?.map(oT(p))??[]).filter(e=>!e.tail).map(e=>e.value).join("")+N.join("")+C.filter(e=>e.tail).map(e=>e.value).join("");case"TemplateElement":return{value:(f=e).cooked,tail:f.tail};default:throw`Expression evaluator does not support expression of type '${e.type}'`}}function oC(e,t){switch(e.type){case"Literal":return e.value;case"Identifier":return e.name;case"MemberExpression":return oC(e.property,t);default:throw`VisitExpressionName does not support expression of type '${e.type}'`}}function oE(e,t){let n=oA(e.callee,t);if(n===oO||e.optional&&null==n)return oO;let o=e.arguments?.map(oT(t));if(n){if("function"!=typeof n)throw`${oW(e.callee)} is not a function`}else throw`No function named ${oW(e.callee)} is defined in this context`;return n(...o)}function oP(e,t){let n=oA(e.object,t);if(n===oO||e.optional&&null==n)return oO;if(null===n)throw TypeError(`TypeError: cannot read properties of null (reading '${oL(e.property,t)}')`);if(void 0===n)switch(e.object.type){case"Identifier":{let n=oC(e.object,t);throw ReferenceError(`ReferenceError: ${n} is not defined`)}case"MemberExpression":throw TypeError(`TypeError: cannot read properties of undefined (reading '${oL(e.property,t)}')`);default:throw`VisitMemberExpression does not support operator '${e.object.type}' type`}if("object"!=typeof n&&"function"!=typeof n&&"string"!=typeof n&&"number"!=typeof n)throw`VisitMemberExpression does not support member access on type ${typeof n}`;let o=e.computed?function(e){if(void 0===e)throw{type:"Illegal property access",message:"No property was supplied to the property access"};if("string"!=typeof e&&"number"!=typeof e)throw{type:"Illegal property access",message:`Cannot use a value of type ${null===e?"null":typeof e} as a property name`};return e}(oN(e.property,t)):function(e){if("Identifier"!==e.type)throw`VisitMemberExpression does not support a property of type '${e.type}'`;return e.name}(e.property);o$(o),function(e,t){if(oM.has(String(t)))return;let n=Object(e);for(;null!==n;){if(Object.hasOwn(n,t)){if(n===Object.prototype||n===Function.prototype)throw{type:"Illegal property access",message:`Cannot access the ${t} property of objects`};return}n=Object.getPrototypeOf(n)}}(n,o);let r=n[o];return"function"==typeof r?r.bind(n):r}function oI(e,t){let n={variables:{...e},globals:{...t},addVariables(e){return this.variables={...this.variables,...e},this}};return n.addVariables.bind(n),n}oi.A.plugins.register(os.A),oi.A.plugins.register(oa.A),oi.A.plugins.register(ol.A),oi.A.plugins.register(oc.A),oi.A.plugins.register(ou.A),oi.A.plugins.register(od.A),oi.A.addBinaryOp("in",7),oi.A.addBinaryOp("??",1);let oO=Symbol("optional chain short-circuited");function oA(e,t){switch(e.type){case"MemberExpression":return oP(e,t);case"CallExpression":return oE(e,t);default:return oN(e,t)}}function oR(e){return e===oO?void 0:e}function oT(e){return function(t){return null===t?null:oN(t,e)}}function o$(e){if("__proto__"===e||"prototype"===e||"constructor"===e)throw{type:"Illegal property access",message:`Cannot access the ${e} property of objects`}}let oM=new Set(["toString","valueOf","hasOwnProperty"]);function oL(e,t){try{return oC(e,t)}catch{return"<computed>"}}function oW(e){return e?"MemberExpression"===e.type?e.property?.name:e.name:null}function oD(e){if("string"!=typeof e&&("object"!=typeof e||!e||!("type"in e)))throw`Unknown expression type ${e}. Expressions must either be a string or pre-compiled string.`;let t={globals:{...op},boundNames:new Set,variables:new Set};return oU("string"==typeof e?(0,oi.A)(e):e,t),[...t.variables]}function oU(e,t){switch(e.type){case"UnaryExpression":return n=e,o=t,void oU(n.argument,o);case"BinaryExpression":return r=e,i=t,void(oU(r.left,i),oU(r.right,i));case"ConditionalExpression":return s=e,a=t,void(oU(s.consequent,a),oU(s.test,a),oU(s.alternate,a));case"CallExpression":return l=e,c=t,void(oU(l.callee,c),l.arguments?.map(oB(c)));case"ArrowFunctionExpression":var n,o,r,i,s,a,l,c,u,d,m,p,f,g,h,w,_,y,v,b,x=e,S=t;let j=new Set(S.boundNames);for(let e of x.params??[])e?.type==="Identifier"&&j.add(e.name);oU(x.body,{...S,boundNames:j});return;case"MemberExpression":return u=e,d=t,void(oU(u.object,d),u.computed&&oU(u.property,d));case"ArrayExpression":return m=e,p=t,void m.elements?.map(oB(p));case"SequenceExpression":return f=e,g=t,void f.expressions?.map(oB(g));case"NewExpression":return h=e,w=t,void h.arguments?.map(oB(w));case"Literal":case"TemplateElement":return;case"Identifier":return _=e,y=t,void(_.name in y.globals||y.boundNames.has(_.name)||y.variables.add(_.name));case"TemplateLiteral":return v=e,b=t,void(v.expressions?.map(oB(b)),v.quasis?.map(oB(b)));default:throw`Expression evaluator does not support expression of type '${e.type}'`}}function oB(e){return function(t){return null===t?null:oU(t,e)}}let oF=M("feature-flags",{flags:function(){let e={};for(let t of Object.keys(localStorage))if(t.startsWith("openmrs:feature-flag:")){let n=t.replace("openmrs:feature-flag:",""),o=JSON.parse(localStorage.getItem(`openmrs:feature-flag-meta:${n}`)||"{}");e[n]={enabled:"true"===localStorage.getItem(t),...o}}return e}()});function oH(e,t,n){oF.setState(o=>({flags:{...o.flags,[e]:{enabled:o.flags[e]?.enabled??!1,label:t,description:n}}}))}function oV(){let e=oF.getState().flags;Object.keys(localStorage).filter(e=>e.startsWith("openmrs:feature-flag:")).forEach(t=>{let n=t.replace("openmrs:feature-flag:","");e[n]||(localStorage.removeItem(t),localStorage.removeItem(`openmrs:feature-flag-meta:${n}`))})}function oz(e){return oF.getState().flags[e].enabled}function oG(e,t){oF.subscribe(n=>{t(n.flags[e].enabled)})}function oq(e,t){oF.setState(n=>({flags:{...n.flags,[e]:{...n.flags[e],enabled:t}}}))}oF.subscribe(e=>{for(let[t,n]of Object.entries(e.flags))localStorage.setItem(`openmrs:feature-flag:${t}`,n.enabled.toString()),localStorage.setItem(`openmrs:feature-flag-meta:${t}`,JSON.stringify({label:n.label,description:n.description}))});var oJ=n(1216);let oK=R("extensionsInternal",{slots:{},extensions:{}}),oX=R("extensionRenderings",{renderings:new Map}),oY=()=>M("extensionsInternal",{slots:{},extensions:{}}),oZ=()=>M("extensionRenderings",{renderings:new Map});function oQ(e){let t=oK.getState(),n=e(t);n!==t&&oK.setState(n)}let o0=null,o1=null;function o2(){let e=oX.getState();return o0&&e===o1||(o0=new Map(e.renderings),o1=e,function(e){for(let t of(rn.clear(),e.values()))rr(t,1);ro=!0}(o0)),o0}function o5(e){o1={renderings:e},oX.setState(o1,!0)}function o6(e){let t=o2();t.has(e.renderingId)||(t.set(e.renderingId,e),rr(e,1),o5(t))}function o8(e){let t=o2(),n=t.get(e);n&&(t.delete(e),rr(n,-1),o5(t))}let o4=()=>M("extensions",{slots:{}}),o3=0,o7=new Set;function o9(e){o3++;try{return e()}finally{if(0==--o3&&o7.size>0){let e=Array.from(o7);for(let t of(o7.clear(),e))re(t)}}}function re(e){try{e()}catch(t){console.error(`The extension system's '${e.name}' recomputation failed`,t)}}function rt(e){o3>0?o7.add(e):re(e)}let rn=new Map,ro=!1;function rr(e,t){let n=JSON.stringify([e.slotName,e.extensionId,e.slotModuleName,e.extensionModuleName]),o=rn.get(n);if(!o){if(t<0)return;rn.set(n,{count:1,record:{slotModuleName:e.slotModuleName,extensionModuleName:e.extensionModuleName,slotName:e.slotName,extensionId:e.extensionId}}),ro=!0;return}o.count+=t,o.count<1&&(rn.delete(n),ro=!0)}function ri(){var e,t;if(o2(),!ro)return;ro=!1;let n=Array.from(rn.values(),({record:e})=>e);n.sort(rs),e=et.getState().mountedExtensions,t=n,e.length===t.length&&e.every((e,n)=>0===rs(e,t[n]))||et.setState({mountedExtensions:n})}function rs(e,t){return ra(e.slotName,t.slotName)||ra(e.extensionId,t.extensionId)||ra(e.slotModuleName,t.slotModuleName)||ra(e.extensionModuleName,t.extensionModuleName)}function ra(e,t){return e===t?0:e<t?-1:1}ri(),oX.subscribe(()=>rt(ri));let rl=oY(),rc=o4(),ru=eo(),rd=es(),rm=new Set,rp=!1;function rf(e){if(null===e)rm=null;else if(null!==rm)for(let t of e)rm.add(t);rt(rg)}function rg(){if(!rp){rp=!0;try{for(let e=1;;e++){let t=rm;if(null!==t&&0===t.size)return;rm=new Set;try{!function(e,t,n,o,r,i=null){let s=rc.getState().slots,a={},l=!1,c=Object.entries(o.flags).filter(([,{enabled:e}])=>e).map(([e])=>e);for(let[o,u]of Object.entries(e.slots)){let d=s[o];if(d&&i&&!i.has(o)){a[o]=d;continue}let{config:m}=ei(t,u.name),p=function(e,t,n,o,r,i){let s=function(e,t){let n=e.add||[],o=e.remove||[],r=e.order||[],{extensions:i}=rl.getState(),s=new Set(o),a=[...t,...n].filter(e=>!s.has(e)),l=rk(r),c=rk(t),u=new Map(a.map(e=>[e,function(e,t,n,o){let r=t.get(e);if(void 0!==r)return r;{if(void 0!==n)return 1e3+n;let t=o.get(e);return void 0!==t?2e3+t:3e3}}(e,l,i[r_(e)]?.order,c)]));return a.sort((e,t)=>u.get(e)-u.get(t))}(n,t.slots[e].attachedIds),a=[];for(let l of s){let{config:s}=ea(o,e,l),c=el(n,e,l),u=c?(0,oJ.A)({},s,c):s,d=r_(l),m=t.extensions[d];if(m){let e=u?.["Display conditions"]?.privileges??m.privileges??[];if(e&&("string"==typeof e||Array.isArray(e)&&e.length>0)&&(!i?.user||!tK(e,i.user))||m.featureFlag&&!r.includes(m.featureFlag))continue;a.push({id:l,name:d,moduleName:m.moduleName,config:u,featureFlag:m.featureFlag,meta:m.meta,displayConditionExpression:u?.["Display conditions"]?.expression||m.displayExpression})}}return a}(o,e,m,n,c,r.session);d&&d.moduleName===u.moduleName&&(0,F.A)(d.candidateExtensions,p)?a[o]=d:(a[o]={moduleName:u.moduleName,candidateExtensions:p},l=!0)}(l||Object.keys(s).length!==Object.keys(a).length)&&rc.setState({slots:a})}(rl.getState(),ru.getState(),rd.getState(),oF.getState(),tU.getState(),t)}catch(e){throw rm=null===t||null===rm?null:new Set([...t,...rm]),e}if(e>=20)return void console.error("The extension system stopped recomputing after 20 passes because something keeps invalidating slots in response to the extension store being written. Some slots are left stale until the next write.")}}finally{rp=!1}}}function rh(e,t){let n=new Set;for(let o of Object.keys(e))e[o]!==t[o]&&n.add(o);for(let o of Object.keys(t))o in e||n.add(o);return n}function rw(e,t){return{moduleName:t,name:e,attachedIds:[]}}function r_(e){let[t]=e.split("#");return t}function ry(e,t){let n=r_(t);return e.extensions[n]}function rv(e){return ry(rl.getState(),e)}rl.subscribe((e,t)=>{rf(e.extensions!==t.extensions?null:rh(e.slots,t.slots))}),ru.subscribe((e,t)=>{rf(rh(e.slots,t.slots))}),rd.subscribe((e,t)=>{rf(rh(e.configs,t.configs))}),oF.subscribe(()=>rf(null)),tU.subscribe(()=>rf(null)),rf(null);let rb=e=>oQ(t=>({...t,extensions:{...t.extensions,[e.name]:{...e}}}));function rx(e,t){oQ(n=>{let o=n.slots[e];return o?{...n,slots:{...n.slots,[e]:{...o,attachedIds:[...o.attachedIds,t]}}}:{...n,slots:{...n.slots,[e]:{...rw(e),attachedIds:[t]}}}})}function rS(e,t){oQ(n=>{let o=n.slots[e];return o&&o.attachedIds.includes(t)?{...n,slots:{...n.slots,[e]:{...o,attachedIds:o.attachedIds.filter(e=>e!==t)}}}:n})}function rj(e){oQ(t=>{let n=t.slots[e];return n?{...t,slots:{...t.slots,[e]:{...n,attachedIds:[]}}}:t})}function rk(e){let t=new Map;return e.forEach((e,n)=>{t.has(e)||t.set(e,n)}),t}function rN(e,t){return function(e,t,n=null,o){let r;return e.filter(e=>{let i=e.displayConditionExpression;if("string"!=typeof i||0===i.trim().length)return!0;r??(r=t&&"object"==typeof t?{session:n,...t}:{session:n});try{return!!oh(i,r)}catch(t){return console.error(`Error while evaluating expression '${i}' for ${e.id}`+(o?` in ${o}`:""),t),!1}})}(rC(e),t,tU.getState().session,e)}function rC(e){return rc.getState().slots[e]?.candidateExtensions??[]}let rE=(e,t)=>rl.setState(n=>{let o=n.slots[t]?.moduleName;if(o&&o!=e)return console.warn(`An extension slot with the name '${t}' already exists. Refusing to register the same slot name twice (in "registerExtensionSlot"). The existing one is from module ${o}.`),n;if(o&&o==e)return n;if(n.slots[t])return{...n,slots:{...n.slots,[t]:{...n.slots[t],moduleName:e}}};let r=rw(t,e);return{...n,slots:{...n.slots,[t]:{...r}}}}),rP=()=>{rm=null,oQ(()=>({slots:{},extensions:{}})),oZ().setState({renderings:new Map}),rc.setState({slots:{}})},rI=R("left-nav",{slotName:null,basePath:window.spaBase,mode:"normal"});function rO({name:e,basePath:t,mode:n,componentContext:o,state:r}){rI.setState({slotName:e,basePath:t,mode:n??"normal",componentContext:o,state:r})}function rA(e){rI.getState().slotName===e&&rI.setState(rI.getInitialState(),!0)}let rR=R("modalRegistry",{modals:{}});function rT(e){rR.setState(t=>(t.modals[e.name]=e,t))}function r$(e){let t=rR.getState().modals[e];if(!t){let n=rv(e);n&&(t={name:e,load:n.load,moduleName:n.moduleName},console.warn(`Modal ${e} was registered as an extension. This is deprecated and will be removed in the future. Please register it in the "modals" section of routes.json instead of the "extensions" section.`),rT(t))}return t}let rM=R("workspace2",{registeredGroupsByName:{},registeredWindowsByName:{},registeredWorkspacesByName:{},openedGroup:null,openedWindows:[],isMostRecentlyOpenedWindowHidden:!1});function rL(e){let{registeredWorkspacesByName:t,registeredWindowsByName:n}=rM.getState(),o=t[e];if(o){let t=n[o.window];if(t)return t;throw Error(`No workspace window found with name: ${o.window} for workspace: ${e}`)}throw Error(`No workspace found with name: ${e}`)}function rW(e){let{registeredGroupsByName:t,registeredWindowsByName:n}=rM.getState(),o=n[e];if(o){let n=t[o.group];if(n)return n;throw Error(`No workspace group found with name: ${o.group} for window: ${e}`)}throw Error(`No workspace window found with name: ${e}`)}function rD(e){let{openedWindows:t}=rM.getState();return t.findIndex(t=>t.openedWorkspaces.find(t=>t.workspaceName===e))}function rU(e,t){if(0==t.length)return;let{registeredGroupsByName:n}=rM.getState(),o={...n};for(let n of t){if(o[n.name])throw Error(`Cannot register workspace group ${n.name} more than once`);o[n.name]={...n,moduleName:e}}rM.setState({registeredGroupsByName:o})}function rB(e,t){if(0==t.length)return;let{registeredWindowsByName:n}=rM.getState(),o={...n};for(let n of t){if(o[n.name])throw Error(`Cannot register workspace window ${n.name} more than once`);let t={...n,moduleName:e};o[n.name]=t}rM.setState({registeredWindowsByName:o})}function rF(e,t){if(0==t.length)return;let{registeredWorkspacesByName:n}=rM.getState(),o={...n};for(let n of t){if(o[n.name])throw Error(`Cannot register workspace ${n.name} more than once`);let t={...n,moduleName:e};o[n.name]=t}rM.setState({registeredWorkspacesByName:o})}let rH=0,rV=null,rz={bootstrap:15e3,mount:15e3,unmount:15e3};function rG(e,t){if(e.timeouts)return e;let n=e.name??"parcel",o=Object.fromEntries(Object.keys(rz).filter(t=>e[t]).map(o=>{var r,i;let s,a;return[o,(r=e[o],i=rz[o],s=Array.isArray(r)?r:[r],a=e=>s.reduce((t,r,i)=>t.then(()=>{let t=r(e);return"function"==typeof t?.then&&"function"==typeof t?.catch?t:Promise.reject(Error(`Lifecycle function ${o} at array index ${i} for parcel ${n} did not return a promise`))}),Promise.resolve(void 0)),e=>{let r,s=new Promise((e,t)=>{r=setTimeout(()=>t(Error(`Lifecycle function ${o} for parcel ${n} did not settle within ${i}ms`)),i)});return Promise.race([a(e),s]).finally(()=>clearTimeout(r)).then(e=>(t(o,!1),e),e=>{throw t(o,!0),e})})]}));return{...e,...o}}async function rq(e,t){var n,o;let r,i,s,a,l,c=await (rV??(rV=new Promise((e,t)=>{(0,ta.xL)({name:"openmrs-extension-host",bootstrap:()=>Promise.resolve(),mount:t=>(e(t.mountParcel),Promise.resolve()),unmount:()=>Promise.resolve()},{domElement:document.createElement("div")}).mountPromise.catch(t)}).catch(e=>(console.error("The host parcel used to mount extensions could not be mounted. Falling back to mounting extensions as root parcels, which leaks their DOM elements.",e),ta.xL))),rV),u={...t},d=(r=u,i=!1,{retarget:e=>r={...e},release:s=()=>(function(e){for(let t of Object.keys(e))delete e[t]})(r),onSettled(e,t){switch(e){case"bootstrap":t&&s();return;case"mount":i||(i=t);return;case"unmount":(t||i)&&s();return}}});return o=c((n=d.onSettled,"function"==typeof e?()=>e().then(e=>rG(e,n)):rG(e,n)),u),a=e=>t=>e.call(o,d.retarget(t)).catch(e=>{throw"SKIP_BECAUSE_BROKEN"===o.getStatus()&&d.release(),e}),l=o.update&&a(o.update),Object.defineProperty(o,"update",{configurable:!0,enumerable:!0,get:()=>l,set:e=>{l=e&&a(e)}})}function rJ(){return rK}function rK(e,t){let n,o=rq(e,t).then(e=>n=e);return{mount:()=>o.then(e=>e.mount()),unmount:()=>o.then(e=>e.unmount()),update:e=>o.then(t=>t.update?.(e)),getStatus:()=>n?.getStatus()??"LOADING_SOURCE_CODE",get loadPromise(){return o.then(e=>e.loadPromise)},get bootstrapPromise(){return o.then(e=>e.bootstrapPromise)},get mountPromise(){return o.then(e=>e.mountPromise)},get unmountPromise(){return o.then(e=>e.unmountPromise)}}}async function rX(e,t,n,o,r=e=>e,i={}){let s=r_(o),a=rv(o),l=null;if(e){let c;if(!a)throw Error(`Couldn't find extension '${s}' to attach to '${t}'`);let{meta:u,moduleName:d,load:m}=a,p=rH++,f=`${t}/${o}-${p}`;e.dataset.extensionRenderingId=f;let g=e=>{try{o8(f)}catch(t){console.error(e,t)}};try{o6({renderingId:f,extensionName:s,extensionModuleName:d,extensionId:o,slotName:t,slotModuleName:n})}catch(e){throw g(`Recomputing configuration after registering '${o}' failed also failed`),e}try{c=await m()}catch(e){throw g(`Recomputing configuration after '${o}' failed to load also failed`),e}try{l=await rq(r({...c,name:`${t}/${s}-${p}`}),{...i,_meta:u,_extensionContext:{extensionId:o,extensionSlotName:t,extensionSlotModuleName:n,extensionModuleName:d,extensionMeta:u},domElement:e})}catch(e){throw g(`Recomputing configuration after '${o}' failed to mount also failed`),e}l.mountPromise.then(void 0,e=>{console.error(`Extension '${o}' in slot '${t}' failed to mount`,e),g(`Recomputing configuration after '${o}' failed to mount also failed`)}),l.unmountPromise.then(()=>g(`Recomputing configuration after unmounting '${o}' failed`),e=>{console.error(`Extension '${o}' in slot '${t}' failed to unmount`,e),g(`Recomputing configuration after '${o}' failed to unmount also failed`)})}else console.warn(`Tried to render ${o} into ${t} but no DOM element was available.`);return l}var rY=n(6925),rZ=n.n(rY);let rQ=(0,rY.createContext)({moduleName:"",featureName:""});var r0=n(5140);function r1({to:e,templateParams:t,onBeforeNavigate:n,children:o,...r}){return(0,rY.useEffect)(()=>{r.href&&console.warn(`ConfigurableLink does not support the href prop. Use the 'to' prop instead. The provided href value is '${r.href}'`),r.onClick&&console.warn(`ConfigurableLink does not support the onClick prop. Use the 'onBeforeNavigate' prop instead. The 'to' prop of the offending link is ${e}`)},[]),(0,r0.jsx)("a",{onClick:o=>{0===o.button&&!o.ctrlKey&&!o.shiftKey&&!o.altKey&&!o.metaKey&&(o.preventDefault(),n?.(o),tj({to:e,templateParams:t})),0===o.button&&(o.ctrlKey||o.metaKey)&&n?.(o),0===o.button&&o.shiftKey&&n?.(o),1===o.button&&n?.(o)},href:tx(e,t),...r,children:o})}let r2=({state:e,children:t,...n})=>{let{extension:o}=(0,rY.useContext)(rQ),r=(0,rY.useRef)(null),i=(0,rY.useRef)(Promise.resolve()),s=(0,rY.useRef)(!1),a=(0,rY.useRef)(!1),l=(0,rY.useRef)(e),c=(0,rY.useCallback)(e=>{if(!e)return;let t=()=>{"MOUNTED"===e.getStatus()&&e.unmount()};switch(e.getStatus()){case"MOUNTED":e.unmount();break;case"UPDATING":i.current?.then(t,t);break;default:e.mountPromise.then(t,()=>{})}},[]),u=(0,rY.useCallback)((e,t)=>{e.update&&"UNMOUNTING"!==e.getStatus()&&(i.current=Promise.all([e.mountPromise,i.current]).then(()=>{if(r.current?.getStatus()==="MOUNTED"&&r.current.update)return r.current.update({...t})}).catch(e=>{let t=r.current?.getStatus();"UNMOUNTING"!==t&&"NOT_MOUNTED"!==t&&"UNLOADING"!==t&&console.error(`The extension '${o?.extensionId}' failed to update`,e)}))},[]),d=(0,rY.useCallback)(t=>{t&&!r.current&&!a.current&&o?.extensionSlotName&&o.extensionSlotModuleName&&(a.current=!0,rX(t,o.extensionSlotName,o.extensionSlotModuleName,o.extensionId,void 0,e).then(t=>{(a.current=!1,r.current=t,s.current)?c(t):t&&l.current!==e&&u(t,l.current)},()=>{a.current=!1}))},[]);return(0,rY.useEffect)(()=>(s.current=!1,()=>{s.current=!0,c(r.current)}),[]),(0,rY.useEffect)(()=>{l.current=e,r.current&&u(r.current,e)},[e]),o?(0,r0.jsx)("div",{ref:d,"data-extension-id":o?.extensionId,style:{position:"relative"},...n}):null};function r5(e){let t=(0,rY.useRef)(e);return x(t.current,e)||(t.current=e),t.current}function r6(e,t){"function"==typeof t&&(t=t(e));let n={};for(let[o,r]of Object.entries(t)){let t=function(...t){e.setState(e=>r(e,...t))};n[o]=t}return n}let r8=e=>e;function r4(e,t=r8,n){let o=(0,rY.useCallback)(t=>e.subscribe(t),[e]),r=(0,rY.useCallback)(()=>t(e.getState()),[e,t]),i=(0,rY.useSyncExternalStore)(o,r,r),s=(0,rY.useMemo)(()=>n?r6(e,n):null,[e,n]);return(0,rY.useMemo)(()=>s?{...i,...s}:i,[i,s])}function r3(e,t){return r4(e,r8,t)}function r7(e){return function(t){let n=(0,rY.useCallback)(t=>e.subscribe(t),[]),o=(0,rY.useCallback)(()=>e.getState(),[]),r=(0,rY.useSyncExternalStore)(n,o,o),i=(0,rY.useMemo)(()=>t?r6(e,t):null,[t]);return(0,rY.useMemo)(()=>i?{...r,...i}:r,[r,i])}}let r9=[];Object.freeze(r9);let ie={candidateExtensions:r9};Object.freeze(ie);let it=e=>{let t=(0,rY.useCallback)(t=>t.slots?.[e]??ie,[e]);return r4(o4(),t)},io=e=>e.session;function ir(e,t){let{candidateExtensions:n}=it(e),o=r4(tU,io),r=r5(t);return(0,rY.useMemo)(()=>rN(e,r),[e,r,o,n])}function ii(e,t){let{moduleName:n}=(0,rY.useContext)(rQ);if(!n)throw Error("ComponentContext has not been provided. This should come from @openmrs/esm-react-utils.");return(0,rY.useEffect)(()=>{rE(n,e)},[n,e]),{extensions:ir(e,t),extensionSlotName:e,extensionSlotModuleName:n}}function is(e){return e}function ia({name:e,extensionSlotName:t,select:n=is,children:o,state:r,style:i,...s}){if(o&&r)throw Error("Both children and state have been provided. If children are provided, the state must be passed as a prop to the `Extension` component.");let a=e??t,l=(0,rY.useRef)(null),{extensions:c,extensionSlotModuleName:u}=ii(a,r),d=(0,rY.useMemo)(()=>n(c),[n,c]),m=(0,rY.useMemo)(()=>{if("function"==typeof o&&!rZ().isValidElement(o))return d.map(e=>o(e,r))},[o,d]);return(0,r0.jsx)("div",{ref:l,"data-extension-slot-name":a,"data-extension-slot-module-name":u,style:{...i,position:"relative"},...s,children:a&&d?.map((e,t)=>(0,r0.jsx)(rQ.Provider,{value:{moduleName:u,featureName:"",extension:{extensionId:e.id,extensionSlotName:a,extensionSlotModuleName:u,extensionMeta:e.meta}},children:m?.[t]??("function"!=typeof o?o:null)??(0,r0.jsx)(r2,{state:r})},e.id))})}var il=n(2852),ic=n.n(il),iu=n(9568),id=n(9737),im=n(749),ip=n.n(im),ig=n(5254);let ih={strictMode:!0,throwErrorsToConsole:!0,disableTranslations:!1},iw=new Map;(0,ig.initCache)(iw);let i_={errorRetryCount:3,fetcher:tW,focusThrottleInterval:18e5,revalidateIfStale:!0,revalidateOnFocus:!1,revalidateOnReconnect:!1,refreshInterval:0,shouldRetryOnError:e=>{if(e instanceof tD){let t=e.response.status;return!!(t>=500)||401===t||403===t||429===t}return!0},provider:()=>iw};function iy(e){if("object"!=typeof e||"string"!=typeof e.featureName||"string"!=typeof e.moduleName)throw Error("Invalid options");let t=Object.assign({},ih,e),n={...i_,...t.swrConfig};return function(e){var o,r,i,s,a;return i=r=class extends(o=rZ().Component){componentDidCatch(e,n){n&&n.componentStack&&(e.extra=Object.assign(e.extra||{},{componentStack:n.componentStack})),t.throwErrorsToConsole&&setTimeout(()=>{throw e}),this.setState({caughtError:e,caughtErrorInfo:n})}render(){if(this.state.caughtError)return(0,r0.jsx)("div",{children:"An error has occurred. Please try reloading the page."});{let o=(0,r0.jsx)(rY.Suspense,{fallback:null,children:(0,r0.jsx)(im.SWRConfig,{value:n,children:(0,r0.jsx)(rQ.Provider,{value:this.state.config,children:t.disableTranslations?(0,r0.jsx)(e,{...this.props}):(0,r0.jsx)(id.I18nextProvider,{i18n:window.i18next,defaultNS:this.state.config.extension?`${this.state.config.moduleName}___${this.state.config.extension.extensionSlotName}___${this.state.config.extension.extensionId}`:this.state.config.moduleName,children:(0,r0.jsx)(e,{...this.props})})})})});return t.strictMode&&rZ().StrictMode?(0,r0.jsx)(rZ().StrictMode,{children:o}):o}}constructor(e){super(e),this.state={caughtError:null,caughtErrorInfo:null,config:{moduleName:t.moduleName,featureName:t.featureName,extension:e._extensionContext}}}},s="displayName",a=`OpenmrsReactComponent(${t.featureName})`,s in i?Object.defineProperty(i,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):i[s]=a,r}}function iv(e,t){return(0,iu.A)({React:rZ(),ReactDOMClient:ic(),rootComponent:iy(t)(e)})}function ib(e,t){return()=>e().then(({default:e})=>iv(e,t))}function ix(e,t){return()=>Promise.resolve(iv(e,t))}let iS=ib,ij=(0,C.y)()(()=>({}));$("openmrs-app-context",ij);let ik={};function iN(e,t=e=>e){let n=ij.getState();return e in n?Object.freeze(Object.assign({},t?t(n[e]):n[e])):null}function iC(e,t){ij.setState(n=>(e in n||(n[e]={}),n[e]=t(n[e]),Object.assign({},n)))}function iE(e){return null===e?null:Object.freeze(Object.assign({},e))}let iP=new Map;function iI(e,t){let n=(0,rY.useRef)(t??{}),o=(0,rY.useRef)(t=>iC(e,t)),r=(0,rY.useRef)(Symbol());return(0,rY.useEffect)(()=>{let n=t??{},o=r.current;return null===iN(e)?!function(e,t=ik){ij.setState(n=>{if(e in n)throw Error(`Attempted to re-register namespace ${e} in the app context. Each namespace must be unregistered before the name can be registered again.`);return Object.assign({},n,{[e]:t===ik?{}:t})})}(e,n):(console.warn(`Namespace ${e} is already registered in the app context. This is likely a race condition during navigation, but may indicate two components are trying to own the same namespace. Updating the existing context.`),iC(e,()=>n)),iP.set(e,o),()=>{iP.get(e)===o&&(ij.setState(t=>(e in t&&delete t[e],t)),iP.delete(e))}},[e]),(0,rY.useEffect)(()=>{let o=t??{};x(n.current,o)||(iC(e,()=>o),n.current=o)},[t]),o.current}function iO({namespace:e,value:t}){return iI(e,t),null}let iA=({children:e,value:t,fallback:n})=>t?(0,r0.jsx)(r0.Fragment,{children:e}):n?(0,r0.jsx)(r0.Fragment,{children:n}):null;function iR(){let e=(0,rY.useRef)(null);return(!e.current||e.current.signal.aborted)&&(e.current=new AbortController),(0,rY.useEffect)(()=>{let t=e.current;return()=>t?.abort()},[]),e.current}function iT(e,t=e=>e??{}){let[n,o]=(0,rY.useState)(()=>{if(i$(e))return;let n=iN(e);if(null!==n)return t?t(n):n});return(0,rY.useEffect)(()=>{if(i$(e))throw Error(`The namespace supplied to useAppContext must be a non-empty string, but was "${e}".`)},[e]),(0,rY.useEffect)(()=>{var n;let r;return(n=e=>{if(null==e)return void o(void 0);let n=t?t(e):e;o(e=>x(e,n)?e:n)})(iE(r=iN(e))),ij.subscribe(t=>{let o=e in t?t[e]:null;o!==r&&(r=o,n(iE(o)))})},[e,t]),n}function i$(e){return"string"!=typeof e||0===e.trim().length}function iM(e){let t=ir(e);return(0,rY.useMemo)(()=>t.map(e=>e.id),[t])}function iL(e){return it(e).candidateExtensions}function iW(e,t,n){let{data:o,error:r,mutate:i,isLoading:s,isValidating:a}=ip()(e?nK(e,t,n):null,tW);return(0,rY.useMemo)(()=>({isLoading:s,data:o?.data.results??[],error:r,mutate:i,isValidating:a}),[o,r,s,a,i])}function iD(e){(0,rY.useEffect)(()=>{if(e){let e=window.getComputedStyle(document.body).overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=e}}},[e])}let iU={},iB=`No ComponentContext has been provided. This should come from "openmrsComponentDecorator".
15
+ ${this.stack}`}}let tU=R("session",{loaded:!1,session:null}),tB=0,tF=null;function tH(){return tF||(tU.getState().loaded&&tB>=Date.now()-6e4?null:tq())}function tV(e){let t=e?.includeAuthStatus??!0,n=e=>t?e:e.user,o=tH();return o?new Promise(e=>{let t=()=>{let t=tU.getState();t.loaded&&(r(),e(n(t.session)))},r=tU.subscribe(t);o.then(t,t)}):Promise.resolve(n(tU.getState().session))}function tz(){return tH(),tU}function tG(e){let t=e.locale??e.user?.userProperties?.defaultLocale;t&&t.includes("_")&&(t=t.replaceAll("_","-")),function(e){if(void 0===e||"string"!=typeof e)return!1;try{new Intl.Locale(e)}catch(e){return!1}return!0}(t)&&t!==document.documentElement.getAttribute("lang")&&document.documentElement.setAttribute("lang",t)}function tq(e,t){tB=Date.now(),r??(r=tB);let n={};e&&t&&(n.Authorization=`Basic ${window.btoa(`${e}:${t}`)}`);let o=t5(tW(tM,{headers:n,rejectAuthFailure:!0})),i=()=>{tF===o&&(tF=null)};return o.then(i,i),tF=o,o}function tJ(){tU.setState({loaded:!0,session:{authenticated:!1,sessionId:""}},!0)}function tK(e,t){var n,o;if(void 0===t)return!e;if(!e)return!0;return n=e,o=t,("string"==typeof n?!(0,D.A)(o.privileges.find(e=>n===e.display)):Array.isArray(n)?n.every(e=>!(0,D.A)(o.privileges.find(t=>e===t.display))):((0,D.A)(n)||console.error(`Could not understand privileges "${n}"`),!0))||!(0,D.A)(t.roles.find(e=>"System Developer"===e.display))}function tX(){let e,t;return new Promise(n=>{let o=o=>{o.loaded&&o.session.user&&(e=o.session.user,n(o.session.user),t&&t())};o(tU.getState()),e||(t=tU.subscribe(o))})}async function tY(){return(await tV()).sessionLocation}async function tZ(e,t){return t5(tW(tM,{method:"POST",body:{sessionLocation:e},headers:{"Content-Type":"application/json"},rejectAuthFailure:!0,signal:t?.signal}))}async function tQ(e,t){return await tW(tM,{method:"POST",body:{locale:e},headers:{"Content-Type":"application/json"},signal:t?.signal}),tq()}async function t0(e,t,n){return n||(n=new AbortController),await tW(`${tT}/user/${e}`,{method:"POST",body:{userProperties:t},headers:{"Content-Type":"application/json"},signal:n.signal}),tq()}async function t1(e,t=!1){let n=await tW(t?`${tM}?rememberMe=true`:tM,{headers:{"X-Totp-Code":e}});return n.data?.authenticated?(await tq()).session:n.data}async function t2(){try{await tW(tM,{method:"DELETE",rejectAuthFailure:!0})}catch(e){if(!t6(e))throw e}tJ(),await tq().catch(()=>{})}function t5(e){return new Promise((t,n)=>{e.then(e=>{if("object"==typeof e?.data){let n={loaded:!0,session:e.data};tU.setState(n,!0),t(n)}else!function(e){if(!e?.redirected||!e.url)return!1;try{return new URL(e.url,window.location.href).pathname.replace(/\/+$/,"").endsWith("/initialsetup")}catch{return!1}}(e)?n(t8(Error("The session endpoint did not respond with a session"))):n(t8(Error("The server is still starting up"),!0))}).catch(e=>{var o,i;if(t6(e)){"object"==typeof(o=e.responseBody)&&null!==o&&!1===o.authenticated?tU.setState({loaded:!0,session:e.responseBody},!0):tJ(),t(tU.getState());return}(i=e)instanceof tD&&502===i.response.status&&!tU.getState().loaded&&void 0!==r&&Date.now()-r<18e4?n(t8(e,!0)):(y(`Failed to fetch new session information: ${e}`),n(t8(e)))})})}function t6(e){return e instanceof tD&&(401===e.response.status||403===e.response.status)}function t8(e,t=!1){return tU.getState().loaded||tU.setState({loaded:!1,session:null,error:e instanceof Error?e:Error(String(e)),initializing:t},!0),tU.getState()}function t4(){return"development"===window.spaEnv||"true"===localStorage.getItem("openmrs:devtools")}tU.subscribe(e=>{e.loaded&&e.session&&tG(e.session)});let t3={"webservices.rest":"2.24.0",fhir2:"1.0.0-SNAPSHOT"};function t7(){eP("@openmrs/esm-api",tA),tq()}let t9="import-map-override:",ne="import-map-overrides-disabled",nt="import-map-overrides:change",nn=!1,no=null,nr=null;async function ni(){return nr??(nr=ns().then(({map:e,complete:t})=>(t||(nr=null),e))),nr}async function ns(){let e=document.querySelectorAll('script[type="systemjs-importmap"]'),t=[],n=!0;for(let o=0;o<e.length;o++){let r=e[o];try{if(r.src){let e=await fetch(r.src);if(!e.ok)throw Error(`Request for ${r.src} returned ${e.status} ${e.statusText}`);t.push(await e.json())}else r.textContent&&t.push(JSON.parse(r.textContent))}catch(e){n=!1,console.warn(`[import-maps] Failed to parse import map from script tag at index ${o}`,e)}}return{map:na(t),complete:n}}function na(e){let t={imports:{}};for(let n of e)n?.imports&&Object.assign(t.imports,n.imports);return t}function nl(){let e={};try{let t=np();for(let n=0;n<localStorage.length;n++){let o=localStorage.key(n);if(o?.startsWith(t9)){let n=o.slice(t9.length);if(!t.includes(n)){let t=localStorage.getItem(o);t&&(e[n]=t)}}}}catch(e){console.warn("[import-maps] Failed to read import-map overrides from localStorage",e)}return{imports:e}}async function nc(){let e=await ni();return nn?na([e,no??nl()]):e}async function nu(){return ni()}async function nd(){return nn?na([await ni(),nl()]):ni()}function nm(e){if(!nn)return{imports:{}};if(e){let e={};for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);if(n?.startsWith(t9)){let t=localStorage.getItem(n);t&&(e[n.slice(t9.length)]=t)}}return{imports:e}}return nl()}function np(){if(!nn)return[];try{let e=localStorage.getItem(ne);if(e){let t=JSON.parse(e);if(Array.isArray(t))return t}}catch{}return[]}function nf(e){return!!nn&&np().includes(e)}function ng(e,t){if(!nn)return void console.warn("[Security] Import map overrides are disabled in production mode.");try{localStorage.setItem(t9+e,t),window.dispatchEvent(new CustomEvent(nt))}catch(e){console.warn("[import-maps] Failed to write import-map override to localStorage",e)}}function nh(e){if(!nn)return void console.warn("[Security] Import map overrides are disabled in production mode.");try{localStorage.removeItem(t9+e);let t=np().filter(t=>t!==e);t.length>0?localStorage.setItem(ne,JSON.stringify(t)):localStorage.removeItem(ne),window.dispatchEvent(new CustomEvent(nt))}catch(e){console.warn("[import-maps] Failed to update import-map overrides in localStorage",e)}}function nw(){if(!nn)return void console.warn("[Security] Import map overrides are disabled in production mode.");try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n?.startsWith(t9)&&e.push(n)}e.forEach(e=>localStorage.removeItem(e)),localStorage.removeItem(ne),window.dispatchEvent(new CustomEvent(nt))}catch(e){console.warn("[import-maps] Failed to clear import-map overrides from localStorage",e)}}function n_(e){if(!nn)return void console.warn("[Security] Import map overrides are disabled in production mode.");try{let t=np().filter(t=>t!==e);t.length>0?localStorage.setItem(ne,JSON.stringify(t)):localStorage.removeItem(ne),window.dispatchEvent(new CustomEvent(nt))}catch(e){console.warn("[import-maps] Failed to update import-map overrides in localStorage",e)}}let ny=!1;function nv(){!ny&&(ny=!0,(nn="development"===window.spaEnv)&&(no=nl()))}function nb(e){return e.replace(/[\/\-@]/g,"_")}async function nx(e,t="./start",o){var r;let i,s=!o?.maxLoadingTime||o.maxLoadingTime<=0?6e5:o.maxLoadingTime;await Promise.race([nS(e,o?.importMap),new Promise((t,n)=>{i=setTimeout(()=>{var t;n(Error(`Could not resolve requested script, ${e}, within ${(t=s)<1e3?`${t} milliseconds`:t<6e4?`${Math.floor(t/1e3)} seconds`:t<36e5?`${Math.floor(t/6e4)} minutes`:t<864e5?`${Math.floor(t/36e5)} hours`:`${Math.floor(t/864e5)} days`}.`))},s)})]),i&&clearTimeout(i);let a=nb(e),l=window[a];if(!("object"==typeof(r=l)&&null!==r&&"init"in r&&"function"==typeof r.init&&"get"in r&&"function"==typeof r.get)){let e=`The global variable ${a} does not refer to a federated module`;throw console.error(e),Error(e)}l.init(n.S.default);let c=(await l.get(t))();if("object"!=typeof c||null===c){let t=`Container for ${e} did not return an ESM module as expected`;throw console.error(t),Error(t)}return c}async function nS(e,t){if("string"!=typeof e||0===e.trim().length){let e="Attempted to call importDynamic() without supplying a package to load";throw console.error(e),Error(e)}let n=nb(e);if(!window[n]){let n=t??await nj();if(!n.imports.hasOwnProperty(e)){let t=`Could not find the package ${e} defined in the current importmap`;throw console.error(t),Error(t)}let o=n.imports[e];o.startsWith("./")&&(o=window.spaBase+o.substring(1));let r=e in nm().imports;try{return await function(e){var t;let n=(t=window)[nk]??(t[nk]=new Map),o=n.get(e);if(o)return o;if(document.head.querySelector(`script[src="${e}"]`))return console.warn(`Script at ${e} already loaded. Not loading it again.`),Promise.resolve();let r=document.createElement("script");r.src=e,r.type="text/javascript",r.async=!0;let i=new Promise((t,o)=>{let i=setTimeout(()=>{console.error(`The script at ${e} did not load within 5 seconds. This may indicate an issue with the imports in the script's entry-point file or with the script's bundler configuration.`)},5e3);function s(){clearTimeout(i),r.removeEventListener("load",a),r.removeEventListener("error",l)}function a(){s(),t()}function l(t){s(),n.delete(e),r.remove();let i=`Failed to load script from ${e}`;console.error(i,t),o(t.message??i)}r.addEventListener("load",a),r.addEventListener("error",l),document.head.appendChild(r)});return n.set(e,i),i}(o)}catch(e){return r&&p({kind:"error",title:tb("scriptLoadingFailed","Error: Script failed to load"),description:tb("scriptLoadingError","Failed to load overridden script from {{- url}}. Please check that the bundled script is available at the expected URL. Click the button below to reset all import map overrides.",{url:o}),actionButtonLabel:tb("resetOverrides","Reset overrides"),onActionButtonClick(){nw(),window.location.reload()}}),Promise.reject(e)}}return Promise.resolve()}async function nj(){return nc()}let nk=Symbol.for("__openmrs_script_loading");function nN(e){return!!e&&"object"==typeof e&&!(Object.hasOwn(e,"pages")&&(!e.pages||!Array.isArray(e.pages))||Object.hasOwn(e,"extensions")&&(!e.extensions||!Array.isArray(e.extensions))||Object.hasOwn(e,"modals")&&(!e.modals||!Array.isArray(e.modals))||Object.hasOwn(e,"workspaces2")&&(!e.workspaces2||!Array.isArray(e.workspaces2))||Object.hasOwn(e,"workspaceWindows2")&&(!e.workspaceWindows2||!Array.isArray(e.workspaceWindows2))||Object.hasOwn(e,"workspaceGroups2")&&(!e.workspaceGroups2||!Array.isArray(e.workspaceGroups2)))}function nC(e){return!!e&&"object"==typeof e&&"routes"in e&&!!e.routes&&"object"==typeof e.routes&&Object.entries(e.routes).every(([e,t])=>"string"==typeof e&&nN(t))}let nE="openmrs-routes:",nP="openmrs-routes:change",nI=!1,nO=null,nA=null;async function nR(){return nA??(nA=nT().then(({map:e,complete:t})=>(t||(nA=null),e))),nA}async function nT(){let e=document.querySelectorAll("script[type='openmrs-routes']"),t=[],n=!0;for(let o=0;o<e.length;o++){let r=e[o];try{let e;if(r.src){let t=await fetch(r.src);if(!t.ok)throw Error(`Request for ${r.src} returned ${t.status} ${t.statusText}`);e=await t.json()}else r.textContent&&(e=JSON.parse(r.textContent));e&&nC(e)&&t.push(e)}catch(e){n=!1,console.warn(`[route-maps] Failed to parse routes from script tag at index ${o}`,e)}}return{map:n$(t),complete:n}}function n$(e){let t={routes:{}};for(let n of e)n&&"object"==typeof n&&!Array.isArray(n)&&(Object.assign(t.routes,n.routes),void 0===t.version&&void 0!==n.version&&(t.version=n.version));return t}async function nM(){let e={version:void 0,routes:{}};try{let t=[];for(let e=0;e<localStorage.length;e++){let n=localStorage.key(e);if(n?.startsWith(nE)){let e=localStorage.getItem(n);e&&t.push({moduleName:n.slice(nE.length),raw:e})}}for(let n of(await Promise.allSettled(t.map(async({moduleName:e,raw:t})=>{let n=JSON.parse(t);if(nN(n))return{moduleName:e,routes:n};if("string"==typeof n&&n.startsWith("http")){let t=await fetch(n),o=await t.json();if(nN(o))return{moduleName:e,routes:o};throw Error(`${n} did not resolve to a valid OpenmrsAppRoutes object`)}throw Error(`Override for ${e} is neither a valid routes object nor a URL`)}))))"fulfilled"===n.status?e.routes[n.value.moduleName]=n.value.routes:console.warn("[route-maps] Failed to load route override",n.reason)}catch(e){console.warn("[route-maps] Failed to read route overrides from localStorage",e)}return e}async function nL(){let e=await nR();return nI?n$([e,nO??await nM()]):e}async function nW(){return nR()}async function nD(){return nI?n$([await nR(),await nM()]):nR()}function nU(){if(!nI)return{};let e={};try{for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);if(n?.startsWith(nE)){let t=localStorage.getItem(n);t&&(e[n.slice(nE.length)]=t)}}}catch(e){console.warn("[route-maps] Failed to read route overrides from localStorage",e)}return e}function nB(e,t){if(!nI)return void console.warn("[Security] Route overrides are disabled outside development mode.");try{if("string"==typeof t)if(t.startsWith("http"))localStorage.setItem(nE+e,JSON.stringify(t));else{let n=JSON.parse(t);if(!nN(n))return void console.error(`The supplied routes for ${e} is not a valid OpenmrsAppRoutes object`,t);localStorage.setItem(nE+e,JSON.stringify(n))}else if(t instanceof URL)localStorage.setItem(nE+e,JSON.stringify(t.toString()));else{if(!nN(t))return void console.error(`Override for ${e} is not in a valid format. Expected either a Javascript Object, a JSON string of a Javascript object, or a URL`,t);localStorage.setItem(nE+e,JSON.stringify(t))}window.dispatchEvent(new CustomEvent(nP))}catch(e){console.warn("[route-maps] Failed to write route override to localStorage",e)}}function nF(e){if(!nI)return void console.warn("[Security] Route overrides are disabled outside development mode.");try{localStorage.removeItem(nE+e),window.dispatchEvent(new CustomEvent(nP))}catch(e){console.warn("[route-maps] Failed to remove route override from localStorage",e)}}function nH(){if(!nI)return void console.warn("[Security] Route overrides are disabled outside development mode.");try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n?.startsWith(nE)&&e.push(n)}e.forEach(e=>localStorage.removeItem(e)),window.dispatchEvent(new CustomEvent(nP))}catch(e){console.warn("[route-maps] Failed to clear route overrides from localStorage",e)}}let nV=null;function nz(){return nV||(nV=(nI="development"===window.spaEnv)?nM().then(e=>{nO=e}):Promise.resolve())}let nG=`${tT}/attachment`;function nq(e,t){return tW(`${nG}/${e}`,{signal:t.signal})}function nJ(e,t,n,o){return tW(nK(e,t,o),{signal:n.signal})}function nK(e,t,n){return n?`${nG}?patient=${e}&encounter=${n}`:`${nG}?patient=${e}&includeEncounterless=${t}`}async function nX(e,t,n){let o=new FormData;return o.append("fileCaption",t.fileDescription),o.append("patient",e),n&&o.append("encounter",n),t.file?o.append("file",t.file,t.fileName):(o.append("file",new File([""],t.fileName),t.fileName),o.append("base64Content",t.base64Content)),tW(`${nG}`,{method:"POST",body:o})}function nY(e,t){return tW(`${nG}/${e}`,{method:"DELETE",signal:t.signal})}async function nZ(e,t){return e?(await tW(`${t$}/Patient/${e}`,t)).data:null}function nQ(e,t){let n=new CustomEvent(`openmrs:${e}`,{detail:t??void 0,cancelable:!0,bubbles:!0});return window.dispatchEvent(n)}function n0(e,t){let n=e=>{t("detail"in e&&null!==e.detail?e.detail:void 0)};return window.addEventListener(`openmrs:${e}`,n),()=>{window.removeEventListener(`openmrs:${e}`,n)}}function n1(e){return{uuid:e.uuid,display:e.display}}function n2(e=null,t=null){let n=new URLSearchParams;e&&n.set("tag",e),t&&n.set("q",t);let o=n.toString();return tW(`${tT}/location${o?"?"+o:""}`).then(e=>e.data.results.map(n1))}function n5(e){return{uuid:e.uuid,display:e.display,name:e.name}}let n6=`${tT}/visittype`;function n8(e=n6){return tW(e).then(e=>e.data.results.map(n5))}var n4=((j={}).NEWVISIT="startVisit",j.EDITVISIT="editVisit",j.LOADING="loadingVisit",j),n3=((k={}).NOTSTARTED="notStarted",k.ONGOING="ongoing",k);let n7="custom:(uuid,display,voided,indication,startDatetime,stopDatetime,encounters:(uuid,display,encounterDatetime,form:(uuid,name),location:ref,encounterType:ref,encounterProviders:(uuid,display,provider:(uuid,display))),patient:(uuid,display),visitType:(uuid,name,display),attributes:(uuid,display,attributeType:(name,datatypeClassname,uuid),value),location:(uuid,name,display))",n9=function(){try{return JSON.parse(sessionStorage.getItem("openmrs:visitStoreState")||"null")}catch(e){return null}}()||{patientUuid:null,manuallySetVisitUuid:null};function oe(){return M("visit",n9)}function ot(e,t){oe().setState({patientUuid:e,manuallySetVisitUuid:t})}function on(e,t){return tW(`${tT}/visit`,{signal:t.signal,method:"POST",headers:{"Content-type":"application/json"},body:e})}function oo(e,t,n){return tW(`${tT}/visit/${e}`,{signal:n.signal,method:"POST",headers:{"Content-type":"application/json"},body:t})}function or(e,t,n){return tW(`${tT}/visit?patient=${e}&v=${n??n7}`,{signal:t.signal,method:"GET",headers:{"Content-type":"application/json"}})}oe().subscribe(e=>{var t;t=e,sessionStorage.setItem("openmrs:visitStoreState",JSON.stringify(t))});var oi=n(9225),os=n(6881),oa=n(6828),ol=n(1956),oc=n(3635),ou=n(7839),od=n(2298);let om={Array,Boolean,Symbol,Infinity,NaN,Math,Number,BigInt,String,RegExp,JSON,isFinite,isNaN,parseFloat,parseInt,decodeURI,encodeURI,encodeURIComponent,Object:{__proto__:void 0,assign:Object.assign.bind(null),fromEntries:Object.fromEntries.bind(null),hasOwn:Object.hasOwn.bind(null),keys:Object.keys.bind(null),is:Object.is.bind(null),values:Object.values.bind(null)}},op={...om,Promise};function of(e,t={}){return ov(e,t,oS)}async function og(e,t={}){return ob(e,t,oS)}function oh(e,t={}){return ov(e,t,oj)}function ow(e,t={}){return ob(e,t,oj)}function o_(e,t={}){return ov(e,t,ok)}function oy(e,t={}){return ob(e,t,ok)}function ov(e,t={},n){if("string"!=typeof e&&("object"!=typeof e||!e||!("type"in e)))throw`Unknown expression type ${e}. Expressions must either be a string or pre-compiled string.`;if("string"==typeof e&&0===e.trim().length)throw{type:"Empty expression",message:"Expression cannot be an empty string"};null==t&&(t={});let o=oI(t,om),r=oN("string"==typeof e?(0,oi.A)(e):e,o);if(n(r))return r;throw{type:"Invalid result",message:"string"==typeof e?`The expression ${e} did not produce a valid result`:"The expression did not produce a valid result"}}async function ob(e,t={},n){if("string"!=typeof e&&("object"!=typeof e||!e||!("type"in e)))return Promise.reject(`Unknown expression type ${e}. Expressions must either be a string or pre-compiled string.`);if("string"==typeof e&&0===e.trim().length)throw{type:"Empty expression",message:"Expression cannot be an empty string"};null==t&&(t={});let o=oI(t,op);return Promise.resolve(oN("string"==typeof e?(0,oi.A)(e):e,o)).then(t=>{if(n(t))return t;throw{type:"Invalid result",message:"string"==typeof e?`The expression ${e} did not produce a valid result`:"The expression did not produce a valid result"}})}function ox(e){return(0,oi.A)(e)}function oS(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||null==e||e instanceof Date}function oj(e){return"boolean"==typeof e}function ok(e){return"number"==typeof e}function oN(e,t){switch(e.type){case"UnaryExpression":var n,o,r,i,s,a,l,c,u,d,m,p,f,g=e,h=t;let w=oN(g.argument,h);switch(g.operator){case"+":return+w;case"-":return-w;case"~":return~w;case"!":return!w;default:throw`Expression evaluator does not support operator '${g.operator}''`}case"BinaryExpression":var _=e,y=t;switch(_.operator){case"&&":return oN(_.left,y)&&oN(_.right,y);case"||":return oN(_.left,y)||oN(_.right,y);case"??":return oN(_.left,y)??oN(_.right,y)}let v=oN(_.left,y),b=oN(_.right,y);switch(_.operator){case"+":return v+b;case"-":return v-b;case"*":return v*b;case"/":return v/b;case"%":return v%b;case"**":return v**b;case"==":return v==b;case"===":return v===b;case"!=":return v!=b;case"!==":return v!==b;case">":return v>b;case">=":return v>=b;case"<":return v<b;case"<=":return v<=b;case"in":return v in b;default:throw`Expression evaluator does not support operator '${_.operator}' operator`}case"ConditionalExpression":return n=e,o=t,oN(n.test,o)?oN(n.consequent,o):oN(n.alternate,o);case"CallExpression":return oR(oE(e,t));case"ArrowFunctionExpression":let x;return r=e,i=t,x=r.params?.map(e=>{if("Identifier"===e.type)return e.name;throw`Cannot handle parameter of type ${e.type}`})??[],(function(...e){if(e.length<x.length)throw`Required argument(s) ${x.slice(e.length,-1).join(", ")} were not provided`;let t=Object.fromEntries(x.reduce((t,n,o)=>{let r=e[o];return function e(t){if("string"==typeof t||"number"==typeof t||"boolean"==typeof t||"function"==typeof t||null===t||t instanceof RegExp)return!0;if("object"==typeof t){for(let n of Object.keys(t))if(!e(t[n]))return!1;return!0}if(Array.isArray(t)){for(let n of t)if(!e(n))break}return!1}(r)&&t.push([n,r]),t},[]));return oN(r.body,i.addVariables(t))}).bind(null);case"MemberExpression":return oR(oP(e,t));case"ArrayExpression":return s=e,a=t,s.elements?.map(oT(a));case"SequenceExpression":let S;return l=e,c=t,(S=l.expressions.map(oT(c)))[S.length-1];case"NewExpression":var j=e,k=t;if(j.callee&&"Identifier"===j.callee.type){let e=j.arguments?.map(oT(k));switch(j.callee.name){case"Date":return new Date(...e);case"RegExp":return new RegExp(...e);default:throw`Cannot instantiate object of type ${j.callee.name}`}}if(j.callee)throw"new must be called with either Date or RegExp";throw'Could not handle "new" without a specified class';case"Literal":return e.value;case"Identifier":return u=e,d=t,(o$(u.name),d.variables&&Object.hasOwn(d.variables,u.name))?d.variables[u.name]:Object.hasOwn(d.globals,u.name)?d.globals[u.name]:void 0;case"TemplateLiteral":let N,C;return m=e,p=t,N=m.expressions?.map(oT(p))??[],(C=m.quasis?.map(oT(p))??[]).filter(e=>!e.tail).map(e=>e.value).join("")+N.join("")+C.filter(e=>e.tail).map(e=>e.value).join("");case"TemplateElement":return{value:(f=e).cooked,tail:f.tail};default:throw`Expression evaluator does not support expression of type '${e.type}'`}}function oC(e,t){switch(e.type){case"Literal":return e.value;case"Identifier":return e.name;case"MemberExpression":return oC(e.property,t);default:throw`VisitExpressionName does not support expression of type '${e.type}'`}}function oE(e,t){let n=oA(e.callee,t);if(n===oO||e.optional&&null==n)return oO;let o=e.arguments?.map(oT(t));if(n){if("function"!=typeof n)throw`${oW(e.callee)} is not a function`}else throw`No function named ${oW(e.callee)} is defined in this context`;return n(...o)}function oP(e,t){let n=oA(e.object,t);if(n===oO||e.optional&&null==n)return oO;if(null===n)throw TypeError(`TypeError: cannot read properties of null (reading '${oL(e.property,t)}')`);if(void 0===n)switch(e.object.type){case"Identifier":{let n=oC(e.object,t);throw ReferenceError(`ReferenceError: ${n} is not defined`)}case"MemberExpression":throw TypeError(`TypeError: cannot read properties of undefined (reading '${oL(e.property,t)}')`);default:throw`VisitMemberExpression does not support operator '${e.object.type}' type`}if("object"!=typeof n&&"function"!=typeof n&&"string"!=typeof n&&"number"!=typeof n)throw`VisitMemberExpression does not support member access on type ${typeof n}`;let o=e.computed?function(e){if(void 0===e)throw{type:"Illegal property access",message:"No property was supplied to the property access"};if("string"!=typeof e&&"number"!=typeof e)throw{type:"Illegal property access",message:`Cannot use a value of type ${null===e?"null":typeof e} as a property name`};return e}(oN(e.property,t)):function(e){if("Identifier"!==e.type)throw`VisitMemberExpression does not support a property of type '${e.type}'`;return e.name}(e.property);o$(o),function(e,t){if(oM.has(String(t)))return;let n=Object(e);for(;null!==n;){if(Object.hasOwn(n,t)){if(n===Object.prototype||n===Function.prototype)throw{type:"Illegal property access",message:`Cannot access the ${t} property of objects`};return}n=Object.getPrototypeOf(n)}}(n,o);let r=n[o];return"function"==typeof r?r.bind(n):r}function oI(e,t){let n={variables:{...e},globals:{...t},addVariables(e){return this.variables={...this.variables,...e},this}};return n.addVariables.bind(n),n}oi.A.plugins.register(os.A),oi.A.plugins.register(oa.A),oi.A.plugins.register(ol.A),oi.A.plugins.register(oc.A),oi.A.plugins.register(ou.A),oi.A.plugins.register(od.A),oi.A.addBinaryOp("in",7),oi.A.addBinaryOp("??",1);let oO=Symbol("optional chain short-circuited");function oA(e,t){switch(e.type){case"MemberExpression":return oP(e,t);case"CallExpression":return oE(e,t);default:return oN(e,t)}}function oR(e){return e===oO?void 0:e}function oT(e){return function(t){return null===t?null:oN(t,e)}}function o$(e){if("__proto__"===e||"prototype"===e||"constructor"===e)throw{type:"Illegal property access",message:`Cannot access the ${e} property of objects`}}let oM=new Set(["toString","valueOf","hasOwnProperty"]);function oL(e,t){try{return oC(e,t)}catch{return"<computed>"}}function oW(e){return e?"MemberExpression"===e.type?e.property?.name:e.name:null}function oD(e){if("string"!=typeof e&&("object"!=typeof e||!e||!("type"in e)))throw`Unknown expression type ${e}. Expressions must either be a string or pre-compiled string.`;let t={globals:{...op},boundNames:new Set,variables:new Set};return oU("string"==typeof e?(0,oi.A)(e):e,t),[...t.variables]}function oU(e,t){switch(e.type){case"UnaryExpression":return n=e,o=t,void oU(n.argument,o);case"BinaryExpression":return r=e,i=t,void(oU(r.left,i),oU(r.right,i));case"ConditionalExpression":return s=e,a=t,void(oU(s.consequent,a),oU(s.test,a),oU(s.alternate,a));case"CallExpression":return l=e,c=t,void(oU(l.callee,c),l.arguments?.map(oB(c)));case"ArrowFunctionExpression":var n,o,r,i,s,a,l,c,u,d,m,p,f,g,h,w,_,y,v,b,x=e,S=t;let j=new Set(S.boundNames);for(let e of x.params??[])e?.type==="Identifier"&&j.add(e.name);oU(x.body,{...S,boundNames:j});return;case"MemberExpression":return u=e,d=t,void(oU(u.object,d),u.computed&&oU(u.property,d));case"ArrayExpression":return m=e,p=t,void m.elements?.map(oB(p));case"SequenceExpression":return f=e,g=t,void f.expressions?.map(oB(g));case"NewExpression":return h=e,w=t,void h.arguments?.map(oB(w));case"Literal":case"TemplateElement":return;case"Identifier":return _=e,y=t,void(_.name in y.globals||y.boundNames.has(_.name)||y.variables.add(_.name));case"TemplateLiteral":return v=e,b=t,void(v.expressions?.map(oB(b)),v.quasis?.map(oB(b)));default:throw`Expression evaluator does not support expression of type '${e.type}'`}}function oB(e){return function(t){return null===t?null:oU(t,e)}}let oF=M("feature-flags",{flags:function(){let e={};for(let t of Object.keys(localStorage))if(t.startsWith("openmrs:feature-flag:")){let n=t.replace("openmrs:feature-flag:",""),o=JSON.parse(localStorage.getItem(`openmrs:feature-flag-meta:${n}`)||"{}");e[n]={enabled:"true"===localStorage.getItem(t),...o}}return e}()});function oH(e,t,n){oF.setState(o=>({flags:{...o.flags,[e]:{enabled:o.flags[e]?.enabled??!1,label:t,description:n}}}))}function oV(){let e=oF.getState().flags;Object.keys(localStorage).filter(e=>e.startsWith("openmrs:feature-flag:")).forEach(t=>{let n=t.replace("openmrs:feature-flag:","");e[n]||(localStorage.removeItem(t),localStorage.removeItem(`openmrs:feature-flag-meta:${n}`))})}function oz(e){return oF.getState().flags[e].enabled}function oG(e,t){oF.subscribe(n=>{t(n.flags[e].enabled)})}function oq(e,t){oF.setState(n=>({flags:{...n.flags,[e]:{...n.flags[e],enabled:t}}}))}oF.subscribe(e=>{for(let[t,n]of Object.entries(e.flags))localStorage.setItem(`openmrs:feature-flag:${t}`,n.enabled.toString()),localStorage.setItem(`openmrs:feature-flag-meta:${t}`,JSON.stringify({label:n.label,description:n.description}))});var oJ=n(1216);let oK=R("extensionsInternal",{slots:{},extensions:{}}),oX=R("extensionRenderings",{renderings:new Map}),oY=()=>M("extensionsInternal",{slots:{},extensions:{}}),oZ=()=>M("extensionRenderings",{renderings:new Map});function oQ(e){let t=oK.getState(),n=e(t);n!==t&&oK.setState(n)}let o0=null,o1=null;function o2(){let e=oX.getState();return o0&&e===o1||(o0=new Map(e.renderings),o1=e,function(e){for(let t of(rn.clear(),e.values()))rr(t,1);ro=!0}(o0)),o0}function o5(e){o1={renderings:e},oX.setState(o1,!0)}function o6(e){let t=o2();t.has(e.renderingId)||(t.set(e.renderingId,e),rr(e,1),o5(t))}function o8(e){let t=o2(),n=t.get(e);n&&(t.delete(e),rr(n,-1),o5(t))}let o4=()=>M("extensions",{slots:{}}),o3=0,o7=new Set;function o9(e){o3++;try{return e()}finally{if(0==--o3&&o7.size>0){let e=Array.from(o7);for(let t of(o7.clear(),e))re(t)}}}function re(e){try{e()}catch(t){console.error(`The extension system's '${e.name}' recomputation failed`,t)}}function rt(e){o3>0?o7.add(e):re(e)}let rn=new Map,ro=!1;function rr(e,t){let n=JSON.stringify([e.slotName,e.extensionId,e.slotModuleName,e.extensionModuleName]),o=rn.get(n);if(!o){if(t<0)return;rn.set(n,{count:1,record:{slotModuleName:e.slotModuleName,extensionModuleName:e.extensionModuleName,slotName:e.slotName,extensionId:e.extensionId}}),ro=!0;return}o.count+=t,o.count<1&&(rn.delete(n),ro=!0)}function ri(){var e,t;if(o2(),!ro)return;ro=!1;let n=Array.from(rn.values(),({record:e})=>e);n.sort(rs),e=et.getState().mountedExtensions,t=n,e.length===t.length&&e.every((e,n)=>0===rs(e,t[n]))||et.setState({mountedExtensions:n})}function rs(e,t){return ra(e.slotName,t.slotName)||ra(e.extensionId,t.extensionId)||ra(e.slotModuleName,t.slotModuleName)||ra(e.extensionModuleName,t.extensionModuleName)}function ra(e,t){return e===t?0:e<t?-1:1}ri(),oX.subscribe(()=>rt(ri));let rl=oY(),rc=o4(),ru=eo(),rd=es(),rm=new Set,rp=!1;function rf(e){if(null===e)rm=null;else if(null!==rm)for(let t of e)rm.add(t);rt(rg)}function rg(){if(!rp){rp=!0;try{for(let e=1;;e++){let t=rm;if(null!==t&&0===t.size)return;rm=new Set;try{!function(e,t,n,o,r,i=null){let s=rc.getState().slots,a={},l=!1,c=Object.entries(o.flags).filter(([,{enabled:e}])=>e).map(([e])=>e);for(let[o,u]of Object.entries(e.slots)){let d=s[o];if(d&&i&&!i.has(o)){a[o]=d;continue}let{config:m}=ei(t,u.name),p=function(e,t,n,o,r,i){let s=function(e,t){let n=e.add||[],o=e.remove||[],r=e.order||[],{extensions:i}=rl.getState(),s=new Set(o),a=[...t,...n].filter(e=>!s.has(e)),l=rk(r),c=rk(t),u=new Map(a.map(e=>[e,function(e,t,n,o){let r=t.get(e);if(void 0!==r)return r;{if(void 0!==n)return 1e3+n;let t=o.get(e);return void 0!==t?2e3+t:3e3}}(e,l,i[r_(e)]?.order,c)]));return a.sort((e,t)=>u.get(e)-u.get(t))}(n,t.slots[e].attachedIds),a=[];for(let l of s){let{config:s}=ea(o,e,l),c=el(n,e,l),u=c?(0,oJ.A)({},s,c):s,d=r_(l),m=t.extensions[d];if(m){let e=u?.["Display conditions"]?.privileges??m.privileges??[];if(e&&("string"==typeof e||Array.isArray(e)&&e.length>0)&&(!i?.user||!tK(e,i.user))||m.featureFlag&&!r.includes(m.featureFlag))continue;a.push({id:l,name:d,moduleName:m.moduleName,config:u,featureFlag:m.featureFlag,meta:m.meta,displayConditionExpression:u?.["Display conditions"]?.expression||m.displayExpression})}}return a}(o,e,m,n,c,r.session);d&&d.moduleName===u.moduleName&&(0,F.A)(d.candidateExtensions,p)?a[o]=d:(a[o]={moduleName:u.moduleName,candidateExtensions:p},l=!0)}(l||Object.keys(s).length!==Object.keys(a).length)&&rc.setState({slots:a})}(rl.getState(),ru.getState(),rd.getState(),oF.getState(),tU.getState(),t)}catch(e){throw rm=null===t||null===rm?null:new Set([...t,...rm]),e}if(e>=20)return void console.error("The extension system stopped recomputing after 20 passes because something keeps invalidating slots in response to the extension store being written. Some slots are left stale until the next write.")}}finally{rp=!1}}}function rh(e,t){let n=new Set;for(let o of Object.keys(e))e[o]!==t[o]&&n.add(o);for(let o of Object.keys(t))o in e||n.add(o);return n}function rw(e,t){return{moduleName:t,name:e,attachedIds:[]}}function r_(e){let[t]=e.split("#");return t}function ry(e,t){let n=r_(t);return e.extensions[n]}function rv(e){return ry(rl.getState(),e)}rl.subscribe((e,t)=>{rf(e.extensions!==t.extensions?null:rh(e.slots,t.slots))}),ru.subscribe((e,t)=>{rf(rh(e.slots,t.slots))}),rd.subscribe((e,t)=>{rf(rh(e.configs,t.configs))}),oF.subscribe(()=>rf(null)),tU.subscribe(()=>rf(null)),rf(null);let rb=e=>oQ(t=>({...t,extensions:{...t.extensions,[e.name]:{...e}}}));function rx(e,t){oQ(n=>{let o=n.slots[e];return o?{...n,slots:{...n.slots,[e]:{...o,attachedIds:[...o.attachedIds,t]}}}:{...n,slots:{...n.slots,[e]:{...rw(e),attachedIds:[t]}}}})}function rS(e,t){oQ(n=>{let o=n.slots[e];return o&&o.attachedIds.includes(t)?{...n,slots:{...n.slots,[e]:{...o,attachedIds:o.attachedIds.filter(e=>e!==t)}}}:n})}function rj(e){oQ(t=>{let n=t.slots[e];return n?{...t,slots:{...t.slots,[e]:{...n,attachedIds:[]}}}:t})}function rk(e){let t=new Map;return e.forEach((e,n)=>{t.has(e)||t.set(e,n)}),t}function rN(e,t){return function(e,t,n=null,o){let r;return e.filter(e=>{let i=e.displayConditionExpression;if("string"!=typeof i||0===i.trim().length)return!0;r??(r=t&&"object"==typeof t?{session:n,...t}:{session:n});try{return!!oh(i,r)}catch(t){return console.error(`Error while evaluating expression '${i}' for ${e.id}`+(o?` in ${o}`:""),t),!1}})}(rC(e),t,tU.getState().session,e)}function rC(e){return rc.getState().slots[e]?.candidateExtensions??[]}let rE=(e,t)=>rl.setState(n=>{let o=n.slots[t]?.moduleName;if(o&&o!=e)return console.warn(`An extension slot with the name '${t}' already exists. Refusing to register the same slot name twice (in "registerExtensionSlot"). The existing one is from module ${o}.`),n;if(o&&o==e)return n;if(n.slots[t])return{...n,slots:{...n.slots,[t]:{...n.slots[t],moduleName:e}}};let r=rw(t,e);return{...n,slots:{...n.slots,[t]:{...r}}}}),rP=()=>{rm=null,oQ(()=>({slots:{},extensions:{}})),oZ().setState({renderings:new Map}),rc.setState({slots:{}})},rI=R("left-nav",{slotName:null,basePath:window.spaBase,mode:"normal"});function rO({name:e,basePath:t,mode:n,componentContext:o,state:r}){rI.setState({slotName:e,basePath:t,mode:n??"normal",componentContext:o,state:r})}function rA(e){rI.getState().slotName===e&&rI.setState(rI.getInitialState(),!0)}let rR=R("modalRegistry",{modals:{}});function rT(e){rR.setState(t=>(t.modals[e.name]=e,t))}function r$(e){let t=rR.getState().modals[e];if(!t){let n=rv(e);n&&(t={name:e,load:n.load,moduleName:n.moduleName},console.warn(`Modal ${e} was registered as an extension. This is deprecated and will be removed in the future. Please register it in the "modals" section of routes.json instead of the "extensions" section.`),rT(t))}return t}let rM=R("workspace2",{registeredGroupsByName:{},registeredWindowsByName:{},registeredWorkspacesByName:{},openedGroup:null,openedWindows:[],isMostRecentlyOpenedWindowHidden:!1});function rL(e){let{registeredWorkspacesByName:t,registeredWindowsByName:n}=rM.getState(),o=t[e];if(o){let t=n[o.window];if(t)return t;throw Error(`No workspace window found with name: ${o.window} for workspace: ${e}`)}throw Error(`No workspace found with name: ${e}`)}function rW(e){let{registeredGroupsByName:t,registeredWindowsByName:n}=rM.getState(),o=n[e];if(o){let n=t[o.group];if(n)return n;throw Error(`No workspace group found with name: ${o.group} for window: ${e}`)}throw Error(`No workspace window found with name: ${e}`)}function rD(e){let{openedWindows:t}=rM.getState();return t.findIndex(t=>t.openedWorkspaces.find(t=>t.workspaceName===e))}function rU(e,t){if(0==t.length)return;let{registeredGroupsByName:n}=rM.getState(),o={...n};for(let n of t){if(o[n.name])throw Error(`Cannot register workspace group ${n.name} more than once`);o[n.name]={...n,moduleName:e}}rM.setState({registeredGroupsByName:o})}function rB(e,t){if(0==t.length)return;let{registeredWindowsByName:n}=rM.getState(),o={...n};for(let n of t){if(o[n.name])throw Error(`Cannot register workspace window ${n.name} more than once`);let t={...n,moduleName:e};o[n.name]=t}rM.setState({registeredWindowsByName:o})}function rF(e,t){if(0==t.length)return;let{registeredWorkspacesByName:n}=rM.getState(),o={...n};for(let n of t){if(o[n.name])throw Error(`Cannot register workspace ${n.name} more than once`);let t={...n,moduleName:e};o[n.name]=t}rM.setState({registeredWorkspacesByName:o})}let rH=0,rV=null,rz={bootstrap:15e3,mount:15e3,unmount:15e3};function rG(e,t){if(e.timeouts)return e;let n=e.name??"parcel",o=Object.fromEntries(Object.keys(rz).filter(t=>e[t]).map(o=>{var r,i;let s,a;return[o,(r=e[o],i=rz[o],s=Array.isArray(r)?r:[r],a=e=>s.reduce((t,r,i)=>t.then(()=>{let t=r(e);return"function"==typeof t?.then&&"function"==typeof t?.catch?t:Promise.reject(Error(`Lifecycle function ${o} at array index ${i} for parcel ${n} did not return a promise`))}),Promise.resolve(void 0)),e=>{let r,s=new Promise((e,t)=>{r=setTimeout(()=>t(Error(`Lifecycle function ${o} for parcel ${n} did not settle within ${i}ms`)),i)});return Promise.race([a(e),s]).finally(()=>clearTimeout(r)).then(e=>(t(o,!1),e),e=>{throw t(o,!0),e})})]}));return{...e,...o}}async function rq(e,t){var n,o;let r,i,s,a,l,c=await (rV??(rV=new Promise((e,t)=>{(0,ta.xL)({name:"openmrs-extension-host",bootstrap:()=>Promise.resolve(),mount:t=>(e(t.mountParcel),Promise.resolve()),unmount:()=>Promise.resolve()},{domElement:document.createElement("div")}).mountPromise.catch(t)}).catch(e=>(console.error("The host parcel used to mount extensions could not be mounted. Falling back to mounting extensions as root parcels, which leaks their DOM elements.",e),ta.xL))),rV),u={...t},d=(r=u,i=!1,{retarget:e=>r={...e},release:s=()=>(function(e){for(let t of Object.keys(e))delete e[t]})(r),onSettled(e,t){switch(e){case"bootstrap":t&&s();return;case"mount":i||(i=t);return;case"unmount":(t||i)&&s();return}}});return o=c((n=d.onSettled,"function"==typeof e?()=>e().then(e=>rG(e,n)):rG(e,n)),u),a=e=>t=>e.call(o,d.retarget(t)).catch(e=>{throw"SKIP_BECAUSE_BROKEN"===o.getStatus()&&d.release(),e}),l=o.update&&a(o.update),Object.defineProperty(o,"update",{configurable:!0,enumerable:!0,get:()=>l,set:e=>{l=e&&a(e)}})}function rJ(){return rK}function rK(e,t){let n,o=rq(e,t).then(e=>n=e);return{mount:()=>o.then(e=>e.mount()),unmount:()=>o.then(e=>e.unmount()),update:e=>o.then(t=>t.update?.(e)),getStatus:()=>n?.getStatus()??"LOADING_SOURCE_CODE",get loadPromise(){return o.then(e=>e.loadPromise)},get bootstrapPromise(){return o.then(e=>e.bootstrapPromise)},get mountPromise(){return o.then(e=>e.mountPromise)},get unmountPromise(){return o.then(e=>e.unmountPromise)}}}async function rX(e,t,n,o,r=e=>e,i={}){let s=r_(o),a=rv(o),l=null;if(e){let c;if(!a)throw Error(`Couldn't find extension '${s}' to attach to '${t}'`);let{meta:u,moduleName:d,load:m}=a,p=rH++,f=`${t}/${o}-${p}`;e.dataset.extensionRenderingId=f;let g=e=>{try{o8(f)}catch(t){console.error(e,t)}};try{o6({renderingId:f,extensionName:s,extensionModuleName:d,extensionId:o,slotName:t,slotModuleName:n})}catch(e){throw g(`Recomputing configuration after registering '${o}' failed also failed`),e}try{c=await m()}catch(e){throw g(`Recomputing configuration after '${o}' failed to load also failed`),e}try{l=await rq(r({...c,name:`${t}/${s}-${p}`}),{...i,_meta:u,_extensionContext:{extensionId:o,extensionSlotName:t,extensionSlotModuleName:n,extensionModuleName:d,extensionMeta:u},domElement:e})}catch(e){throw g(`Recomputing configuration after '${o}' failed to mount also failed`),e}l.mountPromise.then(void 0,e=>{console.error(`Extension '${o}' in slot '${t}' failed to mount`,e),g(`Recomputing configuration after '${o}' failed to mount also failed`)}),l.unmountPromise.then(()=>g(`Recomputing configuration after unmounting '${o}' failed`),e=>{console.error(`Extension '${o}' in slot '${t}' failed to unmount`,e),g(`Recomputing configuration after '${o}' failed to unmount also failed`)})}else console.warn(`Tried to render ${o} into ${t} but no DOM element was available.`);return l}var rY=n(1445),rZ=n.n(rY);let rQ=(0,rY.createContext)({moduleName:"",featureName:""});var r0=n(7088);function r1({to:e,templateParams:t,onBeforeNavigate:n,children:o,...r}){return(0,rY.useEffect)(()=>{r.href&&console.warn(`ConfigurableLink does not support the href prop. Use the 'to' prop instead. The provided href value is '${r.href}'`),r.onClick&&console.warn(`ConfigurableLink does not support the onClick prop. Use the 'onBeforeNavigate' prop instead. The 'to' prop of the offending link is ${e}`)},[]),(0,r0.jsx)("a",{onClick:o=>{0===o.button&&!o.ctrlKey&&!o.shiftKey&&!o.altKey&&!o.metaKey&&(o.preventDefault(),n?.(o),tj({to:e,templateParams:t})),0===o.button&&(o.ctrlKey||o.metaKey)&&n?.(o),0===o.button&&o.shiftKey&&n?.(o),1===o.button&&n?.(o)},href:tx(e,t),...r,children:o})}let r2=({state:e,children:t,...n})=>{let{extension:o}=(0,rY.useContext)(rQ),r=(0,rY.useRef)(null),i=(0,rY.useRef)(Promise.resolve()),s=(0,rY.useRef)(!1),a=(0,rY.useRef)(!1),l=(0,rY.useRef)(e),c=(0,rY.useCallback)(e=>{if(!e)return;let t=()=>{"MOUNTED"===e.getStatus()&&e.unmount()};switch(e.getStatus()){case"MOUNTED":e.unmount();break;case"UPDATING":i.current?.then(t,t);break;default:e.mountPromise.then(t,()=>{})}},[]),u=(0,rY.useCallback)((e,t)=>{e.update&&"UNMOUNTING"!==e.getStatus()&&(i.current=Promise.all([e.mountPromise,i.current]).then(()=>{if(r.current?.getStatus()==="MOUNTED"&&r.current.update)return r.current.update({...t})}).catch(e=>{let t=r.current?.getStatus();"UNMOUNTING"!==t&&"NOT_MOUNTED"!==t&&"UNLOADING"!==t&&console.error(`The extension '${o?.extensionId}' failed to update`,e)}))},[]),d=(0,rY.useCallback)(t=>{t&&!r.current&&!a.current&&o?.extensionSlotName&&o.extensionSlotModuleName&&(a.current=!0,rX(t,o.extensionSlotName,o.extensionSlotModuleName,o.extensionId,void 0,e).then(t=>{(a.current=!1,r.current=t,s.current)?c(t):t&&l.current!==e&&u(t,l.current)},()=>{a.current=!1}))},[]);return(0,rY.useEffect)(()=>(s.current=!1,()=>{s.current=!0,c(r.current)}),[]),(0,rY.useEffect)(()=>{l.current=e,r.current&&u(r.current,e)},[e]),o?(0,r0.jsx)("div",{ref:d,"data-extension-id":o?.extensionId,style:{position:"relative"},...n}):null};function r5(e){let t=(0,rY.useRef)(e);return x(t.current,e)||(t.current=e),t.current}function r6(e,t){"function"==typeof t&&(t=t(e));let n={};for(let[o,r]of Object.entries(t)){let t=function(...t){e.setState(e=>r(e,...t))};n[o]=t}return n}let r8=e=>e;function r4(e,t=r8,n){let o=(0,rY.useCallback)(t=>e.subscribe(t),[e]),r=(0,rY.useCallback)(()=>t(e.getState()),[e,t]),i=(0,rY.useSyncExternalStore)(o,r,r),s=(0,rY.useMemo)(()=>n?r6(e,n):null,[e,n]);return(0,rY.useMemo)(()=>s?{...i,...s}:i,[i,s])}function r3(e,t){return r4(e,r8,t)}function r7(e){return function(t){let n=(0,rY.useCallback)(t=>e.subscribe(t),[]),o=(0,rY.useCallback)(()=>e.getState(),[]),r=(0,rY.useSyncExternalStore)(n,o,o),i=(0,rY.useMemo)(()=>t?r6(e,t):null,[t]);return(0,rY.useMemo)(()=>i?{...r,...i}:r,[r,i])}}let r9=[];Object.freeze(r9);let ie={candidateExtensions:r9};Object.freeze(ie);let it=e=>{let t=(0,rY.useCallback)(t=>t.slots?.[e]??ie,[e]);return r4(o4(),t)},io=e=>e.session;function ir(e,t){let{candidateExtensions:n}=it(e),o=r4(tU,io),r=r5(t);return(0,rY.useMemo)(()=>rN(e,r),[e,r,o,n])}function ii(e,t){let{moduleName:n}=(0,rY.useContext)(rQ);if(!n)throw Error("ComponentContext has not been provided. This should come from @openmrs/esm-react-utils.");return(0,rY.useEffect)(()=>{rE(n,e)},[n,e]),{extensions:ir(e,t),extensionSlotName:e,extensionSlotModuleName:n}}function is(e){return e}function ia({name:e,extensionSlotName:t,select:n=is,children:o,state:r,style:i,...s}){if(o&&r)throw Error("Both children and state have been provided. If children are provided, the state must be passed as a prop to the `Extension` component.");let a=e??t,l=(0,rY.useRef)(null),{extensions:c,extensionSlotModuleName:u}=ii(a,r),d=(0,rY.useMemo)(()=>n(c),[n,c]),m=(0,rY.useMemo)(()=>{if("function"==typeof o&&!rZ().isValidElement(o))return d.map(e=>o(e,r))},[o,d]);return(0,r0.jsx)("div",{ref:l,"data-extension-slot-name":a,"data-extension-slot-module-name":u,style:{...i,position:"relative"},...s,children:a&&d?.map((e,t)=>(0,r0.jsx)(rQ.Provider,{value:{moduleName:u,featureName:"",extension:{extensionId:e.id,extensionSlotName:a,extensionSlotModuleName:u,extensionMeta:e.meta}},children:m?.[t]??("function"!=typeof o?o:null)??(0,r0.jsx)(r2,{state:r})},e.id))})}var il=n(9184),ic=n.n(il),iu=n(9568),id=n(9737),im=n(749),ip=n.n(im),ig=n(5254);let ih={strictMode:!0,throwErrorsToConsole:!0,disableTranslations:!1},iw=new Map;(0,ig.initCache)(iw);let i_={errorRetryCount:3,fetcher:tW,focusThrottleInterval:18e5,revalidateIfStale:!0,revalidateOnFocus:!1,revalidateOnReconnect:!1,refreshInterval:0,shouldRetryOnError:e=>{if(e instanceof tD){let t=e.response.status;return!!(t>=500)||401===t||403===t||429===t}return!0},provider:()=>iw};function iy(e){if("object"!=typeof e||"string"!=typeof e.featureName||"string"!=typeof e.moduleName)throw Error("Invalid options");let t=Object.assign({},ih,e),n={...i_,...t.swrConfig};return function(e){var o,r,i,s,a;return i=r=class extends(o=rZ().Component){componentDidCatch(e,n){n&&n.componentStack&&(e.extra=Object.assign(e.extra||{},{componentStack:n.componentStack})),t.throwErrorsToConsole&&setTimeout(()=>{throw e}),this.setState({caughtError:e,caughtErrorInfo:n})}render(){if(this.state.caughtError)return(0,r0.jsx)("div",{children:"An error has occurred. Please try reloading the page."});{let o=(0,r0.jsx)(rY.Suspense,{fallback:null,children:(0,r0.jsx)(im.SWRConfig,{value:n,children:(0,r0.jsx)(rQ.Provider,{value:this.state.config,children:t.disableTranslations?(0,r0.jsx)(e,{...this.props}):(0,r0.jsx)(id.I18nextProvider,{i18n:window.i18next,defaultNS:this.state.config.extension?`${this.state.config.moduleName}___${this.state.config.extension.extensionSlotName}___${this.state.config.extension.extensionId}`:this.state.config.moduleName,children:(0,r0.jsx)(e,{...this.props})})})})});return t.strictMode&&rZ().StrictMode?(0,r0.jsx)(rZ().StrictMode,{children:o}):o}}constructor(e){super(e),this.state={caughtError:null,caughtErrorInfo:null,config:{moduleName:t.moduleName,featureName:t.featureName,extension:e._extensionContext}}}},s="displayName",a=`OpenmrsReactComponent(${t.featureName})`,s in i?Object.defineProperty(i,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):i[s]=a,r}}function iv(e,t){return(0,iu.A)({React:rZ(),ReactDOMClient:ic(),rootComponent:iy(t)(e)})}function ib(e,t){return()=>e().then(({default:e})=>iv(e,t))}function ix(e,t){return()=>Promise.resolve(iv(e,t))}let iS=ib,ij=(0,C.y)()(()=>({}));$("openmrs-app-context",ij);let ik={};function iN(e,t=e=>e){let n=ij.getState();return e in n?Object.freeze(Object.assign({},t?t(n[e]):n[e])):null}function iC(e,t){ij.setState(n=>(e in n||(n[e]={}),n[e]=t(n[e]),Object.assign({},n)))}function iE(e){return null===e?null:Object.freeze(Object.assign({},e))}let iP=new Map;function iI(e,t){let n=(0,rY.useRef)(t??{}),o=(0,rY.useRef)(t=>iC(e,t)),r=(0,rY.useRef)(Symbol());return(0,rY.useEffect)(()=>{let n=t??{},o=r.current;return null===iN(e)?!function(e,t=ik){ij.setState(n=>{if(e in n)throw Error(`Attempted to re-register namespace ${e} in the app context. Each namespace must be unregistered before the name can be registered again.`);return Object.assign({},n,{[e]:t===ik?{}:t})})}(e,n):(console.warn(`Namespace ${e} is already registered in the app context. This is likely a race condition during navigation, but may indicate two components are trying to own the same namespace. Updating the existing context.`),iC(e,()=>n)),iP.set(e,o),()=>{iP.get(e)===o&&(ij.setState(t=>(e in t&&delete t[e],t)),iP.delete(e))}},[e]),(0,rY.useEffect)(()=>{let o=t??{};x(n.current,o)||(iC(e,()=>o),n.current=o)},[t]),o.current}function iO({namespace:e,value:t}){return iI(e,t),null}let iA=({children:e,value:t,fallback:n})=>t?(0,r0.jsx)(r0.Fragment,{children:e}):n?(0,r0.jsx)(r0.Fragment,{children:n}):null;function iR(){let e=(0,rY.useRef)(null);return(!e.current||e.current.signal.aborted)&&(e.current=new AbortController),(0,rY.useEffect)(()=>{let t=e.current;return()=>t?.abort()},[]),e.current}function iT(e,t=e=>e??{}){let[n,o]=(0,rY.useState)(()=>{if(i$(e))return;let n=iN(e);if(null!==n)return t?t(n):n});return(0,rY.useEffect)(()=>{if(i$(e))throw Error(`The namespace supplied to useAppContext must be a non-empty string, but was "${e}".`)},[e]),(0,rY.useEffect)(()=>{var n;let r;return(n=e=>{if(null==e)return void o(void 0);let n=t?t(e):e;o(e=>x(e,n)?e:n)})(iE(r=iN(e))),ij.subscribe(t=>{let o=e in t?t[e]:null;o!==r&&(r=o,n(iE(o)))})},[e,t]),n}function i$(e){return"string"!=typeof e||0===e.trim().length}function iM(e){let t=ir(e);return(0,rY.useMemo)(()=>t.map(e=>e.id),[t])}function iL(e){return it(e).candidateExtensions}function iW(e,t,n){let{data:o,error:r,mutate:i,isLoading:s,isValidating:a}=ip()(e?nK(e,t,n):null,tW);return(0,rY.useMemo)(()=>({isLoading:s,data:o?.data.results??[],error:r,mutate:i,isValidating:a}),[o,r,s,a,i])}function iD(e){(0,rY.useEffect)(()=>{if(e){let e=window.getComputedStyle(document.body).overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=e}}},[e])}let iU={},iB=`No ComponentContext has been provided. This should come from "openmrsComponentDecorator".
16
16
  Usually this is already applied when using "getAsyncLifecycle" or "getSyncLifecycle".`;function iF(e,t,n){let o=iU[e];if(o)return o;let r=new Promise(e=>{let o=n(t.getState());if(o)return void e(o);let r=t.subscribe(t=>{let o=n(t);o&&(r(),e(o))})});return iU[e]=r,r.then(()=>{iU[e]===r&&delete iU[e]}),r}function iH(e){let{moduleName:t,extension:n}=(0,rY.useContext)(rQ),o=e?.externalModuleName??t;if(!o&&!n)throw Error(iB);let r=function(e){let t=(0,rY.useMemo)(()=>en(e),[e]),n=function(e){let[t,n]=(0,rY.useState)(()=>{let t=e.getState();return t.loaded&&t.config?t.config:null});return(0,rY.useEffect)(()=>e?.subscribe(e=>{e.loaded&&e.config&&n(e.config)}),[e]),t}(t);if(!n)throw iF(e,t,e=>e.loaded?e.config:null);return n}(o),i=function(e){let t=(0,rY.useMemo)(es,[]),n=function(e,t){let[n,o]=(0,rY.useState)(t?()=>{let n=ea(e.getState(),t.extensionSlotName,t.extensionId);if(n.loaded&&n.config)return n.config}:null);return(0,rY.useEffect)(()=>{if(t)return e.subscribe(e=>{let r=ea(e,t.extensionSlotName,t.extensionId);r.loaded&&r.config&&!(0,F.A)(r.config,n)&&o(r.config)})},[e,t,n]),n}(t,e);if(!n&&e)throw iF(`${e.extensionSlotName}-${e.extensionId}`,t,t=>{let n=ea(t,e.extensionSlotName,e.extensionId);return n.loaded?n.config:null});return n||{}}(n);return(0,rY.useMemo)(()=>e?.externalModuleName&&o===e.externalModuleName?{...r}:{...r,...i},[o,e?.externalModuleName,r,i])}let iV=ir;function iz(e,t=300){let[n,o]=(0,rY.useState)(e);return(0,rY.useEffect)(()=>{let n=setTimeout(()=>{o(e)},t);return()=>{clearTimeout(n)}},[e,t]),n}var iG=n(8086),iq=n.n(iG);let iJ=`custom:${[["admissionDecisionConcept","ref"],["admissionEncounterType","ref"],["admissionForm","ref"],["atFacilityVisitType","ref"],["bedAssignmentEncounterType","ref"],["cancelADTRequestEncounterType","ref"],["checkInClerkEncounterRole","ref"],["checkInEncounterType","ref"],["clinicianEncounterRole","ref"],["conceptSourcesForDiagnosisSearch","ref"],["consultEncounterType","ref"],["consultFreeTextCommentsConcept","ref"],["denyAdmissionConcept","ref"],["diagnosisMetadata","ref"],["diagnosisSets","ref"],["dischargeForm","ref"],["dispositionDescriptor","ref"],["dispositions","ref"],["emrApiConceptSource","ref"],["exitFromInpatientEncounterType","ref"],["extraPatientIdentifierTypes","ref"],["fullPrivilegeLevel","ref"],["highPrivilegeLevel","ref"],["identifierTypesToSearch","ref"],["inpatientNoteEncounterType","ref"],["lastViewedPatientSizeLimit","ref"],["metadataSourceName","ref"],["motherChildRelationshipType","ref"],["narrowerThanConceptMapType","ref"],["nonDiagnosisConceptSets","ref"],["orderingProviderEncounterRole","ref"],["patientDiedConcept","ref"],["personImageDirectory","ref"],["primaryIdentifierType","ref"],["sameAsConceptMapType","ref"],["suppressedDiagnosisConcepts","ref"],["supportsAdmissionLocationTag","(uuid,display,name,links)"],["supportsLoginLocationTag","(uuid,display,name,links)"],["supportsTransferLocationTag","(uuid,display,name,links)"],["supportsVisitsLocationTag","(uuid,display,name,links)"],["telephoneAttributeType","ref"],["testPatientPersonAttributeType","ref"],["transferForm","ref"],["transferRequestEncounterType","ref"],["transferWithinHospitalEncounterType","ref"],["unknownCauseOfDeathConcept","ref"],["unknownLocation","ref"],["unknownPatientPersonAttributeType","ref"],["unknownProvider","ref"],["visitAssignmentHandlerAdjustEncounterTimeOfDayIfNecessary","ref"],["visitExpireHours","ref"],["visitNoteEncounterType","ref"]].map(([e,t])=>`${e}:${t}`).join(",")}`;function iK(){let e=`${tT}/emrapi/configuration?v=${iJ}`,t=iq()(e,tW);return(0,rY.useMemo)(()=>({emrConfiguration:t.data?.data,isLoadingEmrConfiguration:t.isLoading,mutateEmrConfiguration:t.mutate,errorFetchingEmrConfiguration:t.error}),[t])}function iX(){return(0,rY.useContext)(rQ).extension}let iY=r7(oY());function iZ(e){let t=ir(e);return(0,rY.useMemo)(()=>Object.fromEntries(t.map(e=>[e.name,e.meta])),[t])}let iQ=r7(o4());function i0(e){let{flags:t}=r4(oF);return t[e]?.enabled??!1}function i1(){let[,e]=(0,rY.useState)(0);return(0,rY.useCallback)(()=>{e(e=>e+1)},[])}function i2(e,t,n={}){return i6(e,t,i5,n)}let i5={getPaginatedUrl:(e,t,n)=>{if(!e)return null;{let o=new URL(tL(e.toString()),window.location.toString());return o.searchParams.set("limit",""+t),o.searchParams.set("startIndex",""+n),o.searchParams.set("totalCount","true"),o.toString()}},getNextUrl:e=>{let t=e?.links?.find(e=>"next"==e.rel)?.uri;if(!t)return null;{let e=new URL(t);return e.host=window.location.host,e.protocol=window.location.protocol,e.toString()}},getTotalCount:e=>e?.totalCount??NaN,getCurrentPageSize:e=>e?.results?.length??NaN,getData:e=>e?.results};function i6(e,t,n,o={}){let{getPaginatedUrl:r,getTotalCount:i,getCurrentPageSize:s,getData:a}=n,{immutable:l,swrConfig:c}=o,u=o.fetcher??tW,[d,m]=(0,rY.useState)(1),p=(0,rY.useRef)(NaN),f=(0,rY.useRef)(NaN),g=(0,rY.useRef)(d),h=(0,rY.useRef)(!1),w=(0,rY.useRef)(!1),_=e?.toString()??"",[y,v]=(0,rY.useState)(_);_!==y&&(v(_),m(1),g.current=1,p.current=NaN,f.current=NaN,h.current=!1,w.current=!1);let b=(d-1)*t,x=(0,rY.useMemo)(()=>r(e,t,b),[e,t,b]),{data:S,...j}=(l?iq():ip())(x,u,c);S?.data&&(p.current=i(S?.data),f.current=s(S?.data),h.current=!0);let k=Math.ceil(p.current/t),N=(0,rY.useCallback)(e=>{if(!Number.isInteger(e)||e<1)return void console.warn(`useServerPagination: ignoring goTo(${e}); page must be a positive integer.`);let n=Math.ceil(p.current/t);!h.current||Number.isNaN(n)||e<=n?(g.current=e,m(e)):console.warn("Invalid attempt to go to out of bounds page: "+e)},[t]);(0,rY.useEffect)(()=>{if(!h.current)return;if(Number.isNaN(p.current)){w.current||(w.current=!0,console.warn(`useServerPagination: ${_} returned no total count, so out-of-range pages cannot be detected.`));return}let e=Math.max(1,Math.ceil(p.current/t));d>e&&(console.warn(`Invalid attempt to go to out of bounds page: ${d}; returning to page ${e}.`),g.current=e,m(e))},[d,t,_,S]);let C=(0,rY.useCallback)(()=>{N(g.current+1)},[N]),E=(0,rY.useCallback)(()=>{N(g.current-1)},[N]);return{data:a(S?.data),totalPages:k,totalCount:p.current,currentPage:d,currentPageSize:f.current,paginated:k>1,showNextButton:d<k,showPreviousButton:d>1,goTo:N,goToNext:C,goToPrevious:E,...j}}function i8(e,t,n={}){return i6(e,t,i4(),n)}function i4(){return{getPaginatedUrl:(e,t,n)=>{if(!e)return null;{let o=new URL(tL(e.toString()),window.location.toString());return o.searchParams.set("_count",""+t),o.searchParams.set("_getpagesoffset",""+n),o.toString()}},getNextUrl:e=>{let t=e?.link?.find(e=>"next"==e.relation)?.url;if(!t)return null;{let e=new URL(t);return e.host=window.location.host,e.protocol=window.location.protocol,e.toString()}},getTotalCount:e=>e?.total??NaN,getCurrentPageSize:e=>e?.entry?.length??NaN,getData:e=>e?.entry?.map(e=>e.resource)}}var i3=n(2216),i7=n.n(i3);function i9(e,t={}){return se(e,i5,t)}function se(e,t,n={}){let{swrInfiniteConfig:o,immutable:r}=n,{getNextUrl:i,getTotalCount:s,getData:a}=t,l=n.fetcher??tW,c=(0,rY.useCallback)((n,o)=>0==n?e?.toString()??null:t.getNextUrl(o.data),[e]),{data:u,size:d,setSize:m,...p}=i7()(c,l,{...o,...r?{revalidateIfStale:!1,revalidateOnFocus:!1,revalidateOnReconnect:!1}:{}}),f=i(u?.[u.length-1].data),g=s(u?.[0]?.data);return{data:u?.flatMap(e=>a(e.data)),totalCount:g,hasMore:null!=f,loadMore:()=>{m((u?.length??0)+1)},nextUri:f,...p}}function st(e,t={}){return sn(e,i5,t)}function sn(e,t,n={}){let o=se(e,t,n),{hasMore:r,error:i,data:s,loadMore:a,isLoading:l,nextUri:c}=o;return((0,rY.useEffect)(()=>{r&&!i&&a()},[r,c]),n.partialData)?o:{...o,data:r||i?void 0:s,isLoading:l||r}}function so(e,t={}){return sn(e,i4(),t)}function sr(e,t={}){return se(e,i4(),t)}function si(){let e="tablet";return document.body.classList.forEach(t=>{switch(t){case"omrs-breakpoint-lt-tablet":e="phone";break;case"omrs-breakpoint-gt-small-desktop":e="large-desktop";break;case"omrs-breakpoint-gt-tablet":e="small-desktop"}}),e}function ss(){let[e,t]=(0,rY.useState)(si);return(0,rY.useEffect)(()=>{let e=()=>{t(si())};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),e}let sa=e=>"small-desktop"===e||"large-desktop"===e;function sl(e){let t=(0,rY.useContext)(rQ);(0,rY.useEffect)(()=>(t&&t.moduleName&&(e.componentContext=t),rO(e),()=>{rA(e.name)}),[t,e])}function sc(){return r4(rI)}let su=[];function sd(e=null,t=null){let n=new URLSearchParams;e&&n.set("tag",e),t&&n.set("q",t);let o=n.toString(),{data:r}=st(`${tT}/location${o?"?"+o:""}`,{immutable:!0});return r??su}function sm(e,t=!0){let n=(0,rY.useRef)(null);return(0,rY.useEffect)(()=>{let o=o=>{t&&n.current&&o.target&&o.target instanceof Node&&(n.current.contains(o.target)||e(o))};return window.addEventListener("mousedown",o),window.addEventListener("touchstart",o),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("touchstart",o)}},[e,t]),n}function sp(e){let t=(0,rY.useRef)(null);return(0,rY.useEffect)(()=>{let n=new IntersectionObserver(t=>{for(let n of t)if(n.isIntersecting)return void e()},{threshold:1});return t.current&&n.observe(t.current),()=>{t.current&&n.unobserve(t.current)}},[t.current,e]),t}function sf(e,t={}){let{abortController:n,fetchInit:o,url:r,swrConfig:i}=t,s=iR(),a=(0,rY.useMemo)(()=>o?.signal??n?.signal??s.signal,[n?.signal,o?.signal,s.signal]),l=(0,rY.useCallback)(e=>tW(function(e,t){if(t)return"function"==typeof t?t(e):t;if("string"==typeof e)return e;throw Error(`When using useOpenmrsSWR with a key that is not a string, you must provide a url() function that converts the key to a valid url. The key for this hook is ${e}.`)}(e,r),{...o,signal:a}),[a,o,r]);return ip()(e,l,i)}function sg(e=[],t=10){let[n,o]=(0,rY.useState)(1),r=(0,rY.useMemo)(()=>"number"==typeof t&&t>0?Math.max(1,Math.ceil(e.length/t)):1,[e.length,t]);n>r&&o(r);let i=Math.min(Math.max(1,n),r),s=(0,rY.useMemo)(()=>{let n=(i-1)*t,o=(i+0)*t;return e.slice(n,o)},[e,i,t]),a=(0,rY.useCallback)(e=>{!Number.isInteger(e)||e<1?console.warn(`usePagination: ignoring goTo(${e}); page must be a positive integer.`):o(e)},[]),l=(0,rY.useCallback)(()=>{o(e=>e+1)},[]),c=(0,rY.useCallback)(()=>{o(e=>Math.max(1,e-1))},[]);return(0,rY.useMemo)(()=>({results:s,totalPages:r,currentPage:i,paginated:e.length>t,showNextButton:i<r,showPreviousButton:i>1,goTo:a,goToNext:l,goToPrevious:c}),[s,r,e.length,t,i,a,l,c])}function sh(e,t,n,o){return{pageSizes:(0,rY.useMemo)(()=>{let n=Math.ceil(t/e);return isNaN(n)&&(n=0),[...Array(n).keys()].map(t=>(t+1)*e)},[e,t]),pageItemsCount:(0,rY.useMemo)(()=>e>t?t:e*n>t?e*(n-1)+o:e*n,[e,t,n,o])}}function sw(){let e=/\/patient\/([a-zA-Z0-9\-]+)\/?/.exec(location.pathname);return e&&e[1]}function s_(e){let[t,n]=(0,rY.useState)(e??sw()),{data:o,error:r,isValidating:i}=ip()(t?["patient",t]:null,()=>nZ(t,{}));return(0,rY.useEffect)(()=>{let e=()=>{let e=sw();e!==t&&n(e)};return window.addEventListener("single-spa:routing-event",e),()=>window.removeEventListener("single-spa:routing-event",e)},[t]),(0,rY.useMemo)(()=>({isLoading:i&&!r&&!o,patient:o,patientUuid:t,error:r}),[i,r,o,t])}function sy(){let e=`${tT}/metadatamapping/termmapping?v=custom:(metadataUuid)&code=emr.primaryIdentifierType`,{data:t,error:n,isLoading:o}=ip()(e,tW);return(0,rY.useMemo)(()=>({primaryIdentifierCode:t?.data?.results[0]?.metadataUuid,isLoading:o,error:n}),[t,n,o])}function sv(e,t,n,o){let r=e?.slotName===t&&e.slotModuleName===n?e.components:null,i=new Map;for(let e of o)i.set(e,r?.get(e)??function(e,t,n){let o=r_(n),r=e=>e.extensions[o]?.meta,i=({state:o})=>{let i=r4(oY(),r),s=(0,rY.useMemo)(()=>({moduleName:t,featureName:"",extension:{extensionId:n,extensionSlotName:e,extensionSlotModuleName:t,extensionMeta:i}}),[i]);return(0,r0.jsx)(rQ.Provider,{value:s,children:(0,r0.jsx)(r2,{state:o})})};return i.displayName=`RenderableExtension(${n})`,i}(t,n,e));return{slotName:t,slotModuleName:n,components:i}}function sb(e){let{extensions:t,extensionSlotModuleName:n}=ii(e),o=(0,rY.useMemo)(()=>new Set(e?t.map(e=>e.id):[]),[e,t]),[r,i]=(0,rY.useState)(()=>sv(null,e,n,o)),s=r;return r.slotName===e&&r.slotModuleName===n&&r.components.size===o.size&&[...o].every(e=>r.components.has(e))||i(s=sv(r,e,n,o)),(0,rY.useMemo)(()=>e?t.flatMap(e=>{let t=s.components.get(e.id);return t?[t]:[]}):[],[e,t,s])}function sx(){let e=(0,rY.useRef)(null),[t,n]=(0,rY.useState)(null),o=null;if(!t){if(i){let e=tz().getState();e.loaded&&(o=e.session)}else i=new Promise(t=>{let n=({loaded:n,session:r})=>{n&&(t(r),o=r,e.current&&(e.current(),e.current=null))};n(tz().getState()),o||(e.current=tz().subscribe(n))});if(o)n(o);else throw i}(0,rY.useEffect)(()=>(e.current||(e.current=tz().subscribe(({loaded:e,session:t})=>{e&&(o=t,n(t))})),()=>{e.current&&(e.current(),e.current=null)}),[]);let r=t||o;if(!r)if(i)throw console.warn("useSession is in an unexpected state. Attempting to recover."),i;else throw Error("useSession is in an invalid state.");return r}let sS=({privilege:e,fallback:t,children:n})=>{let[o,r]=(0,rY.useState)(null);return((0,rY.useEffect)(()=>{let e=tz(),t=e.subscribe(({loaded:e,session:t})=>{r(e?t?.user??null:null)}),{loaded:n,session:o}=e.getState();return n&&r(o?.user??null),t},[]),o&&tK(e,o))?(0,r0.jsx)(r0.Fragment,{children:n}):t?(0,r0.jsx)(r0.Fragment,{children:t}):null};var sj=n(4343),sk=n.n(sj),sN=n(3355);let sC=new Map;function sE(){for(let e of Array.from(sC.values()))e()}let sP={setVisitContext:(e,t)=>null==t?{manuallySetVisitUuid:null}:{manuallySetVisitUuid:t.uuid,patientUuid:t.patient?.uuid}};function sI(e){let t=(0,rY.useId)();return(0,rY.useEffect)(()=>{if(e)return sC.set(t,e),()=>{sC.delete(t)}},[t,e]),{...r3(oe(),sP),mutateVisit:sE}}function sO(e,t=n7){let n=(0,rY.useRef)(void 0),{patientUuid:o,manuallySetVisitUuid:r,setVisitContext:i}=sI((0,rY.useCallback)(()=>n.current?.(),[])),s=e&&o==e?r:null,a=`?patient=${e}&v=${t}&includeInactive=false`,l=`/${s}?v=${t}`,{data:c,error:u,mutate:d,isValidating:m}=ip()(e?`${tT}/visit${a}`:null,tW),{data:p,error:f,mutate:g,isValidating:h}=ip()(e&&s?`${tT}/visit${l}`:null,tW),w=(0,rY.useMemo)(()=>c?.data.results.find(e=>null===e.stopDatetime)??null,[c]),_=(0,rY.useMemo)(()=>s&&p?p.data:null,[p,s]),y=(0,rY.useRef)(null);(0,rY.useEffect)(()=>{!m&&w&&o===e&&null===r&&i(w),h||(y.current&&_&&y.current.uuid===_.uuid&&!y.current.stopDatetime&&_.stopDatetime&&i(null),y.current=_)},[_,r,w,m,h,o]);let v=(0,rY.useCallback)(()=>{d(),g()},[d,g]);(0,rY.useEffect)(()=>{n.current=v},[v]);let b=!!(!c||s&&!p),x=!!(s?f:u);return{error:u||f,mutate:v,isValidating:m||h,activeVisit:w,currentVisit:_,currentVisitIsRetrospective:!!s,isLoading:b&&!x}}sj.extend(sN);let sA=[];function sR(){let{data:e}=iq()(n6,n8);return e??sA}let sT=new Map;async function s$(e,t){let n=t.indexOf("#"),o=n>=0,r=o?t.substring(0,n):e,i=o?t.substring(n+1):t,s=await nx(r);return s&&Object.hasOwn(s,i)&&"function"==typeof s[i]?sL(r,s).then(()=>s[i]()):(s?s&&Object.hasOwn(s,i)?console.warn(`The export ${t}, defined in ${e}'s routes.json, is not a function`):console.warn(`${r} does not define a component called "${i}", referenced in ${e}'s routes.json. This cannot be loaded.`):console.warn(`Unknown app ${r} for ${t} defined in ${e}'s routes.json`),sM)}let sM={bootstrap:()=>Promise.resolve(),mount:()=>Promise.resolve(),unmount:()=>Promise.resolve()};async function sL(e,t){if(e in sT)await sT[e];else{let n=t??await nx(e);await (sT[e]=new Promise((t,o)=>{if(Object.hasOwn(n,"startupApp")){let r=n.startupApp;if("function"==typeof r)return Promise.resolve(r()).then(()=>{eO(e),t(null)}).catch(o)}eO(e),t(null)}))}}function sW(e,t){let n=t.name;if(!n)return void console.error(`An extension definition in ${e} is missing an name and thus cannot be
17
17
  registered. To fix this, ensure that you define the "name" field inside the
18
18
  extension definition.`,t);t.slots&&t.slot&&console.warn(`The extension ${n} from ${e} declares both a 'slots' property and