diff --git a/src/UDS.Net.Forms.Tests/Services/VisitService.cs b/src/UDS.Net.Forms.Tests/Services/VisitService.cs index ee3e89f1..f2cfedd4 100644 --- a/src/UDS.Net.Forms.Tests/Services/VisitService.cs +++ b/src/UDS.Net.Forms.Tests/Services/VisitService.cs @@ -63,11 +63,11 @@ public static List GetSeedingVisits() { return new List() { - new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "email@uky.edu", "", "", false, null), - new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "email@uky.edu", "", "", false, null), - new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "email@uky.edu", "", "", false, null), - new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "email@uky.edu", "", "", false, null), - new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "email@uky.edu", "", "", false, null) + new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "email@uky.edu", "", "", false, null), + new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "email@uky.edu", "", "", false, null), + new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "email@uky.edu", "", "", false, null), + new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "email@uky.edu", "", "", false, null), + new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "email@uky.edu", "", "", false, null) }; } diff --git a/src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs b/src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs index e400d33f..84592aeb 100644 --- a/src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs +++ b/src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs @@ -69,17 +69,35 @@ public static VisitModel ToVM(this Visit visit) }; } - public static PacketSubmissionsModel ToVM(this IEnumerable packetSubmissions) + public static PacketModel ToVM(this Packet packet) { - PacketSubmissionsModel vm = new PacketSubmissionsModel(); - - if (packetSubmissions != null) + return new PacketModel() { - foreach (var packetSubmission in packetSubmissions) - { - vm.List.Add(packetSubmission.ToVM()); - } - } + Id = packet.Id, + ParticipationId = packet.ParticipationId, + VISITNUM = packet.VISITNUM, + PACKET = packet.PACKET, + FORMVER = packet.FORMVER, + VISIT_DATE = packet.VISIT_DATE, + INITIALS = packet.INITIALS, + Status = packet.Status, + CreatedAt = packet.CreatedAt, + CreatedBy = packet.CreatedBy, + ModifiedBy = packet.ModifiedBy, + DeletedBy = packet.DeletedBy, + IsDeleted = packet.IsDeleted, + CanBeFinalized = packet.IsFinalizable, + Forms = packet.Forms.ToVM(), + PacketSubmissions = packet.Submissions.ToVM() + }; + } + + public static List ToVM(this IList packetSubmissions) + { + List vm = new List(); + + if (packetSubmissions != null && packetSubmissions.Count() > 0) + vm = packetSubmissions.Select(p => p.ToVM()).ToList(); return vm; } @@ -106,15 +124,15 @@ public static PacketSubmissionModel ToVM(this PacketSubmission packetSubmission) return vm; } - public static PacketSubmissionErrorsPaginatedModel ToVM(this List packetSubmissionErrors) + public static List ToVM(this List packetSubmissionErrors) { - PacketSubmissionErrorsPaginatedModel vm = new PacketSubmissionErrorsPaginatedModel(); + List vm = new List(); if (packetSubmissionErrors != null) { foreach (var error in packetSubmissionErrors) { - vm.List.Add(error.ToVM()); + vm.Add(error.ToVM()); } } diff --git a/src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs b/src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs index cbdb6429..7b96cc9f 100644 --- a/src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs +++ b/src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs @@ -76,6 +76,23 @@ 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 Packet ToEntity(this PacketModel vm) + { + return new Packet(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(), vm.PacketSubmissions.ToEntity()); + } + + public static List ToEntity(this IList vm) + { + List submissions = new List(); + + if (vm != null) + { + submissions = vm.Select(p => p.ToEntity()).ToList(); + } + + return submissions; + } + public static PacketSubmission ToEntity(this PacketSubmissionModel vm) { return new PacketSubmission(vm.Id, "", vm.SubmissionDate, vm.VisitId, vm.CreatedAt, vm.CreatedBy, vm.ModifiedBy, "", false, 0); diff --git a/src/UDS.Net.Forms/Models/FormModel.cs b/src/UDS.Net.Forms/Models/FormModel.cs index 52097498..3a3f5977 100644 --- a/src/UDS.Net.Forms/Models/FormModel.cs +++ b/src/UDS.Net.Forms/Models/FormModel.cs @@ -88,6 +88,10 @@ public bool AllowsRemote [Required] public bool IsDeleted { get; set; } + public int? UnresolvedErrorCount { get; set; } + + public List UnresolvedErrors { get; set; } = new List(); + public virtual IEnumerable Validate(ValidationContext validationContext) { if (Status == FormStatus.NotStarted) diff --git a/src/UDS.Net.Forms/Models/PacketModel.cs b/src/UDS.Net.Forms/Models/PacketModel.cs new file mode 100644 index 00000000..2ef8a22d --- /dev/null +++ b/src/UDS.Net.Forms/Models/PacketModel.cs @@ -0,0 +1,9 @@ +using System; +namespace UDS.Net.Forms.Models +{ + public class PacketModel : VisitModel + { + public virtual IList PacketSubmissions { get; set; } = new List(); + } +} + diff --git a/src/UDS.Net.Forms/Models/PacketSubmissionErrorsPaginatedModel.cs b/src/UDS.Net.Forms/Models/PacketSubmissionErrorsPaginatedModel.cs deleted file mode 100644 index 49564d61..00000000 --- a/src/UDS.Net.Forms/Models/PacketSubmissionErrorsPaginatedModel.cs +++ /dev/null @@ -1,11 +0,0 @@ -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 b3787190..9a1d40e8 100644 --- a/src/UDS.Net.Forms/Models/PacketSubmissionModel.cs +++ b/src/UDS.Net.Forms/Models/PacketSubmissionModel.cs @@ -24,7 +24,8 @@ public class PacketSubmissionModel public int? ErrorCount { get; set; } - public virtual PacketSubmissionErrorsPaginatedModel Errors { get; set; } = new PacketSubmissionErrorsPaginatedModel(); + public List Errors { get; set; } = new List(); + 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 deleted file mode 100644 index 08d75ed1..00000000 --- a/src/UDS.Net.Forms/Models/PacketSubmissionsPaginatedModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -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/PacketPageModel.cs b/src/UDS.Net.Forms/Models/PageModels/PacketPageModel.cs new file mode 100644 index 00000000..a882f8fa --- /dev/null +++ b/src/UDS.Net.Forms/Models/PageModels/PacketPageModel.cs @@ -0,0 +1,37 @@ +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 PacketPageModel : PageModel + { + protected readonly IPacketService _packetService; + + [BindProperty] + public PacketModel? Packet { get; set; } + + public PacketPageModel(IPacketService packetService) : base() + { + _packetService = packetService; + } + + public async Task OnGetAsync(int? id) + { + if (id == null || id == 0) + return NotFound(); + + var packet = await _packetService.GetById("", id.Value); + + if (packet == null) + return NotFound(); + + Packet = packet.ToVM(); + + return Page(); + } + } +} + diff --git a/src/UDS.Net.Forms/Models/PageModels/PacketSubmissionPageModel.cs b/src/UDS.Net.Forms/Models/PageModels/PacketSubmissionPageModel.cs deleted file mode 100644 index ae56f22c..00000000 --- a/src/UDS.Net.Forms/Models/PageModels/PacketSubmissionPageModel.cs +++ /dev/null @@ -1,48 +0,0 @@ -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/VisitModel.cs b/src/UDS.Net.Forms/Models/VisitModel.cs index 4eccb630..89ee7848 100644 --- a/src/UDS.Net.Forms/Models/VisitModel.cs +++ b/src/UDS.Net.Forms/Models/VisitModel.cs @@ -37,6 +37,8 @@ public class VisitModel public bool CanBeFinalized { get; set; } = false; + public int? TotalUnresolvedErrorCount { get; set; } + [Required] public DateTime CreatedAt { get; set; } @@ -53,7 +55,6 @@ public class VisitModel public virtual IList Forms { get; set; } = new List(); - public virtual IList PacketSubmissions { get; set; } = new List(); } } diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml b/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml index 36ddea34..1046c50f 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml @@ -26,7 +26,7 @@ - Cancel + Cancel diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml.cs index dd4b106c..5b279142 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml.cs @@ -11,32 +11,30 @@ namespace UDS.Net.Forms.Pages.PacketSubmissions { public class CreateModel : PageModel { - protected readonly IVisitService _visitService; protected readonly IParticipationService _participationService; - protected readonly IPacketSubmissionService _packetSubmissionService; + protected readonly IPacketService _packetService; [BindProperty] public PacketSubmissionModel? PacketSubmission { get; set; } - public VisitModel? Visit { get; set; } + public PacketModel? Packet { get; set; } public string PageTitle { get { - if (Visit != null) + if (Packet != null) { - return $"Participant {Visit.Participation.LegacyId} Visit {Visit.VISITNUM} Packet Submissions"; + return $"Participant {Packet.Participation.LegacyId} Visit {Packet.VISITNUM} Packet Submissions"; } return ""; } } - public CreateModel(IVisitService visitService, IParticipationService participationService, IPacketSubmissionService packetSubmissionService) + public CreateModel(IParticipationService participationService, IPacketService packetService) { - _visitService = visitService; _participationService = participationService; - _packetSubmissionService = packetSubmissionService; + _packetService = packetService; } public async Task OnGetAsync(int? visitId) @@ -44,23 +42,23 @@ public async Task OnGetAsync(int? visitId) if (visitId == null || visitId == 0) return NotFound(); - var visit = await _visitService.GetById("", visitId.Value); + var packet = await _packetService.GetById("", visitId.Value); - if (visit == null) + if (packet == null) return NotFound(); - var participation = await _participationService.GetById("", visit.ParticipationId); + var participation = await _participationService.GetById("", packet.ParticipationId); if (participation == null) return NotFound(); - Visit = visit.ToVM(); + Packet = packet.ToVM(); - Visit.Participation = participation.ToVM(); + Packet.Participation = participation.ToVM(); PacketSubmission = new PacketSubmissionModel { - VisitId = visit.Id, + VisitId = packet.Id, SubmissionDate = DateTime.Now, CreatedAt = DateTime.UtcNow, CreatedBy = User.Identity.IsAuthenticated ? User.Identity.Name : "Username" @@ -77,7 +75,7 @@ public async Task OnPostAsync() try { // TODO add isn't working yet - await _packetSubmissionService.Add(User.Identity.IsAuthenticated ? User.Identity.Name : "Username", PacketSubmission.ToEntity()); + await _packetService.Update(User.Identity.IsAuthenticated ? User.Identity.Name : "Username", Packet.ToEntity()); } catch (Exception ex) { diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml.cs index fd1435a5..a6bec917 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml.cs @@ -9,9 +9,9 @@ namespace UDS.Net.Forms.Pages.PacketSubmissions { - public class DetailsModel : PacketSubmissionPageModel + public class DetailsModel : PacketPageModel { - public DetailsModel(IVisitService visitService, IPacketSubmissionService packetSubmissionService) : base(visitService, packetSubmissionService) + public DetailsModel(IPacketService packetService) : base(packetService) { } } diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml.cs index ba818c88..43a43b14 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml.cs @@ -7,9 +7,9 @@ namespace UDS.Net.Forms.Pages.PacketSubmissions { - public class EditModel : PacketSubmissionPageModel + public class EditModel : PacketPageModel { - public EditModel(IVisitService visitService, IPacketSubmissionService packetSubmissionService) : base(visitService, packetSubmissionService) + public EditModel(IPacketService packetSubmissionService) : base(packetSubmissionService) { } } diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml.cs index e2d069f3..1bd6a64d 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Export.cshtml.cs @@ -19,16 +19,14 @@ namespace UDS.Net.Forms.Pages.PacketSubmissions { public class ExportModel : PageModel { - protected readonly IVisitService _visitService; - protected readonly IPacketSubmissionService _packetSubmissionService; + protected readonly IPacketService _packetService; protected readonly IParticipationService _participationService; public bool Processed { get; set; } = false; - public ExportModel(IVisitService visitService, IPacketSubmissionService packetSubmissionService, IParticipationService participationService) + public ExportModel(IPacketService packetService, IParticipationService participationService) { - _visitService = visitService; - _packetSubmissionService = packetSubmissionService; + _packetService = packetService; _participationService = participationService; } @@ -38,347 +36,351 @@ public async Task OnGetAsync(int id) return NotFound(); // TODO use temporal tables to get the data at that point in time of the submission - var packetSubmission = await _packetSubmissionService.GetPacketSubmissionWithForms(User.Identity.Name, id); + var packet = await _packetService.GetPacketWithForms(User.Identity.Name, id); - var visit = await _visitService.GetById(User.Identity.Name, packetSubmission.VisitId); + var participant = await _participationService.GetById(User.Identity.Name, packet.ParticipationId); - var participant = await _participationService.GetById(User.Identity.Name, visit.ParticipationId); - - var vm = packetSubmission.ToVM(); // converting to vm to get filename - string filename = vm.GetFileName(participant.LegacyId, visit.VISIT_DATE); + if (packet != null && packet.Submissions != null && packet.Submissions.Count() > 0) + { + var packetSubmission = packet.Submissions.OrderByDescending(s => s.SubmissionDate).FirstOrDefault(); - var memoryStream = new MemoryStream(); + var vm = packetSubmission.ToVM(); // converting to vm to get filename + string filename = vm.GetFileName(participant.LegacyId, packet.VISIT_DATE); - var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8); + var memoryStream = new MemoryStream(); - using (var csv = new CsvWriter(streamWriter, CultureInfo.InvariantCulture, true)) - { - var record = new CsvRecord(packetSubmission.ADRCId, participant, visit); - var a1 = packetSubmission.Forms.Where(f => f.Kind == "A1").FirstOrDefault(); - var a1a = packetSubmission.Forms.Where(f => f.Kind == "A1a").FirstOrDefault(); - var a2 = packetSubmission.Forms.Where(f => f.Kind == "A2").FirstOrDefault(); - var a3 = packetSubmission.Forms.Where(f => f.Kind == "A3").FirstOrDefault(); - var a4 = packetSubmission.Forms.Where(f => f.Kind == "A4").FirstOrDefault(); - var a4a = packetSubmission.Forms.Where(f => f.Kind == "A4a").FirstOrDefault(); - var a5d2 = packetSubmission.Forms.Where(f => f.Kind == "A5D2").FirstOrDefault(); - var b1 = packetSubmission.Forms.Where(f => f.Kind == "B1").FirstOrDefault(); - var b3 = packetSubmission.Forms.Where(f => f.Kind == "B3").FirstOrDefault(); - var b4 = packetSubmission.Forms.Where(f => f.Kind == "B4").FirstOrDefault(); - var b5 = packetSubmission.Forms.Where(f => f.Kind == "B5").FirstOrDefault(); - var b6 = packetSubmission.Forms.Where(f => f.Kind == "B6").FirstOrDefault(); - var b7 = packetSubmission.Forms.Where(f => f.Kind == "B7").FirstOrDefault(); - var b8 = packetSubmission.Forms.Where(f => f.Kind == "B8").FirstOrDefault(); - var b9 = packetSubmission.Forms.Where(f => f.Kind == "B9").FirstOrDefault(); - var c2 = packetSubmission.Forms.Where(f => f.Kind == "C2").FirstOrDefault(); - var d1a = packetSubmission.Forms.Where(f => f.Kind == "D1a").FirstOrDefault(); - var d1b = packetSubmission.Forms.Where(f => f.Kind == "D1b").FirstOrDefault(); + var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8); - var a4aProps = typeof(A4aTreatmentFormFields).GetProperties(); - var a3FamilyProps = typeof(A3FamilyMemberFormFields).GetProperties(); + using (var csv = new CsvWriter(streamWriter, CultureInfo.InvariantCulture, true)) + { + var record = new CsvRecord(packetSubmission.ADRCId, participant, packet); + var a1 = packetSubmission.Forms.Where(f => f.Kind == "A1").FirstOrDefault(); + var a1a = packetSubmission.Forms.Where(f => f.Kind == "A1a").FirstOrDefault(); + var a2 = packetSubmission.Forms.Where(f => f.Kind == "A2").FirstOrDefault(); + var a3 = packetSubmission.Forms.Where(f => f.Kind == "A3").FirstOrDefault(); + var a4 = packetSubmission.Forms.Where(f => f.Kind == "A4").FirstOrDefault(); + var a4a = packetSubmission.Forms.Where(f => f.Kind == "A4a").FirstOrDefault(); + var a5d2 = packetSubmission.Forms.Where(f => f.Kind == "A5D2").FirstOrDefault(); + var b1 = packetSubmission.Forms.Where(f => f.Kind == "B1").FirstOrDefault(); + var b3 = packetSubmission.Forms.Where(f => f.Kind == "B3").FirstOrDefault(); + var b4 = packetSubmission.Forms.Where(f => f.Kind == "B4").FirstOrDefault(); + var b5 = packetSubmission.Forms.Where(f => f.Kind == "B5").FirstOrDefault(); + var b6 = packetSubmission.Forms.Where(f => f.Kind == "B6").FirstOrDefault(); + var b7 = packetSubmission.Forms.Where(f => f.Kind == "B7").FirstOrDefault(); + var b8 = packetSubmission.Forms.Where(f => f.Kind == "B8").FirstOrDefault(); + var b9 = packetSubmission.Forms.Where(f => f.Kind == "B9").FirstOrDefault(); + var c2 = packetSubmission.Forms.Where(f => f.Kind == "C2").FirstOrDefault(); + var d1a = packetSubmission.Forms.Where(f => f.Kind == "D1a").FirstOrDefault(); + var d1b = packetSubmission.Forms.Where(f => f.Kind == "D1b").FirstOrDefault(); - // ptid, adcid, visitnum, packet, formver, dssub, visit_date m/d/yyyy, initials, frmdatea1, initialsa1, langa1, modea1, rmreasa1 - csv.WriteHeader(); + var a4aProps = typeof(A4aTreatmentFormFields).GetProperties(); + var a3FamilyProps = typeof(A3FamilyMemberFormFields).GetProperties(); - if (a1 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (a1a != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (a2 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (a3 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); + // ptid, adcid, visitnum, packet, formver, dssub, visit_date m/d/yyyy, initials, frmdatea1, initialsa1, langa1, modea1, rmreasa1 + csv.WriteHeader(); - // siblings - var siblingFields = ((A3FormFields)a3.Fields).SiblingFormFields; // we always have a list of 20 siblings - foreach (var siblingField in siblingFields) + if (a1 != null) { - foreach (var prop in a3FamilyProps) + csv.WriteHeader(); + csv.WriteHeader(); + } + if (a1a != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (a2 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (a3 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + + // siblings + var siblingFields = ((A3FormFields)a3.Fields).SiblingFormFields; // we always have a list of 20 siblings + foreach (var siblingField in siblingFields) + { + foreach (var prop in a3FamilyProps) + { + if (prop.Name != "FamilyMemberIndex") + csv.WriteField($"SIB{siblingField.FamilyMemberIndex}{prop.Name}"); + } + } + // kids + var kidFields = ((A3FormFields)a3.Fields).KidsFormFields; // we always have a list of 15 children + foreach (var kidField in kidFields) { - if (prop.Name != "FamilyMemberIndex") - csv.WriteField($"SIB{siblingField.FamilyMemberIndex}{prop.Name}"); + foreach (var prop in a3FamilyProps) + { + if (prop.Name != "FamilyMemberIndex") + csv.WriteField($"KID{kidField.FamilyMemberIndex}{prop.Name}"); + } } } - // kids - var kidFields = ((A3FormFields)a3.Fields).KidsFormFields; // we always have a list of 15 children - foreach (var kidField in kidFields) + if (a4 != null) { - foreach (var prop in a3FamilyProps) + csv.WriteHeader(); + csv.WriteHeader(); + + // we need to hold 40 fields for rxnormids + for (int i = 1; i <= 40; i++) { - if (prop.Name != "FamilyMemberIndex") - csv.WriteField($"KID{kidField.FamilyMemberIndex}{prop.Name}"); + csv.WriteField($"rxnormid{i}"); } } - } - if (a4 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - - // we need to hold 40 fields for rxnormids - for (int i = 1; i <= 40; i++) + if (a4a != null) { - csv.WriteField($"rxnormid{i}"); - } - } - if (a4a != null) - { - csv.WriteHeader(); - csv.WriteHeader(); + csv.WriteHeader(); + csv.WriteHeader(); - var treatments = ((A4aFormFields)a4a.Fields).TreatmentFormFields; // we always have a list of count 8 + var treatments = ((A4aFormFields)a4a.Fields).TreatmentFormFields; // we always have a list of count 8 - foreach (var treatment in treatments) - { - foreach (var prop in a4aProps) + foreach (var treatment in treatments) { - if (prop.Name != "TreatmentIndex") + foreach (var prop in a4aProps) { - csv.WriteField($"{prop.Name}{treatment.TreatmentIndex}"); + if (prop.Name != "TreatmentIndex") + { + csv.WriteField($"{prop.Name}{treatment.TreatmentIndex}"); + } } } } - } - if (a5d2 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (b1 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (b3 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (b4 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (b5 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (b6 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (b7 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (b8 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (b9 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (c2 != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (d1a != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - if (d1b != null) - { - csv.WriteHeader(); - csv.WriteHeader(); - } - - csv.NextRecord(); // end of header row + if (a5d2 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (b1 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (b3 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (b4 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (b5 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (b6 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (b7 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (b8 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (b9 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (c2 != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (d1a != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } + if (d1b != null) + { + csv.WriteHeader(); + csv.WriteHeader(); + } - csv.WriteRecord(record); + csv.NextRecord(); // end of header row - if (a1 != null) - { - var a1Record = new A1Record(a1); - csv.WriteRecord(a1Record); - csv.WriteRecord((A1FormFields)a1.Fields); - } - if (a1a != null) - { - var a1aRecord = new A1aRecord(a1a); - csv.WriteRecord(a1aRecord); - csv.WriteRecord((A1aFormFields)a1a.Fields); - } - if (a2 != null) - { - var a2Record = new A2Record(a2); - csv.WriteRecord(a2Record); - csv.WriteRecord((A2FormFields)a2.Fields); - } - if (a3 != null) - { - var a3Record = new A3Record(a3); - csv.WriteRecord(a3Record); - csv.WriteRecord((A3FormFields)a3.Fields); + csv.WriteRecord(record); - // siblings - var siblings = ((A3FormFields)a3.Fields).SiblingFormFields; - foreach (var sibling in siblings) + if (a1 != null) { - foreach (var prop in a3FamilyProps) + var a1Record = new A1Record(a1); + csv.WriteRecord(a1Record); + csv.WriteRecord((A1FormFields)a1.Fields); + } + if (a1a != null) + { + var a1aRecord = new A1aRecord(a1a); + csv.WriteRecord(a1aRecord); + csv.WriteRecord((A1aFormFields)a1a.Fields); + } + if (a2 != null) + { + var a2Record = new A2Record(a2); + csv.WriteRecord(a2Record); + csv.WriteRecord((A2FormFields)a2.Fields); + } + if (a3 != null) + { + var a3Record = new A3Record(a3); + csv.WriteRecord(a3Record); + csv.WriteRecord((A3FormFields)a3.Fields); + + // siblings + var siblings = ((A3FormFields)a3.Fields).SiblingFormFields; + foreach (var sibling in siblings) { - if (prop.Name != "FamilyMemberIndex") + foreach (var prop in a3FamilyProps) { - var v = prop.GetValue(sibling, null); - csv.WriteField(v); + if (prop.Name != "FamilyMemberIndex") + { + var v = prop.GetValue(sibling, null); + csv.WriteField(v); + } } } - } - var kids = ((A3FormFields)a3.Fields).KidsFormFields; - foreach (var kid in kids) - { - foreach (var prop in a3FamilyProps) + var kids = ((A3FormFields)a3.Fields).KidsFormFields; + foreach (var kid in kids) { - if (prop.Name != "FamilyMemberIndex") + foreach (var prop in a3FamilyProps) { - var v = prop.GetValue(kid, null); - csv.WriteField(v); + if (prop.Name != "FamilyMemberIndex") + { + var v = prop.GetValue(kid, null); + csv.WriteField(v); + } } } } - } - if (a4 != null) - { - var a4Record = new A4Record(a4); - csv.WriteRecord(a4Record); - csv.WriteRecord((A4GFormFields)a4.Fields); - - var details = ((A4GFormFields)a4.Fields).A4Ds.ToArray(); // we do NOT already have a list of 40, size of this list is dynamic - for (int i = 1; i <= 40; i++) + if (a4 != null) { - if (details.Count() >= i) - csv.WriteField(details[i - 1].RxNormId); - else - csv.WriteField(string.Empty); - } - } - if (a4a != null) - { - var a4aRecord = new A4aRecord(a4a); - csv.WriteRecord(a4aRecord); - csv.WriteRecord((A4aFormFields)a4a.Fields); + var a4Record = new A4Record(a4); + csv.WriteRecord(a4Record); + csv.WriteRecord((A4GFormFields)a4.Fields); - var treatments = ((A4aFormFields)a4a.Fields).TreatmentFormFields; - foreach (var treatment in treatments) + var details = ((A4GFormFields)a4.Fields).A4Ds.ToArray(); // we do NOT already have a list of 40, size of this list is dynamic + for (int i = 1; i <= 40; i++) + { + if (details.Count() >= i) + csv.WriteField(details[i - 1].RxNormId); + else + csv.WriteField(string.Empty); + } + } + if (a4a != null) { - foreach (var prop in a4aProps) + var a4aRecord = new A4aRecord(a4a); + csv.WriteRecord(a4aRecord); + csv.WriteRecord((A4aFormFields)a4a.Fields); + + var treatments = ((A4aFormFields)a4a.Fields).TreatmentFormFields; + foreach (var treatment in treatments) { - if (prop.Name != "TreatmentIndex") + foreach (var prop in a4aProps) { - var v = prop.GetValue(treatment, null); - csv.WriteField(v); + if (prop.Name != "TreatmentIndex") + { + var v = prop.GetValue(treatment, null); + csv.WriteField(v); + } } } } - } - if (a5d2 != null) - { - var a5d2Record = new A5D2Record(a5d2); - csv.WriteRecord(a5d2Record); - csv.WriteRecord((A5D2FormFields)a5d2.Fields); - } - if (b1 != null) - { - var b1Record = new B1Record(b1); - csv.WriteRecord(b1Record); - csv.WriteRecord((B1FormFields)b1.Fields); - } - if (b3 != null) - { - var b3Record = new B3Record(b3); - csv.WriteRecord(b3Record); - csv.WriteRecord((B3FormFields)b3.Fields); - } - if (b4 != null) - { - var b4Record = new B4Record(b4); - csv.WriteRecord(b4Record); - csv.WriteRecord((B4FormFields)b4.Fields); - } - if (b5 != null) - { - var b5Record = new B5Record(b5); - csv.WriteRecord(b5Record); - csv.WriteRecord((B5FormFields)b5.Fields); - } - if (b6 != null) - { - var b6Recrod = new B6Record(b6); - csv.WriteRecord(b6Recrod); - csv.WriteRecord((B6FormFields)b6.Fields); - } - if (b7 != null) - { - var b7Record = new B7Record(b7); - csv.WriteRecord(b7Record); - csv.WriteRecord((B7FormFields)b7.Fields); - } - if (b8 != null) - { - var b8Record = new B8Record(b8); - csv.WriteRecord(b8Record); - csv.WriteRecord((B8FormFields)b8.Fields); - } - if (b9 != null) - { - var b9Record = new B9Record(b9); - csv.WriteRecord(b9Record); - csv.WriteRecord((B9FormFields)b9.Fields); - } - if (c2 != null) - { - var c2Record = new C2Record(c2); - csv.WriteRecord(c2Record); - csv.WriteRecord((C2FormFields)c2.Fields); - } - if (d1a != null) - { - var d1aRecord = new D1aRecord(d1a); - csv.WriteRecord(d1aRecord); - csv.WriteRecord((D1aFormFields)d1a.Fields); - } - if (d1b != null) - { - var d1bRecord = new D1bRecord(d1b); - csv.WriteRecord(d1bRecord); - csv.WriteRecord((D1bFormFields)d1b.Fields); - } + if (a5d2 != null) + { + var a5d2Record = new A5D2Record(a5d2); + csv.WriteRecord(a5d2Record); + csv.WriteRecord((A5D2FormFields)a5d2.Fields); + } + if (b1 != null) + { + var b1Record = new B1Record(b1); + csv.WriteRecord(b1Record); + csv.WriteRecord((B1FormFields)b1.Fields); + } + if (b3 != null) + { + var b3Record = new B3Record(b3); + csv.WriteRecord(b3Record); + csv.WriteRecord((B3FormFields)b3.Fields); + } + if (b4 != null) + { + var b4Record = new B4Record(b4); + csv.WriteRecord(b4Record); + csv.WriteRecord((B4FormFields)b4.Fields); + } + if (b5 != null) + { + var b5Record = new B5Record(b5); + csv.WriteRecord(b5Record); + csv.WriteRecord((B5FormFields)b5.Fields); + } + if (b6 != null) + { + var b6Recrod = new B6Record(b6); + csv.WriteRecord(b6Recrod); + csv.WriteRecord((B6FormFields)b6.Fields); + } + if (b7 != null) + { + var b7Record = new B7Record(b7); + csv.WriteRecord(b7Record); + csv.WriteRecord((B7FormFields)b7.Fields); + } + if (b8 != null) + { + var b8Record = new B8Record(b8); + csv.WriteRecord(b8Record); + csv.WriteRecord((B8FormFields)b8.Fields); + } + if (b9 != null) + { + var b9Record = new B9Record(b9); + csv.WriteRecord(b9Record); + csv.WriteRecord((B9FormFields)b9.Fields); + } + if (c2 != null) + { + var c2Record = new C2Record(c2); + csv.WriteRecord(c2Record); + csv.WriteRecord((C2FormFields)c2.Fields); + } + if (d1a != null) + { + var d1aRecord = new D1aRecord(d1a); + csv.WriteRecord(d1aRecord); + csv.WriteRecord((D1aFormFields)d1a.Fields); + } + if (d1b != null) + { + var d1bRecord = new D1bRecord(d1b); + csv.WriteRecord(d1bRecord); + csv.WriteRecord((D1bFormFields)d1b.Fields); + } - } // writer flushed automatically here + } // writer flushed automatically here - Processed = true; + Processed = true; - memoryStream.Position = 0; - Response.Headers["Content-Disposition"] = $"attachment; {filename}"; - return File(memoryStream, "text/csv", filename); + memoryStream.Position = 0; + Response.Headers["Content-Disposition"] = $"attachment; {filename}"; + return File(memoryStream, "text/csv", filename); + } + return null; } } } diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml b/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml index f24192ae..e0a67fb8 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml @@ -5,11 +5,11 @@ } -@if (Model.Visit != null) +@if (Model.Packet != null) { - @if (Model.Visit.Participation != null && Model.Visit.PacketSubmissions != null) + @if (Model.Packet.Participation != null && Model.Packet.PacketSubmissions != null) {
@@ -38,14 +38,14 @@ - @foreach (var packetSubmission in Model.Submissions.List) + @foreach (var packetSubmission in Model.Packet.PacketSubmissions) { @packetSubmission.Id @packetSubmission.SubmissionDate - @(packetSubmission.GetFileName(Model.Visit.Participation.LegacyId, Model.Visit.VISIT_DATE)) + @(packetSubmission.GetFileName(Model.Packet.Participation.LegacyId, Model.Packet.VISIT_DATE)) @packetSubmission.ErrorCount diff --git a/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml.cs b/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml.cs index 8293e8d5..6ca5f391 100644 --- a/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml.cs +++ b/src/UDS.Net.Forms/Pages/PacketSubmissions/Index.cshtml.cs @@ -9,59 +9,49 @@ namespace UDS.Net.Forms.Pages.PacketSubmissions { public class IndexModel : PageModel { - protected readonly IVisitService _visitService; protected readonly IParticipationService _participationService; - protected readonly IPacketSubmissionService _packetSubmissionService; + protected readonly IPacketService _packetService; - public VisitModel Visit { get; set; } - - public PacketSubmissionsModel Submissions { get; set; } + public PacketModel Packet { get; set; } public string PageTitle { get { - if (Visit != null) + if (Packet != null) { - return $"Participant {Visit.Participation.LegacyId} Visit {Visit.VISITNUM} Packet Submissions"; + return $"Participant {Packet.Participation.LegacyId} Visit {Packet.VISITNUM} Packet Submissions"; } return ""; } } - public IndexModel(IVisitService visitService, IParticipationService participationService, IPacketSubmissionService packetSubmissionService) : base() + public IndexModel(IParticipationService participationService, IPacketService packetService) : base() { - _visitService = visitService; _participationService = participationService; - _packetSubmissionService = packetSubmissionService; + _packetService = packetService; } - public async Task OnGetAsync(int? visitId = null, int pageSize = 10, int pageIndex = 1) + public async Task OnGetAsync(int? packetId = null, int pageSize = 10, int pageIndex = 1) { - if (visitId.HasValue) + if (packetId.HasValue) { - var visit = await _visitService.GetByIdWithSubmissions(User.Identity.Name, visitId.Value); + var packet = await _packetService.GetById(User.Identity.Name, packetId.Value); - if (visit == null) + if (packet == null) return NotFound(); - var participation = await _participationService.GetById("", visit.ParticipationId); + var participation = await _participationService.GetById("", packet.ParticipationId); if (participation == null) return NotFound(); - Visit = visit.ToVM(); - - Visit.Participation = participation.ToVM(); + Packet = packet.ToVM(); - Submissions = visit.Submissions.ToVM(); + Packet.Participation = participation.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.ToVM(); } return Page(); diff --git a/src/UDS.Net.Forms/Pages/Packets/Index.cshtml b/src/UDS.Net.Forms/Pages/Packets/Index.cshtml new file mode 100644 index 00000000..4955b244 --- /dev/null +++ b/src/UDS.Net.Forms/Pages/Packets/Index.cshtml @@ -0,0 +1,5 @@ +@page +@model UDS.Net.Forms.Pages.Packets.IndexModel +@{ +} + diff --git a/src/UDS.Net.Forms/Pages/Packets/Index.cshtml.cs b/src/UDS.Net.Forms/Pages/Packets/Index.cshtml.cs new file mode 100644 index 00000000..da5ce170 --- /dev/null +++ b/src/UDS.Net.Forms/Pages/Packets/Index.cshtml.cs @@ -0,0 +1,40 @@ +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.Extensions; +using UDS.Net.Forms.Models; +using UDS.Net.Forms.Models.PageModels; +using UDS.Net.Services; +using UDS.Net.Services.Enums; + +namespace UDS.Net.Forms.Pages.Packets +{ + public class IndexModel : PageModel + { + private readonly IPacketService _packetService; + + public IList? Packets { get; set; } + + public IndexModel(IPacketService packetService) + { + _packetService = packetService; + } + + public async Task OnGetAsync(int pageSize = 10, int pageIndex = 1) + { + List statuses = new List + { + PacketStatus.Finalized + }; + + var packets = await _packetService.List(User.Identity.Name, statuses, pageSize, pageIndex); + + Packets = packets.Select(p => p.ToVM()).ToList(); + + return Page(); + } + } +} diff --git a/src/UDS.Net.Forms/UDS.Net.Forms.csproj b/src/UDS.Net.Forms/UDS.Net.Forms.csproj index b81c2042..3f239281 100644 --- a/src/UDS.Net.Forms/UDS.Net.Forms.csproj +++ b/src/UDS.Net.Forms/UDS.Net.Forms.csproj @@ -25,8 +25,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive @@ -38,4 +38,10 @@ + + + + + + \ No newline at end of file diff --git a/src/UDS.Net.Services/DomainModels/Submission/Packet.cs b/src/UDS.Net.Services/DomainModels/Submission/Packet.cs new file mode 100644 index 00000000..70f8440d --- /dev/null +++ b/src/UDS.Net.Services/DomainModels/Submission/Packet.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using UDS.Net.Services.Enums; + +namespace UDS.Net.Services.DomainModels.Submission +{ + public class Packet : Visit + { + public IList Submissions { get; set; } = new List(); + + public Packet(int id, int number, int participationId, string version, PacketKind packet, DateTime visitDate, string initials, PacketStatus status, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, IList
existingForms, IList packetSubmissions) : base(id, number, participationId, version, packet, visitDate, initials, status, createdAt, createdBy, modifiedBy, deletedBy, isDeleted, existingForms) + { + if (packetSubmissions != null) + Submissions = packetSubmissions; + } + + } +} + diff --git a/src/UDS.Net.Services/DomainModels/Submission/PacketSubmission.cs b/src/UDS.Net.Services/DomainModels/Submission/PacketSubmission.cs index 2a05cfdb..19ab62ee 100644 --- a/src/UDS.Net.Services/DomainModels/Submission/PacketSubmission.cs +++ b/src/UDS.Net.Services/DomainModels/Submission/PacketSubmission.cs @@ -32,7 +32,7 @@ public class PacketSubmission public bool IsDeleted { get; set; } - public PacketSubmission(int id, string adrcId, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, int errorCount) + public PacketSubmission(int id, string adrcId, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, int? errorCount) { Id = id; ADRCId = adrcId; @@ -46,12 +46,12 @@ public PacketSubmission(int id, string adrcId, DateTime submissionDate, int visi ErrorCount = errorCount; } - public PacketSubmission(int id, string adrcId, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, int errorCount, IList forms) : this(id, adrcId, submissionDate, visitId, createdAt, createdBy, modifiedBy, deletedBy, isDeleted, errorCount) + public PacketSubmission(int id, string adrcId, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, int? errorCount, IList forms) : this(id, adrcId, submissionDate, visitId, createdAt, createdBy, modifiedBy, deletedBy, isDeleted, errorCount) { Forms = forms; } - public PacketSubmission(int id, string adrcId, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, int errorCount, IList errors) : this(id, adrcId, submissionDate, visitId, createdAt, createdBy, modifiedBy, deletedBy, isDeleted, errorCount) + public PacketSubmission(int id, string adrcId, DateTime submissionDate, int visitId, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, int? errorCount, IList errors) : this(id, adrcId, submissionDate, visitId, createdAt, createdBy, modifiedBy, deletedBy, isDeleted, errorCount) { if (errors != null) { diff --git a/src/UDS.Net.Services/DomainModels/Visit.cs b/src/UDS.Net.Services/DomainModels/Visit.cs index 3d68d696..62092aaa 100644 --- a/src/UDS.Net.Services/DomainModels/Visit.cs +++ b/src/UDS.Net.Services/DomainModels/Visit.cs @@ -88,7 +88,6 @@ public bool IsFinalizable public IList Forms { get; set; } = new List(); - public IList Submissions { get; set; } = new List(); private void BuildFormsContract(string version, PacketKind kind, DateTime visitDate, IList existingForms) { @@ -208,12 +207,6 @@ public Visit(int id, int number, int participationId, string version, PacketKind } - public Visit(int id, int number, int participationId, string version, PacketKind packet, DateTime visitDate, string initials, PacketStatus status, DateTime createdAt, string createdBy, string modifiedBy, string deletedBy, bool isDeleted, IList existingForms, IList packetSubmissions) : - this(id, number, participationId, version, packet, visitDate, initials, status, createdAt, createdBy, modifiedBy, deletedBy, isDeleted, existingForms) - { - if (packetSubmissions != null) - Submissions = packetSubmissions; - } // TODO There's form fields and then there's validation rules for the form fields based on visit type diff --git a/src/UDS.Net.Services/Extensions/DomainToDtoMapper.cs b/src/UDS.Net.Services/Extensions/DomainToDtoMapper.cs index b0b205a1..696d1ad7 100644 --- a/src/UDS.Net.Services/Extensions/DomainToDtoMapper.cs +++ b/src/UDS.Net.Services/Extensions/DomainToDtoMapper.cs @@ -132,6 +132,19 @@ public static VisitDto ToDto(this Visit visit, string formKind) return dto; } + public static PacketDto ToDto(this Packet packet) + { + var dto = new PacketDto(); + + dto.Id = packet.Id; + dto.Status = packet.Status.ToString(); + + if (packet.Submissions != null) + dto.PacketSubmissions = packet.Submissions.Select(s => s.ToDto()).ToList(); + + return dto; + } + public static PacketSubmissionDto ToDto(this PacketSubmission packetSubmission) { var dto = new PacketSubmissionDto diff --git a/src/UDS.Net.Services/Extensions/DtoToDomainMapper.cs b/src/UDS.Net.Services/Extensions/DtoToDomainMapper.cs index faa69cb3..d1b71835 100644 --- a/src/UDS.Net.Services/Extensions/DtoToDomainMapper.cs +++ b/src/UDS.Net.Services/Extensions/DtoToDomainMapper.cs @@ -56,14 +56,10 @@ public static Visit ToDomain(this VisitDto dto, string username) packetStatus = status; } - IList packetSubmissions = new List(); - - if (dto.PacketSubmissions != null) - packetSubmissions = dto.PacketSubmissions.ToDomain("", dto.Id, username); // we do not need the adrcid until packet submission/export - - return new Visit(dto.Id, dto.VISITNUM, dto.ParticipationId, dto.FORMVER, packetKind, dto.VISIT_DATE, dto.INITIALS, packetStatus, dto.CreatedAt, dto.CreatedBy, dto.ModifiedBy, dto.DeletedBy, dto.IsDeleted, existingForms, packetSubmissions); + return new Visit(dto.Id, dto.VISITNUM, dto.ParticipationId, dto.FORMVER, packetKind, dto.VISIT_DATE, dto.INITIALS, packetStatus, dto.CreatedAt, dto.CreatedBy, dto.ModifiedBy, dto.DeletedBy, dto.IsDeleted, existingForms); } + public static Milestone ToDomain(this M1Dto dto) { return new Milestone() @@ -273,6 +269,37 @@ public static Form ToDomain(this FormDto dto, int visitId, string username) return new Form(visitId, dto.Id, title, dto.Kind, formStatus, dto.FRMDATE, dto.INITIALS, formLanguage, formMode, remoteReasonCode, remoteModality, notIncludedReasonCode, dto.CreatedAt, dto.CreatedBy, dto.ModifiedBy, dto.DeletedBy, dto.IsDeleted, formFields); } + public static Packet ToDomain(this PacketDto dto, string username) + { + IList existingForms = new List(); + + if (dto.Forms != null) + existingForms = dto.Forms.ToDomain(dto.Id, username); + + PacketKind packetKind = PacketKind.I; + + if (!string.IsNullOrWhiteSpace(dto.PACKET)) + { + if (Enum.TryParse(dto.PACKET, true, out PacketKind kind)) + packetKind = kind; + } + + PacketStatus packetStatus = PacketStatus.Pending; + if (!string.IsNullOrWhiteSpace(dto.Status)) + { + if (!Enum.TryParse(dto.Status, true, out PacketStatus status)) + packetStatus = status; + } + + IList packetSubmissions = new List(); + + if (dto.PacketSubmissions != null) + packetSubmissions = dto.PacketSubmissions.ToDomain("", dto.Id, username); // we do not need the adrcid until packet submission/export + + return new Packet(dto.Id, dto.VISITNUM, dto.ParticipationId, dto.FORMVER, packetKind, dto.VISIT_DATE, dto.INITIALS, packetStatus, dto.CreatedAt, dto.CreatedBy, dto.ModifiedBy, dto.DeletedBy, dto.IsDeleted, existingForms, packetSubmissions); + + } + public static IList ToDomain(this List dto, string adrcId, int visitId, string username) { if (dto == null) diff --git a/src/UDS.Net.Services/IPacketService.cs b/src/UDS.Net.Services/IPacketService.cs new file mode 100644 index 00000000..984adfbb --- /dev/null +++ b/src/UDS.Net.Services/IPacketService.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using UDS.Net.Services.DomainModels; +using UDS.Net.Services.DomainModels.Submission; +using UDS.Net.Services.Enums; + +namespace UDS.Net.Services +{ + public interface IPacketService : IService + { + Task GetPacketWithForms(string username, int id); + + Task> List(string username, List statuses, int pageSize = 10, int pageIndex = 1); + + // TODO create packet submission error methods + + } +} + diff --git a/src/UDS.Net.Services/IPacketSubmissionService.cs b/src/UDS.Net.Services/IPacketSubmissionService.cs deleted file mode 100644 index f9edd922..00000000 --- a/src/UDS.Net.Services/IPacketSubmissionService.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Threading.Tasks; -using UDS.Net.Services.DomainModels; -using UDS.Net.Services.DomainModels.Submission; - -namespace UDS.Net.Services -{ - public interface IPacketSubmissionService : IService - { - Task GetPacketSubmissionWithForms(string username, int id); - - // TODO create packet submission error methods - - } -} - diff --git a/src/UDS.Net.Services/IVisitService.cs b/src/UDS.Net.Services/IVisitService.cs index c3a50db6..bfad8b5f 100644 --- a/src/UDS.Net.Services/IVisitService.cs +++ b/src/UDS.Net.Services/IVisitService.cs @@ -9,8 +9,6 @@ public interface IVisitService : IService { Task GetByIdWithForm(string username, int id, string formId); - 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 c275a055..96b8b9d6 100644 --- a/src/UDS.Net.Services/UDS.Net.Services.csproj +++ b/src/UDS.Net.Services/UDS.Net.Services.csproj @@ -13,6 +13,6 @@ 4.1.0-preview.2 - + \ No newline at end of file diff --git a/src/UDS.Net.Web.MVC.Services/PacketService.cs b/src/UDS.Net.Web.MVC.Services/PacketService.cs new file mode 100644 index 00000000..d9b49944 --- /dev/null +++ b/src/UDS.Net.Web.MVC.Services/PacketService.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using UDS.Net.API.Client; +using UDS.Net.Services; +using UDS.Net.Services.Extensions; +using UDS.Net.Services.DomainModels.Submission; +using Microsoft.Extensions.Configuration; +using System.Linq; +using UDS.Net.Services.Enums; + +namespace UDS.Net.Web.MVC.Services +{ + public class PacketService : IPacketService + { + private readonly IApiClient _apiClient; + private readonly IConfiguration _configuration; + + public PacketService(IApiClient apiClient, IConfiguration configuration) + { + _apiClient = apiClient; + _configuration = configuration; + } + + public async Task Add(string username, Packet entity) + { + await _apiClient.PacketClient.Post(entity.ToDto()); + + return entity; + } + + public async Task Count(string username) + { + return await _apiClient.PacketClient.Count(); + } + + public async Task GetById(string username, int id) + { + var packetDto = await _apiClient.PacketClient.Get(id); + + var adrcId = _configuration.GetSection("ADRC:Id"); + + if (packetDto != null) + return packetDto.ToDomain(username); + + throw new Exception("Packet not found"); + } + + public async Task GetPacketWithForms(string username, int id) + { + var packetSubmissionDto = await _apiClient.PacketClient.GetPacketWithForms(id); + + var adrcId = _configuration.GetSection("ADRC:Id"); + + if (packetSubmissionDto != null) + return packetSubmissionDto.ToDomain(adrcId.Value); + + throw new Exception("Packet not found"); + } + + public async Task> List(string username, int pageSize = 10, int pageIndex = 1) + { + List packets = new List(); + + var dto = await _apiClient.PacketClient.Get(pageSize, pageIndex); + + if (dto != null) + packets = dto.Select(p => p.ToDomain(username)).ToList(); + + return packets; + } + + public async Task> List(string username, List statuses, int pageSize = 10, int pageIndex = 1) + { + List packets = new List(); + + string[] stringStatuses = statuses.Select(s => s.ToString()).ToArray(); + + var dto = await _apiClient.PacketClient.GetPacketsByStatusAndAssignee(stringStatuses, "", pageSize, pageIndex); + + if (dto != null) + packets = dto.Select(p => p.ToDomain(username)).ToList(); + + return packets; + } + + public Task Patch(string username, Packet entity) + { + throw new NotImplementedException(); + } + + public Task Remove(string username, Packet entity) + { + throw new NotImplementedException(); + } + + public Task Update(string username, Packet entity) + { + throw new NotImplementedException(); + } + } +} + diff --git a/src/UDS.Net.Web.MVC.Services/PacketSubmissionService.cs b/src/UDS.Net.Web.MVC.Services/PacketSubmissionService.cs deleted file mode 100644 index ddc7d067..00000000 --- a/src/UDS.Net.Web.MVC.Services/PacketSubmissionService.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using UDS.Net.API.Client; -using UDS.Net.Services; -using UDS.Net.Services.Extensions; -using UDS.Net.Services.DomainModels.Submission; -using Microsoft.Extensions.Configuration; - -namespace UDS.Net.Web.MVC.Services -{ - public class PacketSubmissionService : IPacketSubmissionService - { - private readonly IApiClient _apiClient; - private readonly IConfiguration _configuration; - - public PacketSubmissionService(IApiClient apiClient, IConfiguration configuration) - { - _apiClient = apiClient; - _configuration = configuration; - } - - public async Task Add(string username, PacketSubmission entity) - { - await _apiClient.PacketSubmissionClient.Post(entity.ToDto()); - - return entity; - } - - public async Task Count(string username) - { - return await _apiClient.PacketSubmissionClient.Count(); - } - - public async Task GetById(string username, int id) - { - var packetSubmissionDto = await _apiClient.PacketSubmissionClient.Get(id); - - var adrcId = _configuration.GetSection("ADRC:Id"); - - if (packetSubmissionDto != null) - return packetSubmissionDto.ToDomain(adrcId.Value); - - throw new Exception("Packet submission not found"); - } - - public async Task GetPacketSubmissionWithForms(string username, int id) - { - var packetSubmissionDto = await _apiClient.PacketSubmissionClient.GetPacketSubmissionWithForms(id); - - var adrcId = _configuration.GetSection("ADRC:Id"); - - if (packetSubmissionDto != null) - return packetSubmissionDto.ToDomain(adrcId.Value); - - throw new Exception("Packet submission not found"); - } - - public async Task> List(string username, int pageSize = 10, int pageIndex = 1) - { - List submissions = new List(); - - var dto = await _apiClient.PacketSubmissionClient.Get(pageSize, pageIndex); - - //if (dto != null) - // submissions = dto.ToDomain(); - - return submissions; - } - - public Task Patch(string username, PacketSubmission entity) - { - throw new NotImplementedException(); - } - - public Task Remove(string username, PacketSubmission entity) - { - throw new NotImplementedException(); - } - - public Task Update(string username, PacketSubmission entity) - { - throw new NotImplementedException(); - } - } -} - 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 f1d683b7..428855dd 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 @@ -14,8 +14,8 @@ - - + + diff --git a/src/UDS.Net.Web.MVC.Services/VisitService.cs b/src/UDS.Net.Web.MVC.Services/VisitService.cs index d1fc5f97..d7c89fcf 100644 --- a/src/UDS.Net.Web.MVC.Services/VisitService.cs +++ b/src/UDS.Net.Web.MVC.Services/VisitService.cs @@ -60,18 +60,6 @@ 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, int pageSize = 10, int pageIndex = 1) - { - var visitDto = await _apiClient.VisitClient.GetWithPacketSubmissions(id, pageSize, pageIndex); - - if (visitDto != null) - { - return visitDto.ToDomain(username); // converting to domain object implements business rules for shown forms - } - - throw new Exception("Visit with form not found"); - } - public async Task> List(string username, int pageSize = 10, int pageIndex = 1) { var visitDtos = await _apiClient.VisitClient.Get(); diff --git a/src/UDS.Net.Web.MVC/Program.cs b/src/UDS.Net.Web.MVC/Program.cs index 170098be..dd5b0bf1 100644 --- a/src/UDS.Net.Web.MVC/Program.cs +++ b/src/UDS.Net.Web.MVC/Program.cs @@ -33,7 +33,7 @@ builder.Services.AddSingleton(); 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 10f7349d..995d51d0 100644 --- a/src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj +++ b/src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj @@ -20,8 +20,8 @@ all - - + + diff --git a/src/UDS.Net.Web.MVC/Views/Shared/_MainMenuItems.cshtml b/src/UDS.Net.Web.MVC/Views/Shared/_MainMenuItems.cshtml index 49fedad6..5534c496 100644 --- a/src/UDS.Net.Web.MVC/Views/Shared/_MainMenuItems.cshtml +++ b/src/UDS.Net.Web.MVC/Views/Shared/_MainMenuItems.cshtml @@ -17,4 +17,4 @@ Visits -Packet submissions \ No newline at end of file +Packet submissions \ No newline at end of file