From 39acbb7f953a86fc256a0bf762b8e17e3343f00e Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 25 Dec 2024 10:21:31 +0700 Subject: [PATCH] no message --- .../Repositories/InsigniaPeriodsRepository.cs | 34 ++++++- BMA.EHR.Insignia/appsettings.json | 20 ++-- .../Controllers/MainController.cs | 97 +++++++++++++++++++ BMA.EHR.MetaData.Service/Program.cs | 8 ++ .../Services/BloodGroupService.cs | 92 ++++++++++++++++++ .../Services/EducationLevelService.cs | 90 +++++++++++++++++ .../Services/GenderService.cs | 90 +++++++++++++++++ .../Services/PrefixService.cs | 90 +++++++++++++++++ .../Services/ProvinceService.cs | 93 ++++++++++++++++++ .../Services/RelationshipService.cs | 89 +++++++++++++++++ .../Services/ReligionService.cs | 90 +++++++++++++++++ 11 files changed, 780 insertions(+), 13 deletions(-) create mode 100644 BMA.EHR.MetaData.Service/Controllers/MainController.cs create mode 100644 BMA.EHR.MetaData.Service/Services/BloodGroupService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/EducationLevelService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/GenderService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/PrefixService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/ProvinceService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/RelationshipService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/ReligionService.cs diff --git a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs index 7edb2d48..d2cb59ac 100644 --- a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs +++ b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs @@ -87,8 +87,8 @@ namespace BMA.EHR.Application.Repositories Id = i.Id, Name = i.Name, ShortName = i.ShortName, - Level = i.InsigniaType.Name, - LevelId = i.InsigniaType.Id + Level = i.InsigniaType?.Name ?? "", + LevelId = i.InsigniaType?.Id ?? null }) .FirstOrDefault(); @@ -6531,24 +6531,39 @@ namespace BMA.EHR.Application.Repositories (await _userProfileRepository.GetOfficerProfileByRootIdAsync(ocId, AccessToken)); //var allEmployeeProfileByRoot = // (await _userProfileRepository.GetEmployeeProfileByRootIdAsync(ocId, AccessToken)); - + Console.WriteLine("111111"); var type_coin = await GetCoinCandidate(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("111112"); var type1_level1 = await GetInsigniaCandidate_Type1_Level1(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("111113"); var type1_level2 = await GetInsigniaCandidate_Type1_Level2(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("111114"); var type1_level3 = await GetInsigniaCandidate_Type1_Level3(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("111115"); var type1_level4 = await GetInsigniaCandidate_Type1_Level4(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("111116"); var type2_level5 = await GetInsigniaCandidate_Type2_Level5(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("111117"); var type2_level6 = await GetInsigniaCandidate_Type2_Level6(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("111118"); var type2_level7 = await GetInsigniaCandidate_Type2_Level7(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("111119"); var type2_level8 = await GetInsigniaCandidate_Type2_Level8(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("111110"); var type2_level9_1 = await GetInsigniaCandidate_Type2_Level9_1(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("1111111"); var type2_level9_2 = await GetInsigniaCandidate_Type2_Level9_2(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("1111112"); var type3_level10 = await GetInsigniaCandidate_Type3_Level10(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("1111113"); var type3_level11 = await GetInsigniaCandidate_Type3_Level11(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("1111114"); var type4_level10 = await GetInsigniaCandidate_Type4_Level10(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("1111115"); var type4_level11 = await GetInsigniaCandidate_Type4_Level11(periodId, ocId, allOfficerProfilesByRoot); + Console.WriteLine("1111116"); // union result foreach (var r in type_coin) @@ -6693,11 +6708,14 @@ namespace BMA.EHR.Application.Repositories { try { + Console.WriteLine("2222222"); var period = await _dbContext.Set().FirstOrDefaultAsync(p => p.Id == periodId); + Console.WriteLine("22222221"); if (period == null) throw new Exception(GlobalMessages.CoinPeriodNotFound); + Console.WriteLine("22222223"); var inst_profile = allProfilesByRoot.Where(x => x.DateAppoint != null) .Select(p => new { @@ -6743,6 +6761,8 @@ namespace BMA.EHR.Application.Repositories PositionSalaryAmount = p.PositionSalaryAmount, }); + Console.WriteLine("22222224"); + Console.WriteLine(JsonConvert.SerializeObject(inst_profile)); // check วันที่บรรจะต้องมากกว่า 25 ปี var result = ((from p in inst_profile where p.ProfileDateAppoint <= new DateTime(period.Year - 25, 5, 29) @@ -6774,25 +6794,33 @@ namespace BMA.EHR.Application.Repositories MatchingConditions = new List(), })).ToList(); + Console.WriteLine("22222225"); var result_candidate = new List(); + Console.WriteLine("22222226"); foreach (var r in result) { + Console.WriteLine("22222228"); var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + Console.WriteLine("22222220"); // Check ได้รับหรือเคยยื่นขอไปในปีที่แล้วหรือไม่? if (!CanRequestInsignia(r.ProfileId, period.Year)) continue; + Console.WriteLine("22222229"); // Check ว่าชั้นที่ขอสูงกว่าชั้นที่เคยได้รับแล้วหรือไม่? if (!IsHigherLevel2(r.LastInsignia, r.RequestInsignia.Name)) continue; + Console.WriteLine("222222212"); if (old == null) { result_candidate.Add(r); } + Console.WriteLine("222222243"); } + Console.WriteLine("22222227"); return result_candidate; } diff --git a/BMA.EHR.Insignia/appsettings.json b/BMA.EHR.Insignia/appsettings.json index 18131c5b..b46a9934 100644 --- a/BMA.EHR.Insignia/appsettings.json +++ b/BMA.EHR.Insignia/appsettings.json @@ -14,16 +14,16 @@ "AllowedHosts": "*", "ConnectionStrings": { //"DefaultConnection": "User Id=sys;Password=P@ssw0rd;DBA Privilege=SYSDBA;Data Source=localhost:1521/ORCLCDB", - //"DefaultConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" - //"DefaultConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", - "DefaultConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", - "ExamConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_exam_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", - "LeaveConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_leave_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", - "DisciplineConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_discipline_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" + //"DefaultConnection": "server=192.168.1.9;user=root;password=adminVM123;port=53636;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" + //"DefaultConnection": "server=hrms.chin.in.th;user=root;password=adminVM123;port=53636;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", + "DefaultConnection": "server=hrms.chin.in.th;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=53636;database=hrms;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", + "ExamConnection": "server=hrms.chin.in.th;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=53636;database=hrms_exam;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", + "LeaveConnection": "server=hrms.chin.in.th;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=53636;database=hrms_leave;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", + "DisciplineConnection": "server=hrms.chin.in.th;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=53636;database=hrms_discipline;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" }, "Jwt": { - "Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI", - "Issuer": "https://id.frappet.synology.me/realms/bma-ehr" + "Key": "j7C9RO_p4nRtuwCH4z9Db_A_6We42tkD_p4lZtDrezc", + "Issuer": "https://hrms-id.chin.in.th/realms/hrms" }, "EPPlus": { "ExcelPackage": { @@ -42,9 +42,9 @@ }, "Protocol": "HTTPS", "Node": { - "API": "https://bma-ehr.frappet.synology.me/api/v1/probation" + "API": "https://hrms.chin.in.th/api/v1/probation" }, - "API": "https://bma-ehr.frappet.synology.me/api/v1", + "API": "https://hrms.chin.in.th/api/v1", "RabbitMQ": { "URL": "localhost", "UserName": "frappet", diff --git a/BMA.EHR.MetaData.Service/Controllers/MainController.cs b/BMA.EHR.MetaData.Service/Controllers/MainController.cs new file mode 100644 index 00000000..27a5cecd --- /dev/null +++ b/BMA.EHR.MetaData.Service/Controllers/MainController.cs @@ -0,0 +1,97 @@ +using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Models.MetaData; +using BMA.EHR.MetaData.Service.Request; +using BMA.EHR.MetaData.Service.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; + +namespace BMA.EHR.MetaData.Service.Controllers +{ + [Route("api/v{version:apiVersion}/metadata/main")] + [ApiVersion("1.0")] + [ApiController] + [Produces("application/json")] + [Authorize] + [SwaggerTag("จัดการข้อมูลตำแหน่ง เพื่อนำไปใช้งานในระบบ")] + public class MainController : BaseController + { + #region " Fields " + + private readonly BloodGroupService _bloodGroupService; + private readonly EducationLevelService _educationLevelService; + private readonly GenderService _genderService; + private readonly ProvinceService _provinceService; + private readonly PrefixService _prefixService; + private readonly RelationshipService _relationshipService; + private readonly ReligionService _religionService; + + #endregion + + #region " Constructor and Destructor " + + public MainController( + BloodGroupService bloodGroupService, + ProvinceService provinceService, + EducationLevelService educationLevelService, + GenderService genderService, + PrefixService prefixService, + RelationshipService relationshipService, + ReligionService religionService) + { + _bloodGroupService = bloodGroupService; + _provinceService = provinceService; + _educationLevelService = educationLevelService; + _genderService = genderService; + _prefixService = prefixService; + _relationshipService = relationshipService; + _religionService = religionService; + } + + #endregion + + #region " Methods " + + /// + /// อ่านข้อมูล ข้อมูลเกี่ยวกับบุคคล + /// + /// + /// อ่านข้อมูล ข้อมูลเกี่ยวกับบุคคล สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("person")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsMainPersonAsync() + { + try + { + var bloodGroups = await _bloodGroupService.GetsAsync(showAll: false); + var provinces = await _provinceService.GetsAsync(showAll: false); + var educationLevels = await _educationLevelService.GetsAsync(showAll: false); + var genders = await _genderService.GetsAsync(showAll: false); + var prefixs = await _prefixService.GetsAsync(showAll: false); + var relationships = await _relationshipService.GetsAsync(showAll: false); + var religions = await _religionService.GetsAsync(showAll: false); + + return Success(new + { + bloodGroups, + provinces, + educationLevels, + genders, + prefixs, + relationships, + religions, + }); + } + catch (Exception ex) + { + return Error(ex); + } + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Program.cs b/BMA.EHR.MetaData.Service/Program.cs index 7a34cf83..6032b868 100644 --- a/BMA.EHR.MetaData.Service/Program.cs +++ b/BMA.EHR.MetaData.Service/Program.cs @@ -89,6 +89,14 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); + + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); builder.Services.AddControllers(options => { options.SuppressAsyncSuffixInActionNames = false; diff --git a/BMA.EHR.MetaData.Service/Services/BloodGroupService.cs b/BMA.EHR.MetaData.Service/Services/BloodGroupService.cs new file mode 100644 index 00000000..8a689920 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/BloodGroupService.cs @@ -0,0 +1,92 @@ +using BMA.EHR.Domain.Models.MetaData; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using System.Security.Claims; + +namespace BMA.EHR.MetaData.Service.Services +{ + public class BloodGroupService + { + #region " Fields " + + private readonly ApplicationDBContext _context; + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly ILogger _logger; + + #endregion + + #region " Constructor and Destructor " + + public BloodGroupService(ApplicationDBContext context, + IHttpContextAccessor httpContextAccessor, + ILogger logger) + { + _context = context; + _httpContextAccessor = httpContextAccessor; + _logger = logger; + } + + #endregion + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + #endregion + + #region " Methods " + + public async Task> GetsAsync(bool showAll = true) + { + if (showAll) + return await _context.BloodGroups.AsQueryable() + .OrderBy(d => d.Name) + .ToListAsync(); + else + return await _context.BloodGroups.AsQueryable() + .Where(p => p.IsActive) + .OrderBy(d => d.Name) + .ToListAsync(); + } + + public async Task GetByIdAsync(Guid id) + { + return await _context.BloodGroups.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task UpdateAsync(Guid id, BloodGroup updated) + { + var existData = await _context.BloodGroups.FirstOrDefaultAsync(x => x.Id == id); + if (existData != null) + { + if (existData.Name != updated.Name || existData.IsActive != updated.IsActive) + { + existData.Name = updated.Name; + existData.IsActive = updated.IsActive; + existData.LastUpdatedAt = DateTime.Now; + existData.LastUpdateUserId = UserId ?? ""; + existData.LastUpdateFullName = FullName ?? ""; + } + await _context.SaveChangesAsync(); + } + } + + public async Task CreateAsync(BloodGroup inserted) + { + inserted.CreatedUserId = UserId ?? ""; + inserted.CreatedFullName = FullName ?? "System Administrator"; + inserted.CreatedAt = DateTime.Now; + inserted.LastUpdatedAt = DateTime.Now; + inserted.LastUpdateFullName = FullName ?? "System Administrator"; + inserted.LastUpdateUserId = UserId ?? ""; + + await _context.BloodGroups.AddAsync(inserted); + + await _context.SaveChangesAsync(); + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Services/EducationLevelService.cs b/BMA.EHR.MetaData.Service/Services/EducationLevelService.cs new file mode 100644 index 00000000..ac034480 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/EducationLevelService.cs @@ -0,0 +1,90 @@ +using BMA.EHR.Domain.Models.MetaData; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using System.Security.Claims; + + +namespace BMA.EHR.MetaData.Service.Services +{ + public class EducationLevelService + { + #region " Fields " + + private readonly ApplicationDBContext _context; + private readonly IHttpContextAccessor _httpContextAccessor; + + #endregion + + #region " Constructor and Destructor " + + public EducationLevelService(ApplicationDBContext context, + IHttpContextAccessor httpContextAccessor) + { + _context = context; + _httpContextAccessor = httpContextAccessor; + } + + #endregion + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + #endregion + + #region " Methods " + + public async Task> GetsAsync(bool showAll = true) + { + if (showAll) + return await _context.EducationLevels.AsQueryable() + .OrderBy(d => d.Name) + .ToListAsync(); + else + return await _context.EducationLevels.AsQueryable() + .Where(p => p.IsActive) + .OrderBy(d => d.Name) + .ToListAsync(); + } + + public async Task GetByIdAsync(Guid id) + { + return await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task UpdateAsync(Guid id, EducationLevel updated) + { + var existData = await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == id); + if (existData != null) + { + if (existData.Name != updated.Name || existData.IsActive != updated.IsActive) + { + existData.Name = updated.Name; + existData.IsActive = updated.IsActive; + existData.LastUpdatedAt = DateTime.Now; + existData.LastUpdateUserId = UserId ?? ""; + existData.LastUpdateFullName = FullName ?? ""; + } + await _context.SaveChangesAsync(); + } + } + + public async Task CreateAsync(EducationLevel inserted) + { + inserted.CreatedUserId = UserId ?? ""; + inserted.CreatedFullName = FullName ?? "System Administrator"; + inserted.CreatedAt = DateTime.Now; + inserted.LastUpdatedAt = DateTime.Now; + inserted.LastUpdateFullName = FullName ?? "System Administrator"; + inserted.LastUpdateUserId = UserId ?? ""; + + await _context.EducationLevels.AddAsync(inserted); + + await _context.SaveChangesAsync(); + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Services/GenderService.cs b/BMA.EHR.MetaData.Service/Services/GenderService.cs new file mode 100644 index 00000000..59588160 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/GenderService.cs @@ -0,0 +1,90 @@ +using BMA.EHR.Domain.Models.MetaData; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using System.Security.Claims; + + +namespace BMA.EHR.MetaData.Service.Services +{ + public class GenderService + { + #region " Fields " + + private readonly ApplicationDBContext _context; + private readonly IHttpContextAccessor _httpContextAccessor; + + #endregion + + #region " Constructor and Destructor " + + public GenderService(ApplicationDBContext context, + IHttpContextAccessor httpContextAccessor) + { + _context = context; + _httpContextAccessor = httpContextAccessor; + } + + #endregion + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + #endregion + + #region " Methods " + + public async Task> GetsAsync(bool showAll = true) + { + if (showAll) + return await _context.Genders.AsQueryable() + .OrderBy(d => d.Name) + .ToListAsync(); + else + return await _context.Genders.AsQueryable() + .Where(p => p.IsActive) + .OrderBy(d => d.Name) + .ToListAsync(); + } + + public async Task GetByIdAsync(Guid id) + { + return await _context.Genders.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task UpdateAsync(Guid id, Gender updated) + { + var existData = await _context.Genders.FirstOrDefaultAsync(x => x.Id == id); + if (existData != null) + { + if (existData.Name != updated.Name || existData.IsActive != updated.IsActive) + { + existData.Name = updated.Name; + existData.IsActive = updated.IsActive; + existData.LastUpdatedAt = DateTime.Now; + existData.LastUpdateUserId = UserId ?? ""; + existData.LastUpdateFullName = FullName ?? ""; + } + await _context.SaveChangesAsync(); + } + } + + public async Task CreateAsync(Gender inserted) + { + inserted.CreatedUserId = UserId ?? ""; + inserted.CreatedFullName = FullName ?? "System Administrator"; + inserted.CreatedAt = DateTime.Now; + inserted.LastUpdatedAt = DateTime.Now; + inserted.LastUpdateFullName = FullName ?? "System Administrator"; + inserted.LastUpdateUserId = UserId ?? ""; + + await _context.Genders.AddAsync(inserted); + + await _context.SaveChangesAsync(); + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Services/PrefixService.cs b/BMA.EHR.MetaData.Service/Services/PrefixService.cs new file mode 100644 index 00000000..44477c61 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/PrefixService.cs @@ -0,0 +1,90 @@ +using BMA.EHR.Domain.Models.MetaData; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using System.Security.Claims; + + +namespace BMA.EHR.MetaData.Service.Services +{ + public class PrefixService + { + #region " Fields " + + private readonly ApplicationDBContext _context; + private readonly IHttpContextAccessor _httpContextAccessor; + + #endregion + + #region " Constructor and Destructor " + + public PrefixService(ApplicationDBContext context, + IHttpContextAccessor httpContextAccessor) + { + _context = context; + _httpContextAccessor = httpContextAccessor; + } + + #endregion + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + #endregion + + #region " Methods " + + public async Task> GetsAsync(bool showAll = true) + { + if (showAll) + return await _context.Prefixes.AsQueryable() + .OrderBy(d => d.Name) + .ToListAsync(); + else + return await _context.Prefixes.AsQueryable() + .Where(p => p.IsActive) + .OrderBy(d => d.Name) + .ToListAsync(); + } + + public async Task GetByIdAsync(Guid id) + { + return await _context.Prefixes.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task UpdateAsync(Guid id, Prefix updated) + { + var existData = await _context.Prefixes.FirstOrDefaultAsync(x => x.Id == id); + if (existData != null) + { + if (existData.Name != updated.Name || existData.IsActive != updated.IsActive) + { + existData.Name = updated.Name; + existData.IsActive = updated.IsActive; + existData.LastUpdateUserId = UserId ?? ""; + existData.LastUpdateFullName = FullName ?? ""; + existData.LastUpdatedAt = DateTime.Now; + } + await _context.SaveChangesAsync(); + } + } + + public async Task CreateAsync(Prefix inserted) + { + inserted.CreatedUserId = UserId ?? ""; + inserted.CreatedFullName = FullName ?? "System Administrator"; + inserted.CreatedAt = DateTime.Now; + inserted.LastUpdatedAt = DateTime.Now; + inserted.LastUpdateFullName = FullName ?? "System Administrator"; + inserted.LastUpdateUserId = UserId ?? ""; + + await _context.Prefixes.AddAsync(inserted); + + await _context.SaveChangesAsync(); + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Services/ProvinceService.cs b/BMA.EHR.MetaData.Service/Services/ProvinceService.cs new file mode 100644 index 00000000..ade9fb6f --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/ProvinceService.cs @@ -0,0 +1,93 @@ +using BMA.EHR.Domain.Models.MetaData; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using System.Security.Claims; + + +namespace BMA.EHR.MetaData.Service.Services +{ + public class ProvinceService + { + #region " Fields " + + private readonly ApplicationDBContext _context; + private readonly IHttpContextAccessor _httpContextAccessor; + + #endregion + + #region " Constructor and Destructor " + + public ProvinceService(ApplicationDBContext context, + IHttpContextAccessor httpContextAccessor) + { + _context = context; + _httpContextAccessor = httpContextAccessor; + } + + #endregion + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + #endregion + + #region " Methods " + + public async Task> GetsAsync(bool showAll = true) + { + if (showAll) + return await _context.Provinces.AsQueryable() + .OrderBy(d => d.Name) + .ToListAsync(); + else + return await _context.Provinces.AsQueryable() + .Where(p => p.IsActive) + .OrderBy(d => d.Name) + .ToListAsync(); + } + + public async Task GetByIdAsync(Guid id) + { + return await _context.Provinces + .AsQueryable() + .Include(x => x.Districts) + .FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task UpdateAsync(Guid id, Province updated) + { + var existData = await _context.Provinces.FirstOrDefaultAsync(x => x.Id == id); + if (existData != null) + { + if (existData.Name != updated.Name || existData.IsActive != updated.IsActive) + { + existData.Name = updated.Name; + existData.IsActive = updated.IsActive; + existData.LastUpdatedAt = DateTime.Now; + existData.LastUpdateUserId = UserId ?? ""; + existData.LastUpdateFullName = FullName ?? ""; + } + await _context.SaveChangesAsync(); + } + } + + public async Task CreateAsync(Province inserted) + { + inserted.CreatedUserId = UserId ?? ""; + inserted.CreatedFullName = FullName ?? "System Administrator"; + inserted.CreatedAt = DateTime.Now; + inserted.LastUpdatedAt = DateTime.Now; + inserted.LastUpdateFullName = FullName ?? "System Administrator"; + inserted.LastUpdateUserId = UserId ?? ""; + + await _context.Provinces.AddAsync(inserted); + + await _context.SaveChangesAsync(); + } + + #endregion + } +} \ No newline at end of file diff --git a/BMA.EHR.MetaData.Service/Services/RelationshipService.cs b/BMA.EHR.MetaData.Service/Services/RelationshipService.cs new file mode 100644 index 00000000..8b60132f --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/RelationshipService.cs @@ -0,0 +1,89 @@ +using BMA.EHR.Domain.Models.MetaData; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using System.Security.Claims; + + +namespace BMA.EHR.MetaData.Service.Services; + +public class RelationshipService +{ + #region " Fields " + + private readonly ApplicationDBContext _context; + private readonly IHttpContextAccessor _httpContextAccessor; + + #endregion + + #region " Constructor and Destructor " + + public RelationshipService(ApplicationDBContext context, + IHttpContextAccessor httpContextAccessor) + { + _context = context; + _httpContextAccessor = httpContextAccessor; + } + + #endregion + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + #endregion + + #region " Methods " + + public async Task> GetsAsync(bool showAll = true) + { + if (showAll) + return await _context.Relationships.AsQueryable() + .OrderBy(d => d.Name) + .ToListAsync(); + else + return await _context.Relationships.AsQueryable() + .Where(p => p.IsActive) + .OrderBy(d => d.Name) + .ToListAsync(); + } + + public async Task GetByIdAsync(Guid id) + { + return await _context.Relationships.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task UpdateAsync(Guid id, Relationship updated) + { + var existData = await _context.Relationships.FirstOrDefaultAsync(x => x.Id == id); + if (existData != null) + { + if (existData.Name != updated.Name || existData.IsActive != updated.IsActive) + { + existData.Name = updated.Name; + existData.IsActive = updated.IsActive; + existData.LastUpdateUserId = UserId ?? ""; + existData.LastUpdateFullName = FullName ?? ""; + existData.LastUpdatedAt = DateTime.Now; + } + await _context.SaveChangesAsync(); + } + } + + public async Task CreateAsync(Relationship inserted) + { + inserted.CreatedUserId = UserId ?? ""; + inserted.CreatedFullName = FullName ?? "System Administrator"; + inserted.CreatedAt = DateTime.Now; + inserted.LastUpdatedAt = DateTime.Now; + inserted.LastUpdateFullName = FullName ?? "System Administrator"; + inserted.LastUpdateUserId = UserId ?? ""; + + await _context.Relationships.AddAsync(inserted); + + await _context.SaveChangesAsync(); + } + + #endregion +} \ No newline at end of file diff --git a/BMA.EHR.MetaData.Service/Services/ReligionService.cs b/BMA.EHR.MetaData.Service/Services/ReligionService.cs new file mode 100644 index 00000000..f646bc44 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/ReligionService.cs @@ -0,0 +1,90 @@ +using BMA.EHR.Domain.Models.MetaData; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using System.Security.Claims; + + +namespace BMA.EHR.MetaData.Service.Services +{ + public class ReligionService + { + #region " Fields " + + private readonly ApplicationDBContext _context; + private readonly IHttpContextAccessor _httpContextAccessor; + + #endregion + + #region " Constructor and Destructor " + + public ReligionService(ApplicationDBContext context, + IHttpContextAccessor httpContextAccessor) + { + _context = context; + _httpContextAccessor = httpContextAccessor; + } + + #endregion + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + #endregion + + #region " Methods " + + public async Task> GetsAsync(bool showAll = true) + { + if (showAll) + return await _context.Religions.AsQueryable() + .OrderBy(d => d.Name) + .ToListAsync(); + else + return await _context.Religions.AsQueryable() + .Where(p => p.IsActive) + .OrderBy(d => d.Name) + .ToListAsync(); + } + + public async Task GetByIdAsync(Guid id) + { + return await _context.Religions.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task UpdateAsync(Guid id, Religion updated) + { + var existData = await _context.Religions.FirstOrDefaultAsync(x => x.Id == id); + if (existData != null) + { + if (existData.Name != updated.Name || existData.IsActive != updated.IsActive) + { + existData.Name = updated.Name; + existData.IsActive = updated.IsActive; + existData.LastUpdateUserId = UserId ?? ""; + existData.LastUpdateFullName = FullName ?? ""; + existData.LastUpdatedAt = DateTime.Now; + } + await _context.SaveChangesAsync(); + } + } + + public async Task CreateAsync(Religion inserted) + { + inserted.CreatedUserId = UserId ?? ""; + inserted.CreatedFullName = FullName ?? "System Administrator"; + inserted.CreatedAt = DateTime.Now; + inserted.LastUpdatedAt = DateTime.Now; + inserted.LastUpdateFullName = FullName ?? "System Administrator"; + inserted.LastUpdateUserId = UserId ?? ""; + + await _context.Religions.AddAsync(inserted); + + await _context.SaveChangesAsync(); + } + + #endregion + } +}