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.

173 lines
6.7 KiB

2 years ago
  1. using Dapper;
  2. using Npgsql;
  3. using ServiceReferenceHzcyHis;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data.Common;
  7. using System.Linq;
  8. using System.ServiceModel;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using static ServiceReferenceHzcyHis.bstjPortTypeClient;
  12. namespace Shentun.Peis.PlugIns.Gem
  13. {
  14. public class ChargeRequestPlugInsGem : ChargeRequestPlugInsBase
  15. {
  16. private string _endpointAddress = "";
  17. public ChargeRequestPlugInsGem(string parmValue) : base(parmValue)
  18. {
  19. _endpointAddress = InterfaceConfig.GetSection("Interface").GetSection("EndpointAddress").Value;
  20. }
  21. public override async Task<ChargeRequestPlugInsOut> SendRequest(ChargeRequestPlugInsInput input)
  22. {
  23. //建立人员档案
  24. var patientRegisterForPlugIns = await GetPatientRegisterForPlugInsAsync(input.ChargeRequestId);
  25. var chargeRequestForPlugIns = await GeChargeRequestForPlugInsAsync(input.ChargeRequestId);
  26. if(chargeRequestForPlugIns == null)
  27. {
  28. throw new Exception("没有申请单信息");
  29. }
  30. if (!chargeRequestForPlugIns.Asbitems.Any())
  31. {
  32. throw new Exception("申请单没有组合项目信息");
  33. }
  34. if (patientRegisterForPlugIns.BirthDate == null)
  35. {
  36. throw new Exception("出生日期不能为空");
  37. }
  38. var hisPatientQueryInput = new HisPatientQueryInput()
  39. {
  40. Data = new HisPatientQueryDataInput()
  41. {
  42. MsgHeader = new HisMsgHeaderInput()
  43. {
  44. Sender = "PEIS",
  45. MsgType = "SVR_ODS_1101",
  46. MsgVersion = "3.1",
  47. },
  48. Patient = new HisPatientQueryPatientInput()
  49. {
  50. IdCard = patientRegisterForPlugIns.IdNo,
  51. IdCardCode = "01",
  52. Name = patientRegisterForPlugIns.PatientName,
  53. Sex = "1",
  54. BirthDate = ((DateTime)patientRegisterForPlugIns.BirthDate).ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo),
  55. PatientPhone = patientRegisterForPlugIns.MobileTelephone,
  56. EthnicGroupCode = "01",
  57. WorkUnit = patientRegisterForPlugIns.CustomerOrgName,
  58. Address = patientRegisterForPlugIns.Address,
  59. }
  60. }
  61. };
  62. var result = await PatientQuery(hisPatientQueryInput);
  63. if (result.MsgHeader.Status != "true")
  64. {
  65. throw new Exception("建立HIS档案失败"+ result.MsgHeader.Detail);
  66. }
  67. //更新人员登记信息
  68. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  69. {
  70. conn.Execute(@"update patient_register set his_patient_id = @HisPatientId
  71. where id = @PatientRegisterId",
  72. new { HisPatientId = result.Patient.PatientId,
  73. PatientRegisterId = patientRegisterForPlugIns.PatientRegisterId
  74. });
  75. }
  76. //发送项目
  77. var hisInput = new HisMecSaveInput()
  78. {
  79. Data = new HisMecSaveDataInput()
  80. {
  81. MsgHeader = new HisMsgHeaderInput()
  82. {
  83. Sender = "PEIS",
  84. MsgType = "SVR_ODS_6101",
  85. MsgVersion = "3.1",
  86. },
  87. Items = new List<HisMecSaveDataItemInput>()
  88. {
  89. new HisMecSaveDataItemInput()
  90. {
  91. ExamRequestNo =chargeRequestForPlugIns.ChargeRequestNo,
  92. FeeType = "1",
  93. EmpId = result.Patient.PatientId,
  94. DeptId = "",
  95. DoctId = "",
  96. ExeDeptId = "",
  97. Tjunit = patientRegisterForPlugIns.CustomerOrgName,
  98. Tjfee = chargeRequestForPlugIns.Asbitems.Sum(o=>o.Charges).ToString(),
  99. Ztxm = "",
  100. Remark = "体检科"
  101. },
  102. }
  103. }
  104. };
  105. var mecSaveResult = await MecSave(hisInput);
  106. if (mecSaveResult.MsgHeader.Status != "true")
  107. {
  108. throw new Exception("建立HIS档案失败" + mecSaveResult.MsgHeader.Detail);
  109. }
  110. //更新申请单信息
  111. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  112. {
  113. conn.Execute(@"update charge_request set his_charge_no = @HisChargeNo
  114. where id = @ChargeRequestId",
  115. new
  116. {
  117. HisChargeNo = mecSaveResult.MsgHeader.Yjxh,
  118. ChargeRequestId = input.ChargeRequestId
  119. });
  120. }
  121. return new ChargeRequestPlugInsOut();
  122. }
  123. public async Task<HisPatientQueryOut> PatientQuery(HisPatientQueryInput input)
  124. {
  125. using (var client = CreateClient())
  126. {
  127. input.SeviceBaseArg.Service = "patientQuery";
  128. var data = XmlHelper.SerializeToXml(input.Data);
  129. var resultStr = (await client.invokeAsync(input.SeviceBaseArg.Service,
  130. input.SeviceBaseArg.Urid,
  131. input.SeviceBaseArg.Pwd,
  132. data)).@return;
  133. var result = XmlHelper.DeserializeXml<HisPatientQueryOut>(resultStr);
  134. return result;
  135. }
  136. }
  137. public async Task<HisMecSaveOut> MecSave(HisMecSaveInput input)
  138. {
  139. using (var client = CreateClient())
  140. {
  141. input.SeviceBaseArg.Service = "mecSave";
  142. var data = XmlHelper.SerializeToXml(input.Data);
  143. var resultStr = (await client.invokeAsync(input.SeviceBaseArg.Service,
  144. input.SeviceBaseArg.Urid,
  145. input.SeviceBaseArg.Pwd,
  146. data)).@return;
  147. var result = XmlHelper.DeserializeXml<HisMecSaveOut>(resultStr);
  148. return result;
  149. }
  150. }
  151. private bstjPortTypeClient CreateClient()
  152. {
  153. return new bstjPortTypeClient(EndpointConfiguration.bstjHttpSoap11Endpoint,
  154. _endpointAddress);
  155. }
  156. }
  157. }