UNPKG

@ugandaemr/esm-ugandaemr-app

Version:

UgandaEMR microfrontend built on top of OpenMRS 3.x and OHRI

1 lines 4.32 kB
"use strict";(globalThis.webpackChunk_ugandaemr_esm_ugandaemr_app=globalThis.webpackChunk_ugandaemr_esm_ugandaemr_app||[]).push([[335],{8692:(n,e,t)=>{t.r(e),t.d(e,{ProgramEnrollmentSubmissionAction:()=>c,default:()=>p});var r=t(6806),o=t.n(r),i=t(1e3),l=t(1300),a=t(818);function u(n,e,t,r,o,i,l){try{var a=n[i](l),u=a.value}catch(n){return void t(n)}a.done?e(u):Promise.resolve(u).then(r,o)}var s,d,c={applyAction:(s=function(n,e){var t,r,u,s,d,c,p,h,b,w,v,g,y,k,C,E,D,P;return function(n,e){var t,r,o,i,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;l;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return l.label++,{value:i[1],done:!1};case 5:l.label++,r=i[1],i=[0];continue;case 7:i=l.ops.pop(),l.trys.pop();continue;default:if(!((o=(o=l.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){l=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){l.label=i[1];break}if(6===i[0]&&l.label<o[1]){l.label=o[1],o=i;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(i);break}o[2]&&l.ops.pop(),l.trys.pop();continue}i=e.call(n,l)}catch(n){i=[6,n],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}(this,(function(S){switch(S.label){case 0:if(t=n.patient,r=n.encounters,u=n.sessionMode,b=r[0],w=b.location.uuid,v=function(n,e){return(0,i.translateFrom)("@openmrs/openmrs-form-engine-lib",n,e)},g=e.programUuid,"view"===u)return[2];if(!g)throw new Error("Program UUID not configured");return y=null===(d=b.obs)||void 0===d||null===(s=d.find((function(n){return n.formFieldPath.includes(e.enrollmentDate||null)})))||void 0===s?void 0:s.value,k=null===(p=b.obs)||void 0===p||null===(c=p.find((function(n){return n.formFieldPath.includes(e.completionDate||null)})))||void 0===c?void 0:c.value,C=new AbortController,E={patient:t.id,program:g,dateEnrolled:null!=y?y:o()().format(),location:w},[4,(0,l.getPatientEnrolledPrograms)(t.id)];case 1:if(D=S.sent(),P=null===(h=D)||void 0===h?void 0:h.results.find((function(n){return n.program.uuid===g&&!n.dateCompleted})),e.completionDate){if(!k)throw new Error("Completion date was not found in the encounter");if(!P)return(0,i.showSnackbar)({title:v("enrollmentDiscontinuationNotAllowed","Enrollment discontinuation not allowed"),subtitle:v("cannotDiscontinueEnrollment","Cannot discontinue an enrollment that does not exist"),kind:"error",isLowContrast:!1}),[2];E={uuid:P.uuid,dateCompleted:f(k)}}if(P){if(!P.dateCompleted&&!k)return"enter"===u&&(0,i.showSnackbar)({title:v("enrollmentNotAllowed","Enrollment not allowed"),subtitle:v("alreadyEnrolledDescription","This patient is already enrolled in the selected program and cannot be enrolled again."),kind:"error",isLowContrast:!1}),[2];if(P.dateCompleted)return"enter"===u&&(0,i.showSnackbar)({title:v("enrollmentAlreadyDiscontinued","Enrollment already discontinued"),subtitle:v("alreadyDiscontinuedDescription","This patient is already enrolled in the selected program and has already been discontinued."),kind:"error",isLowContrast:!1}),[2]}return(0,l.saveProgramEnrollment)(E,C).then((function(n){(0,i.showSnackbar)({kind:"success",title:m(v,n),isLowContrast:!0})}),(function(n){(0,i.showSnackbar)({title:v("errorSavingEnrollment","Error saving enrollment"),subtitle:(0,a.c)(n).join(", "),kind:"error",isLowContrast:!1})})),[2]}}))},d=function(){var n=this,e=arguments;return new Promise((function(t,r){var o=s.apply(n,e);function i(n){u(o,t,r,i,l,"next",n)}function l(n){u(o,t,r,i,l,"throw",n)}i(void 0)}))},function(n,e){return d.apply(this,arguments)})};function m(n,e){return e.data.dateCompleted?n("enrollmentDiscontinued","The patient's program enrollment has been successfully discontinued."):n("enrolledToProgram","The patient has been successfully enrolled in the program.")}function f(n){if(!n.endsWith("T00:00:00.000+0000"))return n;var e=o()();return o()(n).hour(e.hour()).minute(e.minute()).second(e.second()).millisecond(e.millisecond()).format()}const p=c}}]);