LocalMobilePayProcess.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Common;
  3. using PTMedicalInsurance.Helper;
  4. using PTMedicalInsurance.Variables;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace PTMedicalInsurance.Business
  11. {
  12. class LocalMobilePayProcess : AbstractProcess
  13. {
  14. private Patients MPat;
  15. public Settlements MSettl;
  16. private JObject joParam;
  17. private JObject joInsuAdmObj;
  18. private JObject joResponse;
  19. /// <summary>
  20. /// 支付请求
  21. /// </summary>
  22. /// <param name="input"></param>
  23. /// <returns></returns>
  24. public override CallResult Process(JObject input)
  25. {
  26. //调用HIS费用查询信息
  27. if (hIS.getHisFee(Global.pat, out outParam) != 0)
  28. {
  29. return Exception("获取HIS费用", outParam);
  30. }
  31. //调用医保平台转换
  32. JObject joHisFee = JObject.Parse(outParam);
  33. if (mIS.convertHisFeeWithInsuCode(joHisFee, out outParam) != 0)
  34. {
  35. return Exception("转换HIS费用", outParam);
  36. }
  37. Decimal total = 0;
  38. JArray jaFeeDetail = JArray.Parse(JsonHelper.getDestValue(JObject.Parse(outParam), "data"));
  39. jaFeeDetail.ToList().ForEach((fee) =>
  40. {
  41. fee["chrg_bchno"] = Global.pat.adm_Dr.ToString();
  42. fee["med_type"] = Global.pat.medType;
  43. fee["med_list_spc"] = fee["spec"];
  44. dynamic expContent = new JObject();
  45. JProperty exp = fee.Children<JProperty>().FirstOrDefault(p => p.Name == "expContent");
  46. if (exp != null)
  47. {
  48. exp.Remove();
  49. }
  50. string item_sum = JsonHelper.getDestValue((JObject)fee, "det_item_fee_sumamt");
  51. if (!string.IsNullOrEmpty(item_sum)) {
  52. total += Decimal.Parse(item_sum);
  53. }
  54. expContent.selfpay_prop = fee["SelfPayPercent"];
  55. expContent.drord_no = fee["drord_no"];
  56. fee["exp_content"] = expContent;
  57. });
  58. JObject joSettlement = (JObject)input["settlement"];
  59. joSettlement["medfee_sumamt"] = total;
  60. //合并参数
  61. dynamic joInput = new JObject();
  62. joInput.Add("feedetail", jaFeeDetail);
  63. joInput = mergeJson(joInput, (JObject)input["patInfo"]);
  64. joInput = mergeJson(joInput, (JObject)input["data"]);
  65. joInput = mergeJson(joInput, (JObject)input["mdtrtinfo"]);
  66. joInput = mergeJson(joInput, joSettlement);
  67. joInput.Add("diseinfo_list",input["diseinfo"]);
  68. joInput.Add("feedetail_list", jaFeeDetail);
  69. dynamic joExpContent = new JObject();
  70. joExpContent.op_swssc_flag = "0";
  71. joExpContent.itnt_hosp_flag = "0";
  72. joExpContent.mulaid_flag = "0";
  73. joInput.exp_content = joExpContent;
  74. outParam = JsonHelper.toJsonString(joInput);
  75. return Success();
  76. }
  77. private JObject mergeJson(JObject source,JObject target)
  78. {
  79. source.Merge(target, new JsonMergeSettings
  80. {
  81. MergeArrayHandling = MergeArrayHandling.Union
  82. });
  83. return source;
  84. }
  85. private void init(JObject joInpar)
  86. {
  87. joParam = JObject.Parse(JsonHelper.getDestValue(joInpar, "params[0]"));
  88. joInsuAdmObj = JObject.Parse(JsonHelper.getDestValue(joInpar, "insuAdmObj"));
  89. string response = JsonHelper.getDestValue(joInpar, "responsecontent");
  90. if(!string.IsNullOrEmpty(response))
  91. {
  92. joResponse = JObject.Parse(response);
  93. }
  94. setPatientByInPar();
  95. setSettlementsByInPar();
  96. }
  97. public void setSettlementsByInPar()
  98. {
  99. MSettl.clearingWay = JsonHelper.getDestValue(joInsuAdmObj, "psnSetlway");
  100. MSettl.settlID = JsonHelper.getDestValue(joInsuAdmObj, "payOrdId");
  101. MSettl.payOrdId = JsonHelper.getDestValue(joInsuAdmObj, "payOrdId");
  102. }
  103. public void setPatientByInPar()
  104. {
  105. MPat.adm_Dr = int.Parse(JsonHelper.getDestValue(joParam, "admID"));
  106. Global.pat.adm_Dr = MPat.adm_Dr;
  107. MPat.name = JsonHelper.getDestValue(joInsuAdmObj, "patName");
  108. MPat.recordID = JsonHelper.getDestValue(joParam, "recordID");
  109. MPat.billID = JsonHelper.getDestValue(joParam, "billID");
  110. MPat.medType = JsonHelper.getDestValue(joInsuAdmObj, "medType");
  111. MPat.certType = JsonHelper.getDestValue(joInsuAdmObj, "mdtrtCertType");
  112. MPat.token = JsonHelper.getDestValue(joInsuAdmObj, "ecToken");
  113. MPat.payAuthNo = JsonHelper.getDestValue(joInsuAdmObj, "payAuthNo");
  114. MPat.uldLatlnt = JsonHelper.getDestValue(joInsuAdmObj, "uldLatlnt");
  115. MPat.payOrdId = JsonHelper.getDestValue(joInsuAdmObj, "payOrdId");
  116. MPat.mdtrtID = JsonHelper.getDestValue(joInsuAdmObj, "mdtrt_id");
  117. if (string.IsNullOrEmpty(MPat.mdtrtID) && joResponse != null)
  118. {
  119. MPat.mdtrtID = JsonHelper.getDestValue(joResponse, "SETLINFO.mdtrt_id");
  120. }
  121. MPat.settlID = JsonHelper.getDestValue(joInsuAdmObj, "setl_id");
  122. if (string.IsNullOrEmpty(MPat.settlID) && joResponse != null)
  123. {
  124. MPat.settlID = JsonHelper.getDestValue(joResponse, "SETLINFO.setl_id");
  125. MPat.psn_no = JsonHelper.getDestValue(joResponse, "SETLINFO.psn_no");
  126. MPat.payOrdId = MPat.settlID;
  127. MPat.insuplc_admdvs = JsonHelper.getDestValue(joResponse, "insuplcAdmdvs");
  128. }
  129. Global.pat.mdtrtID = MPat.mdtrtID;
  130. }
  131. /// <summary>
  132. /// 交易确认
  133. /// </summary>
  134. /// <param name="input"></param>
  135. public CallResult Confirm(JObject input)
  136. {
  137. outParam = "";
  138. string errMsg = "";
  139. init(input);
  140. // save
  141. //设置
  142. JObject joSettle = joResponse["SETLINFO"].ToObject<JObject>();
  143. setSettlementsBy6202Rtn(joSettle);
  144. MSettl.confirmFlag = 0;
  145. //存入MI 结算表
  146. if (saveSettlement(out errMsg) != 0)
  147. {
  148. outParam = errMsg;
  149. return Exception(-1, "保存结算信息失败",errMsg);
  150. }
  151. // 返回给HIS
  152. if (returnToHis(joSettle, out errMsg) != 0)
  153. {
  154. outParam = errMsg;
  155. return Exception(-1,"返回结算信息给HIS失败",errMsg);
  156. }
  157. MobilePayConfirmSettlement(joSettle,out outParam);
  158. return IrisReturn("结算成功",null);
  159. }
  160. public CallResult Cancel(JObject input)
  161. {
  162. init(input);
  163. int ret = MobilePayCancelSettlement(out outParam);
  164. if(ret !=0)
  165. {
  166. return IrisReturn(-1,"退费失败", JObject.Parse(outParam));
  167. }
  168. return IrisReturn("退费成功", null);
  169. }
  170. public int MobilePayCancelSettlement(out string outPar)
  171. {
  172. string errMsg;
  173. outPar = "";
  174. try
  175. {
  176. if (MSettl.onlineYBFalg != "Y")
  177. {
  178. Global.businessType = "01301"; //结算
  179. //读电子凭证
  180. if (ReadEc(out errMsg) != 0)
  181. {
  182. outPar = errMsg;
  183. return -1;
  184. }
  185. }
  186. //获取6203入参
  187. if (Get6203Inpar(out errMsg) != 0)
  188. {
  189. outPar = errMsg;
  190. return -1;
  191. }
  192. JObject joInput = JObject.Parse(errMsg);
  193. // 调用his服务(移动支付院内退款服务)
  194. JObject jo6203Rtn = invoker.invokeHISService(JsonHelper.setIrisInpar("05110036", joInput).ToString(), "移动支付退费");
  195. if (JsonHelper.parseIrisRtnValue(jo6203Rtn, out errMsg) != 0)
  196. {
  197. outPar = errMsg;
  198. return -1;
  199. }
  200. else
  201. {
  202. //处理撤销数据
  203. if (cancleSettlement(Global.pat.settlID, out errMsg) != 0)
  204. {
  205. outPar = errMsg;
  206. return -1;
  207. }
  208. joParam.Add("middleSettleFlag", "");
  209. //退HIS结算
  210. if (hIS.cancleSettlementInfo(joParam, out errMsg) != 0)
  211. {
  212. outPar = errMsg;
  213. return -1;
  214. }
  215. else
  216. {
  217. outPar = JsonHelper.setIrisReturnValue(0, errMsg, null).ToString();
  218. return 0;
  219. }
  220. }
  221. }
  222. catch (Exception ex)
  223. {
  224. Global.writeLog("MobilePayCancelSettlement:" + ex.Message);
  225. outPar = ex.Message;
  226. return -1;
  227. }
  228. }
  229. /// <summary>
  230. /// 取消结算
  231. /// </summary>
  232. /// <param name="outParam"></param>
  233. /// <returns></returns>
  234. public int cancleSettlement(string newSettlID, out string outParam)
  235. {
  236. JObject joTmp = new JObject();
  237. string errMsg = "";
  238. try
  239. {
  240. joTmp.Add("HospitalDr", Global.inf.hospitalDr);
  241. joTmp.Add("InterfaceDr", Global.inf.interfaceDr);
  242. joTmp.Add("admID", MPat.adm_Dr);
  243. joTmp.Add("mdtrt_id", MPat.mdtrtID);
  244. joTmp.Add("setl_id", MPat.settlID);
  245. joTmp.Add("new_setl_id", newSettlID);
  246. joTmp.Add("updateUserID", Global.user.ID);
  247. joTmp.Add("msgid", Global.curEvt.msgid);
  248. joTmp.Add("OccurTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  249. JObject joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010052", joTmp).ToString(), "取消结算信息");
  250. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  251. {
  252. outParam = errMsg;
  253. return -1;
  254. }
  255. else
  256. {
  257. outParam = JsonHelper.setExceptionJson(0, "云医保平台", "取消结算成功").ToString();
  258. return 0;
  259. }
  260. }
  261. catch (Exception ex)
  262. {
  263. outParam = "取消结算信息:" + ex.Message;
  264. return -1;
  265. }
  266. }
  267. #region 读卡
  268. public int ReadEc(out string outPar)
  269. {
  270. outPar = "";
  271. try
  272. {
  273. PatientService patientService = new PatientService();
  274. int ret = patientService.trade1161(out outPar);
  275. if (ret != 0)
  276. {
  277. return -1;
  278. }
  279. return 0;
  280. }
  281. catch (Exception ex)
  282. {
  283. outPar = ex.Message;
  284. return -1;
  285. }
  286. }
  287. public void setPatientByEc(JObject jo)
  288. {
  289. MPat.name = JsonHelper.getDestValue(jo, "userName");
  290. MPat.IDNO = JsonHelper.getDestValue(jo, "idNo");
  291. MPat.certType = JsonHelper.getDestValue(jo, "idType");
  292. MPat.token = JsonHelper.getDestValue(jo, "ecToken");
  293. MPat.insuplc_admdvs = JsonHelper.getDestValue(jo, "insuOrg");
  294. MPat.payAuthNo = JsonHelper.getDestValue(jo, "authNo");
  295. MPat.gend = JsonHelper.getDestValue(jo, "gender");
  296. MPat.brdy = JsonHelper.getDestValue(jo, "birthday");
  297. MPat.naty = JsonHelper.getDestValue(jo, "nationality");
  298. }
  299. #endregion
  300. private int returnToHis(JObject joPreSettl,out string errMsg)
  301. {
  302. //返回给HIS后端
  303. //JObject joTmp = JObject.Parse(JsonHelper.getDestValue(joM6201Rtn, "encData"));
  304. JObject joTmp = new JObject();
  305. joTmp.Add("insutype", MPat.insuType);
  306. joTmp.Add("psn_no", MPat.psn_no);
  307. joTmp.Add("insuplc_admdvs", MPat.insuplc_admdvs);
  308. joTmp.Add("mdtrtId", MPat.mdtrtID);
  309. joTmp.Add("mdtrt_id", MPat.mdtrtID);
  310. joTmp.Add("mdtrt_cert_type", JsonHelper.getDestValue(joPreSettl, "mdtrt_cert_type"));
  311. joTmp.Add("mdtrt_cert_no", JsonHelper.getDestValue(joPreSettl, "certno"));
  312. joTmp.Add("med_type", JsonHelper.getDestValue(joPreSettl, "med_type"));
  313. if (returnMPSettlementInfo(joTmp, joPreSettl, out errMsg) != 0)
  314. {
  315. return -1;
  316. }
  317. return 0;
  318. }
  319. private int MobilePayConfirmSettlement(JObject joSettlInfo,out string outPar)
  320. {
  321. string errMsg;
  322. outPar = "";
  323. try
  324. {
  325. //设置
  326. setSettlementsBy6301Rtn(joSettlInfo);
  327. MSettl.confirmFlag = 1;
  328. //存入MI 结算表
  329. if (updateSettlement(out errMsg) != 0)
  330. {
  331. outPar = errMsg;
  332. return -1;
  333. }
  334. else
  335. {
  336. //返回给HIS前端
  337. outPar = JsonHelper.setExceptionJson(0, "云医保平台", "确认成功!").ToString();
  338. return 0;
  339. }
  340. }
  341. catch (Exception ex)
  342. {
  343. outPar = ex.Message;
  344. return -1;
  345. }
  346. }
  347. public void setSettlementsBy6202Rtn(JObject jo)
  348. {
  349. MSettl.settlID = JsonHelper.getDestValue(jo, "setl_id");
  350. MPat.payOrdId = MSettl.settlID;
  351. MSettl.payOrdId = MSettl.settlID;
  352. MSettl.ordStas = JsonHelper.getDestValue(jo, "ordStas");
  353. MSettl.sumamt = getDecimalFee(jo, "medfee_sumamt");
  354. MSettl.personCashPay = getDecimalFee(jo, "ownPayAmt");
  355. MSettl.accountPaySumamt = getDecimalFee(jo, "acct_pay");
  356. MSettl.fundPaySumamt = getDecimalFee(jo, "fund_pay_sumamt");
  357. MSettl.deposit = getDecimalFee(jo, "deposit");
  358. MSettl.clearingOrgan = JsonHelper.getDestValue(jo, "clr_optins");
  359. MSettl.clearingType = JsonHelper.getDestValue(jo, "clr_type");
  360. MSettl.clearingWay = JsonHelper.getDestValue(jo, "clr_way");
  361. MSettl.civilserviceAllowancePay = getDecimalFee(jo, "cvlserv_pay");
  362. MSettl.ownPayAmount = getDecimalFee(jo, "fulamt_ownpay_amt");
  363. MSettl.overLimitAmountmt = getDecimalFee(jo, "overlmt_selfpay");
  364. MSettl.preSelfPayAmount = getDecimalFee(jo, "preselfpay_amt");
  365. MSettl.inPolicyRangeAmount = getDecimalFee(jo, "inscp_scp_amt");
  366. MSettl.actualPayDeductible = getDecimalFee(jo, "act_pay_dedc");
  367. MSettl.healthInsurancePay = getDecimalFee(jo, "hifp_pay");
  368. MSettl.healthInsuranceRatio = getDecimalFee(jo, "pool_prop_selfpay");
  369. MSettl.enterpriseSupplementPay = getDecimalFee(jo, "hifes_pay");
  370. MSettl.seriousIllnessPay = getDecimalFee(jo, "hifmi_pay");
  371. MSettl.largeExpensesSupplementPay = getDecimalFee(jo, "hifob_pay");
  372. MSettl.medicalAssistPay = getDecimalFee(jo, "maf_pay");
  373. MSettl.hospitalPartAmount = getDecimalFee(jo, "hosp_part_amt");
  374. MSettl.otherPay = getDecimalFee(jo, "oth_pay");
  375. MSettl.personPaySumamt = getDecimalFee(jo, "psn_part_amt");
  376. MSettl.balance = getDecimalFee(jo, "balc");
  377. MSettl.accountMutualAidAmount = getDecimalFee(jo, "acct_mulaid_pay");
  378. }
  379. /// <summary>
  380. /// 插入结算信息
  381. /// </summary>
  382. /// <param name="joSettlement"></param>
  383. /// <param name="outParam"></param>
  384. /// <returns></returns>
  385. public int saveSettlement(out string outParam)
  386. {
  387. JObject joTmp = new JObject();
  388. string errMsg = "";
  389. try
  390. {
  391. JObject joSetlinfo = new JObject();
  392. joSetlinfo.Add("HospitalDr", Global.inf.hospitalDr);
  393. joSetlinfo.Add("admID", MPat.adm_Dr);
  394. joSetlinfo.Add("mdtrt_id", MPat.mdtrtID);
  395. joSetlinfo.Add("setl_id", MSettl.settlID);//
  396. joSetlinfo.Add("pay_ord_id", MSettl.payOrdId);
  397. joSetlinfo.Add("psn_no", MPat.psn_no);
  398. joSetlinfo.Add("psn_name", MPat.name);
  399. //joSetlinfo.Add("mdtrt_cert_type", JsonHelper.getDestValue(joRtnSetlinfo, "mdtrt_cert_type"));
  400. joSetlinfo.Add("certno", MPat.certNO);
  401. joSetlinfo.Add("gend", MPat.gend);
  402. joSetlinfo.Add("naty", MPat.naty);
  403. joSetlinfo.Add("brdy", MPat.brdy);
  404. joSetlinfo.Add("age", MPat.age);
  405. joSetlinfo.Add("insutype", MPat.insuType);
  406. joSetlinfo.Add("psn_type", MPat.psn_type);
  407. joSetlinfo.Add("cvlserv_flag", "");
  408. joSetlinfo.Add("setl_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  409. joSetlinfo.Add("mdtrt_cert_type", MPat.mdtrtcertType);
  410. joSetlinfo.Add("med_type", MPat.medType);
  411. joSetlinfo.Add("medfee_sumamt", MSettl.sumamt);//总费用
  412. joSetlinfo.Add("fulamt_ownpay_amt", MSettl.ownPayAmount);//全自费金额
  413. joSetlinfo.Add("overlmt_selfpay", MSettl.overLimitAmountmt);//超限价自费费用
  414. joSetlinfo.Add("preselfpay_amt", MSettl.preSelfPayAmount);//先行自付金额
  415. joSetlinfo.Add("inscp_scp_amt", MSettl.inPolicyRangeAmount);//符合政策范围金额
  416. joSetlinfo.Add("act_pay_dedc", MSettl.actualPayDeductible);//实际支付起付线
  417. joSetlinfo.Add("hifp_pay", MSettl.healthInsurancePay);//基本医疗保险统筹基金支出
  418. joSetlinfo.Add("pool_prop_selfpay", MSettl.healthInsuranceRatio);//基本医疗保险统筹基金支付比例
  419. joSetlinfo.Add("cvlserv_pay", MSettl.civilserviceAllowancePay);//公务员医疗补助资金支出
  420. joSetlinfo.Add("hifes_pay", MSettl.enterpriseSupplementPay);//企业支付 占用 大病报销金额
  421. joSetlinfo.Add("hifmi_pay", MSettl.seriousIllnessPay);// 居民大病保险资金支出
  422. joSetlinfo.Add("hifob_pay", MSettl.largeExpensesSupplementPay);//职工大额医疗费用补助基金支出
  423. joSetlinfo.Add("maf_pay", MSettl.medicalAssistPay);//医疗救助基金支出
  424. joSetlinfo.Add("hosp_part_amt", MSettl.hospitalPartAmount);//医院负担金额
  425. joSetlinfo.Add("oth_pay", MSettl.otherPay);//其他支出
  426. joSetlinfo.Add("fund_pay_sumamt", MSettl.fundPaySumamt);//基金支付总额
  427. joSetlinfo.Add("psn_part_amt", MSettl.personPaySumamt);//个人负担总金额
  428. joSetlinfo.Add("acct_pay", MSettl.accountPaySumamt);//个人账户支出
  429. joSetlinfo.Add("psn_cash_pay", MSettl.personCashPay);//个人现金支出
  430. joSetlinfo.Add("balc", MSettl.balance);// 余额
  431. joSetlinfo.Add("acct_mulaid_pay", "");//个人账户共济支付金额
  432. joSetlinfo.Add("medins_setl_id", "");//医药机构结算ID
  433. joSetlinfo.Add("clr_optins", MSettl.clearingOrgan);//清算经办机构
  434. joSetlinfo.Add("clr_way", MSettl.clearingWay);//清算方式
  435. joSetlinfo.Add("clr_type", MSettl.clearingType);//清算类别
  436. joSetlinfo.Add("ValidFlag", 1);
  437. joSetlinfo.Add("BillType", 1);
  438. joSetlinfo.Add("msgid", Global.curEvt.msgid);
  439. joSetlinfo.Add("admType", "3");
  440. joSetlinfo.Add("billID", MPat.billID);
  441. joSetlinfo.Add("recordID", MPat.recordID);
  442. joSetlinfo.Add("interfaceDr", Global.inf.interfaceDr);
  443. joSetlinfo.Add("insuplc_admdvs", MPat.insuplc_admdvs);
  444. joSetlinfo.Add("OccurTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  445. joSetlinfo.Add("HospitalizationsDays", MSettl.hospitalizationsDays);
  446. joSetlinfo.Add("HospitalizationsTimes", MSettl.hospitalizationsTimes);
  447. joSetlinfo.Add("HISAdmTime", MSettl.hisAdmTime);
  448. joSetlinfo.Add("HISDischargeTime", MSettl.hisDischargeTime);
  449. joSetlinfo.Add("updateUserID", Global.user.ID);
  450. joSetlinfo.Add("ConfirmFlag", MSettl.confirmFlag);
  451. JObject joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010051", joSetlinfo).ToString(), "插入结算信息");
  452. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  453. {
  454. outParam = errMsg;
  455. return -1;
  456. }
  457. else
  458. {
  459. outParam = joSetlinfo.ToString();
  460. return 0;
  461. }
  462. }
  463. catch (Exception ex)
  464. {
  465. outParam = "插入结算信息:" + ex.Message;
  466. return -1;
  467. }
  468. }
  469. public void setSettlementsBy6301Rtn(JObject jo)
  470. {
  471. MSettl.settlID = MPat.payOrdId;
  472. MPat.psn_no = JsonHelper.getDestValue(jo, "psn_no");
  473. MPat.naty = JsonHelper.getDestValue(jo, "naty");
  474. //MPat.name = JsonHelper.getDestValue(jo, "name");
  475. MPat.age = JsonHelper.getDestValue(jo, "age");
  476. MPat.gend = JsonHelper.getDestValue(jo, "gend");
  477. MPat.certNO = JsonHelper.getDestValue(jo, "certno");
  478. MPat.brdy = JsonHelper.getDestValue(jo, "brdy");
  479. MPat.insuType = JsonHelper.getDestValue(jo, "insutype");
  480. MPat.psn_type = JsonHelper.getDestValue(jo, "psn_type");
  481. MPat.mdtrtcertType = JsonHelper.getDestValue(jo, "mdtrt_cert_type");
  482. MPat.medType = JsonHelper.getDestValue(jo, "med_type");
  483. //MPat.insuplc_admdvs = JsonHelper.getDestValue(jo, "insuplc_admdvs");
  484. //MPat.payOrdId = JsonHelper.getDestValue(jo, "payOrdId");
  485. MSettl.ordStas = JsonHelper.getDestValue(jo, "ordStas");
  486. MSettl.sumamt = getDecimalFee(jo, "medfee_sumamt");
  487. MSettl.personCashPay = getDecimalFee(jo, "psn_cash_pay");
  488. MSettl.accountPaySumamt = getDecimalFee(jo, "acct_pay");
  489. MSettl.fundPaySumamt = getDecimalFee(jo, "fund_pay_sumamt");
  490. //MSettl.deposit = getDecimalFee(jo, "deposit");
  491. MSettl.clearingOrgan = JsonHelper.getDestValue(jo, "clr_optins");
  492. MSettl.clearingType = JsonHelper.getDestValue(jo, "clr_type");
  493. MSettl.clearingWay = JsonHelper.getDestValue(jo, "clr_way");
  494. MSettl.civilserviceAllowancePay = getDecimalFee(jo, "cvlserv_pay");
  495. MSettl.ownPayAmount = getDecimalFee(jo, "fulamt_ownpay_amt");
  496. MSettl.overLimitAmountmt = getDecimalFee(jo, "overlmt_selfpay");
  497. MSettl.preSelfPayAmount = getDecimalFee(jo, "preselfpay_amt");
  498. MSettl.inPolicyRangeAmount = getDecimalFee(jo, "inscp_scp_amt");
  499. MSettl.actualPayDeductible = getDecimalFee(jo, "act_pay_dedc");
  500. MSettl.healthInsurancePay = getDecimalFee(jo, "hifp_pay");
  501. MSettl.healthInsuranceRatio = getDecimalFee(jo, "pool_prop_selfpay");
  502. MSettl.enterpriseSupplementPay = getDecimalFee(jo, "hifes_pay");
  503. MSettl.seriousIllnessPay = getDecimalFee(jo, "hifmi_pay");
  504. MSettl.largeExpensesSupplementPay = getDecimalFee(jo, "hifob_pay");
  505. MSettl.medicalAssistPay = getDecimalFee(jo, "maf_pay");
  506. MSettl.hospitalPartAmount = getDecimalFee(jo, "hosp_part_amt");
  507. MSettl.otherPay = getDecimalFee(jo, "oth_pay");
  508. MSettl.personPaySumamt = getDecimalFee(jo, "psn_part_amt");
  509. MSettl.balance = getDecimalFee(jo, "balc");
  510. MSettl.accountMutualAidAmount = getDecimalFee(jo, "acct_mulaid_pay");
  511. }
  512. /// <summary>
  513. /// 获取结算费用的封装
  514. /// </summary>
  515. /// <param name="jo"></param>
  516. /// <param name="path"></param>
  517. /// <returns></returns>
  518. private decimal getDecimalFee(JObject jo, string path)
  519. {
  520. try
  521. {
  522. string temp = JsonHelper.getDestValue(jo, path);
  523. if (temp == "")
  524. {
  525. return 0;
  526. }
  527. else
  528. {
  529. return decimal.Parse(temp);
  530. }
  531. }
  532. catch (Exception ex)
  533. {
  534. Global.writeLog("getFee异常:" + ex.Message);
  535. return 0;
  536. }
  537. }
  538. public int updateSettlement(out string outParam)
  539. {
  540. JObject joTmp = new JObject();
  541. string errMsg = "";
  542. try
  543. {
  544. JObject joSetlinfo = new JObject();
  545. joSetlinfo.Add("HospitalDr", Global.inf.hospitalDr);
  546. joSetlinfo.Add("AdmDr", MPat.adm_Dr);
  547. joSetlinfo.Add("MdtrtID", MPat.mdtrtID);
  548. joSetlinfo.Add("SettlementID", MSettl.settlID);//
  549. joSetlinfo.Add("PayOrdID", MSettl.payOrdId);
  550. joSetlinfo.Add("PersonnelNO", MPat.psn_no);
  551. joSetlinfo.Add("PatientName", MPat.name);
  552. //joSetlinfo.Add("CertificateType", JsonHelper.getDestValue(joRtnSetlinfo, "mdtrt_cert_type"));
  553. joSetlinfo.Add("CertificateNO", MPat.certNO);
  554. joSetlinfo.Add("Gender", MPat.gend);
  555. joSetlinfo.Add("Nation", MPat.naty);
  556. joSetlinfo.Add("BirthDay", MPat.brdy);
  557. joSetlinfo.Add("Age", MPat.age);
  558. joSetlinfo.Add("InsuranceType", MPat.insuType);
  559. joSetlinfo.Add("PersonType", MPat.psn_type);
  560. joSetlinfo.Add("CivilserviceFlag", "");
  561. joSetlinfo.Add("SettlementDateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  562. joSetlinfo.Add("MdtrtCertType", MPat.mdtrtcertType);
  563. joSetlinfo.Add("MedicalType", MPat.medType);
  564. joSetlinfo.Add("Sumamt", MSettl.sumamt);//总费用
  565. joSetlinfo.Add("OwnPayAmount", MSettl.ownPayAmount);//全自费金额
  566. joSetlinfo.Add("OverLimitAmount", MSettl.overLimitAmountmt);//超限价自费费用
  567. joSetlinfo.Add("PreSelfPayAmount", MSettl.preSelfPayAmount);//先行自付金额
  568. joSetlinfo.Add("InPolicyRangeAmount", MSettl.inPolicyRangeAmount);//符合政策范围金额
  569. joSetlinfo.Add("ActualPayDeductible", MSettl.actualPayDeductible);//实际支付起付线
  570. joSetlinfo.Add("HealthInsurancePay", MSettl.healthInsurancePay);//基本医疗保险统筹基金支出
  571. joSetlinfo.Add("HealthInsuranceRatio", MSettl.healthInsuranceRatio);//基本医疗保险统筹基金支付比例
  572. joSetlinfo.Add("CivilserviceAllowancePay", MSettl.civilserviceAllowancePay);//公务员医疗补助资金支出
  573. joSetlinfo.Add("EnterpriseSupplementPay", MSettl.enterpriseSupplementPay);//企业支付
  574. joSetlinfo.Add("SeriousIllnessPay", MSettl.seriousIllnessPay);// 居民大病保险资金支出
  575. joSetlinfo.Add("LargeExpensesSupplementPay", MSettl.largeExpensesSupplementPay);//职工大额医疗费用补助基金支出
  576. joSetlinfo.Add("MedicalAssistPay", MSettl.medicalAssistPay);//医疗救助基金支出
  577. joSetlinfo.Add("HospitalPartAmount", MSettl.hospitalPartAmount);//医院负担金额
  578. joSetlinfo.Add("OtherPay", MSettl.otherPay);//其他支出
  579. joSetlinfo.Add("FundPaySumamt", MSettl.fundPaySumamt);//基金支付总额
  580. joSetlinfo.Add("PersonPaySumamt", MSettl.personPaySumamt);//个人负担总金额
  581. joSetlinfo.Add("AccountPaySumamt", MSettl.accountPaySumamt);//个人账户支出
  582. joSetlinfo.Add("PersonCashPay", MSettl.personCashPay);//个人现金支出
  583. joSetlinfo.Add("Balance", MSettl.balance);// 余额
  584. joSetlinfo.Add("AccountMutualAidAmount", "");//个人账户共济支付金额
  585. joSetlinfo.Add("OrganSettlementID", "");//医药机构结算ID
  586. joSetlinfo.Add("ClearingOrgan", MSettl.clearingOrgan);//清算经办机构
  587. joSetlinfo.Add("ClearingWay", MSettl.clearingWay);//清算方式
  588. joSetlinfo.Add("ClearingType", MSettl.clearingType);//清算类别
  589. joSetlinfo.Add("ValidFlag", 1);
  590. joSetlinfo.Add("BillType", 1);
  591. joSetlinfo.Add("ConfirmFlag", MSettl.confirmFlag);
  592. joSetlinfo.Add("MSGID", Global.curEvt.msgid);
  593. joSetlinfo.Add("AdmType", "3");
  594. joSetlinfo.Add("BillID", MPat.billID);
  595. joSetlinfo.Add("RecordID", MPat.recordID);
  596. joSetlinfo.Add("InterfaceDr", Global.inf.interfaceDr);
  597. joSetlinfo.Add("InsuranceAreaCode", MPat.insuplc_admdvs);
  598. joSetlinfo.Add("OccurTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  599. joSetlinfo.Add("HospitalizationsDays", MSettl.hospitalizationsDays);
  600. joSetlinfo.Add("HospitalizationsTimes", MSettl.hospitalizationsTimes);
  601. joSetlinfo.Add("HISAdmTime", MSettl.hisAdmTime);
  602. joSetlinfo.Add("HISDischargeTime", MSettl.hisDischargeTime);
  603. joSetlinfo.Add("updateUserID", Global.user.ID);
  604. JObject joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010089", joSetlinfo).ToString(), "通过订单号更新结算信息");
  605. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  606. {
  607. outParam = errMsg;
  608. return -1;
  609. }
  610. else
  611. {
  612. outParam = joSetlinfo.ToString();
  613. return 0;
  614. }
  615. }
  616. catch (Exception ex)
  617. {
  618. outParam = "插入结算信息:" + ex.Message;
  619. return -1;
  620. }
  621. }
  622. public void setPatientByMiRegInfo(JObject jo)
  623. {
  624. MPat.name = JsonHelper.getDestValue(jo, "data.PatientName");
  625. MPat.psn_no = JsonHelper.getDestValue(jo, "data.PersonalNO");
  626. MPat.certNO = JsonHelper.getDestValue(jo, "data.CertificateNO");
  627. MPat.IDNO = MPat.certNO;
  628. MPat.certType = JsonHelper.getDestValue(jo, "data.CertificateType");
  629. MPat.payToken = JsonHelper.getDestValue(jo, "data.payToken");
  630. MPat.insuplc_admdvs = JsonHelper.getDestValue(jo, "data.InsuranceAreaCode");
  631. }
  632. //组织M6203入参
  633. public int Get6203Inpar(out string outparam)
  634. {
  635. string errMsg = "";
  636. outparam = "";
  637. try
  638. {
  639. JObject joInpar = new JObject();
  640. //获取医保平台结算信息
  641. if (QuerySettleInfo(out errMsg) != 0)
  642. {
  643. outparam = errMsg;
  644. return -1;
  645. }
  646. JObject joRtn = JObject.Parse(errMsg);
  647. string settlInfo = JsonHelper.getDestValue(joRtn, "result.data[0]");
  648. if (string.IsNullOrEmpty(settlInfo))
  649. {
  650. outparam = "没有查询到结算信息,请检查参数";
  651. return -1;
  652. }
  653. // 组织调用参数
  654. Global.curEvt.msgid = Global.inf.hospitalNO + DateTime.Now.ToString("yyyyMMddHHmmssffff");
  655. JObject joSettl = JObject.Parse(settlInfo);
  656. MPat.settlID = JsonHelper.getDestValue(joSettl, "SettlementID");
  657. //入参
  658. joInpar.Add("outtradeno", JsonHelper.getDestValue(joSettl, "PayOrdID"));//支付订单号
  659. joInpar.Add("appRefdSn", Global.curEvt.msgid);//应用退款流水号
  660. string appRefdTime = JsonHelper.getDestValue(joInsuAdmObj, "appRefdTime");
  661. if (string.IsNullOrEmpty(appRefdTime))
  662. {
  663. appRefdTime = Utils.GetDateTimeNow();
  664. }
  665. joInpar.Add("businessType", "DWREFUND");//应用退费时间
  666. joInpar.Add("hospitalCode", Global.inf.hospitalNO);
  667. joInpar.Add("ec_code", Global.pat.ecToken);
  668. joInpar.Add("patName", Global.pat.name);
  669. joInpar.Add("idType", "01");
  670. joInpar.Add("idCardNo", Global.pat.IDNO);
  671. outparam = joInpar.ToString();
  672. return 0;
  673. }
  674. catch (Exception ex)
  675. {
  676. outparam = "Get6203Inpar:" + ex.Message;
  677. return -1;
  678. }
  679. finally
  680. {
  681. Global.writeLog("Get6203Inpar", "", outparam);
  682. }
  683. }
  684. //查询结算信息
  685. public int QuerySettleInfo(out string errMsg)
  686. {
  687. errMsg = "";
  688. try
  689. {
  690. string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE Hospital_Dr= " + Global.inf.hospitalDr;
  691. sqlStr = sqlStr + " and AdmType = 3 and Adm_Dr= " + MPat.adm_Dr + " and PayOrdID= '" + MPat.payOrdId + "'";
  692. JObject joSqlstr = new JObject();
  693. joSqlstr.Add("sqlStr", sqlStr);
  694. JObject joRtn = mIS.DynamicQuerySettlInfo(joSqlstr);
  695. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  696. {
  697. return -1;
  698. }
  699. else
  700. {
  701. errMsg = joRtn.ToString();
  702. return 0;
  703. }
  704. }
  705. catch (Exception ex)
  706. {
  707. errMsg = ex.Message;
  708. return -1;
  709. }
  710. }
  711. //获取入参,入参基本为类局部变量
  712. public int Get6301Inpar(out string outparam)
  713. {
  714. outparam = "";
  715. try
  716. {
  717. string errMsg;
  718. //查询登记信息
  719. if (mIS.queryRegisterInfo(4, out errMsg) != 0)
  720. {
  721. outparam = errMsg;
  722. return -1;
  723. }
  724. setPatientByMiRegInfo(JObject.Parse(errMsg));
  725. //获取其他入参
  726. JObject joInpar = new JObject();
  727. joInpar.Add("payOrdId", MPat.payOrdId);//待支付订单号
  728. joInpar.Add("payToken", MPat.payToken);//支付订单对应的token
  729. joInpar.Add("orgCodg", Global.inf.hospitalNO);//定点机构编码
  730. joInpar.Add("idNo", MPat.IDNO);//业务流水号 前端传入
  731. joInpar.Add("userName", MPat.name);
  732. joInpar.Add("idType", "01");
  733. joInpar.Add("expData", "");
  734. //JObject joData = new JObject();
  735. //joData.Add("data", joInpar);
  736. outparam = joInpar.ToString();
  737. return 0;
  738. }
  739. catch (Exception ex)
  740. {
  741. outparam = "Get6301Inpar:" + ex.Message;
  742. return -1;
  743. }
  744. finally
  745. {
  746. Global.writeLog("Get6301Inpar", "", outparam);
  747. }
  748. }
  749. /// <summary>
  750. /// 返回移动支付结算信息给HIS
  751. /// </summary>
  752. /// <param name="joSetlInpar"></param>
  753. /// <param name="joSetlinfo"></param>中心返回的信息
  754. /// <param name="outParam"></param>
  755. /// <returns></returns>
  756. public int returnMPSettlementInfo(JObject joReg, JObject joSettl, out string outParam)
  757. {
  758. string errMsg;
  759. try
  760. {
  761. JObject joSumFee = new JObject();
  762. if (sumInsuRtnSettlInfo(joSettl, out joSumFee, out errMsg) != 0)
  763. {
  764. outParam = "返回结算结果给HIS失败,请联系管理员!" + errMsg;
  765. return -1;
  766. }
  767. dynamic joTmp = new JObject();
  768. joTmp.settleInfo = joSettl;
  769. joTmp.updateUserID = Global.user.ID;
  770. joTmp.regInfo = joReg;
  771. joTmp.middleSettleFlag = "";
  772. joTmp.interfaceDr = Global.inf.interfaceDr;
  773. dynamic joHisInfo = new JObject();
  774. joHisInfo.admID = MPat.adm_Dr;
  775. joHisInfo.billID = MPat.billID;
  776. joHisInfo.recordID = MPat.recordID;
  777. joTmp.hisInfo = joHisInfo;
  778. joTmp.psn_type = MPat.psn_type;
  779. joTmp.mobilePayFlag = "Y";
  780. joTmp.sumFeeObj = joSumFee;
  781. joTmp.mdtrtinfo = MPat.mdtrtID;
  782. JObject joRtn = invoker.invokeHISService(JsonHelper.setIrisInpar("05110018", joTmp).ToString(), "返回移动支付结算结果给HIS");
  783. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  784. {
  785. outParam = "返回移动支付结算结果给HIS失败,请联系管理员!" + errMsg;
  786. return -1;
  787. }
  788. else
  789. {
  790. joSumFee.Add("payAuthNo", MPat.payAuthNo);
  791. joSumFee.Add("payOrdId", MPat.payOrdId);
  792. joSumFee.Add("setlLatlnt", MPat.uldLatlnt);
  793. joSumFee.Add("org_no", Global.inf.hospitalNO);
  794. joSumFee.Add("medOrgOrd", MPat.recordID);
  795. joSumFee.Add("mdtrtId", MPat.mdtrtID);
  796. joSumFee.Add("gmt_out_create", MSettl.settlTime.ToString("yyyy-MM-dd HH:mm:ss"));
  797. joRtn["result"] = joSumFee;
  798. outParam = joRtn.ToString();
  799. return 0;
  800. }
  801. }
  802. catch (Exception ex)
  803. {
  804. outParam = "返回移动支付结算结果给HIS出现异常:!" + ex.Message;
  805. return -1;
  806. }
  807. }
  808. /// <summary>
  809. /// 汇总医保返回的结算金额(按照HIS的原则汇总,后期HIS按照这个来进行勾稽关系判断)
  810. /// </summary>
  811. /// <param name="jo"></param>
  812. /// <returns></returns>
  813. public int sumInsuRtnSettlInfo(JObject jo, out JObject joSumFee, out string errMsg)
  814. {
  815. // 医疗费总额是患者在医药机构花费的所有诊疗、药品、耗材、服务设施等项目费用的总和 = 基金支付总额 + 个人负担总金额 + 其他(如医院负担金额);
  816. //3、基金支付总额 = 基本医保统筹基金支出(含职工基本医疗保险、居民基本医疗保险)+补充医疗保险基金支出 (含覆盖全体参保人的居民大病保险和大额医疗费用补助、覆盖部分参保人的企业职工大额医疗费用补助和公务员医疗补助等)+医疗救助基金支出 + 其他支出(如伤残人员医疗保障基金支出);
  817. //5、个人账户支出中包含账户共济支付金额
  818. joSumFee = new JObject();
  819. errMsg = "";
  820. decimal ybAmt, psnAcctAmt, hospAmt, psnCashAmt, medFee;
  821. try
  822. {
  823. ybAmt = 0; psnAcctAmt = 0; hospAmt = 0; psnCashAmt = 0; medFee = 0;
  824. ybAmt = MSettl.fundPaySumamt;
  825. psnAcctAmt = MSettl.accountPaySumamt;
  826. psnCashAmt = MSettl.personCashPay;
  827. hospAmt = MSettl.hospitalPartAmount;
  828. medFee = MSettl.sumamt;
  829. joSumFee.Add("sumamt", medFee);
  830. joSumFee.Add("ybAmt", ybAmt);
  831. joSumFee.Add("psnAcctAmt", psnAcctAmt);
  832. joSumFee.Add("hospAmt", hospAmt);
  833. joSumFee.Add("psnCashAmt", psnCashAmt);
  834. if (medFee != (ybAmt + psnAcctAmt + psnCashAmt + hospAmt))
  835. {
  836. errMsg = "ybAmt(" + ybAmt.ToString() + ")+" + "psnAcctAmt(" + psnAcctAmt.ToString() + ")+" + "psnCashAmt(" + psnCashAmt.ToString() + ")+" + "hospAmt(" + hospAmt.ToString() + ")" + "!=medFee(" + medFee.ToString() + ")";
  837. return -1;
  838. }
  839. return 0;
  840. }
  841. catch (Exception ex)
  842. {
  843. errMsg = ex.Message;
  844. return 1;
  845. }
  846. }
  847. private int MobilePayQuery(out string outPar)
  848. {
  849. string errMsg, M6301Inpar;
  850. outPar = "";
  851. //6301查询具体明细信息
  852. if (Get6301Inpar(out errMsg) != 0)
  853. {
  854. outPar = errMsg;
  855. return -1;
  856. }
  857. M6301Inpar = errMsg;
  858. JObject joM6301Rtn = invoker.invokeMPService("6301", M6301Inpar);
  859. if (JsonHelper.parseMPRtnValue(joM6301Rtn, out errMsg) != 0)
  860. {
  861. outPar = errMsg;
  862. return -1;
  863. }
  864. outPar = joM6301Rtn.ToString();
  865. return 0;
  866. }
  867. }
  868. }