LocalMobilePayProcess.cs 42 KB

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