2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
import{r as v,j as e,C as $,R as S,l as m,B as x,p as w,s as R,d as q}from"./index-B92aEPQH.js";import{P as z}from"./PageBreadcrumb-Dsn9CkpH.js";import{W}from"./useSettings-B5rMnTFQ.js";import{C as P,a as D}from"./Card-DPmHd5BI.js";import{F as c}from"./FormLabel-DFBiGE9d.js";import{F as N}from"./FormCheck-QYGhbIhB.js";import{F as u}from"./FormControl-BhzYseFY.js";import"./PageMetaData-DFmRpQLs.js";import"./FormContext-IkkKm1bh.js";function E(a){return String(a).padStart(2,"0")}function M(a,i){const[h,p]=String(a||"08:00").split(":").map(Number),g=(Number.isNaN(h)?8:h)*60+(Number.isNaN(p)?0:p)+Number(i||60);return`${E(Math.floor(g/60)%24)}:${E(g%60)}`}function _(){return{slots:[],slotDurationMinutes:60,cohortStartWeekdays:[1,2],repeatIntervalDays:2,upcomingSessionCount:30,defaultDurationMinutes:60,skipHolidays:!0,skipPrtLeave:!0,languages:[],paymentStatuses:[],genders:[],diseaseTypes:["ILD","OAD"],maxPatientsPerCohort:10,maxCohortsPerPrt:3,matchingPriority:["language","slot","weekday","disease"],matchingCron:"0 7 * * 6",piiRetentionDays:365,cohortSchedules:[]}}function b({label:a,items:i,onChange:h,placeholder:p}){return e.jsxs("div",{className:"mb-4",children:[e.jsx(c,{children:a}),i.map((g,j)=>e.jsxs("div",{className:"d-flex gap-2 mb-2",children:[e.jsx(u,{value:g,onChange:C=>h(i.map((y,o)=>o===j?C.target.value:y)),required:!0}),e.jsx(x,{type:"button",variant:"outline-danger",size:"sm",className:"btn-icon",onClick:()=>h(i.filter((C,y)=>y!==j)),disabled:i.length<=1,children:e.jsx(w,{className:"fs-lg"})})]},j)),e.jsxs(x,{type:"button",variant:"light",size:"sm",onClick:()=>h([...i,p||""]),children:[e.jsx(R,{className:"me-1"})," Add"]})]})}function ee(){const[a,i]=v.useState(_),[h,p]=v.useState(""),[g,j]=v.useState(""),[C,y]=v.useState(!1),o=(s,t)=>i(n=>({...n,[s]:t})),L=async()=>{const s=await q("/api/settings");i({slots:(s.slots||[]).map(t=>({start:t.start,end:t.end})),slotDurationMinutes:s.slotDurationMinutes||60,cohortStartWeekdays:s.cohortStartWeekdays||[1,2],repeatIntervalDays:s.repeatIntervalDays||2,upcomingSessionCount:s.upcomingSessionCount||30,defaultDurationMinutes:s.defaultDurationMinutes||60,skipHolidays:s.skipHolidays!==!1,skipPrtLeave:s.skipPrtLeave!==!1,languages:s.languages||[],paymentStatuses:s.paymentStatuses||[],genders:s.genders||[],diseaseTypes:s.diseaseTypes||["ILD","OAD"],maxPatientsPerCohort:s.maxPatientsPerCohort||10,maxCohortsPerPrt:s.maxCohortsPerPrt||3,matchingPriority:s.matchingPriority||["language","slot","weekday","disease"],matchingCron:s.matchingCron||"0 7 * * 6",piiRetentionDays:s.piiRetentionDays||365,cohortSchedules:(s.cohortSchedules||[]).map(t=>({id:t.id||"",name:t.name||"",weekdays:t.weekdays||[],upcomingSessionCount:t.upcomingSessionCount||s.upcomingSessionCount||30}))})};v.useEffect(()=>{L().catch(s=>p(s.message))},[]);const T=(s,t,n)=>{i(r=>({...r,slots:r.slots.map((l,d)=>{if(d!==s)return l;const f={...l,[t]:n};return t==="start"&&(f.end=M(n,r.slotDurationMinutes)),f})}))},A=s=>{i(t=>({...t,slotDurationMinutes:s,slots:t.slots.map(n=>({...n,end:M(n.start,s)}))}))},B=s=>{i(t=>{const r=t.cohortStartWeekdays.includes(s)?t.cohortStartWeekdays.filter(l=>l!==s):[...t.cohortStartWeekdays,s].sort((l,d)=>l-d);return{...t,cohortStartWeekdays:r}})},F=async s=>{s.preventDefault(),p(""),j(""),y(!0);try{await q("/api/settings",{method:"PATCH",body:{...a,slotDurationMinutes:Number(a.slotDurationMinutes),repeatIntervalDays:Number(a.repeatIntervalDays),upcomingSessionCount:Number(a.upcomingSessionCount),defaultDurationMinutes:Number(a.defaultDurationMinutes),maxPatientsPerCohort:Number(a.maxPatientsPerCohort),piiRetentionDays:Number(a.piiRetentionDays),maxCohortsPerPrt:Number(a.maxCohortsPerPrt),languages:a.languages.map(t=>t.trim()).filter(Boolean),paymentStatuses:a.paymentStatuses.map(t=>t.trim()).filter(Boolean),genders:a.genders.map(t=>t.trim()).filter(Boolean),diseaseTypes:a.diseaseTypes.map(t=>t.trim()).filter(Boolean),matchingPriority:a.matchingPriority.map(t=>t.trim()).filter(Boolean),cohortSchedules:(a.cohortSchedules||[]).map(t=>({id:t.id,name:t.name,weekdays:t.weekdays,upcomingSessionCount:Number(t.upcomingSessionCount)||Number(a.upcomingSessionCount)||30}))}}),await L(),j("Settings saved.")}catch(t){p(t.message)}finally{y(!1)}};return e.jsxs($,{fluid:!0,children:[e.jsx(z,{title:"Settings",subtitle:"Administration"}),h?e.jsx("div",{className:"alert alert-danger",children:h}):null,g?e.jsx("div",{className:"alert alert-success",children:g}):null,e.jsxs("form",{onSubmit:F,children:[e.jsxs(S,{className:"g-3",children:[e.jsxs(m,{lg:7,children:[e.jsx(P,{className:"mb-3",children:e.jsxs(D,{children:[e.jsx("h5",{className:"mb-2",children:"Cohort schedule"}),e.jsx("p",{className:"text-muted",children:"Rules used when creating a cohort and generating repeat meetings."}),e.jsx(c,{children:"Days a new cohort can start"}),e.jsx("div",{className:"d-flex flex-wrap gap-3 mb-3",children:W.map((s,t)=>e.jsx(N,{type:"checkbox",id:`weekday-${t}`,label:t===0?`${s} (always skipped)`:s,checked:t!==0&&a.cohortStartWeekdays.includes(t),disabled:t===0,onChange:()=>B(t)},s))}),e.jsxs(S,{className:"g-3",children:[e.jsxs(m,{md:4,children:[e.jsx(c,{children:"Repeat every (days)"}),e.jsx(u,{type:"number",min:1,max:30,value:a.repeatIntervalDays,onChange:s=>o("repeatIntervalDays",s.target.value),required:!0}),e.jsx("div",{className:"form-text",children:"1 = daily, 2 = every other day."})]}),e.jsxs(m,{md:4,children:[e.jsx(c,{children:"Meetings per cohort"}),e.jsx(u,{type:"number",min:1,max:60,value:a.upcomingSessionCount,onChange:s=>o("upcomingSessionCount",s.target.value),required:!0}),e.jsx("div",{className:"form-text",children:"Repeat Google Meet series length for each cohort."})]}),e.jsxs(m,{md:4,children:[e.jsx(c,{children:"Meeting length (minutes)"}),e.jsx(u,{type:"number",min:15,max:180,value:a.defaultDurationMinutes,onChange:s=>o("defaultDurationMinutes",s.target.value),required:!0})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(c,{children:"Extra schedules"}),e.jsx("p",{className:"text-muted small mb-2",children:"Normal stays the Repeat every rule and the Meetings per cohort number above. Each extra schedule has its own Meetings per cohort. A skipped holiday or leave does not count as a meeting."}),(a.cohortSchedules||[]).map((s,t)=>e.jsxs("div",{className:"border rounded p-3 mb-2",children:[e.jsxs("div",{className:"d-flex gap-2 mb-2",children:[e.jsx(u,{value:s.name,placeholder:"Schedule name",onChange:n=>i(r=>({...r,cohortSchedules:r.cohortSchedules.map((l,d)=>d===t?{...l,name:n.target.value}:l)})),required:!0}),e.jsx(x,{type:"button",variant:"outline-danger",size:"sm",className:"btn-icon",onClick:()=>i(n=>({...n,cohortSchedules:n.cohortSchedules.filter((r,l)=>l!==t)})),children:e.jsx(w,{className:"fs-lg"})})]}),e.jsxs("div",{className:"mb-2",style:{maxWidth:220},children:[e.jsx(c,{children:"Meetings per cohort"}),e.jsx(u,{type:"number",min:1,max:60,value:s.upcomingSessionCount,onChange:n=>i(r=>({...r,cohortSchedules:r.cohortSchedules.map((l,d)=>d===t?{...l,upcomingSessionCount:n.target.value}:l)})),required:!0})]}),e.jsx("div",{className:"d-flex flex-wrap gap-3",children:W.map((n,r)=>e.jsx(N,{type:"checkbox",id:`schedule-${t}-${r}`,label:r===0?`${n} (always skipped)`:n,checked:r!==0&&(s.weekdays||[]).includes(r),disabled:r===0,onChange:()=>i(l=>({...l,cohortSchedules:l.cohortSchedules.map((d,f)=>{if(f!==t)return d;const I=(d.weekdays||[]).includes(r)?d.weekdays.filter(k=>k!==r):[...d.weekdays||[],r].sort((k,H)=>k-H);return{...d,weekdays:I}})}))},n))})]},s.id||t)),e.jsxs(x,{type:"button",variant:"light",size:"sm",onClick:()=>i(s=>({...s,cohortSchedules:[...s.cohortSchedules||[],{id:"",name:"",weekdays:[1],upcomingSessionCount:Number(s.upcomingSessionCount)||30}]})),children:[e.jsx(R,{className:"me-1"})," Add schedule"]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(N,{type:"switch",id:"skipHolidays",label:"Push (extend) sessions that fall on a holiday",checked:a.skipHolidays,onChange:s=>o("skipHolidays",s.target.checked)}),e.jsx(N,{type:"switch",id:"skipPrtLeave",label:"Push (extend) sessions that fall on approved Virtual PRT leave",checked:a.skipPrtLeave,onChange:s=>o("skipPrtLeave",s.target.checked)})]}),e.jsxs(S,{className:"g-3 mt-1",children:[e.jsxs(m,{md:4,children:[e.jsx(c,{children:"Delete rejected/unpaid after (days)"}),e.jsx(u,{type:"number",min:1,max:3650,value:a.piiRetentionDays,onChange:s=>o("piiRetentionDays",s.target.value),required:!0})]}),e.jsxs(m,{md:4,children:[e.jsx(c,{children:"Max patients per cohort"}),e.jsx(u,{type:"number",min:1,max:40,value:a.maxPatientsPerCohort,onChange:s=>o("maxPatientsPerCohort",s.target.value),required:!0})]}),e.jsxs(m,{md:4,children:[e.jsx(c,{children:"Saturday matching cron"}),e.jsx(u,{value:a.matchingCron,onChange:s=>o("matchingCron",s.target.value),required:!0})]})]})]})}),e.jsx(P,{children:e.jsxs(D,{children:[e.jsx("h5",{className:"mb-2",children:"Slots"}),e.jsx("p",{className:"text-muted",children:"These ranges appear on cohort, onboarding, and session forms."}),e.jsx(S,{className:"g-3 mb-3",children:e.jsxs(m,{md:4,children:[e.jsx(c,{children:"Slot length (minutes)"}),e.jsx(u,{type:"number",min:15,max:180,value:a.slotDurationMinutes,onChange:s=>A(Number(s.target.value)||60),required:!0})]})}),a.slots.map((s,t)=>e.jsxs(S,{className:"g-2 align-items-end mb-2",children:[e.jsxs(m,{md:4,children:[t===0?e.jsx(c,{children:"Start"}):null,e.jsx(u,{type:"time",value:s.start,onChange:n=>T(t,"start",n.target.value),required:!0})]}),e.jsxs(m,{md:4,children:[t===0?e.jsx(c,{children:"End"}):null,e.jsx(u,{type:"time",value:s.end,onChange:n=>T(t,"end",n.target.value),required:!0})]}),e.jsxs(m,{md:4,className:"d-flex align-items-end pb-1",children:[e.jsxs("span",{className:"text-muted me-auto",children:[s.start,"–",s.end]}),e.jsx(x,{type:"button",variant:"outline-danger",size:"sm",className:"btn-icon",onClick:()=>o("slots",a.slots.filter((n,r)=>r!==t)),disabled:a.slots.length<=1,children:e.jsx(w,{className:"fs-lg"})})]})]},t)),e.jsxs(x,{type:"button",variant:"light",className:"mt-2",onClick:()=>{const t=a.slots[a.slots.length-1]?.end||"08:00";o("slots",[...a.slots,{start:t,end:M(t,a.slotDurationMinutes)}])},children:[e.jsx(R,{className:"me-1"})," Add slot"]})]})})]}),e.jsx(m,{lg:5,children:e.jsx(P,{children:e.jsxs(D,{children:[e.jsx("h5",{className:"mb-2",children:"Form lists"}),e.jsx("p",{className:"text-muted",children:"Dropdown options used on patient and master patient forms."}),e.jsx(b,{label:"Languages",items:a.languages,onChange:s=>o("languages",s),placeholder:"Language"}),e.jsx(b,{label:"Genders",items:a.genders,onChange:s=>o("genders",s),placeholder:"Gender"}),e.jsx(b,{label:"Categories",items:a.diseaseTypes,onChange:s=>o("diseaseTypes",s),placeholder:"Category"}),e.jsx(b,{label:"Payment statuses",items:a.paymentStatuses,onChange:s=>o("paymentStatuses",s),placeholder:"Status"}),e.jsx(b,{label:"Matching priority",items:a.matchingPriority,onChange:s=>o("matchingPriority",s),placeholder:"language"})]})})})]}),e.jsx("div",{className:"mt-3",children:e.jsx(x,{type:"submit",disabled:C,children:C?"Saving...":"Save settings"})})]})]})}export{ee as default};
|