initial commit

This commit is contained in:
2026-07-21 13:52:43 +07:00
commit f0e6f38940
881 changed files with 66309 additions and 0 deletions
@@ -0,0 +1,28 @@
@page "/medical/medical-record"
@using Indotalent.Features.Medical.MedicalRecord
@using Indotalent.Features.Medical.MedicalRecord.Cqrs
@using Indotalent.Features.Medical.MedicalRecord.Components
@using MudBlazor
@if (_currentView == ViewMode.Create)
{
<_MedicalRecordCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
}
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
{
<_MedicalRecordUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
}
else
{
<_MedicalRecordDataTable OnAdd="() => ShowCreate()" OnEdit="(item) => ShowUpdate(item, false)" OnView="(item) => ShowUpdate(item, true)" />
}
@code {
private enum ViewMode { Table, Create, Update, View }
private ViewMode _currentView = ViewMode.Table;
private UpdateMedicalRecordRequest? _selectedData;
private void ShowCreate() => _currentView = ViewMode.Create;
private void ShowUpdate(UpdateMedicalRecordRequest data, bool isReadOnly) { _selectedData = data; _currentView = isReadOnly ? ViewMode.View : ViewMode.Update; }
private void BackToTable() { _currentView = ViewMode.Table; _selectedData = null; }
private void HandleSuccess() { _currentView = ViewMode.Table; _selectedData = null; }
}
@@ -0,0 +1,184 @@
@using Indotalent.Features.Medical.MedicalRecord
@using Indotalent.Features.Medical.MedicalRecord.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@inject MedicalRecordService MedicalRecordService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add Medical Record</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">Create a new clinical examination record for patient.</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 8px; border: 1px solid #DCEBFA;">
<MudForm @ref="_form" Model="_model">
<MudGrid Spacing="3">
<MudItem xs="12">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Administration & Metadata</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Record Date</MudText>
<MudDatePicker @bind-Date="_model.RecordDate" For="@(() => _model.RecordDate)" Variant="Variant.Outlined" Margin="Margin.Dense"/>
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Patient</MudText>
<MudSelect @bind-Value="_model.PatientId" For="@(() => _model.PatientId)" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.Patients)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Examining Doctor</MudText>
<MudSelect @bind-Value="_model.EmployeeId" For="@(() => _model.EmployeeId)" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.Doctors)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Group</MudText>
<MudSelect @bind-Value="_model.MedicalRecordGroupId" For="@(() => _model.MedicalRecordGroupId)" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.MedicalRecordGroups)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Category</MudText>
<MudSelect @bind-Value="_model.MedicalRecordCategoryId" For="@(() => _model.MedicalRecordCategoryId)" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.MedicalRecordCategories)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Record Status</MudText>
<MudSelect @bind-Value="_model.Status" For="@(() => _model.Status)" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.Statuses)
{
<MudSelectItem Value="@((Indotalent.Data.Enums.MedicalRecordStatus)item.Value)">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" Class="mt-4">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Vital Signs</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="2">
<MudText Typo="Typo.subtitle2" Class="mb-1">Blood Pressure</MudText>
<MudTextField @bind-Value="_model.BloodPressure" Placeholder="120/80 mmHg" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="2">
<MudText Typo="Typo.subtitle2" Class="mb-1">Temperature</MudText>
<MudTextField @bind-Value="_model.Temperature" Placeholder="36.5 C" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="2">
<MudText Typo="Typo.subtitle2" Class="mb-1">Heart Rate</MudText>
<MudTextField @bind-Value="_model.HeartRate" Placeholder="80 bpm" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="3">
<MudText Typo="Typo.subtitle2" Class="mb-1">Weight</MudText>
<MudTextField @bind-Value="_model.Weight" Placeholder="kg" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="3">
<MudText Typo="Typo.subtitle2" Class="mb-1">Height</MudText>
<MudTextField @bind-Value="_model.Height" Placeholder="cm" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" Class="mt-4">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Clinical Findings (SOAP)</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Subjective (S)</MudText>
<MudTextField @bind-Value="_model.Subjective" Placeholder="Patient's complaints..." Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Objective (O)</MudText>
<MudTextField @bind-Value="_model.Objective" Placeholder="Physical exam results..." Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Assessment (A)</MudText>
<MudTextField @bind-Value="_model.Assessment" For="@(() => _model.Assessment)" Placeholder="Diagnosis..." Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Planning (P)</MudText>
<MudTextField @bind-Value="_model.Planning" Placeholder="Treatment plan..." Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
</MudItem>
<MudItem xs="12">
<MudText Typo="Typo.subtitle2" Class="mb-1">Additional Notes</MudText>
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-8">
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border-radius: 8px; text-transform: none; font-weight: 700;">Cancel</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 8px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText>Create Medical Record</MudText>
}
</MudButton>
</div>
</MudForm>
</MudPaper>
@code {
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm _form = default!;
private CreateMedicalRecordValidator _validator = new();
private CreateMedicalRecordRequest _model = new() { RecordDate = DateTime.Now };
private LookupMedicalRecordResponse _lookupData = new();
private bool _processing = false;
protected override async Task OnInitializedAsync()
{
var response = await MedicalRecordService.GetMedicalRecordLookupAsync();
if (response != null && response.IsSuccess) { _lookupData = response.Value!; }
}
private async Task Submit()
{
await _form.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var response = await MedicalRecordService.CreateMedicalRecordAsync(_model);
await Task.Delay(500);
if (response != null && response.IsSuccess)
{
Snackbar.Add("Medical record created successfully", Severity.Success);
await OnSuccess.InvokeAsync();
}
}
finally { _processing = false; }
}
}
@@ -0,0 +1,357 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Medical.MedicalRecord
@using Indotalent.Features.Medical.MedicalRecord.Cqrs
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using MudBlazor
@using Features.Root.Shared
@using ClosedXML.Excel
@using System.IO
@inject MedicalRecordService MedicalRecordService
@inject IDialogService DialogService
@inject ISnackbar Snackbar
@inject IJSRuntime JSRuntime
<MudPaper Elevation="0" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
<div>
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Medical Record Management</MudText>
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Maintain and track patient clinical encounter records.</MudText>
</div>
<div class="d-flex align-center gap-2">
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Medical</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Medical Record</MudText>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
<div style="display: flex; align-items: center; gap: 8px;">
<MudTextField @bind-Value="_searchString"
Placeholder="Search patient or record number..."
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
IconSize="Size.Small"
Class="mt-0"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Style="background-color: white; width: 280px; border-radius: 12px;"
OnKeyDown="@HandleSearchKeyDown" />
<MudButton Variant="Variant.Text"
Color="Color.Primary"
OnClick="OnSearchClick"
Size="Size.Small"
Style="background:#3B82F6; color:white; font-weight:500; border-radius:6px; text-transform:none; height:34px; padding:0 16px;">
Search
</MudButton>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudButton Variant="Variant.Text"
Color="Color.Success"
OnClick="ExportToExcel"
Size="Size.Small"
Disabled="_isExporting"
StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)"
Style="background:white; border:1px solid #D1D5DB; font-weight:500; border-radius:6px; text-transform:none; height:34px; padding:0 16px;">
@if (_isExporting)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
}
</MudButton>
<MudButton Variant="Variant.Text"
Color="Color.Primary"
OnClick="LoadData"
Size="Size.Small"
StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)"
Disabled="_isRefreshing"
Style="background:white; border:1px solid #D1D5DB; font-weight:500; border-radius:6px; text-transform:none; height:34px; padding:0 16px;">
@if (_isRefreshing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
}
</MudButton>
@if (_selectedRecord != null)
{
<MudButton Variant="Variant.Text"
Color="Color.Info"
StartIcon="@Icons.Material.Filled.Visibility"
OnClick="InvokeView"
Size="Size.Small"
Style="background:white; border:1px solid #D1D5DB; font-weight:500; border-radius:6px; text-transform:none; height:34px; padding:0 12px;">View</MudButton>
<MudButton Variant="Variant.Text"
Color="Color.Primary"
StartIcon="@Icons.Material.Filled.Edit"
OnClick="InvokeEdit"
Size="Size.Small"
Style="background:white; border:1px solid #D1D5DB; font-weight:500; border-radius:6px; text-transform:none; height:34px; padding:0 12px;">Edit</MudButton>
<MudButton Variant="Variant.Text"
Color="Color.Error"
StartIcon="@Icons.Material.Filled.Delete"
OnClick="OnDelete"
Size="Size.Small"
Style="background:white; border:1px solid #FCA5A5; font-weight:500; border-radius:6px; text-transform:none; height:34px; padding:0 12px;">
Remove
</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedRecord = null" />
}
else
{
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 700; border-radius: 12px; height: 34px;">
Add Medical Record
</MudButton>
}
</div>
</div>
<MudTable Items="@GetPagedData()" Striped="true" Class="mud-table-styled" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetMedicalRecordListResponse" OnRowClick="@((args) => _selectedRecord = args.Item)" Loading="@_isRefreshing">
<HeaderContent>
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetMedicalRecordListResponse, object>(x => x.PatientName!)">Patient & Record</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetMedicalRecordListResponse, object>(x => x.RecordDate!)">Date</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">Doctor</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">Assessment / Diagnosis</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">Status</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>
<MudCheckBox T="bool" Value="@(_selectedRecord?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
</MudTd>
<MudTd>
<div class="d-flex flex-column">
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.PatientName</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">@context.AutoNumber</MudText>
</div>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.RecordDate?.ToString("MM/dd/yyyy")</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.EmployeeName</MudTd>
<MudTd>
<MudText Typo="Typo.body2" Style="max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
@context.Assessment
</MudText>
</MudTd>
<MudTd>
<MudChip T="string" Size="Size.Small" Variant="Variant.Text"
Color="@(context.Status == Indotalent.Data.Enums.MedicalRecordStatus.Completed ? Color.Success : Color.Info)"
Style="font-weight: 700; border-radius: 16px;">@context.Status.ToString().ToUpper()</MudChip>
</MudTd>
</RowTemplate>
</MudTable>
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
<div style="display: flex; align-items: center; gap: 12px;">
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
<MudSelect T="int" Value="@_top" ValueChanged="OnPageSizeChanged" Dense="true" Margin="Margin.Dense" Style="width: 110px; background-color: white; font-size: 12px; font-weight: 600; border-radius: 6px;" Variant="Variant.Outlined" Class="mt-0 custom-select-dense">
<MudSelectItem Value="5" />
<MudSelectItem Value="10" />
<MudSelectItem Value="50" />
</MudSelect>
<MudText Typo="Typo.caption" Style="color: #9CA3AF; margin-left: 12px;">
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
</MudText>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" />
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="@(_currentPage == 1 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #374151;")">Prev</MudButton>
@{
var totalPages = _totalPage == 0 ? 1 : _totalPage;
var maxVisible = 5;
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
}
@for (int i = startPage; i <= endPage; i++)
{
var pageNum = i;
var isActive = pageNum == _currentPage;
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
Variant="Variant.Text" Size="Size.Small"
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
}
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #374151;")">Next</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" />
</div>
</div>
</MudPaper>
<style>
.mud-input-outlined-border { border-radius: 6px !important; }
.custom-select-dense .mud-input { min-height: 24px !important; max-height: 24px !important; }
.custom-select-dense .mud-input-slot { padding-top: 1px !important; padding-bottom: 1px !important; padding-left: 6px !important; padding-right: 2px !important; font-size: 11px !important; min-height: unset !important; line-height: 1.2 !important; }
.custom-select-dense .mud-select-input { padding-top: 1px !important; padding-bottom: 1px !important; font-size: 11px !important; }
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
</style>
@code {
[Parameter] public EventCallback OnAdd { get; set; }
[Parameter] public EventCallback<UpdateMedicalRecordRequest> OnEdit { get; set; }
[Parameter] public EventCallback<UpdateMedicalRecordRequest> OnView { get; set; }
private List<GetMedicalRecordListResponse> _records = new();
private GetMedicalRecordListResponse? _selectedRecord;
private string _searchString = "";
private bool _isRefreshing = false;
private bool _isExporting = false;
private int _skip = 0;
private int _top = 10;
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
protected override async Task OnInitializedAsync() => await LoadData();
private async Task LoadData()
{
_isRefreshing = true;
_selectedRecord = null;
StateHasChanged();
try
{
var response = await MedicalRecordService.GetMedicalRecordListAsync();
await Task.Delay(500);
if (response != null && response.IsSuccess) { _records = response.Value ?? new List<GetMedicalRecordListResponse>(); }
}
finally { _isRefreshing = false; StateHasChanged(); }
}
private IEnumerable<GetMedicalRecordListResponse> GetFilteredData()
{
if (string.IsNullOrWhiteSpace(_searchString)) return _records;
return _records.Where(x =>
(x.PatientName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.Assessment?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
);
}
private IEnumerable<GetMedicalRecordListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
private void OnSearchClick() { _skip = 0; _selectedRecord = null; StateHasChanged(); }
private void HandleSearchKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") OnSearchClick(); }
private async Task ExportToExcel()
{
_isExporting = true;
StateHasChanged();
try
{
await Task.Delay(1000);
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.Worksheets.Add("MedicalRecords");
var headerRange = worksheet.Range(1, 1, 1, 6);
headerRange.Style.Font.Bold = true;
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#9CA3AF");
headerRange.Style.Font.FontColor = XLColor.White;
worksheet.Cell(1, 1).Value = "Record Number";
worksheet.Cell(1, 2).Value = "Date";
worksheet.Cell(1, 3).Value = "Patient Name";
worksheet.Cell(1, 4).Value = "Doctor";
worksheet.Cell(1, 5).Value = "Assessment / Diagnosis";
worksheet.Cell(1, 6).Value = "Status";
var currentRow = 1;
foreach (var item in GetFilteredData())
{
currentRow++;
worksheet.Cell(currentRow, 1).Value = item.AutoNumber;
worksheet.Cell(currentRow, 2).Value = item.RecordDate?.ToString("MM/dd/yyyy");
worksheet.Cell(currentRow, 3).Value = item.PatientName;
worksheet.Cell(currentRow, 4).Value = item.EmployeeName;
worksheet.Cell(currentRow, 5).Value = item.Assessment;
worksheet.Cell(currentRow, 6).Value = item.Status.ToString();
}
worksheet.Columns().AdjustToContents();
using (var stream = new MemoryStream())
{
workbook.SaveAs(stream);
var content = Convert.ToBase64String(stream.ToArray());
await JSRuntime.InvokeVoidAsync("downloadFile", "Medical_Record_List.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
Snackbar.Add("Medical records exported successfully", Severity.Success);
}
}
}
catch (Exception ex)
{
Snackbar.Add($"Export failed: {ex.Message}", Severity.Error);
}
finally { _isExporting = false; StateHasChanged(); }
}
private void OnPageChanged(int page) { if (page >= 1 && page <= _totalPage) { _skip = (page - 1) * _top; _selectedRecord = null; StateHasChanged(); } }
private void OnPageSizeChanged(int size) { _top = size; _skip = 0; _selectedRecord = null; StateHasChanged(); }
private async Task InvokeEdit() { if (_selectedRecord != null) { var req = await MapToUpdateRequest(_selectedRecord.Id!); if (req != null) await OnEdit.InvokeAsync(req); } }
private async Task InvokeView() { if (_selectedRecord != null) { var req = await MapToUpdateRequest(_selectedRecord.Id!); if (req != null) await OnView.InvokeAsync(req); } }
private async Task<UpdateMedicalRecordRequest?> MapToUpdateRequest(string id)
{
var response = await MedicalRecordService.GetMedicalRecordByIdAsync(id);
if (response != null && response.IsSuccess && response.Value != null)
{
var d = response.Value;
return new UpdateMedicalRecordRequest
{
Id = d.Id,
AutoNumber = d.AutoNumber,
RecordDate = d.RecordDate,
PatientId = d.PatientId,
EmployeeId = d.EmployeeId,
Subjective = d.Subjective,
Objective = d.Objective,
Assessment = d.Assessment,
Planning = d.Planning,
BloodPressure = d.BloodPressure,
Temperature = d.Temperature,
HeartRate = d.HeartRate,
Weight = d.Weight,
Height = d.Height,
Status = d.Status,
Description = d.Description,
MedicalRecordGroupId = d.MedicalRecordGroupId,
MedicalRecordCategoryId = d.MedicalRecordCategoryId,
CreatedAt = d.CreatedAt,
CreatedBy = d.CreatedBy,
UpdatedAt = d.UpdatedAt,
UpdatedBy = d.UpdatedBy
};
}
return null;
}
private async Task OnDelete()
{
if (_selectedRecord == null) return;
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, $"{_selectedRecord.AutoNumber} ({_selectedRecord.PatientName})" } };
var options = new DialogOptions { CloseButton = false, MaxWidth = MaxWidth.ExtraSmall, FullWidth = true };
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, options);
var result = await dialog.Result;
if (result != null && !result.Canceled)
{
var success = await MedicalRecordService.DeleteMedicalRecordByIdAsync(_selectedRecord.Id!);
if (success) { _selectedRecord = null; await LoadData(); Snackbar.Add("Medical record deleted successfully", Severity.Success); }
}
}
}
@@ -0,0 +1,257 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Medical.MedicalRecord
@using Indotalent.Features.Medical.MedicalRecord.Cqrs
@using Indotalent.Features.Medical.MedicalRecord.Components
@using Indotalent.Shared.Utils
@using MudBlazor
@inject MedicalRecordService MedicalRecordService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Medical Record Detail" : "Edit Medical Record")</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing detailed clinical examination record." : "Update clinical findings and vital signs.")</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 8px; border: 1px solid #DCEBFA;">
@if (_isDataLoading)
{
<div class="d-flex justify-center pa-10"><MudProgressCircular Color="Color.Primary" Indeterminate="true" /></div>
}
else
{
<MudForm @ref="_form" Model="_model">
<MudGrid Spacing="3">
<MudItem xs="12">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Administration & Metadata</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Record Number</MudText>
<MudTextField @bind-Value="_model.AutoNumber" ReadOnly="true" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Record Date</MudText>
<MudDatePicker @bind-Date="_model.RecordDate" For="@(() => _model.RecordDate)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Record Status</MudText>
<MudSelect @bind-Value="_model.Status" For="@(() => _model.Status)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.Statuses)
{
<MudSelectItem Value="@((Indotalent.Data.Enums.MedicalRecordStatus)item.Value)">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Patient</MudText>
<MudSelect @bind-Value="_model.PatientId" For="@(() => _model.PatientId)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.Patients)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Examining Doctor</MudText>
<MudSelect @bind-Value="_model.EmployeeId" For="@(() => _model.EmployeeId)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.Doctors)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Group</MudText>
<MudSelect @bind-Value="_model.MedicalRecordGroupId" For="@(() => _model.MedicalRecordGroupId)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.MedicalRecordGroups)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Category</MudText>
<MudSelect @bind-Value="_model.MedicalRecordCategoryId" For="@(() => _model.MedicalRecordCategoryId)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
@foreach (var item in _lookupData.MedicalRecordCategories)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" Class="mt-4">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Vital Signs</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="2">
<MudText Typo="Typo.subtitle2" Class="mb-1">Blood Pressure</MudText>
<MudTextField @bind-Value="_model.BloodPressure" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="2">
<MudText Typo="Typo.subtitle2" Class="mb-1">Temperature</MudText>
<MudTextField @bind-Value="_model.Temperature" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="2">
<MudText Typo="Typo.subtitle2" Class="mb-1">Heart Rate</MudText>
<MudTextField @bind-Value="_model.HeartRate" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="3">
<MudText Typo="Typo.subtitle2" Class="mb-1">Weight</MudText>
<MudTextField @bind-Value="_model.Weight" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="3">
<MudText Typo="Typo.subtitle2" Class="mb-1">Height</MudText>
<MudTextField @bind-Value="_model.Height" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" Class="mt-4">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Clinical Findings (SOAP)</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Subjective (S)</MudText>
<MudTextField @bind-Value="_model.Subjective" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Objective (O)</MudText>
<MudTextField @bind-Value="_model.Objective" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Assessment (A)</MudText>
<MudTextField @bind-Value="_model.Assessment" For="@(() => _model.Assessment)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Planning (P)</MudText>
<MudTextField @bind-Value="_model.Planning" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
</MudItem>
<MudItem xs="12">
<MudText Typo="Typo.subtitle2" Class="mb-1">Additional Notes</MudText>
<MudTextField @bind-Value="_model.Description" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
</MudItem>
<MudItem xs="12" Class="mt-4">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Audit History</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.CreatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System")</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.UpdatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")</MudText>
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-10">
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border-radius: 8px; text-transform: none; font-weight: 700;">@(ReadOnly ? "Back to List" : "Cancel")</MudButton>
@if (!ReadOnly)
{
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 8px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2">Updating...</MudText>
}
else
{
<MudText>Save Changes</MudText>
}
</MudButton>
}
</div>
</MudForm>
}
</MudPaper>
@code {
[Parameter] public UpdateMedicalRecordRequest Data { get; set; } = new();
[Parameter] public bool ReadOnly { get; set; } = false;
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm _form = default!;
private UpdateMedicalRecordValidator _validator = new();
private GetMedicalRecordByIdResponse _model = new();
private LookupMedicalRecordResponse _lookupData = new();
private bool _processing = false;
private bool _isDataLoading = true;
protected override async Task OnInitializedAsync()
{
await RefreshData();
}
private async Task RefreshData()
{
_isDataLoading = true;
try
{
var response = await MedicalRecordService.GetMedicalRecordLookupAsync();
if (response != null && response.IsSuccess) { _lookupData = response.Value!; }
var medical = await MedicalRecordService.GetMedicalRecordByIdAsync(Data.Id!);
if (medical != null && medical.IsSuccess) { _model = medical.Value!; }
}
finally { _isDataLoading = false; }
}
private async Task Submit()
{
if (ReadOnly) return;
await _form.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var updateRequest = new UpdateMedicalRecordRequest
{
Id = _model.Id,
AutoNumber = _model.AutoNumber,
RecordDate = _model.RecordDate,
PatientId = _model.PatientId,
EmployeeId = _model.EmployeeId,
Subjective = _model.Subjective,
Objective = _model.Objective,
Assessment = _model.Assessment,
Planning = _model.Planning,
BloodPressure = _model.BloodPressure,
Temperature = _model.Temperature,
HeartRate = _model.HeartRate,
Weight = _model.Weight,
Height = _model.Height,
Status = _model.Status,
Description = _model.Description,
MedicalRecordGroupId = _model.MedicalRecordGroupId,
MedicalRecordCategoryId = _model.MedicalRecordCategoryId
};
var response = await MedicalRecordService.UpdateMedicalRecordAsync(updateRequest);
await Task.Delay(500);
if (response != null && response.IsSuccess) { Snackbar.Add("Medical record updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); }
}
finally { _processing = false; }
}
}
@@ -0,0 +1,84 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class CreateMedicalRecordRequest
{
public DateTime? RecordDate { get; set; }
public string? PatientId { get; set; }
public string? EmployeeId { get; set; }
public string? Subjective { get; set; }
public string? Objective { get; set; }
public string? Assessment { get; set; }
public string? Planning { get; set; }
public string? BloodPressure { get; set; }
public string? Temperature { get; set; }
public string? HeartRate { get; set; }
public string? Weight { get; set; }
public string? Height { get; set; }
public MedicalRecordStatus Status { get; set; }
public string? Description { get; set; }
public string? MedicalRecordGroupId { get; set; }
public string? MedicalRecordCategoryId { get; set; }
}
public class CreateMedicalRecordResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
}
public record CreateMedicalRecordCommand(CreateMedicalRecordRequest Data) : IRequest<CreateMedicalRecordResponse>;
public class CreateMedicalRecordHandler : IRequestHandler<CreateMedicalRecordCommand, CreateMedicalRecordResponse>
{
private readonly AppDbContext _context;
public CreateMedicalRecordHandler(AppDbContext context) => _context = context;
public async Task<CreateMedicalRecordResponse> Handle(CreateMedicalRecordCommand request, CancellationToken cancellationToken)
{
var entityName = nameof(Data.Entities.MedicalRecord);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"MR/{{Year}}/{{Month}}/",
ct: cancellationToken
);
var entity = new Data.Entities.MedicalRecord
{
AutoNumber = autoNo,
RecordDate = request.Data.RecordDate ?? DateTime.Now,
PatientId = request.Data.PatientId,
EmployeeId = request.Data.EmployeeId,
Subjective = request.Data.Subjective,
Objective = request.Data.Objective,
Assessment = request.Data.Assessment,
Planning = request.Data.Planning,
BloodPressure = request.Data.BloodPressure,
Temperature = request.Data.Temperature,
HeartRate = request.Data.HeartRate,
Weight = request.Data.Weight,
Height = request.Data.Height,
Status = request.Data.Status,
Description = request.Data.Description,
MedicalRecordGroupId = request.Data.MedicalRecordGroupId,
MedicalRecordCategoryId = request.Data.MedicalRecordCategoryId
};
_context.MedicalRecord.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateMedicalRecordResponse
{
Id = entity.Id,
AutoNumber = entity.AutoNumber
};
}
}
@@ -0,0 +1,53 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class CreateMedicalRecordValidator : AbstractValidator<CreateMedicalRecordRequest>
{
public CreateMedicalRecordValidator()
{
RuleFor(x => x.RecordDate)
.NotEmpty().WithMessage("Record Date is required");
RuleFor(x => x.PatientId)
.NotEmpty().WithMessage("Patient is required");
RuleFor(x => x.EmployeeId)
.NotEmpty().WithMessage("Examining Doctor is required");
RuleFor(x => x.MedicalRecordGroupId)
.NotEmpty().WithMessage("Medical Record Group is required");
RuleFor(x => x.MedicalRecordCategoryId)
.NotEmpty().WithMessage("Medical Record Category is required");
RuleFor(x => x.Assessment)
.NotEmpty().WithMessage("Assessment (Diagnosis) is required")
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Subjective)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Objective)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Planning)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.BloodPressure)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Temperature)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.HeartRate)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Weight)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Height)
.MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public record DeleteMedicalRecordByIdRequest(string Id);
public record DeleteMedicalRecordByIdCommand(DeleteMedicalRecordByIdRequest Data) : IRequest<bool>;
public class DeleteMedicalRecordByIdHandler : IRequestHandler<DeleteMedicalRecordByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteMedicalRecordByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteMedicalRecordByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.MedicalRecord
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.MedicalRecord.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,80 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class GetMedicalRecordByIdResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public DateTime? RecordDate { get; set; }
public string? PatientId { get; set; }
public string? PatientName { get; set; }
public string? EmployeeId { get; set; }
public string? EmployeeName { get; set; }
public string? Subjective { get; set; }
public string? Objective { get; set; }
public string? Assessment { get; set; }
public string? Planning { get; set; }
public string? BloodPressure { get; set; }
public string? Temperature { get; set; }
public string? HeartRate { get; set; }
public string? Weight { get; set; }
public string? Height { get; set; }
public MedicalRecordStatus Status { get; set; }
public string? Description { get; set; }
public string? MedicalRecordGroupId { get; set; }
public string? MedicalRecordCategoryId { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetMedicalRecordByIdQuery(string Id) : IRequest<GetMedicalRecordByIdResponse?>;
public class GetMedicalRecordByIdHandler : IRequestHandler<GetMedicalRecordByIdQuery, GetMedicalRecordByIdResponse?>
{
private readonly AppDbContext _context;
public GetMedicalRecordByIdHandler(AppDbContext context) => _context = context;
public async Task<GetMedicalRecordByIdResponse?> Handle(GetMedicalRecordByIdQuery request, CancellationToken cancellationToken)
{
return await _context.MedicalRecord
.AsNoTracking()
.Include(x => x.Patient)
.Include(x => x.Employee)
.Where(x => x.Id == request.Id)
.Select(x => new GetMedicalRecordByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
RecordDate = x.RecordDate,
PatientId = x.PatientId,
PatientName = x.Patient != null ? x.Patient.Name : string.Empty,
EmployeeId = x.EmployeeId,
EmployeeName = x.Employee != null ? x.Employee.Name : string.Empty,
Subjective = x.Subjective,
Objective = x.Objective,
Assessment = x.Assessment,
Planning = x.Planning,
BloodPressure = x.BloodPressure,
Temperature = x.Temperature,
HeartRate = x.HeartRate,
Weight = x.Weight,
Height = x.Height,
Status = x.Status,
Description = x.Description,
MedicalRecordGroupId = x.MedicalRecordGroupId,
MedicalRecordCategoryId = x.MedicalRecordCategoryId,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,52 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class GetMedicalRecordListResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public DateTime? RecordDate { get; set; }
public string? PatientName { get; set; }
public string? EmployeeName { get; set; }
public string? Assessment { get; set; }
public MedicalRecordStatus Status { get; set; }
public string? MedicalRecordGroupName { get; set; }
public string? MedicalRecordCategoryName { get; set; }
}
public record GetMedicalRecordListQuery() : IRequest<List<GetMedicalRecordListResponse>>;
public class GetMedicalRecordListHandler : IRequestHandler<GetMedicalRecordListQuery, List<GetMedicalRecordListResponse>>
{
private readonly AppDbContext _context;
public GetMedicalRecordListHandler(AppDbContext context) => _context = context;
public async Task<List<GetMedicalRecordListResponse>> Handle(GetMedicalRecordListQuery request, CancellationToken cancellationToken)
{
return await _context.MedicalRecord
.AsNoTracking()
.Include(x => x.Patient)
.Include(x => x.Employee)
.Include(x => x.MedicalRecordGroup)
.Include(x => x.MedicalRecordCategory)
.OrderByDescending(x => x.RecordDate)
.Select(x => new GetMedicalRecordListResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
RecordDate = x.RecordDate,
PatientName = x.Patient != null ? x.Patient.Name : string.Empty,
EmployeeName = x.Employee != null ? x.Employee.Name : string.Empty,
Assessment = x.Assessment,
Status = x.Status,
MedicalRecordGroupName = x.MedicalRecordGroup != null ? x.MedicalRecordGroup.Name : string.Empty,
MedicalRecordCategoryName = x.MedicalRecordCategory != null ? x.MedicalRecordCategory.Name : string.Empty
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,78 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
using Indotalent.Shared.Utils;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class LookupMedicalRecordResponse
{
public List<LookupItem> MedicalRecordGroups { get; set; } = new();
public List<LookupItem> MedicalRecordCategories { get; set; } = new();
public List<LookupItem> Patients { get; set; } = new();
public List<LookupItem> Doctors { get; set; } = new();
public List<StatusLookupItem> Statuses { get; set; } = new();
}
public class LookupItem
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public class StatusLookupItem
{
public int Value { get; set; }
public string? Name { get; set; }
}
public record LookupMedicalRecordQuery() : IRequest<LookupMedicalRecordResponse>;
public class LookupMedicalRecordHandler : IRequestHandler<LookupMedicalRecordQuery, LookupMedicalRecordResponse>
{
private readonly AppDbContext _context;
public LookupMedicalRecordHandler(AppDbContext context) => _context = context;
public async Task<LookupMedicalRecordResponse> Handle(LookupMedicalRecordQuery request, CancellationToken cancellationToken)
{
var result = new LookupMedicalRecordResponse();
result.MedicalRecordGroups = await _context.MedicalRecordGroup
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
result.MedicalRecordCategories = await _context.MedicalRecordCategory
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
result.Patients = await _context.Patient
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
result.Doctors = await _context.Employee
.AsNoTracking()
.Where(x => x.Name!.StartsWith("Dr.") || x.JobTitle!.Contains("Practitioner") || x.JobTitle!.Contains("Surgeon"))
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
result.Statuses = Enum.GetValues(typeof(MedicalRecordStatus))
.Cast<MedicalRecordStatus>()
.Select(x => new StatusLookupItem
{
Value = (int)x,
Name = x.ToString()
})
.ToList();
return result;
}
}
@@ -0,0 +1,84 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class UpdateMedicalRecordRequest
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public DateTime? RecordDate { get; set; }
public string? PatientId { get; set; }
public string? EmployeeId { get; set; }
public string? Subjective { get; set; }
public string? Objective { get; set; }
public string? Assessment { get; set; }
public string? Planning { get; set; }
public string? BloodPressure { get; set; }
public string? Temperature { get; set; }
public string? HeartRate { get; set; }
public string? Weight { get; set; }
public string? Height { get; set; }
public MedicalRecordStatus Status { get; set; }
public string? Description { get; set; }
public string? MedicalRecordGroupId { get; set; }
public string? MedicalRecordCategoryId { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdateMedicalRecordResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdateMedicalRecordCommand(UpdateMedicalRecordRequest Data) : IRequest<UpdateMedicalRecordResponse>;
public class UpdateMedicalRecordHandler : IRequestHandler<UpdateMedicalRecordCommand, UpdateMedicalRecordResponse>
{
private readonly AppDbContext _context;
public UpdateMedicalRecordHandler(AppDbContext context) => _context = context;
public async Task<UpdateMedicalRecordResponse> Handle(UpdateMedicalRecordCommand request, CancellationToken cancellationToken)
{
var entity = await _context.MedicalRecord
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdateMedicalRecordResponse { Id = request.Data.Id, Success = false };
}
entity.RecordDate = request.Data.RecordDate;
entity.PatientId = request.Data.PatientId;
entity.EmployeeId = request.Data.EmployeeId;
entity.Subjective = request.Data.Subjective;
entity.Objective = request.Data.Objective;
entity.Assessment = request.Data.Assessment;
entity.Planning = request.Data.Planning;
entity.BloodPressure = request.Data.BloodPressure;
entity.Temperature = request.Data.Temperature;
entity.HeartRate = request.Data.HeartRate;
entity.Weight = request.Data.Weight;
entity.Height = request.Data.Height;
entity.Status = request.Data.Status;
entity.Description = request.Data.Description;
entity.MedicalRecordGroupId = request.Data.MedicalRecordGroupId;
entity.MedicalRecordCategoryId = request.Data.MedicalRecordCategoryId;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateMedicalRecordResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,56 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class UpdateMedicalRecordValidator : AbstractValidator<UpdateMedicalRecordRequest>
{
public UpdateMedicalRecordValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.RecordDate)
.NotEmpty().WithMessage("Record Date is required");
RuleFor(x => x.PatientId)
.NotEmpty().WithMessage("Patient is required");
RuleFor(x => x.EmployeeId)
.NotEmpty().WithMessage("Examining Doctor is required");
RuleFor(x => x.MedicalRecordGroupId)
.NotEmpty().WithMessage("Medical Record Group is required");
RuleFor(x => x.MedicalRecordCategoryId)
.NotEmpty().WithMessage("Medical Record Category is required");
RuleFor(x => x.Assessment)
.NotEmpty().WithMessage("Assessment (Diagnosis) is required")
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Subjective)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Objective)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Planning)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.BloodPressure)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Temperature)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.HeartRate)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Weight)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Height)
.MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,75 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Features.Medical.MedicalRecord.Cqrs;
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace Indotalent.Features.Medical.MedicalRecord;
public static class MedicalRecordEndpoint
{
public static void MapMedicalRecordEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("/medical-record").WithTags("MedicalRecords")
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
.RequireAuthenticatedUser());
group.MapGet("/", async (IMediator mediator) =>
{
var result = await mediator.Send(new GetMedicalRecordListQuery());
return result.ToApiResponse("Medical record list retrieved successfully");
})
.WithName("GetMedicalRecordList")
.WithTags("MedicalRecords");
group.MapGet("/{id}", async (string id, IMediator mediator) =>
{
var result = await mediator.Send(new GetMedicalRecordByIdQuery(id));
return result.ToApiResponse(result is not null
? "Medical record detail retrieved successfully"
: $"Medical record with ID {id} not found");
})
.WithName("GetMedicalRecordById")
.WithTags("MedicalRecords");
group.MapGet("/lookup", async (IMediator mediator) =>
{
var result = await mediator.Send(new LookupMedicalRecordQuery());
return result.ToApiResponse("Medical record lookup data retrieved successfully");
})
.WithName("GetMedicalRecordLookup")
.WithTags("MedicalRecords");
group.MapPost("/", async (CreateMedicalRecordRequest request, IMediator mediator) =>
{
var result = await mediator.Send(new CreateMedicalRecordCommand(request));
return result.ToApiResponse("Medical record has been created successfully", StatusCodes.Status201Created);
})
.WithName("CreateMedicalRecord")
.WithTags("MedicalRecords");
group.MapPost("/update", async (UpdateMedicalRecordRequest request, IMediator mediator) =>
{
var result = await mediator.Send(new UpdateMedicalRecordCommand(request));
if (!result.Success)
{
return ((object?)null).ToApiResponse("Update failed. The medical record data could not be found.");
}
return result.ToApiResponse("Medical record has been updated successfully");
})
.WithName("UpdateMedicalRecord")
.WithTags("MedicalRecords");
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
{
var result = await mediator.Send(new DeleteMedicalRecordByIdCommand(new DeleteMedicalRecordByIdRequest(id)));
if (!result)
{
return ((object?)null).ToApiResponse("Delete failed. The medical record data could not be found.");
}
return true.ToApiResponse("Medical record has been deleted successfully");
})
.WithName("DeleteMedicalRecordById")
.WithTags("MedicalRecords");
}
}
@@ -0,0 +1,65 @@
using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Medical.MedicalRecord.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Medical.MedicalRecord;
public class MedicalRecordService : BaseService
{
private readonly RestClient _client;
public MedicalRecordService(
IHttpClientFactory clientFactory,
NavigationManager nav,
ISnackbar snackbar,
ICurrentUserService currentUserService,
TokenProvider tokenProvider)
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
{
_client = new RestClient(nav.BaseUri);
}
public async Task<ApiResponse<List<GetMedicalRecordListResponse>>?> GetMedicalRecordListAsync()
{
var request = new RestRequest("api/medical-record", Method.Get);
return await ExecuteWithResponseAsync<List<GetMedicalRecordListResponse>>(_client, request);
}
public async Task<ApiResponse<GetMedicalRecordByIdResponse>?> GetMedicalRecordByIdAsync(string id)
{
var request = new RestRequest($"api/medical-record/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetMedicalRecordByIdResponse>(_client, request);
}
public async Task<ApiResponse<LookupMedicalRecordResponse>?> GetMedicalRecordLookupAsync()
{
var request = new RestRequest("api/medical-record/lookup", Method.Get);
return await ExecuteWithResponseAsync<LookupMedicalRecordResponse>(_client, request);
}
public async Task<ApiResponse<CreateMedicalRecordResponse>?> CreateMedicalRecordAsync(CreateMedicalRecordRequest data)
{
var request = new RestRequest("api/medical-record", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreateMedicalRecordResponse>(_client, request);
}
public async Task<bool> DeleteMedicalRecordByIdAsync(string id)
{
var request = new RestRequest($"api/medical-record/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
public async Task<ApiResponse<UpdateMedicalRecordResponse>?> UpdateMedicalRecordAsync(UpdateMedicalRecordRequest data)
{
var request = new RestRequest("api/medical-record/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdateMedicalRecordResponse>(_client, request);
}
}