@sasindi/ward-admission 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/628.js CHANGED
@@ -1 +1 @@
1
- "use strict";(globalThis.webpackChunk_sasindi_ward_admission=globalThis.webpackChunk_sasindi_ward_admission||[]).push([[628],{26628:(e,t,n)=>{n.r(t),n.d(t,{default:()=>E});var r=n(16072),a=n.n(r),o=n(78465),l=n.n(o),i=n(83757),s=n(14457),c=n(20354),u=n.n(c);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function p(e,t,n,r,a,o,l){try{var i=e[o](l),s=i.value}catch(e){return void n(e)}i.done?t(s):Promise.resolve(s).then(r,a)}function m(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var o=e.apply(t,n);function l(e){p(o,r,a,l,i,"next",e)}function i(e){p(o,r,a,l,i,"throw",e)}l(void 0)}))}}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter((function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})))),r.forEach((function(t){f(e,t,n[t])}))}return e}function y(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t}(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})),e}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,a,o=[],l=!0,i=!1;try{for(n=n.call(e);!(l=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);l=!0);}catch(e){i=!0,a=e}finally{try{l||null==n.return||n.return()}finally{if(i)throw a}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(e,t){var n,r,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return l.next=i(0),l.throw=i(1),l.return=i(2),"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;l&&(l=0,i[0]&&(o=0)),o;)try{if(n=1,r&&(a=2&i[0]?r.return:i[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,i[1])).done)return a;switch(r=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,r=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){o.label=i[1];break}if(6===i[0]&&o.label<a[1]){o.label=a[1],a=i;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(i);break}a[2]&&o.ops.pop(),o.trys.pop();continue}i=t.call(e,o)}catch(e){i=[6,e],r=0}finally{n=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var v="/openmrs/ws/rest/v1/wardadmission";const E=function(){var e,t,n,o=(0,r.useRef)(null),c=h((0,r.useState)(""),2),d=c[0],p=c[1],f=h((0,r.useState)("0"),2),E=f[0],x=f[1],w=h((0,r.useState)(""),2),S=w[0],T=w[1],C=h((0,r.useState)("0"),2),N=C[0],D=C[1],k=h((0,r.useState)("0"),2),P=k[0],I=k[1],_=h((0,r.useState)("New"),2),A=_[0],j=_[1],O=h((0,r.useState)("0"),2),B=O[0],R=O[1],G=h((0,r.useState)("0"),2),z=G[0],W=G[1],U=h((0,r.useState)(!1),2),L=U[0],H=U[1],F=h((0,r.useState)(""),2),Y=F[0],M=F[1],V=h((0,r.useState)(""),2),J=V[0],K=V[1],$=h((0,r.useState)(""),2),q=$[0],Q=$[1],X=h((0,r.useState)(""),2),Z=X[0],ee=X[1],te=h((0,r.useState)(""),2),ne=te[0],re=te[1],ae=h((0,r.useState)(""),2),oe=ae[0],le=ae[1],ie=h((0,r.useState)("0"),2),se=ie[0],ce=ie[1],ue=h((0,r.useState)("0"),2),de=ue[0],pe=ue[1],me=h((0,r.useState)(null),2),fe=me[0],ge=me[1],ye=h((0,r.useState)(null),2),he=ye[0],be=ye[1],ve=h((0,r.useState)("PENDING"),2),Ee=ve[0],xe=ve[1],we=h((0,r.useState)([]),2),Se=we[0],Te=we[1],Ce=h((0,r.useState)([]),2),Ne=Ce[0],De=Ce[1],ke=h((0,r.useState)(!1),2),Pe=ke[0],Ie=ke[1],_e=h((0,r.useState)(!1),2),Ae=_e[0],je=_e[1],Oe=h((0,r.useState)(!1),2),Be=Oe[0],Re=Oe[1],Ge=h((0,r.useState)(""),2),ze=Ge[0],We=Ge[1],Ue=h((0,r.useState)(""),2),Le=Ue[0],He=Ue[1],Fe=h((0,r.useState)(""),2),Ye=Fe[0],Me=Fe[1],Ve=h((0,r.useState)(""),2),Je=Ve[0],Ke=Ve[1];(0,r.useEffect)((function(){$e()}),[]),(0,r.useEffect)((function(){Le&&(Qe(),qe())}),[Le]);var $e=function(){return m((function(){var e,t,n,r,a,o,i,s,c;return b(this,(function(u){switch(u.label){case 0:return u.trys.push([0,11,,12]),console.log("Loading user session..."),[4,fetch("/openmrs/ws/rest/v1/session")];case 1:return[4,u.sent().json()];case 2:return e=u.sent(),console.log("Session data:",e),e.user&&e.user.uuid?(We(e.user.uuid),n=e.user.person.uuid,[4,fetch("/openmrs/ws/rest/v1/person/".concat(n))]):[3,9];case 3:return[4,u.sent().json()];case 4:return r=u.sent(),console.log("Person data:",r),(a=null===(t=r.attributes)||void 0===t?void 0:t.find((function(e){var t;return(null===(t=e.display)||void 0===t?void 0:t.includes("Institute Id"))||"org.openmrs.Location"===e.valueType})))?(o=a.value,console.log("Found institute UUID:",o),He(o),Me(o),[4,fetch("/openmrs/ws/rest/v1/location/".concat(o))]):[3,7];case 5:return[4,u.sent().json()];case 6:return i=u.sent(),console.log("Location data:",i),Ke(i.display||i.name||"Unknown Hospital"),[3,8];case 7:e.sessionLocation&&e.sessionLocation.uuid&&(s=e.sessionLocation.uuid,console.log("Using session location UUID:",s),He(s),Me(s),Ke(e.sessionLocation.display||"Current Location")),u.label=8;case 8:return[3,10];case 9:console.error("No user data in session"),l().fire({title:"Error!",text:"No user session found. Please login again.",icon:"error",confirmButtonColor:"#dc3545"}),u.label=10;case 10:return[3,12];case 11:return c=u.sent(),console.error("Error loading user session:",c),l().fire({title:"Error!",text:"Failed to load user session. Please refresh the page.",icon:"error",confirmButtonColor:"#dc3545"}),[3,12];case 12:return[2]}}))}))()},qe=function(){return m((function(){var e,t,n;return b(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),console.log("Loading wards for institute:",Le),[4,fetch("".concat(v,"/section/").concat(Le))];case 1:return[4,r.sent().json()];case 2:return e=r.sent(),console.log("Wards data:",e),e&&Array.isArray(e)&&(t=e.map((function(e){var t;return{uuid:e[0],name:(null===(t=e[1])||void 0===t?void 0:t.split("@@")[0])||e[1]}})),De(t)),[3,4];case 3:return n=r.sent(),console.error("Error loading wards:",n),[3,4];case 4:return[2]}}))}))()},Qe=function(){return m((function(){var e,t,n,r;return b(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,4,5]),console.log("Fetching referral patients..."),console.log("Institute UUID:",Le),Re(!0),[4,fetch("".concat(v,"/loadwardrefferaldata/").concat(Le))];case 1:if(!(e=a.sent()).ok)throw new Error("HTTP error! status: ".concat(e.status));return[4,e.json()];case 2:return t=a.sent(),console.log("Referral patients data:",t),t&&Array.isArray(t)?(n=t.map((function(e,t){var n=Array.isArray(e),r=e,a={id:n?e[1]:r.id,phn:n?e[4]:r.phn,patientuuid:n?e[3]:r.patientuuid,encounteruuid:n?e[2]:r.encounteruuid,locationuuid:n?e[5]:r.locationuuid,remarks:n?e[6]:r.remarks,status:n?e[16]:r.status,hospitaluuid:n?e[17]:r.hospitaluuid,AdminissionEncounterUUID:n?e[18]:r.AdminissionEncounterUUID,admission_date:n?e[19]:r.admission_date,transfered_from:n?e[20]:r.transfered_from,bht_No:n?e[21]:r.bht_No,admission_type:n?e[22]:r.admission_type,ReferralDateTime:n?e[23]:r.ReferralDateTime,gender:n?e[24]:r.gender,name:n?e[25]:r.givenname||r.name,age:n?e[26]:r.age};return{id:a.id||t,phn:a.phn||"",patientuuid:a.patientuuid||"",encounteruuid:a.encounteruuid||"",locationuuid:a.locationuuid||"",remarks:a.remarks||"",status:a.status||"",hospitaluuid:a.hospitaluuid||"",AdminissionEncounterUUID:a.AdminissionEncounterUUID||"",admission_date:a.admission_date||"",transfered_from:a.transfered_from||"",bht_No:a.bht_No||"",admission_type:a.admission_type||"OPD",ReferralDateTime:a.ReferralDateTime||"",patientDetails:{name:a.name||"Unknown",gender:"M"===a.gender?"Male":"F"===a.gender?"Female":a.gender||"Unknown",age:a.age?"".concat(a.age," years"):"Unknown"}}})),console.log("Transformed referral data:",n),Te(n)):(console.log("No referral data found in response:",t),Te([])),[3,5];case 3:return r=a.sent(),console.error("Error fetching referral patients:",r),l().fire({title:"Error!",text:"Failed to load referral patients. Please try again.",icon:"error",confirmButtonColor:"#dc3545"}),Te([]),[3,5];case 4:return Re(!1),[7];case 5:return[2]}}))}))()},Xe=function(e){return m((function(){var t,n,r,a,o,i,s,c,u,p,m,f,g,y,h,E,x,w,S,T,C,N,D;return b(this,(function(b){switch(b.label){case 0:if(!(t=e||d).trim())return l().fire({title:"Warning!",text:"Please enter a PHN number.",icon:"warning",confirmButtonColor:"#28a745"}),[2];b.label=1;case 1:return b.trys.push([1,15,16,17]),je(!0),console.log("Searching patient with PHN:",t),[4,fetch("".concat(v,"/status/").concat(t))];case 2:return[4,b.sent().json()];case 3:return n=b.sent(),console.log("Status data:",n),n&&n.length>0&&"Admitted"===n[0]?(l().fire({title:"Already Admitted!",text:"This patient is already admitted to a ward.",icon:"warning",confirmButtonColor:"#28a745"}),[2]):[4,fetch("/openmrs/ws/rest/v1/opd/phn/".concat(t))];case 4:return[4,b.sent().json()];case 5:return r=b.sent(),console.log("Patient search raw data:",r),(a=r.patientuuid||(r.person_id?r.person_id.uuid:null))?(console.log("Found patient UUID:",a),[4,fetch("/openmrs/ws/rest/v1/patient/".concat(a,"?v=full"))]):[3,13];case 6:if(!(c=b.sent()).ok)throw new Error("Failed to fetch full patient details");return[4,c.json()];case 7:return u=b.sent(),p=u.person,console.log("Full patient details:",p),m=new Date(p.birthdate),f=new Date,g=f.getFullYear()-m.getFullYear(),y=f.getMonth()-m.getMonth(),(h=f.getDate()-m.getDate())<0&&(y--,E=new Date(f.getFullYear(),f.getMonth(),0),h+=E.getDate()),y<0&&(g--,y+=12),x=null===(o=p.attributes)||void 0===o?void 0:o.find((function(e){var t,n,r;return(null===(t=e.display)||void 0===t?void 0:t.includes("NIC No"))||(null===(r=e.attributeType)||void 0===r||null===(n=r.display)||void 0===n?void 0:n.includes("NIC"))})),w=null===(i=p.attributes)||void 0===i?void 0:i.find((function(e){var t,n,r;return(null===(t=e.display)||void 0===t?void 0:t.includes("Guardian Name"))||(null===(r=e.attributeType)||void 0===r||null===(n=r.display)||void 0===n?void 0:n.includes("Guardian"))})),S="",p.preferredAddress?(S="".concat(p.preferredAddress.address1||""," ").concat(p.preferredAddress.address2||""," ").concat(p.preferredAddress.cityVillage||"").trim(),[3,12]):[3,8];case 8:return b.trys.push([8,11,,12]),[4,fetch("/openmrs/ws/rest/v1/person/".concat(a,"/address"))];case 9:return[4,b.sent().json()];case 10:return(T=b.sent()).results&&T.results.length>0&&(C=T.results[0],S="".concat(C.address1||""," ").concat(C.address2||""," ").concat(C.cityVillage||"").trim()),[3,12];case 11:return N=b.sent(),console.log("Could not fetch address separately",N),[3,12];case 12:return be({uuid:a,phn:t,fullName:p.display,gender:"M"===p.gender?"Male":"F"===p.gender?"Female":p.gender,nic:(null==x?void 0:x.value)||"",address:S,dob:(null===(s=p.birthdate)||void 0===s?void 0:s.split("T")[0])||"",age:{y:g.toString(),m:y.toString(),d:h.toString()},guardianInfo:(null==w?void 0:w.value)||""}),[3,14];case 13:l().fire({title:"Not Found!",text:"Patient not found with this PHN.",icon:"info",confirmButtonColor:"#28a745"}),be(null),b.label=14;case 14:return[3,17];case 15:return D=b.sent(),console.error("Error searching patient:",D),l().fire({title:"Error!",text:"Failed to search patient. Please check if PHN is correct.",icon:"error",confirmButtonColor:"#dc3545"}),be(null),[3,17];case 16:return je(!1),[7];case 17:return[2]}}))}))()},Ze=function(){p(""),ge(null),x("0"),T(""),D("0"),I("0"),j("New"),R("0"),W("0"),H(!1),M(""),K(""),Q(""),ee(""),re(""),le(""),ce("0"),pe("0"),be(null),De([])},et={mainContainer:{width:"100%",backgroundColor:"#f5f5f5",padding:"20px",minHeight:"100vh",fontFamily:'"Open Sans", sans-serif'},card:{backgroundColor:"#ffffff",borderRadius:"8px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)",padding:"20px",marginBottom:"20px"},sectionTitle:{fontSize:"18px",fontWeight:"bold",color:"#28a745",marginBottom:"20px",paddingBottom:"10px",borderBottom:"2px solid #28a745",marginTop:0},gridTwoColumn:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"20px"},inputGroup:{display:"flex",flexDirection:"column"},label:{fontSize:"14px",fontWeight:"bold",color:"#333",marginBottom:"10px"},input:{padding:"10px",border:"1px solid #ccc",borderRadius:"4px",width:"100%",boxSizing:"border-box",fontSize:"14px"},select:{padding:"10px",border:"1px solid #ccc",borderRadius:"4px",width:"100%",boxSizing:"border-box",fontSize:"14px",backgroundColor:"white"},buttonContainer:{display:"flex",justifyContent:"center",gap:"15px",marginTop:"30px"},buttonPrimary:{backgroundColor:"#28a745",color:"white",border:"none",padding:"10px 30px",borderRadius:"5px",cursor:"pointer",fontSize:"16px",fontWeight:"bold"},buttonSecondary:{backgroundColor:"#007bff",color:"white",border:"none",padding:"10px 30px",borderRadius:"5px",cursor:"pointer",fontSize:"16px",fontWeight:"bold"},buttonDanger:{backgroundColor:"#dc3545",color:"white",border:"none",padding:"10px 30px",borderRadius:"5px",cursor:"pointer",fontSize:"16px",fontWeight:"bold"},radioGroup:{display:"flex",gap:"20px",alignItems:"center"},printTemplateWrapper:{position:"fixed",left:"-9999px",top:"0",zIndex:-1,pointerEvents:"none"},printTemplate:{width:"1000px",backgroundColor:"white",padding:"40px",color:"black"},printTable:{width:"100%",borderCollapse:"collapse",marginTop:"20px"},printTd:{border:"1px solid black",padding:"12px",fontSize:"14px"},printTh:{border:"1px solid black",padding:"12px",backgroundColor:"#f2f2f2",textAlign:"left"}},tt=h((0,r.useState)(""),2),nt=tt[0],rt=tt[1],at=h((0,r.useState)(!1),2),ot=at[0],lt=(at[1],(0,r.useMemo)((function(){return Se.filter((function(e){var t;return(null===(t=e.patientDetails)||void 0===t?void 0:t.name)&&e.patientDetails.name.toLowerCase().includes(nt.toLowerCase())||e.phn&&e.phn.toLowerCase().includes(nt.toLowerCase())}))}),[Se,nt])),it=[{name:"No",selector:function(e,t){return t+1},sortable:!0,width:"60px"},{name:"PHN No",selector:function(e){return e.phn},sortable:!0,cell:function(e){return a().createElement("span",{style:{color:"#28a745",fontWeight:"bold"}},e.phn||"No Data")}},{name:"Name",selector:function(e){var t;return(null===(t=e.patientDetails)||void 0===t?void 0:t.name)||"Unknown"},sortable:!0,wrap:!0},{name:"Gender",selector:function(e){var t;return(null===(t=e.patientDetails)||void 0===t?void 0:t.gender)||"Unknown"},sortable:!0,width:"100px"},{name:"Age",selector:function(e){var t;return(null===(t=e.patientDetails)||void 0===t?void 0:t.age)||"Unknown"},sortable:!0,width:"100px"},{name:"Remark",selector:function(e){return e.remarks||"No Data"},sortable:!0,wrap:!0},{name:"Admission Type",selector:function(e){return e.admission_type||"No Data"},sortable:!0,cell:function(e){var t,n="#6c757d";return"OPD"===e.admission_type&&(n="#28a745"),"Clinic"===e.admission_type&&(n="#007bff"),(null===(t=e.admission_type)||void 0===t?void 0:t.includes("Transfer"))&&(n="#6f42c1"),a().createElement("span",{style:{backgroundColor:n,color:"white",padding:"4px 8px",borderRadius:"12px",fontSize:"11px",fontWeight:"bold",whiteSpace:"nowrap"}},e.admission_type||"OPD")}},{name:"Referral Date",selector:function(e){return e.ReferralDateTime||"-"},sortable:!0,cell:function(e){return a().createElement("span",null,e.ReferralDateTime?new Date(e.ReferralDateTime).toLocaleString():"-")},width:"160px"},{name:"Transferred From",selector:function(e){return e.transfered_from||"-"},sortable:!0,wrap:!0},{name:"Action",cell:function(e){return a().createElement("button",{style:{backgroundColor:"#ffc107",color:"#212529",border:"none",padding:"6px 12px",borderRadius:"4px",cursor:"pointer",fontSize:"12px",fontWeight:"bold"},onClick:function(){return p((t=e).phn),ge(t.id),t.patientDetails&&be({uuid:t.patientuuid,phn:t.phn,fullName:t.patientDetails.name,gender:t.patientDetails.gender,nic:"",address:"",dob:"",age:{y:t.patientDetails.age,m:"",d:""},guardianInfo:""}),t.admission_type&&x(t.admission_type),t.transfered_from&&T(t.transfered_from),void(t.phn&&Xe(t.phn));var t}},"Admit")},ignoreRowClick:!0,allowOverflow:!0,button:!0}];return a().createElement("div",{style:et.mainContainer},Pe&&a().createElement("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.5)",display:"flex",justifyContent:"center",alignItems:"center",zIndex:1e3}},a().createElement("div",{style:{color:"white",fontSize:"18px"}},"Loading...")),a().createElement("div",{style:et.card},a().createElement("h2",{style:{fontSize:"24px",fontWeight:"bold",color:"#28a745",marginBottom:"20px",paddingBottom:"10px",borderBottom:"2px solid #28a745",marginTop:0}},"Ward Admission",a().createElement("span",{style:{fontSize:"10px",color:"#912013",marginLeft:"16px",fontWeight:"bold"}},"PATIENT ADMISSION"),a().createElement("button",{onClick:function(){Qe()},style:{marginLeft:"20px",backgroundColor:"#17a2b8",color:"white",border:"none",padding:"8px 16px",borderRadius:"4px",cursor:"pointer",fontSize:"14px",float:"right"}},"Refresh Referral List")),a().createElement("div",{style:{backgroundColor:"#f8f9fa",padding:"10px",marginBottom:"20px",border:"1px solid #dee2e6",borderRadius:"4px",fontSize:"12px"}},a().createElement("strong",null,"Hospital:")," ",Je," | ",a().createElement("strong",null,"Referral Patients:")," ",Se.length),a().createElement("div",{style:{marginBottom:"30px"}},a().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"15px"}},a().createElement("h3",{style:{color:"#495057",fontSize:"24px",fontWeight:"bold",margin:0}},"Patients Waiting for Admission"),a().createElement("div",{style:{display:"flex",alignItems:"center",gap:"10px"}},a().createElement("span",{style:{fontSize:"14px",fontWeight:"bold"}},"Search:"),a().createElement("input",{type:"text",placeholder:"Search by Name or PHN...",style:y(g({},et.input),{width:"250px",marginBottom:0}),value:nt,onChange:function(e){return rt(e.target.value)}}))),a().createElement(i.Ay,{columns:it,data:lt,pagination:!0,paginationResetDefaultPage:ot,persistTableHead:!0,progressPending:Be&&0===Se.length,progressComponent:a().createElement("div",{style:{padding:"20px"}},"Loading referral patients..."),customStyles:{headRow:{style:{borderTop:"1px solid #dee2e6",borderLeft:"1px solid #dee2e6",borderRight:"1px solid #dee2e6",borderRadius:"8px 8px 0 0",backgroundColor:"#f8f9fa"}},headCells:{style:{color:"#333",fontWeight:"bold",fontSize:"14px",padding:"12px"}},cells:{style:{fontSize:"14px",padding:"12px",color:"#555"}},rows:{style:{minHeight:"48px","&:not(:last-of-type)":{borderBottom:"1px solid #eee"},"&:hover":{backgroundColor:"#f1f8e9",transition:"0.2s"}}}},highlightOnHover:!0,noDataComponent:a().createElement("div",{style:{padding:"20px"}},"No patients waiting for admission.")})),a().createElement("h2",{style:et.sectionTitle},"Patient Information"),a().createElement("div",{style:y(g({},et.gridTwoColumn),{marginBottom:"20px"})},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Enter PHN"),a().createElement("input",{style:et.input,placeholder:"Enter PHN to search...",value:d,onChange:function(e){return p(e.target.value)},onKeyPress:function(e){return"Enter"===e.key&&Xe()}})),a().createElement("div",{style:{display:"flex",alignItems:"flex-end"}},a().createElement("button",{style:et.buttonSecondary,onClick:function(){return Xe()},disabled:Ae},Ae?"Searching...":"Search Patient"))),a().createElement("div",{style:{backgroundColor:"#f9f9f9",padding:"15px",borderRadius:"4px",border:"1px solid #e0e0e0",marginBottom:"30px"}},a().createElement("div",{style:et.gridTwoColumn},a().createElement("div",null,a().createElement("strong",null,"Full Name:")," ",(null==he?void 0:he.fullName)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"Gender:")," ",(null==he?void 0:he.gender)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"NIC No:")," ",(null==he?void 0:he.nic)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"Address:")," ",(null==he?void 0:he.address)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"Date Of Birth:")," ",(null==he?void 0:he.dob)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"Age:")," ",(null==he||null===(e=he.age)||void 0===e?void 0:e.y)?"Y:".concat(he.age.y," M:").concat(he.age.m," D:").concat(he.age.d):"No Data"),a().createElement("div",{style:{gridColumn:"span 2"}},a().createElement("strong",null,"Guardian Info:")," ",(null==he?void 0:he.guardianInfo)||"No Data"))),a().createElement("h2",{style:et.sectionTitle},"Admission Details"),a().createElement("div",{style:et.gridTwoColumn},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Admission Type ",a().createElement("span",{style:{color:"red"}},"*")),a().createElement("select",{style:et.select,value:E,onChange:function(e){x(e.target.value),"Internal Transfer"!==e.target.value&&j("New")}},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Direct"},"Direct"),a().createElement("option",{value:"Internal Transfer"},"Internal Transfer"),a().createElement("option",{value:"External Transfer"},"External Transfer"))),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Transferred From"),a().createElement("input",{style:et.input,value:S,onChange:function(e){return T(e.target.value)},disabled:"Direct"===E})),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"BHT Received"),a().createElement("select",{style:et.select,value:N,onChange:function(e){return D(e.target.value)},disabled:"Direct"===E},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Yes"},"Yes"),a().createElement("option",{value:"No"},"No"))),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Documents Received"),a().createElement("select",{style:et.select,value:P,onChange:function(e){return I(e.target.value)},disabled:"Direct"===E},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Yes"},"Yes"),a().createElement("option",{value:"No"},"No")))),"Internal Transfer"===E&&a().createElement("div",{style:{marginTop:"20px",padding:"15px",border:"1px dashed #28a745",borderRadius:"4px"}},a().createElement("label",{style:et.label},"Select BHT Option"),a().createElement("div",{style:et.radioGroup},a().createElement("label",{style:{cursor:"pointer"}},a().createElement("input",{type:"radio",name:"bht",value:"New",checked:"New"===A,onChange:function(){return j("New")}})," ","New BHT"),a().createElement("label",{style:{cursor:"pointer"}},a().createElement("input",{type:"radio",name:"bht",value:"Existing",checked:"Existing"===A,onChange:function(){return j("Existing")}})," ","Continue with existing BHT"))),a().createElement("div",{style:y(g({},et.gridTwoColumn),{marginTop:"20px"})},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Ward ",a().createElement("span",{style:{color:"red"}},"*")),a().createElement("select",{style:et.select,value:B,onChange:function(e){return R(e.target.value)}},a().createElement("option",{value:"0"},"--Select--"),Ne.map((function(e){return a().createElement("option",{key:e.uuid,value:e.uuid},e.name)})))),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Admission Priority"),a().createElement("select",{style:y(g({},et.select),{color:"Stat"===z?"red":"inherit",borderColor:"Stat"===z?"red":"#ccc"}),value:z,onChange:function(e){return W(e.target.value)}},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"See Early"},"See Early"),a().createElement("option",{value:"Stat"},"Stat"))),a().createElement("div",{style:{display:"flex",alignItems:"center",marginTop:"30px"}},a().createElement("label",{style:{display:"flex",alignItems:"center",fontSize:"14px",fontWeight:"bold",cursor:"pointer"}},a().createElement("input",{type:"checkbox",checked:L,onChange:function(e){return H(e.target.checked)},style:{marginRight:"10px",transform:"scale(1.2)"}}),"Injury")),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Transport ",a().createElement("span",{style:{color:"red"}},"*")),a().createElement("div",{style:et.radioGroup},a().createElement("label",{style:{cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"center"}},a().createElement("input",{type:"radio",name:"transport",value:"Trolley",checked:"Trolley"===Y,onChange:function(e){return M(e.target.value)}}),a().createElement("span",{style:{fontSize:"12px"}},"Trolley")),a().createElement("label",{style:{cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"center"}},a().createElement("input",{type:"radio",name:"transport",value:"Wheelchair",checked:"Wheelchair"===Y,onChange:function(e){return M(e.target.value)}}),a().createElement("span",{style:{fontSize:"12px"}},"Wheelchair")),a().createElement("label",{style:{cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"center"}},a().createElement("input",{type:"radio",name:"transport",value:"Walk",checked:"Walk"===Y,onChange:function(e){return M(e.target.value)}}),a().createElement("span",{style:{fontSize:"12px"}},"Walk"))))),a().createElement("div",{style:{marginTop:"30px"}},a().createElement("h2",{style:et.sectionTitle},"Guardian Details"),a().createElement("div",{style:et.gridTwoColumn},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Guardian Name"),a().createElement("input",{style:et.input,value:J,onChange:function(e){return K(e.target.value)}})),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Guardian Contact No"),a().createElement("input",{style:et.input,value:q,onChange:function(e){return Q(e.target.value)}})),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Guardian NIC No"),a().createElement("input",{style:et.input,value:Z,onChange:function(e){return ee(e.target.value)}})),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Guardian Relation"),a().createElement("input",{style:et.input,value:ne,onChange:function(e){return re(e.target.value)}})),a().createElement("div",{style:y(g({},et.inputGroup),{gridColumn:"span 2"})},a().createElement("label",{style:et.label},"Guardian Address"),a().createElement("input",{style:et.input,value:oe,onChange:function(e){return le(e.target.value)}})))),a().createElement("div",{style:{marginTop:"30px"}},a().createElement("h2",{style:et.sectionTitle},"Legal Information"),a().createElement("div",{style:et.gridTwoColumn},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Judicial Action"),a().createElement("select",{style:et.select,value:se,onChange:function(e){return ce(e.target.value)}},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Yes"},"Yes"),a().createElement("option",{value:"No"},"No"))),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Informed to Police"),a().createElement("select",{style:et.select,value:de,onChange:function(e){return pe(e.target.value)}},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Yes"},"Yes"),a().createElement("option",{value:"No"},"No"))))),a().createElement("div",{style:et.buttonContainer},a().createElement("button",{style:et.buttonPrimary,onClick:function(){return m((function(){var e,t,n,r,a,i,c,p,f,g,y,x,w,T,C,D,k,I,_,A,j,O,R,G,W,U,H,F,M;return b(this,(function(V){switch(V.label){case 0:if(!(d.trim()?"0"===E?(l().fire({title:"Validation Error!",text:"Please select admission type.",icon:"error",confirmButtonColor:"#dc3545"}),0):"0"===B?(l().fire({title:"Validation Error!",text:"Please select a ward.",icon:"error",confirmButtonColor:"#dc3545"}),0):Y?J.trim()||(l().fire({title:"Validation Error!",text:"Please enter guardian name.",icon:"error",confirmButtonColor:"#dc3545"}),0):(l().fire({title:"Validation Error!",text:"Please select transport method.",icon:"error",confirmButtonColor:"#dc3545"}),0):(l().fire({title:"Validation Error!",text:"Please enter PHN number.",icon:"error",confirmButtonColor:"#dc3545"}),0)))return[2];if(!he)return l().fire({title:"Error!",text:"Please search for a patient first.",icon:"error",confirmButtonColor:"#dc3545"}),[2];V.label=1;case 1:return V.trys.push([1,14,15,16]),Ie(!0),console.log("Starting full admission workflow..."),[4,Promise.all([fetch("".concat(v,"/patient/").concat(he.uuid)).then((function(e){return e.json()})),fetch("".concat(v,"/location/").concat(Ye||Le)).then((function(e){return e.json()})),fetch("".concat(v,"/users/").concat(ze)).then((function(e){return e.json()})),fetch("".concat(v,"/visittype")).then((function(e){return e.json()})),fetch("".concat(v,"/encountertype")).then((function(e){return e.json()}))])];case 2:if(e=h.apply(void 0,[V.sent(),5]),t=e[0],n=e[1],r=e[2],a=e[3],i=e[4],c=t.id,p=Array.isArray(n)?n[0]:n,f=Array.isArray(r)?r[0]:r,g=Array.isArray(a)?a[0]:a,y=Array.isArray(i)?i[0]:i,console.log("Internal IDs fetched:",{internalPatientId:c,internalLocationId:p,internalUserId:f,visitTypeId:g,encounterTypeId:y}),!(c&&p&&g&&y))throw new Error("Could not resolve all necessary internal IDs (Patient, Location, Visit Type, or Encounter Type). Please check your database metadata.");return x=new Date,w={patient_id:c,location_id:p,visit_type_id:g,creator:f},[4,fetch("".concat(v,"/visit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)})];case 3:if(!(T=V.sent()).ok)throw new Error("Failed to create visit: ".concat(T.statusText));return[4,T.json()];case 4:return C=V.sent(),D=C.visit_id,k={encounter_type:y,patient_id:c,location_id:p,creator:f,visit_id:D},[4,fetch("".concat(v,"/encounter"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)})];case 5:if(!(I=V.sent()).ok)throw new Error("Failed to create encounter: ".concat(I.statusText));return[4,I.json()];case 6:return _=V.sent(),A=_.uuid,j=x.toISOString().split("T")[0],O=x.toTimeString().split(" ")[0].substring(0,5),R={id:fe||0,phn:d,locationuuid:Ye||Le,encounteruuid:A,BHT_No:"0",admission_type:E,transfered_from:S,bht_received:"0"===N?"":N,document_received:"0"===P?"":P,ward:B,admission_date:j,admission_time:O,status:"Admitted",guardian_name:J,guardian_telno:q,guardian_nic:Z,guardian_relation:ne,guardian_address:oe,judicial_action:"0"===se?"":se,informed_to_police:"0"===de?"":de,injury:L?"Yes":"No",admissionPriority:"0"===z?"":z,transport:Y,cby:ze,date_created:x.toISOString()},[4,fetch("".concat(v,"/save"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R)})];case 7:if(!(G=V.sent()).ok)throw new Error("Failed to save ward admission record");return[4,G.json()];case 8:return W=V.sent(),(U=W.BHT_No||W.bht_No)&&xe(U),fe?(H="Clinic"===E?"/savereferralClinicStatus":"/savereferralStatus",[4,fetch("".concat(v).concat(H),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:fe})})]):[3,10];case 9:V.sent(),V.label=10;case 10:return V.trys.push([10,12,,13]),[4,fetch("".concat(v,"/updatetokenwithencounter/").concat(d,"/").concat(Ye||Le,"/").concat(A))];case 11:return V.sent(),[3,13];case 12:return F=V.sent(),console.warn("Token update failed (non-critical):",F),[3,13];case 13:return l().fire({title:"Success!",html:'\n <div style="text-align: center;">\n <h3 style="color: #28a745; margin-bottom: 20px; font-size: 24px;">Patient Admitted Successfully!</h3>\n '.concat(U?'\n <div style="background-color: #f0f8f4; padding: 20px; border-radius: 8px; border: 2px solid #28a745; margin: 15px 0;">\n <p style="margin: 0; font-size: 16px; color: #333;">BHT Number</p>\n <h2 style="margin: 10px 0; color: #28a745; font-size: 32px; font-weight: bold;">'.concat(U,"</h2>\n </div>\n "):"",'\n <p style="margin-top: 20px;">Do you want to print ward Admission?</p>\n </div>\n '),icon:"success",showCancelButton:!0,confirmButtonText:"Yes, Print",cancelButtonText:"No",confirmButtonColor:"#28a745"}).then((function(e){return m((function(){return b(this,(function(t){switch(t.label){case 0:return e.isConfirmed?[4,m((function(){var e,t,n,r,a,l;return b(this,(function(i){switch(i.label){case 0:return o.current?(e=new s.uE({orientation:"landscape",unit:"mm",format:"a4"}),[4,u()(o.current,{scale:2,useCORS:!0,logging:!1,backgroundColor:"#ffffff"})]):[2];case 1:return t=i.sent(),n=t.toDataURL("image/png"),r=e.getImageProperties(n),a=e.internal.pageSize.getWidth(),l=r.height*a/r.width,e.addImage(n,"PNG",0,0,a,l),e.save("Patient Admission Form.pdf"),[2]}}))}))()]:[3,2];case 1:t.sent(),t.label=2;case 2:return Qe(),Ze(),[2]}}))}))()})),[3,16];case 14:return M=V.sent(),console.error("Error in admission workflow:",M),l().fire({title:"Error!",text:"Admission failed: ".concat((K=M,$=Error,(null!=$&&"undefined"!=typeof Symbol&&$[Symbol.hasInstance]?$[Symbol.hasInstance](K):K instanceof $)?M.message:"Unknown error")),icon:"error",confirmButtonColor:"#dc3545"}),[3,16];case 15:return Ie(!1),[7];case 16:return[2]}var K,$}))}))()},disabled:Pe},Pe?"Saving...":"Save"),a().createElement("button",{style:et.buttonDanger,onClick:Ze},"Cancel"))),a().createElement("div",{style:et.printTemplateWrapper},a().createElement("div",{style:et.printTemplate,ref:o},a().createElement("div",{style:{textAlign:"center",marginBottom:"20px"}},a().createElement("h1",{style:{fontSize:"24px",margin:"0",color:"black"}},"Patient Admission Form"),a().createElement("hr",{style:{border:"1px solid black"}})),a().createElement("table",{style:et.printTable},a().createElement("tbody",null,a().createElement("tr",null,a().createElement("th",{style:et.printTh,colSpan:2},"Hospital: ",Je),a().createElement("th",{style:et.printTh,colSpan:2},"PHN: ",(null==he?void 0:he.phn)||d)),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Patient Name:")),a().createElement("td",{style:et.printTd},(null==he?void 0:he.fullName)||"-"),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"BHT Number:")),a().createElement("td",{style:y(g({},et.printTd),{fontWeight:"bold"})},Ee)),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"NIC Number:")),a().createElement("td",{style:et.printTd},(null==he?void 0:he.nic)||"-"),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Date:")),a().createElement("td",{style:et.printTd},(new Date).toLocaleDateString())),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Address:")),a().createElement("td",{style:et.printTd},(null==he?void 0:he.address)||"-"),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Time:")),a().createElement("td",{style:et.printTd},(new Date).toLocaleTimeString())),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Guardian:")),a().createElement("td",{style:et.printTd},J),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Age:")),a().createElement("td",{style:et.printTd},(null==he||null===(t=he.age)||void 0===t?void 0:t.y)||"-"," Years")),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Ward:")),a().createElement("td",{style:et.printTd},(null===(n=Ne.find((function(e){return e.uuid===B})))||void 0===n?void 0:n.name)||"-"),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Gender:")),a().createElement("td",{style:et.printTd},(null==he?void 0:he.gender)||"-")),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Transport:")),a().createElement("td",{style:et.printTd},Y),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Priority:")),a().createElement("td",{style:et.printTd},"0"===z?"-":z)))),a().createElement("div",{style:{marginTop:"50px",fontSize:"12px",textAlign:"right"}},a().createElement("p",null,"Generated by: Ward Admission System | ",(new Date).toLocaleString())))))}}}]);
1
+ "use strict";(globalThis.webpackChunk_sasindi_ward_admission=globalThis.webpackChunk_sasindi_ward_admission||[]).push([[628],{26628:(e,t,n)=>{n.r(t),n.d(t,{default:()=>E});var r=n(16072),a=n.n(r),o=n(78465),l=n.n(o),i=n(83757),s=n(14457),c=n(20354),u=n.n(c);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function p(e,t,n,r,a,o,l){try{var i=e[o](l),s=i.value}catch(e){return void n(e)}i.done?t(s):Promise.resolve(s).then(r,a)}function m(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var o=e.apply(t,n);function l(e){p(o,r,a,l,i,"next",e)}function i(e){p(o,r,a,l,i,"throw",e)}l(void 0)}))}}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter((function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})))),r.forEach((function(t){f(e,t,n[t])}))}return e}function y(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t}(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})),e}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,a,o=[],l=!0,i=!1;try{for(n=n.call(e);!(l=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);l=!0);}catch(e){i=!0,a=e}finally{try{l||null==n.return||n.return()}finally{if(i)throw a}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(e,t){var n,r,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return l.next=i(0),l.throw=i(1),l.return=i(2),"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;l&&(l=0,i[0]&&(o=0)),o;)try{if(n=1,r&&(a=2&i[0]?r.return:i[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,i[1])).done)return a;switch(r=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,r=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){o.label=i[1];break}if(6===i[0]&&o.label<a[1]){o.label=a[1],a=i;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(i);break}a[2]&&o.ops.pop(),o.trys.pop();continue}i=t.call(e,o)}catch(e){i=[6,e],r=0}finally{n=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var v="/openmrs/ws/rest/v1/wardadmission";const E=function(){var e,t,n,o=(0,r.useRef)(null),c=h((0,r.useState)(""),2),d=c[0],p=c[1],f=h((0,r.useState)("0"),2),E=f[0],x=f[1],w=h((0,r.useState)(""),2),S=w[0],T=w[1],C=h((0,r.useState)("0"),2),N=C[0],D=C[1],k=h((0,r.useState)("0"),2),P=k[0],I=k[1],_=h((0,r.useState)("New"),2),A=_[0],j=_[1],O=h((0,r.useState)("0"),2),B=O[0],R=O[1],G=h((0,r.useState)("0"),2),z=G[0],W=G[1],U=h((0,r.useState)(!1),2),L=U[0],H=U[1],F=h((0,r.useState)(""),2),Y=F[0],M=F[1],V=h((0,r.useState)(""),2),J=V[0],K=V[1],$=h((0,r.useState)(""),2),q=$[0],Q=$[1],X=h((0,r.useState)(""),2),Z=X[0],ee=X[1],te=h((0,r.useState)(""),2),ne=te[0],re=te[1],ae=h((0,r.useState)(""),2),oe=ae[0],le=ae[1],ie=h((0,r.useState)("0"),2),se=ie[0],ce=ie[1],ue=h((0,r.useState)("0"),2),de=ue[0],pe=ue[1],me=h((0,r.useState)(null),2),fe=me[0],ge=me[1],ye=h((0,r.useState)(null),2),he=ye[0],be=ye[1],ve=h((0,r.useState)("PENDING"),2),Ee=ve[0],xe=ve[1],we=h((0,r.useState)([]),2),Se=we[0],Te=we[1],Ce=h((0,r.useState)([]),2),Ne=Ce[0],De=Ce[1],ke=h((0,r.useState)(!1),2),Pe=ke[0],Ie=ke[1],_e=h((0,r.useState)(!1),2),Ae=_e[0],je=_e[1],Oe=h((0,r.useState)(!1),2),Be=Oe[0],Re=Oe[1],Ge=h((0,r.useState)(""),2),ze=Ge[0],We=Ge[1],Ue=h((0,r.useState)(""),2),Le=Ue[0],He=Ue[1],Fe=h((0,r.useState)(""),2),Ye=Fe[0],Me=Fe[1],Ve=h((0,r.useState)(""),2),Je=Ve[0],Ke=Ve[1];(0,r.useEffect)((function(){$e()}),[]),(0,r.useEffect)((function(){Le&&(Qe(),qe())}),[Le]);var $e=function(){return m((function(){var e,t,n,r,a,o,i,s,c;return b(this,(function(u){switch(u.label){case 0:return u.trys.push([0,11,,12]),console.log("Loading user session..."),[4,fetch("/openmrs/ws/rest/v1/session")];case 1:return[4,u.sent().json()];case 2:return e=u.sent(),console.log("Session data:",e),e.user&&e.user.uuid?(We(e.user.uuid),n=e.user.person.uuid,[4,fetch("/openmrs/ws/rest/v1/person/".concat(n))]):[3,9];case 3:return[4,u.sent().json()];case 4:return r=u.sent(),console.log("Person data:",r),(a=null===(t=r.attributes)||void 0===t?void 0:t.find((function(e){var t;return(null===(t=e.display)||void 0===t?void 0:t.includes("Institute Id"))||"org.openmrs.Location"===e.valueType})))?(o=a.value,console.log("Found institute UUID:",o),He(o),Me(o),[4,fetch("/openmrs/ws/rest/v1/location/".concat(o))]):[3,7];case 5:return[4,u.sent().json()];case 6:return i=u.sent(),console.log("Location data:",i),Ke(i.display||i.name||"Unknown Hospital"),[3,8];case 7:e.sessionLocation&&e.sessionLocation.uuid&&(s=e.sessionLocation.uuid,console.log("Using session location UUID:",s),He(s),Me(s),Ke(e.sessionLocation.display||"Current Location")),u.label=8;case 8:return[3,10];case 9:console.error("No user data in session"),l().fire({title:"Error!",text:"No user session found. Please login again.",icon:"error",confirmButtonColor:"#dc3545"}),u.label=10;case 10:return[3,12];case 11:return c=u.sent(),console.error("Error loading user session:",c),l().fire({title:"Error!",text:"Failed to load user session. Please refresh the page.",icon:"error",confirmButtonColor:"#dc3545"}),[3,12];case 12:return[2]}}))}))()},qe=function(){return m((function(){var e,t,n;return b(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),console.log("Loading wards for institute:",Le),[4,fetch("".concat(v,"/section/").concat(Le))];case 1:return[4,r.sent().json()];case 2:return e=r.sent(),console.log("Wards data:",e),e&&Array.isArray(e)&&(t=e.map((function(e){var t;return{uuid:e[0],name:(null===(t=e[1])||void 0===t?void 0:t.split("@@")[0])||e[1]}})),De(t)),[3,4];case 3:return n=r.sent(),console.error("Error loading wards:",n),[3,4];case 4:return[2]}}))}))()},Qe=function(){return m((function(){var e,t,n,r;return b(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,4,5]),console.log("Fetching referral patients..."),console.log("Institute UUID:",Le),Re(!0),[4,fetch("".concat(v,"/loadwardrefferaldata/").concat(Le))];case 1:if(!(e=a.sent()).ok)throw new Error("HTTP error! status: ".concat(e.status));return[4,e.json()];case 2:return t=a.sent(),console.log("Referral patients data:",t),t&&Array.isArray(t)?(n=t.map((function(e,t){var n=Array.isArray(e),r=e,a={id:n?e[0]:r.id,phn:n?e[3]:r.phn,patientuuid:n?e[2]:r.patientuuid,encounteruuid:n?e[1]:r.encounteruuid,locationuuid:n?e[4]:r.locationuuid,remarks:n?e[5]:r.remarks,status:n?e[15]:r.status,hospitaluuid:n?e[16]:r.hospitaluuid,AdminissionEncounterUUID:n?e[17]:r.AdminissionEncounterUUID,admission_date:n?e[18]:r.admission_date,transfered_from:n?e[19]:r.transfered_from,bht_No:n?e[20]:r.bht_No,admission_type:n?e[21]:r.admission_type,ReferralDateTime:n?e[22]:r.ReferralDateTime,gender:n?e[23]:r.gender,name:n?e[24]:r.givenname||r.name,age:n?e[25]:r.age};return{id:a.id||t,phn:a.phn||"",patientuuid:a.patientuuid||"",encounteruuid:a.encounteruuid||"",locationuuid:a.locationuuid||"",remarks:a.remarks||"",status:a.status||"",hospitaluuid:a.hospitaluuid||"",AdminissionEncounterUUID:a.AdminissionEncounterUUID||"",admission_date:a.admission_date||"",transfered_from:a.transfered_from||"",bht_No:a.bht_No||"",admission_type:a.admission_type||"OPD",ReferralDateTime:a.ReferralDateTime||"",patientDetails:{name:a.name||"Unknown",gender:"M"===a.gender?"Male":"F"===a.gender?"Female":a.gender||"Unknown",age:a.age?"".concat(a.age," years"):"Unknown"}}})),console.log("Transformed referral data:",n),Te(n)):(console.log("No referral data found in response:",t),Te([])),[3,5];case 3:return r=a.sent(),console.error("Error fetching referral patients:",r),l().fire({title:"Error!",text:"Failed to load referral patients. Please try again.",icon:"error",confirmButtonColor:"#dc3545"}),Te([]),[3,5];case 4:return Re(!1),[7];case 5:return[2]}}))}))()},Xe=function(e){return m((function(){var t,n,r,a,o,i,s,c,u,p,m,f,g,y,h,E,x,w,S,T,C,N,D;return b(this,(function(b){switch(b.label){case 0:if(!(t=e||d).trim())return l().fire({title:"Warning!",text:"Please enter a PHN number.",icon:"warning",confirmButtonColor:"#28a745"}),[2];b.label=1;case 1:return b.trys.push([1,15,16,17]),je(!0),console.log("Searching patient with PHN:",t),[4,fetch("".concat(v,"/status/").concat(t))];case 2:return[4,b.sent().json()];case 3:return n=b.sent(),console.log("Status data:",n),n&&n.length>0&&"Admitted"===n[0]?(l().fire({title:"Already Admitted!",text:"This patient is already admitted to a ward.",icon:"warning",confirmButtonColor:"#28a745"}),[2]):[4,fetch("/openmrs/ws/rest/v1/opd/phn/".concat(t))];case 4:return[4,b.sent().json()];case 5:return r=b.sent(),console.log("Patient search raw data:",r),(a=r.patientuuid||(r.person_id?r.person_id.uuid:null))?(console.log("Found patient UUID:",a),[4,fetch("/openmrs/ws/rest/v1/patient/".concat(a,"?v=full"))]):[3,13];case 6:if(!(c=b.sent()).ok)throw new Error("Failed to fetch full patient details");return[4,c.json()];case 7:return u=b.sent(),p=u.person,console.log("Full patient details:",p),m=new Date(p.birthdate),f=new Date,g=f.getFullYear()-m.getFullYear(),y=f.getMonth()-m.getMonth(),(h=f.getDate()-m.getDate())<0&&(y--,E=new Date(f.getFullYear(),f.getMonth(),0),h+=E.getDate()),y<0&&(g--,y+=12),x=null===(o=p.attributes)||void 0===o?void 0:o.find((function(e){var t,n,r;return(null===(t=e.display)||void 0===t?void 0:t.includes("NIC No"))||(null===(r=e.attributeType)||void 0===r||null===(n=r.display)||void 0===n?void 0:n.includes("NIC"))})),w=null===(i=p.attributes)||void 0===i?void 0:i.find((function(e){var t,n,r;return(null===(t=e.display)||void 0===t?void 0:t.includes("Guardian Name"))||(null===(r=e.attributeType)||void 0===r||null===(n=r.display)||void 0===n?void 0:n.includes("Guardian"))})),S="",p.preferredAddress?(S="".concat(p.preferredAddress.address1||""," ").concat(p.preferredAddress.address2||""," ").concat(p.preferredAddress.cityVillage||"").trim(),[3,12]):[3,8];case 8:return b.trys.push([8,11,,12]),[4,fetch("/openmrs/ws/rest/v1/person/".concat(a,"/address"))];case 9:return[4,b.sent().json()];case 10:return(T=b.sent()).results&&T.results.length>0&&(C=T.results[0],S="".concat(C.address1||""," ").concat(C.address2||""," ").concat(C.cityVillage||"").trim()),[3,12];case 11:return N=b.sent(),console.log("Could not fetch address separately",N),[3,12];case 12:return be({uuid:a,phn:t,fullName:p.display,gender:"M"===p.gender?"Male":"F"===p.gender?"Female":p.gender,nic:(null==x?void 0:x.value)||"",address:S,dob:(null===(s=p.birthdate)||void 0===s?void 0:s.split("T")[0])||"",age:{y:g.toString(),m:y.toString(),d:h.toString()},guardianInfo:(null==w?void 0:w.value)||""}),[3,14];case 13:l().fire({title:"Not Found!",text:"Patient not found with this PHN.",icon:"info",confirmButtonColor:"#28a745"}),be(null),b.label=14;case 14:return[3,17];case 15:return D=b.sent(),console.error("Error searching patient:",D),l().fire({title:"Error!",text:"Failed to search patient. Please check if PHN is correct.",icon:"error",confirmButtonColor:"#dc3545"}),be(null),[3,17];case 16:return je(!1),[7];case 17:return[2]}}))}))()},Ze=function(){p(""),ge(null),x("0"),T(""),D("0"),I("0"),j("New"),R("0"),W("0"),H(!1),M(""),K(""),Q(""),ee(""),re(""),le(""),ce("0"),pe("0"),be(null),De([])},et={mainContainer:{width:"100%",backgroundColor:"#f5f5f5",padding:"20px",minHeight:"100vh",fontFamily:'"Open Sans", sans-serif'},card:{backgroundColor:"#ffffff",borderRadius:"8px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)",padding:"20px",marginBottom:"20px"},sectionTitle:{fontSize:"18px",fontWeight:"bold",color:"#28a745",marginBottom:"20px",paddingBottom:"10px",borderBottom:"2px solid #28a745",marginTop:0},gridTwoColumn:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"20px"},inputGroup:{display:"flex",flexDirection:"column"},label:{fontSize:"14px",fontWeight:"bold",color:"#333",marginBottom:"10px"},input:{padding:"10px",border:"1px solid #ccc",borderRadius:"4px",width:"100%",boxSizing:"border-box",fontSize:"14px"},select:{padding:"10px",border:"1px solid #ccc",borderRadius:"4px",width:"100%",boxSizing:"border-box",fontSize:"14px",backgroundColor:"white"},buttonContainer:{display:"flex",justifyContent:"center",gap:"15px",marginTop:"30px"},buttonPrimary:{backgroundColor:"#28a745",color:"white",border:"none",padding:"10px 30px",borderRadius:"5px",cursor:"pointer",fontSize:"16px",fontWeight:"bold"},buttonSecondary:{backgroundColor:"#007bff",color:"white",border:"none",padding:"10px 30px",borderRadius:"5px",cursor:"pointer",fontSize:"16px",fontWeight:"bold"},buttonDanger:{backgroundColor:"#dc3545",color:"white",border:"none",padding:"10px 30px",borderRadius:"5px",cursor:"pointer",fontSize:"16px",fontWeight:"bold"},radioGroup:{display:"flex",gap:"20px",alignItems:"center"},printTemplateWrapper:{position:"fixed",left:"-9999px",top:"0",zIndex:-1,pointerEvents:"none"},printTemplate:{width:"1000px",backgroundColor:"white",padding:"40px",color:"black"},printTable:{width:"100%",borderCollapse:"collapse",marginTop:"20px"},printTd:{border:"1px solid black",padding:"12px",fontSize:"14px"},printTh:{border:"1px solid black",padding:"12px",backgroundColor:"#f2f2f2",textAlign:"left"}},tt=h((0,r.useState)(""),2),nt=tt[0],rt=tt[1],at=h((0,r.useState)(!1),2),ot=at[0],lt=(at[1],(0,r.useMemo)((function(){return Se.filter((function(e){var t;return(null===(t=e.patientDetails)||void 0===t?void 0:t.name)&&e.patientDetails.name.toLowerCase().includes(nt.toLowerCase())||e.phn&&e.phn.toLowerCase().includes(nt.toLowerCase())}))}),[Se,nt])),it=[{name:"No",selector:function(e,t){return t+1},sortable:!0,width:"60px"},{name:"PHN No",selector:function(e){return e.phn},sortable:!0,cell:function(e){return a().createElement("span",{style:{color:"#28a745",fontWeight:"bold"}},e.phn||"No Data")}},{name:"Name",selector:function(e){var t;return(null===(t=e.patientDetails)||void 0===t?void 0:t.name)||"Unknown"},sortable:!0,wrap:!0},{name:"Gender",selector:function(e){var t;return(null===(t=e.patientDetails)||void 0===t?void 0:t.gender)||"Unknown"},sortable:!0,width:"100px"},{name:"Age",selector:function(e){var t;return(null===(t=e.patientDetails)||void 0===t?void 0:t.age)||"Unknown"},sortable:!0,width:"100px"},{name:"Remark",selector:function(e){return e.remarks||"No Data"},sortable:!0,wrap:!0},{name:"Admission Type",selector:function(e){return e.admission_type||"No Data"},sortable:!0,cell:function(e){var t,n="#6c757d";return"OPD"===e.admission_type&&(n="#28a745"),"Clinic"===e.admission_type&&(n="#007bff"),(null===(t=e.admission_type)||void 0===t?void 0:t.includes("Transfer"))&&(n="#6f42c1"),a().createElement("span",{style:{backgroundColor:n,color:"white",padding:"4px 8px",borderRadius:"12px",fontSize:"11px",fontWeight:"bold",whiteSpace:"nowrap"}},e.admission_type||"OPD")}},{name:"Referral Date",selector:function(e){return e.ReferralDateTime||"-"},sortable:!0,cell:function(e){return a().createElement("span",null,e.ReferralDateTime?new Date(e.ReferralDateTime).toLocaleString():"-")},width:"160px"},{name:"Transferred From",selector:function(e){return e.transfered_from||"-"},sortable:!0,wrap:!0},{name:"Action",cell:function(e){return a().createElement("button",{style:{backgroundColor:"#ffc107",color:"#212529",border:"none",padding:"6px 12px",borderRadius:"4px",cursor:"pointer",fontSize:"12px",fontWeight:"bold"},onClick:function(){return p((t=e).phn),ge(t.id),t.patientDetails&&be({uuid:t.patientuuid,phn:t.phn,fullName:t.patientDetails.name,gender:t.patientDetails.gender,nic:"",address:"",dob:"",age:{y:t.patientDetails.age,m:"",d:""},guardianInfo:""}),t.admission_type&&x(t.admission_type),t.transfered_from&&T(t.transfered_from),void(t.phn&&Xe(t.phn));var t}},"Admit")},ignoreRowClick:!0,allowOverflow:!0,button:!0}];return a().createElement("div",{style:et.mainContainer},Pe&&a().createElement("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.5)",display:"flex",justifyContent:"center",alignItems:"center",zIndex:1e3}},a().createElement("div",{style:{color:"white",fontSize:"18px"}},"Loading...")),a().createElement("div",{style:et.card},a().createElement("h2",{style:{fontSize:"24px",fontWeight:"bold",color:"#28a745",marginBottom:"20px",paddingBottom:"10px",borderBottom:"2px solid #28a745",marginTop:0}},"Ward Admission",a().createElement("span",{style:{fontSize:"10px",color:"#912013",marginLeft:"16px",fontWeight:"bold"}},"PATIENT ADMISSION"),a().createElement("button",{onClick:function(){Qe()},style:{marginLeft:"20px",backgroundColor:"#17a2b8",color:"white",border:"none",padding:"8px 16px",borderRadius:"4px",cursor:"pointer",fontSize:"14px",float:"right"}},"Refresh Referral List")),a().createElement("div",{style:{backgroundColor:"#f8f9fa",padding:"10px",marginBottom:"20px",border:"1px solid #dee2e6",borderRadius:"4px",fontSize:"12px"}},a().createElement("strong",null,"Hospital:")," ",Je," | ",a().createElement("strong",null,"Referral Patients:")," ",Se.length),a().createElement("div",{style:{marginBottom:"30px"}},a().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"15px"}},a().createElement("h3",{style:{color:"#495057",fontSize:"24px",fontWeight:"bold",margin:0}},"Patients Waiting for Admission"),a().createElement("div",{style:{display:"flex",alignItems:"center",gap:"10px"}},a().createElement("span",{style:{fontSize:"14px",fontWeight:"bold"}},"Search:"),a().createElement("input",{type:"text",placeholder:"Search by Name or PHN...",style:y(g({},et.input),{width:"250px",marginBottom:0}),value:nt,onChange:function(e){return rt(e.target.value)}}))),a().createElement(i.Ay,{columns:it,data:lt,pagination:!0,paginationResetDefaultPage:ot,persistTableHead:!0,progressPending:Be&&0===Se.length,progressComponent:a().createElement("div",{style:{padding:"20px"}},"Loading referral patients..."),customStyles:{headRow:{style:{borderTop:"1px solid #dee2e6",borderLeft:"1px solid #dee2e6",borderRight:"1px solid #dee2e6",borderRadius:"8px 8px 0 0",backgroundColor:"#f8f9fa"}},headCells:{style:{color:"#333",fontWeight:"bold",fontSize:"14px",padding:"12px"}},cells:{style:{fontSize:"14px",padding:"12px",color:"#555"}},rows:{style:{minHeight:"48px","&:not(:last-of-type)":{borderBottom:"1px solid #eee"},"&:hover":{backgroundColor:"#f1f8e9",transition:"0.2s"}}}},highlightOnHover:!0,noDataComponent:a().createElement("div",{style:{padding:"20px"}},"No patients waiting for admission.")})),a().createElement("h2",{style:et.sectionTitle},"Patient Information"),a().createElement("div",{style:y(g({},et.gridTwoColumn),{marginBottom:"20px"})},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Enter PHN"),a().createElement("input",{style:et.input,placeholder:"Enter PHN to search...",value:d,onChange:function(e){return p(e.target.value)},onKeyPress:function(e){return"Enter"===e.key&&Xe()}})),a().createElement("div",{style:{display:"flex",alignItems:"flex-end"}},a().createElement("button",{style:et.buttonSecondary,onClick:function(){return Xe()},disabled:Ae},Ae?"Searching...":"Search Patient"))),a().createElement("div",{style:{backgroundColor:"#f9f9f9",padding:"15px",borderRadius:"4px",border:"1px solid #e0e0e0",marginBottom:"30px"}},a().createElement("div",{style:et.gridTwoColumn},a().createElement("div",null,a().createElement("strong",null,"Full Name:")," ",(null==he?void 0:he.fullName)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"Gender:")," ",(null==he?void 0:he.gender)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"NIC No:")," ",(null==he?void 0:he.nic)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"Address:")," ",(null==he?void 0:he.address)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"Date Of Birth:")," ",(null==he?void 0:he.dob)||"No Data"),a().createElement("div",null,a().createElement("strong",null,"Age:")," ",(null==he||null===(e=he.age)||void 0===e?void 0:e.y)?"Y:".concat(he.age.y," M:").concat(he.age.m," D:").concat(he.age.d):"No Data"),a().createElement("div",{style:{gridColumn:"span 2"}},a().createElement("strong",null,"Guardian Info:")," ",(null==he?void 0:he.guardianInfo)||"No Data"))),a().createElement("h2",{style:et.sectionTitle},"Admission Details"),a().createElement("div",{style:et.gridTwoColumn},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Admission Type ",a().createElement("span",{style:{color:"red"}},"*")),a().createElement("select",{style:et.select,value:E,onChange:function(e){x(e.target.value),"Internal Transfer"!==e.target.value&&j("New")}},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Direct"},"Direct"),a().createElement("option",{value:"Internal Transfer"},"Internal Transfer"),a().createElement("option",{value:"External Transfer"},"External Transfer"))),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Transferred From"),a().createElement("input",{style:et.input,value:S,onChange:function(e){return T(e.target.value)},disabled:"Direct"===E})),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"BHT Received"),a().createElement("select",{style:et.select,value:N,onChange:function(e){return D(e.target.value)},disabled:"Direct"===E},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Yes"},"Yes"),a().createElement("option",{value:"No"},"No"))),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Documents Received"),a().createElement("select",{style:et.select,value:P,onChange:function(e){return I(e.target.value)},disabled:"Direct"===E},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Yes"},"Yes"),a().createElement("option",{value:"No"},"No")))),"Internal Transfer"===E&&a().createElement("div",{style:{marginTop:"20px",padding:"15px",border:"1px dashed #28a745",borderRadius:"4px"}},a().createElement("label",{style:et.label},"Select BHT Option"),a().createElement("div",{style:et.radioGroup},a().createElement("label",{style:{cursor:"pointer"}},a().createElement("input",{type:"radio",name:"bht",value:"New",checked:"New"===A,onChange:function(){return j("New")}})," ","New BHT"),a().createElement("label",{style:{cursor:"pointer"}},a().createElement("input",{type:"radio",name:"bht",value:"Existing",checked:"Existing"===A,onChange:function(){return j("Existing")}})," ","Continue with existing BHT"))),a().createElement("div",{style:y(g({},et.gridTwoColumn),{marginTop:"20px"})},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Ward ",a().createElement("span",{style:{color:"red"}},"*")),a().createElement("select",{style:et.select,value:B,onChange:function(e){return R(e.target.value)}},a().createElement("option",{value:"0"},"--Select--"),Ne.map((function(e){return a().createElement("option",{key:e.uuid,value:e.uuid},e.name)})))),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Admission Priority"),a().createElement("select",{style:y(g({},et.select),{color:"Stat"===z?"red":"inherit",borderColor:"Stat"===z?"red":"#ccc"}),value:z,onChange:function(e){return W(e.target.value)}},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"See Early"},"See Early"),a().createElement("option",{value:"Stat"},"Stat"))),a().createElement("div",{style:{display:"flex",alignItems:"center",marginTop:"30px"}},a().createElement("label",{style:{display:"flex",alignItems:"center",fontSize:"14px",fontWeight:"bold",cursor:"pointer"}},a().createElement("input",{type:"checkbox",checked:L,onChange:function(e){return H(e.target.checked)},style:{marginRight:"10px",transform:"scale(1.2)"}}),"Injury")),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Transport ",a().createElement("span",{style:{color:"red"}},"*")),a().createElement("div",{style:et.radioGroup},a().createElement("label",{style:{cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"center"}},a().createElement("input",{type:"radio",name:"transport",value:"Trolley",checked:"Trolley"===Y,onChange:function(e){return M(e.target.value)}}),a().createElement("span",{style:{fontSize:"12px"}},"Trolley")),a().createElement("label",{style:{cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"center"}},a().createElement("input",{type:"radio",name:"transport",value:"Wheelchair",checked:"Wheelchair"===Y,onChange:function(e){return M(e.target.value)}}),a().createElement("span",{style:{fontSize:"12px"}},"Wheelchair")),a().createElement("label",{style:{cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"center"}},a().createElement("input",{type:"radio",name:"transport",value:"Walk",checked:"Walk"===Y,onChange:function(e){return M(e.target.value)}}),a().createElement("span",{style:{fontSize:"12px"}},"Walk"))))),a().createElement("div",{style:{marginTop:"30px"}},a().createElement("h2",{style:et.sectionTitle},"Guardian Details"),a().createElement("div",{style:et.gridTwoColumn},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Guardian Name"),a().createElement("input",{style:et.input,value:J,onChange:function(e){return K(e.target.value)}})),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Guardian Contact No"),a().createElement("input",{style:et.input,value:q,onChange:function(e){return Q(e.target.value)}})),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Guardian NIC No"),a().createElement("input",{style:et.input,value:Z,onChange:function(e){return ee(e.target.value)}})),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Guardian Relation"),a().createElement("input",{style:et.input,value:ne,onChange:function(e){return re(e.target.value)}})),a().createElement("div",{style:y(g({},et.inputGroup),{gridColumn:"span 2"})},a().createElement("label",{style:et.label},"Guardian Address"),a().createElement("input",{style:et.input,value:oe,onChange:function(e){return le(e.target.value)}})))),a().createElement("div",{style:{marginTop:"30px"}},a().createElement("h2",{style:et.sectionTitle},"Legal Information"),a().createElement("div",{style:et.gridTwoColumn},a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Judicial Action"),a().createElement("select",{style:et.select,value:se,onChange:function(e){return ce(e.target.value)}},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Yes"},"Yes"),a().createElement("option",{value:"No"},"No"))),a().createElement("div",{style:et.inputGroup},a().createElement("label",{style:et.label},"Informed to Police"),a().createElement("select",{style:et.select,value:de,onChange:function(e){return pe(e.target.value)}},a().createElement("option",{value:"0"},"--Select--"),a().createElement("option",{value:"Yes"},"Yes"),a().createElement("option",{value:"No"},"No"))))),a().createElement("div",{style:et.buttonContainer},a().createElement("button",{style:et.buttonPrimary,onClick:function(){return m((function(){var e,t,n,r,a,i,c,p,f,g,y,x,w,T,C,D,k,I,_,A,j,O,R,G,W,U,H,F,M;return b(this,(function(V){switch(V.label){case 0:if(!(d.trim()?"0"===E?(l().fire({title:"Validation Error!",text:"Please select admission type.",icon:"error",confirmButtonColor:"#dc3545"}),0):"0"===B?(l().fire({title:"Validation Error!",text:"Please select a ward.",icon:"error",confirmButtonColor:"#dc3545"}),0):Y?J.trim()||(l().fire({title:"Validation Error!",text:"Please enter guardian name.",icon:"error",confirmButtonColor:"#dc3545"}),0):(l().fire({title:"Validation Error!",text:"Please select transport method.",icon:"error",confirmButtonColor:"#dc3545"}),0):(l().fire({title:"Validation Error!",text:"Please enter PHN number.",icon:"error",confirmButtonColor:"#dc3545"}),0)))return[2];if(!he)return l().fire({title:"Error!",text:"Please search for a patient first.",icon:"error",confirmButtonColor:"#dc3545"}),[2];V.label=1;case 1:return V.trys.push([1,14,15,16]),Ie(!0),console.log("Starting full admission workflow..."),[4,Promise.all([fetch("".concat(v,"/patient/").concat(he.uuid)).then((function(e){return e.json()})),fetch("".concat(v,"/location/").concat(Ye||Le)).then((function(e){return e.json()})),fetch("".concat(v,"/users/").concat(ze)).then((function(e){return e.json()})),fetch("".concat(v,"/visittype")).then((function(e){return e.json()})),fetch("".concat(v,"/encountertype")).then((function(e){return e.json()}))])];case 2:if(e=h.apply(void 0,[V.sent(),5]),t=e[0],n=e[1],r=e[2],a=e[3],i=e[4],c=t.id,p=Array.isArray(n)?n[0]:n,f=Array.isArray(r)?r[0]:r,g=Array.isArray(a)?a[0]:a,y=Array.isArray(i)?i[0]:i,console.log("Internal IDs fetched:",{internalPatientId:c,internalLocationId:p,internalUserId:f,visitTypeId:g,encounterTypeId:y}),!(c&&p&&g&&y))throw new Error("Could not resolve all necessary internal IDs (Patient, Location, Visit Type, or Encounter Type). Please check your database metadata.");return x=new Date,w={patient_id:c,location_id:p,visit_type_id:g,creator:f},[4,fetch("".concat(v,"/visit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)})];case 3:if(!(T=V.sent()).ok)throw new Error("Failed to create visit: ".concat(T.statusText));return[4,T.json()];case 4:return C=V.sent(),D=C.visit_id,k={encounter_type:y,patient_id:c,location_id:p,creator:f,visit_id:D},[4,fetch("".concat(v,"/encounter"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)})];case 5:if(!(I=V.sent()).ok)throw new Error("Failed to create encounter: ".concat(I.statusText));return[4,I.json()];case 6:return _=V.sent(),A=_.uuid,j=x.toISOString().split("T")[0],O=x.toTimeString().split(" ")[0].substring(0,5),R={id:fe||0,phn:d,locationuuid:Ye||Le,encounteruuid:A,BHT_No:"0",admission_type:E,transfered_from:S,bht_received:"0"===N?"":N,document_received:"0"===P?"":P,ward:B,admission_date:j,admission_time:O,status:"Admitted",guardian_name:J,guardian_telno:q,guardian_nic:Z,guardian_relation:ne,guardian_address:oe,judicial_action:"0"===se?"":se,informed_to_police:"0"===de?"":de,injury:L?"Yes":"No",admissionPriority:"0"===z?"":z,transport:Y,cby:ze,date_created:x.toISOString()},[4,fetch("".concat(v,"/save"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R)})];case 7:if(!(G=V.sent()).ok)throw new Error("Failed to save ward admission record");return[4,G.json()];case 8:return W=V.sent(),(U=W.BHT_No||W.bht_No)&&xe(U),fe?(H="Clinic"===E?"/savereferralClinicStatus":"/savereferralStatus",[4,fetch("".concat(v).concat(H),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:fe})})]):[3,10];case 9:V.sent(),V.label=10;case 10:return V.trys.push([10,12,,13]),[4,fetch("".concat(v,"/updatetokenwithencounter/").concat(d,"/").concat(Ye||Le,"/").concat(A))];case 11:return V.sent(),[3,13];case 12:return F=V.sent(),console.warn("Token update failed (non-critical):",F),[3,13];case 13:return l().fire({title:"Success!",html:'\n <div style="text-align: center;">\n <h3 style="color: #28a745; margin-bottom: 20px; font-size: 24px;">Patient Admitted Successfully!</h3>\n '.concat(U?'\n <div style="background-color: #f0f8f4; padding: 20px; border-radius: 8px; border: 2px solid #28a745; margin: 15px 0;">\n <p style="margin: 0; font-size: 16px; color: #333;">BHT Number</p>\n <h2 style="margin: 10px 0; color: #28a745; font-size: 32px; font-weight: bold;">'.concat(U,"</h2>\n </div>\n "):"",'\n <p style="margin-top: 20px;">Do you want to print ward Admission?</p>\n </div>\n '),icon:"success",showCancelButton:!0,confirmButtonText:"Yes, Print",cancelButtonText:"No",confirmButtonColor:"#28a745"}).then((function(e){return m((function(){return b(this,(function(t){switch(t.label){case 0:return e.isConfirmed?[4,m((function(){var e,t,n,r,a,l;return b(this,(function(i){switch(i.label){case 0:return o.current?(e=new s.uE({orientation:"landscape",unit:"mm",format:"a4"}),[4,u()(o.current,{scale:2,useCORS:!0,logging:!1,backgroundColor:"#ffffff"})]):[2];case 1:return t=i.sent(),n=t.toDataURL("image/png"),r=e.getImageProperties(n),a=e.internal.pageSize.getWidth(),l=r.height*a/r.width,e.addImage(n,"PNG",0,0,a,l),e.save("Patient Admission Form.pdf"),[2]}}))}))()]:[3,2];case 1:t.sent(),t.label=2;case 2:return Qe(),Ze(),[2]}}))}))()})),[3,16];case 14:return M=V.sent(),console.error("Error in admission workflow:",M),l().fire({title:"Error!",text:"Admission failed: ".concat((K=M,$=Error,(null!=$&&"undefined"!=typeof Symbol&&$[Symbol.hasInstance]?$[Symbol.hasInstance](K):K instanceof $)?M.message:"Unknown error")),icon:"error",confirmButtonColor:"#dc3545"}),[3,16];case 15:return Ie(!1),[7];case 16:return[2]}var K,$}))}))()},disabled:Pe},Pe?"Saving...":"Save"),a().createElement("button",{style:et.buttonDanger,onClick:Ze},"Cancel"))),a().createElement("div",{style:et.printTemplateWrapper},a().createElement("div",{style:et.printTemplate,ref:o},a().createElement("div",{style:{textAlign:"center",marginBottom:"20px"}},a().createElement("h1",{style:{fontSize:"24px",margin:"0",color:"black"}},"Patient Admission Form"),a().createElement("hr",{style:{border:"1px solid black"}})),a().createElement("table",{style:et.printTable},a().createElement("tbody",null,a().createElement("tr",null,a().createElement("th",{style:et.printTh,colSpan:2},"Hospital: ",Je),a().createElement("th",{style:et.printTh,colSpan:2},"PHN: ",(null==he?void 0:he.phn)||d)),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Patient Name:")),a().createElement("td",{style:et.printTd},(null==he?void 0:he.fullName)||"-"),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"BHT Number:")),a().createElement("td",{style:y(g({},et.printTd),{fontWeight:"bold"})},Ee)),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"NIC Number:")),a().createElement("td",{style:et.printTd},(null==he?void 0:he.nic)||"-"),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Date:")),a().createElement("td",{style:et.printTd},(new Date).toLocaleDateString())),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Address:")),a().createElement("td",{style:et.printTd},(null==he?void 0:he.address)||"-"),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Time:")),a().createElement("td",{style:et.printTd},(new Date).toLocaleTimeString())),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Guardian:")),a().createElement("td",{style:et.printTd},J),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Age:")),a().createElement("td",{style:et.printTd},(null==he||null===(t=he.age)||void 0===t?void 0:t.y)||"-"," Years")),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Ward:")),a().createElement("td",{style:et.printTd},(null===(n=Ne.find((function(e){return e.uuid===B})))||void 0===n?void 0:n.name)||"-"),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Gender:")),a().createElement("td",{style:et.printTd},(null==he?void 0:he.gender)||"-")),a().createElement("tr",null,a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Transport:")),a().createElement("td",{style:et.printTd},Y),a().createElement("td",{style:et.printTd},a().createElement("strong",null,"Priority:")),a().createElement("td",{style:et.printTd},"0"===z?"-":z)))),a().createElement("div",{style:{marginTop:"50px",fontSize:"12px",textAlign:"right"}},a().createElement("p",null,"Generated by: Ward Admission System | ",(new Date).toLocaleString())))))}}}]);
package/dist/routes.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":">=2.2.0"},"extensions":[{"name":"Red box","component":"redBox","slot":"Boxes"},{"name":"Blue box","component":"blueBox","slot":"Boxes"},{"name":"Brand box","component":"blueBox","slot":"Boxes"}],"pages":[{"component":"root","route":"root"},{"component":"wardAdmission","route":"ward-admission"},{"component":"wardCheckin","route":"ward-checkin"}],"version":"1.0.9"}
1
+ {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":">=2.2.0"},"extensions":[{"name":"Red box","component":"redBox","slot":"Boxes"},{"name":"Blue box","component":"blueBox","slot":"Boxes"},{"name":"Brand box","component":"blueBox","slot":"Boxes"}],"pages":[{"component":"root","route":"root"},{"component":"wardAdmission","route":"ward-admission"},{"component":"wardCheckin","route":"ward-checkin"}],"version":"1.0.10"}
@@ -526,7 +526,7 @@
526
526
  "auxiliaryFiles": [
527
527
  "628.js.map"
528
528
  ],
529
- "hash": "8c5f3b1d96f9b2de",
529
+ "hash": "9c962a2f47d3ae22",
530
530
  "childrenByOrder": {}
531
531
  },
532
532
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sasindi/ward-admission",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "license": "MPL-2.0",
5
5
  "description": "An OpenMRS seed application for building microfrontends",
6
6
  "browser": "dist/ward-admission.js",