Ejemplo n.º 1
0
        public async Task Create(PrescriptionInDTO prescriptionInDTO)
        {
            var visits = await _repositoryVisit.GetAsync(x => x, x => x.Id == prescriptionInDTO.VisitId);

            var visit = visits.FirstOrDefault();

            Prescription prescription = new Prescription()
            {
                Comments = prescriptionInDTO.Comments,
                DueDate  = DateTime.Now.AddDays(30),
                VisitId  = prescriptionInDTO.VisitId,
                Visit    = visit,
                PrescriptionMedicaments = new List <PrescriptionMedicament>()
            };

            foreach (var item in prescriptionInDTO.Medicaments)
            {
                PrescriptionMedicament prescriptionMedicament = new PrescriptionMedicament();
                prescriptionMedicament.Medicament   = item;
                prescriptionMedicament.Prescription = prescription;

                prescription.PrescriptionMedicaments.Add(prescriptionMedicament);
            }

            await _repositoryPrescription.InsertAsync(prescription);
        }
Ejemplo n.º 2
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Prescription>()
            .HasOne(x => x.Doctor)
            .WithMany(x => x.Prescriptions)
            .HasForeignKey(x => x.IdDoctor);

            modelBuilder.Entity <Prescription>()
            .HasOne(x => x.Patient)
            .WithMany(x => x.Prescriptions)
            .HasForeignKey(x => x.IdPatient);
            modelBuilder.Entity <PrescriptionMedicament>()
            .HasOne(x => x.Medicament)
            .WithMany(x => x.PrescriptionMedicaments)
            .HasForeignKey(x => x.IdMedicament);
            modelBuilder.Entity <PrescriptionMedicament>()
            .HasOne(x => x.Prescription)
            .WithMany(x => x.PrescriptionMedicaments)
            .HasForeignKey(x => x.IdPrescription);
            modelBuilder.Entity <PrescriptionMedicament>()
            .HasKey(x => new { x.IdMedicament, x.IdPrescription });
            var patient = new Patient
            {
                IdPatient = 1, Brithdate = DateTime.Now.AddYears(-10), FirstName = "Bar", LastName = "Farski"
            };
            var doctor = new Doctor
            {
                Email = "*****@*****.**", FirstName = "Doctor", LastName = "Disrespect", IdDoctor = 1
            };
            var prescription = new Prescription
            {
                Date      = DateTime.UtcNow, IdPrescription = 1, DueDate = DateTime.Now.AddMilliseconds(1), IdDoctor = 1,
                IdPatient = 1
            };

            modelBuilder.Entity <Patient>().HasData(patient);
            modelBuilder.Entity <Doctor>().HasData(doctor);
            modelBuilder.Entity <Doctor>().HasMany(x => x.Prescriptions)
            .WithOne(x => x.Doctor).OnDelete(DeleteBehavior.ClientSetNull);
            modelBuilder.Entity <Prescription>().HasData(prescription);
            var medicament = new Medicament
            {
                Description = "wanna meet god?", Name = "🎢", Type = "good stuff", IdMedicament = 1
            };

            modelBuilder.Entity <Medicament>().HasData(new List <Medicament>
            {
                medicament
            });
            var pm = new PrescriptionMedicament
            {
                Details = "Skada", Dose = 44, IdMedicament = medicament.IdMedicament, IdPrescription = prescription.IdPrescription
            };

            modelBuilder.Entity <PrescriptionMedicament>().HasData(new List <PrescriptionMedicament>
            {
                pm
            });
        }
Ejemplo n.º 3
0
        public void DeletePatient(Patient patient)
        {
            using var tran = context.Database.BeginTransaction();
            var read = from p in context.Patient
                       join pre in context.Prescription on p.IdPatient equals pre.IdPatient into gpre
                       from pprree in gpre.DefaultIfEmpty()
                       join pm in context.PrescriptionMedicament on pprree.IdPrescription equals pm.IdPrescription into gpm
                       from ppmm in gpm.DefaultIfEmpty()
                       where p.IdPatient == patient.IdPatient
                       select new { p.IdPatient, pprree.IdPrescription, ppmm.IdMedicament };

            var result = read.ToList();

            var firstDelete = read.Where(x => x.IdMedicament != 0 && x.IdPrescription != 0).Select(x => new { x.IdPrescription, x.IdMedicament });

            foreach (var item in firstDelete)
            {
                var e = new PrescriptionMedicament()
                {
                    IdPrescription = item.IdPrescription,
                    IdMedicament   = item.IdMedicament
                };
                context.PrescriptionMedicament.Attach(e);
                context.PrescriptionMedicament.Remove(e);
            }

            context.SaveChanges();

            var secondDelete = read.Where(x => x.IdPrescription != 0).Select(x => new { x.IdPrescription }).Distinct();

            foreach (var item in secondDelete)
            {
                var e = new Prescription()
                {
                    IdPrescription = item.IdPrescription
                };
                context.Prescription.Attach(e);
                context.Prescription.Remove(e);
            }

            context.SaveChanges();

            var thirdDelete = read.Where(x => x.IdPatient == patient.IdPatient).Select(x => new { x.IdPatient }).Distinct();

            foreach (var item in thirdDelete)
            {
                var e = new Patient()
                {
                    IdPatient = item.IdPatient
                };
                context.Patient.Attach(e);
                context.Patient.Remove(e);
            }

            context.SaveChanges();

            tran.Commit();
        }
Ejemplo n.º 4
0
        public IActionResult getPrescriptions(int id)
        {
            try { 
            var prescList = new List<Prescriptions>();
            var prescMedList = new List<PrescriptionMedicament>();

                using (SqlConnection client = new SqlConnection("Data Source=db-mssql;Initial Catalog=s18840;Integrated Security=True"))
                using (var com = new SqlCommand())
                {
                    com.Connection = client;

                    com.Parameters.AddWithValue("IdPrescription", id);
                    com.CommandText = "Select * from Prescription where IdPrescription = @id";

                    client.Open();
                    var reader = com.ExecuteReader();

                    while (reader.Read()) {
                        var presc = new Prescriptions();
                        presc.IdPrescription = (int)reader["IdPrescription"];
                        presc.Date = DateTime.Parse(reader["Date"].ToString());
                        presc.DueTime = DateTime.Parse(reader["DueDate"].ToString());
                        presc.IdPatient = (int)reader["IdPatient"];
                        presc.IdDoctor = (int)reader["IdPatient"];
                        prescList.Add(presc);
                        //com.ExecuteNonQuery();

                    }
                    com.ExecuteNonQuery();

                    com.Parameters.AddWithValue("IdPrescription2", id);
                    com.CommandText = "Select * from Prescription_Medicament where IdPrescription = @id";

                    while (reader.Read())
                    {
                        var prescMed = new PrescriptionMedicament();
                        var medList = new List<Medicament>();

                        prescMed.IdPrescription = (int)reader["IdPrescription"];
                        prescMed.IdMedicament = (int)reader["IdMedicament"];
                        prescMed.Dose = (int)reader["Dose"];
                        prescMed.Details = reader["Details"].ToString();

                        prescMedList.Add(prescMed);

                    }
                    return Ok(prescList + " " + prescMedList);

                }
            }catch(SqlException ex)
            {
                return BadRequest("Blad");
            }
         
            
        }
Ejemplo n.º 5
0
        public void PopulateData()
        {
            var doctor = new Doctor
            {
                FirstName = "Edzio",
                LastName  = "Listonosz",
                Email     = "*****@*****.**",
            };

            _context.Doctors.Add(doctor);
            _context.SaveChanges();

            var doctorEntry = _context.Doctors
                              .Where(d => d.FirstName == doctor.FirstName)
                              .Where(d => d.LastName == doctor.LastName)
                              .First(d => d.Email == doctor.Email);

            var patient = new Patient
            {
                FirstName = "Arnold",
                LastName  = "Boczek",
                BirthDate = DateTime.Now
            };

            _context.Patients.Add(patient);
            _context.SaveChanges();
            var patientEntry = _context.Patients
                               .Where(d => d.FirstName == patient.FirstName)
                               .Where(d => d.LastName == patient.LastName)
                               .First(d => d.BirthDate.Equals(patient.BirthDate));

            var medicament = new Medicament
            {
                Name        = "Xanax",
                Description = "some description",
                Type        = "some type"
            };

            _context.Medicaments.Add(medicament);
            _context.SaveChanges();
            var medicamentEntry = _context.Medicaments
                                  .Where(m => m.Name == medicament.Name)
                                  .Where(m => m.Description == medicament.Description)
                                  .First(m => m.Type == medicament.Type);
            var prescription = new Prescription
            {
                IdDoctor  = doctorEntry.IdDoctor,
                IdPatient = patientEntry.IdPatient,
                Date      = DateTime.Now,
                Doctor    = doctorEntry,
                Patient   = patientEntry,
                DueDate   = DateTime.Now,
            };

            _context.Prescriptions.Add(prescription);
            _context.SaveChanges();
            var prescriptionEntry = _context.Prescriptions
                                    .Where(p => p.Date.Equals(prescription.Date))
                                    .Where(p => p.Doctor == prescription.Doctor)
                                    .Where(p => p.Patient == prescription.Patient)
                                    .Where(p => p.DueDate.Equals(prescription.DueDate))
                                    .Where(p => p.IdDoctor == prescription.IdDoctor)
                                    .First(p => p.IdPatient == prescription.IdPatient);
            var pres_medicament = new PrescriptionMedicament
            {
                IdMedicament   = medicamentEntry.IdMedicament,
                IdPrescription = prescriptionEntry.IdPrescription,
                Details        = "some details",
                Dose           = 1,
                Medicament     = medicamentEntry,
                Prescription   = prescriptionEntry
            };

            _context.PrescriptionMedicaments.Add(pres_medicament);
            _context.SaveChanges();
        }
Ejemplo n.º 6
0
        public void SeedDbWithData()
        {
            if (context.Doctor.FirstOrDefault() == null)
            {
                var patient1 = new Patient()
                {
                    FirstName = "Tomasz",
                    LastName  = "Kaliniak",
                    BirthDate = DateTime.Now
                };

                var patient2 = new Patient()
                {
                    FirstName = "Jerzy",
                    LastName  = "Stajszczak",
                    BirthDate = DateTime.Now
                };

                var doctor1 = new Doctor()
                {
                    FirstName = "Mariusz",
                    LastName  = "Pudzianowski",
                    Email     = "*****@*****.**"
                };

                var doctor2 = new Doctor()
                {
                    FirstName = "Adam",
                    LastName  = "Małysz",
                    Email     = "*****@*****.**"
                };

                var prescription1 = new Prescription()
                {
                    Date    = DateTime.Now,
                    DueDate = DateTime.Now,
                    Patient = patient1,
                    Doctor  = doctor1
                };

                var medicament1 = new Medicament()
                {
                    Name        = "Rutinoscorbin",
                    Description = "boli cie glowa",
                    Type        = "benzo"
                };

                var prescriptionMedicament1 = new PrescriptionMedicament()
                {
                    Medicament   = medicament1,
                    Prescription = prescription1,
                    Details      = "brac codziennie po 40 tabletek"
                };

                context.Patient.Add(patient1);
                context.Patient.Add(patient2);
                context.Doctor.Add(doctor1);
                context.Doctor.Add(doctor2);
                context.Prescription.Add(prescription1);
                context.Medicament.Add(medicament1);
                context.PrescriptionMedicament.Add(prescriptionMedicament1);


                context.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        public static void InsertExamples()
        {
            var db = new CodeFirstContext();

            var pm = new PrescriptionMedicament()
            {
                Dose    = 200,
                Details = "Dwa razy dziennie"
            };
            var set1 = new HashSet <PrescriptionMedicament> {
                pm
            };

            var p = new Prescription()
            {
                //IdPrescription = 1,
                Date    = DateTime.Now,
                DueDate = DateTime.Now,
                PrescriptionMedicament = set1
            };
            var set = new HashSet <Prescription> {
                p
            };

            var d = new Doctor
            {
                //IdDoctor = 1,
                FirstName    = "Jakub",
                LastName     = "Bogus³awski",
                Email        = "*****@*****.**",
                Prescription = set
            };

            var pt = new Patient()
            {
                //IdPatient = 1,
                FirstName    = "Barbara",
                LastName     = "Bak³a¿an",
                Birthdate    = DateTime.Parse("Jan 1, 2000"),
                Prescription = set
            };



            var m = new Medicament()
            {
                //IdMedicament = 1,
                Name                   = "Theraflu",
                Description            = "Na katar",
                Type                   = "Bez recepty",
                PrescriptionMedicament = set1
            };



            db.Doctor.Add(d);
            db.Patient.Add(pt);
            db.Medicament.Add(m);
            db.Prescription.Add(p);


            db.SaveChanges();
        }
Ejemplo n.º 8
0
        public IActionResult Seed()
        {
            try
            {
                var doctor1 = new Doctor();
                doctor1.FirstName     = "Oleksandr";
                doctor1.LastName      = "Malaniuk";
                doctor1.Email         = "email123.gm.com";
                doctor1.Prescriptions = new List <Prescription>();
                _cfContext.Doctor.Add(doctor1);

                Console.WriteLine(doctor1.ToString());
                var patient1 = new Patient();
                patient1.FirstName     = "Oleg";
                patient1.LastName      = "Little";
                patient1.BirthDate     = DateTime.Now.AddYears(-30);
                patient1.Prescriptions = new List <Prescription>();

                _cfContext.Patient.Add(patient1);

                var medicament1 = new Medicament();
                medicament1.Description             = "Przeciw kataru";
                medicament1.Name                    = "KatarKill";
                medicament1.Type                    = "Sprej";
                medicament1.PrescriptionsMedicament = new List <PrescriptionMedicament>();

                _cfContext.Medicament.Add(medicament1);



                var prescription1 = new Prescription();
                prescription1.Date      = DateTime.Now;
                prescription1.DueDate   = DateTime.Now.AddDays(10);
                prescription1.IdPatient = patient1.IdPatient;
                prescription1.IdDoctor  = doctor1.IdDoctor;

                prescription1.Doctor  = doctor1;
                prescription1.Patient = patient1;

                prescription1.PrescriptionsMedicament = new List <PrescriptionMedicament>();

                _cfContext.Prescription.Add(prescription1);
                _cfContext.SaveChanges();
                doctor1.Prescriptions.Add(prescription1);
                patient1.Prescriptions.Add(prescription1);

                _cfContext.Update(doctor1);
                _cfContext.Update(patient1);
                _cfContext.SaveChanges();

                var prescriptionMedicament1 = new PrescriptionMedicament();
                prescriptionMedicament1.IdMedicament = _cfContext.Medicament.Where(e => e.Name == medicament1.Name &&
                                                                                   e.Description == medicament1.Description && e.Type == medicament1.Type).First().IdMedicament;

                prescriptionMedicament1.IdPrescription = _cfContext.Prescription.Where(e => e.IdDoctor == prescription1.IdDoctor &&
                                                                                       e.IdPatient == prescription1.IdPatient).First().IdPrescription;

                prescriptionMedicament1.Dose       = 1;
                prescriptionMedicament1.Details    = "Codzienie 1 raz wieczorem";
                prescriptionMedicament1.Medicament = medicament1;

                prescriptionMedicament1.Prescription = prescription1;


                _cfContext.PrescriptionMedicaments.Add(prescriptionMedicament1);
                _cfContext.SaveChanges();
                prescription1.PrescriptionsMedicament.Add(prescriptionMedicament1);
                medicament1.PrescriptionsMedicament.Add(prescriptionMedicament1);

                _cfContext.Update(prescription1);
                _cfContext.Update(medicament1);
                _cfContext.SaveChanges();
            }
            catch (Exception e)
            {
                return(NotFound("Something went wrong" + e));
            }
            return(Ok("Ok"));
        }
Ejemplo n.º 9
0
        public void GenerateSampleDate()
        {
            var doctor1 = new Doctor();

            doctor1.IdDoctor  = 1;
            doctor1.FirstName = "Radosław";
            doctor1.LastName  = "Nowak";
            doctor1.Email     = "*****@*****.**";

            var doctor2 = new Doctor();

            doctor1.IdDoctor  = 2;
            doctor1.FirstName = "Marek";
            doctor1.LastName  = "Nowak";
            doctor1.Email     = "*****@*****.**";

            var patient1 = new Patient();

            patient1.IdPatient = 1;
            patient1.FirstName = "Alek";
            patient1.LastName  = "Radolak";
            patient1.Birthdate = DateTime.Now;

            var patient2 = new Patient();

            patient2.IdPatient = 2;
            patient2.FirstName = "Kuba";
            patient2.LastName  = "Radolak";
            patient2.Birthdate = DateTime.Now;

            var medicament1 = new Medicament();

            medicament1.IdMedicament = 1;
            medicament1.Type         = "Vitamin";
            medicament1.Name         = "Vitamin C";
            medicament1.Description  = "good vitamin very good";

            var pres1 = new Prescription();

            pres1.IdPrescription      = 1;
            pres1.Date                = DateTime.Now;
            pres1.DueDate             = DateTime.Now;
            pres1.IdDoctorNavigation  = doctor1;
            pres1.IdPatientNavigation = patient1;

            var pres1med = new PrescriptionMedicament();

            pres1med.Dose    = 9000;
            pres1med.Details = "not too much";
            pres1med.IdMedicamentNavigation   = medicament1;
            pres1med.IdPrescriptionNavigation = pres1;

            var pres2 = new Prescription();

            pres2.IdPrescription      = 1;
            pres2.Date                = DateTime.Now;
            pres2.DueDate             = DateTime.Now;
            pres2.IdDoctorNavigation  = doctor2;
            pres2.IdPatientNavigation = patient2;

            var pres2med = new PrescriptionMedicament();

            pres1med.Dose    = 420;
            pres1med.Details = "666 if needed";
            pres1med.IdMedicamentNavigation   = medicament1;
            pres1med.IdPrescriptionNavigation = pres2;

            _context.Add(doctor1);
            _context.Add(doctor2);
            _context.Add(patient1);
            _context.Add(patient2);
            _context.Add(medicament1);
            _context.Add(pres1);
            _context.Add(pres1med);
            _context.Add(pres2);
            _context.Add(pres2med);

            _context.SaveChanges();
        }