ReadCardProcess.cs 7.9 KB

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