617 lines
27 KiB
C#
617 lines
27 KiB
C#
using AutoMapper;
|
||
using IRaCIS.Application.ExpressionExtend;
|
||
using IRaCIS.Core.Application.Contracts;
|
||
using IRaCIS.Core.Domain.Interfaces;
|
||
using IRaCIS.Core.Domain.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq.Dynamic.Core;
|
||
using System.Linq;
|
||
using IRaCIS.Core.Domain.Share.AuthUser;
|
||
using IRaCIS.Core.Domain.Share;
|
||
using Microsoft.EntityFrameworkCore.Internal;
|
||
|
||
namespace IRaCIS.Core.Application
|
||
{
|
||
public class ReportService : IReportService
|
||
{
|
||
private readonly ITURepository _tURepository;
|
||
private readonly ITRRepository _tRRepository;
|
||
private readonly IRSRepository _rSRepository;
|
||
private readonly IReportRepository _reportRepository;
|
||
private readonly IVisitStageRepository _visitStageRepository;
|
||
private readonly ISubjectVisitRepository _subjectVisitRepository;
|
||
private readonly IWorkloadTPRepository _workloadTPRepository;
|
||
private readonly IWorkloadGlobalRepository _workloadGlobalRepository;
|
||
private readonly IMapper _mapper;
|
||
private readonly IUserInfo _userInfo;
|
||
|
||
private string linkGroupId;
|
||
public ReportService(ITURepository tURepository, ITRRepository tRRepository,
|
||
IRSRepository rSRepository, IReportRepository reportRepository,
|
||
IWorkloadTPRepository workloadTPRepository,
|
||
IVisitStageRepository visitStageRepository,
|
||
ISubjectVisitRepository subjectVisitRepository,
|
||
IWorkloadGlobalRepository workloadGlobalRepository,
|
||
IMapper mapper, IUserInfo userInfo)
|
||
{
|
||
_tURepository = tURepository;
|
||
_tRRepository = tRRepository;
|
||
_rSRepository = rSRepository;
|
||
_reportRepository = reportRepository;
|
||
_workloadTPRepository = workloadTPRepository;
|
||
_visitStageRepository = visitStageRepository;
|
||
_subjectVisitRepository = subjectVisitRepository;
|
||
_workloadGlobalRepository = workloadGlobalRepository;
|
||
_mapper = mapper;
|
||
_userInfo = userInfo;
|
||
}
|
||
public bool AddLesion(List<LesionInformation> lesionList, ReportDTO report)
|
||
{
|
||
TU lastTu = _tURepository.GetAll().OrderByDescending("TUSEQ").FirstOrDefault();
|
||
int tuSeq = 101;
|
||
if (lastTu != null) { tuSeq = lastTu.TUSEQ + 1; }
|
||
TR lastTr = _tRRepository.GetAll().OrderByDescending("TRSEQ").FirstOrDefault();
|
||
int trSeq = 1;
|
||
if (lastTr != null) { trSeq = lastTr.TRSEQ + 1; }
|
||
|
||
foreach (var lesion in lesionList)
|
||
{
|
||
var linkId = lesion.TULNKID;
|
||
if (string.IsNullOrWhiteSpace(lesion.TULNKID))
|
||
{
|
||
linkId = (lesion.TUORRES == "TARGET") ? "T" + tuSeq.ToString() : "NT" + tuSeq.ToString();
|
||
}
|
||
_tURepository.Add(new TU
|
||
{
|
||
STUDYID = lesion.STUDYID,
|
||
LesionType = lesion.LesionType,
|
||
USUBJID = lesion.USUBJID,
|
||
TUSEQ = tuSeq,
|
||
TULNKID = linkId,
|
||
|
||
TUTESTCD = lesion.TUTESTCD,
|
||
TUTEST = lesion.TUTEST,
|
||
TUORRES = lesion.TUORRES,
|
||
TUSTRESC = lesion.TUSTRESC,
|
||
|
||
TULOC = lesion.TULOC,
|
||
LocDescription = lesion.LocDescription,
|
||
TULAT = lesion.TULAT,
|
||
TUDIR = lesion.TUDIR,
|
||
TUPORTOT = lesion.TUPORTOT,
|
||
TUMETHOD = lesion.TUMETHOD,
|
||
TUEVAL = lesion.TUEVAL,
|
||
|
||
VISIT = lesion.VISIT,
|
||
VISITNUM = lesion.VISITNUM,
|
||
VISITDY = lesion.VISITDY,
|
||
|
||
TUREFID = lesion.TUREFID,
|
||
TUACPTFL = lesion.TUACPTFL,
|
||
TUEVALID = _userInfo.ReviewerCode,//lesion.TUEVALID,
|
||
TUGRPID = string.Empty,
|
||
TUDY = lesion.TUDY,// 检查日
|
||
EPOCH = lesion.EPOCH,
|
||
TUDTC = lesion.TUDTC,
|
||
TUNAM = lesion.TUNAM,
|
||
TUSPID = lesion.TUSPID,
|
||
TpCode = report.TpCode
|
||
});
|
||
_tRRepository.Add(new TR
|
||
{
|
||
STUDYID = lesion.STUDYID,
|
||
|
||
USUBJID = lesion.USUBJID,
|
||
TRSEQ = trSeq,
|
||
TRLNKID = linkId,
|
||
TRGRPID = lesion.TRGRPID,
|
||
TRLNKGRP = linkGroupId,
|
||
|
||
TRTESTCD = lesion.TRTESTCD,
|
||
TRTEST = lesion.TRTEST,
|
||
TRORRES = lesion.TRORRES,
|
||
TRORRESU = lesion.TRORRESU,
|
||
|
||
TRNAM = lesion.TUNAM,
|
||
TRMETHOD = lesion.TUMETHOD,
|
||
TREVAL = lesion.TUEVAL,
|
||
TREVALID = _userInfo.ReviewerCode,//lesion.TUEVALID,
|
||
TRACPTFL = lesion.TUACPTFL,
|
||
CoveredLesion = true,
|
||
Note = lesion.Note,
|
||
|
||
VISITNUM = lesion.VISITNUM,
|
||
VISIT = lesion.VISIT,
|
||
VISITDY = lesion.VISITDY,
|
||
EPOCH = lesion.EPOCH,
|
||
TRDTC = lesion.TRDTC,
|
||
TRDY = lesion.TRDY,
|
||
TpCode = report.TpCode
|
||
});
|
||
tuSeq++;
|
||
trSeq++;
|
||
}
|
||
|
||
return _rSRepository.SaveChanges();
|
||
}
|
||
|
||
private IList<LesionInformation> GetBLLesion(string trialCode, string SubjectCode, string tpcodeGroup)
|
||
{
|
||
int[] t = { 1, 2, 3 };
|
||
var query = from tu in _tURepository.Find(u => t.Contains(u.LesionType)
|
||
&& u.STUDYID == trialCode && u.USUBJID == SubjectCode && u.TpCode.Contains(tpcodeGroup) /*u.TUEVALID==_userInfo.ReviewerCode*/)
|
||
join tr in _tRRepository.Find(u => u.VISITNUM == 1 && u.STUDYID == trialCode
|
||
&& u.USUBJID == SubjectCode && u.TREVALID == _userInfo.ReviewerCode)
|
||
on tu.TULNKID equals tr.TRLNKID into temp
|
||
from tr in temp.DefaultIfEmpty()
|
||
select new LesionInformation
|
||
{
|
||
TUId = tu.Id,
|
||
LesionType = tu.LesionType,
|
||
TULNKID = tu.TULNKID,
|
||
TUSEQ = tu.TUSEQ,
|
||
TULOC = tu.TULOC,
|
||
LocDescription = tu.LocDescription,
|
||
TULAT = tu.TULAT,
|
||
TUDIR = tu.TUDIR,
|
||
TUPORTOT = tu.TUPORTOT,
|
||
TRORRES = tr.TRORRES,
|
||
VISITNUM = tu.VISITNUM,
|
||
Note = tr.Note
|
||
};
|
||
return query.ToList();
|
||
}
|
||
|
||
public BaseLineReportDTO GetBaseLineReport(string trialCode, string subjectCode, string tpCode)
|
||
{
|
||
var tpcodeGroup = tpCode.Substring(tpCode.Length - 3, 3);
|
||
var report = _reportRepository.FindSingleOrDefault(u => u.TrialCode == trialCode && u.SubjectCode == subjectCode && u.VisitNum == 1); ;
|
||
|
||
BaseLineReportDTO result = new BaseLineReportDTO
|
||
{
|
||
LesionInformation = GetBLLesion(trialCode, subjectCode, tpcodeGroup).Where(u => u.VISITNUM == 1).ToList(),
|
||
ReportResult = _mapper.Map<ReportDTO>(report)
|
||
};
|
||
return result;
|
||
}
|
||
public VisitLesionInfo GetVisitLesion(string trialCode, string subjectCode, decimal visitNum, string tpCode)
|
||
{
|
||
var tpcodeGroup = tpCode.Substring(tpCode.Length - 3, 3);
|
||
VisitLesionInfo visitLesionInfo = new VisitLesionInfo();
|
||
var blLesionList = GetBLLesion(trialCode, subjectCode, tpcodeGroup);
|
||
int[] t = { 1, 2, 3 };
|
||
var query = from tu in _tURepository.Find(u => u.STUDYID == trialCode && u.USUBJID == subjectCode && u.TpCode.Contains(tpcodeGroup) /*u.TUEVALID == _userInfo.ReviewerCode*/)
|
||
join tr in _tRRepository.Find(u => u.VISITNUM == visitNum && u.STUDYID == trialCode && u.USUBJID == subjectCode && u.TpCode.Contains(tpcodeGroup))
|
||
on tu.TULNKID equals tr.TRLNKID into temp
|
||
from tr in temp.DefaultIfEmpty()
|
||
select new LesionInformation
|
||
{
|
||
TUId = tu.Id,
|
||
TUSEQ = tu.TUSEQ,
|
||
TULOC = tu.TULOC,
|
||
LesionType = tu.LesionType,
|
||
TULNKID = tu.TULNKID,
|
||
LocDescription = tu.LocDescription,
|
||
TULAT = tu.TULAT,
|
||
TUDIR = tu.TUDIR,
|
||
TUPORTOT = tu.TUPORTOT,
|
||
TRORRESU = tr.TRORRESU,
|
||
TRORRES = tr.TRORRES,
|
||
Note = tr.Note,
|
||
CoveredLesion = tr.CoveredLesion,
|
||
VISITNUM = tr.VISITNUM
|
||
};
|
||
var list = query.ToList();
|
||
var currentVisitLesion = list.Where(u => t.Contains(u.LesionType) && u.VISITNUM == visitNum).ToList();
|
||
foreach (var item in blLesionList)
|
||
{
|
||
var temp = _mapper.Map<VisitLesion>(item);
|
||
temp.CurrentLesion = currentVisitLesion.Where(u => u.STUDYID == item.STUDYID
|
||
&& u.USUBJID == item.USUBJID && u.TUEVAL == item.TUEVAL
|
||
&& u.TULNKID == item.TULNKID).FirstOrDefault() ?? new LesionInformation();
|
||
visitLesionInfo.BLLesionList.Add(temp);
|
||
}
|
||
|
||
List<Guid> blIdList = blLesionList.Select(u => u.TUId).ToList();
|
||
List<Guid> visitIdList = currentVisitLesion.Where(u => t.Contains(u.LesionType)).Select(u => u.TUId).ToList();
|
||
var visitLesion = visitIdList.Except(blIdList);
|
||
|
||
foreach (var item in visitLesion)
|
||
{
|
||
VisitLesion tempLesion = new VisitLesion();
|
||
tempLesion.CurrentLesion = currentVisitLesion.Where(u => u.TUId == item).FirstOrDefault() ?? new LesionInformation();
|
||
tempLesion.LesionType = tempLesion.CurrentLesion.LesionType;
|
||
tempLesion.TUSEQ = tempLesion.CurrentLesion.TUSEQ;
|
||
visitLesionInfo.BLLesionList.Add(tempLesion);
|
||
}
|
||
// 以往新病灶,病灶类型为5,且访视编号小于当前访视,且不是基线
|
||
var previousLesion = list.Where(u => u.VISITNUM < visitNum && u.VISITNUM != 1 && u.LesionType == 5).ToList();
|
||
foreach (var item in previousLesion)
|
||
{
|
||
var temp = _mapper.Map<VisitLesion>(item);
|
||
temp.CurrentLesion = currentVisitLesion.Where(u => u.TULNKID==item.TULNKID && u.STUDYID == item.STUDYID && u.USUBJID == item.USUBJID && u.TUEVAL == item.TUEVAL).FirstOrDefault() ?? new LesionInformation();
|
||
visitLesionInfo.PreviousNewLesionList.Add(temp);
|
||
}
|
||
|
||
visitLesionInfo.EquivocalNewLesionList = list.Where(u => u.VISITNUM <= visitNum && u.LesionType == 4).ToList();
|
||
visitLesionInfo.UnequivocalNewLesionList = list.Where(u => u.VISITNUM == visitNum && u.LesionType == 5).ToList();
|
||
|
||
var report = _reportRepository.FindSingleOrDefault(u => u.TrialCode == trialCode && u.SubjectCode == subjectCode && u.VisitNum == visitNum); ;
|
||
visitLesionInfo.ReportResult = _mapper.Map<ReportDTO>(report);
|
||
|
||
var rs = _rSRepository.Find(u => u.STUDYID == trialCode && u.USUBJID == subjectCode
|
||
&& u.RSEVALID == _userInfo.ReviewerCode && u.VISITNUM == visitNum);
|
||
|
||
var target = rs.FirstOrDefault(u => u.RSTESTCD == "TRGRESP");
|
||
var non_target = rs.FirstOrDefault(u => u.RSTESTCD == "NTRGRESP");
|
||
var overall = rs.FirstOrDefault(u => u.RSTESTCD == "OVRLRESP");
|
||
|
||
visitLesionInfo.Efficacy = new EfficacyAssessment
|
||
{
|
||
|
||
TargetLesion = target?.RSORRES,
|
||
TargetLesionNote = target?.Note,
|
||
Non_targetLesion = non_target?.RSORRES,
|
||
Non_targetLesionNote = non_target?.Note,
|
||
OverallAssessment = overall?.RSORRES,
|
||
OverallAssessmentNote = overall?.Note
|
||
};
|
||
|
||
var preRS = _rSRepository.Find(u => u.STUDYID == trialCode && u.USUBJID == subjectCode
|
||
&& u.VISITNUM < visitNum && u.RSTESTCD == "OVRLRESP"
|
||
&& u.RSEVAL == _userInfo.ReviewerCode /*&& u.VISITNUM == visitNum*/)
|
||
.Select(u => new PreviousOverallAssessment
|
||
{
|
||
VisitName = u.VISIT,
|
||
OverallAssessment = u.RSORRES
|
||
}).ToList();
|
||
visitLesionInfo.PreviousOverallAssessment = preRS;
|
||
|
||
var targetList = _tRRepository.Find(u => (!string.IsNullOrWhiteSpace(u.TRLNKID)) && (!u.TRLNKID.Contains("N")) && u.STUDYID == trialCode &&
|
||
u.USUBJID == subjectCode && u.TpCode.Contains(tpcodeGroup) && u.VISITNUM < visitNum).ToList();
|
||
|
||
var q = from ttt in targetList
|
||
group ttt by ttt.VISIT into s
|
||
select new MinVisit
|
||
{
|
||
MinSum = s.Sum(p => p.TRORRES_Double),
|
||
MinVistName = s.Key
|
||
};
|
||
var tempList = q.ToList();
|
||
MinVisit min = new MinVisit();
|
||
if (tempList.Count>0)
|
||
{
|
||
min = tempList.FirstOrDefault();
|
||
}
|
||
foreach (var item in tempList)
|
||
{
|
||
if (min.MinSum > item.MinSum)
|
||
{
|
||
min = item;
|
||
}
|
||
}
|
||
visitLesionInfo.MinVisitInfo = min;
|
||
|
||
return visitLesionInfo;
|
||
}
|
||
|
||
public bool SubmiteReport(Guid tpId)
|
||
{
|
||
// 提交报告 同时查询VisitStage(项目访视计划,看是否需要添加全局)
|
||
|
||
var query = from workloadTp in _workloadTPRepository.GetAll().Where(u => u.Id == tpId)
|
||
join subjectVisit in _subjectVisitRepository.GetAll()
|
||
on workloadTp.SubjectVisitId equals subjectVisit.Id
|
||
join visitStage in _visitStageRepository.GetAll()
|
||
on new { workloadTp.TrialId, subjectVisit.VisitNum } equals new { visitStage.TrialId, visitStage.VisitNum }
|
||
select new
|
||
{
|
||
WorkloadTp = workloadTp,
|
||
VisitNum = subjectVisit.VisitNum,
|
||
VisitName = subjectVisit.VisitName,
|
||
NeedGlobal = visitStage.NeedGlobal
|
||
};
|
||
var workload = query.ToList().FirstOrDefault();
|
||
if (workload != null)
|
||
{
|
||
if (workload.NeedGlobal)// 需要产生全局
|
||
{
|
||
var group = workload.WorkloadTp.TimepointCode.Substring(workload.WorkloadTp.TimepointCode.Length - 2, 2);
|
||
_workloadGlobalRepository.Add(new WorkloadGlobal
|
||
{
|
||
GlobalCode = workload.WorkloadTp.TimepointCode + "G" + group,
|
||
ReviewerId = Guid.Empty,
|
||
SiteId = workload.WorkloadTp.SiteId,
|
||
Status = -1,
|
||
SubjectId = workload.WorkloadTp.SubjectId,
|
||
TrialId = workload.WorkloadTp.TrialId,
|
||
VisitId = workload.WorkloadTp.SubjectVisitId,
|
||
VisitNum = workload.VisitNum,
|
||
VisitName = workload.VisitName,
|
||
UpdateTime = DateTime.Now
|
||
});
|
||
}
|
||
}
|
||
return _workloadTPRepository.Update(u => u.Id == tpId, s => new WorkloadTP
|
||
{
|
||
Status = (int)WorkloadStatus.ReviewFinish
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存基线期报告(病灶及测量数据,扩展报告的信息)
|
||
/// </summary>
|
||
/// <param name="baseLineReportCommand"></param>
|
||
/// <returns></returns>
|
||
public bool SaveBLReport(BaseLineReportCommand baseLineReportCommand)
|
||
{
|
||
if (baseLineReportCommand.LesionInformation.Count < 1) return false;
|
||
|
||
var addedLesion = baseLineReportCommand.LesionInformation[0];
|
||
|
||
//删除已经有的数据
|
||
_tURepository.Delete(u => u.VISITNUM == addedLesion.VISITNUM && u.USUBJID == addedLesion.USUBJID && u.TUEVALID == _userInfo.ReviewerCode);
|
||
_tRRepository.Delete(u => u.VISITNUM == addedLesion.VISITNUM && u.USUBJID == addedLesion.USUBJID && u.TREVALID == _userInfo.ReviewerCode);
|
||
_reportRepository.Delete(u => u.TPId == baseLineReportCommand.ReportResult.TPId);
|
||
|
||
_workloadTPRepository.Update(u => u.Id == baseLineReportCommand.ReportResult.TPId, s => new WorkloadTP
|
||
{
|
||
Status = (int)WorkloadStatus.Reading
|
||
});
|
||
|
||
//序号按照每个项目、每个受试者、每个评估者,一条记录
|
||
TU lastTu = _tURepository.Find(u => u.STUDYID == addedLesion.STUDYID && u.USUBJID == addedLesion.USUBJID
|
||
&& u.TUEVAL == addedLesion.TUEVAL).OrderByDescending("TUSEQ").FirstOrDefault();
|
||
int tuSeq = 101;
|
||
if (lastTu != null) { tuSeq = lastTu.TUSEQ; }
|
||
TR lastTr = _tRRepository.GetAll().OrderByDescending("TRSEQ").FirstOrDefault();
|
||
int trSeq = 1;
|
||
if (lastTr != null) { trSeq = lastTr.TRSEQ; }
|
||
|
||
linkGroupId = Guid.NewGuid().ToString();
|
||
foreach (var lesion in baseLineReportCommand.LesionInformation)
|
||
{
|
||
var linkId = lesion.TULNKID;
|
||
if (string.IsNullOrWhiteSpace(lesion.TULNKID))
|
||
{
|
||
linkId = (lesion.TUORRES == "TARGET") ? "T" + tuSeq.ToString() : "NT" + tuSeq.ToString();
|
||
}
|
||
_tURepository.Add(new TU
|
||
{
|
||
STUDYID = lesion.STUDYID,
|
||
LesionType = lesion.LesionType,
|
||
USUBJID = lesion.USUBJID,
|
||
TUSEQ = tuSeq,
|
||
TULNKID = linkId,
|
||
|
||
TUTESTCD = lesion.TUTESTCD,
|
||
TUTEST = lesion.TUTEST,
|
||
TUORRES = lesion.TUORRES,
|
||
TUSTRESC = lesion.TUSTRESC,
|
||
|
||
TULOC = lesion.TULOC,
|
||
LocDescription = lesion.LocDescription,
|
||
TULAT = lesion.TULAT,
|
||
TUDIR = lesion.TUDIR,
|
||
TUPORTOT = lesion.TUPORTOT,
|
||
TUMETHOD = lesion.TUMETHOD,
|
||
TUEVAL = lesion.TUEVAL,
|
||
VISIT = lesion.VISIT,
|
||
VISITNUM = lesion.VISITNUM,
|
||
VISITDY = lesion.VISITDY,
|
||
|
||
TUREFID = lesion.TUREFID,
|
||
TUACPTFL = lesion.TUACPTFL,
|
||
TUEVALID = _userInfo.ReviewerCode,//lesion.TUEVALID,
|
||
TUGRPID = string.Empty,
|
||
TUDY = lesion.TUDY,// 检查日
|
||
EPOCH = lesion.EPOCH,
|
||
TUDTC = lesion.TUDTC,
|
||
TUNAM = lesion.TUNAM,
|
||
TUSPID = lesion.TUSPID,
|
||
|
||
TpCode = baseLineReportCommand.ReportResult.TpCode
|
||
});
|
||
_tRRepository.Add(new TR
|
||
{
|
||
STUDYID = lesion.STUDYID,
|
||
|
||
USUBJID = lesion.USUBJID,
|
||
TRSEQ = trSeq,
|
||
TRLNKID = linkId,
|
||
TRGRPID = lesion.TRGRPID,
|
||
TRLNKGRP = linkGroupId,
|
||
|
||
TRTESTCD = lesion.TRTESTCD,
|
||
TRTEST = lesion.TRTEST,
|
||
TRORRES = lesion.TRORRES,
|
||
TRORRESU = lesion.TRORRESU,
|
||
|
||
TRNAM = lesion.TUNAM,
|
||
TRMETHOD = lesion.TUMETHOD,
|
||
TREVAL = lesion.TUEVAL,
|
||
TREVALID = _userInfo.ReviewerCode,//lesion.TUEVALID,
|
||
TRACPTFL = lesion.TUACPTFL,
|
||
|
||
Note = lesion.Note,
|
||
|
||
VISITNUM = lesion.VISITNUM,
|
||
VISIT = lesion.VISIT,
|
||
VISITDY = lesion.VISITDY,
|
||
EPOCH = lesion.EPOCH,
|
||
TRDTC = lesion.TRDTC,
|
||
TRDY = lesion.TRDY,
|
||
TpCode = baseLineReportCommand.ReportResult.TpCode
|
||
});
|
||
tuSeq++;
|
||
trSeq++;
|
||
}
|
||
|
||
_tRRepository.Add(new TR
|
||
{
|
||
STUDYID = addedLesion.STUDYID,
|
||
|
||
USUBJID = addedLesion.USUBJID,
|
||
TRSEQ = trSeq,
|
||
TRLNKID = string.Empty,
|
||
TRGRPID = addedLesion.TRGRPID,
|
||
TRLNKGRP = linkGroupId,
|
||
|
||
TRTESTCD = addedLesion.TRTESTCD,
|
||
TRTEST = "Sum of Diameter",
|
||
TRORRES = baseLineReportCommand.SumOfDiameter,
|
||
TRORRESU = "mm",//addedLesion.TRORRESU,
|
||
|
||
TRNAM = addedLesion.TUNAM,
|
||
TRMETHOD = addedLesion.TUMETHOD,
|
||
TREVAL = addedLesion.TUEVAL,
|
||
TREVALID = _userInfo.ReviewerCode,//addedLesion.TUEVALID,
|
||
TRACPTFL = addedLesion.TUACPTFL,
|
||
|
||
Note = string.Empty,
|
||
|
||
VISITNUM = addedLesion.VISITNUM,
|
||
VISIT = addedLesion.VISIT,
|
||
VISITDY = addedLesion.VISITDY,
|
||
EPOCH = addedLesion.EPOCH,
|
||
TRDTC = addedLesion.TRDTC,
|
||
TRDY = addedLesion.TRDY,
|
||
TpCode = baseLineReportCommand.ReportResult.TpCode
|
||
});
|
||
trSeq++;
|
||
_tRRepository.Add(new TR
|
||
{
|
||
STUDYID = addedLesion.STUDYID,
|
||
|
||
USUBJID = addedLesion.USUBJID,
|
||
TRSEQ = trSeq,
|
||
TRLNKID = string.Empty,
|
||
TRGRPID = addedLesion.TRGRPID,
|
||
TRLNKGRP = linkGroupId,
|
||
|
||
TRTESTCD = addedLesion.TRTESTCD,
|
||
TRTEST = "Sum Diameters of Non Lymph Node Tumors",
|
||
TRORRES = baseLineReportCommand.SumDiameterOfNonLymphNode,
|
||
TRORRESU = "mm",//addedLesion.TRORRESU,
|
||
|
||
TRNAM = addedLesion.TUNAM,
|
||
TRMETHOD = addedLesion.TUMETHOD,
|
||
TREVAL = addedLesion.TUEVAL,
|
||
TREVALID = _userInfo.ReviewerCode,//addedLesion.TUEVALID,
|
||
TRACPTFL = addedLesion.TUACPTFL,
|
||
|
||
Note = string.Empty,
|
||
|
||
VISITNUM = addedLesion.VISITNUM,
|
||
VISIT = addedLesion.VISIT,
|
||
VISITDY = addedLesion.VISITDY,
|
||
EPOCH = addedLesion.EPOCH,
|
||
TRDTC = addedLesion.TRDTC,
|
||
TRDY = addedLesion.TRDY,
|
||
TpCode = baseLineReportCommand.ReportResult.TpCode
|
||
});
|
||
trSeq++;
|
||
_reportRepository.Add(_mapper.Map<Report>(baseLineReportCommand.ReportResult));
|
||
|
||
return _reportRepository.SaveChanges();
|
||
}
|
||
|
||
public bool SaveVisitReport(VisitReportCommand visitReportCommand)
|
||
{
|
||
linkGroupId = Guid.NewGuid().ToString();
|
||
var visitNum = visitReportCommand.ReportResult.VisitNum;
|
||
var subjectId = visitReportCommand.ReportResult.SubjectCode;
|
||
|
||
//删除已经有的数据
|
||
_tURepository.Delete(u => u.VISITNUM == visitNum && u.USUBJID == subjectId && u.TUEVALID == _userInfo.ReviewerCode);
|
||
_tRRepository.Delete(u => u.VISITNUM == visitNum && u.USUBJID == subjectId && u.TREVALID == _userInfo.ReviewerCode);
|
||
_reportRepository.Delete(u => u.TPId == visitReportCommand.ReportResult.TPId);
|
||
_rSRepository.Delete(u => u.VISITNUM == visitNum && u.RSEVALID == _userInfo.ReviewerCode);
|
||
|
||
var report = visitReportCommand.ReportResult;
|
||
|
||
_workloadTPRepository.Update(u => u.Id == report.TPId, s => new WorkloadTP
|
||
{
|
||
Status = (int)WorkloadStatus.Reading
|
||
});
|
||
if (visitReportCommand.LesionInformation.Count > 0)
|
||
{
|
||
AddLesion(visitReportCommand.LesionInformation, report);
|
||
}
|
||
|
||
TR lastTr = _tRRepository.GetAll().OrderByDescending("TRSEQ").FirstOrDefault();
|
||
int trSeq = 1;
|
||
if (lastTr != null) { trSeq = lastTr.TRSEQ + 1; }
|
||
|
||
foreach (var lesion in visitReportCommand.TRList)
|
||
{
|
||
_tRRepository.Add(new TR
|
||
{
|
||
STUDYID = lesion.STUDYID,
|
||
|
||
USUBJID = lesion.USUBJID,
|
||
TRSEQ = trSeq,
|
||
TRLNKID = lesion.TRLNKID,
|
||
TRGRPID = lesion.TRGRPID,
|
||
TRLNKGRP = linkGroupId,
|
||
|
||
TRTESTCD = lesion.TRTESTCD,
|
||
TRTEST = lesion.TRTEST,
|
||
TRORRES = lesion.TRORRES,
|
||
TRORRESU = lesion.TRORRESU,
|
||
|
||
TRNAM = lesion.TRNAM,
|
||
TRMETHOD = lesion.TRMETHOD,
|
||
TREVAL = lesion.TREVAL,
|
||
TREVALID = _userInfo.ReviewerCode,// lesion.TREVALID,
|
||
TRACPTFL = lesion.TRACPTFL,
|
||
|
||
Note = lesion.Note,
|
||
CoveredLesion = lesion.CoveredLesion,
|
||
VISITNUM = lesion.VISITNUM,
|
||
VISIT = lesion.VISIT,
|
||
VISITDY = lesion.VISITDY,
|
||
EPOCH = lesion.EPOCH,
|
||
TRDTC = lesion.TRDTC,
|
||
TRDY = lesion.TRDY,
|
||
TpCode = visitReportCommand.ReportResult.TpCode
|
||
});
|
||
trSeq++;
|
||
}
|
||
foreach (var rs in visitReportCommand.RSList)
|
||
{
|
||
_rSRepository.Add(new RS
|
||
{
|
||
STUDYID = rs.STUDYID,
|
||
USUBJID = rs.USUBJID,
|
||
RSSEQ = 0,//
|
||
RSLNKGRP = linkGroupId,
|
||
RSTESTCD = rs.RSTESTCD,
|
||
RSTEST = rs.RSTEST,
|
||
RSCAT = rs.RSCAT,
|
||
RSORRES = rs.RSORRES,
|
||
RSSTRESC = rs.RSSTRESC,
|
||
RSSTAT = rs.RSSTAT,
|
||
RSREASND = rs.RSCAT,
|
||
RSEVAL = rs.RSEVAL,
|
||
RSEVALID = _userInfo.ReviewerCode,//
|
||
VISITNUM = rs.VISITNUM,
|
||
VISIT = rs.VISIT,
|
||
RSDTC = rs.RSDTC,
|
||
RSDY = rs.RSDY,
|
||
TpCode = visitReportCommand.ReportResult.TpCode,
|
||
StudyGuid = rs.StudyGuid,
|
||
TrialGuid = rs.TrialGuid,
|
||
SubjectGuid = rs.SubjectGuid,
|
||
Note = rs.Note
|
||
});
|
||
}
|
||
|
||
_reportRepository.Add(_mapper.Map<Report>(visitReportCommand.ReportResult));
|
||
|
||
return _rSRepository.SaveChanges();
|
||
}
|
||
}
|
||
}
|