public async Task <IActionResult> Excel(ProtocolDrugTherapySearch search, int page = 1) { try { ProtocolDrugTherapyWhereBuilder protocolDrugTherapyWhereBuilder = new ProtocolDrugTherapyWhereBuilder(search); string searchParams = search != default ? search.ToString() : default; List <ProtocolDrugTherapyPreviewViewModel> protocolDrugTherapies = await GetPage(search, protocolDrugTherapyWhereBuilder, searchParams, page); if (protocolDrugTherapies == default) { return(BadRequest()); } return(await base.FormatModel <ProtocolDrugTherapyPreviewViewModel>(protocolDrugTherapies, MedicDataLocalization.ProtocolDrugTherapies, 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; } }
private async Task <List <ProtocolDrugTherapyPreviewViewModel> > GetPage(ProtocolDrugTherapySearch search, ProtocolDrugTherapyWhereBuilder protocolDrugTherapyWhereBuilder, string searchParams, int page) { int pageLength = (int)search.Length; int startIndex = base.GetStartIndex(pageLength, page); string protocolDrugTherapiesKey = $"{nameof(ProtocolDrugTherapyPreviewViewModel)} - {startIndex} - {searchParams}"; if (!base.MedicCache.TryGetValue(protocolDrugTherapiesKey, out List <ProtocolDrugTherapyPreviewViewModel> protocolDrugTherapies)) { ProtocolDrugTherapyHelperBuilder helperBuilder = new ProtocolDrugTherapyHelperBuilder(search); protocolDrugTherapies = await ProtocolDrugTherapyService .GetProtocolDrugTherapiesAsync(protocolDrugTherapyWhereBuilder, helperBuilder, startIndex); base.MedicCache.Set(protocolDrugTherapiesKey, protocolDrugTherapies); } return(protocolDrugTherapies); }
public async Task <IActionResult> Index(ProtocolDrugTherapySearch search, int page = 1) { try { ProtocolDrugTherapyWhereBuilder protocolDrugTherapyWhereBuilder = new ProtocolDrugTherapyWhereBuilder(search); string searchParams = search != default ? search.ToString() : default; List <ProtocolDrugTherapyPreviewViewModel> protocolDrugTherapies = await GetPage(search, protocolDrugTherapyWhereBuilder, searchParams, page); string protocolDrugTherapiesCountKey = $"{MedicConstants.ProtocolDrugTherapies} - {searchParams}"; if (!base.MedicCache.TryGetValue(protocolDrugTherapiesCountKey, out int protocolDrugTherapiesCount)) { protocolDrugTherapiesCount = await ProtocolDrugTherapyService .GetProtocolDrugTherapiesCountAsync(protocolDrugTherapyWhereBuilder); base.MedicCache.Set(protocolDrugTherapiesCountKey, protocolDrugTherapiesCount); } List <string> atcNames = new List <string>() { default }; if (!base.MedicCache.TryGetValue(MedicConstants.AtcNames, out List <string> addedAtcNames)) { addedAtcNames = await DrugProtocolService.GetDrugProtocolATCNames(); addedAtcNames.Sort((x, y) => x.CompareTo(y)); base.MedicCache.Set(MedicConstants.AtcNames, addedAtcNames); } atcNames.AddRange(addedAtcNames); List <SexOption> sexOptions = base.GetDefaultSexes(); sexOptions.AddRange(await base.GetSexesAsync()); List <HealthRegionOption> healthRegions = base.GetDefaultHealthRegions(); healthRegions.AddRange(await base.GetHealthRegionsAsync()); return(View(new ProtocolDrugTherapyPageIndexModel() { ProtocolDrugTherapies = protocolDrugTherapies, Title = MedicDataLocalization.Get(MedicDataLocalization.ProtocolDrugTherapies), Description = MedicDataLocalization.Get(MedicDataLocalization.ProtocolDrugTherapies), Keywords = MedicDataLocalization.Get(MedicDataLocalization.ProtocolDrugTherapiesSummary), Search = search, CurrentPage = page, TotalPages = base.TotalPages((int)search.Length, protocolDrugTherapiesCount), TotalResults = protocolDrugTherapiesCount, Sexes = sexOptions, HealthRegions = healthRegions, ATCNames = atcNames })); } 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; } }
public ProtocolDrugTherapyHelperBuilder(ProtocolDrugTherapySearch protocolDrugTherapySearch) { ProtocolDrugTherapySearch = protocolDrugTherapySearch; }
public ProtocolDrugTherapyWhereBuilder(ProtocolDrugTherapySearch protocolDrugTherapySearch) { ProtocolDrugTherapySearch = protocolDrugTherapySearch; }