ReadCardProcess.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.CardReaders;
  3. using PTMedicalInsurance.Common;
  4. using PTMedicalInsurance.Entity;
  5. using PTMedicalInsurance.Forms;
  6. using PTMedicalInsurance.Helper;
  7. using PTMedicalInsurance.Variables;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace PTMedicalInsurance.Business
  15. {
  16. class ReadCardProcess : AbstractProcess
  17. {
  18. public override CallResult Process(JObject input)
  19. {
  20. JObject joCardInfo = new JObject();
  21. ChooseCard cc = new ChooseCard();
  22. JObject joRtn = new JObject();
  23. JObject joInput = new JObject();
  24. string msg;
  25. try
  26. {
  27. DialogResult dialog = tools.ShowAppDiaglog(cc);
  28. if (dialog == DialogResult.OK)
  29. {
  30. Global.businessType = "";
  31. Global.pat.certType = "01";
  32. //电子凭证
  33. if (cc.cardType == "01")
  34. {
  35. Global.pat.mdtrtcertType = "01";
  36. Global.businessType = cc.businessType;
  37. CardReader reader = new CardReader();
  38. if (reader.ECQuery(out msg) != 0)
  39. {
  40. outParam = "读电子凭证失败!" + msg;
  41. return Error(outParam);
  42. };
  43. JObject joTmp = JObject.Parse(msg);
  44. if (joTmp["code"].ToString() != "0")
  45. {
  46. outParam = "读电子凭证失败!" + joTmp["message"].ToString();
  47. return Error(outParam);
  48. }
  49. Global.pat.mdtrtcertNO = JsonHelper.getDestValue(joTmp, "data.ecToken") ;
  50. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joTmp, "data.insuOrg");
  51. Global.pat.certType = JsonHelper.getDestValue(joTmp, "data.idType");
  52. Global.pat.certNO = JsonHelper.getDestValue(joTmp, "data.idNo");
  53. Global.pat.name = JsonHelper.getDestValue(joTmp, "data.userName");
  54. trade1101(out outParam);
  55. return Parse(outParam);
  56. }
  57. //身份证
  58. if (cc.cardType == "02")
  59. {
  60. Global.pat.mdtrtcertType = "02";
  61. int rtn = -1;
  62. //手工输入身份证
  63. if (cc.tbID.Text != "")
  64. {
  65. Global.pat.certType = "01";
  66. Global.pat.mdtrtcertNO= Global.pat.certNO = cc.tbID.Text;
  67. Global.pat.insuplc_admdvs = Global.pat.card.SearchAdmCode;
  68. Global.pat.name = cc.PatName;
  69. rtn = 0;
  70. }
  71. else
  72. {
  73. //物理读身份证
  74. CardReader reader = new CardReader();
  75. if (reader.ReadSFZ(out msg) != 0)
  76. {
  77. outParam = "读身份证失败!" + msg;
  78. return Error(outParam);
  79. };
  80. Global.pat.certType = "01";
  81. Global.pat.mdtrtcertNO = JsonHelper.getDestValue(JObject.Parse(msg), "IDCardNo") ;
  82. Global.pat.insuplc_admdvs = Global.pat.card.SearchAdmCode;
  83. rtn = 0;
  84. }
  85. if (rtn == 0)
  86. {
  87. trade1101(out outParam);
  88. }
  89. return Parse(outParam);
  90. }
  91. //社保卡
  92. if (cc.cardType == "03")
  93. {
  94. #region 调用读卡接口信息
  95. Global.pat.mdtrtcertType = "03";
  96. int rtn = 0;
  97. //if (!Global.curEvt.enabledDebug)
  98. //{
  99. // CardReader reader = new CardReader(Global.inf.cardURL, Global.inf.areaCode);
  100. // if (reader.Init() != 0)
  101. // {
  102. // outParam = "读社保卡,初始化失败!";
  103. // return Error("读社保卡");
  104. // };
  105. // rtn = reader.ReadCardBas(out outParam);
  106. //}
  107. if (rtn == 0)
  108. {
  109. //清除原数据
  110. trade1101(out outParam);
  111. }
  112. return Parse(outParam);
  113. #endregion
  114. }
  115. //港澳通行证
  116. if (cc.cardType == "04")
  117. {
  118. Global.pat.certType = cc.psnCertType;
  119. Global.pat.mdtrtcertNO = Global.pat.certNO = cc.tbID.Text;
  120. Global.pat.insuplc_admdvs = Global.pat.card.SearchAdmCode;
  121. Global.pat.mdtrtcertType = "99";
  122. trade1101(out outParam);
  123. return Parse(outParam);
  124. }
  125. }
  126. else
  127. {
  128. //outParam = JsonHelper.setExceptionJson().ToString();
  129. return Exception(-1, "读卡", "取消读卡");
  130. }
  131. return Success();
  132. }
  133. catch (Exception ex)
  134. {
  135. return Error("异常:" + ex.Message);
  136. }
  137. }
  138. /// <summary>
  139. /// 通过证件号获取基本信息(无卡)
  140. /// </summary>
  141. /// <param name="cardNo"></param>
  142. /// <param name="outParam"></param>
  143. /// <returns></returns>
  144. public int trade1101(out string outParam)
  145. {
  146. outParam = "";
  147. string errorMsg = "";
  148. JObject joInput = new JObject();
  149. JObject joData = new JObject();
  150. joData.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
  151. joData.Add("mdtrt_cert_no", Utils.ConvertMdtrtcertNo());
  152. joData.Add("card_sn", Global.pat.card.SN);
  153. joData.Add("begntime", Utils.GetShortDateTimeNow());
  154. joData.Add("psn_cert_type", Global.pat.certType);
  155. joData.Add("certno", Global.pat.certNO); //证件号码
  156. joData.Add("psn_name", Global.pat.name);
  157. joInput.Add("data", joData);
  158. InvokeHelper invoker = new InvokeHelper();
  159. JObject joRtn = invoker.invokeCenterService(TradeEnum.PatientInfo, joInput);
  160. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  161. {
  162. outParam = "获取病人信息失败:" + errorMsg;
  163. return -1;
  164. }
  165. else
  166. {
  167. //joRtn["output"]["baseinfo"]["bizCode"] = Global.pat.card.BusinessCode;
  168. outParam = joRtn.ToString();
  169. parsePatient(joRtn);
  170. return 0;
  171. }
  172. }
  173. /// <summary>
  174. /// 读卡并获取基本信息
  175. /// </summary>
  176. /// <param name="outParam"></param>
  177. /// <returns></returns>
  178. public int trade1161(out string outParam)
  179. {
  180. outParam = "";
  181. string errorMsg = "";
  182. JObject joInput = new JObject();
  183. joInput.Add("begntime", Utils.GetShortDateTimeNow());
  184. JObject joRtn = new JObject();
  185. joRtn = invoker.invokeCenterService(TradeEnum.ReadCardInfo, joInput);
  186. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  187. {
  188. outParam = "读卡失败:" + errorMsg;
  189. return -1;
  190. }
  191. else
  192. {
  193. parsePatient(joRtn);
  194. outParam = joRtn.ToString();
  195. }
  196. return 0;
  197. }
  198. /// <summary>
  199. /// 解析人员基本信息
  200. /// </summary>
  201. /// <param name="joRtn"></param>
  202. public void parsePatient(JObject joRtn)
  203. {
  204. // 基线版
  205. PersonCardInfo info = JsonHelper.getOutput<PersonCardInfo>(joRtn);
  206. if (info.cardInfo != null)
  207. {
  208. Global.pat.card.NO = info.cardInfo.cardno;
  209. Global.pat.card.SN = info.cardInfo.card_sn;
  210. Global.pat.card.Cardtoken = info.cardInfo.ecToken;
  211. Global.pat.ecToken = info.cardInfo.ecToken;
  212. }
  213. //Global.writeLog("病人信息:"+joRtn.ToString());
  214. if (info.insuInfo != null && info.insuInfo.Length > 0)
  215. {
  216. //参保地
  217. Global.pat.insuplc_admdvs = info.insuInfo[0].insuplc_admdvs;
  218. Global.pat.insuplc_name = info.insuInfo[0].insuplc_name;
  219. Global.pat.medType = info.insuInfo[0].med_type ?? "C";
  220. }
  221. //证件号
  222. Global.pat.certNO = info.baseInfo?.certno;
  223. // 人员证件类型
  224. Global.pat.certType = info.baseInfo?.psn_cert_type;
  225. // 就诊类型
  226. if (string.IsNullOrEmpty(Global.pat.mdtrtcertType))
  227. {
  228. Global.pat.mdtrtcertType = "03";
  229. }
  230. // 就诊凭证号
  231. if (!string.IsNullOrEmpty(Global.pat.card.NO))
  232. {
  233. Global.pat.mdtrtcertNO = Global.pat.card.NO;
  234. }
  235. // 没有卡号用证件号
  236. if (string.IsNullOrEmpty(Global.pat.mdtrtcertNO))
  237. {
  238. Global.pat.mdtrtcertNO = Global.pat.certNO;
  239. }
  240. Global.pat.payOrdId = info.platformOrderNo;
  241. }
  242. }
  243. }