oro-sdk 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e,r=require("oro-sdk-apis"),n=(t=r)&&"object"==typeof t&&"default"in t?t.default:t,a=require("oro-toolbox"),o=require("idb-keyval");function i(){i=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},a=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",s=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var a=Object.create((e&&e.prototype instanceof f?e:f).prototype),o=new P(n||[]);return a._invoke=function(t,e,r){var n="suspendedStart";return function(a,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw o;return{value:void 0,done:!0}}for(r.method=a,r.arg=o;;){var i=r.delegate;if(i){var s=w(i,r);if(s){if(s===p)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,o),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var p={};function f(){}function h(){}function d(){}var y={};u(y,a,(function(){return this}));var x=Object.getPrototypeOf,v=x&&x(x(I([])));v&&v!==e&&r.call(v,a)&&(y=v);var g=d.prototype=f.prototype=Object.create(y);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function m(t,e){var n;this._invoke=function(a,o){function i(){return new e((function(n,i){!function n(a,o,i,s){var u=l(t[a],t,o);if("throw"!==u.type){var c=u.arg,p=c.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,i,s)}),(function(t){n("throw",t,i,s)})):e.resolve(p).then((function(t){c.value=t,i(c)}),(function(t){return n("throw",t,i,s)}))}s(u.arg)}(a,o,n,i)}))}return n=n?n.then(i,i):i()}}function w(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=l(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var a=n.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function C(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function I(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:T}}function T(){return{value:void 0,done:!0}}return h.prototype=d,u(g,"constructor",d),u(d,"constructor",h),h.displayName=u(d,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,s,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},b(m.prototype),u(m.prototype,o,(function(){return this})),t.AsyncIterator=m,t.async=function(e,r,n,a,o){void 0===o&&(o=Promise);var i=new m(c(e,r,n,a),o);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},b(g),u(g,s,"Generator"),u(g,a,(function(){return this})),u(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=I,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(C),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],i=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n];if(a.tryLoc<=this.prev&&r.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var o=a;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),C(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var a=n.arg;C(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function s(){s=function(t,e){return new r(t,void 0,e)};var t=RegExp.prototype,e=new WeakMap;function r(t,n,a){var o=new RegExp(t,n);return e.set(o,a||e.get(t)),d(o,r.prototype)}function n(t,r){var n=e.get(r);return Object.keys(n).reduce((function(e,r){var a=n[r];if("number"==typeof a)e[r]=t[a];else{for(var o=0;void 0===t[a[o]]&&o+1<a.length;)o++;e[r]=t[a[o]]}return e}),Object.create(null))}return p(r,RegExp),r.prototype.exec=function(e){var r=t.exec.call(this,e);return r&&(r.groups=n(r,this)),r},r.prototype[Symbol.replace]=function(r,a){if("string"==typeof a){var o=e.get(this);return t[Symbol.replace].call(this,r,a.replace(/\$<([^>]+)>/g,(function(t,e){return"$"+o[e]})))}if("function"==typeof a){var i=this;return t[Symbol.replace].call(this,r,(function(){var t=arguments;return"object"!=typeof t[t.length-1]&&(t=[].slice.call(t)).push(n(t,i)),a.apply(this,t)}))}return t[Symbol.replace].call(this,r,a)},s.apply(this,arguments)}function u(t,e,r,n,a,o,i){try{var s=t[o](i),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,a)}function c(t){return function(){var e=this,r=arguments;return new Promise((function(n,a){var o=t.apply(e,r);function i(t){u(o,n,a,i,s,"next",t)}function s(t){u(o,n,a,i,s,"throw",t)}i(void 0)}))}}function l(){return(l=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function p(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&d(t,e)}function f(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,d(t,e)}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function d(t,e){return(d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function y(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function x(t,e,r){return(x=y()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);var a=new(Function.bind.apply(t,n));return r&&d(a,r.prototype),a}).apply(null,arguments)}function v(t){var e="function"==typeof Map?new Map:void 0;return(v=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return x(t,arguments,h(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,t)})(t)}function g(t,e){if(null==t)return{};var r,n,a={},o=Object.keys(t);for(n=0;n<o.length;n++)e.indexOf(r=o[n])>=0||(a[r]=t[r]);return a}function b(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function m(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return b(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?b(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var w=((e={})[r.MetadataCategory.Personal]="you",e[r.MetadataCategory.ChildPersonal]="child",e[r.MetadataCategory.OtherPersonal]="other",e);function k(t,e){var r,n=w[e];return{birthday:t[n+"Birthday"],firstname:t[n+"Firstname"],gender:t[n+"Gender"],name:t[n+"Name"],phone:t[n+"Phone"],zip:t[n+"Zip"],hid:null!=(r=t[n+"HID"])?r:t[n+"ID"],pharmacy:t[n+"Pharmacy"],address:t[n+"Address"]}}function C(t){var e={};return Object.entries(t.fields).forEach((function(t){var r=t[1];e[t[0]]=r.displayedAnswer?r.displayedAnswer:r.answer})),e}function P(t){return"sess-pkey"+t}var I=function(t){function e(){return t.apply(this,arguments)||this}return f(e,t),e}(v(Error)),T=function(t){function e(){return t.apply(this,arguments)||this}return f(e,t),e}(v(Error)),D=function(t){function e(){return t.apply(this,arguments)||this}return f(e,t),e}(v(Error)),O=function(t){function e(){return t.apply(this,arguments)||this}return f(e,t),e}(v(Error)),M=function(t){function e(){return t.apply(this,arguments)||this}return f(e,t),e}(v(Error)),S=function(t){function e(){return t.apply(this,arguments)||this}return f(e,t),e}(v(Error)),U=function(t){function e(){return t.apply(this,arguments)||this}return f(e,t),e}(v(Error));function L(t,e){return E.apply(this,arguments)}function E(){return(E=c(i().mark((function t(e,r){var n,a,o,s;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.selectedAnswers){t.next=2;break}throw U;case 2:return n=K(e.selectedAnswers),a=Object.fromEntries(e.pages.map((function(t){return Object.entries(t.questions).filter((function(t){var e=t[1];return _(e.triggers||[],n)&&e.kind===r}))})).flat()),o=e.selectedAnswers.reduce((function(t,e){return l({},t,e)}),{}),s=Object.keys(a).map((function(t){return o[t]})),t.abrupt("return",s);case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function A(t,e){return G.apply(this,arguments)}function G(){return(G=c(i().mark((function t(e,r){var n,a,o;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.selectedAnswers){t.next=2;break}throw U;case 2:return n=K(e.selectedAnswers),a=Object.fromEntries(e.pages.map((function(t){return Object.entries(t.questions).filter((function(t){return _(t[1].triggers||[],n)}))})).flat()),o={},t.abrupt("return",Promise.all(e.selectedAnswers.map((function(t){return Object.entries(t)})).flat().filter((function(t){var e=t[0];return a[e]&&a[e].metaCategory===r})).map((function(t){var e=t[0];return F(a[e],t[1]).then((function(t){o[e]=t}))}))).then((function(){return{workflowCreatedAt:e.createdAt,workflowId:e.id,locale:e.locale,fields:o}})).catch((function(t){throw console.error("Error while extracting "+r+" data from workflow",t),t})));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function j(t){return B.apply(this,arguments)}function B(){return(B=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,o.getMany(e.map((function(t){var e;return null!=(e=t.id)?e:t})));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function F(t,e){return R.apply(this,arguments)}function R(){return(R=c(i().mark((function t(e,r){var n,a;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=void 0,t.t0=e.kind,t.next="text-select-group"===t.t0?4:"radio"===t.t0||"radio-card"===t.t0||"select"===t.t0?7:"multiple"===t.t0||"checkbox-group"===t.t0?10:"images"===t.t0?13:17;break;case 4:return e.answers&&(a=r[0]+" "+e.answers[r[1]].text),n=r,t.abrupt("break",18);case 7:return e.answers&&(a=e.answers[r].text),n=r,t.abrupt("break",18);case 10:return a=r.map((function(t){if(e.answers)return e.answers[t].text;throw new U})),n=r,t.abrupt("break",18);case 13:return t.next=15,j(r).then((function(t){return t.map((function(t){return{name:t.name,imageData:t.imageData}}))}));case 15:return n=t.sent,t.abrupt("break",18);case 17:n=r;case 18:return t.abrupt("return",Promise.resolve({answer:n,displayedAnswer:a,kind:e.kind}));case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _(t,e){if("string"==typeof t)return e.includes(t);if(Array.isArray(t))return Array.isArray(t[0])?t.some((function(t){return t.every((function(t){return e.includes(t)}))})):t.every((function(t){return e.includes(t)}));throw Error("[isTriggered] triggers is not typed well")}function K(t){for(var e,r=[],n=m(t);!(e=n()).done;)r.push.apply(r,Object.values(e.value));return r.flat(1)}function N(t,e){return void 0===e&&(e=!0),t.pages.map((function(t){for(var r={},n=0,a=Object.entries(t.questions);n<a.length;n++){var o=a[n],i=o[1];r[o[0]]="body-parts"===i.kind?e?[]:void 0:e&&i.defaultValue?i.defaultValue:void 0}return r}))}function J(t,e,r,n,a,o,i,s){return W.apply(this,arguments)}function W(){return(W=c(i().mark((function t(e,n,a,o,s,u,l,p){var f,h,d,y,x,v,g,b;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:void 0===l&&(l=!0),f=void 0,h=void 0,d=void 0,y=15,x=void 0,v=[],g=9;case 8:if(!(y>0)){t.next=24;break}return t.prev=9,t.delegateYield(i().mark((function t(){var m,w,k,C,P,I,T;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return b=0,p&&p(b++/g,"retrieve_practitioners"),t.next=4,new Promise((function(t){return setTimeout(t,2e3)}));case 4:if(d){t.next=8;break}return t.next=7,o.practiceClient.practiceGetFromUuid(n.uuidPractice);case 7:d=t.sent.uuidAdmin;case 8:return t.next=10,o.practiceClient.practiceGetPractitioners(n.uuidPractice).catch((function(t){return console.log("Error retrieving practitioners",t),[]}));case 10:if(C=t.sent,p&&p(b++/g,"create_consult"),f){t.next=16;break}return t.next=15,q(n,o);case 15:f=t.sent;case 16:if(p&&p(b++/g,"create_lockbox"),h){t.next=21;break}return t.next=20,z(o);case 20:h=t.sent;case 21:if(x){t.next=25;break}return t.next=24,o.guardClient.identityGet(e);case 24:x=t.sent;case 25:return t.next=27,o.grantLockbox(d,h).catch((function(t){console.error("Error while granting lockbox to practitioner admin "+d,t),v.push(t)}));case 27:return p&&p(b++/g,"grant_patient"),P=C.filter((function(t){return t.uuid!==d})).map(function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",o.grantLockbox(e.uuid,h).catch((function(t){console.error("Error while granting lockbox to practitioner",t),y<=1||v.push(t)})));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()),(m={})[r.IndexKey.ConsultationLockbox]=[{grant:{lockboxUuid:h,lockboxOwnerUuid:e},consultationId:f.uuid}],I=m,T=C.map(function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",o.vaultIndexAdd(I,e.uuid).catch((function(t){console.error("[SDK: registration] Error while adding to the practitioner's index "+e.uuid,t),y<=1||v.push(t)})));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()),t.next=33,V(f.uuid,h,a,o,p?{onProgress:p,currentStep:b,stepsTotalNum:g}:void 0).catch((function(t){console.error("[SDK: registration] Some errors happened during image upload",t),y<=1||v.push(t)}));case 33:return++b,p&&p(b++/g,"store_patient_data"),t.next=37,Z(f.uuid,n.isoLanguageRequired,h,a,o).catch((function(t){console.error("[SDK: registration] Some errors happened during patient data upload",t),v.push(t)}));case 37:if(p&&p(b++/g,"set_masterkey"),!s||null!=(w=x)&&w.recoveryMasterKey){t.next=44;break}return t.next=41,o.updateMasterKey(e,s,h).catch((function(t){if(console.error("[SDK: registration] Error while updating master key",t),!(y<=1))return v.push(t),x}));case 41:x=t.sent,t.next=45;break;case 44:s=void 0;case 45:if(p&&p(b++/g,"set_security_questions"),!u||null!=(k=x)&&k.recoverySecurityQuestions){t.next=50;break}return t.next=49,o.updateSecurityQuestions(e,u.recoverySecurityQuestions,u.recoverySecurityAnswers,2).catch((function(t){if(console.error("[SDK: registration] Error while updating security questions",t),!(y<=1))return v.push(t),x}));case 49:x=t.sent;case 50:return t.next=52,Promise.all([].concat(P,T));case 52:if(p&&p(b++/g,"search_indexing"),!l){t.next=56;break}return t.next=56,nt(f,a,o).catch((function(t){console.error("[SDK: registration] personal information not found or another error occured during search indexing",t),y<=1||v.push(t)}));case 56:if(!(v.length>0)){t.next=58;break}throw v;case 58:return t.next=60,o.consultClient.updateConsultByUUID(f.uuid,{statusMedical:r.MedicalStatus.New});case 60:return p&&p(b++/g,"success"),t.abrupt("return","break");case 62:case"end":return t.stop()}}),t)}))(),"t0",11);case 11:if("break"!==t.t0){t.next=14;break}return t.abrupt("break",24);case 14:t.next=21;break;case 16:return t.prev=16,t.t1=t.catch(9),console.error("[SDK] Error occured during registration: "+t.t1+", retrying... Retries remaining: "+y),v=[],t.abrupt("continue",21);case 21:y--,t.next=8;break;case 24:if(!(y<=0)){t.next=27;break}throw console.error("[SDK] registration failed: MAX_RETRIES reached"),"RegistrationFailed";case 27:return console.log("Successfully Registered"),t.next=30,o.cleanIndex();case 30:return t.abrupt("return",{masterKey:s,consultationId:f.uuid,lockboxUuid:h});case 31:case"end":return t.stop()}}),t,null,[[9,16]])})))).apply(this,arguments)}function q(t,e){return Q.apply(this,arguments)}function Q(){return(Q=c(i().mark((function t(e,r){var n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.practiceClient.practiceGetPayment(e.uuidPractice,e.idStripeInvoiceOrPaymentIntent);case 2:if(!(n=t.sent)||!n.uuidConsult){t.next=7;break}return t.abrupt("return",r.consultClient.getConsultByUUID(n.uuidConsult).catch((function(t){throw console.error("Error while retrieving consult",t),t})));case 7:return t.next=9,r.consultClient.consultCreate(e).catch((function(t){throw console.error("Error while creating consult",t),t}));case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function z(t){return H.apply(this,arguments)}function H(){return(H=c(i().mark((function t(e){var r,n,a;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.getGrants();case 2:if(!((r=t.sent).length>0)){t.next=8;break}return console.log("The grant has already been created, skipping lockbox create step"),t.abrupt("return",r[0].lockboxUuid);case 8:return t.next=10,e.vaultClient.lockboxCreate().catch((function(t){throw console.error("Error while creating lockbox",t),t}));case 10:return n=t.sent,t.next=13,e.guardClient.authRefresh();case 13:return a=t.sent,t.next=16,e.guardClient.setTokens({accessToken:a.accessToken,refreshToken:a.refreshToken});case 16:return t.next=18,e.guardClient.whoAmI(!0);case 18:return t.abrupt("return",n.lockboxUuid);case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Z(t,e,r,n,a){return Y.apply(this,arguments)}function Y(){return(Y=c(i().mark((function t(e,n,a,o,s){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Promise.all([s.getOrInsertJsonData(a,o,{category:r.MetadataCategory.Raw,contentType:"application/json",consultationId:e},{}),A(o,r.MetadataCategory.Consultation).then((function(t){return s.getOrInsertJsonData(a,t,{category:r.MetadataCategory.Consultation,documentType:r.DocumentType.PopulatedWorkflowData,consultationId:e},{consultationId:e})})),A(o,r.MetadataCategory.Medical).then((function(t){return s.getOrInsertJsonData(a,t,{category:r.MetadataCategory.Medical,documentType:r.DocumentType.PopulatedWorkflowData,consultationIds:[e]},{})})),X(o,a,e,r.MetadataCategory.Personal,s),X(o,a,e,r.MetadataCategory.ChildPersonal,s),X(o,a,e,r.MetadataCategory.OtherPersonal,s),s.getOrInsertJsonData(a,{isoLanguage:n},{category:r.MetadataCategory.Preference,contentType:"application/json"},{})]).then((function(t){return t.flat()})));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function V(t,e,r,n,a){return $.apply(this,arguments)}function $(){return($=c(i().mark((function t(e,n,a,o,s){var u,c,l,p,f;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=j,t.next=3,L(a,"images-alias");case 3:return t.t1=t.sent.flat(),t.next=6,(0,t.t0)(t.t1);case 6:return c=(u=t.sent).filter((function(t){return!!t})),u.length!==c.length&&console.error("[SDK] Some images have not been found, they have been skipped."),l=0,p=c.length,s&&s.onProgress(s.currentStep/s.stepsTotalNum,"store_images",{storedImagesNum:l,totalImagesNum:p}),f=c.map((function(t){return o.getOrInsertJsonData(n,t,{category:r.MetadataCategory.Consultation,documentType:r.DocumentType.ImageAlias,consultationId:e,idbId:t.idbId},{}).then((function(){if(s){++l;var t=Math.round(100*((s.currentStep+1)/s.stepsTotalNum-s.currentStep/s.stepsTotalNum))/100;s.onProgress(s.currentStep/s.stepsTotalNum+t*(l/p),"store_images",{storedImagesNum:l,totalImagesNum:p})}}))})),t.abrupt("return",Promise.all(f));case 14:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function X(t,e,r,n,a){return tt.apply(this,arguments)}function tt(){return(tt=c(i().mark((function t(e,n,a,o,s){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",A(e,o).then((function(t){if(0!==Object.keys(t.fields).length)return s.getOrInsertJsonData(n,t,{category:o,documentType:r.DocumentType.PopulatedWorkflowData,consultationIds:[a]},{})})));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function et(t){return rt.apply(this,arguments)}function rt(){return(rt=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Promise.all([A(e,r.MetadataCategory.Personal),A(e,r.MetadataCategory.ChildPersonal),A(e,r.MetadataCategory.OtherPersonal)]).then((function(t){return{personalInfoPopulatedWfData:t[0],childPersonalInfoPopulatedWfData:t[1],otherPersonalInfoPopulatedWfData:t[2]}})));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nt(t,e,r){return at.apply(this,arguments)}function at(){return(at=c(i().mark((function t(e,n,a){var o,s,u,c,l,p,f;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=[{kind:"consult-shortid",value:e.shortId}],t.next=3,et(n);case 3:return u=(s=t.sent).childPersonalInfoPopulatedWfData,c=s.otherPersonalInfoPopulatedWfData,l=k(C(s.personalInfoPopulatedWfData),r.MetadataCategory.Personal),p=k(C(u),r.MetadataCategory.ChildPersonal),f=k(C(c),r.MetadataCategory.OtherPersonal),o.push({kind:"first-name",value:l.firstname},{kind:"last-name",value:l.name}),p.firstname&&p.name&&o.push({kind:"first-name",value:p.firstname},{kind:"last-name",value:p.name}),f.firstname&&f.name&&o.push({kind:"first-name",value:f.firstname},{kind:"last-name",value:f.name}),t.next=15,a.searchClient.index(e.uuid,o);case 15:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ot(t,e){return t.map((function(t){if(t.encryptedLockbox&&!t.lockboxUuid)try{t.lockboxUuid=a.uuidParse(e.base64DecryptToBytes(t.encryptedLockbox))}catch(t){console.error("[sdk:index] The grant could not be decrypted or was not a valid UUID: ",t)}return t})).filter((function(t){return t.lockboxUuid}))}function it(t,e){return t.map((function(t){try{return[!0,e.base64DecryptToJson(t.encryptedIndexEntry).grant]}catch(t){return console.error("[sdk:index] The consult lockbox grant could not be decrypted: ",t),[!1,void 0]}})).filter((function(t){return t[0]})).map((function(t){return t[1]}))}function st(t,e){return ut.apply(this,arguments)}function ut(){return(ut=c(i().mark((function t(e,n){var a,o,s,u;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.getGrants();case 2:a=[],o=m(t.sent);case 5:if((s=o()).done){t.next=13;break}return u=s.value,t.next=9,e.vaultClient.lockboxMetadataGet(u.lockboxUuid,["consultationId"],[],{category:r.MetadataCategory.Consultation,consultationId:n.consultationId});case 9:t.sent[0].length>=0&&a.push(u);case 11:t.next=5;break;case 13:return t.abrupt("return",a);case 14:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var ct=function(){function t(t,e,r,n,a,o,i,s,u,c){this.toolbox=t,this.tellerClient=e,this.vaultClient=r,this.guardClient=n,this.searchClient=a,this.practiceClient=o,this.consultClient=i,this.workflowClient=s,this.diagnosisClient=u,this.authenticationCallback=c,this.secrets=[],this.cachedMetadataGrants={},this.cachedManifest={}}var e=t.prototype;return e.cleanIndex=function(){var t=c(i().mark((function t(){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this.cachedMetadataGrants={},this.cachedManifest={};case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.signUp=function(){var t=c(i().mark((function t(e,r,n,o,s,u,c){var l,p,f,h,d,y,x,v;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.rsa=new a.CryptoRSA,l=this.rsa.private(),p=this.toolbox.CryptoChaCha.fromPassphrase(r),f=p.bytesEncryptToBase64Payload(l),h=this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(r)),d=!!c,y={practiceUuid:n.uuid,email:e.toLowerCase(),emailConfirmed:d,password:h,publicKey:this.toolbox.encodeToBase64(this.rsa.public()),recoveryPassword:f,tosAndCpAcceptance:o,tokenData:s,subscription:u},t.next=9,this.guardClient.identityCreate(y);case 9:return(x=t.sent).recoveryLogin&&(v=this.toolbox.CryptoChaCha.fromPassphrase(x.recoveryLogin),sessionStorage.setItem(P(x.id),v.bytesEncryptToBase64Payload(l))),t.abrupt("return",x);case 12:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i,s){return t.apply(this,arguments)}}(),e.confirmEmail=function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.guardClient.setTokens({accessToken:e}),t.next=3,this.guardClient.whoAmI();case 3:return t.abrupt("return",this.guardClient.identityUpdate(t.sent.sub,{emailConfirmed:!0}));case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.signIn=function(){var t=c(i().mark((function t(e,r,n,a){var o,s,u;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(n)),s={practiceUuid:e,email:r.toLowerCase(),password:o,otp:a},t.next=4,this.guardClient.authToken(s);case 4:return t.next=6,this.guardClient.whoAmI();case 6:return u=t.sent.sub,t.next=9,this.recoverPrivateKeyFromPassword(u,n);case 9:return t.next=11,this.guardClient.identityGet(u);case 11:return t.abrupt("return",t.sent);case 12:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a){return t.apply(this,arguments)}}(),e.resumeSession=function(){var t=c(i().mark((function t(){var e,r,n,a,o;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.whoAmI();case 2:return e=t.sent.sub,r=sessionStorage.getItem(P(e)),t.next=6,this.guardClient.identityGet(e);case 6:if((n=t.sent.recoveryLogin)&&r){t.next=9;break}throw I;case 9:a=this.toolbox.CryptoChaCha.fromPassphrase(n),o=a.base64PayloadDecryptToBytes(r),this.rsa=this.toolbox.CryptoRSA.fromKey(o);case 12:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.localEncryptToJsonPayload=function(t){if(!this.rsa)throw this.authenticationCallback&&this.authenticationCallback(new I),new I;var e=new this.toolbox.CryptoChaCha;return{encryptedData:e.jsonEncryptToBase64Payload(t),encryptedKey:this.toolbox.encodeToBase64(this.rsa.encryptToBytes(e.key()))}},e.localDecryptJsonPayload=function(t){var e=t.encryptedKey,r=t.encryptedData;if(!this.rsa)throw this.authenticationCallback&&this.authenticationCallback(new I),new I;var n=this.rsa.base64DecryptToBytes(e);return this.toolbox.CryptoChaCha.fromKey(n).base64PayloadDecryptToJson(r)},e.signOut=function(){var t=c(i().mark((function t(){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.rsa=void 0,this.secrets=[],this.guardClient.setTokens({accessToken:void 0,refreshToken:void 0}),t.next=5,this.guardClient.authLogout();case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.registerPatient=function(){var t=c(i().mark((function t(e,r,n,a,o,s){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===o&&(o=!0),this.rsa){t.next=3;break}throw I;case 3:return t.abrupt("return",J(e,r,n,this,this.toolbox.uuid(),a,o,s));case 4:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i){return t.apply(this,arguments)}}(),e.forceUpdateIndexEntries=function(){var t=c(i().mark((function t(){var e,n,a=this;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:return n=t.sent,t.next=5,Promise.all(n.map(function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,a.vaultClient.lockboxMetadataGet(e.lockboxUuid,["consultationId"],[],{category:r.MetadataCategory.Consultation},e.lockboxOwnerUuid).then((function(t){try{return t[0].map((function(t){return l({},t,{grant:{lockboxOwnerUuid:e.lockboxOwnerUuid,lockboxUuid:e.lockboxUuid}})}))}catch(t){return[]}})).catch((function(){return[]}));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())).then((function(t){return t.flat()}));case 5:this.vaultIndexAdd((e={},e[r.IndexKey.Consultation]=t.sent,e)).then((function(){return alert("The Index was successfully updated!")})).catch((function(){return console.error("The index failed to update!")}));case 7:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.vaultIndexAdd=function(){var t=c(i().mark((function t(e,n){var o,s,u,c,p;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:if(!n){t.next=9;break}return t.next=5,this.guardClient.identityGet(n);case 5:o=this.toolbox.decodeFromBase64(t.sent.publicKey),t.next=10;break;case 9:o=this.rsa.public();case 10:s={},u=0,c=Object.keys(e);case 12:if(!(u<c.length)){t.next=23;break}t.t0=p=c[u],t.next=t.t0===r.IndexKey.ConsultationLockbox?18:20;break;case 18:return s[p]=e[p].map((function(t){return l({},t,{uniqueHash:t.consultationId})})).map((function(t){return{uuid:t.uuid,timestamp:t.timestamp,uniqueHash:t.uniqueHash,encryptedIndexEntry:a.CryptoRSA.jsonWithPubEncryptToBase64({consultationId:t.consultationId,grant:t.grant},o)}})),t.abrupt("break",20);case 20:u++,t.next=12;break;case 23:return t.next=25,this.vaultClient.vaultIndexPut(s,n);case 25:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.grantLockbox=function(){var t=c(i().mark((function t(e,r,n){var o,s,u,c;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return t.next=4,this.getCachedSecretCryptor(r,n);case 4:return o=t.sent.key(),t.next=7,this.guardClient.identityGet(e);case 7:return s=this.toolbox.decodeFromBase64(t.sent.publicKey),u=a.CryptoRSA.bytesWithPubEncryptToBase64(o,s),c={encryptedSecret:u,granteeUuid:e},t.next=13,this.vaultClient.lockboxGrant(r,c,n);case 13:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.createMessageData=function(){var t=c(i().mark((function t(e,n,a,o,s){var u,c,l;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return t.next=4,this.getCachedSecretCryptor(e,o);case 4:return c=(u=t.sent).jsonEncryptToBase64Payload(n),t.t0=u,t.next=9,this.guardClient.whoAmI();case 9:return t.t1=t.sent.sub,t.t2={author:t.t1},l=t.t0.jsonEncryptToBase64Payload.call(t.t0,t.t2),t.abrupt("return",this.tellerClient.lockboxDataStore(e,{data:c,publicMetadata:{consultationId:a,category:r.MetadataCategory.Consultation,documentType:r.DocumentType.Message,contentType:"text/plain"},privateMetadata:l},o,s));case 15:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o){return t.apply(this,arguments)}}(),e.createMessageAttachmentData=function(){var t=c(i().mark((function t(e,n,a,o,s){var u,c,l;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return t.next=4,this.getCachedSecretCryptor(e,o);case 4:return t.t0=u=t.sent,t.t1=Uint8Array,t.next=9,n.arrayBuffer();case 9:return t.t2=t.sent,t.t3=new t.t1(t.t2),c=t.t0.bytesEncryptToBase64Payload.call(t.t0,t.t3),t.t4=u,t.next=15,this.guardClient.whoAmI();case 15:return t.t5=t.sent.sub,t.t6=n.name,t.t7=n.lastModified,t.t8=n.size,t.t9={author:t.t5,fileName:t.t6,lastModified:t.t7,size:t.t8},l=t.t4.jsonEncryptToBase64Payload.call(t.t4,t.t9),t.abrupt("return",this.tellerClient.lockboxDataStore(e,{data:c,publicMetadata:{consultationId:a,category:r.MetadataCategory.Consultation,documentType:r.DocumentType.Message,contentType:n.type},privateMetadata:l},o,s));case 24:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o){return t.apply(this,arguments)}}(),e.createConsultationAttachmentData=function(){var t=c(i().mark((function t(e,n,a,o,s,u){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return t.t0=this,t.t1=e,t.t2=Uint8Array,t.next=7,n.arrayBuffer();case 7:return t.t3=t.sent,t.t4=new t.t2(t.t3),t.t5={consultationId:a,category:r.MetadataCategory.Consultation,documentType:o,contentType:n.type},t.next=12,this.guardClient.whoAmI();case 12:return t.t6=t.sent.sub,t.t7=n.name,t.t8={author:t.t6,fileName:t.t7},t.t9=s,t.t10=u,t.abrupt("return",t.t0.createBytesData.call(t.t0,t.t1,t.t4,t.t5,t.t8,t.t9,t.t10));case 18:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i){return t.apply(this,arguments)}}(),e.createJsonData=function(){var t=c(i().mark((function t(e,r,n,a,o,s){var u,c,l;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return t.next=4,this.getCachedSecretCryptor(e,o);case 4:return c=(u=t.sent).jsonEncryptToBase64Payload(r),l=u.jsonEncryptToBase64Payload(a),t.abrupt("return",this.tellerClient.lockboxDataStore(e,{data:c,publicMetadata:n,privateMetadata:l},o,s));case 9:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i){return t.apply(this,arguments)}}(),e.getOrInsertJsonData=function(){var t=c(i().mark((function t(e,r,n,a,o){var s;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===o&&(o=!1),t.next=3,this.vaultClient.lockboxManifestGet(e,n);case 3:if(s=t.sent,o||!(s.length>0)){t.next=9;break}return console.log("The data for "+JSON.stringify(n)+" already exist"),t.abrupt("return",s[0].dataUuid);case 9:return t.next=11,this.createJsonData(e,r,n,a,void 0,o&&s.length>0?s[0].dataUuid:void 0).catch((function(t){throw console.error("Error while upserting data "+JSON.stringify(n)+" data",t),t}));case 11:return t.abrupt("return",t.sent.dataUuid);case 12:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o){return t.apply(this,arguments)}}(),e.createBytesData=function(){var t=c(i().mark((function t(e,r,n,a,o,s){var u,c,l;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return t.next=4,this.getCachedSecretCryptor(e,o);case 4:return c=(u=t.sent).bytesEncryptToBase64Payload(r),l=u.jsonEncryptToBase64Payload(a),t.abrupt("return",this.tellerClient.lockboxDataStore(e,{data:c,publicMetadata:n,privateMetadata:l},o,s));case 9:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i){return t.apply(this,arguments)}}(),e.getJsonData=function(){var t=c(i().mark((function t(e,r,n){var a;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return t.next=4,Promise.all([this.vaultClient.lockboxDataGet(e,r,n),this.getCachedSecretCryptor(e,n)]);case 4:return t.abrupt("return",(a=t.sent)[1].base64PayloadDecryptToJson(a[0].data));case 8:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.getBytesData=function(){var t=c(i().mark((function t(e,r,n){var a;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return t.next=4,Promise.all([this.vaultClient.lockboxDataGet(e,r,n),this.getCachedSecretCryptor(e,n)]);case 4:return t.abrupt("return",(a=t.sent)[1].base64PayloadDecryptToBytes(a[0].data));case 8:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.getGrants=function(){var t=c(i().mark((function t(e){var n,a,o,s,u,c;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:if(n=JSON.stringify(e),!this.cachedMetadataGrants[n]){t.next=5;break}return t.abrupt("return",this.cachedMetadataGrants[n]);case 5:return t.next=7,this.getAccountRole();case 7:if(1!==(a=t.sent).length||a[0]!==r.OtherRoleType.User){t.next=10;break}return t.abrupt("return",[]);case 10:if(![r.OtherRoleType.Patient,r.OtherRoleType.User].every((function(t){return a.includes(t)}))){t.next=26;break}if(!e){t.next=17;break}return t.next=14,st(this,e);case 14:o=t.sent,t.next=20;break;case 17:return t.next=19,this.vaultClient.grantsGet();case 19:o=t.sent.grants;case 20:return t.next=22,ot(o,this.rsa);case 22:return this.cachedMetadataGrants[n]=s=t.sent,console.info("[sdk:grant] Found grant for patient"),t.abrupt("return",s);case 26:if(e){t.next=28;break}throw D;case 28:return t.next=30,this.vaultClient.vaultIndexGet([r.IndexKey.ConsultationLockbox],[e.consultationId]).then((function(t){return t[r.IndexKey.ConsultationLockbox]})).catch((function(t){return console.error(t),[]}));case 30:if(!((c=it(null!=(u=t.sent)?u:[],this.rsa)).length>0)){t.next=36;break}return console.info("[sdk:index] Grants found in user`s constant time secure index"),this.cachedMetadataGrants[n]=c,t.abrupt("return",this.cachedMetadataGrants[n]);case 36:return t.abrupt("return",[]);case 37:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getAccountRole=function(){var t=c(i().mark((function t(){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.whoAmI();case 2:return t.abrupt("return",t.sent.scope.split(" "));case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.getCachedSecretCryptor=function(){var t=c(i().mark((function t(e,r){var n,a,o;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:if(-1!==(n=this.secrets.findIndex((function(t){return t.lockboxUuid===e})))){t.next=13;break}return t.next=6,this.vaultClient.lockboxSecretGet(e,r);case 6:return a=this.rsa.base64DecryptToBytes(t.sent.sharedSecret),o=this.toolbox.CryptoChaCha.fromKey(a),this.secrets.push({lockboxUuid:e,cryptor:o}),t.abrupt("return",o);case 13:return t.abrupt("return",this.secrets[n].cryptor);case 14:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getPersonalInformationsFromConsultId=function(){var t=c(i().mark((function t(e,r,n){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===n&&(n=!1),t.abrupt("return",this.getMetaCategoryFromConsultId(e,r,n));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.getMedicalDataFromConsultId=function(){var t=c(i().mark((function t(e,n){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===n&&(n=!1),t.abrupt("return",this.getMetaCategoryFromConsultId(e,r.MetadataCategory.Medical,n));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getMetaCategoryFromConsultId=function(){var t=c(i().mark((function t(e,n,a){var o,s,u,p,f,h=this;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===a&&(a=!1),t.next=3,this.getGrants({consultationId:e});case 3:o=t.sent,s=[],u=i().mark((function t(){var o,u;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=f.value,t.next=3,h.getLockboxManifest(o.lockboxUuid,{category:n,documentType:r.DocumentType.PopulatedWorkflowData,consultationIds:[e]},!0,o.lockboxOwnerUuid,a);case 3:if(0!==(u=t.sent).length){t.next=8;break}return t.next=7,h.getLockboxManifest(o.lockboxUuid,{category:n,documentType:r.DocumentType.PopulatedWorkflowData},!0,o.lockboxOwnerUuid,a);case 7:u=t.sent.filter((function(t){return!t.metadata.consultationIds}));case 8:return t.next=10,Promise.all(u.map(function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=o.lockboxOwnerUuid,t.t1=o.lockboxUuid,t.t2=e.dataUuid,t.next=5,h.getJsonData(o.lockboxUuid,e.dataUuid);case 5:return t.t3=t.sent,t.abrupt("return",{lockboxOwnerUuid:t.t0,lockboxUuid:t.t1,dataUuid:t.t2,data:t.t3});case 7:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 10:s=l({},s,t.sent);case 12:case"end":return t.stop()}}),t)})),p=m(o);case 7:if((f=p()).done){t.next=11;break}return t.delegateYield(u(),"t0",9);case 9:t.next=7;break;case 11:return t.abrupt("return",s);case 12:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.getPersonalInformations=function(){var t=c(i().mark((function t(e){var n,a,o,s;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(n=t.sent.find((function(t){return t.lockboxOwnerUuid===e}))){t.next=5;break}throw T;case 5:if(o=n.lockboxOwnerUuid,a=n.lockboxUuid){t.next=8;break}throw O;case 8:if(o){t.next=10;break}throw M;case 10:return t.next=12,this.getLockboxManifest(a,{category:r.MetadataCategory.Personal,documentType:r.DocumentType.PopulatedWorkflowData},!1,e);case 12:return s=t.sent[0].dataUuid,t.t0=o,t.t1=a,t.t2=s,t.next=18,this.getJsonData(a,s);case 18:return t.t3=t.sent,t.abrupt("return",{lockboxOwnerUuid:t.t0,lockboxUuid:t.t1,dataUuid:t.t2,data:t.t3});case 20:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getGrantFromConsultId=function(){var t=c(i().mark((function t(e){var r;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants({consultationId:e});case 2:if(0!==(r=t.sent).length){t.next=5;break}throw S;case 5:return t.abrupt("return",r[0]);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getIdentityFromConsultId=function(){var t=c(i().mark((function t(e){var r;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrantFromConsultId(e);case 2:if(!(r=t.sent)||!r.lockboxOwnerUuid){t.next=9;break}return t.next=6,this.guardClient.identityGet(r.lockboxOwnerUuid);case 6:return t.abrupt("return",t.sent);case 9:return t.abrupt("return",void 0);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getLockboxManifest=function(){var t=c(i().mark((function t(e,r,n,a,o){var s,u=this;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===o&&(o=!1),s=JSON.stringify({lockboxUuid:e,filter:r,expandPrivateMetadata:n,lockboxOwnerUuid:a}),o||!this.cachedManifest[s]){t.next=4;break}return t.abrupt("return",this.cachedManifest[s]);case 4:return t.abrupt("return",this.vaultClient.lockboxManifestGet(e,r,a).then((function(t){return Promise.all(t.map(function(){var t=c(i().mark((function t(r){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!n||!r.metadata.privateMetadata){t.next=5;break}return t.next=3,u.getJsonData(e,r.metadata.privateMetadata,a);case 3:r.metadata=l({},r.metadata,t.sent);case 5:return t.abrupt("return",r);case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())).then((function(t){return u.cachedManifest[s]=t}))})));case 5:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o){return t.apply(this,arguments)}}(),e.createPersonalInformations=function(){var t=c(i().mark((function t(e,n,a){var o,s;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(t.t0=o=t.sent.find((function(t){return t.lockboxOwnerUuid===e.id})),null!=t.t0){t.next=7;break}t.t1=void 0,t.next=8;break;case 7:t.t1=o.lockboxUuid;case 8:if(!(s=t.t1)){t.next=13;break}return t.abrupt("return",this.createJsonData(s,n,{category:r.MetadataCategory.Personal,documentType:r.DocumentType.PopulatedWorkflowData},{},void 0,a));case 13:throw O;case 14:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.createUserPreference=function(){var t=c(i().mark((function t(e,n,a){var o,s;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(t.t0=o=t.sent.find((function(t){return t.lockboxOwnerUuid===e.id})),null!=t.t0){t.next=7;break}t.t1=void 0,t.next=8;break;case 7:t.t1=o.lockboxUuid;case 8:if(!(s=t.t1)){t.next=13;break}return t.abrupt("return",this.createJsonData(s,n,{category:r.MetadataCategory.Preference,contentType:"application/json"},{},void 0,a));case 13:throw O;case 14:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.getDataFromGrant=function(){var t=c(i().mark((function t(e,r){var n,a,o;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=e.lockboxOwnerUuid,n=e.lockboxUuid){t.next=3;break}throw O;case 3:if(a){t.next=5;break}throw M;case 5:return t.next=7,this.getLockboxManifest(n,r,!1,e.lockboxOwnerUuid,!0);case 7:return o=t.sent[0].dataUuid,t.t0=a,t.t1=n,t.t2=o,t.next=13,this.getJsonData(n,o);case 13:return t.t3=t.sent,t.abrupt("return",{lockboxOwnerUuid:t.t0,lockboxUuid:t.t1,dataUuid:t.t2,data:t.t3});case 15:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getUserPreferenceFromConsultId=function(){var t=c(i().mark((function t(e){var n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrantFromConsultId(e);case 2:if(n=t.sent){t.next=5;break}throw T;case 5:return t.abrupt("return",this.getDataFromGrant(n,{category:r.MetadataCategory.Preference,contentType:"application/json"}));case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getUserPreference=function(){var t=c(i().mark((function t(e){var n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(n=t.sent.find((function(t){return t.lockboxOwnerUuid===e.id}))){t.next=5;break}throw T;case 5:return t.abrupt("return",this.getDataFromGrant(n,{category:r.MetadataCategory.Preference,contentType:"application/json"}));case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getRecoveryDataFromConsultId=function(){var t=c(i().mark((function t(e){var n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrantFromConsultId(e);case 2:if(n=t.sent){t.next=5;break}throw T;case 5:return t.abrupt("return",this.getDataFromGrant(n,{category:r.MetadataCategory.Recovery,contentType:"application/json"}));case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getRecoveryData=function(){var t=c(i().mark((function t(e){var n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(n=t.sent.find((function(t){return t.lockboxOwnerUuid===e.id}))){t.next=5;break}throw T;case 5:return t.abrupt("return",this.getDataFromGrant(n,{category:r.MetadataCategory.Recovery,contentType:"application/json"}));case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getAssignedConsultations=function(){var t=c(i().mark((function t(e){var n=this;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=Promise,t.next=3,this.getGrants();case 3:return t.t1=t.sent.map((function(t){return n.getLockboxManifest(t.lockboxUuid,{category:r.MetadataCategory.Consultation,documentType:r.DocumentType.PopulatedWorkflowData},!0,void 0).then((function(t){return Promise.all(t.map(function(){var t=c(i().mark((function t(r){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,n.consultClient.getConsultByUUID(r.metadata.consultationId,e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())).then((function(t){return t.flat()}))}))})),t.abrupt("return",t.t0.all.call(t.t0,t.t1).then((function(t){return t.flat()})));case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getPastConsultationsFromConsultId=function(){var t=c(i().mark((function t(e,n){var a,o,s=this;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrantFromConsultId(e);case 2:if(a=t.sent){t.next=5;break}return t.abrupt("return",void 0);case 5:return t.next=7,this.vaultClient.lockboxMetadataGet(a.lockboxUuid,["consultationId"],["consultationId"],{category:r.MetadataCategory.Consultation,documentType:r.DocumentType.PopulatedWorkflowData},a.lockboxOwnerUuid);case 7:if(0!=(o=t.sent.flat().map((function(t){return t.consultationId}))).length){t.next=10;break}return t.abrupt("return",[]);case 10:return t.next=12,Promise.all(o.map(function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.consultClient.getConsultByUUID(e,n);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 12:return t.abrupt("return",t.sent);case 13:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getPatientConsultationData=function(){var t=c(i().mark((function t(e,n){var a=this;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===n&&(n=!1),t.t0=Promise,t.next=4,this.getGrants({consultationId:e});case 4:return t.t1=t.sent.map((function(t){return a.getLockboxManifest(t.lockboxUuid,{category:r.MetadataCategory.Consultation,documentType:r.DocumentType.PopulatedWorkflowData,consultationId:e},!0,t.lockboxOwnerUuid,n).then((function(e){return Promise.all(e.map((function(e){return a.getJsonData(t.lockboxUuid,e.dataUuid,t.lockboxOwnerUuid)})))}))})).flat(),t.abrupt("return",t.t0.all.call(t.t0,t.t1).then((function(t){return t.flat()})));case 6:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getPatientPrescriptionsList=function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getPatientDocumentsList({category:r.MetadataCategory.Consultation,documentType:r.DocumentType.Prescription},!0,e));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getPatientResultsList=function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getPatientDocumentsList({category:r.MetadataCategory.Consultation,documentType:r.DocumentType.Result},!0,e));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getPatientTreatmentPlans=function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getPatientDocumentsList({category:r.MetadataCategory.Consultation,documentType:r.DocumentType.TreatmentPlan},!0,e));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getPatientTreatmentPlanByUuid=function(){var t=c(i().mark((function t(e,n){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getPatientDocumentsList({category:r.MetadataCategory.Consultation,documentType:r.DocumentType.TreatmentPlan,treatmentPlanId:n},!0,e));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getPatientDocumentsList=function(){var t=c(i().mark((function t(e,r,n){var a=this;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=Promise,t.next=3,this.getGrants({consultationId:n});case 3:return t.t1=t.sent.map((function(t){return a.getLockboxManifest(t.lockboxUuid,l({},e,{consultationId:n}),r,t.lockboxOwnerUuid,!0).then((function(e){return Promise.all(e.map(function(){var e=c(i().mark((function e(r){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",l({lockboxOwnerUuid:t.lockboxOwnerUuid,lockboxUuid:t.lockboxUuid},r));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()))}))})).flat(),t.abrupt("return",t.t0.all.call(t.t0,t.t1).then((function(t){return t.flat()})));case 5:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.recoverPrivateKeyFromSecurityQuestions=function(){var t=c(i().mark((function t(e,r,n,a){var o,s;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.identityGet(e);case 2:o=t.sent.recoverySecurityQuestions.filter((function(t){var e=r.indexOf(t.securityQuestion);return-1!==e&&n[e]&&""!=n[e]})).map((function(t){var e=r.indexOf(t.securityQuestion);return t.securityAnswer=n[e],t}));try{s=this.toolbox.reconstructSecret(o,a),this.rsa=this.toolbox.CryptoRSA.fromKey(s)}catch(t){console.error(t)}case 5:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a){return t.apply(this,arguments)}}(),e.recoverPrivateKeyFromPassword=function(){var t=c(i().mark((function t(e,r){var n,a,o,s,u;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.identityGet(e);case 2:a=(n=t.sent).recoveryPassword,o=this.toolbox.CryptoChaCha.fromPassphrase(r),s=o.base64PayloadDecryptToBytes(a),n.recoveryLogin&&(u=this.toolbox.CryptoChaCha.fromPassphrase(n.recoveryLogin),sessionStorage.setItem(P(e),u.bytesEncryptToBase64Payload(s))),this.rsa=this.toolbox.CryptoRSA.fromKey(s);case 8:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.recoverPrivateKeyFromMasterKey=function(){var t=c(i().mark((function t(e,r){var n,a,o;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.identityGet(e);case 2:n=t.sent.recoveryMasterKey,a=this.toolbox.CryptoChaCha.fromPassphrase(r),o=a.base64PayloadDecryptToBytes(n),this.rsa=this.toolbox.CryptoRSA.fromKey(o);case 6:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.updateSecurityQuestions=function(){var t=c(i().mark((function t(e,r,n,a){var o,s;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return o=this.toolbox.breakSecretIntoShards(r,n,this.rsa.private(),a),s={recoverySecurityQuestions:o},t.next=6,this.guardClient.identityUpdate(e,s);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a){return t.apply(this,arguments)}}(),e.updatePassword=function(){var t=c(i().mark((function t(e,r,n){var a,o,s;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return a=this.toolbox.CryptoChaCha.fromPassphrase(r),o=a.bytesEncryptToBase64Payload(this.rsa.private()),n&&(n=this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(n))),r=this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(r)),s={password:{oldPassword:n,newPassword:r},recoveryPassword:o},t.next=9,this.guardClient.identityUpdate(e,s);case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.updateMasterKey=function(){var t=c(i().mark((function t(e,n,a){var o,s,u,c;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw I;case 2:return o=this.toolbox.CryptoChaCha.fromPassphrase(n),s=o.bytesEncryptToBase64Payload(this.rsa.private()),u={recoveryMasterKey:s},t.next=7,this.guardClient.identityUpdate(e,u);case 7:return c=t.sent,t.next=10,this.getOrInsertJsonData(a,{masterKey:n},{category:r.MetadataCategory.Recovery,contentType:"application/json"},{},!0);case 10:return t.abrupt("return",c);case 11:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),t}(),lt=["locale"],pt=["locale"],ft=function(){function t(t,e,n){this.url=t,this.locale=n,this.api=new r.AxiosService({headers:{"X-Clinia-API-Key":e}})}var e=t.prototype;return e.placeSearch=function(t){var e=t.locale,r=g(t,lt);return this.api.post(this.url+"/search/v1/indexes/health_facility/query",r,{params:{locale:null!=e?e:this.locale}})},e.placeMatch=function(t,e){var r=t.locale,n=g(t,pt),a=this.api.post(this.url+"/search/v1/matches",n,{params:{locale:null!=r?r:this.locale}});return e&&(a=a.then((function(t){return t.filter((function(t){return t.type===e}))}))),a},t}();Object.keys(r).forEach((function(t){"default"!==t&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return r[t]}})})),exports.OroToolboxNamespace=a,exports.AssociatedLockboxNotFound=S,exports.CliniaService=ft,exports.IncompleteAuthentication=I,exports.MissingGrant=T,exports.MissingGrantFilter=D,exports.MissingLockbox=O,exports.MissingLockboxOwner=M,exports.OroClient=ct,exports.WorkflowAnswersMissingError=U,exports.buildConsultSearchIndex=nt,exports.decryptConsultLockboxGrants=it,exports.decryptGrants=ot,exports.default=function(t,e,r,a,o,i,s,u,c,l){var p=n({tellerBaseURL:e,vaultBaseURL:r,guardBaseURL:a,searchBaseURL:o,practiceBaseURL:i,consultBaseURL:s,workflowBaseURL:u,diagnosisBaseURL:c},l);return new ct(t,p.tellerService,p.vaultService,p.guardService,p.searchService,p.practiceService,p.consultService,p.workflowService,p.diagnosisService,l)},exports.extractAndStorePersonalWorkflowData=X,exports.extractISOLocalityForConsult=function(t){if(t){var e=t.flatMap((function(t){var e=Object.keys(t).filter((function(t){return-1!==t.indexOf("Country")})).flat(),r=Object.keys(t).filter((function(t){return-1!==t.indexOf("Province")})).flat(),n=Object.keys(t).filter((function(t){return-1!==t.indexOf("Locality")})).flat();return[].concat(e.map((function(e){return"string"==typeof t[e]?t[e]:void 0})),r.map((function(e){return"string"==typeof t[e]?t[e]:void 0})),n.map((function(e){return"string"==typeof t[e]?t[e]:void 0})))})).filter((function(t){return void 0!==t})).filter((function(t){return t.startsWith("isoLocalityConsult")}));if(e&&0!==e.length){var r=s(/isoLocalityConsult(?:_(\d*))?\x2D([a-zA-Z0-9]{2}\x2D[a-zA-Z0-9]{1,3})/,{indexPriority:1,isoValue:2}),n=e.reduce((function(t,e){var n=r.exec(e),a=null!=n?n:[],o=a[1],i=a[2];if(!t)return i;var s=r.exec(t),u=null!=s?s:[],c=u[1];return!o||c&&c>o?u[2]:i}),void 0);return console.log("Picking locality "+n),n}console.log("no locality found in "+e)}},exports.extractPersonalInfoFromWorkflowData=et,exports.fillWorkflowFromPopulatedWorkflow=function(t,e){var r=JSON.parse(JSON.stringify(t));return r.selectedAnswers||(r.selectedAnswers=N(r,!1)),r.pages.forEach((function(t,n){for(var a=0,o=Object.entries(t.questions);a<o.length;a++){var i=o[a][0];e.fields[i]&&r.selectedAnswers&&(r.selectedAnswers[n][i]=e.fields[i].answer)}})),r},exports.filterTriggeredAnsweredWithKind=L,exports.flattenSelectedAnswers=K,exports.getImagesFromIndexDb=j,exports.getInitialisedSelectedAnswers=N,exports.getWorkflowDataByCategory=A,exports.identificationToPersonalInformations=k,exports.isTriggered=_,exports.registerPatient=J,exports.sessionStorePrivateKeyName=P,exports.toActualObject=C,exports.updatePersonalIntoPopulatedWorkflowData=function(t,e,r){var n=w[r],a=JSON.parse(JSON.stringify(e));return t.birthday&&a.fields[n+"Birthday"]&&(a.fields[n+"Birthday"].answer=t.birthday),t.firstname&&a.fields[n+"Firstname"]&&(a.fields[n+"Firstname"].answer=t.firstname),t.gender&&a.fields[n+"Gender"]&&(a.fields[n+"Gender"].answer=t.gender),t.name&&a.fields[n+"Name"]&&(a.fields[n+"Name"].answer=t.name),t.phone&&a.fields[n+"Phone"]&&(a.fields[n+"Phone"].answer=t.phone),t.zip&&a.fields[n+"Zip"]&&(a.fields[n+"Zip"].answer=t.zip),t.hid&&(a.fields[n+"HID"]?a.fields[n+"HID"].answer=t.hid:a.fields[n+"ID"]?a.fields[n+"ID"].answer=t.hid:a.fields[n+"HID"]={kind:"text",answer:t.hid}),a},exports.wasmPath="node_modules/oro-toolbox";
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("oro-sdk-apis"),r=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,n=require("oro-toolbox"),a=require("idb-keyval");function o(){o=function(t,e){return new r(t,void 0,e)};var t=RegExp.prototype,e=new WeakMap;function r(t,n,a){var o=new RegExp(t,n);return e.set(o,a||e.get(t)),f(o,r.prototype)}function n(t,r){var n=e.get(r);return Object.keys(n).reduce((function(e,r){return e[r]=t[n[r]],e}),Object.create(null))}return c(r,RegExp),r.prototype.exec=function(e){var r=t.exec.call(this,e);return r&&(r.groups=n(r,this)),r},r.prototype[Symbol.replace]=function(r,a){if("string"==typeof a){var o=e.get(this);return t[Symbol.replace].call(this,r,a.replace(/\$<([^>]+)>/g,(function(t,e){return"$"+o[e]})))}if("function"==typeof a){var i=this;return t[Symbol.replace].call(this,r,(function(){var t=arguments;return"object"!=typeof t[t.length-1]&&(t=[].slice.call(t)).push(n(t,i)),a.apply(this,t)}))}return t[Symbol.replace].call(this,r,a)},o.apply(this,arguments)}function i(t,e,r,n,a,o,i){try{var s=t[o](i),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,a)}function s(t){return function(){var e=this,r=arguments;return new Promise((function(n,a){var o=t.apply(e,r);function s(t){i(o,n,a,s,u,"next",t)}function u(t){i(o,n,a,s,u,"throw",t)}s(void 0)}))}}function u(){return(u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function c(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&f(t,e)}function l(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,f(t,e)}function p(t){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function d(t,e,r){return(d=h()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var a=new(Function.bind.apply(t,n));return r&&f(a,r.prototype),a}).apply(null,arguments)}function y(t){var e="function"==typeof Map?new Map:void 0;return(y=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return d(t,arguments,p(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),f(r,t)})(t)}function x(t,e){if(null==t)return{};var r,n,a={},o=Object.keys(t);for(n=0;n<o.length;n++)e.indexOf(r=o[n])>=0||(a[r]=t[r]);return a}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function g(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return v(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var b,m,w=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},a=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var a=Object.create((e&&e.prototype instanceof p?e:p).prototype),o=new C(n||[]);return a._invoke=function(t,e,r){var n="suspendedStart";return function(a,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw o;return{value:void 0,done:!0}}for(r.method=a,r.arg=o;;){var i=r.delegate;if(i){var s=m(i,r);if(s){if(s===l)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,o),a}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function p(){}function f(){}function h(){}var d={};s(d,a,(function(){return this}));var y=Object.getPrototypeOf,x=y&&y(y(P([])));x&&x!==e&&r.call(x,a)&&(d=x);var v=h.prototype=p.prototype=Object.create(d);function g(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var n;this._invoke=function(a,o){function i(){return new e((function(n,i){!function n(a,o,i,s){var u=c(t[a],t,o);if("throw"!==u.type){var l=u.arg,p=l.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,i,s)}),(function(t){n("throw",t,i,s)})):e.resolve(p).then((function(t){l.value=t,i(l)}),(function(t){return n("throw",t,i,s)}))}s(u.arg)}(a,o,n,i)}))}return n=n?n.then(i,i):i()}}function m(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,m(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var a=n.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function w(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function P(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:I}}function I(){return{value:void 0,done:!0}}return f.prototype=h,s(v,"constructor",h),s(h,"constructor",f),f.displayName=s(h,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===f||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,s(t,i,"GeneratorFunction")),t.prototype=Object.create(v),t},t.awrap=function(t){return{__await:t}},g(b.prototype),s(b.prototype,o,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,a,o){void 0===o&&(o=Promise);var i=new b(u(e,r,n,a),o);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},g(v),s(v,i,"Generator"),s(v,a,(function(){return this})),s(v,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=P,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],i=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n];if(a.tryLoc<=this.prev&&r.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var o=a;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),k(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var a=n.arg;k(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:P(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(m={exports:{}}),m.exports),k=((b={})[e.MetadataCategory.Personal]="you",b[e.MetadataCategory.ChildPersonal]="child",b[e.MetadataCategory.OtherPersonal]="other",b);function C(t,e){var r,n=k[e];return{birthday:t[n+"Birthday"],firstname:t[n+"Firstname"],gender:t[n+"Gender"],name:t[n+"Name"],phone:t[n+"Phone"],zip:t[n+"Zip"],hid:null!=(r=t[n+"HID"])?r:t[n+"ID"],pharmacy:t[n+"Pharmacy"],address:t[n+"Address"]}}function P(t){var e={};return Object.entries(t.fields).forEach((function(t){var r=t[1];e[t[0]]=r.displayedAnswer?r.displayedAnswer:r.answer})),e}function I(t){return"sess-pkey"+t}var T=function(t){function e(){return t.apply(this,arguments)||this}return l(e,t),e}(y(Error)),D=function(t){function e(){return t.apply(this,arguments)||this}return l(e,t),e}(y(Error)),O=function(t){function e(){return t.apply(this,arguments)||this}return l(e,t),e}(y(Error)),M=function(t){function e(){return t.apply(this,arguments)||this}return l(e,t),e}(y(Error)),S=function(t){function e(){return t.apply(this,arguments)||this}return l(e,t),e}(y(Error)),U=function(t){function e(){return t.apply(this,arguments)||this}return l(e,t),e}(y(Error)),L=function(t){function e(){return t.apply(this,arguments)||this}return l(e,t),e}(y(Error));function E(t,e){return A.apply(this,arguments)}function A(){return(A=s(w.mark((function t(e,r){var n,a,o,i;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.selectedAnswers){t.next=2;break}throw L;case 2:return n=N(e.selectedAnswers),a=Object.fromEntries(e.pages.map((function(t){return Object.entries(t.questions).filter((function(t){var e=t[1];return K(e.triggers||[],n)&&e.kind===r}))})).flat()),o=e.selectedAnswers.reduce((function(t,e){return u({},t,e)}),{}),i=Object.keys(a).map((function(t){return o[t]})),t.abrupt("return",i);case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function G(t,e){return j.apply(this,arguments)}function j(){return(j=s(w.mark((function t(e,r){var n,a,o;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.selectedAnswers){t.next=2;break}throw L;case 2:return n=N(e.selectedAnswers),a=Object.fromEntries(e.pages.map((function(t){return Object.entries(t.questions).filter((function(t){return K(t[1].triggers||[],n)}))})).flat()),o={},t.abrupt("return",Promise.all(e.selectedAnswers.map((function(t){return Object.entries(t)})).flat().filter((function(t){var e=t[0];return a[e]&&a[e].metaCategory===r})).map((function(t){var e=t[0];return F(a[e],t[1]).then((function(t){o[e]=t}))}))).then((function(){return{workflowCreatedAt:e.createdAt,workflowId:e.id,locale:e.locale,fields:o}})).catch((function(t){throw console.error("Error while extracting "+r+" data from workflow",t),t})));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function B(t){return R.apply(this,arguments)}function R(){return(R=s(w.mark((function t(e){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,a.getMany(e.map((function(t){var e;return null!=(e=t.id)?e:t})));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function F(t,e){return _.apply(this,arguments)}function _(){return(_=s(w.mark((function t(e,r){var n,a;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=void 0,t.t0=e.kind,t.next="text-select-group"===t.t0?4:"radio"===t.t0||"radio-card"===t.t0||"select"===t.t0?7:"multiple"===t.t0||"checkbox-group"===t.t0?10:"images"===t.t0?13:17;break;case 4:return e.answers&&(a=r[0]+" "+e.answers[r[1]].text),n=r,t.abrupt("break",18);case 7:return e.answers&&(a=e.answers[r].text),n=r,t.abrupt("break",18);case 10:return a=r.map((function(t){if(e.answers)return e.answers[t].text;throw new L})),n=r,t.abrupt("break",18);case 13:return t.next=15,B(r).then((function(t){return t.map((function(t){return{name:t.name,imageData:t.imageData}}))}));case 15:return n=t.sent,t.abrupt("break",18);case 17:n=r;case 18:return t.abrupt("return",Promise.resolve({answer:n,displayedAnswer:a,kind:e.kind}));case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function K(t,e){if("string"==typeof t)return e.includes(t);if(Array.isArray(t))return Array.isArray(t[0])?t.some((function(t){return t.every((function(t){return e.includes(t)}))})):t.every((function(t){return e.includes(t)}));throw Error("[isTriggered] triggers is not typed well")}function N(t){for(var e,r=[],n=g(t);!(e=n()).done;)r.push.apply(r,Object.values(e.value));return r.flat(1)}function J(t,e){return void 0===e&&(e=!0),t.pages.map((function(t){for(var r={},n=0,a=Object.entries(t.questions);n<a.length;n++){var o=a[n],i=o[1];r[o[0]]="body-parts"===i.kind?e?[]:void 0:e&&i.defaultValue?i.defaultValue:void 0}return r}))}function W(t,e,r,n,a,o,i,s){return q.apply(this,arguments)}function q(){return(q=s(w.mark((function t(r,n,a,o,i,u,c,l){var p,f,h,d,y,x,v,g;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:void 0===c&&(c=!0),p=void 0,f=void 0,h=void 0,d=15,y=void 0,x=[],v=9;case 8:if(!(d>0)){t.next=24;break}return t.prev=9,t.delegateYield(w.mark((function t(){var b,m,k,C,P,I,T;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return g=0,l&&l(g++/v,"retrieve_practitioners"),t.next=4,new Promise((function(t){return setTimeout(t,2e3)}));case 4:if(h){t.next=8;break}return t.next=7,o.practiceClient.practiceGetFromUuid(n.uuidPractice);case 7:h=t.sent.uuidAdmin;case 8:return t.next=10,o.practiceClient.practiceGetPractitioners(n.uuidPractice).catch((function(t){return console.log("Error retrieving practitioners",t),[]}));case 10:if(C=t.sent,l&&l(g++/v,"create_consult"),p){t.next=16;break}return t.next=15,Q(n,o);case 15:p=t.sent;case 16:if(l&&l(g++/v,"create_lockbox"),f){t.next=21;break}return t.next=20,H(o);case 20:f=t.sent;case 21:if(y){t.next=25;break}return t.next=24,o.guardClient.identityGet(r);case 24:y=t.sent;case 25:return t.next=27,o.grantLockbox(h,f).catch((function(t){console.error("Error while granting lockbox to practitioner admin "+h,t),x.push(t)}));case 27:return l&&l(g++/v,"grant_patient"),P=C.filter((function(t){return t.uuid!==h})).map(function(){var t=s(w.mark((function t(e){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",o.grantLockbox(e.uuid,f).catch((function(t){console.error("Error while granting lockbox to practitioner",t),d<=1||x.push(t)})));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()),(b={})[e.IndexKey.ConsultationLockbox]=[{grant:{lockboxUuid:f,lockboxOwnerUuid:r},consultationId:p.uuid}],I=b,T=C.map(function(){var t=s(w.mark((function t(e){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",o.vaultIndexAdd(I,e.uuid).catch((function(t){console.error("[SDK: registration] Error while adding to the practitioner's index "+e.uuid,t),d<=1||x.push(t)})));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()),t.next=33,$(p.uuid,f,a,o,l?{onProgress:l,currentStep:g,stepsTotalNum:v}:void 0).catch((function(t){console.error("[SDK: registration] Some errors happened during image upload",t),d<=1||x.push(t)}));case 33:return++g,l&&l(g++/v,"store_patient_data"),t.next=37,Y(p.uuid,n.isoLanguageRequired,f,a,o).catch((function(t){console.error("[SDK: registration] Some errors happened during patient data upload",t),x.push(t)}));case 37:if(l&&l(g++/v,"set_masterkey"),!i||null!=(m=y)&&m.recoveryMasterKey){t.next=44;break}return t.next=41,o.updateMasterKey(r,i,f).catch((function(t){if(console.error("[SDK: registration] Error while updating master key",t),!(d<=1))return x.push(t),y}));case 41:y=t.sent,t.next=45;break;case 44:i=void 0;case 45:if(l&&l(g++/v,"set_security_questions"),!u||null!=(k=y)&&k.recoverySecurityQuestions){t.next=50;break}return t.next=49,o.updateSecurityQuestions(r,u.recoverySecurityQuestions,u.recoverySecurityAnswers,2).catch((function(t){if(console.error("[SDK: registration] Error while updating security questions",t),!(d<=1))return x.push(t),y}));case 49:y=t.sent;case 50:return t.next=52,Promise.all([].concat(P,T));case 52:if(l&&l(g++/v,"search_indexing"),!c){t.next=56;break}return t.next=56,at(p,a,o).catch((function(t){console.error("[SDK: registration] personal information not found or another error occured during search indexing",t),d<=1||x.push(t)}));case 56:if(!(x.length>0)){t.next=58;break}throw x;case 58:return t.next=60,o.consultClient.updateConsultByUUID(p.uuid,{statusMedical:e.MedicalStatus.New});case 60:return l&&l(g++/v,"success"),t.abrupt("return","break");case 62:case"end":return t.stop()}}),t)}))(),"t0",11);case 11:if("break"!==t.t0){t.next=14;break}return t.abrupt("break",24);case 14:t.next=21;break;case 16:return t.prev=16,t.t1=t.catch(9),console.error("[SDK] Error occured during registration: "+t.t1+", retrying... Retries remaining: "+d),x=[],t.abrupt("continue",21);case 21:d--,t.next=8;break;case 24:if(!(d<=0)){t.next=27;break}throw console.error("[SDK] registration failed: MAX_RETRIES reached"),"RegistrationFailed";case 27:return console.log("Successfully Registered"),t.next=30,o.cleanIndex();case 30:return t.abrupt("return",{masterKey:i,consultationId:p.uuid,lockboxUuid:f});case 31:case"end":return t.stop()}}),t,null,[[9,16]])})))).apply(this,arguments)}function Q(t,e){return z.apply(this,arguments)}function z(){return(z=s(w.mark((function t(e,r){var n;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.practiceClient.practiceGetPayment(e.uuidPractice,e.idStripeInvoiceOrPaymentIntent);case 2:if(!(n=t.sent)||!n.uuidConsult){t.next=7;break}return t.abrupt("return",r.consultClient.getConsultByUUID(n.uuidConsult).catch((function(t){throw console.error("Error while retrieving consult",t),t})));case 7:return t.next=9,r.consultClient.consultCreate(e).catch((function(t){throw console.error("Error while creating consult",t),t}));case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function H(t){return Z.apply(this,arguments)}function Z(){return(Z=s(w.mark((function t(e){var r,n,a;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.getGrants();case 2:if(!((r=t.sent).length>0)){t.next=8;break}return console.log("The grant has already been created, skipping lockbox create step"),t.abrupt("return",r[0].lockboxUuid);case 8:return t.next=10,e.vaultClient.lockboxCreate().catch((function(t){throw console.error("Error while creating lockbox",t),t}));case 10:return n=t.sent,t.next=13,e.guardClient.authRefresh();case 13:return a=t.sent,t.next=16,e.guardClient.setTokens({accessToken:a.accessToken,refreshToken:a.refreshToken});case 16:return t.next=18,e.guardClient.whoAmI(!0);case 18:return t.abrupt("return",n.lockboxUuid);case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Y(t,e,r,n,a){return V.apply(this,arguments)}function V(){return(V=s(w.mark((function t(r,n,a,o,i){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Promise.all([i.getOrInsertJsonData(a,o,{category:e.MetadataCategory.Raw,contentType:"application/json",consultationId:r},{}),G(o,e.MetadataCategory.Consultation).then((function(t){return i.getOrInsertJsonData(a,t,{category:e.MetadataCategory.Consultation,documentType:e.DocumentType.PopulatedWorkflowData,consultationId:r},{consultationId:r})})),G(o,e.MetadataCategory.Medical).then((function(t){return i.getOrInsertJsonData(a,t,{category:e.MetadataCategory.Medical,documentType:e.DocumentType.PopulatedWorkflowData,consultationIds:[r]},{})})),tt(o,a,r,e.MetadataCategory.Personal,i),tt(o,a,r,e.MetadataCategory.ChildPersonal,i),tt(o,a,r,e.MetadataCategory.OtherPersonal,i),i.getOrInsertJsonData(a,{isoLanguage:n},{category:e.MetadataCategory.Preference,contentType:"application/json"},{})]).then((function(t){return t.flat()})));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function $(t,e,r,n,a){return X.apply(this,arguments)}function X(){return(X=s(w.mark((function t(r,n,a,o,i){var s,u,c,l,p;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=B,t.next=3,E(a,"images-alias");case 3:return t.t1=t.sent.flat(),t.next=6,(0,t.t0)(t.t1);case 6:return u=(s=t.sent).filter((function(t){return!!t})),s.length!==u.length&&console.error("[SDK] Some images have not been found, they have been skipped."),c=0,l=u.length,i&&i.onProgress(i.currentStep/i.stepsTotalNum,"store_images",{storedImagesNum:c,totalImagesNum:l}),p=u.map((function(t){return o.getOrInsertJsonData(n,t,{category:e.MetadataCategory.Consultation,documentType:e.DocumentType.ImageAlias,consultationId:r,idbId:t.idbId},{}).then((function(){if(i){++c;var t=Math.round(100*((i.currentStep+1)/i.stepsTotalNum-i.currentStep/i.stepsTotalNum))/100;i.onProgress(i.currentStep/i.stepsTotalNum+t*(c/l),"store_images",{storedImagesNum:c,totalImagesNum:l})}}))})),t.abrupt("return",Promise.all(p));case 14:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function tt(t,e,r,n,a){return et.apply(this,arguments)}function et(){return(et=s(w.mark((function t(r,n,a,o,i){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",G(r,o).then((function(t){if(0!==Object.keys(t.fields).length)return i.getOrInsertJsonData(n,t,{category:o,documentType:e.DocumentType.PopulatedWorkflowData,consultationIds:[a]},{})})));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function rt(t){return nt.apply(this,arguments)}function nt(){return(nt=s(w.mark((function t(r){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Promise.all([G(r,e.MetadataCategory.Personal),G(r,e.MetadataCategory.ChildPersonal),G(r,e.MetadataCategory.OtherPersonal)]).then((function(t){return{personalInfoPopulatedWfData:t[0],childPersonalInfoPopulatedWfData:t[1],otherPersonalInfoPopulatedWfData:t[2]}})));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function at(t,e,r){return ot.apply(this,arguments)}function ot(){return(ot=s(w.mark((function t(r,n,a){var o,i,s,u,c,l,p;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=[{kind:"consult-shortid",value:r.shortId}],t.next=3,rt(n);case 3:return s=(i=t.sent).childPersonalInfoPopulatedWfData,u=i.otherPersonalInfoPopulatedWfData,c=C(P(i.personalInfoPopulatedWfData),e.MetadataCategory.Personal),l=C(P(s),e.MetadataCategory.ChildPersonal),p=C(P(u),e.MetadataCategory.OtherPersonal),o.push({kind:"first-name",value:c.firstname},{kind:"last-name",value:c.name}),l.firstname&&l.name&&o.push({kind:"first-name",value:l.firstname},{kind:"last-name",value:l.name}),p.firstname&&p.name&&o.push({kind:"first-name",value:p.firstname},{kind:"last-name",value:p.name}),t.next=15,a.searchClient.index(r.uuid,o);case 15:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function it(t,e){return t.map((function(t){if(t.encryptedLockbox&&!t.lockboxUuid)try{t.lockboxUuid=n.uuidParse(e.base64DecryptToBytes(t.encryptedLockbox))}catch(t){console.error("[sdk:index] The grant could not be decrypted or was not a valid UUID: ",t)}return t})).filter((function(t){return t.lockboxUuid}))}function st(t,e){return t.map((function(t){try{return[!0,e.base64DecryptToJson(t.encryptedIndexEntry).grant]}catch(t){return console.error("[sdk:index] The consult lockbox grant could not be decrypted: ",t),[!1,void 0]}})).filter((function(t){return t[0]})).map((function(t){return t[1]}))}function ut(t,e){return ct.apply(this,arguments)}function ct(){return(ct=s(w.mark((function t(r,n){var a,o,i,s;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.getGrants();case 2:a=[],o=g(t.sent);case 5:if((i=o()).done){t.next=13;break}return s=i.value,t.next=9,r.vaultClient.lockboxMetadataGet(s.lockboxUuid,["consultationId"],[],{category:e.MetadataCategory.Consultation,consultationId:n.consultationId});case 9:t.sent[0].length>=0&&a.push(s);case 11:t.next=5;break;case 13:return t.abrupt("return",a);case 14:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var lt=function(){function t(t,e,r,n,a,o,i,s,u,c){this.toolbox=t,this.tellerClient=e,this.vaultClient=r,this.guardClient=n,this.searchClient=a,this.practiceClient=o,this.consultClient=i,this.workflowClient=s,this.diagnosisClient=u,this.authenticationCallback=c,this.secrets=[],this.cachedMetadataGrants={},this.cachedManifest={}}var r=t.prototype;return r.cleanIndex=function(){var t=s(w.mark((function t(){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this.cachedMetadataGrants={},this.cachedManifest={};case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.signUp=function(){var t=s(w.mark((function t(e,r,a,o,i,s,u){var c,l,p,f,h,d,y,x;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.rsa=new n.CryptoRSA,c=this.rsa.private(),l=this.toolbox.CryptoChaCha.fromPassphrase(r),p=l.bytesEncryptToBase64Payload(c),f=this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(r)),h=!!u,d={practiceUuid:a.uuid,email:e.toLowerCase(),emailConfirmed:h,password:f,publicKey:this.toolbox.encodeToBase64(this.rsa.public()),recoveryPassword:p,tosAndCpAcceptance:o,tokenData:i,subscription:s},t.next=9,this.guardClient.identityCreate(d);case 9:return(y=t.sent).recoveryLogin&&(x=this.toolbox.CryptoChaCha.fromPassphrase(y.recoveryLogin),sessionStorage.setItem(I(y.id),x.bytesEncryptToBase64Payload(c))),t.abrupt("return",y);case 12:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i,s){return t.apply(this,arguments)}}(),r.confirmEmail=function(){var t=s(w.mark((function t(e){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.guardClient.setTokens({accessToken:e}),t.next=3,this.guardClient.whoAmI();case 3:return t.abrupt("return",this.guardClient.identityUpdate(t.sent.sub,{emailConfirmed:!0}));case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.signIn=function(){var t=s(w.mark((function t(e,r,n,a){var o,i,s;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(n)),i={practiceUuid:e,email:r.toLowerCase(),password:o,otp:a},t.next=4,this.guardClient.authToken(i);case 4:return t.next=6,this.guardClient.whoAmI();case 6:return s=t.sent.sub,t.next=9,this.recoverPrivateKeyFromPassword(s,n);case 9:return t.next=11,this.guardClient.identityGet(s);case 11:return t.abrupt("return",t.sent);case 12:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a){return t.apply(this,arguments)}}(),r.resumeSession=function(){var t=s(w.mark((function t(){var e,r,n,a,o;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.whoAmI();case 2:return e=t.sent.sub,r=sessionStorage.getItem(I(e)),t.next=6,this.guardClient.identityGet(e);case 6:if((n=t.sent.recoveryLogin)&&r){t.next=9;break}throw T;case 9:a=this.toolbox.CryptoChaCha.fromPassphrase(n),o=a.base64PayloadDecryptToBytes(r),this.rsa=this.toolbox.CryptoRSA.fromKey(o);case 12:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.localEncryptToJsonPayload=function(t){if(!this.rsa)throw this.authenticationCallback&&this.authenticationCallback(new T),new T;var e=new this.toolbox.CryptoChaCha;return{encryptedData:e.jsonEncryptToBase64Payload(t),encryptedKey:this.toolbox.encodeToBase64(this.rsa.encryptToBytes(e.key()))}},r.localDecryptJsonPayload=function(t){var e=t.encryptedKey,r=t.encryptedData;if(!this.rsa)throw this.authenticationCallback&&this.authenticationCallback(new T),new T;var n=this.rsa.base64DecryptToBytes(e);return this.toolbox.CryptoChaCha.fromKey(n).base64PayloadDecryptToJson(r)},r.signOut=function(){var t=s(w.mark((function t(){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.rsa=void 0,this.secrets=[],this.guardClient.setTokens({accessToken:void 0,refreshToken:void 0}),t.next=5,this.guardClient.authLogout();case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.registerPatient=function(){var t=s(w.mark((function t(e,r,n,a,o,i){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===o&&(o=!0),this.rsa){t.next=3;break}throw T;case 3:return t.abrupt("return",W(e,r,n,this,this.toolbox.uuid(),a,o,i));case 4:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i){return t.apply(this,arguments)}}(),r.forceUpdateIndexEntries=function(){var t=s(w.mark((function t(){var r,n,a=this;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:return n=t.sent,t.next=5,Promise.all(n.map(function(){var t=s(w.mark((function t(r){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,a.vaultClient.lockboxMetadataGet(r.lockboxUuid,["consultationId"],[],{category:e.MetadataCategory.Consultation},r.lockboxOwnerUuid).then((function(t){try{return t[0].map((function(t){return u({},t,{grant:{lockboxOwnerUuid:r.lockboxOwnerUuid,lockboxUuid:r.lockboxUuid}})}))}catch(t){return[]}})).catch((function(){return[]}));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())).then((function(t){return t.flat()}));case 5:this.vaultIndexAdd((r={},r[e.IndexKey.Consultation]=t.sent,r)).then((function(){return alert("The Index was successfully updated!")})).catch((function(){return console.error("The index failed to update!")}));case 7:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.vaultIndexAdd=function(){var t=s(w.mark((function t(r,a){var o,i,s,c,l;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:if(!a){t.next=9;break}return t.next=5,this.guardClient.identityGet(a);case 5:o=this.toolbox.decodeFromBase64(t.sent.publicKey),t.next=10;break;case 9:o=this.rsa.public();case 10:i={},s=0,c=Object.keys(r);case 12:if(!(s<c.length)){t.next=23;break}t.t0=l=c[s],t.next=t.t0===e.IndexKey.ConsultationLockbox?18:20;break;case 18:return i[l]=r[l].map((function(t){return u({},t,{uniqueHash:t.consultationId})})).map((function(t){return{uuid:t.uuid,timestamp:t.timestamp,uniqueHash:t.uniqueHash,encryptedIndexEntry:n.CryptoRSA.jsonWithPubEncryptToBase64({consultationId:t.consultationId,grant:t.grant},o)}})),t.abrupt("break",20);case 20:s++,t.next=12;break;case 23:return t.next=25,this.vaultClient.vaultIndexPut(i,a);case 25:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.grantLockbox=function(){var t=s(w.mark((function t(e,r,a){var o,i,s,u;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return t.next=4,this.getCachedSecretCryptor(r,a);case 4:return o=t.sent.key(),t.next=7,this.guardClient.identityGet(e);case 7:return i=this.toolbox.decodeFromBase64(t.sent.publicKey),s=n.CryptoRSA.bytesWithPubEncryptToBase64(o,i),u={encryptedSecret:s,granteeUuid:e},t.next=13,this.vaultClient.lockboxGrant(r,u,a);case 13:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.createMessageData=function(){var t=s(w.mark((function t(r,n,a,o,i){var s,u,c;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return t.next=4,this.getCachedSecretCryptor(r,o);case 4:return u=(s=t.sent).jsonEncryptToBase64Payload(n),t.t0=s,t.next=9,this.guardClient.whoAmI();case 9:return t.t1=t.sent.sub,t.t2={author:t.t1},c=t.t0.jsonEncryptToBase64Payload.call(t.t0,t.t2),t.abrupt("return",this.tellerClient.lockboxDataStore(r,{data:u,publicMetadata:{consultationId:a,category:e.MetadataCategory.Consultation,documentType:e.DocumentType.Message,contentType:"text/plain"},privateMetadata:c},o,i));case 15:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o){return t.apply(this,arguments)}}(),r.createMessageAttachmentData=function(){var t=s(w.mark((function t(r,n,a,o,i){var s,u,c;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return t.next=4,this.getCachedSecretCryptor(r,o);case 4:return t.t0=s=t.sent,t.t1=Uint8Array,t.next=9,n.arrayBuffer();case 9:return t.t2=t.sent,t.t3=new t.t1(t.t2),u=t.t0.bytesEncryptToBase64Payload.call(t.t0,t.t3),t.t4=s,t.next=15,this.guardClient.whoAmI();case 15:return t.t5=t.sent.sub,t.t6=n.name,t.t7=n.lastModified,t.t8=n.size,t.t9={author:t.t5,fileName:t.t6,lastModified:t.t7,size:t.t8},c=t.t4.jsonEncryptToBase64Payload.call(t.t4,t.t9),t.abrupt("return",this.tellerClient.lockboxDataStore(r,{data:u,publicMetadata:{consultationId:a,category:e.MetadataCategory.Consultation,documentType:e.DocumentType.Message,contentType:n.type},privateMetadata:c},o,i));case 24:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o){return t.apply(this,arguments)}}(),r.createConsultationAttachmentData=function(){var t=s(w.mark((function t(r,n,a,o,i,s){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return t.t0=this,t.t1=r,t.t2=Uint8Array,t.next=7,n.arrayBuffer();case 7:return t.t3=t.sent,t.t4=new t.t2(t.t3),t.t5={consultationId:a,category:e.MetadataCategory.Consultation,documentType:o,contentType:n.type},t.next=12,this.guardClient.whoAmI();case 12:return t.t6=t.sent.sub,t.t7=n.name,t.t8={author:t.t6,fileName:t.t7},t.t9=i,t.t10=s,t.abrupt("return",t.t0.createBytesData.call(t.t0,t.t1,t.t4,t.t5,t.t8,t.t9,t.t10));case 18:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i){return t.apply(this,arguments)}}(),r.createJsonData=function(){var t=s(w.mark((function t(e,r,n,a,o,i){var s,u,c;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return t.next=4,this.getCachedSecretCryptor(e,o);case 4:return u=(s=t.sent).jsonEncryptToBase64Payload(r),c=s.jsonEncryptToBase64Payload(a),t.abrupt("return",this.tellerClient.lockboxDataStore(e,{data:u,publicMetadata:n,privateMetadata:c},o,i));case 9:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i){return t.apply(this,arguments)}}(),r.getOrInsertJsonData=function(){var t=s(w.mark((function t(e,r,n,a,o){var i;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===o&&(o=!1),t.next=3,this.vaultClient.lockboxManifestGet(e,n);case 3:if(i=t.sent,o||!(i.length>0)){t.next=9;break}return console.log("The data for "+JSON.stringify(n)+" already exist"),t.abrupt("return",i[0].dataUuid);case 9:return t.next=11,this.createJsonData(e,r,n,a,void 0,o&&i.length>0?i[0].dataUuid:void 0).catch((function(t){throw console.error("Error while upserting data "+JSON.stringify(n)+" data",t),t}));case 11:return t.abrupt("return",t.sent.dataUuid);case 12:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o){return t.apply(this,arguments)}}(),r.createBytesData=function(){var t=s(w.mark((function t(e,r,n,a,o,i){var s,u,c;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return t.next=4,this.getCachedSecretCryptor(e,o);case 4:return u=(s=t.sent).bytesEncryptToBase64Payload(r),c=s.jsonEncryptToBase64Payload(a),t.abrupt("return",this.tellerClient.lockboxDataStore(e,{data:u,publicMetadata:n,privateMetadata:c},o,i));case 9:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o,i){return t.apply(this,arguments)}}(),r.getJsonData=function(){var t=s(w.mark((function t(e,r,n){var a;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return t.next=4,Promise.all([this.vaultClient.lockboxDataGet(e,r,n),this.getCachedSecretCryptor(e,n)]);case 4:return t.abrupt("return",(a=t.sent)[1].base64PayloadDecryptToJson(a[0].data));case 8:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getBytesData=function(){var t=s(w.mark((function t(e,r,n){var a;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return t.next=4,Promise.all([this.vaultClient.lockboxDataGet(e,r,n),this.getCachedSecretCryptor(e,n)]);case 4:return t.abrupt("return",(a=t.sent)[1].base64PayloadDecryptToBytes(a[0].data));case 8:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getGrants=function(){var t=s(w.mark((function t(r){var n,a,o,i,s,u;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:if(n=JSON.stringify(r),!this.cachedMetadataGrants[n]){t.next=5;break}return t.abrupt("return",this.cachedMetadataGrants[n]);case 5:return t.next=7,this.getAccountRole();case 7:if(1!==(a=t.sent).length||a[0]!==e.OtherRoleType.User){t.next=10;break}return t.abrupt("return",[]);case 10:if(![e.OtherRoleType.Patient,e.OtherRoleType.User].every((function(t){return a.includes(t)}))){t.next=26;break}if(!r){t.next=17;break}return t.next=14,ut(this,r);case 14:o=t.sent,t.next=20;break;case 17:return t.next=19,this.vaultClient.grantsGet();case 19:o=t.sent.grants;case 20:return t.next=22,it(o,this.rsa);case 22:return this.cachedMetadataGrants[n]=i=t.sent,console.info("[sdk:grant] Found grant for patient"),t.abrupt("return",i);case 26:if(r){t.next=28;break}throw O;case 28:return t.next=30,this.vaultClient.vaultIndexGet([e.IndexKey.ConsultationLockbox],[r.consultationId]).then((function(t){return t[e.IndexKey.ConsultationLockbox]})).catch((function(t){return console.error(t),[]}));case 30:if(!((u=st(null!=(s=t.sent)?s:[],this.rsa)).length>0)){t.next=36;break}return console.info("[sdk:index] Grants found in user`s constant time secure index"),this.cachedMetadataGrants[n]=u,t.abrupt("return",this.cachedMetadataGrants[n]);case 36:return t.abrupt("return",[]);case 37:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getAccountRole=function(){var t=s(w.mark((function t(){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.whoAmI();case 2:return t.abrupt("return",t.sent.scope.split(" "));case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getCachedSecretCryptor=function(){var t=s(w.mark((function t(e,r){var n,a,o;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:if(-1!==(n=this.secrets.findIndex((function(t){return t.lockboxUuid===e})))){t.next=13;break}return t.next=6,this.vaultClient.lockboxSecretGet(e,r);case 6:return a=this.rsa.base64DecryptToBytes(t.sent.sharedSecret),o=this.toolbox.CryptoChaCha.fromKey(a),this.secrets.push({lockboxUuid:e,cryptor:o}),t.abrupt("return",o);case 13:return t.abrupt("return",this.secrets[n].cryptor);case 14:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.getPersonalInformationsFromConsultId=function(){var t=s(w.mark((function t(e,r,n){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===n&&(n=!1),t.abrupt("return",this.getMetaCategoryFromConsultId(e,r,n));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getMedicalDataFromConsultId=function(){var t=s(w.mark((function t(r,n){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===n&&(n=!1),t.abrupt("return",this.getMetaCategoryFromConsultId(r,e.MetadataCategory.Medical,n));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.getMetaCategoryFromConsultId=function(){var t=s(w.mark((function t(r,n,a){var o,i,c,l,p,f=this;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===a&&(a=!1),t.next=3,this.getGrants({consultationId:r});case 3:o=t.sent,i=[],c=w.mark((function t(){var o,c;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=p.value,t.next=3,f.getLockboxManifest(o.lockboxUuid,{category:n,documentType:e.DocumentType.PopulatedWorkflowData,consultationIds:[r]},!0,o.lockboxOwnerUuid,a);case 3:if(0!==(c=t.sent).length){t.next=8;break}return t.next=7,f.getLockboxManifest(o.lockboxUuid,{category:n,documentType:e.DocumentType.PopulatedWorkflowData},!0,o.lockboxOwnerUuid,a);case 7:c=t.sent.filter((function(t){return!t.metadata.consultationIds}));case 8:return t.next=10,Promise.all(c.map(function(){var t=s(w.mark((function t(e){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=o.lockboxOwnerUuid,t.t1=o.lockboxUuid,t.t2=e.dataUuid,t.next=5,f.getJsonData(o.lockboxUuid,e.dataUuid);case 5:return t.t3=t.sent,t.abrupt("return",{lockboxOwnerUuid:t.t0,lockboxUuid:t.t1,dataUuid:t.t2,data:t.t3});case 7:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 10:i=u({},i,t.sent);case 12:case"end":return t.stop()}}),t)})),l=g(o);case 7:if((p=l()).done){t.next=11;break}return t.delegateYield(c(),"t0",9);case 9:t.next=7;break;case 11:return t.abrupt("return",i);case 12:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getPersonalInformations=function(){var t=s(w.mark((function t(r){var n,a,o,i;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(n=t.sent.find((function(t){return t.lockboxOwnerUuid===r}))){t.next=5;break}throw D;case 5:if(o=n.lockboxOwnerUuid,a=n.lockboxUuid){t.next=8;break}throw M;case 8:if(o){t.next=10;break}throw S;case 10:return t.next=12,this.getLockboxManifest(a,{category:e.MetadataCategory.Personal,documentType:e.DocumentType.PopulatedWorkflowData},!1,r);case 12:return i=t.sent[0].dataUuid,t.t0=o,t.t1=a,t.t2=i,t.next=18,this.getJsonData(a,i);case 18:return t.t3=t.sent,t.abrupt("return",{lockboxOwnerUuid:t.t0,lockboxUuid:t.t1,dataUuid:t.t2,data:t.t3});case 20:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getGrantFromConsultId=function(){var t=s(w.mark((function t(e){var r;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants({consultationId:e});case 2:if(0!==(r=t.sent).length){t.next=5;break}throw U;case 5:return t.abrupt("return",r[0]);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getIdentityFromConsultId=function(){var t=s(w.mark((function t(e){var r;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrantFromConsultId(e);case 2:if(!(r=t.sent)||!r.lockboxOwnerUuid){t.next=9;break}return t.next=6,this.guardClient.identityGet(r.lockboxOwnerUuid);case 6:return t.abrupt("return",t.sent);case 9:return t.abrupt("return",void 0);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getLockboxManifest=function(){var t=s(w.mark((function t(e,r,n,a,o){var i,c=this;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===o&&(o=!1),i=JSON.stringify({lockboxUuid:e,filter:r,expandPrivateMetadata:n,lockboxOwnerUuid:a}),o||!this.cachedManifest[i]){t.next=4;break}return t.abrupt("return",this.cachedManifest[i]);case 4:return t.abrupt("return",this.vaultClient.lockboxManifestGet(e,r,a).then((function(t){return Promise.all(t.map(function(){var t=s(w.mark((function t(r){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!n||!r.metadata.privateMetadata){t.next=5;break}return t.next=3,c.getJsonData(e,r.metadata.privateMetadata,a);case 3:r.metadata=u({},r.metadata,t.sent);case 5:return t.abrupt("return",r);case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())).then((function(t){return c.cachedManifest[i]=t}))})));case 5:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a,o){return t.apply(this,arguments)}}(),r.createPersonalInformations=function(){var t=s(w.mark((function t(r,n,a){var o,i;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(t.t0=o=t.sent.find((function(t){return t.lockboxOwnerUuid===r.id})),null!=t.t0){t.next=7;break}t.t1=void 0,t.next=8;break;case 7:t.t1=o.lockboxUuid;case 8:if(!(i=t.t1)){t.next=13;break}return t.abrupt("return",this.createJsonData(i,n,{category:e.MetadataCategory.Personal,documentType:e.DocumentType.PopulatedWorkflowData},{},void 0,a));case 13:throw M;case 14:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.createUserPreference=function(){var t=s(w.mark((function t(r,n,a){var o,i;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(t.t0=o=t.sent.find((function(t){return t.lockboxOwnerUuid===r.id})),null!=t.t0){t.next=7;break}t.t1=void 0,t.next=8;break;case 7:t.t1=o.lockboxUuid;case 8:if(!(i=t.t1)){t.next=13;break}return t.abrupt("return",this.createJsonData(i,n,{category:e.MetadataCategory.Preference,contentType:"application/json"},{},void 0,a));case 13:throw M;case 14:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getDataFromGrant=function(){var t=s(w.mark((function t(e,r){var n,a,o;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=e.lockboxOwnerUuid,n=e.lockboxUuid){t.next=3;break}throw M;case 3:if(a){t.next=5;break}throw S;case 5:return t.next=7,this.getLockboxManifest(n,r,!1,e.lockboxOwnerUuid,!0);case 7:return o=t.sent[0].dataUuid,t.t0=a,t.t1=n,t.t2=o,t.next=13,this.getJsonData(n,o);case 13:return t.t3=t.sent,t.abrupt("return",{lockboxOwnerUuid:t.t0,lockboxUuid:t.t1,dataUuid:t.t2,data:t.t3});case 15:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.getUserPreferenceFromConsultId=function(){var t=s(w.mark((function t(r){var n;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrantFromConsultId(r);case 2:if(n=t.sent){t.next=5;break}throw D;case 5:return t.abrupt("return",this.getDataFromGrant(n,{category:e.MetadataCategory.Preference,contentType:"application/json"}));case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getUserPreference=function(){var t=s(w.mark((function t(r){var n;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(n=t.sent.find((function(t){return t.lockboxOwnerUuid===r.id}))){t.next=5;break}throw D;case 5:return t.abrupt("return",this.getDataFromGrant(n,{category:e.MetadataCategory.Preference,contentType:"application/json"}));case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getRecoveryDataFromConsultId=function(){var t=s(w.mark((function t(r){var n;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrantFromConsultId(r);case 2:if(n=t.sent){t.next=5;break}throw D;case 5:return t.abrupt("return",this.getDataFromGrant(n,{category:e.MetadataCategory.Recovery,contentType:"application/json"}));case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getRecoveryData=function(){var t=s(w.mark((function t(r){var n;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrants();case 2:if(n=t.sent.find((function(t){return t.lockboxOwnerUuid===r.id}))){t.next=5;break}throw D;case 5:return t.abrupt("return",this.getDataFromGrant(n,{category:e.MetadataCategory.Recovery,contentType:"application/json"}));case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getAssignedConsultations=function(){var t=s(w.mark((function t(r){var n=this;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=Promise,t.next=3,this.getGrants();case 3:return t.t1=t.sent.map((function(t){return n.getLockboxManifest(t.lockboxUuid,{category:e.MetadataCategory.Consultation,documentType:e.DocumentType.PopulatedWorkflowData},!0,void 0).then((function(t){return Promise.all(t.map(function(){var t=s(w.mark((function t(e){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,n.consultClient.getConsultByUUID(e.metadata.consultationId,r);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())).then((function(t){return t.flat()}))}))})),t.abrupt("return",t.t0.all.call(t.t0,t.t1).then((function(t){return t.flat()})));case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getPastConsultationsFromConsultId=function(){var t=s(w.mark((function t(r,n){var a,o,i=this;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getGrantFromConsultId(r);case 2:if(a=t.sent){t.next=5;break}return t.abrupt("return",void 0);case 5:return t.next=7,this.vaultClient.lockboxMetadataGet(a.lockboxUuid,["consultationId"],["consultationId"],{category:e.MetadataCategory.Consultation,documentType:e.DocumentType.PopulatedWorkflowData},a.lockboxOwnerUuid);case 7:if(0!=(o=t.sent.flat().map((function(t){return t.consultationId}))).length){t.next=10;break}return t.abrupt("return",[]);case 10:return t.next=12,Promise.all(o.map(function(){var t=s(w.mark((function t(e){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,i.consultClient.getConsultByUUID(e,n);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 12:return t.abrupt("return",t.sent);case 13:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.getPatientConsultationData=function(){var t=s(w.mark((function t(r,n){var a=this;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===n&&(n=!1),t.t0=Promise,t.next=4,this.getGrants({consultationId:r});case 4:return t.t1=t.sent.map((function(t){return a.getLockboxManifest(t.lockboxUuid,{category:e.MetadataCategory.Consultation,documentType:e.DocumentType.PopulatedWorkflowData,consultationId:r},!0,t.lockboxOwnerUuid,n).then((function(e){return Promise.all(e.map((function(e){return a.getJsonData(t.lockboxUuid,e.dataUuid,t.lockboxOwnerUuid)})))}))})).flat(),t.abrupt("return",t.t0.all.call(t.t0,t.t1).then((function(t){return t.flat()})));case 6:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.getPatientPrescriptionsList=function(){var t=s(w.mark((function t(r){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getPatientDocumentsList({category:e.MetadataCategory.Consultation,documentType:e.DocumentType.Prescription},!0,r));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getPatientResultsList=function(){var t=s(w.mark((function t(r){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getPatientDocumentsList({category:e.MetadataCategory.Consultation,documentType:e.DocumentType.Result},!0,r));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getPatientTreatmentPlans=function(){var t=s(w.mark((function t(r){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getPatientDocumentsList({category:e.MetadataCategory.Consultation,documentType:e.DocumentType.TreatmentPlan},!0,r));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getPatientTreatmentPlanByUuid=function(){var t=s(w.mark((function t(r,n){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getPatientDocumentsList({category:e.MetadataCategory.Consultation,documentType:e.DocumentType.TreatmentPlan,treatmentPlanId:n},!0,r));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.getPatientDocumentsList=function(){var t=s(w.mark((function t(e,r,n){var a=this;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=Promise,t.next=3,this.getGrants({consultationId:n});case 3:return t.t1=t.sent.map((function(t){return a.getLockboxManifest(t.lockboxUuid,u({},e,{consultationId:n}),r,t.lockboxOwnerUuid,!0).then((function(e){return Promise.all(e.map(function(){var e=s(w.mark((function e(r){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({lockboxOwnerUuid:t.lockboxOwnerUuid,lockboxUuid:t.lockboxUuid},r));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()))}))})).flat(),t.abrupt("return",t.t0.all.call(t.t0,t.t1).then((function(t){return t.flat()})));case 5:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.recoverPrivateKeyFromSecurityQuestions=function(){var t=s(w.mark((function t(e,r,n,a){var o,i;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.identityGet(e);case 2:o=t.sent.recoverySecurityQuestions.filter((function(t){var e=r.indexOf(t.securityQuestion);return-1!==e&&n[e]&&""!=n[e]})).map((function(t){var e=r.indexOf(t.securityQuestion);return t.securityAnswer=n[e],t}));try{i=this.toolbox.reconstructSecret(o,a),this.rsa=this.toolbox.CryptoRSA.fromKey(i)}catch(t){console.error(t)}case 5:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a){return t.apply(this,arguments)}}(),r.recoverPrivateKeyFromPassword=function(){var t=s(w.mark((function t(e,r){var n,a,o,i,s;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.identityGet(e);case 2:a=(n=t.sent).recoveryPassword,o=this.toolbox.CryptoChaCha.fromPassphrase(r),i=o.base64PayloadDecryptToBytes(a),n.recoveryLogin&&(s=this.toolbox.CryptoChaCha.fromPassphrase(n.recoveryLogin),sessionStorage.setItem(I(e),s.bytesEncryptToBase64Payload(i))),this.rsa=this.toolbox.CryptoRSA.fromKey(i);case 8:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.recoverPrivateKeyFromMasterKey=function(){var t=s(w.mark((function t(e,r){var n,a,o;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.guardClient.identityGet(e);case 2:n=t.sent.recoveryMasterKey,a=this.toolbox.CryptoChaCha.fromPassphrase(r),o=a.base64PayloadDecryptToBytes(n),this.rsa=this.toolbox.CryptoRSA.fromKey(o);case 6:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.updateSecurityQuestions=function(){var t=s(w.mark((function t(e,r,n,a){var o,i;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return o=this.toolbox.breakSecretIntoShards(r,n,this.rsa.private(),a),i={recoverySecurityQuestions:o},t.next=6,this.guardClient.identityUpdate(e,i);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t,this)})));return function(e,r,n,a){return t.apply(this,arguments)}}(),r.updatePassword=function(){var t=s(w.mark((function t(e,r,n){var a,o,i;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return a=this.toolbox.CryptoChaCha.fromPassphrase(r),o=a.bytesEncryptToBase64Payload(this.rsa.private()),n&&(n=this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(n))),r=this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(r)),i={password:{oldPassword:n,newPassword:r},recoveryPassword:o},t.next=9,this.guardClient.identityUpdate(e,i);case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.updateMasterKey=function(){var t=s(w.mark((function t(r,n,a){var o,i,s,u;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.rsa){t.next=2;break}throw T;case 2:return o=this.toolbox.CryptoChaCha.fromPassphrase(n),i=o.bytesEncryptToBase64Payload(this.rsa.private()),s={recoveryMasterKey:i},t.next=7,this.guardClient.identityUpdate(r,s);case 7:return u=t.sent,t.next=10,this.getOrInsertJsonData(a,{masterKey:n},{category:e.MetadataCategory.Recovery,contentType:"application/json"},{},!0);case 10:return t.abrupt("return",u);case 11:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),t}(),pt=["locale"],ft=["locale"],ht=function(){function t(t,r,n){this.url=t,this.locale=n,this.api=new e.AxiosService({headers:{"X-Clinia-API-Key":r}})}var r=t.prototype;return r.placeSearch=function(t){var e=t.locale,r=x(t,pt);return this.api.post(this.url+"/search/v1/indexes/health_facility/query",r,{params:{locale:null!=e?e:this.locale}})},r.placeMatch=function(t,e){var r=t.locale,n=x(t,ft),a=this.api.post(this.url+"/search/v1/matches",n,{params:{locale:null!=r?r:this.locale}});return e&&(a=a.then((function(t){return t.filter((function(t){return t.type===e}))}))),a},t}();Object.keys(e).forEach((function(t){"default"!==t&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})})),exports.OroToolboxNamespace=n,exports.AssociatedLockboxNotFound=U,exports.CliniaService=ht,exports.IncompleteAuthentication=T,exports.MissingGrant=D,exports.MissingGrantFilter=O,exports.MissingLockbox=M,exports.MissingLockboxOwner=S,exports.OroClient=lt,exports.WorkflowAnswersMissingError=L,exports.buildConsultSearchIndex=at,exports.decryptConsultLockboxGrants=st,exports.decryptGrants=it,exports.default=function(t,e,n,a,o,i,s,u,c,l){var p=r({tellerBaseURL:e,vaultBaseURL:n,guardBaseURL:a,searchBaseURL:o,practiceBaseURL:i,consultBaseURL:s,workflowBaseURL:u,diagnosisBaseURL:c},l);return new lt(t,p.tellerService,p.vaultService,p.guardService,p.searchService,p.practiceService,p.consultService,p.workflowService,p.diagnosisService,l)},exports.extractAndStorePersonalWorkflowData=tt,exports.extractISOLocalityForConsult=function(t){if(t){var e=t.flatMap((function(t){var e=Object.keys(t).filter((function(t){return-1!==t.indexOf("Country")})).flat(),r=Object.keys(t).filter((function(t){return-1!==t.indexOf("Province")})).flat(),n=Object.keys(t).filter((function(t){return-1!==t.indexOf("Locality")})).flat();return[].concat(e.map((function(e){return"string"==typeof t[e]?t[e]:void 0})),r.map((function(e){return"string"==typeof t[e]?t[e]:void 0})),n.map((function(e){return"string"==typeof t[e]?t[e]:void 0})))})).filter((function(t){return void 0!==t})).filter((function(t){return t.startsWith("isoLocalityConsult")}));if(e&&0!==e.length){var r=o(/isoLocalityConsult(?:_(\d*))?\x2D([a-zA-Z0-9]{2}\x2D[a-zA-Z0-9]{1,3})/,{indexPriority:1,isoValue:2}),n=e.reduce((function(t,e){var n=r.exec(e),a=null!=n?n:[],o=a[1],i=a[2];if(!t)return i;var s=r.exec(t),u=null!=s?s:[],c=u[1];return!o||c&&c>o?u[2]:i}),void 0);return console.log("Picking locality "+n),n}console.log("no locality found in "+e)}},exports.extractPersonalInfoFromWorkflowData=rt,exports.fillWorkflowFromPopulatedWorkflow=function(t,e){var r=JSON.parse(JSON.stringify(t));return r.selectedAnswers||(r.selectedAnswers=J(r,!1)),r.pages.forEach((function(t,n){for(var a=0,o=Object.entries(t.questions);a<o.length;a++){var i=o[a][0];e.fields[i]&&r.selectedAnswers&&(r.selectedAnswers[n][i]=e.fields[i].answer)}})),r},exports.filterTriggeredAnsweredWithKind=E,exports.flattenSelectedAnswers=N,exports.getImagesFromIndexDb=B,exports.getInitialisedSelectedAnswers=J,exports.getWorkflowDataByCategory=G,exports.identificationToPersonalInformations=C,exports.isTriggered=K,exports.registerPatient=W,exports.sessionStorePrivateKeyName=I,exports.toActualObject=P,exports.updatePersonalIntoPopulatedWorkflowData=function(t,e,r){var n=k[r],a=JSON.parse(JSON.stringify(e));return t.birthday&&a.fields[n+"Birthday"]&&(a.fields[n+"Birthday"].answer=t.birthday),t.firstname&&a.fields[n+"Firstname"]&&(a.fields[n+"Firstname"].answer=t.firstname),t.gender&&a.fields[n+"Gender"]&&(a.fields[n+"Gender"].answer=t.gender),t.name&&a.fields[n+"Name"]&&(a.fields[n+"Name"].answer=t.name),t.phone&&a.fields[n+"Phone"]&&(a.fields[n+"Phone"].answer=t.phone),t.zip&&a.fields[n+"Zip"]&&(a.fields[n+"Zip"].answer=t.zip),t.hid&&(a.fields[n+"HID"]?a.fields[n+"HID"].answer=t.hid:a.fields[n+"ID"]?a.fields[n+"ID"].answer=t.hid:a.fields[n+"HID"]={kind:"text",answer:t.hid}),a},exports.wasmPath="node_modules/oro-toolbox";
2
2
  //# sourceMappingURL=oro-sdk.cjs.production.min.js.map