PageSourceSearch

https://care.soberpedia.ai/assets/VisitWorkspaceRoute-UsnWtNh7.js

js soberpedia.ai collected 2026-10-05 15:07:51 UTC 33,683 bytes, 1 lines download raw bytes

1import{j as e,r as c}from"./react-vendor-CU6Sz31W.js";import{ez as U,eA as oe,eB as T,sp as Le,sq as Te,kw as qe,i as P,L as B,U as M,E as z,ax as Z,c6 as de,aW as Se,g9 as se,u as ie,be as Q,c7 as H,c8 as G,c9 as Y,ca as J,cb as D,I as Ce,az as te,aA as $,a0 as Ue,aD as Fe}from"./index-DEXJEDAi.js";import{A as _e}from"./AccessDenied-Ba4b0-Uz.js";import{u as De,P as ne}from"./usePracticeRoute-BanfQY79.js";import{P as Ve}from"./patient-name-link-BAfQKbEs.js";import{u as $e}from"./useOpenPatientProfile-CASNKG5E.js";import{v as re}from"./visitPresentation-CQKFg6I_.js";import{c as A}from"./clinicalApi--8E0qkZ_.js";import{P as X}from"./PracticeFormDialog-RdnfXKaS.js";import{Q as Me}from"./quill-editor-D-DS6c39.js";import{n as ze,b as le,a as Be}from"./soapUtils-zvO4AHg3.js";import{P as Qe}from"./PracticeLabResults-D8MPDUph.js";import{a as He,b as Ge,P as Ye}from"./PracticeVideo--u4gdaPy.js";import{E as ae,A as Je}from"./chartingAttestations-B6EQggPo.js";import{P as Ke}from"./PracticeFormRenderer-C6Jj5kJp.js";import"./firebase-w6DYUbFN.js";import"./payment-icons-Daq1K3F1.js";import"./shield-alert-DjOj07_r.js";import"./text-highlight-BFqqfcjs.js";import"./use-unsaved-changes-B6nL5Xdd.js";import"./modal-form-CqN5DZuv.js";import"./editor-D8UbQKN1.js";import"./audio-lines-GJL3_Ka2.js";import"./square-D7DkS8S2.js";import"./link-2-a8lhpkQ6.js";import"./code-BEcI87AG.js";import"./strikethrough-CiKozLGy.js";import"./underline-B_XtWKJP.js";import"./list-ordered-GNrnoOhB.js";import"./api-DkVW0jWd.js";const We=[["allergies","Allergies"],["current_medications","Current medications"],["medical_conditions","Medical conditions"],["surgical_history","Surgical history"]];function Ne({patient:s}){var r;const{openPatientProfile:a,buildPatientProfileHref:t}=$e();return e.jsx(U,{title:"Patient",children:e.jsxs(oe,{children:[e.jsx(T,{label:"Patient",children:e.jsx(Ve,{patientId:s.id,name:s.fullName||[s.firstName,s.lastName].filter(Boolean).join(" "),href:t(s.id),onOpen:a})}),e.jsx(T,{label:"Date of birth",children:s.dateOfBirth}),e.jsx(T,{label:"Email",children:s.email}),e.jsx(T,{label:"State",children:((r=s.address)==null?void 0:r.state)||s.state}),e.jsx(T,{label:"Sex at birth",children:s.sexAtBirth||s.sexAssignedAtBirth}),We.map(([i,n])=>e.jsx(T,{label:n,children:Le(i,Te({type:"patient_data_field",patientDataTarget:i},s)||qe(i,s))||"Not recorded"},i))]})})}function Ze({practiceId:s,visitId:a,busy:t,onPendingChange:r,onDraft:i}){const[n,l]=c.useState(""),[h,d]=c.useState(!1),[f,v]=c.useState(null),[R,N]=c.useState(""),p=c.useRef(null);async function k(j){var I;if(h||t)return;const b=JSON.stringify([j,n]);((I=p.current)==null?void 0:I.fingerprint)!==b&&(p.current={fingerprint:b,requestId:crypto.randomUUID()}),d(!0),r(!0),N("");let E=!1;try{const u=await A(s,`/${encodeURIComponent(a)}/assistance`,{body:{requestId:p.current.requestId,mode:j,...j==="assistant"?{question:n}:{}}});v(u),E=!0}catch(u){N(u.message),p.current=null}finally{d(!1),E||r(!1)}}function g(){v(null),r(!1),p.current=null}return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-3 border-b border-border pb-4","aria-label":"Clinical assistance",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Clinical assistance"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generate from the saved encounter. Review the draft before applying it to your notes."}),e.jsx(P,{type:"button",variant:"outline",disabled:t||h,onClick:()=>k("soap"),children:h?"Generating…":"Generate SOAP draft"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"practice-visit-question",children:"Ask about this encounter"}),e.jsx(M,{id:"practice-visit-question",value:n,maxLength:4e3,disabled:t||h,onChange:j=>l(j.target.value)}),e.jsx(P,{type:"button",variant:"outline",disabled:t||h||!n.trim(),onClick:()=>k("assistant"),children:"Ask clinical assistant"})]}),R&&e.jsx(z,{reason:"error",title:"Unable to generate assistance",description:R,action:null})]}),f&&e.jsx(Z,{open:!0,size:"lg",title:f.soapNotes?"Review SOAP draft":"Visit assistance",description:"Review against the patient’s chart before using this clinical draft.",mobileStickyFooter:!0,onOpenChange:j=>{j||g()},footer:e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"outline",onClick:g,children:"Close"}),f.soapNotes&&e.jsx(P,{onClick:()=>{i(f.soapNotes),g()},children:"Use draft in editor"})]}),children:e.jsx(de,{children:f.soapNotes?Object.entries(f.soapNotes).map(([j,b])=>e.jsx(U,{title:j,children:e.jsx("div",{className:"prose prose-sm max-w-none text-foreground dark:prose-invert",dangerouslySetInnerHTML:{__html:Se(b)}
1})},j)):e.jsx(U,{title:"Response",children:e.jsx("p",{className:"whitespace-pre-wrap break-words text-sm",children:f.answer})})})})]})}const ue=[["providerPrivateNotes","Internal provider notes"],["assessmentNotes","Assessment notes"],["additionalProviderNotes","Additional provider notes"]],W=[...le.map(s=>[s,Be[s]]),...ue],ee=s=>{const a=s.review||s.visit;return{...ze(a.soapNotes,""),...Object.fromEntries(ue.map(([t])=>{var r;return[t,(t==="providerPrivateNotes"?(r=s.privateNotes)==null?void 0:r.providerPrivateNotes:a[t])||""]}))}};function Xe({label:s,value:a,onChange:t,readOnly:r}){return e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s}),e.jsx(Me,{editorLabel:s,value:a,onChange:t,readOnly:r,placeholder:s})]})}function Pe({value:s}){return s?e.jsx("div",{className:"prose prose-sm max-w-none break-words text-foreground dark:prose-invert",dangerouslySetInnerHTML:{__html:Se(s)}}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No notes saved."})}function Re({data:s,onEdit:a}){var r,i,n;const t=ee(s);return e.jsx(U,{title:"Chart notes",actions:((r=s.notesAccess)==null?void 0:r.canEdit)&&e.jsx(P,{variant:"outline",size:"sm",onClick:a,children:"Edit notes"}),children:e.jsxs("div",{className:"space-y-4",children:[W.filter(([l])=>t[l]).map(([l,h])=>e.jsx(T,{label:h,children:e.jsx(Pe,{value:t[l]})},l)),!W.some(([l])=>t[l])&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No chart notes have been saved."}),!((i=s.notesAccess)!=null&&i.canEdit)&&e.jsx("p",{className:"text-sm text-muted-foreground",children:(n=s.notesAccess)==null?void 0:n.reason})]})})}function es({practiceId:s,visitId:a,data:t,onSaved:r,onClose:i}){const[n]=c.useState(()=>ee(t)),l=c.useRef(n),h=c.useRef(t.notesAccess.revision),d=c.useRef(typeof(t.review||t.visit).soapNotes=="string"),f=c.useRef(null),[v,R]=c.useState(null),[N,p]=c.useState(!1),[k,g]=c.useState(!1),[j,b]=c.useState(""),E=`/${encodeURIComponent(a)}`;async function I(){p(!0),b("");try{R(await A(s,E))}catch(o){b(o.message)}finally{p(!1)}}async function u(o){var F;if(v)throw new Error("Review the latest saved notes before saving your edits.");const m=Object.fromEntries(W.filter(([C])=>o[C]!==n[C]).map(([C])=>[C,o[C]]));if(!Object.keys(m).length)return;const y=le.some(C=>Object.hasOwn(m,C)),L=Object.fromEntries(le.filter(C=>y&&(d.current||Object.hasOwn(m,C))).map(C=>[C,Object.hasOwn(m,C)?o[C]:l.current[C]])),x={...Object.fromEntries(ue.filter(([C])=>Object.hasOwn(m,C)).map(([C])=>[C,m[C]])),...Object.keys(L).length?{soapNotes:L}:{}},S=JSON.stringify([h.current,x]);((F=f.current)==null?void 0:F.fingerprint)!==S&&(f.current={fingerprint:S,requestId:crypto.randomUUID()});try{await A(s,`${E}/notes`,{body:{revision:h.current,requestId:f.current.requestId,patch:x}})}catch(C){throw C.status===409&&await I(),C}const q=await A(s,E);r(q),se.success("Chart notes saved")}return e.jsx(X,{title:"Edit chart notes",description:"Save clinical notes for this visit.",initial:n,pending:N||k,onSave:u,onClose:i,saveLabel:"Save notes",children:(o,m,y)=>{var L,x;return e.jsxs(e.Fragment,{children:[e.jsx(Ze,{practiceId:s,visitId:a,busy:y,onPendingChange:g,onDraft:S=>{for(const[q,F]of Object.entries(S))m(q,F)}}),W.map(([S,q])=>e.jsx(Xe,{label:q,value:o[S],onChange:F=>m(S,F),readOnly:y},S)),v&&e.jsxs("section",{"aria-label":"Latest saved notes",className:"space-y-4 border-t border-border pt-4",children:[e.jsx("h3",{className:"font-medium",children:"Notes changed while you were editing"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your draft is above. Compare the latest saved version of each section you edited below. Saving again will replace only your edited sections."}),W.filter(([S])=>o[S]!==n[S]).map(([S,q])=>e.jsx(T,{label:q,children:e.jsx(Pe,{value:ee(v)[S]})},S)),(L=v.notesAccess)!=null&&L.canEdit?e.jsx(P,{type:"button",variant:"outline",onClick:()=>{h.current=v.notesAccess.revision,l.current=ee(v),d.current=typeof(v.review||v.visit).soapNotes=="string",f.current=null,R(null)},children:"I reviewed the latest notes; keep my edits"}):e.jsx("p",{className:"text-sm text-status-danger",children:(x=v.notesAccess)==null?void 0:x.reason}),e.jsx(P,{type:"button",variant:"ghost",onClick:I,children:"Refresh latest notes"})]}),j&&e.jsxs("div",{role:"alert",className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-status-danger",children:j}),e.jsx(P,{type:"button",variant:"outline",onClick:I,children:"Load latest notes"})]})]})}})}function ss({practiceId:s,visitId:a,data:t,onSaved:r,onBusyChange:i}){var I,u;const{userDoc:n}=ie(),[l,h]=c.useState(null),[d,f]=c.useState(!1),[v,R]=c.useState(""),[N,p]=c.useState("");
1if(![t.visit,t.review,t.order].filter(Boolean).some(o=>{var m;return o.requiresLabs||((m=o.labRequirement)==null?void 0:m.required)}))return null;const g=((I=t.review)==null?void 0:I.labRequirement)||t.visit.labRequirement||((u=t.order)==null?void 0:u.labRequirement),j=Q(n==null?void 0:n.userType,"Practice Provider")&&t.visit.providerId===(n==null?void 0:n.id);async function b(){f(!0),R(""),i(!0);try{const o=await A(s,`/${encodeURIComponent(a)}/lab-results`);h(o.results),p(crypto.randomUUID())}catch(o){R(o.message),i(!1)}finally{f(!1)}}function E(){h(null),i(!1)}return e.jsxs(U,{title:"Required laboratory review",actions:j&&e.jsx(P,{variant:"outline",size:"sm",disabled:d,onClick:b,children:"Review lab results"}),children:[e.jsx("p",{className:"text-sm",children:(g==null?void 0:g.status)==="satisfied"?"A provider qualified a laboratory report. Current results and protocol requirements are checked again before approval and prescribing.":"A provider must qualify the required laboratory results before approval."}),v&&e.jsx("p",{role:"alert",className:"text-sm text-status-danger",children:v}),l&&e.jsx(X,{title:"Qualify laboratory results",description:"Review the original laboratory report and confirm its specimen or result date. Qualification does not approve treatment.",initial:{orderId:"",resultDate:"",reviewed:!1},onClose:E,saveLabel:"Qualify results",onSave:async o=>{const m=l.find(y=>y.orderId===o.orderId);if(!m)throw Error("Choose a laboratory result");await A(s,`/${encodeURIComponent(a)}/lab-clearance`,{body:{requestId:N,labOrderId:m.orderId,resultRevision:m.resultRevision,resultDate:new Date(o.resultDate).toISOString(),reviewed:o.reviewed}}),r(await A(s,`/${encodeURIComponent(a)}`))},children:(o,m)=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"practice-lab-result",children:"Laboratory report"}),e.jsxs(H,{value:o.orderId,onValueChange:y=>{m("orderId",y),m("reviewed",!1)},children:[e.jsx(G,{id:"practice-lab-result",children:e.jsx(Y,{placeholder:"Choose a report"})}),e.jsx(J,{children:l.map(y=>e.jsx(D,{value:y.orderId,children:y.productName},y.orderId))})]}),!l.length&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No completed, paid laboratory results are available for this patient."})]}),o.orderId&&e.jsx(Qe,{practiceId:s,orderId:o.orderId}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(B,{htmlFor:"practice-lab-date",children:["Report specimen or result date (",Intl.DateTimeFormat().resolvedOptions().timeZone,")"]}),e.jsx(Ce,{id:"practice-lab-date",type:"datetime-local",required:!0,value:o.resultDate,onChange:y=>{m("resultDate",y.target.value),m("reviewed",!1)}})]}),e.jsxs("label",{htmlFor:"practice-lab-reviewed",className:"flex items-start gap-2 text-sm",children:[e.jsx(te,{id:"practice-lab-reviewed",checked:o.reviewed,onCheckedChange:y=>m("reviewed",y===!0)}),"I reviewed the original report, verified the date, and confirm it meets this encounter’s laboratory requirements."]})]})})]})}function ts({practiceId:s,visitId:a,data:t,onSaved:r,onBusyChange:i}){const{userDoc:n}=ie(),[l,h]=c.useState(null),[d,f]=c.useState(!1),[v,R]=c.useState(""),N=t.visit.providerId;if(t.visit.visitMode!=="async"||["completed","cancelled","voided"].includes(String(t.visit.status).toLowerCase())||!(Q(n==null?void 0:n.userType,"Practice Admin")||Q(n==null?void 0:n.userType,"Practice Provider")&&N===(n==null?void 0:n.id)))return null;async function p(){f(!0),R(""),i(!0);try{const g=await A(s,`/${encodeURIComponent(a)}/escalation-providers`);h(g.providers.filter(j=>j.id!==N))}catch(g){R(g.message),i(!1)}finally{f(!1)}}function k(){h(null),i(!1)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{variant:"outline",disabled:d,onClick:p,children:"Escalate to MD"}),v&&e.jsx("p",{role:"alert",className:"text-sm text-status-danger",children:v}),l&&e.jsx(X,{title:"Escalate to MD",description:"Hand this review to a licensed Practice physician without recording a decision.",initial:{providerId:"",note:""},onClose:k,saveLabel:"Escalate review",onSave:async g=>{await A(s,`/${encodeURIComponent(a)}/escalate`,{body:{...g,revision:t.visit.assignmentRevision||0}}),r(await A(s,`/${encodeURIComponent(a)}`))},children:(g,j)=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"practice-escalation-provider",children:"Physician"}),e.jsxs(H,{value:g.providerId,onValueChange:b=>j("providerId",b),children:[e.jsx(G,{id:"practice-escalation-provider",children:e.jsx(Y,{placeholder:"Choose a physician"})}),e.jsx(J,{children:l.map(b=>e.jsx(D,{value:b.id,children:b.name},b.id))})]}),!l.length&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No eligible physicians are available in this Practice."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"practice-escalation-note",children:"Clinical handoff note"}),e.jsx(M,{id:"practice-escalation-note",required:!0,maxLength:4e3,value:g.note,onChange:b=>j("note",b.target.value)})]})]})})]})}function rs({practiceId:s,visitId:a,data:t,onBusyChange:r}){var u;const{userDoc:i}=ie(),[n,l]=c.useState(!1),[h,d]=c.useState(""),[f,v]=c.useState(null),R=c.useRef(crypto.randomUUID()),N=c.useRef(!1),p=t.order,k=(p==null?void 0:p.cancellationReviewRequired)||["on_hold","pending_cancellation_review","cancelled","canceled","voided"].includes(String(p==null?void 0:p.status).toLowerCase())||["refunded","voided"].includes(String(p==null?void 0:p.paymentStatus).toLowerCase())||[p==null?void 0:p.refundStatus,p==null?void 0:p.parentRefundStatus].some(o=>["processing","unknown","pending","succeeded"].includes(String(o).toLowerCase())),g=(p==null?void 0:p.workflowKind)==="practice_lab_first"&&p.paymentStatus!=="paid",j=t.visit.reviewPurpose==="product_approval_only"||((u=t.review)==null?void 0:u.reviewPurpose)==="product_approval_only",b=Q(i==null?void 0:i.userType,"Practice Provider")&&t.visit.providerId===(i==null?void 0:i.id)&&t.visit.approvalStatus==="approved"&&!k&&!g&&!j;
1async function E(){if(N.current)return;N.current=!0,l(!0),r(!0),d("");let o=!1;try{const m=await A(s,`/${encodeURIComponent(a)}/prescribing`,{body:{requestId:R.current,darkMode:document.querySelector('[data-client-theme="dark"]')?"on":"off"}}),y=new URL(m.url);if(y.protocol!=="https:"||!["ssu.scriptsure.com","app.scriptsure.com"].includes(y.hostname))throw new Error("The prescribing session returned an unsupported address. Contact your Practice administrator.");v(m),o=!0}catch(m){d(m.message)}finally{N.current=!1,l(!1),o||r(!1)}}function I(){v(null),r(!1)}return e.jsxs(e.Fragment,{children:[e.jsxs(U,{title:"Prescribing",actions:b&&e.jsx(P,{variant:"outline",size:"sm",disabled:n,onClick:E,children:n?"Preparing prescribing…":"Prescribe with ScriptSure"}),children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:b?"Open the patient’s secure prescribing chart. Prescription status returns here after the pharmacy submission is recorded.":j?"This review authorizes product access only.":g?"The patient must pay for the approved treatment before prescribing.":k?"Resolve the order hold, cancellation review, or refund before prescribing.":"The assigned Practice Provider can prescribe after approving the clinical review and resolving order holds."}),h&&e.jsx(z,{reason:"error",title:"Unable to open prescribing",description:h,action:e.jsx(P,{variant:"outline",disabled:n,onClick:E,children:"Try again"})})]}),f&&e.jsx(Z,{open:!0,size:"full",title:"ScriptSure prescribing",description:"Prescribe for the patient in this Practice.",mobileFullHeight:!0,mobileStickyFooter:!0,contentClassName:"h-full",bodyClassName:"flex min-h-0 flex-1 flex-col p-0",onOpenChange:o=>{o||I()},footer:e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"outline",asChild:!0,children:e.jsx("a",{href:f.url,target:"_blank",rel:"noopener noreferrer",children:"Open in new tab"})}),e.jsx(P,{variant:"outline",onClick:I,children:"Close"})]}),children:e.jsx("iframe",{title:"Practice patient prescribing chart",src:f.url,className:"min-h-0 w-full flex-1 border-0",referrerPolicy:"no-referrer"})})]})}function is({questions:s=[],answers:a,onChange:t}){return s.filter(r=>r.enabled!==!1).map(r=>{const i=`practice-decision-question-${r.id}`,n=a[r.id],l=d=>t({...a,[r.id]:d}),h=`${r.label}${r.required?" (required)":""}`;return e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:i,children:h}),r.type==="acknowledgment"?e.jsx(te,{id:i,"aria-label":h,checked:n===!0,onCheckedChange:d=>l(d===!0)}):r.type==="multi_select"?e.jsxs("fieldset",{className:"space-y-2",children:[e.jsx("legend",{className:"sr-only",children:h}),r.options.map(d=>e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(te,{checked:Array.isArray(n)&&n.includes(d.value),onCheckedChange:f=>l(f?[...n||[],d.value]:(n||[]).filter(v=>v!==d.value))}),d.label]},d.value))]}):["yes_no","single_select"].includes(r.type)?e.jsxs(H,{value:n||"",onValueChange:l,children:[e.jsx(G,{id:i,children:e.jsx(Y,{placeholder:"Choose an answer"})}),e.jsx(J,{children:(r.type==="yes_no"?[{value:"yes",label:"Yes"},{value:"no",label:"No"}]:r.options).map(d=>e.jsx(D,{value:d.value,children:d.label},d.value))})]}):r.type==="long_text"?e.jsx(M,{id:i,required:r.required,value:n||"",maxLength:5e3,onChange:d=>l(d.target.value)}):e.jsx(Ce,{id:i,required:r.required,value:n||"",maxLength:1e3,onChange:d=>l(d.target.value)})]},r.id)})}const ce=s=>s.formName||s.formTitle||"Submitted intake";function Ae({submissions:s,onOpen:a}){return e.jsx(U,{title:"Intake forms",children:s.length?e.jsx("ul",{className:"divide-y divide-border",children:s.map(t=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-3 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"break-words text-sm font-medium",children:ce(t)}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[re(t.status||"Submitted"),t.formVersion?` · Version ${t.formVersion}`:"",t.reviewStatus&&t.reviewStatus!=="not_required"?` · Review ${re(t.reviewStatus).toLowerCase()}`:""]})]}),e.jsx(P,{variant:"outline",size:"sm","aria-label":`View answers: ${ce(t)}`,onClick:()=>a(t),children:"View answers"})]},t.id))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No intake forms are linked to this visit."})})}function ke({submission:s,onClose:a}){var t,r;return e.jsx(Z,{open:!0,size:"xl",title:ce(s),description:"The questions and answers saved with this submission.",mobileStickyFooter:!0,onOpenChange:i=>{i||a()},footer:e.jsx(P,{variant:"outline",onClick:a,children:"Close answers"}),children:e.jsxs(de,{className:"space-y-4",children:[s.disqualified&&e.jsx("p",{role:"status",className:"text-sm text-status-danger",children:"This submission did not meet the form’s eligibility criteria."}),(r=(t=s.formSnapshot)==null?void 0:t.sections)!=null&&r.length?e.jsx(Ke,{form:s.formSnapshot,responses:s.responses||{},userDoc:{},readOnly:!0,layoutVariant:"embedded-flat"}):e.jsx(z,{reason:"error",title:"Saved form unavailable",description:"The original questions are missing from this submission. Contact your Practice administrator to recover the saved form before using these answers for a clinical decision."})]})})}const ns=[["information_required","More information needed"],["follow_up_required","Follow-up needed"],["additional_review","Additional review needed"],["prescription_clarification","Prescription clarification"],["other","Other clinical reason"]];function as({data:s,onEdit:a}){var r,i,n,l,h;const t=s.review||s.visit;return e.jsx(U,{title:"Clinical decision",actions:((r=s.decisionAccess)==null?void 0:r.canDecide)&&e.jsx(P,{variant:"outline",size:"sm",onClick:a,children:t.approvalStatus?"Change decision":"Record decision"}),children:e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsx("p",{children:t.approvalStatus?re(t.approvalStatus):"Awaiting provider review"}),t.approvalStatus==="denied"&&e.jsx("p",{className:"whitespace-pre-wrap break-words",children:t.denialReason}),t.approvalStatus==="deferred"&&e.jsx("p",{className:"whitespace-pre-wrap break-words",children:t.deferReasonPatientMessage||t.deferReason}),t.approvalStatus==="deferred"&&((i=s.privateNotes)==null?void 0:i.deferReasonInternalNote)&&e.jsxs("p",{className:"whitespace-pre-wrap break-words",children:[e.jsx("span",{className:"font-medium",children:"Internal 
1clinical note: "}),s.privateNotes.deferReasonInternalNote]}),(n=t.decisionQuestionAnswers)==null?void 0:n.map(d=>e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:d.label}),e.jsx("p",{className:"whitespace-pre-wrap",children:d.type==="acknowledgment"?"Acknowledged":(Array.isArray(d.value)?d.value:[d.value]).map(f=>{var v,R;return((R=(v=d.options)==null?void 0:v.find(N=>N.value===f))==null?void 0:R.label)||String(f)}).join(", ")})]},d.questionId)),!((l=s.decisionAccess)!=null&&l.canDecide)&&e.jsx("p",{className:"text-muted-foreground",children:(h=s.decisionAccess)==null?void 0:h.reason})]})})}function os({practiceId:s,visitId:a,data:t,onSaved:r,onClose:i}){const[n]=c.useState({decision:"approved",answers:{},denialReason:"",deferReasonCode:"",deferReasonPatientMessage:"",deferReasonInternalNote:"",attestations:{...ae}}),[l,h]=c.useState(t),[d,f]=c.useState(!1),[v,R]=c.useState(!1),[N,p]=c.useState(""),[k,g]=c.useState(null),j=c.useRef(null),b=`/${encodeURIComponent(a)}`;async function E(u){R(!0),p("");try{const o=await A(s,b);h(o),r(o),f(!1),j.current=null,u("attestations",{...ae}),u("answers",{})}catch(o){p(o.message)}finally{R(!1)}}async function I(u){var L,x,S;if(d)throw new Error("Reload and review the latest chart before signing.");if(!((L=l.decisionAccess)!=null&&L.canDecide))throw new Error(((x=l.decisionAccess)==null?void 0:x.reason)||"Clinical signing is unavailable.");const o={answers:u.answers,decision:u.decision,attestations:u.attestations,revision:l.decisionAccess.revision,reviewToken:l.decisionAccess.reviewToken,...u.decision==="denied"?{denialReason:u.denialReason}:{},...u.decision==="deferred"?{deferReasonCode:u.deferReasonCode,deferReasonPatientMessage:u.deferReasonPatientMessage,deferReasonInternalNote:u.deferReasonInternalNote}:{}},m=JSON.stringify(o);((S=j.current)==null?void 0:S.fingerprint)!==m&&(j.current={fingerprint:m,requestId:crypto.randomUUID()});try{await A(s,`${b}/decision`,{body:{...o,requestId:j.current.requestId}})}catch(q){throw q.status===409&&f(!0),q}const y=await A(s,b);r(y),se.success("Clinical decision recorded")}return e.jsxs(e.Fragment,{children:[e.jsx(X,{title:"Record clinical decision",description:"Review the chart and sign as the provider of record.",initial:n,pending:v||!!k,onSave:I,onClose:i,saveLabel:"Sign decision",children:(u,o)=>{var m,y,L;return e.jsxs(e.Fragment,{children:[e.jsx(Ne,{patient:l.patient}),e.jsx(Re,{data:{...l,notesAccess:{canEdit:!1}}}),e.jsx(Ae,{submissions:l.submissions,onOpen:g}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{htmlFor:"practice-decision",children:"Decision"}),e.jsxs(H,{value:u.decision,onValueChange:x=>{o("decision",x),o("attestations",{...ae})},children:[e.jsx(G,{id:"practice-decision",children:e.jsx(Y,{})}),e.jsxs(J,{children:[e.jsx(D,{value:"approved",children:"Approve"}),e.jsx(D,{value:"denied",children:"Deny"}),e.jsx(D,{value:"deferred",children:"Defer"})]})]})]}),u.decision==="approved"&&((y=(m=l.decisionAccess)==null?void 0:m.approvalBlockers)==null?void 0:y.length)>0&&e.jsx("ul",{className:"list-disc space-y-1 pl-5 text-sm text-status-danger",children:l.decisionAccess.approvalBlockers.map(x=>e.jsx("li",{children:x},x))}),u.decision==="denied"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{htmlFor:"practice-denial",children:"Reason for denial"}),e.jsx(M,{id:"practice-denial",required:!0,maxLength:4e3,value:u.denialReason,onChange:x=>o("denialReason",x.target.value)}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Use language suitable for the patient’s care record."})]}),u.decision==="deferred"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{htmlFor:"practice-defer-reason",children:"Reason for deferral"}),e.jsxs(H,{value:u.deferReasonCode,onValueChange:x=>o("deferReasonCode",x),children:[e.jsx(G,{id:"practice-defer-reason",children:e.jsx(Y,{placeholder:"Choose a clinical reason"})}),e.jsx(J,{children:ns.map(([x,S])=>e.jsx(D,{value:x,children:S},x))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{htmlFor:"practice-patient-instructions",children:"Patient explanation and next step"}),e.jsx(M,{id:"practice-patient-instructions",required:!0,maxLength:4e3,value:u.deferReasonPatientMessage,onChange:x=>o("deferReasonPatientMessage",x.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{optional:!0,htmlFor:"practice-internal-reason",children:"Internal 
1clinical note"}),e.jsx(M,{id:"practice-internal-reason",maxLength:2e3,value:u.deferReasonInternalNote,onChange:x=>o("deferReasonInternalNote",x.target.value)}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Visible only to Practice providers and administrators."})]})]}),e.jsx(is,{questions:(L=l.workflow)==null?void 0:L.decisionQuestions,answers:u.answers,onChange:x=>o("answers",x)}),e.jsxs("fieldset",{className:"space-y-3",children:[e.jsx("legend",{className:"mb-3 text-sm font-medium",children:"Provider attestations"}),Je.filter(x=>u.decision==="approved"||x.key!=="goodFaithExam").map(x=>e.jsxs("label",{className:"flex items-start gap-3 text-sm",children:[e.jsx(te,{"aria-label":x.ariaLabel,checked:u.attestations[x.key],onCheckedChange:S=>o("attestations",{...u.attestations,[x.key]:S===!0})}),e.jsx("span",{children:x.label})]},x.key))]}),d&&e.jsx("p",{role:"alert",className:"text-sm text-status-danger",children:"The record changed or a requirement is incomplete. Your draft is retained. Reload the latest chart, review its notes and intake, then attest again."}),N&&e.jsx("p",{role:"alert",className:"text-sm text-status-danger",children:N}),e.jsx(P,{type:"button",variant:"outline",onClick:()=>E(o),children:"Reload latest chart"})]})}}),k&&e.jsx(ke,{submission:k,onClose:()=>g(null)})]})}function ls({practiceId:s,visitId:a,onClose:t}){var fe,je,ge,be,ye,we;const{userDoc:r}=ie(),[i,n]=c.useState(null),[l,h]=c.useState(""),[d,f]=c.useState(0),[v,R]=c.useState(null),[N,p]=c.useState(!1),[k,g]=c.useState(!1),[j,b]=c.useState(!1),[E,I]=c.useState(null),[u,o]=c.useState(!1),[m,y]=c.useState(!1),[L,x]=c.useState(!1),[S,q]=c.useState(!1),[F,C]=c.useState(!1),[K,pe]=c.useState(!1),[he,Ee]=c.useState(!1),[me,xe]=c.useState("");async function ve(){pe(!0),xe("");try{await A(s,`/${encodeURIComponent(a)}/start`,{body:{requestId:crypto.randomUUID(),assignmentRevision:i.visit.assignmentRevision||0}}),n(await A(s,`/${encodeURIComponent(a)}`)),se.success("Visit started")}catch(w){xe(w.message)}finally{pe(!1)}}c.useEffect(()=>{const w=new AbortController;return n(null),h(""),A(s,`/${encodeURIComponent(a)}`,{signal:w.signal}).then(_=>{w.signal.aborted||n(_)}).catch(_=>{w.signal.aborted||h(_.message)}),()=>w.abort()},[s,a,d]);async function Ie(){p(!0),h("");try{const w=await A(s,`/${encodeURIComponent(a)}/providers`),_=Q(r==null?void 0:r.userType,"Practice Provider")?w.providers.filter(V=>V.id===r.id):w.providers;R(_)}catch(w){h(w.message)}finally{p(!1)}}const O=i==null?void 0:i.visit,Oe=["completed","complete","cancelled","canceled","voided","denied","approved"].includes(String((O==null?void 0:O.status)||"").toLowerCase());return e.jsxs(e.Fragment,{children:[e.jsx(Z,{open:!0,size:"xl",title:"Practice visit",description:"Patient context, intake answers, and chart notes.",mobileStickyFooter:!0,onOpenChange:w=>{!w&&!u&&!m&&!L&&!S&&!F&&!N&&!K&&!he&&!k&&!v&&!E&&!j&&t()},footer:e.jsx(P,{variant:"outline",disabled:u||m||L||S||F||N||K||he,onClick:t,children:"Close"}),children:e.jsxs(de,{children:[l&&e.jsx(z,{reason:"error",title:"Unable to load visit details",description:l,action:e.jsx(P,{onClick:()=>f(w=>w+1),children:"Try again"})}),!i&&!l&&e.jsx(Ue,{className:"h-48 w-full"}),i&&e.jsxs("div",{className:"divide-y divide-border",children:[e.jsx(U,{title:"Encounter",actions:!Oe&&e.jsx(P,{variant:"outline",size:"sm",disabled:N,onClick:Ie,children:N?"Loading providers…":"Assign provider"}),children:e.jsxs(oe,{children:[e.jsx(T,{label:"Status",children:re(O.status)}),e.jsx(T,{label:"Assigned to",children:O.providerName||"Unassigned"}),e.jsx(T,{label:"Service",children:O.productName||((fe=i.order)==null?void 0:fe.productName)||"Visit"}),e.jsx(T,{label:"Mode",children:O.visitMode||"sync"})]})}),((je=i.productGuidance)==null?void 0:je.length)>0&&e.jsx(U,{title:"Clinical product guidance",description:"Current instructions from the Practice product catalog.",children:e.jsx(oe,{columns:1,children:i.productGuidance.map(w=>e.jsx(T,{label:w.name,children:e.jsx("p",{className:"whitespace-pre-wrap break-words leading-relaxed",children:w.unavailable?"This product is unavailable. Ask a Practice administrator to verify its clinical instructions before proceeding.":w.productNotesDisclaimer})},w.productId))})}),O.visitMode==="sync"&&e.jsxs(U,{title:"Live visit",actions:((ge=i.lifecycleAccess)==null?void 0:ge.canStart)&&e.jsx(P,{variant:"outline",size:"sm",disabled:K,onClick:ve,children:K?"Starting…":"Start visit"}),children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:(be=i.lifecycleAccess)!=null&&be.started?"This visit is in progress. Record the clinical decision when the consultation is complete.":((ye
1=i.lifecycleAccess)==null?void 0:ye.reason)||"Start the scheduled consultation to record its clinical decision."}),me&&e.jsx(z,{reason:"error",title:"Unable to start visit",description:me,action:e.jsx(P,{variant:"outline",disabled:K,onClick:ve,children:"Try again"})})]}),e.jsx(Ne,{patient:i.patient}),e.jsx(Ae,{submissions:i.submissions,onOpen:I}),e.jsx(Re,{data:i,onEdit:()=>g(!0)}),i.escalationNote&&e.jsx(U,{title:"Clinical handoff",children:e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:i.escalationNote})}),e.jsx(He,{canChange:((we=i.lifecycleAccess)==null?void 0:we.canChangeAppointment)===!0,practiceId:s,visit:O,onBusyChange:y,onSaved:async()=>n(await A(s,`/${encodeURIComponent(a)}`))}),(!Q(r==null?void 0:r.userType,"Practice Provider")||O.providerId===(r==null?void 0:r.id))&&e.jsx(Ge,{practiceId:s,source:O,onBusyChange:x}),e.jsx(ts,{practiceId:s,visitId:a,data:i,onSaved:n,onBusyChange:q}),e.jsx(ss,{practiceId:s,visitId:a,data:i,onSaved:n,onBusyChange:o}),e.jsx(as,{data:i,onEdit:()=>b(!0)}),O.visitMode==="sync"&&O.providerId===(r==null?void 0:r.id)&&["confirmed","in progress"].includes(String(O.status).toLowerCase())&&e.jsx(Ye,{practiceId:s,visitId:a,onBusyChange:C}),e.jsx(rs,{practiceId:s,visitId:a,data:i,onBusyChange:Ee},a)]})]})}),j&&e.jsx(os,{practiceId:s,visitId:a,data:i,onSaved:n,onClose:()=>b(!1)}),E&&e.jsx(ke,{submission:E,onClose:()=>I(null)}),k&&e.jsx(es,{practiceId:s,visitId:a,data:i,onSaved:n,onClose:()=>g(!1)}),v&&e.jsx(X,{title:"Assign provider",description:"Choose an eligible provider in this Practice.",initial:{providerId:""},onClose:()=>R(null),saveLabel:"Assign provider",onSave:async w=>{if(!w.providerId)throw new Error("Choose a provider to continue.");await A(s,`/${encodeURIComponent(a)}/assignment`,{body:{providerId:w.providerId,revision:O.assignmentRevision||0}});const _=await A(s,`/${encodeURIComponent(a)}`);n(_),se.success("Provider assigned")},children:(w,_)=>e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{htmlFor:"visit-provider",children:"Provider"}),v.length?e.jsxs(H,{value:w.providerId,onValueChange:V=>_("providerId",V),children:[e.jsx(G,{id:"visit-provider",children:e.jsx(Y,{placeholder:"Choose a provider"})}),e.jsx(J,{children:v.map(V=>e.jsx(D,{value:V.id,children:V.name||"Provider"},V.id))})]}):e.jsx(z,{reason:"empty",title:"No eligible providers",description:"Check provider onboarding, state licenses, and the Practice’s clinical policies."})]})})]})}function Ds(){const[s,a]=Fe(),{role:t,practiceId:r}=De(),i=s.get("visit"),n=()=>a(l=>{const h=new URLSearchParams(l);return h.delete("visit"),h},{replace:!0});return i?[ne.ADMIN,ne.PROVIDER,ne.DELEGATE].includes(t)?e.jsx(ls,{practiceId:r,visitId:i,onClose:n},`${r}:${i}`):e.jsx(Z,{open:!0,title:"Practice visit",onOpenChange:l=>{l||n()},children:e.jsx(_e,{subject:"clinical visits"})}):null}export{Ds 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.