ReadCardProcess.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Common;
  3. using PTMedicalInsurance.Entity;
  4. using PTMedicalInsurance.Forms;
  5. using PTMedicalInsurance.Helper;
  6. using PTMedicalInsurance.Variables;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace PTMedicalInsurance.Business
  14. {
  15. class ReadCardProcess : AbstractProcess
  16. {
  17. public override CallResult Process(JObject input)
  18. {
  19. JObject joCardInfo = new JObject();
  20. ChooseCard cc = new ChooseCard();
  21. JObject joRtn = new JObject();
  22. JObject joInput = new JObject();
  23. try
  24. {
  25. string safeNo = Global.pat.admType == 1 ? "2207A" : "1101";
  26. DialogResult dialog = tools.ShowAppDiaglog(cc);
  27. if (dialog == DialogResult.OK)
  28. {
  29. Global.businessType = "";
  30. Global.pat.certType = "01";
  31. //电子凭证
  32. if (cc.cardType == "01")
  33. {
  34. Global.pat.mdtrtcertType = "01";
  35. Global.businessType = cc.businessType;
  36. if (tradeEcToken(out outParam) != 0)
  37. {
  38. return Error(outParam);
  39. }
  40. trade1101(out outParam);
  41. return Success();
  42. }
  43. //身份证
  44. if (cc.cardType == "02")
  45. {
  46. Global.pat.mdtrtcertType = "02";
  47. YinHaiSafeCtrl safeCtrl = new YinHaiSafeCtrl();
  48. safeCtrl.Prepare(safeNo);
  49. trade1101(out outParam);
  50. return Success();
  51. }
  52. //社保卡
  53. if (cc.cardType == "03")
  54. {
  55. #region 调用读卡接口信息
  56. Global.pat.mdtrtcertType = "03";
  57. int rtn = 0;
  58. if (!Global.curEvt.enabledDebug)
  59. {
  60. YinHaiSafeCtrl safeCtrl = new YinHaiSafeCtrl();
  61. safeCtrl.Prepare(safeNo);
  62. }
  63. if (rtn == 0)
  64. {
  65. //清除原数据
  66. trade1101(out outParam);
  67. return Success();
  68. }
  69. return Exception(-1, "读卡", outParam);
  70. #endregion
  71. }
  72. }
  73. else
  74. {
  75. //outParam = JsonHelper.setExceptionJson().ToString();
  76. return Exception(-1, "读卡", "取消读卡");
  77. }
  78. return Success();
  79. }
  80. catch (Exception ex)
  81. {
  82. return Error("异常:" + ex.Message);
  83. }
  84. }
  85. /// <summary>
  86. /// 通过证件号获取基本信息(无卡)
  87. /// </summary>
  88. /// <param name="cardNo"></param>
  89. /// <param name="outParam"></param>
  90. /// <returns></returns>
  91. public int trade1101(out string outParam)
  92. {
  93. Utils.GetInsuCode();
  94. outParam = "";
  95. string errorMsg = "";
  96. JObject joInput = new JObject();
  97. JObject joData = new JObject();
  98. joData.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
  99. joData.Add("mdtrt_cert_no", Utils.ConvertMdtrtcertNo());
  100. joData.Add("card_sn", Global.pat.card.SN);
  101. joData.Add("begntime", Utils.GetDateTimeNow());
  102. joData.Add("psn_cert_type", Global.pat.certType);
  103. joData.Add("certno", Global.pat.certNO); //证件号码
  104. joData.Add("psn_name", Global.pat.name);
  105. dynamic joExpContent = new JObject();
  106. joExpContent.card_token = Global.pat.card.Cardtoken;
  107. joData.Add("expContent", joExpContent);
  108. joInput.Add("data", joData);
  109. InvokeHelper invoker = new InvokeHelper();
  110. JObject joRtn = invoker.invokeCenterService(TradeEnum.PatientInfo, joInput);
  111. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  112. {
  113. outParam = "获取病人信息失败:" + errorMsg;
  114. return -1;
  115. }
  116. else
  117. {
  118. //joRtn["output"]["baseinfo"]["bizCode"] = Global.pat.card.BusinessCode;
  119. outParam = joRtn.ToString();
  120. parsePatient(joRtn);
  121. return 0;
  122. }
  123. }
  124. /// <summary>
  125. /// 读卡并获取基本信息
  126. /// </summary>
  127. /// <param name="outParam"></param>
  128. /// <returns></returns>
  129. public int trade1161(out string outParam)
  130. {
  131. outParam = "";
  132. string errorMsg = "";
  133. JObject joInput = new JObject();
  134. joInput.Add("begntime", Utils.GetDateTimeNow());
  135. JObject joRtn = new JObject();
  136. joRtn = invoker.invokeCenterService(TradeEnum.ReadCardInfo, joInput);
  137. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  138. {
  139. outParam = "读卡失败:" + errorMsg;
  140. return -1;
  141. }
  142. else
  143. {
  144. parsePatient(joRtn);
  145. outParam = joRtn.ToString();
  146. }
  147. return 0;
  148. }
  149. /// <summary>
  150. /// 解析人员基本信息
  151. /// </summary>
  152. /// <param name="joRtn"></param>
  153. public void parsePatient(JObject joRtn)
  154. {
  155. // 基线版
  156. PersonCardInfo info = JsonHelper.getOutput<PersonCardInfo>(joRtn);
  157. if (info.cardInfo != null)
  158. {
  159. Global.pat.card.NO = info.cardInfo.cardno;
  160. Global.pat.card.SN = info.cardInfo.card_sn;
  161. Global.pat.card.Cardtoken = info.cardInfo.ecToken;
  162. Global.pat.ecToken = info.cardInfo.ecToken;
  163. }
  164. //Global.writeLog("病人信息:"+joRtn.ToString());
  165. if (info.insuInfo != null && info.insuInfo.Length > 0)
  166. {
  167. //参保地
  168. Global.pat.insuplc_admdvs = info.insuInfo[0].insuplc_admdvs;
  169. Global.pat.insuplc_name = info.insuInfo[0].insuplc_name;
  170. Global.pat.medType = info.insuInfo[0].med_type ?? "C";
  171. }
  172. //证件号
  173. Global.pat.certNO = info.baseInfo?.certno;
  174. // 人员证件类型
  175. Global.pat.certType = info.baseInfo?.psn_cert_type;
  176. // 就诊类型
  177. if (string.IsNullOrEmpty(Global.pat.mdtrtcertType))
  178. {
  179. Global.pat.mdtrtcertType = "03";
  180. }
  181. // 就诊凭证号
  182. if (!string.IsNullOrEmpty(Global.pat.card.NO))
  183. {
  184. Global.pat.mdtrtcertNO = Global.pat.card.NO;
  185. }
  186. // 没有卡号用证件号
  187. if (string.IsNullOrEmpty(Global.pat.mdtrtcertNO))
  188. {
  189. Global.pat.mdtrtcertNO = Global.pat.certNO;
  190. }
  191. Global.pat.payOrdId = info.platformOrderNo;
  192. }
  193. /// <summary>
  194. /// 通过电子凭证获取基本信息
  195. /// </summary>
  196. /// <param name="outParam"></param>
  197. /// <returns></returns>
  198. public int tradeEcToken(out string outParam)
  199. {
  200. //cardInfo
  201. outParam = "";
  202. int ret = ECTokenReader.ECQuery("1",out outParam);
  203. return ret;
  204. }
  205. }
  206. }