ReadCardProcess.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. if (cc.ShowDialog() == DialogResult.OK)
  26. {
  27. Global.businessType = "";
  28. Utils.GetInsuCode();
  29. Global.pat.certType = "01";
  30. //电子凭证
  31. if (cc.cardType == "01")
  32. {
  33. Global.pat.mdtrtcertType = "01";
  34. Global.businessType = cc.businessType;
  35. tradeEcToken(out outParam);
  36. //return trade1161(out outParam);
  37. return Success();
  38. }
  39. //身份证
  40. if (cc.cardType == "02")
  41. {
  42. Global.pat.mdtrtcertType = "02";
  43. //读身份证
  44. CardReader reader = new CardReader();
  45. int rtn = reader.ReadSFZ(out outParam);
  46. if (rtn == 0)
  47. {
  48. trade1101(out outParam);
  49. }
  50. return Success();
  51. }
  52. //社保卡
  53. if (cc.cardType == "03")
  54. {
  55. #region 调用读卡接口信息
  56. Global.pat.mdtrtcertType = "03";
  57. //return trade1161(out outParam);
  58. int rtn = 0;
  59. if (!Global.curEvt.enabledDebug)
  60. {
  61. CardReader reader = new CardReader();
  62. rtn = reader.ReadCardBas(out outParam);
  63. }
  64. if (rtn == 0)
  65. {
  66. //清除原数据
  67. trade1101(out outParam);
  68. }
  69. return Success();
  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. outParam = "";
  94. string errorMsg = "";
  95. JObject joInput = new JObject();
  96. JObject joData = new JObject();
  97. joData.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
  98. joData.Add("mdtrt_cert_no", Utils.ConvertMdtrtcertNo());
  99. joData.Add("card_sn", Global.pat.card.SN);
  100. joData.Add("begntime", Utils.GetDateTimeNow());
  101. joData.Add("psn_cert_type", Global.pat.certType);
  102. joData.Add("certno", Global.pat.certNO); //证件号码
  103. joData.Add("psn_name", Global.pat.name);
  104. joInput.Add("data", joData);
  105. InvokeHelper invoker = new InvokeHelper();
  106. JObject joRtn = invoker.invokeCenterService(TradeEnum.PatientInfo, joInput);
  107. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  108. {
  109. outParam = "获取病人信息失败:" + errorMsg;
  110. return -1;
  111. }
  112. else
  113. {
  114. //手动增加业务码(沈阳)
  115. joRtn["output"]["baseinfo"]["bizCode"] = Global.pat.card.BusinessCode;
  116. outParam = joRtn.ToString();
  117. parsePatient(joRtn);
  118. return 0;
  119. }
  120. }
  121. /// <summary>
  122. /// 读卡并获取基本信息
  123. /// </summary>
  124. /// <param name="outParam"></param>
  125. /// <returns></returns>
  126. public int trade1161(out string outParam)
  127. {
  128. outParam = "";
  129. string errorMsg = "";
  130. JObject joInput = new JObject();
  131. joInput.Add("begntime", Utils.GetDateTimeNow());
  132. JObject joRtn = new JObject();
  133. joRtn = invoker.invokeCenterService(TradeEnum.ReadCardInfo, joInput);
  134. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  135. {
  136. outParam = "读卡失败:" + errorMsg;
  137. return -1;
  138. }
  139. else
  140. {
  141. parsePatient(joRtn);
  142. outParam = joRtn.ToString();
  143. }
  144. return 0;
  145. }
  146. /// <summary>
  147. /// 解析人员基本信息
  148. /// </summary>
  149. /// <param name="joRtn"></param>
  150. public void parsePatient(JObject joRtn)
  151. {
  152. // 基线版
  153. PersonCardInfo info = JsonHelper.getOutput<PersonCardInfo>(joRtn);
  154. if (info.cardInfo != null)
  155. {
  156. Global.pat.card.NO = info.cardInfo.cardno;
  157. Global.pat.card.SN = info.cardInfo.card_sn;
  158. Global.pat.card.Cardtoken = info.cardInfo.ecToken;
  159. Global.pat.ecToken = info.cardInfo.ecToken;
  160. }
  161. //Global.writeLog("病人信息:"+joRtn.ToString());
  162. if (info.insuInfo != null && info.insuInfo.Length > 0)
  163. {
  164. //参保地
  165. Global.pat.insuplc_admdvs = info.insuInfo[0].insuplc_admdvs;
  166. Global.pat.insuplc_name = info.insuInfo[0].insuplc_name;
  167. Global.pat.medType = info.insuInfo[0].med_type ?? "C";
  168. }
  169. //证件号
  170. Global.pat.certNO = info.baseInfo?.certno;
  171. // 人员证件类型
  172. Global.pat.certType = info.baseInfo?.psn_cert_type;
  173. // 就诊类型
  174. if (string.IsNullOrEmpty(Global.pat.mdtrtcertType))
  175. {
  176. Global.pat.mdtrtcertType = "03";
  177. }
  178. // 就诊凭证号
  179. if (!string.IsNullOrEmpty(Global.pat.card.NO))
  180. {
  181. Global.pat.mdtrtcertNO = Global.pat.card.NO;
  182. }
  183. if (string.IsNullOrEmpty(Global.pat.mdtrtcertNO))
  184. {
  185. Global.pat.mdtrtcertNO = Global.pat.certNO;
  186. }
  187. Global.pat.payOrdId = info.platformOrderNo;
  188. }
  189. /// <summary>
  190. /// 通过电子凭证获取基本信息
  191. /// </summary>
  192. /// <param name="outParam"></param>
  193. /// <returns></returns>
  194. public int tradeEcToken(out string outParam)
  195. {
  196. //cardInfo
  197. outParam = ECTokenReader.ECQuery("1");
  198. trade1101(out outParam);
  199. return 0;
  200. }
  201. }
  202. }