123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957 |
- using Newtonsoft.Json.Linq;
- using PTMedicalInsurance.Common;
- using PTMedicalInsurance.Helper;
- using PTMedicalInsurance.Variables;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PTMedicalInsurance.Business
- {
- class LocalMobilePayProcess : AbstractProcess
- {
- private Patients MPat;
- public Settlements MSettl;
- private JObject joParam;
- private JObject joInsuAdmObj;
- private JObject joResponse;
- /// <summary>
- /// 支付请求
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public override CallResult Process(JObject input)
- {
- //调用HIS费用查询信息
- if (hIS.getHisFee(Global.pat, out outParam) != 0)
- {
- return Exception("获取HIS费用", outParam);
- }
- //调用医保平台转换
- JObject joHisFee = JObject.Parse(outParam);
- if (mIS.convertHisFeeWithInsuCode(joHisFee, out outParam) != 0)
- {
- return Exception("转换HIS费用", outParam);
- }
- Decimal total = 0;
- JArray jaFeeDetail = JArray.Parse(JsonHelper.getDestValue(JObject.Parse(outParam), "data"));
- jaFeeDetail.ToList().ForEach((fee) =>
- {
- fee["chrg_bchno"] = Global.pat.adm_Dr.ToString();
- fee["med_type"] = Global.pat.medType;
- fee["med_list_spc"] = fee["spec"];
- fee["medins_list_codg"] = fee["med_list_codg"]; // 医院编码须转换为中心编码
- dynamic expContent = new JObject();
- JProperty exp = fee.Children<JProperty>().FirstOrDefault(p => p.Name == "expContent");
- if (exp != null)
- {
- exp.Remove();
- }
- string item_sum = JsonHelper.getDestValue((JObject)fee, "det_item_fee_sumamt");
- if (!string.IsNullOrEmpty(item_sum)) {
- total += Decimal.Parse(item_sum);
- }
- expContent.selfpay_prop = fee["SelfPayPercent"];
- expContent.drord_no = fee["drord_no"];
- fee["exp_content"] = expContent;
- });
- JObject joSettlement = (JObject)input["settlement"];
- joSettlement["medfee_sumamt"] = total;
- //合并参数
- dynamic joInput = new JObject();
- //joInput.Add("feedetail", jaFeeDetail);
- joInput = mergeJson(joInput, (JObject)input["patInfo"]);
- joInput = mergeJson(joInput, (JObject)input["data"]);
- joInput = mergeJson(joInput, (JObject)input["mdtrtinfo"]);
- joInput = mergeJson(joInput, joSettlement);
- joInput.Add("diseinfo_list",input["diseinfo"]);
- joInput.Add("feedetail_list", jaFeeDetail);
- dynamic joExpContent = new JObject();
- joExpContent.op_swssc_flag = "0";
- joExpContent.itnt_hosp_flag = "0";
- joExpContent.mulaid_flag = "0";
- joInput.exp_content = joExpContent;
- outParam = JsonHelper.toJsonString(joInput);
- return Success();
- }
- private JObject mergeJson(JObject source,JObject target)
- {
- source.Merge(target, new JsonMergeSettings
- {
- MergeArrayHandling = MergeArrayHandling.Union
- });
- return source;
- }
-
- private void init(JObject joInpar)
- {
- joParam = JObject.Parse(JsonHelper.getDestValue(joInpar, "params[0]"));
- joInsuAdmObj = JObject.Parse(JsonHelper.getDestValue(joInpar, "insuAdmObj"));
- string response = JsonHelper.getDestValue(joInpar, "responsecontent");
- if(!string.IsNullOrEmpty(response))
- {
- joResponse = JObject.Parse(response);
- }
- setPatientByInPar();
- setSettlementsByInPar();
- }
- public void setSettlementsByInPar()
- {
- MSettl.clearingWay = JsonHelper.getDestValue(joInsuAdmObj, "psnSetlway");
- MSettl.settlID = JsonHelper.getDestValue(joInsuAdmObj, "payOrdId");
- MSettl.payOrdId = JsonHelper.getDestValue(joInsuAdmObj, "payOrdId");
- MSettl.onlineYBFalg = JsonHelper.getDestValue(joInsuAdmObj, "onlineYBFalg");
- string medOrdId = JsonHelper.getDestValue(joParam, "med_org_ord");
- if(!string.IsNullOrEmpty(medOrdId))
- {
- MSettl.medins_setl_id = medOrdId;
- }
- }
- public void setPatientByInPar()
- {
- MPat.adm_Dr = int.Parse(JsonHelper.getDestValue(joParam, "admID"));
- Global.pat.adm_Dr = MPat.adm_Dr;
- MPat.name = JsonHelper.getDestValue(joInsuAdmObj, "patName");
- if (string.IsNullOrEmpty(MPat.name)) {
- MPat.name = JsonHelper.getDestValue(joInsuAdmObj, "psn_name");
- }
- MPat.IDNO = JsonHelper.getDestValue(joInsuAdmObj, "idNo");
- MPat.recordID = JsonHelper.getDestValue(joParam, "recordID");
- MPat.billID = JsonHelper.getDestValue(joParam, "billID");
- MPat.medType = JsonHelper.getDestValue(joInsuAdmObj, "medType");
- MPat.certType = JsonHelper.getDestValue(joInsuAdmObj, "mdtrtCertType");
- MPat.token = JsonHelper.getDestValue(joInsuAdmObj, "ecToken");
- MPat.payAuthNo = JsonHelper.getDestValue(joInsuAdmObj, "payAuthNo");
- MPat.uldLatlnt = JsonHelper.getDestValue(joInsuAdmObj, "uldLatlnt");
- MPat.payOrdId = JsonHelper.getDestValue(joInsuAdmObj, "payOrdId");
- MPat.mdtrtID = JsonHelper.getDestValue(joInsuAdmObj, "mdtrt_id");
- if (string.IsNullOrEmpty(MPat.mdtrtID) && joResponse != null)
- {
- MPat.mdtrtID = JsonHelper.getDestValue(joResponse, "SETLINFO.mdtrt_id");
- }
- MPat.settlID = JsonHelper.getDestValue(joInsuAdmObj, "setl_id");
- if (string.IsNullOrEmpty(MPat.settlID) && joResponse != null)
- {
- MPat.settlID = JsonHelper.getDestValue(joResponse, "SETLINFO.setl_id");
- MPat.psn_no = JsonHelper.getDestValue(joResponse, "SETLINFO.psn_no");
- MPat.payOrdId = MPat.settlID;
- MPat.insuplc_admdvs = JsonHelper.getDestValue(joResponse, "insuplcAdmdvs");
- }
- Global.pat.mdtrtID = MPat.mdtrtID;
- }
- /// <summary>
- /// 交易确认
- /// </summary>
- /// <param name="input"></param>
- public CallResult Confirm(JObject input)
- {
- outParam = "";
- string errMsg = "";
- init(input);
- // save
- //设置
- JObject joSettle = joResponse["SETLINFO"].ToObject<JObject>();
- setSettlementsBy6202Rtn(joSettle);
- MSettl.confirmFlag = 0;
- //存入MI 结算表
- if (saveSettlement(out errMsg) != 0)
- {
- outParam = errMsg;
- return Exception(-1, "保存结算信息失败",errMsg);
- }
- // 返回给HIS
- if (returnToHis(joSettle, out errMsg) != 0)
- {
- outParam = errMsg;
- return Exception(-1,"返回结算信息给HIS失败",errMsg);
- }
- MobilePayConfirmSettlement(joSettle,out outParam);
- return IrisReturn("结算成功",null);
- }
- public CallResult Cancel(JObject input)
- {
- init(input);
- int ret = MobilePayCancelSettlement(out outParam);
- if(ret !=0)
- {
- return IrisReturn(-1,"退费失败", JObject.Parse(outParam));
- }
- return IrisReturn("退费成功", null);
- }
- public int MobilePayCancelSettlement(out string outPar)
- {
- string errMsg;
- outPar = "";
- try
- {
- if (MSettl.onlineYBFalg != "Y")
- {
- Global.businessType = "01301"; //结算
- //读电子凭证
- if (ReadEc(out errMsg) != 0)
- {
- outPar = errMsg;
- return -1;
- }
- }
-
- //获取6203入参
- if (Get6203Inpar(out errMsg) != 0)
- {
- outPar = errMsg;
- return -1;
- }
- JObject joInput = JObject.Parse(errMsg);
- // 调用his服务(移动支付院内退款服务)
- JObject jo6203Rtn = invoker.invokeHISService(JsonHelper.setIrisInpar("05110036", joInput).ToString(), "移动支付退费");
- //JObject jo6203Rtn = invoker.invokeServiceAsync(JsonHelper.setIrisInpar("05110036", joInput).ToString());
- Global.writeLog("异步调用返回:"+JsonHelper.toJsonString(jo6203Rtn));
- if (JsonHelper.parseIrisRtnValue(jo6203Rtn, out errMsg) != 0)
- {
- outPar = JsonHelper.setIrisReturnValue(-1, errMsg, null).ToString(); ;
- return -1;
- }
- else
- {
- //处理撤销数据
- if (cancleSettlement(Global.pat.settlID, out errMsg) != 0)
- {
- outPar = errMsg;
- return -1;
- }
- joParam.Add("middleSettleFlag", "");
- //退HIS结算
- if (hIS.cancleSettlementInfo(joParam, out errMsg) != 0)
- {
- outPar = errMsg;
- return -1;
- }
- else
- {
- outPar = JsonHelper.setIrisReturnValue(0, errMsg, null).ToString();
- return 0;
- }
- }
- }
- catch (Exception ex)
- {
- Global.writeLog("MobilePayCancelSettlement:" + ex.Message);
- outPar = ex.Message;
- return -1;
- }
- }
- /// <summary>
- /// 取消结算
- /// </summary>
- /// <param name="outParam"></param>
- /// <returns></returns>
- public int cancleSettlement(string newSettlID, out string outParam)
- {
- JObject joTmp = new JObject();
- string errMsg = "";
- try
- {
- joTmp.Add("HospitalDr", Global.inf.hospitalDr);
- joTmp.Add("InterfaceDr", Global.inf.interfaceDr);
- joTmp.Add("admID", MPat.adm_Dr);
- joTmp.Add("mdtrt_id", MPat.mdtrtID);
- joTmp.Add("setl_id", MPat.settlID);
- joTmp.Add("new_setl_id", newSettlID);
- joTmp.Add("updateUserID", Global.user.ID);
- joTmp.Add("msgid", Global.curEvt.msgid);
- joTmp.Add("OccurTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- JObject joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010052", joTmp).ToString(), "取消结算信息");
- if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
- {
- outParam = errMsg;
- return -1;
- }
- else
- {
- outParam = JsonHelper.setExceptionJson(0, "云医保平台", "取消结算成功").ToString();
- return 0;
- }
- }
- catch (Exception ex)
- {
- outParam = "取消结算信息:" + ex.Message;
- return -1;
- }
- }
- #region 读卡
- public int ReadEc(out string outPar)
- {
- outPar = "";
- try
- {
- PatientService patientService = new PatientService();
- int ret = patientService.readCard(out outPar);
- if (ret != 0)
- {
- return -1;
- }
- MPat.ecCardNo = Global.pat.ecCardNo;
- MPat.ecToken = Global.pat.ecToken;
- return 0;
- }
- catch (Exception ex)
- {
- outPar = ex.Message;
- return -1;
- }
- }
- public void setPatientByEc(JObject jo)
- {
- MPat.name = JsonHelper.getDestValue(jo, "userName");
- MPat.IDNO = JsonHelper.getDestValue(jo, "idNo");
- MPat.certType = JsonHelper.getDestValue(jo, "idType");
- MPat.token = JsonHelper.getDestValue(jo, "ecToken");
- MPat.insuplc_admdvs = JsonHelper.getDestValue(jo, "insuOrg");
- MPat.payAuthNo = JsonHelper.getDestValue(jo, "authNo");
- MPat.gend = JsonHelper.getDestValue(jo, "gender");
- MPat.brdy = JsonHelper.getDestValue(jo, "birthday");
- MPat.naty = JsonHelper.getDestValue(jo, "nationality");
- }
- #endregion
- private int returnToHis(JObject joPreSettl,out string errMsg)
- {
- //返回给HIS后端
- //JObject joTmp = JObject.Parse(JsonHelper.getDestValue(joM6201Rtn, "encData"));
- JObject joTmp = new JObject();
- joTmp.Add("insutype", MPat.insuType);
- joTmp.Add("psn_no", MPat.psn_no);
- joTmp.Add("insuplc_admdvs", MPat.insuplc_admdvs);
- joTmp.Add("mdtrtId", MPat.mdtrtID);
- joTmp.Add("mdtrt_id", MPat.mdtrtID);
- joTmp.Add("mdtrt_cert_type", JsonHelper.getDestValue(joPreSettl, "mdtrt_cert_type"));
- joTmp.Add("mdtrt_cert_no", JsonHelper.getDestValue(joPreSettl, "certno"));
- joTmp.Add("med_type", JsonHelper.getDestValue(joPreSettl, "med_type"));
- if (returnMPSettlementInfo(joTmp, joPreSettl, out errMsg) != 0)
- {
- return -1;
- }
- return 0;
- }
- private int MobilePayConfirmSettlement(JObject joSettlInfo,out string outPar)
- {
- string errMsg;
- outPar = "";
- try
- {
- //设置
- setSettlementsBy6301Rtn(joSettlInfo);
- MSettl.confirmFlag = 1;
- //存入MI 结算表
- if (updateSettlement(out errMsg) != 0)
- {
- outPar = errMsg;
- return -1;
- }
- else
- {
- //返回给HIS前端
- outPar = JsonHelper.setExceptionJson(0, "云医保平台", "确认成功!").ToString();
- return 0;
- }
- }
- catch (Exception ex)
- {
- outPar = ex.Message;
- return -1;
- }
- }
- public void setSettlementsBy6202Rtn(JObject jo)
- {
- MSettl.settlID = JsonHelper.getDestValue(jo, "setl_id");
- MPat.payOrdId = MSettl.settlID;
- MSettl.payOrdId = MSettl.settlID;
- MSettl.ordStas = JsonHelper.getDestValue(jo, "ordStas");
- MSettl.sumamt = getDecimalFee(jo, "medfee_sumamt");
- MSettl.personCashPay = getDecimalFee(jo, "ownPayAmt");
- MSettl.accountPaySumamt = getDecimalFee(jo, "acct_pay");
- MSettl.fundPaySumamt = getDecimalFee(jo, "fund_pay_sumamt");
- MSettl.deposit = getDecimalFee(jo, "deposit");
- MSettl.clearingOrgan = JsonHelper.getDestValue(jo, "clr_optins");
- MSettl.clearingType = JsonHelper.getDestValue(jo, "clr_type");
- MSettl.clearingWay = JsonHelper.getDestValue(jo, "clr_way");
- MSettl.civilserviceAllowancePay = getDecimalFee(jo, "cvlserv_pay");
- MSettl.ownPayAmount = getDecimalFee(jo, "fulamt_ownpay_amt");
- MSettl.overLimitAmountmt = getDecimalFee(jo, "overlmt_selfpay");
- MSettl.preSelfPayAmount = getDecimalFee(jo, "preselfpay_amt");
- MSettl.inPolicyRangeAmount = getDecimalFee(jo, "inscp_scp_amt");
- MSettl.actualPayDeductible = getDecimalFee(jo, "act_pay_dedc");
- MSettl.healthInsurancePay = getDecimalFee(jo, "hifp_pay");
- MSettl.healthInsuranceRatio = getDecimalFee(jo, "pool_prop_selfpay");
- MSettl.enterpriseSupplementPay = getDecimalFee(jo, "hifes_pay");
- MSettl.seriousIllnessPay = getDecimalFee(jo, "hifmi_pay");
- MSettl.largeExpensesSupplementPay = getDecimalFee(jo, "hifob_pay");
- MSettl.medicalAssistPay = getDecimalFee(jo, "maf_pay");
- MSettl.hospitalPartAmount = getDecimalFee(jo, "hosp_part_amt");
- MSettl.otherPay = getDecimalFee(jo, "oth_pay");
- MSettl.personPaySumamt = getDecimalFee(jo, "psn_part_amt");
- MSettl.balance = getDecimalFee(jo, "balc");
- MSettl.accountMutualAidAmount = getDecimalFee(jo, "acct_mulaid_pay");
- }
- /// <summary>
- /// 插入结算信息
- /// </summary>
- /// <param name="joSettlement"></param>
- /// <param name="outParam"></param>
- /// <returns></returns>
- public int saveSettlement(out string outParam)
- {
- JObject joTmp = new JObject();
- string errMsg = "";
- try
- {
- JObject joSetlinfo = new JObject();
- joSetlinfo.Add("HospitalDr", Global.inf.hospitalDr);
- joSetlinfo.Add("admID", MPat.adm_Dr);
- joSetlinfo.Add("mdtrt_id", MPat.mdtrtID);
- joSetlinfo.Add("setl_id", MSettl.settlID);//
- joSetlinfo.Add("pay_ord_id", MSettl.payOrdId);
- joSetlinfo.Add("psn_no", MPat.psn_no);
- joSetlinfo.Add("psn_name", MPat.name);
- //joSetlinfo.Add("mdtrt_cert_type", JsonHelper.getDestValue(joRtnSetlinfo, "mdtrt_cert_type"));
- joSetlinfo.Add("certno", MPat.certNO);
- joSetlinfo.Add("gend", MPat.gend);
- joSetlinfo.Add("naty", MPat.naty);
- joSetlinfo.Add("brdy", MPat.brdy);
- joSetlinfo.Add("age", MPat.age);
- joSetlinfo.Add("insutype", MPat.insuType);
- joSetlinfo.Add("psn_type", MPat.psn_type);
- joSetlinfo.Add("cvlserv_flag", "");
- joSetlinfo.Add("setl_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- joSetlinfo.Add("mdtrt_cert_type", MPat.mdtrtcertType);
- joSetlinfo.Add("med_type", MPat.medType);
- joSetlinfo.Add("medfee_sumamt", MSettl.sumamt);//总费用
- joSetlinfo.Add("fulamt_ownpay_amt", MSettl.ownPayAmount);//全自费金额
- joSetlinfo.Add("overlmt_selfpay", MSettl.overLimitAmountmt);//超限价自费费用
- joSetlinfo.Add("preselfpay_amt", MSettl.preSelfPayAmount);//先行自付金额
- joSetlinfo.Add("inscp_scp_amt", MSettl.inPolicyRangeAmount);//符合政策范围金额
- joSetlinfo.Add("act_pay_dedc", MSettl.actualPayDeductible);//实际支付起付线
- joSetlinfo.Add("hifp_pay", MSettl.healthInsurancePay);//基本医疗保险统筹基金支出
- joSetlinfo.Add("pool_prop_selfpay", MSettl.healthInsuranceRatio);//基本医疗保险统筹基金支付比例
- joSetlinfo.Add("cvlserv_pay", MSettl.civilserviceAllowancePay);//公务员医疗补助资金支出
- joSetlinfo.Add("hifes_pay", MSettl.enterpriseSupplementPay);//企业支付 占用 大病报销金额
- joSetlinfo.Add("hifmi_pay", MSettl.seriousIllnessPay);// 居民大病保险资金支出
- joSetlinfo.Add("hifob_pay", MSettl.largeExpensesSupplementPay);//职工大额医疗费用补助基金支出
- joSetlinfo.Add("maf_pay", MSettl.medicalAssistPay);//医疗救助基金支出
- joSetlinfo.Add("hosp_part_amt", MSettl.hospitalPartAmount);//医院负担金额
- joSetlinfo.Add("oth_pay", MSettl.otherPay);//其他支出
- joSetlinfo.Add("fund_pay_sumamt", MSettl.fundPaySumamt);//基金支付总额
- joSetlinfo.Add("psn_part_amt", MSettl.personPaySumamt);//个人负担总金额
- joSetlinfo.Add("acct_pay", MSettl.accountPaySumamt);//个人账户支出
- joSetlinfo.Add("psn_cash_pay", MSettl.personCashPay);//个人现金支出
- joSetlinfo.Add("balc", MSettl.balance);// 余额
- joSetlinfo.Add("acct_mulaid_pay", "");//个人账户共济支付金额
- joSetlinfo.Add("medins_setl_id", "");//医药机构结算ID
- joSetlinfo.Add("clr_optins", MSettl.clearingOrgan);//清算经办机构
- joSetlinfo.Add("clr_way", MSettl.clearingWay);//清算方式
- joSetlinfo.Add("clr_type", MSettl.clearingType);//清算类别
- joSetlinfo.Add("ValidFlag", 1);
- joSetlinfo.Add("BillType", 1);
- joSetlinfo.Add("msgid", Global.curEvt.msgid);
- joSetlinfo.Add("admType", "3");
- joSetlinfo.Add("billID", MPat.billID);
- joSetlinfo.Add("recordID", MPat.recordID);
- joSetlinfo.Add("interfaceDr", Global.inf.interfaceDr);
- joSetlinfo.Add("insuplc_admdvs", MPat.insuplc_admdvs);
- joSetlinfo.Add("OccurTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- joSetlinfo.Add("HospitalizationsDays", MSettl.hospitalizationsDays);
- joSetlinfo.Add("HospitalizationsTimes", MSettl.hospitalizationsTimes);
- joSetlinfo.Add("HISAdmTime", MSettl.hisAdmTime);
- joSetlinfo.Add("HISDischargeTime", MSettl.hisDischargeTime);
- joSetlinfo.Add("updateUserID", Global.user.ID);
- joSetlinfo.Add("ConfirmFlag", MSettl.confirmFlag);
- JObject joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010051", joSetlinfo).ToString(), "插入结算信息");
- if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
- {
- outParam = errMsg;
- return -1;
- }
- else
- {
- outParam = joSetlinfo.ToString();
- return 0;
- }
- }
- catch (Exception ex)
- {
- outParam = "插入结算信息:" + ex.Message;
- return -1;
- }
- }
- public void setSettlementsBy6301Rtn(JObject jo)
- {
- MSettl.settlID = MPat.payOrdId;
- MPat.psn_no = JsonHelper.getDestValue(jo, "psn_no");
- MPat.naty = JsonHelper.getDestValue(jo, "naty");
- //MPat.name = JsonHelper.getDestValue(jo, "name");
- MPat.age = JsonHelper.getDestValue(jo, "age");
- MPat.gend = JsonHelper.getDestValue(jo, "gend");
- MPat.certNO = JsonHelper.getDestValue(jo, "certno");
- MPat.brdy = JsonHelper.getDestValue(jo, "brdy");
- MPat.insuType = JsonHelper.getDestValue(jo, "insutype");
- MPat.psn_type = JsonHelper.getDestValue(jo, "psn_type");
- MPat.mdtrtcertType = JsonHelper.getDestValue(jo, "mdtrt_cert_type");
- MPat.medType = JsonHelper.getDestValue(jo, "med_type");
- //MPat.insuplc_admdvs = JsonHelper.getDestValue(jo, "insuplc_admdvs");
- //MPat.payOrdId = JsonHelper.getDestValue(jo, "payOrdId");
- MSettl.ordStas = JsonHelper.getDestValue(jo, "ordStas");
- MSettl.sumamt = getDecimalFee(jo, "medfee_sumamt");
- MSettl.personCashPay = getDecimalFee(jo, "psn_cash_pay");
- MSettl.accountPaySumamt = getDecimalFee(jo, "acct_pay");
- MSettl.fundPaySumamt = getDecimalFee(jo, "fund_pay_sumamt");
- //MSettl.deposit = getDecimalFee(jo, "deposit");
- MSettl.clearingOrgan = JsonHelper.getDestValue(jo, "clr_optins");
- MSettl.clearingType = JsonHelper.getDestValue(jo, "clr_type");
- MSettl.clearingWay = JsonHelper.getDestValue(jo, "clr_way");
- MSettl.civilserviceAllowancePay = getDecimalFee(jo, "cvlserv_pay");
- MSettl.ownPayAmount = getDecimalFee(jo, "fulamt_ownpay_amt");
- MSettl.overLimitAmountmt = getDecimalFee(jo, "overlmt_selfpay");
- MSettl.preSelfPayAmount = getDecimalFee(jo, "preselfpay_amt");
- MSettl.inPolicyRangeAmount = getDecimalFee(jo, "inscp_scp_amt");
- MSettl.actualPayDeductible = getDecimalFee(jo, "act_pay_dedc");
- MSettl.healthInsurancePay = getDecimalFee(jo, "hifp_pay");
- MSettl.healthInsuranceRatio = getDecimalFee(jo, "pool_prop_selfpay");
- MSettl.enterpriseSupplementPay = getDecimalFee(jo, "hifes_pay");
- MSettl.seriousIllnessPay = getDecimalFee(jo, "hifmi_pay");
- MSettl.largeExpensesSupplementPay = getDecimalFee(jo, "hifob_pay");
- MSettl.medicalAssistPay = getDecimalFee(jo, "maf_pay");
- MSettl.hospitalPartAmount = getDecimalFee(jo, "hosp_part_amt");
- MSettl.otherPay = getDecimalFee(jo, "oth_pay");
- MSettl.personPaySumamt = getDecimalFee(jo, "psn_part_amt");
- MSettl.balance = getDecimalFee(jo, "balc");
- MSettl.accountMutualAidAmount = getDecimalFee(jo, "acct_mulaid_pay");
- }
- /// <summary>
- /// 获取结算费用的封装
- /// </summary>
- /// <param name="jo"></param>
- /// <param name="path"></param>
- /// <returns></returns>
- private decimal getDecimalFee(JObject jo, string path)
- {
- try
- {
- string temp = JsonHelper.getDestValue(jo, path);
- if (temp == "")
- {
- return 0;
- }
- else
- {
- return decimal.Parse(temp);
- }
- }
- catch (Exception ex)
- {
- Global.writeLog("getFee异常:" + ex.Message);
- return 0;
- }
- }
- public int updateSettlement(out string outParam)
- {
- JObject joTmp = new JObject();
- string errMsg = "";
- try
- {
- JObject joSetlinfo = new JObject();
- joSetlinfo.Add("HospitalDr", Global.inf.hospitalDr);
- joSetlinfo.Add("AdmDr", MPat.adm_Dr);
- joSetlinfo.Add("MdtrtID", MPat.mdtrtID);
- joSetlinfo.Add("SettlementID", MSettl.settlID);//
- joSetlinfo.Add("PayOrdID", MSettl.payOrdId);
- joSetlinfo.Add("PersonnelNO", MPat.psn_no);
- joSetlinfo.Add("PatientName", MPat.name);
- //joSetlinfo.Add("CertificateType", JsonHelper.getDestValue(joRtnSetlinfo, "mdtrt_cert_type"));
- joSetlinfo.Add("CertificateNO", MPat.certNO);
- joSetlinfo.Add("Gender", MPat.gend);
- joSetlinfo.Add("Nation", MPat.naty);
- joSetlinfo.Add("BirthDay", MPat.brdy);
- joSetlinfo.Add("Age", MPat.age);
- joSetlinfo.Add("InsuranceType", MPat.insuType);
- joSetlinfo.Add("PersonType", MPat.psn_type);
- joSetlinfo.Add("CivilserviceFlag", "");
- joSetlinfo.Add("SettlementDateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- joSetlinfo.Add("MdtrtCertType", MPat.mdtrtcertType);
- joSetlinfo.Add("MedicalType", MPat.medType);
- joSetlinfo.Add("Sumamt", MSettl.sumamt);//总费用
- joSetlinfo.Add("OwnPayAmount", MSettl.ownPayAmount);//全自费金额
- joSetlinfo.Add("OverLimitAmount", MSettl.overLimitAmountmt);//超限价自费费用
- joSetlinfo.Add("PreSelfPayAmount", MSettl.preSelfPayAmount);//先行自付金额
- joSetlinfo.Add("InPolicyRangeAmount", MSettl.inPolicyRangeAmount);//符合政策范围金额
- joSetlinfo.Add("ActualPayDeductible", MSettl.actualPayDeductible);//实际支付起付线
- joSetlinfo.Add("HealthInsurancePay", MSettl.healthInsurancePay);//基本医疗保险统筹基金支出
- joSetlinfo.Add("HealthInsuranceRatio", MSettl.healthInsuranceRatio);//基本医疗保险统筹基金支付比例
- joSetlinfo.Add("CivilserviceAllowancePay", MSettl.civilserviceAllowancePay);//公务员医疗补助资金支出
- joSetlinfo.Add("EnterpriseSupplementPay", MSettl.enterpriseSupplementPay);//企业支付
- joSetlinfo.Add("SeriousIllnessPay", MSettl.seriousIllnessPay);// 居民大病保险资金支出
- joSetlinfo.Add("LargeExpensesSupplementPay", MSettl.largeExpensesSupplementPay);//职工大额医疗费用补助基金支出
- joSetlinfo.Add("MedicalAssistPay", MSettl.medicalAssistPay);//医疗救助基金支出
- joSetlinfo.Add("HospitalPartAmount", MSettl.hospitalPartAmount);//医院负担金额
- joSetlinfo.Add("OtherPay", MSettl.otherPay);//其他支出
- joSetlinfo.Add("FundPaySumamt", MSettl.fundPaySumamt);//基金支付总额
- joSetlinfo.Add("PersonPaySumamt", MSettl.personPaySumamt);//个人负担总金额
- joSetlinfo.Add("AccountPaySumamt", MSettl.accountPaySumamt);//个人账户支出
- joSetlinfo.Add("PersonCashPay", MSettl.personCashPay);//个人现金支出
- joSetlinfo.Add("Balance", MSettl.balance);// 余额
- joSetlinfo.Add("AccountMutualAidAmount", "0");//个人账户共济支付金额
- joSetlinfo.Add("OrganSettlementID", MSettl.medins_setl_id);//医药机构结算ID);//医药机构结算ID
- joSetlinfo.Add("ClearingOrgan", MSettl.clearingOrgan);//清算经办机构
- joSetlinfo.Add("ClearingWay", MSettl.clearingWay);//清算方式
- joSetlinfo.Add("ClearingType", MSettl.clearingType);//清算类别
- joSetlinfo.Add("ValidFlag", 1);
- joSetlinfo.Add("BillType", 1);
- joSetlinfo.Add("ConfirmFlag", MSettl.confirmFlag);
- joSetlinfo.Add("MSGID", Global.curEvt.msgid);
- joSetlinfo.Add("AdmType", "3");
- joSetlinfo.Add("BillID", MPat.billID);
- joSetlinfo.Add("RecordID", MPat.recordID);
- joSetlinfo.Add("InterfaceDr", Global.inf.interfaceDr);
- joSetlinfo.Add("InsuranceAreaCode", MPat.insuplc_admdvs);
- joSetlinfo.Add("OccurTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- joSetlinfo.Add("HospitalizationsDays", MSettl.hospitalizationsDays);
- joSetlinfo.Add("HospitalizationsTimes", MSettl.hospitalizationsTimes);
- joSetlinfo.Add("HISAdmTime", MSettl.hisAdmTime);
- joSetlinfo.Add("HISDischargeTime", MSettl.hisDischargeTime);
- joSetlinfo.Add("updateUserID", Global.user.ID);
- JObject joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010089", joSetlinfo).ToString(), "通过订单号更新结算信息");
- if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
- {
- outParam = errMsg;
- return -1;
- }
- else
- {
- outParam = joSetlinfo.ToString();
- return 0;
- }
- }
- catch (Exception ex)
- {
- outParam = "插入结算信息:" + ex.Message;
- return -1;
- }
- }
- public void setPatientByMiRegInfo(JObject jo)
- {
- MPat.name = JsonHelper.getDestValue(jo, "data.PatientName");
- MPat.psn_no = JsonHelper.getDestValue(jo, "data.PersonalNO");
- MPat.certNO = JsonHelper.getDestValue(jo, "data.CertificateNO");
- MPat.IDNO = MPat.certNO;
- MPat.certType = JsonHelper.getDestValue(jo, "data.CertificateType");
- MPat.payToken = JsonHelper.getDestValue(jo, "data.payToken");
- MPat.insuplc_admdvs = JsonHelper.getDestValue(jo, "data.InsuranceAreaCode");
- }
- //组织M6203入参
- public int Get6203Inpar(out string outparam)
- {
- string errMsg = "";
- outparam = "";
- try
- {
- JObject joInpar = new JObject();
- //获取医保平台结算信息
- if (QuerySettleInfo(out errMsg) != 0)
- {
- outparam = Error(-1, errMsg).Data;
- return -1;
- }
- JObject joRtn = JObject.Parse(errMsg);
- string settlInfo = JsonHelper.getDestValue(joRtn, "result.data[0]");
- if (string.IsNullOrEmpty(settlInfo))
- {
- outparam = Error(-1, "没有查询到结算信息,请检查参数").Data;
- return -1;
- }
- // 组织调用参数
- Global.curEvt.msgid = Global.inf.hospitalNO + DateTime.Now.ToString("yyyyMMddHHmmssffff");
- JObject joSettl = JObject.Parse(settlInfo);
- string tradeNo = JsonHelper.getDestValue(joSettl, "OrganSettlementID");
- if(string.IsNullOrEmpty(tradeNo))
- {
- outparam = Error(-1,"支付交易流水号为空,请核实").Data;
- return -1;
- }
- MPat.settlID = JsonHelper.getDestValue(joSettl, "SettlementID");
- //入参
- joInpar.Add("outtradeno", tradeNo);//支付订单号(采用本地ID)
- joInpar.Add("appRefdSn", Global.curEvt.msgid);//应用退款流水号
- joInpar.Add("businessType", "DWREFUND");//应用退费时间
- JObject session = Global.curEvt.jaSession?[0].ToObject<JObject>();
- joInpar.Add("hospitalCode", JsonHelper.getDestValue(session,"hospCode")); //hiscode
- joInpar.Add("ec_code", MPat.ecToken);
- joInpar.Add("patName", MPat.name);
- joInpar.Add("idType", "01");
- joInpar.Add("idCardNo", MPat.IDNO);
- outparam = joInpar.ToString();
- return 0;
- }
- catch (Exception ex)
- {
- outparam = Error(-1, ex.Message).Data;
- return -1;
- }
- finally
- {
- Global.writeLog("Get6203Inpar", "", outparam);
- }
- }
- //查询结算信息
- public int QuerySettleInfo(out string errMsg)
- {
- errMsg = "";
- try
- {
- string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE Hospital_Dr= " + Global.inf.hospitalDr;
- sqlStr = sqlStr + " and AdmType = 3 and Adm_Dr= " + MPat.adm_Dr + " and PayOrdID= '" + MPat.settlID + "'";
- JObject joSqlstr = new JObject();
- joSqlstr.Add("sqlStr", sqlStr);
- JObject joRtn = mIS.DynamicQuerySettlInfo(joSqlstr);
- if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
- {
- return -1;
- }
- else
- {
- errMsg = joRtn.ToString();
- return 0;
- }
- }
- catch (Exception ex)
- {
- errMsg = ex.Message;
- return -1;
- }
- }
- //获取入参,入参基本为类局部变量
- public int Get6301Inpar(out string outparam)
- {
- outparam = "";
- try
- {
- string errMsg;
- //查询登记信息
- if (mIS.queryRegisterInfo(4, out errMsg) != 0)
- {
- outparam = errMsg;
- return -1;
- }
- setPatientByMiRegInfo(JObject.Parse(errMsg));
- //获取其他入参
- JObject joInpar = new JObject();
- joInpar.Add("payOrdId", MPat.payOrdId);//待支付订单号
- joInpar.Add("payToken", MPat.payToken);//支付订单对应的token
- joInpar.Add("orgCodg", Global.inf.hospitalNO);//定点机构编码
- joInpar.Add("idNo", MPat.IDNO);//业务流水号 前端传入
- joInpar.Add("userName", MPat.name);
- joInpar.Add("idType", "01");
- joInpar.Add("expData", "");
- //JObject joData = new JObject();
- //joData.Add("data", joInpar);
- outparam = joInpar.ToString();
- return 0;
- }
- catch (Exception ex)
- {
- outparam = "Get6301Inpar:" + ex.Message;
- return -1;
- }
- finally
- {
- Global.writeLog("Get6301Inpar", "", outparam);
- }
- }
- /// <summary>
- /// 返回移动支付结算信息给HIS
- /// </summary>
- /// <param name="joSetlInpar"></param>
- /// <param name="joSetlinfo"></param>中心返回的信息
- /// <param name="outParam"></param>
- /// <returns></returns>
- public int returnMPSettlementInfo(JObject joReg, JObject joSettl, out string outParam)
- {
- string errMsg;
- try
- {
- JObject joSumFee = new JObject();
- if (sumInsuRtnSettlInfo(joSettl, out joSumFee, out errMsg) != 0)
- {
- outParam = "返回结算结果给HIS失败,请联系管理员!" + errMsg;
- return -1;
- }
- dynamic joTmp = new JObject();
- joTmp.settleInfo = joSettl;
- joTmp.updateUserID = Global.user.ID;
- joTmp.regInfo = joReg;
- joTmp.middleSettleFlag = "";
- joTmp.interfaceDr = Global.inf.interfaceDr;
- dynamic joHisInfo = new JObject();
- joHisInfo.admID = MPat.adm_Dr;
- joHisInfo.billID = MPat.billID;
- joHisInfo.recordID = MPat.recordID;
- joTmp.hisInfo = joHisInfo;
- joTmp.psn_type = MPat.psn_type;
- joTmp.mobilePayFlag = "Y";
- joTmp.sumFeeObj = joSumFee;
- joTmp.mdtrtinfo = MPat.mdtrtID;
- JObject joRtn = invoker.invokeHISService(JsonHelper.setIrisInpar("05110018", joTmp).ToString(), "返回移动支付结算结果给HIS");
- if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
- {
- outParam = "返回移动支付结算结果给HIS失败,请联系管理员!" + errMsg;
- return -1;
- }
- else
- {
- joSumFee.Add("payAuthNo", MPat.payAuthNo);
- joSumFee.Add("payOrdId", MPat.payOrdId);
- joSumFee.Add("setlLatlnt", MPat.uldLatlnt);
- joSumFee.Add("org_no", Global.inf.hospitalNO);
- joSumFee.Add("medOrgOrd", MPat.recordID);
- joSumFee.Add("mdtrtId", MPat.mdtrtID);
- joSumFee.Add("gmt_out_create", MSettl.settlTime.ToString("yyyy-MM-dd HH:mm:ss"));
- joRtn["result"] = joSumFee;
- outParam = joRtn.ToString();
- return 0;
- }
- }
- catch (Exception ex)
- {
- outParam = "返回移动支付结算结果给HIS出现异常:!" + ex.Message;
- return -1;
- }
- }
- /// <summary>
- /// 汇总医保返回的结算金额(按照HIS的原则汇总,后期HIS按照这个来进行勾稽关系判断)
- /// </summary>
- /// <param name="jo"></param>
- /// <returns></returns>
- public int sumInsuRtnSettlInfo(JObject jo, out JObject joSumFee, out string errMsg)
- {
- // 医疗费总额是患者在医药机构花费的所有诊疗、药品、耗材、服务设施等项目费用的总和 = 基金支付总额 + 个人负担总金额 + 其他(如医院负担金额);
- //3、基金支付总额 = 基本医保统筹基金支出(含职工基本医疗保险、居民基本医疗保险)+补充医疗保险基金支出 (含覆盖全体参保人的居民大病保险和大额医疗费用补助、覆盖部分参保人的企业职工大额医疗费用补助和公务员医疗补助等)+医疗救助基金支出 + 其他支出(如伤残人员医疗保障基金支出);
- //5、个人账户支出中包含账户共济支付金额
- joSumFee = new JObject();
- errMsg = "";
- decimal ybAmt, psnAcctAmt, hospAmt, psnCashAmt, medFee;
- try
- {
- ybAmt = 0; psnAcctAmt = 0; hospAmt = 0; psnCashAmt = 0; medFee = 0;
- ybAmt = MSettl.fundPaySumamt;
- psnAcctAmt = MSettl.accountPaySumamt;
- psnCashAmt = MSettl.personCashPay;
- hospAmt = MSettl.hospitalPartAmount;
- medFee = MSettl.sumamt;
- joSumFee.Add("sumamt", medFee);
- joSumFee.Add("ybAmt", ybAmt);
- joSumFee.Add("psnAcctAmt", psnAcctAmt);
- joSumFee.Add("hospAmt", hospAmt);
- joSumFee.Add("psnCashAmt", psnCashAmt);
- if (medFee != (ybAmt + psnAcctAmt + psnCashAmt + hospAmt))
- {
- errMsg = "ybAmt(" + ybAmt.ToString() + ")+" + "psnAcctAmt(" + psnAcctAmt.ToString() + ")+" + "psnCashAmt(" + psnCashAmt.ToString() + ")+" + "hospAmt(" + hospAmt.ToString() + ")" + "!=medFee(" + medFee.ToString() + ")";
- return -1;
- }
- return 0;
- }
- catch (Exception ex)
- {
- errMsg = ex.Message;
- return 1;
- }
- }
- private int MobilePayQuery(out string outPar)
- {
- string errMsg, M6301Inpar;
- outPar = "";
- //6301查询具体明细信息
- if (Get6301Inpar(out errMsg) != 0)
- {
- outPar = errMsg;
- return -1;
- }
- M6301Inpar = errMsg;
- JObject joM6301Rtn = invoker.invokeMPService("6301", M6301Inpar);
- if (JsonHelper.parseMPRtnValue(joM6301Rtn, out errMsg) != 0)
- {
- outPar = errMsg;
- return -1;
- }
- outPar = joM6301Rtn.ToString();
- return 0;
- }
- }
- }
|