PatientService.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. 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. Global.pat.ecToken = info.cardInfo.ecToken;
  181. //Global.writeLog("病人信息:"+joRtn.ToString());
  182. if (info.insuInfo != null && info.insuInfo.Length > 0)
  183. {
  184. //参保地
  185. Global.pat.insuplc_admdvs = info.insuInfo[0].insuplc_admdvs;
  186. Global.pat.insuplc_name = info.insuInfo[0].insuplc_name;
  187. Global.pat.medType = info.insuInfo[0].psn_type??"A"; //济南替用psn_type
  188. }
  189. //证件号
  190. Global.pat.certNO = info.baseInfo.certno;
  191. // 人员证件类型
  192. Global.pat.certType = info.baseInfo.psn_cert_type;
  193. // 就诊类型
  194. if(string.IsNullOrEmpty(Global.pat.mdtrtcertType))
  195. {
  196. Global.pat.mdtrtcertType = "03";
  197. }
  198. // 就诊凭证号
  199. if (!string.IsNullOrEmpty(Global.pat.card.NO))
  200. {
  201. Global.pat.mdtrtcertNO = Global.pat.card.NO;
  202. }
  203. if (string.IsNullOrEmpty(Global.pat.mdtrtcertNO))
  204. {
  205. Global.pat.mdtrtcertNO = Global.pat.certNO;
  206. }
  207. Global.pat.payOrdId = info.platformOrderNo;
  208. }
  209. /// <summary>
  210. /// 读卡并展示病人信息
  211. /// </summary>
  212. /// <param name="outParam"></param>
  213. /// <returns></returns>
  214. public string readPatientInfo(out string outParam)
  215. {
  216. string patInfo = "";
  217. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  218. if (readCard(out outParam) != 0)
  219. {
  220. return JsonHelper.setExceptionJson(-100, "读卡失败!", outParam).ToString();
  221. }
  222. else
  223. {
  224. patInfo = outParam;
  225. //展示患者信息界面(合并到后面登记界面)
  226. //if (hBus.showPatInfo(patInfo, out outParam) != 0)
  227. //{
  228. // return JsonHelper.setExceptionJson(-100, "操作员取消!", outParam).ToString();
  229. //}
  230. hBus.convertPatientInfo(patInfo, out outParam);
  231. }
  232. #region 展示患者信息
  233. //患者信息赋值给全局变量
  234. string errMsg = "";
  235. if (hBus.setGlobalPatAfaterShowPatInfo(outParam, out errMsg) != 0)
  236. {
  237. return JsonHelper.setExceptionJson(-1, "setGlobalPatAfaterShowPatInfo", errMsg).ToString();
  238. }
  239. //校验HIS姓名与医保姓名是否一致
  240. if (hBus.checkName(Global.pat.name, out errMsg) != 0)
  241. {
  242. return JsonHelper.setExceptionJson(-1, "校验HIS与医保姓名是否一致", errMsg).ToString();
  243. }
  244. #endregion
  245. return "0";
  246. }
  247. }
  248. }