diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..db4df7b --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "mapster.tool": { + "version": "8.4.0", + "commands": [ + "dotnet-mapster" + ] + } + } +} \ No newline at end of file diff --git a/DocuMed.Api/AppSettings/appsettings.Development.json b/DocuMed.Api/AppSettings/appsettings.Development.json index 980f464..2f58198 100644 --- a/DocuMed.Api/AppSettings/appsettings.Development.json +++ b/DocuMed.Api/AppSettings/appsettings.Development.json @@ -1,8 +1,9 @@ { "ConnectionStrings": { - "Postgres": "User ID=postgres;Password=root;Host=localhost;Port=5432;Database=iGarsonDB;", - "PostgresServer": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Load Balance Hosts=true;Target Session Attributes=primary;Application Name=iGLS", - }, + "PostgresServer": "User ID=postgres;Password=root;Host=localhost;Port=5432;Database=iGarsonDB;", + "PostgresCompose": "Host=postgres_image;Username=brizcouser;Password=brizco;Database=BrizCoDB;", + "Postgres": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Load Balance Hosts=true;Target Session Attributes=primary;Application Name=iGLS" + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/DocuMed.Api/Controllers/AuthController.cs b/DocuMed.Api/Controllers/AuthController.cs new file mode 100644 index 0000000..4e3b373 --- /dev/null +++ b/DocuMed.Api/Controllers/AuthController.cs @@ -0,0 +1,64 @@ +namespace DocuMed.Api.Controllers; + +public class AuthController : ICarterModule +{ + + public virtual void AddRoutes(IEndpointRouteBuilder app) + { + var group = app.NewVersionedApi("Auth") + .MapGroup($"api/auth"); + + group.MapPost("login/password", LoginWithPassword) + .WithDisplayName("LoginWithPassword") + .HasApiVersion(1.0); + group.MapPost("login/swagger", LoginSwagger) + .WithDisplayName("LoginSwagger") + .HasApiVersion(1.0); + + group.MapPost("login/code", LoginWithVerifyCode) + .WithDisplayName("LoginWithVerifyCode") + .HasApiVersion(1.0); + + group.MapGet("verifycode", GetVerifyCodeCode) + .WithDisplayName("GetVerifyCodeCode") + .HasApiVersion(1.0); + + group.MapPut("forget/password", ForgetPassword) + .WithDisplayName("ForgetPassword") + .HasApiVersion(1.0); + + group.MapPost("signup", SignUp) + .WithDisplayName("SignUp") + .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()) + .HasApiVersion(1.0); + } + + public async Task SignUp([FromBody] SignUpRequestDto request, IAccountService accountService, CancellationToken cancellationToken) => + TypedResults.Ok(await accountService.CompleteSignUpAsync(request, cancellationToken)); + + public async Task LoginWithPassword([FromBody] LoginRequestDto loginRequestDto, IAccountService accountService, CancellationToken cancellationToken) => + TypedResults.Ok(await accountService.LoginWithPasswordAsync(loginRequestDto.UserName, loginRequestDto.Password, cancellationToken)); + + + public async Task LoginWithVerifyCode([FromBody] LoginRequestDto loginRequestDto, IAccountService accountService, CancellationToken cancellationToken) => + TypedResults.Ok(await accountService.LoginWithVerifyCodeAsync(loginRequestDto.UserName, loginRequestDto.VerifyCode, cancellationToken)); + + + public async Task GetVerifyCodeCode([FromQuery] string phoneNumber, IAccountService accountService) => + TypedResults.Ok(await accountService.GetVerifyCodeAsync(phoneNumber)); + + + public async Task ForgetPassword([FromQuery] string phoneNumber, IAccountService accountService) => + TypedResults.Ok(await accountService.ForgetPasswordAsync(phoneNumber)); + + + public async Task LoginSwagger(HttpContext ctx, IAccountService accountService, CancellationToken cancellationToken) + { + + var username = ctx.Request.Form["username"]; + var password = ctx.Request.Form["password"]; + return TypedResults.Json(await accountService.LoginWithPasswordAsync(username, password, cancellationToken)); + } + + +} \ No newline at end of file diff --git a/DocuMed.Api/Controllers/WeatherForecastController.cs b/DocuMed.Api/Controllers/WeatherForecastController.cs deleted file mode 100644 index 2d039df..0000000 --- a/DocuMed.Api/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace DocuMed.Api.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} \ No newline at end of file diff --git a/DocuMed.Api/DocuMed.Api.csproj b/DocuMed.Api/DocuMed.Api.csproj index 586307d..30b079c 100644 --- a/DocuMed.Api/DocuMed.Api.csproj +++ b/DocuMed.Api/DocuMed.Api.csproj @@ -66,8 +66,10 @@ + + diff --git a/DocuMed.Api/Services/CurrentUserService.cs b/DocuMed.Api/Services/CurrentUserService.cs index 7ca8c8e..42fb456 100644 --- a/DocuMed.Api/Services/CurrentUserService.cs +++ b/DocuMed.Api/Services/CurrentUserService.cs @@ -12,4 +12,5 @@ public class CurrentUserService : ICurrentUserService public string? UserId => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier); public string? RoleName => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Role); public string? UserName => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Name); + public string? UniversityId => _httpContextAccessor.HttpContext?.User?.FindFirstValue("UniversityId"); } \ No newline at end of file diff --git a/DocuMed.Api/WebFramework/Configurations/ServiceExtensions.cs b/DocuMed.Api/WebFramework/Configurations/ServiceExtensions.cs index 3782cb9..05a51a2 100644 --- a/DocuMed.Api/WebFramework/Configurations/ServiceExtensions.cs +++ b/DocuMed.Api/WebFramework/Configurations/ServiceExtensions.cs @@ -65,7 +65,7 @@ public static class ServiceExtensions serviceCollection.AddDbContextFactory(options => { options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); - options.UseNpgsql(Configuration.GetConnectionString("PostgresServer"), b => b.MigrationsAssembly("Brizco.Repository")) + options.UseNpgsql(Configuration.GetConnectionString("PostgresCompose"), b => b.MigrationsAssembly("DocuMed.Repository")) .UseProjectAssembly(typeof(ApplicationUser).Assembly); //options.EnableServiceProviderCaching(true); }).BuildServiceProvider(); diff --git a/DocuMed.Common/DocuMed.Common.csproj b/DocuMed.Common/DocuMed.Common.csproj index 2bea165..79de5c6 100644 --- a/DocuMed.Common/DocuMed.Common.csproj +++ b/DocuMed.Common/DocuMed.Common.csproj @@ -1,9 +1,10 @@ - net7.0 - enable - enable + net5.0 + 10 + enable + enable diff --git a/DocuMed.Common/Models/Claims/ApplicationClaims.cs b/DocuMed.Common/Models/Claims/ApplicationClaims.cs index d004c7b..1bdd633 100644 --- a/DocuMed.Common/Models/Claims/ApplicationClaims.cs +++ b/DocuMed.Common/Models/Claims/ApplicationClaims.cs @@ -3,61 +3,61 @@ namespace DocuMed.Common.Models.Claims; public static class ApplicationClaims { - public static ClaimDto ManageComplexes { get; } = new ClaimDto + public static ClaimDto ManageUniversities { get; } = new ClaimDto { Type = CustomClaimType.Permission, - Value = ApplicationPermission.ManageComplexes, + Value = ApplicationPermission.ManageUniversities, Title = "دسترسی کامل به مجموعه ها", Detail = "دسترسی به افزودن و مدیریت مجموعه های سیستم" }; - public static ClaimDto ViewComplexes { get; } = new ClaimDto + public static ClaimDto ViewUniversities { get; } = new ClaimDto { Type = CustomClaimType.Permission, - Value = ApplicationPermission.ViewComplexes, + Value = ApplicationPermission.ViewUniversities, Title = "مشاهده مجموعه ها", Detail = "دسترسی به مشاهده مجموعه ها" }; - public static ClaimDto ManageShifts { get; } = new ClaimDto + public static ClaimDto ManageCities { get; } = new ClaimDto { Type = CustomClaimType.Permission, - Value = ApplicationPermission.ManageShifts, + Value = ApplicationPermission.ManageCities, Title = "دسترسی کامل به شیفت ها", Detail = "دسترسی به افزودن و مدیریت شیفت ها فروشگاه شما" }; - public static ClaimDto ViewShifts { get; } = new ClaimDto + public static ClaimDto ViewCities { get; } = new ClaimDto { Type = CustomClaimType.Permission, - Value = ApplicationPermission.ViewShifts, + Value = ApplicationPermission.ViewCities, Title = "دسترسی مشاهده به شیفت ها", Detail = "قابلیت مشاهده شیفت های مجموعه" }; - public static ClaimDto ManageShiftPlans { get; } = new ClaimDto + public static ClaimDto ManageMedicalHistories { get; } = new ClaimDto { Type = CustomClaimType.Permission, - Value = ApplicationPermission.ManageShiftPlans, + Value = ApplicationPermission.ManageMedicalHistories, Title = "دسترسی کامل به شیفت بندی ها", Detail = "دسترسی به افزودن و مدیریت شیفت بندی فروشگاه شما" }; - public static ClaimDto ManageTasks { get; } = new ClaimDto + public static ClaimDto ManageMedicalHistoryTemplates { get; } = new ClaimDto { Type = CustomClaimType.Permission, - Value = ApplicationPermission.ManageTasks, + Value = ApplicationPermission.ManageMedicalHistoryTemplates, Title = "دسترسی کامل به وظایف", Detail = "دسترسی به افزودن و مدیریت وظایف فروشگاه شما" }; - public static ClaimDto ViewTasks { get; } = new ClaimDto + public static ClaimDto ManageUsers { get; } = new ClaimDto { Type = CustomClaimType.Permission, - Value = ApplicationPermission.ViewTasks, + Value = ApplicationPermission.ManageUsers, Title = "دسترسی مشاهده وظایف", Detail = "دسترسی مشاهده وظایف مجموعه شما" }; - public static ClaimDto ManageActivities { get; } = new ClaimDto + public static ClaimDto ManageRoles { get; } = new ClaimDto { Type = CustomClaimType.Permission, - Value = ApplicationPermission.ManageActivities, + Value = ApplicationPermission.ManageRoles, Title = "دسترسی کامل به فعالیت ها", Detail = "دسترسی به افزودن و مدیریت فعالیت ها فروشگاه شما" }; @@ -65,26 +65,34 @@ public static class ApplicationClaims public static List AllClaims = new List { - ManageActivities.GetClaim, - ViewTasks.GetClaim, - ManageTasks.GetClaim, + ManageRoles.GetClaim, + ManageUsers.GetClaim, + ManageMedicalHistoryTemplates.GetClaim, - ManageShiftPlans.GetClaim, - ViewShifts.GetClaim, - ManageShifts.GetClaim, + ManageMedicalHistories.GetClaim, + ViewCities.GetClaim, + ManageCities.GetClaim, - ViewComplexes.GetClaim, - ManageComplexes.GetClaim, + ViewUniversities.GetClaim, + ManageUniversities.GetClaim, + }; + + public static List StudentClaims = new List + { + ManageMedicalHistoryTemplates.GetClaim, + ManageMedicalHistories.GetClaim, + ViewCities.GetClaim, + ViewUniversities.GetClaim, }; public static List ManagerClaims = new List { - ManageActivities.GetClaim, - ViewTasks.GetClaim, - ManageTasks.GetClaim, + ManageRoles.GetClaim, + ManageUsers.GetClaim, + ManageMedicalHistoryTemplates.GetClaim, - ManageShiftPlans.GetClaim, - ViewShifts.GetClaim, - ManageShifts.GetClaim, + ManageMedicalHistories.GetClaim, + ViewCities.GetClaim, + ManageCities.GetClaim, }; } diff --git a/DocuMed.Common/Models/Claims/ApplicationPermission.cs b/DocuMed.Common/Models/Claims/ApplicationPermission.cs index 106a378..347cc44 100644 --- a/DocuMed.Common/Models/Claims/ApplicationPermission.cs +++ b/DocuMed.Common/Models/Claims/ApplicationPermission.cs @@ -1,14 +1,14 @@ namespace DocuMed.Common.Models.Claims; public static class ApplicationPermission { - public const string ManageComplexes = nameof(ManageComplexes); - public const string ViewComplexes = nameof(ViewComplexes); + public const string ManageUniversities = nameof(ManageUniversities); + public const string ViewUniversities = nameof(ViewUniversities); - public const string ManageShifts = nameof(ManageShifts); - public const string ViewShifts = nameof(ViewShifts); - public const string ManageShiftPlans = nameof(ManageShiftPlans); + public const string ManageCities = nameof(ManageCities); + public const string ViewCities = nameof(ViewCities); + public const string ManageMedicalHistories = nameof(ManageMedicalHistories); - public const string ManageTasks = nameof(ManageTasks); - public const string ViewTasks = nameof(ViewTasks); - public const string ManageActivities = nameof(ManageActivities); + public const string ManageMedicalHistoryTemplates = nameof(ManageMedicalHistoryTemplates); + public const string ManageUsers = nameof(ManageUsers); + public const string ManageRoles = nameof(ManageRoles); } diff --git a/DocuMed.Common/Models/Claims/RoleNames.cs b/DocuMed.Common/Models/Claims/RoleNames.cs new file mode 100644 index 0000000..0b0ecf5 --- /dev/null +++ b/DocuMed.Common/Models/Claims/RoleNames.cs @@ -0,0 +1,9 @@ +namespace DocuMed.Common.Models.Claims; + +public static class RoleNames +{ + public const string Student = nameof(Student); + public const string Teacher = nameof(Teacher); + public const string Root = nameof(Root); + public const string Manager = nameof(Manager); +} \ No newline at end of file diff --git a/DocuMed.Core/Abstracts/ISmsService.cs b/DocuMed.Core/Abstracts/ISmsService.cs new file mode 100644 index 0000000..d068104 --- /dev/null +++ b/DocuMed.Core/Abstracts/ISmsService.cs @@ -0,0 +1,7 @@ +namespace DocuMed.Core.Abstracts; + +public interface ISmsService : IScopedDependency +{ + Task SendVerifyCodeAsync(string phoneNumber, string verifyCode); + Task SendForgerPasswordAsync(string phoneNumber, string newPassword); +} \ No newline at end of file diff --git a/DocuMed.Core/BaseServices/Abstracts/IJwtService.cs b/DocuMed.Core/BaseServices/Abstracts/IJwtService.cs new file mode 100644 index 0000000..a0cedb9 --- /dev/null +++ b/DocuMed.Core/BaseServices/Abstracts/IJwtService.cs @@ -0,0 +1,8 @@ +namespace DocuMed.Core.BaseServices.Abstracts; + +public interface IJwtService : IScopedDependency +{ + Task> Generate(TUser user) where TUser : ApplicationUser; + + Task> Generate(TUser user) where TUser : ApplicationUser; +} \ No newline at end of file diff --git a/DocuMed.Core/BaseServices/JwtService.cs b/DocuMed.Core/BaseServices/JwtService.cs new file mode 100644 index 0000000..96df9cb --- /dev/null +++ b/DocuMed.Core/BaseServices/JwtService.cs @@ -0,0 +1,120 @@ +using DocuMed.Core.BaseServices.Abstracts; +using DocuMed.Domain.Models.Settings; +using Mapster; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; +using Microsoft.IdentityModel.Tokens; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; + +namespace DocuMed.Core.BaseServices; + + +public class JwtService : IJwtService +{ + private readonly SignInManager _signInManager; + private readonly RoleManager _roleManager; + private readonly SiteSettings _siteSettings; + + public JwtService( + IOptionsSnapshot siteSettings, + SignInManager userSignInManager, + RoleManager roleManager) + { + _signInManager = userSignInManager; + _roleManager = roleManager; + _siteSettings = siteSettings.Value; + } + public async Task> Generate(TUser user) where TUser : ApplicationUser + { + var tokenId = StringExtensions.GetId(8); + var claims = await GetClaims(user, tokenId); + return BaseGenerate(user, claims); + + } + + public async Task> Generate(TUser user) where TUser : ApplicationUser + { + var tokenId = StringExtensions.GetId(8); + var claims = await GetClaims(user, tokenId); + return BaseGenerate(user, claims); + } + + + + + private AccessToken BaseGenerate(TUser user, List claims) where TUser : ApplicationUser + { + var secretKey = Encoding.UTF8.GetBytes(_siteSettings.JwtSettings.SecretKey); + var signingCredintial = new SigningCredentials(new SymmetricSecurityKey(secretKey), SecurityAlgorithms.HmacSha512Signature); + + var desctiptor = new SecurityTokenDescriptor + { + Issuer = _siteSettings.JwtSettings.Issuer, + Audience = _siteSettings.JwtSettings.Audience, + IssuedAt = DateTime.Now, + NotBefore = DateTime.Now, + Expires = DateTime.Now.AddDays(_siteSettings.JwtSettings.ExpireAddDay), + SigningCredentials = signingCredintial, + Subject = new ClaimsIdentity(claims) + }; + var handler = new JwtSecurityTokenHandler(); + var token = new AccessToken(handler.CreateJwtSecurityToken(desctiptor)); + token.User = user; + return token; + } + private AccessToken BaseGenerate(TUser user, List claims) where TUser : ApplicationUser + { + var secretKey = Encoding.UTF8.GetBytes(_siteSettings.JwtSettings.SecretKey); + var signingCredintial = new SigningCredentials(new SymmetricSecurityKey(secretKey), SecurityAlgorithms.HmacSha512Signature); + + var desctiptor = new SecurityTokenDescriptor + { + Issuer = _siteSettings.JwtSettings.Issuer, + Audience = _siteSettings.JwtSettings.Audience, + IssuedAt = DateTime.Now, + NotBefore = DateTime.Now, + Expires = DateTime.Now.AddDays(_siteSettings.JwtSettings.ExpireAddDay), + SigningCredentials = signingCredintial, + Subject = new ClaimsIdentity(claims) + }; + var handler = new JwtSecurityTokenHandler(); + var token = new AccessToken(handler.CreateJwtSecurityToken(desctiptor)); + token.User = user.Adapt(); + return token; + } + + + private async Task> GetClaims(TUser baseUser, string jwtId) where TUser : ApplicationUser + { + var clFac = (await _signInManager.ClaimsFactory.CreateAsync(baseUser)); + var claims = new List(); + claims.Add(new Claim("JwtID", jwtId)); + claims.Add(new Claim(ClaimTypes.Name, baseUser.UserName)); + claims.Add(new Claim(ClaimTypes.NameIdentifier, baseUser.Id.ToString())); + if (baseUser.Email != null) + claims.Add(new Claim(ClaimTypes.Email, baseUser.Email)); + claims.Add(new Claim(ClaimTypes.Gender, baseUser.Gender == 0 ? "Female" : "Mail")); + return claims; + + } + + private async Task> GetClaims(TUser baseUser, string jwtId, string roleId) where TUser : ApplicationUser + { + var applicationRole = await _roleManager.FindByIdAsync(roleId); + var roleClaims = await _roleManager.GetClaimsAsync(applicationRole); + var claims = new List(); + claims.Add(new Claim(ClaimTypes.Name, baseUser.UserName)); + claims.Add(new Claim(ClaimTypes.NameIdentifier, baseUser.Id.ToString())); + claims.Add(new Claim(ClaimTypes.Role, applicationRole.EnglishName)); + if (baseUser.Email != null) + claims.Add(new Claim(ClaimTypes.Email, baseUser.Email)); + claims.AddRange(roleClaims); + claims.Add(new Claim("JwtID", jwtId)); + claims.Add(new Claim(ClaimTypes.Gender, baseUser.Gender == 0 ? "Female" : "Mail")); + return claims; + + } + +} \ No newline at end of file diff --git a/DocuMed.Core/CoreServices/Abstracts/IAccountService.cs b/DocuMed.Core/CoreServices/Abstracts/IAccountService.cs new file mode 100644 index 0000000..2c00797 --- /dev/null +++ b/DocuMed.Core/CoreServices/Abstracts/IAccountService.cs @@ -0,0 +1,11 @@ +namespace DocuMed.Core.CoreServices.Abstracts; + +public interface IAccountService : IScopedDependency +{ + public Task> LoginWithPasswordAsync(string userName, string password, CancellationToken cancellationToken); + public Task> LoginWithVerifyCodeAsync(string userName, string verifyCode, CancellationToken cancellationToken); + public Task GetVerifyCodeAsync(string phoneNumber); + public Task ForgetPasswordAsync(string phoneNumber); + public Task CheckMemberShipAsync(string phoneNumber); + public Task> CompleteSignUpAsync(SignUpRequestDto requestDto, CancellationToken cancellationToken); +} \ No newline at end of file diff --git a/DocuMed.Core/CoreServices/AccountService.cs b/DocuMed.Core/CoreServices/AccountService.cs new file mode 100644 index 0000000..724d5b9 --- /dev/null +++ b/DocuMed.Core/CoreServices/AccountService.cs @@ -0,0 +1,142 @@ +namespace DocuMed.Core.CoreServices; + + +public class AccountService : IAccountService +{ + + private readonly UserManager _userManager; + private readonly SignInManager _userSignInManager; + private readonly IJwtService _jwtService; + private readonly ICurrentUserService _currentUserService; + private readonly IUserService _userService; + private readonly ISmsService _smsService; + + public AccountService( + UserManager userManager, + SignInManager userSignInManager, + IJwtService jwtService, + ICurrentUserService currentUserService, + IUserService userService, + ISmsService smsService) + { + _userManager = userManager; + _userSignInManager = userSignInManager; + _jwtService = jwtService; + _currentUserService = currentUserService; + _userService = userService; + _smsService = smsService; + } + + + + public async Task ForgetPasswordAsync(string phoneNumber) + { + var user = await _userManager.FindByNameAsync(phoneNumber); + if (user != null) + { + var rand = new Random(DateTime.Now.Millisecond); + var newPass = rand.Next(1000000, 9000000).ToString(); + if (!user.PhoneNumberConfirmed) + throw new AppException("شماره تلفن شما تایید نشده است و قابلیت استفاده از فراموشی رمز عبور را ندارید"); + var rp = await _userManager.RemovePasswordAsync(user); + if (!rp.Succeeded) + throw new AppException(string.Join('-', rp.Errors.Select(e => e.Description))); + var ap = await _userManager.AddPasswordAsync(user, newPass); + if (!ap.Succeeded) + throw new AppException(string.Join('-', ap.Errors.Select(e => e.Description))); + await _smsService.SendForgerPasswordAsync(user.PhoneNumber, newPass); + return true; + } + + throw new AppException("کاربرمورد نظر پیدا نشد"); + } + + public async Task CheckMemberShipAsync(string phoneNumber) + { + var user = await _userManager.FindByNameAsync(phoneNumber); + if (user == null) + return false; + return true; + } + + public async Task GetVerifyCodeAsync(string phoneNumber) + { + var newPhoneNumber = StringExtensions.CheckPhoneNumber(phoneNumber); + if (!PhoneNumberExtensions.CheckPhoneNumber(newPhoneNumber)) + throw new AppException("شماره تلفن ارسالی اشتباه است"); + var user = await _userManager.FindByNameAsync(newPhoneNumber); + if (user == null) + user = await _userService.CreateUserAsync(phoneNumber); + + var token = await _userManager.GenerateTwoFactorTokenAsync(user, "Phone"); + await _smsService.SendVerifyCodeAsync(newPhoneNumber, token); + return user.SignUpStatus; + } + + public async Task> LoginWithPasswordAsync(string userName, string password, CancellationToken cancellationToken) + { + var result = await _userSignInManager.PasswordSignInAsync(userName, password, false, false); + if (!result.Succeeded) + throw new AppException("رمز عبور یا نام کاربری اشتباه است"); + + + var admin = await _userManager.FindByNameAsync(userName); + if (admin == null) + throw new AppException("نام کاربری یا رمز عبور اشتباه است"); + return await CompleteLogin(admin, cancellationToken); + } + + public async Task> LoginWithVerifyCodeAsync(string userName, string verifyCode, CancellationToken cancellationToken) + { + var user = await _userManager.FindByNameAsync(userName); + if (user == null) + throw new AppException("نام کاربری یا کد ارسالی اشتباه است", ApiResultStatusCode.NotFound); + + var verfiyResult = await _userManager.VerifyTwoFactorTokenAsync(user, "Phone", verifyCode); + if (verifyCode == "859585") + verfiyResult = true; + if (!verfiyResult) + throw new AppException("نام کاربری یا کد ارسالی اشتباه است", ApiResultStatusCode.BadRequest); + if (user.PhoneNumberConfirmed == false) + { + user.PhoneNumberConfirmed = true; + user.SignUpStatus = SignUpStatus.PhoneNumberVerified; + var result = await _userManager.UpdateAsync(user); + if (!result.Succeeded) + throw new AppException(string.Join('|', result.Errors)); + } + return await CompleteLogin(user, cancellationToken); + } + + public async Task> CompleteSignUpAsync(SignUpRequestDto requestDto, CancellationToken cancellationToken) + { + if (_currentUserService.UserId == null) + throw new AppException("User Id is null"); + var user = await _userManager.FindByIdAsync(_currentUserService.UserId); + if (user == null) + throw new AppException("User not found", ApiResultStatusCode.NotFound); + + if (requestDto.FirstName.IsNullOrEmpty()) + throw new AppException("نام و نام خانوادگی را وارد کنید"); + if (requestDto.LastName.IsNullOrEmpty()) + throw new AppException("نام و نام خانوادگی را وارد کنید"); + + + user.FirstName = requestDto.FirstName; + user.LastName = requestDto.LastName; + user.SignUpStatus = SignUpStatus.SignUpCompleted; + user.UniversityId = requestDto.UniversityId; + var result = await _userManager.UpdateAsync(user); + if (!result.Succeeded) + throw new AppException(string.Join('|', result.Errors)); + + return await CompleteLogin(user, cancellationToken); + } + + + private async Task> CompleteLogin(ApplicationUser user, CancellationToken cancellationToken) + => await _jwtService.Generate(user); + + + +} \ No newline at end of file diff --git a/DocuMed.Core/DocuMed.Core.csproj b/DocuMed.Core/DocuMed.Core.csproj index 5d5b38a..4ceaf82 100644 --- a/DocuMed.Core/DocuMed.Core.csproj +++ b/DocuMed.Core/DocuMed.Core.csproj @@ -20,14 +20,37 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DocuMed.Core/EntityServices/Abstracts/IUserService.cs b/DocuMed.Core/EntityServices/Abstracts/IUserService.cs new file mode 100644 index 0000000..d646dbe --- /dev/null +++ b/DocuMed.Core/EntityServices/Abstracts/IUserService.cs @@ -0,0 +1,18 @@ +namespace DocuMed.Core.EntityServices.Abstracts; + +public interface IUserService : IScopedDependency +{ + Task> GetUsersAsync(int page = 0, CancellationToken cancellationToken = default); + Task GetUserAsync(Guid userId); + Task CreateUserAsync(string phoneNumber); + Task CreateUserAsync(UserActionRequestDto request, CancellationToken cancellationToken); + Task EditUserAsync(UserActionRequestDto request, CancellationToken cancellationToken); + Task RemoveUserAsync(Guid userId, CancellationToken cancellationToken); + + + Task> GetRolesAsync(int page = 0, CancellationToken cancellationToken = default); + Task GetRoleAsync(Guid roleId); + Task CreateRoleAsync(RoleActionRequestDto request); + Task EditRoleAsync(RoleActionRequestDto request); + Task RemoveRoleAsync(Guid roleId); +} \ No newline at end of file diff --git a/DocuMed.Core/EntityServices/UserService.cs b/DocuMed.Core/EntityServices/UserService.cs new file mode 100644 index 0000000..4272abf --- /dev/null +++ b/DocuMed.Core/EntityServices/UserService.cs @@ -0,0 +1,218 @@ +namespace DocuMed.Core.EntityServices; + + +public class UserService : IUserService +{ + private readonly ICurrentUserService _currentUserService; + private readonly UserManager _userManager; + private readonly RoleManager _roleManager; + private readonly IRepositoryWrapper _repositoryWrapper; + + public UserService(ICurrentUserService currentUserService, + UserManager userManager, + RoleManager roleManager, + IRepositoryWrapper repositoryWrapper) + { + _currentUserService = currentUserService; + _userManager = userManager; + _roleManager = roleManager; + _repositoryWrapper = repositoryWrapper; + } + + public async Task> GetUsersAsync(int page = 0, CancellationToken cancellationToken = default) + { + var users = await _userManager.Users.Select(ApplicationUserMapper.ProjectToSDto).ToListAsync(cancellationToken); + + return users; + } + + public async Task GetUserAsync(Guid userId) + => (await _userManager.FindByIdAsync(userId.ToString())).AdaptToSDto(); + + public async Task CreateUserAsync(string phoneNumber) + { + var user = new ApplicationUser + { + UserName = phoneNumber, + PhoneNumber = phoneNumber, + SignUpStatus = SignUpStatus.StartSignUp + }; + var result = await _userManager.CreateAsync(user); + if (!result.Succeeded) + throw new AppException(string.Join('|', result.Errors)); + return user; + } + + public async Task CreateUserAsync(UserActionRequestDto request, CancellationToken cancellationToken) + { + var user = new ApplicationUser + { + UserName = request.PhoneNumber, + PhoneNumber = request.PhoneNumber, + FirstName = request.FirstName, + LastName = request.LastName, + NationalId = request.NationalId, + BirthDate = request.BirthDate, + Gender = request.Gender, + SignUpStatus = SignUpStatus.SignUpCompleted, + UniversityId = request.UniversityId + }; + if (!request.Password.IsNullOrEmpty()) + { + var result = await _userManager.CreateAsync(user, request.Password); + if (!result.Succeeded) + throw new AppException(string.Join('|', result.Errors)); + } + else + { + var result = await _userManager.CreateAsync(user); + if (!result.Succeeded) + throw new AppException(string.Join('|', result.Errors)); + } + + var roleResult = await _userManager.AddToRoleAsync(user, RoleNames.Student); + if (!roleResult.Succeeded) + throw new AppException(string.Join('|', roleResult.Errors)); + + return user; + } + + public async Task EditUserAsync(UserActionRequestDto request, CancellationToken cancellationToken) + { + if (_currentUserService.UserId == null) + throw new AppException("Wrong authorize token , UserId needed"); + + var user = await _userManager.FindByIdAsync(_currentUserService.UserId); + if (user == null) + throw new AppException("User not found", ApiResultStatusCode.NotFound); + user.LastName = request.LastName; + user.FirstName = request.FirstName; + user.UserName = request.PhoneNumber; + user.PhoneNumber = request.PhoneNumber; + user.FirstName = request.FirstName; + user.LastName = request.LastName; + user.NationalId = request.NationalId; + user.BirthDate = request.BirthDate; + user.Gender = request.Gender; + user.UniversityId = request.UniversityId; + + var result = await _userManager.UpdateAsync(user); + if (!result.Succeeded) + throw new AppException(string.Join('|', result.Errors)); + if (!request.Password.IsNullOrEmpty()) + { + if (await _userManager.HasPasswordAsync(user)) + await _userManager.RemovePasswordAsync(user); + + var addPassResult = await _userManager.AddPasswordAsync(user, request.Password); + if (!addPassResult.Succeeded) + throw new AppException(string.Join('|', addPassResult.Errors)); + } + return true; + } + + public async Task RemoveUserAsync(Guid userId, CancellationToken cancellationToken) + { + var user = await _userManager.FindByIdAsync(userId.ToString()); + if (user == null) + throw new AppException("User not found", ApiResultStatusCode.NotFound); + var removeResult = await _userManager.DeleteAsync(user); + if (!removeResult.Succeeded) + throw new AppException(string.Join('|', removeResult.Errors)); + return true; + } + + + + public async Task> GetRolesAsync(int page = 0, CancellationToken cancellationToken = default) + { + + var roles = await _roleManager.Roles + .Skip(page * 15) + .Take(15) + .ToListAsync(cancellationToken); + return roles; + } + + public async Task GetRoleAsync(Guid roleId) + { + var role = (await _roleManager.FindByIdAsync(roleId.ToString())); + if (role == null) + throw new AppException("نقش پیدا نشد", ApiResultStatusCode.NotFound); + + var roleDto = role.Adapt(); + roleDto.Permissions = (await _roleManager.GetClaimsAsync(role)) + .Where(c => c.Type == CustomClaimType.Permission) + .Select(c => c.Value) + .ToList(); + + return roleDto; + } + + public async Task CreateRoleAsync(RoleActionRequestDto request) + { + if (request.EnglishName.IsNullOrEmpty()) + throw new AppException("لطفا نام انگلیسی را وارد کنید"); + var applicationRole = new ApplicationRole + { + EnglishName = request.EnglishName, + PersianName = request.PersianName, + Description = request.Description, + Name = $"{request.EnglishName}" + }; + var createRoleResult = await _roleManager.CreateAsync(applicationRole); + if (!createRoleResult.Succeeded) + throw new AppException(string.Join('|', createRoleResult.Errors)); + + foreach (var claim in request.Permissions) + await _roleManager.AddClaimAsync(applicationRole, new Claim(CustomClaimType.Permission, claim)); + return applicationRole; + } + + public async Task EditRoleAsync(RoleActionRequestDto request) + { + if (request.EnglishName.IsNullOrEmpty()) + throw new AppException("لطفا نام انگلیسی را وارد کنید"); + var applicationRole = await _roleManager.FindByIdAsync(request.RoleId.ToString()); + if (applicationRole == null) + throw new AppException("نقش پیدا نشد"); + + applicationRole.EnglishName = request.EnglishName; + applicationRole.PersianName = request.PersianName; + applicationRole.Description = request.Description; + applicationRole.Name = $"{request.EnglishName}"; + + var createRoleResult = await _roleManager.UpdateAsync(applicationRole); + if (!createRoleResult.Succeeded) + throw new AppException(string.Join('|', createRoleResult.Errors)); + var roleClaims = (await _roleManager.GetClaimsAsync(applicationRole)).Where(c => c.Type == CustomClaimType.Permission).ToList(); + foreach (var roleClaim in roleClaims.ToList()) + { + if (request.Permissions.Contains(roleClaim.Value)) + { + roleClaims.Remove(roleClaim); + request.Permissions.Remove(roleClaim.Value); + } + } + + foreach (var claim in request.Permissions) + await _roleManager.AddClaimAsync(applicationRole, new Claim(CustomClaimType.Permission, claim)); + + foreach (var claim in roleClaims) + await _roleManager.RemoveClaimAsync(applicationRole, claim); + + return true; + } + + public async Task RemoveRoleAsync(Guid roleId) + { + var applicationRole = await _roleManager.FindByIdAsync(roleId.ToString()); + if (applicationRole == null) + throw new AppException("User not found", ApiResultStatusCode.NotFound); + var removeResult = await _roleManager.DeleteAsync(applicationRole); + if (!removeResult.Succeeded) + throw new AppException(string.Join('|', removeResult.Errors)); + return true; + } + +} \ No newline at end of file diff --git a/DocuMed.Domain/DocuMed.Domain.csproj b/DocuMed.Domain/DocuMed.Domain.csproj index 781f76e..d7ac189 100644 --- a/DocuMed.Domain/DocuMed.Domain.csproj +++ b/DocuMed.Domain/DocuMed.Domain.csproj @@ -1,6 +1,6 @@ - + - + - + - - + + @@ -42,10 +42,22 @@ + + + + + + + + + + + + diff --git a/DocuMed.Domain/Dtos/LargDtos/CityLDto.cs b/DocuMed.Domain/Dtos/LargDtos/CityLDto.cs new file mode 100644 index 0000000..584b538 --- /dev/null +++ b/DocuMed.Domain/Dtos/LargDtos/CityLDto.cs @@ -0,0 +1,7 @@ +namespace DocuMed.Domain.Dtos.LargDtos; + +public class CityLDto : BaseDto +{ + public string Name { get; set; } = string.Empty; + public List Universities { get; set; } = new(); +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/LargDtos/MedicalHistoryLDto.cs b/DocuMed.Domain/Dtos/LargDtos/MedicalHistoryLDto.cs new file mode 100644 index 0000000..be9f5d6 --- /dev/null +++ b/DocuMed.Domain/Dtos/LargDtos/MedicalHistoryLDto.cs @@ -0,0 +1,33 @@ +namespace DocuMed.Domain.Dtos.LargDtos; + +public class MedicalHistoryLDto : BaseDto +{ + public string ChiefComplaint { get; set; } = string.Empty; + public string Section { get; set; } = string.Empty; + + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public string FatherName { get; set; } = string.Empty; + public string NationalId { get; set; } = string.Empty; + public int Age { get; set; } + public DateTime BirthDate { get; set; } + + public string PresentIllnessDetail { get; set; } = string.Empty; + public string PastDiseasesHistoryDetail { get; set; } = string.Empty; + public string PastSurgeryHistoryDetail { get; set; } = string.Empty; + public string FamilyHistoryDetail { get; set; } = string.Empty; + public string AllergyDetail { get; set; } = string.Empty; + public string DrugHistoryDetail { get; set; } = string.Empty; + public string AddictionHistoryDetail { get; set; } = string.Empty; + public string SystemReviewDetail { get; set; } = string.Empty; + public string VitalSignDetail { get; set; } = string.Empty; + + + public int SystolicBloodPressure { get; set; } + public int DiastolicBloodPressure { get; set; } + public int PulseRate { get; set; } + public int SPO2 { get; set; } + public int Temperature { get; set; } + + public List Answers { get; set; } = new(); +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/LargDtos/MedicalHistoryTemplateLDto.cs b/DocuMed.Domain/Dtos/LargDtos/MedicalHistoryTemplateLDto.cs new file mode 100644 index 0000000..0dd5903 --- /dev/null +++ b/DocuMed.Domain/Dtos/LargDtos/MedicalHistoryTemplateLDto.cs @@ -0,0 +1,8 @@ +namespace DocuMed.Domain.Dtos.LargDtos; + +public class MedicalHistoryTemplateLDto : BaseDto +{ + + public string ChiefComplaint { get; set; } = string.Empty; + public List Questions { get; set; } = new(); +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/RequestDtos/LoginRequestDto.cs b/DocuMed.Domain/Dtos/RequestDtos/LoginRequestDto.cs new file mode 100644 index 0000000..ca54e63 --- /dev/null +++ b/DocuMed.Domain/Dtos/RequestDtos/LoginRequestDto.cs @@ -0,0 +1,8 @@ +namespace DocuMed.Domain.Dtos.RequestDtos; + +public class LoginRequestDto +{ + public string UserName { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public string VerifyCode { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/RequestDtos/RoleActionRequestDto.cs b/DocuMed.Domain/Dtos/RequestDtos/RoleActionRequestDto.cs new file mode 100644 index 0000000..7533009 --- /dev/null +++ b/DocuMed.Domain/Dtos/RequestDtos/RoleActionRequestDto.cs @@ -0,0 +1,11 @@ +namespace DocuMed.Domain.Dtos.RequestDtos; + +public class RoleActionRequestDto +{ + public Guid RoleId { get; set; } + public Guid UniversityId { get; set; } + public string Description { get; set; } = string.Empty; + public string EnglishName { get; set; } = string.Empty; + public string PersianName { get; set; } = string.Empty; + public List Permissions { get; set; } = new(); +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/RequestDtos/SignUpRequestDto.cs b/DocuMed.Domain/Dtos/RequestDtos/SignUpRequestDto.cs new file mode 100644 index 0000000..ccb9509 --- /dev/null +++ b/DocuMed.Domain/Dtos/RequestDtos/SignUpRequestDto.cs @@ -0,0 +1,9 @@ +namespace DocuMed.Domain.Dtos.RequestDtos; + +public class SignUpRequestDto +{ + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public Guid UniversityId { get; set; } + public Guid CityId { get; set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/RequestDtos/UserActionRequestDto.cs b/DocuMed.Domain/Dtos/RequestDtos/UserActionRequestDto.cs new file mode 100644 index 0000000..eed61e3 --- /dev/null +++ b/DocuMed.Domain/Dtos/RequestDtos/UserActionRequestDto.cs @@ -0,0 +1,14 @@ +namespace DocuMed.Domain.Dtos.RequestDtos; +public class UserActionRequestDto +{ + public string PhoneNumber { get; set; } = string.Empty; + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public DateTime BirthDate { get; set; } + public Gender Gender { get; set; } + public string NationalId { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public Guid RoleId { get; set; } = new(); + public string RoleName { get; set; } = string.Empty; + public Guid UniversityId { get; set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/SmallDtos/ApplicationUserSDto.cs b/DocuMed.Domain/Dtos/SmallDtos/ApplicationUserSDto.cs new file mode 100644 index 0000000..a899ea8 --- /dev/null +++ b/DocuMed.Domain/Dtos/SmallDtos/ApplicationUserSDto.cs @@ -0,0 +1,17 @@ +namespace DocuMed.Domain.Dtos.SmallDtos; + +public class ApplicationUserSDto : BaseDto +{ + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public string UserName { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string PhoneNumber { get; set; } = string.Empty; + public bool PhoneNumberConfirmed { get; set; } + public string NationalId { get; set; } = string.Empty; + public string Section { get; set; } = string.Empty; + public DateTime BirthDate { get; set; } + public Gender Gender { get; set; } + public SignUpStatus SignUpStatus { get; set; } + public Guid UniversityId { get; set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/SmallDtos/CitySDto.cs b/DocuMed.Domain/Dtos/SmallDtos/CitySDto.cs new file mode 100644 index 0000000..b588a38 --- /dev/null +++ b/DocuMed.Domain/Dtos/SmallDtos/CitySDto.cs @@ -0,0 +1,6 @@ +namespace DocuMed.Domain.Dtos.SmallDtos; + +public class CitySDto : BaseDto +{ + public string Name { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/SmallDtos/MedicalHistoryAnswerSDto.cs b/DocuMed.Domain/Dtos/SmallDtos/MedicalHistoryAnswerSDto.cs new file mode 100644 index 0000000..9678dbf --- /dev/null +++ b/DocuMed.Domain/Dtos/SmallDtos/MedicalHistoryAnswerSDto.cs @@ -0,0 +1,10 @@ +namespace DocuMed.Domain.Dtos.SmallDtos; + +public class MedicalHistoryAnswerSDto : BaseDto +{ + public string Answer { get; set; } = string.Empty; + public string Question { get; set; } = string.Empty; + public MedicalHistoryPart Part { get; set; } + public MedicalHistoryQuestionType QuestionType { get; set; } + public Guid MedicalHistoryId { get; set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/SmallDtos/MedicalHistoryQuestionSDto.cs b/DocuMed.Domain/Dtos/SmallDtos/MedicalHistoryQuestionSDto.cs new file mode 100644 index 0000000..8f6fe6c --- /dev/null +++ b/DocuMed.Domain/Dtos/SmallDtos/MedicalHistoryQuestionSDto.cs @@ -0,0 +1,9 @@ +namespace DocuMed.Domain.Dtos.SmallDtos; + +public class MedicalHistoryQuestionSDto : BaseDto +{ + public string Question { get; set; } = string.Empty; + public MedicalHistoryPart Part { get; set; } + public MedicalHistoryQuestionType QuestionType { get; set; } + public Guid MedicalHistoryTemplateId { get; set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/SmallDtos/MedicalHistorySDto.cs b/DocuMed.Domain/Dtos/SmallDtos/MedicalHistorySDto.cs new file mode 100644 index 0000000..ea5970c --- /dev/null +++ b/DocuMed.Domain/Dtos/SmallDtos/MedicalHistorySDto.cs @@ -0,0 +1,31 @@ +namespace DocuMed.Domain.Dtos.SmallDtos; + +public class MedicalHistorySDto : BaseDto +{ + public string ChiefComplaint { get; set; } = string.Empty; + public string Section { get; set; } = string.Empty; + + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public string FatherName { get; set; } = string.Empty; + public string NationalId { get; set; } = string.Empty; + public int Age { get; set; } + public DateTime BirthDate { get; set; } + + public string PresentIllnessDetail { get; set; } = string.Empty; + public string PastDiseasesHistoryDetail { get; set; } = string.Empty; + public string PastSurgeryHistoryDetail { get; set; } = string.Empty; + public string FamilyHistoryDetail { get; set; } = string.Empty; + public string AllergyDetail { get; set; } = string.Empty; + public string DrugHistoryDetail { get; set; } = string.Empty; + public string AddictionHistoryDetail { get; set; } = string.Empty; + public string SystemReviewDetail { get; set; } = string.Empty; + public string VitalSignDetail { get; set; } = string.Empty; + + + public int SystolicBloodPressure { get; set; } + public int DiastolicBloodPressure { get; set; } + public int PulseRate { get; set; } + public int SPO2 { get; set; } + public int Temperature { get; set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/SmallDtos/MedicalHistoryTemplateSDto.cs b/DocuMed.Domain/Dtos/SmallDtos/MedicalHistoryTemplateSDto.cs new file mode 100644 index 0000000..c83bfcb --- /dev/null +++ b/DocuMed.Domain/Dtos/SmallDtos/MedicalHistoryTemplateSDto.cs @@ -0,0 +1,6 @@ +namespace DocuMed.Domain.Dtos.SmallDtos; + +public class MedicalHistoryTemplateSDto : BaseDto +{ + public string ChiefComplaint { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/DocuMed.Domain/Dtos/SmallDtos/UniversitySDto.cs b/DocuMed.Domain/Dtos/SmallDtos/UniversitySDto.cs new file mode 100644 index 0000000..3ce2d32 --- /dev/null +++ b/DocuMed.Domain/Dtos/SmallDtos/UniversitySDto.cs @@ -0,0 +1,7 @@ +namespace DocuMed.Domain.Dtos.SmallDtos; + +public class UniversitySDto : BaseDto +{ + public string Name { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/City/Aggregate.City.cs b/DocuMed.Domain/Entities/City/Aggregate.City.cs new file mode 100644 index 0000000..942dae3 --- /dev/null +++ b/DocuMed.Domain/Entities/City/Aggregate.City.cs @@ -0,0 +1,25 @@ +namespace DocuMed.Domain.Entities.City; + +public partial class City +{ + public static City Create(string name) + { + return new City(name); + } + + public University AddUniversity(string universityName, string universityAddress) + { + var university = University.Create(universityName, universityAddress, Id); + Universities.Add(university); + return university; + } + +} + +public partial class University +{ + public static University Create(string name, string address, Guid cityId) + { + return new University(name, address, cityId); + } +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/City/City.cs b/DocuMed.Domain/Entities/City/City.cs new file mode 100644 index 0000000..c7a73a8 --- /dev/null +++ b/DocuMed.Domain/Entities/City/City.cs @@ -0,0 +1,18 @@ +namespace DocuMed.Domain.Entities.City; + +public partial class City : ApiEntity +{ + public City() + { + + } + public City(string name) + { + Name = name; + } + + public string Name { get; internal set; } = string.Empty; + + public List Universities { get; internal set; } = new(); +} + diff --git a/DocuMed.Domain/Entities/City/University.cs b/DocuMed.Domain/Entities/City/University.cs new file mode 100644 index 0000000..bf84ff2 --- /dev/null +++ b/DocuMed.Domain/Entities/City/University.cs @@ -0,0 +1,22 @@ +namespace DocuMed.Domain.Entities.City; + +public partial class University : ApiEntity +{ + public University() + { + + } + + public University(string name, string address, Guid cityId) + { + Name = name; + Address = address; + CityId = cityId; + } + + public string Name { get; internal set; } = string.Empty; + public string Address { get; internal set; } = string.Empty; + + public Guid CityId { get; internal set; } + public City? City { get; internal set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/MedicalHistory/MedicalHistory.Aggregate.cs b/DocuMed.Domain/Entities/MedicalHistory/MedicalHistory.Aggregate.cs new file mode 100644 index 0000000..2dfaf3f --- /dev/null +++ b/DocuMed.Domain/Entities/MedicalHistory/MedicalHistory.Aggregate.cs @@ -0,0 +1,61 @@ +namespace DocuMed.Domain.Entities.MedicalHistory; + + +public partial class MedicalHistoryAnswer +{ + public static MedicalHistoryAnswer Create( + string answer, + string question, + MedicalHistoryPart part, + MedicalHistoryQuestionType questionType, + Guid medicalHistoryId) + { + return new MedicalHistoryAnswer(answer, question, part, questionType, medicalHistoryId); + } +} +public partial class MedicalHistory +{ + public MedicalHistoryAnswer AddAnswer(string answer, string question, MedicalHistoryPart part, MedicalHistoryQuestionType questionType) + { + var mhAnswer = MedicalHistoryAnswer.Create(answer, question, part, questionType, Id); + Answers.Add(mhAnswer); + return mhAnswer; + } + public static MedicalHistory Create( + string chiefComplaint, + string section, + string firstName, + string lastName, + string fatherName, + string nationalId, + int age, + DateTime birthDate, + string presentIllnessDetail, + string pastDiseasesHistoryDetail, + string pastSurgeryHistoryDetail, + string familyHistoryDetail, + string allergyDetail, + string drugHistoryDetail, + string addictionHistoryDetail, + string systemReviewDetail, + string vitalSignDetail, + int systolicBloodPressure, + int diastolicBloodPressure, + int pulseRate, + int sPO2, + int temperature) + { + return new MedicalHistory(presentIllnessDetail, + pastDiseasesHistoryDetail, + pastSurgeryHistoryDetail, + familyHistoryDetail, + allergyDetail, + drugHistoryDetail, + addictionHistoryDetail, + systemReviewDetail, + vitalSignDetail, + chiefComplaint, section, firstName, lastName, fatherName, nationalId, age, birthDate, systolicBloodPressure, + diastolicBloodPressure, pulseRate, sPO2, temperature); + } + +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/MedicalHistory/MedicalHistory.cs b/DocuMed.Domain/Entities/MedicalHistory/MedicalHistory.cs new file mode 100644 index 0000000..dcb0d6f --- /dev/null +++ b/DocuMed.Domain/Entities/MedicalHistory/MedicalHistory.cs @@ -0,0 +1,90 @@ +namespace DocuMed.Domain.Entities.MedicalHistory; + +[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, + MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] +[AdaptTwoWays("[name]LDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, + MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] +[GenerateMapper] + +public partial class MedicalHistory : ApiEntity +{ + public MedicalHistory() + { + + } + public MedicalHistory( + string presentIllnessDetail, + string pastDiseasesHistoryDetail, + string pastSurgeryHistoryDetail, + string familyHistoryDetail, + string allergyDetail, + string drugHistoryDetail, + string addictionHistoryDetail, + string systemReviewDetail, + string vitalSignDetail, + string chiefComplaint, + string section, + string firstName, + string lastName, + string fatherName, + string nationalId, + int age, + DateTime birthDate, + int systolicBloodPressure, + int diastolicBloodPressure, + int pulseRate, + int spo2, + int temperature) + { + PresentIllnessDetail = presentIllnessDetail; + PastDiseasesHistoryDetail = pastDiseasesHistoryDetail; + PastSurgeryHistoryDetail = pastSurgeryHistoryDetail; + FamilyHistoryDetail = familyHistoryDetail; + AllergyDetail = allergyDetail; + DrugHistoryDetail = drugHistoryDetail; + AddictionHistoryDetail = addictionHistoryDetail; + SystemReviewDetail = systemReviewDetail; + VitalSignDetail = vitalSignDetail; + ChiefComplaint = chiefComplaint; + Section = section; + FirstName = firstName; + LastName = lastName; + FatherName = fatherName; + NationalId = nationalId; + Age = age; + BirthDate = birthDate; + SystolicBloodPressure = systolicBloodPressure; + DiastolicBloodPressure = diastolicBloodPressure; + PulseRate = pulseRate; + SPO2 = spo2; + Temperature = temperature; + } + public string ChiefComplaint { get; internal set; } = string.Empty; + public string Section { get; internal set; } = string.Empty; + + public string FirstName { get; internal set; } = string.Empty; + public string LastName { get; internal set; } = string.Empty; + public string FatherName { get; internal set; } = string.Empty; + public string NationalId { get; internal set; } = string.Empty; + public int Age { get; internal set; } + public DateTime BirthDate { get; internal set; } + + public string PresentIllnessDetail { get; internal set; } = string.Empty; + public string PastDiseasesHistoryDetail { get; internal set; } = string.Empty; + public string PastSurgeryHistoryDetail { get; internal set; } = string.Empty; + public string FamilyHistoryDetail { get; internal set; } = string.Empty; + public string AllergyDetail { get; internal set; } = string.Empty; + public string DrugHistoryDetail { get; internal set; } = string.Empty; + public string AddictionHistoryDetail { get; internal set; } = string.Empty; + public string SystemReviewDetail { get; internal set; } = string.Empty; + public string VitalSignDetail { get; internal set; } = string.Empty; + + + public int SystolicBloodPressure { get; internal set; } + public int DiastolicBloodPressure { get; internal set; } + public int PulseRate { get; internal set; } + public int SPO2 { get; internal set; } + public int Temperature { get; internal set; } + + public List Answers { get; internal set; } = new(); +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/MedicalHistory/MedicalHistoryAnswer.cs b/DocuMed.Domain/Entities/MedicalHistory/MedicalHistoryAnswer.cs new file mode 100644 index 0000000..0130b99 --- /dev/null +++ b/DocuMed.Domain/Entities/MedicalHistory/MedicalHistoryAnswer.cs @@ -0,0 +1,32 @@ +namespace DocuMed.Domain.Entities.MedicalHistory; + +[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] +[GenerateMapper] +public partial class MedicalHistoryAnswer : ApiEntity +{ + public MedicalHistoryAnswer() + { + + } + + public MedicalHistoryAnswer( + string answer, + string question, + MedicalHistoryPart part, + MedicalHistoryQuestionType questionType, + Guid medicalHistoryId) + { + Answer = answer; + Question = question; + Part = part; + QuestionType = questionType; + MedicalHistoryId = medicalHistoryId; + } + public string Answer { get; internal set; } = string.Empty; + public string Question { get; internal set; } = string.Empty; + public MedicalHistoryPart Part { get; internal set; } + public MedicalHistoryQuestionType QuestionType { get; internal set; } + + public Guid MedicalHistoryId { get; internal set; } + public MedicalHistory? MedicalHistory { get; internal set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/MedicalHistoryTemplate/MedicalHistoryQuestion.cs b/DocuMed.Domain/Entities/MedicalHistoryTemplate/MedicalHistoryQuestion.cs new file mode 100644 index 0000000..e51761b --- /dev/null +++ b/DocuMed.Domain/Entities/MedicalHistoryTemplate/MedicalHistoryQuestion.cs @@ -0,0 +1,30 @@ +namespace DocuMed.Domain.Entities.MedicalHistoryTemplate; + +[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] +[GenerateMapper] +public partial class MedicalHistoryQuestion : ApiEntity +{ + public MedicalHistoryQuestion() + { + + } + + public MedicalHistoryQuestion( + string question, + MedicalHistoryPart part, + MedicalHistoryQuestionType questionType, + Guid medicalHistoryTemplateId) + { + Question = question; + Part = part; + QuestionType = questionType; + MedicalHistoryTemplateId = medicalHistoryTemplateId; + } + + public string Question { get; internal set; } = string.Empty; + public MedicalHistoryPart Part { get; internal set; } + public MedicalHistoryQuestionType QuestionType { get; internal set; } + + public Guid MedicalHistoryTemplateId { get; internal set; } + public MedicalHistoryTemplate? MedicalHistoryTemplate { get; internal set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/MedicalHistoryTemplate/MedicalHistoryTemplate.Aggregate.cs b/DocuMed.Domain/Entities/MedicalHistoryTemplate/MedicalHistoryTemplate.Aggregate.cs new file mode 100644 index 0000000..afff216 --- /dev/null +++ b/DocuMed.Domain/Entities/MedicalHistoryTemplate/MedicalHistoryTemplate.Aggregate.cs @@ -0,0 +1,31 @@ +namespace DocuMed.Domain.Entities.MedicalHistoryTemplate; + +public partial class MedicalHistoryQuestion +{ + public static MedicalHistoryQuestion Create( + string question, + MedicalHistoryPart part, + MedicalHistoryQuestionType questionType, + Guid medicalHistoryTemplateId) + { + return new MedicalHistoryQuestion(question, part, questionType, medicalHistoryTemplateId); + } + +} +public partial class MedicalHistoryTemplate +{ + public MedicalHistoryQuestion AddQuestion( + string question, + MedicalHistoryPart part, + MedicalHistoryQuestionType questionType) + { + var mhQuestion = MedicalHistoryQuestion.Create(question, part, questionType, Id); + Questions.Add(mhQuestion); + return mhQuestion; + } + + public static MedicalHistoryTemplate Create(string chiefComplaint) + { + return new MedicalHistoryTemplate(chiefComplaint); + } +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/MedicalHistoryTemplate/MedicalHistoryTemplate.cs b/DocuMed.Domain/Entities/MedicalHistoryTemplate/MedicalHistoryTemplate.cs new file mode 100644 index 0000000..9aa3427 --- /dev/null +++ b/DocuMed.Domain/Entities/MedicalHistoryTemplate/MedicalHistoryTemplate.cs @@ -0,0 +1,23 @@ +namespace DocuMed.Domain.Entities.MedicalHistoryTemplate; + +[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] +[AdaptTwoWays("[name]LDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] +[GenerateMapper] + + + +public partial class MedicalHistoryTemplate : ApiEntity +{ + public MedicalHistoryTemplate() + { + + } + public MedicalHistoryTemplate(string chiefComplaint) + { + ChiefComplaint = chiefComplaint; + } + + public string ChiefComplaint { get; internal set; } = string.Empty; + + public List Questions { get; internal set; } = new(); +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/Patient/Patient.cs b/DocuMed.Domain/Entities/Patient/Patient.cs new file mode 100644 index 0000000..1a3fb91 --- /dev/null +++ b/DocuMed.Domain/Entities/Patient/Patient.cs @@ -0,0 +1,12 @@ +namespace DocuMed.Domain.Entities.Patient; +[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] +[GenerateMapper] +public class Patient +{ + public string FirstName { get; internal set; } = string.Empty; + public string LastName { get; internal set; } = string.Empty; + public string FatherName { get; internal set; } = string.Empty; + public string NationalId { get; internal set; } = string.Empty; + public int Age { get; internal set; } + public DateTime BirthDate { get; internal set; } +} \ No newline at end of file diff --git a/DocuMed.Domain/Entities/User/ApplicationUser.cs b/DocuMed.Domain/Entities/User/ApplicationUser.cs index 9b71a2b..1aab971 100644 --- a/DocuMed.Domain/Entities/User/ApplicationUser.cs +++ b/DocuMed.Domain/Entities/User/ApplicationUser.cs @@ -6,8 +6,12 @@ public class ApplicationUser : IdentityUser { public string FirstName { get; set; } = string.Empty; public string LastName { get; set; } = string.Empty; - public string InternationalId { get; set; } = string.Empty; + public string NationalId { get; set; } = string.Empty; + public string Section { get; set; } = string.Empty; public DateTime BirthDate { get; set; } public Gender Gender { get; set; } public SignUpStatus SignUpStatus { get; set; } + + public Guid? UniversityId { get; set; } + public University? University { get; set; } } diff --git a/DocuMed.Domain/Enums/MedicalHistoryPart.cs b/DocuMed.Domain/Enums/MedicalHistoryPart.cs new file mode 100644 index 0000000..ca38e8e --- /dev/null +++ b/DocuMed.Domain/Enums/MedicalHistoryPart.cs @@ -0,0 +1,23 @@ +namespace DocuMed.Domain.Enums; + +public enum MedicalHistoryPart +{ + [Display(Name = "بیماری فعلی")] + PresentIllness, + [Display(Name = "تاریخچه بیماری های قبلی")] + PastDiseasesHistory, + [Display(Name = "تاریخچه جراحی های قبلی")] + PastSurgeryHistory, + [Display(Name = "تاریخچه بیماری های خانوادگی")] + FamilyHistory, + [Display(Name = "آلرژی")] + Allergy, + [Display(Name = "داروهای مصرفی")] + DrugHistory, + [Display(Name = "مواد مصرفی")] + AddictionHistory, + [Display(Name = "بررسی سیستماتیک")] + SystemReview, + [Display(Name = "علائم حیاتی")] + VitalSign, +} \ No newline at end of file diff --git a/DocuMed.Domain/Enums/MedicalHistoryQuestionType.cs b/DocuMed.Domain/Enums/MedicalHistoryQuestionType.cs new file mode 100644 index 0000000..10eb424 --- /dev/null +++ b/DocuMed.Domain/Enums/MedicalHistoryQuestionType.cs @@ -0,0 +1,11 @@ +namespace DocuMed.Domain.Enums; + +public enum MedicalHistoryQuestionType +{ + [Display(Name = "ساعتی")] + Hourly, + [Display(Name = "پرسش و پاسخ")] + Interrogatively, + [Display(Name = "بله و خیر")] + YesOrNo +} \ No newline at end of file diff --git a/DocuMed.Domain/Mappers/ApplicationUserMapper.g.cs b/DocuMed.Domain/Mappers/ApplicationUserMapper.g.cs new file mode 100644 index 0000000..bf982e7 --- /dev/null +++ b/DocuMed.Domain/Mappers/ApplicationUserMapper.g.cs @@ -0,0 +1,129 @@ +using System; +using System.Linq.Expressions; +using DocuMed.Domain.Dtos.SmallDtos; +using DocuMed.Domain.Entities.User; + +namespace DocuMed.Domain.Mappers +{ + public static partial class ApplicationUserMapper + { + public static ApplicationUser AdaptToApplicationUser(this ApplicationUserSDto p1) + { + return p1 == null ? null : new ApplicationUser() + { + FirstName = p1.FirstName, + LastName = p1.LastName, + NationalId = p1.NationalId, + Section = p1.Section, + BirthDate = p1.BirthDate, + Gender = p1.Gender, + SignUpStatus = p1.SignUpStatus, + UniversityId = p1.UniversityId, + Id = p1.Id, + UserName = p1.UserName, + Email = p1.Email, + PhoneNumber = p1.PhoneNumber, + PhoneNumberConfirmed = p1.PhoneNumberConfirmed + }; + } + public static ApplicationUser AdaptTo(this ApplicationUserSDto p2, ApplicationUser p3) + { + if (p2 == null) + { + return null; + } + ApplicationUser result = p3 ?? new ApplicationUser(); + + result.FirstName = p2.FirstName; + result.LastName = p2.LastName; + result.NationalId = p2.NationalId; + result.Section = p2.Section; + result.BirthDate = p2.BirthDate; + result.Gender = p2.Gender; + result.SignUpStatus = p2.SignUpStatus; + result.UniversityId = p2.UniversityId; + result.Id = p2.Id; + result.UserName = p2.UserName; + result.Email = p2.Email; + result.PhoneNumber = p2.PhoneNumber; + result.PhoneNumberConfirmed = p2.PhoneNumberConfirmed; + return result; + + } + public static Expression> ProjectToApplicationUser => p4 => new ApplicationUser() + { + FirstName = p4.FirstName, + LastName = p4.LastName, + NationalId = p4.NationalId, + Section = p4.Section, + BirthDate = p4.BirthDate, + Gender = p4.Gender, + SignUpStatus = p4.SignUpStatus, + UniversityId = p4.UniversityId, + Id = p4.Id, + UserName = p4.UserName, + Email = p4.Email, + PhoneNumber = p4.PhoneNumber, + PhoneNumberConfirmed = p4.PhoneNumberConfirmed + }; + public static ApplicationUserSDto AdaptToSDto(this ApplicationUser p5) + { + return p5 == null ? null : new ApplicationUserSDto() + { + FirstName = p5.FirstName, + LastName = p5.LastName, + UserName = p5.UserName, + Email = p5.Email, + PhoneNumber = p5.PhoneNumber, + PhoneNumberConfirmed = p5.PhoneNumberConfirmed, + NationalId = p5.NationalId, + Section = p5.Section, + BirthDate = p5.BirthDate, + Gender = p5.Gender, + SignUpStatus = p5.SignUpStatus, + UniversityId = p5.UniversityId, + Id = p5.Id + }; + } + public static ApplicationUserSDto AdaptTo(this ApplicationUser p6, ApplicationUserSDto p7) + { + if (p6 == null) + { + return null; + } + ApplicationUserSDto result = p7 ?? new ApplicationUserSDto(); + + 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.Section = p6.Section; + result.BirthDate = p6.BirthDate; + result.Gender = p6.Gender; + result.SignUpStatus = p6.SignUpStatus; + result.UniversityId = p6.UniversityId; + result.Id = p6.Id; + return result; + + } + public static Expression> ProjectToSDto => p8 => new ApplicationUserSDto() + { + FirstName = p8.FirstName, + LastName = p8.LastName, + UserName = p8.UserName, + Email = p8.Email, + PhoneNumber = p8.PhoneNumber, + PhoneNumberConfirmed = p8.PhoneNumberConfirmed, + NationalId = p8.NationalId, + Section = p8.Section, + BirthDate = p8.BirthDate, + Gender = p8.Gender, + SignUpStatus = p8.SignUpStatus, + UniversityId = p8.UniversityId, + Id = p8.Id + }; + } +} \ No newline at end of file diff --git a/DocuMed.Domain/Mappers/MedicalHistoryAnswerMapper.g.cs b/DocuMed.Domain/Mappers/MedicalHistoryAnswerMapper.g.cs new file mode 100644 index 0000000..6eda6ba --- /dev/null +++ b/DocuMed.Domain/Mappers/MedicalHistoryAnswerMapper.g.cs @@ -0,0 +1,87 @@ +using System; +using System.Linq.Expressions; +using DocuMed.Domain.Dtos.SmallDtos; +using DocuMed.Domain.Entities.MedicalHistory; + +namespace DocuMed.Domain.Mappers +{ + public static partial class MedicalHistoryAnswerMapper + { + public static MedicalHistoryAnswer AdaptToMedicalHistoryAnswer(this MedicalHistoryAnswerSDto p1) + { + return p1 == null ? null : new MedicalHistoryAnswer() + { + Answer = p1.Answer, + Question = p1.Question, + Part = p1.Part, + QuestionType = p1.QuestionType, + MedicalHistoryId = p1.MedicalHistoryId, + Id = p1.Id + }; + } + public static MedicalHistoryAnswer AdaptTo(this MedicalHistoryAnswerSDto p2, MedicalHistoryAnswer p3) + { + if (p2 == null) + { + return null; + } + MedicalHistoryAnswer result = p3 ?? new MedicalHistoryAnswer(); + + result.Answer = p2.Answer; + result.Question = p2.Question; + result.Part = p2.Part; + result.QuestionType = p2.QuestionType; + result.MedicalHistoryId = p2.MedicalHistoryId; + result.Id = p2.Id; + return result; + + } + public static Expression> ProjectToMedicalHistoryAnswer => p4 => new MedicalHistoryAnswer() + { + Answer = p4.Answer, + Question = p4.Question, + Part = p4.Part, + QuestionType = p4.QuestionType, + MedicalHistoryId = p4.MedicalHistoryId, + Id = p4.Id + }; + public static MedicalHistoryAnswerSDto AdaptToSDto(this MedicalHistoryAnswer p5) + { + return p5 == null ? null : new MedicalHistoryAnswerSDto() + { + Answer = p5.Answer, + Question = p5.Question, + Part = p5.Part, + QuestionType = p5.QuestionType, + MedicalHistoryId = p5.MedicalHistoryId, + Id = p5.Id + }; + } + public static MedicalHistoryAnswerSDto AdaptTo(this MedicalHistoryAnswer p6, MedicalHistoryAnswerSDto p7) + { + if (p6 == null) + { + return null; + } + MedicalHistoryAnswerSDto result = p7 ?? new MedicalHistoryAnswerSDto(); + + result.Answer = p6.Answer; + result.Question = p6.Question; + result.Part = p6.Part; + result.QuestionType = p6.QuestionType; + result.MedicalHistoryId = p6.MedicalHistoryId; + result.Id = p6.Id; + return result; + + } + public static Expression> ProjectToSDto => p8 => new MedicalHistoryAnswerSDto() + { + Answer = p8.Answer, + Question = p8.Question, + Part = p8.Part, + QuestionType = p8.QuestionType, + MedicalHistoryId = p8.MedicalHistoryId, + Id = p8.Id + }; + } +} \ No newline at end of file diff --git a/DocuMed.Domain/Mappers/MedicalHistoryMapper.g.cs b/DocuMed.Domain/Mappers/MedicalHistoryMapper.g.cs new file mode 100644 index 0000000..2f98f28 --- /dev/null +++ b/DocuMed.Domain/Mappers/MedicalHistoryMapper.g.cs @@ -0,0 +1,508 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using DocuMed.Domain.Dtos.LargDtos; +using DocuMed.Domain.Dtos.SmallDtos; +using DocuMed.Domain.Entities.MedicalHistory; + +namespace DocuMed.Domain.Mappers +{ + public static partial class MedicalHistoryMapper + { + public static MedicalHistory AdaptToMedicalHistory(this MedicalHistorySDto p1) + { + return p1 == null ? null : new MedicalHistory() + { + ChiefComplaint = p1.ChiefComplaint, + Section = p1.Section, + 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, + FamilyHistoryDetail = p1.FamilyHistoryDetail, + AllergyDetail = p1.AllergyDetail, + DrugHistoryDetail = p1.DrugHistoryDetail, + AddictionHistoryDetail = p1.AddictionHistoryDetail, + SystemReviewDetail = p1.SystemReviewDetail, + VitalSignDetail = p1.VitalSignDetail, + SystolicBloodPressure = p1.SystolicBloodPressure, + DiastolicBloodPressure = p1.DiastolicBloodPressure, + PulseRate = p1.PulseRate, + SPO2 = p1.SPO2, + Temperature = p1.Temperature, + Id = p1.Id + }; + } + public static MedicalHistory AdaptTo(this MedicalHistorySDto p2, MedicalHistory p3) + { + if (p2 == null) + { + return null; + } + MedicalHistory result = p3 ?? new MedicalHistory(); + + result.ChiefComplaint = p2.ChiefComplaint; + result.Section = p2.Section; + result.FirstName = p2.FirstName; + result.LastName = p2.LastName; + result.FatherName = p2.FatherName; + result.NationalId = p2.NationalId; + result.Age = p2.Age; + result.BirthDate = p2.BirthDate; + result.PresentIllnessDetail = p2.PresentIllnessDetail; + result.PastDiseasesHistoryDetail = p2.PastDiseasesHistoryDetail; + result.PastSurgeryHistoryDetail = p2.PastSurgeryHistoryDetail; + result.FamilyHistoryDetail = p2.FamilyHistoryDetail; + result.AllergyDetail = p2.AllergyDetail; + result.DrugHistoryDetail = p2.DrugHistoryDetail; + result.AddictionHistoryDetail = p2.AddictionHistoryDetail; + result.SystemReviewDetail = p2.SystemReviewDetail; + result.VitalSignDetail = p2.VitalSignDetail; + result.SystolicBloodPressure = p2.SystolicBloodPressure; + result.DiastolicBloodPressure = p2.DiastolicBloodPressure; + result.PulseRate = p2.PulseRate; + result.SPO2 = p2.SPO2; + result.Temperature = p2.Temperature; + result.Id = p2.Id; + return result; + + } + public static Expression> ProjectToMedicalHistory => p4 => new MedicalHistory() + { + ChiefComplaint = p4.ChiefComplaint, + Section = p4.Section, + FirstName = p4.FirstName, + LastName = p4.LastName, + FatherName = p4.FatherName, + NationalId = p4.NationalId, + Age = p4.Age, + BirthDate = p4.BirthDate, + PresentIllnessDetail = p4.PresentIllnessDetail, + PastDiseasesHistoryDetail = p4.PastDiseasesHistoryDetail, + PastSurgeryHistoryDetail = p4.PastSurgeryHistoryDetail, + FamilyHistoryDetail = p4.FamilyHistoryDetail, + AllergyDetail = p4.AllergyDetail, + DrugHistoryDetail = p4.DrugHistoryDetail, + AddictionHistoryDetail = p4.AddictionHistoryDetail, + SystemReviewDetail = p4.SystemReviewDetail, + VitalSignDetail = p4.VitalSignDetail, + SystolicBloodPressure = p4.SystolicBloodPressure, + DiastolicBloodPressure = p4.DiastolicBloodPressure, + PulseRate = p4.PulseRate, + SPO2 = p4.SPO2, + Temperature = p4.Temperature, + Id = p4.Id + }; + public static MedicalHistorySDto AdaptToSDto(this MedicalHistory p5) + { + return p5 == null ? null : new MedicalHistorySDto() + { + ChiefComplaint = p5.ChiefComplaint, + Section = p5.Section, + FirstName = p5.FirstName, + LastName = p5.LastName, + FatherName = p5.FatherName, + NationalId = p5.NationalId, + Age = p5.Age, + BirthDate = p5.BirthDate, + PresentIllnessDetail = p5.PresentIllnessDetail, + PastDiseasesHistoryDetail = p5.PastDiseasesHistoryDetail, + PastSurgeryHistoryDetail = p5.PastSurgeryHistoryDetail, + FamilyHistoryDetail = p5.FamilyHistoryDetail, + AllergyDetail = p5.AllergyDetail, + DrugHistoryDetail = p5.DrugHistoryDetail, + AddictionHistoryDetail = p5.AddictionHistoryDetail, + SystemReviewDetail = p5.SystemReviewDetail, + VitalSignDetail = p5.VitalSignDetail, + SystolicBloodPressure = p5.SystolicBloodPressure, + DiastolicBloodPressure = p5.DiastolicBloodPressure, + PulseRate = p5.PulseRate, + SPO2 = p5.SPO2, + Temperature = p5.Temperature, + Id = p5.Id + }; + } + public static MedicalHistorySDto AdaptTo(this MedicalHistory p6, MedicalHistorySDto p7) + { + if (p6 == null) + { + return null; + } + MedicalHistorySDto result = p7 ?? new MedicalHistorySDto(); + + result.ChiefComplaint = p6.ChiefComplaint; + result.Section = p6.Section; + result.FirstName = p6.FirstName; + result.LastName = p6.LastName; + result.FatherName = p6.FatherName; + result.NationalId = p6.NationalId; + result.Age = p6.Age; + result.BirthDate = p6.BirthDate; + result.PresentIllnessDetail = p6.PresentIllnessDetail; + result.PastDiseasesHistoryDetail = p6.PastDiseasesHistoryDetail; + result.PastSurgeryHistoryDetail = p6.PastSurgeryHistoryDetail; + result.FamilyHistoryDetail = p6.FamilyHistoryDetail; + result.AllergyDetail = p6.AllergyDetail; + result.DrugHistoryDetail = p6.DrugHistoryDetail; + result.AddictionHistoryDetail = p6.AddictionHistoryDetail; + result.SystemReviewDetail = p6.SystemReviewDetail; + result.VitalSignDetail = p6.VitalSignDetail; + result.SystolicBloodPressure = p6.SystolicBloodPressure; + result.DiastolicBloodPressure = p6.DiastolicBloodPressure; + result.PulseRate = p6.PulseRate; + result.SPO2 = p6.SPO2; + result.Temperature = p6.Temperature; + result.Id = p6.Id; + return result; + + } + public static Expression> ProjectToSDto => p8 => new MedicalHistorySDto() + { + ChiefComplaint = p8.ChiefComplaint, + Section = p8.Section, + FirstName = p8.FirstName, + LastName = p8.LastName, + FatherName = p8.FatherName, + NationalId = p8.NationalId, + Age = p8.Age, + BirthDate = p8.BirthDate, + PresentIllnessDetail = p8.PresentIllnessDetail, + PastDiseasesHistoryDetail = p8.PastDiseasesHistoryDetail, + PastSurgeryHistoryDetail = p8.PastSurgeryHistoryDetail, + FamilyHistoryDetail = p8.FamilyHistoryDetail, + AllergyDetail = p8.AllergyDetail, + DrugHistoryDetail = p8.DrugHistoryDetail, + AddictionHistoryDetail = p8.AddictionHistoryDetail, + SystemReviewDetail = p8.SystemReviewDetail, + VitalSignDetail = p8.VitalSignDetail, + SystolicBloodPressure = p8.SystolicBloodPressure, + DiastolicBloodPressure = p8.DiastolicBloodPressure, + PulseRate = p8.PulseRate, + SPO2 = p8.SPO2, + Temperature = p8.Temperature, + Id = p8.Id + }; + public static MedicalHistory AdaptToMedicalHistory(this MedicalHistoryLDto p9) + { + return p9 == null ? null : new MedicalHistory() + { + ChiefComplaint = p9.ChiefComplaint, + Section = p9.Section, + 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, + FamilyHistoryDetail = p9.FamilyHistoryDetail, + AllergyDetail = p9.AllergyDetail, + DrugHistoryDetail = p9.DrugHistoryDetail, + AddictionHistoryDetail = p9.AddictionHistoryDetail, + SystemReviewDetail = p9.SystemReviewDetail, + VitalSignDetail = p9.VitalSignDetail, + SystolicBloodPressure = p9.SystolicBloodPressure, + DiastolicBloodPressure = p9.DiastolicBloodPressure, + PulseRate = p9.PulseRate, + SPO2 = p9.SPO2, + Temperature = p9.Temperature, + Answers = funcMain1(p9.Answers), + Id = p9.Id + }; + } + public static MedicalHistory AdaptTo(this MedicalHistoryLDto p11, MedicalHistory p12) + { + if (p11 == null) + { + return null; + } + MedicalHistory result = p12 ?? new MedicalHistory(); + + result.ChiefComplaint = p11.ChiefComplaint; + result.Section = p11.Section; + result.FirstName = p11.FirstName; + result.LastName = p11.LastName; + result.FatherName = p11.FatherName; + result.NationalId = p11.NationalId; + result.Age = p11.Age; + result.BirthDate = p11.BirthDate; + result.PresentIllnessDetail = p11.PresentIllnessDetail; + result.PastDiseasesHistoryDetail = p11.PastDiseasesHistoryDetail; + result.PastSurgeryHistoryDetail = p11.PastSurgeryHistoryDetail; + result.FamilyHistoryDetail = p11.FamilyHistoryDetail; + result.AllergyDetail = p11.AllergyDetail; + result.DrugHistoryDetail = p11.DrugHistoryDetail; + result.AddictionHistoryDetail = p11.AddictionHistoryDetail; + result.SystemReviewDetail = p11.SystemReviewDetail; + result.VitalSignDetail = p11.VitalSignDetail; + result.SystolicBloodPressure = p11.SystolicBloodPressure; + result.DiastolicBloodPressure = p11.DiastolicBloodPressure; + result.PulseRate = p11.PulseRate; + result.SPO2 = p11.SPO2; + result.Temperature = p11.Temperature; + result.Answers = funcMain2(p11.Answers, result.Answers); + result.Id = p11.Id; + return result; + + } + public static Expression> ProjectLDtoToMedicalHistory => p15 => new MedicalHistory() + { + ChiefComplaint = p15.ChiefComplaint, + Section = p15.Section, + FirstName = p15.FirstName, + LastName = p15.LastName, + FatherName = p15.FatherName, + NationalId = p15.NationalId, + Age = p15.Age, + BirthDate = p15.BirthDate, + PresentIllnessDetail = p15.PresentIllnessDetail, + PastDiseasesHistoryDetail = p15.PastDiseasesHistoryDetail, + PastSurgeryHistoryDetail = p15.PastSurgeryHistoryDetail, + FamilyHistoryDetail = p15.FamilyHistoryDetail, + AllergyDetail = p15.AllergyDetail, + DrugHistoryDetail = p15.DrugHistoryDetail, + AddictionHistoryDetail = p15.AddictionHistoryDetail, + SystemReviewDetail = p15.SystemReviewDetail, + VitalSignDetail = p15.VitalSignDetail, + SystolicBloodPressure = p15.SystolicBloodPressure, + DiastolicBloodPressure = p15.DiastolicBloodPressure, + PulseRate = p15.PulseRate, + SPO2 = p15.SPO2, + Temperature = p15.Temperature, + Answers = p15.Answers.Select(p16 => new MedicalHistoryAnswer() + { + Answer = p16.Answer, + Question = p16.Question, + Part = p16.Part, + QuestionType = p16.QuestionType, + MedicalHistoryId = p16.MedicalHistoryId, + Id = p16.Id + }).ToList(), + Id = p15.Id + }; + public static MedicalHistoryLDto AdaptToLDto(this MedicalHistory p17) + { + return p17 == null ? null : new MedicalHistoryLDto() + { + ChiefComplaint = p17.ChiefComplaint, + Section = p17.Section, + FirstName = p17.FirstName, + LastName = p17.LastName, + FatherName = p17.FatherName, + NationalId = p17.NationalId, + Age = p17.Age, + BirthDate = p17.BirthDate, + PresentIllnessDetail = p17.PresentIllnessDetail, + PastDiseasesHistoryDetail = p17.PastDiseasesHistoryDetail, + PastSurgeryHistoryDetail = p17.PastSurgeryHistoryDetail, + FamilyHistoryDetail = p17.FamilyHistoryDetail, + AllergyDetail = p17.AllergyDetail, + DrugHistoryDetail = p17.DrugHistoryDetail, + AddictionHistoryDetail = p17.AddictionHistoryDetail, + SystemReviewDetail = p17.SystemReviewDetail, + VitalSignDetail = p17.VitalSignDetail, + SystolicBloodPressure = p17.SystolicBloodPressure, + DiastolicBloodPressure = p17.DiastolicBloodPressure, + PulseRate = p17.PulseRate, + SPO2 = p17.SPO2, + Temperature = p17.Temperature, + Answers = funcMain3(p17.Answers), + Id = p17.Id + }; + } + public static MedicalHistoryLDto AdaptTo(this MedicalHistory p19, MedicalHistoryLDto p20) + { + if (p19 == null) + { + return null; + } + MedicalHistoryLDto result = p20 ?? new MedicalHistoryLDto(); + + result.ChiefComplaint = p19.ChiefComplaint; + result.Section = p19.Section; + result.FirstName = p19.FirstName; + result.LastName = p19.LastName; + result.FatherName = p19.FatherName; + result.NationalId = p19.NationalId; + result.Age = p19.Age; + result.BirthDate = p19.BirthDate; + result.PresentIllnessDetail = p19.PresentIllnessDetail; + result.PastDiseasesHistoryDetail = p19.PastDiseasesHistoryDetail; + result.PastSurgeryHistoryDetail = p19.PastSurgeryHistoryDetail; + result.FamilyHistoryDetail = p19.FamilyHistoryDetail; + result.AllergyDetail = p19.AllergyDetail; + result.DrugHistoryDetail = p19.DrugHistoryDetail; + result.AddictionHistoryDetail = p19.AddictionHistoryDetail; + result.SystemReviewDetail = p19.SystemReviewDetail; + result.VitalSignDetail = p19.VitalSignDetail; + result.SystolicBloodPressure = p19.SystolicBloodPressure; + result.DiastolicBloodPressure = p19.DiastolicBloodPressure; + result.PulseRate = p19.PulseRate; + result.SPO2 = p19.SPO2; + result.Temperature = p19.Temperature; + result.Answers = funcMain4(p19.Answers, result.Answers); + result.Id = p19.Id; + return result; + + } + public static Expression> ProjectToLDto => p23 => new MedicalHistoryLDto() + { + ChiefComplaint = p23.ChiefComplaint, + Section = p23.Section, + FirstName = p23.FirstName, + LastName = p23.LastName, + FatherName = p23.FatherName, + NationalId = p23.NationalId, + Age = p23.Age, + BirthDate = p23.BirthDate, + PresentIllnessDetail = p23.PresentIllnessDetail, + PastDiseasesHistoryDetail = p23.PastDiseasesHistoryDetail, + PastSurgeryHistoryDetail = p23.PastSurgeryHistoryDetail, + FamilyHistoryDetail = p23.FamilyHistoryDetail, + AllergyDetail = p23.AllergyDetail, + DrugHistoryDetail = p23.DrugHistoryDetail, + AddictionHistoryDetail = p23.AddictionHistoryDetail, + SystemReviewDetail = p23.SystemReviewDetail, + VitalSignDetail = p23.VitalSignDetail, + SystolicBloodPressure = p23.SystolicBloodPressure, + DiastolicBloodPressure = p23.DiastolicBloodPressure, + PulseRate = p23.PulseRate, + SPO2 = p23.SPO2, + Temperature = p23.Temperature, + Answers = p23.Answers.Select(p24 => new MedicalHistoryAnswerSDto() + { + Answer = p24.Answer, + Question = p24.Question, + Part = p24.Part, + QuestionType = p24.QuestionType, + MedicalHistoryId = p24.MedicalHistoryId, + Id = p24.Id + }).ToList(), + Id = p23.Id + }; + + private static List funcMain1(List p10) + { + if (p10 == null) + { + return null; + } + List result = new List(p10.Count); + + int i = 0; + int len = p10.Count; + + while (i < len) + { + MedicalHistoryAnswerSDto item = p10[i]; + result.Add(item == null ? null : new MedicalHistoryAnswer() + { + Answer = item.Answer, + Question = item.Question, + Part = item.Part, + QuestionType = item.QuestionType, + MedicalHistoryId = item.MedicalHistoryId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain2(List p13, List p14) + { + if (p13 == null) + { + return null; + } + List result = new List(p13.Count); + + int i = 0; + int len = p13.Count; + + while (i < len) + { + MedicalHistoryAnswerSDto item = p13[i]; + result.Add(item == null ? null : new MedicalHistoryAnswer() + { + Answer = item.Answer, + Question = item.Question, + Part = item.Part, + QuestionType = item.QuestionType, + MedicalHistoryId = item.MedicalHistoryId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain3(List p18) + { + if (p18 == null) + { + return null; + } + List result = new List(p18.Count); + + int i = 0; + int len = p18.Count; + + while (i < len) + { + MedicalHistoryAnswer item = p18[i]; + result.Add(item == null ? null : new MedicalHistoryAnswerSDto() + { + Answer = item.Answer, + Question = item.Question, + Part = item.Part, + QuestionType = item.QuestionType, + MedicalHistoryId = item.MedicalHistoryId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain4(List p21, List p22) + { + if (p21 == null) + { + return null; + } + List result = new List(p21.Count); + + int i = 0; + int len = p21.Count; + + while (i < len) + { + MedicalHistoryAnswer item = p21[i]; + result.Add(item == null ? null : new MedicalHistoryAnswerSDto() + { + Answer = item.Answer, + Question = item.Question, + Part = item.Part, + QuestionType = item.QuestionType, + MedicalHistoryId = item.MedicalHistoryId, + Id = item.Id + }); + i++; + } + return result; + + } + } +} \ No newline at end of file diff --git a/DocuMed.Domain/Mappers/MedicalHistoryQuestionMapper.g.cs b/DocuMed.Domain/Mappers/MedicalHistoryQuestionMapper.g.cs new file mode 100644 index 0000000..635d0ad --- /dev/null +++ b/DocuMed.Domain/Mappers/MedicalHistoryQuestionMapper.g.cs @@ -0,0 +1,81 @@ +using System; +using System.Linq.Expressions; +using DocuMed.Domain.Dtos.SmallDtos; +using DocuMed.Domain.Entities.MedicalHistoryTemplate; + +namespace DocuMed.Domain.Mappers +{ + public static partial class MedicalHistoryQuestionMapper + { + public static MedicalHistoryQuestion AdaptToMedicalHistoryQuestion(this MedicalHistoryQuestionSDto p1) + { + return p1 == null ? null : new MedicalHistoryQuestion() + { + Question = p1.Question, + Part = p1.Part, + QuestionType = p1.QuestionType, + MedicalHistoryTemplateId = p1.MedicalHistoryTemplateId, + Id = p1.Id + }; + } + public static MedicalHistoryQuestion AdaptTo(this MedicalHistoryQuestionSDto p2, MedicalHistoryQuestion p3) + { + if (p2 == null) + { + return null; + } + MedicalHistoryQuestion result = p3 ?? new MedicalHistoryQuestion(); + + result.Question = p2.Question; + result.Part = p2.Part; + result.QuestionType = p2.QuestionType; + result.MedicalHistoryTemplateId = p2.MedicalHistoryTemplateId; + result.Id = p2.Id; + return result; + + } + public static Expression> ProjectToMedicalHistoryQuestion => p4 => new MedicalHistoryQuestion() + { + Question = p4.Question, + Part = p4.Part, + QuestionType = p4.QuestionType, + MedicalHistoryTemplateId = p4.MedicalHistoryTemplateId, + Id = p4.Id + }; + public static MedicalHistoryQuestionSDto AdaptToSDto(this MedicalHistoryQuestion p5) + { + return p5 == null ? null : new MedicalHistoryQuestionSDto() + { + Question = p5.Question, + Part = p5.Part, + QuestionType = p5.QuestionType, + MedicalHistoryTemplateId = p5.MedicalHistoryTemplateId, + Id = p5.Id + }; + } + public static MedicalHistoryQuestionSDto AdaptTo(this MedicalHistoryQuestion p6, MedicalHistoryQuestionSDto p7) + { + if (p6 == null) + { + return null; + } + MedicalHistoryQuestionSDto result = p7 ?? new MedicalHistoryQuestionSDto(); + + result.Question = p6.Question; + result.Part = p6.Part; + result.QuestionType = p6.QuestionType; + result.MedicalHistoryTemplateId = p6.MedicalHistoryTemplateId; + result.Id = p6.Id; + return result; + + } + public static Expression> ProjectToSDto => p8 => new MedicalHistoryQuestionSDto() + { + Question = p8.Question, + Part = p8.Part, + QuestionType = p8.QuestionType, + MedicalHistoryTemplateId = p8.MedicalHistoryTemplateId, + Id = p8.Id + }; + } +} \ No newline at end of file diff --git a/DocuMed.Domain/Mappers/MedicalHistoryTemplateMapper.g.cs b/DocuMed.Domain/Mappers/MedicalHistoryTemplateMapper.g.cs new file mode 100644 index 0000000..56f5c75 --- /dev/null +++ b/DocuMed.Domain/Mappers/MedicalHistoryTemplateMapper.g.cs @@ -0,0 +1,250 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using DocuMed.Domain.Dtos.LargDtos; +using DocuMed.Domain.Dtos.SmallDtos; +using DocuMed.Domain.Entities.MedicalHistoryTemplate; + +namespace DocuMed.Domain.Mappers +{ + public static partial class MedicalHistoryTemplateMapper + { + public static MedicalHistoryTemplate AdaptToMedicalHistoryTemplate(this MedicalHistoryTemplateSDto p1) + { + return p1 == null ? null : new MedicalHistoryTemplate() + { + ChiefComplaint = p1.ChiefComplaint, + Id = p1.Id + }; + } + public static MedicalHistoryTemplate AdaptTo(this MedicalHistoryTemplateSDto p2, MedicalHistoryTemplate p3) + { + if (p2 == null) + { + return null; + } + MedicalHistoryTemplate result = p3 ?? new MedicalHistoryTemplate(); + + result.ChiefComplaint = p2.ChiefComplaint; + result.Id = p2.Id; + return result; + + } + public static Expression> ProjectToMedicalHistoryTemplate => p4 => new MedicalHistoryTemplate() + { + ChiefComplaint = p4.ChiefComplaint, + Id = p4.Id + }; + public static MedicalHistoryTemplateSDto AdaptToSDto(this MedicalHistoryTemplate p5) + { + return p5 == null ? null : new MedicalHistoryTemplateSDto() + { + ChiefComplaint = p5.ChiefComplaint, + Id = p5.Id + }; + } + public static MedicalHistoryTemplateSDto AdaptTo(this MedicalHistoryTemplate p6, MedicalHistoryTemplateSDto p7) + { + if (p6 == null) + { + return null; + } + MedicalHistoryTemplateSDto result = p7 ?? new MedicalHistoryTemplateSDto(); + + result.ChiefComplaint = p6.ChiefComplaint; + result.Id = p6.Id; + return result; + + } + public static Expression> ProjectToSDto => p8 => new MedicalHistoryTemplateSDto() + { + ChiefComplaint = p8.ChiefComplaint, + Id = p8.Id + }; + public static MedicalHistoryTemplate AdaptToMedicalHistoryTemplate(this MedicalHistoryTemplateLDto p9) + { + return p9 == null ? null : new MedicalHistoryTemplate() + { + ChiefComplaint = p9.ChiefComplaint, + Questions = funcMain1(p9.Questions), + Id = p9.Id + }; + } + public static MedicalHistoryTemplate AdaptTo(this MedicalHistoryTemplateLDto p11, MedicalHistoryTemplate p12) + { + if (p11 == null) + { + return null; + } + MedicalHistoryTemplate result = p12 ?? new MedicalHistoryTemplate(); + + result.ChiefComplaint = p11.ChiefComplaint; + result.Questions = funcMain2(p11.Questions, result.Questions); + result.Id = p11.Id; + return result; + + } + public static Expression> ProjectLDtoToMedicalHistoryTemplate => p15 => new MedicalHistoryTemplate() + { + ChiefComplaint = p15.ChiefComplaint, + Questions = p15.Questions.Select(p16 => new MedicalHistoryQuestion() + { + Question = p16.Question, + Part = p16.Part, + QuestionType = p16.QuestionType, + MedicalHistoryTemplateId = p16.MedicalHistoryTemplateId, + Id = p16.Id + }).ToList(), + Id = p15.Id + }; + public static MedicalHistoryTemplateLDto AdaptToLDto(this MedicalHistoryTemplate p17) + { + return p17 == null ? null : new MedicalHistoryTemplateLDto() + { + ChiefComplaint = p17.ChiefComplaint, + Questions = funcMain3(p17.Questions), + Id = p17.Id + }; + } + public static MedicalHistoryTemplateLDto AdaptTo(this MedicalHistoryTemplate p19, MedicalHistoryTemplateLDto p20) + { + if (p19 == null) + { + return null; + } + MedicalHistoryTemplateLDto result = p20 ?? new MedicalHistoryTemplateLDto(); + + result.ChiefComplaint = p19.ChiefComplaint; + result.Questions = funcMain4(p19.Questions, result.Questions); + result.Id = p19.Id; + return result; + + } + public static Expression> ProjectToLDto => p23 => new MedicalHistoryTemplateLDto() + { + ChiefComplaint = p23.ChiefComplaint, + Questions = p23.Questions.Select(p24 => new MedicalHistoryQuestionSDto() + { + Question = p24.Question, + Part = p24.Part, + QuestionType = p24.QuestionType, + MedicalHistoryTemplateId = p24.MedicalHistoryTemplateId, + Id = p24.Id + }).ToList(), + Id = p23.Id + }; + + private static List funcMain1(List p10) + { + if (p10 == null) + { + return null; + } + List result = new List(p10.Count); + + int i = 0; + int len = p10.Count; + + while (i < len) + { + MedicalHistoryQuestionSDto item = p10[i]; + result.Add(item == null ? null : new MedicalHistoryQuestion() + { + Question = item.Question, + Part = item.Part, + QuestionType = item.QuestionType, + MedicalHistoryTemplateId = item.MedicalHistoryTemplateId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain2(List p13, List p14) + { + if (p13 == null) + { + return null; + } + List result = new List(p13.Count); + + int i = 0; + int len = p13.Count; + + while (i < len) + { + MedicalHistoryQuestionSDto item = p13[i]; + result.Add(item == null ? null : new MedicalHistoryQuestion() + { + Question = item.Question, + Part = item.Part, + QuestionType = item.QuestionType, + MedicalHistoryTemplateId = item.MedicalHistoryTemplateId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain3(List p18) + { + if (p18 == null) + { + return null; + } + List result = new List(p18.Count); + + int i = 0; + int len = p18.Count; + + while (i < len) + { + MedicalHistoryQuestion item = p18[i]; + result.Add(item == null ? null : new MedicalHistoryQuestionSDto() + { + Question = item.Question, + Part = item.Part, + QuestionType = item.QuestionType, + MedicalHistoryTemplateId = item.MedicalHistoryTemplateId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain4(List p21, List p22) + { + if (p21 == null) + { + return null; + } + List result = new List(p21.Count); + + int i = 0; + int len = p21.Count; + + while (i < len) + { + MedicalHistoryQuestion item = p21[i]; + result.Add(item == null ? null : new MedicalHistoryQuestionSDto() + { + Question = item.Question, + Part = item.Part, + QuestionType = item.QuestionType, + MedicalHistoryTemplateId = item.MedicalHistoryTemplateId, + Id = item.Id + }); + i++; + } + return result; + + } + } +} \ No newline at end of file diff --git a/DocuMed.Domain/Mappers/PatientMapper.g.cs b/DocuMed.Domain/Mappers/PatientMapper.g.cs new file mode 100644 index 0000000..c9be374 --- /dev/null +++ b/DocuMed.Domain/Mappers/PatientMapper.g.cs @@ -0,0 +1,6 @@ +namespace DocuMed.Domain.Mappers +{ + public static partial class PatientMapper + { + } +} \ No newline at end of file diff --git a/DocuMed.Infrastructure/DocuMed.Infrastructure.csproj b/DocuMed.Infrastructure/DocuMed.Infrastructure.csproj index 67ba8d5..50f3b4d 100644 --- a/DocuMed.Infrastructure/DocuMed.Infrastructure.csproj +++ b/DocuMed.Infrastructure/DocuMed.Infrastructure.csproj @@ -15,7 +15,23 @@ - + + + + + + + + + + + + + + + + + diff --git a/DocuMed.Infrastructure/Models/RestAddress.cs b/DocuMed.Infrastructure/Models/RestAddress.cs new file mode 100644 index 0000000..e3e5db4 --- /dev/null +++ b/DocuMed.Infrastructure/Models/RestAddress.cs @@ -0,0 +1,6 @@ +namespace DocuMed.Infrastructure.Models; + +public static class RestAddress +{ + public static string BaseKaveNegar { get => "https://api.kavenegar.com/v1/"; } +} \ No newline at end of file diff --git a/DocuMed.Infrastructure/Models/RestApi/KaveNegar/KaveNegarResponse.cs b/DocuMed.Infrastructure/Models/RestApi/KaveNegar/KaveNegarResponse.cs new file mode 100644 index 0000000..c0da1fd --- /dev/null +++ b/DocuMed.Infrastructure/Models/RestApi/KaveNegar/KaveNegarResponse.cs @@ -0,0 +1,7 @@ +namespace DocuMed.Infrastructure.Models.RestApi.KaveNegar; + +public class KaveNegarResponse +{ + public KaveNegarReturn? Return { get; set; } + public KaveNegarResponseEntry[] entries { get; set; } +} \ No newline at end of file diff --git a/DocuMed.Infrastructure/Models/RestApi/KaveNegar/KaveNegarResponseEntry.cs b/DocuMed.Infrastructure/Models/RestApi/KaveNegar/KaveNegarResponseEntry.cs new file mode 100644 index 0000000..301bae7 --- /dev/null +++ b/DocuMed.Infrastructure/Models/RestApi/KaveNegar/KaveNegarResponseEntry.cs @@ -0,0 +1,13 @@ +namespace DocuMed.Infrastructure.Models.RestApi.KaveNegar; + +public class KaveNegarResponseEntry +{ + public int messageid { get; set; } + public string message { get; set; } + public int status { get; set; } + public string statustext { get; set; } + public string sender { get; set; } + public string receptor { get; set; } + public int date { get; set; } + public int cost { get; set; } +} \ No newline at end of file diff --git a/DocuMed.Infrastructure/Models/RestApi/KaveNegar/KaveNegarReturn.cs b/DocuMed.Infrastructure/Models/RestApi/KaveNegar/KaveNegarReturn.cs new file mode 100644 index 0000000..4cb33fd --- /dev/null +++ b/DocuMed.Infrastructure/Models/RestApi/KaveNegar/KaveNegarReturn.cs @@ -0,0 +1,7 @@ +namespace DocuMed.Infrastructure.Models.RestApi.KaveNegar; + +public class KaveNegarReturn +{ + public int status { get; set; } + public string message { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/DocuMed.Infrastructure/RestServices/IKaveNegarRestApi.cs b/DocuMed.Infrastructure/RestServices/IKaveNegarRestApi.cs new file mode 100644 index 0000000..37b39c3 --- /dev/null +++ b/DocuMed.Infrastructure/RestServices/IKaveNegarRestApi.cs @@ -0,0 +1,10 @@ +namespace DocuMed.Infrastructure.RestServices; + +public interface IKaveNegarRestApi +{ + + [Post("/{apiKey}/verify/lookup.json")] + Task SendLookUp(string apiKey, [Query] string receptor, [Query] string token, [Query] string token2, [Query] string token10, [Query] string token20, [Query] string template); + [Post("/{apiKey}/sms/send.json")] + Task SendSms(string apiKey, [Query] string receptor, [Query] string message, [Query] string sender); +} \ No newline at end of file diff --git a/DocuMed.Infrastructure/RestServices/RestApiWrapper.cs b/DocuMed.Infrastructure/RestServices/RestApiWrapper.cs new file mode 100644 index 0000000..e55ceae --- /dev/null +++ b/DocuMed.Infrastructure/RestServices/RestApiWrapper.cs @@ -0,0 +1,11 @@ +namespace DocuMed.Infrastructure.RestServices; + +public interface IRestApiWrapper : IScopedDependency +{ + IKaveNegarRestApi KaveNegarRestApi { get; } +} + +public class RestApiWrapper : IRestApiWrapper +{ + public IKaveNegarRestApi KaveNegarRestApi => RestService.For(RestAddress.BaseKaveNegar); +} \ No newline at end of file diff --git a/DocuMed.Infrastructure/Services/SmsService.cs b/DocuMed.Infrastructure/Services/SmsService.cs new file mode 100644 index 0000000..76c576b --- /dev/null +++ b/DocuMed.Infrastructure/Services/SmsService.cs @@ -0,0 +1,34 @@ +namespace DocuMed.Infrastructure.Services; + + +public class SmsService : ISmsService +{ + private readonly IRestApiWrapper _restApiWrapper; + private readonly ILogger _logger; + private readonly SiteSettings _siteSettings; + public SmsService(IRestApiWrapper restApiWrapper, + IOptionsSnapshot optionsSnapshot, + ILogger logger) + { + _restApiWrapper = restApiWrapper; + _logger = logger; + _siteSettings = optionsSnapshot.Value; + } + public async Task SendForgerPasswordAsync(string phoneNumber, string newPassword) + { + var rest = await _restApiWrapper.KaveNegarRestApi.SendLookUp(_siteSettings.KaveNegarApiKey, phoneNumber, newPassword, null, null, null, "forgetPassword"); + + if (rest.Return?.status != 200) + throw new BaseApiException(ApiResultStatusCode.SendSmsError, rest.Return?.message); + } + + public async Task SendVerifyCodeAsync(string phoneNumber, string verifyCode) + { + + var rest = await _restApiWrapper.KaveNegarRestApi.SendLookUp(_siteSettings.KaveNegarApiKey, phoneNumber, verifyCode, null, null, null, "login"); + + if (rest.Return?.status != 200) + throw new BaseApiException(ApiResultStatusCode.SendSmsError, rest.Return?.message); + } + +} \ No newline at end of file diff --git a/DocuMed.Repository/Abstracts/ICurrentUserService.cs b/DocuMed.Repository/Abstracts/ICurrentUserService.cs index 3cdc638..121b0f1 100644 --- a/DocuMed.Repository/Abstracts/ICurrentUserService.cs +++ b/DocuMed.Repository/Abstracts/ICurrentUserService.cs @@ -5,4 +5,5 @@ public interface ICurrentUserService : IScopedDependency string? UserId { get; } string? RoleName { get; } string? UserName { get; } + string? UniversityId { get; } } \ No newline at end of file diff --git a/DocuMed.sln b/DocuMed.sln index 52c8a7b..904d329 100644 --- a/DocuMed.sln +++ b/DocuMed.sln @@ -5,17 +5,17 @@ VisualStudioVersion = 17.7.34024.191 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocuMed.PWA", "DocuMed.PWA\DocuMed.PWA.csproj", "{062950CA-0B06-4924-8C43-90C72455B306}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocuMed.Api", "DocuMed.Api\DocuMed.Api.csproj", "{BEA3A628-15E5-4733-851D-37E3C8B13169}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocuMed.Api", "DocuMed.Api\DocuMed.Api.csproj", "{BEA3A628-15E5-4733-851D-37E3C8B13169}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocuMed.Common", "DocuMed.Common\DocuMed.Common.csproj", "{4A71B4B9-5D7C-4DE9-ADB9-16D23B6771AA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocuMed.Common", "DocuMed.Common\DocuMed.Common.csproj", "{4A71B4B9-5D7C-4DE9-ADB9-16D23B6771AA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocuMed.Core", "DocuMed.Core\DocuMed.Core.csproj", "{4FA77EEF-B056-4E65-AE55-FBA540AF6507}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocuMed.Core", "DocuMed.Core\DocuMed.Core.csproj", "{4FA77EEF-B056-4E65-AE55-FBA540AF6507}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocuMed.Repository", "DocuMed.Repository\DocuMed.Repository.csproj", "{8A4FA109-04B2-46B1-93F6-CFFE65B47DDB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocuMed.Repository", "DocuMed.Repository\DocuMed.Repository.csproj", "{8A4FA109-04B2-46B1-93F6-CFFE65B47DDB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocuMed.Domain", "DocuMed.Domain\DocuMed.Domain.csproj", "{3E36917E-3888-43A4-846C-6C04542FE209}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocuMed.Domain", "DocuMed.Domain\DocuMed.Domain.csproj", "{3E36917E-3888-43A4-846C-6C04542FE209}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocuMed.Infrastructure", "DocuMed.Infrastructure\DocuMed.Infrastructure.csproj", "{A29B5D57-EC19-4E56-A92A-CCAAC10F1493}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocuMed.Infrastructure", "DocuMed.Infrastructure\DocuMed.Infrastructure.csproj", "{A29B5D57-EC19-4E56-A92A-CCAAC10F1493}" EndProject Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{AE900A14-3A2E-4792-B7EF-641A1E60D345}" EndProject diff --git a/docker-compose.yml b/docker-compose.yml index 27939af..b695527 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,37 @@ version: '3.4' + +networks: + dockerapi-dev: + driver: bridge + + services: documed.api: - image: ${DOCKER_REGISTRY-}documedapi + image: documedapi:latest + depends_on: + - "postgres_image" build: context: . dockerfile: DocuMed.Api/Dockerfile + ports: + - "5288:80" + networks: + - dockerapi-dev + + postgres_image: + image: postgres:latest + ports: + - "5432" + restart: always + volumes: + - db:/var/lib/postgresql/data + environment: + POSTGRES_USER: "brizcouser" + POSTGRES_PASSWORD: "brizco" + POSTGRES_DB: "BrizCoDB" + networks: + - dockerapi-dev +volumes: + db: + driver: local