PatientService.cs 9.9 KB

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