public OptionObject RunScript(OptionObject optionObject, String scriptName)
        {
            var currentTime = DateTime.Now.ToString("hh:mm tt");
            OptionObject returnOptionObject = new OptionObject();
            returnOptionObject.EntityID = optionObject.EntityID;
            returnOptionObject.OptionId = optionObject.OptionId;
            returnOptionObject.Facility = optionObject.Facility;
            returnOptionObject.SystemCode = optionObject.SystemCode;

            switch (scriptName.Split(',')[0])
            {
                #region Case statements < 11-09-2015
                case "checkForHomeless":
                    returnOptionObject = emptyZipCode(optionObject,string.Empty);
                    break;
                case "ssnAllNines":
                    returnOptionObject = clearZipCodeIfAllNines(optionObject, string.Empty);
                    break;
                case "MakeTimeRequired":
                    returnOptionObject = MakeTimeRequired(optionObject, false);
                    break;
                case "MakeTimeRequiredInpatient":
                    returnOptionObject = MakeTimeRequired(optionObject, true);
                    break;
                case "SourceOfAdmission":
                    returnOptionObject = SourceOfAdmission(optionObject);
                    break;
                case "SocialSecurityDefault":
                    returnOptionObject = SocialSecurityDefault(optionObject, true);
                    break;
                case "SocialSecurityDefaultDemo":
                    returnOptionObject = SocialSecurityDefault(optionObject, false);
                    break;
                case "CheckDiagnosis":
                    returnOptionObject = CheckDiagnosis(optionObject, scriptName);
                    break;
                case "Discharge":
                    returnOptionObject = Discharge(optionObject);
                    break;
                case "CheckSubscriberPolicy":
                    returnOptionObject = CheckSubscriberPolicy(optionObject);
                    break;
                case "CheckSubscriberMedicaid":
                    returnOptionObject = CheckSubscriberMedicaid(optionObject);
                    break;
                case "CheckSubscriberMedicare":
                    returnOptionObject = CheckSubscriberMedicare(optionObject);
                    break;
                case "CheckNoteType":
                    returnOptionObject = CheckNoteType(optionObject);
                    break;
                case "DisabilityAlert":
                    returnOptionObject = DisabilityAlert(optionObject);
                    break;
                case "TreatmentPlan":
                    returnOptionObject = TreatmentPlan(optionObject);
                    break;
                case "ServiceNeedsIntensityAssessment":
                    returnOptionObject = ServiceNeedsIntensityAssessment(optionObject);
                    break;
                case "DefaultMGAFScore":
                    returnOptionObject = DefaultMGAFScore(optionObject);
                    break;
                case "ChartLocationOptionLoad":
                    returnOptionObject = ChartLocation(optionObject, true);
                    break;
                case "ChartLocation":
                    returnOptionObject = ChartLocation(optionObject, false);
                    break;
                case "MapReferral":
                    returnOptionObject = MapReferral(optionObject, false);
                    break;
                case "ReferralDirections":
                    returnOptionObject = MapReferral(optionObject, true);
                    break;
                case "LoadDisclaimers":
                    returnOptionObject = LoadDisclaimers(optionObject);
                    break;
                case "DefaultCheckinInventory":
                    returnOptionObject = DefaultPractitioner(optionObject, true);
                    break;
                case "DefaultCheckoutInventory":
                    returnOptionObject = DefaultPractitioner(optionObject, false);
                    break;
                case "AppointmentStatus":
                    returnOptionObject = AppointmentStatus(optionObject, true);
                    break;
                case "StaffAppointmentStatus":
                    returnOptionObject = AppointmentStatus(optionObject, false);
                    break;
                case "EmailAuthorizationNotification":
                    returnOptionObject = EmailAuthorizationNotification(optionObject);
                    break;
                case "CheckFSROutcome":
                    returnOptionObject = CheckFSROutcome(optionObject);
                    break;
                case "CheckFSRDraft":
                    returnOptionObject = CheckFSRDraft(optionObject);
                    break;
                case "CheckFSRStatus":
                    returnOptionObject = CheckFSRStatus(optionObject);
                    break;
                case "CheckDaysWorked":
                    returnOptionObject = CheckDaysWorked(optionObject);
                    break;
                case "EmailVoidPN":
                    returnOptionObject = EmailVoidPN(optionObject, currentTime);
                    break;
                case "AddDurationOutpatient":
                    returnOptionObject = AddDuration(optionObject, false);
                    break;
                case "AddDurationInpatient":
                    returnOptionObject = AddDuration(optionObject, true);
                    break;
                case "MakeEpisodeRequired":
                    returnOptionObject = MakeEpisodeRequired(optionObject);
                    break;
                case "UpdateUser":
                    returnOptionObject = UpdateUser(optionObject);
                    break;
                case "DefaultAssessmentInfo":
                    returnOptionObject = DefaultAssessmentInfo(optionObject);
                    break;
                case "DefaultSubstanceAbuse":
                    returnOptionObject = DefaultSubstanceAbuse(optionObject);
                    break;
                case "DefaultDiagnosticAssessment":
                    returnOptionObject = DefaultDiagnosticAssessment(optionObject);
                    break;
                case "DefaultResidentialCaregiver":
                    returnOptionObject = DefaultResidentialCaregiver(optionObject);
                    break;
                case "DefaultCrisisServices":
                    returnOptionObject = DefaultCrisisServices(optionObject);
                    break;
                case "DefaultPsychosocial":
                    returnOptionObject = DefaultPsychosocial(optionObject);
                    break;
                case "RemoveCaseload":
                    returnOptionObject = RemoveCaseload(optionObject);
                    break;
                case "CheckOverlapPsyEval":
                    returnOptionObject = CheckOverlap(optionObject, "PsyEval");
                    break;
                case "CheckOverlapOPN":
                    returnOptionObject = CheckOverlap(optionObject, "OPN");
                    break;
                case "CheckOverlapPsyHist":
                    returnOptionObject = CheckOverlap(optionObject, "PsyHist");
                    break;
                case "CheckOverlapTXPN":
                    returnOptionObject = CheckOverlap(optionObject, "TXPN");
                    break;
                case "CheckOverlapMedNote":
                    returnOptionObject = CheckOverlap(optionObject, "MedNote");
                    break;
                case "AddDurationAndTime":
                    returnOptionObject = AddDurationAndTime(optionObject, scriptName);
                    break;
                case "Required":
                    returnOptionObject = MakeFieldsRequired(optionObject, scriptName);
                    break;
                case "MakeSubscriberPolicyRequired":
                    returnOptionObject = MakeSubscriberPolicyRequired(optionObject);
                    break;
                case "ProgramTransfer":
                    returnOptionObject = ProgramTransfer(optionObject, scriptName);
                    break;
                case "PreAdmitCompleted":
                    string status = PreAdmitCompleted(optionObject, returnOptionObject, "554", "7");
                       returnOptionObject.ErrorCode = Convert.ToInt32(status.Split('|')[0].ToString());
                       returnOptionObject.ErrorMesg = status.Split('|')[1].ToString();
                    break;
                case "MUVisit":
                    MUVisitSummary mu = new MUVisitSummary();
                    returnOptionObject = mu.setAppointmentInformation(optionObject, "988", "137.43");
                    break;
                case "AppointmentEditDetails":
                    returnOptionObject = AppointmentEditDetails(optionObject);
                    break;
                case "ClientLGBTAdmission" :
                    setAdmissionLGBT lgbt = new setAdmissionLGBT();
                    //return optionObject
                    returnOptionObject = lgbt.createReturnOO(optionObject, "523", "636.3");
                    break;
                case "FSRinDraft" :
                    CheckForMissingFSROnDischarge cmf = new CheckForMissingFSROnDischarge();
                    returnOptionObject = cmf.createOptionObject(optionObject, "550", "55");
                    break;
            #endregion

                #region ValidateField
                case "ValidateField":
                    #region variables
                    string formId = scriptName.Split(',')[1];
                    string FieldToValidate_FieldNumber = scriptName.Split(',')[2];
                    string fieldName = scriptName.Split(',')[3];
                    string errorMsgZip = "Invalid Zip Code. If client is Homeless or does not have a Zip Code, then use brach Zip Code";
                    string errorMsgSSN = "Invalid SSN. If client does not have a valid SSN, then use " +
                        "<font color = 'blue'><strong>888-88-8888</strong></font>";

                    int index = 0;
                    StringBuilder valueToCheck = new StringBuilder();
                    OptionObjectHelper SimpleHelper = new OptionObjectHelper();
                    #endregion
                    switch (fieldName)
                    {
                        case "Zip Code":
                            string ZipCode_fieldValue = SimpleHelper.getFieldValue(optionObject, formId, FieldToValidate_FieldNumber);
                            index = ZipCode_fieldValue.Length;
                            ValidateField(fieldName, errorMsgZip, optionObject, returnOptionObject, formId, FieldToValidate_FieldNumber, SimpleHelper, index);
                            break;
                        case "SSN":
                            string SSN_fieldValue = SimpleHelper.getFieldValue(optionObject, formId, FieldToValidate_FieldNumber);
                            index = SSN_fieldValue.Length - 2;
                            ValidateField(fieldName, errorMsgSSN, optionObject, returnOptionObject, formId, FieldToValidate_FieldNumber, SimpleHelper, index);
                            break;
                    }
                    break;
                #endregion

                default:
                    break;
            }
            return returnOptionObject;
        }
        private static void ValidateField(string fieldName, string errorMsg, OptionObject optionObject, OptionObject returnOptionObject, string formId, string FieldToValidate_FieldNumber, OptionObjectHelper SimpleHelper, int index)
        {
            string fieldValue = SimpleHelper.getFieldValue(optionObject, formId, FieldToValidate_FieldNumber);
            List<string> allowedSSN = new List<string>(){"888888888"};

            for (int i = 0; i <= 9; i++)
            {
                StringBuilder temp = new StringBuilder();
                for (int x = 1; x <= index; x++)
                {
                    temp.Append(i.ToString());
                }
                if (fieldName.Equals("SSN"))
                {
                    if (allowedSSN.Any(x => x.Equals(temp.ToString())))
                        continue;
                    temp.Insert(3, '-');
                    temp.Insert(6, '-');
                }
                if (fieldValue.Equals(temp.ToString()))
                {
                    returnOptionObject.ErrorCode = 1;
                    returnOptionObject.ErrorMesg = errorMsg;
                    break;
                }
            }
        }
        private string PreAdmitCompleted(OptionObject OO, OptionObject optionObject,string formId, string FieldNumber)
        {
            OptionObjectHelper SimpleHelper = new OptionObjectHelper();
            string episode_number = SimpleHelper.getFieldValue(OO, formId, FieldNumber);
            var returnOptionObject = new OptionObject();
            var Client = getClientInfoByClientEpisode(optionObject.EntityID, episode_number);
            var westBrowardPrograms = ConfigurationManager.AppSettings["WestBrowardPrograms"].ToString().Split(',').ToList();
            var housingPrograms = ConfigurationManager.AppSettings["HousingPrograms"].ToString().Split(',').ToList();

            #region//optionObject.ErrorCode = 2; code for testing
            //if (Client != null)
            //{
            //    try
            //    {
            //        optionObject.ErrorMesg = "This is a <strong>TEST</strong>. Please select <strong>OK</strong> and continue the note.<br>Line 585<br>"
            //                            + Client.ClientName.ToString() + "<br>"
            //                            + episode_number;
            //    }
            //    catch (Exception exc)
            //    {
            //        optionObject.ErrorMesg = "This is a <strong>TEST</strong>. Please select <strong>OK</strong> and continue the note.<br>line 589<br>" + exc.ToString() +
            //                                 "<br>PATID: " + optionObject.EntityID +
            //                                 "<br>EN: " + optionObject.EpisodeNumber.ToString();
            //    }
            //}
            //else
            #endregion
            try
            {
                if (Client != null)
                {
                    if (westBrowardPrograms.Contains(Client.ProgramCode))
                    {
                        sendEmail(
                            ConfigurationManager.AppSettings["SMTPFromEmailAddress"].ToString(),
                            "Pre-admit/Admit for (" + Client.ProgramCode + ") " + Client.ProgramValue + " completed.",
                            Client.ToString(),
                            new List<string> { ConfigurationManager.AppSettings["SMTPCreateSWTicket"].ToString() },
                            new List<string>(),
                            ConfigurationManager.AppSettings["westBrowardAdmitTicketCreation"].ToString().Split(',').ToList());
                    }
                    else if (housingPrograms.Contains(Client.ProgramCode))
                    {
                        sendEmail(
                            ConfigurationManager.AppSettings["SMTPFromEmailAddress"].ToString(),
                            "Pre-admit/Admit for (" + Client.ProgramCode + ") " + Client.ProgramValue + " completed.",
                            Client.ToString(),
                            new List<string> { ConfigurationManager.AppSettings["SMTPCreateSWTicket"].ToString() },
                            new List<string>(),
                            ConfigurationManager.AppSettings["housingAdmitTicketCreation"].ToString().Split(',').ToList());
                    }
                }
            }
            catch (Exception exc)
            {
                return "2|This is a <strong>TEST</strong>. Please select <strong>OK</strong> and continue the note.<br>Line 639<br>" + exc.ToString() + "<br>" + Client.ClientName;
            }
                return "0|Message Sent";
        }