PatientService.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. int rtn = 0;
  75. if (!Global.curEvt.enabledDebug)
  76. {
  77. CardReader reader = new CardReader();
  78. rtn = reader.ReadCardBas(out outParam);
  79. }
  80. if(rtn ==0)
  81. {
  82. trade1101(out outParam);
  83. }
  84. return rtn;
  85. #endregion
  86. }
  87. }
  88. else {
  89. outParam = JsonHelper.setExceptionJson(-1, "读卡", "取消读卡").ToString();
  90. return -1;
  91. }
  92. return 0;
  93. }
  94. catch (Exception ex)
  95. {
  96. outParam = "异常:" + ex.Message;
  97. return -1;
  98. }
  99. }
  100. /// <summary>
  101. /// 通过电子凭证获取基本信息
  102. /// </summary>
  103. /// <param name="outParam"></param>
  104. /// <returns></returns>
  105. public int tradeEcToken(out string outParam)
  106. {
  107. //cardInfo
  108. outParam = ECTokenReader.ECQuery("1");
  109. trade1101(out outParam);
  110. return 0;
  111. }
  112. /// <summary>
  113. /// 通过证件号获取基本信息(无卡)
  114. /// </summary>
  115. /// <param name="cardNo"></param>
  116. /// <param name="outParam"></param>
  117. /// <returns></returns>
  118. public int trade1101(out string outParam)
  119. {
  120. outParam = "";
  121. string errorMsg = "";
  122. JObject joInput = new JObject();
  123. JObject joData = new JObject();
  124. joData.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
  125. joData.Add("mdtrt_cert_no", Utils.ConvertMdtrtcertNo());
  126. joData.Add("card_sn", Global.pat.card.SN);
  127. joData.Add("begntime", Utils.GetDateTimeNow());
  128. joData.Add("psn_cert_type", Global.pat.certType);
  129. joData.Add("certno", Global.pat.certNO); //证件号码
  130. joData.Add("psn_name", Global.pat.name);
  131. joInput.Add("data", joData);
  132. InvokeHelper invoker = new InvokeHelper();
  133. JObject joRtn = invoker.invokeCenterService(TradeEnum.PatientInfo, joInput);
  134. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  135. {
  136. outParam = "获取病人信息失败:" + errorMsg;
  137. return -1;
  138. }
  139. else
  140. {
  141. outParam = joRtn.ToString();
  142. parsePatient(joRtn);
  143. return 0;
  144. }
  145. }
  146. /// <summary>
  147. /// 读卡并获取基本信息
  148. /// </summary>
  149. /// <param name="outParam"></param>
  150. /// <returns></returns>
  151. public int trade1161( out string outParam)
  152. {
  153. outParam = "";
  154. string errorMsg = "";
  155. JObject joInput = new JObject();
  156. joInput.Add("begntime", Utils.GetDateTimeNow());
  157. JObject joRtn = new JObject();
  158. joRtn = invoker.invokeCenterService(TradeEnum.ReadCardInfo, joInput);
  159. if (JsonHelper.parseCenterRtnValue(joRtn, out errorMsg) != 0)
  160. {
  161. outParam = "读卡失败:" + errorMsg;
  162. return -1;
  163. }
  164. else
  165. {
  166. parsePatient(joRtn);
  167. outParam = joRtn.ToString();
  168. }
  169. return 0;
  170. }
  171. /// <summary>
  172. /// 解析人员基本信息
  173. /// </summary>
  174. /// <param name="joRtn"></param>
  175. public void parsePatient(JObject joRtn)
  176. {
  177. // 基线版
  178. PersonCardInfo info = JsonHelper.getOutput<PersonCardInfo>(joRtn);
  179. if (info.cardInfo != null)
  180. {
  181. Global.pat.card.NO = info.cardInfo.cardno;
  182. Global.pat.card.SN = info.cardInfo.card_sn;
  183. Global.pat.card.Cardtoken = info.cardInfo.ecToken;
  184. Global.pat.ecToken = info.cardInfo.ecToken;
  185. }
  186. //Global.writeLog("病人信息:"+joRtn.ToString());
  187. if (info.insuInfo != null && info.insuInfo.Length > 0)
  188. {
  189. //参保地
  190. Global.pat.insuplc_admdvs = info.insuInfo[0].insuplc_admdvs;
  191. Global.pat.insuplc_name = info.insuInfo[0].insuplc_name;
  192. Global.pat.medType = info.insuInfo[0].med_type ?? "C";
  193. }
  194. //证件号
  195. Global.pat.certNO = info.baseInfo?.certno;
  196. // 人员证件类型
  197. Global.pat.certType = info.baseInfo?.psn_cert_type;
  198. // 就诊类型
  199. if(string.IsNullOrEmpty(Global.pat.mdtrtcertType))
  200. {
  201. Global.pat.mdtrtcertType = "03";
  202. }
  203. // 就诊凭证号
  204. if (!string.IsNullOrEmpty(Global.pat.card.NO))
  205. {
  206. Global.pat.mdtrtcertNO = Global.pat.card.NO;
  207. }
  208. if (string.IsNullOrEmpty(Global.pat.mdtrtcertNO))
  209. {
  210. Global.pat.mdtrtcertNO = Global.pat.certNO;
  211. }
  212. Global.pat.payOrdId = info.platformOrderNo;
  213. }
  214. /// <summary>
  215. /// 读卡并展示病人信息
  216. /// </summary>
  217. /// <param name="outParam"></param>
  218. /// <returns></returns>
  219. public string readPatientInfo(out string outParam)
  220. {
  221. string patInfo = "";
  222. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  223. if (readCard(out outParam) != 0)
  224. {
  225. outParam = JsonHelper.setExceptionJson(-100, "读卡失败!", outParam).ToString();
  226. return outParam;
  227. }
  228. else
  229. {
  230. patInfo = outParam;
  231. //展示患者信息界面(合并到后面登记界面)
  232. //if (hBus.showPatInfo(patInfo, out outParam) != 0)
  233. //{
  234. // return JsonHelper.setExceptionJson(-100, "操作员取消!", outParam).ToString();
  235. //}
  236. hBus.convertPatientInfo(patInfo, out outParam);
  237. }
  238. #region 展示患者信息
  239. //患者信息赋值给全局变量
  240. string errMsg = "";
  241. if (hBus.setGlobalPatAfaterShowPatInfo(outParam, out errMsg) != 0)
  242. {
  243. return JsonHelper.setExceptionJson(-1, "setGlobalPatAfaterShowPatInfo", errMsg).ToString();
  244. }
  245. //校验HIS姓名与医保姓名是否一致
  246. if (hBus.checkName(Global.pat.name, out errMsg) != 0)
  247. {
  248. return JsonHelper.setExceptionJson(-1, "校验HIS与医保姓名是否一致", errMsg).ToString();
  249. }
  250. #endregion
  251. return "0";
  252. }
  253. }
  254. }