@icap-ethiopia/esm-ethiohri-phrh
Version:
An OpenMRS seed application for building microfrontends
1 lines • 11.6 kB
JavaScript
;(globalThis.webpackChunk_icap_ethiopia_esm_ethiohri_phrh=globalThis.webpackChunk_icap_ethiopia_esm_ethiohri_phrh||[]).push([[238],{630:(e,n,t)=>{t.d(n,{bQ:()=>u,zv:()=>c});var r=t(231),o=t.n(r),l=t(5987);function a(e){return e.includes(".")&&(e=e.split(".")[0]),o()(e,"YYYY-MM-DDTHH:mm:ss",!0).toDate()}function i(e,n){return a(n.obsDatetime)-a(e.obsDatetime)}function u(e,n){return function(e,n,t,r){var o,a,u,c,s,d,f,v,p,m,b,h=function(e,n){var t,r,o,l,a=(null===(r=e)||void 0===r||null===(t=r.obs)||void 0===t?void 0:t.filter((function(e){return e.concept.uuid===n})))||[];return 1==(null===(o=a)||void 0===o?void 0:o.length)?a[0]:null===(l=a)||void 0===l?void 0:l.sort(i)[0]}(e,n);return h?r?"1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"==(null===(c=h)||void 0===c||null===(u=c.value)||void 0===u?void 0:u.uuid)?"Yes":"No":t?(0,l.formatDate)((0,l.parseDate)(null===(s=h)||void 0===s?void 0:s.value),{mode:"wide",noToday:!0,time:!1}):"object"==typeof h.value&&(null===(a=h)||void 0===a||null===(o=a.value)||void 0===o?void 0:o.names)?(null===(v=h.value)||void 0===v||null===(f=v.names)||void 0===f||null===(d=f.find((function(e){var n;return"SHORT"===(null===(n=e)||void 0===n?void 0:n.conceptNameType)})))||void 0===d?void 0:d.name)||(null===(b=h)||void 0===b||null===(m=b.value)||void 0===m||null===(p=m.name)||void 0===p?void 0:p.name):h.value:"--"}(e,n,arguments.length>2&&void 0!==arguments[2]&&arguments[2],arguments.length>3&&void 0!==arguments[3]&&arguments[3])}var c=function(e){var n=new Date(e);return o()(n).format("YYYY-MM-DD")}},9238:(e,n,t)=>{t.r(n),t.d(n,{default:()=>U});var r=t(6072),o=t.n(r),l=t(941),a=t(9785),i=t(5987),u=t(7677),c=t(8322),s=t(3901),d=t(9208),f=t(5973),v=t(2250),p=t(6818),m=t(4200),b=t(3371),h=t(630);function y(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function w(e,n,t,r,o,l,a){try{var i=e[l](a),u=i.value}catch(e){return void t(e)}i.done?n(u):Promise.resolve(u).then(r,o)}function A(e){return function(){var n=this,t=arguments;return new Promise((function(r,o){var l=e.apply(n,t);function a(e){w(l,r,o,a,i,"next",e)}function i(e){w(l,r,o,a,i,"throw",e)}a(void 0)}))}}function g(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function D(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),r.forEach((function(n){g(e,n,t[n])}))}return e}function E(e,n){return n=null!=n?n:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):function(e){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n.push.apply(n,t)}return n}(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})),e}function O(e){return function(e){if(Array.isArray(e))return y(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||S(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e,n){if(e){if("string"==typeof e)return y(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?y(e,n):void 0}}function k(e,n){var t,r,o,l,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return l={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(l){return function(i){return function(l){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,r=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){a.label=l[1];break}if(6===l[0]&&a.label<o[1]){a.label=o[1],o=l;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(l);break}o[2]&&a.ops.pop(),a.trys.pop();continue}l=n.call(e,a)}catch(e){l=[6,e],r=0}finally{t=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,i])}}}const U=function(e){var n,t,y,w,g,U,C,j,N,x=e.encounter,I=e.type,T=e.mutateEncounters,P=(new Date).toISOString(),Y=(0,i.usePatient)(),_=null===(n=Y)||void 0===n?void 0:n.patientUuid,M=(0,i.useSession)(),V=(0,p.V)().facilityInfo,q=(j=(0,r.useState)(!1),N=2,function(e){if(Array.isArray(e))return e}(j)||function(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,o,l=[],a=!0,i=!1;try{for(t=t.call(e);!(a=(r=t.next()).done)&&(l.push(r.value),!n||l.length!==n);a=!0);}catch(e){i=!0,o=e}finally{try{a||null==t.return||t.return()}finally{if(i)throw o}}return l}}(j,N)||S(j,N)||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.")}()),B=q[0],F=q[1],H=(0,a.mN)({resolver:(0,f.t)(s.cG),defaultValues:x?(0,d.j)(x,v.Aq,v.b8):v.Aq,mode:"all"}),z=H.control,G=H.handleSubmit,R=(H.watch,H.setError),W=H.clearErrors,$=(H.setValue,H.formState),K=$.errors,Q=$.touchedFields,J=(0,a.jz)({control:z,name:"coupon"}),L=J.fields,X=J.replace,Z=(0,a.FH)({control:z}),ee=null===(w=x)||void 0===w||null===(y=w.obs)||void 0===y||null===(t=y.find((function(e){var n,t;return(null===(t=e)||void 0===t||null===(n=t.concept)||void 0===n?void 0:n.uuid)===v.b8.followUpDate})))||void 0===t?void 0:t.value,ne=(C=A((function(e){var n,t,r,o;return k(this,(function(l){switch(l.label){case 0:n=e.coupon.map((function(e){return e.value})).filter(Boolean),l.label=1;case 1:return l.trys.push([1,3,,4]),[4,(0,c.x)(n,new AbortController)];case 2:return t=l.sent().results,r=!0,L.forEach((function(e,n){return W("coupon.".concat(n,".value"))})),t.forEach((function(n){var t=e.coupon.findIndex((function(e){return e.value===n.couponId}));if(-1!==t){var o=[{condition:!1!==n.isUsed,message:"This coupon ID has already been used"},{condition:!0!==n.isValid,message:"This coupon ID is invalid"},{condition:null!==n.isReturned,message:"This coupon ID has been returned or has an invalid return status"}].find((function(e){return e.condition}));o&&(R("coupon.".concat(t,".value"),{type:"server",message:o.message}),r=!1)}})),[2,r];case 3:throw o=l.sent(),(0,i.showSnackbar)({title:"Validation Error",kind:"error",subtitle:"Failed to validate coupon IDs with server"}),o;case 4:return[2]}}))})),function(e){return C.apply(this,arguments)}),te=function(){var e=A((function(e){var n,t,r;return k(this,(function(o){switch(o.label){case 0:F(!0),o.label=1;case 1:return o.trys.push([1,3,4,5]),[4,(0,b.g)(e,{namespace:"rfe-forms",touchedFields:Q,encounter:x,conceptsUuid:v.b8,encounterType:m.tY,formUuid:m.aE,encounterDate:P,patientUuid:Y.patientUuid,providerUuid:M.currentProvider.uuid,locationUuid:V.uuid,encounterUuid:null===(n=x)||void 0===n?void 0:n.uuid,mutateEncounters:T,workspaceName:"sns-form-workspace",editMode:null===(t=I)||void 0===t?void 0:t.edit})];case 2:return o.sent(),[3,5];case 3:return r=o.sent(),console.error("Error submitting form:",r),[3,5];case 4:return F(!1),[7];case 5:return[2]}}))}));return function(n){return e.apply(this,arguments)}}(),re=(0,r.useCallback)(A((function(){var e,n,t;return k(this,(function(r){switch(r.label){case 0:return[4,(0,c.t)(_,m.tY,v.b8.followUpDate,(0,h.zv)(Z.followUpDate),new AbortController)];case 1:return t=r.sent(),(null===(e=t)||void 0===e?void 0:e.status)?R("followUpDate",{type:"manual",message:"FollowUp date should not be same as the last followUp date"}):W("followUpDate"),[2,null===(n=t)||void 0===n?void 0:n.status]}}))})),[W,Z.followUpDate,_,R]),oe=function(){var e=A((function(e){var n;return k(this,(function(t){switch(t.label){case 0:return t.trys.push([0,4,,5]),[4,re()];case 1:return t.sent()?[2]:[4,ne(e)];case 2:return t.sent()?[4,te(e)]:[2];case 3:return t.sent(),[3,5];case 4:return n=t.sent(),console.error("Submission error:",n),[3,5];case 5:return[2]}}))}));return function(n){return e.apply(this,arguments)}}();return(0,r.useEffect)((function(){var e=Math.min(Z.numberOfCoupons,5),n=L.length;if(e>n){var t=Array(e-n).fill(null).map((function(){return{value:""}}));X(O(L).concat(O(t)))}else e<n&&X(L.slice(0,e))}),[Z.numberOfCoupons,L,X]),(0,r.useEffect)((function(){Z.followUpDate&&_&&(0,h.zv)(Z.followUpDate)!==ee&&re()}),[Z.followUpDate,_,ee,re]),o().createElement(l.lVW,{onSubmit:G(oe),className:u.A.formNew},o().createElement("div",{className:u.A.scrollableContent},o().createElement(l.nD3,null,o().createElement(l.AsP,{open:!0,title:"Social Network Service",className:u.A.container},o().createElement("div",{className:u.A.formContainer},o().createElement(a.xI,{name:"followUpDate",control:z,render:function(e){var n,t,r=e.field;return o().createElement(i.OpenmrsDatePicker,E(D({id:"followUpDate"},r),{labelText:o().createElement("span",null,"Date of Visit ",o().createElement("span",{className:u.A.required},"*")),value:r.value,maxDate:P,invalid:!!K.followUpDate,invalidText:null===(n=K.followUpDate)||void 0===n?void 0:n.message,isReadOnly:null===(t=I)||void 0===t?void 0:t.view}))}})),o().createElement("div",{className:u.A.formContainer},o().createElement(a.xI,{name:"numberOfCoupons",control:z,render:function(e){var n,t,r=e.field;return o().createElement(l.Q7x,E(D({},r),{id:"numberOfCoupons",label:o().createElement("span",null,"Number of Coupons Given ",o().createElement("span",{className:u.A.required},"*")),min:0,max:5,value:r.value,invalid:!!K.numberOfCoupons,invalidText:null===(n=K.numberOfCoupons)||void 0===n?void 0:n.message,readOnly:null===(t=I)||void 0===t?void 0:t.view,disableWheel:!0,onChange:function(e,n){var t=n.value;r.onChange(""!==t?Number(t):null),r.onBlur()},onKeyDown:function(e){(["e","E","+","-"].includes(e.key)||1===e.key.length&&!/\d/.test(e.key))&&e.preventDefault()}}))}})),L.map((function(e,n){return o().createElement(a.xI,{name:"coupon.".concat(n,".value"),control:z,render:function(e){var t,r,a,i,c,s,d=e.field;return o().createElement(l.ksK,{labelText:o().createElement("span",null,"Coupon ID ",n+1," ",o().createElement("span",{className:u.A.required},"*")),value:d.value,onChange:function(e){d.onChange(e.target.value),d.onBlur()},placeholder:"Enter coupon ID",invalid:Boolean(null===(r=K.coupon)||void 0===r||null===(t=r[n])||void 0===t?void 0:t.value),invalidText:null===(c=K.coupon)||void 0===c||null===(i=c[n])||void 0===i||null===(a=i.value)||void 0===a?void 0:a.message,readOnly:null===(s=I)||void 0===s?void 0:s.view})}})}))))),o().createElement("div",{className:u.A.stickyButtonSet},o().createElement(l.$nd,{kind:"secondary",onClick:function(){return(0,i.closeWorkspace)("sns-form-workspace")},className:u.A.button},"Discard"),!(null===(g=I)||void 0===g?void 0:g.view)&&o().createElement(l.$nd,{className:u.A.button,kind:"primary",type:"submit",disabled:B},B?o().createElement("span",null,o().createElement(l.OuH,null),"Submitting ..."):(null===(U=I)||void 0===U?void 0:U.edit)?"Update":"Save")))}}}]);