All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m22s
187 lines
7.4 KiB
Plaintext
187 lines
7.4 KiB
Plaintext
@page "/sales/patients"
|
|
@using phronCare.UIBlazor.Services.Sales
|
|
@using phronCare.UIBlazor.Data
|
|
@using Domain.Entities
|
|
@using Domain.Generics
|
|
@using Domain.SearchParams
|
|
@inject IToastService toastService
|
|
@inject NavigationManager Navigation
|
|
@inject PatientService patientService
|
|
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-center align-items-center" style="zoom:80%;">
|
|
<h3 class="card-title m-0">Búsqueda de pacientes</h3>
|
|
</div>
|
|
<div class="card-body" style="zoom:80%;">
|
|
<div class="mb-4 space-y-2">
|
|
<input @bind="SearchParams.Name" placeholder="Nombre o Apellido" class="border rounded p-1 w-full" />
|
|
<input @bind="SearchParams.Document" placeholder="Documento" class="border rounded p-1 w-full" />
|
|
<button class="btn btn-primary rounded-pill" @onclick="BuscarPacientes">
|
|
<i class="fas fa-binoculars me-1"></i> Buscar
|
|
</button>
|
|
<button class="btn btn-success rounded-pill" @onclick="NuevoPaciente">
|
|
<i class="fas fa-plus me-1"></i> Nuevo
|
|
</button>
|
|
<button class="btn btn-success rounded-pill" @onclick="ExportarExcel">
|
|
<i class="fas fa-file-excel me-1"></i> Excel
|
|
</button>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="Volver">
|
|
<i class="fas fa-arrow-left me-1"></i> Volver
|
|
</button>
|
|
</div>
|
|
<hr />
|
|
<div>
|
|
@if (TablaPacientes != null && TablaPacientes.Any())
|
|
{
|
|
<PhTable Columns="TableColumns"
|
|
Data="TablaPacientes"
|
|
SelectionField="Id"
|
|
RowsPerPage=SearchParams.PageSize
|
|
RenderButtons="true" Buttons="botones"
|
|
ShowPageButtons="false"
|
|
ShowQuickSearch="false"
|
|
RenderSelect="false" />
|
|
}
|
|
else
|
|
{
|
|
<p>No hay resultados.</p>
|
|
}
|
|
</div>
|
|
</div>
|
|
<div class="card-footer d-flex justify-content-center align-items-center" style="zoom:80%;">
|
|
<div class="d-flex align-items-center gap-3">
|
|
<button class="btn btn-secondary rounded-pill" @onclick="PrimeraPagina" disabled="@(SearchParams.Page == 1)">
|
|
<i class="fas fa-angle-double-left me-1"></i> Primera
|
|
</button>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="AnteriorPagina" disabled="@(!PuedeRetroceder)">
|
|
<i class="fas fa-chevron-left me-1"></i> Anterior
|
|
</button>
|
|
<span class="mx-2">
|
|
Página <strong>@SearchParams.Page</strong> de <strong>@TotalPaginas</strong>
|
|
</span>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="SiguientePagina" disabled="@(!PuedeAvanzar)">
|
|
Siguiente <i class="fas fa-chevron-right ms-1"></i>
|
|
</button>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="UltimaPagina" disabled="@(SearchParams.Page == TotalPaginas)">
|
|
Última <i class="fas fa-angle-double-right ms-1"></i>
|
|
</button>
|
|
<div class="d-flex align-items-center ms-3">
|
|
<input type="number" class="form-control form-control-sm rounded" style="width: 80px;" min="1" max="@TotalPaginas" @bind="PaginaDeseada" />
|
|
<button class="btn btn-outline-primary btn-sm ms-2 rounded-pill" @onclick="IrAPagina">
|
|
<i class="fas fa-arrow-right-to-bracket me-1"></i> Ir
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
private PatientSearchParams SearchParams = new();
|
|
private PagedResult<EPatient>? PagedResult;
|
|
private List<Dictionary<string, object>> TablaPacientes = new();
|
|
private List<string> TableColumns = new()
|
|
{
|
|
"Id", "Nombre", "Apellido", "Documento", "#Socio | #Afiliado", "Género", "Teléfono", "Email"
|
|
};
|
|
private int PaginaDeseada = 1;
|
|
|
|
private List<PhTable.ButtonOptions> botones;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
botones = new List<PhTable.ButtonOptions>
|
|
{
|
|
new PhTable.ButtonOptions
|
|
{
|
|
Caption = "Editar",
|
|
ElementClass = "btn btn-primary btn-sm",
|
|
UrlAction = "/sales/patientform/",
|
|
OnClickAction = async (id) =>
|
|
{
|
|
if (int.TryParse(id, out var pacienteId))
|
|
{
|
|
Navigation.NavigateTo($"/sales/patientform/{pacienteId}");
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
private async Task BuscarPacientes() => await CargarPacientes();
|
|
|
|
private async Task CargarPacientes()
|
|
{
|
|
PagedResult = await patientService.SearchPatientsAsync(SearchParams);
|
|
if (PagedResult?.Items is not null)
|
|
{
|
|
TablaPacientes = PagedResult.Items.Select(p => new Dictionary<string, object>
|
|
{
|
|
{ "Id", p.Id },
|
|
{ "Nombre", p.Firstname ?? string.Empty },
|
|
{ "Apellido", p.Lastname ?? string.Empty },
|
|
{ "Documento", $"{p.DocumenttypesId} {p.DocumentNumber}" },
|
|
{ "#Socio | #Afiliado", $"{p.AffiliateNumber}" },
|
|
{ "Género", p.Gender ?? string.Empty },
|
|
{ "Teléfono", p.Phone ?? string.Empty },
|
|
{ "Email", p.Email ?? string.Empty }
|
|
}).ToList();
|
|
}
|
|
}
|
|
|
|
private async Task PrimeraPagina() { SearchParams.Page = 1; await BuscarPacientes(); }
|
|
private async Task UltimaPagina() { SearchParams.Page = TotalPaginas; await BuscarPacientes(); }
|
|
private async Task SiguientePagina() => await CambiarPagina(1);
|
|
private async Task AnteriorPagina() => await CambiarPagina(-1);
|
|
|
|
private async Task CambiarPagina(int delta)
|
|
{
|
|
var nuevaPagina = SearchParams.Page + delta;
|
|
if (nuevaPagina >= 1 && nuevaPagina <= TotalPaginas)
|
|
{
|
|
SearchParams.Page = nuevaPagina;
|
|
await BuscarPacientes();
|
|
}
|
|
}
|
|
|
|
private async Task IrAPagina()
|
|
{
|
|
if (PaginaDeseada >= 1 && PaginaDeseada <= TotalPaginas)
|
|
{
|
|
SearchParams.Page = PaginaDeseada;
|
|
await BuscarPacientes();
|
|
}
|
|
else
|
|
{
|
|
toastService.ShowWarning("Número de página fuera de rango.");
|
|
}
|
|
}
|
|
|
|
private async Task ExportarExcel()
|
|
{
|
|
var searchParams = new PatientSearchParams
|
|
{
|
|
Name = SearchParams.Name,
|
|
Document = SearchParams.Document,
|
|
Page = 1,
|
|
PageSize = int.MaxValue
|
|
};
|
|
try
|
|
{
|
|
await patientService.ExportFilteredAsync(searchParams);
|
|
toastService.ShowSuccess("Exportación completada exitosamente.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
toastService.ShowError($"{ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void NuevoPaciente() => Navigation.NavigateTo("/sales/patientform/");
|
|
private void Volver() => Navigation.NavigateTo("/DashboardPanel");
|
|
|
|
private bool PuedeRetroceder => PagedResult != null && SearchParams.Page > 1;
|
|
private bool PuedeAvanzar => PagedResult != null && SearchParams.Page < TotalPaginas;
|
|
private int TotalPaginas => PagedResult is null ? 1 :
|
|
(int)Math.Ceiling((double)(PagedResult.TotalItems) / SearchParams.PageSize);
|
|
}
|