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.

151 lines
6.4 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
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
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
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
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
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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using Dapper;
  2. using Microsoft.Data.SqlClient;
  3. using Newtonsoft.Json;
  4. using Npgsql;
  5. using NPOI.Util;
  6. using NUglify.Helpers;
  7. using Oracle.ManagedDataAccess.Client;
  8. using Shentun.Peis.ImportLisResults;
  9. using Shentun.Peis.LisRequests;
  10. using Shentun.Utilities;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data.Common;
  14. using System.Linq;
  15. using System.Net.Http.Headers;
  16. using System.Security.Policy;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. namespace Shentun.Peis.PlugIns
  20. {
  21. public class ImportLisResultPlugInsDbBase : ImportLisResultPlugInsBase
  22. {
  23. public ImportLisResultPlugInsDbBase(string parmValue) : base(parmValue)
  24. {
  25. }
  26. public override async Task<ImportLisResultPlugInsOut> ImportResultByPatientRegisterIdAsync(Guid patientRegisterId)
  27. {
  28. if (ItemColumnReferenceId == null || ItemColumnReferenceId == Guid.Empty)
  29. {
  30. throw new Exception("没有设置项目编码对照");
  31. }
  32. var result = new ImportLisResultPlugInsOut();
  33. var execOrganizationUnitIdStr = InterfaceConfig.GetSection("Interface").GetSection("ExecOrganizationUnitId").Value;
  34. if (string.IsNullOrWhiteSpace(execOrganizationUnitIdStr))
  35. {
  36. throw new Exception("执行科室配置不能为空");
  37. }
  38. if (!Guid.TryParse(execOrganizationUnitIdStr, out Guid execOrganizationUnitId))
  39. {
  40. throw new Exception("执行科室配置不是有效的GUID值");
  41. }
  42. var lisRequests = await GetLisRequestForImportResultPlugInssAsync(patientRegisterId);
  43. using (DbConnection conn = CreateInterfaceDbConnect())
  44. {
  45. //设置结果,生成小结
  46. //await LoginAsync();
  47. var createImportLisResultDtos = new List<CreateImportLisResultDto>();
  48. foreach (var lisRequest in lisRequests)
  49. {
  50. //if (lisRequest.LisRequestNo == "2405090117")
  51. //{
  52. // ;
  53. //}
  54. createImportLisResultDtos.Clear();
  55. string sql;
  56. sql = InterfaceSql + " where " + InterfaceSqlKeyColumn + " = '" + lisRequest.LisRequestNo + "'";
  57. var lisResultFromInterfaces = (await conn.QueryAsync<LisResultFromImportInterface>(sql)).ToList();
  58. try
  59. {
  60. foreach (var lisResult in lisResultFromInterfaces)
  61. {
  62. if(string.IsNullOrWhiteSpace(lisResult.Result))
  63. {
  64. continue;
  65. }
  66. if (string.IsNullOrWhiteSpace(lisResult.ItemId))
  67. {
  68. throw new Exception("第三方接口数据项目编码不能为空");
  69. }
  70. if (string.IsNullOrWhiteSpace(lisResult.ItemName))
  71. {
  72. throw new Exception("第三方接口数据项目名称不能为空");
  73. }
  74. if (string.IsNullOrWhiteSpace(lisResult.CheckDoctorName))
  75. {
  76. throw new Exception("检验医生不能为空");
  77. }
  78. //if(lisResult.ItemId == "435")
  79. //{
  80. // ;
  81. //}
  82. var columnReferenceCodes = await GetColumnReferenceCodeValuesAsync(ItemColumnReferenceId, lisResult.ItemId);
  83. if (columnReferenceCodes == null || !columnReferenceCodes.Any())
  84. {
  85. //throw new Exception($"LIS系统中项目名:{lisResult.ItemName} 编码:{lisResult.ItemId}没有与体检系统对照编码");
  86. continue;
  87. }
  88. foreach (var columnReferenceCode in columnReferenceCodes)
  89. {
  90. if (string.IsNullOrWhiteSpace(columnReferenceCode.CodeValue))
  91. {
  92. continue;
  93. }
  94. if (!Guid.TryParse(columnReferenceCode.CodeValue, out var appItemId))
  95. {
  96. throw new Exception($"{lisResult.ItemName}对照的编码无效");
  97. }
  98. var createImportLisResultDto = new CreateImportLisResultDto()
  99. {
  100. LisRequestNo = lisResult.LisRequestNo,
  101. ItemId = appItemId,
  102. ItemName = lisResult.ItemName,
  103. Result = lisResult.Result,
  104. Unit = lisResult.Unit,
  105. ReferenceRangeValue = lisResult.ReferenceRangeValue,
  106. CriticalRangeValue = lisResult.CriticalRangeValue,
  107. ResultStatusId = lisResult.ResultStatusId,
  108. ReportPrompt = lisResult.ReportPrompt,
  109. CheckDoctorName = lisResult.CheckDoctorName,
  110. CheckDate = lisResult.CheckDate,
  111. ExecOrganizationUnitId = execOrganizationUnitId
  112. };
  113. createImportLisResultDtos.Add(createImportLisResultDto);
  114. }
  115. }
  116. if (!createImportLisResultDtos.Any())
  117. {
  118. continue;
  119. }
  120. var callResult = await CallAppServiceAsync<List<CreateImportLisResultDto>, object>("api/app/ImportLisResult/ImportResult", createImportLisResultDtos);
  121. }
  122. catch (Exception ex)
  123. {
  124. //throw ex;
  125. }
  126. }
  127. }
  128. return result;
  129. }
  130. }
  131. }