2 lines
3.1 KiB
JavaScript
2 lines
3.1 KiB
JavaScript
import{r as p,d as h,j as e,B as u}from"./index-DGCPJq4z.js";import{F as g}from"./FormLabel-DoSLr8ng.js";import{F as m}from"./FormCheck-tmQhdIFS.js";import{M as f,a as x,b as j,c as C}from"./Modal-DBjPCxyq.js";function y({cohortId:o,value:t,onChange:n}){const[r,s]=p.useState([]),c=t.status==="cancelled"&&t.original!=="cancelled";p.useEffect(()=>{if(!c)return;let a=!0;return h("/api/cohorts?status=active&limit=100").then(l=>{a&&s((l.items||[]).filter(d=>d.id!==o))}).catch(()=>{a&&s([])}),()=>{a=!1}},[c,o]);const i=a=>n({...t,...a});return e.jsxs(e.Fragment,{children:[e.jsx(g,{children:"Status"}),e.jsxs("select",{className:"form-select",value:t.status,onChange:a=>i({status:a.target.value}),children:[e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"completed",children:"Completed"}),e.jsx("option",{value:"cancelled",children:"Cancelled"})]}),c?e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"form-text mb-1",children:"Upcoming sessions stop. Where should the patients go?"}),e.jsx(m,{type:"radio",id:"cancel-pool",name:"cancelAction",label:"Move all patients to the unassigned pool",checked:t.patientAction==="pool",onChange:()=>i({patientAction:"pool"})}),e.jsx(m,{type:"radio",id:"cancel-move",name:"cancelAction",label:"Move all patients to an existing cohort",checked:t.patientAction==="move",onChange:()=>i({patientAction:"move"})}),t.patientAction==="move"?e.jsxs("select",{className:"form-select mt-2",value:t.targetCohortId,onChange:a=>i({targetCohortId:a.target.value}),children:[e.jsx("option",{value:"",children:"Select cohort"}),r.map(a=>{const l=[a.virtualPrt?.firstName,a.virtualPrt?.lastName].filter(Boolean).join(" "),d=[a.name,l,`${a.patientCount} patients`].filter(Boolean).join(" · ");return e.jsx("option",{value:a.id,children:d},a.id)})]}):null]}):null]})}function M(o){const t=o?.status==="confirmed"?"active":o?.status||"active";return{original:t,status:t,patientAction:"pool",targetCohortId:""}}function N(o){return o?.status==="cancelled"&&o.original!=="cancelled"&&o.patientAction==="move"&&!o.targetCohortId?"Select the cohort to move the patients into.":""}async function F(o,t,{force:n=!1}={}){!t||t.status===t.original||await h(`/api/cohorts/${o}/status`,{method:"POST",body:{status:t.status,patientAction:t.patientAction,targetCohortId:t.targetCohortId||null,force:n}})}async function I(o,t){return!t||t.status===t.original||t.status!=="cancelled"||t.patientAction!=="move"?[]:(await h(`/api/cohorts/${o}/status`,{method:"POST",body:{status:t.status,patientAction:t.patientAction,targetCohortId:t.targetCohortId||null,check:!0}}))?.warnings||[]}function k({warnings:o,busy:t,onCancel:n,onConfirm:r}){return e.jsxs(f,{show:o.length>0,onHide:n,children:[e.jsx(x,{closeButton:!0,children:e.jsx("h5",{className:"modal-title",children:"Target cohort does not fully match"})}),e.jsxs(j,{children:[e.jsx("ul",{className:"mb-2 ps-3",children:o.map(s=>e.jsx("li",{children:s},s))}),"Do you still want to move the patients?"]}),e.jsxs(C,{children:[e.jsx(u,{variant:"light",onClick:n,children:"Cancel"}),e.jsx(u,{variant:"warning",disabled:t,onClick:r,children:t?"Saving…":"Move anyway"})]})]})}export{y as C,k as a,N as b,M as c,I as d,F as s};
|