InsuBusiness.cs 81 KB

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