You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
5.6 KiB

2 years ago
2 years ago
2 years ago
2 years ago
  1. using Newtonsoft.Json.Converters;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net.Http.Headers;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Shentun.Peis.ImportPacsResults;
  10. using NPOI.SS.Formula.Functions;
  11. using Shentun.Peis.ImportLisResults;
  12. namespace Shentun.Peis.PlugIns.Gem
  13. {
  14. public class PacsImportResultPlugInsGem : ImportPacsResultPlugInsBase
  15. {
  16. public PacsImportResultPlugInsGem(string parmValue) : base(parmValue)
  17. {
  18. }
  19. public override async Task<ImportPacsResultPlugInsOut> ImportResultAsync(ImportPacsResultPlugInsInput input)
  20. {
  21. //if (DepartmentColumnReferenceId == null || DepartmentColumnReferenceId == Guid.Empty)
  22. //{
  23. // throw new Exception("没有设置科室编码对照");
  24. //}
  25. var pacsRequests = await GetPacsRequestForImportResultPlugInssAsync(input.PatientRegisterId);
  26. var beginTime = DateTime.Now.Date.AddDays(-30);
  27. foreach (var pacsRequest in pacsRequests)
  28. {
  29. var interfaceInpu = new PacsImportResultInterfaceInput()
  30. {
  31. tjNum = pacsRequest.CheckRequestNo,
  32. organizeCode = "1",
  33. patientType = "3",
  34. //requestId = pacsRequest.CheckRequestNo,
  35. beginTime = beginTime.ToString("yyyy-MM-dd HH:mm:ss"),
  36. pageNo = 1,
  37. pageSize = 20
  38. };
  39. var apiResult = await CallInterfaceServiceAsync<PacsImportResultInterfaceInput,
  40. PacsImportResultInterfaceOut>(interfaceInpu);
  41. if(!apiResult.data.Any())
  42. {
  43. continue;
  44. }
  45. var firstData = apiResult.data[0];
  46. if(!DateTime.TryParse(firstData.reportDateTime,out var checkDate))
  47. {
  48. throw new Exception("报告时间格式不正确");
  49. }
  50. var createImportPacsResultDto = new CreateImportPacsResultDto()
  51. {
  52. CheckRequestNo = pacsRequest.CheckRequestNo,
  53. PatientName = pacsRequest.PatientName,
  54. Result = firstData.examDescript,
  55. Summary = firstData.examDiagnosis,
  56. Suggestion = firstData.suggestion,
  57. CheckDate = checkDate,
  58. CheckDoctorName = firstData.reportDoctorName,
  59. Files = new List<CreateImportPacsResultPictureDto>()
  60. {
  61. new CreateImportPacsResultPictureDto()
  62. {
  63. IsPrint = 'Y',
  64. FileTransMode = "0",
  65. FileName = firstData.reportUrl,
  66. FileFormat = "1",
  67. FileBase64 = Shentun.Utilities.FileHelper.ToBase64(firstData.reportUrl)
  68. },
  69. }
  70. };
  71. var callResult = await CallAppServiceAsync<CreateImportPacsResultDto, object>("api/app/ImportLisResult/ImportResult", createImportPacsResultDto);
  72. }
  73. var result = new ImportPacsResultPlugInsOut();
  74. return result;
  75. }
  76. public async Task<TOut> CallInterfaceServiceAsync<TInput, TOut>( TInput data)
  77. {
  78. string baseAddress = InterfaceWebApiUrl;
  79. using (var httpClientHandler = new HttpClientHandler())
  80. {
  81. using (var httpClient = new HttpClient(httpClientHandler))
  82. {
  83. httpClient.BaseAddress = new Uri(baseAddress);
  84. httpClient.DefaultRequestHeaders.Accept.Add(
  85. new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型
  86. //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
  87. IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
  88. timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
  89. var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
  90. using (HttpContent httpContent = new StringContent(sendData))
  91. {
  92. httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
  93. HttpResponseMessage response = await httpClient.PostAsync("", httpContent);
  94. string result;
  95. if (!response.IsSuccessStatusCode)
  96. {
  97. result = response.Content.ReadAsStringAsync().Result;
  98. throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
  99. }
  100. result = await response.Content.ReadAsStringAsync();
  101. dynamic resultDto = JsonConvert.DeserializeObject<TOut>(result);
  102. if (resultDto != null)
  103. {
  104. if (resultDto.code!= "200")
  105. {
  106. throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.code + resultDto.msg);
  107. }
  108. }
  109. return resultDto;
  110. }
  111. }
  112. }
  113. }
  114. }
  115. }