稽查小小修改 重命名

Uat_Study
hang 2022-08-17 09:21:07 +08:00
parent 47342540f9
commit 97a2fa5ed1
3 changed files with 290 additions and 97 deletions

View File

@ -70,7 +70,7 @@ namespace IRaCIS.Application.Services
var attachment = await _attachmentRepository.InsertFromDTOAsync(attachmentViewModel);
//intoGroupItem.AttachmentId = attachment.Id;
await _enrollRepository.UpdatePartialNoQueryAsync(intoGroupItem.Id,u=>new Enroll(){AttachmentId = attachment.Id});
await _enrollRepository.UpdatePartialFromQueryAsync(intoGroupItem.Id,u=>new Enroll(){AttachmentId = attachment.Id});
var success = await _enrollRepository.SaveChangesAsync();
@ -88,12 +88,12 @@ namespace IRaCIS.Application.Services
public async Task<IResponseOutput> DeleteReviewerAckSOW(Guid trialId, Guid doctorId, Guid attachmentId)
{
var success1 = await _attachmentRepository.BatchDeleteNoTrackingAsync(a => a.Id == attachmentId);
var success2 = await _enrollRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trialId && t.DoctorId == doctorId, u =>
await _enrollRepository.UpdatePartialFromQueryAsync(t => t.TrialId == trialId && t.DoctorId == doctorId, u =>
new Enroll()
{
AttachmentId = Guid.Empty
});
return ResponseOutput.Result(success1 && success2);
},true);
return ResponseOutput.Ok(success1 );
}
/// <summary>

View File

@ -702,10 +702,23 @@ namespace IRaCIS.Core.Infra.EFCore.Common
subjectVisit = subjectVisit ?? new SubjectVisit();
if (type == "Add")
{
await AddInspectionRecordAsync(new InspectionConvertDTO()
//await AddInspectionRecordAsync( new
//{
// QcQuestionAnswerCommands = await Getdata(entitylist),
//},new InspectionConvertDTO()
//{
// SiteId = subjectVisit.SiteId,
// Identification = $"{_userInfo.RequestUrl}/{firstEntity.GetType().Name}/{type}",
// SubjectId = subjectVisit.SubjectId,
// SubjectVisitName = subjectVisit.VisitName,
// TrialId = subjectVisit.TrialId,
// SubjectVisitId = subjectVisit.Id,
// GeneralId = subjectVisit.Id,
//});
await InsertInspection(firstEntity, type, answer => new InspectionConvertDTO()
{
SiteId = subjectVisit.SiteId,
Identification = $"{_userInfo.RequestUrl}/{firstEntity.GetType().Name}/{type}",
SubjectId = subjectVisit.SubjectId,
SubjectVisitName = subjectVisit.VisitName,
TrialId = subjectVisit.TrialId,
@ -723,19 +736,33 @@ namespace IRaCIS.Core.Infra.EFCore.Common
var createUserId = entitylist.Select(x => x.CreateUserId).FirstOrDefault();
var noUpdateData = _dbContext.TrialQCQuestionAnswer.Where(x => x.CreateUserId == createUserId && x.SubjectVisitId == subjectVisit.Id && !questionIds.Contains(x.Id)).ToList();
entitylist.AddRange(noUpdateData);
await AddInspectionRecordAsync(new InspectionConvertDTO()
await InsertInspection(firstEntity, type, answer => new InspectionConvertDTO()
{
Identification = $"{_userInfo.RequestUrl}/{firstEntity.GetType().Name}/{type}",
SiteId = subjectVisit.SiteId,
SubjectId = subjectVisit.SubjectId,
SubjectVisitName = subjectVisit.VisitName,
TrialId = subjectVisit.TrialId,
SubjectVisitId = subjectVisit.Id,
SubjectVisitName = subjectVisit.VisitName,
GeneralId = subjectVisit.Id,
}, new
{
QcQuestionAnswerCommands = await Getdata(entitylist),
});
//await AddInspectionRecordAsync( new
//{
// QcQuestionAnswerCommands = await Getdata(entitylist),
//},new InspectionConvertDTO()
//{
// Identification = $"{_userInfo.RequestUrl}/{firstEntity.GetType().Name}/{type}",
// SiteId = subjectVisit.SiteId,
// SubjectId = subjectVisit.SubjectId,
// TrialId = subjectVisit.TrialId,
// SubjectVisitId = subjectVisit.Id,
// SubjectVisitName = subjectVisit.VisitName,
// GeneralId = subjectVisit.Id,
//});
}
async Task<List<AnswerDto>> Getdata(List<TrialQCQuestionAnswer> questionAnswers)
@ -787,10 +814,30 @@ namespace IRaCIS.Core.Infra.EFCore.Common
{
Name = doctor.FullName,
ChineseName = doctor.ChineseName,
Email=doctor.EMail,
}) ;
Email = doctor.EMail,
IsUploadedACKSOW = entity.AttachmentId != Guid.Empty
});
}
//独立阅片人 状态修改 上传SoW
if (entitys.Any(x => x.Entity.GetType() == typeof(EnrollReadingCategory)))
{
var list = entitys.Where(x => x.Entity.GetType() == typeof(EnrollReadingCategory)).Select(t => t.Entity as EnrollReadingCategory).ToList();
var enrollId = list.Select(t => t.EnrollId).FirstOrDefault();
var enroll = await _dbContext.Enroll.Include(t => t.Doctor).FirstAsync(t => t.Id == enrollId);
await InsertInspection<Enroll>(enroll, type, x => new InspectionConvertDTO()
{
GeneralId = enroll.Id,
}, new
{
Name = enroll.Doctor.FullName,
ChineseName = enroll.Doctor.ChineseName,
Email = enroll.Doctor.EMail,
ReadingCategoryList = list.Select(t => t.ReadingCategory).ToList()
});
}
//// 医生详情
@ -815,18 +862,198 @@ namespace IRaCIS.Core.Infra.EFCore.Common
/// <param name="expression">表达式</param>
/// <param name="otherItem">其他对象</param>
/// <returns></returns>
public async Task InsertInspection<T>(T data, string type, Expression<Func<T, InspectionConvertDTO>> expression = null, object otherItem = null, object originaldata = null) where T : class
public async Task InsertInspection<T>(T entityObj, string type, Expression<Func<T, InspectionConvertDTO>> expression = null, object otherItem = null, object originaldata = null) where T : class
{
object entityobj = data;
InspectionConvertDTO inspection = new InspectionConvertDTO();
if (expression != null)
{
var f = expression.Compile();
var entitydata = entityobj as T;
inspection = f(entitydata);
inspection = f(entityObj);
}
var entityTypeName = entityobj.GetType().Name;
inspection.Identification = await GetInspectionRecordIdentificationAsync(entityObj,type);
//将实体对象属性 映射到稽查实体
MapEntityPropertyToAuditEntity(entityObj, inspection);
var generalData = await GetInspectionGeneralDataAsync(inspection);
#region 处理标识
var from = await _dbContext.FrontAuditConfig.FirstOrDefaultAsync(x => x.Identification == inspection.Identification);
inspection.ObjectTypeId = from?.ObjectTypeId;
inspection.OptTypeId = from?.OptTypeId;
inspection.ChildrenTypeId = from?.ChildrenTypeId;
inspection.ModuleTypeId = from?.ModuleTypeId;
#endregion
if (inspection.ParentId == null)
{
inspection.ParentId = (await _dbContext.DataInspection.AsQueryable().Where(x => x.TrialId == inspection.TrialId && x.SubjectVisitId == inspection.SubjectVisitId && x.SubjectId == inspection.SubjectId && x.SiteId == inspection.SiteId && x.VisitStageId == inspection.VisitStageId && x.GeneralId == inspection.GeneralId).OrderByDescending(x => x.CreateTime).FirstOrDefaultAsync())?.Id;
}
inspection.CreateUserId = _userInfo.Id;
inspection.IP = _userInfo.IP;
inspection.CreateTime = inspection.CreateTime == default(DateTime) ? DateTime.Now : inspection.CreateTime;
if (_userInfo.SignId != null)
{
inspection.SignId = _userInfo.SignId;
inspection.IsSign = true;
}
var inspectionData = new InspectionJsonDetail()
{
//稽查实体,加上扩充的信息
Data = AddJsonItem(entityObj, otherItem),
//通用信息
Inspection = generalData
};
inspection.JsonDetail = inspectionData.ToJsonStr();
inspection.BatchId = _userInfo.BatchId.Value;
await _dbContext.DataInspection.AddAsync(inspection);
//await AddInspectionRecordAsync( entityObj, inspection, otherItem);
}
/// <summary>
/// 将数据库实体属性,映射到稽查实体属性 避免重复赋值
/// </summary>
/// <param name="date"></param>
/// <param name="auditEntity"></param>
public void MapEntityPropertyToAuditEntity(object data, DataInspection auditEntity)
{
foreach (var auditEntityPropertyInfo in auditEntity.GetType().GetProperties())
{
var excepetNameList = typeof(Entity).GetProperties().Select(t => t.Name)
.Concat(typeof(ISoftDelete).GetProperties().Select(t => t.Name))
.Concat(typeof(IAuditAdd<>).GetProperties().Select(t => t.Name))
.Concat(typeof(IAuditUpdate<>).GetProperties().Select(t => t.Name));
var filterProperties = data.GetType().GetProperties().Where(t => !excepetNameList.Any(u => u == t.Name));
if (filterProperties.Any(t => t.Name == auditEntityPropertyInfo.Name))
{
var value = data.GetType().GetProperty(auditEntityPropertyInfo.Name).GetValue(data);
auditEntity.GetType().GetProperty(auditEntityPropertyInfo.Name).SetValue(auditEntity, value);
}
}
}
/// <summary>
/// 获取稽查通用数据 (每条稽查记录必须查询的)
/// </summary>
/// <param name="inspection"></param>
/// <returns></returns>
public async Task<InspectionGeneralData> GetInspectionGeneralDataAsync(InspectionConvertDTO inspection)
{
InspectionGeneralData generalData = new InspectionGeneralData()
{
SiteCode = inspection.SiteCode,
SiteId = inspection.SiteId,
SiteName = inspection.SiteName,
SubjectCode = inspection.SubjectCode,
SubjectId = inspection.SubjectId,
SubjectVisitId = inspection.SubjectVisitId,
SubjectVisitName = inspection.SubjectVisitName,
ResearchProgramNo = inspection.ResearchProgramNo,
TrialId = inspection.TrialId,
TrialName = inspection.TrialName
};
#region 项目名称
if (generalData.TrialId != null)
{
//项目添加哪里 直接会带信息过来,不用查询数据库 其他的地方需要查询数据库
if (string.IsNullOrEmpty(generalData.ResearchProgramNo) || string.IsNullOrEmpty(generalData.TrialName))
{
var trialdata = (await _dbContext.Trial.Select(x => new { x.Id, x.ResearchProgramNo, x.ExperimentName, }).FirstOrDefaultAsync(x => x.Id == generalData.TrialId)).IfNullThrowException();
generalData.ResearchProgramNo = trialdata.ResearchProgramNo;
generalData.TrialName = trialdata.ExperimentName;
}
}
#endregion
#region 测试中心名称
if (generalData.TrialId != null && generalData.SiteId != null)
{
generalData.SiteCode = (await _dbContext.TrialSite.IgnoreQueryFilters().Where(x => x.TrialId == generalData.TrialId && x.SiteId == generalData.SiteId).Select(t => t.TrialSiteCode).FirstOrDefaultAsync()).IfNullThrowException();
// 添加Site 哪里会带信息过来
if (string.IsNullOrEmpty(generalData.SiteName))
{
generalData.SiteName = (await _dbContext.Site.Where(x => x.Id == generalData.SiteId).Select(x => x.SiteName).FirstOrDefaultAsync()).IfNullThrowException();
}
}
#endregion
#region 受试者
if (generalData.SubjectId != null)
{
// 添加Subject 哪里会带信息过来
if (string.IsNullOrEmpty(generalData.SubjectCode))
{
generalData.SubjectCode = (await _dbContext.Subject.Where(x => x.Id == generalData.SubjectId).Select(x => x.Code).FirstOrDefaultAsync()).IfNullThrowException();
}
}
#endregion
#region 访视
if (generalData.SubjectVisitId != null)
{
//添加访视的时候,会带信息过来
if (string.IsNullOrEmpty(generalData.SubjectVisitName))
{
generalData.SubjectVisitName = (await _dbContext.SubjectVisit.Where(x => x.Id == generalData.SubjectVisitId).Select(x => x.VisitName).FirstOrDefaultAsync()).IfNullThrowException();
}
}
#endregion
return generalData;
}
/// <summary>
/// 获取稽查记录的标识符 部分业务会进行特殊处理
/// </summary>
/// <returns></returns>
public async Task<string> GetInspectionRecordIdentificationAsync<T>(T entityObj, string type)
{
var entityTypeName = entityObj.GetType().Name;
#region 标识符特殊处理
//文档签署这块,不区分系统和项目的 需要处理为同一个标识
if (typeof(T) == typeof(TrialDocUserTypeConfirmedUser) || typeof(T) == typeof(SystemDocConfirmedUser))
@ -835,7 +1062,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
}
dynamic entity;
switch (entityobj.GetType().Name)
switch (entityObj.GetType().Name)
{
case nameof(QCChallengeDialog):
case nameof(QCChallenge):
@ -852,11 +1079,11 @@ namespace IRaCIS.Core.Infra.EFCore.Common
}
break;
case nameof(SystemBasicData):
entity = entityobj as SystemBasicData;
entity = entityObj as SystemBasicData;
type = type + (entity.ParentId == null ? "/parent" : string.Empty);
break;
case nameof(Trial):
entity = entityobj as Trial;
entity = entityObj as Trial;
Guid id = entity.Id;
Trial oldentity = await _dbContext.Trial.Where(x => x.Id == id).FirstOrDefaultAsync();
switch (_userInfo.RequestUrl.ToLower())
@ -873,7 +1100,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
}
break;
case nameof(SubjectVisit):
entity = entityobj as SubjectVisit;
entity = entityObj as SubjectVisit;
switch (_userInfo.RequestUrl.ToLower())
{
case "qcoperation/obtainorcancelqctask":
@ -892,24 +1119,48 @@ namespace IRaCIS.Core.Infra.EFCore.Common
break;
}
inspection.Identification = $"{_userInfo.RequestUrl}/{entityTypeName}/{type}";
#region 注释
//if (data != null)
//{
// var originaldata = data.OriginalValues.ToObject();
// if (originaldata != null)
// {
// inspection.LastJsonDetail = originaldata.ToJcJson();
// }
//}
#endregion
await AddInspectionRecordAsync(inspection, entityobj, otherItem);
return $"{_userInfo.RequestUrl}/{entityTypeName}/{type}";
}
/// 往json里面添加属性
/// </summary>
/// <param name="jsonObj">json</param>
/// <param name="otherItem">添加对象</param>
/// <returns></returns>
public IDictionary<string, object> AddJsonItem(object jsonObj, object otherItem = null)
{
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>((jsonObj).ToJsonStr());
if (otherItem == null)
{
return JsonData;
}
var other = JsonConvert.DeserializeObject<IDictionary<string, object>>(otherItem.ToJsonStr());
foreach (var item in other)
{
if (JsonData.ContainsKey(item.Key))
{
JsonData[item.Key] = item.Value;
}
else
{
JsonData.Add(item.Key, item.Value);
}
}
return JsonData;
}
#region 待废弃 -by zhouhang 调整
/// <summary>
/// 映射数据
@ -939,31 +1190,6 @@ namespace IRaCIS.Core.Infra.EFCore.Common
}
}
/// <summary>
/// 将数据库实体属性,映射到稽查实体属性 避免重复赋值
/// </summary>
/// <param name="date"></param>
/// <param name="auditEntity"></param>
public void EntityMapPropertyToAuditEntity(object data, DataInspection auditEntity)
{
foreach (var auditEntityPropertyInfo in auditEntity.GetType().GetProperties())
{
var excepetNameList = typeof(Entity).GetProperties().Select(t => t.Name)
.Concat(typeof(ISoftDelete).GetProperties().Select(t => t.Name))
.Concat(typeof(IAuditAdd<>).GetProperties().Select(t => t.Name))
.Concat(typeof(IAuditUpdate<>).GetProperties().Select(t => t.Name));
var filterProperties = data.GetType().GetProperties().Where(t => !excepetNameList.Any(u=>u==t.Name));
if (filterProperties.Any(t => t.Name == auditEntityPropertyInfo.Name))
{
var value = data.GetType().GetProperty(auditEntityPropertyInfo.Name).GetValue(data);
auditEntity.GetType().GetProperty(auditEntityPropertyInfo.Name).SetValue(auditEntity, value);
}
}
}
/// <summary>
/// 添加稽查
/// </summary>
@ -971,11 +1197,11 @@ namespace IRaCIS.Core.Infra.EFCore.Common
/// <param name="data">数据</param>
/// <returns></returns>
/// <exception cref="BusinessValidationFailedException"></exception>
public async Task AddInspectionRecordAsync(InspectionConvertDTO add, object data, object otherItem = null)
public async Task AddInspectionRecordAsync<T>(T data, InspectionConvertDTO add, object otherItem = null) where T : class
{
//MapData(data, add);
EntityMapPropertyToAuditEntity(data, add);
MapEntityPropertyToAuditEntity(data, add);
InspectionGeneralData generalData = new InspectionGeneralData()
{
@ -994,6 +1220,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
};
await SetInspectionNameValue(generalData);
#region 处理标识
var from = await _dbContext.FrontAuditConfig.FirstOrDefaultAsync(x => x.Identification == add.Identification);
@ -1031,43 +1258,6 @@ namespace IRaCIS.Core.Infra.EFCore.Common
}
/// <summary>
/// 往json里面添加属性
/// </summary>
/// <param name="jsonObj">json</param>
/// <param name="otherItem">添加对象</param>
/// <returns></returns>
public IDictionary<string, object> AddJsonItem(object jsonObj, object otherItem = null)
{
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>((jsonObj).ToJsonStr());
if (otherItem == null)
{
return JsonData;
}
var other = JsonConvert.DeserializeObject<IDictionary<string, object>>(otherItem.ToJsonStr());
foreach (var item in other)
{
if (JsonData.ContainsKey(item.Key))
{
JsonData[item.Key] = item.Value;
}
else
{
JsonData.Add(item.Key, item.Value);
}
}
return JsonData;
}
/// <summary>
/// 设置项目以及名称
/// </summary>
@ -1144,5 +1334,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common
}
#endregion
}
}

View File

@ -188,7 +188,7 @@ namespace IRaCIS.Core.Infra.EFCore
#region Enroll
public virtual DbSet<Workload> DoctorWorkload { get; set; }
public virtual DbSet<Enroll> IntoGroup { get; set; }
public virtual DbSet<Enroll> Enroll { get; set; }
public virtual DbSet<EnrollReadingCategory> EnrollReadingCategory { get; set; }