Ejemplo n.º 1
0
    private void UploadFile(string fullPath)
    {
        chsi.dat.payFileImports fi = new chsi.dat.payFileImports();

        if (this.ddFileType.SelectedValue == "IEHP")
        {
            chsi.dom.pay.ImportIEHP i = new chsi.dom.pay.ImportIEHP();
            i.ImportFile(fullPath);
        }

        if (this.ddFileType.SelectedValue == "LIHP")
        {
            chsi.dom.pay.ImportLIHP i = new chsi.dom.pay.ImportLIHP();
            i.ImportFile(fullPath);
        }

        if (this.ddFileType.SelectedValue == "CHG")
        {
            chsi.dom.pay.ImportCHG i = new chsi.dom.pay.ImportCHG();
            i.ImportFile(fullPath);
        }

        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();
        chsi.dat.payFileImports fileImp = db.payFileImports.OrderByDescending(a => a.payFileImport).First();

        decimal ratio = decimal.Round((decimal)fileImp.MembersWithVisits / (decimal)fileImp.MemberCount, 2);
        int iRatio = (int)(ratio *100);
        string sRatio = iRatio.ToString() + "%";

        lblMessage.Text = string.Format("Members Added: <b>{0}</b><br/>Members Removed: <b>{1}</b><br/>Total Member Count: <b>{2}</b><br/>Members With Visits: <b>{3}</b><br/>Member/Visit Ratio: <b>{4}</b>",
            fileImp.NewMembers, fileImp.DeletedMembers, fileImp.MemberCount, fileImp.MembersWithVisits, sRatio);
    }
    protected void btnSearchDependent_Click(object sender, EventArgs e)
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();
        string firstName = txtFirstName.Text.Trim();
        string lastName = txtLastName.Text.Trim();

        List<acaApplicants> dependents;

        if (!String.IsNullOrEmpty(firstName) && !String.IsNullOrEmpty(lastName))
        {
            dependents = db.acaApplicants.Where(col => col.PrimaryApplicantId != null
                                                                        && col.FirstName.Contains(txtFirstName.Text.Trim())
                                                                        && col.LastName.Contains(txtLastName.Text.Trim())).ToList();
        }
        else if (!String.IsNullOrEmpty(firstName) && String.IsNullOrEmpty(lastName))
        {
            dependents = db.acaApplicants.Where(col => col.PrimaryApplicantId != null
                                                                        && col.FirstName.Contains(txtFirstName.Text.Trim())).ToList();
        }
        else if (String.IsNullOrEmpty(firstName) && !String.IsNullOrEmpty(lastName))
        {
            dependents = db.acaApplicants.Where(col => col.PrimaryApplicantId != null
                                                                        && col.LastName.Contains(txtLastName.Text.Trim())).ToList();
        }
        else
        {
            dependents = db.acaApplicants.Where(col => col.PrimaryApplicantId != null).ToList();
        }

        rptItems.DataSource = dependents;
        rptItems.DataBind();
    }
Ejemplo n.º 3
0
 public ImportCHG()
 {
     db = new chsi.dat.CHSIEntities();
     providers = new Dictionary<string, string>();
     currentMembers = new List<int>();
     _payer = Payers.CHG;
 }
Ejemplo n.º 4
0
    public bool PatientContactSave(int patientId, string employee, string whatHappened, string notes, bool isDND, bool isIneligible, bool isCallback, bool isApptMade, DateTime? callBackDateTime, DateTime? apptDateTime)
    {
        try
        {

            chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();

            string details = "";

            chsi.dat.payNewPatientContacts c = new chsi.dat.payNewPatientContacts();
            c.payNewPatientId = patientId;
            c.ContactDate = DateTime.Now;
            c.EmployeeName = employee;

            switch (whatHappened.ToLower().Trim())
            {
                case "phonenoanswer": c.isPhoneNoAnswer = true; break;
                case "phoneanswer": c.isPhoneAnswered = true; break;
                case "phoneleftmessage": c.isPhoneLeftMessage = true; break;
                case "phonebusy": c.isPhoneBusy = true; break;
                case "phonewrongnumber": c.isPhoneWrongNumber = true; break;
                case "phonedisconnected": c.isPhoneDisconnected = true; break;
                case "postcardsent": c.isPostCardSent = true; break;

            }

            c.isDoNotDisturbRequested = isDND;
            c.isIneligible = isIneligible;
            c.isRequestCallBack = isCallback;
            c.isApptMade = isApptMade;

            if (isCallback)
            {
                c.CallBack = callBackDateTime;
                DateTime dt = (DateTime)callBackDateTime;
                details = string.Format("Callback requested for {0} {1}{2}", dt.ToShortDateString(), (dt.Hour > 0 ? dt.ToShortTimeString() : ""), Environment.NewLine);

            }

            if (isApptMade)
            {
                c.Appt = apptDateTime;
                DateTime dt = (DateTime)apptDateTime;
                details = string.Format("Appointment made for {0} {1}{2}", dt.ToShortDateString(), (dt.Hour > 0 ? dt.ToShortTimeString() : ""), Environment.NewLine);
            }

            if (isDND)
            {
                details += "Patient requests Do Not Disturb" + Environment.NewLine;
            }

            if (isIneligible)
            {
                details += "Patient is inelibible" + Environment.NewLine;
            }

            details += notes;
            c.Details = details;

            db.AddTopayNewPatientContacts(c);
            db.SaveChanges();

            return true;
        }
        catch (Exception e)
        {

        }

        return false;
    }
Ejemplo n.º 5
0
    public int PatientRemove(int patientId)
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();
        chsi.dat.payNewPatients patient = db.payNewPatients.Where(a => a.payNewPatientId == patientId).FirstOrDefault();

        if (patient == null)
            return 0;

        patient.Active = false;
        db.SaveChanges();
        return patientId;
    }
Ejemplo n.º 6
0
    public string PatientLoad(int patientId)
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();

        var patient = (from p in db.payNewPatients
                       join payers in db.payPatientPayers on p.payNewPatientId equals payers.payNewPatientId
                       join busLines in db.payBusinessLines on p.payBusinessLineId equals busLines.payBusinessLineId
                       where p.payNewPatientId == patientId
                       select new {p.DOB, payers.HMOId, p.Address, p.City, p.State, p.Zip, p.Phone, p.NG_provider_id, BusinessLine =busLines.Name, Payer = payers.payPayers.Name }).FirstOrDefault();

        chsi.dom.hlp.EFSerializer efs = new chsi.dom.hlp.EFSerializer();
        return efs.EFSerialize(patient);
    }
Ejemplo n.º 7
0
    public string PatientContactsLoad(int patientId)
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();

         List<chsi.dat.payNewPatientContacts> contacts =
                (from c in db.payNewPatientContacts
                where c.payNewPatientId == patientId
                orderby c.ContactID
                select c).ToList();

         chsi.dom.hlp.EFSerializer efs = new chsi.dom.hlp.EFSerializer();
         return efs.EFSerialize(contacts);
    }
Ejemplo n.º 8
0
    private void LoadData()
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();
        chsi.dat.acaApplicants app = db.acaApplicants.FirstOrDefault(a => a.ApplicantId == _appId);
        int depCount = db.acaApplicants.Where(a => a.PrimaryApplicantId == _appId).Count();

        litPrimaryApplicantName.Text = app.FirstName + " " + app.LastName + "<BR>Total Dependents: " + depCount;
        List<chsi.dat.acaAssists> assists = app.acaAssists.ToList();

        //foreach (chsi.dat.acaAssists ass in assists)
        //    Response.Write(ass.Notes + "<BR>");

        DataTable dt;

        //if (!String.IsNullOrEmpty(Request.QueryString["appId"]))
        //{
        //    string appId = Request.QueryString["appId"];

        dt = Data.GetAssistsByPrimaryApplicantID(_appId.ToString());

        //    if (dt.Rows.Count > 0)
        //        litPrimaryApplicantName.Text = "Primary Applicant:  " + dt.Rows[0]["FirstName"].ToString() + " " + dt.Rows[0]["LastName"].ToString();
        //}
        //else
        //{
        //    dt = Data.GetAssists();
        //    btnNewAssist.Visible = false;
        //}

        this.rptItems.Visible = false;

        if (dt.Rows.Count == 0)
        {
            litEmpty.Text = "No Assists at This Time.";
            litEmpty.Visible = true;
            return;
        }

        //string filter = "1 = 1";

        ////apply filters
        //if (ddPSR.SelectedIndex > 0)
        //    filter += string.Format(" AND RepresentativeId = '{0}'", ddPSR.SelectedValue);

        //if (ddSite.SelectedIndex > 0)
        //    filter += string.Format(" AND SiteId = '{0}'", ddSite.SelectedValue);

        //bind repeater
        //dt.DefaultView.RowFilter = filter;
        this.rptItems.DataSource = dt;
        this.rptItems.DataBind();
        this.rptItems.Visible = true;
    }
Ejemplo n.º 9
0
    protected void btnSaveAssist_Click(object sender, EventArgs e)
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();
        int _assistId = 0;
        int _appId = 0;

        if (!String.IsNullOrEmpty(Request.QueryString["assistId"]))
        {
            string assistId = Request.QueryString["assistId"];
            int.TryParse(assistId, out _assistId);
        }

        if (!String.IsNullOrEmpty(Request.QueryString["appId"]))
        {
            string appId = Request.QueryString["appId"];
            int.TryParse(appId, out _appId);
        }

        if (_assistId == 0)
        {
            chsi.dat.acaAssists newAssist = new acaAssists();

            newAssist.Notes = txtNotes.Text;
            newAssist.AssistDate = Convert.ToDateTime(txtDateOfEncounter.Text);
            newAssist.PrimaryApplicantId = _appId;
            newAssist.RegionId = Convert.ToInt32(ddlRegion.SelectedValue);
            newAssist.SiteId = Convert.ToInt32(ddlSite.SelectedValue);
            newAssist.AssistTypeId = Convert.ToInt32(ddlAssistType.SelectedValue);
            newAssist.RepresentativeId = Convert.ToInt32(ddlPSR.SelectedValue);

            if (ddlAssistType.SelectedValue == "7")
                newAssist.isSubmission = true;
            else
                newAssist.isSubmission = false;

            if (ddlAssistType.SelectedValue == "9")
                newAssist.isEnrolled = true;
            else
                newAssist.isEnrolled = false;

            db.acaAssists.AddObject(newAssist);
            db.SaveChanges();

        }
        else
        {
            acaAssists assist = (from a in db.acaAssists
                                 where a.AssistId == _assistId
                                 select a).FirstOrDefault();

            assist.Notes = txtNotes.Text;
            assist.AssistDate = Convert.ToDateTime(txtDateOfEncounter.Text);
            assist.RegionId = Convert.ToInt32(ddlRegion.SelectedValue);
            assist.SiteId = Convert.ToInt32(ddlSite.SelectedValue);
            assist.AssistTypeId = Convert.ToInt32(ddlAssistType.SelectedValue);
            assist.RepresentativeId = Convert.ToInt32(ddlPSR.SelectedValue);

            if (ddlAssistType.SelectedValue == "7")
                assist.isSubmission = true;
            else
                assist.isSubmission = false;

            if (ddlAssistType.SelectedValue == "9")
                assist.isEnrolled = true;
            else
                assist.isEnrolled = false;

            db.SaveChanges();

        }

        foreach (RepeaterItem item in rptrFamily.Items)
        {
            HiddenField applicantId = (HiddenField)item.FindControl("hidApplicantId");
            CheckBox submission = (CheckBox)item.FindControl("cbxSubmission");
            CheckBox enrolled = (CheckBox)item.FindControl("cbxEnrolled");
            CheckBox providerSelected = (CheckBox)item.FindControl("cbxProviderSelected");
            DropDownList payer = (DropDownList)item.FindControl("ddlPayers");
            DropDownList types = (DropDownList)item.FindControl("ddlTypes");
            DropDownList tiers = (DropDownList)item.FindControl("ddlTiers");
            DropDownList subTiers = (DropDownList)item.FindControl("ddlSubTiers");

            int appId = Convert.ToInt32(applicantId.Value);

            //Save Applicant
            acaApplicants app = (from a in db.acaApplicants
                                 where a.ApplicantId == appId
                                 select a).FirstOrDefault();

            app.IsEnrolled = enrolled.Checked;
            app.IsSubmission = submission.Checked;
            app.SelectedCHSIProvider = providerSelected.Checked;

            db.SaveChanges();

            //Save health plan
            acaHealthPlans hp = (from h in db.acaHealthPlans
                                 where h.ApplicantId == appId
                                 select h).FirstOrDefault();

            if (payer.SelectedIndex > 0)
                hp.PayerId = Convert.ToInt32(payer.SelectedValue);
            else
                hp.PayerId = null;

            if (types.SelectedIndex > 0)
                hp.PlanTypeId = Convert.ToInt32(types.SelectedValue);
            else
                hp.PlanTypeId = null;

            if (tiers.SelectedIndex > 0)
                hp.PlanTierId = Convert.ToInt32(tiers.SelectedValue);
            else
                hp.PlanTierId = null;

            if (subTiers.SelectedIndex > 0)
                hp.PlanSubTierId = Convert.ToInt32(subTiers.SelectedValue);
            else
                hp.PlanSubTierId = null;

            db.SaveChanges();

        }

        //total assists for each assist record
        int totalAssistCount = db.acaAssists.Where(a => a.PrimaryApplicantId == _appId).Count();
        int totalEnrolled = db.acaAssists.Where(a => a.AssistTypeId == 9 && a.PrimaryApplicantId == _appId).Count();
        int totalSubmitted = db.acaAssists.Where(a => a.AssistTypeId == 7 && a.PrimaryApplicantId == _appId).Count();
        int familyCount = db.acaApplicants.Where(a => a.PrimaryApplicantId == _appId || a.ApplicantId == _appId).Count();

        var some = db.acaAssists.Where(a => a.PrimaryApplicantId == _appId).ToList();

        some.ForEach(a => a.NumberAssisted = (totalAssistCount * familyCount));
        some.ForEach(a => a.NumberEnrolled = (totalEnrolled));
        some.ForEach(a => a.NumberSubmitted = (totalSubmitted));

        db.SaveChanges();

        Response.Redirect(string.Format("/aca/assists?appId={0}", _appId));
    }
Ejemplo n.º 10
0
    protected void rptrFamily_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DropDownList players = ((DropDownList)e.Item.FindControl("ddlPayers"));
            DropDownList types = ((DropDownList)e.Item.FindControl("ddlTypes"));
            DropDownList tiers = ((DropDownList)e.Item.FindControl("ddlTiers"));
            DropDownList subTiers = ((DropDownList)e.Item.FindControl("ddlSubTiers"));
            HiddenField applicantId = ((HiddenField)e.Item.FindControl("hidApplicantId"));

            int appId = Convert.ToInt32(applicantId.Value);

            acaHealthPlans plan = db.acaHealthPlans.Where(h => h.ApplicantId == appId).FirstOrDefault();

            if (plan != null)
            {
                players.DataSource = _payers;
                players.DataTextField = "Payer";
                players.DataValueField = "PayerId";
                players.DataBind();
                players.Items.Insert(0, new ListItem("Select Payer", "0"));
                players.SelectedValue = plan.PayerId.ToString();

                types.DataSource = _types;
                types.DataTextField = "PlanType";
                types.DataValueField = "PlanTypeId";
                types.DataBind();
                types.Items.Insert(0, new ListItem("Select Type", "0"));
                types.SelectedValue = plan.PlanTypeId.ToString();

                tiers.DataSource = _tiers;
                tiers.DataTextField = "tier";
                tiers.DataValueField = "PlanTierId";
                tiers.DataBind();
                tiers.Items.Insert(0, new ListItem("Select Tier", "0"));
                tiers.SelectedValue = plan.PlanTierId.ToString();

                subTiers.DataSource = _sub;
                subTiers.DataTextField = "SubTier";
                subTiers.DataValueField = "PlanSubTierId";
                subTiers.DataBind();
                subTiers.Items.Insert(0, new ListItem("Select Sub Tier", "0"));
                subTiers.SelectedValue = plan.PlanSubTierId.ToString();
            }

        }
    }
Ejemplo n.º 11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();
        int _assistId = 0;
        int _appId = 0;

        if (!String.IsNullOrEmpty(Request.QueryString["assistId"]))
        {
            string assistId = Request.QueryString["assistId"];
            int.TryParse(assistId, out _assistId);
        }

        if (!String.IsNullOrEmpty(Request.QueryString["appId"]))
        {
            string appId = Request.QueryString["appId"];
            int.TryParse(appId, out _appId);
        }

            if (!IsPostBack)
            {
                DataSet dsDropdownData = Data.GetDropdownData_Applicants();

                AddDropDownItems(dsDropdownData.Tables[0], ddlPSR, "FullName", "RepresentativeId");
                AddDropDownItems(dsDropdownData.Tables[1], ddlRegion, "Region", "RegionId");
                AddDropDownItems(dsDropdownData.Tables[2], ddlSite, "SiteName", "SiteId");
                AddDropDownItems(dsDropdownData.Tables[4], ddlAssistType, "AssistType", "AssistTypeId");

                _payers = db.acaPayers.Where(p => p.IsActive == true).OrderBy(s => s.SortOrder).ToList();
                _types = db.acaPlanTypes.Where(p => p.IsActive == true).OrderBy(s => s.SortOrder).ToList();
                _tiers = db.acaPlanTiers.Where(p => p.IsActive == true).OrderBy(s => s.SortOrder).ToList();
                _sub = db.acaPlanSubTiers.Where(p => p.IsActive == true).OrderBy(s => s.SortOrder).ToList();

                List<acaApplicants> apps = db.acaApplicants.Where(a => a.PrimaryApplicantId == _appId
                                                            || a.ApplicantId == _appId).ToList();

                rptrFamily.DataSource = apps;
                rptrFamily.DataBind();

                if (_assistId > 0)
                {
                    acaAssists assist = (from a in db.acaAssists
                                         where a.AssistId == _assistId
                                         select a).FirstOrDefault();

                    this.txtDateOfEncounter.Text = String.Format("{0:M/dd/yyyy}", assist.AssistDate);
                    this.txtNotes.Text = assist.Notes;
                    this.ddlPSR.SelectedValue = assist.RepresentativeId.ToString();
                    this.ddlAssistType.SelectedValue = assist.AssistTypeId.ToString();
                    this.ddlRegion.SelectedValue = assist.RegionId.ToString();
                    this.ddlSite.SelectedValue = assist.SiteId.ToString();
                }
            }
    }
Ejemplo n.º 12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int _appId = 0;

        if (!String.IsNullOrEmpty(Request.QueryString["appId"]))
        {
            string appId = Request.QueryString["appId"];
            int.TryParse(appId, out _appId);
        }

        if (!IsPostBack)
        {
            DataSet dsDropdownData = Data.GetDropdownData_Applicants();
            AddDropDownItems(dsDropdownData.Tables[1], ddRegion, "Region", "RegionId");

            if (_appId > 0)
            {
                chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();

                acaApplicants app = (from a in db.acaApplicants
                                     where a.ApplicantId == _appId
                                     select a).FirstOrDefault();

                this.txtFirstName.Text = app.FirstName;
                this.txtLastName.Text = app.LastName;
               // this.txtEmail.Text = app.Email;
               // this.txtAddress.Text = app.Address;
                this.txtDOB.Text = String.Format("{0:M/dd/yyyy}", app.DateOfBirth);
                //this.txtCity.Text = app.City;
                this.txtPhone.Text = app.Phone;
                this.ddRegion.SelectedValue = app.RegionId.ToString();

                if (app.isActive)
                    this.chkActive.Checked = true;
                else
                    this.chkActive.Checked = false;

                //this.txtZip.Text = app.Zip;
                this.txtNotes.Text = app.Notes;
            }
        }
    }
Ejemplo n.º 13
0
    protected void btnAddApplicant_Click(object sender, EventArgs e)
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();
        int _appId = 0;

        if (!String.IsNullOrEmpty(Request.QueryString["appId"]))
        {
            string appId = Request.QueryString["appId"];
            int.TryParse(appId, out _appId);
        }

        if (_appId == 0)
        {
            chsi.dat.acaApplicants app = new acaApplicants();

            app.FirstName = this.txtFirstName.Text.Trim();
            app.LastName = this.txtLastName.Text.Trim();
            //app.Email = this.txtEmail.Text.Trim();
            //app.Address = this.txtAddress.Text.Trim();
            //app.City = this.txtCity.Text.Trim();
            app.isPrimary = true;
            app.DateOfBirth = Convert.ToDateTime(this.txtDOB.Text);
            app.Phone = this.txtPhone.Text.Trim();
            app.RegionId = int.Parse(this.ddRegion.SelectedValue);
            app.isActive = this.chkActive.Checked;
            //app.Zip = this.txtZip.Text.Trim();
            app.Notes = this.txtNotes.Text.Trim();

            db.acaApplicants.AddObject(app);
            db.SaveChanges();

            int appId = app.ApplicantId;

            acaHealthPlans hp = new acaHealthPlans();
            hp.ApplicantId = appId;
            db.acaHealthPlans.AddObject(hp);
            db.SaveChanges();

            Response.Redirect(string.Format("/aca/assists?appId={0}", appId));
        }
        else
        {
            acaApplicants app = (from a in db.acaApplicants
                                       where a.ApplicantId == _appId
                                       select a).FirstOrDefault();

            app.FirstName = this.txtFirstName.Text.Trim();
            app.LastName = this.txtLastName.Text.Trim();
            //app.Email = this.txtEmail.Text.Trim();
            //app.Address = this.txtAddress.Text.Trim();
            //app.City = this.txtCity.Text.Trim();
            app.DateOfBirth = Convert.ToDateTime(this.txtDOB.Text);
            app.isPrimary = true;
            app.Phone = this.txtPhone.Text.Trim();
            app.RegionId = int.Parse(this.ddRegion.SelectedValue);
            app.isActive = this.chkActive.Checked;
            //app.Zip = this.txtZip.Text.Trim();
            app.Notes = this.txtNotes.Text.Trim();

            db.SaveChanges();
            Response.Redirect(string.Format("/aca/assists?appId={0}", _appId));

        }
    }
Ejemplo n.º 14
0
    public int SaveApplicant(string FirstName, string LastName, string DateOfBirth, string Region
                            , string Active, string Address, string City, string Zip
                            , string Phone, string Email, string Notes)
    {
        chsi.dat.acaApplicants applicant = new chsi.dat.acaApplicants();

        applicant.FirstName = FirstName;
        applicant.LastName = LastName;
        applicant.isActive = (Active == "true")? true : false;
        applicant.Address = Address;
        applicant.City = City;
        applicant.Zip = Zip;
        applicant.Phone = Phone;
        applicant.Email = Email;
        applicant.DateOfBirth = Convert.ToDateTime(DateOfBirth);
        applicant.RegionId = Convert.ToInt32(Region);
        applicant.Notes = Notes;

        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();
        db.acaApplicants.AddObject(applicant);
        db.SaveChanges();

        return applicant.ApplicantId;
    }
    protected void btnSaveAssist_Click(object sender, EventArgs e)
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();
        int _assistId = 0;
        int _appId = 0;

        _submissionId = int.Parse(ddlAssistType.Items.FindByText("Submitting application").Value);
        _enrolledId = int.Parse(ddlAssistType.Items.FindByText("Enrollment Confirmation, payment submitted").Value);

        if (!String.IsNullOrEmpty(Request.QueryString["assistId"]))
        {
            string assistId = Request.QueryString["assistId"];
            int.TryParse(assistId, out _assistId);
        }

        if (!String.IsNullOrEmpty(Request.QueryString["appId"]))
        {
            string appId = Request.QueryString["appId"];
            int.TryParse(appId, out _appId);
        }

        chsi.dat.acaAssists assist = new acaAssists();

        if (_assistId > 0)
        {
            assist = (from a in db.acaAssists
                      where a.AssistId == _assistId
                      select a).FirstOrDefault();
        }

        assist.Notes = txtNotes.Text;
        assist.AssistDate = Convert.ToDateTime(txtDateOfEncounter.Text);
        assist.PrimaryApplicantId = _appId;
        assist.RegionId = Convert.ToInt32(ddlRegion.SelectedValue);
        assist.SiteId = Convert.ToInt32(ddlSite.SelectedValue);
        assist.AssistTypeId = Convert.ToInt32(ddlAssistType.SelectedValue);
        assist.RepresentativeId = Convert.ToInt32(ddlPSR.SelectedValue);

        assist.isSubmission = (int.Parse(ddlAssistType.SelectedValue) == _submissionId);
        assist.isEnrolled = (int.Parse(ddlAssistType.SelectedValue) == _enrolledId);

        int familyCount = db.acaApplicants.Where(a => a.PrimaryApplicantId == _appId || a.ApplicantId == _appId).Count();
        assist.NumberAssisted = familyCount;

        if (assist.isSubmission )
        {
            //get previous totals
            int prevSubmitted = 0;
            int.TryParse(db.acaAssists.Where(a => a.AssistTypeId == _submissionId && a.PrimaryApplicantId == _appId).ToList().Select(a => a.NumberAssisted).Sum().ToString(), out prevSubmitted);
            int totalSubmitted = GetCount("cbxSubmission");
            assist.NumberAssisted = Math.Abs(totalSubmitted - prevSubmitted);
        }

        if (assist.isEnrolled)
        {
            //get previous totals
            int prevEnrolled = 0;
            int.TryParse(db.acaAssists.Where(a => a.AssistTypeId == _enrolledId && a.PrimaryApplicantId == _appId).ToList().Select(a => a.NumberAssisted).Sum().ToString(), out prevEnrolled);

            int totalEnrolled = GetCount("cbxEnrolled");
            assist.NumberAssisted = Math.Abs(totalEnrolled - prevEnrolled);
        }

        if (_assistId == 0)
            db.acaAssists.AddObject(assist);

        //only update health plans if this is an enrollment or submission
        if (assist.isEnrolled || assist.isSubmission)
            UpdateHealthPlans();

        db.SaveChanges();

        Response.Redirect(string.Format("/aca/assists?appId={0}", _appId));
    }
    private void UpdateHealthPlans()
    {
        chsi.dat.CHSIEntities db = new chsi.dat.CHSIEntities();

        foreach (RepeaterItem item in rptrFamily.Items)
        {
            HiddenField applicantId = (HiddenField)item.FindControl("hidApplicantId");
            CheckBox submission = (CheckBox)item.FindControl("cbxSubmission");
            CheckBox enrolled = (CheckBox)item.FindControl("cbxEnrolled");
            CheckBox providerSelected = (CheckBox)item.FindControl("cbxProviderSelected");
            DropDownList payer = (DropDownList)item.FindControl("ddlPayers");
            DropDownList types = (DropDownList)item.FindControl("ddlTypes");
            DropDownList tiers = (DropDownList)item.FindControl("ddlTiers");
            DropDownList subTiers = (DropDownList)item.FindControl("ddlSubTiers");

            int appId = Convert.ToInt32(applicantId.Value);

            //Save Applicant
            acaApplicants app = (from a in db.acaApplicants
                                 where a.ApplicantId == appId
                                 select a).FirstOrDefault();

            app.IsEnrolled = enrolled.Checked;
            app.IsSubmission = submission.Checked;
            app.SelectedCHSIProvider = providerSelected.Checked;

                      db.SaveChanges();

            //Save health plan
            acaHealthPlans hp = (from h in db.acaHealthPlans
                                 where h.ApplicantId == appId
                                 select h).FirstOrDefault();

            if (payer.SelectedIndex > 0)
                hp.PayerId = Convert.ToInt32(payer.SelectedValue);
            else
                hp.PayerId = null;

            if (types.SelectedIndex > 0)
                hp.PlanTypeId = Convert.ToInt32(types.SelectedValue);
            else
                hp.PlanTypeId = null;

            if (tiers.SelectedIndex > 0)
                hp.PlanTierId = Convert.ToInt32(tiers.SelectedValue);
            else
                hp.PlanTierId = null;

            if (subTiers.SelectedIndex > 0)
                hp.PlanSubTierId = Convert.ToInt32(subTiers.SelectedValue);
            else
                hp.PlanSubTierId = null;

            db.SaveChanges();

        }
    }