Exemplo n.º 1
0
        public async Task <IActionResult> Excel(PathProcedureSearch search, int page = 1)
        {
            try
            {
                PathProcedureWhereBuilder pathProcedureWhereBuilder = new PathProcedureWhereBuilder(search);

                string searchParams = search != default ? search.ToString() : default;

                List <PathProcedurePreviewViewModel> pathProcedures = await GetPage(search, pathProcedureWhereBuilder, searchParams, page);

                if (pathProcedures == default)
                {
                    return(BadRequest());
                }

                return(await base.FormatModel <PathProcedurePreviewViewModel>(pathProcedures, MedicDataLocalization.PathProcedures, FormattableFactory));
            }
            catch (Exception ex)
            {
                Task <int> _ = MedicLoggerService.SaveAsync(new Log()
                {
                    Message = ex.Message,
                    InnerExceptionMessage = ex?.InnerException?.Message ?? null,
                    Source     = ex.Source,
                    StackTrace = ex.StackTrace,
                    Date       = DateTime.Now
                });

                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(PathProcedureSearch search, int page = 1)
        {
            try
            {
                PathProcedureWhereBuilder pathProcedureWhereBuilder = new PathProcedureWhereBuilder(search);

                string searchParams = search != default ? search.ToString() : default;

                List <PathProcedurePreviewViewModel> pathProcedures = await GetPage(search, pathProcedureWhereBuilder, searchParams, page);

                string pathProceduresCountKey = $"{MedicConstants.PathProcedures} - {searchParams}";

                if (!base.MedicCache.TryGetValue(pathProceduresCountKey, out int pathProceduresCount))
                {
                    pathProceduresCount = await PathProcedureService
                                          .GetPathProceduresCountAsync(pathProcedureWhereBuilder);

                    base.MedicCache.Set(pathProceduresCountKey, pathProceduresCount);
                }

                List <SexOption> sexOptions = base.GetDefaultSexes();
                sexOptions.AddRange(await base.GetSexesAsync());

                List <HealthRegionOption> healthRegions = base.GetDefaultHealthRegions();
                healthRegions.AddRange(await base.GetHealthRegionsAsync());

                if (!base.MedicCache.TryGetValue(MedicConstants.ClinicUsedDrugsCode, out List <string> usedDrugs))
                {
                    usedDrugs = await ClinicUsedDrugsService.GetDrugCodesAsync();

                    usedDrugs.Sort((x, y) => x.CompareTo(y));

                    base.MedicCache.Set(MedicConstants.ClinicUsedDrugsCode, usedDrugs);
                }

                List <string> usedDrugCodes = new List <string>()
                {
                    default
                };

                usedDrugCodes.AddRange(usedDrugs);

                return(View(new PathProcedurePageIndexModel()
                {
                    PathProcedures = pathProcedures,
                    Title = MedicDataLocalization.Get(MedicDataLocalization.PathProcedures),
                    Description = MedicDataLocalization.Get(MedicDataLocalization.PathProcedures),
                    Keywords = MedicDataLocalization.Get(MedicDataLocalization.PathProceduresSummary),
                    Search = search,
                    CurrentPage = page,
                    TotalPages = base.TotalPages((int)search.Length, pathProceduresCount),
                    TotalResults = pathProceduresCount,
                    Sexes = sexOptions,
                    HealthRegions = healthRegions,
                    UsedDrugCodes = usedDrugCodes
                }));
            }
            catch (Exception ex)
            {
                Task <int> _ = MedicLoggerService.SaveAsync(new Log()
                {
                    Message = ex.Message,
                    InnerExceptionMessage = ex?.InnerException?.Message ?? null,
                    Source     = ex.Source,
                    StackTrace = ex.StackTrace,
                    Date       = DateTime.Now
                });

                throw ex;
            }
        }