InsuBusiness.cs 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using PTMedicalInsurance.Common;
  7. using PTMedicalInsurance.Business;
  8. using System.Windows.Forms;
  9. using PTMedicalInsurance.Helper;
  10. using Newtonsoft.Json.Linq;
  11. using PTMedicalInsurance.Variables;
  12. using PTMedicalInsurance.Forms;
  13. using System.IO;
  14. using System.Reflection;
  15. using System.Data;
  16. using System.Xml.Linq;
  17. using Newtonsoft.Json;
  18. using System.Xml;
  19. using System.Threading;
  20. using System.Diagnostics;
  21. using System.Runtime.InteropServices;
  22. using PTMedicalInsurance.Forms.SettlementWithNopwdApplys;
  23. namespace PTMedicalInsurance
  24. {
  25. public class InsuBusiness : IInsuBusiness
  26. {
  27. public enum ShowCommands : int
  28. {
  29. SW_HIDE = 0,
  30. SW_SHOWNORMAL = 1,
  31. SW_NORMAL = 1,
  32. SW_SHOWMINIMIZED = 2,
  33. SW_SHOWMAXIMIZED = 3,
  34. SW_MAXIMIZE = 3,
  35. SW_SHOWNOACTIVATE = 4,
  36. SW_SHOW = 5,
  37. SW_MINIMIZE = 6,
  38. SW_SHOWMINNOACTIVE = 7,
  39. SW_SHOWNA = 8,
  40. SW_RESTORE = 9,
  41. SW_SHOWDEFAULT = 10,
  42. SW_FORCEMINIMIZE = 11,
  43. SW_MAX = 11
  44. };
  45. [DllImport("shell32.dll")]
  46. public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);
  47. //json对象属性
  48. private JObject joInParam;
  49. private JArray jaSession ;
  50. private JArray jaParams;
  51. private JObject joParam;
  52. private JObject joInterface;
  53. private JObject joInsuAdmObj;
  54. //设置业务实例
  55. CenterBusiness cBus = new CenterBusiness();
  56. HisMainBusiness hBus = new HisMainBusiness();
  57. HisIrisServices hIS = new HisIrisServices();
  58. MIIrisServices mIS= new MIIrisServices();
  59. InvokeHelper invoker = new InvokeHelper();
  60. private XmlHelper xmler = new XmlHelper();
  61. //
  62. private string businessType;
  63. public InsuBusiness()
  64. {
  65. Global.curEvt.path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  66. ComputerInfo comp = new ComputerInfo();
  67. Global.curEvt.mac = comp.GetMAC();
  68. Global.curEvt.ip = comp.GetIP();
  69. Global.pat.insuplc_admdvs = "";//如果是NULL中心会报错
  70. }
  71. #region 内部私有方法封装
  72. private int parseInparam(string inParam, out string errMsg)
  73. {
  74. errMsg = "";
  75. try
  76. {
  77. joInParam = JObject.Parse(inParam);
  78. jaSession = JArray.Parse(JsonHelper.getDestValue(joInParam, "session"));
  79. Global.curEvt.jaSession = jaSession;
  80. jaParams = JArray.Parse(JsonHelper.getDestValue(joInParam, "params"));
  81. joParam = JObject.FromObject(jaParams[0]);
  82. joInterface = JObject.Parse(JsonHelper.getDestValue(joInParam, "interfaceinfo"));
  83. if (JsonHelper.getDestValue(joInParam, "insuAdmObj") !="")
  84. joInsuAdmObj = JObject.Parse(JsonHelper.getDestValue(joInParam, "insuAdmObj"));
  85. businessType = JsonHelper.getDestValue(joInParam, "businessType");
  86. if (JsonHelper.getDestValue(joInParam, "operationType") != "")
  87. {
  88. Global.operationType = (OperationType)Enum.Parse(typeof(OperationType), JsonHelper.getDestValue(joInParam, "operationType"));
  89. }
  90. Global.curEvt.businessType = businessType;
  91. return 0;
  92. }
  93. catch (Exception ex)
  94. {
  95. errMsg = "parseInparam 解析入参异常:" + errMsg;
  96. return -1;
  97. }
  98. }
  99. private int init(string inParam, out string outParam)
  100. {
  101. string errMsg;
  102. outParam = "";
  103. try
  104. {
  105. //BS架构调用方式问题,每次调用都需要重新初始化
  106. JObject joInitRtn = JObject.Parse(Init(inParam));
  107. if (JsonHelper.parseIrisRtnValue(joInitRtn, out errMsg) != 0)
  108. {
  109. outParam = JsonHelper.setExceptionJson(-100, "init(HIS医保环境初始化)", errMsg).ToString();
  110. return -1;
  111. }
  112. else
  113. {
  114. return 0;
  115. }
  116. }
  117. catch (Exception ex)
  118. {
  119. outParam = JsonHelper.setExceptionJson(-100, "init(HIS医保环境初始化)异常", ex.Message).ToString();
  120. return -1;
  121. }
  122. }
  123. #endregion
  124. #region 核心业务
  125. /// <summary>
  126. /// 初始化
  127. /// </summary>
  128. /// <param name="InParam"></param>
  129. /// <returns></returns>
  130. public string Init(string InParam)
  131. {
  132. string errMsg, rtnResult ="";
  133. JObject joRtn = new JObject();
  134. try
  135. {
  136. //解析入参
  137. if (parseInparam(InParam, out errMsg) != 0)
  138. {
  139. return JsonHelper.setExceptionJson(-100, "initEnvironment解析入参失败", errMsg).ToString();
  140. }
  141. if (hBus.initEnvironment(InParam, out errMsg) != 0)
  142. {
  143. return JsonHelper.setExceptionJson(-100, "initEnvironment(获取HIS及医保平台配置信息,当前登录用户信息,当前接口的详细信息) 失败", errMsg).ToString();
  144. }
  145. else
  146. {
  147. //签到
  148. if (mIS.isSigned(ref Global.curEvt.signno) != true)
  149. {
  150. //签到
  151. if (cBus.signIn(out joRtn) != 0)
  152. {
  153. rtnResult = JsonHelper.setExceptionJson(-1, "签到异常", (string)joRtn["err_msg"]).ToString();
  154. //return rtnResult;
  155. }
  156. else
  157. {
  158. Global.curEvt.signno = JsonHelper.getDestValue(joRtn, "output.signinoutb.sign_no");
  159. //插入签到表
  160. if (mIS.saveSignRecord(Global.curEvt.signno, out errMsg) != 0)
  161. {
  162. rtnResult = JsonHelper.setIrisReturnValue(0, "中心签到成功但插入签到表失败:" + errMsg, null).ToString();
  163. }
  164. else
  165. {
  166. rtnResult = JsonHelper.setIrisReturnValue(0, "签到成功", joRtn).ToString();
  167. }
  168. }
  169. }
  170. InvokeHelper.yhCom = new YinHaiCom();
  171. if (InvokeHelper.initYHCom(out errMsg) != 0)
  172. {
  173. return JsonHelper.setExceptionJson(-100, "初始化银海COM组件失败", errMsg).ToString();
  174. }
  175. else
  176. {
  177. rtnResult = JsonHelper.setIrisReturnValue(0, "初始化成功!", null).ToString();
  178. }
  179. return rtnResult;
  180. }
  181. }
  182. catch (Exception ex)
  183. {
  184. rtnResult = JsonHelper.setExceptionJson(-100, "初始化异常", ex.Message).ToString();
  185. return rtnResult;
  186. }
  187. finally
  188. {
  189. Global.writeLog("初始化结果:" + rtnResult);
  190. }
  191. }
  192. /// <summary>
  193. /// 获取患者信息
  194. /// </summary>
  195. /// <param name="InParam"></param>
  196. /// <returns></returns>
  197. public string GetPatientInfo(string InParam)
  198. {
  199. Global.writeLog("GetPatientInfo入参:" + JsonHelper.Compress(InParam));
  200. //设置返回值,错误信息
  201. int errCode;
  202. string errMsg, rtnResult = "",outParam;
  203. //BS架构调用方式问题,每次调用都需要重新初始化
  204. if (init(InParam, out outParam) != 0)
  205. {
  206. rtnResult = outParam;
  207. return rtnResult;
  208. }
  209. string businessType = JsonHelper.getDestValue(joInParam,"businessType");
  210. try
  211. {
  212. switch (businessType)
  213. {
  214. case "M1"://门诊读卡
  215. {
  216. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  217. if (hBus.readCard(out outParam) != 0)
  218. {
  219. rtnResult = JsonHelper.setExceptionJson(-100, "读卡失败!", outParam).ToString();
  220. }
  221. else
  222. {
  223. //展示患者信息界面
  224. if (hBus.showPatInfo(outParam, out outParam) != 0)
  225. {
  226. rtnResult = outParam;
  227. }
  228. else
  229. {
  230. rtnResult = outParam;
  231. }
  232. }
  233. break;
  234. }
  235. case "Z1"://住院读卡
  236. {
  237. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  238. if (hBus.readCard(out outParam) != 0)
  239. {
  240. rtnResult = JsonHelper.setExceptionJson(-100, "读卡失败!", outParam).ToString();
  241. }
  242. else
  243. {
  244. string patInfo = outParam;
  245. //展示患者信息界面
  246. if (hBus.showPatInfo(patInfo, out outParam) != 0)
  247. {
  248. rtnResult = outParam;
  249. }
  250. else
  251. {
  252. rtnResult = JsonHelper.setIrisReturnValue(0,"",JObject.Parse(outParam)).ToString();
  253. }
  254. }
  255. break;
  256. }
  257. }
  258. return rtnResult;
  259. }
  260. catch (Exception ex)
  261. {
  262. rtnResult = JsonHelper.setIrisReturnValue(-1 , "GetPatientInfo发生异常;" + ex.Message,null).ToString();
  263. return rtnResult;
  264. }
  265. finally
  266. {
  267. Global.writeLog("GetPatientInfo出参:" + JsonHelper.Compress(rtnResult));
  268. }
  269. }
  270. /// <summary>
  271. /// 登记
  272. /// </summary>
  273. /// <param name="InParam"></param>
  274. /// <returns></returns>
  275. public string Register(string InParam)
  276. {
  277. Global.writeLog("Register 入参:" + JsonHelper.Compress(InParam));
  278. //设置返回值,错误信息
  279. string errMsg, rtnResult = "", outParam;
  280. try
  281. {
  282. //BS架构调用方式问题,每次调用都需要重新初始化
  283. if (init(InParam, out outParam) != 0)
  284. {
  285. rtnResult = outParam;
  286. return rtnResult;
  287. }
  288. //获取pat
  289. hBus.GetRegPatInfo(businessType, joInParam, out Global.pat);
  290. switch (businessType)
  291. {
  292. case "M2"://门诊登记
  293. {
  294. break;
  295. }
  296. case "M2C"://门诊登记撤销
  297. {
  298. break;
  299. }
  300. case "Z0"://住院修改
  301. {
  302. break;
  303. }
  304. case "Z2"://入院登记
  305. {
  306. string regInParam = "";
  307. errMsg = "";
  308. if (hBus.checkName(Global.pat.name, out errMsg) != 0)
  309. {
  310. rtnResult = errMsg;
  311. return rtnResult;
  312. }
  313. //显示登记面板
  314. if (hBus.showInPatRegisterForm( out regInParam) == 0)
  315. {
  316. JObject joReg = JObject.Parse(regInParam);
  317. JObject joRegIn = JObject.Parse(JsonHelper.getDestValue(joReg, "input"));
  318. //将中心返回的结果返回HIS,调用HIS服务进行保存
  319. if (invoker.invokeYHCom("21", joRegIn, out outParam)== 0)
  320. {
  321. string outPut = xmler.ToJSON(outParam);
  322. JObject joRegOut = JObject.Parse(outPut);
  323. Global.pat.mdtrtID = JsonHelper.getDestValue(joRegOut, "output.prm_akc190");
  324. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joRegOut, "output.prm_yab003");
  325. //插入患者本次就诊用的参保信息
  326. if (hBus.insertPatCurInsuInfo(JsonHelper.getDestValue(joParam, "patientInfo"), out outParam) != 0)
  327. {
  328. if (DialogResult.Yes == MessageBox.Show(outParam, " 是否继续? ", MessageBoxButtons.YesNo))
  329. {
  330. }
  331. else
  332. {
  333. invoker.cancleYHCom(out errMsg);
  334. rtnResult = JsonHelper.setExceptionJson(-1, "插入患者本次就诊用的参保信息,请联系管理员!", outParam).ToString();
  335. return rtnResult;
  336. }
  337. }
  338. //插入医保平台
  339. joRegOut.Add("validflag", 1);
  340. joRegOut.Add("regstate", 1);
  341. joRegOut.Add("type", 1);
  342. if (mIS.saveInpatRegisterInfo(joRegIn, joRegOut, out outParam) != 0)
  343. {
  344. rtnResult = JsonHelper.setExceptionJson(-1, "云平台保存登记信息", outParam).ToString();
  345. invoker.cancleYHCom(out errMsg);
  346. return rtnResult;
  347. }
  348. //返回登记信息,插入HIS
  349. if (hIS.returnRegisterInfo(joRegIn, joRegOut, out outParam) != 0)
  350. {
  351. rtnResult = JsonHelper.setExceptionJson(-1, "HIS平台保存登记信息", outParam).ToString();
  352. invoker.cancleYHCom(out errMsg);
  353. return rtnResult;
  354. }
  355. else
  356. {
  357. //确认中心结算
  358. if (invoker.confirmYHCom(out errMsg) != 0)
  359. {
  360. rtnResult = JsonHelper.setExceptionJson(-1, "中心确认失败", errMsg).ToString();
  361. invoker.cancleYHCom(out errMsg);
  362. return rtnResult;
  363. }
  364. else
  365. {
  366. rtnResult = JsonHelper.setIrisReturnValue(0, "登记成功", null).ToString();
  367. return rtnResult;
  368. }
  369. }
  370. }
  371. else
  372. {
  373. rtnResult = JsonHelper.setExceptionJson(-1, "展示登记界面", outParam).ToString();
  374. invoker.cancleYHCom(out errMsg);
  375. return rtnResult;
  376. }
  377. }
  378. else
  379. {
  380. rtnResult = JsonHelper.setExceptionJson(-1, "展示登记界面", regInParam).ToString();
  381. invoker.cancleYHCom(out errMsg);
  382. return rtnResult;
  383. }
  384. }
  385. case "Z2C"://入院登记取消
  386. {
  387. string sqlStr = "SELECT * FROM BS_MedInsuRegisterInfo WHERE Type=1 and Interface_Dr=" + Global.inf.interfaceDr;
  388. sqlStr = sqlStr + " AND InsuRegID='" + Global.pat.mdtrtID + "'";
  389. sqlStr = sqlStr + " AND Adm_Dr='" + Global.pat.adm_Dr + "'";
  390. JObject joSqlstr = new JObject();
  391. joSqlstr.Add("sqlStr", sqlStr);
  392. JArray jaParam = new JArray();
  393. jaParam.Add(joSqlstr);
  394. JObject joSettlQuery = new JObject();
  395. joSettlQuery.Add("params", jaParam);
  396. joSettlQuery.Add("code", "09010062");
  397. JObject joRtn = invoker.invokeInsuService(joSettlQuery.ToString(), "查询住院登记信息");
  398. JArray jaRegInfo = JArray.Parse(JsonHelper.getDestValue(joRtn,"result.data"));
  399. if (jaRegInfo.Count != 1)
  400. {
  401. rtnResult = JsonHelper.setExceptionJson(-1, "云平台:", "未查询到或查询到多条住院登记信息").ToString();
  402. return rtnResult;
  403. }
  404. else
  405. {
  406. Global.pat.medType = jaRegInfo[0]["med_type"].ToString();
  407. Global.pat.insuplc_admdvs = jaRegInfo[0]["insuplc_admdvs"].ToString();
  408. Global.pat.insuType = jaRegInfo[0]["InsuType"].ToString();
  409. hBus.setPrmBatch();
  410. }
  411. //取消中心登记
  412. if (cBus.cancleRegister(out outParam) != 0)
  413. {
  414. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记失败,", outParam).ToString();
  415. ////询问收款员是否继续进行HIS退费
  416. //if (DialogResult.Yes == MessageBox.Show("中心提示:" + outParam, " 是否强制取消HIS登记 ", MessageBoxButtons.YesNo))
  417. //{
  418. // //取消HIS 登记
  419. // if (hIS.cancleRegister(out outParam) != 0)
  420. // {
  421. // rtnResult = JsonHelper.setExceptionJson(-1, "强制取消HIS登记失败,", outParam).ToString();
  422. // }
  423. // else
  424. // {
  425. // rtnResult = JsonHelper.setExceptionJson(0, "强制取消HIS登记成功", outParam).ToString();
  426. // }
  427. //}
  428. return rtnResult;
  429. }
  430. //取消医保平台登记
  431. if (mIS.cancleRegister(1, out outParam) != 0)
  432. {
  433. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记成功,但云医保平台取消失败,", outParam).ToString();
  434. return rtnResult;
  435. }
  436. //取消HIS 登记
  437. if (hIS.cancleRegister( out outParam) != 0)
  438. {
  439. rtnResult = JsonHelper.setExceptionJson(-1, "中心和云医保平台取消登记成功,但HIS取消失败,", outParam).ToString();
  440. return rtnResult;
  441. }
  442. else
  443. {
  444. rtnResult = JsonHelper.setIrisReturnValue(0, "取消医保登记成功", null).ToString();
  445. return rtnResult;
  446. }
  447. }
  448. case "Z6"://出院登记
  449. {
  450. break;
  451. }
  452. case "Z6C"://出院登记取消
  453. {
  454. //从医保平台获取患者详细的医保登记信息
  455. if (mIS.queryRegisterInfo(1, out outParam) != 0)
  456. {
  457. rtnResult = JsonHelper.setExceptionJson(-1, "查询患者云平台登记信息", outParam).ToString();
  458. return rtnResult;
  459. }
  460. JObject joReg = JObject.Parse(outParam);
  461. Global.pat.medType = JsonHelper.getDestValue(joReg, "data.MedicalType");
  462. Global.pat.insuType = JsonHelper.getDestValue(joReg, "data.InsuType");
  463. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joReg, "data.InsuranceAreaCode");
  464. hBus.setPrmBatch();
  465. if (cBus.cancleDisRegister(out errMsg) != 0)
  466. {
  467. rtnResult = JsonHelper.setExceptionJson(-1, "取消出院登记", errMsg).ToString();
  468. return rtnResult;
  469. }
  470. else
  471. {
  472. rtnResult = JsonHelper.setIrisReturnValue(0, "取消出院登记成功", null).ToString();
  473. return rtnResult;
  474. }
  475. break;
  476. }
  477. default:
  478. {
  479. rtnResult = JsonHelper.setExceptionJson(-1, "Register 交易", "传入的业务编码不对!").ToString();
  480. return rtnResult;
  481. }
  482. }
  483. }
  484. catch (Exception ex)
  485. {
  486. rtnResult = JsonHelper.setIrisReturnValue(-1, "Register 发生异常;" + ex.Message, null).ToString();
  487. return rtnResult;
  488. }
  489. finally
  490. {
  491. Global.writeLog("Register 出参:" + JsonHelper.Compress(rtnResult));
  492. }
  493. return "";
  494. }
  495. /// <summary>
  496. /// 费用上传
  497. /// </summary>
  498. /// <param name="InParam"></param>
  499. /// <returns></returns>
  500. public string FeeUpload(string InParam)
  501. {
  502. Global.writeLog("FeeUpload 入参:" + JsonHelper.Compress(InParam));
  503. //设置返回值,错误信息
  504. int errCode;
  505. string errMsg, rtnResult = "", outParam;
  506. try
  507. {
  508. //事前分析
  509. //if (hBus.PreAnalysis("5", out errMsg) != 0)
  510. //{
  511. // rtnResult = JsonHelper.setExceptionJson(-1, "事前提示:" , errMsg).ToString();
  512. // return rtnResult;
  513. //}
  514. //解析入参
  515. if (parseInparam(InParam, out errMsg) != 0)
  516. {
  517. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  518. return rtnResult;
  519. }
  520. //BS架构调用方式问题,每次调用都需要重新初始化
  521. if (init(InParam, out outParam) != 0)
  522. {
  523. rtnResult = outParam;
  524. return rtnResult;
  525. }
  526. //获取pat
  527. hBus.GetFeeHisInfo(businessType, joInParam, out Global.pat);
  528. switch (businessType)
  529. {
  530. case "M3"://门诊费用上传
  531. {
  532. break;
  533. }
  534. case "M3C"://门诊费用撤销
  535. {
  536. break;
  537. }
  538. case "Z3"://入院费用上传
  539. {
  540. //从医保平台获取患者详细的医保登记信息
  541. if (mIS.queryRegisterInfo(1, out outParam) != 0)
  542. {
  543. rtnResult = JsonHelper.setExceptionJson(-1, "查询患者云平台登记信息", outParam).ToString();
  544. return rtnResult;
  545. }
  546. JObject joReg = JObject.Parse(outParam);
  547. Global.pat.medType = JsonHelper.getDestValue(joReg, "data.MedicalType");
  548. Global.pat.insuType = JsonHelper.getDestValue(joReg, "data.InsuType");
  549. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joReg, "data.InsuranceAreaCode");
  550. hBus.setPrmBatch();
  551. if (Global.pat.medType != "G31")
  552. {
  553. Global.pat.patExtend.prm_yabtch = Global.pat.insuplc_admdvs;
  554. ////事前分析
  555. if (Global.curEvt.ext.isOpenAnalysis)
  556. {
  557. if (hBus.PreAnalysis("4","", out errMsg) != 0)
  558. {
  559. rtnResult = JsonHelper.setExceptionJson(-1, "事前分析", errMsg).ToString();
  560. return rtnResult;
  561. }
  562. }
  563. }
  564. ////先取消中心费用传送
  565. //cBus.cancleFeeUpload("2302", out errMsg);
  566. ////再删除医保传送表的数据
  567. //mIS.deleteFee(out errMsg);
  568. //费用上传
  569. if (hBus.uploadFee("2301", 50, out outParam) != 0)
  570. {
  571. rtnResult = JsonHelper.setExceptionJson(-1, "费用上传", outParam).ToString();
  572. return rtnResult;
  573. }
  574. else
  575. {
  576. rtnResult = JsonHelper.setIrisReturnValue(0, "住院费用上传成功", null).ToString();
  577. return rtnResult;
  578. }
  579. }
  580. case "Z3C"://住院费用上传取消
  581. {
  582. //从医保平台获取患者详细的医保登记信息
  583. if (mIS.queryRegisterInfo(1, out outParam) != 0)
  584. {
  585. rtnResult = JsonHelper.setExceptionJson(-1, "查询患者云平台登记信息", outParam).ToString();
  586. return rtnResult;
  587. }
  588. JObject joReg = JObject.Parse(outParam);
  589. Global.pat.medType = JsonHelper.getDestValue(joReg, "data.MedicalType");
  590. Global.pat.insuType = JsonHelper.getDestValue(joReg, "data.InsuType");
  591. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joReg, "data.InsuranceAreaCode");
  592. hBus.setPrmBatch();
  593. if (cBus.cancleFeeUpload("2302", out errMsg) != 0)
  594. {
  595. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心费用", errMsg).ToString();
  596. return rtnResult;
  597. }
  598. if (mIS.deleteFee( out errMsg) != 0)
  599. {
  600. rtnResult = JsonHelper.setExceptionJson(-1, "删除医保平台费用", errMsg).ToString();
  601. return rtnResult;
  602. }
  603. else
  604. {
  605. rtnResult = JsonHelper.setIrisReturnValue(0, "住院费用上传取消成功", null).ToString();
  606. return rtnResult;
  607. }
  608. }
  609. default:
  610. {
  611. rtnResult = JsonHelper.setExceptionJson(-1, "FeeUpload 交易", "传入的业务编码不对!").ToString();
  612. return rtnResult;
  613. }
  614. }
  615. return rtnResult;
  616. }
  617. catch (Exception ex)
  618. {
  619. rtnResult = JsonHelper.setExceptionJson(-1, "FeeUpload 交易", ex.Message).ToString();
  620. return rtnResult;
  621. }
  622. finally
  623. {
  624. Global.writeLog("FeeUpload 出参:" + JsonHelper.Compress(rtnResult));
  625. }
  626. }
  627. /// <summary>
  628. /// 结算
  629. /// </summary>
  630. /// <param name="InParam"></param>
  631. /// <returns></returns>
  632. public string Settlement(string InParam)
  633. {
  634. Global.writeLog("Settlement 入参:" + JsonHelper.Compress(InParam));
  635. //设置返回值,错误信息
  636. string errMsg, rtnResult = "", outParam;
  637. try
  638. {
  639. //解析入参
  640. if (parseInparam(InParam, out errMsg) != 0)
  641. {
  642. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  643. return rtnResult;
  644. }
  645. //BS架构调用方式问题,每次调用都需要重新初始化
  646. if (init(InParam, out outParam) != 0)
  647. {
  648. rtnResult = outParam;
  649. return rtnResult;
  650. }
  651. //获取pat
  652. hBus.GetSettlementHisInfo(businessType, joInParam, out Global.pat);
  653. switch (businessType)
  654. {
  655. case "M4"://门诊预结算
  656. {
  657. OutpatientRegistration frmReg = new OutpatientRegistration();
  658. if (frmReg.ShowDialog() == DialogResult.OK)
  659. {
  660. rtnResult = "调用结束";
  661. }
  662. break;
  663. }
  664. case "M4C"://门诊预结算撤销
  665. {
  666. break;
  667. }
  668. case "M5"://门诊结算
  669. {
  670. STA sta = new STA();
  671. Thread thread = new Thread(new ParameterizedThreadStart(sta.showOutPatientIntegratedServicesForm));
  672. thread.SetApartmentState(ApartmentState.STA); //重点
  673. thread.IsBackground = true;
  674. object[] o = new object[3];
  675. o[0] = "-1";
  676. thread.Start(o);
  677. thread.Join();
  678. if ((int)o[0] != 0)
  679. {
  680. rtnResult = JsonHelper.setExceptionJson(-100, "门诊结算失败!", (string)o[2]).ToString();
  681. return rtnResult;
  682. }
  683. else
  684. {
  685. rtnResult = (string)o[2];
  686. return rtnResult;
  687. }
  688. }
  689. case "M5C"://门诊结算撤销
  690. {
  691. string setl_id = JsonHelper.getDestValue(joParam, "setl_id");
  692. //查询结算表
  693. string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE ValidFlag =1 and billType = 1 and Hospital_Dr=" + Global.inf.hospitalDr
  694. + " and Adm_Dr=" + Global.pat.adm_Dr
  695. + " and MdtrtID='" + Global.pat.mdtrtID + "'"
  696. + " AND SettlementID='" + setl_id + "'";
  697. JObject joSql = new JObject();
  698. joSql.Add("sqlStr", sqlStr);
  699. JObject joSettlInfo = mIS.QuerySettlementInfo(joSql);
  700. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  701. Global.pat.medType = JsonHelper.getDestValue(joSettlInfo, "result.data[0].MedicalType");
  702. Global.pat.insuType = JsonHelper.getDestValue(joSettlInfo, "result.data[0].InsuranceType");
  703. hBus.setPrmBatch();
  704. //共济
  705. DataTable dtSettlInfo = (DataTable)JsonConvert.DeserializeObject(joSettlInfo["result"]["data"].ToString(), (typeof(DataTable)));
  706. if (dtSettlInfo.Rows.Count != 1)
  707. {
  708. rtnResult = JsonHelper.setIrisReturnValue(-1, "未查询到相关结算信息!", joSettlInfo).ToString();
  709. return rtnResult;
  710. }
  711. int mutualAidFlag = 0;
  712. if (!string.IsNullOrEmpty(dtSettlInfo.Rows[0]["MutualAidFlag"].ToString()))
  713. {
  714. mutualAidFlag = Convert.ToInt32(dtSettlInfo.Rows[0]["MutualAidFlag"].ToString());
  715. }
  716. if (mutualAidFlag > 0)
  717. {
  718. STA sta = new STA();
  719. Thread thread = new Thread(sta.MutualAid);
  720. thread.SetApartmentState(ApartmentState.STA); //重点
  721. thread.IsBackground = true;
  722. object[] o = new object[2];
  723. o[0] = setl_id;
  724. thread.Start(o);
  725. thread.Join();
  726. //重新赋值
  727. hBus.GetSettlementHisInfo(businessType, joInParam, out Global.pat);
  728. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  729. Global.pat.patExtend.prm_yabtch = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  730. Global.pat.medType = JsonHelper.getDestValue(joSettlInfo, "result.data[0].MedicalType");
  731. Global.pat.insuType = JsonHelper.getDestValue(joSettlInfo, "result.data[0].InsuranceType");
  732. }
  733. //退中心结算
  734. if (cBus.cancleSettlement( out outParam) != 0)
  735. {
  736. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算", outParam).ToString();
  737. //查看是医保平台是否已经退费,如果是,则询问是否继续退费
  738. //string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr;
  739. ////sqlStr = sqlStr + " AND SettlementID ='" + Global.pat.settlID + "'"; // 广州本地门诊退结算ID 跟结算ID 一致,但异地门诊不一致
  740. //sqlStr = sqlStr + " AND RecordID ='" + Global.pat.recordID + "'";
  741. //sqlStr = sqlStr + " AND ValidFlag = 0 AND BillType = -1";
  742. //string sqlStr = "SELECT RecordID FROM BS_MedInsuSettlement WHERE Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr;
  743. //sqlStr = sqlStr + " AND SettlementID ='" + Global.pat.settlID + "'" + " AND BillType = 1 ";
  744. //sqlStr = "(" + sqlStr + ")";
  745. //sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr
  746. // + " AND BillType = -1 and RecordID=" + sqlStr;
  747. sqlStr = "SELECT A.* FROM BS_MedInsuSettlement A LEFT JOIN BS_MedInsuSettlement B ON A.RecordID = b.RecordID";
  748. sqlStr = sqlStr + " AND A.BillType = -1 AND B.BillType = 1 ";
  749. sqlStr = sqlStr + " where B.SettlementID ='" + Global.pat.settlID + "'";
  750. sqlStr = sqlStr + " AND A.Interface_Dr=" + Global.inf.interfaceDr;
  751. JObject joSqlStr = new JObject();
  752. joSqlStr.Add("sqlStr", sqlStr);
  753. JObject joCancleSettlInfo = mIS.QuerySettlementInfo(joSqlStr);
  754. JArray jaCancleSettlInfo = JArray.Parse(JsonHelper.getDestValue(joCancleSettlInfo, "result.data"));
  755. if (jaCancleSettlInfo.Count == 0)
  756. {
  757. //询问收款员是否继续进行HIS退费
  758. //if (DialogResult.Yes == MessageBox.Show("中心提示:" + outParam, " 该费用在医保中心未成功退费,是否强制退HIS费用? ", MessageBoxButtons.YesNo))
  759. //{
  760. // rtnResult = JsonHelper.setExceptionJson(0, "该费用在医保中心未成功退费,收款员选择强制退HIS费用!", outParam).ToString();
  761. //}
  762. }
  763. else if (jaCancleSettlInfo.Count == 1)
  764. {
  765. ////询问收款员是否继续进行HIS退费
  766. //if (DialogResult.Yes == MessageBox.Show("中心提示:" +outParam, " 该费用在医保中心已成功退费但在HIS未成功退费,是否强制退HIS费用? ", MessageBoxButtons.YesNo))
  767. //{
  768. // rtnResult = JsonHelper.setExceptionJson(0, "该费用在医保中心已成功退费但在HIS未成功退费,收款员选择强制退HIS费用!", outParam).ToString();
  769. //}
  770. }
  771. else
  772. {
  773. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算(云医保平台未退费或未查询到退费记录)", outParam).ToString();
  774. }
  775. return rtnResult;
  776. }
  777. //确认中心结算
  778. if (invoker.confirmYHCom(out errMsg) != 0)
  779. {
  780. rtnResult = JsonHelper.setExceptionJson(-1, "中心确认失败", outParam).ToString();
  781. return rtnResult;
  782. }
  783. string newSettleID = JsonHelper.getDestValue(JObject.Parse(xmler.ToJSON(outParam)), "output.prm_yka198");
  784. //退云医保平台结算
  785. if (mIS.cancleSettlement(newSettleID,out outParam) != 0)
  786. {
  787. rtnResult = JsonHelper.setExceptionJson(-1, "取消平台结算信息", outParam).ToString();
  788. //return rtnResult;
  789. }
  790. ////云平台取消传送
  791. //if (mIS.deleteFee(out errMsg) != 0)
  792. //{
  793. // rtnResult = JsonHelper.setExceptionJson(-1, "删除医保平台费用", errMsg).ToString();
  794. // return rtnResult;
  795. //}
  796. //退HIS结算
  797. if (hIS.cancleSettlementInfo(joParam, out outParam) != 0)
  798. {
  799. rtnResult = JsonHelper.setExceptionJson(-1, "取消HIS结算信息", outParam).ToString();
  800. return rtnResult;
  801. }
  802. else
  803. {
  804. rtnResult = JsonHelper.setIrisReturnValue(0, "取消结算成功", null).ToString();
  805. return rtnResult;
  806. }
  807. }
  808. case "M6"://门诊移动支付结算
  809. {
  810. MobilePay mp = new MobilePay(InParam, out errMsg);
  811. if (errMsg != "")
  812. {
  813. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  814. return rtnResult;
  815. }
  816. if (mp.MobilePaySettlement(out outParam) != 0)
  817. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
  818. else
  819. rtnResult = outParam;
  820. return rtnResult;
  821. }
  822. case "M6C"://门诊移动支付结算撤销
  823. {
  824. string onlineYBFalg = JsonHelper.getDestValue(joInsuAdmObj, "onlineYBFalg");
  825. //if (onlineYBFalg == "Y")
  826. //{
  827. // rtnResult = JsonHelper.setExceptionJson(-1, "门诊移动支付撤销交易", "不支持线上退费").ToString();
  828. // return rtnResult;
  829. //}
  830. MobilePay mp = new MobilePay(InParam, out errMsg);
  831. if (errMsg != "")
  832. {
  833. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  834. return rtnResult;
  835. }
  836. if (String.IsNullOrEmpty(onlineYBFalg))
  837. mp.MSettl.onlineYBFalg = "N";
  838. else
  839. mp.MSettl.onlineYBFalg = onlineYBFalg;
  840. if (mp.MobilePayCancelSettlement(out outParam) != 0)
  841. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
  842. else
  843. rtnResult = JsonHelper.setExceptionJson(0, "Settlement 交易", outParam).ToString();
  844. return rtnResult;
  845. }
  846. case "M6Confirm"://门诊移动支付确认
  847. {
  848. MobilePay mp = new MobilePay(InParam, out errMsg);
  849. if (errMsg != "")
  850. {
  851. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  852. return rtnResult;
  853. }
  854. if (mp.MobilePayConfirmSettlement(out outParam) != 0)
  855. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
  856. else
  857. rtnResult = outParam;
  858. return rtnResult;
  859. }
  860. case "Z4"://住院预结算
  861. {
  862. JObject joSettle = new JObject();
  863. if (hBus.preSettlement(out joSettle, out outParam) != 0)
  864. {
  865. rtnResult = JsonHelper.setExceptionJson(-1, "结算信息展示", outParam).ToString();
  866. return rtnResult;
  867. }
  868. else
  869. {
  870. rtnResult = JsonHelper.setIrisReturnValue(0, "预结算成功", null).ToString();
  871. return rtnResult;
  872. }
  873. }
  874. case "Z4C"://住院预结算撤销
  875. {
  876. rtnResult = JsonHelper.setExceptionJson(-100, "该接口不支持预结算取消!", null).ToString();
  877. return rtnResult;
  878. }
  879. case "Z5"://住院结算
  880. {
  881. JObject joPreSetOutpar ;
  882. if (hBus.preSettlement(out joPreSetOutpar, out outParam) != 0)
  883. {
  884. rtnResult = JsonHelper.setExceptionJson(-1, "结算信息展示", outParam).ToString();
  885. return rtnResult;
  886. }
  887. else
  888. {
  889. if (Global.pat.patExtend.isMutualAid && Global.pat.patExtend.isSettlementWithNopwd)
  890. {
  891. rtnResult = JsonHelper.setExceptionJson(-1, "无密码结算和共济结算只能选择一个", "").ToString();
  892. return rtnResult;
  893. }
  894. if (Global.pat.patExtend.prm_yabtch != "GS01")
  895. {
  896. ////事中分析
  897. if (Global.curEvt.ext.isOpenAnalysis)
  898. {
  899. if (hBus.InProcessAnalysis("8", out errMsg) != 0)
  900. {
  901. outParam = JsonHelper.setExceptionJson(-1, "InProcessAnalysis", errMsg).ToString();
  902. return outParam;
  903. }
  904. }
  905. }
  906. string sqlStr = "SELECT * FROM SQLUser.BS_MIPatCurrentInsuInfo WHERE Interface_Dr =" + Global.inf.interfaceDr
  907. + " AND AdmID = '" + Global.pat.adm_Dr + "'"
  908. + " AND MdtrtID = '" + Global.pat.mdtrtID + "'";
  909. JObject joSqlStr = new JObject();
  910. joSqlStr.Add("sqlStr", sqlStr);
  911. JObject joCurrentInsuInfo = mIS.DynamicQueryPatCurrentInsuInfo(joSqlStr);
  912. if (JsonHelper.parseIrisRtnValue(joCurrentInsuInfo, out errMsg) != 0)
  913. {
  914. }
  915. else
  916. {
  917. Global.pat.patExtend.prm_auther_certno = JsonHelper.getDestValue(joCurrentInsuInfo, "result.rows[0].extField1");
  918. Global.pat.patExtend.prm_auther_insu_admdvs = JsonHelper.getDestValue(joCurrentInsuInfo, "result.rows[0].extField2");
  919. Global.pat.patExtend.prm_auther_name = JsonHelper.getDestValue(joCurrentInsuInfo, "result.rows[0].extField3");
  920. Global.pat.patExtend.prm_auther_no = JsonHelper.getDestValue(joCurrentInsuInfo, "result.rows[0].extField4");
  921. }
  922. if (Global.pat.patExtend.isMutualAid && (string.IsNullOrEmpty(Global.pat.patExtend.prm_auther_certno) || string.IsNullOrEmpty(Global.pat.patExtend.prm_auther_no)))
  923. {
  924. outParam = ("未检测到该患者有共济授权人,请取消勾选共济结算!!");
  925. rtnResult = JsonHelper.setExceptionJson(-1, "结算信息展示", outParam).ToString();
  926. return rtnResult;
  927. }
  928. JObject joSettlement = JObject.Parse(JsonHelper.getDestValue(joPreSetOutpar, "Settlement"));
  929. //出院登记
  930. //invoker.invokeYHCom
  931. JObject joDischargeRegister = JObject.Parse(JsonHelper.getDestValue(joPreSetOutpar, "DischargeRegister"));
  932. if (invoker.invokeYHCom("25",joDischargeRegister, out errMsg) != 0)
  933. {
  934. rtnResult = JsonHelper.setExceptionJson(-1, "结算失败", errMsg).ToString();
  935. return rtnResult;
  936. }
  937. string settlementFunNO = "41";
  938. if (Global.pat.patExtend.isSettlementWithNopwd)
  939. {
  940. ApplyReason frm = new ApplyReason();
  941. frm.StartPosition = FormStartPosition.CenterParent;
  942. if (frm.ShowDialog() != DialogResult.OK)
  943. {
  944. rtnResult = JsonHelper.setExceptionJson(-1, "无密码结算必须输入原因", "").ToString();
  945. return rtnResult;
  946. }
  947. if (string.IsNullOrEmpty(frm.reason))
  948. {
  949. rtnResult = JsonHelper.setExceptionJson(-1, "无密码结算必须输入原因", "").ToString();
  950. return rtnResult;
  951. }
  952. joSettlement["prm_aae013"] = frm.reason;
  953. joSettlement.Remove("businessType");
  954. joSettlement.Remove("officeId");
  955. joSettlement.Remove("officeName");
  956. joSettlement.Remove("operatorId");
  957. joSettlement.Remove("operatorName");
  958. joSettlement.Remove("orgId");
  959. joSettlement.Remove("deviceType");
  960. joSettlement.Remove("cardtype");
  961. joSettlement.Remove("cardid");
  962. joSettlement.Remove("cardname");
  963. settlementFunNO = "41d";
  964. }
  965. //正式结算
  966. if (invoker.invokeYHCom(settlementFunNO,joSettlement, out outParam) != 0)
  967. {
  968. rtnResult = JsonHelper.setExceptionJson(-1, "结算失败", outParam).ToString();
  969. cBus.cancleDisRegister( out errMsg);
  970. return rtnResult;
  971. }
  972. else
  973. {
  974. Global.pat.admType = 2;
  975. JObject joSettlRtn = JObject.Parse(xmler.ToJSON(outParam));
  976. //返回给云医保平台结算信息
  977. if (mIS.saveSettlement(joSettlRtn, out outParam) != 0)
  978. {
  979. rtnResult = JsonHelper.setExceptionJson(-1, "结算成功,但云医保平台保存失败", outParam).ToString();
  980. return rtnResult;
  981. }
  982. //共济支付
  983. if (Global.pat.patExtend.isMutualAid)
  984. {
  985. decimal psnCashPay = decimal.Parse(JsonHelper.getDestValue(joSettlRtn, "output.psn_cash_pay"));
  986. if (psnCashPay == 0)
  987. {
  988. MessageBox.Show("该患者自付金额为0,不需要进行共济支付!");
  989. }
  990. else
  991. {
  992. //开启自付界面,因涉及到多次自付
  993. JObject joMa = new JObject();
  994. joMa.Add("setl_id", JsonHelper.getDestValue(joSettlRtn, "output.prm_yka103"));
  995. joMa.Add("MainSettlInfo", joSettlRtn);
  996. joMa.Add("psnCashPay", psnCashPay);
  997. //MutualAid frmMA = new MutualAid(joMa);
  998. //if (frmMA.dtSumumt.Rows.Count != 0)
  999. //{
  1000. // frmMA.WindowState = FormWindowState.Maximized;
  1001. // if (frmMA.ShowDialog() == DialogResult.OK)
  1002. // {
  1003. // outParam = frmMA.finalSettlementInfo;
  1004. // joSettlRtn = frmMA.joMainSettlInfo;
  1005. // }
  1006. // else
  1007. // {
  1008. // MessageBox.Show("开启共济支付失败,原因为收款员取消共济支付!");
  1009. // }
  1010. //}
  1011. //else
  1012. //{
  1013. // MessageBox.Show("开启共济支付失败,原因为未检测到有效的被共济人的医保结算数据!");
  1014. //}
  1015. STA sta = new STA();
  1016. Thread thread = new Thread(new ParameterizedThreadStart(sta.MutualAid_));
  1017. thread.SetApartmentState(ApartmentState.STA); //重点
  1018. thread.IsBackground = true;
  1019. object[] o = new object[2];
  1020. o[0] = joMa;
  1021. thread.Start(o);
  1022. thread.Join();
  1023. rtnResult = (string)o[1];
  1024. JObject joMutualAidRtn = JObject.Parse(rtnResult);
  1025. if (JsonHelper.parseIrisRtnValue(joMutualAidRtn, out errMsg) != 0)
  1026. {
  1027. return rtnResult;
  1028. }
  1029. else
  1030. {
  1031. outParam = JsonHelper.getDestValue(joMutualAidRtn, "result.settlInfo");
  1032. joSettlRtn = JObject.Parse(JsonHelper.getDestValue(joMutualAidRtn, "result.settlRtn"));
  1033. }
  1034. }
  1035. }
  1036. //返回给HIS
  1037. JObject joSetlinfo = JObject.Parse(outParam);
  1038. if (hIS.returnInpatSettlementInfo(joSettlRtn, joSetlinfo, out outParam) != 0)
  1039. {
  1040. rtnResult = JsonHelper.setExceptionJson(-1, "返回结算信息给HIS", outParam).ToString();
  1041. return rtnResult;
  1042. }
  1043. //确认中心结算
  1044. if (invoker.confirmYHCom(out errMsg) != 0)
  1045. {
  1046. rtnResult = JsonHelper.setExceptionJson(-1, "中心确认失败", errMsg).ToString();
  1047. invoker.cancleYHCom(out errMsg);
  1048. return rtnResult;
  1049. }
  1050. else
  1051. {
  1052. //返回给前端
  1053. JObject joHisServieRtn = JObject.Parse(outParam);
  1054. hBus.returnToFrontEndAfterSettlement(joSettlRtn, joHisServieRtn, out outParam);
  1055. rtnResult = JsonHelper.setIrisReturnValue(0, "结算成功", JObject.Parse(outParam)).ToString();
  1056. return rtnResult;
  1057. }
  1058. }
  1059. }
  1060. }
  1061. case "Z5C"://住院结算撤销
  1062. {
  1063. //查询结算表
  1064. string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE billType = 1 and Hospital_Dr=" + Global.inf.hospitalDr
  1065. + " and Adm_Dr=" + Global.pat.adm_Dr
  1066. + " and MdtrtID='" + Global.pat.mdtrtID + "'"
  1067. + " and SettlementID='" + Global.pat.settlID + "'";
  1068. JObject joSql = new JObject();
  1069. joSql.Add("sqlStr", sqlStr);
  1070. JObject joSettlInfo = mIS.QuerySettlementInfo(joSql);
  1071. //if (JsonHelper.parseIrisRtnValue(joSettlInfo, out errMsg) != 0)
  1072. //{
  1073. // rtnResult = JsonHelper.setExceptionJson(-1, "查询结算信息失败!", errMsg).ToString();
  1074. // return rtnResult;
  1075. //}
  1076. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  1077. Global.pat.insuType = JsonHelper.getDestValue(joSettlInfo, "result.data[0].InsuranceType");
  1078. Global.pat.medType = JsonHelper.getDestValue(joSettlInfo, "result.data[0].MedicalType");
  1079. hBus.setPrmBatch();
  1080. //共济
  1081. DataTable dtSettlInfo = (DataTable)JsonConvert.DeserializeObject(joSettlInfo["result"]["data"].ToString(), (typeof(DataTable)));
  1082. int mutualAidFlag = 0;
  1083. if (!string.IsNullOrEmpty(dtSettlInfo.Rows[0]["MutualAidFlag"].ToString()))
  1084. {
  1085. mutualAidFlag = Convert.ToInt32(dtSettlInfo.Rows[0]["MutualAidFlag"].ToString());
  1086. }
  1087. if (mutualAidFlag > 0)
  1088. {
  1089. //开启自付界面,因涉及到多次自付
  1090. //MutualAid frmMA = new MutualAid(setl_id);
  1091. //if (frmMA.dtSettlInfo.Rows.Count != 0)
  1092. //{
  1093. // frmMA.WindowState = FormWindowState.Maximized;
  1094. // if (frmMA.ShowDialog() == DialogResult.OK)
  1095. // {
  1096. // }
  1097. // else
  1098. // {
  1099. // rtnResult = JsonHelper.setIrisReturnValue(-1, "收款员取消共济支付撤销!", null).ToString();
  1100. // return rtnResult;
  1101. // }
  1102. //}
  1103. //else
  1104. //{
  1105. // rtnResult = JsonHelper.setIrisReturnValue(-1, "开启共济支付失败,原因为未检测到有效的被共济人的医保结算数据!", null).ToString();
  1106. // return rtnResult;
  1107. //}
  1108. STA sta = new STA();
  1109. Thread thread = new Thread(sta.MutualAid);
  1110. thread.SetApartmentState(ApartmentState.STA); //重点
  1111. thread.IsBackground = true;
  1112. object[] o = new object[2];
  1113. o[0] = Global.pat.settlID;
  1114. thread.Start(o);
  1115. thread.Join();
  1116. //重新赋值
  1117. hBus.GetSettlementHisInfo(businessType, joInParam, out Global.pat);
  1118. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  1119. Global.pat.patExtend.prm_yabtch = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  1120. Global.pat.medType = JsonHelper.getDestValue(joSettlInfo, "result.data[0].MedicalType");
  1121. Global.pat.insuType = JsonHelper.getDestValue(joSettlInfo, "result.data[0].InsuranceType");
  1122. hBus.setPrmBatch();
  1123. }
  1124. //取消中心结算信息
  1125. if (cBus.cancleSettlement(out outParam) != 0)
  1126. {
  1127. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算信息失败!", outParam).ToString();
  1128. ////询问收款员是否继续进行HIS退费
  1129. //if (DialogResult.Yes == MessageBox.Show("中心提示:" + outParam, " 是否强制退HIS费用? ", MessageBoxButtons.YesNo))
  1130. //{
  1131. // rtnResult = JsonHelper.setExceptionJson(0, "收款员选择强制退HIS费用!", outParam).ToString();
  1132. //}
  1133. return rtnResult;
  1134. }
  1135. else
  1136. {
  1137. //确认中心结算
  1138. if (invoker.confirmYHCom(out errMsg) != 0)
  1139. {
  1140. rtnResult = JsonHelper.setExceptionJson(-1, "中心确认失败", outParam).ToString();
  1141. return rtnResult;
  1142. }
  1143. string rtn = xmler.ToJSON(outParam);
  1144. //退结算会返一个新的ID
  1145. string newSettleID = JsonHelper.getDestValue(JObject.Parse(rtn), "output.prm_yka198");
  1146. if (string.IsNullOrEmpty(newSettleID)) newSettleID = Global.pat.settlID;
  1147. //取消平台结算信息
  1148. if (mIS.cancleSettlement(newSettleID,out outParam) != 0)
  1149. {
  1150. rtnResult = JsonHelper.setExceptionJson(-1, "中心结算取消成功,医保平台结算信息取消失败!", outParam).ToString();
  1151. return rtnResult;
  1152. }
  1153. //取消HIS医保结算信息
  1154. if (hIS.cancleSettlementInfo(joParam, out outParam) != 0)
  1155. {
  1156. rtnResult = JsonHelper.setExceptionJson(-1, "中心跟医保平台结算取消成功, 取消HIS结算信息失败!", outParam).ToString();
  1157. return rtnResult;
  1158. }
  1159. //取消出院登记
  1160. if (cBus.cancleDisRegister( out outParam) != 0)
  1161. {
  1162. rtnResult = JsonHelper.setExceptionJson(0, "中心,医保平台及HIS结算信息取消成功,取消出院登记失败!请手工取消出院登记!", outParam).ToString();
  1163. return rtnResult;
  1164. }
  1165. rtnResult = JsonHelper.setIrisReturnValue(0, "取消结算成功", null).ToString();
  1166. return rtnResult;
  1167. }
  1168. }
  1169. default:
  1170. {
  1171. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", "传入的业务编码不对!").ToString();
  1172. return rtnResult;
  1173. }
  1174. }
  1175. return rtnResult;
  1176. }
  1177. catch (Exception ex)
  1178. {
  1179. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", ex.Message).ToString();
  1180. return rtnResult;
  1181. }
  1182. finally
  1183. {
  1184. Global.writeLog("Settlement 出参:" + JsonHelper.Compress(rtnResult));
  1185. }
  1186. }
  1187. /// <summary>
  1188. /// 辅助交易
  1189. /// </summary>
  1190. /// <param name="InParam"></param>
  1191. /// <returns></returns>
  1192. public string AgentFun(string InParam)
  1193. {
  1194. Global.writeLog("AgentFun 入参:" + JsonHelper.Compress(InParam));
  1195. //设置返回值,错误信息
  1196. string errMsg, rtnResult = "", outParam;
  1197. try
  1198. {
  1199. //解析入参
  1200. if (parseInparam(InParam, out errMsg) != 0)
  1201. {
  1202. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  1203. return rtnResult;
  1204. }
  1205. //BS架构调用方式问题,每次调用都需要重新初始化
  1206. if (init(InParam, out outParam) != 0)
  1207. {
  1208. rtnResult = outParam;
  1209. return rtnResult;
  1210. }
  1211. //获取pat
  1212. hBus.GetAgentFunHisInfo(businessType, joInParam, out Global.pat);
  1213. switch (businessType)
  1214. {
  1215. case "BasicData"://基础数据维护
  1216. {
  1217. STA sta = new STA();
  1218. Thread thread = new Thread(sta.BasicData);
  1219. thread.SetApartmentState(ApartmentState.STA); //重点
  1220. thread.IsBackground = true;
  1221. thread.Start();
  1222. thread.Join();
  1223. break;
  1224. }
  1225. case "Exception"://异常处理
  1226. {
  1227. STA sta = new STA();
  1228. Thread thread = new Thread(sta.Exception);
  1229. thread.SetApartmentState(ApartmentState.STA); //重点
  1230. thread.IsBackground = true;
  1231. thread.Start();
  1232. thread.Join();
  1233. break;
  1234. }
  1235. case "CheckAndClearing"://对账清算
  1236. {
  1237. STA sta = new STA();
  1238. Thread thread = new Thread(sta.CheckAndClearing);
  1239. thread.SetApartmentState(ApartmentState.STA); //重点
  1240. thread.IsBackground = true;
  1241. thread.Start();
  1242. thread.Join();
  1243. break;
  1244. }
  1245. case "Print"://打印
  1246. {
  1247. //Global.pat.adm_Dr = int.Parse(JsonHelper.getDestValue(joInsuAdmObj, "admID"));
  1248. //Global.pat.mdtrtID = JsonHelper.getDestValue(joInsuAdmObj, "mdtrt_id");
  1249. //Global.pat.settlID = JsonHelper.getDestValue(joInsuAdmObj, "setl_id");
  1250. //Thread thread = new Thread(print);
  1251. //callBack cb = new callBack(CallBack);
  1252. //thread.SetApartmentState(ApartmentState.STA); //重点
  1253. //thread.IsBackground = true;
  1254. //thread.Start();
  1255. //thread.Join();
  1256. //SettlListPrint frm = new SettlListPrint();
  1257. //if (frm.ShowDialog() == DialogResult.OK)
  1258. //{
  1259. //}
  1260. //显示打印界面
  1261. //SettlementChecklist frmSettlList;
  1262. //string inparam = joInParam.ToString() ;
  1263. //string sendData = JsonConvert.SerializeObject(inparam);
  1264. //string inpar = sendData;
  1265. //Process p = new Process();
  1266. ////p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //把窗口隐藏,使其在后台运行
  1267. //p.StartInfo.FileName = Global.curEvt.path + "\\SettlList.exe ";
  1268. //p.StartInfo.Arguments = inpar;
  1269. //p.StartInfo.CreateNoWindow = true;
  1270. //p.StartInfo.UseShellExecute = false;
  1271. //p.Start();
  1272. //p.WaitForExit();
  1273. //return JsonHelper.setIrisReturnValue(0, "", null).ToString();
  1274. //调用方式2
  1275. string exeName = "SettlList.exe ";
  1276. string exePath = Global.curEvt.path;
  1277. string inparam = joInParam.ToString();
  1278. string sendData = JsonConvert.SerializeObject(inparam);
  1279. string inpar = sendData;
  1280. Stopwatch oTime = new System.Diagnostics.Stopwatch(); //定义一个计时对象
  1281. oTime.Start();
  1282. ShellExecute(IntPtr.Zero, new StringBuilder("Open"), new StringBuilder(exeName), new StringBuilder(inpar), new StringBuilder(exePath), 1);
  1283. oTime.Stop();
  1284. Global.writeLog("调用:" +oTime.Elapsed.TotalMilliseconds.ToString());
  1285. return JsonHelper.setIrisReturnValue(0, "", null).ToString();
  1286. }
  1287. case "Log"://日志
  1288. {
  1289. MessageBox.Show(businessType);
  1290. break;
  1291. }
  1292. case "RecordUpload"://上传记录
  1293. {
  1294. MessageBox.Show(businessType);
  1295. break;
  1296. }
  1297. case "HospitalRegister"://备案
  1298. {
  1299. MessageBox.Show(businessType);
  1300. break;
  1301. }
  1302. case "CenterQuery1":// 中心提供的查询服务1
  1303. {
  1304. break;
  1305. }
  1306. case "MutualAid"://共济结算
  1307. {
  1308. STA sta = new STA();
  1309. Thread thread = new Thread(new ParameterizedThreadStart(sta.MutualAid));
  1310. thread.SetApartmentState(ApartmentState.STA); //重点
  1311. thread.IsBackground = true;
  1312. object[] o = new object[2];
  1313. o[0] = "123456";
  1314. thread.Start(o);
  1315. thread.Join();
  1316. rtnResult = (string)o[1];
  1317. //MutualAid frmMA = new MutualAid();
  1318. //frmMA.WindowState = FormWindowState.Maximized;
  1319. //frmMA.ShowDialog();
  1320. break;
  1321. }
  1322. case "PreAndInProcessAnalysis"://事前分析 诊间只有住院的事前分析
  1323. {
  1324. Global.pat.adm_Dr = int.Parse(JsonHelper.getDestValue(joInParam, "params[0].admID"));
  1325. //Global.pat.adm_Dr = int.Parse(JsonHelper.getDestValue(joInParam, "params[0].admID"));
  1326. //Global.pat.adm_Dr = int.Parse(JsonHelper.getDestValue(joInParam, "params[0].admID"));
  1327. JObject joResult = new JObject();
  1328. joResult.Add("result", JObject.Parse(JsonHelper.getDestValue(joParam, "insuData")));
  1329. //事前分析
  1330. if (Global.curEvt.ext.isOpenAnalysis)
  1331. {
  1332. if (hBus.PreAnalysis("5",joResult.ToString(), out errMsg) != 0)
  1333. {
  1334. MessageBox.Show(errMsg);
  1335. break;
  1336. }
  1337. }
  1338. break; //
  1339. }
  1340. case "MaternityInsuranceRegist"://生育门诊登记
  1341. {
  1342. STA sta = new STA();
  1343. Thread thread = new Thread(sta.MaternityInsuranceRegist);
  1344. thread.SetApartmentState(ApartmentState.STA); //重点
  1345. thread.IsBackground = true;
  1346. thread.Start();
  1347. thread.Join();
  1348. break;
  1349. }
  1350. case "SettlementWithNopwdApply"://对账清算
  1351. {
  1352. STA sta = new STA();
  1353. Thread thread = new Thread(sta.SettlementWithNopwdApply);
  1354. thread.SetApartmentState(ApartmentState.STA); //重点
  1355. thread.IsBackground = true;
  1356. thread.Start();
  1357. thread.Join();
  1358. break;
  1359. }
  1360. default:
  1361. {
  1362. rtnResult = JsonHelper.setExceptionJson(-1, "AgentFun 交易", "传入的业务编码不对!").ToString();
  1363. return rtnResult;
  1364. }
  1365. }
  1366. return rtnResult;
  1367. }
  1368. catch (Exception ex)
  1369. {
  1370. rtnResult = JsonHelper.setExceptionJson(-1, "AgentFun 交易", ex.Message).ToString();
  1371. return rtnResult;
  1372. }
  1373. finally
  1374. {
  1375. Global.writeLog("AgentFun 出参:" + JsonHelper.Compress(rtnResult));
  1376. }
  1377. }
  1378. public string Download(string InParam)
  1379. {
  1380. return "";
  1381. }
  1382. public string PlatformDirectConnect(string InParam)
  1383. {
  1384. //设置返回值,错误信息
  1385. int errCode;
  1386. string errMsg, rtnResult = "", outParam;
  1387. try
  1388. {
  1389. Global.writeLog("PlatformDirectConnect 入参:" + JsonHelper.Compress(InParam));
  1390. //解析入参
  1391. if (parseInparam(InParam, out errMsg) != 0)
  1392. {
  1393. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  1394. return rtnResult;
  1395. }
  1396. Global.businessType = businessType;
  1397. string funNO = JsonHelper.getDestValue(joInParam,"funNO");
  1398. //BS架构调用方式问题,每次调用都需要重新初始化
  1399. if (init(InParam, out outParam) != 0)
  1400. {
  1401. rtnResult = outParam;
  1402. return rtnResult;
  1403. }
  1404. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joInParam, "insuplc_admdvs");
  1405. if (invoker.invokeYHCom(funNO, joParam ,out errMsg) != 0)
  1406. {
  1407. rtnResult = JsonHelper.setExceptionJson(-1, "平台直连错误", errMsg).ToString();
  1408. return rtnResult;
  1409. }
  1410. else
  1411. {
  1412. JObject joRtn = new JObject();
  1413. joRtn.Add("result",errMsg);
  1414. rtnResult = JsonHelper.setIrisReturnValue(0, "", joRtn).ToString();
  1415. return rtnResult;
  1416. }
  1417. }
  1418. catch (Exception ex)
  1419. {
  1420. rtnResult = JsonHelper.setExceptionJson(-1, "PlatformDirectConnect 交易", ex.Message).ToString();
  1421. return rtnResult;
  1422. }
  1423. finally
  1424. {
  1425. Global.writeLog("PlatformDirectConnect 出参:" + JsonHelper.Compress(rtnResult));
  1426. }
  1427. }
  1428. #endregion
  1429. }
  1430. }