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 == "ser"
                         select p).FirstOrDefault<Process>();
         per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
         btnAccept.Visible = per.Modify;
     }
     //
     if (Request.QueryString["InsuranceId"] != null)
     {
         insuranceId = Int32.Parse(Request.QueryString["InsuranceId"]);
         ins = CntAriCli.GetInsurance(insuranceId, ctx);
         txtInsurance.Text = ins.Name;
     }
     // 
     if (Request.QueryString["InsuranceServiceId"] != null)
     {
         insuranceServiceId = Int32.Parse(Request.QueryString["InsuranceServiceId"]);
         inser = CntAriCli.GetInsuranceService(insuranceServiceId, ctx);
         LoadData(inser);
     }
 }
        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 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();
            }
        }
 protected void UnloadData(InsuranceService inser)
 {
     serviceId = Int32.Parse(txtServiceId.Text);
     inser.Insurance = ins;
     inser.Service = CntAriCli.GetService(serviceId, ctx);
     inser.Price = Decimal.Parse(txtPrice.Text);
 }
 protected void LoadData(InsuranceService inser)
 {
     txtInsuranceServiceId.Text = inser.InsuranceServiceId.ToString();
     txtInsurance.Text = inser.Insurance.Name;
     txtServiceId.Text = inser.Service.ServiceId.ToString();
     txtServiceName.Text = inser.Service.Name;
     txtPrice.Text = String.Format("{0:C}",inser.Price);
 }
 protected bool CreateChange()
 {
     if (!DataOk())
         return false;
     if (inser == null)
     {
         inser = new InsuranceService();
         UnloadData(inser);
         ctx.Add(inser);
     }
     else
     {
         inser = CntAriCli.GetInsuranceService(insuranceServiceId, ctx);
         ins = inser.Insurance;
         UnloadData(inser);
     }
     ctx.SaveChanges();
     return true;
 }
Example #7
0
    protected void txtInsuranceServiceId_TextChanged(object sender, EventArgs e)
    {
        // check before go to search thats a policy selected
        if (rdcbPolicy.SelectedValue == "")
        {
            lblMessage.Text = Resources.GeneralResource.PolicyNeeded;
            return;
        }
        // insurance selected
        policyId = Int32.Parse(rdcbPolicy.SelectedValue);
        pol = CntAriCli.GetPolicy(policyId, ctx);
        insurance = pol.Insurance;
        // serach for Insurance Service
        insuranceServiceId = Int32.Parse(txtInsuranceServiceId.Text);
        insuranceService = CntAriCli.GetInsuranceService(insuranceServiceId,insurance, ctx);
        if (insuranceService != null)
        {
            txtInsuranceServiceId.Text = insuranceService.InsuranceServiceId.ToString();
            txtInsuranceServiceName.Text = insuranceService.Service.Name;
            // Solo cambiamos la descripción si no había algo previamente
            if (txtDescription.Text == "")
                txtDescription.Text = insuranceService.Service.Name;
            //txtAmount.Text = String.Format("{0:0.00}", insuranceService.Price);
            if (txtAmount.Text == "")
                txtAmount.Text = insuranceService.Price.ToString();
        }
        else
        {
            txtInsuranceServiceId.Text = "";
            txtInsuranceServiceName.Text = Resources.GeneralResource.InsuranceServiceDoesNotExists;
        }

    }
Example #8
0
        public static void ImportAssurancePolicies(OleDbConnection con, AriClinicContext ctx)
        {
            //(0) Borrar las aseguradoras y pólizas previas.
            ctx.Delete(ctx.Policies);
            ctx.Delete(ctx.Insurances);
            ctx.Delete(ctx.InsuranceServices);
            ctx.SaveChanges();

            //(1) Por defecto creamos una aseguradora que es la clínica de Valencia.

            Insurance insurance = (from i in ctx.Insurances
                                   where i.Name == "MIESTETIC (Valencia)"
                                   select i).FirstOrDefault<Insurance>();
            if (insurance == null)
            {
                insurance = new Insurance();
                insurance.Name = "MIESTETIC (Valencia)";
                insurance.Internal = true;
                ctx.Add(insurance);
            }

            //(2) Ahora leemos, de nuevo, todos los tipos de servicio porque en OFT
            // ellos llevan los importes y en nuestro caso son los Insurance services
            string sql = "SELECT * FROM ServMed";
            cmd = new OleDbCommand(sql, con);
            da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "ConServicios");
            int nreg = ds.Tables["ConServicios"].Rows.Count;
            int reg = 0;
            InsuranceService ins = null;
            foreach (DataRow dr in ds.Tables["ConServicios"].Rows)
            {
                reg++;
                Console.WriteLine("Servicions {0:#####0} de {1:#####0} {2}", reg, nreg, "SERVICIO");
                int id = (int)dr["IdServMed"];
                ins = (from i in ctx.InsuranceServices
                       where i.OftId == id
                       select i).FirstOrDefault<InsuranceService>();
                if (ins == null)
                {
                    ins = new InsuranceService();
                    ctx.Add(ins);
                }
                ins.Insurance = insurance;
                ins.Service = (from s in ctx.Services
                               where s.OftId == id
                               select s).FirstOrDefault<Service>();
                ins.Price = (decimal)dr["Importe"];
            }

            //(3) por último asignamos una póliza a todos los clientes que tenemos dados de alta.
            foreach (Customer cus in ctx.Customers)
            {
                Customer localCus = cus;
                Policy pol = (from p in ctx.Policies
                              where p.Customer.PersonId == localCus.PersonId &&
                                    p.Insurance.InsuranceId == insurance.InsuranceId
                              select p).FirstOrDefault<Policy>();
                if (pol == null)
                {
                    pol = new Policy();
                    pol.Customer = localCus;
                    pol.Insurance = insurance;
                    ctx.Add(pol);
                }
            }
            ctx.SaveChanges();
        }