コード例 #1
0
 // Add a visit in the visit List
 public Boolean addVisit(int[] staff, int patient, int type, string dateTime)
 {
     if (doesClientIdExist(patient))
     {
         if (sin.IsVisitTypeValid(type))
         {
             if (visitStaffRequiredValidation(type, staff))
             {
                 if (dateComparison(dateTime, type))
                 {
                     Visit visit = new Visit();
                     visit.StaffIdsVector   = staff;
                     visit.ClientIdentifier = patient;
                     visit.VisitType        = type;
                     visit.VisitTime        = dateTime;
                     visitList.Add(visit);
                     return(true);
                 }
                 else
                 {
                     throw new Exception("Impossible to add the visit, time slot is already booked \n");
                 }
             }
             else
             {
                 throw new Exception("Impossible to add the visit. the staff required is not adapt for visit type \n");
             }
         }
         else
         {
             throw new Exception("Impossible to add the visit , the visit type does not exists \n");
         }
     }
     else
     {
         throw new Exception("Impossible to add the visit, the patient ID does not exists \n");
     }
 }
コード例 #2
0
 internal VisitBL(Visit Visit)
 {
     Translate(Visit);
 }
コード例 #3
0
        // Load method using Tuple
        public Tuple <List <Staff>, List <Client>, List <Visit> > loadAll()
        {
            // Declare all the lists
            List <Client> clients   = new List <Client>();
            List <Staff>  employees = new List <Staff>();
            List <Visit>  visits    = new List <Visit>();

            // Gets all the lines from the text file.
            string str;

            string[] words;
            string[] lines = File.ReadAllLines(@"C:\Users\valka\OneDrive\Работен плот\Coursework Sharp 2\40399682\cw2\PresentationLayer\BusinessLayer\DataLayer\Data.txt");

            foreach (string line in lines)
            {
                // For each Client line split, replace and then create a new Client and add it to the clients list.
                if (line.Contains("Client - ID"))
                {
                    str   = line.Replace("Client - ID: ", "");
                    str   = str.Replace("FirstName", "");
                    str   = str.Replace("Surname", "");
                    str   = str.Replace("Address", "");
                    str   = str.Replace("LocationLat", "");
                    str   = str.Replace("LocationLon", "");
                    words = str.Split(':');

                    Client client = new Client
                    {
                        Id        = Int32.Parse(words[0]),
                        FirstName = words[1],
                        Surname   = words[2],
                        Address1  = words[3].Replace(" Edinburgh", ""),
                        Address2  = "Edinburgh",
                        LocLat    = Double.Parse(words[4]),
                        LocLon    = Double.Parse(words[5])
                    };
                    clients.Add(client);
                }

                // For each Visit line split, replace and then create a new Visit and add it to the visits list.
                if (line.Contains("ClientID"))
                {
                    str   = line.Replace("ClientID- ", "");
                    str   = str.Replace("Staff", "");
                    str   = str.Replace("Type", "");
                    str   = str.Replace("Date", "");
                    words = str.Split('-');

                    Visit visit = new Visit
                    {
                        ClientId = Int32.Parse(words[0]),
                        Type     = Int32.Parse(words[2]),
                        Date     = DateTime.Parse(words[3])
                    };

                    string[] staff = words[1].Split(' ');

                    foreach (string i in staff)
                    {
                        if (i != "")
                        {
                            visit.addToList(Int32.Parse(i));
                        }
                    }
                    visits.Add(visit);
                }

                // For each Staff Member line split, replace and then create a new Staff and add it to the employees list.
                if (line.Contains("Staff Member"))
                {
                    str   = line.Replace("Staff Member - ID: ", "");
                    str   = str.Replace("FirstName", "");
                    str   = str.Replace("Surname", "");
                    str   = str.Replace("Address", "");
                    str   = str.Replace("Category", "");
                    str   = str.Replace("BaseLocationLat", "");
                    str   = str.Replace("BaseLocationLon", "");
                    words = str.Split(':');

                    Staff staff = new Staff
                    {
                        Id         = Int32.Parse(words[0]),
                        FirstName  = words[1],
                        Surname    = words[2],
                        Address1   = words[3].Replace(" Edinburgh", ""),
                        Address2   = "Edinburgh",
                        Category   = words[4],
                        BaseLocLat = Double.Parse(words[5]),
                        BaseLocLon = Double.Parse(words[6])
                    };
                    employees.Add(staff);
                }
            }

            // Return a tuple with the 3 lists
            return(Tuple.Create(employees, clients, visits));
        }
コード例 #4
0
        public Boolean addVisit(int[] staff, int patient, int type, string dateTime)
        {
            // If the lists are empty throw an error since the methods bellow require these lists to be full
            if (employees.Count == 0 || clients.Count == 0)
            {
                throw new Exception("Error - You must add Staff and Client first! \n");
            }
            else
            {
                // TYPE VALIDATION
                if (type != visitTypes.assessment && type != visitTypes.medication && type != visitTypes.bath && type != visitTypes.meal)
                {
                    throw new Exception("Error - not a valid type! (Patient " + patient + " @" + dateTime + ")\n");
                }

                // CLIENT VALIDATION
                bool exists = false;
                foreach (Client c in clients)
                {
                    if (patient == c.Id)
                    {
                        exists = true;
                    }
                }
                if (exists == false)
                {
                    throw new Exception("Error - client does not exist! (Patient " + patient + " @" + dateTime + ")\n");
                }

                // STAFF TYPE VALIDATION
                // Create a list for the staff required for each visit
                List <String> mealStaff = new List <String>()
                {
                    "Care Worker"
                };
                List <String> bathingStaff = new List <String>()
                {
                    "Care Worker", "Care Worker"
                };
                List <String> assessmentStaff = new List <String>()
                {
                    "Social Worker", "General Practitioner"
                };
                List <String> medicationStaff = new List <String>()
                {
                    "Community Nurse"
                };

                // ASSESMENT
                if (type == 0)
                {
                    // Go through each element in the passed list
                    foreach (int el in staff)
                    {
                        // Go through each staff and check if it  has the same id as the passed staff
                        foreach (Staff s in employees)
                        {
                            // If it has then check if the categories are correct and if they are not throw an error
                            if (el == s.Id)
                            {
                                if (s.Category == assessmentStaff[0] || s.Category == assessmentStaff[1])
                                {
                                    continue;
                                }
                                else
                                {
                                    throw new Exception("Error - not a valid staff type! (Patient " + patient + " @" + dateTime + ")\n");
                                }
                            }
                        }
                    }
                }

                // MEDICATION
                if (type == 1)
                {
                    // Go through each element in the passed list
                    foreach (int el in staff)
                    {
                        // Go through each staff and check if it  has the same id as the passed staff
                        foreach (Staff s in employees)
                        {
                            // If it has then check if the categories are correct and if they are not throw an error
                            if (el == s.Id)
                            {
                                if (s.Category == medicationStaff[0])
                                {
                                    continue;
                                }
                                else
                                {
                                    throw new Exception("Error - not a valid staff type! (Patient " + patient + " @" + dateTime + ")\n");
                                }
                            }
                        }
                    }
                }

                // BATHING
                if (type == 2)
                {
                    // Go through each element in the passed list
                    foreach (int el in staff)
                    {
                        // Go through each staff and check if it  has the same id as the passed staff
                        foreach (Staff s in employees)
                        {
                            // If it has then check if the categories are correct and if they are not throw an error
                            if (el == s.Id)
                            {
                                if (s.Category == bathingStaff[0] || s.Category == bathingStaff[1])
                                {
                                    continue;
                                }
                                else
                                {
                                    throw new Exception("Error - not a valid staff type! (Patient " + patient + " @" + dateTime + ")\n");
                                }
                            }
                        }
                    }
                }

                // MEAL
                if (type == 3)
                {
                    // Go through each element in the passed list
                    foreach (int el in staff)
                    {
                        // Go through each staff and check if it  has the same id as the passed staff
                        foreach (Staff s in employees)
                        {
                            // If it has then check if the categories are correct and if they are not throw an error
                            if (el == s.Id)
                            {
                                if (s.Category == mealStaff[0])
                                {
                                    continue;
                                }
                                else
                                {
                                    throw new Exception("Error - not a valid staff type! (Patient " + patient + " @" + dateTime + ")\n");
                                }
                            }
                        }
                    }
                }

                // TIME CLASH VALIDATION
                // Declare the start and end min/hour for the date that is passed to the function
                bool     clash           = false;
                DateTime passedValue     = DateTime.Parse(dateTime);
                int      passedStartHour = DateTime.Parse(dateTime).Hour;
                int      passedStartMin  = DateTime.Parse(dateTime).Minute;

                int passedEndHour = 0;
                int passedEndMin  = 0;

                // Set the hour and minute for the date that is passed after adding the minutes for the type ASSESSMENT
                if (visitTypes.assessment == type)
                {
                    passedValue.AddMinutes(visitDuration.assessment);
                    passedEndHour = passedValue.Hour;
                    passedEndMin  = passedValue.Minute;
                }
                // Set the hour and minute for the date that is passed after adding the minutes for the type MEDICATION
                else if (visitTypes.medication == type)
                {
                    passedValue.AddMinutes(visitDuration.medication);
                    passedEndHour = passedValue.Hour;
                    passedEndMin  = passedValue.Minute;
                }
                // Set the hour and minute for the date that is passed after adding the minutes for the type BATH
                else if (visitTypes.bath == type)
                {
                    passedValue.AddMinutes(visitDuration.bath);
                    passedEndHour = passedValue.Hour;
                    passedEndMin  = passedValue.Minute;
                }
                // Set the hour and minute for the date that is passed after adding the minutes for the type MEAL
                else if (visitTypes.meal == type)
                {
                    passedValue.AddMinutes(visitDuration.meal);
                    passedEndHour = passedValue.Hour;
                    passedEndMin  = passedValue.Minute;
                }

                // Loop through all the visits that are so far in the list
                foreach (Visit v in visits)
                {
                    // Declare the start and end min/hour for the date of a visit that is already in the list
                    DateTime currentVisit     = v.Date;
                    int      currentStartHour = v.Date.Hour;
                    int      currentStartMin  = v.Date.Minute;

                    int currentEndHour = 0;
                    int currentEndMin  = 0;

                    // Set the hour and minute for the date of the current visit after adding the minutes for the type ASSESSMENT
                    if (visitTypes.assessment == v.Type)
                    {
                        currentVisit.AddMinutes(visitDuration.assessment);
                        currentEndHour = currentVisit.Hour;
                        currentEndMin  = currentVisit.Minute;
                    }
                    // Set the hour and minute for the date of the current visit after adding the minutes for the type MEDICATION
                    else if (visitTypes.medication == v.Type)
                    {
                        currentVisit.AddMinutes(visitDuration.medication);
                        currentEndHour = currentVisit.Hour;
                        currentEndMin  = currentVisit.Minute;
                    }
                    // Set the hour and minute for the date of the current visit after adding the minutes for the type BATH
                    else if (visitTypes.bath == v.Type)
                    {
                        currentVisit.AddMinutes(visitDuration.bath);
                        currentEndHour = currentVisit.Hour;
                        currentEndMin  = currentVisit.Minute;
                    }
                    // Set the hour and minute for the date of the current visit after adding the minutes for the type MEAL
                    else if (visitTypes.meal == v.Type)
                    {
                        currentVisit.AddMinutes(visitDuration.meal);
                        currentEndHour = currentVisit.Hour;
                        currentEndMin  = currentVisit.Minute;
                    }

                    // Compare if the hours clash and if they do compare the minutes
                    if (passedStartHour <= currentEndHour && currentStartHour <= passedEndHour)
                    {
                        // If the minutes clash then set the bool to true
                        if (passedStartMin <= currentEndMin && currentStartMin <= passedEndMin)
                        {
                            clash = true;
                        }
                    }
                }

                // If clash is true throw and exception
                if (clash == true)
                {
                    throw new Exception("Error - time clash with visit 1! (Patient " + patient + " @" + dateTime + ")\n");
                }

                // If everything else if okay, create a new Visit and add it to the list
                Visit visit = new Visit
                {
                    ClientId = patient,
                    Type     = type,
                    Date     = DateTime.Parse(dateTime)
                };
                // Add staff method to the list in Visit
                foreach (int i in staff)
                {
                    visit.addToList(i);
                }
                visits.Add(visit);
                // throw new Exception("Error - add visit not yet implemented (Patient "+ patient +" @" + dateTime+")\n");
            }
            return(false);//If no errors thrown, assum OK
        }