InsuBusiness.cs 81 KB

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