-
Notifications
You must be signed in to change notification settings - Fork 11
OHID-475 Add remote user export in Admin section and other UI improvement #2858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dc7367b
Add remote user export in Admin section
bergomi02 4caf2bc
remove unused import
bergomi02 eb5d791
Merge branch 'develop' into feature/ohid-475
bergomi02 6ff009d
Potential fix for pull request finding 'Missed ternary opportunity'
bergomi02 184b8fa
Merge branch 'develop' into feature/ohid-475
bergomi02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,8 @@ | |
| .action-icon { | ||
| margin-top: -.4rem; | ||
| cursor: pointer; | ||
| width: 150px; | ||
| text-align: right; | ||
| } | ||
|
|
||
| &.divider { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using CsvHelper; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.Extensions.Logging; | ||
| using OfficeOpenXml; | ||
| using OfficeOpenXml.Style; | ||
|
|
||
| namespace Prime.Services | ||
| { | ||
| public class ExportService : BaseService, IExportService | ||
| { | ||
| public ExportService( | ||
| ApiDbContext context, | ||
| ILogger<ExportService> logger) | ||
| : base(context, logger) | ||
| { | ||
| // Set EPPlus license context | ||
| ExcelPackage.LicenseContext = LicenseContext.NonCommercial; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Export remote users to CSV format | ||
| /// </summary> | ||
| public async Task<byte[]> ExportRemoteUsersToCSVAsync(int siteId) | ||
| { | ||
| using (var memoryStream = new MemoryStream()) | ||
| using (var writer = new StreamWriter(memoryStream, Encoding.UTF8)) | ||
| using (var csvWriter = new CsvWriter(writer, CultureInfo.InvariantCulture)) | ||
| { | ||
| // Write headers | ||
| csvWriter.WriteHeader<RemoteUserExportDto>(); | ||
| await csvWriter.NextRecordAsync(); | ||
|
|
||
| // Write data | ||
| var exportDtos = await GetRemoteUsers(siteId); | ||
| await csvWriter.WriteRecordsAsync(exportDtos); | ||
| await writer.FlushAsync(); | ||
|
|
||
| return memoryStream.ToArray(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Export remote users to Excel format | ||
| /// </summary> | ||
| public async Task<byte[]> ExportRemoteUsersToExcelAsync(int siteId) | ||
| { | ||
| using (var package = new ExcelPackage()) | ||
| { | ||
| var worksheet = package.Workbook.Worksheets.Add("Remote Users"); | ||
|
|
||
| // Set headers | ||
| var headers = new[] { "First Name", "Last Name", "Email", "College", "License Class", "License Number", "Practitioner Id" }; | ||
| for (int i = 0; i < headers.Length; i++) | ||
| { | ||
| worksheet.Cells[1, i + 1].Value = headers[i]; | ||
| } | ||
|
|
||
| // Format header row | ||
| var headerRow = worksheet.Cells[1, 1, 1, headers.Length]; | ||
| headerRow.Style.Font.Bold = true; | ||
| headerRow.Style.Fill.PatternType = ExcelFillStyle.Solid; | ||
| headerRow.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray); | ||
|
|
||
| // Write data | ||
| var exportDtos = await GetRemoteUsers(siteId); | ||
| for (int i = 0; i < exportDtos.Count(); i++) | ||
| { | ||
| var dto = exportDtos.ElementAt(i); | ||
| worksheet.Cells[i + 2, 1].Value = dto.FirstName; | ||
| worksheet.Cells[i + 2, 2].Value = dto.LastName; | ||
| worksheet.Cells[i + 2, 3].Value = dto.Email; | ||
| worksheet.Cells[i + 2, 4].Value = dto.College; | ||
| worksheet.Cells[i + 2, 5].Value = dto.LicenseClass; | ||
| worksheet.Cells[i + 2, 6].Value = dto.LicenseNumber; | ||
| worksheet.Cells[i + 2, 7].Value = dto.PractitionerId; | ||
| } | ||
|
|
||
| // Auto-fit columns | ||
| worksheet.Cells.AutoFitColumns(); | ||
|
|
||
| return await Task.FromResult(package.GetAsByteArray()); | ||
|
Check warning on line 88 in prime-dotnet-webapi/Services/ExportService.cs
|
||
| } | ||
| } | ||
|
|
||
| private async Task<IEnumerable<RemoteUserExportDto>> GetRemoteUsers(int siteId) | ||
| { | ||
| return await _context.RemoteUsers | ||
| .Where(ru => ru.SiteId == siteId) | ||
| .Select(ru => new RemoteUserExportDto | ||
| { | ||
| FirstName = ru.FirstName, | ||
| LastName = ru.LastName, | ||
| Email = ru.Email, | ||
| College = ru.RemoteUserCertification.College.Name, | ||
| LicenseClass = ru.RemoteUserCertification.License.Name, | ||
| LicenseNumber = ru.RemoteUserCertification.LicenseNumber, | ||
| PractitionerId = ru.RemoteUserCertification.PractitionerId | ||
| }) | ||
| .ToListAsync(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// DTO for exporting remote user data | ||
| /// </summary> | ||
| public class RemoteUserExportDto | ||
| { | ||
| public string FirstName { get; set; } | ||
| public string LastName { get; set; } | ||
| public string Email { get; set; } | ||
| public string College { get; set; } | ||
| public string LicenseClass { get; set; } | ||
| public string LicenseNumber { get; set; } | ||
| public string PractitionerId { get; set; } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Prime.ViewModels.Sites; | ||
|
|
||
| namespace Prime.Services | ||
| { | ||
| public interface IExportService | ||
| { | ||
| /// <summary> | ||
| /// Export remote users to CSV format | ||
| /// </summary> | ||
| Task<byte[]> ExportRemoteUsersToCSVAsync(int siteId); | ||
|
|
||
| /// <summary> | ||
| /// Export remote users to Excel format | ||
| /// </summary> | ||
| Task<byte[]> ExportRemoteUsersToExcelAsync(int siteId); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.