Esempio n. 1
0
        private static void ImportDoctorServices(ForeignDoctor foreignDoctor, List <DoctorService> doctorServices)
        {
            if (doctorServices == null)
            {
                return;
            }

            foreach (var doctorService in doctorServices)
            {
                var foreignDoctorService = foreignDoctor.ForeignDoctorServices
                                           .SingleOrDefault(ds => ds != null && ds.Id == doctorService.Id)
                                           ?? new ForeignDoctorService();

                foreignDoctorService.Id              = doctorService.Id;
                foreignDoctorService.Name            = doctorService.Name;
                foreignDoctorService.PriceMax        = doctorService.PriceMax;
                foreignDoctorService.PriceMin        = doctorService.PriceMin;
                foreignDoctorService.ServiceId       = doctorService.ServiceId;
                foreignDoctorService.ForeignDoctorId = foreignDoctor.Id;

                if (false == foreignDoctor.ForeignDoctorServices.Exists(fd => fd.Id == doctorService.Id))
                {
                    foreignDoctor.ForeignDoctorServices.Add(foreignDoctorService);
                }
            }
        }
Esempio n. 2
0
        private static void ClearLeftOverDoctorServices(ForeignDoctor foreignDoctor, List <DoctorService> doctorServices)
        {
            string[] validDoctorServiceIDs = doctorServices.Select(ds => ds.Id).ToArray();
            var      invalidDoctorServices = foreignDoctor.ForeignDoctorServices
                                             .Where(fds =>
                                                    false == validDoctorServiceIDs.Contains(fds.Id) &&
                                                    fds.ForeignDoctorId == foreignDoctor.Id
                                                    );

            string[] invalidIds = invalidDoctorServices
                                  .Select(ds => ds.Id)
                                  .ToArray();

            var invalidSchedules = db.DoctorSchedules.Where(ds => invalidIds.Contains(ds.ForeignDoctorServiceId));

            foreach (var schedule in invalidSchedules)
            {
                schedule.ForeignDoctorServiceId = null;
                schedule.ForeignDoctorService   = null;
            }

            db.DoctorMappings.RemoveRange(db.DoctorMappings.Where(dm => invalidIds.Contains(dm.ForeignDoctorServiceId)));
            db.ForeignDoctorServices.RemoveRange(invalidDoctorServices);
        }
Esempio n. 3
0
        private static void ImportAddresses(ForeignFacility foreignFacility, ForeignDoctor foreignDoctor, List <Address> addresses)
        {
            if (addresses == null)
            {
                return;
            }

            foreach (var address in addresses)
            {
                var foreignAddress = foreignFacility.ForeignAddresses
                                     .SingleOrDefault(fa => fa.Id == address.Id)
                                     ?? new ForeignAddress();

                foreignAddress.Id              = address.Id;
                foreignAddress.Name            = address.Name;
                foreignAddress.Street          = address.Street + " " + address.PostCode;
                foreignAddress.ForeignDoctor   = foreignDoctor;
                foreignAddress.ForeignFacility = foreignFacility;

                var extraFields = foreignAddress.BookingExtraFields ?? new Data.BookingExtraFields()
                {
                    ForeignAddressId = address.Id
                };

                extraFields.IsBirthDate = address.BookingExtraFields.IsBirthDateEnabled;
                extraFields.IsGender    = address.BookingExtraFields.IsGenderEnabled;
                extraFields.IsNin       = address.BookingExtraFields.IsNinEnabled;

                foreignAddress.BookingExtraFields = extraFields;

                if (false == foreignFacility.ForeignAddresses.Exists(fa => fa.Id == address.Id))
                {
                    foreignFacility.ForeignAddresses.Add(foreignAddress);
                }
            }
        }
Esempio n. 4
0
        private static void ImportSpecializations(DPCollection <REST.DTO.Specialization> specializations, ForeignDoctor foreignDoctor)
        {
            if (specializations == null)
            {
                return;
            }

            specializations
            .Items
            .Where(s => s.Id != null && s.Name != null)
            .ToList()
            .ForEach(s =>
            {
                var foreignSpecialization = foreignDoctor.ForeignSpecializations
                                            .SingleOrDefault(fs => fs.Id == s.Id && fs.ForeignDoctorId == foreignDoctor.Id)
                                            ?? new ForeignSpecialization();

                foreignSpecialization.ForeignDoctor = foreignDoctor;
                foreignSpecialization.Id            = s.Id;
                foreignSpecialization.Name          = s.Name;

                if (false == foreignDoctor.ForeignSpecializations.Exists(fs => fs.Id == s.Id))
                {
                    foreignDoctor.ForeignSpecializations.Add(foreignSpecialization);
                }
            });
        }
Esempio n. 5
0
        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
                    });
                }
            });
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        private static void ImportDoctorServices(ForeignDoctorServiceRepository doctorServiceRepo, DPDoctor dpDoctor, ForeignDoctor foreignDoctor, List <DoctorService> doctorServices)
        {
            if (doctorServices == null)
            {
                return;
            }

            foreach (var doctorService in doctorServices)
            {
                var foreignDoctorService = new ForeignDoctorService()
                {
                    Id              = doctorService.Id,
                    Name            = doctorService.Name,
                    PriceMax        = doctorService.PriceMax,
                    PriceMin        = doctorService.PriceMin,
                    ServiceId       = doctorService.ServiceId,
                    ForeignDoctorId = foreignDoctor.Id
                };

                doctorServiceRepo.InsertOrUpdate(foreignDoctorService);
            }
        }
Esempio n. 8
0
        private static void ImportAddresses(ForeignAddressRepository addressRepo, DPDoctor dpDoctor, ForeignFacility foreignFacility, ForeignDoctor foreignDoctor, List <Address> addresses)
        {
            if (addresses == null)
            {
                return;
            }

            foreach (var address in addresses)
            {
                var foreignAddress = new ForeignAddress()
                {
                    Id                 = address.Id,
                    Name               = address.Name,
                    Street             = address.Street + " " + address.PostCode,
                    BookingExtraFields = new Data.BookingExtraFields()
                    {
                        ForeignAddressId = address.Id,
                        IsBirthDate      = address.BookingExtraFields.IsBirthDateEnabled,
                        IsGender         = address.BookingExtraFields.IsGenderEnabled,
                        IsNin            = address.BookingExtraFields.IsNinEnabled
                    },
                    ForeignDoctorId   = foreignDoctor.Id,
                    ForeignFacilityId = foreignFacility.Id
                };

                addressRepo.InsertOrUpdate(foreignAddress);
            }
        }