ReadCardProcess.cs 8.1 KB

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