/// <summary>
 ///     Takes data from the view to create a new reccord and add it to the list of records
 /// </summary>
 /// <param name="patient"></param>
 /// <param name="doctor"></param>
 /// <param name="hospital"></param>
 /// <param name="diagnosis"></param>
 /// <param name="outcome"></param>
 public void CreateRecord(Patient patient, Doctor doctor, Hospital hospital, string diagnosis, Outcome outcome)
 {
     try
     {
         PatientRecord newRecord = new PatientRecord(patient, doctor, hospital, diagnosis, outcome);
         records.Add(newRecord);
     }
     catch (Exception)
     {
         ErrorMsg("Record cannot be added due to some exception, sorry");
     }
 }
Beispiel #2
0
        private void UpdateRecord()
        {
            string        header = "UPDATING RECORD\n" + breaker;
            int           id;
            PatientRecord h = null;

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Clear();
                Console.WriteLine(header);
                controller.ViewRecord();
                Console.Write("Please choose a record by entering it's ID: ");
                try
                {
                    id = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception)
                {
                    controller.ErrorMsg("Invalid ID. ID should be integer only");
                    continue;
                }
                if ((h = controller.findRecord(id)) == null)
                {
                    controller.ErrorMsg("This record id does not exist");
                    continue;
                }
                break;
            }
            if (h == null)
            {
                return;
            }
            header += "\n" + h.ToString();
            int choice = 0;

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Clear();
                Console.WriteLine(header);
                Console.WriteLine(editHospital);
                Console.Write("Please choose an option: ");
                try
                {
                    choice = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception)
                {
                    controller.ErrorMsg("Invalid Input");
                    continue;
                }
                if (choice != 1)
                {
                    controller.ErrorMsg("Invalid Input");
                    continue;
                }
                break;
            }
            switch (choice)
            {
            case 1: Console.Write("Enter new diagnosis:");
                string diagnosis = Console.ReadLine();
                if (controller.DiagnosisChecker(diagnosis))
                {
                    h.Diagnosis = diagnosis;
                    Console.WriteLine("Diagnosis edited to " + h.Diagnosis);
                }
                break;
            }
        }
        /// <summary>
        ///     Takes data from the view and delete it from list
        /// </summary>
        /// <param name="category"></param>
        /// <param name="choice"></param>
        /// <returns></returns>
        public bool Delete(Category category, int choice)
        {
            switch (category)
            {
            case Category.HOSPITAL:
                try
                {
                    Hospital h = findHospital(choice);
                    SuccessMsg("Hospital " + h.Name + " Deleted");
                    hospitals.Remove(h);
                }
                catch (Exception)
                {
                    ErrorMsg("Wrong ID. Hospital cannot be deleted");
                }
                break;

            case Category.DOCTOR:
                try
                {
                    Doctor d = findDoctor(choice);
                    SuccessMsg("Doctor " + d.Name + " Deleted");
                    doctors.Remove(d);
                }
                catch (Exception)
                {
                    ErrorMsg("Wrong ID. Doctor cannot be deleted");
                }
                break;

            case Category.PATIENT:
                try
                {
                    Patient p = findPatient(choice);
                    SuccessMsg("Patient " + p.Name + " Deleted");
                    patients.Remove(p);
                }
                catch (Exception)
                {
                    ErrorMsg("Wrong ID. Patient cannot be deleted");
                }
                break;

            case Category.RECORD:
                try
                {
                    PatientRecord r = findRecord(choice);
                    SuccessMsg("Record " + r.ID + " Deleted");
                    records.Remove(r);
                }
                catch (Exception)
                {
                    ErrorMsg("Wrong ID. Record cannot be deleted");
                }
                break;

            default:
                ErrorMsg("Wrong Category");
                return(false);
            }
            return(true);
        }