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