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.

140 lines
6.2 KiB

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