InsuBusiness.cs 82 KB

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