PatientService.cs 9.0 KB

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