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.

142 lines
6.2 KiB

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