public async Task <List <RepSchedule> > GetRepScheduleAsync(DateTime startDate) { try { if (_dates.Count > 0) { _dates.Clear(); } DateTime start = startDate; DateTime end = start.AddDays(6); int workDays = 0; while (start != end) { if (start.DayOfWeek != DayOfWeek.Sunday) { _dates.Add(start); workDays++; } start = start.AddDays(1); if (workDays == 6) { break; } } _repNames = GetRepresentatives(); _stock = await GetMedicineStock(); _docNames = GetDoctors(); if (_repNames == null || _stock == null || _docNames == null) { _log.Error("Could not get RepName or Stock or DocName"); return(null); } for (var i = 0; i < _dates.Count; i++) { var rep = new RepSchedule { RepName = _repNames[(i % _repNames.Count)].RepresentativeName, DoctorName = _docNames[i].Name, TreatingAilment = _docNames[i].TreatingAilment, MeetingSlot = "1pm-2pm", DateOfMeeting = _dates[i] }; var meds = (from s in _stock where s.TargetAilment.Contains(_docNames[i].TreatingAilment) select s.Name).ToList(); rep.Medicine = string.Join(",", meds); rep.DoctorContactNumber = _docNames[i].ContactNumber; _repSchedule.Add(rep); } _log.Info("returning schedule"); return(_repSchedule); } catch (Exception e) { _log.Error("Error while scheduling - " + e.Message); throw; } }
public async Task <List <RepSchedule> > GetRepScheduleAsync(string startDate) { try { if (_dates.Count > 0) { _dates.Clear(); } DateTime start = Convert.ToDateTime(startDate); DateTime end = start.AddDays(6); int workDays = 0; while (start != end) { if (start.DayOfWeek != DayOfWeek.Sunday) { _dates.Add(start); workDays++; } if (workDays == 5) { break; } start = start.AddDays(1); } _repNames = GetRepresentatives(); _stock = await _medicineStockProvider.GetMedicineStock(); _docNames = GetDoctors(); if (_repNames == null || _repNames.Count == 0 || _stock.Count == 0 || _stock == null || _docNames.Count == 0 || _docNames == null) { return(null); } for (var i = 0; i < _dates.Count; i++) { var rep = new RepSchedule { RepName = _repNames[(i % _repNames.Count)].RepresentativeName, DoctorName = _docNames[i].Name, TreatingAilment = _docNames[i].TreatingAilment, MeetingSlot = "1pm-2pm", DateOfMeeting = _dates[i].ToShortDateString() }; var meds = (from s in _stock where s.TargetAilment.Contains(_docNames[i].TreatingAilment) select s.Name).ToList(); rep.Medicine = string.Join(",", meds); rep.DoctorContactNumber = _docNames[i].ContactNumber; _repSchedule.Add(rep); } return(_repSchedule); } catch (Exception) { throw; } }
public async Task <List <RepSchedule> > GetRepScheduleAsync(DateTime startDate) { Dates.Clear(); DateTime start = startDate; DateTime end = start.AddDays(6); int workDays = 0; while (start != end) { if (start.DayOfWeek != DayOfWeek.Sunday) { Dates.Add(start); workDays++; } start = start.AddDays(1); if (workDays == 6) { break; } } repNames = GetRepresentatives(); stock = await GetMedicineStock(); docNames = GetDocters(); for (int i = 0; i < Dates.Count; i++) { RepSchedule rep = new RepSchedule(); rep.Rep_Name = repNames[(i % repNames.Count)].Representative_Name; rep.Doctor_Name = docNames[i].Name; rep.Treating_Ailment = docNames[i].Treating_Ailment; rep.Meeting_Slot = "1pm-2pm"; rep.Date_Of_Meeting = Dates[i]; List <string> meds = (from s in stock where s.Target_Ailment.Contains(docNames[i].Treating_Ailment) select s.Name).ToList(); rep.Medicine = string.Join(",", meds); rep.Doctor_Contact_Number = docNames[i].Contact_Number; repSchedule.Add(rep); } return(repSchedule); }
public void CreateSchedule(DateTime date) { try { int count = 0; while (count != 5) { if (date.DayOfWeek != DayOfWeek.Sunday) { Doctor doc = RepScheduleRepository.lsdoc[count]; IEnumerable <string> medicines = from m in stock where m.TargetAilment == doc.TreatingAilment select m.Name; RepSchedule rp = new RepSchedule(); rp.RepName = MedicalRepresentativeRepository.medicalRepresentativeList[count % 3].Name; //Representative Name rp.Medicine = medicines; rp.Doctor = doc; rp.MeetingSlot = "1 pm to 2 pm"; rp.DateOfMeeting = date; count++; scheduleList.Add(rp); } date = date.AddDays(1); } if (scheduleList.Count == 0) { _log4net.Info(nameof(RepScheduleProvider) + "RepSchedule list is null"); } else { _log4net.Info(nameof(RepScheduleProvider) + "Succesfully schedule created"); } } catch (Exception e) { _log4net.Error(nameof(RepScheduleProvider) + "Exception" + e.Message); } }
public dynamic ScheduleMeet(string startDate) { _log4net.Info("Date Enter through user" + startDate); try { Dates.Clear(); CultureInfo culture = new CultureInfo("en-US"); DateTime tempDate = Convert.ToDateTime(startDate, culture); DateTime start = tempDate.Date; int workDays = 0; DateTime end = start.AddDays(6); while (start != end) { if (start.DayOfWeek != DayOfWeek.Sunday) { _log4net.Info("Workday is Added to Dates List" + start); Dates.Add(start.ToString().Split(' ')[0]); workDays++; } start = start.AddDays(1); if (workDays == 6) { _log4net.Info("Sunday is Removed" + start); break; } } //Reading CSV and Stock API to get Stock Items try { _log4net.Info("Reading CSV and Stock API to get Stock Items"); var DoctorListTest = ReadDoctorsCsv(); var StockApiDataItems = getStockApiData(); } catch (Exception exception) { _log4net.Info("Errors in Reading CSV and Stock API to get Stock Items " + exception); return(null); } //Formating Meeting Structure _log4net.Info("Contruct Required Table Schedule Meet"); for (int i = 0; i < Dates.Count; i++) { RepSchedule rs = new RepSchedule(); rs.MRName = MRList[(i % MRList.Count)].MRName; rs.DoctorName = DoctorList[i].DoctorName; rs.TreatingAilment = DoctorList[i].TreatingAilment; IList <string> meds = (from s in Stockdata where s.TargetAilment.Contains(DoctorList[i].TreatingAilment) select s.Name).ToList(); string medss = string.Join(",", meds); rs.Medicine = medss; rs.MeetingSlot = "1 to 2 PM"; rs.DateofMeeting = Dates[i]; rs.DoctorContactNumber = DoctorList[i].ContactNumber; Meeting.Add(rs); meds.Clear(); } return(Meeting); } catch (Exception exception) { _log4net.Info("Erorrs in Schedule Meet Check Date" + exception); return(null); } }
public async Task <IEnumerable <RepSchedule> > CreateRepSchedule(DateTime ScheduleStartDate) { try { List <RepSchedule> repSchedules = new List <RepSchedule>(); if (!IsValid(ScheduleStartDate)) { throw new ArgumentException("InValid date"); } else { medicineStockList = await _medicines.GetMedicineStock(); doctorDTOList = _doctors.GetDoctorDTOList().ToList(); representativeDTOList = _representatives.GetRepresentativeList().ToList(); if (medicineStockList == null || doctorDTOList == null || representativeDTOList == null || medicineStockList.Count == 0 || doctorDTOList.Count == 0 || representativeDTOList.Count == 0) { return(null); } else { for (int i = 0; i < 5; i++) { DateTime MeetingDate; if (ScheduleStartDate.DayOfWeek == DayOfWeek.Sunday) { ScheduleStartDate = ScheduleStartDate.AddDays(1); MeetingDate = ScheduleStartDate; } else { MeetingDate = ScheduleStartDate; } var MedicinesByAilment = medicineStockList.Where(m => m.TargetAilment == doctorDTOList[i % doctorDTOList.Count].TreatingAilment).Select(m => m.Name); string MedicineNames = string.Join(", ", MedicinesByAilment); RepSchedule singleSchedule = new RepSchedule { Name = representativeDTOList[i % representativeDTOList.Count].Name, DocterName = doctorDTOList[i % doctorDTOList.Count].Name, MettingSlot = "1 PM To 2 PM", TreatmentAilment = doctorDTOList[i % doctorDTOList.Count].TreatingAilment, DocterContactNumber = doctorDTOList[i % doctorDTOList.Count].ContactNumber, DateOfMetting = MeetingDate, Medicine = MedicineNames }; repSchedules.Add(singleSchedule); ScheduleStartDate = ScheduleStartDate.AddDays(1); } return(repSchedules); } } } catch (ArgumentException argumentException) { _log.Error(argumentException); throw; } catch (Exception e) { _log.Error(e); throw; } }