ReadCardProcess.cs 8.2 KB

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