PageSourceSearch

https://ehr.roojh.com/assets/labForm-DnBNDMzC.js

js roojh.com collected 2026-09-24 14:19:37 UTC 12,018 bytes, 1 lines download raw bytes

1import{r as a,b as X,A as Z,j as e,w as n,T as f,c as Se,d as Fe,B as H}from"./index-BPZ0Tu-q.js";import{C as je,u as ve,d as Re,F as Ce,D as Ee,P as De}from"./PatientSearchBar-BQ7GDA7s.js";import{d as we}from"./LocalPharmacyOutlined-Bjw11kCc.js";import{d as Ie}from"./ArrowBackIosNew-CUEleMrs.js";import{u as ke}from"./useFacilitySearch-D3mh_iDQ.js";import{d as ze}from"./DeleteOutline-DPom3O4e.js";import{C as q}from"./CircularProgress-BZ_7TLQW.js";import{I as Te}from"./IconButton-DoiAad2V.js";import{B as J}from"./Button-CJX4vknK.js";import{R as Le}from"./RadioGroup-CNTI6oCE.js";import{F as U}from"./FormControlLabel-CQTFdK6G.js";import{R as Y}from"./Radio-Bduq6zF6.js";import"./createSvgIcon-C0tb55I3.js";import"./debounce-B4KKL1rx.js";import"./isMuiElement-CWMwEMB2.js";import"./useId-DWBHnGLh.js";import"./useControlled-Cv_cl0Xp.js";import"./useIsFocusVisible-Di6E_YNW.js";import"./facility-cache-DFkB2Nvl.js";import"./ButtonBase-CHULMRoT.js";import"./assertThisInitialized-CPFABtj-.js";import"./useFormControl-CzRgK9dn.js";import"./formControlState-CBHnTVNO.js";import"./Stack-ytE0SEjs.js";import"./styled-BHCmf7oE.js";import"./createStyled-CnDF2OVD.js";import"./useThemeProps-amPutscP.js";import"./SwitchBase-B9Y6hk3V.js";(function(){try{var s=typeof globalThis<"u"?globalThis:typeof global<"u"?global:typeof window<"u"?window:typeof self<"u"?self:{};s["__faroGitHash_roojh-web"]="e10f4edfac9af7700f53a2e4507d7c1e30f45024"}catch{}})();(function(){try{var s=typeof globalThis<"u"?globalThis:typeof global<"u"?global:typeof window<"u"?window:typeof self<"u"?self:{};s["__faroBundleId_roojh-web"]="1790253054184ad54def21a"}catch{}})();const K=s=>({id:s,orderId:"",selected:null,qty:0,inputVal:"",showDrop:!1,errors:{}}),Be=(s,u,S,m,g=!0)=>
1{const[j,F]=a.useState([]),[R,h]=a.useState(!1),{apiCall:d}=X();a.useEffect(()=>{if(!g||!u){F([]);return}const b=setTimeout(()=>{C()},250);return()=>clearTimeout(b)},[u,S,m,g]);const C=async()=>{var b;try{h(!0);const p=new URLSearchParams;p.set("categoryId",u),s&&p.set("enterpriseId",s),S&&p.set("patientType",S),m&&p.set("limit",String(m));const c=await d(!1,`api/v1/billingServices/getBillingServicesByCategoryId?${p.toString()}`,Z.GET),v=((b=c==null?void 0:c.data)==null?void 0:b.data)||(c==null?void 0:c.data)||c||[];F(v)}catch(p){console.error("Billing service search error:",p),F([])}finally{h(!1)}};return{searchResult:j,loadingSearch:R}},Oe=({row:s,options:u,loadingSearch:S,frozen:m,showDelete:g,isFirstRow:j,onInputChange:F,onFocus:R,onBlur:h,onSelect:d,onDelete:C})=>{const b=a.useRef(null),p=s.inputVal.length>=1?u.filter(c=>c.label.toLowerCase().includes(s.inputVal.toLowerCase())||c.description.toLowerCase().includes(s.inputVal.toLowerCase())):u.slice(0,20);return e.jsx(n,{sx:{border:"1px solid #F1F3F9",borderRadius:"8px",p:"12px 14px",mb:"10px",background:m?"#FAFAFA":"#fff"},children:e.jsxs(n,{sx:{display:"grid",gridTemplateColumns:"1fr 36px",gap:"10px",alignItems:"start"},children:[j&&e.jsxs(e.Fragment,{children:[e.jsx(je,{required:!0,children:"Lab Service"}),e.jsx(n,{})]}),e.jsx(n,{sx:{position:"relative"},children:m&&s.selected?e.jsxs(n,{sx:{border:"1px solid #E6E6E6",borderRadius:"6px",px:"10px",display:"flex",flexDirection:"column",justifyContent:"center",height:"40px",background:"#FAFAFA"},children:[e.jsx(f,{sx:{fontFamily:"Rubik",fontWeight:500,fontSize:"12px",color:"#313437"},children:s.selected.label}),e.jsx(f,{sx:{fontFamily:"Rubik",fontSize:"10px",color:"#757575"},children:s.selected.description})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:b,value:s.inputVal,placeholder:"Search lab service...",disabled:m,onChange:c=>F(s.id,c.target.value),onFocus:()=>R(s.id),onBlur:()=>setTimeout(()=>h(s.id),180),style:{width:"100%",height:"40px",padding:"0 10px",border:`1px solid ${s.errors.service?"#EF4444":"#E6E6E6"}`,borderRadius:"6px",fontFamily:"Rubik",fontSize:"12px",color:"#313437",outline:"none",boxSizing:"border-box"}}),s.errors.service&&e.jsx(f,{sx:{fontFamily:"Rubik",fontSize:"10px",color:"#EF4444",mt:"3px"},children:s.errors.service}),s.showDrop&&e.jsx(n,{sx:{position:"absolute",top:"calc(100% + 3px)",left:0,right:0,zIndex:300,background:"#fff",border:"1px solid #E6E6E6",borderRadius:"6px",boxShadow:"0 4px 16px rgba(0,0,0,0.10)",maxHeight:"300px",overflowY:"auto"},children:S?e.jsx(n,{sx:{display:"flex",justifyContent:"center",py:2},children:e.jsx(q,{size:18,sx:{color:"#204289"}})}):p.length===0?e.jsx(f,{sx:{p:2,fontSize:"12px",textAlign:"center",color:"#9CA3AF"},children:"No services found"}):p.map((c,v)=>e.jsxs(n,{onMouseDown:k=>{k.preventDefault(),d(s.id,c)},sx:{px:2,py:1,cursor:"pointer",borderBottom:"1px solid #F1F3F9","&:hover":{background:"#EFF3FF"}},children:[e.jsx(f,{sx:{fontFamily:"Rubik",fontSize:"12px",fontWeight:500,color:"#313437"},children:c.label}),e.jsx(f,{sx:{fontFamily:"Rubik",fontSize:"10px",color:"#757575"},children:c.description})]},v))})]})}),e.jsx(n,{sx:{pt:"2px"},children:g?e.jsx(Te,{size:"small",onClick:()=>C(s.id),sx:{width:"36px",height:"40px",borderRadius:"6px",color:"#DC2626","&:hover":{background:"#FEF2F2"}},children:e.jsx(ze,{sx:{fontSize:"18px"}})}):e.jsx(n,{sx:{width:"36px"}})})]})})},dt=()=>{var Q,G;const[s,u]=a.useState(""),[S,m]=a.useState(!1),[g,j]=a.useState(""),[F,R]=a.useState(!1),[h,d]=a.useState([]),[C,b]=a.useState(0),[p,c]=a.useState("idle"),[v,k]=a.useState(null),[W,L]=a.useState(null),[ee,B]=a.useState([]),[x,z]=a.useState(null),[te,E]=a.useState(void 0),V=Se(),O=Fe(),{apiCall:D}=X(),oe=a.useRef(D),{searchResult:w}=ve(),{searchResult:I,loadingSearch:se}=ke(),[A,M]=a.useState(((Q=O.state)==null?void 0:Q.selectedTab)==="OPD"?"OPD":"IPD"),re="2",ie=(x==null?void 0:x.patientType)||"",ae=localStorage.getItem("enterpriseId")??"",{searchResult:N,loadingSearch:ne}=Be(ae,re,ie,50,!0),le=((G=O.state)==null?void 0:G.formStatus)??"order";a.useEffect(()=>{!s&&I&&I.length>0&&u(I[0]._id)},[I,s]),a.useEffect(()=>{!g&&w&&w.length>0&&j(w[0]._id)},[w,g]),a.useEffect(()=>{oe.current=D},[D]),a.useEffect(()=>{const t=(N||[]).map(o=>({label:(o==null?void 0:o.serviceName)||"",description:(o==null?void 0:o.description)||"",raw:o,testC
1ode:(o==null?void 0:o.testCode)||""})).filter(o=>o.label);B(t)},[N]),a.useEffect(()=>{if(!(x!=null&&x._id)){B([]);return}},[x==null?void 0:x._id]),a.useEffect(()=>{var t;M(((t=O.state)==null?void 0:t.selectedTab)==="OPD"?"OPD":"IPD"),d([K(0)]),b(1),B([]),L(null),z(null),E(void 0)},[le]);const P=p!=="idle",ce=t=>{d(o=>o.filter(l=>l.id!==t))},de=(t,o)=>{L(t),d(l=>l.map(r=>r.id===t?{...r,inputVal:o,selected:null,showDrop:!0,errors:{...r.errors,lab:void 0}}:r))},pe=t=>{L(t),d(o=>o.map(l=>l.id===t?{...l,showDrop:!0}:l))},xe=t=>{d(o=>o.map(l=>l.id===t?{...l,showDrop:!1}:l))},fe=(t,o)=>{if(h.some(r=>r.id!==t&&r.selected&&r.selected.label.toLowerCase()===o.label.toLowerCase())){H.warning("Lab service is already added to the list"),d(r=>r.map(i=>i.id===t?{...i,inputVal:"",selected:null,showDrop:!1}:i));return}d(r=>{const i=r.map(y=>y.id===t?{...y,selected:o,inputVal:o.label,showDrop:!1,errors:{...y.errors,lab:void 0}}:y);return i[i.length-1].id===t&&(i.push(K(C)),b(y=>y+1)),i})},ue=(t,o)=>{d(l=>l.map(r=>r.id===t?{...r,qty:Math.max(0,r.qty+o),errors:{...r.errors,qty:void 0}}:r))},he=(t,o)=>{const l=Math.max(0,Number(o)||0);d(r=>r.map(i=>i.id===t?{...i,qty:l,errors:{...i.errors,qty:void 0}}:i))},me=(t,o,l)=>{d(r=>r.map(i=>i.id===t?{...i,[o]:l,errors:{...i.errors,[o]:void 0}}:i))},T=t=>t.selected!==null||t.qty>0,ge=()=>{if(!x)return E("Please select a patient"),!1;if(E(void 0),h.filter(T).length===0)return!1;let o=!0;return d(l=>l.map(r=>{if(!T(r))return r;const i={};return r.selected||(i.lab="Required",o=!1),{...r,errors:i}})),o},be=async()=>{if(!ge())return;c("placing"),k(null);const t=localStorage.getItem("enterpriseId")??"";try{const l={services:h.filter(T).map(i=>{var _,y;return{testCode:i.selected.testCode,serviceName:i.selected.label,servicdescription:i.selected.description,price:((_=i.selected.raw)==null?void 0:_.price)||0,gst:((y=i.selected.raw)==null?void 0:y.gst)||0,quantity:i.qty}}),billType:A,patientId:x==null?void 0:x._id,doctorId:g,enterpriseId:t,facilityId:s};await D(!1,"api/v1/labs/createOrder",Z.POST,JSON.stringify(l))&&(H.success("Order placed successfully"),V("/settings/lab"))}catch(o){console.error("Error submitting pharmacy form:",o),k("Failed to place order. Please try again."),c("idle")}},$=p==="placing",ye=h.some(T);return e.jsxs(n,{sx:{background:"#F8FAFF",minHeight:"100vh",padding:"24px 28px",fontFamily:"Rubik, sans-serif"},children:[e.jsx(J,{startIcon:e.jsx(Ie,{sx:{fontSize:"12px !important"}}),onClick:()=>V(-1),sx:{fontFamily:"Rubik",fontSize:"12px",fontWeight:500,color:"#204289",textTransform:"none",mb:"16px",p:"4px 0",minWidth:0,"&:hover":{background:"none",opacity:.7}},children:"Back to Orders"}),e.jsxs(n,{sx:{background:"#fff",borderRadius:"12px",border:"1px solid #E6E6E6",boxShadow:"0px 4px 20px rgba(32,66,137,0.08)"},children:[e.jsxs(n,{sx:{background:"#EFF3FF",padding:"12px 20px",borderBottom:"1px solid #DEEBFE",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(we,{sx:{color:"#204289",fontSize:"20px"}}),e.jsx(f,{sx:{fontFamily:"Rubik",fontWeight:600,fontSize:"14px",color:"#204289"},children:"Lab Service Order"})]}),p==="idle"&&e.jsx(J,{variant:"contained",disabled:!ye||$,onClick:be,startIcon:$?e.jsx(q,{size:14,sx:{color:"#fff"}}):e.jsx(Re,{sx:{fontSize:"16px !important"}}),sx:{backgroundColor:"#204289",color:"#ffffff !important",fontFamily:"Rubik",fontSize:"13px",fontWeight:500,textTransform:"none",borderRadius:"6px",height:"36px",px:"16px",boxShadow:"none","&:hover":{backgroundColor:"#1a3570 !important",color:"#ffffff !important"},"&.Mui-disabled":{backgroundColor:"#B0BDD6 !important",color:"#ffffff !important"}},children:"Place Order"}),p==="placing"&&e.jsxs(n,{sx:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(q,{size:16,sx:{color:"#204289"}}),e.jsx(f,{sx:{fontFamily:"Rubik",fontSize:"13px",color:"#204289"},children:'"Placing order..."'})]})]}),e.jsxs(n,{sx:{padding:"20px"},children:[v&&e.jsx(n,{sx:{background:"#FEF2F2",border:"1px solid #FECACA",borderRadius:"8px",p:"10px 14px",mb:"16px",display:"flex",alignItems:"center",gap:"8px"},children:e.jsx(f,{sx:{fontFamily:"Rubik",fontSize:"12px",color:"#DC2626"},children:v})}),e.jsxs(n,{sx:{border:"1px solid #E6E6E6",borderRadius:"10px",p:"16px",background:"#fff"},children:[e.jsxs(n,{sx:{display:"flex",flexDirection:{xs:"column",md:"row"},gap:2,mb:2,alignItems:"flex-start"},children:[e.jsxs(n,{sx:{width:150},children:[e.jsxs(f,{sx:{fontFamily:"Rubik",fontSize:"11px",fontWeight:500,color:"#57595C",mb:"6px"},children:["Patient Type",e.jsx("span",{style:{color:"#EF4444",marginLeft:"2px"},children:"*"})]}),e.jsxs(Le,{row:!0,value:A,onChange:t=>{M(t.target.value),z(null),E(void 0)},sx:{height:"40px",border:"1px solid #E6E6E6",borderRadius:"6px",px:1,alignItems:"center",background:"#fff"},children:[e.jsx(U,{value:"IPD",control:e.jsx(Y,{size:"small",sx:{color:"#204289","&.Mui-checked":{color:"#204289"}}}),label:e.jsx(f,{sx:{fontFamily:"Rubik",fontSize:"12px",fontWeight:500},children:"IPD"})}),e.jsx(U,{value:"OPD",control:e.jsx(Y,{size:"small",sx:{color:"#204289","&.Mui-checked":{color:"#204289"}}}),label:e.jsx(f,{sx:{fontFamily:"Rubik",fontSize:"12px",fontWeight:500},children:"OPD"})})]})]}),e.jsx(n,{sx:{flex:.45},children:e.jsx(Ce,{value:s,options:I,onSelect:u,showDrop:S,setShowDrop:m,loading:se})}),e.jsx(n,{sx:{flex:.45},children:e.jsx(Ee,{value:g,options:w,onSelect:j,showDrop:F,setShowDrop:R})}),e.jsx(n,{sx:{flex:.8},children:e.jsx(De,{disabled:P,selectedPatient:x,onSelect:t=>{z(t),E(void 0)},patientType:A,onClear:()=>{z(null)},error:te,apiCall:D})})]}),h.map((t,o)=>e.jsx(Oe,{row:t,options:W===t.id?ee:[],loadingSearch:W===t.id&&ne,frozen:P,showDelete:h.length>1&&!P,isFirstRow:o===0,onInputChange:de,onFocus:pe,onBlur:xe,onSelect:fe,onQty:ue,onQtyInput:he,onFieldChange:me,onDelete:ce},t.id))]})]})]})]})};export{dt 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.