2 lines
8.2 KiB
JavaScript
2 lines
8.2 KiB
JavaScript
import{r,d as n,j as e,C as F,B as u,R as K,l as E,m as Y}from"./index-B92aEPQH.js";import{P as _}from"./PageBreadcrumb-Dsn9CkpH.js";import{u as G,W as J}from"./useSettings-B5rMnTFQ.js";import{C as b,a as P}from"./Card-DPmHd5BI.js";import{T as M}from"./Table-BCHyhTAY.js";import"./PageMetaData-DFmRpQLs.js";function R(l){return l==null||l===""?"":J[Number(l)]||""}function Q(l,g){const h=l.patientCount||(l.patients||[]).length||0;return(g||[]).filter(c=>!(c.id===l.id||(c.remainingSeats||0)<h||l.language&&c.language&&l.language!==c.language||l.diseaseType&&c.diseaseType&&l.diseaseType!==c.diseaseType))}function le(){const[l,g]=r.useState([]),[h,c]=r.useState([]),[A,I]=r.useState([]),[z,L]=r.useState({}),[j,S]=r.useState({}),[f,w]=r.useState({}),[C,O]=r.useState([]),[W,H]=r.useState([]),[$,p]=r.useState(""),[T,y]=r.useState(""),[k,B]=r.useState([]),[m,x]=r.useState(""),{settings:D}=G(),V=D?.cohortSchedules||[],q=async s=>{const t=[...new Set((s||[]).map(a=>a.virtualPrt?.id).filter(Boolean))],d=await Promise.all(t.map(async a=>{const i=await n(`/api/matching/empty-slots?prtId=${a}`);return[a,i.items||[]]}));L(Object.fromEntries(d))},v=async()=>{const[s,t,d]=await Promise.all([n("/api/matching/pool"),n("/api/matching/proposals"),n("/api/reassignments")]),a=t.items||[];g(s.items||[]),c(a),I(t.mergeTargets||[]),O(d.items||[]),S({}),w({}),await q(a)};r.useEffect(()=>{v().catch(s=>p(s.message)),n("/api/matching/substitutes").then(s=>H(s.items||[])).catch(()=>{})},[]);const U=async()=>{x("run"),p(""),y(""),B([]);try{const s=await n("/api/matching/run",{method:"POST"});y(s.message||`Created ${s.created||0} proposed cohort(s).`),B(s.notes||[]),await v()}catch(s){p(s.message)}finally{x("")}},o=async(s,t,d)=>{x(s),p("");try{await t(),d&&y(d),await v()}catch(a){p(a.message)}finally{x("")}};return e.jsxs(F,{fluid:!0,children:[e.jsx(_,{title:"Matching",subtitle:"Program"}),$?e.jsx("div",{className:"alert alert-danger",children:$}):null,T?e.jsx("div",{className:"alert alert-success",children:T}):null,k.length?e.jsx("div",{className:"alert alert-warning",children:e.jsx("ul",{className:"mb-0 ps-3",children:k.map(s=>e.jsx("li",{children:s},s))})}):null,e.jsxs("div",{className:"d-flex flex-wrap gap-2 mb-3",children:[e.jsx(u,{onClick:U,disabled:m==="run",children:m==="run"?"Matching...":"Run matching now"}),e.jsx(u,{variant:"outline-primary",disabled:!h.length||m,onClick:()=>o("confirm",()=>n("/api/matching/confirm-all",{method:"POST"}),"All proposals confirmed."),children:"Confirm all proposals"})]}),e.jsxs(K,{className:"g-3",children:[e.jsx(E,{lg:5,children:e.jsx(b,{children:e.jsxs(P,{children:[e.jsxs("h5",{className:"mb-3",children:["Unassigned pool (",l.length,")"]}),e.jsxs(M,{responsive:!0,size:"sm",className:"mb-0",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Patient"}),e.jsx("th",{children:"Match key"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[l.map(s=>e.jsxs("tr",{children:[e.jsxs("td",{children:[e.jsx("div",{className:"fw-semibold",children:s.name}),e.jsx("div",{className:"text-muted small",children:s.mobile})]}),e.jsx("td",{className:"small",children:[s.sessionLanguage,s.slot,R(s.preferredWeekday),s.diseaseType].filter(Boolean).join(" · ")}),e.jsx("td",{children:e.jsx(u,{size:"sm",variant:"outline-secondary",onClick:()=>o(`hold-${s.id}`,()=>n(`/api/matching/patients/${s.id}`,{method:"PATCH",body:{action:"hold"}})),children:"Return to pool"})})]},s.id)),l.length?null:e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"text-muted",children:"No patients waiting for matching."})})]})]})]})})}),e.jsxs(E,{lg:7,children:[e.jsx(b,{className:"mb-3",children:e.jsxs(P,{children:[e.jsx("h5",{className:"mb-3",children:"Proposed cohorts"}),h.map(s=>{const t=Q(s,A),d=z[s.virtualPrt?.id]||[];return e.jsxs("div",{className:"border rounded p-3 mb-3",children:[e.jsxs("div",{className:"d-flex justify-content-between gap-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"fw-semibold",children:s.name}),e.jsx("div",{className:"text-muted small",children:[s.slot,R(s.weekday),s.language,s.diseaseType,s.virtualPrt?`${s.virtualPrt.firstName} ${s.virtualPrt.lastName}`:""].filter(Boolean).join(" · ")})]}),e.jsx(u,{size:"sm",disabled:m,onClick:()=>o(`confirm-${s.id}`,()=>n(`/api/matching/proposals/${s.id}/confirm`,{method:"POST"}),`${s.name} confirmed.`),children:"Confirm"})]}),e.jsxs("select",{className:"form-select form-select-sm mt-2",style:{maxWidth:280},value:s.scheduleId||"",disabled:!!m,onChange:a=>o(`schedule-${s.id}`,()=>n(`/api/matching/proposals/${s.id}/schedule`,{method:"PATCH",body:{scheduleId:a.target.value}})),children:[e.jsx("option",{value:"",children:"Normal (current)"}),V.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]}),e.jsx("div",{className:"small mt-2",children:(s.patients||[]).map(a=>e.jsxs("div",{className:"d-flex justify-content-between align-items-center py-1",children:[e.jsx("span",{children:a.name}),e.jsxs("select",{className:"form-select form-select-sm",style:{width:220},defaultValue:"",onChange:async i=>{const N=i.target.value;N&&await o(`move-${a.id}`,async()=>{N==="hold"?await n(`/api/matching/patients/${a.id}`,{method:"PATCH",body:{action:"hold"}}):await n(`/api/matching/patients/${a.id}`,{method:"PATCH",body:{action:"move",cohortId:N}})})},children:[e.jsx("option",{value:"",children:"Move / return to pool"}),e.jsx("option",{value:"hold",children:"Return to pool"}),h.filter(i=>i.id!==s.id).map(i=>e.jsx("option",{value:i.id,children:i.name},i.id))]})]},a.id))}),e.jsxs("div",{className:"d-flex flex-wrap gap-2 align-items-center mt-3",children:[e.jsxs("select",{className:"form-select form-select-sm",style:{minWidth:220},value:j[s.id]||"",onChange:a=>S(i=>({...i,[s.id]:a.target.value})),children:[e.jsx("option",{value:"",children:"Merge into existing"}),t.map(a=>e.jsxs("option",{value:a.id,children:[a.name," · ",a.remainingSeats," seat",a.remainingSeats===1?"":"s"]},a.id))]}),e.jsx(u,{size:"sm",variant:"outline-secondary",disabled:!j[s.id]||m,onClick:()=>o(`merge-${s.id}`,()=>n(`/api/matching/proposals/${s.id}/merge`,{method:"POST",body:{cohortId:j[s.id]}}),`${s.name} merged.`),children:"Merge"})]}),t.length?null:e.jsx("div",{className:"text-muted small mt-1",children:"No compatible cohort with enough seats."}),e.jsxs("div",{className:"d-flex flex-wrap gap-2 align-items-center mt-2",children:[e.jsxs("select",{className:"form-select form-select-sm",style:{minWidth:220},value:f[s.id]||"",onChange:a=>w(i=>({...i,[s.id]:a.target.value})),children:[e.jsx("option",{value:"",children:"Use empty slot"}),d.map(a=>e.jsxs("option",{value:a.key,children:[a.weekdayLabel," · ",a.slot]},a.key))]}),e.jsx(u,{size:"sm",variant:"outline-secondary",disabled:!f[s.id]||m,onClick:()=>{const[a,i]=(f[s.id]||"").split("|");return o(`slot-${s.id}`,()=>n(`/api/matching/proposals/${s.id}`,{method:"PATCH",body:{weekday:Number(a),slot:i}}),`${s.name} moved to an empty slot.`)},children:"Save slot"})]}),d.length?null:e.jsx("div",{className:"text-muted small mt-1",children:"No empty weekday + slot for this Virtual PRT."})]},s.id)}),h.length?null:e.jsx("p",{className:"text-muted mb-0",children:"No proposed matches. Run matching or create a cohort manually."})]})}),e.jsx(b,{children:e.jsxs(P,{children:[e.jsx("h5",{className:"mb-3",children:"Reassignment queue"}),e.jsxs(M,{responsive:!0,size:"sm",className:"mb-0",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Cohort"}),e.jsx("th",{children:"From"}),e.jsx("th",{children:"Assign"})]})}),e.jsxs("tbody",{children:[C.map(s=>e.jsxs("tr",{children:[e.jsx("td",{children:s.cohort?.name||"—"}),e.jsx("td",{children:s.fromPrt?`${s.fromPrt.firstName} ${s.fromPrt.lastName}`:"—"}),e.jsx("td",{children:e.jsxs("select",{className:"form-select form-select-sm",defaultValue:"",onChange:t=>{t.target.value&&o(`reassign-${s.id}`,()=>n(`/api/reassignments/${s.id}/resolve`,{method:"POST",body:{toPrtId:t.target.value}}))},children:[e.jsx("option",{value:"",children:"Select substitute"}),W.map(t=>e.jsxs("option",{value:t.id,children:[t.firstName," ",t.lastName]},t.id))]})})]},s.id)),C.length?null:e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"text-muted",children:"No open reassignments."})})]})]}),e.jsx("div",{className:"mt-3",children:e.jsx(Y,{to:"/cohorts/new",children:"Create a cohort manually"})})]})})]})]})]})}export{le as default};
|