InsuBusiness.cs 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Business;
  3. using PTMedicalInsurance.Business.Core.SelfServiceMachine.ProcessScheduler;
  4. using PTMedicalInsurance.Common;
  5. using PTMedicalInsurance.Forms;
  6. using PTMedicalInsurance.Helper;
  7. using PTMedicalInsurance.Variables;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using System.Windows.Forms;
  18. namespace PTMedicalInsurance
  19. {
  20. public class InsuBusiness : IInsuBusiness
  21. {
  22. //定义相关的变量
  23. private Patients patient;
  24. private Fees fee;
  25. private Settlements settlement;
  26. //json对象属性
  27. private JObject joInParam;
  28. private JArray jaSession ;
  29. private JArray jaParams;
  30. private JObject joParam;
  31. private JObject joInterface;
  32. private JObject joInsuAdmObj;
  33. //设置业务实例
  34. CenterBusiness cBus = new CenterBusiness();
  35. HisMainBusiness hBus = new HisMainBusiness();
  36. HisIrisServices hIS = new HisIrisServices();
  37. MIIrisServices mIS= new MIIrisServices();
  38. InvokeHelper invoker = new InvokeHelper();
  39. //
  40. private string businessType;
  41. public InsuBusiness()
  42. {
  43. Global.curEvt.path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  44. ComputerInfo comp = new ComputerInfo();
  45. Global.curEvt.mac = comp.GetMAC();
  46. Global.curEvt.ip = comp.GetIP();
  47. Global.pat.insuplc_admdvs = ""; //如果是NULL中心会报错
  48. }
  49. private int parseInparam(string inParam,out string errMsg)
  50. {
  51. errMsg = "";
  52. try
  53. {
  54. joInParam = JObject.Parse(inParam);
  55. jaSession = JArray.Parse(JsonHelper.getDestValue(joInParam, "session"));
  56. Global.curEvt.jaSession = jaSession;
  57. jaParams = JArray.Parse(JsonHelper.getDestValue(joInParam, "params"));
  58. joParam = JObject.FromObject(jaParams[0]);
  59. if (JsonHelper.getDestValue(joInParam, "insuAdmObj") != "")
  60. joInsuAdmObj = JObject.Parse(JsonHelper.getDestValue(joInParam, "insuAdmObj"));
  61. joInterface = JObject.Parse(JsonHelper.getDestValue(joInParam, "interfaceinfo"));
  62. businessType = JsonHelper.getDestValue(joInParam, "businessType");
  63. if ((businessType == "M6") || (businessType == "M6C") || (businessType == "M6Confirm"))
  64. {
  65. Environment.CurrentDirectory = @"D:\HttpServerAPI\bin\libs";
  66. }
  67. return 0;
  68. }
  69. catch (Exception ex)
  70. {
  71. errMsg = "parseInparam 解析入参异常:" + errMsg;
  72. return -1;
  73. }
  74. }
  75. /// <summary>
  76. /// 签到
  77. /// </summary>
  78. /// <param name="InParam"></param>
  79. /// <returns></returns>
  80. public string Init(string InParam)
  81. {
  82. string errMsg, rtnResult ="";
  83. JObject joRtn = new JObject();
  84. try
  85. {
  86. if (hBus.initEnvironment(InParam, out errMsg) != 0)
  87. {
  88. return JsonHelper.setExceptionJson(-100, "initEnvironment 失败", errMsg).ToString();
  89. }
  90. else
  91. {
  92. if (mIS.isSigned(ref Global.curEvt.signno) != true)
  93. {
  94. if (businessType != "BasicData")//如果是打开数据对照界面不调用初始化
  95. {
  96. //签到
  97. if (cBus.signIn(out joRtn) != 0)
  98. {
  99. rtnResult = JsonHelper.setExceptionJson(-1, "签到异常", (string)joRtn["err_msg"]).ToString();
  100. return rtnResult;
  101. }
  102. else
  103. {
  104. Global.curEvt.signno = JsonHelper.getDestValue(joRtn, "output.signinoutb.sign_no");
  105. //插入签到表
  106. if (mIS.saveSignRecord(Global.curEvt.signno, out errMsg) != 0)
  107. {
  108. rtnResult = JsonHelper.setIrisReturnValue(0, "中心签到成功但插入签到表失败:" + errMsg, null).ToString();
  109. }
  110. else
  111. {
  112. rtnResult = JsonHelper.setIrisReturnValue(0, "签到成功", joRtn).ToString();
  113. }
  114. }
  115. }
  116. else
  117. {
  118. Global.curEvt.signno = "ABC123";
  119. rtnResult = JsonHelper.setIrisReturnValue(0, "初始化成功(医保对照不初始化)!", null).ToString();
  120. }
  121. }
  122. else
  123. {
  124. rtnResult = JsonHelper.setIrisReturnValue(0, "初始化成功!", null).ToString();
  125. }
  126. return rtnResult;
  127. }
  128. }
  129. catch (Exception ex)
  130. {
  131. rtnResult = JsonHelper.setExceptionJson(-100, "Init 异常", ex.Message).ToString();
  132. return rtnResult;
  133. }
  134. finally
  135. {
  136. Global.writeLog("初始化结果:" + rtnResult);
  137. }
  138. }
  139. /// <summary>
  140. /// 初始化
  141. /// </summary>
  142. /// <param name="inParam"></param>
  143. /// <param name="outParam"></param>
  144. /// <returns></returns>
  145. private int init(string inParam, out string outParam)
  146. {
  147. string errMsg;
  148. outParam = "";
  149. try
  150. {
  151. //BS架构调用方式问题,每次调用都需要重新初始化
  152. JObject joInitRtn = JObject.Parse(Init(inParam));
  153. if (JsonHelper.parseIrisRtnValue(joInitRtn, out errMsg) != 0)
  154. {
  155. outParam = JsonHelper.setExceptionJson(-100, "init(HIS医保环境初始化)", errMsg).ToString();
  156. return -1;
  157. }
  158. else
  159. {
  160. return 0;
  161. }
  162. }
  163. catch (Exception ex)
  164. {
  165. outParam = JsonHelper.setExceptionJson(-100, "init(HIS医保环境初始化)异常", ex.Message).ToString();
  166. return -1;
  167. }
  168. }
  169. /// <summary>
  170. /// 获取患者信息
  171. /// </summary>
  172. /// <param name="InParam"></param>
  173. /// <returns></returns>
  174. public string GetPatientInfo(string InParam)
  175. {
  176. Global.writeLog("GetPatientInfo入参:" + JsonHelper.Compress(InParam));
  177. //设置返回值,错误信息
  178. int errCode;
  179. string errMsg, rtnResult = "",outParam;
  180. //BS架构调用方式问题,每次调用都需要重新初始化
  181. if (init(InParam,out outParam)!= 0)
  182. {
  183. rtnResult = outParam;
  184. return rtnResult;
  185. }
  186. JObject joInParam = JObject.Parse(InParam);
  187. string businessType = JsonHelper.getDestValue(joInParam,"businessType");
  188. try
  189. {
  190. switch (businessType)
  191. {
  192. case "M1"://门诊读卡
  193. {
  194. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  195. if (hBus.readCard(out outParam) != 0)
  196. {
  197. rtnResult = JsonHelper.setExceptionJson(-100, "读卡失败!", outParam).ToString();
  198. }
  199. else
  200. {
  201. //展示患者信息界面
  202. if (hBus.showPatInfo(outParam, out outParam) != 0)
  203. {
  204. rtnResult = outParam;
  205. }
  206. else
  207. {
  208. rtnResult = JsonHelper.setIrisReturnValue(0, "", JObject.Parse(outParam)).ToString();
  209. }
  210. }
  211. break;
  212. }
  213. case "Z1"://住院读卡
  214. {
  215. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  216. if (hBus.readCard(out outParam) != 0)
  217. {
  218. rtnResult = JsonHelper.setExceptionJson(-100, "读卡失败!", outParam).ToString();
  219. }
  220. else
  221. {
  222. string patInfo = outParam;
  223. //展示患者信息界面
  224. if (hBus.showPatInfo(patInfo, out outParam) != 0)
  225. {
  226. rtnResult = outParam;
  227. }
  228. else
  229. {
  230. rtnResult = JsonHelper.setIrisReturnValue(0,"",JObject.Parse(outParam)).ToString();
  231. }
  232. }
  233. break;
  234. }
  235. }
  236. return rtnResult;
  237. }
  238. catch (Exception ex)
  239. {
  240. rtnResult = JsonHelper.setIrisReturnValue(-1 , "GetPatientInfo发生异常;" + ex.Message,null).ToString();
  241. return rtnResult;
  242. }
  243. finally
  244. {
  245. Global.writeLog("GetPatientInfo出参:" + JsonHelper.Compress(rtnResult));
  246. }
  247. }
  248. /// <summary>
  249. /// 登记
  250. /// </summary>
  251. /// <param name="InParam"></param>
  252. /// <returns></returns>
  253. public string Register(string InParam)
  254. {
  255. Global.writeLog("Register 入参:" + JsonHelper.Compress(InParam));
  256. //设置返回值,错误信息
  257. string errMsg, rtnResult = "", outParam;
  258. try
  259. {
  260. //解析入参
  261. if (parseInparam(InParam, out errMsg) != 0)
  262. {
  263. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  264. return rtnResult;
  265. }
  266. //BS架构调用方式问题,每次调用都需要重新初始化
  267. if (init(InParam, out outParam) != 0)
  268. {
  269. rtnResult = outParam;
  270. return rtnResult;
  271. }
  272. //获取pat
  273. hBus.GetRegPatInfo(businessType, joInParam, out Global.pat);
  274. switch (businessType)
  275. {
  276. case "M2"://门诊登记
  277. {
  278. break;
  279. }
  280. case "M2C"://门诊登记撤销
  281. {
  282. break;
  283. }
  284. case "Z0"://住院修改
  285. {
  286. break;
  287. }
  288. case "Z2"://入院登记
  289. {
  290. Global.pat.RYorCY = "1"; //1入院2出院
  291. Global.writeLog(Global.pat.insuType);
  292. string regInParam = "";
  293. //显示登记面板
  294. if (hBus.showInPatRegisterForm( out regInParam) == 0)
  295. {
  296. Global.writeLog(regInParam);
  297. JObject joRegIn_plain = JObject.Parse(JsonHelper.setCenterInpar_plain("2401", regInParam));
  298. JObject joRegIn = JObject.Parse(JsonHelper.setCenterInpar("2401", regInParam));
  299. //上传给中心
  300. JObject joRegOut = invoker.invokeCenterService("2401", joRegIn);
  301. //将中心返回的结果返回HIS,调用HIS服务进行保存
  302. if (JsonHelper.parseCenterRtnValue(joRegOut,out errMsg) == 0)
  303. {
  304. joRegOut.Add("validflag",1);
  305. joRegOut.Add("regstate", 1);
  306. joRegOut.Add("type", 1);
  307. Global.pat.mdtrtID = JsonHelper.getDestValue(joRegOut, "output.result.mdtrt_id");
  308. //插入患者本次就诊用的参保信息
  309. if (hBus.insertPatCurInsuInfo(JsonHelper.getDestValue(joParam, "patientInfo"), out outParam) != 0)
  310. {
  311. if (DialogResult.Yes == MessageBox.Show(outParam, " 是否继续? ", MessageBoxButtons.YesNo))
  312. {
  313. }
  314. else
  315. {
  316. rtnResult = JsonHelper.setExceptionJson(-1, "插入患者本次就诊用的参保信息,请联系管理员!", outParam).ToString();
  317. return rtnResult;
  318. }
  319. }
  320. //插入医保平台
  321. if (mIS.saveInpatRegisterInfo(joRegIn_plain, joRegOut, out outParam) != 0)
  322. {
  323. rtnResult = JsonHelper.setExceptionJson(-1, "云平台保存登记信息", outParam).ToString();
  324. return rtnResult;
  325. }
  326. //返回登记信息,插入HIS
  327. if (hIS.returnRegisterInfo(joRegIn_plain, joRegOut, out outParam) != 0)
  328. {
  329. rtnResult = JsonHelper.setExceptionJson(-1, "HIS平台保存登记信息", outParam).ToString();
  330. return rtnResult;
  331. }
  332. else
  333. {
  334. rtnResult = JsonHelper.setIrisReturnValue(0, "登记成功", null).ToString();
  335. return rtnResult;
  336. }
  337. }
  338. else
  339. {
  340. rtnResult = JsonHelper.setExceptionJson(-1, "展示登记界面", errMsg).ToString();
  341. return rtnResult;
  342. }
  343. }
  344. else
  345. {
  346. rtnResult = JsonHelper.setExceptionJson(-1, "展示登记界面", regInParam).ToString();
  347. return rtnResult;
  348. }
  349. }
  350. case "Z2C"://入院登记取消
  351. {
  352. //if (DialogResult.Yes == MessageBox.Show("即将进行取消中心医保登记,确定继续吗?", " 询问? ", MessageBoxButtons.YesNo))
  353. //{
  354. //}
  355. //else
  356. //{
  357. // rtnResult = JsonHelper.setExceptionJson(-1, "收费员撤销取消登记操作!", outParam).ToString();
  358. // return rtnResult;
  359. //}
  360. //取消中心登记
  361. if (cBus.cancleRegister("2404", out outParam) != 0)
  362. {
  363. //如果医保中心没有HIS所传的医保登记信息则默认撤销HIS登记信息
  364. int i = outParam.IndexOf("不存在有效的就诊登记信息");
  365. if (i != 0)
  366. {
  367. if (DialogResult.Yes != MessageBox.Show("医保中心提示:" + outParam + ",是否强制撤销HIS医保登记信息?", "提示", MessageBoxButtons.YesNo))
  368. {
  369. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记失败,", outParam).ToString();
  370. return rtnResult;
  371. }
  372. }
  373. else
  374. {
  375. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记失败,", outParam).ToString();
  376. return rtnResult;
  377. }
  378. }
  379. //取消医保平台登记
  380. if (mIS.cancleRegister(1, out outParam) != 0)
  381. {
  382. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记成功,但云医保平台取消失败,", outParam).ToString();
  383. return rtnResult;
  384. }
  385. //取消HIS 登记
  386. if (hIS.cancleRegister( out outParam) != 0)
  387. {
  388. rtnResult = JsonHelper.setExceptionJson(-1, "中心和云医保平台取消登记成功,但HIS取消失败,", outParam).ToString();
  389. return rtnResult;
  390. }
  391. else
  392. {
  393. //CM 20230602 删除医保平台医保费用明细上传表数据
  394. mIS.deleteFee(out errMsg);
  395. rtnResult = JsonHelper.setIrisReturnValue(0, "取消医保登记成功", null).ToString();
  396. return rtnResult;
  397. }
  398. }
  399. case "Z6"://出院登记
  400. {
  401. break;
  402. }
  403. case "Z6C"://出院登记取消
  404. {
  405. if (cBus.cancleRegister("2405", out errMsg) != 0)
  406. {
  407. rtnResult = JsonHelper.setExceptionJson(-1, "取消出院登记", errMsg).ToString();
  408. return rtnResult;
  409. }
  410. else
  411. {
  412. rtnResult = JsonHelper.setIrisReturnValue(0, "取消出院登记成功", null).ToString();
  413. return rtnResult;
  414. }
  415. break;
  416. }
  417. default:
  418. {
  419. rtnResult = JsonHelper.setExceptionJson(-1, "Register 交易", "传入的业务编码不对!").ToString();
  420. return rtnResult;
  421. }
  422. }
  423. }
  424. catch (Exception ex)
  425. {
  426. rtnResult = JsonHelper.setIrisReturnValue(-1, "Register 发生异常;" + ex.Message, null).ToString();
  427. return rtnResult;
  428. }
  429. finally
  430. {
  431. Global.writeLog("Register 出参:" + JsonHelper.Compress(rtnResult));
  432. }
  433. return "";
  434. }
  435. /// <summary>
  436. /// 费用上传
  437. /// </summary>
  438. /// <param name="InParam"></param>
  439. /// <returns></returns>1
  440. public string FeeUpload(string InParam)
  441. {
  442. Global.writeLog("FeeUpload 入参:" + JsonHelper.Compress(InParam));
  443. //设置返回值,错误信息
  444. int errCode;
  445. string errMsg, rtnResult = "", outParam;
  446. try
  447. {
  448. //解析入参
  449. if (parseInparam(InParam, out errMsg) != 0)
  450. {
  451. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  452. return rtnResult;
  453. }
  454. //BS架构调用方式问题,每次调用都需要重新初始化
  455. if (init(InParam, out outParam) != 0)
  456. {
  457. rtnResult = outParam;
  458. return rtnResult;
  459. }
  460. //获取pat
  461. hBus.GetFeeHisInfo(businessType, joInParam, out Global.pat);
  462. switch (businessType)
  463. {
  464. case "M3"://门诊费用上传
  465. {
  466. break;
  467. }
  468. case "M3C"://门诊费用撤销
  469. {
  470. break;
  471. }
  472. case "Z3"://入院费用上传
  473. {
  474. //从医保平台获取患者详细的医保登记信息
  475. if (mIS.queryRegisterInfo(1, out outParam) != 0)
  476. {
  477. rtnResult = JsonHelper.setExceptionJson(-1, "查询患者云平台登记信息", outParam).ToString();
  478. return rtnResult;
  479. }
  480. JObject joReg = JObject.Parse(outParam);
  481. Global.pat.medType = JsonHelper.getDestValue(joReg, "data.MedicalType");
  482. Global.pat.insuType = JsonHelper.getDestValue(joReg, "data.InsuType");
  483. //先取消中心费用传送
  484. cBus.cancleFeeUpload("2302", out errMsg);
  485. //再删除医保传送表的数据
  486. mIS.deleteFee(out errMsg);
  487. #region【住院费用上传前调用3101事前服务】
  488. //事前分析
  489. if (Global.curEvt.ext.isOpenAnalysis)
  490. {
  491. if (hBus.PreAnalysis("4", "", out errMsg) != 0)
  492. {
  493. //rtnResult = JsonHelper.setExceptionJson(-1, "事前分析", errMsg).ToString();
  494. //return rtnResult;
  495. }
  496. }
  497. #endregion
  498. //开始进行费用传送
  499. //调用HIS费用查询信息
  500. if (hIS.getHisFee(Global.pat, out outParam) != 0)
  501. {
  502. rtnResult = JsonHelper.setExceptionJson(-1, "获取HIS费用", outParam).ToString();
  503. return rtnResult;
  504. }
  505. //调用医保平台转换
  506. JObject joHisFee = JObject.Parse(outParam);
  507. if (mIS.convertHisFeeWithInsuCode(joHisFee,out outParam) != 0)
  508. {
  509. rtnResult = JsonHelper.setExceptionJson(-1, "转换HIS费用", outParam).ToString();
  510. return rtnResult;
  511. }
  512. JArray jaFeeDetail = JArray.Parse(JsonHelper.getDestValue(JObject.Parse(outParam), "data"));
  513. //按指定条数分割后上传,保存,更新
  514. if (hBus.uploadFeeToCenter("2301",10, jaFeeDetail, out outParam) != 0)
  515. {
  516. rtnResult = JsonHelper.setExceptionJson(-1, "上传费用", outParam).ToString();
  517. return rtnResult;
  518. }
  519. else
  520. {
  521. rtnResult = JsonHelper.setIrisReturnValue(0, "住院费用上传成功", null).ToString();
  522. return rtnResult;
  523. }
  524. }
  525. case "Z3C"://住院费用上传取消
  526. {
  527. if (cBus.cancleFeeUpload("2302", out errMsg) != 0)
  528. {
  529. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心费用", errMsg).ToString();
  530. return rtnResult;
  531. }
  532. if (mIS.deleteFee( out errMsg) != 0)
  533. {
  534. rtnResult = JsonHelper.setExceptionJson(-1, "删除医保平台费用", errMsg).ToString();
  535. return rtnResult;
  536. }
  537. else
  538. {
  539. rtnResult = JsonHelper.setIrisReturnValue(0, "住院费用上传取消成功", null).ToString();
  540. return rtnResult;
  541. }
  542. }
  543. default:
  544. {
  545. rtnResult = JsonHelper.setExceptionJson(-1, "FeeUpload 交易", "传入的业务编码不对!").ToString();
  546. return rtnResult;
  547. }
  548. }
  549. return rtnResult;
  550. }
  551. catch (Exception ex)
  552. {
  553. rtnResult = JsonHelper.setExceptionJson(-1, "FeeUpload 交易", ex.Message).ToString();
  554. return rtnResult;
  555. }
  556. finally
  557. {
  558. Global.writeLog("FeeUpload 出参:" + JsonHelper.Compress(rtnResult));
  559. }
  560. }
  561. /// <summary>
  562. /// 结算
  563. /// </summary>
  564. /// <param name="InParam"></param>
  565. /// <returns></returns>
  566. public string Settlement(string InParam)
  567. {
  568. Global.writeLog("Settlement 入参:" + JsonHelper.Compress(InParam));
  569. //设置返回值,错误信息
  570. string errMsg, rtnResult = "", outParam;
  571. try
  572. {
  573. //解析入参
  574. if (parseInparam(InParam, out errMsg) != 0)
  575. {
  576. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  577. return rtnResult;
  578. }
  579. //BS架构调用方式问题,每次调用都需要重新初始化
  580. if (init(InParam, out outParam) != 0)
  581. {
  582. rtnResult = outParam;
  583. return rtnResult;
  584. }
  585. //获取pat
  586. hBus.GetSettlementHisInfo(businessType, joInParam, out Global.pat);
  587. switch (businessType)
  588. {
  589. case "M4"://门诊预结算
  590. {
  591. OutpatientRegistration frmReg = new OutpatientRegistration();
  592. if (frmReg.ShowDialog() == DialogResult.OK)
  593. {
  594. rtnResult = "调用结束";
  595. }
  596. break;
  597. }
  598. case "M4C"://门诊预结算撤销
  599. {
  600. break;
  601. }
  602. case "M5"://门诊结算
  603. {
  604. string patInfo ="";
  605. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  606. if (hBus.readCard(out outParam) != 0)
  607. {
  608. rtnResult = JsonHelper.setExceptionJson(-100, "读卡失败!", outParam).ToString();
  609. return rtnResult;
  610. }
  611. else
  612. {
  613. patInfo = outParam;
  614. //展示患者信息界面
  615. if (hBus.convertPatientInfo(patInfo, out outParam) != 0)
  616. {
  617. rtnResult = outParam;
  618. return rtnResult;
  619. }
  620. }
  621. //患者信息赋值给全局变量
  622. patInfo = outParam;
  623. if (hBus.setGlobalPatAfaterShowPatInfo(patInfo, out errMsg) != 0)
  624. {
  625. rtnResult = JsonHelper.setExceptionJson(-1, "setGlobalPatAfaterShowPatInfo", errMsg).ToString();
  626. return rtnResult;
  627. }
  628. //校验HIS姓名与医保姓名是否一致
  629. if (hBus.checkName(Global.pat.name, out errMsg) != 0)
  630. {
  631. rtnResult = JsonHelper.setExceptionJson(-1, "校验HIS与医保姓名是否一致", errMsg).ToString();
  632. return rtnResult;
  633. }
  634. //显示登记面板
  635. if (hBus.showOutPatRegisterForm(out outParam) != 0)
  636. {
  637. rtnResult = JsonHelper.setExceptionJson(-1, "显示登记面板", outParam).ToString();
  638. return rtnResult;
  639. }
  640. JObject joReg = JObject.Parse(outParam);
  641. //医保挂号
  642. JObject jo2201Inpar = JObject.Parse(JsonHelper.getDestProperty(joReg, "data"));
  643. JObject jo2201Inpar_plain = JObject.Parse(JsonHelper.getDestProperty(joReg, "data"));
  644. jo2201Inpar = JObject.Parse(JsonHelper.setCenterInpar("2201", jo2201Inpar));
  645. jo2201Inpar_plain = JObject.Parse(JsonHelper.setCenterInpar_plain("2201", jo2201Inpar_plain));
  646. //此处先取到就诊信息上传的入参,只要挂号成功就保存到云HIS后台(保存后台需要用到2203入参)
  647. JObject jo2203Inpar = new JObject();
  648. JObject jo2203Inpar_plain = new JObject();
  649. jo2203Inpar.Add("mdtrtinfo", JObject.Parse(JsonHelper.getDestValue(joReg, "mdtrtinfo")));
  650. jo2203Inpar.Add("diseinfo",JArray.Parse(JsonHelper.getDestValue(joReg, "diseinfo")));
  651. JObject jo2201Rtn = invoker.invokeCenterService("2201", jo2201Inpar);
  652. if (JsonHelper.parseCenterRtnValue(jo2201Rtn, out errMsg) != 0)
  653. {
  654. rtnResult = JsonHelper.setExceptionJson(-1, "医保挂号", errMsg).ToString();
  655. return rtnResult;
  656. }
  657. else
  658. {
  659. Global.pat.mdtrtID = JsonHelper.getDestValue(jo2201Rtn, "output.data.mdtrt_id");
  660. //插入患者本次就诊用的参保信息
  661. if (hBus.insertPatCurInsuInfo(patInfo, out outParam) != 0)
  662. {
  663. if (DialogResult.Yes != MessageBox.Show(outParam, " 是否继续? ", MessageBoxButtons.YesNo))
  664. {
  665. rtnResult = JsonHelper.setExceptionJson(-1, "插入患者本次就诊用的参保信息,请联系管理员!是否继续?", outParam).ToString();
  666. return rtnResult;
  667. }
  668. }
  669. jo2203Inpar["mdtrtinfo"]["mdtrt_id"] = Global.pat.mdtrtID;
  670. jo2203Inpar_plain = JObject.Parse(JsonHelper.setCenterInpar_plain("2203", jo2203Inpar));
  671. jo2203Inpar = JObject.Parse(JsonHelper.setCenterInpar("2203", jo2203Inpar));
  672. //门诊登记信息,插入云医保平台
  673. jo2201Rtn.Add("validflag", 1);
  674. jo2201Rtn.Add("regstate", 1);
  675. jo2201Rtn.Add("type", 3);
  676. if (mIS.saveOutpatRegisterInfo(jo2201Inpar_plain, jo2201Rtn, jo2203Inpar_plain, out errMsg) != 0)
  677. {
  678. rtnResult = JsonHelper.setExceptionJson(-1, "中心登记成功但医保平台保存失败,请联系管理员!", errMsg).ToString();
  679. return rtnResult;
  680. }
  681. }
  682. //门诊就诊信息上传
  683. JObject jo2203Rtn = invoker.invokeCenterService("2203",jo2203Inpar );
  684. if (JsonHelper.parseCenterRtnValue(jo2203Rtn, out errMsg) != 0)
  685. {
  686. rtnResult = JsonHelper.setExceptionJson(-1, "门诊就诊信息上传", errMsg).ToString();
  687. return rtnResult;
  688. }
  689. #region【门诊就诊信息上传成功后调用3101事前服务】
  690. //事前分析
  691. //1.门诊挂号 2.门诊收费登记 3.住院登记 4.住院收费登记 5.住院执行医嘱 6.门诊结算 7.门诊预结算 8.住院结算 9.住院预结算 10.购药划卡
  692. if (Global.curEvt.ext.isOpenAnalysis)
  693. {
  694. if (hBus.PreAnalysis("2", "", out errMsg) != 0)
  695. {
  696. //调用失败后仍继续往下执行-朱鹏飞要求
  697. outParam = outParam + "门诊就诊信息上传成功后调用3101事前服务失败:" + errMsg;
  698. //return Error("门诊就诊信息上传成功后调用3101事前服务失败:" + errMsg);
  699. }
  700. }
  701. #endregion
  702. //费用上传
  703. if (hBus.uploadFee("2204", 50, out outParam) != 0)
  704. {
  705. rtnResult = JsonHelper.setExceptionJson(-1, "费用上传", outParam).ToString();
  706. return rtnResult;
  707. }
  708. #region【门诊预结算2206前调用3102医保明细审核事中服务】
  709. #endregion
  710. //调用IRIS获取医保各项金额
  711. if (mIS.getSumFee(out outParam) != 0)
  712. {
  713. rtnResult = JsonHelper.setExceptionJson(-1, "获取医保费用各项汇总金额", outParam).ToString();
  714. return rtnResult;
  715. }
  716. JObject joSumFee = JObject.Parse(outParam);
  717. JObject joSettlement = JObject.Parse(JsonHelper.getDestValue(joReg, "settlement"));
  718. //修改joSettlement的就诊ID ,总金额等
  719. joSettlement["mdtrt_id"] = Global.pat.mdtrtID;
  720. joSettlement["medfee_sumamt"] = JsonHelper.getDestValue(joSumFee, "data.Sumamt");
  721. //预结算2206
  722. if (hBus.preSettlement_OutPat(joSettlement, out outParam) != 0)
  723. {
  724. rtnResult = JsonHelper.setExceptionJson(-1, "结算信息展示", outParam).ToString();
  725. return rtnResult;
  726. }
  727. #region【门诊正式结算前调用1192身份验证】
  728. if (hBus.IdentityVerify("2207", out errMsg) != 0)
  729. {
  730. rtnResult = JsonHelper.setExceptionJson(-1, "调用门诊正式结算2207前,身份核验1192失败", errMsg).ToString();
  731. return rtnResult;
  732. }
  733. else
  734. {
  735. JObject joDataExp = new JObject();
  736. joDataExp.Add("cardtoken", Global.pat.card.Cardtoken);
  737. joDataExp.Add("acct_payamt", Global.Set.acctPay);
  738. joDataExp.Add("elec_bill_code", "");
  739. joDataExp.Add("elec_billno_code", "");
  740. joDataExp.Add("elec_bill_chkcode", "");
  741. joSettlement["exp_content"] = joDataExp;
  742. }
  743. #endregion
  744. //正式结算
  745. JObject joData = new JObject();
  746. joData.Add("data",joSettlement);
  747. JObject joRtn = invoker.invokeCenterService("2207", JsonHelper.setCenterInpar("2207", joData));
  748. if (JsonHelper.parseCenterRtnValue(joRtn, out errMsg) != 0)
  749. {
  750. rtnResult = JsonHelper.setExceptionJson(-1, "结算失败", errMsg).ToString();
  751. return rtnResult;
  752. }
  753. else
  754. {
  755. Global.pat.admType = 1;
  756. Global.pat.ExpContent = ""; //门诊不需要保存 外伤标志等相关扩展参数
  757. //返回给云医保平台结算信息
  758. if (mIS.saveSettlement(joRtn, out errMsg) != 0)
  759. {
  760. rtnResult = JsonHelper.setExceptionJson(-1, "结算成功,但云医保平台保存失败", errMsg).ToString();
  761. return rtnResult;
  762. }
  763. //返回给云医保平台结算明细信息
  764. if (mIS.saveSettlementDetail(joRtn, out errMsg) != 0)
  765. {
  766. rtnResult = JsonHelper.setExceptionJson(-1, "云医保平台保存结算明细失败", errMsg).ToString();
  767. return rtnResult;
  768. }
  769. //返回给HIS
  770. JObject joSetlinfo = JObject.Parse(JsonHelper.getDestValue(joRtn, "output.setlinfo"));
  771. if (hIS.returnOutpatSettlementInfo(joSettlement, joSetlinfo, out outParam) != 0)
  772. {
  773. rtnResult = JsonHelper.setExceptionJson(-1, "返回结算信息给HIS", outParam).ToString();
  774. return rtnResult;
  775. }
  776. else
  777. {
  778. JObject joHisServieRtn = JObject.Parse(outParam);
  779. hBus.returnToFrontEndAfterSettlement(joRtn, joHisServieRtn, out outParam);
  780. rtnResult = JsonHelper.setIrisReturnValue(0, "结算成功", JObject.Parse(outParam)).ToString();
  781. return rtnResult;
  782. }
  783. }
  784. }
  785. case "M5C"://门诊结算撤销
  786. {
  787. //查询HIS医保结算记录表获取该病人的参保地
  788. string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE billType = 1 and ValidFlag = 1 ";
  789. sqlStr = sqlStr + " AND Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr;
  790. sqlStr = sqlStr + " AND SettlementID ='" + Global.pat.settlID + "'";
  791. JObject joSql = new JObject();
  792. joSql.Add("sqlStr", sqlStr);
  793. JObject joSettlInfo = mIS.QuerySettlementInfo(joSql);
  794. //if (JsonHelper.parseIrisRtnValue(joSettlInfo, out errMsg) != 0)
  795. //{
  796. // rtnResult = JsonHelper.setExceptionJson(-1, "查询结算信息失败!", errMsg).ToString();
  797. // return rtnResult;
  798. //}
  799. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  800. //退中心结算
  801. string newSettleID = "";
  802. if (cBus.cancleSettlement("2208", out outParam) != 0)
  803. {
  804. int i = outParam.IndexOf("获取到的就诊信息为无效状态,不能办理结算撤销业务");
  805. if (i != 0)
  806. {
  807. if (DialogResult.Yes != MessageBox.Show("医保中心提示:" + outParam + ",是否强制撤销HIS结算信息?", "提示", MessageBoxButtons.YesNo))
  808. {
  809. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消结算失败,", outParam).ToString();
  810. return rtnResult;
  811. }
  812. newSettleID = "YC";
  813. }
  814. else
  815. {
  816. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算", outParam).ToString();
  817. //查看是医保平台是否已经退费,如果是,则询问是否继续退费
  818. string SqlStr = " SELECT * FROM BS_MedInsuSettlement WHERE ValidFlag = 0 AND BillType = -1 ";
  819. SqlStr = SqlStr + " AND Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr;
  820. SqlStr = SqlStr + " AND SettlementID ='" + Global.pat.settlID + "'";
  821. JObject joSqlStr = new JObject();
  822. joSqlStr.Add("sqlStr", SqlStr);
  823. JObject joCancleSettlInfo = mIS.QuerySettlementInfo(joSqlStr);
  824. JArray jaCancleSettlInfo = JArray.Parse(JsonHelper.getDestValue(joCancleSettlInfo, "result.data"));
  825. if (jaCancleSettlInfo.Count == 1)
  826. {
  827. //询问收款员是否继续进行HIS退费
  828. if (DialogResult.Yes == MessageBox.Show("中心提示:" + outParam, " 该费用在医保中心已成功退费但在HIS未成功退费,是否强制退HIS费用? ", MessageBoxButtons.YesNo))
  829. {
  830. rtnResult = JsonHelper.setExceptionJson(0, "该费用在医保中心已成功退费但在HIS未成功退费,收款员选择强制退HIS费用!", outParam).ToString();
  831. }
  832. }
  833. else
  834. {
  835. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算(云医保平台未退费或未查询到退费记录)", outParam).ToString();
  836. }
  837. return rtnResult;
  838. }
  839. }
  840. else
  841. {
  842. newSettleID = JsonHelper.getDestValue(JObject.Parse(outParam), "output.setlinfo.setl_id");
  843. }
  844. //string newSettleID = "10290453";
  845. //Global.pat.mdtrtID = "202210281547480034293700000000";
  846. //Global.pat.psn_no = "YX423049577";
  847. //Global.pat.settlID = "10290445";
  848. //退云医保平台结算
  849. if (mIS.cancleSettlement(newSettleID, out outParam) != 0)
  850. {
  851. rtnResult = JsonHelper.setExceptionJson(-1, "取消平台结算信息", outParam).ToString();
  852. //return rtnResult;
  853. }
  854. //中心取消传送
  855. if (cBus.cancleFeeUpload("2205", out errMsg) != 0)
  856. {
  857. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心费用", errMsg).ToString();
  858. return rtnResult;
  859. }
  860. //云平台取消传送
  861. if (mIS.deleteFee(out errMsg) != 0)
  862. {
  863. rtnResult = JsonHelper.setExceptionJson(-1, "删除医保平台费用", errMsg).ToString();
  864. return rtnResult;
  865. }
  866. //取消中心登记
  867. if (cBus.cancleRegister("2202", out outParam) != 0)
  868. {
  869. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记失败,", outParam).ToString();
  870. return rtnResult;
  871. }
  872. //取消医保平台登记
  873. if (mIS.cancleRegister(3, out outParam) != 0)
  874. {
  875. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记成功,但云医保平台取消失败,", outParam).ToString();
  876. return rtnResult;
  877. }
  878. //退HIS结算
  879. if (hIS.cancleSettlementInfo(joParam, out outParam) != 0)
  880. {
  881. rtnResult = JsonHelper.setExceptionJson(-1, "取消HIS结算信息", outParam).ToString();
  882. return rtnResult;
  883. }
  884. else
  885. {
  886. rtnResult = JsonHelper.setIrisReturnValue(0, "取消结算成功", null).ToString();
  887. return rtnResult;
  888. }
  889. }
  890. case "M6"://门诊移动支付结算
  891. {
  892. MobilePay mp = new MobilePay(InParam, out errMsg);
  893. if (errMsg != "")
  894. {
  895. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  896. return rtnResult;
  897. }
  898. if (mp.MobilePaySettlement(out outParam) != 0)
  899. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
  900. else
  901. rtnResult = outParam;
  902. return rtnResult;
  903. }
  904. case "M6C"://门诊移动支付结算撤销
  905. {
  906. string onlineYBFalg = JsonHelper.getDestValue(joInsuAdmObj, "onlineYBFalg");
  907. MobilePay mp = new MobilePay(InParam, out errMsg);
  908. if (errMsg != "")
  909. {
  910. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  911. return rtnResult;
  912. }
  913. if (String.IsNullOrEmpty(onlineYBFalg))
  914. mp.MSettl.onlineYBFalg = "N";
  915. else
  916. mp.MSettl.onlineYBFalg = onlineYBFalg;
  917. if (mp.MobilePayCancelSettlement(out outParam) != 0)
  918. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
  919. else
  920. rtnResult = JsonHelper.setExceptionJson(0, "Settlement 交易", outParam).ToString();
  921. return rtnResult;
  922. }
  923. case "M6Confirm"://门诊移动支付确认
  924. {
  925. MobilePay mp = new MobilePay(InParam, out errMsg);
  926. if (errMsg != "")
  927. {
  928. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  929. return rtnResult;
  930. }
  931. if (mp.MobilePayConfirmSettlement(out outParam) != 0)
  932. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
  933. else
  934. rtnResult = outParam;
  935. return rtnResult;
  936. }
  937. case "M6Q":
  938. {
  939. MobilePay mp = new MobilePay(InParam, out errMsg);
  940. if (errMsg != "")
  941. {
  942. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  943. return rtnResult;
  944. }
  945. mp.MobilePayQuery(out outParam);
  946. return outParam;
  947. }
  948. case "Z4"://住院预结算
  949. {
  950. #region【住院预结算2303前调用3102医保明细审核事中服务】
  951. #endregion
  952. Global.pat.RYorCY = "2";
  953. JObject joSettle = new JObject();
  954. if (hBus.preSettlement("2303",out joSettle, out outParam) != 0)
  955. {
  956. rtnResult = JsonHelper.setExceptionJson(-1, "结算信息展示", outParam).ToString();
  957. return rtnResult;
  958. }
  959. else
  960. {
  961. rtnResult = JsonHelper.setIrisReturnValue(0, "预结算成功", null).ToString();
  962. return rtnResult;
  963. }
  964. }
  965. case "Z4C"://住院预结算撤销
  966. {
  967. rtnResult = JsonHelper.setExceptionJson(-100, "该接口不支持预结算取消!", null).ToString();
  968. return rtnResult;
  969. }
  970. case "Z5"://住院结算
  971. {
  972. #region【住院预结算2303前调用3102医保明细审核事中服务】
  973. #endregion
  974. Global.pat.RYorCY = "2";
  975. JObject joPreSetOutpar ;
  976. if (hBus.preSettlement("2303",out joPreSetOutpar, out outParam) != 0)
  977. {
  978. rtnResult = JsonHelper.setExceptionJson(-1, "结算信息展示", outParam).ToString();
  979. return rtnResult;
  980. }
  981. else
  982. {
  983. JObject joSettlement = joSettlement = JObject.Parse(JsonHelper.getDestValue(joPreSetOutpar, "Settlement"));
  984. JObject joDataExp = new JObject();
  985. joDataExp.Add("cardtoken", Global.pat.card.Cardtoken);
  986. joDataExp.Add("acct_payamt", Global.Set.acctPay);
  987. joDataExp.Add("elec_bill_code", "");
  988. joDataExp.Add("elec_billno_code", "");
  989. joDataExp.Add("elec_bill_chkcode", "");
  990. joSettlement["exp_content"] = joDataExp;
  991. //正式结算
  992. joSettlement.Add("data", joSettlement);
  993. JObject jo2304Rtn = invoker.invokeCenterService("2304",JsonHelper.setCenterInpar("2304",joSettlement));
  994. if (JsonHelper.parseCenterRtnValue(jo2304Rtn, out errMsg) != 0)
  995. {
  996. rtnResult = JsonHelper.setExceptionJson(-1, "结算失败", errMsg).ToString();
  997. cBus.cancleRegister("2405", out errMsg);
  998. return rtnResult;
  999. }
  1000. else
  1001. {
  1002. Global.pat.admType = 2;
  1003. //返回给云医保平台结算信息
  1004. if (mIS.saveSettlement(jo2304Rtn, out errMsg) != 0)
  1005. {
  1006. rtnResult = JsonHelper.setExceptionJson(-1, "结算成功,但云医保平台保存失败", errMsg).ToString();
  1007. return rtnResult;
  1008. }
  1009. //返回给云医保平台结算明细信息
  1010. if (mIS.saveSettlementDetail(jo2304Rtn, out errMsg) != 0)
  1011. {
  1012. rtnResult = JsonHelper.setExceptionJson(-1, "云医保平台保存结算明细失败", errMsg).ToString();
  1013. Global.writeLog(rtnResult);
  1014. MessageBox.Show(errMsg);
  1015. }
  1016. //返回给HIS
  1017. JObject joSetlinfo = JObject.Parse(JsonHelper.getDestValue(jo2304Rtn, "output.setlinfo"));
  1018. if (hIS.returnInpatSettlementInfo(joParam, joSetlinfo, out outParam) != 0)
  1019. {
  1020. rtnResult = JsonHelper.setExceptionJson(-1, "返回结算信息给HIS", outParam).ToString();
  1021. return rtnResult;
  1022. }
  1023. else
  1024. {
  1025. //返回给前端
  1026. JObject joHisServieRtn = JObject.Parse(outParam);
  1027. hBus.returnToFrontEndAfterSettlement(jo2304Rtn, joHisServieRtn, out outParam);
  1028. rtnResult = JsonHelper.setIrisReturnValue(0, "结算成功", JObject.Parse(outParam)).ToString();
  1029. return rtnResult;
  1030. }
  1031. }
  1032. }
  1033. }
  1034. case "Z5C"://住院结算撤销
  1035. {
  1036. //查询结算表
  1037. string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE billType = 1 and Hospital_Dr=" + Global.inf.hospitalDr
  1038. + " and Adm_Dr='" + Global.pat.adm_Dr + "'"
  1039. + " and MdtrtID='" + Global.pat.mdtrtID + "'"
  1040. + " Order By ID DESC ";
  1041. JObject joSql = new JObject();
  1042. joSql.Add("sqlStr", sqlStr);
  1043. JObject joSettlInfo = mIS.QuerySettlementInfo(joSql);
  1044. //if (JsonHelper.parseIrisRtnValue(joSettlInfo, out errMsg) != 0)
  1045. //{
  1046. // rtnResult = JsonHelper.setExceptionJson(-1, "查询结算信息失败!", errMsg).ToString();
  1047. // return rtnResult;
  1048. //}
  1049. //MessageBox.Show(joSettlInfo.ToString());
  1050. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  1051. Global.pat.SettID_YBJSB = JsonHelper.getDestValue(joSettlInfo, "result.data[0].SettlementID");
  1052. if (Global.pat.settlID != Global.pat.SettID_YBJSB)
  1053. {
  1054. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", "通过09010059服务获取到的SettlementID<" + Global.pat.settlID + ">与DLL通过SQL语句" +
  1055. joSql + ",获取到的SettlementID<" + Global.pat.SettID_YBJSB + ">不同,可能存在HIS单边账,请联系医保开发人员处理该笔结算记录!").ToString();
  1056. //return rtnResult;
  1057. }
  1058. Global.pat.settlID = Global.pat.SettID_YBJSB;
  1059. //取消中心结算信息
  1060. if (cBus.cancleSettlement("2305", out outParam) != 0)
  1061. {
  1062. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算信息失败!", outParam).ToString();
  1063. //查看是医保平台是否已经退费,如果是,则询问是否继续退费
  1064. string SqlStr = " SELECT * FROM BS_MedInsuSettlement WHERE ValidFlag = 0 AND BillType = -1 ";
  1065. SqlStr = SqlStr + " AND Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr;
  1066. SqlStr = SqlStr + " AND SettlementID ='" + Global.pat.settlID + "'";
  1067. JObject joSqlStr = new JObject();
  1068. joSqlStr.Add("sqlStr", SqlStr);
  1069. JObject joCancleSettlInfo = mIS.QuerySettlementInfo(joSqlStr);
  1070. JArray jaCancleSettlInfo = JArray.Parse(JsonHelper.getDestValue(joCancleSettlInfo, "result.data"));
  1071. if (jaCancleSettlInfo.Count == 1)
  1072. {
  1073. //询问收款员是否继续进行HIS退费
  1074. if (DialogResult.Yes == MessageBox.Show("中心提示:" + outParam, " 该费用在医保中心已成功退费但在HIS未成功退费,是否强制退HIS费用? ", MessageBoxButtons.YesNo))
  1075. {
  1076. rtnResult = JsonHelper.setExceptionJson(0, "该费用在医保中心已成功退费但在HIS未成功退费,收款员选择强制退HIS费用!", outParam).ToString();
  1077. }
  1078. }
  1079. else
  1080. {
  1081. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算(云医保平台未退费或未查询到退费记录)", outParam).ToString();
  1082. }
  1083. return rtnResult;
  1084. }
  1085. else
  1086. {
  1087. //退结算会返一个新的ID
  1088. string newSettleID = JsonHelper.getDestValue(JObject.Parse(outParam), "output.setlinfo.setl_id");
  1089. //取消平台结算信息
  1090. if (mIS.cancleSettlement(newSettleID, out outParam) != 0)
  1091. {
  1092. rtnResult = JsonHelper.setExceptionJson(-1, "中心结算取消成功,医保平台结算信息取消失败!", outParam).ToString();
  1093. return rtnResult;
  1094. }
  1095. //中心取消传送
  1096. if (cBus.cancleFeeUpload("2302", out errMsg) != 0)
  1097. {
  1098. //rtnResult = JsonHelper.setExceptionJson(-1, "取消中心费用", errMsg).ToString();
  1099. //return rtnResult;
  1100. }
  1101. //云平台取消传送
  1102. if (mIS.deleteFee(out errMsg) != 0)
  1103. {
  1104. //rtnResult = JsonHelper.setExceptionJson(-1, "删除医保平台费用", errMsg).ToString();
  1105. //return rtnResult;
  1106. }
  1107. //取消HIS医保结算信息
  1108. if (hIS.cancleSettlementInfo(joParam, out outParam) != 0)
  1109. {
  1110. rtnResult = JsonHelper.setExceptionJson(-1, "中心跟医保平台结算取消成功, 取消HIS结算信息失败!", outParam).ToString();
  1111. return rtnResult;
  1112. }
  1113. //取消出院登记
  1114. if (cBus.cancleRegister("2405", out outParam) != 0)
  1115. {
  1116. rtnResult = JsonHelper.setExceptionJson(0, "中心,医保平台及HIS结算信息取消成功,取消出院登记失败!请手工取消出院登记!", outParam).ToString();
  1117. return rtnResult;
  1118. }
  1119. rtnResult = JsonHelper.setIrisReturnValue(0, "取消结算成功", null).ToString();
  1120. return rtnResult;
  1121. }
  1122. }
  1123. default:
  1124. {
  1125. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", "传入的业务编码不对!").ToString();
  1126. return rtnResult;
  1127. }
  1128. }
  1129. return rtnResult;
  1130. }
  1131. catch (Exception ex)
  1132. {
  1133. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", ex.Message).ToString();
  1134. return rtnResult;
  1135. }
  1136. finally
  1137. {
  1138. Global.writeLog("Settlement 出参:" + JsonHelper.Compress(rtnResult));
  1139. }
  1140. }
  1141. /// <summary>
  1142. /// 自助机
  1143. /// </summary>
  1144. /// <param name="InParam"></param>
  1145. /// <returns></returns>
  1146. public string SelfServiceMachine(string InParam)
  1147. {
  1148. Global.writeLog("SelfServiceMachine 入参:" + JsonHelper.Compress(InParam));
  1149. //设置返回值,错误信息
  1150. string errMsg, rtnResult = "", outParam;
  1151. try
  1152. {
  1153. //解析入参
  1154. if (parseInparam(InParam, out errMsg) != 0)
  1155. {
  1156. rtnResult = JsonHelper.setExceptionJson(-1, "parseInparam", errMsg).ToString();
  1157. return rtnResult;
  1158. }
  1159. //获取pat
  1160. hBus.GetSelfServiceMachineInfo(businessType, joInParam, out Global.pat);
  1161. //BS架构调用方式问题,每次调用都需要重新初始化
  1162. if (init(InParam, out errMsg) != 0)
  1163. //if (hBus.InitA(InParam, out errMsg) != 0)
  1164. {
  1165. rtnResult = JsonHelper.setExceptionJson(-1, "InitA", errMsg).ToString(); ;
  1166. return rtnResult;
  1167. }
  1168. else
  1169. {
  1170. //joInParam.Add("patInfo", errMsg);
  1171. Global.writeLog($"InitA初始化成功!");
  1172. }
  1173. switch (businessType)
  1174. {
  1175. case "GetPatientInfo"://读取患者信息,该节点无需重定向
  1176. {
  1177. //重定向
  1178. Business.Core.SelfServiceMachine.PatientService patientService = new Business.Core.SelfServiceMachine.PatientService();
  1179. rtnResult = patientService.GetPatientInfo();
  1180. break;
  1181. }
  1182. case "OPReg"://门诊挂号
  1183. {
  1184. #region 链条式任务调度者
  1185. OPRegService service = new OPRegService();
  1186. rtnResult = service.Charge(Global.Set.operationType.ToString(), joInParam);
  1187. break;
  1188. #endregion
  1189. }
  1190. case "OPSettl"://门诊结算
  1191. {
  1192. OPSettlementService service = new OPSettlementService();
  1193. rtnResult = service.Charge(Global.Set.operationType.ToString(), joInParam);
  1194. break;
  1195. }
  1196. case "IPInReg"://入院登记
  1197. {
  1198. IPAdmRegService service = new IPAdmRegService();
  1199. rtnResult = service.Register(Global.Set.operationType.ToString(), joInParam);
  1200. break;
  1201. }
  1202. case "IPInRegCancel"://取消入院登记
  1203. {
  1204. IPAdmRegService service = new IPAdmRegService();
  1205. rtnResult = service.CancelRegister(Global.Set.operationType.ToString(), joInParam);
  1206. break;
  1207. }
  1208. case "IPOutReg"://出院登记
  1209. {
  1210. break;
  1211. }
  1212. case "IPUpoload"://住院费用上传
  1213. {
  1214. break;
  1215. }
  1216. case "IPPreSettl"://住院预计结算
  1217. {
  1218. break;
  1219. }
  1220. case "IPSettl"://住院结算
  1221. {
  1222. IPSettlementService service = new IPSettlementService();
  1223. rtnResult = service.Charge(joInParam);
  1224. return rtnResult;
  1225. }
  1226. case "DischargeAudit"://费用核查
  1227. {
  1228. DischargeAuditService service = new DischargeAuditService();
  1229. rtnResult = service.Audit(joInParam);
  1230. return rtnResult;
  1231. }
  1232. default:
  1233. {
  1234. rtnResult = JsonHelper.setExceptionJson(-1, "SelfServiceMachine 交易", "传入的业务编码不对!").ToString();
  1235. return rtnResult;
  1236. }
  1237. }
  1238. return rtnResult;
  1239. }
  1240. catch (Exception ex)
  1241. {
  1242. rtnResult = JsonHelper.setExceptionJson(-1, "SelfServiceMachine 交易", ex.Message).ToString();
  1243. return rtnResult;
  1244. }
  1245. finally
  1246. {
  1247. Global.writeLog("SelfServiceMachine 出参:" + JsonHelper.Compress(rtnResult));
  1248. }
  1249. }
  1250. //[STAThread]
  1251. //public void print(JObject joInParam)
  1252. //{
  1253. // //显示打印界面
  1254. // SettlementChecklist frmSettlList;
  1255. // string insuAdmObj = JsonHelper.getDestValue(joInParam, "insuAdmObj");
  1256. // if (insuAdmObj == "")
  1257. // {
  1258. // frmSettlList = new SettlementChecklist();
  1259. // }
  1260. // else
  1261. // {
  1262. // JObject joInsuAdmObj = JObject.Parse(insuAdmObj);
  1263. // frmSettlList = new SettlementChecklist(joInsuAdmObj);
  1264. // }
  1265. // if (frmSettlList.ShowDialog() == DialogResult.OK)
  1266. // {
  1267. // };
  1268. //}
  1269. //[STAThread]
  1270. /// <summary>
  1271. /// 辅助交易
  1272. /// </summary>
  1273. /// <param name="InParam"></param>
  1274. /// <returns></returns>
  1275. public string AgentFun(string InParam)
  1276. {
  1277. Global.writeLog("AgentFun 入参:" + JsonHelper.Compress(InParam));
  1278. //设置返回值,错误信息
  1279. int errCode;
  1280. string errMsg, rtnResult = "", outParam;
  1281. try
  1282. {
  1283. //解析入参
  1284. if (parseInparam(InParam, out errMsg) != 0)
  1285. {
  1286. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  1287. return rtnResult;
  1288. }
  1289. //BS架构调用方式问题,每次调用都需要重新初始化
  1290. if (init(InParam, out outParam) != 0)
  1291. {
  1292. rtnResult = outParam;
  1293. return rtnResult;
  1294. }
  1295. //获取pat
  1296. //hBus.GetFeeHisInfo(businessType, joInParam, out Global.pat);
  1297. switch (businessType)
  1298. {
  1299. case "BasicData"://基础数据维护
  1300. {
  1301. BasicData bd = new BasicData();
  1302. bd.ShowDialog();
  1303. break;
  1304. }
  1305. case "Exception"://异常处理
  1306. {
  1307. //显示异常处理界面
  1308. HandleException frmEX = new HandleException();
  1309. if (frmEX.ShowDialog() == DialogResult.OK)
  1310. {
  1311. }
  1312. break;
  1313. }
  1314. case "CheckAndClearing"://对账清算
  1315. {
  1316. //Clearing frmEX = new Clearing();
  1317. //if (frmEX.ShowDialog() == DialogResult.OK)
  1318. //{
  1319. //}
  1320. //break;
  1321. STA sta = new STA();
  1322. Thread thread = new Thread(sta.CheckAndClearing);
  1323. thread.SetApartmentState(ApartmentState.STA); //重点
  1324. thread.IsBackground = true;
  1325. thread.Start();
  1326. thread.Join();
  1327. break;
  1328. }
  1329. case "Print"://打印
  1330. {
  1331. //显示打印界面
  1332. SettlementBillPrint frmSettlList;
  1333. string insuAdmObj = JsonHelper.getDestValue(joInParam, "insuAdmObj");
  1334. if (insuAdmObj == "")
  1335. {
  1336. frmSettlList = new SettlementBillPrint();
  1337. frmSettlList.ShowDialog();
  1338. }
  1339. else
  1340. {
  1341. JObject joInsuAdmObj = JObject.Parse(insuAdmObj);
  1342. frmSettlList = new SettlementBillPrint(joInsuAdmObj);
  1343. string groupID = JsonHelper.getDestValue((JObject)Global.curEvt.jaSession[0], "groupID");
  1344. DataTable dt = (DataTable)frmSettlList.dgvSettlRecord.DataSource;
  1345. CardReader CardRead = new CardReader();
  1346. string sOutPar;
  1347. CardRead.FastReportPrint(out sOutPar);
  1348. if (JsonHelper.getDestValue(JObject.Parse(sOutPar), "code") != "0")
  1349. {
  1350. return JsonHelper.setIrisReturnValue(0, "调用FastReportDLL失败", null).ToString();
  1351. }
  1352. if (dt.Rows.Count != 1)
  1353. {
  1354. frmSettlList.ShowDialog();
  1355. }
  1356. else
  1357. {
  1358. frmSettlList.btnPrint_Click(null, null);
  1359. }
  1360. }
  1361. return JsonHelper.setIrisReturnValue(0, "", null).ToString();
  1362. break;
  1363. }
  1364. case "Log"://日志
  1365. {
  1366. MessageBox.Show(businessType);
  1367. break;
  1368. }
  1369. case "RecordUpload"://上传记录
  1370. {
  1371. MessageBox.Show(businessType);
  1372. break;
  1373. }
  1374. case "HospitalRegister"://备案
  1375. {
  1376. ToRecordChoose Referral = new ToRecordChoose();
  1377. Referral.ShowDialog();
  1378. break;
  1379. }
  1380. case "PreAndInProcessAnalysis"://事前分析 诊间只有住院的事前分析
  1381. {
  1382. Global.pat.adm_Dr = int.Parse(JsonHelper.getDestValue(joInParam, "params[0].admID"));
  1383. Global.pat.psn_no = JsonHelper.getDestValue(joInParam, "params[0].insuData.patient_dtos[0].patn_id");
  1384. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joInParam, "params[0].insuData.patient_dtos[0].poolarea");
  1385. Global.pat.insuType = JsonHelper.getDestValue(joInParam, "params[0].insuData.patient_dtos[0].fsi_encounter_dtos[0].insutype");
  1386. Global.pat.medType = JsonHelper.getDestValue(joInParam, "params[0].insuData.patient_dtos[0].fsi_encounter_dtos[0].med_type");
  1387. JObject joResult = new JObject();
  1388. joResult.Add("result", JObject.Parse(JsonHelper.getDestValue(joParam, "insuData")));
  1389. //事前分析
  1390. if (Global.curEvt.ext.isOpenAnalysis)
  1391. {
  1392. if (hBus.PreAnalysis("5", joResult.ToString(), out errMsg) != 0)
  1393. {
  1394. MessageBox.Show(errMsg);
  1395. break;
  1396. }
  1397. }
  1398. break;
  1399. }
  1400. default:
  1401. {
  1402. rtnResult = JsonHelper.setExceptionJson(-1, "AgentFun 交易", "传入的业务编码不对!").ToString();
  1403. return rtnResult;
  1404. }
  1405. }
  1406. return rtnResult;
  1407. }
  1408. catch (Exception ex)
  1409. {
  1410. rtnResult = JsonHelper.setExceptionJson(-1, "AgentFun 交易", ex.Message).ToString();
  1411. return rtnResult;
  1412. }
  1413. finally
  1414. {
  1415. Global.writeLog("AgentFun 出参:" + JsonHelper.Compress(rtnResult));
  1416. }
  1417. }
  1418. public string Download(string InParam)
  1419. {
  1420. Global.writeLog("Download 入参:" + JsonHelper.Compress(InParam));
  1421. //设置返回值,错误信息
  1422. int errCode;
  1423. string errMsg, rtnResult = "", outParam;
  1424. try
  1425. {
  1426. //解析入参
  1427. if (parseInparam(InParam, out errMsg) != 0)
  1428. {
  1429. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  1430. return rtnResult;
  1431. }
  1432. //BS架构调用方式问题,每次调用都需要重新初始化
  1433. if (init(InParam, out outParam) != 0)
  1434. {
  1435. rtnResult = outParam;
  1436. return rtnResult;
  1437. }
  1438. dynamic joData = new JObject();
  1439. joData.data = joParam["data"];
  1440. //string code = (string)joInParam["code"];
  1441. string funNO = (string)joParam["funNO"];
  1442. switch (businessType)
  1443. {
  1444. case "DirectoryDownload":
  1445. {
  1446. string downloadParam = JsonHelper.setCenterInpar(funNO, joData.ToString());
  1447. rtnResult = hBus.DownloadDirectory(funNO, downloadParam).ToString();
  1448. break;
  1449. }
  1450. case "DictionayDownload":
  1451. {
  1452. string downloadParam = JsonHelper.setCenterInpar(funNO, joData.ToString());
  1453. rtnResult = hBus.downDictionary(downloadParam);
  1454. break;
  1455. }
  1456. }
  1457. return rtnResult;
  1458. }
  1459. catch (Exception ex)
  1460. {
  1461. rtnResult = JsonHelper.setExceptionJson(-100, "Download", ex.Message).ToString();
  1462. return rtnResult;
  1463. }
  1464. finally
  1465. {
  1466. Global.writeLog("Download 出参:" + rtnResult);
  1467. }
  1468. }
  1469. public string PlatformDirectConnect(string InParam)
  1470. {
  1471. //设置返回值,错误信息
  1472. int errCode;
  1473. string errMsg, rtnResult = "", outParam;
  1474. try
  1475. {
  1476. Global.writeLog("PlatformDirectConnect 入参:" + JsonHelper.Compress(InParam));
  1477. //解析入参
  1478. if (parseInparam(InParam, out errMsg) != 0)
  1479. {
  1480. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  1481. return rtnResult;
  1482. }
  1483. Global.businessType = businessType;
  1484. string funNO = JsonHelper.getDestValue(joInParam, "funNO");
  1485. //BS架构调用方式问题,每次调用都需要重新初始化
  1486. if (init(InParam, out outParam) != 0)
  1487. {
  1488. rtnResult = outParam;
  1489. return rtnResult;
  1490. }
  1491. if (funNO=="4101Y")
  1492. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joInParam, "insuplc_admdvs");
  1493. JObject joRtn = invoker.invokeCenterService(funNO, JsonHelper.setCenterInpar(funNO, joParam));
  1494. if (JsonHelper.parseCenterRtnValue(joRtn, out errMsg) != 0)
  1495. {
  1496. rtnResult = JsonHelper.setExceptionJson(-1, "平台直连错误", errMsg).ToString();
  1497. return rtnResult;
  1498. }
  1499. else
  1500. {
  1501. rtnResult = JsonHelper.setIrisReturnValue(0, "", joRtn).ToString();
  1502. return rtnResult;
  1503. }
  1504. }
  1505. catch (Exception ex)
  1506. {
  1507. rtnResult = JsonHelper.setExceptionJson(-1, "PlatformDirectConnect 交易", ex.Message).ToString();
  1508. return rtnResult;
  1509. }
  1510. finally
  1511. {
  1512. Global.writeLog("PlatformDirectConnect 出参:" + JsonHelper.Compress(rtnResult));
  1513. }
  1514. }
  1515. }
  1516. }