PageSourceSearch

https://smadar.ai/assets/MedicalRecords-B1b2gsFh.js

js smadar.ai collected 2026-10-05 15:06:34 UTC 10,539 bytes, 4 lines download raw bytes

1import{b as A,f as Q,u as K,e as c,g as O,s as i,aj as d,j as e,B as $,i as M,S as G,C as k,h as S,F as H}from"./index-BoPK12rZ.js";import{B as f}from"./badge-Dzgcftu_.js";import{D as J,a as X,b as Y,c as Z,d as V}from"./dialog-By_dUouJ.js";import{F as B}from"./folder-open-C_qrhCxL.js";import{U as E}from"./upload-C8ESeIAY.js";import{U as W}from"./user-BOOKI8Fb.js";import{B as ee}from"./building-2-uabQeOaa.js";import{C as se}from"./calendar-days-Ghlhkcyw.js";import{P as ae}from"./pill-DyW1TgDo.js";import{C as te}from"./chevron-up-BRs2jkXF.js";import{C as ne}from"./chevron-down-BAeWndFz.js";import{M as re}from"./message-circle-ZpEgKGux.js";import{C as ie}from"./circle-check-BHOaP-8t.js";import{C as oe}from"./circle-x-BuNTa0rd.js";import{R as le}from"./refresh-cw-DOixBuok.js";import"./index-BAk_bO_9.js";import"./index-DR_KIw6N.js";import"./index-DuY6vpjC.js";const $e=()=>{const{t:a,language:m}=A(),p=m==="he",l=Q(),C=K(),j=c.useRef(null),[o,y]=c.useState(!1),[N,x]=c.useState(!1),[w,_]=c.useState(new Set),[b,g]=c.useState(new Set),{data:D=[],isLoading:P}=O({queryKey:["medical-records"],queryFn:async()=>{const{data:{user:s}}=await i.auth.getUser();if(!s)return[];const{data:n,error:r}=await i.from("medical_records").select("*").eq("user_id",s.id).order("created_at",{ascending:!1});if(r)throw r;return n||[]}}),v=c.useCallback(async(s,n,r)=>{g(t=>new Set(t).add(s));try{const{data:t,error:u}=await i.functions.invoke("process-medical-document",{body:{file_url:n,record_id:s,user_id:r}});if(u)throw u;if(t!=null&&t.success)d.success(a(`המסמך עובד! זוהו ${t.appointments_count??0} פגישות ו-${t.medications_count??0} תרופות`,`Document processed! Found ${t.appointments_count??0} appointments and ${t.medications_count??0} medications`));else if(t!=null&&t.message)d.info(t.message);else throw new Error((t==null?void 0:t.error)||"Unknown error")}catch(t){console.error("Processing error:",t),d.error(a("שגיאה בעיבוד המסמך. ניתן לנסות שוב.","Document processing failed. You can retry."))}finally{g(t=>{const u=new Set(t);return u.delete(s),u}),l.invalidateQueries({queryKey:["medical-records"]})}},[l,a]),q=c.useCallback(async s=>{var r;if(!["application/pdf","image/jpeg","image/png","image/webp"].includes(s.type)&&!s.name.match(/\.(pdf|jpg|jpeg|png|webp)$/i)){d.error(a("סוג קובץ לא נתמך","Unsupported file type"));return}if(s.size>50*1024*1024){d.error(a("הקובץ גדול מדי (מקסימום 50MB)","File too large (max 50MB)"));return}x(!0);try{const{data:{user:t}}=await i.auth.getUser();if(!t)throw new Error("Not authenticated");const u=((r=s.name.split(".").pop())==null?void 0:r.replace(/[^a-zA-Z0-9]/g,""))||"bin",U=`${t.id}/${Date.now()}.${u}`,{error:F}=await i.storage.from("documents").upload(U,s);if(F)throw F;const{data:h}=await i.storage.from("documents").createSignedUrl(U,3600);if(!(h!=null&&h.signedUrl))throw new Error("Could not get file URL");const{data:z,error:R}=await i.from("medical_records").insert({user_id:t.id,file_name:s.name,file_url:h.signedUrl,storage_path:U,processing_status:"processing"}).select("id").single();if(R)throw R;y(!1),d.success(a("הקובץ הועלה בהצלחה","File uploaded successfully")),l.invalidateQueries({queryKey:["medical-records"]}),v(z.id,h.signedUrl,t.id)}catch(t){console.error("Upload error:",t),d.error(a("שגיאה בהעלאה","Upload failed"))}finally{x(!1)}},[v,l,a]),L=c.useCallback(async s=>{if(s.processing_status==="processing"||s.processing_status==="completed")return;const{data:{user:n}}=await i.auth.getUser();if(!n)return;let r=s.file_url;if(s.storage_path){const{data:t}=await i.storage.from("documents").createSignedUrl(s.storage_path,3600);t!=null&&t.signedUrl&&(r=t.signedUrl)}if(!r){d.error(a("לא ניתן לאתר את הקובץ","File not found"));return}await i.from("medical_records").update({processing_status:"processing"}).eq("id",s.id),l.invalidateQueries({queryKey:["medical-records"]}),v(s.id,r,n.id)},[v,l,a]),I=s=>{_(n=>{const r=new Set(n);return r.has(s)?r.delete(s):r.add(s),r})},T=s=>s.processing_status==="processing"||b.has(s.id);return e.jsx("div",{className:"min-h-screen bg-background p-4 pb-24",dir:p?"rtl":"ltr",children:e.jsxs("div",{className:"max-w-lg mx-auto 
1space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(B,{className:"h-7 w-7 text-primary"}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:a("רשומות רפואיות","Medical Records")})]}),e.jsxs(J,{open:o,onOpenChange:y,children:[e.jsx(X,{asChild:!0,children:e.jsxs($,{size:"sm",children:[e.jsx(E,{className:"h-4 w-4 me-1"}),a("העלאה","Upload")]})}),e.jsxs(Y,{className:"max-w-sm",children:[e.jsx(Z,{children:e.jsx(V,{children:a("העלאת מסמך רפואי","Upload Medical Document")})}),e.jsx("div",{className:"border-2 border-dashed rounded-xl p-8 text-center cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>{var s;return(s=j.current)==null?void 0:s.click()},children:N?e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{className:"h-8 w-8 animate-spin mx-auto text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("מעלה...","Uploading...")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-8 w-8 mx-auto text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("לחץ לבחירת קובץ","Click to select file")}),e.jsxs("p",{className:"text-xs text-muted-foreground/70",children:["PDF, JPG, PNG · ",a("עד 50MB","Up to 50MB")]})]})}),e.jsx("input",{ref:j,type:"file",className:"hidden",accept:".pdf,.jpg,.jpeg,.png,.webp",onChange:s=>{var r;const n=(r=s.target.files)==null?void 0:r[0];n&&q(n),s.target.value=""}})]})]})]}),e.jsx(G,{className:"h-[calc(100vh-180px)]",children:e.jsx("div",{className:"space-y-3",children:P?Array.from({length:3}).map((s,n)=>e.jsx(k,{children:e.jsxs(S,{className:"p-4 space-y-2 animate-pulse",children:[e.jsx("div",{className:"h-4 bg-muted rounded w-3/4"}),e.jsx("div",{className:"h-3 bg-muted rounded w-1/2"}),e.jsx("div",{className:"h-3 bg-muted rounded w-full"})]})},n)):D.length===0?e.jsx(k,{children:e.jsxs(S,{className:"p-8 text-center text-muted-foreground",children:[e.jsx(B,{className:"h-10 w-10 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"font-medium",children:a("אין מסמכים עדיין","No documents yet")}),e.jsx("p",{className:"text-sm mt-1",children:a("העלה מסמכים רפואיים לניתוח אוטומטי","Upload medical documents for automatic analysis")})]})}):D.map(s=>e.jsx(ce,{record:s,isProcessing:T(s),isExpanded:w.has(s.id),onToggleExpand:()=>I(s.id),onRetry:()=>L(s),onAskSmadar:n=>{const r=[n.file_name&&`מסמך: ${n.file_name}`,n.document_type&&`סוג: ${n.document_type}`,n.doctor_name&&`רופא: ${n.doctor_name}`,n.institution&&`מוסד: ${n.institution}`,n.summary&&`סיכום: ${n.summary}`].filter(Boolean).join(`
2`);C("/ai-chat",{state:{prefill:a(`אני רוצה לשאול על המסמך הרפואי הבא:
3${r}`,`I want to ask about this medical document:
4${r}`)}})},t:a,language:m},s.id))})})]})})},ce=({record:a,isProcessing:m,isExpanded:p,onToggleExpand:l,onRetry:C,onAskSmadar:j,t:o,language:y})=>{var w,_,b,g;const N=((_=(w=a.auto_extracted_items)==null?void 0:w.appointments)==null?void 0:_.length)??0,x=((g=(b=a.auto_extracted_items)==null?void 0:b.medications)==null?void 0:g.length)??0;return e.jsx(k,{className:m?"animate-pulse":"",children:e.jsxs(S,{className:"p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(H,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("p",{className:"text-sm font-medium truncate text-foreground",children:a.file_name||o("מסמך ללא שם","Untitled document")})]}),e.jsx(de,{status:m?"processing":a.processing_status,onRetry:C,t:o})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[a.document_type&&e.jsx(f,{variant:"secondary",className:"text-[10px]",children:a.document_type}),a.doctor_name&&e.jsxs(f,{variant:"outline",className:"text-[10px] gap-1",children:[e.jsx(W,{className:"h-2.5 w-2.5"}),a.doctor_name]}),a.institution&&e.jsxs(f,{variant:"outline",className:"text-[10px] gap-1",children:[e.jsx(ee,{className:"h-2.5 w-2.5"}),a.institution]}),N>0&&e.jsxs(f,{className:"text-[10px] gap-1 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300",children:[e.jsx(se,{className:"h-2.5 w-2.5"}),N," ",o("פגישות","appointments")]}),x>0&&e.jsxs(f,{className:"text-[10px] gap-1 bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300",children:[e.jsx(ae,{className:"h-2.5 w-2.5"}),x," ",o("תרופות","medications")]})]}),a.summary&&e.jsxs("div",{children:[e.jsx("p",{className:`text-xs text-muted-foreground leading-relaxed ${p?"":"line-clamp-2"}`,children:a.summary}),a.summary.length>120&&e.jsx("button",{onClick:l,className:"flex items-center gap-0.5 text-[10px] text-primary mt-0.5 hover:underline",children:p?e.jsxs(e.Fragment,{children:[o("הסתר","Less"),e.jsx(te,{className:"h-3 w-3"})]}):e.jsxs(e.Fragment,{children:[o("עוד","More"),e.jsx(ne,{className:"h-3 w-3"})]})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground
4/60",children:new Date(a.created_at).toLocaleDateString(y==="he"?"he-IL":"en-US",{day:"numeric",month:"short",year:"numeric"})}),a.processing_status==="completed"&&e.jsxs($,{variant:"ghost",size:"sm",className:"h-7 px-2 gap-1 text-primary hover:text-primary/80",onClick:()=>j(a),children:[e.jsx(re,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"text-[11px] font-medium",children:o("שאל/י את סמדר","Ask Smadar")})]})]})]})})},de=({status:a,onRetry:m,t:p})=>a==="processing"?e.jsxs("div",{className:"flex items-center gap-1 text-primary shrink-0",children:[e.jsx(M,{className:"h-3.5 w-3.5 animate-spin"}),e.jsx("span",{className:"text-[10px] font-medium",children:p("מנתח...","Analyzing...")})]}):a==="completed"?e.jsx(ie,{className:"h-4 w-4 text-green-500 shrink-0"}):a==="failed"?e.jsxs($,{variant:"ghost",size:"sm",className:"h-6 px-2 text-destructive gap-1",onClick:m,children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),e.jsx(le,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[10px]",children:p("נסה שוב","Retry")})]}):null;export{$e 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.