protected void Page_Init(object sender, EventArgs e)
    {
        ctx = new AriClinicContext("AriClinicContext");
        // security control, it must be a user logged
        if (Session["User"] == null)
            Response.Redirect("Default.aspx");
        else
        {
            user = CntAriCli.GetUser((Session["User"] as User).UserId, ctx);
            Process proc = (from p in ctx.Processes
                            where p.Code == "ticket"
                            select p).FirstOrDefault<Process>();
            per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
            btnAccept.Visible = per.Modify;
        }

       
            if (Request.QueryString["CustomerId"] != null)
            {
                customerId = Int32.Parse(Request.QueryString["CustomerId"]);
                cus = CntAriCli.GetCustomer(customerId, ctx);
                //txtCustomerId.Text = cus.PersonId.ToString();

                rdcComercialName.Items.Clear();
                rdcComercialName.Items.Add(new RadComboBoxItem(cus.FullName, cus.PersonId.ToString()));
                rdcComercialName.SelectedValue = cus.PersonId.ToString();
                rdcComercialName.Enabled = false;

                btnCustomerId.Visible = false;
            }
            else
            {
                LoadClinicCombo(null);
            }
            if (Session["Clinic"] != null)
                cl = (Clinic)Session["Clinic"];
            // 
            if (Request.QueryString["AnestheticServiceNoteId"] != null)
            {
                anestheticServiceNoteId = Int32.Parse(Request.QueryString["AnestheticServiceNoteId"]);
                asn = CntAriCli.GetAnestheticServiceNote(anestheticServiceNoteId, ctx);
                cus = asn.Customer;
                customerId = cus.PersonId;
                if(!IsPostBack)
                    LoadData(asn);
                // Load internal frame
                HtmlControl frm = (HtmlControl)this.FindControl("ifTickets");
                frm.Attributes["src"] = String.Format("TicketGrid.aspx?AnestheticServiceNoteId={0}", anestheticServiceNoteId);
            }
            else
            {
                // If there isn't a ticket the default date must be today
                rddpServiceNoteDate.SelectedDate = DateTime.Now;
                LoadClinicCombo(null);
            }
        
    }
        public static bool[] SaveTckChecks(AnestheticServiceNote asn)
        {
            bool[] ls = new bool[asn.AnestheticTickets.Count];
            int    i  = 0;

            foreach (AnestheticTicket atck in asn.AnestheticTickets)
            {
                ls[i++] = atck.Checked;
            }
            return(ls);
        }
 public static void ApplyRisk(AnestheticServiceNote asn, AriClinicContext ctx)
 {
     if (asn.Chk3)
     {
         foreach (AnestheticTicket atck in asn.AnestheticTickets)
         {
             atck.Amount = atck.Amount * 1.5M;
         }
         ctx.SaveChanges();
     }
 }
        public static void ApplyPCA(AnestheticServiceNote asn, AriClinicContext ctx)
        {
            // Read parameters
            AriCliModel.Parameter parameter = GetParameter(ctx);
            Service painPump = parameter.PainPump;

            // Do we need check pain pump?
            if (painPump != null && asn.Chk1)
            {
                // Is there a pain pump assigned?
                var rs = from t in asn.AnestheticTickets
                         where t.InsuranceService.Service.ServiceId == painPump.ServiceId
                         select t;
                if (rs.Count() == 0)
                {
                    // Does this customer have a primary policy with that service?
                    Policy pol = PrimaryPolicy(asn.Customer);
                    if (pol == null)
                    {
                        throw new AriCliException(1, "There isn't a primary policy for this customer");
                    }
                    // Does this policy (insurance) includes a pain pump service?
                    InsuranceService ins = PolicyIncludesService(pol, painPump);
                    if (ins == null)
                    {
                        throw new AriCliException(2, "The insurance company have not the pain pump service assigned");
                    }
                    // More expensive procedure
                    AnestheticTicket aatck = asn.AnestheticTickets.OrderByDescending(x => x.Amount).FirstOrDefault <AnestheticTicket>();
                    if (aatck != null)
                    {
                        Procedure proc = aatck.Procedure;
                        // Everything seems ok, we can add the ticket
                        AnestheticTicket atck = new AnestheticTicket()
                        {
                            TicketDate            = asn.ServiceNoteDate,
                            Description           = String.Format("{0} ({1})", proc.Name, ins.Service.Name),
                            Amount                = ins.Price,
                            Policy                = pol,
                            InsuranceService      = ins,
                            User                  = asn.User,
                            Clinic                = asn.Clinic,
                            Professional          = asn.Professional,
                            Surgeon               = asn.Surgeon,
                            Procedure             = proc,
                            AnestheticServiceNote = asn
                        };
                        ctx.Add(atck);
                        ctx.SaveChanges();
                    }
                }
            }
        }
 public static void ApplyPCA(AnestheticServiceNote asn, AriClinicContext ctx)
 {
     // Read parameters
     AriCliModel.Parameter parameter = GetParameter(ctx);
     Service painPump = parameter.PainPump;
     // Do we need check pain pump?
     if (painPump != null && asn.Chk1)
     {
         // Is there a pain pump assigned?
         var rs = from t in asn.AnestheticTickets
                  where t.InsuranceService.Service.ServiceId == painPump.ServiceId
                  select t;
         if (rs.Count() == 0)
         {
             // Does this customer have a primary policy with that service?
             Policy pol = PrimaryPolicy(asn.Customer);
             if (pol == null)
             {
                 throw new AriCliException(1, "There isn't a primary policy for this customer");
             }
             // Does this policy (insurance) includes a pain pump service?
             InsuranceService ins = PolicyIncludesService(pol, painPump);
             if (ins == null)
             {
                 throw new AriCliException(2, "The insurance company have not the pain pump service assigned");
             }
             // More expensive procedure
             AnestheticTicket aatck = asn.AnestheticTickets.OrderByDescending(x => x.Amount).FirstOrDefault<AnestheticTicket>();
             if (aatck != null)
             {
                 Procedure proc = aatck.Procedure;
                 // Everything seems ok, we can add the ticket
                 AnestheticTicket atck = new AnestheticTicket()
                 {
                     TicketDate = asn.ServiceNoteDate,
                     Description = String.Format("{0} ({1})", proc.Name, ins.Service.Name),
                     Amount = ins.Price,
                     Policy = pol,
                     InsuranceService = ins,
                     User = asn.User,
                     Clinic = asn.Clinic,
                     Professional = asn.Professional,
                     Surgeon = asn.Surgeon,
                     Procedure = proc,
                     AnestheticServiceNote = asn
                 };
                 ctx.Add(atck);
                 ctx.SaveChanges();
             }
         }
     }
 }
 public static void ApplyMultiTicket(AnestheticServiceNote asn, AriClinicContext ctx)
 {
     bool first = true;
     if (asn.AnestheticTickets.Count > 1)
     {
         foreach (AnestheticTicket atck in asn.AnestheticTickets.OrderByDescending(x => x.Amount))
         {
             if (!first)
             {
                 atck.Amount = atck.Amount / 2;
                 atck.Comments = "-50%";
                 ctx.SaveChanges();
             }
             first = false;
         }
     }
 }
        public static void ApplyMultiTicket(AnestheticServiceNote asn, AriClinicContext ctx)
        {
            bool first = true;

            if (asn.AnestheticTickets.Count > 1)
            {
                foreach (AnestheticTicket atck in asn.AnestheticTickets.OrderByDescending(x => x.Amount))
                {
                    if (!first)
                    {
                        atck.Amount   = atck.Amount / 2;
                        atck.Comments = "-50%";
                        ctx.SaveChanges();
                    }
                    first = false;
                }
            }
        }
        public static bool UpdateRelatedTckV2(AnestheticServiceNote asn, bool[] lschk, AriClinicContext ctx)
        {
            bool res = true;

            try
            {
                CreateAssociateTickets(asn, ctx);
                ApplyMultiTicket(asn, ctx);
                ApplyPCA(asn, ctx);
                ApplyRisk(asn, ctx);
                CheckTickets(asn, lschk, ctx);
            }
            catch (AriCliException ex)
            {
                res = false;
            }
            return(res);
        }
        public static void CheckTickets(AnestheticServiceNote asn, bool[] lschk, AriClinicContext ctx)
        {
            int i      = 0;
            int lenght = lschk.Count();

            foreach (AnestheticTicket actk in asn.AnestheticTickets)
            {
                if (asn.Chk2)
                {
                    actk.Checked = true;
                }
                else
                {
                    if (i < lenght)
                    {
                        actk.Checked = lschk[i];
                    }
                }
                i++;
            }
            ctx.SaveChanges();
        }
        public static void CreateAssociateTickets(AnestheticServiceNote asn, AriClinicContext ctx)
        {
            // Does this customer have a primary policy with that service?
            Policy pol = PrimaryPolicy(asn.Customer);

            if (pol == null)
            {
                throw new AriCliException(1, "There isn't a primary policy for this customer");
            }
            // Delete all tickets
            ctx.Delete(asn.AnestheticTickets);
            foreach (Procedure proc in asn.Procedures)
            {
                // Does this policy includes related (from procedure) services
                InsuranceService ins = PolicyIncludesService(pol, proc.Service);
                if (ins == null)
                {
                    throw new AriCliException(3, "The insurance company have not the nomenclator service assigned");
                }
                // Everything seems ok, we can add anesthetic ticket
                AnestheticTicket atck = new AnestheticTicket()
                {
                    TicketDate            = asn.ServiceNoteDate,
                    Description           = String.Format("{0} ({1})", proc.Name, ins.Service.Name),
                    Amount                = ins.Price,
                    Policy                = pol,
                    InsuranceService      = ins,
                    User                  = asn.User,
                    Clinic                = asn.Clinic,
                    Professional          = asn.Professional,
                    Surgeon               = asn.Surgeon,
                    Procedure             = proc,
                    AnestheticServiceNote = asn
                };
                ctx.Add(atck);
                ctx.SaveChanges();
            }
        }
        public static void CreateAssociateTickets(AnestheticServiceNote asn, AriClinicContext ctx)
        {
            // Does this customer have a primary policy with that service?
            Policy pol = PrimaryPolicy(asn.Customer);
            if (pol == null)
            {
                throw new AriCliException(1, "There isn't a primary policy for this customer");
            }
            // Delete all tickets
            ctx.Delete(asn.AnestheticTickets);
            foreach (Procedure proc in asn.Procedures)
            {
                // Does this policy includes related (from procedure) services
                InsuranceService ins = PolicyIncludesService(pol, proc.Service);
                if (ins == null)
                {
                    throw new AriCliException(3, "The insurance company have not the nomenclator service assigned");
                }
                // Everything seems ok, we can add anesthetic ticket
                AnestheticTicket atck = new AnestheticTicket()
                {
                    TicketDate = asn.ServiceNoteDate,
                    Description = String.Format("{0} ({1})", proc.Name, ins.Service.Name),
                    Amount = ins.Price,
                    Policy = pol,
                    InsuranceService = ins,
                    User = asn.User,
                    Clinic = asn.Clinic,
                    Professional = asn.Professional,
                    Surgeon = asn.Surgeon,
                    Procedure = proc,
                    AnestheticServiceNote = asn
                };
                ctx.Add(atck);
                ctx.SaveChanges();
            }

        }
 public static bool UpdateRelatedTckV2(AnestheticServiceNote asn, bool[] lschk, AriClinicContext ctx)
 {
     bool res = true;
     try
     {
         CreateAssociateTickets(asn, ctx);
         ApplyMultiTicket(asn, ctx);
         ApplyPCA(asn, ctx);
         ApplyRisk(asn, ctx);
         CheckTickets(asn, lschk, ctx);
     }
     catch (AriCliException ex)
     {
         res = false;
     }
     return res;
 }
 public static bool[] SaveTckChecks(AnestheticServiceNote asn)
 {
     bool[] ls = new bool[asn.AnestheticTickets.Count];
     int i = 0;
     foreach (AnestheticTicket atck in asn.AnestheticTickets)
     {
         ls[i++] = atck.Checked;
     }
     return ls;
 }
 public static void CheckTickets(AnestheticServiceNote asn, bool[] lschk,  AriClinicContext ctx)
 {
     int i = 0;
     int lenght = lschk.Count();
     foreach (AnestheticTicket actk in asn.AnestheticTickets)
     {
         if (asn.Chk2)
         {
             actk.Checked = true;
         }
         else
         {
             if (i < lenght) actk.Checked = lschk[i];
         }
         i++;
     }
     ctx.SaveChanges();
 }
 public static void ApplyRisk(AnestheticServiceNote asn, AriClinicContext ctx)
 {
     if (asn.Chk3)
     {
         foreach (AnestheticTicket atck in asn.AnestheticTickets)
         {
             atck.Amount = atck.Amount * 1.5M;
         }
         ctx.SaveChanges();
     }
 }
 protected bool AreThereTicketsChecked(AnestheticServiceNote asn)
 {
     bool res = false;
     var rs = from t in asn.AnestheticTickets
              where t.Checked == true
              select t;
     if (rs.Count() > 0) res = true;
     return res;
 }
 protected void LoadClinicCombo(AnestheticServiceNote asn)
 {
     // clear previous items 
     rdcbClinic.Items.Clear();
     foreach (Clinic c in ctx.Clinics)
     {
         rdcbClinic.Items.Add(new RadComboBoxItem(c.Name, c.ClinicId.ToString()));
     }
     if (asn != null)
     {
         rdcbClinic.SelectedValue = asn.Clinic.ClinicId.ToString();
     }
     else
     {
         if (cl != null)
         {
             rdcbClinic.SelectedValue = cl.ClinicId.ToString();
         }
         else
         {
             rdcbClinic.Items.Add(new RadComboBoxItem(" ", ""));
             rdcbClinic.SelectedValue = "";
         }
     }
 }
Example #18
0
 public static int InvoiceAnesthesicServiceNote(AnestheticServiceNote asn, AriClinicContext ctx)
 {
     // it there's an invoice related to this service 
     // we do nothing and return 0
     if (asn.Invoice != null)
         return 0;
     
     // invoice
     Invoice i = new Invoice();
     Decimal total = 0;
     i.Customer = asn.Customer;
     asn.Invoice = i; // this make the relationship
     i.InvoiceDate = asn.ServiceNoteDate;
     i.Serial = CntAriCli.GetHealthCompany(ctx).InvoiceSerial;
     i.Year = i.InvoiceDate.Year;
     i.InvoiceNumber = CntAriCli.GetNextInvoiceNumber(i.Serial, i.Year, ctx);
     ctx.Add(i);
         
     // invoice lines
     foreach (Ticket t in asn.AnestheticTickets)
     {
         InvoiceLine il = new InvoiceLine();
         il.Invoice = i;
         il.Ticket = t;
         il.Description = t.Description;
         il.Amount = t.Amount;
         il.TaxType = t.InsuranceService.Service.TaxType;
         il.TaxPercentage = il.TaxType.Percentage;
         total += il.Amount;
         ctx.Add(il);
     }
     i.Total = total;
 
     // save the work and return id
     ctx.SaveChanges();
     return i.InvoiceId;
 }
    protected void UnloadData(AnestheticServiceNote asn)
    {
        asn.ServiceNoteDate = (DateTime)rddpServiceNoteDate.SelectedDate;
        clinicId = Int32.Parse(rdcbClinic.SelectedValue);
        asn.Clinic = CntAriCli.GetClinic(clinicId, ctx);
        asn.User = CntAriCli.GetUser(user.UserId, ctx);
        //
        decimal tt = 0;
        decimal.TryParse(txtTotal.Text, out tt);
        asn.Total = tt;
        //
        asn.Chk1 = chkChecked.Checked;
        asn.Chk2 = chkCkecked2.Checked;
        asn.Chk3 = chkChecked3.Checked;
        //customerId = Int32.Parse(txtCustomerId.Text);
        asn.Customer = CntAriCli.GetCustomer(int.Parse(rdcComercialName.SelectedValue), ctx);
        if (rdcProfessionalName.SelectedValue != "")
        {
            professionalId = Int32.Parse(rdcProfessionalName.SelectedValue);
            asn.Professional = CntAriCli.GetProfessional(professionalId, ctx);
        }
        else
        {
            asn.Professional = null;
        }
        if (rdcSurgeonName.SelectedValue != "")
        {
            surgeonId = Int32.Parse(rdcSurgeonName.SelectedValue);
            asn.Surgeon = CntAriCli.GetProfessional(surgeonId, ctx);
        }
        else
        {
            asn.Surgeon = null;
        }

        asn.Procedures.Clear();
        ctx.SaveChanges();
        //ctx.Delete(asn.Procedures);

        if (rdcProcedureName1.SelectedValue != "")
        {
            procedureId = Int32.Parse(rdcProcedureName1.SelectedValue);
            asn.Procedures.Add(CntAriCli.GetProcedure(procedureId, ctx));
        }
        if (rdcProcedureName2.SelectedValue != "")
        {
            procedureId = Int32.Parse(rdcProcedureName2.SelectedValue);
            asn.Procedures.Add(CntAriCli.GetProcedure(procedureId, ctx));
        }
        if (rdcProcedureName3.SelectedValue != "")
        {
            procedureId = Int32.Parse(rdcProcedureName3.SelectedValue);
            asn.Procedures.Add(CntAriCli.GetProcedure(procedureId, ctx));
        }
        
        
    }
 protected void LoadData(AnestheticServiceNote asn)
 {
     txtAnestheticServiceNoteId.Text = asn.AnestheticServiceNoteId.ToString();
     //txtCustomerId.Text = asn.Customer.PersonId.ToString();
     rdcComercialName.Items.Clear();
     rdcComercialName.Items.Add(new RadComboBoxItem(asn.Customer.FullName, asn.Customer.PersonId.ToString()));
     rdcComercialName.SelectedValue = asn.Customer.PersonId.ToString();
     rddpServiceNoteDate.SelectedDate = asn.ServiceNoteDate;
     LoadClinicCombo(asn);
     txtTotal.Text = asn.Total.ToString();
     //
     chkChecked.Checked = asn.Chk1;
     chkCkecked2.Checked = asn.Chk2;
     //chkCkecked2.Checked = AreThereTicketsChecked(asn);
     chkChecked3.Checked = asn.Chk3;
     if (asn.Professional != null)
     {
         //txtProfessionalId.Text = asn.Professional.PersonId.ToString();
         rdcProfessionalName.Items.Clear();
         rdcProfessionalName.Items.Add(new RadComboBoxItem(asn.Professional.FullName, asn.Professional.PersonId.ToString()));
         rdcProfessionalName.SelectedValue = asn.Professional.PersonId.ToString();
     }
     if (asn.Surgeon != null) 
     {
         //txtSurgeonId.Text = asn.Surgeon.PersonId.ToString();
         rdcSurgeonName.Items.Clear();
         rdcSurgeonName.Items.Add(new RadComboBoxItem(asn.Surgeon.FullName, asn.Surgeon.PersonId.ToString()));
         rdcSurgeonName.SelectedValue = asn.Surgeon.PersonId.ToString();
         //txtSurgeonName.Text = asn.Surgeon.FullName;
     }
     if (asn.Procedures.Count>0 && asn.Procedures[0] != null)
     {
         //txtProcedureId1.Text = asn.Procedures[0].ProcedureId.ToString();
         rdcProcedureName1.Items.Clear();
         rdcProcedureName1.Items.Add(new RadComboBoxItem(asn.Procedures[0].Name, asn.Procedures[0].ProcedureId.ToString()));
         rdcProcedureName1.SelectedValue = asn.Procedures[0].ProcedureId.ToString();
         //txtProcedureName1.Text = asn.Procedures[0].Name;
     }
     if (asn.Procedures.Count > 1)
     {
         if (asn.Procedures[1] != null)
         {
             //txtProcedureId2.Text = asn.Procedures[1].ProcedureId.ToString();
             //txtProcedureName2.Text = asn.Procedures[1].Name;
             rdcProcedureName2.Items.Clear();
             rdcProcedureName2.Items.Add(new RadComboBoxItem(asn.Procedures[1].Name, asn.Procedures[1].ProcedureId.ToString()));
             rdcProcedureName2.SelectedValue = asn.Procedures[1].ProcedureId.ToString();
         }
     }
     if (asn.Procedures.Count > 2)
     {
         if (asn.Procedures[2] != null)
         {
             //txtProcedureId3.Text = asn.Procedures[2].ProcedureId.ToString();
             //txtProcedureName3.Text = asn.Procedures[2].Name;
             rdcProcedureName3.Items.Clear();
             rdcProcedureName3.Items.Add(new RadComboBoxItem(asn.Procedures[2].Name, asn.Procedures[2].ProcedureId.ToString()));
             rdcProcedureName3.SelectedValue = asn.Procedures[2].ProcedureId.ToString();
         }
     }
 }
Example #21
0
        public static void DeleteAnestheticServiceNote(AnestheticServiceNote ansn, AriClinicContext ctx)
        {
            foreach (AnestheticTicket at in ansn.AnestheticTickets)
                ctx.Delete(at);

            ctx.Delete(ansn);
            ctx.SaveChanges();
        }
Example #22
0
 public static bool ContainsAnesthesicTicketsInvoiced(AnestheticServiceNote asn, AriClinicContext ctx)
 {
     foreach (Ticket t in asn.AnestheticTickets)
     {
         if (t.InvoiceLines.Count > 0)
             return true;
     }
     return false;
 }
Example #23
0
 public static IList<SaveCheck> SaveChecks(AnestheticServiceNote asn)
 {
     IList<SaveCheck> lsc = new List<SaveCheck>();
     foreach (AnestheticTicket atck in asn.AnestheticTickets)
     {
         if (atck.Checked)
         {
             SaveCheck schk = new SaveCheck();
             schk.ProcedureId = atck.Procedure.ProcedureId;
             schk.Chk = true;
             lsc.Add(schk);
         }
     }
     return lsc;
 }
Example #24
0
 public static void CheckAnestheticServiceNoteTickets(AnestheticServiceNote ansn, AriClinicContext ctx, IList<SaveCheck> lschk)
 {
     // Read parameters
     AriCliModel.Parameter parameter = GetParameter(ctx);
     Service painPump = parameter.PainPump;
     bool hRisk = ansn.Chk3;
     //
     AnestheticTicket anstk = null;
     // Do we need check pain pump?
     if (painPump != null && ansn.Chk1)
     {
         // Is there a pain pump assigned?
         var rs = from t in ansn.AnestheticTickets
                  where t.InsuranceService.Service.ServiceId == painPump.ServiceId
                  select t;
         if (rs.Count() == 0)
         {
             // Does this customer have a primary policy with that service?
             Policy pol = PrimaryPolicy(ansn.Customer);
             if (pol == null)
             {
                 throw new AriCliException(1, "There isn't a primary policy for this customer");
             }
             // Does this policy (insurance) includes a pain pump service?
             InsuranceService ins = PolicyIncludesService(pol, painPump);
             if (ins == null)
             {
                 throw new AriCliException(2, "The insurance company have not the pain pump service assigned");
             }
             // Everything seems ok, we can add the ticket
             anstk = new AnestheticTicket()
             {
                 TicketDate = ansn.ServiceNoteDate,
                 Description = String.Format("{0} ({1})", ansn.Procedures[0].Name, ins.Service.Name),
                 Amount = ins.Price,
                 Policy = pol,
                 InsuranceService = ins,
                 User = ansn.User,
                 Clinic = ansn.Clinic,
                 Professional = ansn.Professional,
                 Surgeon = ansn.Surgeon,
                 Procedure = ansn.Procedures[0],
                 AnestheticServiceNote = ansn
             };
             if (ansn.Chk2)
             {
                 anstk.Checked = true;
             }
             else
             {
                 anstk.Checked = CntAriCli.IsItInChecks(anstk, lschk);
             }
             if (hRisk)
                 anstk.Amount = anstk.Amount * 1.5M; // increase 50%
             ctx.Add(anstk);
     
             ctx.SaveChanges();
         }
     }
     // Do we need check procedure - service link?
     if (parameter.UseNomenclator)
     {
         bool multi = false;
         foreach (Procedure p in ansn.Procedures)
         {
             AddAutomaticTicket(ansn, p, ctx, multi, lschk);
             multi = true;
         }
     }
 }
    protected bool CreateChange()
    {
        if (asn == null)
        {
            firstTime = true;
            asn = new AnestheticServiceNote();
            UnloadData(asn);
            ctx.Add(asn);
            lschk = CntAriCli.SaveTckChecks(asn);
        }
        else
        { 
            asn = CntAriCli.GetAnestheticServiceNote(anestheticServiceNoteId, ctx);
            //lschk = CntAriCli.SaveChecks(asn);
            lschk = CntAriCli.SaveTckChecks(asn);
            bool procedurechanged = false;
            if(Session["procedurechanged"]!=null)
                procedurechanged = (bool)Session["procedurechanged"];
            if (procedurechanged )
            {
                firstTime = true;
                Session["procedurechanged"] = null;

                IList<AnestheticTicket> tickets = asn.AnestheticTickets;
                
                foreach (AnestheticTicket item in tickets)
                {
                    ctx.Delete(CntAriCli.GetTicket(item.TicketId, ctx));
                }
                ctx.SaveChanges();

                asn.AnestheticTickets.Clear();
                asn.Procedures.Clear();
            }
            UnloadData(asn);
        }
        //bool res = UpdateRelatedTickets(asn, lschk);
        // ---
        bool res = CntAriCli.UpdateRelatedTckV2(asn, lschk, ctx);
        // Update anesthetic service note total
        asn.Total = asn.AnestheticTickets.Sum(x => x.Amount);
        ctx.SaveChanges();
        if (firstTime)
        {
            firstTime = false;
            Response.Redirect(String.Format("AnestheticServiceNoteForm.aspx?AnestheticServiceNoteId={0}", asn.AnestheticServiceNoteId));
        }
        return res;
    }
 protected bool UpdateRelatedTickets(AnestheticServiceNote asn, IList<SaveCheck> lschk)
 {
     try
     {
         ctx.Delete(asn.AnestheticTickets);
         asn.AnestheticTickets.Clear();
         CntAriCli.CheckAnestheticServiceNoteTickets(asn, ctx, lschk);
         if (firstTime)
         {
             firstTime = false;
             Response.Redirect(String.Format("AnestheticServiceNoteForm.aspx?AnestheticServiceNoteId={0}", asn.AnestheticServiceNoteId));
         }
     }
     catch (AriCliException ex)
     {
         string message = "";
         switch (ex.Number)
         {
             case 1:
                 message = Resources.GeneralResource.NoPrimaryPolicy;
                 break;
             case 2:
                 message = Resources.GeneralResource.NoPainPump;
                 break;
             case 3:
                 message = Resources.GeneralResource.NoNomenclatorService;
                 break;
             default:
                 message = ex.Message;
                 break;
         }
         string command = String.Format("showDialog('{0}','{1}','warning',null,0,0);"
                                        , Resources.GeneralResource.Warning
                                        , message);
         RadAjaxManager1.ResponseScripts.Add(command);
         Session["LinkId"] = asn.AnestheticServiceNoteId;
         return false;
     }
     return true;
 }
Example #27
0
 protected void Page_Init(object sender, EventArgs e)
 {
     ctx = new AriClinicContext("AriClinicContext");
     // security control, it must be a user logged
     if (Session["User"] == null)
         Response.Redirect("Default.aspx");
     else
     {
         user = CntAriCli.GetUser((Session["User"] as User).UserId, ctx);
         Process proc = (from p in ctx.Processes
                         where p.Code == "policy"
                         select p).FirstOrDefault<Process>();
         per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
     }
     // cheks if is call from another form
     if (Request.QueryString["Type"] != null)
         type = Request.QueryString["Type"];
     // read the realated patient
     if (Request.QueryString["PatientId"] != null)
     {
         patientId = Int32.Parse(Request.QueryString["PatientId"]);
         pat = CntAriCli.GetPatient(patientId, ctx);
         cus = pat.Customer;
     }
     // read passed customer if any
     if (Request.QueryString["CustomerId"] != null)
     {
         customerId = Int32.Parse(Request.QueryString["CustomerId"]);
         cus = CntAriCli.GetCustomer(customerId, ctx);
     }
     //
     if (Request.QueryString["NotPaid"] != null)
     {
         notPaid = true;
     }
     // 
     if (type == "InTab")
     {
         HtmlControl tt = (HtmlControl)this.FindControl("TitleArea");
         tt.Attributes["class"] = "ghost";
         // hide patient column
         RadGrid1.Columns.FindByDataField("Policy.Customer.FullName").Visible = false;
         //
         RadGrid1.PageSize = 6;
     }
     else
     {
         
     }
     if (Request.QueryString["AnestheticServiceNoteId"] != null)
     {
         anestheticServiceNoteId = Int32.Parse(Request.QueryString["AnestheticServiceNoteId"]);
         asn = CntAriCli.GetAnestheticServiceNote(anestheticServiceNoteId, ctx);
         HtmlControl tt = (HtmlControl)this.FindControl("TitleArea");
         tt.Attributes["class"] = "ghost";
         // here the fields that must be hidden
         RadGrid1.Columns.FindByDataField("TicketDate").Visible = false;
         RadGrid1.Columns.FindByDataField("Policy.Customer.FullName").Visible = false;
         RadGrid1.Columns.FindByDataField("Checked").Visible = false;
         RadGrid1.Columns.FindByDataField("Clinic.Name").Visible = false;
     }
     if (Request.QueryString["ServiceNoteId"] != null)
     {
         serviceNoteId = int.Parse(Request.QueryString["ServiceNoteId"]);
         sn = CntAriCli.GetServiceNote(serviceNoteId, ctx);
         HtmlControl tt = (HtmlControl)this.FindControl("TitleArea");
         tt.Attributes["class"] = "ghost";
         // here the fields that must be hidden
         RadGrid1.Columns.FindByDataField("TicketDate").Visible = false;
         RadGrid1.Columns.FindByDataField("Policy.Customer.FullName").Visible = false;
         RadGrid1.Columns.FindByDataField("Checked").Visible = false;
         RadGrid1.Columns.FindByDataField("Clinic.Name").Visible = false;
         RadGrid1.Columns.FindByDataField("Paid").Visible = false;
     }
     // translate filters
     CntWeb.TranslateRadGridFilters(RadGrid1);
     //
 }
Example #28
0
 public static void AddAutomaticTicket(AnestheticServiceNote ansn, Procedure proc, AriClinicContext ctx, bool multi, IList<SaveCheck> lschk)
 {
     // Does this customer have a primary policy with that service?
     Policy pol = PrimaryPolicy(ansn.Customer);
     bool hRisk = ansn.Chk3;
     if (pol == null)
     {
         throw new AriCliException(1, "There isn't a primary policy for this customer");
     }
     // Does this policy includes related (from procedure) services
     InsuranceService ins = PolicyIncludesService(pol, proc.Service);
     if (ins == null)
     {
         throw new AriCliException(3, "The insurance company have not the nomenclator service assigned");
     }
     // Everything seems ok, we can add anesthetic ticket
     AnestheticTicket anstk = new AnestheticTicket()
     {
         TicketDate = ansn.ServiceNoteDate,
         Description = String.Format("{0} ({1})", proc.Name, ins.Service.Name),
         Amount = ins.Price,
         Policy = pol,
         InsuranceService = ins,
         User = ansn.User,
         Clinic = ansn.Clinic,
         Professional = ansn.Professional,
         Surgeon = ansn.Surgeon,
         Procedure = proc,
         AnestheticServiceNote = ansn
     };
     if (ansn.Chk2)
     {
         anstk.Checked = true;
     }
     else
     {
         anstk.Checked = CntAriCli.IsItInChecks(anstk, lschk);
     }
     if (multi)
     {
         anstk.Amount = anstk.Amount / 2;
         anstk.Comments = "-50%";
     }
     if (hRisk)
         anstk.Amount = anstk.Amount * 1.5M; // high risk increase 50%
     ctx.Add(anstk);
     ctx.SaveChanges();
 }