196 lines
8.8 KiB
C#
196 lines
8.8 KiB
C#
using IRaCIS.Core.Application.Contracts;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Dynamic.Core;
|
|
using AutoMapper;
|
|
using IRaCIS.Application.ViewModels;
|
|
using IRaCIS.Core.Domain.Interfaces;
|
|
using IRaCIS.Core.Domain.Models;
|
|
|
|
namespace IRaCIS.Core.Application
|
|
{
|
|
public class GlobalService : IGlobalService
|
|
{
|
|
private readonly IGlobalRSRepository _globalRsRepository;
|
|
private readonly IGlobalResultRepository _globalResultRepository;
|
|
private readonly IRSRepository _rsRepository;
|
|
private readonly IVisitStageRepository _visitStageRepository;
|
|
private readonly IMapper _mapper;
|
|
private readonly ISubjectVisitRepository _subjectVisitRepository;
|
|
private readonly IWorkloadADRepository _workloadAdRepository;
|
|
private readonly IWorkloadGlobalRepository _workloadGlobalRepository;
|
|
private readonly ITrialRepository _trialRepository;
|
|
private readonly ISubjectRepository _subjectRepository;
|
|
|
|
public GlobalService(IGlobalRSRepository globalRsRepository, IGlobalResultRepository globalResultRepository,
|
|
IRSRepository rsRepository, IVisitStageRepository visitStageRepository, IMapper mapper, ISubjectVisitRepository subjectVisitRepository, IWorkloadADRepository workloadAdRepository,
|
|
IWorkloadGlobalRepository workloadGlobalRepository, ITrialRepository trialRepository, ISubjectRepository subjectRepository)
|
|
{
|
|
_globalRsRepository = globalRsRepository;
|
|
_globalResultRepository = globalResultRepository;
|
|
_rsRepository = rsRepository;
|
|
_visitStageRepository = visitStageRepository;
|
|
_mapper = mapper;
|
|
_subjectVisitRepository = subjectVisitRepository;
|
|
_workloadAdRepository = workloadAdRepository;
|
|
_workloadGlobalRepository = workloadGlobalRepository;
|
|
_trialRepository = trialRepository;
|
|
_subjectRepository = subjectRepository;
|
|
}
|
|
|
|
|
|
public IEnumerable<HistoryVisitRSDTO> GetHistoryVisitRsList(Guid trialId, Guid subjectId, decimal visitNum, Guid globalId, string globalCode)
|
|
{
|
|
|
|
var tpGroup = 'T' + globalCode.Trim().Substring(globalCode.Trim().Length - 2);
|
|
|
|
|
|
var query = from rs in _rsRepository.GetAll()
|
|
.Where(t => t.SubjectGuid == subjectId && t.TrialGuid == trialId && t.RSTESTCD == "OVRLRESP" && t.VISITNUM <= visitNum && t.TpCode.Contains(tpGroup))
|
|
|
|
join globalRs in _globalRsRepository.GetAll().Where(t => t.GlobalId == globalId) on new { rs.TpCode, VisitNum = rs.VISITNUM } equals new { globalRs.TpCode, globalRs.VisitNum } into cc
|
|
from globalRs in cc.DefaultIfEmpty()
|
|
|
|
join visitStage in _visitStageRepository.GetAll().Where(t => t.TrialId == trialId) on rs.VISITNUM equals visitStage.VisitNum
|
|
select new HistoryVisitRSDTO
|
|
{
|
|
StudyId = rs.StudyGuid,
|
|
StudyCode = rs.STUDYID,
|
|
VisitNum = visitStage.VisitNum,
|
|
VisitName = visitStage.VisitName,
|
|
OverallResponse = rs.RSORRES,
|
|
TpCode = rs.TpCode,
|
|
GlobalRSSelect = new GlobalRSSelectView()
|
|
{
|
|
Agree = globalRs.Agree,
|
|
NewRS = globalRs.NewRS,
|
|
Note = globalRs.Note
|
|
}
|
|
};
|
|
|
|
var visitRsList = query.OrderBy(t => t.VisitNum).ToList();
|
|
|
|
return visitRsList;
|
|
|
|
}
|
|
|
|
public PreviousGlobalReadsView GetHistoryGlobalRsList(Guid trialId, Guid subjectId, decimal visitNum,
|
|
Guid globalId)
|
|
{
|
|
//subjectCode = subjectCode.Trim();
|
|
|
|
var query = from globalResult in _globalResultRepository.GetAll()
|
|
.Where(t => t.SubjectId == subjectId && t.VisitNum < visitNum)
|
|
join visitStage in _visitStageRepository.GetAll().Where(t => t.TrialId == trialId) on globalResult.VisitNum equals visitStage.VisitNum
|
|
select new HistoryGlobalRsDTO
|
|
{
|
|
VisitNum = visitStage.VisitNum,
|
|
VisitName = visitStage.VisitName,
|
|
OverallResponse = globalResult.Result
|
|
};
|
|
|
|
var subjectNote = _globalResultRepository.GetAll().FirstOrDefault(t => t.GlobalId == globalId)?.SubjectNote;
|
|
|
|
return new PreviousGlobalReadsView()
|
|
{
|
|
PreviousGlobalReadsList = query.ToList(),
|
|
SubjectNote = subjectNote
|
|
};
|
|
|
|
}
|
|
|
|
public bool AddGlobalReport(GlobalTaskReportCommand globalTaskReportCommand)
|
|
{
|
|
//删除上一次保存得记录
|
|
_globalResultRepository.Delete(t => t.GlobalId == globalTaskReportCommand.GlobalId);
|
|
_globalRsRepository.Delete(t => t.GlobalId == globalTaskReportCommand.GlobalId);
|
|
|
|
|
|
var globalRsList = _mapper.Map<List<GlobalRS>>(globalTaskReportCommand.GlobalRSReportList);
|
|
|
|
_globalRsRepository.AddRange(globalRsList);
|
|
|
|
var first = globalRsList.OrderByDescending(t => t.VisitNum).First();
|
|
|
|
var globalResult = new GlobalResult()
|
|
{
|
|
VisitNum = first.VisitNum,
|
|
SubjectCode = globalTaskReportCommand.SubjectCode,
|
|
SubjectNote = globalTaskReportCommand.SubjectNote,
|
|
SubjectId = globalTaskReportCommand.SubjectId,
|
|
|
|
GlobalId = first.GlobalId,
|
|
Result = first.NewRS
|
|
};
|
|
|
|
_globalResultRepository.Add(globalResult);
|
|
|
|
return _globalResultRepository.SaveChanges();
|
|
|
|
}
|
|
|
|
//public string GetCommentsForSubject(Guid globalId)
|
|
//{
|
|
// return _globalResultRepository.GetAll().FirstOrDefault(t => t.GlobalId == globalId)?.SubjectNote;
|
|
//}
|
|
|
|
public AdReportDTO GetAdReport(Guid adId)
|
|
{
|
|
var adReport = new AdReportDTO();
|
|
var ad = _workloadAdRepository.GetAll().First(t => t.Id == adId);
|
|
var globalId1 = ad.Global1Id;
|
|
var globalId2 = ad.Global2Id;
|
|
|
|
var query = from global in _workloadGlobalRepository.GetAll().Where(t => t.Id == globalId1 || t.Id == globalId2)
|
|
join trial in _trialRepository.GetAll().Where(t => t.Id == ad.TrialId) on global.TrialId equals trial.Id
|
|
join subject in _subjectRepository.GetAll() on global.SubjectId equals subject.Id
|
|
select new WorkloadReadingDTO
|
|
{
|
|
Id = global.Id,
|
|
WorkloadId = global.Id,
|
|
WorkloadType = 1,
|
|
Status = global.Status,
|
|
UpdateTime = global.UpdateTime,
|
|
TrialId = global.TrialId,
|
|
SubjectId = global.SubjectId,
|
|
SubjectCode = subject.Code,
|
|
//VisitNum = visit.VisitNum,
|
|
//VisitName = visit.VisitName,
|
|
VisitNum = global.VisitNum,
|
|
VisitName = global.VisitName,
|
|
|
|
Expedited = trial.Expedited,
|
|
TrialCode = trial.Code,
|
|
TrialIndication = trial.Indication,
|
|
WorkloadCode = global.GlobalCode
|
|
};
|
|
|
|
var globalList = query.ToList();
|
|
|
|
var global1 = globalList.First(t => t.Id == globalId1);
|
|
var global2 = globalList.First(t => t.Id == globalId2);
|
|
|
|
adReport.Global1VisitRS = GetHistoryVisitRsList(global1.TrialId, global1.SubjectId,
|
|
global1.VisitNum, global1.Id, global1.WorkloadCode);
|
|
|
|
adReport.Global2VisitRS = GetHistoryVisitRsList(global2.TrialId, global2.SubjectId
|
|
,global2.VisitNum, global2.Id, global2.WorkloadCode);
|
|
|
|
adReport.Global1 = GetHistoryGlobalRsList(global1.TrialId, global1.SubjectId, global1.VisitNum, global1.Id);
|
|
adReport.Global2 = GetHistoryGlobalRsList(global2.TrialId, global2.SubjectId, global2.VisitNum, global2.Id);
|
|
|
|
adReport.ADInfo = ad;
|
|
|
|
return adReport;
|
|
|
|
}
|
|
|
|
public bool AddAdjudicationReport(ADReportCommand adReportCommand)
|
|
{
|
|
return _workloadAdRepository.Update(t => t.Id == adReportCommand.AdId,
|
|
u => new WorkloadAD()
|
|
{AdNote = adReportCommand.ADNote, SelectGlobalId = adReportCommand.SelectGlobalId});
|
|
}
|
|
}
|
|
} |