|
|
using NPOI.Util;using Shentun.Peis.Enums;using Shentun.Peis.HelperDto;using Shentun.Peis.Models;using Shentun.Utilities;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using Volo.Abp;using Volo.Abp.Domain.Repositories;using Volo.Abp.Domain.Services;
namespace Shentun.Peis.Items{
/// <summary>
/// 项目设置
/// </summary>
public class ItemManager : DomainService { private readonly IRepository<Item, Guid> _repository; private readonly IRepository<AsbitemDetail> _asbtiemDetailRepository; private readonly IRepository<ItemTemplateDetail> _itemTemplateDetailRepository; private readonly IRepository<RegisterCheckItem> _registerCheckItemRepository; private readonly IRepository<ReferenceRange, Guid> _referenceRangeRepository; private readonly IRepository<ItemResultTemplate, Guid> _itemResultTemplateRepository; private readonly IRepository<ItemResultMatch, Guid> _itemResultMatchRepository; private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository; private readonly IRepository<RegisterCheckAsbitem, Guid> _registerAsbitemRepository; private readonly IRepository<RegisterCheck> _registerCheckRepository;
public ItemManager( IRepository<Item, Guid> repository, IRepository<ItemResultMatch, Guid> itemResultMatchRepository, IRepository<ItemResultTemplate, Guid> itemResultTemplateRepository, IRepository<ReferenceRange, Guid> referenceRangeRepository, IRepository<AsbitemDetail> asbtiemDetailRepository, IRepository<ItemTemplateDetail> itemTemplateDetailRepository, IRepository<RegisterCheckItem> registerCheckItemRepository, IRepository<SexHormoneReferenceRange, Guid> sexHormoneReferenceRangeRepository, IRepository<PatientRegister, Guid> patientRegisterRepository, IRepository<RegisterCheckAsbitem, Guid> registerAsbitemRepository, IRepository<RegisterCheck, Guid> registerCheckRepository) { this._repository = repository; this._asbtiemDetailRepository = asbtiemDetailRepository; this._itemTemplateDetailRepository = itemTemplateDetailRepository; this._registerCheckItemRepository = registerCheckItemRepository; this._registerCheckRepository = registerCheckRepository; this._referenceRangeRepository = referenceRangeRepository; this._itemResultTemplateRepository = itemResultTemplateRepository; this._itemResultMatchRepository = itemResultMatchRepository; this._patientRegisterRepository = patientRegisterRepository; this._registerAsbitemRepository = registerAsbitemRepository; } /// <summary>
/// 创建
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<Item> CreateAsync( Item entity ) { Verify(entity); //await EntityHelper.CheckSameName<Item, Guid>(_repository, entity.DisplayName);
var existEntity = await _repository.CountAsync(o => o.DisplayName == entity.DisplayName && o.ItemTypeId == entity.ItemTypeId); if (existEntity > 0) { throw new UserFriendlyException($"名称:'{entity.DisplayName}'在同一科室下已存在"); } return new Item { DisplayName = entity.DisplayName, SimpleCode = LanguageConverter.GetPYSimpleCode(entity.DisplayName), DisplayOrder = await EntityHelper.CreateMaxDisplayOrder<Item>(_repository), DefaultResult = entity.DefaultResult, DiagnosisFunction = entity.DiagnosisFunction, IsActive = entity.IsActive, IsContinueProcess = entity.IsContinueProcess, IsDiagnosisFunction = entity.IsDiagnosisFunction, ItemTypeId = entity.ItemTypeId, Price = entity.Price, CalculationFunction = entity.CalculationFunction, EnglishShortName = entity.EnglishShortName, InputCheck = entity.InputCheck, IsCalculationItem = entity.IsCalculationItem, IsNameIntoSummary = entity.IsNameIntoSummary, IsProduceSummary = entity.IsProduceSummary, PriceItemId = entity.PriceItemId, ReferenceRangeTypeFlag = entity.ReferenceRangeTypeFlag, ResultTemplateTypeFlag = entity.ResultTemplateTypeFlag, UnitId = entity.UnitId, LineModeFlag = entity.LineModeFlag, DeviceTypeId = entity.DeviceTypeId, IsCriticalValueFunction = entity.IsCriticalValueFunction, IsFollowUpFunction = entity.IsFollowUpFunction, FollowUpFunction = entity.FollowUpFunction, CriticalValueFunction = entity.CriticalValueFunction }; } /// <summary>
/// 更新
/// </summary>
/// <param name="sourceEntity"></param>
/// <param name="targetEntity"></param>
/// <returns></returns>
public async Task UpdateAsync( Item sourceEntity, Item targetEntity ) { DataHelper.CheckEntityIsNull(targetEntity); Verify(sourceEntity); if (sourceEntity.DisplayName != targetEntity.DisplayName) { var existEntity = await _repository.CountAsync(o => o.Id != targetEntity.Id && o.DisplayName == sourceEntity.DisplayName && o.ItemTypeId == sourceEntity.ItemTypeId); if (existEntity > 0) { throw new UserFriendlyException($"名称:'{sourceEntity.DisplayName}'在同一科室下已存在"); } //await EntityHelper.CheckSameName<Item, Guid>(_repository, sourceEntity.DisplayName, targetEntity);
targetEntity.DisplayName = sourceEntity.DisplayName; targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName); }
targetEntity.DefaultResult = sourceEntity.DefaultResult; targetEntity.DiagnosisFunction = sourceEntity.DiagnosisFunction; targetEntity.IsActive = sourceEntity.IsActive; targetEntity.IsContinueProcess = sourceEntity.IsContinueProcess; targetEntity.IsDiagnosisFunction = sourceEntity.IsDiagnosisFunction; targetEntity.ItemTypeId = sourceEntity.ItemTypeId; targetEntity.Price = sourceEntity.Price; targetEntity.CalculationFunction = sourceEntity.CalculationFunction; targetEntity.EnglishShortName = sourceEntity.EnglishShortName; targetEntity.InputCheck = sourceEntity.InputCheck; targetEntity.IsCalculationItem = sourceEntity.IsCalculationItem; targetEntity.IsNameIntoSummary = sourceEntity.IsNameIntoSummary; targetEntity.IsProduceSummary = sourceEntity.IsProduceSummary; targetEntity.PriceItemId = sourceEntity.PriceItemId; targetEntity.ReferenceRangeTypeFlag = sourceEntity.ReferenceRangeTypeFlag; targetEntity.ResultTemplateTypeFlag = sourceEntity.ResultTemplateTypeFlag; targetEntity.UnitId = sourceEntity.UnitId; targetEntity.LineModeFlag = sourceEntity.LineModeFlag; targetEntity.DeviceTypeId = sourceEntity.DeviceTypeId; targetEntity.IsCriticalValueFunction = sourceEntity.IsCriticalValueFunction; targetEntity.IsFollowUpFunction = sourceEntity.IsFollowUpFunction; targetEntity.CriticalValueFunction = sourceEntity.CriticalValueFunction; targetEntity.FollowUpFunction = sourceEntity.FollowUpFunction; }
private void Verify(Item entity) { DataHelper.CheckEntityIsNull(entity); DataHelper.CheckStringIsNull(entity.DisplayName, "名称"); DataHelper.CheckGuidIsDefaultValue(entity.ItemTypeId, "项目类别"); DataHelper.CheckCharIsYOrN(entity.IsProduceSummary, "是否生成小结"); DataHelper.CheckCharIsYOrN(entity.IsNameIntoSummary, "名称是否进入小结"); DataHelper.CheckCharIsYOrN(entity.IsDiagnosisFunction, "是否启用诊断函数"); DataHelper.CheckCharIsYOrN(entity.IsCalculationItem, "是否计算项目"); DataHelper.CheckCharIsYOrN(entity.IsContinueProcess, "是否继续处理"); DataHelper.CheckCharIsYOrN(entity.IsActive, "是否启用"); if (entity.ReferenceRangeTypeFlag != ItemReferenceRangeTypeFlag.None && entity.ReferenceRangeTypeFlag != ItemReferenceRangeTypeFlag.Number && entity.ReferenceRangeTypeFlag != ItemReferenceRangeTypeFlag.Character && entity.ReferenceRangeTypeFlag != ItemReferenceRangeTypeFlag.SexHormone) { throw new ArgumentException($"参考范围类别参数为:{entity.ReferenceRangeTypeFlag},是无效值,只能为'{ItemReferenceRangeTypeFlag.None}','{ItemReferenceRangeTypeFlag.Number}','{ItemReferenceRangeTypeFlag.Character}','{ItemReferenceRangeTypeFlag.SexHormone}'"); } DataHelper.CheckCharIsYOrN(entity.IsCriticalValueFunction, "是否启用危急值函数"); DataHelper.CheckCharIsYOrN(entity.IsFollowUpFunction, "是否启用随访函数"); }
/// <summary>
/// 更新参考范围类型
/// </summary>
/// <param name="sourceEntity"></param>
/// <param name="targetEntity"></param>
/// <returns></returns>
public async Task UpdateRangeTypeAsync(Guid itemid, char ReferenceRangeTypeFlag) { var itement = await _repository.GetAsync(itemid); if (itement != null) { itement.ReferenceRangeTypeFlag = ReferenceRangeTypeFlag; await _repository.UpdateAsync(itement); }
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
public async Task UpdateManySortAsync(Guid id, int SortType) { await EntityHelper.UpdateManySortAsync(_repository, id, SortType); }
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="repository"></param>
/// <param name="input"></param>
/// <returns></returns>
public async Task UpdateSortManyAsync(UpdateSortManyDto input) { await EntityHelper.UpdateSortManyAsync(_repository, input);
}
/// <summary>
/// 删除项目时,同步删除项目结果模板( item_result_template)、参考范围(reference_range)、结果匹配(item_result_match)、组合项目包含的项目(asbitem_detail),项目模板明细(ItemTemplateDetail)。
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task CheckAndDeleteAsync(Guid id) { var itemEnt = await _repository.FindAsync(m => m.Id == id); if (itemEnt != null) {
var IsRegister = from a in await _patientRegisterRepository.GetQueryableAsync() join b in await _registerAsbitemRepository.GetQueryableAsync() on a.Id equals b.PatientRegisterId join c in await _registerCheckRepository.GetQueryableAsync() on b.RegisterCheckId equals c.Id join d in await _registerCheckItemRepository.GetQueryableAsync() on c.Id equals d.RegisterCheckId where d.ItemId == id select new { PatientName = a.PatientName };
if (IsRegister.Count() > 0) { throw new UserFriendlyException($"该项目已被{IsRegister.ToList().FirstOrDefault().PatientName}登记,无法删除"); }
//删除item_result_match数据
var itemResultMatchList = await _itemResultMatchRepository.GetListAsync(m => m.ItemId == id); if (itemResultMatchList.Any()) { await _itemResultMatchRepository.DeleteManyAsync(itemResultMatchList); }
//删除item_result_template数据
var itemResultTemplateList = await _itemResultTemplateRepository.GetListAsync(m => m.ItemId == id); if (itemResultTemplateList.Any()) { await _itemResultTemplateRepository.DeleteManyAsync(itemResultTemplateList); }
//删除reference_range数据
var referenceRangeList = await _referenceRangeRepository.GetListAsync(m => m.ItemId == id); if (referenceRangeList.Any()) { await _referenceRangeRepository.DeleteManyAsync(referenceRangeList); }
//删除asbitem_detail数据
var asbtiemDetailList = await _asbtiemDetailRepository.GetListAsync(m => m.ItemId == id); if (asbtiemDetailList.Any()) { await _asbtiemDetailRepository.DeleteManyAsync(asbtiemDetailList); }
//删除项目模板明细
await _itemTemplateDetailRepository.DeleteAsync(m => m.ItemId == id);
//删除项目
await _repository.DeleteAsync(id);
} else { throw new UserFriendlyException("数据不存在"); }
}
}}
|