ReadCardProcess.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. string safeNo = Global.pat.admType == 1 ? "2207A" : "1101";
  26. //string safeNo = "1101";
  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. }
  38. //身份证
  39. if (cc.cardType == "02")
  40. {
  41. Global.pat.mdtrtcertType = "02";
  42. }
  43. //社保卡
  44. if (cc.cardType == "03")
  45. {
  46. Global.pat.mdtrtcertType = "03";
  47. }
  48. #region 调用读卡接口信息
  49. // 全部都采用银海
  50. int rtn = 0;
  51. //if (!Global.curEvt.enabledDebug)
  52. //{
  53. // YinHaiSafeCtrl safeCtrl = new YinHaiSafeCtrl();
  54. // rtn = safeCtrl.Prepare(safeNo, out outParam);
  55. // if (rtn != 0)
  56. // {
  57. // return Exception("调用安全控件", outParam);
  58. // }
  59. //}
  60. //else
  61. //{
  62. // YinHaiSafeCtrl safeCtrl = new YinHaiSafeCtrl();
  63. // rtn = safeCtrl.Prepare(cc.cardType,safeNo, out outParam);
  64. // if (rtn != 0)
  65. // {
  66. // return Exception("调用安全控件", outParam);
  67. // }
  68. //}
  69. YinHaiSafeCtrl safeCtrl = new YinHaiSafeCtrl();
  70. if (Global.pat.admType == 1)
  71. {
  72. if (Global.pat.mdtrtcertType == "03")
  73. {
  74. rtn = safeCtrl.Prepare(Global.pat.mdtrtcertType, "1101", out outParam);
  75. if (rtn != 0)
  76. {
  77. return Exception("调用安全控件", outParam);
  78. }
  79. //重定向
  80. if (hBus.Redirect(Global.inf.originalInterfaceDr, out outParam) != 0)
  81. {
  82. return Exception(-2, "Redirect", outParam);
  83. }
  84. //再次调用门诊2207A,否则后面无法结算
  85. rtn = safeCtrl.Prepare(Global.pat.mdtrtcertType, "2207A", out outParam);
  86. if (rtn != 0)
  87. {
  88. return Exception("调用安全控件", outParam);
  89. }
  90. }
  91. else
  92. //if (Global.pat.mdtrtcertType == "01")
  93. {
  94. rtn = safeCtrl.Prepare(Global.pat.mdtrtcertType, "2207A", out outParam);
  95. if (rtn != 0)
  96. {
  97. return Exception("调用安全控件", outParam);
  98. }
  99. //重定向
  100. if (hBus.Redirect(Global.inf.originalInterfaceDr, out outParam) != 0)
  101. {
  102. return Exception(-2, "Redirect", outParam);
  103. }
  104. }
  105. }
  106. else
  107. {
  108. rtn = safeCtrl.Prepare(Global.pat.mdtrtcertType, "1101", out outParam);
  109. if (hBus.Redirect(Global.inf.originalInterfaceDr, out outParam) != 0)
  110. {
  111. return Exception(-2, "Redirect", outParam);
  112. }
  113. if (Global.pat.mdtrtcertType == "03")
  114. {
  115. //再次调用门诊1101,否则后面无法结算
  116. rtn = safeCtrl.Prepare(Global.pat.mdtrtcertType, "1101", out outParam);
  117. if (rtn != 0)
  118. {
  119. return Exception("调用安全控件", outParam);
  120. }
  121. }
  122. if (rtn != 0)
  123. {
  124. return Exception("调用安全控件", outParam);
  125. }
  126. }
  127. if (rtn == 0)
  128. {
  129. rtn = trade1101(out outParam);
  130. }
  131. if (rtn == 0)
  132. {
  133. return Success();
  134. }
  135. #endregion
  136. }
  137. else
  138. {
  139. return Exception(-1, "读卡", "取消读卡");
  140. }
  141. return Exception(-1, "读卡", outParam);
  142. }
  143. catch (Exception ex)
  144. {
  145. return Error("异常:" + ex.Message);
  146. }
  147. }
  148. /// <summary>
  149. /// 通过证件号获取基本信息(无卡)
  150. /// </summary>
  151. /// <param name="cardNo"></param>
  152. /// <param name="outParam"></param>
  153. /// <returns></returns>
  154. public int trade1101(out string outParam)
  155. {
  156. Utils.GetInsuCode();
  157. outParam = "";
  158. string errorMsg = "";
  159. JObject joInput = new JObject();
  160. JObject joData = new JObject();
  161. joData.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
  162. joData.Add("mdtrt_cert_no", Utils.ConvertMdtrtcertNo());
  163. joData.Add("card_sn", Global.pat.card.SN);
  164. joData.Add("begntime", Utils.GetDateTimeNow());
  165. joData.Add("psn_cert_type", Global.pat.certType);
  166. joData.Add("certno", Global.pat.certNO); //证件号码
  167. joData.Add("psn_name", Global.pat.name);
  168. dynamic joExpContent = new JObject();
  169. joExpContent.card_token = Global.pat.card.Cardtoken;
  170. joData.Add("expContent", joExpContent);
  171. joInput.Add("data", joData);
  172. InvokeHelper invoker = new InvokeHelper();
  173. JObject joRtn = invoker.invokeCenterService(TradeEnum.PatientInfo, joInput);
  174. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  175. {
  176. outParam = "获取病人信息失败:" + errorMsg;
  177. return -1;
  178. }
  179. else
  180. {
  181. //joRtn["output"]["baseinfo"]["bizCode"] = Global.pat.card.BusinessCode;
  182. outParam = joRtn.ToString();
  183. parsePatient(joRtn);
  184. return 0;
  185. }
  186. }
  187. /// <summary>
  188. /// 读卡并获取基本信息
  189. /// </summary>
  190. /// <param name="outParam"></param>
  191. /// <returns></returns>
  192. public int trade1161(out string outParam)
  193. {
  194. outParam = "";
  195. string errorMsg = "";
  196. JObject joInput = new JObject();
  197. joInput.Add("begntime", Utils.GetDateTimeNow());
  198. JObject joRtn = new JObject();
  199. joRtn = invoker.invokeCenterService(TradeEnum.ReadCardInfo, joInput);
  200. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  201. {
  202. outParam = "读卡失败:" + errorMsg;
  203. return -1;
  204. }
  205. else
  206. {
  207. parsePatient(joRtn);
  208. outParam = joRtn.ToString();
  209. }
  210. return 0;
  211. }
  212. /// <summary>
  213. /// 解析人员基本信息
  214. /// </summary>
  215. /// <param name="joRtn"></param>
  216. public void parsePatient(JObject joRtn)
  217. {
  218. // 基线版
  219. PersonCardInfo info = JsonHelper.getOutput<PersonCardInfo>(joRtn);
  220. if (info.cardInfo != null)
  221. {
  222. Global.pat.card.NO = info.cardInfo.cardno;
  223. Global.pat.card.SN = info.cardInfo.card_sn;
  224. Global.pat.card.Cardtoken = info.cardInfo.ecToken;
  225. Global.pat.ecToken = info.cardInfo.ecToken;
  226. }
  227. //Global.writeLog("病人信息:"+joRtn.ToString());
  228. if (info.insuInfo != null && info.insuInfo.Length > 0)
  229. {
  230. //参保地
  231. Global.pat.insuplc_admdvs = info.insuInfo[0].insuplc_admdvs;
  232. Global.pat.insuplc_name = info.insuInfo[0].insuplc_name;
  233. //Global.pat.medType = info.insuInfo[0].med_type ?? "C";
  234. }
  235. //证件号
  236. Global.pat.certNO = info.baseInfo?.certno;
  237. // 人员证件类型
  238. Global.pat.certType = info.baseInfo?.psn_cert_type;
  239. // 就诊类型
  240. if (string.IsNullOrEmpty(Global.pat.mdtrtcertType))
  241. {
  242. Global.pat.mdtrtcertType = "03";
  243. }
  244. // 就诊凭证号
  245. if (!string.IsNullOrEmpty(Global.pat.card.NO))
  246. {
  247. Global.pat.mdtrtcertNO = Global.pat.card.NO;
  248. }
  249. // 没有卡号用证件号
  250. if (string.IsNullOrEmpty(Global.pat.mdtrtcertNO))
  251. {
  252. Global.pat.mdtrtcertNO = Global.pat.certNO;
  253. }
  254. Global.pat.payOrdId = info.platformOrderNo;
  255. }
  256. /// <summary>
  257. /// 通过电子凭证获取基本信息
  258. /// </summary>
  259. /// <param name="outParam"></param>
  260. /// <returns></returns>
  261. public int tradeEcToken(out string outParam)
  262. {
  263. //cardInfo
  264. outParam = "";
  265. int ret = ECTokenReader.ECQuery("1",out outParam);
  266. return ret;
  267. }
  268. }
  269. }