146 lines
5.1 KiB
C#
146 lines
5.1 KiB
C#
//--------------------------------------------------------------------
|
|
// 此代码由T4模板自动生成 byzhouhang 20210918
|
|
// 生成时间 2024-03-22 15:44:31
|
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
|
//--------------------------------------------------------------------
|
|
|
|
using IRaCIS.Core.Domain.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using IRaCIS.Core.Application.Interfaces;
|
|
using IRaCIS.Core.Application.ViewModel;
|
|
using FellowOakDicom.Network.Client;
|
|
using FellowOakDicom.Network;
|
|
using IRaCIS.Application.Contracts;
|
|
using IRaCIS.Core.Domain.Share;
|
|
namespace IRaCIS.Core.Application.Service
|
|
{
|
|
/// <summary>
|
|
/// DicomAEService
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "Common")]
|
|
public class DicomAEService (IRepository<DicomAE> _dicomAERepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IDicomAEService
|
|
{
|
|
|
|
|
|
|
|
[HttpPost]
|
|
public async Task<IResponseOutput< PageOutput<DicomAEView>>> GetDicomAEList(DicomAEQuery inQuery)
|
|
{
|
|
|
|
var dicomAEQueryable = _dicomAERepository
|
|
.WhereIf(!string.IsNullOrWhiteSpace(inQuery.IP), t => t.IP.Contains(inQuery.IP))
|
|
.WhereIf(inQuery.Port != null, t => t.Port == inQuery.Port)
|
|
.WhereIf(inQuery.PacsTypeEnum != null, t => t.PacsTypeEnum == inQuery.PacsTypeEnum)
|
|
.WhereIf(inQuery.IsTestOK != null, t => t.IsTestOK == inQuery.IsTestOK)
|
|
.WhereIf(!string.IsNullOrWhiteSpace(inQuery.CalledAE), t => t.CalledAE.Contains(inQuery.CalledAE))
|
|
.WhereIf(!string.IsNullOrWhiteSpace(inQuery.Description), t => t.Description.Contains(inQuery.Description))
|
|
.WhereIf(!string.IsNullOrWhiteSpace(inQuery.Modality), t => t.ModalityList.Contains(inQuery.Modality))
|
|
.ProjectTo<DicomAEView>(_mapper.ConfigurationProvider);
|
|
|
|
|
|
|
|
|
|
var pageList = await dicomAEQueryable.ToPagedListAsync(inQuery, nameof(DicomAEView.CalledAE));
|
|
|
|
|
|
return ResponseOutput.Ok(pageList);
|
|
}
|
|
|
|
|
|
public async Task<IResponseOutput> AddOrUpdateDicomAE(DicomAEAddOrEdit addOrEditDicomAE)
|
|
{
|
|
var verifyExp1 = new EntityVerifyExp<DicomAE>()
|
|
{
|
|
VerifyExp = u => u.IP == addOrEditDicomAE.IP && u.Port == addOrEditDicomAE.Port && u.PacsTypeEnum==addOrEditDicomAE.PacsTypeEnum,
|
|
|
|
VerifyMsg = _localizer["DicomAE_RepeatIPAndPort"] //"不允许添加相同的IP和端口的记录"
|
|
};
|
|
|
|
// 在此处拷贝automapper 映射
|
|
var entity = await _dicomAERepository.InsertOrUpdateAsync(addOrEditDicomAE, true, verifyExp1);
|
|
|
|
return ResponseOutput.Ok(entity.Id.ToString());
|
|
|
|
}
|
|
|
|
|
|
[HttpDelete("{dicomAEId:guid}")]
|
|
public async Task<IResponseOutput> DeleteDicomAE(Guid dicomAEId)
|
|
{
|
|
var success = await _dicomAERepository.DeleteFromQueryAsync(t => t.Id == dicomAEId, true);
|
|
return ResponseOutput.Ok();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 测试scp server 是否可以连接
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("{dicomAEId:guid}")]
|
|
public async Task<bool> TestSCPServerConnect(Guid dicomAEId)
|
|
{
|
|
var find = await _dicomAERepository.FirstOrDefaultAsync(t => t.Id == dicomAEId);
|
|
|
|
if (find == null)
|
|
{
|
|
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
find.LatestTestTime = DateTime.Now;
|
|
|
|
try
|
|
{
|
|
var client = DicomClientFactory.Create(find.IP, find.Port, false, "test-callingAE", find.CalledAE);
|
|
|
|
|
|
client.NegotiateAsyncOps();
|
|
|
|
client.ServiceOptions.RequestTimeout = TimeSpan.FromSeconds(3);
|
|
|
|
var request = new DicomCEchoRequest
|
|
{
|
|
OnResponseReceived = (req, response) =>
|
|
{
|
|
Console.WriteLine($"C-ECHO Response: {response.Status}");
|
|
|
|
if (response.Status == DicomStatus.Success)
|
|
{
|
|
find.IsTestOK = true;
|
|
}
|
|
else
|
|
{
|
|
find.IsTestOK = false;
|
|
}
|
|
}
|
|
};
|
|
|
|
await client.AddRequestAsync(request);
|
|
|
|
|
|
await client.SendAsync();
|
|
|
|
|
|
await _dicomAERepository.SaveChangesAsync();
|
|
|
|
|
|
|
|
return find.IsTestOK;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
find.IsTestOK = false;
|
|
await _dicomAERepository.SaveChangesAsync();
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|