PageSourceSearch

https://mymgconnect.com/assets/PrepareAppointment-eP7MZU1A.js

js mymgconnect.com collected 2026-09-24 14:48:56 UTC 36,242 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DRQAaCbt.js","assets/vendor-react-CoJda1Bd.js","assets/vendor-radix-I618Mglk.js","assets/vendor-supabase-BI1TbgRl.js","assets/vendor-charts-Df9hQbmF.js","assets/vendor-icons-BbhXjgy5.js","assets/vendor-query-_n4XbDCE.js","assets/vendor-router-BG1ccVOB.js","assets/vendor-date-Ctl2uRge.js","assets/index-CHjfJmCN.css"])))=>i.map(i=>d[i]);
2import{s as l,u as U,_ as ye}from"./index-DRQAaCbt.js";import{r as i,j as e}from"./vendor-react-CoJda1Bd.js";import{L as re,a as Me,d as Ke}from"./vendor-router-BG1ccVOB.js";import{r as et,a as tt}from"./sinceLastVisitAnchor-Il07-Rd-.js";import{b as je,i as st,j as at}from"./mgAdlSeries-DxD0rQDu.js";import{r as rt,x as it,V as nt,u as ot,y as ct,z as lt}from"./VoiceEntryRecorder-Dv8acccw.js";import{L as we}from"./Layout-DJPFJEnW.js";import{u as dt,P as mt}from"./PortalBottomNav-C8v4d43x.js";import{B as Y}from"./button-ozMsoqIh.js";import{C as de,a as me,c as ue,b as pe}from"./card-CGxU6Ujh.js";import{T as ut}from"./textarea-B9C9WMMJ.js";import{B as ve}from"./badge-CHLB95D3.js";import{S as Ne,a as Se,b as Ce,c as Ae,d as ke}from"./select-DPNV9hN7.js";import{A as pt,a as ht,b as gt,c as xt,d as ft,e as _t,f as yt,g as vt}from"./alert-dialog-CUgdgaiM.js";import{u as Re,g as bt,t as ae}from"./use-caregiver-context-B5bWaKto.js";import{L as he,s as jt,av as Oe,aQ as wt,r as Le,u as Ee,ab as De,F as Pe,an as Nt,T as Fe,S as $e,P as Qe,Z as Be,v as Ye,K as Ge,C as Te,a7 as He,ag as St,aM as Ct,n as At,aP as kt,l as Et}from"./vendor-icons-BbhXjgy5.js";import{C as Dt}from"./CaregiverBadge-BKc2-w7t.js";import{V as Pt}from"./VisitPrepAI-ClSicp9R.js";import{F as Tt,P as It}from"./PostVisitBanner-CwPVA2mH.js";import{r as Vt}from"./upcomingVisit-BOr0QZoh.js";import{b as qt,s as ze}from"./eventSummaryLabel-Xgzhnykb.js";import{s as Mt,f as be,p as Ue,d as Rt,i as Ot,h as Lt,q as Ft}from"./vendor-date-Ctl2uRge.js";import"./vendor-radix-I618Mglk.js";import"./vendor-supabase-BI1TbgRl.js";import"./vendor-charts-Df9hQbmF.js";import"./vendor-query-_n4XbDCE.js";import"./label-BPNmfi2k.js";import"./calendar-31DnDnJr.js";import"./input-B2adqXLP.js";import"./radio-group-D83kb3uo.js";import"./checkbox-DMpx7LYF.js";import"./alert-BldCaXLd.js";import"./haptics-IUZ9jpTP.js";import"./LogoMark-C8Gzk_Eb.js";import"./branding-CSuvK0zE.js";import"./schemas-5iI55soa.js";import"./vendor-forms-BFc0VN4G.js";import"./treatmentDerivation-BmzSioBR.js";import"./intake-DaqTMNW9.js";import"./treatmentMatchers-CruuOT3h.js";import"./mgRelevance-C5hIcfPS.js";import"./focusDerivation-B0iphS8f.js";import"./packetEventLedger-BilYh_jg.js";import"./FocusSetupModal-C0GJymM4.js";const Ie=[{value:"general",label:"General"},{value:"medication",label:"Medications"},{value:"symptoms",label:"Symptoms"},{value:"lifestyle",label:"Lifestyle"},{value:"referral",label:"Referrals"}],Ve=[{value:"high",label:"High",color:"destructive"},{value:"medium",label:"Medium",color:"warning"},{value:"low",label:"Low",color:"secondary"}];function Je({patientId:t}){const[n,y]=i.useState([]),[m,V]=i.useState(!0),[v,A]=i.useState(!1),[w,_]=i.useState(""),[u,N]=i.useState("general"),[p,h]=i.useState("medium"),[k,S]=i.useState(null),[E,J]=i.useState(null),$=Re(t);i.useEffect(()=>{(async()=>{const{data:{session:o}}=await l.auth.getSession();J(o?.user?.id||null)})(),D()},[t]);const D=async()=>{const{data:s,error:o}=await l.from("doctor_questions").select("id, question_text, category, priority, status, answer_notes, appointment_date, created_at, created_by, caregiver_attribution").eq("patient_id",t).is("resolved_at",null).order("created_at",{ascending:!1});if(o)U.error("Failed to load questions"),console.error(o);else{const r=(s||[]).map(d=>({...d,category:d.category??"general",priority:d.priority??"medium",status:d.status??"pending",created_by:d.created_by??null,caregiver_attribution:d.caregiver_attribution}));y(r)}V(!1)},W=async()=>{if(!w.trim()){U.error("Please enter a question");return}A(!0);const s={patient_id:t,question_text:w.trim(),category:u,priority:p,status:"pending",created_by:E,caregiver_attribution:$.isCaregiverViewing?bt($):null},{error:o}=await l.from("doctor_questions").insert(s);o?(U.error("Failed to add question"),console.error(o)):(U.success("Question added"),_(""),N("general"),h("medium"),D()),A(!1)},G=async s=>{const o=s.status==="pending"?"asked":"pending",{error:r}=await l.from("doctor_questions").update({status:o}).eq("id",s.id);r?U.error("Failed to update question"):D()},H=async s=>{const{error:o}=await l.from("doctor_questions").delete().eq("id",s);o?U.error("Failed to delete question"):(U.success("Question deleted"),D()),S(null)},Q=async()=>{const{error:s}=await l.from("doctor_questions").delete().eq("patient_id",t).eq("status","asked");s?U.error("Failed to clear questions"):(U.success("Asked questions cleared"),D())},O=n.filter(s=>s.status==="pending"),b=n.filter(s=>s.status==="asked"),M=s=>Ie.find(o=>o.value===s)?.label||s,L=s=>{const o=Ve.find(r=>r.value===s);return e.jsx(ve,{variant:o?.color,className:"text-xs",children:o?.label||s})};return m?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(he,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs(de,{children:[e.jsx(me,{className:"pb-3",children:e.jsxs(ue,{className:"text-base flex items-center gap-2",children:[e.jsx(jt,{className:"w-4 h-4"}),"Add a Question"]})}),e.jsxs(pe,{className:"space-y-4",children:[e.jsx(ut,{placeholder:"What would you like to ask your doctor?",value:w,onChange:s=>_(s.target.value),className:"min-h-[80px]"}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(Ne,{value:u,onValueChange:N,children:[e.jsx(Se,{className:"w-[140px]",children:e.jsx(Ce,{placeholder:"Category"})}),e.jsx(Ae,{children:Ie.map(s=>e.jsx(ke,{value:s.value,children:s.label},s.value))})]}),e.jsxs(Ne,{value:p,onValueChange:h,children:[e.jsx(Se,{className:"w-[120px]",children:e.jsx(Ce,{placeholder:"Priority"})}),e.jsx(Ae,{children:Ve.map(s=>e.jsx(ke,{value:s.value,children:s.label},s.value))})]}),e.jsxs(Y,{onClick:W,disabled:v,className:"ml-auto",children:[v?e.jsx(he,{className:"w-4 h-4 animate-spin mr-2"}):null,"Add Question"]})]})]})]}),e.jsxs(de,{children:[e.jsx(me,{className:"pb-3",children:e.jsxs(ue,{className:"text-base flex items-center gap-2",children:[e.jsx(Oe,{className:"w-4 h-4"}),"Questions to Ask (",O.length,")"]})}),e.jsx(pe,{children:O.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No questions yet. Add one above!"}):e.jsx("div",{className:"space-y-3",children:O.map(s=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 transition-colors",children:[e.jsx("button",{onClick:()=>G(s),className:"mt-0.5 shrink-0",title:"Mark as asked",children:e.jsx(wt,{className:"w-5 h-5 text-muted-foreground hover:text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:s.question_text}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[e.jsx(ve,{variant:"outline",className:"text-xs",children:M(s.category)}),L(s.priority),s.caregiver_attribution&&e.jsxs(ve,{variant:"secondary",className:"text-xs gap-1",children:[e.jsx(Le,{className:"w-3 h-3"}),s.caregiver_attribution.caregiver_name||"Caregiver"]})]})]}),e.jsx("button",{onClick:()=>S(s.id),className:"text-muted-foreground hover:text-destructive transition-colors shrink-0",title:"Delete",children:e.jsx(Ee,{className:"w-4 h-4"})})]},s.id))})})]}),b.length>0&&e.jsxs(de,{children:[e.jsx(me,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(ue,{className:"text-base flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4 text-primary"}),"Already Asked (",b.length,")"]}),e.jsx(Y,{variant:"ghost",size:"sm",onClick:Q,className:"text-xs",children:"Clear All"})]})}),e.jsx(pe,{children:e.jsx("div",{className:"space-y-2",children:b.map(s=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-dashed bg-muted/30",children:[e.jsx("button",{onClick:()=>G(s),className:"mt-0.5 shrink-0",title:"Mark as pending",children:e.jsx(De,{className:"w-5 h-5 text-primary"})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-sm text-muted-foreground line-through",children:s.question_text})}),e.jsx("button",{onClick:()=>S(s.id),className:"text-muted-foreground hover:text-destructive transition-colors shrink-0",title:"Delete",children:e.jsx(Ee,{className:"w-4 h-4"})})]},s.id))})})]}),e.jsx(pt,{open:!!k,onOpenChange:()=>S(null),children:e.jsxs(ht,{children:[e.jsxs(gt,{children:[e.jsx(xt,{children:"Delete Question?"}),e.jsx(ft,{children:"This action cannot be undone."})]}),e.jsxs(_t,{children:[e.jsx(yt,{children:"Cancel"}),e.jsx(vt,{onClick:()=>k&&H(k),children:"Delete"})]})]})})]})}const ge=["symptom_flare","medication_side_effect","medication_change","potential_trigger","hospital_event","procedure"],$t={symptom_flare:[],medication_side_effect:[],medication_change:[],potential_trigger:[],hospital_event:[],procedure:[]};function We(t){return[...t?["check_in"]:[],...ge,"priorities","questions","end"]}function Qt(t,n){const y=i.useMemo(()=>
2{if(!n)return 0;const _=t.indexOf(n);return _>=0?_:0},[t,n]),[m,V]=i.useState(y),v=t[Math.min(m,t.length-1)],A=i.useCallback(()=>{V(_=>Math.min(_+1,t.length-1))},[t.length]),w=i.useCallback(_=>{const u=t.indexOf(_);u>=0&&V(u)},[t]);return{cards:t,index:m,currentCard:v,next:A,goTo:w}}function Bt(t,n){const y=t.indexOf(n);return y<0?null:t[Math.min(y+1,t.length-1)]??null}const qe={symptom_flare:0,hospital_event:0,medication_change:0,medication_side_effect:0,potential_trigger:0,procedure:0};function Yt(t){const[n,y]=i.useState({loading:!0,lastVisitDate:null,nextVisitDate:null,mgAdlScores:[],mgAdlSeries:je({}),currentMgAdlScore:null,scoreDelta:null,mgAdlComparison:null,lastCheckInDate:null,sinceAnchorISO:null,sinceAnchorType:null,sinceAnchorFutureISO:null,infusionOutcomes:[],pulseChecks:[],medicationChanges:[],keyEvents:[],sweepCounts:{...qe},sweepItems:{...$t}}),m=i.useCallback(async()=>{if(t){const{data:V}=await l.from("patients").select("last_visit_confirmed_at, doctor_visit_date").eq("id",t).maybeSingle(),v=V?.last_visit_confirmed_at||null,A=await Vt(t,V?.doctor_visit_date),[w,_]=await Promise.all([l.from("mg_intake_responses").select("completed_at").eq("patient_id",t).not("completed_at","is",null).order("completed_at",{ascending:!1}).limit(1).maybeSingle(),l.from("timeline_entries").select("occurred_at").eq("patient_id",t).eq("entry_type","doctor_visit").order("occurred_at",{ascending:!1})]),u=Date.now(),N=(_.data||[]).map(a=>a.occurred_at).filter(a=>!!a&&new Date(a).getTime()<=u),p=et(v,w.data?.completed_at||null,N),h=p?.anchorISO??null,k=p?.anchorType??null,S=p?.fallbackReason==="future_date"?p.futureAnchorISO??null:null,E=h?new Date(h).toISOString():Mt(new Date,90).toISOString(),[J,$,D,W,G,H]=await Promise.all([l.from("timeline_entries").select("occurred_at, data").eq("patient_id",t).eq("entry_type","status_update").gte("occurred_at",E).order("occurred_at",{ascending:!0}),l.from("infusion_schedules").select("id, therapy_name").eq("patient_id",t),l.from("pulse_checks").select("id, rating, recorded_at").eq("patient_id",t).gte("recorded_at",E).order("recorded_at",{ascending:!0}),l.from("timeline_entries").select("id, title, data, occurred_at").eq("patient_id",t).eq("entry_type","medication_change").gte("occurred_at",E).order("occurred_at",{ascending:!1}).limit(10),l.from("timeline_entries").select("id, title, entry_type, occurred_at, data").eq("patient_id",t).in("entry_type",["
2symptom_flare","hospital_event","lab_result","potential_trigger"]).gte("occurred_at",E).order("occurred_at",{ascending:!1}).limit(10),l.from("mg_intake_responses").select("completed_at, responses").eq("patient_id",t).not("completed_at","is",null).maybeSingle()]);let Q=null;const O=H.data?.responses;H.data?.completed_at&&O?.mgadlScore?.totalScore!==void 0&&(Q={completedAt:H.data.completed_at,score:O.mgadlScore.totalScore});const b=[];J.data?.forEach(a=>{const c=a.data;typeof c?.mgAdlTotal=="number"&&b.push({date:a.occurred_at,score:c.mgAdlTotal,administeredBy:c.administered_by??null})});const M=je({baseline:Q,checkIns:b}),L=M.points.map(a=>({date:a.recordedAt,plotAt:a.plotAt,score:a.score,isBaseline:a.kind==="baseline",entriesThatDay:a.entriesThatDay})),s=M.current?.score??null,o=M.comparison?.value??null,r=M.current?.recordedAt??null,d=($.data||[]).map(a=>a.id),q=new Map(($.data||[]).map(a=>[a.id,a.therapy_name]));let P=[];if(d.length>0){const a=E.split("T")[0],{data:c}=await l.from("infusion_events").select("id, expected_date, actual_date, schedule_id, status").eq("status","completed").in("schedule_id",d).gte("expected_date",a).order("expected_date",{ascending:!1});if(c&&c.length>0){const ne=c.map(T=>T.id),{data:xe}=await l.from("infusion_outcomes").select("*").in("event_id",ne),Z=new Map((xe||[]).map(T=>[T.event_id,T]));P=c.map(T=>{const B=Z.get(T.id),te=B?.pulse_rating??null;let se=null;return te===1?se="great":te===2?se="ok":te===3&&(se="not_well"),{id:T.id,date:T.actual_date||T.expected_date,therapyName:q.get(T.schedule_id)||"Infusion",outcome:se,pulseRating:te,symptoms:B?.ae_symptoms||[],severity:B?.ae_severity||null,onset:B?.ae_onset_timing||null,comparison:B?.comparison_to_previous||null,notes:B?.notes||null}});const oe={not_well:0,ok:1,great:2};P.sort((T,B)=>(oe[T.outcome??"great"]??3)-(oe[B.outcome??"great"]??3))}}const z=(D.data||[]).map(a=>({id:a.id,rating:a.rating,recordedAt:a.recorded_at})),X=(W.data||[]).filter(a=>a.data?.change_type!=="dose_corrected").map(a=>{const c=a.data;return{id:a.id,medication:c?.medication_name||a.title,changeType:c?.change_type||"change",dose:c?.dose,occurredAt:a.occurred_at,isCaregiverReported:c?.reported_by==="caregiver",isPending:!!c?.pending_patient_approval}}),ee=(G.data||[]).map(a=>{const c=a.data;return{id:a.id,title:a.title,type:a.entry_type,occurredAt:a.occurred_at,timeBand:c?.occurred_time_band||null,isCaregiverReported:c?.reported_by==="caregiver",caregiverName:c?.caregiver_name}}),F={...qe},j={symptom_flare:[],medication_side_effect:[],medication_change:[],potential_trigger:[],hospital_event:[],procedure:[]},{data:ie}=await l.from("timeline_entries").select("id, title, entry_type, occurred_at, data, created_at").eq("patient_id",t).in("entry_type",["
2symptom_flare","hospital_event","medication_change","medication_side_effect","potential_trigger","procedure"]).gte("occurred_at",E).order("occurred_at",{ascending:!1});(ie||[]).forEach(a=>{const c=a.entry_type;c in F&&(F[c]+=1,j[c].push({id:a.id,title:a.title,occurredAt:a.occurred_at,entryType:c,summary:qt(c,a.title,a.data),loggedNote:rt(a.data,a.created_at)}))}),y({loading:!1,lastVisitDate:v,nextVisitDate:A,mgAdlScores:L,mgAdlSeries:M,currentMgAdlScore:s,scoreDelta:o,mgAdlComparison:M.comparison,lastCheckInDate:r,sinceAnchorISO:h,sinceAnchorType:k,sinceAnchorFutureISO:S,infusionOutcomes:P,pulseChecks:z,medicationChanges:X,keyEvents:ee,sweepCounts:F,sweepItems:j})}},[t]);return i.useEffect(()=>{m()},[m]),{...n,refetch:m}}function Gt(){return e.jsx("div",{className:"space-y-4",children:e.jsxs(de,{children:[e.jsx(me,{className:"pb-3",children:e.jsxs(ue,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4 text-primary"}),"Share with Doctor"]})}),e.jsxs(pe,{className:"space-y-4",children:[e.jsx(Y,{asChild:!0,className:"w-full gap-2",size:"lg",children:e.jsxs(re,{to:"/portal/doctor-packet",children:[e.jsx(Pe,{className:"w-4 h-4"}),"Preview Clinical Summary"]})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Includes MG-ADL trajectory, infusion outcomes, medication changes, your questions, and key events"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-muted/50 border border-border",children:[e.jsx(Nt,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your data is only shared when you choose to share it. Nothing is sent automatically."})]})]})]})})}const Ht=[{type:"symptom_flare",label:"Symptom Event",icon:e.jsx(Fe,{className:"w-5 h-5"}),iconColor:"text-warning",bgColor:"bg-warning/10"},{type:"medication_side_effect",label:"Side Effect",icon:e.jsx($e,{className:"w-5 h-5"}),iconColor:"text-orange-500",bgColor:"bg-orange-500/10"},{type:"medication_change",label:"Medication",icon:e.jsx(Qe,{className:"w-5 h-5"}),iconColor:"text-primary",bgColor:"bg-primary/10"},{type:"potential_trigger",label:"Log Trigger",icon:e.jsx(Be,{className:"w-5 h-5"}),iconColor:"text-amber-500",bgColor:"bg-amber-500/10"},{type:"hospital_event",label:"ER / Hospital",icon:e.jsx(Ye,{className:"w-5 h-5"}),iconColor:"text-destructive",bgColor:"bg-destructive/10"},{type:"procedure",label:"Procedure",icon:e.jsx(Ge,{className:"w-5 h-5"}),iconColor:"text-teal-600",bgColor:"bg-teal-600/10"}];function zt({counts:t,sinceDateLabel:n,patientId:y}){return e.jsx("div",{children:e.jsx("div",{className:"grid grid-cols-3 gap-2",children:Ht.map(m=>e.jsxs(re,{to:`/portal/add-entry?from=prepare&type=${m.type}`,onClick:()=>ae("visit_prep_sweep_chip_tapped",y,{entry_type:m.type,count:t?.[m.type]??0}),className:"flex flex-col items-center gap-1.5 p-3 rounded-lg border border-border hover:border-primary/50 hover:bg-muted/50 transition-colors text-center",children:[e.jsx("div",{className:`flex items-center justify-center w-8 h-8 rounded-lg ${m.bgColor} ${m.iconColor}`,children:m.icon}),e.jsx("span",{className:"text-xs font-medium text-foreground leading-tight",children:m.label})]},m.type))})})}const Xe={symptom_flare:{short:"Flare",label:"Symptom Event",plural:"symptom events",icon:e.jsx(Fe,{className:"w-5 h-5"}),iconColor:"text-warning",bgColor:"bg-warning/10"},medication_side_effect:{short:"Side effect",label:"Side Effect",plural:"side effects",icon:e.jsx($e,{className:"w-5 h-5"}),iconColor:"text-orange-500",bgColor:"bg-orange-500/10"},medication_change:{short:"Medication",label:"Medication",plural:"medication changes",icon:e.jsx(Qe,{className:"w-5 h-5"}),iconColor:"text-primary",bgColor:"bg-primary/10"},potential_trigger:{short:"Trigger",label:"Trigger",plural:"triggers",icon:e.jsx(Be,{className:"w-5 h-5"}),iconColor:"text-amber-500",bgColor:"bg-amber-500/10"},hospital_event:{short:"ER / Hospital",label:"ER / Hospital",plural:"ER or hospital visits",icon:e.jsx(Ye,{className:"w-5 h-5"}),iconColor:"text-destructive",bgColor:"bg-destructive/10"},procedure:{short:"Procedure",label:"Procedure",plural:"procedures",icon:e.jsx(Ge,{className:"w-5 h-5"}),iconColor:"text-teal-600",bgColor:"bg-teal-600/10"}},Ut=6;function Jt(t){return ge.flatMap(n=>t[n]??[]).sort((n,y)=>n.occurredAt<y.occurredAt?1:-1)}function Wt({items:t,sinceDateLabel:n,headerVariant:y="logged"}){const[m,V]=i.useState(!1),v=Jt(t);if(v.length===0)return e.jsx("p",{className:"text-[15px] text-muted-foreground",children:n?`Nothing logged since ${n}.`:"Nothing logged yet."});const A=m?v:v.slice(0,Ut),w=v.length-A.length,_=y==="on_file"?n?`Here's what's on file since your last visit with MG Specialist / Neurologist (${n}):`:"Here's what's on file since your last visit:":n?`Since your last visit with MG Specialist / Neurologist (${n}
2) you've logged:`:"You've logged:";return e.jsxs("div",{children:[e.jsx("p",{className:"text-[15px] font-medium text-foreground mb-2",children:_}),e.jsx("ul",{className:"space-y-1.5",children:A.map(u=>{const N=Xe[u.entryType],p=it(u.occurredAt),h=u.summary??ze(u.title||"");return e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:`${N.iconColor} shrink-0 mt-0.5`,children:N.icon}),e.jsxs("span",{className:"text-[15px] text-foreground leading-snug",children:[N.short,h?` — ${h}`:"",p?e.jsxs("span",{className:"text-muted-foreground",children:[" · ",p]}):null,u.loggedNote?e.jsxs("span",{className:"text-muted-foreground",children:[" ","(",u.loggedNote,")"]}):null]})]},u.id)})}),w>0&&e.jsxs("button",{type:"button",onClick:()=>V(!0),className:"mt-2 text-[15px] text-primary hover:underline",children:["+",w," more"]})]})}const Xt={symptom_flare:"Any symptom events to add?",medication_side_effect:"Any side effects to add?",medication_change:"Any medication changes to add?",potential_trigger:"Any triggers to add?",hospital_event:"Any ER or hospital visits to add?",procedure:"Any procedures to add?"};function Zt(t){try{return be(Ue(t),"MMM d")}catch{return""}}function Kt({patientId:t,sinceDateLabel:n,sweepItems:y,needsCheckIn:m,initialCardId:V,checkInSummary:v,priorCheckInLine:A,justAddedCard:w,justAddedReady:_,onVoiceEntriesAdded:u,onExit:N}){const p=Me(),h=We(m),{currentCard:k,next:S}=Qt(h,V),[E,J]=i.useState({}),[$,D]=i.useState(null),[W,G]=i.useState(null),[H,Q]=i.useState(!1),O=async r=>{D(null),G(r),Q(!0);try{await u?.(r)}finally{Q(!1)}},b=(r,d)=>{ae("visit_prep_sweep_card_answered",t,{card:r,choice:d})},M=()=>{ae("visit_prep_sweep_exited",t,{card:k}),N()},L=(r,d,q,P)=>e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"flex items-center justify-center w-9 h-9 rounded-lg bg-muted text-foreground shrink-0",children:d}),e.jsx("h3",{className:"text-base font-semibold text-foreground",children:r})]}),q,P]}),s=(r,d="Skip")=>e.jsxs("div",{className:"flex items-center justify-between mt-4",children:[e.jsx("button",{type:"button",onClick:()=>{b(r,"skip"),S()},className:"text-[15px] text-muted-foreground hover:text-foreground underline-offset-4 hover:underline",children:d}),e.jsx("button",{type:"button",onClick:M,className:"text-[15px] text-muted-foreground hover:text-foreground underline-offset-4 hover:underline",children:"Finish later"})]});let o=null;if(k==="check_in")o=L("Your check-in",e.jsx(St,{className:"w-5 h-5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[17px] text-foreground",children:"There's no check-in from the past week. Doing one now gives your doctor the most current picture."}),A&&e.jsx("p",{className:"text-[15px] text-muted-foreground mt-2",children:A}),e.jsx(Y,{className:"w-full mt-4 min-h-11 text-[17px]",onClick:()=>{b("check_in","yes"),p("/portal/check-in?from=prepare&sweep=1")},children:"Start check-in"})]}),s("check_in","Not now"));else if(ge.includes(k)){const r=k,d=Xe[r],q=y[r]??[],P=w===r||W===r,z=w===r&&!_||W===r&&H,X=!!E[r],ee=X?q:q.slice(0,4),F=q.length-ee.length;o=L(d.label,e.jsx("span",{className:`${d.iconColor}`,children:d.icon}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[19px] font-semibold text-foreground",children:Xt[r]}),n&&e.jsxs("p",{className:"text-[15px] text-muted-foreground mt-1",children:["Since ",n]}),z&&e.jsxs("p",{className:"text-[15px] text-muted-foreground mt-3 flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4 animate-spin"}),"Saving to your record…"]}),P&&_&&e.jsxs("p",{className:"text-[15px] text-foreground mt-3 flex items-center gap-2",children:[e.jsx(Te,{className:"w-4 h-4 text-primary"}),"Added"]}),q.length>0&&e.jsxs("ul",{className:"mt-3 space-y-1",children:[ee.map(j=>e.jsxs("li",{className:"text-[15px] text-muted-foreground",children:["Logged: ",Zt(j.occurredAt)," —"," ",j.summary??ze(j.title||""),j.loggedNote?` (${j.loggedNote})`:""]},j.id)),F>0&&e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>J(j=>({...j,[r]:!0})),className:"min-h-11 text-[15px] text-primary hover:underline",children:["+",F," more"]})}),X&&q.length>4&&e.jsx("li",{children:e.jsx("button",{type:"button",onClick:()=>J(j=>({...j,[r]:!1})),className:"min-h-11 text-[15px] text-primary hover:underline",children:"Show less"})})]}),$===r?e.jsx("div",{className:"mt-4",children:e.jsx(nt,{patientId:t,scopedEntryType:r,scopedLabel:d.label,onEntryAdded:()=>void O(r),onCancel:()=>D(null)})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-3 mt-4",children:[e.jsx(Y,{variant:"outline",className:"flex-1 min-h-11 text-[17px]",disabled:z,onClick:()=>{b(r,"no"),S()},children:P?"No, that's all →":"No"}),e.jsx(Y,{className:"flex-1 min-h-11 text-[17px]",disabled:z,onClick:()=>{b(r,P?"add_another":"yes"),p(`/portal/add-entry?from=prepare&type=${r}&sweep=${r}`)},children:P?"Add another":"Yes, add one"})]}),e.jsxs("button",{type:"button",disabled:z,onClick:()=>{ae("visit_prep_sweep_voice_opened",t,{card:r}),D(r)},className:"flex items-center justify-center gap-2 w-full min-h-11 mt-3 rounded-lg border border-border text-[17px] text-foreground hover:bg-muted/50 disabled:opacity-50",children:[e.jsx(He,{className:"w-4 h-4"}),"Say it instead"]})]})]}),$===r?void 0:s(r))}else if(k==="priorities")o=L("Your priorities",e.jsx(Ct,{className:"w-5 h-5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[17px] text-foreground mb-4",children:"What matters most to you at this visit?"}),e.jsx(Tt,{patientId:t}),e.jsx(Y,{variant:"outline",className:"w-full mt-4 min-h-11 text-[17px]",onClick:()=>{b("priorities","yes"),S()},children:"Continue"})]}),s("priorities"));
2else if(k==="questions")o=L("Your questions",e.jsx(Oe,{className:"w-5 h-5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[17px] text-foreground mb-4",children:"Anything you want to ask at this visit?"}),e.jsx(Je,{patientId:t}),e.jsx(Y,{variant:"outline",className:"w-full mt-4 min-h-11 text-[17px]",onClick:()=>{b("questions","yes"),S()},children:"Continue"})]}),s("questions"));else{const r=ge.reduce((d,q)=>d+(y[q]?.length??0),0);o=L("Ready for your visit",e.jsx(Te,{className:"w-5 h-5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[17px] text-foreground",children:n?`${r} item${r===1?"":"s"} logged since ${n}.`:`${r} item${r===1?"":"s"} logged.`}),v&&e.jsx("p",{className:"text-[15px] text-muted-foreground mt-1",children:v}),e.jsx(Y,{className:"w-full mt-4 min-h-11 text-[17px]",onClick:()=>{ae("visit_prep_sweep_completed",t,{}),p("/portal/doctor-packet?from=prepare-appointment")},children:"Open clinical summary"}),e.jsx("button",{type:"button",onClick:N,className:"w-full mt-3 text-[15px] text-muted-foreground hover:text-foreground underline-offset-4 hover:underline",children:"Back to Visit Prep"})]}))}return e.jsx("div",{className:"mb-8",children:o})}function Ys(){const[t,n]=i.useState(null),[y,m]=i.useState(null),[V,v]=i.useState(null),[A,w]=i.useState(!0),_=Me(),[u]=Ke(),N=u.get("patientId"),p=Re(t||""),h=Yt(t),{data:k}=ot(t),{enabled:S}=dt("companion"),[E,J]=i.useState(null),[$,D]=i.useState([]),[W,G]=i.useState(!1),[H,Q]=i.useState(null),[O,b]=i.useState(!1),[M,L]=i.useState(0),s=u.get("sweep"),o=u.get("after"),r=u.get("card"),d=u.get("added"),[q,P]=i.useState(!1),[z,X]=i.useState(!!s),[ee,F]=i.useState(null),[j,ie]=i.useState(!!s),[a,c]=i.useState(!1),ne=i.useRef(null),xe=7,Z=h.lastCheckInDate?Rt(new Date,new Date(h.lastCheckInDate))>xe:!0;i.useEffect(()=>{if(!d){P(!1);return}let x=!1;return P(!1),h.refetch().then(()=>{x||P(!0)}),()=>{x=!0}},[d]),i.useEffect(()=>{if(!s)return;const x=We(Z);r?F(r):o&&F(Bt(x,o)),X(!0),ie(!0)},[s,o,r,Z]);const oe=()=>{ae("visit_prep_sweep_started",t??void 0,{needs_check_in:Z}),F(null),X(!0),ie(!0),c(!1)},T=()=>{X(!1),F(null),requestAnimationFrame(()=>{ne.current?.scrollIntoView({behavior:"smooth",block:"start"})})},B=async(x,C)=>{const{data:g}=await l.from("post_visit_summaries").select("id").eq("patient_id",x).eq("visit_date",be(C,"yyyy-MM-dd")).maybeSingle();v(!!g)};i.useEffect(()=>{(async()=>{const{data:{session:C}}=await l.auth.getSession();if(!C){_(`/auth?redirect=${encodeURIComponent(window.location.pathname+window.location.search)}`);return}let g,R,K;if(N){const{data:f}=await l.from("caregiver_patient_access").select("patient_id").eq("caregiver_user_id",C.user.id).eq("patient_id",N).eq("status","accepted").maybeSingle();if(f?.patient_id){g=f.patient_id;const{data:I}=await l.from("patients").select("doctor_visit_date, last_visit_confirmed_at").eq("id",g).maybeSingle();R=I?.doctor_visit_date,K=I?.last_visit_confirmed_at}}if(!g){const{data:f,error:I}=await l.from("patients").select("id, doctor_visit_date, last_visit_confirmed_at").eq("patient_id",C.user.id).maybeSingle();if(I){console.error("PrepareAppointment: patient lookup failed",I);return}g=f?.id,R=f?.doctor_visit_date,K=f?.last_visit_confirmed_at}if(!g){const{data:f,error:I}=await l.from("caregiver_patient_access").select("patient_id").eq("caregiver_user_id",C.user.id).eq("status","accepted").limit(1).maybeSingle();if(I){console.error("PrepareAppointment: caregiver lookup failed",I);return}if(f?.patient_id){g=f.patient_id;const{data:le}=await l.from("patients").select("doctor_visit_date, last_visit_confirmed_at").eq("id",g).maybeSingle();R=le?.doctor_visit_date,K=le?.last_visit_confirmed_at}else{_("/onboarding");return}}if(n(g),R&&m(new Date(R)),K){const f=new Date(K.split("T")[0]+"T12:00:00"),I=Math.floor((Date.now()-f.getTime())/(1e3*60*60*24));Ot(f)&&!Lt(f)&&I<=14&&(J(f),await B(g,f))}w(!1)})()},[_,N]),i.useEffect(()=>{!t||!S||(G(!0),l.from("companion_insights_cache").select("insights_json, generated_at").eq("patient_id",t).eq("invalidated",!1).order("generated_at",{ascending:!1}).limit(1).maybeSingle().then(({data:x})=>{if(x?.insights_json){const g=x.insights_json.visitTopics||[];D(g),Q(x.generated_at)}G(!1)}))},[t,S]);const te=async()=>
2{if(!(!t||O)){b(!0);try{const{data:{session:x},error:C}=await l.auth.refreshSession();if(C||!x){const{toast:f}=await ye(async()=>{const{toast:I}=await import("./index-DRQAaCbt.js").then(le=>le.M);return{toast:I}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));f.error("Session expired. Please sign in again.");return}const g=await fetch("https://ygohwaqhuuqpddytftqj.supabase.co/functions/v1/generate-companion-insights",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${x.access_token}`,apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inlnb2h3YXFodXVxcGRkeXRmdHFqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc1NTEwNTYsImV4cCI6MjA4MzEyNzA1Nn0.vNw84VBftniZvM25lU_cIcxw7m86-37jCvw0wVFmlEI"},body:JSON.stringify({force_refresh:!0})}),{toast:R}=await ye(async()=>{const{toast:f}=await import("./index-DRQAaCbt.js").then(I=>I.M);return{toast:f}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));if(!g.ok){if(g.status===429)R.error("Rate limit reached. Please try again in a moment.");else if(g.status===402)R.error("AI credits exhausted. Please add credits in workspace settings.");else{const f=await g.json().catch(()=>({error:"Error"}));R.error(f.error||"Failed to generate topics")}return}const K=await g.json();D(K.visitTopics||[]),Q(new Date().toISOString()),R.success("Discussion topics ready")}catch(x){console.error("Generate topics error:",x);const{toast:C}=await ye(async()=>{const{toast:g}=await import("./index-DRQAaCbt.js").then(R=>R.M);return{toast:g}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));C.error("Failed to generate topics")}finally{b(!1)}}},se=E&&V===!1;if(A)return e.jsx(we,{children:e.jsx("div",{className:"content-container section-padding",children:e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(he,{className:"w-6 h-6 animate-spin text-muted-foreground"})})})});const Ze=()=>p.isCaregiverViewing&&t?`/portal/dashboard?patientId=${t}`:"/portal/dashboard",fe=h.sinceAnchorISO?tt(h.sinceAnchorISO):null,_e=ct(k??[]).upcoming[0]??null,ce=(()=>{if(!_e)return null;const x=Ue(`${_e.visit_date}T12:00:00`),C=Ft(x,new Date),g=C===0?"today":C===1?"tomorrow":`in ${C} days`;return{label:lt[_e.appointment_type]??"Visit",dateStr:be(x,"EEE MMM d"),when:g}})();return e.jsxs(we,{children:[e.jsx("section",{className:"hidden md:block bg-gradient-to-b from-muted/50 to-background border-b border-border",children:e.jsx("div",{className:"content-container py-6",children:e.jsx("div",{className:"flex items-start justify-between gap-4",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Y,{variant:"ghost",size:"icon",asChild:!0,className:"mt-1",children:e.jsx(re,{to:Ze(),children:e.jsx(At,{className:"w-5 h-5"})})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx("h1",{className:"text-xl md:text-2xl font-serif font-bold text-foreground",children:"Prepare for Your Appointment"}),p.isCaregiverViewing&&e.jsx(Dt,{caregiverRole:p.caregiverRole,caregiverName:p.caregiverName,compact:!0})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p.isCaregiverViewing?"Help prepare questions and review what will be shared":"Everything you need to make your next visit count"})]})]})})})}),e.jsx("section",{className:"px-2.5 md:section-padding pb-24 xl:pb-6",children:e.jsxs("div",{className:"content-container overflow-hidden",children:[se&&t&&E&&e.jsx("div",{className:"mb-6",children:e.jsx(It,{patientId:t,visitDate:E,onSummaryAdded:()=>v(!0)})}),ce&&e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-base font-semibold text-foreground",children:["Next ",ce.label," visit"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[ce.dateStr," · ",ce.when]})]}),e.jsx(re,{to:"/portal/appointments",className:"text-sm text-primary hover:underline shrink-0 mt-0.5",children:"Details"})]}),p.isCaregiverViewing&&e.jsxs("div",{className:"flex items-center gap-2 mb-6 p-3 rounded-lg bg-muted/50 border border-border",children:[e.jsx(Le,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Questions and observations you add here will be visible to the patient and included in their summary."})]}),z&&t?e.jsx(Kt,{patientId:t,sinceDateLabel:fe,sweepItems:h.sweepItems,needsCheckIn:Z,initialCardId:ee,justAddedCard:d,justAddedReady:q,checkInSummary:Z?null:at(h.mgAdlSeries),priorCheckInLine:st(h.mgAdlSeries),onVoiceEntriesAdded:async()=>{await h.refetch()},onExit:T}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:"Catch up"}),e.jsx("div",{className:"mb-5",children:e.jsx(Wt,{items:h.sweepItems,sinceDateLabel:fe})}),!j&&e.jsxs("button",{type:"button",onClick:oe,className:"flex items-start gap-3 w-full p-4 mb-3 rounded-xl border-2 border-primary bg-primary/10 hover:bg-primary/15 transition-colors text-left",children:[e.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-lg bg-primary/15 text-primary shrink-0",children:e.jsx(kt,{className:"w-5 h-5"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-base font-semibold text-foreground",children:"Get ready for your visit"}),e.jsx("span",{className:"block text-sm text-muted-foreground",children:"Walk through each category (~3 min)"})]})]}),!a&&e.jsxs("button",{type:"button",onClick:()=>c(!0),className:"flex items-center gap-1.5 min-h-[44px] mb-6 text-sm text-primary hover:underline",children:[j?"Added everything? You can still add one more":"Or add one thing quickly",e.jsx(Et,{className:"w-4 h-4"})]}),a&&e.jsxs("div",{className:"mb-8",children:[e.jsxs(re,{to:"/portal/add-entry?from=prepare&voice=true",className:"flex items-center gap-3 w-full p-4 mb-4 rounded-xl border-2 border-primary/30 bg-primary/5 hover:border-primary hover:bg-primary/10 transition-colors text-left",children:[e.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10 text-primary shrink-0",children:e.jsx(He,{className:"w-5 h-5"})}),e.jsx("span",{className:"text-base font-semibold text-foreground",children:"Add it by voice — we'll log it"})]}),e.jsx(zt,{counts:h.sweepCounts,sinceDateLabel:fe,patientId:t??void 0})]}),e.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:"Organize"}),t&&e.jsx("div",{className:"mb-6",children:e.jsx(Je,{patientId:t},M)}),S&&t&&!p.isCaregiverViewing&&e.jsx("div",{className:"mb-8",children:e.jsx(Pt,{topics:$,loading:W,patientId:t,onGenerate:te,generating:O,generatedAt:H,onQuestionsAdded:()=>L(x=>x+1)})})]}),!z&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{ref:ne,className:"text-base font-semibold text-foreground mb-3 scroll-mt-4",children:"Review & share"}),!p.isCaregiverViewing&&e.jsx(Gt,{})]})]})}),t&&e.jsx(mt,{patientId:t})]})}
2export{Ys 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.