Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

                ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
                configurationBuilder.AddUserSecrets <Program>();
                configurationBuilder.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"));

                IConfigurationRoot configuration = configurationBuilder.Build();

                DbContextOptionsBuilder <MedicContext> builder = new DbContextOptionsBuilder <MedicContext>();
                builder.UseSqlServer(configuration[Constants.ConnectionString]);
                builder.EnableSensitiveDataLogging();

                using MedicContext context = new MedicContext(builder.Options);
                IMedicContextSeeder medicContextSeeder = new MedicContextSeeder(context);
                medicContextSeeder.Seed();

                AMapperConfiguration mapConfiguration = new AMapperConfiguration();
                IMappable            mapper           = new AMapper(mapConfiguration.CreateConfiguration());

                string cpDirectory, clprDirectory;
                bool   doesCpDirectoryExist = true, doesCLPRDirectoryExist = true;

                while (true)
                {
                    consoleWriter.Notify("Enter directory for CP files");
                    cpDirectory = consoleReader.Read();
                    consoleWriter.Notify("Enter directory for CLPR files");
                    clprDirectory = consoleReader.Read();

                    if (!string.IsNullOrWhiteSpace(cpDirectory))
                    {
                        doesCpDirectoryExist = Directory.Exists(cpDirectory);
                    }

                    if (!string.IsNullOrWhiteSpace(clprDirectory))
                    {
                        doesCLPRDirectoryExist = Directory.Exists(clprDirectory);
                    }

                    if (doesCpDirectoryExist && doesCLPRDirectoryExist)
                    {
                        break;
                    }
                    else
                    {
                        if (!doesCpDirectoryExist)
                        {
                            consoleWriter.Notify("CP directory does not exist.");
                        }

                        if (!doesCLPRDirectoryExist)
                        {
                            consoleWriter.Notify("CLPR directory does not exist.");
                        }
                    }

                    doesCpDirectoryExist   = true;
                    doesCLPRDirectoryExist = true;
                }

                if (!string.IsNullOrWhiteSpace(cpDirectory))
                {
                    ReadCpFiles(mapper, builder, cpDirectory);
                }

                if (!string.IsNullOrWhiteSpace(clprDirectory))
                {
                    ReadCLPRFiles(mapper, builder, clprDirectory);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            consoleWriter.Notify("Press any key to exit.");
            Console.ReadKey();
        }
        public static IServiceCollection ConfigureServices(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment)
        {
            if (configuration == default)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (environment == default)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            services.AddTransient <IMappable, AMapper>();

            services.AddDbContext <MedicContext>(options =>
            {
                options.UseSqlServer(configuration[Constants.ConnectionString]);
            });

            services.AddDbContext <MedicIdentityContext>((DbContextOptionsBuilder options) =>
            {
                options.UseSqlServer(configuration[Constants.IdentityConnectionString]);
            });

            services.AddTransient <IMedicContext, MedicContext>();

            services.AddTransient <IMedicContextSeeder, Seeder.MedicContextSeeder>();

            services.AddIdentity <IdentityUser, IdentityRole>(options =>
            {
                options.Password.RequireDigit           = true;
                options.Password.RequiredLength         = 10;
                options.Password.RequireLowercase       = true;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = true;
            })
            .AddEntityFrameworkStores <MedicIdentityContext>();

            services.AddTransient <ICPFileService, CPFileService>();
            services.AddTransient <IDiagnoseService, DiagnoseService>();
            services.AddTransient <IDiagService, DiagService>();
            services.AddTransient <IHospitalPracticeService, HospitalPracticeService>();
            services.AddTransient <IPatientService, PatientService>();
            services.AddTransient <IInService, InService>();
            services.AddTransient <IOutService, OutService>();
            services.AddTransient <IUsedDrugService, UsedDrugService>();
            services.AddTransient <IInClinicProcedureService, InClinicProcedureService>();
            services.AddTransient <IPathProcedureService, PathProcedureService>();
            services.AddTransient <IHealthRegionService, HealthRegionService>();
            services.AddTransient <IProtocolDrugTherapyService, ProtocolDrugTherapyService>();
            services.AddTransient <ICommissionAprService, CommissionAprService>();
            services.AddTransient <IDispObservationService, DispObservationService>();
            services.AddTransient <IPlannedService, PlannedService>();
            services.AddTransient <IClinicUsedDrugsService, ClinicUsedDrugsService>();
            services.AddTransient <IDrugProtocolService, DrugProtocolService>();
            services.AddTransient <ITransferService, TransferService>();

            services.AddTransient <IImportMedicFile, ImportMedicFile>();
            services.AddTransient <IGetXmlParameters, GetXmlParameters>();

            services.AddTransient <PatientLocalization>();
            services.AddTransient <MedicDataLocalization>();
            services.AddTransient <GeneralLocalization>();

            services.BuildServiceProvider().GetRequiredService <MedicContext>();

            AMapperConfiguration mapConfiguration = new AMapperConfiguration();

            services.AddSingleton <MapperConfiguration>(mapConfiguration.CreateConfiguration());
            services.AddSingleton <ICacheable>(new MedicCache());

            services.AddTransient <IMedicXmlParser, DefaultMedicXmlParser>();

            services.AddTransient <IEHRManager, EHRManager>();

            services.AddTransient <IToEHRConverter, ToEHRConverter>();

            services.AddTransient <IFormattableFactory, FormatterFactory>();

            services.AddDbContext <MedicLoggerContext>(options =>
            {
                options.UseSqlite($"Data Source={Path.Combine(environment.ContentRootPath, "Logs\\Logs.sqlite")}");
            });

            services.AddTransient <IMedicLoggerContext, MedicLoggerContext>();

            services.AddTransient <IMedicLoggerService, MedicLoggerService>();

            services.AddTransient <IEnumResolver, EnumResolver>();

            services.Configure <IISOptions>(options =>
            {
                options.ForwardClientCertificate = false;
            });

            ServiceProvider serviceProvider = services.BuildServiceProvider();

            MedicContextSeeder medicContextSeeder = new MedicContextSeeder(
                serviceProvider.GetRequiredService <MedicIdentityContext>(),
                serviceProvider.GetRequiredService <UserManager <IdentityUser> >(),
                serviceProvider.GetRequiredService <RoleManager <IdentityRole> >());

            medicContextSeeder.Seed(new List <(string username, string password, string email)>()
            {
                (
                    configuration[MC.MedicConstants.AdministratorName],
                    configuration[MC.MedicConstants.AdministratorPassword],
                    configuration[MC.MedicConstants.AdministratorEmail]
                )
            });

            serviceProvider.GetRequiredService <MedicLoggerContext>().Database.EnsureCreated();

            serviceProvider.GetRequiredService <IMedicContextSeeder>().Seed();

            return(services);
        }