InsuBusiness.cs 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679
  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. //事前分析
  723. if (Global.curEvt.ext.isOpenAnalysis)
  724. {
  725. if (hBus.PreAnalysis("1", "", out errMsg) != 0)
  726. {
  727. rtnResult = JsonHelper.setExceptionJson(-1, "门诊就诊信息上传成功后调用3101事前服务失败:", errMsg).ToString();
  728. return rtnResult;
  729. }
  730. }
  731. #endregion
  732. #region 费用上传[2204]
  733. if (hBus.uploadFee("2204", 50, out outParam) != 0)
  734. {
  735. rtnResult = JsonHelper.setExceptionJson(-1, "费用上传", outParam).ToString();
  736. return rtnResult;
  737. }
  738. #endregion
  739. #region【门诊预结算2206前调用3102医保明细审核事中服务】
  740. //1.获取3102入参报文
  741. //事前分析
  742. if ((Global.curEvt.ext.isOpenAnalysis) && (Global.operationType == OperationType.SettlementOP))
  743. {
  744. if (hBus.PreAnalysis("2", "", out errMsg) != 0)
  745. {
  746. rtnResult = JsonHelper.setExceptionJson(-1, "【3102】医保明细审核事中分析服务调用失败:", errMsg).ToString();
  747. return rtnResult;
  748. }
  749. }
  750. #endregion
  751. #region 门诊预结算[2206]
  752. //调用IRIS获取医保各项金额
  753. if (mIS.getSumFee(out outParam) != 0)
  754. {
  755. rtnResult = JsonHelper.setExceptionJson(-1, "获取医保费用各项汇总金额", outParam).ToString();
  756. return rtnResult;
  757. }
  758. JObject joSumFee = JObject.Parse(outParam);
  759. JObject joSettlement = JObject.Parse(JsonHelper.getDestValue(joReg, "settlement"));
  760. //修改joSettlement的就诊ID ,总金额等
  761. joSettlement["mdtrt_id"] = Global.pat.mdtrtID;
  762. joSettlement["medfee_sumamt"] = JsonHelper.getDestValue(joSumFee, "data.Sumamt");
  763. if ("RegisterOP".Equals(operationType))
  764. {
  765. // 门诊挂号(医疗类别)
  766. joSettlement["med_type"] = "12";
  767. }
  768. //预结算2206
  769. if (hBus.preSettlement_OutPat(joSettlement, out outParam) != 0)
  770. {
  771. rtnResult = JsonHelper.setExceptionJson(-1, "结算信息展示", outParam).ToString();
  772. return rtnResult;
  773. }
  774. #endregion
  775. #region【门诊正式结算前调用1192身份验证】重庆无?
  776. //if (hBus.IdentityVerify("2207", out errMsg) != 0)
  777. //{
  778. // rtnResult = JsonHelper.setExceptionJson(-1, "调用门诊正式结算2207前,身份核验1192失败", errMsg).ToString();
  779. // return rtnResult;
  780. //}
  781. //else
  782. //{
  783. // JObject joDataExp = new JObject();
  784. // joDataExp.Add("cardtoken", Global.pat.card.Cardtoken);
  785. // joDataExp.Add("acct_payamt", Global.Set.acctPay);
  786. // joDataExp.Add("elec_bill_code", "");
  787. // joDataExp.Add("elec_billno_code", "");
  788. // joDataExp.Add("elec_bill_chkcode", "");
  789. // joSettlement["exp_content"] = joDataExp;
  790. //}
  791. #endregion
  792. # region 正式结算[2207]
  793. JObject joData = new JObject();
  794. joData.Add("data",joSettlement);
  795. JObject joRtn = invoker.invokeCenterService("2207", JsonHelper.setCenterInpar("2207", joData));
  796. if (JsonHelper.parseCenterRtnValue(joRtn, out errMsg) != 0)
  797. {
  798. rtnResult = JsonHelper.setExceptionJson(-1, "结算失败", errMsg).ToString();
  799. return rtnResult;
  800. }
  801. else
  802. {
  803. Global.pat.admType = 1;
  804. Global.pat.ExpContent = ""; //门诊不需要保存 外伤标志等相关扩展参数
  805. //返回给云医保平台结算信息
  806. if (mIS.saveSettlement(joRtn, out errMsg) != 0)
  807. {
  808. rtnResult = JsonHelper.setExceptionJson(-1, "结算成功,但云医保平台保存失败", errMsg).ToString();
  809. return rtnResult;
  810. }
  811. //返回给云医保平台结算明细信息
  812. if (mIS.saveSettlementDetail(joRtn, out errMsg) != 0)
  813. {
  814. rtnResult = JsonHelper.setExceptionJson(-1, "云医保平台保存结算明细失败", errMsg).ToString();
  815. return rtnResult;
  816. }
  817. //返回给HIS
  818. JObject joSetlinfo = JObject.Parse(JsonHelper.getDestValue(joRtn, "output.setlinfo"));
  819. if (hIS.returnOutpatSettlementInfo(joSettlement, joSetlinfo, out outParam) != 0)
  820. {
  821. rtnResult = JsonHelper.setExceptionJson(-1, "返回结算信息给HIS", outParam).ToString();
  822. return rtnResult;
  823. }
  824. else
  825. {
  826. JObject joHisServieRtn = JObject.Parse(outParam);
  827. hBus.returnToFrontEndAfterSettlement(joRtn, joHisServieRtn, out outParam);
  828. rtnResult = JsonHelper.setIrisReturnValue(0, "结算成功", JObject.Parse(outParam)).ToString();
  829. return rtnResult;
  830. }
  831. }
  832. #endregion
  833. }
  834. case "M5C"://门诊结算撤销
  835. {
  836. #region 查询结算信息
  837. //查询HIS医保结算记录表获取该病人的参保地
  838. string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE billType = 1 and ValidFlag = 1 ";
  839. sqlStr = sqlStr + " AND Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr;
  840. sqlStr = sqlStr + " AND SettlementID ='" + Global.pat.settlID + "'";
  841. JObject joSql = new JObject();
  842. joSql.Add("sqlStr", sqlStr);
  843. JObject joSettlInfo = mIS.QuerySettlementInfo(joSql);
  844. //if (JsonHelper.parseIrisRtnValue(joSettlInfo, out errMsg) != 0)
  845. //{
  846. // rtnResult = JsonHelper.setExceptionJson(-1, "查询结算信息失败!", errMsg).ToString();
  847. // return rtnResult;
  848. //}
  849. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  850. #endregion
  851. #region 门诊结算撤销 [2208]
  852. string newSettleID = "";
  853. if (cBus.cancleSettlement("2208", out outParam) != 0)
  854. {
  855. int i = outParam.IndexOf("获取到的就诊信息为无效状态,不能办理结算撤销业务");
  856. if (i != 0)
  857. {
  858. if (DialogResult.Yes != MessageBox.Show("医保中心提示:" + outParam + ",是否强制撤销HIS结算信息?", "提示", MessageBoxButtons.YesNo))
  859. {
  860. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消结算失败,", outParam).ToString();
  861. return rtnResult;
  862. }
  863. newSettleID = "YC";
  864. }
  865. else
  866. {
  867. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算", outParam).ToString();
  868. //查看是医保平台是否已经退费,如果是,则询问是否继续退费
  869. string SqlStr = " SELECT * FROM BS_MedInsuSettlement WHERE ValidFlag = 0 AND BillType = -1 ";
  870. SqlStr = SqlStr + " AND Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr;
  871. SqlStr = SqlStr + " AND SettlementID ='" + Global.pat.settlID + "'";
  872. JObject joSqlStr = new JObject();
  873. joSqlStr.Add("sqlStr", SqlStr);
  874. JObject joCancleSettlInfo = mIS.QuerySettlementInfo(joSqlStr);
  875. JArray jaCancleSettlInfo = JArray.Parse(JsonHelper.getDestValue(joCancleSettlInfo, "result.data"));
  876. if (jaCancleSettlInfo.Count == 1)
  877. {
  878. //询问收款员是否继续进行HIS退费
  879. if (DialogResult.Yes == MessageBox.Show("中心提示:" + outParam, " 该费用在医保中心已成功退费但在HIS未成功退费,是否强制退HIS费用? ", MessageBoxButtons.YesNo))
  880. {
  881. rtnResult = JsonHelper.setExceptionJson(0, "该费用在医保中心已成功退费但在HIS未成功退费,收款员选择强制退HIS费用!", outParam).ToString();
  882. }
  883. }
  884. else
  885. {
  886. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算(云医保平台未退费或未查询到退费记录)", outParam).ToString();
  887. }
  888. return rtnResult;
  889. }
  890. }
  891. else
  892. {
  893. newSettleID = JsonHelper.getDestValue(JObject.Parse(outParam), "output.setlinfo.setl_id");
  894. }
  895. //退云医保平台结算
  896. if (mIS.cancleSettlement(newSettleID, out outParam) != 0)
  897. {
  898. rtnResult = JsonHelper.setExceptionJson(-1, "取消平台结算信息", outParam).ToString();
  899. //return rtnResult;
  900. }
  901. #endregion
  902. #region 费用明细取消[2205]
  903. //中心取消传送
  904. if (cBus.cancleFeeUpload("2205", out errMsg) != 0)
  905. {
  906. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心费用", errMsg).ToString();
  907. return rtnResult;
  908. }
  909. //云平台取消传送
  910. if (mIS.deleteFee(out errMsg) != 0)
  911. {
  912. rtnResult = JsonHelper.setExceptionJson(-1, "删除医保平台费用", errMsg).ToString();
  913. return rtnResult;
  914. }
  915. #endregion
  916. #region 取消挂号[2202]
  917. //取消中心登记
  918. if (cBus.cancleRegister("2202", out outParam) != 0)
  919. {
  920. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记失败,", outParam).ToString();
  921. return rtnResult;
  922. }
  923. //取消医保平台登记
  924. if (mIS.cancleRegister(3, out outParam) != 0)
  925. {
  926. rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记成功,但云医保平台取消失败,", outParam).ToString();
  927. return rtnResult;
  928. }
  929. #endregion
  930. #region 退HIS结算
  931. if (hIS.cancleSettlementInfo(joParam, out outParam) != 0)
  932. {
  933. rtnResult = JsonHelper.setExceptionJson(-1, "取消HIS结算信息", outParam).ToString();
  934. return rtnResult;
  935. }
  936. else
  937. {
  938. rtnResult = JsonHelper.setIrisReturnValue(0, "取消结算成功", null).ToString();
  939. return rtnResult;
  940. }
  941. #endregion
  942. }
  943. case "M6"://门诊移动支付结算
  944. {
  945. MobilePay mp = new MobilePay(InParam, out errMsg);
  946. if (errMsg != "")
  947. {
  948. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  949. return rtnResult;
  950. }
  951. if (mp.MobilePaySettlement(out outParam) != 0)
  952. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
  953. else
  954. rtnResult = outParam;
  955. return rtnResult;
  956. }
  957. case "M6C"://门诊移动支付结算撤销
  958. {
  959. string onlineYBFalg = JsonHelper.getDestValue(joInsuAdmObj, "onlineYBFalg");
  960. MobilePay mp = new MobilePay(InParam, out errMsg);
  961. if (errMsg != "")
  962. {
  963. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  964. return rtnResult;
  965. }
  966. if (String.IsNullOrEmpty(onlineYBFalg))
  967. {
  968. mp.MSettl.onlineYBFalg = "N";
  969. }
  970. else
  971. {
  972. mp.MSettl.onlineYBFalg = onlineYBFalg;
  973. }
  974. if (mp.MobilePayCancelSettlement(out outParam) != 0)
  975. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
  976. else
  977. rtnResult = outParam;
  978. return rtnResult;
  979. }
  980. case "M6Confirm"://门诊移动支付确认
  981. {
  982. MobilePay mp = new MobilePay(InParam, out errMsg);
  983. if (errMsg != "")
  984. {
  985. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
  986. return rtnResult;
  987. }
  988. if (mp.MobilePayConfirmSettlement(out outParam) != 0)
  989. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
  990. else
  991. rtnResult = outParam;
  992. return rtnResult;
  993. }
  994. case "Z4"://住院预结算
  995. {
  996. #region 预结算(需先进行调用费用明细上传)
  997. Global.pat.RYorCY = "2";
  998. JObject joSettle = new JObject();
  999. if (hBus.preSettlement("2303",out joSettle, out outParam) != 0)
  1000. {
  1001. rtnResult = JsonHelper.setExceptionJson(-1, "结算信息展示", outParam).ToString();
  1002. return rtnResult;
  1003. }
  1004. else
  1005. {
  1006. rtnResult = JsonHelper.setIrisReturnValue(0, "预结算成功", null).ToString();
  1007. return rtnResult;
  1008. }
  1009. #endregion
  1010. }
  1011. case "Z4C"://住院预结算撤销
  1012. {
  1013. rtnResult = JsonHelper.setExceptionJson(-100, "该接口不支持预结算取消!", null).ToString();
  1014. return rtnResult;
  1015. }
  1016. case "Z5"://住院结算
  1017. {
  1018. #region【住院预结算2303前调用3102医保明细审核事中服务】
  1019. //1.获取3102入参报文
  1020. /*
  1021. if (hIS.GetInsuPatInfo("9", Global.pat, out outParam) != 0)
  1022. {
  1023. rtnResult = JsonHelper.setExceptionJson(-1, "获取3102医保明细审核事中分析服务入参失败:", outParam).ToString();
  1024. return rtnResult;
  1025. }
  1026. else
  1027. {
  1028. //2.调用医保3102明细审核事前分析服务
  1029. JObject joInput = new JObject();
  1030. joInput = JObject.Parse(outParam);
  1031. JObject jo3102Rtn = invoker.invokeCenterService("3102", JsonHelper.setCenterInpar("3102", joInput.ToString().Replace("\r\n", "")));
  1032. if (JsonHelper.parseCenterRtnValue(jo3102Rtn, out errMsg) != 0)
  1033. {
  1034. DialogResult dr = MessageBox.Show("【3102】医保明细审核事中分析服务医保中心返回结果1:" + errMsg + "!是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1035. if (dr != DialogResult.OK)
  1036. {
  1037. rtnResult = JsonHelper.setExceptionJson(-1, "【3102】医保明细审核事中分析服务调用失败:", errMsg).ToString();
  1038. return rtnResult;
  1039. }
  1040. }
  1041. }
  1042. */
  1043. #endregion
  1044. Global.pat.admType = 2;
  1045. Global.pat.RYorCY = "2";
  1046. #region【住院预结算前调用1192身份验证】
  1047. //if (hBus.IdentityVerify("2304", out errMsg) != 0)
  1048. //{
  1049. // rtnResult = JsonHelper.setExceptionJson(-1, "调用住院正式结算2304前,身份核验1192失败", errMsg).ToString();
  1050. // return rtnResult;
  1051. //}
  1052. #endregion
  1053. JObject joPreSetOutpar ;
  1054. // 结算前先调用预结算?
  1055. if (hBus.preSettlement("2303",out joPreSetOutpar, out outParam) != 0)
  1056. {
  1057. rtnResult = JsonHelper.setExceptionJson(-1, "结算信息展示", outParam).ToString();
  1058. return rtnResult;
  1059. }
  1060. else
  1061. {
  1062. #region【住院正式结算前调用1192身份验证】
  1063. //if (hBus.IdentityVerify("2304", out errMsg) != 0)
  1064. //{
  1065. // rtnResult = JsonHelper.setExceptionJson(-1, "调用住院正式结算2304前,身份核验1192失败", errMsg).ToString();
  1066. // return rtnResult;
  1067. //}
  1068. //else
  1069. //{
  1070. // JObject joDataExp = new JObject();
  1071. // joDataExp.Add("cardtoken", Global.pat.card.Cardtoken);
  1072. // joDataExp.Add("acct_payamt", Global.Set.acctPay);
  1073. // joDataExp.Add("elec_bill_code", "");
  1074. // joDataExp.Add("elec_billno_code", "");
  1075. // joDataExp.Add("elec_bill_chkcode", "");
  1076. // joSettlement["exp_content"] = joDataExp;
  1077. //}
  1078. #endregion
  1079. #region 正式出院结算
  1080. JObject joSettlement = joSettlement = JObject.Parse(JsonHelper.getDestValue(joPreSetOutpar, "Settlement"));
  1081. JObject joDataExp = new JObject();
  1082. joDataExp.Add("cardtoken", Global.pat.card.Cardtoken);
  1083. joDataExp.Add("acct_payamt", Global.Set.acctPay);
  1084. joDataExp.Add("elec_bill_code", "");
  1085. joDataExp.Add("elec_billno_code", "");
  1086. joDataExp.Add("elec_bill_chkcode", "");
  1087. joSettlement["exp_content"] = joDataExp;
  1088. joSettlement.Add("data", joSettlement);
  1089. JObject jo2304Rtn = invoker.invokeCenterService("2304",JsonHelper.setCenterInpar("2304",joSettlement));
  1090. if (JsonHelper.parseCenterRtnValue(jo2304Rtn, out errMsg) != 0)
  1091. {
  1092. rtnResult = JsonHelper.setExceptionJson(-1, "结算失败", errMsg).ToString();
  1093. cBus.cancleRegister("2405", out errMsg);
  1094. return rtnResult;
  1095. }
  1096. else
  1097. {
  1098. Global.pat.admType = 2;
  1099. //返回给云医保平台结算信息
  1100. if (mIS.saveSettlement(jo2304Rtn, out errMsg) != 0)
  1101. {
  1102. rtnResult = JsonHelper.setExceptionJson(-1, "结算成功,但云医保平台保存失败", errMsg).ToString();
  1103. return rtnResult;
  1104. }
  1105. //返回给云医保平台结算明细信息
  1106. if (mIS.saveSettlementDetail(jo2304Rtn, out errMsg) != 0)
  1107. {
  1108. rtnResult = JsonHelper.setExceptionJson(-1, "云医保平台保存结算明细失败", errMsg).ToString();
  1109. Global.writeLog(rtnResult);
  1110. MessageBox.Show(errMsg);
  1111. }
  1112. //返回给HIS
  1113. JObject joSetlinfo = JObject.Parse(JsonHelper.getDestValue(jo2304Rtn, "output.setlinfo"));
  1114. if (hIS.returnInpatSettlementInfo(joParam, joSetlinfo, out outParam) != 0)
  1115. {
  1116. rtnResult = JsonHelper.setExceptionJson(-1, "返回结算信息给HIS", outParam).ToString();
  1117. return rtnResult;
  1118. }
  1119. else
  1120. {
  1121. //返回给前端
  1122. JObject joHisServieRtn = JObject.Parse(outParam);
  1123. hBus.returnToFrontEndAfterSettlement(jo2304Rtn, joHisServieRtn, out outParam);
  1124. rtnResult = JsonHelper.setIrisReturnValue(0, "结算成功", JObject.Parse(outParam)).ToString();
  1125. return rtnResult;
  1126. }
  1127. }
  1128. #endregion
  1129. }
  1130. }
  1131. case "Z5C"://住院结算撤销
  1132. {
  1133. //查询结算表
  1134. string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE billType = 1 and Hospital_Dr=" + Global.inf.hospitalDr
  1135. + " and Adm_Dr='" + Global.pat.adm_Dr + "'"
  1136. + " and MdtrtID='" + Global.pat.mdtrtID + "'"
  1137. + " Order By ID DESC ";
  1138. JObject joSql = new JObject();
  1139. joSql.Add("sqlStr", sqlStr);
  1140. JObject joSettlInfo = mIS.QuerySettlementInfo(joSql);
  1141. //if (JsonHelper.parseIrisRtnValue(joSettlInfo, out errMsg) != 0)
  1142. //{
  1143. // rtnResult = JsonHelper.setExceptionJson(-1, "查询结算信息失败!", errMsg).ToString();
  1144. // return rtnResult;
  1145. //}
  1146. //MessageBox.Show(joSettlInfo.ToString());
  1147. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");
  1148. Global.pat.SettID_YBJSB = JsonHelper.getDestValue(joSettlInfo, "result.data[0].SettlementID");
  1149. if (Global.pat.settlID != Global.pat.SettID_YBJSB)
  1150. {
  1151. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", "通过09010059服务获取到的SettlementID<" + Global.pat.settlID + ">与DLL通过SQL语句" +
  1152. joSql + ",获取到的SettlementID<" + Global.pat.SettID_YBJSB + ">不同,可能存在HIS单边账,请联系医保开发人员处理该笔结算记录!").ToString();
  1153. //return rtnResult;
  1154. }
  1155. Global.pat.settlID = Global.pat.SettID_YBJSB;
  1156. //取消中心结算信息
  1157. if (cBus.cancleSettlement("2305", out outParam) != 0)
  1158. {
  1159. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算信息失败!", outParam).ToString();
  1160. //查看是医保平台是否已经退费,如果是,则询问是否继续退费
  1161. string SqlStr = " SELECT * FROM BS_MedInsuSettlement WHERE ValidFlag = 0 AND BillType = -1 ";
  1162. SqlStr = SqlStr + " AND Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr;
  1163. SqlStr = SqlStr + " AND SettlementID ='" + Global.pat.settlID + "'";
  1164. JObject joSqlStr = new JObject();
  1165. joSqlStr.Add("sqlStr", SqlStr);
  1166. JObject joCancleSettlInfo = mIS.QuerySettlementInfo(joSqlStr);
  1167. JArray jaCancleSettlInfo = JArray.Parse(JsonHelper.getDestValue(joCancleSettlInfo, "result.data"));
  1168. if (jaCancleSettlInfo.Count == 1)
  1169. {
  1170. //询问收款员是否继续进行HIS退费
  1171. if (DialogResult.Yes == MessageBox.Show("中心提示:" + outParam, " 该费用在医保中心已成功退费但在HIS未成功退费,是否强制退HIS费用? ", MessageBoxButtons.YesNo))
  1172. {
  1173. rtnResult = JsonHelper.setExceptionJson(0, "该费用在医保中心已成功退费但在HIS未成功退费,收款员选择强制退HIS费用!", outParam).ToString();
  1174. }
  1175. }
  1176. else
  1177. {
  1178. rtnResult = JsonHelper.setExceptionJson(-1, "取消中心结算(云医保平台未退费或未查询到退费记录)", outParam).ToString();
  1179. }
  1180. return rtnResult;
  1181. }
  1182. else
  1183. {
  1184. //退结算会返一个新的ID
  1185. string newSettleID = JsonHelper.getDestValue(JObject.Parse(outParam), "output.setlinfo.setl_id");
  1186. //取消平台结算信息
  1187. if (mIS.cancleSettlement(newSettleID, out outParam) != 0)
  1188. {
  1189. rtnResult = JsonHelper.setExceptionJson(-1, "中心结算取消成功,医保平台结算信息取消失败!", outParam).ToString();
  1190. return rtnResult;
  1191. }
  1192. //取消出院登记
  1193. if (cBus.cancleRegister("2405", out outParam) != 0)
  1194. {
  1195. rtnResult = JsonHelper.setExceptionJson(0, "中心,医保平台及HIS结算信息取消成功,取消出院登记失败!请手工取消出院登记!", outParam).ToString();
  1196. return rtnResult;
  1197. }
  1198. //中心取消传送
  1199. if (cBus.cancleFeeUpload("2302", out errMsg) != 0)
  1200. {
  1201. //rtnResult = JsonHelper.setExceptionJson(-1, "取消中心费用", errMsg).ToString();
  1202. //return rtnResult;
  1203. }
  1204. //云平台取消传送
  1205. if (mIS.deleteFee(out errMsg) != 0)
  1206. {
  1207. //rtnResult = JsonHelper.setExceptionJson(-1, "删除医保平台费用", errMsg).ToString();
  1208. //return rtnResult;
  1209. }
  1210. //取消HIS医保结算信息
  1211. if (hIS.cancleSettlementInfo(joParam, out outParam) != 0)
  1212. {
  1213. rtnResult = JsonHelper.setExceptionJson(-1, "中心跟医保平台结算取消成功, 取消HIS结算信息失败!", outParam).ToString();
  1214. return rtnResult;
  1215. }
  1216. rtnResult = JsonHelper.setIrisReturnValue(0, "取消结算成功", null).ToString();
  1217. return rtnResult;
  1218. }
  1219. }
  1220. default:
  1221. {
  1222. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", "传入的业务编码不对!").ToString();
  1223. return rtnResult;
  1224. }
  1225. }
  1226. return rtnResult;
  1227. }
  1228. catch (Exception ex)
  1229. {
  1230. rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", ex.Message).ToString();
  1231. return rtnResult;
  1232. }
  1233. finally
  1234. {
  1235. Global.writeLog("Settlement 出参:" + JsonHelper.Compress(rtnResult));
  1236. }
  1237. }
  1238. //[STAThread]
  1239. //public void print(JObject joInParam)
  1240. //{
  1241. // //显示打印界面
  1242. // SettlementChecklist frmSettlList;
  1243. // string insuAdmObj = JsonHelper.getDestValue(joInParam, "insuAdmObj");
  1244. // if (insuAdmObj == "")
  1245. // {
  1246. // frmSettlList = new SettlementChecklist();
  1247. // }
  1248. // else
  1249. // {
  1250. // JObject joInsuAdmObj = JObject.Parse(insuAdmObj);
  1251. // frmSettlList = new SettlementChecklist(joInsuAdmObj);
  1252. // }
  1253. // if (frmSettlList.ShowDialog() == DialogResult.OK)
  1254. // {
  1255. // };
  1256. //}
  1257. //[STAThread]
  1258. /// <summary>
  1259. /// 辅助交易
  1260. /// </summary>
  1261. /// <param name="InParam"></param>
  1262. /// <returns></returns>
  1263. public string AgentFun(string InParam)
  1264. {
  1265. Global.writeLog("AgentFun 入参:" + JsonHelper.Compress(InParam));
  1266. //设置返回值,错误信息
  1267. int errCode;
  1268. string errMsg, rtnResult = "", outParam;
  1269. try
  1270. {
  1271. //解析入参
  1272. if (parseInparam(InParam, out errMsg) != 0)
  1273. {
  1274. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  1275. return rtnResult;
  1276. }
  1277. //BS架构调用方式问题,每次调用都需要重新初始化
  1278. if (init(InParam, out outParam) != 0)
  1279. {
  1280. Global.writeLog("初始化异常:" + outParam);
  1281. rtnResult = outParam;
  1282. // 基础数据没有初始化成功,也可以运行
  1283. if (!businessType.Equals("BasicData"))
  1284. {
  1285. return rtnResult;
  1286. }
  1287. }
  1288. //获取pat
  1289. hBus.GetAgentFunHisInfo(businessType, joInParam, out Global.pat);
  1290. switch (businessType)
  1291. {
  1292. case "BasicData"://基础数据维护
  1293. {
  1294. BasicData bd = new BasicData();
  1295. bd.ShowDialog();
  1296. break;
  1297. }
  1298. case "Exception"://异常处理
  1299. {
  1300. //显示异常处理界面
  1301. HandleException frmEX = new HandleException();
  1302. if (frmEX.ShowDialog() == DialogResult.OK)
  1303. {
  1304. }
  1305. break;
  1306. }
  1307. case "CheckAndClearing"://对账清算
  1308. {
  1309. Clearing frmEX = new Clearing();
  1310. if (frmEX.ShowDialog() == DialogResult.OK)
  1311. {
  1312. }
  1313. break;
  1314. }
  1315. case "Print"://打印
  1316. {
  1317. try
  1318. {
  1319. //显示打印界面
  1320. SettlementChecklist frmSettlList;
  1321. string insuAdmObj = JsonHelper.getDestValue(joInParam, "insuAdmObj");
  1322. if (insuAdmObj == "")
  1323. {
  1324. frmSettlList = new SettlementChecklist();
  1325. frmSettlList.ShowDialog();
  1326. }
  1327. else
  1328. {
  1329. JObject joInsuAdmObj = JObject.Parse(insuAdmObj);
  1330. frmSettlList = new SettlementChecklist(joInsuAdmObj);
  1331. string groupID = JsonHelper.getDestValue((JObject)Global.curEvt.jaSession[0], "groupID");
  1332. DataTable dt = (DataTable)frmSettlList.dgvSettlRecord.DataSource;
  1333. if (dt.Rows.Count != 1)
  1334. {
  1335. frmSettlList.ShowDialog();
  1336. }
  1337. else
  1338. {
  1339. frmSettlList.btnPrint_Click(null, null);
  1340. }
  1341. }
  1342. return JsonHelper.setIrisReturnValue(0, "", null).ToString();
  1343. }
  1344. catch (Exception ex)
  1345. {
  1346. MessageBox.Show(ex.Message);
  1347. }
  1348. break;
  1349. }
  1350. case "Log"://日志
  1351. {
  1352. MessageBox.Show(businessType);
  1353. break;
  1354. }
  1355. case "RecordUpload"://上传记录
  1356. {
  1357. MessageBox.Show(businessType);
  1358. break;
  1359. }
  1360. case "HospitalRegister"://备案
  1361. {
  1362. ToRecordChoose Referral = new ToRecordChoose();
  1363. Referral.ShowDialog();
  1364. break;
  1365. }
  1366. case "PreAndInProcessAnalysis"://事前分析 诊间只有住院的事前分析
  1367. {
  1368. Global.pat.adm_Dr = JsonHelper.getDestValue(joInParam, "params[0].admID");
  1369. JObject joResult = new JObject();
  1370. joResult.Add("result", JObject.Parse(JsonHelper.getDestValue(joParam, "insuData")));
  1371. //事前分析
  1372. if (Global.curEvt.ext.isOpenAnalysis)
  1373. {
  1374. if (hBus.PreAnalysis("5", joResult.ToString(), out errMsg) != 0)
  1375. {
  1376. MessageBox.Show(errMsg);
  1377. break;
  1378. }
  1379. }
  1380. break;
  1381. }
  1382. case "PrescribeCirculation"://处方流转
  1383. {
  1384. PrescriptionCirculation PresCir = new PrescriptionCirculation();
  1385. PresCir.ShowDialog();
  1386. break;
  1387. }
  1388. default:
  1389. {
  1390. rtnResult = JsonHelper.setExceptionJson(-1, "AgentFun 交易", "传入的业务编码不对!").ToString();
  1391. return rtnResult;
  1392. }
  1393. }
  1394. return rtnResult;
  1395. }
  1396. catch (Exception ex)
  1397. {
  1398. rtnResult = JsonHelper.setExceptionJson(-1, "AgentFun 交易", ex.Message).ToString();
  1399. return rtnResult;
  1400. }
  1401. finally
  1402. {
  1403. Global.writeLog("AgentFun 出参:" + JsonHelper.Compress(rtnResult));
  1404. }
  1405. }
  1406. public string Download(string InParam)
  1407. {
  1408. Global.writeLog("Download 入参:" + JsonHelper.Compress(InParam));
  1409. //设置返回值,错误信息
  1410. int errCode;
  1411. string errMsg, rtnResult = "", outParam;
  1412. try
  1413. {
  1414. //解析入参
  1415. if (parseInparam(InParam, out errMsg) != 0)
  1416. {
  1417. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  1418. return rtnResult;
  1419. }
  1420. //BS架构调用方式问题,每次调用都需要重新初始化
  1421. if (init(InParam, out outParam) != 0)
  1422. {
  1423. rtnResult = outParam;
  1424. return rtnResult;
  1425. }
  1426. dynamic joData = new JObject();
  1427. joData.data = joParam["data"];
  1428. //string code = (string)joInParam["code"];
  1429. string funNO = (string)joParam["funNO"];
  1430. switch (businessType)
  1431. {
  1432. case "DirectoryDownload":
  1433. {
  1434. string downloadParam = JsonHelper.setCenterInpar(funNO, joData.ToString());
  1435. rtnResult = hBus.DownloadDirectory(funNO, downloadParam).ToString();
  1436. break;
  1437. }
  1438. case "DictionayDownload":
  1439. {
  1440. string downloadParam = JsonHelper.setCenterInpar(funNO, joData.ToString());
  1441. rtnResult = hBus.downDictionary(downloadParam);
  1442. break;
  1443. }
  1444. }
  1445. return rtnResult;
  1446. }
  1447. catch (Exception ex)
  1448. {
  1449. rtnResult = JsonHelper.setExceptionJson(-100, "Download", ex.Message).ToString();
  1450. return rtnResult;
  1451. }
  1452. finally
  1453. {
  1454. Global.writeLog("Download 出参:" + rtnResult);
  1455. }
  1456. }
  1457. public string PlatformDirectConnect(string InParam)
  1458. {
  1459. //设置返回值,错误信息
  1460. int errCode;
  1461. string errMsg, rtnResult = "", outParam;
  1462. try
  1463. {
  1464. Global.writeLog("PlatformDirectConnect 入参:" + JsonHelper.Compress(InParam));
  1465. //解析入参
  1466. if (parseInparam(InParam, out errMsg) != 0)
  1467. {
  1468. rtnResult = JsonHelper.setExceptionJson(-1, "", errMsg).ToString();
  1469. return rtnResult;
  1470. }
  1471. Global.businessType = businessType;
  1472. string funNO = JsonHelper.getDestValue(joInParam, "funNO");
  1473. //BS架构调用方式问题,每次调用都需要重新初始化
  1474. if (init(InParam, out outParam) != 0)
  1475. {
  1476. rtnResult = outParam;
  1477. return rtnResult;
  1478. }
  1479. if (funNO=="4101Y")
  1480. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joInParam, "insuplc_admdvs");
  1481. JObject joRtn = invoker.invokeCenterService(funNO, JsonHelper.setCenterInpar(funNO, joParam));
  1482. if (JsonHelper.parseCenterRtnValue(joRtn, out errMsg) != 0)
  1483. {
  1484. rtnResult = JsonHelper.setExceptionJson(-1, "平台直连错误", errMsg).ToString();
  1485. return rtnResult;
  1486. }
  1487. else
  1488. {
  1489. rtnResult = JsonHelper.setIrisReturnValue(0, "", joRtn).ToString();
  1490. return rtnResult;
  1491. }
  1492. }
  1493. catch (Exception ex)
  1494. {
  1495. rtnResult = JsonHelper.setExceptionJson(-1, "PlatformDirectConnect 交易", ex.Message).ToString();
  1496. return rtnResult;
  1497. }
  1498. finally
  1499. {
  1500. Global.writeLog("PlatformDirectConnect 出参:" + JsonHelper.Compress(rtnResult));
  1501. }
  1502. }
  1503. }
  1504. }