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.

130 lines
5.7 KiB

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