diff --git a/Models/AvailablePositionLevelEntity.cs b/Models/AvailablePositionLevelEntity.cs index 7610c1c..a37e90c 100644 --- a/Models/AvailablePositionLevelEntity.cs +++ b/Models/AvailablePositionLevelEntity.cs @@ -1,11 +1,9 @@ - -using BMA.EHR.Organization.Service.Models; -using BMA.EHR.Report.Service.Models; +using BMA.EHR.MetaData.Service.Models; using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace BMA.EHR.Profile.Service.Models +namespace BMA.EHR.Organization.Service.Models { public class AvailablePositionLevelEntity : EntityBase { diff --git a/Models/OrganizationEntity.cs b/Models/OrganizationEntity.cs index 723a102..19c7dfd 100644 --- a/Models/OrganizationEntity.cs +++ b/Models/OrganizationEntity.cs @@ -1,9 +1,9 @@ using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using BMA.EHR.Report.Service.Models; +using BMA.EHR.MetaData.Service.Models; -namespace BMA.EHR.Profile.Service.Models +namespace BMA.EHR.Organization.Service.Models { public class OrganizationEntity : EntityBase { @@ -67,6 +67,21 @@ namespace BMA.EHR.Profile.Service.Models [Column(Order = 13), Comment("OrganizationUserNote")] public string? OrganizationUserNote { get; set; } + + [Column(Order = 14), Comment("หน่วยงาน")] + public string? Agency { get; set; } + + [Column(Order = 15), Comment("ส่วนราชการ")] + public string? Government { get; set; } + + [Column(Order = 16), Comment("ฝ่าย/ส่วน")] + public string? Department { get; set; } + + [Column(Order = 17), Comment("กอง")] + public string? Pile { get; set; } + + public Guid? OrganizationStatusId { get; set; } + public List Organizations { get; } = new(); } diff --git a/Models/OrganizationPositionEntity.cs b/Models/OrganizationPositionEntity.cs index 1249286..acbe154 100644 --- a/Models/OrganizationPositionEntity.cs +++ b/Models/OrganizationPositionEntity.cs @@ -1,13 +1,13 @@ -using BMA.EHR.Organization.Service.Models; -using BMA.EHR.Report.Service.Models; +using BMA.EHR.MetaData.Service.Models; using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace BMA.EHR.Profile.Service.Models +namespace BMA.EHR.Organization.Service.Models { public class OrganizationPositionEntity : EntityBase { + [ForeignKey("PositionMasterId")] public PositionMasterEntity? PositionMaster_PositionMasterId { get; set; } @@ -28,5 +28,12 @@ namespace BMA.EHR.Profile.Service.Models [Column(Order = 6), Comment("PositionNumberId")] public Guid? PositionNumberId { get; set; } + + [Column(Order = 7), Comment("ติดเงื่อนไข")] + public bool? IsCondition { get; set; } + + [Column(Order = 8), Comment("รายละเอียดเงื่อนไข")] + public string? ConditionNote { get; set; } + } } diff --git a/Models/OrganizationPublishFileEntity.cs b/Models/OrganizationPublishFileEntity.cs new file mode 100644 index 0000000..729d6ca --- /dev/null +++ b/Models/OrganizationPublishFileEntity.cs @@ -0,0 +1,17 @@ +using BMA.EHR.MetaData.Service.Models; +using System.ComponentModel.DataAnnotations; + +namespace BMA.EHR.Organization.Service.Models +{ + /// + /// เก็บข้อมูลไฟล์ structure ที่ถูกสร้างตอนทำการ publish + /// + public class OrganizationPublishFileEntity : EntityBase + { + [Required] + public string Description { get; set; } = string.Empty; + + [Required] + public string FileName { get; set; } = string.Empty; + } +} diff --git a/Models/OrganizationPublishHistoryEntity.cs b/Models/OrganizationPublishHistoryEntity.cs new file mode 100644 index 0000000..9e15c67 --- /dev/null +++ b/Models/OrganizationPublishHistoryEntity.cs @@ -0,0 +1,15 @@ +using BMA.EHR.MetaData.Service.Models; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations.Schema; + +namespace BMA.EHR.Organization.Service.Models +{ + public class OrganizationPublishHistoryEntity : EntityBase + { + [Column(Order = 1), Comment("รายละเอียดการแก้ไข")] + public string Detail { get; set; } = string.Empty; + + [Column(Order = 2), Comment("เก็บ Object ที่มีการอัพเดตในระบบ")] + public string ObjectValue { get; set; } = string.Empty; + } +} diff --git a/Models/PositionMasterEntity.cs b/Models/PositionMasterEntity.cs index d4a4c93..654dd6f 100644 --- a/Models/PositionMasterEntity.cs +++ b/Models/PositionMasterEntity.cs @@ -73,7 +73,7 @@ namespace BMA.EHR.Organization.Service.Models public string? PositionExecutiveSideObject { get; set; } //public List AvailablePositionLevels { get; } = new(); - //public List PositionMasterHistorys { get; } = new(); + public List PositionMasterHistorys { get; } = new(); } } diff --git a/Models/PositionMasterHistoryEntity.cs b/Models/PositionMasterHistoryEntity.cs new file mode 100644 index 0000000..8bf2f8e --- /dev/null +++ b/Models/PositionMasterHistoryEntity.cs @@ -0,0 +1,54 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using BMA.EHR.MetaData.Service.Models; + +namespace BMA.EHR.Organization.Service.Models +{ + public class PositionMasterHistoryEntity : EntityBase + { + [Column(Order = 2), Comment("Position")] + public string? Position { get; set; } + + [Column(Order = 3), Comment("PositionPath")] + public string? PositionPath { get; set; } + + [Column(Order = 4), Comment("PositionType")] + public string? PositionType { get; set; } + + [Column(Order = 5), Comment("PositionExecutive")] + public string? PositionExecutive { get; set; } + + [Column(Order = 6), Comment("PositionExecutiveSide")] + public string? PositionExecutiveSide { get; set; } + + [Column(Order = 7), Comment("PositionPathSide")] + public string? PositionPathSide { get; set; } + + [Column(Order = 8), Comment("PositionLine")] + public string? PositionLine { get; set; } + + [Column(Order = 10), Comment("PositionStatus")] + public string? PositionStatus { get; set; } + + [Column(Order = 11), Comment("PositionCondition")] + public string? PositionCondition { get; set; } + + [Column(Order = 12), Comment("PositionLevel")] + public string? PositionLevel { get; set; } + + [Column(Order = 13), Comment("PositionMasterUserNote")] + public string? PositionMasterUserNote { get; set; } + + [Column(Order = 14), Comment("IsDirector")] + public bool? IsDirector { get; set; } + + [Column(Order = 15), Comment("คุณวุฒิ")] + public string? Qualification { get; set; } + public PositionMasterEntity? PositionMasterEntity { get; set; } + + public string? PositionPathSideObject { get; set; } + + public string? PositionExecutiveSideObject { get; set; } + } +} diff --git a/Models/PositionNumberEntity.cs b/Models/PositionNumberEntity.cs index 6382108..e16d169 100644 --- a/Models/PositionNumberEntity.cs +++ b/Models/PositionNumberEntity.cs @@ -1,9 +1,9 @@ using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using BMA.EHR.Report.Service.Models; +using BMA.EHR.MetaData.Service.Models; -namespace BMA.EHR.Profile.Service.Models +namespace BMA.EHR.Organization.Service.Models { public class PositionNumberEntity : EntityBase { @@ -16,5 +16,9 @@ namespace BMA.EHR.Profile.Service.Models [Column(Order = 3), Comment("Shortname")] public Guid? OrganizationShortNameId { get; set; } + + + + } } diff --git a/Models/ProfilePosition.cs b/Models/ProfilePosition.cs index b77a6e1..77228dc 100644 --- a/Models/ProfilePosition.cs +++ b/Models/ProfilePosition.cs @@ -1,9 +1,8 @@ -using Microsoft.EntityFrameworkCore; +using BMA.EHR.MetaData.Service.Models; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal; using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using BMA.EHR.Report.Service.Models; -namespace BMA.EHR.Profile.Service.Models +namespace BMA.EHR.Organization.Service.Models { /// /// Link Profile กับ OrganizationPosition diff --git a/Services/OrganizationReportService.cs b/Services/OrganizationReportService.cs index 65c1d4b..3a052cd 100644 --- a/Services/OrganizationReportService.cs +++ b/Services/OrganizationReportService.cs @@ -107,12 +107,16 @@ namespace BMA.EHR.Report.Service.Services { var ret = new List(); - var oc = await _context.Organizations.FirstOrDefaultAsync(x => x.Id == id); + var oc = await _context.Organizations + .Select(x => new { x.Id, x.ParentId }) + .FirstOrDefaultAsync(x => x.Id == id); if (oc == null) throw new Exception(GlobalMessages.DataNotFound); ret.Add(oc.Id); - var child = await _context.Organizations.AsQueryable().Where(x => x.ParentId == id).ToListAsync(); + var child = await _context.Organizations.AsQueryable() + .Select(x => new { x.Id, x.ParentId }) + .Where(x => x.ParentId == id).ToListAsync(); if (child.Any()) { foreach (var item in child) @@ -135,14 +139,18 @@ namespace BMA.EHR.Report.Service.Services { var ret = new List(); - var oc = await _context.Organizations.FirstOrDefaultAsync(x => x.Id == id); + var oc = await _context.Organizations + .Select(x => new { x.Id, x.ParentId, x.OrganizationOrder }) + .FirstOrDefaultAsync(x => x.Id == id); if (oc == null) throw new Exception(GlobalMessages.DataNotFound); var thisLevel = level; //var thisLevel = oc.OrganizationOrder.Value; ret.Add(new OrganizationItem { Id = oc.Id, Order = thisLevel.ToString() }); - var child = await _context.Organizations.AsQueryable().Where(x => x.ParentId == id).OrderBy(x => x.OrganizationOrder).ToListAsync(); + var child = await _context.Organizations.AsQueryable() + .Select(x => new { x.Id, x.ParentId, x.OrganizationOrder }) + .Where(x => x.ParentId == id).OrderBy(x => x.OrganizationOrder).ToListAsync(); if (child.Any()) { var c = 1; @@ -176,7 +184,14 @@ namespace BMA.EHR.Report.Service.Services public async Task?> GetOrganizationTypes(string type) { - var Organizations = await _context.Organizations.ToListAsync(); + var Organizations = await _context.Organizations + .Select(x => new + { + Id = x.Id, + OrganizationOrganizationId = x.OrganizationOrganizationId, + OrganizationTypeId = x.OrganizationTypeId, + OrganizationOrder = x.OrganizationOrder + }).ToListAsync(); var OrganizationOrganizations = await _context.OrganizationOrganizations.ToListAsync(); var OrganizationTypes = await _context.OrganizationTypes.FirstOrDefaultAsync(x => x.Name == type); @@ -208,9 +223,41 @@ namespace BMA.EHR.Report.Service.Services var orgWithOrder = new List(); orgWithOrder = await GetAllOcItemByRootAsync(ocId); - var organizationPositions = await _context.OrganizationPositions.ToListAsync(); - var positionMasters = await _context.PositionMasters.ToListAsync(); - var organizations = await _context.Organizations.ToListAsync(); + var organizationPositions = await _context.OrganizationPositions + .Select(x => new + { + x.Id, x.OrganizationId, + x.PositionUserNote, + x.PositionMasterId, + x.PositionNumberId + }).ToListAsync(); + + var positionMasters = await _context.PositionMasters + .Select(x => new + { + x.Id, + x.PositionPathId, + x.PositionPathSideId, + x.PositionExecutiveId, + x.PositionExecutiveSideId, + x.PositionTypeId, + x.PositionPathSideObject, + x.PositionExecutiveSideObject, + x.IsDirector + }) + .ToListAsync(); + + var organizations = await _context.Organizations + .Select(x => new + { + Id = x.Id, + OrganizationOrganizationId = x.OrganizationOrganizationId, + OrganizationTypeId = x.OrganizationTypeId, + OrganizationOrder = x.OrganizationOrder, + OrganizationShortNameId = x.OrganizationShortNameId + }).ToListAsync(); + + var organizationOrganizations = await _applicationDbContext.OrganizationOrganizations.ToListAsync(); var organizationShortNames = await _applicationDbContext.OrganizationShortNames.ToListAsync(); var positionNumbers = await _context.PositionNumbers.ToListAsync(); @@ -278,19 +325,59 @@ namespace BMA.EHR.Report.Service.Services var RootOcName = _profileService.GetOrganizationNameFullPath(organizationId, false, false); var prefixes = await _applicationDbContext.Prefixes.ToListAsync(); - var organizationPositions = await _context.OrganizationPositions.ToListAsync(); + + + //var organizationPositions = await _context.OrganizationPositions.ToListAsync(); + var organizationPositions = await _context.OrganizationPositions + .Select(x => new + { + x.Id, + x.OrganizationId, + x.PositionUserNote, + x.PositionMasterId, + x.PositionNumberId + }).ToListAsync(); + var profilePositions = await _context.ProfilePositions.ToListAsync(); var positionNumbers = await _context.PositionNumbers.ToListAsync(); var positionPaths = await _applicationDbContext.PositionPaths.ToListAsync(); var positionLevels = await _applicationDbContext.PositionLevels.ToListAsync(); - var positionMasters = await _context.PositionMasters.ToListAsync(); + + //var positionMasters = await _context.PositionMasters.ToListAsync(); + var positionMasters = await _context.PositionMasters + .Select(x => new + { + x.Id, + x.PositionPathId, + x.PositionPathSideId, + x.PositionExecutiveId, + x.PositionExecutiveSideId, + x.PositionTypeId, + x.PositionPathSideObject, + x.PositionExecutiveSideObject, + x.IsDirector, + x.Qualification + }) + .ToListAsync(); + var profiles = await _applicationDbContext.Profiles.ToListAsync(); var organizationShortNames = await _applicationDbContext.OrganizationShortNames.ToListAsync(); var report2s = await _context.Report2s.ToListAsync(); var positionPathSides = await _applicationDbContext.PositionPathSides.ToListAsync(); var positionExecutiveSides = await _applicationDbContext.PositionExecutiveSides.ToListAsync(); var positionExecutives = await _applicationDbContext.PositionExecutives.ToListAsync(); - var orgData = await _applicationDbContext.Organizations.ToListAsync(); + + var orgData = await _applicationDbContext.Organizations + .Select(x => new + { + Id = x.Id, + OrganizationOrganizationId = x.OrganizationOrganizationId, + OrganizationTypeId = x.OrganizationTypeId, + OrganizationOrder = x.OrganizationOrder, + OrganizationShortNameId = x.OrganizationShortNameId + }).ToListAsync(); + + var positionTypes = await _applicationDbContext.PositionTypes.ToListAsync(); var raw_results = (from op in organizationPositions @@ -455,7 +542,6 @@ namespace BMA.EHR.Report.Service.Services try { - var ocIdList = _profileService.GetAllIdByRoot(ocId); var RootOcName = _profileService.GetOrganizationNameFullPath(ocId, false, false); diff --git a/Services/ProfileService.cs b/Services/ProfileService.cs index d525dc9..d0ad75f 100644 --- a/Services/ProfileService.cs +++ b/Services/ProfileService.cs @@ -1,4 +1,5 @@ using Amazon.S3.Model.Internal.MarshallTransformations; +using BMA.EHR.Organization.Service.Models; using BMA.EHR.Profile.Service.Models; using BMA.EHR.Report.Service.Data; using Microsoft.EntityFrameworkCore; @@ -6,508 +7,532 @@ using System.Text.RegularExpressions; namespace BMA.EHR.Profile.Service.Services { - public class OrganizationItem - { - public Guid Id { get; set; } - - public string Name { get; set; } = string.Empty; - - public int Order { get; set; } = 0; - } - - public class ProfileService - { - private readonly EHRDbContext _context; - - public ProfileService(EHRDbContext context) - { - _context = context; - } - - public string ConvertRelationshipToEng(string thai_text) - { - switch (thai_text) - { - case "หย่า": - case "หย่าร้าง": return "divorced"; - case "โสด": return "single"; - case "สมรส": return "married"; - case "แยกกันอยู่": return "seperated"; - default: return "na"; - } - } - - public string ConvertGenderToEng(string thai_text) - { - switch (thai_text) - { - case "ชาย": return "male"; - case "หญิง": return "female"; - default: return "na"; - } - } - - #region " Organizations " - - public string FindOCFullPath(Guid id, bool showRoot = false) - { - try - { - var ocList = GetOcNameFullPath(id, showRoot); - var ret = String.Empty; - foreach (var oc in ocList) - { - ret = oc + " " + ret; - } - - ret = ret.Substring(0, ret.Length - 1); - - return ret; - } - catch - { - throw; - } - } - - public string FindOCFullPathWithNewLine(Guid id, bool showRoot = false, string suppress = "") - { - try - { - var ocList = GetOcNameFullPath(id, showRoot); - var ret = String.Empty; - foreach (var oc in ocList) - { - if ((oc == suppress) && ocList.Count > 1) continue; - ret = $"{oc}\r\n{ret}"; - } - - ret = ret.Substring(0, ret.Length - 2); - - return ret; - } - catch - { - throw; - } - } - - public string GetOrganizationNameFullPathNewLine(Guid id, bool showRoot = false, bool descending = false) - { - try - { - var ocList = GetOCWithFullPath(id, showRoot); - if (descending) - ocList = ocList.OrderBy(x => x.Order).ToList(); - - var ret = String.Empty; - foreach (var oc in ocList) - { - ret = $"{oc.Name}\r\n{ret}"; - } - - ret = ret.Substring(0, ret.Length - 1); - - return ret; - } - catch - { - throw; - } - } - - public string GetOrganizationName(Guid id) - { - try - { - var organizations = _context.Organizations.ToList(); - var organizationOrganizations = _context.OrganizationOrganizations.ToList(); - - - var oc = (from o in organizations - join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id - select new - { - Id = o.Id, - Name = oc_name.Name, - //o.IsActive, - o.ParentId, - IsRoot = o.ParentId == null - }).FirstOrDefault(x => x.Id == id); - - return oc == null ? "" : oc.Name; - } - catch - { - throw; - } - } - - public string GetOrganizationNameFullPath(Guid id, bool showRoot = false, bool descending = false) - { - try - { - var ocList = GetOCWithFullPath(id, showRoot); - if (descending) - ocList = ocList.OrderBy(x => x.Order).ToList(); - - var ret = String.Empty; - foreach (var oc in ocList) - { - ret = oc.Name + " " + ret; - } - if (ret.Length > 0) - ret = ret.Substring(0, ret.Length - 1); - - return ret; - } - catch - { - throw; - } - } - - public List GetOCWithFullPath(Guid id, bool showRoot = false) - { - try - { - var ocList = new List(); - - var organizations = _context.Organizations.ToList(); - var organizationOrganizations = _context.OrganizationOrganizations.ToList(); - - - var oc = (from o in organizations - join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id - select new - { - Id = o.Id, - Name = oc_name.Name, - //o.IsActive, - o.ParentId, - IsRoot = o.ParentId == null - }).FirstOrDefault(x => x.Id == id); - - - //ocList.Add(new OrganizationItem { Id = oc.Id, Name = oc.Name }); - - if (!showRoot) - { - if (!oc.IsRoot) - ocList.Add(new OrganizationItem { Id = oc.Id, Name = oc.Name }); - } - else - ocList.Add(new OrganizationItem { Id = oc.Id, Name = oc.Name }); - - if (oc.ParentId != null) - { - ocList.AddRange(GetOCWithFullPath(oc.ParentId.Value, showRoot)); - } - - return ocList; - } - catch - { - throw; - } - } - - public List GetOcNameFullPath(Guid id, bool showRoot = false) - { - try - { - var ocList = new List(); - - var organizations = _context.Organizations.ToList(); - var organizationOrganizations = _context.OrganizationOrganizations.ToList(); - - var oc = (from o in organizations - join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id - select new - { - Id = o.Id, - Name = oc_name.Name, - //o.IsActive, - o.ParentId, - IsRoot = o.ParentId == null - }).FirstOrDefault(x => x.Id == id); - - if (!showRoot) - { - if (!oc.IsRoot) - ocList.Add(oc.Name); - } - else - ocList.Add(oc.Name); - - //ocList.Add(oc.Name); - - if (oc.ParentId != null) - { - ocList.AddRange(GetOcNameFullPath(oc.ParentId.Value, showRoot)); - } - - return ocList; - } - catch - { - throw; - } - } - - public List GetAllIdByRoot(Guid id) - { - try - { - var ret = new List(); - - var oc = _context.Organizations.FirstOrDefault(x => x.Id == id); - if (oc != null) - ret.Add(oc.Id); - - var child = _context.Organizations.AsQueryable().Where(x => x.ParentId == id).ToList(); - if (child.Any()) - { - foreach (var item in child) - { - ret.AddRange(GetAllIdByRoot(item.Id)); - } - } - - return ret; - } - catch - { - throw; - } - } - - public List GetOCWithChildrenByRoot(Guid id) - { - try - { - var ret = new List(); - - var organizations = _context.Organizations.ToList(); - var organizationOrganizations = _context.OrganizationOrganizations.ToList(); - - // var oc = _context.Organizations.FirstOrDefault(x => x.Id == id && x.IsActive); - var oc = (from o in organizations - join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id - select new - { - Id = o.Id, - Name = oc_name.Name, - //o.IsActive, - o.ParentId, - IsRoot = o.ParentId == null - }).FirstOrDefault(x => x.Id == id); - - var child = (from o in organizations - join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id - select new - { - Id = o.Id, - Name = oc_name.Name, - //o.IsActive, - o.ParentId, - IsRoot = o.ParentId == null - }) - .Where(x => x.ParentId == id) - .ToList(); - - // var child = _context.Organizations.AsQueryable().Where(x => x.ParentId == id && x.IsActive).ToList(); - - - if (child.Any()) - { - var node = new - { - id = oc.Id, - label = oc.Name, - children = new List() - }; - foreach (var item in child) - { - node.children.AddRange(GetOCWithChildrenByRoot(item.Id)); - } - - ret.Add(node); - } - else - { - var node = new - { - id = oc.Id, - label = oc.Name, - }; - ret.Add(node); - } - - return ret; - } - catch - { - throw; - } - } - - public List GetOcByRoot(Guid id) - { - try - { - var ret = new List(); - var oc = _context.Organizations.FirstOrDefault(x => x.Id == id); - ret.Add(oc); - var child = _context.Organizations.AsQueryable().Where(x => x.ParentId == id).ToList(); - if (child.Any()) - { - foreach (var item in child) - { - //ret.Add(item); - var c = _context.Organizations.AsQueryable().Where(x => x.ParentId == item.Id).ToList(); - if (c.Any()) - ret.AddRange(GetOcByRoot(item.Id)); - else - ret.Add(item); - } - } - return ret; - } - catch - { - throw; - } - } - - public string GetPositionLevel(Guid id) - { - try - { - var level = (from alv in _context.AvailablePositionLevels - join lv in _context.PositionLevels on alv.PositionLevelId equals lv.Id - where alv.PositionMasterId == id - select lv.Name).ToList(); - - - var count = 0; - var ret = String.Empty; - foreach (var lv in level) - { - if (count != 0) - ret = $"{ret}หรือ\r\n{lv}"; - else - ret += lv; - - count++; - } - - return ret; - } - catch - { - throw; - } - } - - #endregion - - #region " Profiles " - - public async Task GetProfileById(Guid profileId) - { - try - { - var profile = await _context.Profiles.AsQueryable() - // .Include(p => p.Organization) - .Include(p => p.Position) - // .ThenInclude(p => p.PositionPath) - // .Include(p => p.PositionNumber) - - .Include(p => p.Certificates) - .Include(p => p.Disciplines) - .Include(p => p.Educations) - .Include(p => p.Honors) - .Include(p => p.Insignias) - .Include(p => p.Trainings) - - // .Include(p => p.Salaries) - // .ThenInclude(s => s.SalaryPosition) - // .Include(s => s.Salaries) - // .ThenInclude(s => s.SalaryOrganization) - // .Include(p => p.Salaries) - // .ThenInclude(s => s.SalaryPositionNumber) - // .Include(p => p.Salaries) - // .ThenInclude(s => s.SalaryPositionLevel) - // .Include(p => p.Salaries) - // .ThenInclude(s => s.SalaryPositionType) - .Include(x => x.Avatar) - - // .Include(x => x.PositionType) - // .Include(x => x.PositionLevel) - .Include(x => x.Childrens) - .FirstOrDefaultAsync(p => p.Id == profileId); - - return profile; - } - catch - { - throw; - } - } - - public bool ValidateProfileById(string profileId) - { - var idcardno = profileId; - - if (string.IsNullOrEmpty(idcardno)) - { - return false; - } - - if (idcardno.Length != 13) - { - return false; - } - - bool isDigit = Regex.IsMatch(idcardno, @"^[0-9]*$"); - if (!isDigit) - { - return false; - } - - - int sum = 0; - for (int i = 0; i < 12; i++) - { - sum += Convert.ToInt32(idcardno.Substring(i, 1)) * (13 - i); - } - - int checksum = (11 - (sum % 11)) % 10; - if (checksum != Convert.ToInt32(idcardno.Substring(12))) - { - return false; - } - - return true; - - } - - public async Task CheckExistCitizenId(string profileId) - { - try - { - var profile = await _context.Profiles.AsQueryable().Where(p => p.CitizenId == profileId).FirstOrDefaultAsync(); - - return profile != null; - } - catch - { - throw; - } - } - - - #endregion - } + public class OrganizationItem + { + public Guid Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public int Order { get; set; } = 0; + } + + public class ProfileService + { + private readonly EHRDbContext _context; + + public ProfileService(EHRDbContext context) + { + _context = context; + } + + public string ConvertRelationshipToEng(string thai_text) + { + switch (thai_text) + { + case "หย่า": + case "หย่าร้าง": return "divorced"; + case "โสด": return "single"; + case "สมรส": return "married"; + case "แยกกันอยู่": return "seperated"; + default: return "na"; + } + } + + public string ConvertGenderToEng(string thai_text) + { + switch (thai_text) + { + case "ชาย": return "male"; + case "หญิง": return "female"; + default: return "na"; + } + } + + #region " Organizations " + + public string FindOCFullPath(Guid id, bool showRoot = false) + { + try + { + var ocList = GetOcNameFullPath(id, showRoot); + var ret = String.Empty; + foreach (var oc in ocList) + { + ret = oc + " " + ret; + } + + ret = ret.Substring(0, ret.Length - 1); + + return ret; + } + catch + { + throw; + } + } + + public string FindOCFullPathWithNewLine(Guid id, bool showRoot = false, string suppress = "") + { + try + { + var ocList = GetOcNameFullPath(id, showRoot); + var ret = String.Empty; + foreach (var oc in ocList) + { + if ((oc == suppress) && ocList.Count > 1) continue; + ret = $"{oc}\r\n{ret}"; + } + + ret = ret.Substring(0, ret.Length - 2); + + return ret; + } + catch + { + throw; + } + } + + public string GetOrganizationNameFullPathNewLine(Guid id, bool showRoot = false, bool descending = false) + { + try + { + var ocList = GetOCWithFullPath(id, showRoot); + if (descending) + ocList = ocList.OrderBy(x => x.Order).ToList(); + + var ret = String.Empty; + foreach (var oc in ocList) + { + ret = $"{oc.Name}\r\n{ret}"; + } + + ret = ret.Substring(0, ret.Length - 1); + + return ret; + } + catch + { + throw; + } + } + + public string GetOrganizationName(Guid id) + { + try + { + var organizations = _context.Organizations + .Select(x => new + { + Id = x.Id, + ParentId = x.ParentId, + OrganizationOrganizationId = x.OrganizationOrganizationId, + OrganizationTypeId = x.OrganizationTypeId, + OrganizationOrder = x.OrganizationOrder, + OrganizationShortNameId = x.OrganizationShortNameId + }) + .ToList(); + var organizationOrganizations = _context.OrganizationOrganizations.ToList(); + + + var oc = (from o in organizations + join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id + select new + { + Id = o.Id, + Name = oc_name.Name, + //o.IsActive, + o.ParentId, + IsRoot = o.ParentId == null + }).FirstOrDefault(x => x.Id == id); + + return oc == null ? "" : oc.Name; + } + catch + { + throw; + } + } + + public string GetOrganizationNameFullPath(Guid id, bool showRoot = false, bool descending = false) + { + try + { + var ocList = GetOCWithFullPath(id, showRoot); + if (descending) + ocList = ocList.OrderBy(x => x.Order).ToList(); + + var ret = String.Empty; + foreach (var oc in ocList) + { + ret = oc.Name + " " + ret; + } + if (ret.Length > 0) + ret = ret.Substring(0, ret.Length - 1); + + return ret; + } + catch + { + throw; + } + } + + public List GetOCWithFullPath(Guid id, bool showRoot = false) + { + try + { + var ocList = new List(); + + var organizations = _context.Organizations.Select(x => new { x.Id, x.ParentId, x.OrganizationOrganizationId }).ToList(); + var organizationOrganizations = _context.OrganizationOrganizations.ToList(); + + + var oc = (from o in organizations + join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id + select new + { + Id = o.Id, + Name = oc_name.Name, + //o.IsActive, + o.ParentId, + IsRoot = o.ParentId == null + }).FirstOrDefault(x => x.Id == id); + + + //ocList.Add(new OrganizationItem { Id = oc.Id, Name = oc.Name }); + + if (!showRoot) + { + if (!oc.IsRoot) + ocList.Add(new OrganizationItem { Id = oc.Id, Name = oc.Name }); + } + else + ocList.Add(new OrganizationItem { Id = oc.Id, Name = oc.Name }); + + if (oc.ParentId != null) + { + ocList.AddRange(GetOCWithFullPath(oc.ParentId.Value, showRoot)); + } + + return ocList; + } + catch + { + throw; + } + } + + public List GetOcNameFullPath(Guid id, bool showRoot = false) + { + try + { + var ocList = new List(); + + var organizations = _context.Organizations + .Select(x => new { x.Id, x.ParentId, x.OrganizationOrganizationId }) + .ToList(); + var organizationOrganizations = _context.OrganizationOrganizations.ToList(); + + var oc = (from o in organizations + join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id + select new + { + Id = o.Id, + Name = oc_name.Name, + //o.IsActive, + o.ParentId, + IsRoot = o.ParentId == null + }).FirstOrDefault(x => x.Id == id); + + if (!showRoot) + { + if (!oc.IsRoot) + ocList.Add(oc.Name); + } + else + ocList.Add(oc.Name); + + //ocList.Add(oc.Name); + + if (oc.ParentId != null) + { + ocList.AddRange(GetOcNameFullPath(oc.ParentId.Value, showRoot)); + } + + return ocList; + } + catch + { + throw; + } + } + + public List GetAllIdByRoot(Guid id) + { + try + { + var ret = new List(); + + var oc = _context.Organizations + .Select(x => new { x.Id, x.ParentId }) + .FirstOrDefault(x => x.Id == id); + if (oc != null) + ret.Add(oc.Id); + + var child = _context.Organizations.AsQueryable() + .Select(x => new { x.Id, x.ParentId }) + .Where(x => x.ParentId == id).ToList(); + if (child.Any()) + { + foreach (var item in child) + { + ret.AddRange(GetAllIdByRoot(item.Id)); + } + } + + return ret; + } + catch + { + throw; + } + } + + public List GetOCWithChildrenByRoot(Guid id) + { + try + { + var ret = new List(); + + var organizations = _context.Organizations + .Select(x => new { x.Id, x.ParentId, x.OrganizationOrganizationId }) + .ToList(); + var organizationOrganizations = _context.OrganizationOrganizations.ToList(); + + // var oc = _context.Organizations.FirstOrDefault(x => x.Id == id && x.IsActive); + var oc = (from o in organizations + join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id + select new + { + Id = o.Id, + Name = oc_name.Name, + //o.IsActive, + o.ParentId, + IsRoot = o.ParentId == null + }).FirstOrDefault(x => x.Id == id); + + var child = (from o in organizations + join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id + select new + { + Id = o.Id, + Name = oc_name.Name, + //o.IsActive, + o.ParentId, + IsRoot = o.ParentId == null + }) + .Where(x => x.ParentId == id) + .ToList(); + + // var child = _context.Organizations.AsQueryable().Where(x => x.ParentId == id && x.IsActive).ToList(); + + + if (child.Any()) + { + var node = new + { + id = oc.Id, + label = oc.Name, + children = new List() + }; + foreach (var item in child) + { + node.children.AddRange(GetOCWithChildrenByRoot(item.Id)); + } + + ret.Add(node); + } + else + { + var node = new + { + id = oc.Id, + label = oc.Name, + }; + ret.Add(node); + } + + return ret; + } + catch + { + throw; + } + } + + public List GetOcByRoot(Guid id) + { + try + { + var ret = new List(); + var oc = _context.Organizations + //.Select(x => new { x.Id, x.ParentId, x.OrganizationOrganizationId }) + .FirstOrDefault(x => x.Id == id); + ret.Add(oc); + var child = _context.Organizations.AsQueryable() + // .Select(x => new { x.Id, x.ParentId, x.OrganizationOrganizationId }) + .Where(x => x.ParentId == id).ToList(); + if (child.Any()) + { + foreach (var item in child) + { + //ret.Add(item); + var c = _context.Organizations.AsQueryable() + // .Select(x => new { x.Id, x.ParentId, x.OrganizationOrganizationId }) + .Where(x => x.ParentId == item.Id).ToList(); + if (c.Any()) + ret.AddRange(GetOcByRoot(item.Id)); + else + ret.Add(item); + } + } + return ret; + } + catch + { + throw; + } + } + + public string GetPositionLevel(Guid id) + { + try + { + var level = (from alv in _context.AvailablePositionLevels + join lv in _context.PositionLevels on alv.PositionLevelId equals lv.Id + where alv.PositionMasterId == id + select lv.Name).ToList(); + + + var count = 0; + var ret = String.Empty; + foreach (var lv in level) + { + if (count != 0) + ret = $"{ret}หรือ\r\n{lv}"; + else + ret += lv; + + count++; + } + + return ret; + } + catch + { + throw; + } + } + + #endregion + + #region " Profiles " + + public async Task GetProfileById(Guid profileId) + { + try + { + var profile = await _context.Profiles.AsQueryable() + // .Include(p => p.Organization) + .Include(p => p.Position) + // .ThenInclude(p => p.PositionPath) + // .Include(p => p.PositionNumber) + + .Include(p => p.Certificates) + .Include(p => p.Disciplines) + .Include(p => p.Educations) + .Include(p => p.Honors) + .Include(p => p.Insignias) + .Include(p => p.Trainings) + + // .Include(p => p.Salaries) + // .ThenInclude(s => s.SalaryPosition) + // .Include(s => s.Salaries) + // .ThenInclude(s => s.SalaryOrganization) + // .Include(p => p.Salaries) + // .ThenInclude(s => s.SalaryPositionNumber) + // .Include(p => p.Salaries) + // .ThenInclude(s => s.SalaryPositionLevel) + // .Include(p => p.Salaries) + // .ThenInclude(s => s.SalaryPositionType) + .Include(x => x.Avatar) + + // .Include(x => x.PositionType) + // .Include(x => x.PositionLevel) + .Include(x => x.Childrens) + .FirstOrDefaultAsync(p => p.Id == profileId); + + return profile; + } + catch + { + throw; + } + } + + public bool ValidateProfileById(string profileId) + { + var idcardno = profileId; + + if (string.IsNullOrEmpty(idcardno)) + { + return false; + } + + if (idcardno.Length != 13) + { + return false; + } + + bool isDigit = Regex.IsMatch(idcardno, @"^[0-9]*$"); + if (!isDigit) + { + return false; + } + + + int sum = 0; + for (int i = 0; i < 12; i++) + { + sum += Convert.ToInt32(idcardno.Substring(i, 1)) * (13 - i); + } + + int checksum = (11 - (sum % 11)) % 10; + if (checksum != Convert.ToInt32(idcardno.Substring(12))) + { + return false; + } + + return true; + + } + + public async Task CheckExistCitizenId(string profileId) + { + try + { + var profile = await _context.Profiles.AsQueryable().Where(p => p.CitizenId == profileId).FirstOrDefaultAsync(); + + return profile != null; + } + catch + { + throw; + } + } + + + #endregion + } } diff --git a/appsettings.Development.json b/appsettings.Development.json index 11096b0..dfadc49 100644 --- a/appsettings.Development.json +++ b/appsettings.Development.json @@ -14,9 +14,9 @@ "AllowedHosts": "*", "ConnectionStrings": { "MongoConnection": "mongodb://admin:adminVM123@127.0.0.1:27017", - "RecruitConnection": "server=127.0.0.1;user=root;password=P@ssw0rd;port=3308;database=bma_recruit;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", + "RecruitConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_recruit_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", "EHRConnection": "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;", - "ExamConnection": "server=127.0.0.1;user=root;password=P@ssw0rd;port=3308;database=bma_ehr_exam;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" + "ExamConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_exam_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" }, "Jwt": { "Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI",