VirtualPR/frontend/dist/assets/SessionVitalsModal-DDMDFsin.js

2 lines
4.8 KiB
JavaScript

import{r as m,u as I,j as e,c as B,J as A,R as b,l as r,B as N,d as G}from"./index-B92aEPQH.js";import{M as T,a as $,b as V,c as P}from"./Modal-D4T7V4-p.js";import{a as E,F as q}from"./FormCheck-QYGhbIhB.js";import{F as c}from"./FormControl-BhzYseFY.js";const g=m.forwardRef(({className:s,bsPrefix:a,as:l="span",...p},u)=>(a=I(a,"input-group-text"),e.jsx(l,{ref:u,className:B(s,a),...p})));g.displayName="InputGroupText";const O=s=>e.jsx(g,{children:e.jsx(E,{type:"checkbox",...s})}),w=s=>e.jsx(g,{children:e.jsx(E,{type:"radio",...s})}),M=m.forwardRef(({bsPrefix:s,size:a,hasValidation:l,className:p,as:u="div",...x},h)=>{s=I(s,"input-group");const j=m.useMemo(()=>({}),[]);return e.jsx(A.Provider,{value:j,children:e.jsx(u,{ref:h,...x,className:B(p,s,a&&`${s}-${a}`,l&&"has-validation")})})});M.displayName="InputGroup";const f=Object.assign(M,{Text:g,Radio:w,Checkbox:O});function S(){return{bp:"",spo2:"",pulse:""}}function y(s){const[a="",l=""]=String(s||"").split("/").map(p=>p.trim());return{sbp:a,dbp:l}}function D(s,a){const l=String(s??"").trim(),p=String(a??"").trim();return l||p?`${l}/${p}`:""}function v(){return{fev1:"",fvc:"",sixMwt:"",eq5d3l:"",sgrq:"",sitToStand:"",rpeRest:"",rpeActivity:"",o2Regular:"",o2WithExercise:""}}const H=[["fev1","FEV1"],["fvc","FVC"],["sixMwt","6-minute walk"],["eq5d3l","EQ-5D"],["sgrq","SGRQ"],["sitToStand","Sit-to-stand"],["rpeRest","RPE at rest"],["rpeActivity","RPE with activity"],["o2Regular","Oxygen at rest"],["o2WithExercise","Oxygen with exercise"]],C={bp:"",spo2:"",pulse:""};function R(s){return{bp:D(s?.sbp,s?.dbp),spo2:s?.spo2===""||s?.spo2==null?"":Number(s.spo2),pulse:s?.pulse===""||s?.pulse==null?"":Number(s.pulse)}}function Q({value:s,disabled:a,onChange:l}){return e.jsxs(f,{children:[e.jsx(c,{placeholder:"SBP",type:"number",value:s?.sbp??"",disabled:a,onChange:p=>l({...s,sbp:p.target.value})}),e.jsx(f.Text,{children:"/"}),e.jsx(c,{placeholder:"DBP",type:"number",value:s?.dbp??"",disabled:a,onChange:p=>l({...s,dbp:p.target.value})})]})}function W(s){return Number(s)===15||Number(s)===30}function K(s){return s?{...s,records:(s.records||[]).map(a=>({patientId:a.patient?.id,name:a.patient?.name||"Patient",attended:!!a.attended,sessionNo:a.patientSessionNo??null,pre:{...S(),...a.pre,...y(a.pre?.bp),spo2:a.pre?.spo2??"",pulse:a.pre?.pulse??""},post:{...S(),...a.post,...y(a.post?.bp),spo2:a.post?.spo2??"",pulse:a.post?.pulse??""},assessment:{...v(),...a.assessment}}))}:null}function U({roster:s,onChange:a,onClose:l,onSaved:p}){const[u,x]=m.useState(!1),[h,j]=m.useState(""),d=(t,i)=>{const n=[...s.records];n[t]=i,a({...s,records:n})},F=async()=>{j(""),x(!0);try{await G(`/api/cohort-sessions/${s.id}/records`,{method:"PATCH",body:{completed:!0,records:s.records.map(t=>({patientId:t.patientId,attended:t.attended,pre:t.attended?R(t.pre):C,post:t.attended?R(t.post):C,assessment:t.attended?t.assessment:v()}))}}),p?.(),l()}catch(t){j(t.message||"Could not save vitals")}finally{x(!1)}};return e.jsxs(T,{show:!!s,onHide:l,size:"lg",children:[e.jsx($,{closeButton:!0,children:e.jsxs("h5",{className:"modal-title",children:["Attendance and vitals",s?.index?` · cohort session ${s.index}`:""]})}),e.jsxs(V,{children:[h?e.jsx("div",{className:"alert alert-danger",children:h}):null,(s?.records||[]).length?(s.records||[]).map((t,i)=>e.jsxs("div",{className:"border rounded p-3 mb-3",children:[e.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-2",children:[e.jsxs("strong",{children:[t.name,t.sessionNo?e.jsxs("span",{className:"text-muted small ms-2",children:["session ",t.sessionNo]}):null]}),e.jsx(q,{type:"switch",label:"Attended",checked:t.attended,onChange:n=>d(i,{...t,attended:n.target.checked})})]}),e.jsx(b,{className:"g-2",children:["pre","post"].map(n=>e.jsxs(r,{md:6,children:[e.jsx("div",{className:"text-muted text-uppercase small mb-1",children:n}),e.jsxs(b,{className:"g-2",children:[e.jsx(r,{xs:6,children:e.jsx(Q,{value:t[n],disabled:!t.attended,onChange:o=>d(i,{...t,[n]:o})})}),e.jsx(r,{children:e.jsx(c,{placeholder:"SpO2",type:"number",value:t[n].spo2,disabled:!t.attended,onChange:o=>d(i,{...t,[n]:{...t[n],spo2:o.target.value}})})}),e.jsx(r,{children:e.jsx(c,{placeholder:"Pulse",type:"number",value:t[n].pulse,disabled:!t.attended,onChange:o=>d(i,{...t,[n]:{...t[n],pulse:o.target.value}})})})]})]},n))}),W(t.sessionNo)?e.jsx(b,{className:"g-2 mt-2",children:H.map(([n,o])=>e.jsx(r,{md:4,children:e.jsx(c,{placeholder:o,value:t.assessment?.[n]||"",disabled:!t.attended,onChange:k=>d(i,{...t,assessment:{...v(),...t.assessment,[n]:k.target.value}})})},n))}):null]},t.patientId||i)):e.jsx("p",{className:"text-muted mb-0",children:"No patients are assigned to this session yet."})]}),e.jsxs(P,{children:[e.jsx(N,{variant:"light",onClick:l,children:"Close"}),e.jsx(N,{onClick:F,disabled:u||!(s?.records||[]).length,children:u?"Saving...":"Save roster"})]})]})}export{H as A,Q as B,U as S,v as e,K as r,y as s,R as v};