public void RunScript(string patientId, IEnumerable <PlanOrPlanSum> plansAndPlanSumsInScope, PlanOrPlanSum activePlan)
        {
            try
            {
                SaveRecent(patientId, plansAndPlanSumsInScope, activePlan);

                var patient = _esapiApp.OpenPatientById(patientId);
                var context = CreateScriptContext(patient, plansAndPlanSumsInScope, activePlan);

                if (_scriptWithWindow != null)
                {
                    var window = new Window();
                    _scriptWithWindow.Execute(context, window);
                    window.ShowDialog();
                }
                else if (_script != null)
                {
                    _script.Run(context);
                }
            }
            catch (Exception e)
            {
                // Mimic Eclipse by showing a message box when an exception is thrown
                MessageBox.Show(e.Message, ApplicationName, MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            finally
            {
                _esapiApp.ClosePatient();
            }
        }