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.

139 lines
6.0 KiB

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