ReadCardProcess.cs 8.2 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. 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. outParam = "";
  107. string errorMsg = "";
  108. JObject joInput = new JObject();
  109. JObject joData = new JObject();
  110. joData.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
  111. joData.Add("mdtrt_cert_no", Utils.ConvertMdtrtcertNo());
  112. joData.Add("card_sn", Global.pat.card.SN);
  113. joData.Add("begntime", Utils.GetShortDateTimeNow());
  114. joData.Add("psn_cert_type", Global.pat.certType);
  115. joData.Add("certno", Global.pat.certNO); //证件号码
  116. joData.Add("psn_name", Global.pat.name);
  117. joInput.Add("data", joData);
  118. InvokeHelper invoker = new InvokeHelper();
  119. JObject joRtn = invoker.invokeCenterService(TradeEnum.PatientInfo, joInput);
  120. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  121. {
  122. outParam = "获取病人信息失败:" + errorMsg;
  123. return -1;
  124. }
  125. else
  126. {
  127. //joRtn["output"]["baseinfo"]["bizCode"] = Global.pat.card.BusinessCode;
  128. outParam = joRtn.ToString();
  129. parsePatient(joRtn);
  130. return 0;
  131. }
  132. }
  133. /// <summary>
  134. /// 读卡并获取基本信息
  135. /// </summary>
  136. /// <param name="outParam"></param>
  137. /// <returns></returns>
  138. public int trade1161(out string outParam)
  139. {
  140. outParam = "";
  141. string errorMsg = "";
  142. JObject joInput = new JObject();
  143. joInput.Add("begntime", Utils.GetShortDateTimeNow());
  144. JObject joRtn = new JObject();
  145. joRtn = invoker.invokeCenterService(TradeEnum.ReadCardInfo, joInput);
  146. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  147. {
  148. outParam = "读卡失败:" + errorMsg;
  149. return -1;
  150. }
  151. else
  152. {
  153. parsePatient(joRtn);
  154. outParam = joRtn.ToString();
  155. }
  156. return 0;
  157. }
  158. /// <summary>
  159. /// 解析人员基本信息
  160. /// </summary>
  161. /// <param name="joRtn"></param>
  162. public void parsePatient(JObject joRtn)
  163. {
  164. // 基线版
  165. PersonCardInfo info = JsonHelper.getOutput<PersonCardInfo>(joRtn);
  166. if (info.cardInfo != null)
  167. {
  168. Global.pat.card.NO = info.cardInfo.cardno;
  169. Global.pat.card.SN = info.cardInfo.card_sn;
  170. Global.pat.card.Cardtoken = info.cardInfo.ecToken;
  171. Global.pat.ecToken = info.cardInfo.ecToken;
  172. }
  173. //Global.writeLog("病人信息:"+joRtn.ToString());
  174. if (info.insuInfo != null && info.insuInfo.Length > 0)
  175. {
  176. //参保地
  177. Global.pat.insuplc_admdvs = info.insuInfo[0].insuplc_admdvs;
  178. Global.pat.insuplc_name = info.insuInfo[0].insuplc_name;
  179. Global.pat.medType = info.insuInfo[0].med_type ?? "C";
  180. }
  181. //证件号
  182. Global.pat.certNO = info.baseInfo?.certno;
  183. // 人员证件类型
  184. Global.pat.certType = info.baseInfo?.psn_cert_type;
  185. // 就诊类型
  186. if (string.IsNullOrEmpty(Global.pat.mdtrtcertType))
  187. {
  188. Global.pat.mdtrtcertType = "03";
  189. }
  190. // 就诊凭证号
  191. if (!string.IsNullOrEmpty(Global.pat.card.NO))
  192. {
  193. Global.pat.mdtrtcertNO = Global.pat.card.NO;
  194. }
  195. // 没有卡号用证件号
  196. if (string.IsNullOrEmpty(Global.pat.mdtrtcertNO))
  197. {
  198. Global.pat.mdtrtcertNO = Global.pat.certNO;
  199. }
  200. Global.pat.payOrdId = info.platformOrderNo;
  201. }
  202. /// <summary>
  203. /// 通过电子凭证获取基本信息
  204. /// </summary>
  205. /// <param name="outParam"></param>
  206. /// <returns></returns>
  207. public int tradeEcToken(out string outParam)
  208. {
  209. //cardInfo
  210. outParam = "";
  211. int ret = ECTokenReader.ECQuery("1",out outParam);
  212. return ret;
  213. }
  214. }
  215. }