From 73cc2f1b71666d860188c0f4a1a1202d62fb55c8 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com> Date: Sun, 12 May 2024 14:42:41 +0800 Subject: [PATCH] =?UTF-8?q?pacs=E7=BB=93=E6=9E=9C=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PacsImportResultInterfaceInput.cs | 28 ++ .../PacsImportResultInterfaceOut.cs | 74 +++++ .../PacsImportResultPlugInsGem.cs | 110 +++++++- .../PacsImportResultPlugInsGemTest.cs | 37 +++ .../appsettings.json | 6 +- .../LisResultImportPlugInsBase.cs | 9 +- .../PacsImportResultPlugInsBase.cs | 8 +- ...s => PacsRequestForImportResultPlugIns.cs} | 4 +- .../PlugInsBase.cs | 39 ++- .../ThirdPlugInsBase.cs | 2 +- .../CreateImportPacsResultDto.cs | 87 ++++++ .../ImportPacsResultAppService.cs | 259 ++++++++++++++++++ src/Shentun.Peis.Domain/ImageHelper.cs | 61 ++++- src/Shentun.Utilities/FileHelper.cs | 42 ++- src/Shentun.Utilities/PDFHelper.cs | 40 +++ .../Shentun.Utilities.csproj | 3 +- .../ImportPacsResultAppServiceTest.cs | 83 ++++++ 17 files changed, 865 insertions(+), 27 deletions(-) create mode 100644 ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultInterfaceInput.cs create mode 100644 ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultInterfaceOut.cs create mode 100644 ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/PacsImportResultPlugInsGemTest.cs rename src/Shentun.ColumnReferencePlugIns/{PacsRequestForResultImportPlugIns.cs => PacsRequestForImportResultPlugIns.cs} (63%) create mode 100644 src/Shentun.Peis.Application.Contracts/ImportPacsResults/CreateImportPacsResultDto.cs create mode 100644 src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs create mode 100644 src/Shentun.Utilities/PDFHelper.cs create mode 100644 test/Shentun.Peis.Application.Tests/ImportPacsResultAppServiceTest.cs diff --git a/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultInterfaceInput.cs b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultInterfaceInput.cs new file mode 100644 index 0000000..ec0538f --- /dev/null +++ b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultInterfaceInput.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.Peis.PlugIns.Gem +{ + public class PacsImportResultInterfaceInput + { + public string tjNum { get; set; } + public string checkupItemId { get; set; } + public string organizeCode { get; set; } + public string examTypeCode { get; set; } + public string idCard { get; set; } + public string patientType { get; set; } + public string patientId { get; set; } + public string requestId { get; set; } + public string clinicId { get; set; } + public string hospizationId { get; set; } + public string visitId { get; set; } + public long? examRequestId { get; set; } + public string beginTime { get; set; } + public string endTime { get; set; } + public int pageNo { get; set; } + public int pageSize { get; set; } + } +} diff --git a/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultInterfaceOut.cs b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultInterfaceOut.cs new file mode 100644 index 0000000..f5ab0d9 --- /dev/null +++ b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultInterfaceOut.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.Peis.PlugIns.Gem +{ + public class PacsImportResultInterfaceOut + { + public string code { get; set; } + public string msg { get; set; } + public List data { get; set; } + } + + public class PacsImportResultInterfaceData + { + /// + /// 姓名 + /// + public string patientName { get; set; } + /// + /// 科室名称 + /// + public string reportDeptName { get; set; } + /// + /// 放射DICOM影像浏览地址 + /// + public string webPacsURL { get; set; } + /// + /// 1阳性 0阴性 + /// + + public int malignant { get; set; } + /// + /// 结论 + /// + + public string examDiagnosis { get; set; } + /// + /// 描述 + /// + public string examDescript { get; set; } + /// + /// 建议 + /// + public string suggestion { get; set; } + /// + /// 报告医生 + /// + public string reportDoctorName { get; set; } + /// + /// 审核医生 + /// + public string reviewDoctorName { get; set; } + /// + /// 报告时间 + /// + + public string reportDateTime { get; set; } + /// + /// 审核时间 + /// + public string reviewDateTime { get; set; } + /// + /// 图文报告浏览地址 + /// + public string reportUrl { get; set; } + /// + /// 超声打印图片列表,字符串base64数组 + /// + public List imageList { get; set; } + } +} diff --git a/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultPlugInsGem.cs b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultPlugInsGem.cs index 37beea2..c658c7b 100644 --- a/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultPlugInsGem.cs +++ b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/PacsImportResultPlugInsGem.cs @@ -1,8 +1,14 @@ -using System; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; +using Shentun.Peis.ImportPacsResults; +using NPOI.SS.Formula.Functions; +using Shentun.Peis.ImportLisResults; namespace Shentun.Peis.PlugIns.Gem { @@ -12,11 +18,109 @@ namespace Shentun.Peis.PlugIns.Gem { } - public override Task ImportResultAsync(PacsImportResultPlugInsInput input) + public override async Task ImportResultAsync(PacsImportResultPlugInsInput input) { + //if (DepartmentColumnReferenceId == null || DepartmentColumnReferenceId == Guid.Empty) + //{ + // throw new Exception("没有设置科室编码对照"); + //} + var pacsRequests = await GetPacsRequestForImportResultPlugInssAsync(input.PatientRegisterId); + var beginTime = DateTime.Now.Date.AddDays(-30); + foreach (var pacsRequest in pacsRequests) + { + var interfaceInpu = new PacsImportResultInterfaceInput() + { + tjNum = pacsRequest.CheckRequestNo, + organizeCode = "1", + patientType = "3", + //requestId = pacsRequest.CheckRequestNo, + beginTime = beginTime.ToString("yyyy-MM-dd HH:mm:ss"), + pageNo = 1, + pageSize = 20 + }; + var apiResult = await CallInterfaceServiceAsync(interfaceInpu); + if(!apiResult.data.Any()) + { + continue; + } + var firstData = apiResult.data[0]; + if(!DateTime.TryParse(firstData.reportDateTime,out var checkDate)) + { + throw new Exception("报告时间格式不正确"); + } + var createImportPacsResultDto = new CreateImportPacsResultDto() + { + CheckRequestNo = pacsRequest.CheckRequestNo, + PatientName = pacsRequest.PatientName, + Result = firstData.examDescript, + Summary = firstData.examDiagnosis, + Suggestion = firstData.suggestion, + CheckDate = checkDate, + CheckDoctorName = firstData.reportDoctorName, + Files = new List() + { + new CreateImportPacsResultPictureDto() + { + IsPrint = 'Y', + FileTransMode = "0", + FileName = firstData.reportUrl, + FileFormat = "1", + FileBase64 = Shentun.Utilities.FileHelper.ToBase64(firstData.reportUrl) + }, + + } + }; - return base.ImportResultAsync(input); + var callResult = await CallAppServiceAsync("api/app/ImportLisResult/ImportResult", createImportPacsResultDto); + + } + var result = new PacsImportResultPlugInsOut(); + return result; + } + + + public async Task CallInterfaceServiceAsync( TInput data) + { + string baseAddress = InterfaceWebApiAddress; + using (var httpClientHandler = new HttpClientHandler()) + { + using (var httpClient = new HttpClient(httpClientHandler)) + { + httpClient.BaseAddress = new Uri(baseAddress); + + httpClient.DefaultRequestHeaders.Accept.Add( + new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型 + //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken); + IsoDateTimeConverter timeFormat = new IsoDateTimeConverter(); + timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; + var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat); + using (HttpContent httpContent = new StringContent(sendData)) + { + httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + HttpResponseMessage response = await httpClient.PostAsync("", httpContent); + string result; + if (!response.IsSuccessStatusCode) + { + result = response.Content.ReadAsStringAsync().Result; + throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result); + } + result = await response.Content.ReadAsStringAsync(); + + dynamic resultDto = JsonConvert.DeserializeObject(result); + if (resultDto != null) + { + if (resultDto.code!= "200") + { + throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.code + resultDto.msg); + } + } + return resultDto; + } + + } + } } } } diff --git a/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/PacsImportResultPlugInsGemTest.cs b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/PacsImportResultPlugInsGemTest.cs new file mode 100644 index 0000000..4890f1a --- /dev/null +++ b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/PacsImportResultPlugInsGemTest.cs @@ -0,0 +1,37 @@ +using Shentun.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit.Abstractions; + +namespace Shentun.Peis.PlugIns.Gem.Test +{ + public class PacsImportResultPlugInsGemTest + { + private readonly ITestOutputHelper _output; + public PacsImportResultPlugInsGemTest(ITestOutputHelper testOutputHelper) + { + _output = testOutputHelper; + + } + + [Fact] + public async Task ImportResultAsync() + { + string configParm; + string filePath = DirectoryHelper.GetAppDirectory() + "/appsettings.json"; + configParm = File.ReadAllText(filePath); + + var input = new PacsImportResultPlugInsGem(configParm); + var item = await input.ImportResultAsync( + new PacsImportResultPlugInsInput() + { + PatientRegisterId = new Guid("3a1277ab-376c-fbdb-4419-92bbb4594607") + }); + + + } + } +} diff --git a/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/appsettings.json b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/appsettings.json index 3caa762..601e6d2 100644 --- a/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/appsettings.json +++ b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/appsettings.json @@ -16,11 +16,13 @@ "Sql": "select ZHID as Code ,ZHMC as DisplayName from PORTAL56_LIS.vi_tj_testitemgroup", "ColumnNames": "编码,名称", - "EndpointAddress": "http://10.1.12.140:8082/gemse-tj/services/bstj.bstjHttpSoap11Endpoint" + "EndpointAddress": "http://10.1.12.140:8082/gemse-tj/services/bstj.bstjHttpSoap11Endpoint", + "WebApiAddress": "http://10.1.13.18:8380/ris/findReportList" }, "ConnectionStrings": { - "Default": "Host=140.143.162.39;Port=5432;Database=ShentunPeis070703;User ID=postgres;Password=shentun123;" + //"Default": "Host=140.143.162.39;Port=5432;Database=ShentunPeis070703;User ID=postgres;Password=shentun123;", //"Default": "Host=localhost;Port=5432;Database=ShentunPeis1218;User ID=postgres;Password=wxd123;" + "Default": "Host=10.1.12.140;Port=5432;Database=ShentunPeis0508;User ID=postgres;Password=st123;" }, "AuthServer": { diff --git a/src/Shentun.ColumnReferencePlugIns/LisResultImportPlugInsBase.cs b/src/Shentun.ColumnReferencePlugIns/LisResultImportPlugInsBase.cs index 5b4bf0e..820bf3e 100644 --- a/src/Shentun.ColumnReferencePlugIns/LisResultImportPlugInsBase.cs +++ b/src/Shentun.ColumnReferencePlugIns/LisResultImportPlugInsBase.cs @@ -11,17 +11,12 @@ namespace Shentun.Peis.PlugIns { public class LisResultImportPlugInsBase : ThirdPlugInsBase { - protected Guid ItemColumnReferenceId; + protected string AppLisUser; protected string AppLisPassword; public LisResultImportPlugInsBase(string parmValue) : base(parmValue) { - var itemColumnReferenceIdStr = InterfaceConfig.GetSection("Interface") - .GetSection("ItemColumnReferenceId").Value; - if (!string.IsNullOrWhiteSpace(itemColumnReferenceIdStr)) - { - ItemColumnReferenceId = new Guid(itemColumnReferenceIdStr); - } + AppLisUser = AppConfig.GetSection("App") .GetSection("LisUser").Value; AppLisPassword = AppConfig.GetSection("App") diff --git a/src/Shentun.ColumnReferencePlugIns/PacsImportResultPlugInsBase.cs b/src/Shentun.ColumnReferencePlugIns/PacsImportResultPlugInsBase.cs index 860bbfa..7bdc662 100644 --- a/src/Shentun.ColumnReferencePlugIns/PacsImportResultPlugInsBase.cs +++ b/src/Shentun.ColumnReferencePlugIns/PacsImportResultPlugInsBase.cs @@ -20,13 +20,15 @@ namespace Shentun.Peis.PlugIns var result = new PacsImportResultPlugInsOut(); return result; } - public async Task> GetLisRequestForResultImportPlugInssAsync(Guid patientRegisterId) + public async Task> GetPacsRequestForImportResultPlugInssAsync(Guid patientRegisterId) { using (DbConnection conn = new NpgsqlConnection(AppConnctionStr)) { string sql; sql = @" - SELECT distinct register_check.id , + SELECT distinct patient_register.patient_register_no, + patient_register.patient_name, + register_check.id , register_check.check_request_no from patient_register JOIN register_check on patient_register.id = register_check.patient_register_id @@ -36,7 +38,7 @@ JOIN item_type on asbitem.item_type_id = item_type.id where patient_register.id = @PatientRegisterId and item_type.is_check_request = 'Y' "; - var pacsRequestForResultImportPlugInss = (await conn.QueryAsync(sql, + var pacsRequestForResultImportPlugInss = (await conn.QueryAsync(sql, new { PatientRegisterId = patientRegisterId })).ToList(); return pacsRequestForResultImportPlugInss; } diff --git a/src/Shentun.ColumnReferencePlugIns/PacsRequestForResultImportPlugIns.cs b/src/Shentun.ColumnReferencePlugIns/PacsRequestForImportResultPlugIns.cs similarity index 63% rename from src/Shentun.ColumnReferencePlugIns/PacsRequestForResultImportPlugIns.cs rename to src/Shentun.ColumnReferencePlugIns/PacsRequestForImportResultPlugIns.cs index 9ef66b8..c183908 100644 --- a/src/Shentun.ColumnReferencePlugIns/PacsRequestForResultImportPlugIns.cs +++ b/src/Shentun.ColumnReferencePlugIns/PacsRequestForImportResultPlugIns.cs @@ -6,8 +6,10 @@ using System.Threading.Tasks; namespace Shentun.Peis.PlugIns { - public class PacsRequestForResultImportPlugIns + public class PacsRequestForImportResultPlugIns { + public string PatientRegisterNo { get; set; } + public string PatientName { get; set; } public Guid RegisterCheckId { get; set; } public string CheckRequestNo { get; set;} } diff --git a/src/Shentun.ColumnReferencePlugIns/PlugInsBase.cs b/src/Shentun.ColumnReferencePlugIns/PlugInsBase.cs index 872892e..a2fe8cc 100644 --- a/src/Shentun.ColumnReferencePlugIns/PlugInsBase.cs +++ b/src/Shentun.ColumnReferencePlugIns/PlugInsBase.cs @@ -29,7 +29,14 @@ namespace Shentun.Peis.PlugIns protected string InterfaceSqlKeyColumn; protected string InterfaceDbType; protected string? InterfaceConnctionStr; - + + protected string? InterfaceWebApiAddress; + + protected Guid ItemColumnReferenceId; + protected Guid AsbitemColumnReferenceId; + protected Guid DepartmentColumnReferenceId; + protected Guid UserColumnReferenceId; + static PlugInsBase() { Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true; @@ -56,8 +63,38 @@ namespace Shentun.Peis.PlugIns InterfaceSql = InterfaceConfig.GetSection("Interface").GetSection("Sql").Value; InterfaceSqlKeyColumn = InterfaceConfig.GetSection("Interface").GetSection("SqlKeyColumn").Value; InterfaceDbType = InterfaceConfig.GetSection("Interface").GetSection("DbType").Value; + InterfaceWebApiAddress = InterfaceConfig.GetSection("Interface").GetSection("WebApiAddress").Value; + InterfaceConnctionStr = InterfaceConfig.GetSection("Interface").GetSection("ConnectionStrings").Value; + var itemColumnReferenceIdStr = InterfaceConfig.GetSection("Interface") + .GetSection("ItemColumnReferenceId").Value; + if (!string.IsNullOrWhiteSpace(itemColumnReferenceIdStr)) + { + ItemColumnReferenceId = new Guid(itemColumnReferenceIdStr); + } + + var asbItemColumnReferenceIdStr = InterfaceConfig.GetSection("Interface") + .GetSection("AsbitemColumnReferenceId").Value; + if (!string.IsNullOrWhiteSpace(asbItemColumnReferenceIdStr)) + { + AsbitemColumnReferenceId = new Guid(asbItemColumnReferenceIdStr); + } + + var departmentColumnReferenceIdStr = InterfaceConfig.GetSection("Interface") + .GetSection("DepartmentColumnReferenceId").Value; + if (!string.IsNullOrWhiteSpace(departmentColumnReferenceIdStr)) + { + DepartmentColumnReferenceId = new Guid(departmentColumnReferenceIdStr); + } + + var userColumnReferenceIdStr = InterfaceConfig.GetSection("Interface") + .GetSection("UserColumnReferenceId").Value; + if (!string.IsNullOrWhiteSpace(userColumnReferenceIdStr)) + { + UserColumnReferenceId = new Guid(userColumnReferenceIdStr); + } + } protected DbConnection CreateInterfaceDbConnect() diff --git a/src/Shentun.ColumnReferencePlugIns/ThirdPlugInsBase.cs b/src/Shentun.ColumnReferencePlugIns/ThirdPlugInsBase.cs index b6b6334..f45092c 100644 --- a/src/Shentun.ColumnReferencePlugIns/ThirdPlugInsBase.cs +++ b/src/Shentun.ColumnReferencePlugIns/ThirdPlugInsBase.cs @@ -16,7 +16,7 @@ namespace Shentun.Peis.PlugIns public ThirdPlugInsBase(string parmValue):base(parmValue) { - + } public async Task> GetColumnReferenceInterfaceCodeValuesAsync(Guid columnReferenceId, diff --git a/src/Shentun.Peis.Application.Contracts/ImportPacsResults/CreateImportPacsResultDto.cs b/src/Shentun.Peis.Application.Contracts/ImportPacsResults/CreateImportPacsResultDto.cs new file mode 100644 index 0000000..c10418a --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/ImportPacsResults/CreateImportPacsResultDto.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.ImportPacsResults +{ + public class CreateImportPacsResultDto + { + public string CheckRequestNo { get; set; } + /// + /// 姓名 + /// + + public string PatientName { get; set; } + /// + /// 检查所见 + /// + public string? Result { get; set; } + + /// + /// 结论 + /// + public string? Summary { get; set; } + + /// + /// 结论 + /// + public string? Suggestion { get; set; } + + /// + /// 危急值范围 + /// + + public string? CriticalRangeValue { get; set; } + /// + /// 危急值 + /// + + public string? CriticalValue { get; set; } + /// + /// 报告单状态 + /// + + public string? ResultStatusId { get; set; } = "01";//01-正常 + /// + /// 报告单提示 + /// + public string ReportPrompt { get; set; } + /// + /// 检查医生 + /// + + public string? CheckDoctorName { get; set; } + /// + /// 检查日期 + /// + + public DateTime? CheckDate { get; set; } + + public Guid ExecOrganizationUnitId { get; set; } + public List Files { get; set; } = new List(); + } + + public class CreateImportPacsResultPictureDto + { + /// + /// 文件格式,0-图片,1-pdf + /// + public string FileFormat { get; set; } + /// + /// 0-json,1-url + /// + + public string FileTransMode { get; set; } + /// + /// 文件名 + /// + public string FileName { get; set; } + /// + /// base64文件 + /// + public string FileBase64 { get; set; } + + public char IsPrint { get; set; } + } + +} diff --git a/src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs b/src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs new file mode 100644 index 0000000..b775249 --- /dev/null +++ b/src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs @@ -0,0 +1,259 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using NPOI.SS.Formula.Functions; +using NUglify.Helpers; +using Shentun.Peis.DiagnosisFunctions; +using Shentun.Peis.ImportLisResults; +using Shentun.Peis.Items; +using Shentun.Peis.Models; +using Shentun.Peis.ReferenceRanges; +using Shentun.Peis.RegisterCheckItems; +using Shentun.Peis.RegisterChecks; +using Shentun.Peis.Units; +using Shentun.Utilities; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Guids; +using Volo.Abp.Identity; +using Volo.Abp.Users; + +namespace Shentun.Peis.ImportPacsResults +{ + public class ImportPacsResultAppService : ApplicationService + { + private readonly IRepository _registerCheckItemRepository; + private readonly IRepository _registerCheckPictureRepository; + private readonly IRepository _patientRegisterRepository; + private readonly IRepository _referenceRangeRepository; + private readonly IRepository _registerCheckRepository; + private readonly IRepository _registerCheckAsbitemRepository; + private readonly IRepository _lisRequestRepository; + private readonly IRepository _itemRepository; + private readonly IRepository _registerCheckSummaryRepository; + private readonly IRepository _registerCheckSuggestionRepository; + private readonly IRepository _userRepository; + private readonly IRepository _unitRepository; + private readonly RegisterCheckManager _registerCheckManager; + private readonly RegisterCheckItemManager _registerCheckItemManager; + private readonly CacheService _cacheService; + private readonly IGuidGenerator _guidGenerator; + private readonly IConfiguration _configuration; + private readonly ICurrentUser _currentUser; + private readonly IRepository _userItemTypeRepository; + private readonly IRepository _asbitemRepository; + private readonly DiagnosisFunctionAppService _diagnosisFunctionAppService; + private readonly ReferenceRangeManager _referenceRangeManager; + private readonly ItemManager _itemManager; + private readonly UnitManager _unitManager; + private readonly RegisterCheckAppService _registerCheckAppService; + private List _units; + private List _referenceRanges; + private static bool _isRunning = false; + private static readonly object lockObject = new object(); + public ImportPacsResultAppService(IRepository registerCheckRepository, + IRepository registerCheckItemRepository, + IRepository patientRegisterRepository, + IRepository referenceRangeRepository, + IRepository registerCheckSummaryRepository, + IRepository registerCheckSuggestionRepository, + IRepository userRepository, + RegisterCheckManager registerCheckManager, + RegisterCheckItemManager registerCheckItemManager, + CacheService cacheService, + IGuidGenerator guidGenerator, + IConfiguration configuration, + ICurrentUser currentUser, + IRepository userItemTypeRepository, + IRepository asbitemRepository, + IRepository registerCheckAsbitemRepository, + IRepository lisRequestRepository, + IRepository unitRepository, + DiagnosisFunctionAppService diagnosisFunctionAppService, + ReferenceRangeManager referenceRangeManager, + IRepository itemRepository, + ItemManager itemManager, + UnitManager unitManager, + RegisterCheckAppService registerCheckAppService, + IRepository registerCheckPictureRepository) + { + _registerCheckRepository = registerCheckRepository; + _userRepository = userRepository; + _registerCheckManager = registerCheckManager; + _patientRegisterRepository = patientRegisterRepository; + _referenceRangeRepository = referenceRangeRepository; + _registerCheckItemRepository = registerCheckItemRepository; + _registerCheckSummaryRepository = registerCheckSummaryRepository; + _registerCheckSuggestionRepository = registerCheckSuggestionRepository; + _registerCheckItemManager = registerCheckItemManager; + _cacheService = cacheService; + _guidGenerator = guidGenerator; + _configuration = configuration; + _currentUser = currentUser; + _userItemTypeRepository = userItemTypeRepository; + _asbitemRepository = asbitemRepository; + _registerCheckAsbitemRepository = registerCheckAsbitemRepository; + _lisRequestRepository = lisRequestRepository; + _diagnosisFunctionAppService = diagnosisFunctionAppService; + _referenceRangeManager = referenceRangeManager; + _itemRepository = itemRepository; + _itemManager = itemManager; + _unitRepository = unitRepository; + _units = _unitRepository.GetListAsync().Result; + _unitManager = unitManager; + _registerCheckAppService = registerCheckAppService; + _registerCheckPictureRepository = registerCheckPictureRepository; + } + + [HttpPost("api/app/ImportPacsResult/ImportResult")] + public async Task ImportResultAsync(CreateImportPacsResultDto input) + { + //设置结果 + + var list = (from patientRegister in await _patientRegisterRepository.GetQueryableAsync() + join registerCheck in await _registerCheckRepository.GetQueryableAsync() + on patientRegister.Id equals registerCheck.PatientRegisterId + join registerCheckItem in await _registerCheckItemRepository.GetQueryableAsync() + on registerCheck.Id equals registerCheckItem.RegisterCheckId + join item in await _itemRepository.GetQueryableAsync() + on registerCheckItem.ItemId equals item.Id + where registerCheck.CheckRequestNo == input.CheckRequestNo + select new + { + patientRegister, + registerCheck, + registerCheckItem, + item, + }).ToList(); + if (!list.Any()) + { + return; + } + var firstEntity = list.First(); + + if (string.IsNullOrWhiteSpace(input.Result)) + { + return; + } + if (string.IsNullOrWhiteSpace(input.CheckDoctorName)) + { + throw new UserFriendlyException("检查医生不能为空"); + } + if (string.IsNullOrWhiteSpace(input.PatientName)) + { + throw new UserFriendlyException("姓名不能为空"); + } + if (input.PatientName != firstEntity.patientRegister.PatientName) + { + throw new UserFriendlyException($"Pacs姓名{input.PatientName}和体检系统姓名{firstEntity.patientRegister.PatientName}不一致"); + } + var updateCheckResultDto = new UpdateCheckResultDto() + { + RegisterCheckId = firstEntity.registerCheck.Id, + CheckDoctorId = input.CheckDoctorName, + CheckDate = input.CheckDate, + ExecOrganizationUnitId = input.ExecOrganizationUnitId, + RegisterCheckItems = list + .Select(o => new UpdateRegisterCheckItemDetail() + { + ItemId = o.registerCheckItem.ItemId, + Result = input.Result, + + }).ToList() + + }; + + + //生成小结 + updateCheckResultDto.Summarys.Add(new UpdateRegisterCheckSummaryDetail() + { + Summary = input.Summary, + SummaryFlag = '0' + }); + //保存明细结果和小结 + await _registerCheckAppService.UpdateCheckResult(updateCheckResultDto); + //保存图片 + string absolutePath = _configuration.GetValue("VirtualPath:RealPath"); + //删除以前的图片 + var registerCheckPictures = await _registerCheckPictureRepository.GetListAsync(o => o.RegisterCheckId == firstEntity.registerCheck.Id); + await _registerCheckPictureRepository.DeleteManyAsync(registerCheckPictures); + //插入新图片 + string pictureUrl; + foreach (var file in input.Files) + { + string fileName; + if (string.IsNullOrWhiteSpace(file.FileName)) + { + fileName = Guid.NewGuid().ToString(); + } + else + { + fileName = Path.GetFileNameWithoutExtension(file.FileName); + } + + //0-图片,1-PDF + if (file.FileFormat == "0") + { + + pictureUrl = ImageHelper.Base64StrToImageInAbsolutePath(absolutePath, fileName, file.FileBase64, firstEntity.patientRegister.Id.ToString(), + firstEntity.registerCheck.Id.ToString()); + + } + else if (file.FileFormat == "1") + { + byte[] pdfBytes = Convert.FromBase64String(file.FileBase64); + var tempFilePath = DirectoryHelper.GetAppDirectory() + "\\temp-files"; + if (!Directory.Exists(tempFilePath)) + { + Directory.CreateDirectory(tempFilePath); + } + + string tempPdf = tempFilePath + "\\temp.pdf"; + using (System.IO.FileStream stream = new System.IO.FileStream(tempPdf, System.IO.FileMode.Create)) + { + //通过流的方式写入 + using(System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream) ) + { + writer.Write(pdfBytes, 0, pdfBytes.Length); + writer.Close(); + } + + } + PDFHelper.ConvertPdfToImage(tempPdf, tempFilePath ,"tempImage"); + + pictureUrl = ImageHelper.SavePacsFile(absolutePath, tempFilePath + "\\tempImage_0.jpg", firstEntity.patientRegister.Id.ToString(), + firstEntity.registerCheck.Id.ToString(), fileName); + } + else + { + throw new UserFriendlyException("不支持的文件类型"); + } + + + + if (string.IsNullOrEmpty(pictureUrl)) + { + throw new UserFriendlyException("pictureUrl是空值"); + } + var registerCheckPicture = new RegisterCheckPicture + { + DisplayOrder = input.Files.IndexOf(file) + 1, + IsPrint = file.IsPrint, + PictureFilename = pictureUrl, + RegisterCheckId = firstEntity.registerCheck.Id, + }; + + await _registerCheckPictureRepository.InsertAsync(registerCheckPicture); + } + + + + } + } +} diff --git a/src/Shentun.Peis.Domain/ImageHelper.cs b/src/Shentun.Peis.Domain/ImageHelper.cs index 30bd310..c06d921 100644 --- a/src/Shentun.Peis.Domain/ImageHelper.cs +++ b/src/Shentun.Peis.Domain/ImageHelper.cs @@ -2,6 +2,7 @@ using NPOI.HPSF; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; @@ -273,7 +274,7 @@ namespace Shentun.Peis } - + /// @@ -478,5 +479,63 @@ namespace Shentun.Peis result = "data:image/jpeg;base64," + result; return result; } + + + public static string SavePacsFile(string absolutePath, string sourceFileFullName, string PatientRegisterId, string RegisterCheckId, string imageName) + { + var ret = ""; + + string savePath = ""; + string hostPath = ""; + + if (string.IsNullOrWhiteSpace(sourceFileFullName)) + { + throw new UserFriendlyException("文件名不能为空"); + } + + if (!File.Exists(sourceFileFullName)) + { + throw new UserFriendlyException("文件名不存在"); + } + + var ImageSuffix = Path.GetExtension(sourceFileFullName); + + + if (ImageSuffix == null) + { + throw new UserFriendlyException("图片数据有误"); + } + + string fileFilt = ".gif|.jpg|.jpeg|.png"; + + if (fileFilt.IndexOf(ImageSuffix.ToLower(), StringComparison.Ordinal) <= -1) + { + throw new UserFriendlyException("请上传jpg、png、gif格式的图片"); + } + + savePath = absolutePath + "\\" + PatientRegisterId + "\\" + RegisterCheckId + "\\" + imageName + ImageSuffix; + hostPath = "/CheckPictureImg/" + PatientRegisterId + "/" + RegisterCheckId + "/" + imageName + ImageSuffix; + + + if (!Directory.Exists(absolutePath + "\\" + PatientRegisterId)) + { + Directory.CreateDirectory(absolutePath + "\\" + PatientRegisterId); + } + + if (!Directory.Exists(absolutePath + "\\" + PatientRegisterId + "\\" + RegisterCheckId)) + { + Directory.CreateDirectory(absolutePath + "\\" + PatientRegisterId + "\\" + RegisterCheckId); + } + + File.Copy(sourceFileFullName, savePath, true);//true允许覆盖 + + + ret = hostPath; + return ret; + } + + + } } + diff --git a/src/Shentun.Utilities/FileHelper.cs b/src/Shentun.Utilities/FileHelper.cs index 38e0075..50ca9a3 100644 --- a/src/Shentun.Utilities/FileHelper.cs +++ b/src/Shentun.Utilities/FileHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net.Http; using System.Text; namespace Shentun.Utilities @@ -9,16 +10,43 @@ namespace Shentun.Utilities { public static string ToBase64(string filename) { - Stream stream; + Stream stream; string fileBase64; - using (stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) + if (filename.StartsWith("http")) { - byte[] byteData = new byte[stream.Length]; - stream.Read(byteData, 0, byteData.Length); - fileBase64 = Convert.ToBase64String(byteData); - stream.Close(); + using (var httpClientHandler = new HttpClientHandler()) + { + using (var httpClient = new HttpClient(httpClientHandler)) + { + var response = httpClient.GetAsync(filename).Result; + if (response.IsSuccessStatusCode) + { + var contentStream = response.Content.ReadAsStreamAsync().Result; + using var memoryStream = new MemoryStream(); + contentStream.CopyTo(memoryStream); + var fileBytes = memoryStream.ToArray(); + return Convert.ToBase64String(fileBytes); + } + else + { + throw new Exception("转换base64时,返回错误:" + response.StatusCode); + } + } + } + } - return fileBase64; + else + { + using (stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) + { + byte[] byteData = new byte[stream.Length]; + stream.Read(byteData, 0, byteData.Length); + fileBase64 = Convert.ToBase64String(byteData); + stream.Close(); + } + return fileBase64; + } + } } } diff --git a/src/Shentun.Utilities/PDFHelper.cs b/src/Shentun.Utilities/PDFHelper.cs new file mode 100644 index 0000000..6085656 --- /dev/null +++ b/src/Shentun.Utilities/PDFHelper.cs @@ -0,0 +1,40 @@ +using Spire.Pdf; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.Utilities +{ + public class PDFHelper + { + public static void ConvertPdfToImage(string? pdfFullPath, string? imageFilePath, string imageFileName) + { + if (string.IsNullOrWhiteSpace(pdfFullPath)) + throw new ArgumentNullException(pdfFullPath); + if (string.IsNullOrWhiteSpace(imageFilePath)) + throw new ArgumentNullException(imageFilePath); + + if (!File.Exists(pdfFullPath)) + throw new FileNotFoundException(pdfFullPath); + var doc = new PdfDocument(); + doc.LoadFromFile(pdfFullPath); + var pageCount = doc.Pages.Count; + for (int i = 0; i < pageCount; i++) + { + string jpgFullName = string.Empty; + + jpgFullName = imageFilePath + "\\" + imageFileName + $"_{i}" + ".jpg"; + using var stream = File.Open(jpgFullName, FileMode.Create); + using Image bmp = doc.SaveAsImage(i); + bmp.Save(stream, ImageFormat.Jpeg); + + + } + } + } +} diff --git a/src/Shentun.Utilities/Shentun.Utilities.csproj b/src/Shentun.Utilities/Shentun.Utilities.csproj index c71321c..0ca38f3 100644 --- a/src/Shentun.Utilities/Shentun.Utilities.csproj +++ b/src/Shentun.Utilities/Shentun.Utilities.csproj @@ -6,6 +6,7 @@ + @@ -17,7 +18,7 @@ - + diff --git a/test/Shentun.Peis.Application.Tests/ImportPacsResultAppServiceTest.cs b/test/Shentun.Peis.Application.Tests/ImportPacsResultAppServiceTest.cs new file mode 100644 index 0000000..b98093b --- /dev/null +++ b/test/Shentun.Peis.Application.Tests/ImportPacsResultAppServiceTest.cs @@ -0,0 +1,83 @@ +using Shentun.Peis.ImportLisResults; +using Shentun.Peis.ImportPacsResults; +using Shentun.Peis.Models; +using Shentun.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Uow; +using Xunit; +using Xunit.Abstractions; + +namespace Shentun.Peis +{ + public class ImportPacsResultAppServiceTest : PeisApplicationTestBase + { + private readonly IRepository _repository; + private readonly ImportPacsResultAppService _appService; + private readonly ITestOutputHelper _output; + private readonly IUnitOfWorkManager _unitOfWorkManager; + public ImportPacsResultAppServiceTest(ITestOutputHelper testOutputHelper) + { + _output = testOutputHelper; + _unitOfWorkManager = GetRequiredService(); + _repository = GetRequiredService>(); + _appService = GetRequiredService(); + } + [Fact] + public async Task ImportResultAsync() + { + using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true)) + { + + var entity = new CreateImportPacsResultDto() + { + CheckRequestNo = "2405112185", + PatientName = "测试pacs", + Result = "Pacs检查所见", + Summary = "Pacs结论", + Suggestion = "Pacs建议", + CheckDate = DateTime.Now, + CheckDoctorName = "张医生", + Files = new List() + { + new CreateImportPacsResultPictureDto() + { + IsPrint = 'Y', + FileName = Guid.NewGuid().ToString(), + FileFormat = "0", + FileBase64 = Shentun.Utilities.FileHelper.ToBase64("E:\\Whitedolphins\\prog20220722\\pic\\login.png") + }, + new CreateImportPacsResultPictureDto() + { + IsPrint = 'Y', + FileFormat = "0", + FileName = Guid.NewGuid().ToString(), + FileBase64 = Shentun.Utilities.FileHelper.ToBase64("E:\\Whitedolphins\\prog20220722\\pic\\首页背景图.jpg") + }, + new CreateImportPacsResultPictureDto() + { + IsPrint = 'Y', + FileFormat = "1", + FileName = Guid.NewGuid().ToString(), + FileBase64 = Shentun.Utilities.FileHelper.ToBase64("E:\\Whitedolphins\\doc\\体检中心排队系统.pdf") + }, + } + }; + + await _appService.ImportResultAsync(entity); + await unitOfWork.CompleteAsync(); + } + } + + + [Fact] + public void ConvertPdfToImage() + { + PDFHelper.ConvertPdfToImage("E:\\Whitedolphins\\doc\\体检中心排队系统.pdf", "E:\\Whitedolphins\\prog20220722\\pic", "测试"); + } + } +}