Skip to content

Commit

Permalink
Merge pull request #329 from gaepdit/309-create-a-pending-report-and-…
Browse files Browse the repository at this point in the history
…add-a-button

Create Pending Report and add button on Facility Search page
  • Loading branch information
tom-karasch authored Feb 19, 2024
2 parents 1f9da0e + 7841bb3 commit a79ae76
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 23 deletions.
43 changes: 23 additions & 20 deletions FMS.Infrastructure/Repositories/FacilityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public async Task<FacilityDetailDto> GetFacilityAsync(Guid id)

var facilityDetail = new FacilityDetailDto(facility);

if(!facilityDetail.FileLabel.IsNullOrEmpty())
if (!facilityDetail.FileLabel.IsNullOrEmpty())
{
facilityDetail.Cabinets = (await _context.GetCabinetListAsync(false))
.GetCabinetsForFile(facilityDetail.FileLabel);
}
}

return facilityDetail;
}

Expand Down Expand Up @@ -133,7 +133,7 @@ public async Task<PaginatedList<FacilitySummaryDto>> GetFacilityPaginatedListAsy
{
bool test = item.FacilityType.Name != "RN" || !item.FileLabel.IsNullOrEmpty();

item.Cabinets = cabinets.GetCabinetsForFile(item.FileLabel, test);
item.Cabinets = cabinets.GetCabinetsForFile(item.FileLabel, test);
}

var totalCount = await queried.CountAsync();
Expand All @@ -158,10 +158,13 @@ public async Task<IReadOnlyList<FacilityDetailDto>> GetFacilityDetailListAsync(F

var items = await ordered.Select(e => new FacilityDetailDto(e)).ToListAsync();

var cabinets = await _context.GetCabinetListAsync(false);
foreach (var item in items)
{
item.Cabinets = cabinets.GetCabinetsForFile(item.FileLabel);
if (!spec.ShowPendingOnly)
{
var cabinets = await _context.GetCabinetListAsync(false);
foreach (var item in items)
{
item.Cabinets = cabinets.GetCabinetsForFile(item.FileLabel);
}
}

return items;
Expand All @@ -172,25 +175,25 @@ public async Task<IReadOnlyList<FacilityMapSummaryDto>> GetFacilityListAsync(Fac
var conn = _context.Database.GetDbConnection();

return (await conn.QueryAsync<FacilityMapSummaryDto>("dbo.getNearbyFacilities",
new {Active = !spec.ShowDeleted, spec.Latitude, spec.Longitude, spec.Radius, spec.FacilityTypeId },
new { Active = !spec.ShowDeleted, spec.Latitude, spec.Longitude, spec.Radius, spec.FacilityTypeId },
commandType: CommandType.StoredProcedure)).ToList();
}
}

public async Task<IEnumerable<RetentionRecordDetailDto>> GetRetentionRecordsListAsync(FacilitySpec spec)
{
var queried = QueryFacilities(spec);

var included = queried
.Include(e => e.RetentionRecords);

var ordered = OrderFacilityQuery(included, spec.SortBy);
// create a List<RetentionRecord>
var retentionRecordsList = await ordered.SelectMany(e => e.RetentionRecords).ToListAsync();
// convert the List<RetentionRecord> to IEnumerable<RetentionRecordDetailDto>
var returnList = from retentionRecord in retentionRecordsList
select new RetentionRecordDetailDto(retentionRecord);
var ordered = OrderFacilityQuery(included, spec.SortBy);

// create a List<RetentionRecord>
var retentionRecordsList = await ordered.SelectMany(e => e.RetentionRecords).ToListAsync();

// convert the List<RetentionRecord> to IEnumerable<RetentionRecordDetailDto>
var returnList = from retentionRecord in retentionRecordsList
select new RetentionRecordDetailDto(retentionRecord);

return returnList;
}
Expand Down Expand Up @@ -229,7 +232,7 @@ private async Task<Guid> CreateFacilityInternalAsync(FacilityCreateDto newFacili
else
{
// Otherwise, if File Label is provided, make sure it exists
file = await _context.Files.SingleOrDefaultAsync(e => e.FileLabel == newFacility.FileLabel );
file = await _context.Files.SingleOrDefaultAsync(e => e.FileLabel == newFacility.FileLabel);
if (file == null && newFileId) throw new ArgumentException($"File Label {newFacility.FileLabel} does not exist.");
}

Expand Down
41 changes: 41 additions & 0 deletions FMS/Helpers/FacilityPendingDtoScalar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using ClosedXML.Attributes;
using FMS.Domain.Dto;
using System;

namespace FMS.Helpers
{
public class FacilityPendingDtoScalar
{
public FacilityPendingDtoScalar(FacilityDetailDto facility)
{
FacilityNumber = facility.FacilityNumber.Substring(2);
Name = facility.Name;
OrganizationalUnit = facility.OrganizationalUnit?.Name;
HistoricalUnit = facility.HistoricalUnit;
ComplianceOfficer = facility.ComplianceOfficer?.Name;
RNDateReceived = facility.RNDateReceived;
Comments = facility.Comments;
}

[XLColumn(Header = "Facility Number")]
public string FacilityNumber { get; }

[XLColumn(Header = "Facility Name")]
public string Name { get; }

[XLColumn(Header = "Organizational Unit")]
public string OrganizationalUnit { get; }

[XLColumn(Header = "Compliance Officer")]
public string ComplianceOfficer { get; }

[XLColumn(Header = "Historical Unit")]
public string HistoricalUnit { get; set; }

[XLColumn(Header = "Date Received")]
public DateOnly? RNDateReceived { get; set; }

[XLColumn(Header = "Comments")]
public string Comments { get; set; }
}
}
8 changes: 6 additions & 2 deletions FMS/Pages/Facilities/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,15 @@
<input type="hidden" asp-for="Spec.SortBy" />
<button id="ExportButton" asp-page-handler="ExportButton"
class="btn btn-sm btn-outline-primary mb-1">
Export to Excel
Excel Export
</button>
<button id="PendingButton" asp-page-handler="PendingButton"
class="btn btn-sm btn-outline-primary mb-1 @(Model.ShowPendingOnly ? "" : "d-none")">
Pending Report
</button>
<button id="DownloadRetentionRecords" asp-page-handler="DownloadRetentionRecords"
class="btn btn-sm btn-outline-primary mb-1">
Download Retention Records
Retention Records Form
</button>
</form>
</div>
Expand Down
12 changes: 11 additions & 1 deletion FMS/Pages/Facilities/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using FMS.Domain.Dto.PaginatedList;
using FMS.Domain.Repositories;
using FMS.Domain.Services;
using FMS.Helpers;
using FMS.Platform.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
Expand Down Expand Up @@ -84,7 +85,16 @@ public async Task<IActionResult> OnPostExportButtonAsync()
var facilityDetailList = from p in facilityReportList select new FacilityDetailDtoScalar(p);
return File(facilityDetailList.ExportExcelAsByteArray(), "application/vnd.ms-excel", fileName);
}


public async Task<IActionResult> OnPostPendingButtonAsync()
{
var fileName = $"FMS_PendingRN_export_{DateTime.Now:yyyy-MM-dd-HH-mm-ss.FFF}.xlsx";
// "FacilityPendingList" Detailed Facility List to go to a report
IReadOnlyList<FacilityDetailDto> facilityReportList = await _repository.GetFacilityDetailListAsync(Spec);
var facilityDetailList = from p in facilityReportList select new FacilityPendingDtoScalar(p);
return File(facilityDetailList.ExportExcelAsByteArray(), "application/vnd.ms-excel", fileName);
}

public async Task<IActionResult> OnPostDownloadRetentionRecordsAsync()
{
var currentUser = await _userService.GetCurrentUserAsync();
Expand Down
2 changes: 2 additions & 0 deletions FMS/wwwroot/js/formSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ $(document).ready(function formSearch() {
$("#Spec_FacilityTypeId").on("change", function () {
if ($("#Spec_FacilityTypeId option:selected").text().trim() === "RN (Release Notification)") {
$("#RNBlock").removeClass("d-none");
$("#RNPending").removeClass("d-none");
} else {
$("#RNBlock").addClass("d-none");
$("#RNPending").addClass("d-none");
$("#Spec_ShowPendingOnly").prop("checked",false)
}
});
Expand Down

0 comments on commit a79ae76

Please sign in to comment.