121 lines
4.9 KiB
C#
121 lines
4.9 KiB
C#
using AutoMapper;
|
|
using AutoMapper.QueryableExtensions;
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Application.ViewModels;
|
|
using IRaCIS.Core.Application.Contracts.RequestAndResponse;
|
|
using IRaCIS.Core.Domain.Interfaces;
|
|
using IRaCIS.Core.Domain.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace IRaCIS.Application.Services
|
|
{
|
|
public class TrialExperienceService : ITrialExperienceService
|
|
{
|
|
private readonly ITrialExperienceRepository _trialExperienceRepository;
|
|
private readonly IDoctorRepository _doctorRepository;
|
|
private readonly IAttachmentRepository _attachmentRepository;
|
|
private readonly IMapper _mapper;
|
|
|
|
public TrialExperienceService(ITrialExperienceRepository trialExperienceRepository, IDoctorRepository doctorRepository, IAttachmentRepository attachmentRepository, IMapper mapper)
|
|
{
|
|
_trialExperienceRepository = trialExperienceRepository;
|
|
_doctorRepository = doctorRepository;
|
|
_attachmentRepository = attachmentRepository;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public TrialExperienceViewModel GetTrialExperience(Guid doctorId)
|
|
{
|
|
var trialExperience = new TrialExperienceViewModel();
|
|
|
|
var doctor = _doctorRepository.Find(o => o.Id == doctorId)
|
|
.ProjectTo<TrialExperienceViewModel>(_mapper.ConfigurationProvider).FirstOrDefault();
|
|
|
|
trialExperience.ClinicalTrialExperienceList =
|
|
GetTrialExperienceList(doctorId);
|
|
|
|
if (doctor != null)
|
|
{
|
|
trialExperience.GCP = doctor.GCP;
|
|
trialExperience.Id = doctor.Id;
|
|
trialExperience.OtherClinicalExperience = doctor.OtherClinicalExperience ?? "";
|
|
var attachment = _attachmentRepository.GetAll().FirstOrDefault(t => t.Id == doctor.GCPId);
|
|
if (attachment != null)
|
|
{
|
|
trialExperience.ExpiryDateStr = attachment.ExpiryDate == null ? "" : attachment.ExpiryDate?.ToString("yyyy-MM-dd HH:mm");
|
|
|
|
trialExperience.Path = attachment.Path;
|
|
trialExperience.Type = attachment.Type;
|
|
trialExperience.FileName = attachment.FileName;
|
|
trialExperience.GCPId = attachment.Id;
|
|
}
|
|
|
|
}
|
|
|
|
return trialExperience;
|
|
}
|
|
|
|
private List<TrialExperienceCommand> GetTrialExperienceList(Guid doctorId)
|
|
{
|
|
var doctorClinicalTrialExperienceList = _trialExperienceRepository.Find(o => o.DoctorId == doctorId).OrderBy(t => t.CreateTime)
|
|
.ProjectTo<TrialExperienceCommand>(_mapper.ConfigurationProvider).ToList();
|
|
|
|
return doctorClinicalTrialExperienceList;
|
|
}
|
|
|
|
public IResponseOutput AddOrUpdateTrialExperience(TrialExperienceCommand trialExperienceViewModel)
|
|
{
|
|
if (trialExperienceViewModel.Id == Guid.Empty|| trialExperienceViewModel.Id == null)
|
|
{
|
|
var trialExperience =
|
|
_mapper.Map<TrialExperience>(trialExperienceViewModel);
|
|
_trialExperienceRepository.Add(trialExperience);
|
|
|
|
var success = _trialExperienceRepository.SaveChanges();
|
|
return ResponseOutput.Result(success, trialExperience.Id);
|
|
}
|
|
else
|
|
{
|
|
_trialExperienceRepository.Update(_mapper.Map<TrialExperience>(trialExperienceViewModel));
|
|
var success = _trialExperienceRepository.SaveChanges();
|
|
return ResponseOutput.Result(success, trialExperienceViewModel.Id);
|
|
}
|
|
}
|
|
|
|
public IResponseOutput DeleteTrialExperience(Guid doctorId)
|
|
{
|
|
var success = _trialExperienceRepository.Delete(o => o.Id == doctorId);
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
|
|
public IResponseOutput UpdateGcpExperience(GCPExperienceCommand updateGCPExperienceParam)
|
|
{
|
|
//_attachmentRepository.Delete(t => t.DoctorId == updateGCPExperienceParam.Id && t.Type == StaticData.GCP);
|
|
|
|
var successs = _doctorRepository.Update(o => o.Id == updateGCPExperienceParam.Id, u => new Doctor()
|
|
{
|
|
GCP = updateGCPExperienceParam.GCP,
|
|
GCPId = updateGCPExperienceParam.GCPId
|
|
});
|
|
|
|
|
|
|
|
return ResponseOutput.Result(successs, updateGCPExperienceParam.GCPId.ToString());
|
|
|
|
}
|
|
|
|
/// <summary> 更新其他经验 </summary>
|
|
public IResponseOutput UpdateOtherExperience(Guid doctorId, string otherClinicalExperience)
|
|
{
|
|
var success = _doctorRepository.Update(o => o.Id == doctorId, u => new Doctor()
|
|
{
|
|
OtherClinicalExperience = otherClinicalExperience ?? string.Empty
|
|
});
|
|
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
|
|
}
|
|
} |