diff --git a/src/Shentun.ColumnReferencePlugIns/ImportLisResultPlugInsBase.cs b/src/Shentun.ColumnReferencePlugIns/ImportLisResultPlugInsBase.cs index 363f7ac..00cd814 100644 --- a/src/Shentun.ColumnReferencePlugIns/ImportLisResultPlugInsBase.cs +++ b/src/Shentun.ColumnReferencePlugIns/ImportLisResultPlugInsBase.cs @@ -75,7 +75,7 @@ ORDER BY register_check.patient_register_id public override Task DoWork() { - var loginResult = LoginAsync().Result; + //var loginResult = LoginAsync().Result; var queryDaysStr = InterfaceConfig.GetSection("Interface").GetSection("Scheduler").GetSection("QueryDays").Value; if (string.IsNullOrWhiteSpace(queryDaysStr)) { diff --git a/src/Shentun.ColumnReferencePlugIns/ImportPacsResultPlugInsBase.cs b/src/Shentun.ColumnReferencePlugIns/ImportPacsResultPlugInsBase.cs index ebccf6d..1c2e935 100644 --- a/src/Shentun.ColumnReferencePlugIns/ImportPacsResultPlugInsBase.cs +++ b/src/Shentun.ColumnReferencePlugIns/ImportPacsResultPlugInsBase.cs @@ -80,7 +80,7 @@ ORDER BY register_check.patient_register_id public override Task DoWork() { - var loginResult = LoginAsync().Result; + //var loginResult = LoginAsync().Result; var queryDaysStr = InterfaceConfig.GetSection("Interface").GetSection("Scheduler").GetSection("QueryDays").Value; if (string.IsNullOrWhiteSpace(queryDaysStr)) { diff --git a/src/Shentun.ColumnReferencePlugIns/PlugInsBase.cs b/src/Shentun.ColumnReferencePlugIns/PlugInsBase.cs index ecf1891..383a561 100644 --- a/src/Shentun.ColumnReferencePlugIns/PlugInsBase.cs +++ b/src/Shentun.ColumnReferencePlugIns/PlugInsBase.cs @@ -10,7 +10,9 @@ using Shentun.Utilities; using System; using System.Collections.Generic; using System.Data.Common; +using System.IdentityModel.Tokens.Jwt; using System.Linq; +using System.Linq.Dynamic.Core.Tokenizer; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; @@ -89,7 +91,7 @@ namespace Shentun.Peis.PlugIns { DepartmentColumnReferenceId = new Guid(departmentColumnReferenceIdStr); } - + var userColumnReferenceIdStr = InterfaceConfig.GetSection("Interface") .GetSection("UserColumnReferenceId").Value; if (!string.IsNullOrWhiteSpace(userColumnReferenceIdStr)) @@ -126,9 +128,10 @@ namespace Shentun.Peis.PlugIns return conn; } - public async Task CallAppServiceAsync(string url, TInput data,string method = "post") + public async Task CallAppServiceAsync(string url, TInput data, string method = "post") { string baseAddress = _appBaseAddress; + await CheckLoginAsync(); using (var httpClientHandler = new HttpClientHandler()) { using (var httpClient = new HttpClient(httpClientHandler)) @@ -140,7 +143,7 @@ namespace Shentun.Peis.PlugIns 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); + var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat); using (HttpContent httpContent = new StringContent(sendData)) { httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); @@ -153,7 +156,7 @@ namespace Shentun.Peis.PlugIns { response = await httpClient.GetAsync(url); } - + string result; if (!response.IsSuccessStatusCode) { @@ -161,23 +164,23 @@ namespace Shentun.Peis.PlugIns throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result); } result = await response.Content.ReadAsStringAsync(); - + dynamic resultDto = JsonConvert.DeserializeObject(result); - if(resultDto != null) + if (resultDto != null) { - if(resultDto.code == "-1") + if (resultDto.code == "-1") { - throw new Exception($"调用WebApi失败,返回-1,消息:"+resultDto.message); + throw new Exception($"调用WebApi失败,返回-1,消息:" + resultDto.message); } JObject jsonObject = JObject.Parse(result); var returnStr = jsonObject["data"].ToString(); - if(string.IsNullOrWhiteSpace(returnStr) || returnStr == "null") + if (string.IsNullOrWhiteSpace(returnStr) || returnStr == "null") { return default(TOut); } - + var returnValue = JsonConvert.DeserializeObject(returnStr); - + return returnValue; } return resultDto; @@ -192,9 +195,9 @@ namespace Shentun.Peis.PlugIns } - public virtual Task DoWork() + public virtual Task DoWork() { - return Task.CompletedTask; + return Task.CompletedTask; } public async virtual Task LoginAsync() @@ -202,9 +205,16 @@ namespace Shentun.Peis.PlugIns var relult = await LoginAsync(SelfUser, SelfPassword); return relult; } - public async Task LoginAsync(string userId,string password) + public async Task LoginAsync(string userId, string password) { - + if (string.IsNullOrWhiteSpace(userId)) + { + throw new Exception("用户ID不能为空"); + } + if (string.IsNullOrWhiteSpace(password)) + { + throw new Exception("密码不能为空"); + } using (var httpClientHandler = new HttpClientHandler()) { using (var httpClient = new HttpClient(httpClientHandler)) @@ -231,12 +241,12 @@ namespace Shentun.Peis.PlugIns throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result); } result = await response.Content.ReadAsStringAsync(); - var restultDto = JsonConvert.DeserializeObject(result); + var restultDto = JsonConvert.DeserializeObject(result); if (restultDto == null) { throw new Exception("返回结果是空"); } - if (restultDto.Code != "1") + if (restultDto.Code != "1") { throw new Exception($"登录失败{restultDto.Message}"); } @@ -247,5 +257,41 @@ namespace Shentun.Peis.PlugIns } } } + + private async Task CheckLoginAsync() + { + if (string.IsNullOrWhiteSpace(_accesToken)) + { + await LoginAsync(); + } + else + { + var handler = new JwtSecurityTokenHandler(); + var payload = handler.ReadJwtToken(_accesToken).Payload; + var claims = payload.Claims; + var exp = claims.First(claim => claim.Type == "exp").Value; + if (exp == null) + { + await LoginAsync(); + } + else + { + if (long.TryParse(exp, out var expires)) + { + var expireTime = DateTimeOffset.FromUnixTimeSeconds(expires).LocalDateTime; + if (expireTime <= DateTime.Now) + { + await LoginAsync(); + } + } + else + { + await LoginAsync(); + } + + } + + } + } } } diff --git a/src/Shentun.Peis.Application/ImportLisResults/ImportLisResultAppService.cs b/src/Shentun.Peis.Application/ImportLisResults/ImportLisResultAppService.cs index bfa9c54..7b23026 100644 --- a/src/Shentun.Peis.Application/ImportLisResults/ImportLisResultAppService.cs +++ b/src/Shentun.Peis.Application/ImportLisResults/ImportLisResultAppService.cs @@ -16,6 +16,7 @@ using Shentun.Peis.Units; using SqlSugar; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Text.Json; @@ -115,7 +116,12 @@ namespace Shentun.Peis.ImportLisResults _registerCheckAppService = registerCheckAppService; _thirdInterfaceRepository = thirdInterfaceRepository; } - + /// + /// 从第三方接口导入结果 + /// + /// + /// + /// [HttpPost("api/app/ImportLisResult/ImportResult")] public async Task ImportResultAsync(List input) { @@ -273,7 +279,12 @@ namespace Shentun.Peis.ImportLisResults } - + /// + /// 导入某个人的结果 + /// + /// + /// + [HttpPost("api/app/ImportLisResult/ImportResultByPatientRegisterId")] public async Task ImportResultByPatientRegisterIdAsync(PatientRegisterIdInputDto input) { var thirdInterfaces = await _thirdInterfaceRepository.GetListAsync(o => @@ -282,12 +293,15 @@ namespace Shentun.Peis.ImportLisResults foreach (var thirdInterface in thirdInterfaces) { var parmValue = thirdInterface.ParmValue; - JsonDocument doc = JsonDocument.Parse(parmValue); - var assemblyName = doc.RootElement.GetProperty("Interface").GetProperty("AssemblyName").ToString(); - var className = doc.RootElement.GetProperty("Interface").GetProperty("ClassName").ToString(); - } - + var configurationBuilder = new ConfigurationBuilder() + .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue))); + var config = configurationBuilder.Build(); + var assemblyName = config.GetSection("Interface").GetSection("AssemblyName").Value; + var className = config.GetSection("Interface").GetSection("ClassName").Value; + object[] objects = new object[] { input.PatientRegisterId }; + var pluginsOut = await Utilities.ReflectionHelper.InvokeAsync(assemblyName, className, parmValue, "ImportResultByPatientRegisterIdAsync", objects); + } } private async Task UpdateItemReferenceRangeValueAsync(Guid itemId, char sexId, int? age, string referenceRangeValue) diff --git a/src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs b/src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs index f2c6b00..1e07c2e 100644 --- a/src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs +++ b/src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs @@ -4,9 +4,12 @@ using Microsoft.Extensions.Configuration; using NPOI.SS.Formula.Functions; using NUglify.Helpers; using Shentun.Peis.DiagnosisFunctions; +using Shentun.Peis.Enums; using Shentun.Peis.ImportLisResults; using Shentun.Peis.Items; using Shentun.Peis.Models; +using Shentun.Peis.PatientRegisters; +using Shentun.Peis.PlugIns; using Shentun.Peis.ReferenceRanges; using Shentun.Peis.RegisterCheckItems; using Shentun.Peis.RegisterChecks; @@ -32,6 +35,7 @@ namespace Shentun.Peis.ImportPacsResults [Authorize] public class ImportPacsResultAppService : ApplicationService { + private readonly IRepository _thirdInterfaceRepository; private readonly IRepository _registerCheckItemRepository; private readonly IRepository _registerCheckPictureRepository; private readonly IRepository _patientRegisterRepository; @@ -85,7 +89,8 @@ namespace Shentun.Peis.ImportPacsResults ItemManager itemManager, UnitManager unitManager, RegisterCheckAppService registerCheckAppService, - IRepository registerCheckPictureRepository) + IRepository registerCheckPictureRepository, + IRepository thirdInterfaceRepository) { _registerCheckRepository = registerCheckRepository; _userRepository = userRepository; @@ -113,6 +118,7 @@ namespace Shentun.Peis.ImportPacsResults _unitManager = unitManager; _registerCheckAppService = registerCheckAppService; _registerCheckPictureRepository = registerCheckPictureRepository; + _thirdInterfaceRepository = thirdInterfaceRepository; } [HttpPost("api/app/ImportPacsResult/ImportResult")] @@ -302,5 +308,25 @@ namespace Shentun.Peis.ImportPacsResults } + + [HttpPost("api/app/ImportPacsResult/ImportResultByPatientRegisterId")] + public async Task ImportResultByPatientRegisterIdAsync(PatientRegisterIdInputDto input) + { + var thirdInterfaces = await _thirdInterfaceRepository.GetListAsync(o => + o.ThirdInterfaceType == ThirdInterfaceTypeFlag.ImportPacsResult + && o.IsActive == 'Y'); + foreach (var thirdInterface in thirdInterfaces) + { + var parmValue = thirdInterface.ParmValue; + var configurationBuilder = new ConfigurationBuilder() + .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue))); + var config = configurationBuilder.Build(); + var assemblyName = config.GetSection("Interface").GetSection("AssemblyName").Value; + var className = config.GetSection("Interface").GetSection("ClassName").Value; + object[] objects = new object[] { input.PatientRegisterId }; + var pluginsOut = await Utilities.ReflectionHelper.InvokeAsync(assemblyName, className, parmValue, "ImportResultByPatientRegisterIdAsync", objects); + + } + } } } diff --git a/test/Shentun.Peis.Application.Tests/ImportLisResultAppServiceTest.cs b/test/Shentun.Peis.Application.Tests/ImportLisResultAppServiceTest.cs index 838e535..755a586 100644 --- a/test/Shentun.Peis.Application.Tests/ImportLisResultAppServiceTest.cs +++ b/test/Shentun.Peis.Application.Tests/ImportLisResultAppServiceTest.cs @@ -1,6 +1,7 @@ using Shentun.Peis.ChargeRequests; using Shentun.Peis.ImportLisResults; using Shentun.Peis.Models; +using Shentun.Peis.PatientRegisters; using System; using System.Collections.Generic; using System.Linq; @@ -67,5 +68,20 @@ namespace Shentun.Peis await unitOfWork.CompleteAsync(); } } + + + [Fact] + public async Task ImportResultByPatientRegisterIdAsync() + { + using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true)) + { + await _appService.ImportResultByPatientRegisterIdAsync(new PatientRegisterIdInputDto() + { + PatientRegisterId = new Guid("3a128196-ec34-aa17-0a04-b4bb6bafc752") + }); + await unitOfWork.CompleteAsync(); + } + } + } } diff --git a/test/Shentun.Peis.Application.Tests/ImportPacsResultAppServiceTest.cs b/test/Shentun.Peis.Application.Tests/ImportPacsResultAppServiceTest.cs index 8cd4bdb..bb226a4 100644 --- a/test/Shentun.Peis.Application.Tests/ImportPacsResultAppServiceTest.cs +++ b/test/Shentun.Peis.Application.Tests/ImportPacsResultAppServiceTest.cs @@ -1,6 +1,7 @@ using Shentun.Peis.ImportLisResults; using Shentun.Peis.ImportPacsResults; using Shentun.Peis.Models; +using Shentun.Peis.PatientRegisters; using Shentun.Utilities; using System; using System.Collections.Generic; @@ -79,6 +80,20 @@ namespace Shentun.Peis } + [Fact] + public async Task ImportResultByPatientRegisterIdAsync() + { + using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true)) + { + await _appService.ImportResultByPatientRegisterIdAsync(new PatientRegisterIdInputDto() + { + PatientRegisterId = new Guid("3a128196-ec34-aa17-0a04-b4bb6bafc752") + }); + await unitOfWork.CompleteAsync(); + } + } + + [Fact] public void ConvertPdfToImage() { diff --git a/test/Shentun.Peis.Application.Tests/appsettings.json b/test/Shentun.Peis.Application.Tests/appsettings.json index a734ba5..04c7cde 100644 --- a/test/Shentun.Peis.Application.Tests/appsettings.json +++ b/test/Shentun.Peis.Application.Tests/appsettings.json @@ -4,6 +4,19 @@ "Microsoft.EntityFrameworkCore.Database.Command": "Debug" } }, + "App": { + "SelfUrl": "http://10.1.12.140:9529", + "ClientUrl": "http://10.1.12.140:9529", + //"SelfUrl": "http://localhost:9530", + //"ClientUrl": "http://localhost:9530", + "CorsOrigins": "https://*.Peis.com,http://localhost:4200,http://localhost:9530,http://192.168.1.108:9530,http://localhost:8080,http://localhost:8081", + "RedirectAllowedUrls": "http://localhost:9530", + "Sql": "select id::varchar as Code ,display_name as DisplayName ,simple_code as SimpleCode ,display_order as DisplayOrder from asbitem", + "ColumnNames": "编码,名称", + "SelfUser": "admin", + "SelfPassword": "666666" + + }, "ConnectionStrings": { //"Default": "Host=140.143.162.39;Port=5432;Database=ShentunPeis070703;User ID=postgres;Password=shentun123;", "Default": "Host=10.1.12.140;Port=5432;Database=ShentunPeis0508;User ID=postgres;Password=st123;"