InsuBusiness.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.IO;
  9. using Newtonsoft.Json;
  10. using System.Windows.Forms;
  11. using PTMedInsuInterface.Common;
  12. using PTMedInsuInterface.Helper;
  13. using PTMedInsuInterface.Business;
  14. using PTMedInsuInterface.Variables;
  15. using System.Net.Http;
  16. namespace PTMedInsuInterface
  17. {
  18. public class InsuBusiness: IInsuBusiness
  19. {
  20. string errorCode = "0", errorMessage = "成功", result = "{}";
  21. string Test = "000000";
  22. private InvokeHelper invoker = new InvokeHelper();
  23. private HisIrisServices hIS = new HisIrisServices();
  24. private MIIrisServices mIS = new MIIrisServices();
  25. private ShellBusiness sBus = new ShellBusiness();
  26. private bool isServiceSeflMachine = false;
  27. private string isNeedRedirect = "0";
  28. public InsuBusiness()
  29. {
  30. sBus.getCurrentEnvironmentInfo();
  31. }
  32. #region 主要交易
  33. /// <summary>
  34. /// 初始化,前端传过来接口DR,根据DR获取接口完整信息传给业务DLL
  35. /// </summary>
  36. /// <param name="InParam"></param>
  37. /// <returns></returns>
  38. //public string Init(string InParam)
  39. //{
  40. // JObject joRtn = new JObject();
  41. // try
  42. // {
  43. // if (!sBus.isExistConfig())
  44. // {
  45. // return JsonHelper.setExceptionJson(-1, "Init(getPlatformHospitalDr)异常", "未找到配置文件INSUConfigure.ini").ToString();
  46. // }
  47. // //获取Iris配置
  48. // sBus.getHisConfingue(out Global.hisConfig);
  49. // //获取云医保配置
  50. // sBus.getInsuConfingue(out Global.insuConfig);
  51. // //设置DLL 命名空间,
  52. // sBus.getDLLInfo(out Global.dll);
  53. // JObject joInparam = JObject.Parse(InParam);
  54. // string hospID = JsonHelper.getDestValue(joInparam, "hospID");
  55. // Global.inf.hisHospitalDr=Global.inf.hospitalDr = Convert.ToInt32(hospID);
  56. // string hospDr = "";
  57. // if (Global.curEvt.MIVer == "2")
  58. // {
  59. // if (mIS.getPlatformHospitalDr(hospID, out hospDr) != 0)
  60. // {
  61. // return JsonHelper.setExceptionJson(-1, "Init(getPlatformHospitalDr)异常", hospDr).ToString();
  62. // }
  63. // if (hospDr == "")
  64. // {
  65. // return JsonHelper.setExceptionJson(-1, "Init", "医院ID不能为空!").ToString();
  66. // }
  67. // Global.inf.hospitalDr = Convert.ToInt32(hospDr);
  68. // }
  69. // else
  70. // hospDr = hospID;
  71. // string interfaceDr = JsonHelper.getDestValue(joInparam, "interfaceDr");
  72. // //如果为空则取insuAdmObj里的interfaceDr
  73. // if (interfaceDr == "")
  74. // {
  75. // interfaceDr = JsonHelper.getDestValue(joInparam, "insuAdmObj.interfaceDr");
  76. // }
  77. // //获取接口信息
  78. // if (interfaceDr == "")
  79. // {
  80. // ShellBusiness shell = new ShellBusiness();
  81. // JObject joInterfaceResult = shell.showInterfaceChooseForm();
  82. // if (joInterfaceResult["errorCode"].ToString() != "0")
  83. // {
  84. // joRtn = JsonHelper.setExceptionJson(-100, "showInterfaceChooseForm", joInterfaceResult["errorMessage"].ToString());
  85. // return joRtn.ToString();
  86. // }
  87. // else
  88. // {
  89. // JObject joInterface = JObject.FromObject(joInterfaceResult["result"]);
  90. // sBus.getDLLInfo(joInterface);
  91. // joRtn = (JObject)joInterfaceResult.DeepClone();
  92. // }
  93. // }
  94. // else
  95. // {
  96. // joRtn = mIS.getspecifiedInterface(int.Parse(hospDr), int.Parse(interfaceDr));
  97. // if (JsonHelper.parseIrisRtnValue(joRtn,out errorMessage) != 0)
  98. // {
  99. // return joRtn.ToString();
  100. // }
  101. // else
  102. // {
  103. // JObject joInterface = JObject.FromObject(joRtn["result"]);
  104. // sBus.getDLLInfo(joInterface);
  105. // }
  106. // }
  107. // joRtn.Add("hisIrisUrl", Global.hisConfig.ip + "//" + Global.hisConfig.url);
  108. // joRtn.Add("insuIrisUrl", Global.insuConfig.ip + "//" + Global.insuConfig.url);
  109. // return joRtn.ToString();
  110. // }
  111. // catch (Exception e)
  112. // {
  113. // joRtn = JsonHelper.setExceptionJson(-1, "Init", e.Message );
  114. // return joRtn.ToString();
  115. // }
  116. // finally
  117. // {
  118. // Global.writeLog("Init", InParam, joRtn.ToString());
  119. // }
  120. //}
  121. public string Init(string InParam)
  122. {
  123. Global.writeLog($"入参:{InParam}");
  124. JObject joRtn = new JObject();
  125. try
  126. {
  127. if (!sBus.isExistConfig())
  128. {
  129. return JsonHelper.setExceptionJson(-1, "Init(getPlatformHospitalDr)异常", "未找到配置文件INSUConfigure.ini").ToString();
  130. }
  131. //获取Iris配置
  132. sBus.getHisConfingue(out Global.hisConfig);
  133. //获取云医保配置
  134. sBus.getInsuConfingue(out Global.insuConfig);
  135. //设置DLL 命名空间,
  136. sBus.getDLLInfo(out Global.dll);
  137. JObject joInparam = JObject.Parse(InParam);
  138. string hospID = JsonHelper.getDestValue(joInparam, "hospID");
  139. Global.inf.hisHospitalDr = Global.inf.hospitalDr = Convert.ToInt32(hospID);
  140. string hospDr = "";
  141. if (Global.curEvt.MIVer.Trim() == "2")
  142. {
  143. if (mIS.getPlatformHospitalDr(hospID, out hospDr) != 0)
  144. {
  145. return JsonHelper.setExceptionJson(-1, "Init(getPlatformHospitalDr)异常", hospDr).ToString();
  146. }
  147. if (hospDr == "")
  148. {
  149. return JsonHelper.setExceptionJson(-1, "Init", "医院ID不能为空!").ToString();
  150. }
  151. Global.inf.hospitalDr = Convert.ToInt32(hospDr);
  152. }
  153. else
  154. hospDr = hospID;
  155. string interfaceDr = JsonHelper.getDestValue(joInparam, "interfaceDr");
  156. //如果为空则取insuAdmObj里的interfaceDr
  157. if (interfaceDr == "")
  158. {
  159. interfaceDr = JsonHelper.getDestValue(joInparam, "insuAdmObj.interfaceDr");
  160. }
  161. //获取接口信息
  162. if (interfaceDr == "")
  163. {
  164. //如果是自助机,则选择自助机的接口
  165. if (isServiceSeflMachine)
  166. {
  167. joRtn = mIS.getSelfServiceInterface();
  168. isNeedRedirect = "1";
  169. }
  170. else
  171. {
  172. ShellBusiness shell = new ShellBusiness();
  173. joRtn = shell.showInterfaceChooseForm();
  174. }
  175. }
  176. else
  177. {
  178. joRtn = mIS.getspecifiedInterface(int.Parse(hospDr), int.Parse(interfaceDr));
  179. }
  180. if (JsonHelper.parseIrisRtnValue(joRtn, out errorMessage) != 0)
  181. {
  182. return joRtn.ToString();
  183. }
  184. else
  185. {
  186. JObject joInterface = JObject.FromObject(joRtn["result"]);
  187. sBus.getDLLInfo(joInterface);
  188. }
  189. joRtn.Add("hisIrisUrl", Global.hisConfig.ip + "//" + Global.hisConfig.url);
  190. joRtn.Add("insuIrisUrl", Global.insuConfig.ip + "//" + Global.insuConfig.url);
  191. return joRtn.ToString();
  192. }
  193. catch (Exception e)
  194. {
  195. joRtn = JsonHelper.setExceptionJson(-1, "Init", e.Message);
  196. return joRtn.ToString();
  197. }
  198. finally
  199. {
  200. Global.writeLog("Init", InParam, joRtn.ToString());
  201. }
  202. }
  203. public string GetPatientInfo(string InParam)
  204. {
  205. Global.writeLog_debug($"调用单例模式类,程序应用域(shell):{AppDomain.CurrentDomain.FriendlyName}--{AppDomain.CurrentDomain.Id}");
  206. //return JsonHelper.setIrisReturnValue(-1,"测试",null).ToString();
  207. return Transact("GetPatientInfo", InParam);
  208. }
  209. public string Register(string InParam)
  210. {
  211. return Transact("Register", InParam);
  212. }
  213. public string FeeUpload(string InParam)
  214. {
  215. return Transact("FeeUpload", InParam);
  216. }
  217. public string Settlement(string InParam)
  218. {
  219. return Transact("Settlement", InParam);
  220. }
  221. public string AgentFun(string InParam)
  222. {
  223. return Transact("AgentFun", InParam);
  224. }
  225. public string PlatformDirectConnect(string InParam)
  226. {
  227. string outParam = string.Empty;
  228. JObject joRtn = new JObject();
  229. JObject joInparam = new JObject();
  230. try
  231. {
  232. //获取Iris配置
  233. sBus.getHisConfingue(out Global.hisConfig);
  234. //获取云医保配置
  235. sBus.getInsuConfingue(out Global.insuConfig);
  236. joInparam = JObject.Parse(InParam);
  237. string interfaceInfo = JsonHelper.getDestValue(joInparam, "interfaceinfo");
  238. JObject joInterfaceInfo;
  239. if (interfaceInfo == "")
  240. { joInterfaceInfo = null; }
  241. else
  242. { joInterfaceInfo = JObject.Parse(interfaceInfo); }
  243. if (joInterfaceInfo != null)
  244. {
  245. Global.dll.name = JsonHelper.getDestValue(joInterfaceInfo, "dLLName");
  246. Global.dll.nameSpace = "PTMedicalInsurance";
  247. }
  248. else
  249. {
  250. string hospID = JsonHelper.getDestValue(joInparam, "hospID");
  251. string interfaceDr = JsonHelper.getDestValue(joInparam, "interfaceDr");
  252. joInterfaceInfo = mIS.getspecifiedInterface(int.Parse(hospID), int.Parse(interfaceDr));
  253. if (JsonHelper.parseIrisRtnValue(joInterfaceInfo, out errorMessage) != 0)
  254. {
  255. joRtn = JsonHelper.setExceptionJson(-100, "PlatformDirectConnect", errorMessage);
  256. outParam = joRtn.ToString();
  257. return outParam;
  258. }
  259. else
  260. {
  261. Global.dll.name = JsonHelper.getDestValue(joInterfaceInfo, "result.DLLName");
  262. Global.dll.nameSpace = "PTMedicalInsurance";
  263. joInparam.Add("interfaceinfo", JObject.Parse(JsonHelper.getDestValue(joInterfaceInfo, "result")));
  264. }
  265. }
  266. InvokeHelper bus = new InvokeHelper();
  267. joRtn = bus.InvokeBusinessDLL("PlatformDirectConnect", joInparam.ToString());
  268. outParam = joRtn.ToString();
  269. return outParam;
  270. }
  271. catch (Exception ex)
  272. {
  273. joRtn = JsonHelper.setExceptionJson(-100, "PlatformDirectConnect", ex.Message);
  274. outParam = joRtn.ToString();
  275. return outParam;
  276. }
  277. finally
  278. {
  279. Global.writeLog("PlatformDirectConnect", InParam, outParam);
  280. }
  281. }
  282. public string SelfServiceMachine(string InParam)
  283. {
  284. isServiceSeflMachine = true;
  285. return Transact("SelfServiceMachine", InParam);
  286. }
  287. #endregion
  288. #region 私有交易
  289. /// <summary>
  290. /// 交易封装
  291. /// </summary>
  292. private string Transact(string transName,string inParam)
  293. {
  294. string outParam = string.Empty, errorMsg = "", businessType = "";
  295. JObject joRtn ;
  296. JObject joInparam;
  297. try
  298. {
  299. joInparam = JObject.Parse(inParam);
  300. businessType = JsonHelper.getDestValue(joInparam, "businessType");
  301. string initRtn = Init(inParam);
  302. JObject joInit = JObject.Parse(initRtn);
  303. if (JsonHelper.parseIrisRtnValue(joInit, out errorMsg) != 0)
  304. {
  305. outParam = JsonHelper.setExceptionJson(-100, "初始化失败", errorMsg).ToString();
  306. return outParam;
  307. }
  308. JObject joInterface = JObject.FromObject(joInit["result"]);
  309. //组织业务DLL入参
  310. JObject joBusInparam= JObject.FromObject(joInparam.DeepClone());
  311. joBusInparam.Add("interfaceinfo", joInterface);
  312. if (isServiceSeflMachine)
  313. {
  314. joBusInparam.Add("isNeedRedirect", isNeedRedirect);
  315. }
  316. InvokeHelper bus = new InvokeHelper();
  317. JObject joPaitientInfo = bus.InvokeBusinessDLL(transName, joBusInparam.ToString());
  318. if (joPaitientInfo["errorCode"].ToString() != "0")
  319. {
  320. outParam = joPaitientInfo.ToString();
  321. return outParam;
  322. }
  323. else
  324. {
  325. joRtn = new JObject();
  326. dynamic joResult = new JObject();
  327. //List<string> lst = new List<string> { "Settlement", "SelfServiceMachine" };
  328. //if (lst.Contains(transName)) //不这样写的话,住院结算后HIS前端一直转圈
  329. //{
  330. // joRtn = joPaitientInfo;
  331. //}
  332. //else
  333. //{
  334. // joResult.patientInfo = joPaitientInfo["result"];
  335. // joResult.interfaceInfo = joInit;
  336. // joRtn.Add("result", JObject.FromObject(joResult));
  337. // joRtn.Add("errorCode", 0);
  338. // joRtn.Add("errorMessage", "");
  339. //}
  340. List<string> lst = new List<string> { "GetPatientInfo" };
  341. if (lst.Contains(transName) || lst.Contains(businessType)) //不这样写的话,住院结算后HIS前端一直转圈
  342. {
  343. joResult.patientInfo = joPaitientInfo["result"];
  344. joResult.interfaceInfo = joInit;
  345. joRtn.Add("result", JObject.FromObject(joResult));
  346. joRtn.Add("errorCode", 0);
  347. joRtn.Add("errorMessage", "");
  348. }
  349. else
  350. {
  351. joRtn = joPaitientInfo;
  352. }
  353. outParam = joRtn.ToString();
  354. return outParam;
  355. }
  356. }
  357. catch (Exception ex)
  358. {
  359. String innerMessage = (ex.InnerException != null)
  360. ? ex.InnerException.Message
  361. : "";
  362. joRtn = JsonHelper.setExceptionJson(-100, transName, "aa"+ex.Message + innerMessage);
  363. outParam = joRtn.ToString();
  364. return outParam;
  365. }
  366. finally
  367. {
  368. Global.writeLog(transName, inParam, outParam);
  369. }
  370. }
  371. #endregion
  372. }
  373. }