Update to .NET 9, add patient features, and refactor

Updated target framework to .NET 9 across multiple projects and updated package references. Refactored `HospitalController` to use MediatR commands. Introduced new patient-related functionalities including new API endpoints, commands, queries, and DTOs. Removed user-related properties from medical history mappings. Added new handlers for patient creation, retrieval, and section updates.
master
Amir Hossein Khademi 2025-01-12 11:22:32 +03:30
parent b3ca3c51ea
commit 1a813edf6a
38 changed files with 781 additions and 363 deletions

View File

@ -1,4 +1,6 @@
using DocuMed.Domain.Entities.MedicalHistory;
using DocuMed.Domain.CommandQueries.Commands;
using DocuMed.Domain.Entities.MedicalHistory;
using MediatR;
namespace DocuMed.Api.Controllers;
@ -30,32 +32,32 @@ public class HospitalController : ICarterModule
}
// GET:Get All Entity
public virtual async Task<IResult> GetAllAsync([FromQuery] int page, IMedicalHistoryRepository repository, CancellationToken cancellationToken)
private async Task<IResult> GetAllAsync([FromQuery] int page, IMedicalHistoryRepository repository, CancellationToken cancellationToken)
{
return TypedResults.Ok(await repository.GetMedicalHistoriesAsync(page, cancellationToken));
}
// GET:Get An Entity By Id
public async Task<IResult> GetAsync(Guid id, IMedicalHistoryRepository repository, CancellationToken cancellationToken)
private async Task<IResult> GetAsync(Guid id, IMedicalHistoryRepository repository, CancellationToken cancellationToken)
{
return TypedResults.Ok(await repository.GetMedicalHistoryAsync(id, cancellationToken));
}
// POST:Add New Entity
public virtual async Task<IResult> Post([FromBody] MedicalHistoryLDto dto, IMedicalHistoryService service, ICurrentUserService currentUserService, CancellationToken cancellationToken)
private async Task<IResult> Post([FromBody] CreateHospitalCommand dto, IMediator service, ICurrentUserService currentUserService, CancellationToken cancellationToken)
{
return TypedResults.Ok(await service.AddAsync(dto, cancellationToken));
return TypedResults.Ok(await service.Send(dto,cancellationToken));
}
// PUT:Update Entity
public virtual async Task<IResult> Put([FromBody] MedicalHistoryLDto dto, IMedicalHistoryService service, ICurrentUserService currentUserService, CancellationToken cancellationToken)
private async Task<IResult> Put([FromBody] UpdateHospitalCommand dto, IMediator service, ICurrentUserService currentUserService, CancellationToken cancellationToken)
{
return TypedResults.Ok(await service.EditAsync(dto, cancellationToken));
return TypedResults.Ok(await service.Send(dto,cancellationToken));
}
// DELETE:Delete Entity
public virtual async Task<IResult> Delete(Guid id, IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
private async Task<IResult> Delete(Guid id, IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
{
var ent = await repositoryWrapper.SetRepository<MedicalHistory>().GetByIdAsync(cancellationToken, id);
repositoryWrapper.SetRepository<MedicalHistory>().Delete(ent);

View File

@ -0,0 +1,21 @@
namespace DocuMed.Api.Controllers;
public class PatientController : ICarterModule
{
public void AddRoutes(IEndpointRouteBuilder app)
{
var group = app.NewVersionedApi("Patient")
.MapGroup($"api/patient");
group.MapGet("", GetAllAsync)
.WithDisplayName("Get All Patient")
.HasApiVersion(1.0);
}
private async Task<IResult> GetAllAsync([FromQuery]int page ,
[FromQuery]int? count ,
[FromQuery]string searchName ,
[FromServices]IMediator mediator,
CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new GetPatientsQuery(page, Count: count ?? Refers.SizeM, searchName), cancellationToken));
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
@ -13,42 +13,42 @@
<ItemGroup>
<PackageReference Include="Asp.Versioning.Http" Version="8.1.0" />
<PackageReference Include="Ben.BlockingDetector" Version="0.0.4" />
<PackageReference Include="Carter" Version="8.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PackageReference Include="Carter" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Autofac" Version="8.1.0" />
<PackageReference Include="Autofac" Version="8.2.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Elmah.Io.AspNetCore.Serilog" Version="5.1.23" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.5" />
<PackageReference Include="Sentry.Serilog" Version="4.11.0" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
<PackageReference Include="Sentry.Serilog" Version="5.0.0" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.PostgreSQL" Version="2.3.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.ElmahIo" Version="5.1.43" />
<PackageReference Include="Serilog.Sinks.Seq" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.ElmahIo" Version="5.2.50" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="10.2.0" />
<PackageReference Include="StackExchange.Redis.Extensions.Core" Version="10.2.0" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="10.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
<PackageReference Include="System.Drawing.Common" Version="8.0.8" />
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
@ -73,6 +73,7 @@
<Using Include="DocuMed.Core.EntityServices.Abstracts" />
<Using Include="DocuMed.Core.Models.Api" />
<Using Include="DocuMed.Domain" />
<Using Include="DocuMed.Domain.CommandQueries.Queries" />
<Using Include="DocuMed.Domain.Dtos.LargDtos" />
<Using Include="DocuMed.Domain.Dtos.RequestDtos" />
<Using Include="DocuMed.Domain.Dtos.SmallDtos" />
@ -81,6 +82,7 @@
<Using Include="DocuMed.Domain.Entities.User" />
<Using Include="DocuMed.Domain.Enums.QueryFilters" />
<Using Include="DocuMed.Domain.Mappers" />
<Using Include="DocuMed.Domain.Models" />
<Using Include="DocuMed.Domain.Models.Settings" />
<Using Include="DocuMed.Infrastructure" />
<Using Include="DocuMed.Infrastructure.Models" />
@ -90,6 +92,7 @@
<Using Include="DocuMed.Repository.Models" />
<Using Include="DocuMed.Repository.Repositories.Base.Contracts" />
<Using Include="DocuMed.Repository.Repositories.Entities.Abstracts" />
<Using Include="MediatR" />
<Using Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<Using Include="Microsoft.AspNetCore.Identity" />
<Using Include="Microsoft.AspNetCore.Mvc" />

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>10</LangVersion>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
@ -11,10 +11,10 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
</ItemGroup>
</ItemGroup>-->
<!--<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
@ -24,8 +24,8 @@
<PackageReference Include="MD.PersianDateTime.Standard" Version="2.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.0" />
</ItemGroup>-->
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.3.0" />
</ItemGroup>
<ItemGroup>
<Using Include="MD.PersianDateTime.Standard" />

View File

@ -126,7 +126,6 @@ public class AccountService(
return await CompleteLogin(user, cancellationToken);
}
private async Task<AccessToken<ApplicationUserSDto>> CompleteLogin(ApplicationUser user, CancellationToken cancellationToken)
{
var token = await jwtService.Generate<ApplicationUserSDto, ApplicationUser>(user);

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
@ -12,7 +12,7 @@
<PackageReference Include="AspNetCoreRateLimit.Redis" Version="2.0.0" />
<PackageReference Include="Autofac.Extras.Quartz" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Quartz" Version="3.13.0" />
<PackageReference Include="Quartz" Version="3.13.1" />
</ItemGroup>
<ItemGroup>

View File

@ -8,6 +8,7 @@ public sealed record CreateMedicalHistoryCommand(
string FatherName,
string NationalId,
DateTime BirthDate,
Guid PatientId,
string PresentIllnessDetail,
string PastDiseasesHistoryDetail,
string PastSurgeryHistoryDetail,
@ -23,7 +24,6 @@ public sealed record CreateMedicalHistoryCommand(
double PulseRate,
double SPO2,
double Temperature,
Guid ApplicationUserId,
Guid MedicalHistoryTemplateId,
List<MedicalHistoryAnswerSDto> Answers) : IRequest<Guid>;
@ -36,6 +36,7 @@ public sealed record UpdateMedicalHistoryCommand(
string FatherName,
string NationalId,
DateTime BirthDate,
Guid PatientId,
string PresentIllnessDetail,
string PastDiseasesHistoryDetail,
string PastSurgeryHistoryDetail,
@ -51,7 +52,6 @@ public sealed record UpdateMedicalHistoryCommand(
double PulseRate,
double SPO2,
double Temperature,
Guid ApplicationUserId,
Guid MedicalHistoryTemplateId,
List<MedicalHistoryAnswerSDto> Answers) : IRequest<Guid>;

View File

@ -0,0 +1,26 @@
namespace DocuMed.Domain.CommandQueries.Commands;
public sealed record CreatePatientCommand(
string FirstName,
string LastName,
string UnitNumber,
string NationalId,
string Room,
string Bed,
DateTime AdmissionAt,
Guid SectionId) : IRequest<Guid>;
public sealed record UpdatePatientCommand(
Guid Id,
string FirstName,
string LastName,
string UnitNumber,
string NationalId,
string Room,
string Bed,
DateTime AdmissionAt,
Guid SectionId) : IRequest<Guid>;
public sealed record UpdatePatientSectionCommand(Guid Id, Guid SectionId) : IRequest<Guid>;
public sealed record DeletePatientCommand(Guid Id) : IRequest<bool>;

View File

@ -0,0 +1,4 @@
namespace DocuMed.Domain.CommandQueries.Queries;
public sealed record GetPatientQuery(Guid? Id = null , string? NationalId = null) : IRequest<PatientSDto>;
public sealed record GetPatientsQuery(int Page , int Count , string? SearchName = null , string? NationalId = null) : IRequest<List<PatientSDto>>;

View File

@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mapster" Version="7.4.0" />
<PackageReference Include="Mapster.Core" Version="1.2.1" />
<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="9.0.0" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
</ItemGroup>-->
</ItemGroup>
<PropertyGroup>
<!--<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>10</LangVersion>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
@ -27,7 +27,7 @@
<PackageReference Include="MediatR" Version="12.1.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="5.0.0" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
</ItemGroup>
</ItemGroup>-->
<Target Name="Mapster">
@ -37,37 +37,37 @@
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n DocuMed.Domain.Mappers -o Mappers" />
</Target>
<ItemGroup>
<ProjectReference Include="..\DocuMed.Common\DocuMed.Common.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DocuMed.Common\DocuMed.Common.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Dtos\ResponseDtos\" />
<Folder Include="Dtos\RequestDtos\" />
<Folder Include="Entities\City\" />
<Folder Include="Entities\Patients\" />
<Folder Include="Entities\User\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Dtos\ResponseDtos\" />
<Folder Include="Dtos\RequestDtos\" />
<Folder Include="Entities\City\" />
<Folder Include="Entities\User\" />
</ItemGroup>
<ItemGroup>
<Using Include=" DocuMed.Domain.Entities.MedicalHistoryTemplate" />
<Using Include="DocuMed.Common.Models.Entity" />
<Using Include="DocuMed.Common.Models.Mapper" />
<Using Include="DocuMed.Domain.Dtos.SmallDtos" />
<Using Include="DocuMed.Domain.Entities.City" />
<Using Include="DocuMed.Domain.Entities.Hospitals" />
<Using Include="DocuMed.Domain.Entities.MedicalHistory" />
<Using Include="DocuMed.Domain.Entities.Staffs" />
<Using Include="DocuMed.Domain.Entities.User" />
<Using Include="DocuMed.Domain.Enums" />
<Using Include="DocuMed.Domain.Models" />
<Using Include="Mapster" />
<Using Include="MD.PersianDateTime.Standard" />
<Using Include="MediatR" />
<Using Include="Microsoft.AspNetCore.Identity" />
<Using Include="Newtonsoft.Json" />
<Using Include="System.ComponentModel.DataAnnotations" />
<Using Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<Using Include=" DocuMed.Domain.Entities.MedicalHistoryTemplate" />
<Using Include="DocuMed.Common.Models.Entity" />
<Using Include="DocuMed.Common.Models.Mapper" />
<Using Include="DocuMed.Domain.Dtos.SmallDtos" />
<Using Include="DocuMed.Domain.Entities.City" />
<Using Include="DocuMed.Domain.Entities.Hospitals" />
<Using Include="DocuMed.Domain.Entities.MedicalHistory" />
<Using Include="DocuMed.Domain.Entities.Patients" />
<Using Include="DocuMed.Domain.Entities.Staffs" />
<Using Include="DocuMed.Domain.Entities.User" />
<Using Include="DocuMed.Domain.Enums" />
<Using Include="DocuMed.Domain.Models" />
<Using Include="Mapster" />
<Using Include="MD.PersianDateTime.Standard" />
<Using Include="MediatR" />
<Using Include="Microsoft.AspNetCore.Identity" />
<Using Include="Newtonsoft.Json" />
<Using Include="System.ComponentModel.DataAnnotations" />
<Using Include="System.Numerics" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,19 @@
namespace DocuMed.Domain.Dtos.SmallDtos;
public class PatientSDto : BaseDto<PatientSDto,Patient>
{
public string UnitNumber { get; set; } = string.Empty;
public string Room { get; set; } = string.Empty;
public string Bed { get; set; } = string.Empty;
public DateTime AdmissionAt { get; set; }
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string NationalId { get; set; } = string.Empty;
public DateTime BirthDate { get; set; }
public Gender Gender { get; set; }
public Guid HospitalId { get; set; }
public Guid SectionId { get; set; }
public string SectionName { get; set; } = string.Empty;
public string FullName => FirstName + " " + LastName;
}

View File

@ -41,7 +41,8 @@ public partial class MedicalHistory
double pulseRate,
double sPO2,
double temperature,
Guid applicationUserId,
Guid studentId,
Guid patientId,
Guid medicalHistoryTemplateId)
{
var code = StringExtensions.GetIntId(6);
@ -63,7 +64,8 @@ public partial class MedicalHistory
sPO2,
temperature,
code,
applicationUserId,
studentId,
patientId,
medicalHistoryTemplateId);
}

View File

@ -31,7 +31,8 @@ public partial class MedicalHistory : ApiEntity
double spo2,
double temperature,
string code,
Guid applicationUserId,
Guid studentId,
Guid patientId,
Guid medicalHistoryTemplateId)
{
PresentIllnessDetail = presentIllnessDetail;
@ -52,7 +53,8 @@ public partial class MedicalHistory : ApiEntity
SPO2 = spo2;
Temperature = temperature;
Code = code;
ApplicationUserId = applicationUserId;
StudentId = studentId;
PatientId = patientId;
MedicalHistoryTemplateId = medicalHistoryTemplateId;
}
public string ChiefComplaint { get; internal set; } = string.Empty;
@ -79,8 +81,11 @@ public partial class MedicalHistory : ApiEntity
public double Temperature { get; internal set; }
public Guid MedicalHistoryTemplateId { get; internal set; }
public Guid ApplicationUserId { get; internal set; }
public ApplicationUser? ApplicationUser { get; internal set; }
public Guid StudentId { get; internal set; }
public Student? Student { get; internal set; }
public Guid PatientId { get; set; }
public Patient? Patient { get; set; }
public List<MedicalHistoryAnswer> Answers { get; internal set; } = new();
}

View File

@ -10,17 +10,17 @@ public partial class MedicalHistoryTemplate : ApiEntity
{
}
public MedicalHistoryTemplate(string chiefComplaint,Guid sectionId,Guid applicationUserId)
public MedicalHistoryTemplate(string chiefComplaint,Guid sectionId,Guid studentId)
{
ChiefComplaint = chiefComplaint;
SectionId = sectionId;
ApplicationUserId = applicationUserId;
StudentId = studentId;
}
public string ChiefComplaint { get; internal set; } = string.Empty;
public Guid SectionId { get; set; }
public Section? Section { get; set; }
public Guid ApplicationUserId { get; internal set; }
public ApplicationUser? ApplicationUser { get; set; }
public Guid StudentId { get; internal set; }
public Student? Student { get; set; }
public List<MedicalHistoryQuestion> Questions { get; internal set; } = new();
}

View File

@ -2,6 +2,6 @@
public partial class Patient
{
public static Patient Create(string unitNumber, string room, string bed, DateTime admissionAt, Guid sectionId, Guid userId)
=> new Patient(unitNumber, room, bed, admissionAt, sectionId, userId);
}
public static Patient Create(string unitNumber, string room, string bed, DateTime admissionAt,Guid sectionId,Guid hospitalId, Guid userId)
=> new Patient(unitNumber, room, bed, admissionAt,sectionId,hospitalId, userId);
}

View File

@ -11,13 +11,14 @@ public partial class Patient : ApiEntity
}
public Patient(string unitNumber, string room, string bed, DateTime admissionAt, Guid sectionId, Guid userId)
public Patient(string unitNumber, string room, string bed, DateTime admissionAt,Guid sectionId,Guid hospitalId, Guid userId)
{
UnitNumber = unitNumber;
Room = room;
Bed = bed;
AdmissionAt = admissionAt;
SectionId = sectionId;
HospitalId = hospitalId;
UserId = userId;
}
public string UnitNumber { get; internal set; } = string.Empty;
@ -28,6 +29,8 @@ public partial class Patient : ApiEntity
public Guid SectionId { get; internal set; }
public Section? Section { get; internal set; }
public Guid HospitalId { get; internal set; }
public Guid UserId { get; internal set; }
public ApplicationUser? User { get; internal set; }
}

View File

@ -1,6 +1,4 @@
using DocuMed.Domain.Entities.Patients;
namespace DocuMed.Domain.Entities.User;
namespace DocuMed.Domain.Entities.User;
[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)]
[GenerateMapper]
@ -13,6 +11,6 @@ public class ApplicationUser : IdentityUser<Guid>
public Gender Gender { get; set; }
public SignUpStatus SignUpStatus { get; set; }
public Student? Student { get; set; }
public Patient? Patient { get; set; }
public List<Student> Students { get; set; } = [];
public List<Patient> Patients { get; set; } = [];
}

View File

@ -71,60 +71,47 @@ namespace DocuMed.Domain.Mappers
PhoneNumber = p5.PhoneNumber,
PhoneNumberConfirmed = p5.PhoneNumberConfirmed,
NationalId = p5.NationalId,
StudentId = funcMain1(p5.Student == null ? null : (Guid?)p5.Student.Id),
BirthDate = p5.BirthDate,
Gender = p5.Gender,
SignUpStatus = p5.SignUpStatus,
Id = p5.Id
};
}
public static ApplicationUserSDto AdaptTo(this ApplicationUser p7, ApplicationUserSDto p8)
public static ApplicationUserSDto AdaptTo(this ApplicationUser p6, ApplicationUserSDto p7)
{
if (p7 == null)
if (p6 == null)
{
return null;
}
ApplicationUserSDto result = p8 ?? new ApplicationUserSDto();
ApplicationUserSDto result = p7 ?? new ApplicationUserSDto();
result.FirstName = p7.FirstName;
result.LastName = p7.LastName;
result.UserName = p7.UserName;
result.Email = p7.Email;
result.PhoneNumber = p7.PhoneNumber;
result.PhoneNumberConfirmed = p7.PhoneNumberConfirmed;
result.NationalId = p7.NationalId;
result.StudentId = funcMain2(p7.Student == null ? null : (Guid?)p7.Student.Id, result.StudentId);
result.BirthDate = p7.BirthDate;
result.Gender = p7.Gender;
result.SignUpStatus = p7.SignUpStatus;
result.Id = p7.Id;
result.FirstName = p6.FirstName;
result.LastName = p6.LastName;
result.UserName = p6.UserName;
result.Email = p6.Email;
result.PhoneNumber = p6.PhoneNumber;
result.PhoneNumberConfirmed = p6.PhoneNumberConfirmed;
result.NationalId = p6.NationalId;
result.BirthDate = p6.BirthDate;
result.Gender = p6.Gender;
result.SignUpStatus = p6.SignUpStatus;
result.Id = p6.Id;
return result;
}
public static Expression<Func<ApplicationUser, ApplicationUserSDto>> ProjectToSDto => p11 => new ApplicationUserSDto()
public static Expression<Func<ApplicationUser, ApplicationUserSDto>> ProjectToSDto => p8 => new ApplicationUserSDto()
{
FirstName = p11.FirstName,
LastName = p11.LastName,
UserName = p11.UserName,
Email = p11.Email,
PhoneNumber = p11.PhoneNumber,
PhoneNumberConfirmed = p11.PhoneNumberConfirmed,
NationalId = p11.NationalId,
StudentId = p11.Student.Id.ToString(),
BirthDate = p11.BirthDate,
Gender = p11.Gender,
SignUpStatus = p11.SignUpStatus,
Id = p11.Id
FirstName = p8.FirstName,
LastName = p8.LastName,
UserName = p8.UserName,
Email = p8.Email,
PhoneNumber = p8.PhoneNumber,
PhoneNumberConfirmed = p8.PhoneNumberConfirmed,
NationalId = p8.NationalId,
BirthDate = p8.BirthDate,
Gender = p8.Gender,
SignUpStatus = p8.SignUpStatus,
Id = p8.Id
};
private static string funcMain1(Guid? p6)
{
return p6 == null ? null : ((Guid)p6).ToString();
}
private static string funcMain2(Guid? p9, string p10)
{
return p9 == null ? null : ((Guid)p9).ToString();
}
}
}

View File

@ -6,7 +6,6 @@ using DocuMed.Domain.Dtos.LargDtos;
using DocuMed.Domain.Dtos.SmallDtos;
using DocuMed.Domain.Entities.Hospitals;
using DocuMed.Domain.Entities.MedicalHistory;
using DocuMed.Domain.Entities.User;
using Mapster.Models;
namespace DocuMed.Domain.Mappers
@ -26,12 +25,6 @@ namespace DocuMed.Domain.Mappers
HospitalId = p1.Section.HospitalId,
Id = p1.Section.Id
},
FirstName = p1.FirstName,
LastName = p1.LastName,
FatherName = p1.FatherName,
NationalId = p1.NationalId,
Age = p1.Age,
BirthDate = p1.BirthDate,
PresentIllnessDetail = p1.PresentIllnessDetail,
PastDiseasesHistoryDetail = p1.PastDiseasesHistoryDetail,
PastSurgeryHistoryDetail = p1.PastSurgeryHistoryDetail,
@ -49,7 +42,6 @@ namespace DocuMed.Domain.Mappers
SPO2 = p1.SPO2,
Temperature = p1.Temperature,
MedicalHistoryTemplateId = p1.MedicalHistoryTemplateId,
ApplicationUserId = p1.ApplicationUserId,
Answers = funcMain1(p1.Answers),
Id = p1.Id,
CreatedAt = p1.CreatedAt
@ -66,12 +58,6 @@ namespace DocuMed.Domain.Mappers
result.ChiefComplaint = p3.ChiefComplaint;
result.SectionId = p3.SectionId;
result.Section = funcMain2(p3.Section, result.Section);
result.FirstName = p3.FirstName;
result.LastName = p3.LastName;
result.FatherName = p3.FatherName;
result.NationalId = p3.NationalId;
result.Age = p3.Age;
result.BirthDate = p3.BirthDate;
result.PresentIllnessDetail = p3.PresentIllnessDetail;
result.PastDiseasesHistoryDetail = p3.PastDiseasesHistoryDetail;
result.PastSurgeryHistoryDetail = p3.PastSurgeryHistoryDetail;
@ -89,7 +75,6 @@ namespace DocuMed.Domain.Mappers
result.SPO2 = p3.SPO2;
result.Temperature = p3.Temperature;
result.MedicalHistoryTemplateId = p3.MedicalHistoryTemplateId;
result.ApplicationUserId = p3.ApplicationUserId;
result.Answers = funcMain3(p3.Answers, result.Answers);
result.Id = p3.Id;
result.CreatedAt = p3.CreatedAt;
@ -107,12 +92,6 @@ namespace DocuMed.Domain.Mappers
HospitalId = p9.Section.HospitalId,
Id = p9.Section.Id
},
FirstName = p9.FirstName,
LastName = p9.LastName,
FatherName = p9.FatherName,
NationalId = p9.NationalId,
Age = p9.Age,
BirthDate = p9.BirthDate,
PresentIllnessDetail = p9.PresentIllnessDetail,
PastDiseasesHistoryDetail = p9.PastDiseasesHistoryDetail,
PastSurgeryHistoryDetail = p9.PastSurgeryHistoryDetail,
@ -130,7 +109,6 @@ namespace DocuMed.Domain.Mappers
SPO2 = p9.SPO2,
Temperature = p9.Temperature,
MedicalHistoryTemplateId = p9.MedicalHistoryTemplateId,
ApplicationUserId = p9.ApplicationUserId,
Answers = p9.Answers.Select<MedicalHistoryAnswerSDto, MedicalHistoryAnswer>(p10 => new MedicalHistoryAnswer()
{
Answer = p10.Answer,
@ -149,12 +127,6 @@ namespace DocuMed.Domain.Mappers
{
ChiefComplaint = p11.ChiefComplaint,
SectionId = p11.SectionId,
FirstName = p11.FirstName,
LastName = p11.LastName,
FatherName = p11.FatherName,
NationalId = p11.NationalId,
Age = p11.Age,
BirthDate = p11.BirthDate,
Code = p11.Code,
Section = p11.Section == null ? null : new SectionSDto()
{
@ -179,7 +151,6 @@ namespace DocuMed.Domain.Mappers
PulseRate = p11.PulseRate,
SPO2 = p11.SPO2,
Temperature = p11.Temperature,
ApplicationUserId = p11.ApplicationUserId,
CreatedAt = p11.CreatedAt,
Answers = funcMain4(p11.Answers),
Id = p11.Id
@ -195,12 +166,6 @@ namespace DocuMed.Domain.Mappers
result.ChiefComplaint = p13.ChiefComplaint;
result.SectionId = p13.SectionId;
result.FirstName = p13.FirstName;
result.LastName = p13.LastName;
result.FatherName = p13.FatherName;
result.NationalId = p13.NationalId;
result.Age = p13.Age;
result.BirthDate = p13.BirthDate;
result.Code = p13.Code;
result.Section = funcMain5(p13.Section, result.Section);
result.PresentIllnessDetail = p13.PresentIllnessDetail;
@ -219,7 +184,6 @@ namespace DocuMed.Domain.Mappers
result.PulseRate = p13.PulseRate;
result.SPO2 = p13.SPO2;
result.Temperature = p13.Temperature;
result.ApplicationUserId = p13.ApplicationUserId;
result.CreatedAt = p13.CreatedAt;
result.Answers = funcMain6(p13.Answers, result.Answers);
result.Id = p13.Id;
@ -230,12 +194,6 @@ namespace DocuMed.Domain.Mappers
{
ChiefComplaint = p19.ChiefComplaint,
SectionId = p19.SectionId,
FirstName = p19.FirstName,
LastName = p19.LastName,
FatherName = p19.FatherName,
NationalId = p19.NationalId,
Age = p19.Age,
BirthDate = p19.BirthDate,
Code = p19.Code,
Section = p19.Section == null ? null : new SectionSDto()
{
@ -260,7 +218,6 @@ namespace DocuMed.Domain.Mappers
PulseRate = p19.PulseRate,
SPO2 = p19.SPO2,
Temperature = p19.Temperature,
ApplicationUserId = p19.ApplicationUserId,
CreatedAt = p19.CreatedAt,
Answers = p19.Answers.Select<MedicalHistoryAnswer, MedicalHistoryAnswerSDto>(p20 => new MedicalHistoryAnswerSDto()
{
@ -284,12 +241,6 @@ namespace DocuMed.Domain.Mappers
Name = p21.SectionName,
Id = p21.SectionId
},
FirstName = p21.FirstName,
LastName = p21.LastName,
FatherName = p21.FatherName,
NationalId = p21.NationalId,
Age = p21.Age,
BirthDate = p21.BirthDate,
PresentIllnessDetail = p21.PresentIllnessDetail,
PastDiseasesHistoryDetail = p21.PastDiseasesHistoryDetail,
PastSurgeryHistoryDetail = p21.PastSurgeryHistoryDetail,
@ -307,8 +258,6 @@ namespace DocuMed.Domain.Mappers
SPO2 = p21.SPO2,
Temperature = p21.Temperature,
MedicalHistoryTemplateId = p21.MedicalHistoryTemplateId,
ApplicationUserId = p21.ApplicationUserId,
ApplicationUser = new ApplicationUser() {Id = p21.ApplicationUserId},
Id = p21.Id,
CreatedAt = p21.CreatedAt
};
@ -324,12 +273,6 @@ namespace DocuMed.Domain.Mappers
result.ChiefComplaint = p22.ChiefComplaint;
result.SectionId = p22.SectionId;
result.Section = funcMain7(new Never(), result.Section, p22);
result.FirstName = p22.FirstName;
result.LastName = p22.LastName;
result.FatherName = p22.FatherName;
result.NationalId = p22.NationalId;
result.Age = p22.Age;
result.BirthDate = p22.BirthDate;
result.PresentIllnessDetail = p22.PresentIllnessDetail;
result.PastDiseasesHistoryDetail = p22.PastDiseasesHistoryDetail;
result.PastSurgeryHistoryDetail = p22.PastSurgeryHistoryDetail;
@ -347,119 +290,96 @@ namespace DocuMed.Domain.Mappers
result.SPO2 = p22.SPO2;
result.Temperature = p22.Temperature;
result.MedicalHistoryTemplateId = p22.MedicalHistoryTemplateId;
result.ApplicationUserId = p22.ApplicationUserId;
result.ApplicationUser = funcMain8(new Never(), result.ApplicationUser, p22);
result.Id = p22.Id;
result.CreatedAt = p22.CreatedAt;
return result;
}
public static MedicalHistorySDto AdaptToSDto(this MedicalHistory p28)
public static MedicalHistorySDto AdaptToSDto(this MedicalHistory p26)
{
return p28 == null ? null : new MedicalHistorySDto()
return p26 == null ? null : new MedicalHistorySDto()
{
ChiefComplaint = p28.ChiefComplaint,
SectionId = p28.SectionId,
SectionName = p28.Section != null ? p28.Section.Name : string.Empty,
FirstName = p28.FirstName,
LastName = p28.LastName,
FatherName = p28.FatherName,
NationalId = p28.NationalId,
MedicalHistoryTemplateId = p28.MedicalHistoryTemplateId,
Age = p28.Age,
BirthDate = p28.BirthDate,
Code = p28.Code,
PresentIllnessDetail = p28.PresentIllnessDetail,
PastDiseasesHistoryDetail = p28.PastDiseasesHistoryDetail,
PastSurgeryHistoryDetail = p28.PastSurgeryHistoryDetail,
FamilyHistoryDetail = p28.FamilyHistoryDetail,
AllergyDetail = p28.AllergyDetail,
DrugHistoryDetail = p28.DrugHistoryDetail,
AddictionHistoryDetail = p28.AddictionHistoryDetail,
SystemReviewDetail = p28.SystemReviewDetail,
VitalSignDetail = p28.VitalSignDetail,
GeneralAppearanceDetail = p28.GeneralAppearanceDetail,
SystolicBloodPressure = p28.SystolicBloodPressure,
DiastolicBloodPressure = p28.DiastolicBloodPressure,
PulseRate = p28.PulseRate,
SPO2 = p28.SPO2,
Temperature = p28.Temperature,
ApplicationUserId = p28.ApplicationUserId,
CreatedAt = p28.CreatedAt,
Id = p28.Id
ChiefComplaint = p26.ChiefComplaint,
SectionId = p26.SectionId,
SectionName = p26.Section != null ? p26.Section.Name : string.Empty,
MedicalHistoryTemplateId = p26.MedicalHistoryTemplateId,
Code = p26.Code,
PresentIllnessDetail = p26.PresentIllnessDetail,
PastDiseasesHistoryDetail = p26.PastDiseasesHistoryDetail,
PastSurgeryHistoryDetail = p26.PastSurgeryHistoryDetail,
FamilyHistoryDetail = p26.FamilyHistoryDetail,
AllergyDetail = p26.AllergyDetail,
DrugHistoryDetail = p26.DrugHistoryDetail,
AddictionHistoryDetail = p26.AddictionHistoryDetail,
SystemReviewDetail = p26.SystemReviewDetail,
VitalSignDetail = p26.VitalSignDetail,
GeneralAppearanceDetail = p26.GeneralAppearanceDetail,
SystolicBloodPressure = p26.SystolicBloodPressure,
DiastolicBloodPressure = p26.DiastolicBloodPressure,
PulseRate = p26.PulseRate,
SPO2 = p26.SPO2,
Temperature = p26.Temperature,
CreatedAt = p26.CreatedAt,
Id = p26.Id
};
}
public static MedicalHistorySDto AdaptTo(this MedicalHistory p29, MedicalHistorySDto p30)
public static MedicalHistorySDto AdaptTo(this MedicalHistory p27, MedicalHistorySDto p28)
{
if (p29 == null)
if (p27 == null)
{
return null;
}
MedicalHistorySDto result = p30 ?? new MedicalHistorySDto();
MedicalHistorySDto result = p28 ?? new MedicalHistorySDto();
result.ChiefComplaint = p29.ChiefComplaint;
result.SectionId = p29.SectionId;
result.SectionName = p29.Section != null ? p29.Section.Name : string.Empty;
result.FirstName = p29.FirstName;
result.LastName = p29.LastName;
result.FatherName = p29.FatherName;
result.NationalId = p29.NationalId;
result.MedicalHistoryTemplateId = p29.MedicalHistoryTemplateId;
result.Age = p29.Age;
result.BirthDate = p29.BirthDate;
result.Code = p29.Code;
result.PresentIllnessDetail = p29.PresentIllnessDetail;
result.PastDiseasesHistoryDetail = p29.PastDiseasesHistoryDetail;
result.PastSurgeryHistoryDetail = p29.PastSurgeryHistoryDetail;
result.FamilyHistoryDetail = p29.FamilyHistoryDetail;
result.AllergyDetail = p29.AllergyDetail;
result.DrugHistoryDetail = p29.DrugHistoryDetail;
result.AddictionHistoryDetail = p29.AddictionHistoryDetail;
result.SystemReviewDetail = p29.SystemReviewDetail;
result.VitalSignDetail = p29.VitalSignDetail;
result.GeneralAppearanceDetail = p29.GeneralAppearanceDetail;
result.SystolicBloodPressure = p29.SystolicBloodPressure;
result.DiastolicBloodPressure = p29.DiastolicBloodPressure;
result.PulseRate = p29.PulseRate;
result.SPO2 = p29.SPO2;
result.Temperature = p29.Temperature;
result.ApplicationUserId = p29.ApplicationUserId;
result.CreatedAt = p29.CreatedAt;
result.Id = p29.Id;
result.ChiefComplaint = p27.ChiefComplaint;
result.SectionId = p27.SectionId;
result.SectionName = p27.Section != null ? p27.Section.Name : string.Empty;
result.MedicalHistoryTemplateId = p27.MedicalHistoryTemplateId;
result.Code = p27.Code;
result.PresentIllnessDetail = p27.PresentIllnessDetail;
result.PastDiseasesHistoryDetail = p27.PastDiseasesHistoryDetail;
result.PastSurgeryHistoryDetail = p27.PastSurgeryHistoryDetail;
result.FamilyHistoryDetail = p27.FamilyHistoryDetail;
result.AllergyDetail = p27.AllergyDetail;
result.DrugHistoryDetail = p27.DrugHistoryDetail;
result.AddictionHistoryDetail = p27.AddictionHistoryDetail;
result.SystemReviewDetail = p27.SystemReviewDetail;
result.VitalSignDetail = p27.VitalSignDetail;
result.GeneralAppearanceDetail = p27.GeneralAppearanceDetail;
result.SystolicBloodPressure = p27.SystolicBloodPressure;
result.DiastolicBloodPressure = p27.DiastolicBloodPressure;
result.PulseRate = p27.PulseRate;
result.SPO2 = p27.SPO2;
result.Temperature = p27.Temperature;
result.CreatedAt = p27.CreatedAt;
result.Id = p27.Id;
return result;
}
public static Expression<Func<MedicalHistory, MedicalHistorySDto>> ProjectToSDto => p31 => new MedicalHistorySDto()
public static Expression<Func<MedicalHistory, MedicalHistorySDto>> ProjectToSDto => p29 => new MedicalHistorySDto()
{
ChiefComplaint = p31.ChiefComplaint,
SectionId = p31.SectionId,
SectionName = p31.Section != null ? p31.Section.Name : string.Empty,
FirstName = p31.FirstName,
LastName = p31.LastName,
FatherName = p31.FatherName,
NationalId = p31.NationalId,
MedicalHistoryTemplateId = p31.MedicalHistoryTemplateId,
Age = p31.Age,
BirthDate = p31.BirthDate,
Code = p31.Code,
PresentIllnessDetail = p31.PresentIllnessDetail,
PastDiseasesHistoryDetail = p31.PastDiseasesHistoryDetail,
PastSurgeryHistoryDetail = p31.PastSurgeryHistoryDetail,
FamilyHistoryDetail = p31.FamilyHistoryDetail,
AllergyDetail = p31.AllergyDetail,
DrugHistoryDetail = p31.DrugHistoryDetail,
AddictionHistoryDetail = p31.AddictionHistoryDetail,
SystemReviewDetail = p31.SystemReviewDetail,
VitalSignDetail = p31.VitalSignDetail,
GeneralAppearanceDetail = p31.GeneralAppearanceDetail,
SystolicBloodPressure = p31.SystolicBloodPressure,
DiastolicBloodPressure = p31.DiastolicBloodPressure,
PulseRate = p31.PulseRate,
SPO2 = p31.SPO2,
Temperature = p31.Temperature,
ApplicationUserId = p31.ApplicationUserId,
CreatedAt = p31.CreatedAt,
Id = p31.Id
ChiefComplaint = p29.ChiefComplaint,
SectionId = p29.SectionId,
SectionName = p29.Section != null ? p29.Section.Name : string.Empty,
MedicalHistoryTemplateId = p29.MedicalHistoryTemplateId,
Code = p29.Code,
PresentIllnessDetail = p29.PresentIllnessDetail,
PastDiseasesHistoryDetail = p29.PastDiseasesHistoryDetail,
PastSurgeryHistoryDetail = p29.PastSurgeryHistoryDetail,
FamilyHistoryDetail = p29.FamilyHistoryDetail,
AllergyDetail = p29.AllergyDetail,
DrugHistoryDetail = p29.DrugHistoryDetail,
AddictionHistoryDetail = p29.AddictionHistoryDetail,
SystemReviewDetail = p29.SystemReviewDetail,
VitalSignDetail = p29.VitalSignDetail,
GeneralAppearanceDetail = p29.GeneralAppearanceDetail,
SystolicBloodPressure = p29.SystolicBloodPressure,
DiastolicBloodPressure = p29.DiastolicBloodPressure,
PulseRate = p29.PulseRate,
SPO2 = p29.SPO2,
Temperature = p29.Temperature,
CreatedAt = p29.CreatedAt,
Id = p29.Id
};
private static List<MedicalHistoryAnswer> funcMain1(List<MedicalHistoryAnswerSDto> p2)
@ -619,14 +539,5 @@ namespace DocuMed.Domain.Mappers
return result;
}
private static ApplicationUser funcMain8(Never p26, ApplicationUser p27, MedicalHistorySDto p22)
{
ApplicationUser result = p27 ?? new ApplicationUser();
result.Id = p22.ApplicationUserId;
return result;
}
}
}

View File

@ -24,7 +24,6 @@ namespace DocuMed.Domain.Mappers
HospitalId = p1.Section.HospitalId,
Id = p1.Section.Id
},
ApplicationUserId = p1.ApplicationUserId,
Questions = funcMain1(p1.Questions),
Id = p1.Id,
CreatedAt = p1.CreatedAt
@ -41,7 +40,6 @@ namespace DocuMed.Domain.Mappers
result.ChiefComplaint = p3.ChiefComplaint;
result.SectionId = p3.SectionId;
result.Section = funcMain2(p3.Section, result.Section);
result.ApplicationUserId = p3.ApplicationUserId;
result.Questions = funcMain3(p3.Questions, result.Questions);
result.Id = p3.Id;
result.CreatedAt = p3.CreatedAt;
@ -59,7 +57,6 @@ namespace DocuMed.Domain.Mappers
HospitalId = p9.Section.HospitalId,
Id = p9.Section.Id
},
ApplicationUserId = p9.ApplicationUserId,
Questions = p9.Questions.Select<MedicalHistoryQuestionSDto, MedicalHistoryQuestion>(p10 => new MedicalHistoryQuestion()
{
Question = p10.Question,
@ -87,7 +84,6 @@ namespace DocuMed.Domain.Mappers
HospitalId = p11.Section.HospitalId,
Id = p11.Section.Id
},
ApplicationUserId = p11.ApplicationUserId,
CreatedAt = p11.CreatedAt,
Questions = funcMain4(p11.Questions),
Id = p11.Id
@ -104,7 +100,6 @@ namespace DocuMed.Domain.Mappers
result.ChiefComplaint = p13.ChiefComplaint;
result.SectionId = p13.SectionId;
result.Section = funcMain5(p13.Section, result.Section);
result.ApplicationUserId = p13.ApplicationUserId;
result.CreatedAt = p13.CreatedAt;
result.Questions = funcMain6(p13.Questions, result.Questions);
result.Id = p13.Id;
@ -122,7 +117,6 @@ namespace DocuMed.Domain.Mappers
HospitalId = p19.Section.HospitalId,
Id = p19.Section.Id
},
ApplicationUserId = p19.ApplicationUserId,
CreatedAt = p19.CreatedAt,
Questions = p19.Questions.Select<MedicalHistoryQuestion, MedicalHistoryQuestionSDto>(p20 => new MedicalHistoryQuestionSDto()
{
@ -143,7 +137,6 @@ namespace DocuMed.Domain.Mappers
{
ChiefComplaint = p21.ChiefComplaint,
SectionId = p21.SectionId,
ApplicationUserId = p21.ApplicationUserId,
Id = p21.Id,
CreatedAt = p21.CreatedAt
};
@ -158,7 +151,6 @@ namespace DocuMed.Domain.Mappers
result.ChiefComplaint = p22.ChiefComplaint;
result.SectionId = p22.SectionId;
result.ApplicationUserId = p22.ApplicationUserId;
result.Id = p22.Id;
result.CreatedAt = p22.CreatedAt;
return result;
@ -171,7 +163,6 @@ namespace DocuMed.Domain.Mappers
ChiefComplaint = p24.ChiefComplaint,
SectionName = p24.Section == null ? null : p24.Section.Name,
SectionId = p24.SectionId,
ApplicationUserId = p24.ApplicationUserId,
CreatedAt = p24.CreatedAt,
Id = p24.Id
};
@ -187,7 +178,6 @@ namespace DocuMed.Domain.Mappers
result.ChiefComplaint = p25.ChiefComplaint;
result.SectionName = p25.Section == null ? null : p25.Section.Name;
result.SectionId = p25.SectionId;
result.ApplicationUserId = p25.ApplicationUserId;
result.CreatedAt = p25.CreatedAt;
result.Id = p25.Id;
return result;
@ -198,7 +188,6 @@ namespace DocuMed.Domain.Mappers
ChiefComplaint = p27.ChiefComplaint,
SectionName = p27.Section.Name,
SectionId = p27.SectionId,
ApplicationUserId = p27.ApplicationUserId,
CreatedAt = p27.CreatedAt,
Id = p27.Id
};

View File

@ -1,6 +1,91 @@
using System;
using System.Linq.Expressions;
using DocuMed.Domain.Dtos.SmallDtos;
using DocuMed.Domain.Entities.Patients;
namespace DocuMed.Domain.Mappers
{
public static partial class PatientMapper
{
public static Patient AdaptToPatient(this PatientSDto p1)
{
return p1 == null ? null : new Patient()
{
UnitNumber = p1.UnitNumber,
Room = p1.Room,
Bed = p1.Bed,
AdmissionAt = p1.AdmissionAt,
SectionId = p1.SectionId,
Id = p1.Id
};
}
public static Patient AdaptTo(this PatientSDto p2, Patient p3)
{
if (p2 == null)
{
return null;
}
Patient result = p3 ?? new Patient();
result.UnitNumber = p2.UnitNumber;
result.Room = p2.Room;
result.Bed = p2.Bed;
result.AdmissionAt = p2.AdmissionAt;
result.SectionId = p2.SectionId;
result.Id = p2.Id;
return result;
}
public static Expression<Func<PatientSDto, Patient>> ProjectToPatient => p4 => new Patient()
{
UnitNumber = p4.UnitNumber,
Room = p4.Room,
Bed = p4.Bed,
AdmissionAt = p4.AdmissionAt,
SectionId = p4.SectionId,
Id = p4.Id
};
public static PatientSDto AdaptToSDto(this Patient p5)
{
return p5 == null ? null : new PatientSDto()
{
UnitNumber = p5.UnitNumber,
Room = p5.Room,
Bed = p5.Bed,
AdmissionAt = p5.AdmissionAt,
SectionId = p5.SectionId,
SectionName = p5.Section == null ? null : p5.Section.Name,
Id = p5.Id
};
}
public static PatientSDto AdaptTo(this Patient p6, PatientSDto p7)
{
if (p6 == null)
{
return null;
}
PatientSDto result = p7 ?? new PatientSDto();
result.UnitNumber = p6.UnitNumber;
result.Room = p6.Room;
result.Bed = p6.Bed;
result.AdmissionAt = p6.AdmissionAt;
result.SectionId = p6.SectionId;
result.SectionName = p6.Section == null ? null : p6.Section.Name;
result.Id = p6.Id;
return result;
}
public static Expression<Func<Patient, PatientSDto>> ProjectToSDto => p8 => new PatientSDto()
{
UnitNumber = p8.UnitNumber,
Room = p8.Room,
Bed = p8.Bed,
HospitalId = p8.HospitalId,
AdmissionAt = p8.AdmissionAt,
SectionId = p8.SectionId,
SectionName = p8.Section.Name,
Id = p8.Id
};
}
}

View File

@ -5,4 +5,5 @@ public static class Refers
public const int SizeS = 10;
public const int SizeM = 15;
public const int SizeL = 20;
public const int MaxSize = 25;
}

View File

@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Refit" Version="7.2.1" />
<PackageReference Include="Refit" Version="8.0.0" />
</ItemGroup>
<ItemGroup>

View File

@ -3,7 +3,7 @@
<Exec Command="npm run buildcss" />
</Target>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
@ -13,15 +13,15 @@
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="Blazorise.LottieAnimation" Version="1.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.8" PrivateAssets="all" />
<PackageReference Include="Blazorise.LottieAnimation" Version="1.7.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0" PrivateAssets="all" />
<PackageReference Include="MudBlazor" Version="6.13.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Refit" Version="7.2.1" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.2.1" />
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.2.1" />
<PackageReference Include="Toolbelt.Blazor.PWA.Updater" Version="2.1.0.1" />
<PackageReference Include="Refit" Version="8.0.0" />
<PackageReference Include="Refit.HttpClientFactory" Version="8.0.0" />
<PackageReference Include="Refit.Newtonsoft.Json" Version="8.0.0" />
<PackageReference Include="Toolbelt.Blazor.PWA.Updater" Version="3.0.1" />
</ItemGroup>
<ItemGroup>

View File

@ -15,4 +15,5 @@ public static class Address
public static string UserController = $"{BaseAddress}/user";
public static string MedicalHistoryTemplateController = $"{BaseAddress}/medicalhistory/template";
public static string MedicalHistoryController = $"{BaseAddress}/medicalhistory";
public static string PatientController = $"{BaseAddress}/patient";
}

View File

@ -5,17 +5,55 @@
<p class="text-center text-md">شرح حال بیمار را در مراحل مختلف و اطلاعات را با دقت وارد نمایید ، در مرحله اخر میتوانید شرحال کامل را مشاهده کنید
</p>
<BasePartDivider Index="1" Title="شکایت اصلی بیمار" />
<MudForm>
<MudFocusTrap>
<MudTextField Required="true" RequiredError="نام بیمار خود را وارد کنید" Value="@PatientFirstName" ValueChanged="async detail => { PatientFirstName = detail; await PatientFirstNameChanged.InvokeAsync(detail); }"
T="string" Label="نام بیمار" Variant="Variant.Outlined" class="text-sm my-5" />
<MudTextField Required="true" RequiredError="نام خانوادگی بیمار خود را وارد کنید" Value="@PatientLastName" ValueChanged="async detail => { PatientLastName = detail; await PatientLastNameChanged.InvokeAsync(detail); }"
T="string" Label="نام خانوادگی بیمار" Variant="Variant.Outlined" class="text-sm my-5" />
<MudNumericField Required="true" RequiredError="سن بیمار خود را وارد کنید" Value="@PatientAge"
<MudAutocomplete Value="@SelectedPatient"
CoerceValue="true"
class="text-sm my-5"
ToStringFunc="dto => dto.FullName"
SearchFunc="@SearchPatients"
ValueChanged="async dto => { SelectedPatient = dto; }"
T="PatientSDto"
Label="کد ملی بیمار"
Variant="Variant.Outlined">
<ProgressIndicatorInPopoverTemplate>
<MudList Clickable="false">
<MudListItem>
<div class="flex flex-row w-full mx-auto">
<MudProgressCircular class="my-auto mr-1 -ml-4" Size="Size.Small" Indeterminate="true"/>
<p class="font-bold my-1 mx-auto text-md">منتظر بمانید</p>
</div>
</MudListItem>
</MudList>
</ProgressIndicatorInPopoverTemplate>
<ItemTemplate Context="e">
<p>@e.FullName</p>
</ItemTemplate>
</MudAutocomplete>
<MudTextField Required="true" RequiredError="نام بیمار خود را وارد کنید" Value="@PatientFirstName"
ValueChanged="async detail => { PatientFirstName = detail; await PatientFirstNameChanged.InvokeAsync(detail); }"
T="string" Label="نام بیمار"
Variant="Variant.Outlined"
class="text-sm my-5"/>
<MudTextField Required="true"
RequiredError="نام خانوادگی بیمار خود را وارد کنید"
Value="@PatientLastName"
ValueChanged="async detail => { PatientLastName = detail; await PatientLastNameChanged.InvokeAsync(detail); }"
T="string"
Label="نام خانوادگی بیمار"
Variant="Variant.Outlined"
class="text-sm my-5"/>
<MudNumericField Required="true"
RequiredError="سن بیمار خود را وارد کنید" Value="@PatientAge"
ValueChanged="async detail => { PatientAge = detail; await PatientAgeChanged.InvokeAsync(detail); }"
Min="0"
T="int" Label="سن بیمار" Variant="Variant.Outlined" />
T="int"
Label="سن بیمار"
Variant="Variant.Outlined"/>
@ -28,7 +66,7 @@
<MudList Clickable="false">
<MudListItem>
<div class="flex flex-row w-full mx-auto">
<MudProgressCircular class="my-auto mr-1 -ml-4" Size="Size.Small" Indeterminate="true" />
<MudProgressCircular class="my-auto mr-1 -ml-4" Size="Size.Small" Indeterminate="true"/>
<p class="font-bold my-1 mx-auto text-md">منتظر بمانید</p>
</div>
</MudListItem>
@ -40,20 +78,22 @@
</MudAutocomplete>
<MudTextField Required="true" RequiredError="شکایت اصلی بیمار را وارد کنید" Value="@ChiefComplaint" ValueChanged="async detail => { ChiefComplaint = detail; await ChiefComplaintChanged.InvokeAsync(detail); }"
T="string" Label="شکایت اصلی بیمار" Variant="Variant.Outlined" class="text-sm my-5" />
T="string" Label="شکایت اصلی بیمار" Variant="Variant.Outlined" class="text-sm my-5"/>
<MudAutocomplete Value="@SelectedTemplate"
CoerceValue="true"
class="text-sm my-5"
ToStringFunc="dto => dto.ChiefComplaint"
SearchFunc="@SearchTemplates"
ValueChanged="async dto => { SelectedTemplate = dto; await SelectedTemplateChanged.InvokeAsync(SelectedTemplate); }"
T="MedicalHistoryTemplateSDto" Label="انتخاب از پیش نویس ها" Variant="Variant.Outlined">
T="MedicalHistoryTemplateSDto"
Label="انتخاب از پیش نویس ها"
Variant="Variant.Outlined">
<ProgressIndicatorInPopoverTemplate>
<MudList Clickable="false">
<MudListItem>
<div class="flex flex-row w-full mx-auto">
<MudProgressCircular class="my-auto mr-1 -ml-4" Size="Size.Small" Indeterminate="true" />
<MudProgressCircular class="my-auto mr-1 -ml-4" Size="Size.Small" Indeterminate="true"/>
<p class="font-bold my-1 mx-auto text-md">منتظر بمانید</p>
</div>
</MudListItem>
@ -109,6 +149,10 @@
[Parameter]
public MedicalHistoryTemplateSDto SelectedTemplate { get; set; } = new();
[Parameter]
public PatientSDto SelectedPatient { get; set; } = new();
[Parameter]
public EventCallback<MedicalHistoryTemplateSDto> SelectedTemplateChanged { get; set; }
@ -123,6 +167,7 @@
public List<SectionSDto> Sections { get; private set; } = new List<SectionSDto>();
public List<MedicalHistoryTemplateSDto> Templates { get; private set; } = new List<MedicalHistoryTemplateSDto>();
public List<PatientSDto> Patients { get; private set; } = new List<PatientSDto>();
public async Task<IEnumerable<MedicalHistoryTemplateSDto>> SearchTemplates(string template)
@ -149,6 +194,27 @@
}
}
public async Task<IEnumerable<PatientSDto>> SearchPatients(string name)
{
try
{
var token = await UserUtility.GetBearerTokenAsync();
var list = await RestWrapper.PatientRestApi.GetPatientsAsync(token,0,Refers.SizeM,null,name);
Patients = list;
return Patients;
}
catch (ApiException ex)
{
var exe = await ex.GetContentAsAsync<ApiResult>();
return Patients;
}
catch (Exception e)
{
return Patients;
}
}
public async Task<IEnumerable<SectionSDto>> SearchSection(string section)
{
try

View File

@ -0,0 +1,11 @@
namespace DocuMed.PWA.Services.RestServices;
public interface IPatientRestApi
{
[Get("/")]
Task<List<PatientSDto>> GetPatientsAsync([Header("Authorization")] string authorization,
[Query]int page ,
[Query]int? count = null,
[Query]string? searchName = null,
[Query]string? nationalId = null );
}

View File

@ -11,4 +11,5 @@ public interface IRestWrapper
public ICityRestApi CityRestApi { get; }
public IUserRestApi UserRestApi { get; }
public IMedicalHistoryRestApi MedicalHistoryRestApi { get; }
public IPatientRestApi PatientRestApi { get; }
}

View File

@ -25,4 +25,5 @@ public class RestWrapper : IRestWrapper
public ICityRestApi CityRestApi => RestService.For<ICityRestApi>(Address.CityController, setting);
public IUserRestApi UserRestApi => RestService.For<IUserRestApi>(Address.UserController, setting);
public IMedicalHistoryRestApi MedicalHistoryRestApi => RestService.For<IMedicalHistoryRestApi>(Address.MedicalHistoryController);
public IPatientRestApi PatientRestApi => RestService.For<IPatientRestApi>(Address.PatientController,setting);
}

View File

@ -1,26 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Pluralize.NET" Version="1.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="StackExchange.Redis" Version="2.8.16" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.24" />
<PackageReference Include="StackExchange.Redis.Extensions.Core" Version="10.2.0" />
</ItemGroup>
@ -42,10 +42,13 @@
<Using Include="DocuMed.Domain.Dtos.SmallDtos" />
<Using Include="DocuMed.Domain.Entities.MedicalHistory" />
<Using Include="DocuMed.Domain.Entities.MedicalHistoryTemplate" />
<Using Include="DocuMed.Domain.Entities.Patients" />
<Using Include="DocuMed.Domain.Entities.Staffs" />
<Using Include="DocuMed.Domain.Entities.User" />
<Using Include="DocuMed.Domain.Enums" />
<Using Include="DocuMed.Domain.Enums.QueryFilters" />
<Using Include="DocuMed.Domain.Mappers" />
<Using Include="DocuMed.Domain.Models" />
<Using Include="DocuMed.Domain.Models.Settings" />
<Using Include="DocuMed.Repository.Abstracts" />
<Using Include="DocuMed.Repository.Extensions" />

View File

@ -1,18 +1,70 @@
namespace DocuMed.Repository.Handlers.MedicalHistories;
using DocuMed.Domain.Entities.Staffs;
public class CreateMedicalHistoryCommandHandler(IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService) : IRequestHandler<CreateMedicalHistoryCommand,Guid>
namespace DocuMed.Repository.Handlers.MedicalHistories;
public class CreateMedicalHistoryCommandHandler(
IRepositoryWrapper repositoryWrapper,
ICurrentUserService currentUserService,
IMediator mediator) : IRequestHandler<CreateMedicalHistoryCommand,Guid>
{
public async Task<Guid> Handle(CreateMedicalHistoryCommand template, CancellationToken cancellationToken)
{
if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
throw new AppException("دسترسی غیرمجاز", ApiResultStatusCode.UnAuthorized);
var ent = MedicalHistory.Create(template.ChiefComplaint, template.SectionId,
template.PresentIllnessDetail, template.PastDiseasesHistoryDetail, template.PastSurgeryHistoryDetail,
template.FamilyHistoryDetail, template.AllergyDetail, template.DrugHistoryDetail,
template.AddictionHistoryDetail, template.SystemReviewDetail, template.VitalSignDetail, template.GeneralAppearanceDetail,
template.SystolicBloodPressure, template.DiastolicBloodPressure, template.PulseRate, template.SPO2,
template.Temperature, userId, template.MedicalHistoryTemplateId);
var student = await repositoryWrapper.SetRepository<Student>()
.TableNoTracking
.FirstOrDefaultAsync(f => f.UserId == userId, cancellationToken);
if (student == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Student not found");
Guid patientId;
if (template.PatientId != default)
{
var patient = await repositoryWrapper.SetRepository<Patient>()
.TableNoTracking
.FirstOrDefaultAsync(f => f.Id == template.PatientId, cancellationToken);
if (patient == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Patient not found");
patientId = patient.Id;
}
else
{
var patentCommand = new CreatePatientCommand(template.FirstName,
template.LastName,
string.Empty,
template.NationalId,
string.Empty,
string.Empty,
DateTime.Now,
template.SectionId
);
patientId = await mediator.Send(patentCommand, cancellationToken);
}
var ent = MedicalHistory.Create(template.ChiefComplaint,
template.SectionId,
template.PresentIllnessDetail,
template.PastDiseasesHistoryDetail,
template.PastSurgeryHistoryDetail,
template.FamilyHistoryDetail,
template.AllergyDetail,
template.DrugHistoryDetail,
template.AddictionHistoryDetail,
template.SystemReviewDetail,
template.VitalSignDetail,
template.GeneralAppearanceDetail,
template.SystolicBloodPressure,
template.DiastolicBloodPressure,
template.PulseRate,
template.SPO2,
template.Temperature,
student.Id,
patientId,
template.MedicalHistoryTemplateId);
foreach (var answer in template.Answers)
ent.AddAnswer(answer.Answer, answer.Question, answer.Part, answer.QuestionType);

View File

@ -1,22 +1,75 @@
namespace DocuMed.Repository.Handlers.MedicalHistories;
using MediatR;
public class UpdateMedicalHistoryCommandHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService) : IRequestHandler<UpdateMedicalHistoryCommand, Guid>
namespace DocuMed.Repository.Handlers.MedicalHistories;
public class UpdateMedicalHistoryCommandHandler(IRepositoryWrapper repositoryWrapper,
ICurrentUserService currentUserService,
IMediator mediator) : IRequestHandler<UpdateMedicalHistoryCommand, Guid>
{
public async Task<Guid> Handle(UpdateMedicalHistoryCommand template, CancellationToken cancellationToken)
{
if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
throw new AppException("دسترسی غیرمجاز", ApiResultStatusCode.UnAuthorized);
var student = await repositoryWrapper.SetRepository<Student>()
.TableNoTracking
.FirstOrDefaultAsync(f => f.UserId == userId, cancellationToken);
if (student == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Student not found");
var ent = await repositoryWrapper.SetRepository<MedicalHistory>().TableNoTracking
.FirstOrDefaultAsync(m => m.Id == template.Id, cancellationToken);
if(ent==null)
throw new AppException("شرح حال پیدا نشد", ApiResultStatusCode.NotFound);
var newEnt = MedicalHistory.Create(template.ChiefComplaint, template.SectionId,
template.PresentIllnessDetail, template.PastDiseasesHistoryDetail, template.PastSurgeryHistoryDetail,
template.FamilyHistoryDetail, template.AllergyDetail, template.DrugHistoryDetail,
template.AddictionHistoryDetail, template.SystemReviewDetail, template.VitalSignDetail, template.GeneralAppearanceDetail,
template.SystolicBloodPressure, template.DiastolicBloodPressure, template.PulseRate, template.SPO2,
template.Temperature, template.ApplicationUserId, template.MedicalHistoryTemplateId);
if (ent == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "شرح حال پیدا نشد");
if (ent.StudentId != student.Id)
throw new BaseApiException(ApiResultStatusCode.NotFound, "شرح حال متعلق به دانشجو نیست");
Guid patientId;
if (template.PatientId != default)
{
var patient = await repositoryWrapper.SetRepository<Patient>()
.TableNoTracking
.FirstOrDefaultAsync(f => f.Id == template.PatientId, cancellationToken);
if (patient == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Patient not found");
patientId = patient.Id;
}
else
{
var patentCommand = new CreatePatientCommand(template.FirstName,
template.LastName,
string.Empty,
template.NationalId,
string.Empty,
string.Empty,
DateTime.Now,
template.SectionId
);
patientId = await mediator.Send(patentCommand, cancellationToken);
}
var newEnt = MedicalHistory.Create(template.ChiefComplaint,
template.SectionId,
template.PresentIllnessDetail,
template.PastDiseasesHistoryDetail,
template.PastSurgeryHistoryDetail,
template.FamilyHistoryDetail,
template.AllergyDetail,
template.DrugHistoryDetail,
template.AddictionHistoryDetail,
template.SystemReviewDetail,
template.VitalSignDetail,
template.GeneralAppearanceDetail,
template.SystolicBloodPressure,
template.DiastolicBloodPressure,
template.PulseRate,
template.SPO2,
template.Temperature,
student.Id,
patientId,
template.MedicalHistoryTemplateId);
newEnt.Id = ent.Id;
newEnt.CreatedAt = ent.CreatedAt;

View File

@ -0,0 +1,44 @@
namespace DocuMed.Repository.Handlers.Patients;
public class CreatePatientCommandHandler(IRepositoryWrapper repositoryWrapper , UserManager<ApplicationUser> userManager) : IRequestHandler<CreatePatientCommand,Guid>
{
public async Task<Guid> Handle(CreatePatientCommand request, CancellationToken cancellationToken)
{
var user = await userManager.Users.FirstOrDefaultAsync(u => u.NationalId == request.NationalId,
cancellationToken);
if (user == null)
{
user = new ApplicationUser
{
UserName = request.NationalId,
NationalId = request.NationalId,
FirstName = request.FirstName,
LastName = request.LastName,
SignUpStatus = SignUpStatus.StartSignUp
};
var result = await userManager.CreateAsync(user);
if (!result.Succeeded)
throw new AppException(string.Join('|', result.Errors));
}
var section = await repositoryWrapper.SetRepository<Section>()
.TableNoTracking
.FirstOrDefaultAsync(f => f.Id == request.SectionId, cancellationToken);
if (section == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Section not found");
var patient = Patient.Create(
request.UnitNumber,
request.Room,
request.Bed,
request.AdmissionAt,
request.SectionId,
user.Id,
section.HospitalId
);
repositoryWrapper.SetRepository<Patient>()
.Add(patient);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return patient.Id;
}
}

View File

@ -0,0 +1,37 @@
namespace DocuMed.Repository.Handlers.Patients;
public class GetPatientQueryHandler(IRepositoryWrapper repositoryWrapper,UserManager<ApplicationUser> userManager) : IRequestHandler<GetPatientQuery, PatientSDto>
{
public async Task<PatientSDto> Handle(GetPatientQuery request, CancellationToken cancellationToken)
{
if (request.Id != null)
{
var ent = await repositoryWrapper.SetRepository<Patient>()
.TableNoTracking
.Where(f => f.Id == request.Id)
.Select(PatientMapper.ProjectToSDto)
.FirstOrDefaultAsync(cancellationToken);
if(ent == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Patient not found");
return ent;
}
else if (request.NationalId != null)
{
var user = await userManager.Users.FirstOrDefaultAsync(f => f.NationalId == request.NationalId,
cancellationToken);
if (user == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "User with this national id not found");
var ent = await repositoryWrapper.SetRepository<Patient>()
.TableNoTracking
.Where(f => f.UserId == user.Id)
.Select(PatientMapper.ProjectToSDto)
.FirstOrDefaultAsync(cancellationToken);
if (ent == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Patient not found");
return ent;
}
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Request is not correct - NationalId and Id is null");
}
}

View File

@ -0,0 +1,34 @@
namespace DocuMed.Repository.Handlers.Patients;
public class GetPatientsQueryHandler(IRepositoryWrapper repositoryWrapper,UserManager<ApplicationUser> userManager) : IRequestHandler<GetPatientsQuery,List<PatientSDto>>
{
public async Task<List<PatientSDto>> Handle(GetPatientsQuery request, CancellationToken cancellationToken)
{
var count = request.Count;
if(count > Refers.MaxSize)
count = Refers.SizeM;
var query = repositoryWrapper.SetRepository<Patient>()
.TableNoTracking;
if (!string.IsNullOrEmpty(request.SearchName))
{
}
if(!string.IsNullOrEmpty(request.NationalId))
{
query = from users in userManager.Users
join patients in query on users.Id equals patients.UserId
where users.NationalId == request.NationalId
select patients;
}
var result = await query
.OrderByDescending(x => x.CreatedAt)
.Skip(request.Page * count)
.Take(count)
.Select(PatientMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
return result;
}
}

View File

@ -0,0 +1,38 @@
namespace DocuMed.Repository.Handlers.Patients;
public class UpdatePatientSectionCommandHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler<UpdatePatientSectionCommand,Guid>
{
public async Task<Guid> Handle(UpdatePatientSectionCommand request, CancellationToken cancellationToken)
{
var patient = await repositoryWrapper.SetRepository<Patient>()
.TableNoTracking
.Where(f => f.Id == request.Id)
.Select(PatientMapper.ProjectToSDto)
.FirstOrDefaultAsync(cancellationToken);
if (patient == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Patient not found");
var section = await repositoryWrapper.SetRepository<Section>()
.TableNoTracking
.FirstOrDefaultAsync(f => f.Id == request.SectionId, cancellationToken);
if (section == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Section not found");
if(patient.HospitalId != section.HospitalId)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Patient and Section hospital is not same");
var newEnt = Patient.Create(
patient.UnitNumber,
patient.Room,
patient.Bed,
patient.AdmissionAt,
section.Id,
patient.HospitalId,
patient.Id);
repositoryWrapper.SetRepository<Patient>().Update(newEnt);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return newEnt.Id;
}
}

View File

@ -7,8 +7,15 @@ public class MedicalHistoryRepository(ApplicationContext dbContext, ICurrentUser
{
if (!Guid.TryParse(CurrentUserService.UserId, out Guid userId))
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
var student = await dbContext.Set<Student>()
.AsNoTracking()
.FirstOrDefaultAsync(f => f.UserId == userId, cancellationToken);
if (student == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Student not found");
var list = await TableNoTracking
.Where(t => t.ApplicationUserId == userId)
.Where(t => t.StudentId == student.Id)
.OrderByDescending(t => t.CreatedAt)
.Skip(page * 15)
.Take(15)
@ -21,12 +28,20 @@ public class MedicalHistoryRepository(ApplicationContext dbContext, ICurrentUser
{
if (!Guid.TryParse(CurrentUserService.UserId, out Guid userId))
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
var student = await dbContext.Set<Student>()
.AsNoTracking()
.FirstOrDefaultAsync(f => f.UserId == userId, cancellationToken);
if (student == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Student not found");
var list = new List<MedicalHistorySDto>();
switch (dayQuery)
{
case DayQueryFilter.Today:
list = await TableNoTracking
.Where(t => t.ApplicationUserId == userId && t.CreatedAt.Date == DateTime.Today)
.Where(t => t.StudentId == student.Id && t.CreatedAt.Date == DateTime.Today)
.OrderByDescending(t => t.CreatedAt)
.Skip(page * 15)
.Take(15)
@ -35,7 +50,7 @@ public class MedicalHistoryRepository(ApplicationContext dbContext, ICurrentUser
break;
case DayQueryFilter.Yesterday:
list = await TableNoTracking
.Where(t => t.ApplicationUserId == userId && t.CreatedAt.Date == DateTime.Today.AddDays(-1))
.Where(t => t.StudentId == student.Id && t.CreatedAt.Date == DateTime.Today.AddDays(-1))
.OrderByDescending(t => t.CreatedAt)
.Skip(page * 15)
.Take(15)
@ -44,7 +59,7 @@ public class MedicalHistoryRepository(ApplicationContext dbContext, ICurrentUser
break;
case DayQueryFilter.Week:
list = await TableNoTracking
.Where(t => t.ApplicationUserId == userId && t.CreatedAt.Date >= DateTime.Today.AddDays(-7) )
.Where(t => t.StudentId == student.Id && t.CreatedAt.Date >= DateTime.Today.AddDays(-7) )
.OrderByDescending(t => t.CreatedAt)
.Skip(page * 15)
.Take(15)

View File

@ -7,8 +7,15 @@ public class MedicalHistoryTemplateRepository(ApplicationContext dbContext, ICur
{
if (!Guid.TryParse(CurrentUserService.UserId, out Guid userId))
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
var student = await dbContext.Set<Student>()
.AsNoTracking()
.FirstOrDefaultAsync(f => f.UserId == userId, cancellationToken);
if (student == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Student not found");
var list = await TableNoTracking
.Where(t => t.ApplicationUserId == userId)
.Where(t => t.StudentId == student.Id)
.OrderByDescending(t => t.CreatedAt)
.Skip(page * 15)
.Take(15)