PageSourceSearch

https://lifeto.ai/assets/DoctorSoapDraftReviewQueue-4XMMwSP3.js

js lifeto.ai collected 2026-10-05 12:09:47 UTC 12,309 bytes, 1 lines download raw bytes

1import{q as ne,r,j as e,bx as Z,f as A,bQ as y,v as ie,F as Q,bk as le,L as C,e as ce,u as D,eK as de,cd as ue,cL as me,bA as pe}from"./vendor-BlB_7aU1.js";import{Q as he,a8 as xe,ah as ve,ai as ge,ak as fe,ag as W,a9 as je,ap as _e,aq as Ne,ar as be,D as F,e as O,o as M,f as I,g as P,O as Y,p as V,B as o,z as ee,P as B,X as we,y as Ce}from"./index-CBfKlGil.js";const ae={draft:{label:"Rascunho",className:"bg-muted text-muted-foreground border-border",icon:Q},in_review:{label:"Em revisão",className:"bg-amber-500/15 text-amber-700 border-amber-500/30",icon:ie},changes_requested:{label:"Devolvido",className:"bg-rose-500/15 text-rose-700 border-rose-500/30",icon:y},approved:{label:"Aprovado",className:"bg-emerald-500/15 text-emerald-700 border-emerald-500/30",icon:A},discarded:{label:"Descartado",className:"bg-muted text-muted-foreground/70 border-border line-through",icon:Z}},De=[{key:"in_review",label:"Em revisão"},{key:"draft",label:"Rascunhos"},{key:"changes_requested",label:"Devolvidos"},{key:"approved",label:"Aprovados"},{key:"discarded",label:"Descartados"},{key:"all",label:"Todos"}];function Se(){var J;const{user:s}=he(),k=ne(),[n,S]=r.useState("in_review"),[p,h]=r.useState(""),[T,j]=r.useState(!0),[x,q]=r.useState([]),[v,u]=r.useState(null),[_,g]=r.useState(""),[R,N]=r.useState(null),[E,G]=r.useState(""),[L,b]=r.useState(null),[H,U]=r.useState(""),[i,X]=r.useState(!1),$=async()=>{if(s){j(!0);try{let a=B.from("soap_drafts").select("id, patient_id, appointment_id, doctor_id, status, source, version_number, review_round, sent_to_review_at, changes_requested_at, changes_requested_notes, reviewed_at, approved_consultation_record_id, chief_complaint, diagnosis, ai_model, created_at").eq("doctor_id",s.id).order("created_at",{ascending:!1}).limit(200);n!=="all"&&(a=a.eq("status",n));const{data:c,error:f}=await a;if(f)throw f;const l=c??[],m=Array.from(new Set(l.map(t=>t.patient_id)));let d=new Map;if(m.length){const{data:t}=await B.from("patients").select("id, name").in("id",m);d=new Map((t??[]).map(K=>[K.id,K.name??""]))}q(l.map(t=>({...t,patient_name:d.get(t.patient_id)??null})))}catch(a){we.error("[SoapDraftReviewQueue] load error",a),D.error("Falha ao carregar fila",{description:"Tente recarregar a página em alguns instantes."})}finally{j(!1)}}};r.useEffect(()=>{$()},[s==null?void 0:s.id,n]);const w=r.useMemo(()=>{const a=p.trim().toLowerCase();return a?x.filter(c=>[c.patient_name,c.chief_complaint,c.diagnosis].filter(Boolean).some(f=>f.toLowerCase().includes(a))):x},[x,p]),z=async(a,c,f)=>{X(!0);try{const{error:l}=await B.rpc(a,c);if(l)throw l;return await $(),!0}catch(l){const m=(l==null?void 0:l.message)??"";let d="Não foi possível concluir a ação",t="Verifique o status do rascunho e tente novamente.";return m.includes("invalid_transition_from")?(d="Transição inválida",t="O rascunho já mudou de status. Recarregue a fila para ver o estado atual."):m.includes("forbidden_not_doctor")?(d="Permissão insuficiente",t="Apenas profissionais com perfil de médico podem aprovar rascunhos."):m.includes("forbidden_not_owner")?(d="Você não é o autor do rascunho",t="Apenas o médico que criou o rascunho pode alterá-lo."):m.includes("notes_required")&&(d="Justificativa obrigatória",t="Escreva pelo menos 3 caracteres explicando o que precisa ser corrigido."),D.error(d,{description:t}),!1}finally{X(!1)}},se=async()=>{if(!v)return;await z("approve_soap_draft",{p_draft_id:v.id,p_review_reason:_.trim()||null})&&(u(null),g(""))},re=async()=>{if(!R)return;const a=E.trim();if(a.length<3){D.warning("Escreva o que deve ser corrigido",{description:"A justificativa precisa ter pelo menos 3 caracteres."});return}await z("request_changes_soap_draft",{p_draft_id:R.id,p_notes:a})&&(N(null),G(""))},te=async()=>{if(!L)return;await z("discard_soap_draft",{p_draft_id:L.id,p_reason:H.trim()||"discarded_via_queue"})&&(b(null),U(""))},oe=a=>{if(!a.appointment_id){D.warning("Rascunho sem consulta vinculada",{description:"Abra o prontuário do paciente manualmente para revisar este rascunho."});return}k("/doctor/prontuarios",{state:{appointmentId:a.appointment_id,patientId:a.patient_id,openSoapDraft:!0}})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("header",{className:"flex flex-col gap-2",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",style:{color:"hsl(var(--heading-color))"},children:"Fila de Rascunhos SOAP"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Aprove, devolva para correções ou descarte rascunhos gerados por IA. A aprovação cria uma evolução não-finalizada no prontuário com versão oficial v1 (atribuída a você)."})]}),e.jsxs(xe,{children:[e.jsxs(ve,{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx(ge,{className:"text-base",children:"Triagem"}),e.jsxs(fe,{children:[w.length," rascunho",w.length===1?"":"s"," ",n==="all"?"no total":`em "${(J=ae[n])==null?void 0:J.label.toLowerCase()}"`]})]}),e.jsxs("div",{className:"relative w-full sm:w-72",children:[e.jsx(le,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(W,{placeholder:"Paciente, queixa ou diagnóstico…",value:p,onChange:a=>h(a.target.value),className:"pl-9"})]})]}),e.jsxs(je,{className:"space-y-4",children:[e.jsx(_e,{value:n,onValueChange:a=>S(a),children:e.jsx(Ne,{className:"flex flex-wrap gap-1",children:De.map(a=>e.jsx(be,{value:a.key,children:a.label},a.key))})}),T?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(C,{className:"h-5 w-5 animate-spin mr-2"}),"Carregando rascunhos…"]}):w.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center text-muted-foreground gap-2",children:[e.jsx(Q,{className:"h-10 w-10 opacity-40"}),e.jsx("p",{className:"font-medium",children:"Nenhum rascunho nessa fila"}),e.jsx("p",{className:"text-xs",children:n==="in_review"?"Quando você (ou a Anna) envi
1ar um rascunho para revisão, ele aparece aqui.":"Nada para mostrar com os filtros atuais."})]}):e.jsx("ul",{className:"divide-y rounded-md border bg-card",children:w.map(a=>e.jsx(Ae,{draft:a,onApprove:()=>u(a),onReturn:()=>N(a),onDiscard:()=>b(a),onOpen:()=>oe(a)},a.id))})]})]}),e.jsx(F,{open:!!v,onOpenChange:a=>!a&&u(null),children:e.jsxs(O,{children:[e.jsxs(M,{children:[e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-5 w-5 text-emerald-600"}),"Aprovar rascunho SOAP"]}),e.jsxs(P,{children:["Vai criar uma ",e.jsx("strong",{children:"evolução não-finalizada"})," no prontuário do paciente, com você como autor da versão oficial v1. Você ainda precisa assinar a evolução para ela virar oficial perante o conselho."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Motivo da aprovação (opcional)"}),e.jsx(Y,{value:_,onChange:a=>g(a.target.value),placeholder:"Ex.: Revisado, condiz com a transcrição.",rows:3})]}),e.jsxs(V,{children:[e.jsx(o,{variant:"ghost",onClick:()=>u(null),disabled:i,children:"Cancelar"}),e.jsxs(o,{onClick:se,disabled:i,className:"gap-2",children:[i?e.jsx(C,{className:"h-4 w-4 animate-spin"}):e.jsx(A,{className:"h-4 w-4"}),"Aprovar e criar evolução"]})]})]})}),e.jsx(F,{open:!!R,onOpenChange:a=>!a&&N(null),children:e.jsxs(O,{children:[e.jsxs(M,{children:[e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx(y,{className:"h-5 w-5 text-rose-600"}),"Devolver para correções"]}),e.jsxs(P,{children:["O rascunho volta para edição (status ",e.jsx(ee,{variant:"outline",children:"changes_requested"}),") com a sua justificativa anexada e o contador de revisões avança em 1."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-sm font-medium",children:["O que precisa ser corrigido ",e.jsx("span",{className:"text-rose-600",children:"*"})]}),e.jsx(Y,{value:E,onChange:a=>G(a.target.value),placeholder:"Ex.: A avaliação não menciona o exame de glicemia recente; revise o plano.",rows:4}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Mínimo de 3 caracteres. A justificativa fica visível no histórico do rascunho."})]}),e.jsxs(V,{children:[e.jsx(o,{variant:"ghost",onClick:()=>N(null),disabled:i,children:"Cancelar"}),e.jsxs(o,{variant:"destructive",onClick:re,disabled:i||E.trim().length<3,className:"gap-2",children:[i?e.jsx(C,{className:"h-4 w-4 animate-spin"}):e.jsx(y,{className:"h-4 w-4"}),"Devolver"]})]})]})}),e.jsx(F,{open:!!L,onOpenChange:a=>!a&&b(null),children:e.jsxs(O,{children:[e.jsxs(M,{children:[e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx(ce,{className:"h-5 w-5 text-rose-600"}),"Descartar rascunho?"]}),e.jsxs(P,{children:["O rascunho some da fila ativa, mas o histórico de status é preservado para auditoria LGPD. Esta ação ",e.jsx("strong",{children:"não"})," pode ser desfeita."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Motivo (opcional)"}),e.jsx(W,{value:H,onChange:a=>U(a.target.value),placeholder:"Ex.: Gerado por engano em consulta errada."})]}),e.jsxs(V,{children:[e.jsx(o,{variant:"ghost",onClick:()=>b(null),disabled:i,children:"Cancelar"}),e.jsxs(o,{variant:"destructive",onClick:te,disabled:i,className:"gap-2",children:[i?e.jsx(C,{className:"h-4 w-4 animate-spin"}):e.jsx(Z,{className:"h-4 w-4"}),"Descartar"]})]})]})})]})}function Ae({draft:s,onApprove:k,onReturn:n,onDiscard:S,onOpen:p}){var g;const h=ae[s.status],T=h.icon,j=s.status==="approved"||s.status==="discarded",x=s.status==="draft"||s.status==="in_review",q=s.status==="in_review",v=!j,u=s.sent_to_review_at??s.created_at,_=u?de(new Date(u),{addSuffix:!0,locale:pe}):"—";return e.jsxs("li",{className:"flex flex-col gap-3 p-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ee,{variant:"outline",className:Ce("gap-1",h.className),children:[e.jsx(T,{className:"h-3 w-3"}),h.label]}),e.jsx("span",{className:"text-sm font-medium truncate",children:s.patient_name??"Paciente sem nome"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["v",s.version_number,s.review_round&&s.review_round>0?` · rodada ${s.review_round}`:""]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground line-clamp-2",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Queixa:"})," ",((g=s.chief_complaint)==null?void 0:g.trim())||e.jsx("em",{children:"(em branco)"}),s.diagnosis?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"font-medium text-foreground",children:"Dx:"})," ",s.diagnosis]}):null]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.status==="in_review"?"Enviado ":"Atualizado ",_," · ","fonte: ",s.source," · IA: ",s.ai_model,s.status==="changes_requested"&&s.changes_requested_notes?e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsxs("span",{className:"text-rose-600",children:["Devolvido: ",s.changes_requested_notes.slice(0,120),s.changes_requested_notes.length>120?"…":""]})]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 sm:justify-end shrink-0",children:[e.jsxs(o,{variant:"ghost",size:"sm",onClick:p,className:"gap-1","aria-label":"Abrir editor completo no prontuário",title:"Abrir editor completo no prontuário",children:[e.jsx(ue,{className:"h-4 w-4"}),"Abrir editor"]}),q?e.jsxs(o,{variant:"outline",size:"sm",onClick:n,className:"gap-1","aria-label":"Devolver para correções",children:[e.jsx(y,{className:"h-4 w-4"}),"Devolver"]}):null,x?e.jsxs(o,{size:"sm",onClick:k,className:"gap-1","aria-label":"Aprovar rascunho",children:[e.jsx(A,{className:"h-4 w-4"}),"Aprovar"]}):null,v?e.jsxs(o,{variant:"ghost",size:"sm",onClick:S,className:"gap-1 text-rose-600 hover:text-rose-700","aria-label":"Descartar rascunho",t
1itle:"Descartar rascunho",children:[e.jsx(me,{className:"h-4 w-4"}),"Descartar"]}):null,s.status==="approved"&&s.approved_consultation_record_id?e.jsxs(o,{variant:"ghost",size:"sm",onClick:p,className:"gap-1 text-emerald-700","aria-label":"Ver evolução criada",children:[e.jsx(Q,{className:"h-4 w-4"}),"Ver evolução"]}):null]})]})}export{Se as default};

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.