Пример #1
0
        public ActionResult ShowEligibility()
        {
            if (!SessionHelper.IsUserLoggedIn)
            {
                return(RedirectToAction("Index", "Account", null));
            }

            if (SessionHelper.SessionForm == null)
            {
                SessionHelper.SessionForm = new SessionForm();
            }

            // retrieve and set SessionForm params
            string     formIdent = "CA-ADAP-DASHBOARD", entName = "California";
            def_Forms  frm = formsRepo.GetFormByIdentifier(formIdent);
            Enterprise ent = new AuthenticationClient().GetEnterpriseByName(entName);

            if (frm == null)
            {
                return(Content("Could not find form with identifier \"" + formIdent + "\""));
            }

            if (ent == null)
            {
                return(Content("Could not find enterprise with name \"" + entName + "\""));
            }

            //  Get the FormResult to get the subject of the current Application
            def_FormResults fr = formsRepo.GetFormResultById(SessionHelper.SessionForm.formResultId);

            if (fr == null)
            {
                return(Content("Could not find the current Application  \"" + SessionHelper.SessionForm.formResultId.ToString() + "\""));
            }

            // Get the Eligibility Form for the subject
            IEnumerable <def_FormResults> frElgList = formsRepo.GetFormResultsByFormSubject(frm.formId, fr.subject);
            def_FormResults frElg = null;

            if ((frElgList == null) || frElgList.Count <def_FormResults>() == 0)
            {
                mLogger.Debug("Couldn't find a current FormResult for Eligibility.  Create one.");
                frElg = new def_FormResults()
                {
                    formId               = frm.formId,
                    formStatus           = 0,
                    sessionStatus        = 0,
                    dateUpdated          = DateTime.Now,
                    deleted              = false,
                    locked               = false,
                    archived             = false,
                    EnterpriseID         = ent.EnterpriseID,
                    GroupID              = fr.GroupID, // User the same Enrollment Center
                    subject              = fr.subject,
                    interviewer          = fr.interviewer,
                    assigned             = fr.assigned,
                    training             = false,
                    reviewStatus         = 0,
                    statusChangeDate     = DateTime.Now,
                    LastModifiedByUserId = fr.LastModifiedByUserId
                };

                AuthenticationClient authClient = new AuthenticationClient();
                var groupIds = authClient.GetGroupsInUserPermissions(SessionHelper.LoginStatus.EnterpriseID, SessionHelper.LoginStatus.UserID).Select(x => x.GroupID);
                var groupId  = groupIds.FirstOrDefault();

                Dictionary <string, string> uasItemDictionary = new Dictionary <string, string>();
                var uasData = authClient.GetUser(fr.subject.Value);

                var adapId = authClient.GetExistingAdapIdentifier(uasData.UserID, uasData.EnterpriseID);

                // ADAP ID
                if (!String.IsNullOrWhiteSpace(adapId))
                {
                    uasItemDictionary.Add("C1_MemberIdentifier_item", adapId);
                }

                Applications appl = new Applications(formsRepo);

                //Populate from UAS
                //Populate items where Source = UAS in json file
                frElg = appl.CreateFormResultPopulatedFromUAS(SessionHelper.LoginStatus.EnterpriseID, groupId, uasData.UserID, frm.formId, uasItemDictionary);

                int newFrmRsltId = formsRepo.AddFormResult(frElg);
                mLogger.Debug("New Eligibility FormResult created: {0}", newFrmRsltId);
            }
            else
            {
                frElg = frElgList.First <def_FormResults>();
            }


            SessionHelper.SessionForm.formId         = frElg.formId;
            SessionHelper.SessionForm.formResultId   = frElg.formResultId;
            SessionHelper.SessionForm.formIdentifier = formIdent;
            // SessionHelper.LoginStatus.EnterpriseID = ent.EnterpriseID;


            def_Parts prt = formsRepo.GetFormParts(frm)[0];

            SessionHelper.SessionForm.partId = prt.partId;
            Session["part"] = prt.partId.ToString();
            def_Sections sct = formsRepo.GetSectionsInPart(prt)[1];

            Session["section"] = sct.sectionId.ToString();

            return(RedirectToAction("Template", "Results", new { sectionId = sct.sectionId.ToString(), partId = SessionHelper.SessionForm.partId.ToString() }));
        }
Пример #2
0
        public ActionResult CreateAdapApplication()
        {
            def_Forms frm = formsRepo.GetFormByIdentifier("ADAP");
            //string userId = Request["userId"];
            int userId = 0;

            try
            {
                userId = Convert.ToInt32(Request["userId"]);
            }
            catch (Exception excptn)
            {
                Debug.WriteLine("Adap Controller CreateAdapApplication exception:" + excptn.Message);
            }

            int?            intSO   = formsRepo.GetStatusDetailByMasterIdentifier(1, "CANCELLED").sortOrder;
            def_FormResults prevRes = formsRepo.GetEntities <def_FormResults>(x => x.formId == frm.formId &&
                                                                              x.subject == userId &&
                                                                              x.formStatus != intSO)
                                      .OrderByDescending(x => x.dateUpdated)
                                      .FirstOrDefault();

            //def_FormResults prevRes = frm.def_FormResults.Where(f => f.subject == userId && intSO != null && f.formStatus != intSO).OrderByDescending(f => f.dateUpdated).FirstOrDefault();


            if ((prevRes == null) || (prevRes.formStatus == formsRepo.GetStatusDetailByMasterIdentifier(1, "APPROVED").sortOrder))
            {
                AuthenticationClient webclient = new AuthenticationClient();
                UserDisplay          ud        = webclient.GetUserDisplay(userId);

                Dictionary <string, string> ItemsToPopulateFromUAS = new Dictionary <string, string>();
                ItemsToPopulateFromUAS.Add(
                    "ADAP_D1_FirstName_item", String.IsNullOrEmpty(ud.FirstName) ? String.Empty : ud.FirstName);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_D1_LastName_item", String.IsNullOrEmpty(ud.LastName) ? String.Empty : ud.LastName);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_D1_MiddleIntl_item", String.IsNullOrEmpty(ud.MiddleName) ? String.Empty : ud.MiddleName.Substring(0, 1));
                ItemsToPopulateFromUAS.Add(
                    "ADAP_D2_DOB_item", (ud.DOB == null) ? String.Empty : Convert.ToDateTime(ud.DOB).ToString("MM/dd/yyyy"));
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_Address_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].Address1 : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_MayContactYN_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ((ud.Addresses[0].MayContactAddress) ? "1" : "0") : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_City_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].City : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_State_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].State : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_Zip_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].ZIP : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_Address_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].Address1 : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_MayContactYN_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ((ud.Addresses[1].MayContactAddress) ? "1" : "0") : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_City_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].City : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_State_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].State : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_Zip_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].ZIP : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C3_Phone1_Num_item", (ud.Phones != null && ud.Phones.Count() > 0) ? ud.Phones[0].Phone : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C3_Phone1_MayMsgYN_item", (ud.Phones != null && ud.Phones.Count() > 0) ? ((ud.Phones[0].MayContactPhone) ? "1" : "0") : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C3_Phone2_Num_item", (ud.Phones != null && ud.Phones.Count() > 1) ? ud.Phones[1].Phone : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C3_Phone2_MayMsgYN_item", (ud.Phones != null && ud.Phones.Count() > 1) ? ((ud.Phones[1].MayContactPhone) ? "1" : "0") : String.Empty);

                // * * * OT 1-20-16 updated this list based on Docs/ADAP/ADAP_item_list.xslx (revision 80734)
                string[] ItemIdentifiersToPopulateFromPrevApplication = new string[]
                {
                    #region long list of item identifiers
                    "ADAP_D1_LastName_item",
                    "ADAP_D1_FirstName_item",
                    "ADAP_D1_MiddleIntl_item",
                    "ADAP_D1_AltName_item",
                    "ADAP_D2_DOB_item",
                    "ADAP_D3_White_item",
                    "ADAP_D3_Black_item",
                    "ADAP_D3_Asian_item",
                    "ADAP_D3_Native_item",
                    "ADAP_D3_Indian_item",
                    "ADAP_D4_EthnicDrop_item",
                    "ADAP_D4_Mexican_item",
                    "ADAP_D4_Puerto_item",
                    "ADAP_D4_Cuban_item",
                    "ADAP_D4_Other_item",
                    "ADAP_D5_Indian_item",
                    "ADAP_D5_Filipino_item",
                    "ADAP_D5_Korean_item",
                    "ADAP_D5_Other_item",
                    "ADAP_D5_Chinese_item",
                    "ADAP_D5_Japanese_item",
                    "ADAP_D5_Vietnamese_item",
                    "ADAP_D5_NA_item",
                    "ADAP_D6_Native_item",
                    "ADAP_D6_Guam_item",
                    "ADAP_D6_Samoan_item",
                    "ADAP_D6_Other_item",
                    "ADAP_D6_NA_item",
                    "ADAP_D7_LangDrop_item",
                    "ADAP_D7_LangOther_item",
                    "ADAP_D8_CurrGenderDrop_item",
                    "ADAP_D8_BirthGenderDrop_item",
                    "ADAP_D9_Ramsell_item",
                    "ADAP_D10_SSN_item",
                    "ADAP_C1_Address_item",
                    "ADAP_C1_City_item",
                    "ADAP_C1_State_item",
                    "ADAP_C1_Zip_item",
                    "ADAP_C1_County_item",
                    "ADAP_C1_MayContactYN_item",
                    "ADAP_C2_SameAsMailing_item",
                    "ADAP_C2_Address_item",
                    "ADAP_C2_City_item",
                    "ADAP_C2_State_item",
                    "ADAP_C2_Zip_item",
                    "ADAP_C2_County_item",
                    "ADAP_C2_MayContactYN_item",
                    "ADAP_C3_Phone1_Num_item",
                    "ADAP_C3_Phone1_Type_item",
                    "ADAP_C3_Phone1_MayMsgYN_item",
                    "ADAP_C3_Phone2_Num_item",
                    "ADAP_C3_Phone2_Type_item",
                    "ADAP_C3_Phone2_MayMsgYN_item",
                    "ADAP_C4_MayCallYN_item",
                    "ADAP_C4_Name_item",
                    "ADAP_C4_Phone_item",
                    "ADAP_C4_KnowHivYN_item",
                    "ADAP_C5_HasCaseMngrYN_item",
                    "ADAP_C5_Mngr1_Name_item",
                    "ADAP_C5_Mngr1_Clinic_item",
                    "ADAP_C5_Mngr2_Name_item",
                    "ADAP_C5_Mngr2_Clinic_item",
                    "ADAP_C5_CanReferYN_item",
                    "ADAP_M1_Month_item",
                    "ADAP_M1_Year_item",
                    "ADAP_M1_DiagnosisLoc_item",
                    "ADAP_M2_ToldAIDS_item",
                    "ADAP_M3_ToldHepC_item",
                    "ADAP_M4_Clinic_item",
                    "ADAP_I1_Med_Yes_item",
                    "ADAP_I1_Med_Denied_item",
                    "ADAP_I1_Med_No_item",
                    "ADAP_I1_Med_Waiting_item",
                    "ADAP_I1_Med_DontKnow_item",
                    "ADAP_I1_DeniedReason_item",
                    "ADAP_I1_NotAppliedReason_item",
                    "ADAP_I2_AffCareOpt_item",
                    "ADAP_I2_AffCareOther_item",
                    "ADAP_I3_MedicareYN_item",
                    "ADAP_I3_MedNumber_item",
                    "ADAP_I3_PartAYN_item",
                    "ADAP_I3_PartBYN_item",
                    "ADAP_I3_PartADate_item",
                    "ADAP_I3_PartBDate_item",
                    "ADAP_H1_StatusDrop_item",
                    "ADAP_H2_RelnDrop_item",
                    "ADAP_H2_RelnOther_item",
                    "ADAP_H3_FileTaxYN_item",
                    "ADAP_H3_TaxStatusOpt_item",
                    "ADAP_H3_TaxDependants_item",
                    "ADAP_H3_TaxNotFileOpt_item",
                    "ADAP_H3_TaxNotFileOther_item",
                    "ADAP_H3_Relatives_item",
                    "ADAP_H4_ChildrenIn_item",
                    "ADAP_H4_ChildrenOut_item",
                    "ADAP_F1_EmployOpt_item",
                    "ADAP_F1_EmployOther_item",
                    "ADAP_F1_EmployerInsOpt_item",
                    "ADAP_F1_EmployNotEnrolled_item",
                    "ADAP_F2_EmployLast90YN_item",
                    "ADAP_F3_A_Recipient_item",
                    "ADAP_F3_A_IncomeTypeDrop_item",
                    "ADAP_F3_A_Employer_item",
                    "ADAP_F3_A_EmployStart_item",
                    "ADAP_F3_A_TempYN_item",
                    "ADAP_F3_A_IncomeTypeOther_item",
                    "ADAP_F3_A_IncomeAmt_item",
                    "ADAP_F3_A_EmployerForm_item",
                    "ADAP_F3_B_Recipient_item",
                    "ADAP_F3_B_IncomeTypeDrop_item",
                    "ADAP_F3_B_Employer_item",
                    "ADAP_F3_B_EmployStart_item",
                    "ADAP_F3_B_TempYN_item",
                    "ADAP_F3_B_IncomeTypeOther_item",
                    "ADAP_F3_B_IncomeAmt_item",
                    "ADAP_F3_B_EmployerForm_item",
                    "ADAP_F3_C_Recipient_item",
                    "ADAP_F3_C_IncomeTypeDrop_item",
                    "ADAP_F3_C_Employer_item",
                    "ADAP_F3_C_EmployStart_item",
                    "ADAP_F3_C_TempYN_item",
                    "ADAP_F3_C_IncomeTypeOther_item",
                    "ADAP_F3_C_IncomeAmt_item",
                    "ADAP_F3_C_EmployerForm_item",
                    "ADAP_F3_D_Recipient_item",
                    "ADAP_F3_D_IncomeTypeDrop_item",
                    "ADAP_F3_D_Employer_item",
                    "ADAP_F3_D_EmployStart_item",
                    "ADAP_F3_D_TempYN_item",
                    "ADAP_F3_D_IncomeTypeOther_item",
                    "ADAP_F3_D_IncomeAmt_item",
                    "ADAP_F3_D_EmployerForm_item",
                    "ADAP_cert_NoSharing_item",
                    "ADAP_cert_Reminders_item"
                    #endregion
                };

                Applications    appl   = new Applications(formsRepo);
                def_FormResults frmRes = appl.CreateFormResultPopulatedFromUAS(SessionHelper.LoginStatus.EnterpriseID, SessionHelper.LoginStatus.GroupID, userId, frm.formId, ItemsToPopulateFromUAS);
                appl.PopulateItemsFromPrevApplication(frmRes, ItemIdentifiersToPopulateFromPrevApplication);

                frmRes.statusChangeDate = DateTime.Now;

                // Save the FormResult, ItemResults, and ResponseVariables
                int newFormResultId = 0;
                try
                {
                    newFormResultId = formsRepo.AddFormResult(frmRes);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("AddFormResult exception:" + ex.Message);
                }

                Debug.WriteLine("AddFormResult newFormResultId:" + newFormResultId.ToString());

                // query the ramsell system and update the formResult responses based on Ramsell response
                def_ResponseVariables rvMemberId = formsRepo.GetResponseVariablesByFormResultIdentifier(newFormResultId, "ADAP_D9_Ramsell");
                if (rvMemberId != null && !String.IsNullOrWhiteSpace(rvMemberId.rspValue))
                {
                    string memberId = rvMemberId.rspValue;
                    string usrId    = UAS.Business.UAS_Business_Functions.GetEntAppConfigAdap("USR");
                    string password = UAS.Business.UAS_Business_Functions.GetEntAppConfigAdap("PWD");
                    Debug.WriteLine("Ramsell UseriD / Password: "******" / " + password);

                    string token = Ramsell.GetOauthToken(usrId, password);
                    new RamsellImport(formsRepo, frmRes.formResultId).ImportApplication(token, memberId);
                }
                //AJBoggs.Adap.Services.Api.Ramsell.PopulateItemsFromRamsellImport(formsRepo, frmRes);

                if (SessionHelper.SessionForm == null)
                {
                    SessionHelper.SessionForm = new SessionForm();
                }

                SessionForm sf = SessionHelper.SessionForm;
                sf.formId         = frm.formId;
                sf.formIdentifier = frm.identifier;
                sf.sectionId      = formsRepo.GetSectionByIdentifier("ADAP_demographic").sectionId;
                sf.partId         = formsRepo.GetPartByFormAndIdentifier(frm, "ADAP").partId;

                // *** RRB - should be deprecated - use SessionForm
                // *** BR - line 359 of the ResultsController calls this session variable, so it must be set to prevent an exception.
                //  Other parts of the application may still use that variable, so changing it in the ResultsController may break something else.
                Session["part"] = sf.partId;
                // Should have the partId also - may not be required.

                sf.formResultId = newFormResultId;

                return(RedirectToAction("Template", "Results", new { sectionId = sf.sectionId.ToString() }));
            }
            else
            {
                return(RedirectToAction("AdapPortal", "COADAP", new { userId = userId, error = "Not Approved" }));
            }
        }
Пример #3
0
        public ActionResult CreateAdapApplication()
        {
            def_Forms frm = formsRepo.GetFormByIdentifier("LA-ADAP");
            //string userId = Request["userId"];
            int userId = 0;

            try
            {
                userId = Convert.ToInt32(Request["userId"]);
            }
            catch (Exception excptn)
            {
                Debug.WriteLine("Adap Controller CreateAdapApplication exception:" + excptn.Message);
            }

            bool isCaseMgr = UAS.Business.UAS_Business_Functions.hasPermission(2, "RptsExpts"); // Case Manager permission

            int?intSO = formsRepo.GetStatusDetailByMasterIdentifier(1, "CANCELLED").sortOrder;

            def_FormResults prevRes = formsRepo.GetEntities <def_FormResults>(f => f.subject == userId && intSO != null && f.formStatus != intSO).OrderByDescending(f => f.dateUpdated).FirstOrDefault();

            //def_FormResults prevRes = frm.def_FormResults.Where(f => f.subject == userId && intSO != null && f.formStatus != intSO).OrderByDescending(f => f.dateUpdated).FirstOrDefault();

            if ((prevRes == null) || (prevRes.formStatus == formsRepo.GetStatusDetailByMasterIdentifier(1, "APPROVED").sortOrder))
            {
                AuthenticationClient webclient = new AuthenticationClient();
                UserDisplay          ud        = webclient.GetUserDisplay(userId);

                //Dictionary<string, string> ItemsToPopulateFromUAS = new Dictionary<string, string>();
                //ItemsToPopulateFromUAS.Add(
                //    "ADAP_D1_FirstName_item", String.IsNullOrEmpty(ud.FirstName) ? String.Empty : ud.FirstName);
                //ItemsToPopulateFromUAS.Add(
                //    "ADAP_D1_LastName_item", String.IsNullOrEmpty(ud.LastName) ? String.Empty : ud.LastName);

                //ItemsToPopulateFromUAS.Add(
                //    "ADAP_D2_DOB_item", ud.DOB.HasValue == false ? String.Empty : ud.DOB.Value.ToShortDateString());

                //if (ud.Addresses.Any())
                //{
                //    ItemsToPopulateFromUAS.Add(
                //                        "ADAP_C1_Address_item", String.IsNullOrEmpty(ud.Addresses[0].Address1) ? String.Empty
                //                        : ud.Addresses[0].Address1);
                //    ItemsToPopulateFromUAS.Add(
                //                       "LA_ADAP_AddrAptNum_item", String.IsNullOrEmpty(ud.Addresses[0].Address2) ? String.Empty
                //                       : ud.Addresses[0].Address2);
                //    ItemsToPopulateFromUAS.Add(
                //                       "ADAP_C1_City_item", String.IsNullOrEmpty(ud.Addresses[0].City) ? String.Empty
                //                       : ud.Addresses[0].City);
                //    ItemsToPopulateFromUAS.Add(
                //                       "ADAP_C1_State_item", String.IsNullOrEmpty(ud.Addresses[0].State) ? String.Empty
                //                       : ud.Addresses[0].State);
                //    ItemsToPopulateFromUAS.Add(
                //                       "ADAP_C1_Zip_item", String.IsNullOrEmpty(ud.Addresses[0].ZIP) ? String.Empty
                //                       : ud.Addresses[0].ZIP);
                //}

                //if (ud.Emails.Any())
                //{
                //    ItemsToPopulateFromUAS.Add(
                //                        "LA_ADAP_Email_Adr", String.IsNullOrEmpty(ud.Emails[0].Email) ? String.Empty
                //                        : ud.Emails[0].Email);
                //}
                Dictionary <string, string> ItemsToPopulateFromUAS = new Dictionary <string, string>();
                ItemsToPopulateFromUAS.Add(
                    "ADAP_D1_FirstName_item", String.IsNullOrEmpty(ud.FirstName) ? String.Empty : ud.FirstName);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_D1_LastName_item", String.IsNullOrEmpty(ud.LastName) ? String.Empty : ud.LastName);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_D1_MiddleIntl_item", String.IsNullOrEmpty(ud.MiddleName) ? String.Empty : ud.MiddleName.Substring(0, 1));
                ItemsToPopulateFromUAS.Add(
                    "ADAP_D2_DOB_item", (ud.DOB == null) ? String.Empty : Convert.ToDateTime(ud.DOB).ToString("MM/dd/yyyy"));
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_Address_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].Address1 : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_MayContactYN_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ((ud.Addresses[0].MayContactAddress) ? "1" : "0") : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_City_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].City : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_State_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].State : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C1_Zip_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].ZIP : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_Address_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].Address1 : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_MayContactYN_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ((ud.Addresses[1].MayContactAddress) ? "1" : "0") : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_City_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].City : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_State_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].State : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C2_Zip_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].ZIP : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C3_Phone1_Num_item", (ud.Phones != null && ud.Phones.Count() > 0) ? ud.Phones[0].Phone : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C3_Phone1_MayMsgYN_item", (ud.Phones != null && ud.Phones.Count() > 0) ? ((ud.Phones[0].MayContactPhone) ? "1" : "0") : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C3_Phone2_Num_item", (ud.Phones != null && ud.Phones.Count() > 1) ? ud.Phones[1].Phone : String.Empty);
                ItemsToPopulateFromUAS.Add(
                    "ADAP_C3_Phone2_MayMsgYN_item", (ud.Phones != null && ud.Phones.Count() > 1) ? ((ud.Phones[1].MayContactPhone) ? "1" : "0") : String.Empty);



                Applications    appl   = new Applications(formsRepo);
                def_FormResults frmRes = appl.CreateFormResultPopulatedFromUAS(SessionHelper.LoginStatus.EnterpriseID, SessionHelper.LoginStatus.GroupID, userId, frm.formId, ItemsToPopulateFromUAS);

                if (isCaseMgr)
                {
                    frmRes.interviewer = SessionHelper.LoginStatus.UserID;
                }
                else if (ud.ManagerID != null)
                {
                    frmRes.interviewer = ud.ManagerID;
                }

                frmRes.statusChangeDate = DateTime.Now;

                // Save the FormResult, ItemResults, and ResponseVariables
                int newFormResultId = 0;
                try
                {
                    newFormResultId = formsRepo.AddFormResult(frmRes);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("AddFormResult exception:" + ex.Message);
                }

                Debug.WriteLine("AddFormResult newFormResultId:" + newFormResultId.ToString());

                if (SessionHelper.SessionForm == null)
                {
                    SessionHelper.SessionForm = new SessionForm();
                }

                SessionForm sf = SessionHelper.SessionForm;
                sf.formId         = frm.formId;
                sf.formIdentifier = frm.identifier;
                sf.sectionId      = formsRepo.GetSectionByIdentifier("LA_ADAP_PreScreen").sectionId;
                sf.partId         = formsRepo.GetPartByFormAndIdentifier(frm, "LA-ADAP").partId;

                // *** RRB - should be deprecated - use SessionForm
                // *** BR - line 359 of the ResultsController calls this session variable, so it must be set to prevent an exception.
                //  Other parts of the application may still use that variable, so changing it in the ResultsController may break something else.
                Session["part"] = sf.partId;
                // Should have the partId also - may not be required.

                sf.formResultId = newFormResultId;

                return(RedirectToAction("Template", "Results", new { sectionId = sf.sectionId.ToString() }));
            }
            else
            {
                if (isCaseMgr)
                {
                    userId = SessionHelper.LoginStatus.UserID;
                }
                return(RedirectToAction("AdapPortal", "LAADAP", new { userId = userId, error = "Not Approved" }));
            }
        }