1import{j as i,r as l}from"./react-vendor-CU6Sz31W.js";import{g as Ve,d as Le}from"./firebase-w6DYUbFN.js";import{fT as Be,b as ke,gx as G,ah as xe,eC as Oe,ce as _e,e5 as Fe,cW as Ke,u as ye,hj as We,be as z,al as ze,eo as Ue,p9 as He,jv as qe,i as K,es as ue,gB as $e,S as De,bH as Xe,fH as Je,E as Ye,as as Ge,g9 as X,b8 as Qe}from"./index-DEXJEDAi.js";import{A as Ze}from"./AccessDenied-Ba4b0-Uz.js";import{P as et}from"./patient-name-link-BAfQKbEs.js";import{u as tt}from"./useOpenPatientProfile-CASNKG5E.js";import{u as st,w as it}from"./useClientsById-BI_N6qCU.js";import{F as at}from"./form-type-badge-C6n28ItU.js";import{i as nt,g as rt,a as ot}from"./statusHelpers-D6-TWPHn.js";import{g as lt,h as ct}from"./statusBadge-Dq6-fXVv.js";import{g as dt,i as mt,a as pt,c as ut}from"./productApprovalOnly-GEXGR3EQ.js";import{a as ft}from"./DataTableCard-BluwWKn_.js";import"./calendar-RV2oTCrW.js";import"./ExportCsvAction-BJr9eiP6.js";import{D as gt}from"./cells-Db2ZEFlu.js";import{D as J,a as ht,b as vt,V as xt}from"./VisitSandboxScopePill-CLRMsrcS.js";import{u as yt,P as St}from"./ProviderAssignmentPopover-BezpO-3b.js";import{R as Nt}from"./ReassignVisitDialog-BEbFAHvS.js";import{u as Ct}from"./useClinicalRecordMessagingActions-DbPdmNJ5.js";import{u as bt,a as Pt,i as Mt}from"./useNetworkLicensurePolicy-DGC2H23P.js";import{g as At}from"./providerClaimEligibility-D-3lpAwY.js";import{u as Rt,a as wt}from"./useVisitChartingLauncher-B1f2Z2_Q.js";import{E as jt}from"./ellipsis-vertical-C-dQ6Kzj.js";import"./payment-icons-Daq1K3F1.js";import"./shield-alert-DjOj07_r.js";import"./text-highlight-BFqqfcjs.js";import"./chartingWorkflow-C6kNA8aD.js";import"./index-BSuGcRaZ.js";import"./table-CxPdvV_9.js";import"./arrow-up-D6DFVL4j.js";import"./arrow-down-BjUlbB4f.js";import"./pill-filter-CtZSNPVl.js";import"./date-picker-filter-Qp1kqu9t.js";import"./clear-filters-button-DmPemFGr.js";import"./addWeeks-1hrFjz19.js";import"./modal-option-cards-Dksohkou.js";import"./ban-DZ1NMSKK.js";import"./providerOperations-ELdKx_YD.js";import"./networkLicensurePolicy-Ct3PZM4V.js";import"./ConfirmActionDialog-DH9STE_r.js";import"./user-round-c4EWOTq5.js";import"./arrow-right-left-B4vnGqzD.js";import"./user-x-D3cjntxi.js";import"./schedulingSelection-CZL0RDzD.js";import"./VisitSchedulePicker-4J6xpsxo.js";import"./clientProviderAvailability-CFIfqNIp.js";import"./visitDisplay-XXmI5Egl.js";function It({row:e}){return i.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[i.jsx(Be,{accentColor:e.clientAccentColor||ke,title:e.clientName,className:"max-w-[120px] max-lg:max-w-[9
16px] max-lg:px-1.5",children:e.clientName||"â"}),e.clientSandbox&&i.jsx(G,{tone:"amber",title:"This client is in sandbox mode",children:"Sandbox"})]})}function Tt({row:e}){const a=dt(e)||e.orderProductName;return i.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 max-lg:gap-1",children:[i.jsx(xe,{className:"size-3.5 shrink-0 text-[var(--status-info-text)] max-lg:size-3"}),a?i.jsx("span",{className:"truncate text-xs text-content-secondary max-lg:text-2xs",title:a,children:a}):i.jsx(at,{formType:e.formType,className:"max-w-full truncate text-3xs"}),mt(e)&&i.jsx(G,{tone:"purple",className:"shrink-0 text-3xs",title:a||ut(e),children:pt(e)})]})}function Et({millis:e}){if(!e)return"N/A";const a=new Date(e);return i.jsxs("div",{className:"text-sm tabular-nums text-content-secondary",children:[i.jsx("div",{className:"font-medium",children:a.toLocaleDateString("en-US",{month:"short",day:"numeric"})}),i.jsx("div",{className:"text-xs text-content-tertiary max-lg:text-3xs max-lg:leading-tight",children:a.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})})]})}function Vt({row:e}){let a;if(e.visitMode!=="async")a=lt(e);else if(nt(e))a=[rt()];else{const n=String(e.status||"").toLowerCase(),o=["completed","voided","cancelled","canceled"].includes(n)||["approved","denied","deferred"].includes(e.approvalStatus)?"completed":["under_review","in_review","in review","in progress"].includes(n)?"review":"pending";a=ot({...e,soapNotes:e.hasSoapNotes?"present":"",reviewStatus:o}),a.length||(a=[{key:o,label:o==="completed"?"Completed":"Pending",className:Oe(o)}])}return i.jsxs("div",{className:"flex flex-wrap items-center gap-2 max-lg:gap-1",children:[a.map(n=>i.jsx(_e,{variant:"outline",className:`${n.className} whitespace-nowrap max-lg:px-1.5 max-lg:text-3xs max-lg:leading-tight`,children:n.label},n.key)),!e.prescriptionCreated&&i.jsx(G,{tone:"red",className:"h-4 min-h-0 px-1.5 text-3xs font-medium",children:"No Rx"})]})}const W={rows:[],loading:!0,loadingMore:!1,error:"",filteredCount:0,totalCount:0,facet_counts:[],hasMore:!1,pageLatencyMs:800};async function fe(e){const a=await Ke({entity:"visits",...e}),n=(a==null?void 0:a.result)??a;if((n==null?void 0:n.success)===!1)throw new Error(n.error||"Unable to load visits. Retry.");return n}function Lt(e,a,n){const o=JSON.stringify({providerNetworkId:e,revision:a,...n}),[x,p]=l.useState(W),u=l.useRef(null),c=l.useMemo(()=>{const s=JSON.parse(o);return delete s.providerNetworkId,delete s.revision,s},[o]);l.useEffect(()=>{const s={current:!0,fetching:!1,page:0,hasMore:!1,key:o,pageLatencyMs:W.pageLatencyMs};if(u.current=s,p({...W,key:o,loading:!!e}),!e)return()=>{s.current=!1};async function d(){if(!s.current||s.fetching||s.page&&!s.hasMore)return;s.fetching=!0;const y=performance.now();p(h=>({...h,loadingMore:s.page>0,error:""}));try{const h=await fe({...c,page:s.page+1,perPage:50,includeFacets:s.page===0});if(!s.current)return;s.page=h.page,s.hasMore=h.hasMore;const R=performance.now()-y;s.pageLatencyMs=Math.round(s.pageLatencyMs*.65+R*.35),p(M=>{const A=new Set(M.rows.map(N=>N.id));return{...M,...h,rows:[...M.rows,...h.rows.filter(N=>!A.has(N.id))],loading:!1,loadingMore:!1,error:"",pageLatencyMs:s.pageLatencyMs}})}catch(h){s.current&&p(R=>({...R,loading:!1,loadingMore:!1,error:h.message||"Unable to load visits. Retry."}))}finally{s.fetching=!1}}s.fetchNext=d;const g=setTimeout(d,150);return()=>{clearTimeout(g),s.current=!1}},[e,o,c]);const f=l.useCallback(()=>{var s,d,g;if(((s=u.current)==null?void 0:s.key)===o)return(g=(d=u.current).fetchNext)==null?void 0:g.call(d)},[o]),P=l.useCallback(async()=>{const s=await Fe({searchFn:fe,requestBody:c,pickRows:d=>d.rows,getCount:d=>d.filteredCount});if(s.truncated)throw new Error("Too many visits to export. Narrow the filters and retry.");return s.rows},[c]);return{...x.key===o?x:W,loadMore:f,fetchAllRows:P}}const Bt=new Set(["completed","cancelled","canceled","voided"]),kt=new Set(["approved","denied","deferred"]),Ot=new Set(["pending","pending_review","pending_forms"]),ge=e=>String(e||"").trim().toLowerCase();function he(e,{provider:a=!1,admin:n=!1,delegate:o=!1,userId:x}={}
1){const p=ge(e.status),u=Bt.has(p)||kt.has(ge(e.approvalStatus)),c=Ot.has(p),f=!!(e.providerId||e.assignedTo);return{claim:a&&e.visitMode==="async"&&c&&!f&&!u,assign:(n||o)&&(e.visitMode==="async"?!!e.chartReviewId:!u),void:!o&&!u&&(n||a&&e.visitMode==="async"&&c&&!f),restore:p==="pending_patient_response"&&!!e.chartReviewId&&(n||o||a&&e.providerId===x),terminal:u}}const _t=20,Ft=75,Kt=8;function Wt(e,a,n){return Math.min(n,Math.max(a,e))}function zt({scrollTop:e,clientHeight:a,averageRowHeight:n,renderedRowCount:o,loadedRowCount:x,scrollVelocityPxPerMs:p=0,requestLatencyMs:u=800}){const c=Math.max(1,n||1),f=Math.max(1,Math.ceil(a/c)),P=Math.min(o,Math.ceil((Math.max(0,e)+a)/c)),s=Math.ceil(Math.max(0,p)*Math.max(0,u)/c),d=Wt(f+s+Kt,_t,Ft),g=Math.max(0,x-P);return{lastVisibleRow:P,lookAheadRows:d,remainingLoadedRows:g,shouldPrefetch:g<=d}}const Y="h-7 min-w-0 gap-1 px-2 text-3xs leading-none sm:px-2.5 sm:text-2xs xl:text-xs max-[1024px]:min-h-7 max-[1024px]:min-w-0 [&_svg]:size-3",Se=[["visitMode","Visit type"],["statusKey","Status"],["clientId","Client"],["productName","Product / form"],["assignmentKey","Provider"],["patientState","Patient state"],["rxKey","Prescription"]],ve=Object.fromEntries(Se.map(([e])=>[e,[]]));function Ut({enabled:e,loadedRowCount:a,loadingMore:n,pageLatencyMs:o,loadMore:x}){const p=l.useRef(null),u=l.useRef({top:0,time:0,velocity:0}),c=l.useRef(null),f=l.useCallback((s,d=!0)=>{var I;if(!s||!e||n||a===0)return;const g=performance.now(),y=u.current,h=g-y.time,R=d&&y.time>0&&h>0?Math.max(0,s.scrollTop-y.top)/h:0,M=d?y.velocity*.65+R*.35:y.velocity;u.current={top:s.scrollTop,time:g,velocity:M};const A=s.querySelector("tbody"),N=((I=A==null?void 0:A.rows)==null?void 0:I.length)||0;if(!N)return;const U=A.getBoundingClientRect().height/N;zt({scrollTop:s.scrollTop,clientHeight:s.clientHeight,averageRowHeight:U,renderedRowCount:N,loadedRowCount:a,scrollVelocityPxPerMs:M,requestLatencyMs:o}).shouldPrefetch&&x()},[e,a,n,o,x]),P=l.useCallback(s=>{const d=s.currentTarget;c.current!=null&&cancelAnimationFrame(c.current),c.current=requestAnimationFrame(()=>{c.current=null,f(d)})},[f]);return l.useEffect(()=>{const s=p.current;if(!s)return;const d=requestAnimationFrame(()=>f(s,!1));return()=>cancelAnimationFrame(d)},[f]),l.useEffect(()=>()=>{c.current!=null&&cancelAnimationFrame(c.current)},[]),{scrollAreaRef:p,onScroll:P}}function Ht(){const{userDoc:e,providerNetwork:a}=ye(),{branding:n}=ze(),o=Ue(),{openPatientProfile:x}=tt(),p=z(e==null?void 0:e.userType,"Provider"),u=z(e==null?void 0:e.userType,"Provider Network Admin"),c=z(e==null?void 0:e.userType,"Provider Delegate"),[f,P]=l.useState(0),s=()=>P(t=>t+1),{openVisitCharting:d}=Rt(),g=t=>d({visitId:t.id,chartReviewId:t.chartReviewId,seed:t,intent:p&&t.providerId===(e==null?void 0:e.id)?"chart":"view"});wt({onClose:s});const{providers:y,loading:h,error:R}=He(e==null?void 0:e.providerNetworkId),{verifiedStates:M,hasDeaLicense:A,loading:N}=bt(e==null?void 0:e.id,p),{enforceStateLicensure:U}=Pt(e==null?void 0:e.providerNetworkId,p),w=Ct(),[I,Q]=l.useState(""),[k,Z]=l.useState(ve),[v,ee]=l.useState(),[H,te]=l.useState(J),[O,Ne]=l.useState({key:"encounterMillis",direction:"desc"}),[V,q]=l.useState(null),se=yt({providerNetworkId:e==null?void 0:e.providerNetworkId,isDelegate:c,enabled:u||c,providerOptions:y,onSuccess:s}),[T,_]=l.useState(""),ie={provider:p,admin:u,delegate:c,userId:e==null?void 0:e.id},ae=()=>{Q(""),Z(ve),ee(void 0),te(J)},E=!!(I||v!=null&&v.from||Object.values(k).some(t=>t.length)||H!==J),Ce=v!=null&&v.from?new Date(v.from).setHours(0,0,0,0):void 0,be=v!=null&&v.from?new Date(v.to||v.from).setHours(23,59,59,999):void 0,{rows:L,loading:F,loadingMore:ne,error:B,filteredCount:Pe,totalCount:Me,facet_counts:re,hasMore:oe,loadMore:le,fetchAllRows:Ae,pageLatencyMs:Re}=Lt(e==null?void 0:e.providerNetworkId,f,{query:I,facets:k,from:Ce,to:be,sandbox:H===ht,sortField:O.key,sortDirection:O.direction}),ce=Ut({enabled:oe&&!F&&!B,loadedRowCount:L.length,loadingMore:ne,pageLatencyMs:Re,loadMore:le}),de=st(l.useMemo(()=>L.map(t=>t.clientId),[L])),we=l.useMemo(()=>L.map(t=>({...t,clientAccentColor:it(de,t).clientAccentColor})),[L,de]),je=t=>{var S,pe;const r=((S=re.find(m=>m.field_name===t))==null?void 0:S.counts)||[],C=t==="clientId"?"clientOption":t==="assignmentKey"?"providerOption":null,b=new Map((((pe=re.find(m=>m.field_name===C))==null?void 0:pe.counts)||[]).map(m=>JSON.parse(m.value))),j=new Map(r.map(({value:m})=>{const D=C?b.get(m)||m:t==="statusKey"?ct(m):t==="visitMode"?m==="async"?"Async":"Sync":t==="rxKey"?m==="no-rx"?"No Rx":"With Rx":m;return[m,{id:m,label:D}]}));for(const m of k[t])j.has(m)||j.set(m,{id:m,label:m});return[...j.values()].sort((m,D)=>m.label.localeCompare(D.label))},Ie=[{type:"custom",id:"sandbox",render:()=>i.jsx(vt,{scope:H,onScopeChange:te})},...Se.map(([t,r])=>({id:t,defaultLabel:r,filters:je(t),activeFilters:k[t],onFilterChange:C=>Z(b=>({...b,[t]:C})),searchable:!0})),{type:"date",id:"encounter-date",label:"Encounter date",date:v,setDate:ee}];async function $(t,r,C,b,j){_(t.id);try{const S=await Qe(r,C);if((S==null?void 0:S.success)===!1)throw new Error(S.error||"Unable to update visit. Please try again.");return X.success(b),j?j(S):s(),!0}catch(S){return X.error(S),!1}finally{_("")}}async function Te(t){_(t.id);try{const r=await Ve(Le(Ge,"Visits",t.id));if(!r.exists())throw new Error("Visit no longer exists. Refresh and try again.");q({...r.data(),id:r.id})}catch(r){X.error(r)}finally{_("")}}const Ee=t=>N?"Checking your credentialsâ¦":At(t,{providerHasDea:!!(e!=null&&e.dea||e!=null&&e.deaNumber||A),unlicensedPatientState:U&&(!t.patientState||!Mt(t.patientState,M))?t.patientState||"the patientâs state":null}),me=[{id:"name",header:"Name",sortKey:"patientName",minWidth:180,renderCell:t=>i.jsxs("div",{children:[i.jsx(et,{name:t.patientName,patientId:t.patientId,onOpen:r=>x(r,{tab:"visits"}),className:"font-medium"}),i.jsx("div",{className:"text-xs text-muted-foreground",children:t.patientState||"â"})]})},{id:"client",header:"Client",sortKey:"clientName",minWidth:130,renderCell:t=>i.jsx(It,{row:t})},{id:"product",header:"Product Purchased",sortKey:"productName",minWidth:160,renderCell:t=>i.jsx(Tt,{row:t})}
1,{id:"type",header:"Type",sortKey:"visitMode",minWidth:80,renderCell:t=>i.jsx(qe,{mode:t.visitMode})},{id:"date",header:"Encounter date",sortKey:"encounterMillis",minWidth:130,renderCell:t=>i.jsx(Et,{millis:t.encounterMillis})},{id:"provider",header:"Assigned To",sortKey:"providerName",minWidth:140,renderCell:t=>{if(!he(t,ie).assign)return t.providerName;const r={...t,assignedTo:t.providerId,assignedToName:t.providerName};return i.jsx(St,{assignment:se,form:r,loading:h,error:R?"Unable to load providers. Reload the page to retry.":"",onAssign:t.visitMode==="sync"?()=>Te(t):void 0,children:i.jsxs(K,{variant:"ghost",disabled:!!T,className:"h-auto min-h-0 gap-1.5 p-0 text-sm font-normal text-content-secondary hover:bg-transparent max-lg:text-2xs","aria-label":`${t.providerId?"Reassign":"Assign"} provider: ${t.providerName}`,children:[t.providerName,i.jsx(jt,{className:"size-3.5 shrink-0 text-content-tertiary"})]})})}},...a&&a.hideLastProviderColumn!==!0?[{id:"lastProvider",header:"Last Provider",sortKey:"patientLastProviderName",minWidth:140,renderCell:t=>t.patientLastProviderName||"â"}]:[],{id:"status",header:"Status",sortKey:"statusKey",minWidth:160,renderCell:t=>i.jsx(Vt,{row:t})},{id:"actions",header:"Actions",align:"right",minWidth:210,renderCell:t=>{const r=he(t,ie),C=r.claim?Ee(t):"";return i.jsxs("div",{className:"flex items-center justify-end gap-1.5 [&>*]:shrink-0 max-lg:flex-nowrap max-lg:gap-1",children:[!r.claim&&i.jsxs(K,{variant:"outline",size:"sm",className:Y,onClick:()=>g(t),children:[r.terminal?i.jsx(xe,{className:"size-3"}):p&&t.providerId===(e==null?void 0:e.id)?i.jsx(ue,{className:"size-3"}):i.jsx($e,{className:"size-3"}),r.terminal?"View Summary":p&&t.providerId===(e==null?void 0:e.id)?"Continue":"View"]}),r.claim&&i.jsxs(K,{size:"sm",className:Y,title:C||void 0,disabled:!!C||!!T,onClick:()=>$(t,"claimChartReview",{visitId:t.id},"Review claimed.",b=>o(`/async-visits?tab=review&visit=${encodeURIComponent(b.visitId||t.id)}`)),children:[T===t.id?i.jsx(De,{size:"xs"}):i.jsx(ue,{className:"size-3"}),"Claim"]}),r.void&&i.jsx(xt,{className:Y,disabled:!!T,loading:T===t.id,onConfirm:async b=>{if(!await $(t,"manageProviderNetworkForm",{action:"voidChartReview",visitId:t.id,...t.chartReviewId?{chartReviewId:t.chartReviewId}:{},reason:b},"Visit voided."))throw new Error("Unable to void visit. Please try again.")}}),i.jsx(gt,{borderless:!0,label:`More actions for ${t.patientName}`,actions:[r.restore?{id:"restore",label:"Move to In Progress",disabled:!!T,onSelect:()=>$(t,"manageProviderNetworkForm",{action:"resolvePendingPatientResponse",visitId:t.id,chartReviewId:t.chartReviewId},"Visit moved to In Progress.")}:null,w.messagingEnabled&&t.patientId?{id:"message-patient",label:"Message patient",disabled:!!w.busyKey,onSelect:()=>w.openPatientConversationForRecord(t)}:null,w.messagingEnabled&&t.clientId?{id:"message-client",label:"Message client group",disabled:!!w.busyKey,onSelect:()=>w.openClientConversationForRecord(t)}:null]})]})}}];return i.jsxs("div",{className:"space-y-6",children:[i.jsx(Xe,{hideTitle:!0,title:"All Visits",description:"All network encounters, ordered by encounter date."}),i.jsx(ft,{id:"all-visits-network",title:"All Visits",icon:Je,accentColor:n==null?void 0:n.accentColor,loading:F,loadingMore:ne,error:B,rows:we,onEndReached:oe&&!B?le:void 0,columns:me,windowRows:!0,stickyLastColumn:!0,className:"[&_th]:!border-r-0 [&_td]:!border-r-0 [&_th:last-child]:!border-l-0 [&_td:last-child]:!border-l-0",tableScrollRef:ce.scrollAreaRef,scrollAreaProps:{onScroll:ce.onScroll},search:{value:I,onChange:Q,placeholder:"Search patients, clients, products, or providersâ¦"},filters:Ie,hasActiveFilters:E,onClearFilters:ae,rowClick:g,rowKeyboardAccessible:!0,rowAriaLabel:t=>`Open visit for ${t.patientName}`,csvExport:{feature:"all-visits",tenantSlug:n==null?void 0:n.businessName,disabled:F||!!B,columns:[...me.filter(t=>t.sortKey).map(t=>({header:t.header,csvValue:r=>t.sortKey==="encounterMillis"?r.encounterMillis?new Date(r.encounterMillis).toISOString():"":r[t.sortKey]||""})),{header:"Prescription",csvValue:t=>t.prescriptionCreated?"With Rx":"No Rx"}],view:{getRows:Ae}},filteredCount:Pe,totalCount:Me,sortKey:O.key,sortDirection:O.direction,onSort:t=>Ne(r=>({key:t,direction:r.key===t&&r.direction==="desc"?"asc":"desc"})),actions:i.jsx(K,{variant:"outline",size:"sm",onClick:s,disabled:F,children:B?"Retry":"Refresh"}),emptyMessage:i.jsx(Ye,{reason:E?"filtered":"empty",title:E?"No matching visits":"No visits yet",description:E?"Clear filters to
1see all network visits.":"Network encounters will appear here.",action:{label:E?"Clear filters":"Refresh",onClick:E?ae:s}})}),se.dialogs,(V==null?void 0:V.visitMode)!=="async"&&V&&i.jsx(Nt,{open:!0,visit:V,providers:y,onOpenChange:t=>{t||q(null)},onSuccess:()=>{q(null),s()}})]})}function _s(){const{userDoc:e}=ye();return We(e)==="ProviderNetwork"&&["Provider","Provider Delegate","Provider Network Admin"].some(n=>z(e==null?void 0:e.userType,n))?i.jsx(Ht,{},e==null?void 0:e.providerNetworkId):i.jsx(Ze,{})}export{_s as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.