InsuBusiness.cs 81 KB

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