Ejemplo n.º 1
0
        public RptInvoice(int idInvoice, AriClinicContext ctx1)
        : this()
        {
            ctx1 = new AriClinicContext("AriClinicContext");
            HealthcareCompany healthcare = CntAriCli.GetHealthCompany(ctx1);
            companyname = healthcare.Name;
            
            foreach (Address item in healthcare.Addresses)
            {
                if (item.Type == "Primary")
                    companyaddress = item;
            }
            
            foreach (Telephone item in healthcare.Telephones)
            {
                if (item.Type == "Primary")
                    companytelf = item;
            }
            
            foreach (Email item in healthcare.Emails)
            {
                if (item.Type == "Primary")
                    companyemail = item;
            }
            
            companynif = healthcare.VATIN;

            Invoice invoice = CntAriCli.GetInvoice(idInvoice, ctx1);

            if (invoice != null)
            {
                foreach (Address item in invoice.Customer.Addresses)
                {
                    if (item.Type == "Primary")
                        customeraddress = item;
                }
                
                this.DataSource = invoice;
                //this.subReport1.ReportSource.DataSource = invoice.InvoiceLines;
                //this.subReport2.ReportSource.DataSource = invoice.InvoiceLines;
                this.subReport1.Report.DataSource = invoice.InvoiceLines;
                this.subReport2.Report.DataSource = invoice.InvoiceLines;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Traspasa los datos de los pacientes desde OFT a AriClinic
        /// </summary>
        /// <param name="con"> Connector a OFT</param>
        /// <param name="ctx"> Contexto de AriClinic</param>
        public static void ImportPatientCustomer(OleDbConnection con, AriClinicContext ctx)
        {
            Console.WriteLine("---Importando Historiales---");
            // (1) Eliminar los datos que pudiera haber previamente y que serán
            // sustituidos por los nuevos.
            ctx.Delete(ctx.Addresses); // elimar direcciones.
            ctx.Delete(ctx.Emails); // eliminar correos electrónicos
            ctx.Delete(ctx.Telephones); // eliminar teléfonos.
            ctx.Delete(ctx.Customers); // eliminar los clientes.
            ctx.Delete(ctx.Patients); // por último, los pcaientes.
            ctx.SaveChanges();

            // (2) Lleer todos los pacientes en OFT
            string sql = "SELECT * FROM Historiales";
            cmd = new OleDbCommand(sql, con);
            da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "ConHistoriales");
            int nreg = ds.Tables["ConHistoriales"].Rows.Count;
            int reg = 0;
            foreach (DataRow dr in ds.Tables["ConFacturas"].Rows)
            {
                Console.WriteLine("[{0} de {1}] {2}", ++reg, nreg, dr["Nombre"]);
                // (2.1) Crear cliente
                Customer customer = new Customer();
                customer.VATIN = (string)dr["NumDni"];
                customer.FullName = (string)dr["Nombre"];
                customer.ComercialName = (string)dr["Nombre"];
                ctx.Add(customer);

                // (2.2) Crear paciente y asignarle el cliente
                Patient patient = new Patient();
                patient.Name = (string)dr["Nom"];
                patient.Surname1 = (string)dr["Apell1"];
                patient.Surname2 = (string)dr["Apell2"];
                patient.FullName = (string)dr["Nombre"];
                patient.BornDate = (DateTime)dr["FechaNac"];
                patient.Customer = customer;
                ctx.Add(patient);

                // (2.3) Crear la dirección y asignársela a cliente y paciente.
                Address address = new Address();
                address.Street = (string)dr["Direccion"];
                address.City = (string)dr["Poblacion"];
                address.PostCode = (string)dr["CodPostal"];
                address.Province = (string)dr["Provincia"];
                address.Type = "Primary";
                ctx.Add(address);
                customer.Addresses.Add(address);
                patient.Addresses.Add(address);

                // (2.4) Lo mismo para los teléfono.
                Telephone telephone = new Telephone();
                if ((string)dr["Tel1"] != "")
                {
                    telephone.Number = (string)dr["Tel1"];
                    telephone.Type = "Primary";
                    ctx.Add(telephone);
                    patient.Telephones.Add(telephone);
                    customer.Telephones.Add(telephone);
                }
                if ((string)dr["Tel2"] != "")
                {
                    telephone = new Telephone();
                    telephone.Number = (string)dr["Tel2"];
                    telephone.Type = "Primary";
                    ctx.Add(telephone);
                    patient.Telephones.Add(telephone);
                    customer.Telephones.Add(telephone);
                }
                if ((string)dr["Movil"] != "")
                {
                    telephone = new Telephone();
                    telephone.Number = (string)dr["Movil"];
                    telephone.Type = "Secondary";
                    ctx.Add(telephone);
                    patient.Telephones.Add(telephone);
                    customer.Telephones.Add(telephone);
                }

                // (2.5) Igual pero para correos electrónicos
                Email email = new Email();
                email.Url = (string)dr["Email"];
                email.Type = "Primary";
                ctx.Add(email);
                patient.Emails.Add(email);
                customer.Emails.Add(email);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Traspasa los datos de los pacientes desde OFT a AriClinic
        /// </summary>
        /// <param name="con"> Connector a OFT</param>
        /// <param name="ctx"> Contexto de AriClinic</param>
        public static void ImportPatientCustomer(OleDbConnection con, AriClinicContext ctx)
        {
            // (1) Eliminar los datos que pudiera haber previamente y que serán
            // sustituidos por los nuevos.
            ctx.Delete(ctx.Addresses); // eliminar direcciones.
            ctx.Delete(ctx.Emails); // eliminar correos electrónicos
            ctx.Delete(ctx.Telephones); // eliminar teléfonos.
            ctx.Delete(ctx.Policies); // eliminar las pólizas.

            ctx.Delete(ctx.Customers); // eliminar los clientes.
            ctx.Delete(ctx.Patients); // por último, los pacientes.
            ctx.SaveChanges();

            // (2) Lleer todos los pacientes en OFT
            string sql = "SELECT * FROM Historiales";
            cmd = new OleDbCommand(sql, con);
            da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "ConHistoriales");
            int nreg = ds.Tables["ConHistoriales"].Rows.Count;
            int reg = 0;

            // (2.0) Por cada fila lieda de la tabla, damos de alta el 
            // paciente correspondiente con sus direcciones, teléfonosç
            // y correo electrónico.
            foreach (DataRow dr in ds.Tables["ConHistoriales"].Rows)
            {
                ++reg; // un registro más (para saber por donde va)

                // (2.1) Crear cliente
                Customer customer = new Customer();
                if (dr["NumDni"] != DBNull.Value)
                    customer.VATIN = (string)dr["NumDni"];
                customer.FullName = (string)dr["Nombre"];
                customer.ComercialName = (string)dr["Nombre"];
                customer.OftId = (int)dr["NumHis"];
                ctx.Add(customer);

                // (2.2) Crear paciente y asignarle el cliente
                Patient patient = new Patient();
                patient.Name = (string)dr["Nom"];
                patient.Surname1 = (string)dr["Apell1"];
                if (dr["Apell2"] != DBNull.Value)
                    patient.Surname2 = (string)dr["Apell2"];
                patient.FullName = (string)dr["Nombre"];
                if (dr["FechaNac"] != DBNull.Value) 
                    patient.BornDate = (DateTime)dr["FechaNac"];
                patient.Sex = "M";
                if (dr["Sexo"] != DBNull.Value)
                    if ((byte)dr["Sexo"] == 2)
                        patient.Sex = "W";
                patient.Customer = customer;
                patient.OftId = (int)dr["NumHis"];
                ctx.Add(patient);

                // (2.3) Crear la dirección y asignársela a cliente y paciente.
                Address address = new Address();
                address.Street = (string)dr["Direccion"];
                address.City = (string)dr["Poblacion"];
                if (dr["CodPostal"] != DBNull.Value)
                    address.PostCode = (string)dr["CodPostal"];
                address.Province = (string)dr["Provincia"];
                address.Type = "Primary";
                ctx.Add(address);
                customer.Addresses.Add(address);
                patient.Addresses.Add(address);

                // (2.4) Lo mismo para los teléfono.
                Telephone telephone = new Telephone();
                if (dr["Tel1"] != DBNull.Value)
                {
                    telephone.Number = (string)dr["Tel1"];
                    telephone.Type = "Primary";
                    ctx.Add(telephone);
                    patient.Telephones.Add(telephone);
                    customer.Telephones.Add(telephone);
                }
                if (dr["Tel2"] != DBNull.Value)
                {
                    telephone = new Telephone();
                    telephone.Number = (string)dr["Tel2"];
                    telephone.Type = "Primary";
                    ctx.Add(telephone);
                    patient.Telephones.Add(telephone);
                    customer.Telephones.Add(telephone);
                }
                if (dr["Movil"] != DBNull.Value)
                {
                    telephone = new Telephone();
                    telephone.Number = (string)dr["Movil"];
                    telephone.Type = "Secondary";
                    ctx.Add(telephone);
                    patient.Telephones.Add(telephone);
                    customer.Telephones.Add(telephone);
                }

                // (2.5) Igual pero para correos electrónicos
                Email email = new Email();
                if (dr["Email"] != DBNull.Value)
                    email.Url = (string)dr["Email"];
                email.Type = "Primary";
                ctx.Add(email);
                patient.Emails.Add(email);
                customer.Emails.Add(email);
            }
            ctx.SaveChanges();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Traspasa los datos de los pacientes desde OFT a AriClinic
        /// </summary>
        /// <param name="con"> Connector a OFT</param>
        /// <param name="ctx"> Contexto de AriClinic</param>
        public static void ImportPatientCustomer(OleDbConnection con, AriClinicContext ctx)
        {
            // (1) Eliminar los datos que pudiera haber previamente y que serán
            // sustituidos por los nuevos.
            // DeletePatientRelated(ctx);

            /* ACL-176
             * Ahora solo pretendem,os importar direcciones, correos y telfonos
             * suponemos que personas, pacientes y clientes son correctos
             * y que los pacientes están corretamente ligados a clientes
             * 
             * */
            DeleteEmailsAddressAndTelephones(ctx);

            // (1.1) Montar las procedencias
            Console.WriteLine("Importing sources...");
            ImportSources(con, ctx);



            // (2) Lleer todos los pacientes en OFT
            string sql = "SELECT * FROM Historiales";
            cmd = new OleDbCommand(sql, con);
            da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "ConHistoriales");
            int nreg = ds.Tables["ConHistoriales"].Rows.Count;
            int reg = 0;

            // (2.0) Por cada fila lieda de la tabla, damos de alta el 
            // paciente correspondiente con sus direcciones, teléfonosç
            // y correo electrónico.
            foreach (DataRow dr in ds.Tables["ConHistoriales"].Rows)
            {
                ++reg; // un registro más (para saber por donde va)
                Console.WriteLine("registro {1:#####0} de {2:#####0} / {0}", (string)dr["Nombre"], reg, nreg);
                // (2.1) Crear cliente
                // ACL-176 nos aseguramos que al menos el cliente existe
                Customer customer = CntAriCli.GetCustomerByOftId((int)dr["NumHis"], ctx);
                if (customer == null)
                {
                    customer = new Customer();
                    customer.OftId = (int)dr["NumHis"];
                    ctx.Add(customer);
                }
                if (dr["NumDni"] != DBNull.Value)
                    customer.VATIN = (string)dr["NumDni"];
                customer.FullName = (string)dr["Nombre"];
                customer.ComercialName = (string)dr["Nombre"];
                ctx.SaveChanges();

                // (2.2) Crear paciente y asignarle el cliente
                Patient patient = CntAriCli.GetPatientByOftId((int)dr["NumHis"], ctx);
                if (patient == null)
                {
                    patient = new Patient();
                    patient.OftId = (int)dr["NumHis"];
                    ctx.Add(patient);
                }
                patient.Name = (string)dr["Nom"];
                patient.Surname1 = (string)dr["Apell1"];
                if (dr["Apell2"] != DBNull.Value)
                    patient.Surname2 = (string)dr["Apell2"];
                patient.FullName = (string)dr["Nombre"];
                if (dr["FechaNac"] != DBNull.Value)
                    patient.BornDate = (DateTime)dr["FechaNac"];
                patient.Sex = "M";
                if (dr["Sexo"] != DBNull.Value)
                    if ((byte)dr["Sexo"] == 2)
                        patient.Sex = "W";
                // ACL-176 machacamos la asociación
                patient.Customer = customer;
                // asignar la procedencia
                // ACL-176 la procedencia preexiste
                Source src = (from s in ctx.Sources
                              where s.OftId == (int)dr["IdProcMed"]
                              select s).FirstOrDefault<Source>();
                if (src != null)
                    patient.Source = src;
                // asignar la fecha de apertura
                if (dr["FecAper"] != DBNull.Value)
                    patient.OpenDate = (DateTime)dr["FecAper"];
                ctx.SaveChanges();

                // ACL-176 innecesario por el borre inicial
                //// eliminar los datos asociados
                //ctx.Delete(customer.Addresses);
                //ctx.Delete(patient.Addresses);
                //ctx.SaveChanges();

                // (2.3) Crear la dirección y asignársela a paciente y cliente.
                Address address = new Address();
                address.Street = (string)dr["Direccion"];
                address.City = (string)dr["Poblacion"];
                if (dr["CodPostal"] != DBNull.Value)
                    address.PostCode = (string)dr["CodPostal"];
                address.Province = (string)dr["Provincia"];
                address.Type = "Primary";
                // ACL-176 ¿Qué persona es el paciente?
                address.Person = CntAriCli.GetPersonByPatient(patient, ctx);
                ctx.Add(address);
                ctx.SaveChanges();
                // ACL-176 pacientes y clientes tienen duplicados sus registros
                address = new Address();
                address.Street = (string)dr["Direccion"];
                address.City = (string)dr["Poblacion"];
                if (dr["CodPostal"] != DBNull.Value)
                    address.PostCode = (string)dr["CodPostal"];
                address.Province = (string)dr["Provincia"];
                address.Type = "Primary";
                // ACL-176 ¿Qué persona es el paciente?
                address.Person = CntAriCli.GetPersonByCustomer(customer, ctx);
                ctx.Add(address);
                ctx.SaveChanges();


                // ACL-176 el borre inicial lo vuelve innecesario
                //// eliminar los teléfonos asociados
                //ctx.Delete(customer.Telephones);
                //ctx.Delete(patient.Telephones);
                //ctx.SaveChanges();


                // (2.4) Lo mismo para los teléfono.
                Telephone telephone = new Telephone();
                if (dr["Tel1"] != DBNull.Value)
                {
                    telephone.Number = (string)dr["Tel1"];
                    if (telephone.Number != "")
                    {
                        telephone.Type = "Primary";
                        // ACL-176 turno del paciente
                        telephone.Person = CntAriCli.GetPersonByPatient(patient, ctx);
                        ctx.Add(telephone);
                        ctx.SaveChanges();
                    }
                }
                if (dr["Tel2"] != DBNull.Value)
                {
                    telephone = new Telephone();
                    telephone.Number = (string)dr["Tel2"];
                    if (telephone.Number != "")
                    {
                        telephone.Type = "Primary";
                        // ACL-176 turno del paciente
                        telephone.Person = CntAriCli.GetPersonByPatient(patient, ctx);
                        ctx.Add(telephone);
                        ctx.SaveChanges();
                    }
                }
                if (dr["Movil"] != DBNull.Value)
                {
                    telephone = new Telephone();
                    telephone.Number = (string)dr["Movil"];
                    if (telephone.Number != "")
                    {
                        telephone.Type = "Secondary";
                        // ACL-176 turno del paciente
                        telephone.Person = CntAriCli.GetPersonByPatient(patient, ctx);
                        ctx.Add(telephone);
                        ctx.SaveChanges();
                    }
                }

                //ACL-176 Es un rollo pero hay que repetir todo el proceso para el cliente
                telephone = new Telephone();
                if (dr["Tel1"] != DBNull.Value)
                {
                    telephone.Number = (string)dr["Tel1"];
                    if (telephone.Number != "")
                    {
                        telephone.Type = "Primary";
                        // ACL-176 turno del paciente
                        telephone.Person = CntAriCli.GetPersonByCustomer(customer, ctx);
                        ctx.Add(telephone);
                        ctx.SaveChanges();
                    }
                }
                if (dr["Tel2"] != DBNull.Value)
                {
                    telephone = new Telephone();
                    telephone.Number = (string)dr["Tel2"];
                    if (telephone.Number != "")
                    {
                        telephone.Type = "Primary";
                        // ACL-176 turno del paciente
                        telephone.Person = CntAriCli.GetPersonByCustomer(customer, ctx);
                        ctx.Add(telephone);
                        ctx.SaveChanges();
                    }
                }
                if (dr["Movil"] != DBNull.Value)
                {
                    telephone = new Telephone();
                    telephone.Number = (string)dr["Movil"];
                    if (telephone.Number != "")
                    {
                        telephone.Type = "Secondary";
                        // ACL-176 turno del paciente
                        telephone.Person = CntAriCli.GetPersonByCustomer(customer, ctx);
                        ctx.Add(telephone);
                        ctx.SaveChanges();
                    }

                }

                // ACL-176 innecasrio por borre total
                //// eliminar los correos anteriores
                //ctx.Delete(customer.Emails);
                //ctx.Delete(patient.Emails);
                //ctx.SaveChanges();

                // (2.5) Igual pero para correos electrónicos
                Email email = new Email();
                if (dr["Email"] != DBNull.Value)
                    email.Url = (string)dr["Email"];
                if (email.Url != "0" && email.Url != "")
                {
                    email.Type = "Primary";
                    //ACL-176 turno de paciente
                    email.Person = CntAriCli.GetPersonByPatient(patient, ctx);
                    ctx.Add(email);
                    ctx.SaveChanges();
                }
                // ACL-176 ahora el cliente.
                email = new Email();
                if (dr["Email"] != DBNull.Value)
                    email.Url = (string)dr["Email"];
                if (email.Url != "0" && email.Url != "")
                {
                    email.Type = "Primary";
                    //ACL-176 turno de paciente
                    email.Person = CntAriCli.GetPersonByCustomer(customer, ctx);
                    ctx.Add(email);
                    ctx.SaveChanges();
                }
            }
        }
Ejemplo n.º 5
0
 public static void SetRequestAssociation(Patient p, IList<Request> lr, AriClinicContext ctx){
     foreach (Request req in lr)
     {
         Request r = CntAriCli.GetRequest(req.RequestId, ctx);
         if (r != null)
         {
             r.Patient = CntAriCli.GetPatient(p.PersonId, ctx);
             r.Surname1 = "";
             r.Surname2 = "";
             r.Name = "";
             r.FullName = "";
             r.Sex = "";
             ctx.SaveChanges();
             if (r.BornDate != null && r.BornDate != new DateTime())
             {
                 p.BornDate = r.BornDate;
             }
             if (r.Dni != "")
             {
                 p.Customer.VATIN = r.Dni;
                 r.Dni = "";
             }
             if (p.Addresses.Count == 0)
             {
                 Address a = new Address();
                 a.PostCode = r.PostalCode;
                 p.Addresses.Add(a);
                 r.PostalCode = "";
             }
             if (p.Emails.Count == 0)
             {
                 Email e = new Email();
                 e.Url = r.Email;
                 p.Emails.Add(e);
                 r.Email = "";
             }
             if (p.Telephones.Count == 0)
             {
                 Telephone t = new Telephone();
                 t.Number = r.Telephone;
                 p.Telephones.Add(t);
                 r.Telephone = "";
             }
             ctx.SaveChanges();
         }
     }
 }