private static void ImportSpecializations(ForeignSpecializationRepository repo, DPDoctor dpDoctor, ForeignDoctor foreignDoctor) { if (dpDoctor.Specializations == null) { return; } dpDoctor.Specializations .Items .ForEach(ds => { if (ds.Id != null && ds.Name != null) { repo.InsertOrUpdate(new ForeignSpecialization() { ForeignDoctorId = foreignDoctor.Id, Id = ds.Id, Name = ds.Name }); } }); }
static void Main(string[] args) { string clientId = AppSettings.ClientId; string clientSecret = AppSettings.ClientSecret; string locale = AppSettings.Locale; bool shouldExit = false; HospitalContext myDb = new HospitalContext(); var facilityRepo = new ForeignFacilityRepository(myDb); var doctorRepo = new ForeignDoctorRepository(myDb); var addressRepo = new ForeignAddressRepository(myDb); var specializationRepo = new ForeignSpecializationRepository(myDb); var doctorServiceRepo = new ForeignDoctorServiceRepository(myDb); var client = new DpApi(clientId, clientSecret, (Locale)locale); var facilities = client.GetFacilities(); foreach (var facility in facilities) { Console.WriteLine($"IMPORTING FACILITY: {facility.Name}\n"); var foreignFacility = new ForeignFacility() { Id = facility.Id, Name = facility.Name }; facilityRepo.InsertOrUpdate(foreignFacility); var dpDoctors = new List <DPDoctor>(client.GetDoctors(facility.Id, true)); Console.WriteLine("DOCTORS:"); foreach (var dpDoctor in dpDoctors) { Console.WriteLine($"-> {dpDoctor.Name} {dpDoctor.Surname} (ID:{dpDoctor.Id})"); var foreignDoctor = new ForeignDoctor() { Id = dpDoctor.Id, Name = dpDoctor.Name, Surname = dpDoctor.Surname }; var tempDoctor = client.GetDoctor(facility.Id, dpDoctor.Id); Console.WriteLine("---> IMPORTING SPECIZALIZATIONS"); ImportSpecializations(specializationRepo, tempDoctor, foreignDoctor); var addresses = client.GetAddresses(facility.Id, dpDoctor.Id); Console.WriteLine("---> IMPORTING ADDRESSES"); ImportAddresses(addressRepo, dpDoctor, foreignFacility, foreignDoctor, addresses); var doctorServices = client.GetDoctorServices(facility.Id, dpDoctor.Id); Console.WriteLine("---> IMPORTING DOCTOR SERVICES"); ImportDoctorServices(doctorServiceRepo, dpDoctor, foreignDoctor, doctorServices); doctorRepo.InsertOrUpdate(foreignDoctor); Console.WriteLine(); } } doctorRepo.Save(); Console.WriteLine("DONE"); if (shouldExit == false) { Console.ReadLine(); } }