InsuBusiness.cs 79 KB

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