160 lines
6.9 KiB
C#
160 lines
6.9 KiB
C#
using AutoMapper;
|
|
using IRaCIS.Application.ExpressionExtend;
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Application.ViewModels;
|
|
using IRaCIS.Core.Application.Contracts.RequestAndResponse;
|
|
using IRaCIS.Domain.Interfaces;
|
|
using IRaCIS.Domain.Models;
|
|
using IRaCIS.Infra.Data.ExpressionExtend;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace IRaCIS.Application.Services
|
|
{
|
|
public class ImageService : IImageService
|
|
{
|
|
private readonly IImageRepository _imageRepository;
|
|
private readonly ISubjectRepository _subjectsRepository;
|
|
private readonly IDicomStudyRepository _visitPointRepository;
|
|
private readonly IMapper _mapper;
|
|
private readonly IVisitStageRepository _visitPlanRepository;
|
|
private readonly ISiteRepository _siteRepository;
|
|
public ImageService(IImageRepository imageRepository,
|
|
ISubjectRepository subjectsRepository,
|
|
IVisitStageRepository trialInterviewRepository,
|
|
ISiteRepository centerRepository,
|
|
IDicomStudyRepository visitPointRepository, IMapper mapper)
|
|
{
|
|
_imageRepository = imageRepository;
|
|
_subjectsRepository = subjectsRepository;
|
|
_visitPlanRepository = trialInterviewRepository;
|
|
_siteRepository = centerRepository;
|
|
_visitPointRepository = visitPointRepository;
|
|
_mapper = mapper;
|
|
}
|
|
public IResponseOutput AddImage(ImageCommand model, Guid userId)
|
|
{
|
|
//更新受试者访视阶段
|
|
var subject = _subjectsRepository.GetAll().FirstOrDefault(t => t.Id == model.SubjectId);
|
|
subject.VisitStageId = model.VisitStageId;
|
|
|
|
_subjectsRepository.Update(subject);
|
|
|
|
//添加受试者访视点
|
|
var visitPoint = new DicomStudy()
|
|
{
|
|
VisitStageId = model.VisitStageId,
|
|
|
|
SubjectId = model.SubjectId,
|
|
StudyCode = string.Empty
|
|
};
|
|
|
|
_visitPointRepository.Add(visitPoint);
|
|
|
|
//添加影像记录
|
|
var image = _mapper.Map<ImageRecord>(model);
|
|
|
|
image.State = 1;
|
|
//image.StudyId=Guid.Empty;
|
|
image.StudyDate=DateTime.Now;
|
|
image.Modalities = string.Empty;
|
|
//image.StudyId= visitPoint.Id;
|
|
|
|
|
|
var last = _imageRepository.Find(u => u.TrialId == model.TrialId).OrderByDescending(c => c.ImageNo).FirstOrDefault();
|
|
if (last != null)
|
|
{
|
|
var num = 0;
|
|
var len = last.ImageNo.Length;
|
|
if (len > 4 && int.TryParse(last.ImageNo.Substring(len - 4, 4), out num))
|
|
{
|
|
image.ImageNo = "I" + model.TrialCode + (++num).ToString().PadLeft(4, '0');
|
|
}
|
|
else
|
|
{
|
|
return ResponseOutput.NotOk("Generated Code failed.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
image.ImageNo = "I" + model.TrialCode + 1.ToString().PadLeft(4, '0');
|
|
}
|
|
|
|
|
|
var result = _imageRepository.Add(image);
|
|
bool isSuccess = _imageRepository.SaveChanges();
|
|
return ResponseOutput.Result(isSuccess, result.Id.ToString());
|
|
}
|
|
public IResponseOutput DeleteImage(Guid id)
|
|
{
|
|
var result = _imageRepository.Delete(u => u.Id == id);
|
|
return ResponseOutput.Result(result);
|
|
}
|
|
//public PageOutput<ImageDetailDTO> GetImageList(ImageQueryDTO param)
|
|
//{
|
|
//Expression<Func<ImageRecord, bool>> imageLambda = x => true;
|
|
//if (param.State != 0)
|
|
//{
|
|
// imageLambda = imageLambda.And(t => t.State == param.State);
|
|
//}
|
|
//Expression<Func<Subject, bool>> subjectlambda = x => true;
|
|
//if (!string.IsNullOrWhiteSpace(param.SubjectCode))
|
|
//{
|
|
// subjectlambda = subjectlambda.And(t => t.Code.Contains(param.SubjectCode));
|
|
//}
|
|
|
|
//Expression<Func<VisitStage, bool>> visitStageLambda = x => true;
|
|
//visitStageLambda = visitStageLambda.And(t => t.TrialId == param.TrialId);
|
|
//if (param.VisitStageId != Guid.Empty)
|
|
//{
|
|
// visitStageLambda = visitStageLambda.And(t => t.Id == param.VisitStageId);
|
|
//}
|
|
|
|
//var query = from image in _imageRepository.Find(imageLambda).Where(u => u.TrialId == param.TrialId)
|
|
// join subject in _subjectsRepository.Find(subjectlambda)
|
|
// on image.SubjectId equals subject.Id
|
|
// join visitPoint in _visitPointRepository.Find()
|
|
// on image.StudyId equals visitPoint.Id //into d
|
|
// //from visitPointItem in d.DefaultIfEmpty()
|
|
// join visitPlan in _visitPlanRepository.Find(visitStageLambda)
|
|
// on visitPoint.VisitStageId equals visitPlan.Id //into e
|
|
// //from visitPlanItem in e.DefaultIfEmpty()
|
|
// join center in _siteRepository.GetAll()
|
|
// on image.SiteId equals center.Id
|
|
// select new ImageDetailDTO
|
|
// {
|
|
// Id = image.Id,
|
|
// TrialId = image.TrialId,
|
|
// SubjectId = subject == null ? Guid.Empty : subject.Id,
|
|
// StudyId = visitPoint == null ? Guid.Empty : visitPoint.Id,
|
|
// SiteId = center == null ? Guid.Empty : center.Id,
|
|
// ImageNo = image.ImageNo,
|
|
// SubjectCode = subject == null ? string.Empty : subject.Code,
|
|
// SiteName = center == null ? string.Empty : center.SiteName,
|
|
// Period = visitPlan == null ? string.Empty : visitPlan.Period,
|
|
// VisitStageId = visitPlan == null ? Guid.Empty : visitPlan.Id,
|
|
// MedicalNo = subject == null ? string.Empty : subject.MedicalNo,
|
|
// State = image.State,
|
|
// StudyDate = image.StudyDate,
|
|
// CreateTime = image.CreateTime,
|
|
// Modalities = image.Modalities
|
|
// };
|
|
//var count = query.Count();
|
|
|
|
//var propName = param.SortField == string.Empty ? "CreateTime" : param.SortField;
|
|
|
|
//query = param.Asc
|
|
// ? query.OrderBy(propName)
|
|
// : query.OrderByDescending(propName);
|
|
|
|
//query = query.Skip((param.PageIndex - 1) * param.PageSize).Take(param.PageSize);
|
|
//var list = query.ToList();
|
|
//return new PageOutput<ImageDetailDTO>(param.PageIndex,
|
|
// param.PageSize, count, list);
|
|
//}
|
|
|
|
}
|
|
}
|