Exemplo n.º 1
0
        public void ShowPotentialDonors(Patients patient, int numberOfDonors)
        {
            List <Donors> potentialDonors = patientsDAO.FindCompatibleDonors(patient);

            potentialDonors = potentialDonors.OrderBy(d => d.BloodGroup).Take(numberOfDonors).ToList();
            Console.WriteLine($"Here are all the donors compatible with your blood group {patient.BloodGroup} and their phone numbers.");
            for (int i = 0; i < potentialDonors.Count; i++)
            {
                Console.WriteLine($"{i + 1}. {potentialDonors[i].Name} {potentialDonors[i].PhoneNumber}");
            }
            Console.WriteLine();
            Console.Write("Pick the number of donor you want blood from: ");
            int donorIndex = 0;

            do
            {
                donorIndex = int.Parse(Console.ReadLine());
            } while (donorIndex <= 0 && donorIndex > numberOfDonors);
            Donors donatingDonor = potentialDonors[donorIndex - 1];

            donorsDAO.TransfuseBlood(donatingDonor, patient);
            Console.WriteLine($"You successfully received blood from {donatingDonor.Name}. You can call him to thank.");
            Console.WriteLine($"We hope your {patient.Diagnose} will be cured. Your account will be deleted now.");
            Console.WriteLine("If you receive blood again you can register at any time.");
            patientsDAO.DeletePatient(patient);
            Console.WriteLine("Press any key to return to the main menu.");
        }
Exemplo n.º 2
0
        public void FindCompatibleDonorsTest()
        {
            //Arrange
            PatientsDAO patientsDAO = new PatientsDAO();
            Patient     patient     = new Patient();

            patient.PatientId   = 1;
            patient.Name        = "Test Patient";
            patient.Email       = "*****@*****.**";
            patient.Password    = "******";
            patient.PhoneNumber = "0888123456";
            patient.Diagnose    = "test";
            patient.BloodGroup  = "B-";
            bool       result = true;
            List <int> ids    = new List <int>()
            {
                39, 40
            };

            //Act
            List <Donor> donors = patientsDAO.FindCompatibleDonors(patient);

            foreach (var donor in donors)
            {
                result &= ids.Contains(donor.DonorId);
            }

            //Assert
            Assert.IsTrue(result);
        }
Exemplo n.º 3
0
        /// <summary>Gets the potential donors.</summary>
        /// <param name="patient">The patient.</param>
        /// <param name="numberOfDonors">The number of donors.</param>
        /// <returns>List&lt;Donor&gt;.</returns>
        public List <Donor> GetPotentialDonors(Patient patient, int numberOfDonors)
        {
            List <Donor> potentialDonors = patientsDAO.FindCompatibleDonors(patient);

            potentialDonors = potentialDonors.OrderBy(d => d.BloodGroup).Take(numberOfDonors).ToList();

            return(potentialDonors);
        }