From b03140f20d9e5c953c274b67b85ab77fc45b0f72 Mon Sep 17 00:00:00 2001 From: Ashley Wilson Date: Thu, 29 Aug 2024 09:03:47 -0400 Subject: [PATCH] Add capability to export to csv --- .../UDS.Net.Forms.Tests.csproj | 2 +- .../Extensions/DomainToViewModelMapper.cs | 61 ++++++++++++++ .../Extensions/ViewModelToDomainMapper.cs | 6 ++ .../PacketSubmissionErrorsPaginatedModel.cs | 11 +++ .../Models/PacketSubmissionModel.cs | 28 ++++++- .../Models/PacketSubmissionsPaginatedModel.cs | 10 +++ .../PageModels/PacketSubmissionPageModel.cs | 48 +++++++++++ src/UDS.Net.Forms/Models/PaginatedModel.cs | 2 +- .../Pages/PacketSubmissions/Create.cshtml | 33 +++++++- .../Pages/PacketSubmissions/Create.cshtml.cs | 82 ++++++++++++++++++- .../Pages/PacketSubmissions/Details.cshtml | 5 ++ .../Pages/PacketSubmissions/Details.cshtml.cs | 18 ++++ .../Pages/PacketSubmissions/Edit.cshtml | 4 +- .../Pages/PacketSubmissions/Edit.cshtml.cs | 10 ++- .../Pages/PacketSubmissions/Export.cshtml | 8 +- .../Pages/PacketSubmissions/Export.cshtml.cs | 55 ++++++++++++- .../Pages/PacketSubmissions/Index.cshtml | 56 +++++++++++++ .../Pages/PacketSubmissions/Index.cshtml.cs | 26 ++++-- .../Pages/Participations/Create.cshtml.cs | 2 +- .../Pages/Participations/Details.cshtml | 2 +- .../Pages/Visits/Finalize.cshtml | 82 ++++++++++++++++--- src/UDS.Net.Forms/UDS.Net.Forms.csproj | 9 +- .../UDS.Net.Services.Test.csproj | 2 +- .../Submission/PacketSubmission.cs | 7 +- .../Extensions/DtoToDomainMapper.cs | 4 +- src/UDS.Net.Services/IVisitService.cs | 2 +- src/UDS.Net.Services/UDS.Net.Services.csproj | 6 +- .../UDS.Net.Web.MVC.Services.csproj | 8 +- src/UDS.Net.Web.MVC.Services/VisitService.cs | 8 +- src/UDS.Net.Web.MVC/Program.cs | 1 + src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj | 6 +- src/UDS.Net.sln | 12 +-- 32 files changed, 550 insertions(+), 66 deletions(-) create mode 100644 src/UDS.Net.Forms/Models/PacketSubmissionErrorsPaginatedModel.cs create mode 100644 src/UDS.Net.Forms/Models/PacketSubmissionsPaginatedModel.cs create mode 100644 src/UDS.Net.Forms/Models/PageModels/PacketSubmissionPageModel.cs create mode 100644 src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml create mode 100644 src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml.cs diff --git a/src/UDS.Net.Forms.Tests/UDS.Net.Forms.Tests.csproj b/src/UDS.Net.Forms.Tests/UDS.Net.Forms.Tests.csproj index 7ccbd54b..c831c00f 100644 --- a/src/UDS.Net.Forms.Tests/UDS.Net.Forms.Tests.csproj +++ b/src/UDS.Net.Forms.Tests/UDS.Net.Forms.Tests.csproj @@ -5,7 +5,7 @@ enable enable false - 4.1.0-preview.1 + 4.1.0-preview.2 diff --git a/src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs b/src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs index b750c50d..e400d33f 100644 --- a/src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs +++ b/src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs @@ -3,6 +3,7 @@ using UDS.Net.Forms.Models.UDS4; using UDS.Net.Services.DomainModels; using UDS.Net.Services.DomainModels.Forms; +using UDS.Net.Services.DomainModels.Submission; using UDS.Net.Services.Enums; using UDS.Net.Services.LookupModels; @@ -68,6 +69,66 @@ public static VisitModel ToVM(this Visit visit) }; } + public static PacketSubmissionsModel ToVM(this IEnumerable packetSubmissions) + { + PacketSubmissionsModel vm = new PacketSubmissionsModel(); + + if (packetSubmissions != null) + { + foreach (var packetSubmission in packetSubmissions) + { + vm.List.Add(packetSubmission.ToVM()); + } + } + + return vm; + } + + public static PacketSubmissionModel ToVM(this PacketSubmission packetSubmission) + { + PacketSubmissionModel vm = new PacketSubmissionModel(); + + if (packetSubmission != null) + { + vm.Id = packetSubmission.Id; + vm.SubmissionDate = packetSubmission.SubmissionDate; + vm.CreatedAt = packetSubmission.CreatedAt; + vm.CreatedBy = packetSubmission.CreatedBy; + vm.ModifiedBy = packetSubmission.ModifiedBy; + vm.ErrorCount = packetSubmission.ErrorCount; + + if (packetSubmission.Errors != null) + { + vm.Errors = packetSubmission.Errors.ToVM(); + } + } + + return vm; + } + + public static PacketSubmissionErrorsPaginatedModel ToVM(this List packetSubmissionErrors) + { + PacketSubmissionErrorsPaginatedModel vm = new PacketSubmissionErrorsPaginatedModel(); + + if (packetSubmissionErrors != null) + { + foreach (var error in packetSubmissionErrors) + { + vm.List.Add(error.ToVM()); + } + } + + return vm; + } + + public static PacketSubmissionErrorModel ToVM(this PacketSubmissionError packetSubmissionError) + { + return new PacketSubmissionErrorModel + { + // TODO error model properties + }; + } + public static MilestoneModel ToVM(this Milestone milestone) { return new MilestoneModel() diff --git a/src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs b/src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs index 7a67e46c..69d9c1a0 100644 --- a/src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs +++ b/src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs @@ -4,6 +4,7 @@ using UDS.Net.Forms.Models.UDS4; using UDS.Net.Services.DomainModels; using UDS.Net.Services.DomainModels.Forms; +using UDS.Net.Services.DomainModels.Submission; namespace UDS.Net.Forms.Extensions { @@ -75,6 +76,11 @@ public static Visit ToEntity(this VisitModel vm) return new Visit(vm.Id, vm.VISITNUM, vm.ParticipationId, vm.FORMVER, vm.PACKET, vm.VISIT_DATE, vm.INITIALS, vm.Status, vm.CreatedAt, vm.CreatedBy, vm.ModifiedBy, vm.DeletedBy, vm.IsDeleted, vm.Forms.ToEntity()); } + public static PacketSubmission ToEntity(this PacketSubmissionModel vm) + { + return new PacketSubmission(vm.Id, vm.SubmissionDate, vm.VisitId, vm.CreatedAt, vm.CreatedBy, vm.ModifiedBy, "", false, 0); + } + public static List
ToEntity(this IList vm) { return vm.Select(v => v.ToEntity()).ToList(); diff --git a/src/UDS.Net.Forms/Models/PacketSubmissionErrorsPaginatedModel.cs b/src/UDS.Net.Forms/Models/PacketSubmissionErrorsPaginatedModel.cs new file mode 100644 index 00000000..49564d61 --- /dev/null +++ b/src/UDS.Net.Forms/Models/PacketSubmissionErrorsPaginatedModel.cs @@ -0,0 +1,11 @@ +using System; +namespace UDS.Net.Forms.Models +{ + public class PacketSubmissionErrorsPaginatedModel : PaginatedModel + { + public int PacketSubmissionId { get; set; } + + public List List { get; set; } = new List(); + } +} + diff --git a/src/UDS.Net.Forms/Models/PacketSubmissionModel.cs b/src/UDS.Net.Forms/Models/PacketSubmissionModel.cs index 5faf8738..cc0bf449 100644 --- a/src/UDS.Net.Forms/Models/PacketSubmissionModel.cs +++ b/src/UDS.Net.Forms/Models/PacketSubmissionModel.cs @@ -1,10 +1,34 @@ -using System; +using System.ComponentModel.DataAnnotations; +using UDS.Net.Services.DomainModels; +using UDS.Net.Services.DomainModels.Submission; + namespace UDS.Net.Forms.Models { public class PacketSubmissionModel { + public int Id { get; set; } + + public int VisitId { get; set; } + + [Required] + [Display(Name = "Submission date")] + public DateTime SubmissionDate { get; set; } + + [Required] + public DateTime CreatedAt { get; set; } + + [Required] + public string CreatedBy { get; set; } = ""; + + public string? ModifiedBy { get; set; } + + public int ErrorCount { get; set; } = 0; - public virtual IList Errors { get; set; } = new List(); + public virtual PacketSubmissionErrorsPaginatedModel Errors { get; set; } = new PacketSubmissionErrorsPaginatedModel(); + public string GetFileName(string participantLegacyId, DateTime visitDate) + { + return $"UDS_{participantLegacyId}_{visitDate.Year}_EXPORTED_{SubmissionDate.ToFileTime()}.csv"; + } } } diff --git a/src/UDS.Net.Forms/Models/PacketSubmissionsPaginatedModel.cs b/src/UDS.Net.Forms/Models/PacketSubmissionsPaginatedModel.cs new file mode 100644 index 00000000..08d75ed1 --- /dev/null +++ b/src/UDS.Net.Forms/Models/PacketSubmissionsPaginatedModel.cs @@ -0,0 +1,10 @@ +using System; +namespace UDS.Net.Forms.Models +{ + public class PacketSubmissionsModel + { + public bool CanCreateNewSubmission { get; set; } = false; + public List List { get; set; } = new List(); + } +} + diff --git a/src/UDS.Net.Forms/Models/PageModels/PacketSubmissionPageModel.cs b/src/UDS.Net.Forms/Models/PageModels/PacketSubmissionPageModel.cs new file mode 100644 index 00000000..ae56f22c --- /dev/null +++ b/src/UDS.Net.Forms/Models/PageModels/PacketSubmissionPageModel.cs @@ -0,0 +1,48 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using UDS.Net.Forms.Extensions; +using UDS.Net.Services; + +namespace UDS.Net.Forms.Models.PageModels +{ + public class PacketSubmissionPageModel : PageModel + { + protected readonly IVisitService _visitService; + protected readonly IPacketSubmissionService _packetSubmissionService; + + [BindProperty] + public PacketSubmissionModel? PacketSubmission { get; set; } + + public VisitModel? Visit { get; set; } + + public PacketSubmissionPageModel(IVisitService visitService, IPacketSubmissionService packetSubmissionService) : base() + { + _visitService = visitService; + _packetSubmissionService = packetSubmissionService; + } + + public async Task OnGetAsync(int? id) + { + if (id == null || id == 0) + return NotFound(); + + var packetSubmission = await _packetSubmissionService.GetById("", id.Value); + + if (packetSubmission == null) + return NotFound(); + + PacketSubmission = packetSubmission.ToVM(); + + var visit = await _visitService.GetById("", packetSubmission.VisitId); + + if (visit == null) + return NotFound(); + + Visit = visit.ToVM(); + + return Page(); + } + } +} + diff --git a/src/UDS.Net.Forms/Models/PaginatedModel.cs b/src/UDS.Net.Forms/Models/PaginatedModel.cs index 52306ae3..832ab2d7 100644 --- a/src/UDS.Net.Forms/Models/PaginatedModel.cs +++ b/src/UDS.Net.Forms/Models/PaginatedModel.cs @@ -50,7 +50,7 @@ public int CurrentPageEnd } } - public string Search { get; set; } + public string Search { get; set; } = ""; public string Action { get; set; } = "Index"; public int? Id { get; set; } = null; // sometimes the paginated list is a child of the current object, do we might need an id } diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml b/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml index 59a73254..36ddea34 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml @@ -1,4 +1,35 @@ -@page +@page "{id:int?}" +@model UDS.Net.Forms.Pages.PacketSubmissions.CreateModel @{ + ViewData["Title"] = "Create packet submission"; } +
+ +
+
+
+ +
+
+ +
+

Clicking "Yes" will download the .csv file to your computer.

+
+
+
+
+ + + + + + Cancel +
+
+ + + +
\ No newline at end of file diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml.cs index 285046b9..dd4b106c 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml.cs @@ -1,10 +1,88 @@ using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using UDS.Net.Forms.Extensions; +using UDS.Net.Forms.Models; +using UDS.Net.Forms.Models.PageModels; +using UDS.Net.Services; +using UDS.Net.Services.DomainModels; + namespace UDS.Net.Forms.Pages.PacketSubmissions { - public class Create + public class CreateModel : PageModel { - public Create() + protected readonly IVisitService _visitService; + protected readonly IParticipationService _participationService; + protected readonly IPacketSubmissionService _packetSubmissionService; + + [BindProperty] + public PacketSubmissionModel? PacketSubmission { get; set; } + + public VisitModel? Visit { get; set; } + + public string PageTitle + { + get + { + if (Visit != null) + { + return $"Participant {Visit.Participation.LegacyId} Visit {Visit.VISITNUM} Packet Submissions"; + } + return ""; + } + } + + public CreateModel(IVisitService visitService, IParticipationService participationService, IPacketSubmissionService packetSubmissionService) + { + _visitService = visitService; + _participationService = participationService; + _packetSubmissionService = packetSubmissionService; + } + + public async Task OnGetAsync(int? visitId) + { + if (visitId == null || visitId == 0) + return NotFound(); + + var visit = await _visitService.GetById("", visitId.Value); + + if (visit == null) + return NotFound(); + + var participation = await _participationService.GetById("", visit.ParticipationId); + + if (participation == null) + return NotFound(); + + Visit = visit.ToVM(); + + Visit.Participation = participation.ToVM(); + + PacketSubmission = new PacketSubmissionModel + { + VisitId = visit.Id, + SubmissionDate = DateTime.Now, + CreatedAt = DateTime.UtcNow, + CreatedBy = User.Identity.IsAuthenticated ? User.Identity.Name : "Username" + }; + + return Page(); + } + + public async Task OnPostAsync() { + if (!ModelState.IsValid) + return Page(); + + try + { + // TODO add isn't working yet + await _packetSubmissionService.Add(User.Identity.IsAuthenticated ? User.Identity.Name : "Username", PacketSubmission.ToEntity()); + } + catch (Exception ex) + { + } + return RedirectToPage("./Index", new { VisitId = PacketSubmission.VisitId }); } } } diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml b/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml new file mode 100644 index 00000000..e8e29c9c --- /dev/null +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml @@ -0,0 +1,5 @@ +@page +@model UDS.Net.Forms.Pages.PacketSubmissions.DetailsModel +@{ +} + diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml.cs new file mode 100644 index 00000000..fd1435a5 --- /dev/null +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using UDS.Net.Forms.Models.PageModels; +using UDS.Net.Services; + +namespace UDS.Net.Forms.Pages.PacketSubmissions +{ + public class DetailsModel : PacketSubmissionPageModel + { + public DetailsModel(IVisitService visitService, IPacketSubmissionService packetSubmissionService) : base(visitService, packetSubmissionService) + { + } + } +} diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml b/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml index 59a73254..f0a38660 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml @@ -1,4 +1,6 @@ -@page +@page "{id:int?}" +@model UDS.Net.Forms.Pages.PacketSubmissions.EditModel @{ + ViewData["Title"] = "Edit packet submission"; } diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml.cs index 83ac3264..ba818c88 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml.cs @@ -1,9 +1,15 @@ using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using UDS.Net.Forms.Models; +using UDS.Net.Forms.Models.PageModels; +using UDS.Net.Services; + namespace UDS.Net.Forms.Pages.PacketSubmissions { - public class Edit + public class EditModel : PacketSubmissionPageModel { - public Edit() + public EditModel(IVisitService visitService, IPacketSubmissionService packetSubmissionService) : base(visitService, packetSubmissionService) { } } diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml b/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml index 59a73254..1dfa3b9f 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml @@ -1,4 +1,10 @@ -@page +@page "{id:int?}" +@model UDS.Net.Forms.Pages.PacketSubmissions.ExportModel @{ + ViewData["Title"] = "Export packet submission"; } +@if (Model.Processed) +{ + +} \ No newline at end of file diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml.cs index f74a8568..5a9b329d 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml.cs @@ -1,10 +1,61 @@ using System; +using System.Formats.Asn1; +using System.Globalization; +using System.Text; +using CsvHelper; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using UDS.Net.Forms.Extensions; +using UDS.Net.Forms.Models; +using UDS.Net.Forms.Models.PageModels; +using UDS.Net.Services; + namespace UDS.Net.Forms.Pages.PacketSubmissions { - public class Export + public class ExportModel : PageModel { - public Export() + protected readonly IVisitService _visitService; + protected readonly IPacketSubmissionService _packetSubmissionService; + protected readonly IParticipationService _participationService; + + public bool Processed { get; set; } = false; + + public ExportModel(IVisitService visitService, IPacketSubmissionService packetSubmissionService, IParticipationService participationService) + { + _visitService = visitService; + _packetSubmissionService = packetSubmissionService; + _participationService = participationService; + } + + public async Task OnGetAsync(int id) { + if (id == 0) + return NotFound(); + + // TODO use temporal tables to get the data at that point in time of the submission + var packetSubmission = await _packetSubmissionService.GetById(User.Identity.Name, id); + + var visit = await _visitService.GetById(User.Identity.Name, packetSubmission.VisitId); + + var participant = await _participationService.GetById(User.Identity.Name, visit.ParticipationId); + + var vm = packetSubmission.ToVM(); + + string filename = vm.GetFileName(participant.LegacyId, visit.VISIT_DATE); + + var memoryStream = new MemoryStream(); + var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8); + + using (var csv = new CsvWriter(streamWriter, CultureInfo.InvariantCulture, true)) + { + csv.WriteRecords(visit.Forms); + } + + Processed = true; + + memoryStream.Position = 0; + Response.Headers["Content-Disposition"] = $"attachment; {filename}"; + return File(memoryStream, "text/csv", filename); } } } diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml b/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml index ae0851cd..f24192ae 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml @@ -4,3 +4,59 @@ ViewData["Title"] = Model.PageTitle; } + +@if (Model.Visit != null) +{ + + @if (Model.Visit.Participation != null && Model.Visit.PacketSubmissions != null) + { +
+
+

All packet submissions

+

A list of all packet submissions.

+
+
+
+
+ + + + + + + + + + + + @foreach (var packetSubmission in Model.Submissions.List) + { + + + + + + + + } + +
IdSubmission dateDownloadError countEdit errors
@packetSubmission.Id@packetSubmission.SubmissionDate + + @(packetSubmission.GetFileName(Model.Visit.Participation.LegacyId, Model.Visit.VISIT_DATE)) + + @packetSubmission.ErrorCountEdit
+
+
+
+
+ } +} \ No newline at end of file diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml.cs index 980283e3..8293e8d5 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml.cs @@ -10,13 +10,12 @@ namespace UDS.Net.Forms.Pages.PacketSubmissions public class IndexModel : PageModel { protected readonly IVisitService _visitService; + protected readonly IParticipationService _participationService; protected readonly IPacketSubmissionService _packetSubmissionService; - [BindProperty] public VisitModel Visit { get; set; } - [BindProperty] - public List Submissions { get; set; } + public PacketSubmissionsModel Submissions { get; set; } public string PageTitle { @@ -30,24 +29,39 @@ public string PageTitle } } - public IndexModel(IVisitService visitService) : base() + public IndexModel(IVisitService visitService, IParticipationService participationService, IPacketSubmissionService packetSubmissionService) : base() { _visitService = visitService; + _participationService = participationService; + _packetSubmissionService = packetSubmissionService; } public async Task OnGetAsync(int? visitId = null, int pageSize = 10, int pageIndex = 1) { if (visitId.HasValue) { - var visit = await _visitService.GetById(User.Identity.Name, visitId.Value); + var visit = await _visitService.GetByIdWithSubmissions(User.Identity.Name, visitId.Value); + + if (visit == null) + return NotFound(); + + var participation = await _participationService.GetById("", visit.ParticipationId); + + if (participation == null) + return NotFound(); Visit = visit.ToVM(); + + Visit.Participation = participation.ToVM(); + + Submissions = visit.Submissions.ToVM(); } else { + // if there is no visit id, get all packet submissions paginated var packetSubmissions = await _packetSubmissionService.List(User.Identity.Name, pageSize, pageIndex); - //Submissions = packetSubmissions.Select(p => p.ToVM()).List(); + Submissions = packetSubmissions.ToVM(); } return Page(); diff --git a/src/UDS.Net.Forms/Pages/Participations/Create.cshtml.cs b/src/UDS.Net.Forms/Pages/Participations/Create.cshtml.cs index 9993a68e..dd99b4e5 100644 --- a/src/UDS.Net.Forms/Pages/Participations/Create.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/Participations/Create.cshtml.cs @@ -52,7 +52,7 @@ public async Task OnPostAsync() if (!ModelState.IsValid) return Page(); - await _participationService.Add("", Participation.ToEntity()); + await _participationService.Add(User.Identity.IsAuthenticated ? User.Identity.Name : "Username", Participation.ToEntity()); return RedirectToPage("./Index"); } diff --git a/src/UDS.Net.Forms/Pages/Participations/Details.cshtml b/src/UDS.Net.Forms/Pages/Participations/Details.cshtml index 5a1c3a36..a60ad7c6 100644 --- a/src/UDS.Net.Forms/Pages/Participations/Details.cshtml +++ b/src/UDS.Net.Forms/Pages/Participations/Details.cshtml @@ -93,7 +93,7 @@ Date - Yype + Type Details Progress diff --git a/src/UDS.Net.Forms/Pages/Visits/Finalize.cshtml b/src/UDS.Net.Forms/Pages/Visits/Finalize.cshtml index d484f4c6..7ebe5a71 100644 --- a/src/UDS.Net.Forms/Pages/Visits/Finalize.cshtml +++ b/src/UDS.Net.Forms/Pages/Visits/Finalize.cshtml @@ -4,17 +4,73 @@ ViewData["Title"] = Model.PageTitle; } -@if (Model.Visit != null) -{ - @Model.Visit.Status +
+
+ @if (Model.Visit != null) + { + + } +
+
+ @if (Model.Visit != null) + { +
+
- @if (Model.Visit.CanBeFinalized) - { - - - Create packet submission - - } -} \ No newline at end of file +
+

Packet @Model.Visit.PACKET

+
+
+ + @("UDS" + Model.Visit.FORMVER) +
+
+ + @Model.Visit.CreatedBy +
+
+ + Visit on @Model.Visit.VISIT_DATE.ToLongDateString() +
+
+
+
+ + @if (Model.Visit.CanBeFinalized) + { + + + Ready for submission + + } + +
+
+
+ + +
+
    +
  • + Loading... +
  • + + +
+
+ + } +
+
\ No newline at end of file diff --git a/src/UDS.Net.Forms/UDS.Net.Forms.csproj b/src/UDS.Net.Forms/UDS.Net.Forms.csproj index fb7c201f..9f228a2b 100644 --- a/src/UDS.Net.Forms/UDS.Net.Forms.csproj +++ b/src/UDS.Net.Forms/UDS.Net.Forms.csproj @@ -6,13 +6,13 @@ enable true UDS.Net.Forms - 4.1.0-preview.1 + 4.1.0-preview.2 Sanders-Brown Center on Aging UDS Forms razor class library UK-SBCoA Razor class library for rendering UDS forms https://github.com/UK-SBCoA/uniform-data-set-dotnet-web - 4.1.0-preview.1 + 4.1.0-preview.2 @@ -25,7 +25,8 @@ - - + + + \ No newline at end of file diff --git a/src/UDS.Net.Services.Test/UDS.Net.Services.Test.csproj b/src/UDS.Net.Services.Test/UDS.Net.Services.Test.csproj index 1a8a5367..3ca71a47 100644 --- a/src/UDS.Net.Services.Test/UDS.Net.Services.Test.csproj +++ b/src/UDS.Net.Services.Test/UDS.Net.Services.Test.csproj @@ -7,7 +7,7 @@ false true - 4.1.0-preview.1 + 4.1.0-preview.2 diff --git a/src/UDS.Net.Services/DomainModels/Submission/PacketSubmission.cs b/src/UDS.Net.Services/DomainModels/Submission/PacketSubmission.cs index 2b0838d8..eaa7ec2a 100644 --- a/src/UDS.Net.Services/DomainModels/Submission/PacketSubmission.cs +++ b/src/UDS.Net.Services/DomainModels/Submission/PacketSubmission.cs @@ -14,6 +14,8 @@ public class PacketSubmission public int VisitId { get; set; } + public int ErrorCount { get; set; } = 0; + public List Errors { get; set; } = new List(); public DateTime CreatedAt { get; set; } @@ -26,7 +28,7 @@ public class PacketSubmission public bool IsDeleted { get; set; } - public PacketSubmission(int id, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted) + public PacketSubmission(int id, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, int errorCount) { Id = id; SubmissionDate = submissionDate; @@ -36,9 +38,10 @@ public PacketSubmission(int id, DateTime submissionDate, int visitId, DateTime c ModifiedBy = modifiedBy; DeletedBy = deletedBy; IsDeleted = IsDeleted; + ErrorCount = errorCount; } - public PacketSubmission(int id, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, IList errors) : this(id, submissionDate, visitId, createdAt, createdBy, modifiedBy, deletedBy, isDeleted) + public PacketSubmission(int id, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, int errorCount, IList errors) : this(id, submissionDate, visitId, createdAt, createdBy, modifiedBy, deletedBy, isDeleted, errorCount) { if (errors != null) { diff --git a/src/UDS.Net.Services/Extensions/DtoToDomainMapper.cs b/src/UDS.Net.Services/Extensions/DtoToDomainMapper.cs index de126f86..16805edd 100644 --- a/src/UDS.Net.Services/Extensions/DtoToDomainMapper.cs +++ b/src/UDS.Net.Services/Extensions/DtoToDomainMapper.cs @@ -289,10 +289,10 @@ public static PacketSubmission ToDomain(this PacketSubmissionDto dto) { var errors = dto.PacketSubmissionErrors.Select(e => e.ToDomain()).ToList(); - return new PacketSubmission(dto.Id, dto.SubmissionDate, dto.VisitId, dto.CreatedAt, dto.CreatedBy, dto.ModifiedBy, dto.DeletedBy, dto.IsDeleted, errors); + return new PacketSubmission(dto.Id, dto.SubmissionDate, dto.VisitId, dto.CreatedAt, dto.CreatedBy, dto.ModifiedBy, dto.DeletedBy, dto.IsDeleted, dto.ErrorCount, errors); } else - return new PacketSubmission(dto.Id, dto.SubmissionDate, dto.VisitId, dto.CreatedAt, dto.CreatedBy, dto.ModifiedBy, dto.DeletedBy, dto.IsDeleted); + return new PacketSubmission(dto.Id, dto.SubmissionDate, dto.VisitId, dto.CreatedAt, dto.CreatedBy, dto.ModifiedBy, dto.DeletedBy, dto.IsDeleted, dto.ErrorCount); } public static PacketSubmissionError ToDomain(this PacketSubmissionErrorDto dto) diff --git a/src/UDS.Net.Services/IVisitService.cs b/src/UDS.Net.Services/IVisitService.cs index bdf75b47..c3a50db6 100644 --- a/src/UDS.Net.Services/IVisitService.cs +++ b/src/UDS.Net.Services/IVisitService.cs @@ -9,7 +9,7 @@ public interface IVisitService : IService { Task GetByIdWithForm(string username, int id, string formId); - Task GetByIdWithSubmissions(string username, int id); + Task GetByIdWithSubmissions(string username, int id, int pageSize = 10, int pageIndex = 1); Task UpdateForm(string username, Visit entity, string formId); } diff --git a/src/UDS.Net.Services/UDS.Net.Services.csproj b/src/UDS.Net.Services/UDS.Net.Services.csproj index b49e67f8..390893c6 100644 --- a/src/UDS.Net.Services/UDS.Net.Services.csproj +++ b/src/UDS.Net.Services/UDS.Net.Services.csproj @@ -4,15 +4,15 @@ netstandard2.1 Library UDS.Net.Services - 4.1.0-preview.1 + 4.1.0-preview.2 Sanders-Brown Center on Aging Service contracts for implmenting your own back-end with MVC web app UK-SBCoA Service contracts required by MVC web app https://github.com/UK-SBCoA/uniform-data-set-dotnet-web - 4.1.0-preview.1 + 4.1.0-preview.2 - + \ No newline at end of file diff --git a/src/UDS.Net.Web.MVC.Services/UDS.Net.Web.MVC.Services.csproj b/src/UDS.Net.Web.MVC.Services/UDS.Net.Web.MVC.Services.csproj index ca4153d8..2c16aa55 100644 --- a/src/UDS.Net.Web.MVC.Services/UDS.Net.Web.MVC.Services.csproj +++ b/src/UDS.Net.Web.MVC.Services/UDS.Net.Web.MVC.Services.csproj @@ -4,18 +4,18 @@ netstandard2.1 Library UDS.Net.MVC.Services - 4.1.0-preview.1 + 4.1.0-preview.2 Sanders-Brown Center on Aging Implemented service layer for using MVC front-end with API back-end UK-SBCoA Implemented service contract https://github.com/UK-SBCoA/uniform-data-set-dotnet-web - 4.1.0-preview.1 + 4.1.0-preview.2 - - + + diff --git a/src/UDS.Net.Web.MVC.Services/VisitService.cs b/src/UDS.Net.Web.MVC.Services/VisitService.cs index e7d62a2c..d1fc5f97 100644 --- a/src/UDS.Net.Web.MVC.Services/VisitService.cs +++ b/src/UDS.Net.Web.MVC.Services/VisitService.cs @@ -60,16 +60,12 @@ public async Task GetByIdWithForm(string username, int id, string formId) throw new Exception("Visit with form not found"); } - public async Task GetByIdWithSubmissions(string username, int id) // TODO Upgrade to include pagination on submissions + public async Task GetByIdWithSubmissions(string username, int id, int pageSize = 10, int pageIndex = 1) { - var visitDto = await _apiClient.VisitClient.Get(id); + var visitDto = await _apiClient.VisitClient.GetWithPacketSubmissions(id, pageSize, pageIndex); if (visitDto != null) { - var submissionsDto = await _apiClient.PacketSubmissionClient.GetPacketSubmissionsByVisit(id); - - visitDto.PacketSubmissions = submissionsDto; - return visitDto.ToDomain(username); // converting to domain object implements business rules for shown forms } diff --git a/src/UDS.Net.Web.MVC/Program.cs b/src/UDS.Net.Web.MVC/Program.cs index 9e0a8895..29d509bc 100644 --- a/src/UDS.Net.Web.MVC/Program.cs +++ b/src/UDS.Net.Web.MVC/Program.cs @@ -31,6 +31,7 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); ////************************************************************************************************* diff --git a/src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj b/src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj index 6029675e..6c521a1e 100644 --- a/src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj +++ b/src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj @@ -6,7 +6,7 @@ enable aspnet-UDS.Net.Web.MVC-F92C0881-61B6-4292-8635-0004DE84CFE6 ../docker-compose.dcproj - 4.1.0-preview.1 + 4.1.0-preview.2 @@ -20,8 +20,8 @@ all
- - + +
diff --git a/src/UDS.Net.sln b/src/UDS.Net.sln index fa638dd6..e4f4b1f3 100644 --- a/src/UDS.Net.sln +++ b/src/UDS.Net.sln @@ -15,7 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UDS.Net.Web.MVC.Services", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UDS.Net.Services.Test", "UDS.Net.Services.Test\UDS.Net.Services.Test.csproj", "{395296FB-4036-4FC9-A8DC-A50F96D35623}" EndProject -Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "docker-compose", "docker-compose.dcproj", "{E2EAFF76-4F37-4704-A089-7552852DF5CF}" +Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "docker-compose", "docker-compose.dcproj", "{7E228C1C-7495-46FF-8D20-FAB0D398747E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -47,10 +47,10 @@ Global {395296FB-4036-4FC9-A8DC-A50F96D35623}.Debug|Any CPU.Build.0 = Debug|Any CPU {395296FB-4036-4FC9-A8DC-A50F96D35623}.Release|Any CPU.ActiveCfg = Release|Any CPU {395296FB-4036-4FC9-A8DC-A50F96D35623}.Release|Any CPU.Build.0 = Release|Any CPU - {E2EAFF76-4F37-4704-A089-7552852DF5CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E2EAFF76-4F37-4704-A089-7552852DF5CF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E2EAFF76-4F37-4704-A089-7552852DF5CF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E2EAFF76-4F37-4704-A089-7552852DF5CF}.Release|Any CPU.Build.0 = Release|Any CPU + {7E228C1C-7495-46FF-8D20-FAB0D398747E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7E228C1C-7495-46FF-8D20-FAB0D398747E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7E228C1C-7495-46FF-8D20-FAB0D398747E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7E228C1C-7495-46FF-8D20-FAB0D398747E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -59,6 +59,6 @@ Global SolutionGuid = {3268D734-1592-4E39-88A2-3A53468CC430} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - version = 4.1.0-preview.1 + version = 4.1.0-preview.2 EndGlobalSection EndGlobal