ReadCardProcess.cs 7.8 KB

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