Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="patientMedicament_View"></param>
        /// <param name="createdUserId"></param>
        public static void UpdatePatientMedicaments(PatientMedicament_ViewBE patientMedicament_View, Guid createdUserId)
        {
            using (Health.Back.BE.HealthEntities dc = new Health.Back.BE.HealthEntities(Common.CnnString_Entities))
            {
                PatientMedicament patientMedicament_db = dc.PatientMedicaments.Where(p => p.PatientMedicamentId.Equals(patientMedicament_View.PatientMedicamentId)).FirstOrDefault <PatientMedicament>();

                if (patientMedicament_db == null)
                {
                    return;
                }

                patientMedicament_db.Status = patientMedicament_View.Status;

                patientMedicament_db.MedicalEventId = patientMedicament_View.MedicalEventId;
                patientMedicament_db.PatientId      = patientMedicament_View.PatientId;

                patientMedicament_db.PatientMedicamentId_Parent = patientMedicament_View.PatientMedicamentId_Parent;
                patientMedicament_db.MedicamentName             = patientMedicament_View.MedicamentName;
                patientMedicament_db.MedicamentPresentation     = patientMedicament_View.MedicamentPresentation;
                patientMedicament_db.Dosis             = patientMedicament_View.Dosis;
                patientMedicament_db.Periodicity_hours = patientMedicament_View.Periodicity_hours;
                patientMedicament_db.CreatedDate       = System.DateTime.Now;
                patientMedicament_db.CreatedUserId     = createdUserId;
                patientMedicament_db.Enabled           = patientMedicament_View.Enabled;
                patientMedicament_db.DaysCount         = patientMedicament_View.DaysCount;

                dc.SaveChanges();
            }
        }
Exemple #2
0
        public static void AddPatientMedicaments(PatientMedicament_ViewBE patientMedicament_View, Guid createdUserId)
        {
            using (Health.Back.BE.HealthEntities dc = new Health.Back.BE.HealthEntities(Common.CnnString_Entities))
            {
                PatientMedicament patientMedicament_db = new PatientMedicament();

                patientMedicament_db.Status = patientMedicament_View.Status;

                patientMedicament_db.MedicalEventId = patientMedicament_View.MedicalEventId;
                patientMedicament_db.PatientId      = patientMedicament_View.PatientId;
                if (patientMedicament_View.PatientMedicamentId_Parent >= 0)
                {
                    patientMedicament_db.PatientMedicamentId_Parent = patientMedicament_View.PatientMedicamentId_Parent;
                }

                patientMedicament_db.MedicamentName         = patientMedicament_View.MedicamentName;
                patientMedicament_db.MedicamentPresentation = patientMedicament_View.MedicamentPresentation;
                patientMedicament_db.Dosis             = patientMedicament_View.Dosis;
                patientMedicament_db.Periodicity_hours = patientMedicament_View.Periodicity_hours;
                patientMedicament_db.CreatedDate       = System.DateTime.Now;
                patientMedicament_db.CreatedUserId     = createdUserId;
                patientMedicament_db.DaysCount         = patientMedicament_View.DaysCount;
                patientMedicament_db.Enabled           = true;
                dc.PatientMedicaments.AddObject(patientMedicament_db);
                dc.SaveChanges();
            }
        }
Exemple #3
0
        internal static PatientMedicament GeneratePrescription(int patientId, int medicamentId)
        {
            PatientMedicament prescription = new PatientMedicament()
            {
                PatientId    = patientId,
                MedicamentId = medicamentId
            };

            return(prescription);
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pPatientMedicamentId"></param>
        public static void RemovePatientMedicaments(int pPatientMedicamentId)
        {
            using (Health.Back.BE.HealthEntities dc = new Health.Back.BE.HealthEntities(Common.CnnString_Entities))
            {
                PatientMedicament patientMedicament_db = dc.PatientMedicaments.Where(p => p.PatientMedicamentId.Equals(pPatientMedicamentId)).FirstOrDefault <PatientMedicament>();

                dc.PatientMedicaments.DeleteObject(patientMedicament_db);
                dc.SaveChanges();
            }
        }
Exemple #5
0
        public static void NewPrescription(Patient patient, Medicament medicament, HospitalContext context)
        {
            var prescription = new PatientMedicament()
            {
                Patient    = patient,
                Medicament = medicament
            };

            patient.Prescriptions.Add(prescription);
            context.SaveChanges();
        }
Exemple #6
0
        public static void NewPrescription(int patientId, int medicamentId, HospitalContext context)
        {
            var prescription = new PatientMedicament()
            {
                PatientId    = patientId,
                MedicamentId = medicamentId
            };

            context.Patients.Find(patientId).Prescriptions.Add(prescription);
            context.SaveChanges();
        }
Exemple #7
0
        private PatientMedicament TryCreatePrescription(Patient patient, Medicament medicament)
        {
            if (this.Context.Prescriptions.Any(p => p.Patient.PatientId == patient.PatientId && p.Medicament.MedicamentId == medicament.MedicamentId))
            {
                throw new InvalidOperationException(string.Format(ErrorMessages.PrescriptionAlreadyExists, medicament.Name, patient.FirstName, patient.LastName));
            }

            PatientMedicament prescription = new PatientMedicament(patient, medicament);

            return(prescription);
        }
Exemple #8
0
        public static void DisablePatientMedicaments(int patientMedicamentId, Guid guid, MedicamentStatus status)
        {
            using (Health.Back.BE.HealthEntities dc = new Health.Back.BE.HealthEntities(Common.CnnString_Entities))
            {
                PatientMedicament patientMedicament_db = dc.PatientMedicaments.Where(p => p.PatientMedicamentId.Equals(patientMedicamentId)).FirstOrDefault <PatientMedicament>();

                if (patientMedicament_db != null)
                {
                    patientMedicament_db.Status  = (int)status;
                    patientMedicament_db.Enabled = false;
                }
                dc.SaveChanges();
            }
        }
Exemple #9
0
        static PatientMedicamentBE GetPatientMedicament(int patientId, int patientMedicamentId)
        {
            using (Health.Back.BE.HealthEntities dc = new Health.Back.BE.HealthEntities(Common.CnnString_Entities))
            {
                PatientMedicament patientMedicament_db = dc.PatientMedicaments.Where(p => p.PatientId.Equals(patientId) && p.PatientMedicamentId.Equals(patientMedicamentId)).FirstOrDefault <PatientMedicament>();

                if (patientMedicament_db != null)
                {
                    return((PatientMedicamentBE)patientMedicament_db);
                }

                return(null);
            }
        }
Exemple #10
0
        public static void InitialPrescriptionSeed(HospitalDbContext db)
        {
            var random = new Random();

            var allMedicamentIds = db.Medicaments.Select(d => d.Id).ToArray();

            var allPatientIds = db.Patients.Select(p => p.Id).ToArray();

            foreach (int patientId in allPatientIds)
            {
                var patientMedicamentsCount = random.Next(1, 4);

                var medicamentIds = new int[patientMedicamentsCount];

                for (int id = 0; id < patientMedicamentsCount; id++)
                {
                    var index = -1;

                    while (!allMedicamentIds.Contains(index) || medicamentIds.Contains(index))
                    {
                        index = random.Next(allMedicamentIds.Max());
                    }

                    medicamentIds[id] = index;
                }

                var medicaments = new List <PatientMedicament>();

                foreach (int medicamentId in medicamentIds)
                {
                    var medicament = new PatientMedicament()
                    {
                        PatientId    = patientId,
                        MedicamentId = medicamentId
                    };

                    medicaments.Add(medicament);
                }

                db.Patients.Find(patientId).Medicaments = medicaments;
            }

            db.SaveChanges();
        }
Exemple #11
0
        internal static void InitialPrescriptionSeed(HospitalContext context)
        {
            Random rnd = new Random();

            int[] allMedicamentIds = context.Medicaments.Select(d => d.MedicamentId).ToArray();

            int[] allPatientIds = context.Patients.Select(p => p.PatientId).ToArray();

            foreach (int patientId in allPatientIds)
            {
                int patientMedicamentsCount = rnd.Next(1, 4);

                int[] medicamentIds = new int[patientMedicamentsCount];

                for (int id = 0; id < patientMedicamentsCount; id++)
                {
                    int index = -1;

                    while (!allMedicamentIds.Contains(index) || medicamentIds.Contains(index))
                    {
                        index = rnd.Next(allMedicamentIds.Max());
                    }

                    medicamentIds[id] = index;
                }

                var prescriptions = new List <PatientMedicament>();
                foreach (int medicamentId in medicamentIds)
                {
                    var prescription = new PatientMedicament()
                    {
                        PatientId    = patientId,
                        MedicamentId = medicamentId
                    };

                    prescriptions.Add(prescription);
                }
                context.Patients.Find(patientId).Prescriptions = prescriptions;
            }

            context.SaveChanges();
        }
 private static void SeedPrescriptions(HospitalContext context, int prescriptionSeeds)
 {
     int[] patientIds    = context.Patients.Select(p => p.PatientId).ToArray();
     int[] medicamentIds = context.Medicaments.Select(m => m.MedicamentId).ToArray();
     if (patientIds.Length > 0 && medicamentIds.Length > 0)
     {
         var prescriptions = context.PatientsMedicaments.ToList();
         for (int prs = 1; prs <= prescriptionSeeds; prs++)
         {
             int patientId    = patientIds[rng.Next(patientIds.Length)];
             int medicamentId = medicamentIds[rng.Next(medicamentIds.Length)];
             PatientMedicament prescription = PrescriptionGenerator
                                              .GeneratePrescription(patientId, medicamentId);
             if (!prescriptions.Any(pr => pr.CompareTo(prescription) == 0))
             {
                 prescriptions.Add(prescription);
             }
         }
         context.PatientsMedicaments.AddRange(prescriptions);
         context.SaveChanges();
     }
 }
Exemple #13
0
        public override void Execute()
        {
            FindPatientByIdCommand findPatientByIdCommand = new FindPatientByIdCommand(this.Context, this.IsDoctorLogged, this.LoggedDoctorId, this.Reader, this.Writer);

            Patient patient = findPatientByIdCommand.TryFindPatientById();

            if (!patient.Visitations.Any(v => v.DoctorId == this.LoggedDoctorId))
            {
                this.Writer.Write(Environment.NewLine);
                this.Writer.WriteLine(string.Format(ErrorMessages.PatientNotVisitedByThisDoctor, "prescription"));
                this.Writer.Write(Environment.NewLine);
                return;
            }

            Medicament        medicament   = this.TryFindMedicamentByName();
            PatientMedicament prescription = this.TryCreatePrescription(patient, medicament);

            this.Context.Prescriptions.Add(prescription);
            this.Context.SaveChanges();

            this.Writer.Write(Environment.NewLine);
            this.Writer.WriteLine(string.Format(InfoMessages.SuccessfullyPrescribedMedication, medicament.Name, patient.FirstName, patient.LastName));
        }
Exemple #14
0
        //Edit patient in system
        public void EditPatient(HospitalContext context)
        {
            var medicament = new Medicament();
            var diagnose   = new Diagnose();
            var visitation = new Visitation();

            Console.WriteLine("Please, write patient first name and last name you want to edit:");
            List <string> names = Console.ReadLine()
                                  .Split(" ")
                                  .ToList();

            string patientFirstname = names[0];
            string patientLastname  = names[1];

            var patientToEdit = context.Patients
                                .FirstOrDefault(p => p.FirstName == patientFirstname &&
                                                p.LastName == patientLastname && p.HasInsurance == true);

            if (context.Patients.Any(p => p == patientToEdit))
            {
                Console.WriteLine("What do you want to edit? To add visitation/medicament/diagnose write some of the following - " +
                                  "Add visitation/Add medicament/Add diagnose. To remove the same - Remove visitation/Remove medicament/" +
                                  "Remove diagnose.");

                string answer = Console.ReadLine();

                if (answer == "Add visitation")
                {
                    Console.WriteLine("Enter date for visitation:");
                    string visitationDate = Console.ReadLine();

                    visitation.Date = DateTime.Parse(visitationDate);

                    var currentDoctor = context.Doctor.FirstOrDefault(d => d.Name == docName && d.Specialty == docSpecialty &&
                                                                      d.Password == docPassword);

                    visitation.Doctor  = currentDoctor;
                    visitation.Patient = patientToEdit;

                    patientToEdit.Visitations.Add(visitation);
                    Console.WriteLine("Visitation added!");


                    context.SaveChanges();
                }

                else if (answer == "Add medicament")
                {
                    Console.WriteLine("Write medicament name:");
                    string medicamentName = Console.ReadLine();

                    medicament.Name = medicamentName;

                    var patientMedicaments = new PatientMedicament()
                    {
                        Patient    = patientToEdit,
                        Medicament = medicament
                    };

                    patientToEdit.Prescriptions.Add(patientMedicaments);
                    Console.WriteLine("Medicament added!");

                    context.SaveChanges();
                }

                else if (answer == "Add diagnose")
                {
                    Console.WriteLine("Write diagnose name:");
                    string diagnoseName = Console.ReadLine();

                    diagnose.Name    = diagnoseName;
                    diagnose.Patient = patientToEdit;

                    patientToEdit.Diagnoses.Add(diagnose);
                    Console.WriteLine("Diagnose added!");

                    context.SaveChanges();
                }

                else if (answer == "Remove visitation")
                {
                    Console.WriteLine("Write visitation date:");
                    string visitationDate = Console.ReadLine();
                    var    date           = DateTime.Parse(visitationDate);

                    var currentDoctor = context.Doctor
                                        .FirstOrDefault(d => d.Name == docName &&
                                                        d.Specialty == docSpecialty &&
                                                        d.Password == docPassword);

                    var visitationToRemove = context.Visitations
                                             .FirstOrDefault(v => v.Doctor == currentDoctor &&
                                                             v.Patient == patientToEdit);

                    if (patientToEdit.Visitations.Any(v => v == visitationToRemove))
                    {
                        patientToEdit.Visitations.Remove(visitationToRemove);
                        Console.WriteLine("Visitation deleted!");

                        context.SaveChanges();
                    }

                    else
                    {
                        throw new ArgumentException("No such visitation!");
                    }
                }

                else if (answer == "Remove medicament")
                {
                    Console.WriteLine("Write medicament name:");
                    string medicamentName = Console.ReadLine();

                    medicament.Name = medicamentName;

                    var patients = context.PatientMedicaments
                                   .Where(p => p.Patient.PatientId == patientToEdit.PatientId).ToList();

                    var medicaments = context.PatientMedicaments
                                      .Where(m => m.Medicament.MedicamentId == medicament.MedicamentId).ToList();

                    foreach (var patient in patients)
                    {
                        if (context.PatientMedicaments
                            .Any(p => p.Patient.PatientId == patient.PatientId))
                        {
                            context.PatientMedicaments.Remove(patient);

                            context.SaveChanges();
                        }

                        else
                        {
                            throw new ArgumentException("No such patient!");
                        }
                    }

                    foreach (var med in medicaments)
                    {
                        if (context.PatientMedicaments
                            .Any(m => m.MedicamentId == med.MedicamentId))
                        {
                            context.PatientMedicaments.Remove(med);

                            context.SaveChanges();
                        }

                        else
                        {
                            throw new ArgumentException("No such medicament!");
                        }
                    }

                    var medicamentToRemove = context.Medicaments
                                             .Where(m => m.Name == medicament.Name)
                                             .FirstOrDefault();

                    if (context.Medicaments
                        .Any(m => m.MedicamentId == medicamentToRemove.MedicamentId))
                    {
                        context.Medicaments.Remove(medicamentToRemove);
                        context.SaveChanges();

                        Console.WriteLine("Medicament removed!");
                    }

                    else
                    {
                        throw new ArgumentException("No such medicament!");
                    }
                }

                else if (answer == "Remove diagnose")
                {
                    Console.WriteLine("Write diagnose name:");
                    string diagnoseName = Console.ReadLine();

                    var diagnoseToEdit = context.Diagnoses
                                         .FirstOrDefault(d => d.Name == diagnoseName);

                    if (context.Diagnoses.Any(d => d == diagnoseToEdit))
                    {
                        patientToEdit.Diagnoses.Remove(diagnoseToEdit);
                        Console.WriteLine("Diagnose removed!");

                        context.SaveChanges();
                    }
                    else
                    {
                        throw new ArgumentException("No such diagnose!");
                    }
                }
            }

            else
            {
                throw new ArgumentException("There is no such patient in the system!");
            }
        }
        public void Start(HospitalContex context)
        {
            var input = Console.ReadLine();

            while (input != "Stop")
            {
                var inputArgs = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();

                switch (inputArgs[0])
                {
                case "AddPatient":

                    var patient = new Patient()
                    {
                        FirstName = inputArgs[1],
                        LastName  = inputArgs[2],
                        Address   = inputArgs[3],
                        Email     = inputArgs[4]
                    };

                    context.Patients.Add(patient);

                    break;

                case "AddVisitation":

                    var info = inputArgs.Skip(2).ToArray();

                    int    patientId = int.Parse(info.Last());
                    string comment   = string.Join(" ", info.SkipLast(1));

                    var visitation = new Visitation()
                    {
                        Date      = DateTime.Parse(inputArgs[1]),
                        Comments  = comment,
                        PatientId = patientId
                    };

                    context.Visitations.Add(visitation);

                    break;

                case "AddMedicament":

                    var medicament = new Medicament()
                    {
                        Name = inputArgs[1]
                    };

                    context.Medicaments.Add(medicament);

                    break;

                case "AddDiagnose":

                    string name            = inputArgs[1];
                    string diagnoseComment =
                        string.Join(" ", inputArgs.Skip(2).SkipLast(1));

                    var targetPatientId = context.Patients
                                          .Where(x => x.FirstName == inputArgs.Last())
                                          .FirstOrDefault().PatientId;

                    var diagnose = new Diagnose()
                    {
                        Name      = name,
                        Comments  = diagnoseComment,
                        PatientId = targetPatientId
                    };

                    context.Diagnoses.Add(diagnose);

                    break;

                case "AddedMedicationToPatient":


                    var patientID = context
                                    .Patients
                                    .Where(x => x.FirstName == inputArgs[1])
                                    .FirstOrDefault().PatientId;

                    var medicamentID = context
                                       .Medicaments
                                       .Where(x => x.Name == inputArgs[2])
                                       .FirstOrDefault().MedicamentId;

                    var patientsMedicaments = new PatientMedicament()
                    {
                        PatientId    = patientID,
                        MedicamentId = medicamentID
                    };

                    context.PatientMedicaments.Add(patientsMedicaments);
                    break;

                default:
                    break;
                }

                context.SaveChanges();
                input = Console.ReadLine();
            }
        }