PageSourceSearch

https://mymgconnect.com/assets/VisitSummaryDetailModal-B-SK-KK9.js

js mymgconnect.com collected 2026-10-02 01:40:22 UTC 9,933 bytes, 1 lines download raw bytes

1import{r as n,j as e}from"./vendor-react-CoJda1Bd.js";import{D as J,a as Z,b as $,c as ee}from"./Layout-CNne9y_G.js";import{B as p}from"./button-YmQu2n53.js";import{L as te}from"./label-DLHt3M7E.js";import{T as se}from"./textarea-Bu1ScCez.js";import{s as f,c as g,u as q}from"./index-BSjGD56s.js";import{b as ae}from"./treatmentDerivation-BI28UtXE.js";import{f as re}from"./treatmentMatchers-CruuOT3h.js";import{d as de,L as O,b as ie,P as ne,aT as le,c as oe,G as ce,C as me,g as xe,r as ue,U as pe}from"./vendor-icons-DhRJS5mG.js";import{p as w,f as P,d as R}from"./vendor-date-Ctl2uRge.js";const z={HIGH:"bg-destructive/10 text-destructive border-destructive/20",MEDIUM:"bg-amber-100 text-amber-800 border-amber-200 dark:bg-amber-900/30 dark:text-amber-400 dark:border-amber-800",LOW:"bg-muted text-muted-foreground border-border"},h={answered:{label:"Answered",icon:me,color:"text-emerald-600 dark:text-emerald-400"},not_relevant:{label:"Not relevant",icon:ce,color:"text-muted-foreground"},pending:{label:"Still pending",icon:oe,color:"text-amber-600 dark:text-amber-400"}};function ke({open:j,onOpenChange:A,summary:r,patientId:l,canEdit:G,onUpdated:U}){const[v,b]=n.useState(!1),[k,D]=n.useState(r.what_was_discussed||""),[N,S]=n.useState(!1),[s,C]=n.useState({loading:!0,mgAdlBefore:null,mgAdlAfter:null,activeTreatments:[]}),B=r.visit_context,m=B?.questions_at_visit||[],x=B?.ai_topics_at_visit||[],o=n.useMemo(()=>w(r.visit_date+"T12:00:00"),[r.visit_date]);n.useEffect(()=>{if(!j)return;let t=!1;return C(d=>({...d,loading:!0})),(async()=>{const d=o.toISOString(),[i,_,K,W]=await Promise.all([f.from("timeline_entries").select("occurred_at, data").eq("patient_id",l).eq("entry_type","status_update").lte("occurred_at",d).order("occurred_at",{ascending:!1}).limit(1).maybeSingle(),f.from("timeline_entries").select("occurred_at, data").eq("patient_id",l).eq("entry_type","status_update").gt("occurred_at",d).order("occurred_at",{ascending:!0}).limit(1).maybeSingle(),f.from("other_medications").select("name, started_on, stopped_on").eq("patient_id",l),ae(l,r.visit_date)]);if(t)return;const T=i.data?.data||null,E=_.data?.data||null,L=r.visit_date,Q=W.map(a=>({name:a.name,startDate:a.startDate||""})),X=(K.data||[]).filter(a=>{const u=!a.started_on||a.started_on<=L,I=!a.stopped_on||a.stopped_on>=L;return u&&I}).map(a=>({name:a.name,startDate:a.started_on||""})),y=[];for(const a of[...Q,...X]){const u=(a.name||"").trim();if(!u)continue;y.some(Y=>re(Y.name,u))||y.push(a)}C({loading:!1,mgAdlBefore:i.data&&T?.mgAdlTotal!==void 0?{score:T.mgAdlTotal,date:i.data.occurred_at}:null,mgAdlAfter:_.data&&E?.mgAdlTotal!==void 0?{score:E.mgAdlTotal,date:_.data.occurred_at}:null,activeTreatments:y})})(),()=>{t=!0}},[j,l,r.visit_date,o]);const M=(()=>{const t=r.caregiver_attribution;return t?.reported_by==="caregiver"?{label:t.caregiver_name||"Caregiver",icon:ue}:{label:"Patient",icon:pe}})(),V=M.icon,H=async()=>{S(!0);try{const{error:t}=await f.from("post_visit_summaries").update({what_was_discussed:k.trim()||null}).eq("id",r.id);if(t)throw t;q.success("Summary updated"),b(!1),U?.()}catch(t){console.error("Error updating summary:",t),q.error("Failed to update summary")}finally{S(!1)}},F=()=>{D(r.what_was_discussed||""),b(!1)},c=s.mgAdlBefore&&s.mgAdlAfter?s.mgAdlAfter.score-s.mgAdlBefore.score:null;return e.jsx(J,{open:j,onOpenChange:A,children:e.jsxs(Z,{className:"sm:max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs($,{children:[e.jsxs(ee,{className:"pr-10",children:["Visit on ",P(o,"MMMM d, yyyy")]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground mt-1",children:[e.jsx(V,{className:"w-3.5 h-3.5"}),e.jsxs("span",{children:["Entered by ",M.label]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["Recorded ",P(new Date(r.created_at),"MMM d, yyyy")]})]})]}),G&&!v&&e.jsx("div",{className:"flex justify-end -mt-2",children:e.jsxs(p,{variant:"outline",size:"sm",onClick:()=>b(!0),className:"gap-1.5 rounded-lg h-8 text-xs",children:[e.jsx(de,{className:"w-3.5 h-3.5"}),"Edit takeaways"]})}),e.jsxs("div",{className:"space-y-5 py-2",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Key takeaways"}),v?e.jsxs("div",{className:"space-y-2",children:[e.jsx(te,{htmlFor:"edit-summary",className:"sr-only",children:"Key takeaways"}),e.jsx(se,{id:"edit-summary",value:k,onChange:t=>D(t.target.value),rows:5,className:"resize-none",placeholder:"Decisions made, what changed, anything to remember…"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(p,{variant:"outline",size:"sm",onClick:F,disabled:N,children:"Cancel"}),e.jsxs(p,{size:"sm",onClick:H,disabled:N,children:[N&&e.jsx(O,{className:"h-4 w-4 mr-2 animate-spin"}),"Save"]})]})]}):e.jsx("div",{className:"bg-muted/30 rounded-lg p-4",children:e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:r.what_was_discussed||e.jsx("span",{className:"italic text-muted-foreground",children:"No takeaways recorded"})})})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground flex items-center gap-1.5",children:[e.jsx(ie,{className:"w-3.5 h-3.5"}),"Clinical snapshot"]}),e.jsxs("div",{className:"rounded-xl border bg-card p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1.5",children:"MG-ADL around this visit"}),s.loading?e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx(O,{className:"w-3 h-3 inline animate-spin mr-1"})," Loading…"]}):s.mgAdlBefore||s.mgAdlAfter?e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[s.mgAdlBefore&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Before · "}),e.jsx("span",{className:"font-semibold",children:s.mgAdlBefore.score}),e.jsxs("span",{className:"text-muted-foreground text-xs ml-1",children:["(",R(o,w(s.mgAdlBefore.date)),"d prior)"]})]}),s.mgAdlAfter&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"After · "}),e.jsx("span",{className:"font-semibold",children:s.mgAdlAfter.score}),e.jsxs("span",{className:"text-muted-foreground text-xs ml-1",children:["(",R(w(s.mgAdlAfter.date),o),"d after)"]})]}),c!==null&&e.jsxs("span",{className:g("text-xs font-medium px-2 py-0.5 rounded-full",c<0?"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400":c>0?"bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-400":"bg-muted text-muted-foreground"),children:[c>0?"+":"",c," change"]})]}):e.jsx("div",{className:"text-xs text-muted-foreground italic",children:"No MG-ADL check-ins recorded near this visit."})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs text-muted-foreground mb-1.5 flex items-center gap-1",children:[e.jsx(ne,{className:"w-3 h-3"})," Active treatments at visit"]}),s.loading?e.jsx("div",{className:"text-xs text-muted-foreground",children:"…"}):s.activeTreatments.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.activeTreatments.map(t=>e.jsx("span",{className:"text-xs px-2 py-1 rounded-full bg-primary/10 text-primary border border-primary/20",children:t.name}
1,t.name))}):e.jsx("div",{className:"text-xs text-muted-foreground italic",children:"No active infusion therapies on file for this date."})]})]})]}),m.length>0&&e.jsxs("section",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground flex items-center gap-1.5",children:[e.jsx(le,{className:"w-3.5 h-3.5"}),"Your questions (",m.length,")"]}),e.jsx("div",{className:"space-y-2",children:m.map(t=>{const d=h[t.status]||h.pending,i=d.icon;return e.jsxs("div",{className:"rounded-xl border bg-card p-3 space-y-1.5",children:[e.jsx("p",{className:"text-sm font-medium",children:t.question_text}),e.jsxs("div",{className:g("flex items-center gap-1 text-xs",d.color),children:[e.jsx(i,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:d.label})]}),t.doctor_notes&&e.jsx("p",{className:"text-xs text-muted-foreground bg-muted/40 rounded-md p-2 mt-1 whitespace-pre-wrap",children:t.doctor_notes})]},t.id)})})]}),x.length>0&&e.jsxs("section",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground flex items-center gap-1.5",children:[e.jsx(xe,{className:"w-3.5 h-3.5"}),"AI discussion topics (",x.length,")"]}),e.jsx("div",{className:"space-y-2",children:x.map(t=>{const d=h[t.status]||h.pending,i=d.icon;return e.jsxs("div",{className:"rounded-xl border bg-card p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.priority&&e.jsx("span",{className:g("text-[10px] font-bold px-2 py-0.5 rounded-full border",z[t.priority]||z.LOW),children:t.priority}),t.data_point&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:t.data_point})]}),e.jsx("p",{className:"text-sm font-medium",children:t.topic}),t.detail&&e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:t.detail}),e.jsxs("div",{className:g("flex items-center gap-1 text-xs",d.color),children:[e.jsx(i,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:t.status==="answered"?"Discussed":d.label})]}),t.doctor_notes&&e.jsx("p",{className:"text-xs text-muted-foreground bg-muted/40 rounded-md p-2 mt-1 whitespace-pre-wrap",children:t.doctor_notes})]},t.id)})})]}),m.length===0&&x.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"No open questions or AI topics were resolved at this visit."})]}),!v&&e.jsx("div",{className:"flex justify-end gap-2 pt-2 border-t",children:e.jsx(p,{variant:"outline",onClick:()=>A(!1),children:"Close"})})]})})}export{ke as V};

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.