PatientService.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Common;
  3. using PTMedicalInsurance.Entity;
  4. using PTMedicalInsurance.Entity.Local;
  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 PatientService
  17. {
  18. protected HisMainBusiness hBus = new HisMainBusiness();
  19. protected InvokeHelper invoker = new InvokeHelper();
  20. /// <summary>
  21. /// 读卡
  22. /// </summary>
  23. /// <returns></returns>
  24. public int readCard(out string outParam)
  25. {
  26. outParam = "";
  27. JObject joCardInfo = new JObject();
  28. ChooseCard cc = new ChooseCard();
  29. JObject joRtn = new JObject();
  30. JObject joInput = new JObject();
  31. try
  32. {
  33. if (cc.ShowDialog() == DialogResult.OK)
  34. {
  35. Global.businessType = "";
  36. Utils.GetInsuCode();
  37. Global.pat.certType = "01";
  38. //电子凭证
  39. if (cc.cardType == "01")
  40. {
  41. Global.pat.mdtrtcertType = "01";
  42. Global.businessType = cc.businessType;
  43. tradeEcToken(out outParam);
  44. //return trade1161(out outParam);
  45. return 0;
  46. }
  47. //身份证
  48. if (cc.cardType == "02")
  49. {
  50. if (cc.ID == "")
  51. {
  52. Global.pat.mdtrtcertType = "02";
  53. Global.pat.name = "";
  54. }
  55. else
  56. {
  57. Global.pat.mdtrtcertType = "02";
  58. //读身份证
  59. CardReader reader = new CardReader();
  60. int rtn = reader.ReadSFZ(out outParam);
  61. if (rtn == 0)
  62. {
  63. trade1101(out outParam);
  64. }
  65. }
  66. return 0;
  67. }
  68. //社保卡
  69. if (cc.cardType == "03")
  70. {
  71. #region 调用读卡接口信息
  72. Global.pat.mdtrtcertType = "03";
  73. //return trade1161(out outParam);
  74. CardReader reader = new CardReader();
  75. int rtn = reader.ReadCardBas(out outParam);
  76. if(rtn ==0)
  77. {
  78. trade1101(out outParam);
  79. }
  80. return rtn;
  81. #endregion
  82. }
  83. }
  84. else {
  85. outParam = JsonHelper.setExceptionJson(-1, "读卡", "取消读卡").ToString();
  86. return -1;
  87. }
  88. return 0;
  89. }
  90. catch (Exception ex)
  91. {
  92. outParam = "异常:" + ex.Message;
  93. return -1;
  94. }
  95. }
  96. /// <summary>
  97. /// 通过电子凭证获取基本信息
  98. /// </summary>
  99. /// <param name="outParam"></param>
  100. /// <returns></returns>
  101. public int tradeEcToken(out string outParam)
  102. {
  103. //cardInfo
  104. outParam = ECTokenReader.ECQuery("1");
  105. trade1101(out outParam);
  106. return 0;
  107. }
  108. /// <summary>
  109. /// 通过证件号获取基本信息(无卡)
  110. /// </summary>
  111. /// <param name="cardNo"></param>
  112. /// <param name="outParam"></param>
  113. /// <returns></returns>
  114. public int trade1101(out string outParam)
  115. {
  116. outParam = "";
  117. string errorMsg = "";
  118. JObject joInput = new JObject();
  119. JObject joData = new JObject();
  120. joData.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
  121. joData.Add("mdtrt_cert_no", Utils.ConvertMdtrtcertNo());
  122. joData.Add("card_sn", Global.pat.card.SN);
  123. joData.Add("begntime", Utils.GetDateTimeNow());
  124. joData.Add("psn_cert_type", Global.pat.certType);
  125. joData.Add("certno", Global.pat.certNO); //证件号码
  126. joData.Add("psn_name", Global.pat.name);
  127. joInput.Add("data", joData);
  128. InvokeHelper invoker = new InvokeHelper();
  129. JObject joRtn = invoker.invokeCenterService(TradeEnum.PatientInfo, joInput);
  130. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  131. {
  132. outParam = "获取病人信息失败:" + errorMsg;
  133. return -1;
  134. }
  135. else
  136. {
  137. outParam = joRtn.ToString();
  138. parsePatient(joRtn);
  139. return 0;
  140. }
  141. }
  142. /// <summary>
  143. /// 读卡并获取基本信息
  144. /// </summary>
  145. /// <param name="outParam"></param>
  146. /// <returns></returns>
  147. public int trade1161( out string outParam)
  148. {
  149. outParam = "";
  150. string errorMsg = "";
  151. JObject joInput = new JObject();
  152. joInput.Add("begntime", Utils.GetDateTimeNow());
  153. JObject joRtn = new JObject();
  154. joRtn = invoker.invokeCenterService(TradeEnum.ReadCardInfo, joInput);
  155. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  156. {
  157. outParam = "读卡失败:" + errorMsg;
  158. return -1;
  159. }
  160. else
  161. {
  162. parsePatient(joRtn);
  163. outParam = joRtn.ToString();
  164. }
  165. return 0;
  166. }
  167. /// <summary>
  168. /// 解析人员基本信息
  169. /// </summary>
  170. /// <param name="joRtn"></param>
  171. public void parsePatient(JObject joRtn)
  172. {
  173. // 基线版
  174. PersonCardInfo info = JsonHelper.getOutput<PersonCardInfo>(joRtn);
  175. Global.pat.card.NO = info.cardInfo?.cardno;
  176. Global.pat.card.SN = info.cardInfo?.card_sn;
  177. Global.pat.card.Cardtoken = info.cardInfo?.ecToken;
  178. Global.pat.ecToken = info.cardInfo?.ecToken;
  179. //Global.writeLog("病人信息:"+joRtn.ToString());
  180. if (info.insuInfo != null && info.insuInfo.Length > 0)
  181. {
  182. //参保地
  183. Global.pat.insuplc_admdvs = info.insuInfo[0].insuplc_admdvs;
  184. Global.pat.insuplc_name = info.insuInfo[0].insuplc_name;
  185. Global.pat.medType = info.insuInfo[0].med_type ?? "C";
  186. }
  187. //证件号
  188. Global.pat.certNO = info.baseInfo?.certno;
  189. // 人员证件类型
  190. Global.pat.certType = info.baseInfo?.psn_cert_type;
  191. // 就诊类型
  192. if(string.IsNullOrEmpty(Global.pat.mdtrtcertType))
  193. {
  194. Global.pat.mdtrtcertType = "03";
  195. }
  196. // 就诊凭证号
  197. if (!string.IsNullOrEmpty(Global.pat.card.NO))
  198. {
  199. Global.pat.mdtrtcertNO = Global.pat.card.NO;
  200. }
  201. if (string.IsNullOrEmpty(Global.pat.mdtrtcertNO))
  202. {
  203. Global.pat.mdtrtcertNO = Global.pat.certNO;
  204. }
  205. Global.pat.payOrdId = info.platformOrderNo;
  206. }
  207. /// <summary>
  208. /// 读卡并展示病人信息
  209. /// </summary>
  210. /// <param name="outParam"></param>
  211. /// <returns></returns>
  212. public string readPatientInfo(out string outParam)
  213. {
  214. string patInfo = "";
  215. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  216. if (readCard(out outParam) != 0)
  217. {
  218. outParam = JsonHelper.setExceptionJson(-100, "读卡失败!", outParam).ToString();
  219. return outParam;
  220. }
  221. else
  222. {
  223. patInfo = outParam;
  224. //展示患者信息界面(合并到后面登记界面)
  225. //if (hBus.showPatInfo(patInfo, out outParam) != 0)
  226. //{
  227. // return JsonHelper.setExceptionJson(-100, "操作员取消!", outParam).ToString();
  228. //}
  229. hBus.convertPatientInfo(patInfo, out outParam);
  230. }
  231. #region 展示患者信息
  232. //患者信息赋值给全局变量
  233. string errMsg = "";
  234. if (hBus.setGlobalPatAfaterShowPatInfo(outParam, out errMsg) != 0)
  235. {
  236. return JsonHelper.setExceptionJson(-1, "setGlobalPatAfaterShowPatInfo", errMsg).ToString();
  237. }
  238. //校验HIS姓名与医保姓名是否一致
  239. if (hBus.checkName(Global.pat.name, out errMsg) != 0)
  240. {
  241. return JsonHelper.setExceptionJson(-1, "校验HIS与医保姓名是否一致", errMsg).ToString();
  242. }
  243. #endregion
  244. return "0";
  245. }
  246. }
  247. }