protected void Page_Load(object sender, EventArgs e) { // First control the type of parent page if (Request.QueryString["HcId"] != null) { hcId = Int32.Parse(Request.QueryString["HcId"]); hc = CntAriCli.GetHealthCompany(ctx); caller = "hccom"; // Called by a Healthcare Company } if (Request.QueryString["ClinicId"] != null) { clinicId = Int32.Parse(Request.QueryString["ClinicId"]); cl = CntAriCli.GetClinic(clinicId, ctx); caller = "clinic"; // Called by a Healthcare Company } if (Request.QueryString["PatientId"] != null) { patientId = Int32.Parse(Request.QueryString["PatientId"]); pat = CntAriCli.GetPatient(patientId, ctx); caller = "patient"; } if (Request.QueryString["CustomerId"] != null) { customerId = Int32.Parse(Request.QueryString["CustomerId"]); cus = CntAriCli.GetCustomer(customerId, ctx); caller = "customer"; } if (Request.QueryString["ProfessionalId"] != null) { professionalId = Int32.Parse(Request.QueryString["ProfessionalId"]); prof = CntAriCli.GetProfessional(professionalId, ctx); caller = "professional"; } }
public static GeneralPayment GeneralPaymentNew(Clinic clinic, ServiceNote sn, decimal amount, PaymentMethod payMethod, DateTime payDate, string description, AriClinicContext ctx) { var rs = from t in sn.Tickets where t.Amount > t.Paid select t; GeneralPayment gp = new GeneralPayment(); gp.ServiceNote = sn; gp.PaymentDate = payDate; gp.Description = description; gp.PaymentMethod = payMethod; gp.Amount = amount; gp.Clinic = clinic; ctx.Add(gp); foreach (Ticket t in rs.OrderByDescending(tk => tk.Amount - tk.Paid)) { Payment pay = new Payment(); pay.PaymentMethod = payMethod; pay.PaymentDate = payDate; pay.Ticket = t; pay.GeneralPayment = gp; pay.Description = description; pay.Clinic = clinic; decimal dif = t.Amount - t.Paid; if (dif <= amount) { pay.Amount = dif; amount = amount - dif; t.Paid = t.Paid + dif; } else { pay.Amount = amount; t.Paid = t.Paid + amount; amount = 0; } ctx.Add(pay); if (amount == 0) break; } ctx.SaveChanges(); return gp; }
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 == "profInvoice" select p).FirstOrDefault<Process>(); per = CntAriCli.GetPermission(user.UserGroup, proc, ctx); btnAccept.Visible = per.Modify; } // if (Request.QueryString["InvoiceId"] != null) { invoiceId = Int32.Parse(Request.QueryString["InvoiceId"]); inv = CntAriCli.GetProfessionalInvoice(invoiceId, ctx); LoadInvoiceData(); } else { //TODO: What to do if there is not an invoice } if (Session["Clinic"] != null) cl = (Clinic)Session["Clinic"]; // if (Request.QueryString["InvoiceLineId"] != null) { invoiceLineId = Int32.Parse(Request.QueryString["InvoiceLineId"]); invl = CntAriCli.GetProfessionalInvoiceLine(invoiceLineId, ctx); LoadData(invl); } else { LoadTaxTypeCombo(null); } }
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 == "profInvoice" select p).FirstOrDefault<Process>(); per = CntAriCli.GetPermission(user.UserGroup, proc, ctx); btnAccept.Visible = per.Modify; } hc = CntAriCli.GetHealthCompany(ctx); // if (Request.QueryString["InvoiceId"] != null) { invoiceId = Int32.Parse(Request.QueryString["InvoiceId"]); inv = CntAriCli.GetProfessionalInvoice(invoiceId, ctx); LoadData(inv); } else { // deafault values rddpInvoiceDate.SelectedDate = DateTime.Now; txtYear.Text = DateTime.Now.Year.ToString(); } // if (Request.QueryString["Caller"] != null) caller = Request.QueryString["Caller"]; if (Session["Clinic"] != null) cl = (Clinic)Session["Clinic"]; // always read Healt care company }
private static void CreateThings() { // Create a user using (AriClinicContext ctx = new AriClinicContext("AriClinicContext")) { Console.WriteLine("Deleting all records...."); ctx.Delete(ctx.Logs); ctx.Delete(ctx.Users); ctx.Delete(ctx.UserGroups); ctx.Delete(ctx.HealthcareCompanies); ctx.SaveChanges(); Console.WriteLine("Creating default group.."); UserGroup ug = new UserGroup(); ug.Name = "Reservado"; ctx.Add(ug); Console.WriteLine("Creating administrator user.."); User user = new User(); user.Name = "Superuser"; user.Login = "******"; user.UserGroup = ug; user = CntAriCli.EncryptPassword(user, "admin"); ctx.Add(user); HealthcareCompany hc = new HealthcareCompany(); hc.Name = "Ariadna Salud S.L."; ctx.Add(hc); Clinic clinic = new Clinic() { Name = "Clinica 1" }; ctx.Add(clinic); // parameters Console.WriteLine("Creating parameters..."); AriCliModel.Parameter parameter = new Parameter() { PainPump = null, UseNomenclator = false }; ctx.Add(parameter); // processes Console.WriteLine("Creating process..."); Process process = new Process() { Name = "Administración", Code = "admin", }; Process admin = process; ctx.Add(admin); process = new Process() { Name = "Procesos", Code = "process", ParentProcess = admin }; ctx.Add(process); process = new Process() { Name = "Permisos", Code = "permision", ParentProcess = admin }; ctx.Add(process); // permissions Console.WriteLine("Creating permissions..."); Permission permission = new Permission() { Process = admin, UserGroup = ug, View=true, Create=true, Modify=true, Execute=true, }; ctx.Add(permission); permission = new Permission() { Process = process, // must be permission process UserGroup = ug, View = true, Create = true, Modify = true, Execute = true, }; ctx.Add(permission); // import data ctx.SaveChanges(); Console.WriteLine("All jobs done"); } }
public static void ImportServiceNote(OleDbConnection con, AriClinicContext ctx) { //(0) Borrar las notas de servicio y tickets previos //ctx.Delete(ctx.Payments); //ctx.Delete(ctx.GeneralPayments); //ctx.Delete(ctx.Tickets); //ctx.Delete(ctx.ServiceNotes); //ctx.SaveChanges(); // Nos hace falta una clínica, la creamos ahora Clinic cl = (from c in ctx.Clinics where c.Name == "Clinica Valencia" select c).FirstOrDefault<Clinic>(); if (cl == null) { cl = new Clinic(); cl.Name = "Clinica Valencia"; ctx.Add(cl); ctx.SaveChanges(); } //(1) Leer las notas de servicio OFT string sql = "SELECT * FROM NotaServicio"; cmd = new OleDbCommand(sql, con); da = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "ConNotaServicio"); int nreg = ds.Tables["ConNotaServicio"].Rows.Count; int reg = 0; foreach (DataRow dr in ds.Tables["ConNotaServicio"].Rows) { reg++; Console.WriteLine("Notas de servicio {0:#####0} de {1:#####0} A:{2} N:{3}", reg, nreg,(int)dr["Ano"], (int)dr["NumNota"]); ServiceNote sn = (from s in ctx.ServiceNotes where s.Oft_Ano == (int)dr["Ano"] && s.Oft_NumNota == (int)dr["NumNota"] select s).FirstOrDefault<ServiceNote>(); if (sn == null) { sn = new ServiceNote(); ctx.Add(sn); } int id = (int)dr["NumHis"]; sn.Customer = (from cus in ctx.Customers where cus.OftId == id select cus).FirstOrDefault<Customer>(); sn.ServiceNoteDate = (DateTime)dr["Fecha"]; decimal total = (decimal)dr["Total"]; sn.Total = total; sn.Clinic = cl; Professional prf = (from p in ctx.Professionals where p.OftId == 0 select p).FirstOrDefault<Professional>(); sn.Professional = prf; sn.Oft_Ano = (int)dr["Ano"]; sn.Oft_NumNota = (int)dr["NumNota"]; ctx.SaveChanges(); } //(2) Importar la líneas de las notas de servicio sql = "SELECT * FROM LinNotaServicio"; cmd = new OleDbCommand(sql, con); da = new OleDbDataAdapter(cmd); ds = new DataSet(); da.Fill(ds, "ConLineasServicio"); nreg = ds.Tables["ConLineasServicio"].Rows.Count; reg = 0; foreach (DataRow dr in ds.Tables["ConLineasServicio"].Rows) { reg++; Console.WriteLine("Lineas de servicio {0:#####0} de {1:#####0} A:{2} N:{3}", reg, nreg, (int)dr["Ano"], (int)dr["NumNota"]); int idSer = (int)dr["IdServMed"]; int idAno = (int)dr["Ano"]; int idNumNota = (int)dr["NumNota"]; int idProfessional = (int)dr["IdMed"]; InsuranceService insuranceService = (from ins in ctx.InsuranceServices where ins.Service.OftId == idSer select ins).FirstOrDefault<InsuranceService>(); ServiceNote serviceNote = (from sn in ctx.ServiceNotes where sn.Oft_Ano == idAno && sn.Oft_NumNota == idNumNota select sn).FirstOrDefault<ServiceNote>(); Decimal amount = (decimal)dr["Importe"]; Professional professional = (from p in ctx.Professionals where p.OftId == idProfessional select p).FirstOrDefault<Professional>(); Ticket tk = (from t in ctx.Tickets where t.ServiceNote.ServiceNoteId == serviceNote.ServiceNoteId && t.InsuranceService.InsuranceServiceId == insuranceService.InsuranceServiceId && t.Professional.PersonId == professional.PersonId && t.Amount == amount select t).FirstOrDefault<Ticket>(); if (tk == null) { tk = new Ticket(); ctx.Add(tk); } tk.InsuranceService = insuranceService; tk.ServiceNote = serviceNote; tk.Amount = amount; tk.Professional = professional; tk.ServiceNote.Professional = tk.Professional; if (tk.ServiceNote.Professional == null) tk.ServiceNote.Professional = tk.Professional; tk.Description = (string)dr["Descripcion"]; tk.Clinic = cl; tk.TicketDate = tk.ServiceNote.ServiceNoteDate; // hay notas sin cliente, no deberia pero las hay if (tk.ServiceNote.Customer != null) tk.Policy = tk.ServiceNote.Customer.Policies.FirstOrDefault<Policy>(); ctx.SaveChanges(); } }
public static void CreatePayment(Ticket t, PaymentMethod pm, Decimal amount, DateTime dt, string des, ServiceNote note, Clinic cl, GeneralPayment gp, AriClinicContext ctx) { // Now we need verify if there's a payment yet with the same values Payment p = new Payment(); p.Amount = amount; p.Clinic = cl; p.PaymentDate = dt; p.PaymentMethod = pm; p.GeneralPayment = gp; p.Description = des; p.Ticket = t; t.Paid = t.Paid + amount; ctx.Add(p); }
public static bool PayNote(PaymentMethod pm, Decimal amount, DateTime dt, string des, ServiceNote note, Clinic cl, GeneralPayment gp, AriClinicContext ctx) { Payment p = null; // payment to be created Ticket t = null; // related ticket //(0) Control if amount > pending in note decimal total_paid = 0; foreach (Ticket tk in note.Tickets) total_paid += tk.Paid; if ((note.Total - total_paid) < amount) return false; // amount bigger than debt. //(1) Look for a ticket (inside note) with the same amount t = (from tk in note.Tickets where (tk.Amount - tk.Paid) == amount select tk).FirstOrDefault<Ticket>(); if (t != null) { // (1.1) It exists. CreatePayment(t, pm, amount, dt, des, note, cl, gp, ctx); } else { // (1.2) It doesn't exist var rs = from tk in note.Tickets orderby (tk.Amount - tk.Paid) select tk; foreach (Ticket tk in rs) { if (tk.Amount - tk.Paid >= amount) { CreatePayment(tk, pm, amount, dt, des, note, cl, gp, ctx); break; // out } else { decimal paid = tk.Amount - tk.Paid; amount = amount - paid; CreatePayment(tk, pm, paid, dt, des, note, cl, gp, ctx); } } } ctx.SaveChanges(); return true; }