Skip to content

Commit

Permalink
Simplify method to get order of forms for visit
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleybot committed Jan 30, 2025
1 parent d0f23f6 commit d5d1b78
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/UDS.Net.Forms.Tests/Services/VisitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public async Task<int> CountByStatus(string username, string[] statuses = null)
throw new NotImplementedException();
}

public Task<string> GetNextFormId(string username, int visitId, string currentFormId)
public Task<string> GetNextFormKind(string username, int visitId, string currentFormKind)
{
throw new NotImplementedException();
}

public Task<List<Form>> SortForms(string username, List<Form> forms)
public Task<List<string>> GetFormOrder(string username, int visitId)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/UDS.Net.Forms.Tests/UDS.Net.Forms.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ReleaseVersion>6.0.0-preview.4</ReleaseVersion>
<ReleaseVersion>6.0.0-preview.5</ReleaseVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
Expand Down
15 changes: 15 additions & 0 deletions src/UDS.Net.Forms/Models/PageModels/VisitPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ public virtual async Task<IActionResult> OnGet(int? id)
Visit = visit.ToVM();
Visit.Participation = participation.ToVM();

// Re-order forms
if (Visit.Forms != null)
{
// Sort forms
var ordering = await _visitService.GetFormOrder(User.Identity.Name, id.Value);
List<FormModel> forms = new List<FormModel>();
foreach (var kind in ordering)
{
var form = Visit.Forms.Where(f => f.Kind == kind).FirstOrDefault();
if (form != null)
forms.Add(form);
}
Visit.Forms = forms;
}

return Page();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/UDS.Net.Forms/UDS.Net.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<ImplicitUsings>enable</ImplicitUsings>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PackageId>UDS.Net.Forms</PackageId>
<Version>6.0.0-preview.4</Version>
<Version>6.0.0-preview.5</Version>
<Authors>Sanders-Brown Center on Aging</Authors>
<Description>UDS Forms razor class library</Description>
<Owners>UK-SBCoA</Owners>
<PackageDescription>Razor class library for rendering UDS forms</PackageDescription>
<RepositoryUrl>https://github.com/UK-SBCoA/uniform-data-set-dotnet-web</RepositoryUrl>
<ReleaseVersion>6.0.0-preview.4</ReleaseVersion>
<ReleaseVersion>6.0.0-preview.5</ReleaseVersion>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Expand Down
2 changes: 1 addition & 1 deletion src/UDS.Net.Services.Test/UDS.Net.Services.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<ReleaseVersion>6.0.0-preview.4</ReleaseVersion>
<ReleaseVersion>6.0.0-preview.5</ReleaseVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
Expand Down
4 changes: 2 additions & 2 deletions src/UDS.Net.Services/IVisitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public interface IVisitService : IService<Visit>

Task<Visit> UpdateForm(string username, Visit entity, string formId);

Task<List<Form>> SortForms(string username, List<Form> forms);
Task<List<string>> GetFormOrder(string username, int visitId);

Task<string> GetNextFormId(string username, int visitId, string currentFormId);
Task<string> GetNextFormKind(string username, int visitId, string currentFormKind);

Task<int> GetNextVisitNumber(string username, int participationId);

Expand Down
4 changes: 2 additions & 2 deletions src/UDS.Net.Services/UDS.Net.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<TargetFramework>netstandard2.1</TargetFramework>
<OutputType>Library</OutputType>
<PackageId>UDS.Net.Services</PackageId>
<Version>6.0.0-preview.4</Version>
<Version>6.0.0-preview.5</Version>
<Authors>Sanders-Brown Center on Aging</Authors>
<Description>Service contracts for implmenting your own back-end with MVC web app</Description>
<Owners>UK-SBCoA</Owners>
<PackageDescription>Service contracts required by MVC web app</PackageDescription>
<RepositoryUrl>https://github.com/UK-SBCoA/uniform-data-set-dotnet-web</RepositoryUrl>
<ReleaseVersion>6.0.0-preview.4</ReleaseVersion>
<ReleaseVersion>6.0.0-preview.5</ReleaseVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="UDS.Net.Dto" Version="4.5.0" />
Expand Down
4 changes: 2 additions & 2 deletions src/UDS.Net.Web.MVC.Services/UDS.Net.Web.MVC.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<TargetFramework>netstandard2.1</TargetFramework>
<OutputType>Library</OutputType>
<PackageId>UDS.Net.MVC.Services</PackageId>
<Version>6.0.0-preview.4</Version>
<Version>6.0.0-preview.5</Version>
<Authors>Sanders-Brown Center on Aging</Authors>
<Description>Implemented service layer for using MVC front-end with API back-end</Description>
<Owners>UK-SBCoA</Owners>
<PackageDescription>Implemented service contract</PackageDescription>
<RepositoryUrl>https://github.com/UK-SBCoA/uniform-data-set-dotnet-web</RepositoryUrl>
<ReleaseVersion>6.0.0-preview.4</ReleaseVersion>
<ReleaseVersion>6.0.0-preview.5</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
<ItemGroup>
Expand Down
17 changes: 9 additions & 8 deletions src/UDS.Net.Web.MVC.Services/VisitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,20 @@ public async Task<int> GetVisitCountByVersion(string username, int participation
throw new NotImplementedException("The developer must update with functionality to support pre-UDS version 4.");
}

public async Task<string> GetNextFormId(string username, int visitId, string currentFormId)
public async Task<string> GetNextFormKind(string username, int visitId, string currentFormKind)
{
var visit = await GetById(username, visitId);
var ordering = await GetFormOrder(username, visitId);

string nextFormId = "";

for (int i = 0; i < visit.Forms.Count(); i++)
for (int i = 0; i < ordering.Count(); i++)
{
if (visit.Forms[i].Kind == currentFormId)
if (ordering[i] == currentFormKind)
{
// check if there is a next form
if (i + 1 < visit.Forms.Count())
if (i + 1 < ordering.Count())
{
nextFormId = visit.Forms[i + 1].Kind;
nextFormId = ordering[i + 1];
break;
}
}
Expand All @@ -170,10 +170,11 @@ public async Task<string> GetNextFormId(string username, int visitId, string cur
return nextFormId;
}

public async Task<List<Form>> SortForms(string username, List<Form> forms)
public async Task<List<string>> GetFormOrder(string username, int visitId)
{
// In this implementation we are sorting by kind alphabetically, but other organizations may want the flexibilty to order forms by another parameter.
return forms.OrderBy(f => f.Kind).ToList();
var visit = await GetById(username, visitId);
return visit.Forms.OrderBy(f => f.Kind).Select(f => f.Kind).ToList();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-UDS.Net.Web.MVC-F92C0881-61B6-4292-8635-0004DE84CFE6</UserSecretsId>
<DockerComposeProjectPath>../docker-compose.dcproj</DockerComposeProjectPath>
<ReleaseVersion>6.0.0-preview.4</ReleaseVersion>
<ReleaseVersion>6.0.0-preview.5</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
Expand Down
2 changes: 1 addition & 1 deletion src/UDS.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ Global
SolutionGuid = {3268D734-1592-4E39-88A2-3A53468CC430}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 6.0.0-preview.4
version = 6.0.0-preview.5
EndGlobalSection
EndGlobal

0 comments on commit d5d1b78

Please sign in to comment.