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.

141 lines
6.1 KiB

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