!function(){$$WP.Utilities.guaranteeExistence($$WP,"DecisionTrees.Controllers");var r=$$WP.DecisionTrees.Models.Questionnaire,n=Epic.PatientEngagement.Questionnaire.QuestionnaireAction,u=Epic.PatientEngagement.Questionnaire.MyChart.QuestionnaireController,f=Epic.PatientEngagement.Questionnaire.QuestionnaireWorkflowInformation,e=Epic.PatientEngagement.Questionnaire.UiCallbacks,o=Epic.PatientEngagement.Questionnaire.Ui,t=$$WP.DecisionTrees.Enums.TraversalAction,i=function(n,t,i,r,u,f,e){this.WP$Controllers$Controller();this.$root=n;this.nodeData=t;this.afterCompleteCallback=e;this.settings=u||new $$WP.DecisionTrees.Models.TraversalSettings;this.additionalContext=f||new $$WP.DecisionTrees.Models.TraversalAdditionalContext;this.questionnaireContext=i;this.questionnaireContextIdentifier=r;this.initialize()};i.prototype={$root:null,afterCompleteCallback:null,nodeData:null,settings:null,additionalContext:null,questionnaire:null,questionnaireContext:null,questionnaireContextIdentifier:null,templateData:null,initialize:function(){this.questionnaire=new r(this.nodeData.Questionnaire);this.templateData=this.nodeData;this.templateData.IsBackAllowed=this.settings.AllowBack;this.templateData.IsFinishLaterAllowed=this.settings.AllowFinishLater;this.templateData.IsCancelAllowed=this.settings.AllowCancel;this.render()},render:function(){var t,i,r,n,s;this.$root.safeAppend($afe.renderTemplate($$WP.Templates.DecisionTrees.QuestionnaireNode,this.templateData));t=o.getDomElementsForQuestionnaireView();i={alwaysEnableBackButton:!this.nodeData.IsFirst,shouldDisplayQuestionnaireName:!1,callBackOnSave:!0,showBottomBackButton:!$$WP.Utilities.UI.IsMobile,focusOnIntialRender:this.settings.FocusOnLoad,allowFinishLater:this.templateData.IsFinishLaterAllowed,StringNamespace:$$WP.Utilities.UI.IsSelfTriageForAll?"SelfTriage.SelfTriagePage":"",disableUnsavedChangesPopup:this.settings.DisableUnsavedChangesPopup};s={hideSummaryPage:!0,defaultAnswersFromDAT:this.additionalContext.FavoriteApptDAT?this.additionalContext.FavoriteApptDAT:null};r=new f(this,this.questionnaireContext,this.questionnaireContextIdentifier,i,null,s);n=new e;this.questionnaireContext===$$WP.DecisionTrees.Enums.TraversalSourceWorkflow.Scheduling&&(n.defaultSettings={scrollToTop:!1});new u(this.questionnaire.ID,t,r,n).start()},questionnaireCallback:function(i,r){var u;switch(this.questionnaire.AnswerID=r,i){case n.AdvanceQuestionnaire:u=t.Next;break;case n.BackQuestionnaire:u=t.Previous;break;case n.CancelQuestionnaire:u=t.Cancel;break;case n.SaveQuestionnaire:u=t.Save;break;case n.Error:u=t.Error}null!==this.afterCompleteCallback&&"function"==typeof this.afterCompleteCallback&&this.afterCompleteCallback(u,this.questionnaire)},_suppressSpinner:function(){$afe.select(".dt-spinner").hide()}};$$WP.DecisionTrees.Controllers.QuestionnaireNodeController=i;i.extend($$WP.Controllers.Controller,"WP$DecisionTrees$Controllers$QuestionnaireNodeController")}();!function(){$$WP.Utilities.guaranteeExistence($$WP,"DecisionTrees.Controllers");var i=$$WP.Questions.QuestionsController,n=$$WP.DecisionTrees.Enums.TraversalAction,t=function(n,t,i,r,u){this.WP$Controllers$Controller();this.proxify("_onPopupButtonClick","_onContinueButtonClick","_onBackButtonClick","_onFinishLaterButtonClick","_onCancelButtonClick","_onQuestionLoaded");this.$root=n;this.$formButtonsRoot=t;this.nodeData=i;this.afterCompleteCallback=u;this.settings=r||new $$WP.DecisionTrees.Models.TraversalSettings;this.initialize()};t.prototype={$root:null,$formButtonsRoot:null,afterCompleteCallback:null,nodeData:null,settings:!0,templateData:null,questionsController:null,initialize:function(){this.templateData=this.nodeData;this.render()},render:function(){var n;this.$root.safeAppend($afe.renderTemplate($$WP.Templates.DecisionTrees.QuestionNode,this.templateData));n=$afe.select("#question-wrapper");this.questionsController=new i(n,[this.nodeData.Question],this._onQuestionLoaded);this.postRender()},postRender:function(){0!==$afe.select(".question-prompt-header.required").length&&($afe.select("#required-legend").addClass("required"),$afe.select("#required-legend").show());this.$formButtonsRoot.find("#next-step").on("click",this._onContinueButtonClick);this.$formButtonsRoot.find("#previous-step").on("click",this._onBackButtonClick);this.$formButtonsRoot.find("#save-workflow").on("click",this._onFinishLaterButtonClick);this.$formButtonsRoot.find("#cancel-workflow").on("click",this._onCancelButtonClick);this._setBeforeUnload()},_onQuestionLoaded:function(){var n,t;this.settings.FocusOnLoad&&(n=this.$root.find(".questionsContainer > :first-child"),t=$$WPQuestionUtil.getFocusableElement(n),setTimeout(function(n){n.focus()},500,t))},_onContinueButtonClick:function(){return this._disableClickHandlers(),this._performCallback(n.Next,this.questionsController.getCoreModelsWithAnswers()[0]),!1},_onBackButtonClick:function(){return!!this.settings.AllowBack&&(this._disableClickHandlers(),this._performCallback(n.Previous),!1)},_onCancelButtonClick:function(){if(!this.settings.AllowCancel)return!1;$$WP.Strings.setDefaultNamespace(this.settings.StringNamespace);var t=$$WP.Strings.get("DTCancelPopupPrompt"),n=[];return n.push(new $$WPComp.ComplexObjects.Button($$WP.Strings.get("DTCancelPopupDeleteResponsesButtonLabel"),null,"primary negative","continue")),this.settings.AllowFinishLater&&n.push(new $$WPComp.ComplexObjects.Button($$WP.Strings.get("DTCancelPopupSaveResponsesButtonLabel"),null,"secondary neutral","saveandcontinue")),n.push(new $$WPComp.ComplexObjects.Button($$WP.Strings.get("DTCancelPopupGoBackButtonLabel"),null,"secondary neutral","cancel")),$$WPUtil.quickMessageBox(t,$$WP.Strings.get("DTCancelPopupTitle"),n,this._onPopupButtonClick,void 0,void 0,!isDataTile()&&void 0),$$WP.Strings.clearDefaultNamespace(),!1},_onFinishLaterButtonClick:function(){return!!this.settings.AllowFinishLater&&(this._disableClickHandlers(),this._performCallback(n.Save,this.questionsController.getCoreModelsWithAnswers()[0]),!1)},_onPopupButtonClick:function(t){switch(t.replace($$WP.Components.TOOLBARIDENTIFIER,"")){case"continue":this._disableClickHandlers();this._performCallback(n.Cancel);break;case"saveandcontinue":this._onFinishLaterButtonClick();break;case"exit":this._clearBeforeUnload(!0);window.location.href=makeLink("default.asp")}},_performCallback:function(n,t){null!==this.afterCompleteCallback&&"function"==typeof this.afterCompleteCallback&&this.afterCompleteCallback(n,t)},_disableClickHandlers:function(){this.$formButtonsRoot.find("#next-step").off("click",this._onContinueButtonClick);this.$formButtonsRoot.find("#previous-step").off("click",this._onBackButtonClick);this.$formButtonsRoot.find("#save-workflow").off("click",this._onFinishLaterButtonClick);this.$formButtonsRoot.find("#cancel-workflow").off("click",this._onCancelButtonClick);this._clearBeforeUnload()},_setBeforeUnload:function(){this.settings.DisableUnsavedChangesPopup||WP.Events.beforeUnload()},_clearBeforeUnload:function(n){this.settings.DisableUnsavedChangesPopup||WP.Events.cancelBeforeUnload(n)}};$$WP.DecisionTrees.Controllers.QuestionNodeController=t;t.extend($$WP.Controllers.Controller,"WP$DecisionTrees$Controllers$QuestionNodeController")}();!function(){$$WP.Utilities.guaranteeExistence($$WP,"DecisionTrees.Controllers");var f=$$WP.DecisionTrees.Models.TreeTraversal,u=$$WP.DecisionTrees.Models.InputNode,n=$$WP.DecisionTrees.Enums.TraversalAction,t=$$WP.DecisionTrees.Enums.NodeType,e=$$WP.DecisionTrees.Controllers.QuestionNodeController,o=$$WP.DecisionTrees.Controllers.QuestionnaireNodeController,i=$$WP.DecisionTrees.Enums.TraversalStatus,s=$$WP.DecisionTrees.Enums.TraversalSourceWorkflow,r=function(n,t,i,r,u,f,e,o,s,h){this.WP$Controllers$Controller();this.proxify("_onQuestionNodeCallback","_onQuestionnaireNodeCallback","_onRequestCallback","_handleNextStepSuccess","_handlePreviousStepSuccess","_handleSaveStepSuccess","_handleDiscardWorkflowSuccess","_handleError");r=null!==r&&r instanceof $$WP.DecisionTrees.Models.TraversalSettings?r:new $$WP.DecisionTrees.Models.TraversalSettings;e=null!==e&&e instanceof $$WP.DecisionTrees.Models.TraversalAdditionalContext?e:new $$WP.DecisionTrees.Models.TraversalAdditionalContext;this.$root=n||$afe.select("body");this.afterCompleteCallback=f;this.settings=r;this.initialize(t,i,u,e,o,s,h)},h={$root:null,afterCompleteCallback:null,traversalInfo:null,currentInputNode:null,settings:null,_isActive:!0,_isTemplateLoaded:!1,_isInitialRender:!0,_useSameRoot:!1,_parentTreeWasDirty:!1,initialize:function(n,t,i,r,u,e,o){this.traversalInfo=new f({TreeID:n,SourceWorkflow:t,AdditionalContext:r,RestartTree:i,ParentAnswerID:e});this._useSameRoot=u;this._parentTreeWasDirty=o;this._nextStep()},destroy:function(){this.$root.empty();this.afterCompleteCallback=null;this._isActive=!1},render:function(){var n,i,u;this._isActive&&((this._updateTemplateData(),this._isTemplateLoaded&&!this.traversalInfo.TreeWasLocked||null!==this.currentInputNode&&this.currentInputNode.Type===t.AddAppointmentRequest||(this.$root.empty(),this.$root.safeAppend($afe.renderTemplate($$WP.Templates.DecisionTrees.DecisionTree,this.templateData)),this._fadeContent(),this._isTemplateLoaded=!0),this.traversalInfo.TreeWasLocked)||(u=$afe.select("body"),n=this.$root.find("#dt-node-content"),i=this.$root.find("#dt-node-container .formbuttons"),this.traversalInfo.TreeWasDirty||this._parentTreeWasDirty?this.$root.find("#dt-banner").removeClass("hidden"):this.$root.find("#dt-banner").addClass("hidden"),this._isInitialRender?(this._isInitialRender=!1,this.settings.FocusOnLoad=!1):this.settings.FocusOnLoad=!0,this._updateBackButtonVisibility(),u.hasClass("md_scheduling_index")?$afe.select("#dt-node-content").empty():n.empty(),this._resetContainer(),this.currentInputNode.Type===t.Question?new e(n,i,this.currentInputNode,this.settings,this._onQuestionNodeCallback):this.currentInputNode.Type===t.Questionnaire?new o(n,this.currentInputNode,this.traversalInfo.SourceWorkflow,this.traversalInfo.TreeID,this.settings,this.traversalInfo.AdditionalContext,this._onQuestionnaireNodeCallback):this.currentInputNode.Type===t.AddAppointmentRequest?new r(this.$root,this.currentInputNode.DecisionTree.ID,this.traversalInfo.SourceWorkflow,this.settings,!1,this._onRequestCallback,null,!0,this.traversalInfo.TreeAnswerID,this.traversalInfo.TreeWasDirty||this._parentTreeWasDirty):$$WP.Debug.logError("Unsupported input node type encountered during tree traversal.")),(this.traversalInfo.TreeWasLocked||this.currentInputNode.Type!==t.AddAppointmentRequest)&&this._showContent())},hadAnyQuestions:function(){var n=null;return this.traversalInfo&&(n=this.traversalInfo.ParentAnswerID),this.currentInputNode&&!n},_resetContainer:function(){var n=this.$root.find("#dt-node-container");this.$root.find("#dt-node-container .formbuttons #next-step").prop("data-disable-if-invalid");n.removeAttr("data-invalid");n.length>0&&$$WP.FormValidation.checkIfFormIsValid(n,!0)},_updateBackButtonVisibility:function(){var n=this.$root.find("#dt-node-container .formbuttons #previous-step");this.settings.AllowBack&&this.currentInputNode&&!this.currentInputNode.IsFirst?(n.show().removeClass("btnHidden"),n.safeAttr("aria-hidden","false")):n.hide().addClass("btnHidden")},_updateTemplateData:function(){$$WP.Strings.setDefaultNamespace(this.settings.StringNamespace);this.templateData={};this.templateData.StringNamespace=this.settings.StringNamespace;this.templateData.TreeWasLocked=this.traversalInfo.TreeWasLocked;this.templateData.IsFinishLaterAllowed=this.settings.AllowFinishLater;this.templateData.IsBackAllowed=this.settings.AllowBack;this.templateData.IsCancelAllowed=this.settings.AllowCancel;this.templateData.ContinueButtonLabel=$$WP.Strings.getForTemplate("DTContinueButtonLabel");this.templateData.BackButtonLabel=$$WP.Strings.getForTemplate("DTBackButtonLabel");this.templateData.FinishLaterButtonLabel=$$WP.Strings.getForTemplate("DTFinishLaterButtonLabel");this.templateData.CancelButtonLabel=$$WP.Strings.getForTemplate("DTCancelButtonLabel");$$WP.Strings.clearDefaultNamespace()},_nextStep:function(n){var t;this._fadeContent();t={};$$WPUtil.IsNullOrEmpty(this.traversalInfo)||(t.traversalInfo=this.traversalInfo.toRawObject());$$WPUtil.IsNullOrEmpty(this.currentInputNode)||(t.prevInputNode=this.currentInputNode.toRawObject(),t.prevInputNode.Question=null);t.question=n;$.ajax({url:makeLink(this.__getDecisionTreeAjaxUrl("NextStep")),type:"POST",dataType:"json",data:$$WP.Utilities.postify(t),success:this._handleNextStepSuccess,error:this._handleError})},_previousStep:function(){var n;this._fadeContent();n={};this.currentInputNode.IsFirst?this._handleError():($$WPUtil.IsNullOrEmpty(this.traversalInfo)||(n.traversalInfo=this.traversalInfo.toRawObject()),$.ajax({url:makeLink("DecisionTrees/DecisionTree/PreviousStep"),type:"POST",dataType:"json",data:$$WP.Utilities.postify(n),success:this._handlePreviousStepSuccess,error:this._handleError}))},_saveStep:function(n){var t;this._fadeContent();t={};$$WPUtil.IsNullOrEmpty(this.traversalInfo)||(t.traversalInfo=this.traversalInfo.toRawObject());$$WPUtil.IsNullOrEmpty(this.currentInputNode)||(t.inputNode=this.currentInputNode.toRawObject(),t.inputNode.Question=null);t.question=n;$.ajax({url:makeLink("DecisionTrees/DecisionTree/SaveStep"),type:"POST",dataType:"json",data:$$WP.Utilities.postify(t),success:this._handleSaveStepSuccess,error:this._handleError})},_discardWorkflow:function(){var n;this._fadeContent();n={};$$WPUtil.IsNullOrEmpty(this.traversalInfo)||(n.traversalInfo=this.traversalInfo.toRawObject());$.ajax({url:makeLink("DecisionTrees/DecisionTree/DiscardWorkflow"),type:"POST",dataType:"json",data:$$WP.Utilities.postify(n),success:this._handleDiscardWorkflowSuccess,error:this._handleError})},__getDecisionTreeAjaxUrl:function(n){return $$WP.WidgetMode?"DecisionTrees/EmbeddedDecisionTree/"+n:$$WP.Utilities.UI.IsLoggedIn||this.traversalInfo.SourceWorkflow==s.SelfTriage||this.traversalInfo.AdditionalContext.IsGuest?"DecisionTrees/DecisionTree/"+n:"DecisionTrees/AnonymousDecisionTree/"+n},_handleNextStepSuccess:function(t){var f,r;f=t.NextInputNode;r=t.TraversalInfo;this.traversalInfo.IsTraversalComplete=r.IsTraversalComplete;this.traversalInfo.TreeWasDirty=r.TreeWasDirty;this.traversalInfo.TreeWasLocked=r.TreeWasLocked;this.traversalInfo.TreeAnswerID=r.TreeAnswerID;this.traversalInfo.RestartTree=!1;this.traversalInfo.TreeWasLocked?this.render():this.traversalInfo.IsTraversalComplete?this._performCallback(i.Complete,this.traversalInfo.TreeAnswerID,this._useSameRoot,n.Next):(this.currentInputNode=new u(f),this.render(),this.settings&&this.settings.OnStepRender&&this.settings.OnStepRender())},_handlePreviousStepSuccess:function(t){var f,r;f=t.PreviousInputNode;r=t.TraversalInfo;this.traversalInfo.IsTraversalComplete=r.IsTraversalComplete;this.traversalInfo.TreeWasDirty=r.TreeWasDirty;this.traversalInfo.TreeWasLocked=r.TreeWasLocked;this.traversalInfo.TreeAnswerID=r.TreeAnswerID;this.traversalInfo.TreeWasLocked?this.render():this._useSameRoot&&""===f.ID?this._performCallback(i.Complete,this.traversalInfo.TreeAnswerID,this._useSameRoot,n.Previous):(this.currentInputNode=new u(f),this.render(),this.settings&&this.settings.OnStepRender&&this.settings.OnStepRender())},_handleSaveStepSuccess:function(t){this.traversalInfo.TreeWasLocked=t.TraversalInfo.TreeWasLocked;this.traversalInfo.TreeWasLocked?this.render():this._performCallback(i.FinishLater,this.traversalInfo.TreeAnswerID,this._useSameRoot,n.Save)},_handleDiscardWorkflowSuccess:function(t){this.traversalInfo.TreeWasLocked=t.TraversalInfo.TreeWasLocked;this.traversalInfo.TreeWasLocked?this.render():this._performCallback(i.FinishLater,this.traversalInfo.TreeAnswerID,this._useSameRoot,n.Cancel)},_handleError:function(){this._performCallback(i.Error)},_onQuestionNodeCallback:function(n,t){this._onButtonClick(n,t,null)},_onQuestionnaireNodeCallback:function(n,t){this._onButtonClick(n,null,t)},_onRequestCallback:function(n){this._onButtonClick(n)},_onButtonClick:function(i,r,u){switch(this.currentInputNode.Type===t.Questionnaire&&(this.currentInputNode.Questionnaire=u),i){case n.Next:this._nextStep(r);break;case n.Previous:this._previousStep();break;case n.Save:this._saveStep(r);break;case n.Cancel:this._discardWorkflow();break;case n.Error:this._handleError()}},_performCallback:function(n,t,i,r){!0!==i&&this.$root.empty();null!=r&&null!==this.afterCompleteCallback&&"function"==typeof this.afterCompleteCallback?this.afterCompleteCallback(r,t):null!==this.afterCompleteCallback&&"function"==typeof this.afterCompleteCallback&&this.afterCompleteCallback(n,t)},_fadeContent:function(){this.$root.find("#dt-node-container").fadeTo("fast",0);$$WPUtil.ShowAjaxSpinner(this.$root.find(".dt-spinner .ajaxspinner"));this.$root.find(".dt-spinner").fadeTo("fast",1)},_showContent:function(){this.$root.find(".dt-spinner").fadeTo("fast",.1,function(){$$WPUtil.HideAjaxSpinner($afe.jq(this).find(".ajaxspinner"))});this.$root.find("#dt-node-container").fadeTo("fast",1)}};r.prototype=h;$$WP.DecisionTrees.Controllers.DecisionTreeTraversalController=r;r.extend($$WP.Controllers.Controller,"WP$DecisionTrees$Controllers$DecisionTreeTraversalController")}()