LocalMedDirDownloadProcess.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Common;
  3. using PTMedicalInsurance.Entity;
  4. using PTMedicalInsurance.Helper;
  5. using PTMedicalInsurance.Variables;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace PTMedicalInsurance.Business
  13. {
  14. class LocalMedDirDownloadProcess : AbstractProcess
  15. {
  16. int maxNo = 0;
  17. string ypbz = "";
  18. /// <summary>
  19. /// 药品、诊疗目录
  20. /// </summary>
  21. /// <param name="input"></param>
  22. /// <returns></returns>
  23. public override CallResult Process(JObject input)
  24. {
  25. // sbjgbh传需要查询的社保局编号,济南医疗传370100(或37010101),工伤传37019L(或37019L01)省医保37000000
  26. if(!string.IsNullOrEmpty(input["ver"].Text()))
  27. {
  28. maxNo = int.Parse(input["ver"].Text());
  29. }
  30. ypbz = input["ypbz"].Text();
  31. bool hasMore = true;
  32. while (hasMore)
  33. {
  34. //核心目录
  35. //var ret = FetchDirectory(TradeEnum.DirectoryDownload, "ylxm_ds", "sxzfbl_ds", "xj_ds");
  36. //医院项目
  37. //var ret = FetchDirectory(TradeEnum.DirectoryDownload, "yyxm_ds", "", "xj_ds");
  38. var ret = FetchDirectory(TradeEnum.DirectoryDownloadExt, "yyxm_ds", "", "xj_ds");
  39. hasMore = ret.hasMore;
  40. updateDirectory(ret.data);
  41. updateLimitPrice(ret.limitData);
  42. // 多自费项目
  43. updateSelfPercent(ret.percentData);
  44. }
  45. return IrisReturn("更新成功!", null);
  46. }
  47. private void updateDirectory(JArray data)
  48. {
  49. List<HBMedInsuDirectory> list = new List<HBMedInsuDirectory>();
  50. try
  51. {
  52. foreach (var dir in data)
  53. {
  54. HBMedInsuDirectory obj = ConvertToEntity((JObject)dir);
  55. list.Add(obj);
  56. }
  57. // 保存
  58. saveToServer(list);
  59. }
  60. catch (Exception ex)
  61. {
  62. }
  63. }
  64. private JObject saveToServer(List<HBMedInsuDirectory> data)
  65. {
  66. JObject joIn = new JObject();
  67. JObject joRtn = new JObject();
  68. string outParam = "";
  69. try
  70. {
  71. joIn.Add("params", JArray.Parse(JsonHelper.toJsonString(data)));
  72. joIn.Add("code", "09010035");
  73. joIn.Add("updateUserID", Global.user.ID);
  74. InvokeHelper invoker = new InvokeHelper();
  75. string sInput = joIn.ToString();
  76. joRtn = invoker.invokeInsuService(sInput, "applyDataToIris");
  77. outParam = joRtn.ToString();
  78. return joRtn;
  79. }
  80. catch (Exception ex)
  81. {
  82. joRtn = JsonHelper.setExceptionJson(-1, "applyDataToIris", ex.Message);
  83. outParam = joRtn.ToString();
  84. return joRtn;
  85. }
  86. }
  87. private (bool hasMore, JArray data, JArray percentData, JArray limitData) FetchDirectory(TradeEnum trade, string dsName)
  88. {
  89. return FetchDirectory(trade,dsName,null,null);
  90. }
  91. private (bool hasMore, JArray data,JArray percentData,JArray limitData) FetchDirectory(TradeEnum trade, string dsName,string percentName,string limitName)
  92. {
  93. JObject joInput = new JObject();
  94. joInput["p_sxh"] = maxNo.ToString(); //全量下载0,后面传最大
  95. joInput["p_ypbz"] = ypbz; //
  96. //joInput["p_filetype"] = "excel";
  97. Global.pat.insuplc_admdvs = "370100";
  98. JObject joRtn = invoker.invokeCenterService(trade, joInput);
  99. if ("0".Equals(JsonHelper.getDestValue(joRtn, "resultcode")))
  100. {
  101. // 是否还有数据
  102. bool hasMore = "1".Equals(JsonHelper.getDestValue(joRtn, "sfjxxz"));
  103. JArray data = JArray.Parse(JsonHelper.getDestValue(joRtn, dsName));
  104. JArray percent = new JArray();
  105. if (!string.IsNullOrEmpty(percentName))
  106. {
  107. percent = JArray.Parse(JsonHelper.getDestValue(joRtn, percentName));
  108. }
  109. else {
  110. //自付比例在项目中
  111. foreach (var item in data)
  112. {
  113. if (!string.IsNullOrEmpty(item["zfbl"].Text()))
  114. {
  115. dynamic percentObj = new JObject();
  116. percentObj.ylxmbm = item["gbxmbm"].Text();
  117. percentObj.rqlb = item["rqlb"].Text();
  118. percentObj.yltclb = item["yltclb"].Text();
  119. percentObj.sm = item["sm"].Text();
  120. percentObj.qsrq = item["qsrq"].Text();
  121. percentObj.zzrq = item["zzrq"].Text();
  122. percentObj.xzbz = item["xzbz"].Text();
  123. percentObj.sxzfbl = item["zfbl"].Text();
  124. percent.Add(percentObj);
  125. }
  126. }
  127. }
  128. JArray limit = new JArray();
  129. if (!string.IsNullOrEmpty(limitName))
  130. {
  131. limit = JArray.Parse(JsonHelper.getDestValue(joRtn, limitName));
  132. }
  133. return (hasMore, data, percent, limit);
  134. }
  135. else
  136. {
  137. MessageBox.Show(JsonHelper.getDestValue(joRtn, "err_msg"));
  138. }
  139. return (false, new JArray(), new JArray(), new JArray());
  140. }
  141. public CallResult DownloadSelfpay(JObject input)
  142. {
  143. string code = input["code"].Text();
  144. //if (!string.IsNullOrEmpty(code))
  145. //{
  146. dynamic joInput = new JObject();
  147. joInput.p_yyxmbm = code;
  148. joInput.p_rq = "";
  149. //单个更新比例
  150. Global.pat.insuplc_admdvs = "370100";
  151. JObject joRtn = invoker.invokeCenterService(TradeEnum.SelfPayPercent, joInput);
  152. if ("0".Equals(JsonHelper.getDestValue(joRtn, "resultcode")))
  153. {
  154. JArray percent = new JArray();
  155. JArray data = JArray.Parse(JsonHelper.getDestValue(joRtn, "zfbl_ds"));
  156. foreach (var item in data)
  157. {
  158. if (!string.IsNullOrEmpty(item["zfbl"].Text()))
  159. {
  160. dynamic percentObj = new JObject();
  161. percentObj.ylxmbm = code;
  162. percentObj.rqlb = item["rqlb"].Text();
  163. percentObj.yltclb = "6";
  164. percentObj.sm = item["sm"].Text();
  165. percentObj.sxzfbl = item["zfbl"].Text();
  166. percent.Add(percentObj);
  167. }
  168. }
  169. updateSelfPercent(percent);
  170. }
  171. //}
  172. return Success();
  173. }
  174. /// <summary>
  175. /// 诊断目录下载
  176. /// </summary>
  177. /// <param name="input"></param>
  178. /// <returns></returns>
  179. public CallResult DownloadDiagnosis(JObject input)
  180. {
  181. //sbjgbh传需要查询的社保局编号,济南医疗传370100(或37010101),工伤传37019L(或37019L01)
  182. if (!string.IsNullOrEmpty(input["ver"].Text()))
  183. {
  184. maxNo = int.Parse(input["ver"].Text());
  185. }
  186. bool hasMore = true;
  187. while (hasMore)
  188. {
  189. var ret = FetchDirectory(TradeEnum.DirectoryDownloadCore, "ybjb_ds");
  190. hasMore = ret.hasMore;
  191. List<HBMedInsuDirectory> list = new List<HBMedInsuDirectory>();
  192. foreach (var d in ret.data)
  193. {
  194. list.Add(NewDiagnosis((JObject)d));
  195. }
  196. saveToServer(list);
  197. }
  198. return IrisReturn("下载成功",null);
  199. }
  200. /// <summary>
  201. /// 科室查询
  202. /// </summary>
  203. /// <param name="input"></param>
  204. /// <returns></returns>
  205. public CallResult QueryDepartment()
  206. {
  207. JObject joInput = new JObject();
  208. joInput["p_ksbm"] = ""; //全量下载
  209. Global.pat.insuplc_admdvs = "370100";
  210. JObject joRtn = invoker.invokeCenterService(TradeEnum.DepartmentQuery, joInput);
  211. if ("0".Equals(JsonHelper.getDestValue(joRtn, "resultcode")))
  212. {
  213. // 是否还有数据
  214. outParam = JsonHelper.getDestValue(joRtn, "dept_ds");
  215. }
  216. return Success();
  217. }
  218. private HBMedInsuDirectory NewDiagnosis(JObject obj)
  219. {
  220. HBMedInsuDirectory jsonTemp = new HBMedInsuDirectory();
  221. jsonTemp.updateUserID = Global.user.ID;
  222. jsonTemp.HospitalDr = Global.inf.hospitalDr;
  223. jsonTemp.InterfaceDr = Global.inf.interfaceDr;
  224. jsonTemp.Code = obj["jbbm"].Text();
  225. jsonTemp.Name = obj["jbmc"].Text();
  226. jsonTemp.HisType = "4";
  227. jsonTemp.HisTypeName = "诊断";
  228. jsonTemp.ValidFlag = "1".Equals(obj["zxbz"].Text()) ? 0 : 1;
  229. jsonTemp.Note = obj["bz"].Text();
  230. jsonTemp.PinyinSearchCode = obj["py"].Text();
  231. jsonTemp.DrugSafetyStandardCode = "";
  232. return jsonTemp;
  233. }
  234. private HBMedInsuDirectory ConvertToEntity(JObject obj)
  235. {
  236. string hisType = obj["ypbz"].Text() ?? "2";
  237. string hisTypeName = hisType.Equals("1") ? "药品" : "诊疗"; HBMedInsuDirectory insu = new HBMedInsuDirectory();
  238. maxNo = Math.Max(maxNo, int.Parse(obj["sxh"].ToString()));
  239. insu.ID = "";
  240. insu.updateUserID = Global.user.ID;
  241. insu.HospitalDr = Global.inf.hospitalDr;
  242. insu.InterfaceDr = Global.inf.interfaceDr;
  243. insu.Code = obj["ylxmbm"].Text();
  244. insu.Name = obj["ylxmbzmc"].Text();
  245. insu.NationalCode = obj["gbxmbm"].Text();
  246. insu.NationalName = obj["gbxmmc"].Text();
  247. insu.HisType = hisType;
  248. insu.HisTypeName = hisTypeName;
  249. insu.LocateCode = obj["pms_id"].Text();
  250. insu.LocateName = obj["pms_name"].Text();
  251. insu.DosageFormCode = obj["jxm"].Text();
  252. insu.DosageFormName = obj["jxm"].Text();
  253. insu.CategoryCode = obj["listtype"].Text();
  254. insu.CategoryName = "";
  255. // 规格
  256. insu.Specification = obj["bzgg"].Text();
  257. insu.SpecificationCode = obj["gg"].Text();
  258. insu.UnitOfPackag = obj["dw"].Text();
  259. insu.UnitOfValuation = obj["ms_charge_unit"].Text();
  260. //insu.StartDate = obj["qsrq"].Text();
  261. //insu.EndDate = obj["zzrq"].Text();
  262. insu.PinyinSearchCode = obj["py"].Text();
  263. insu.Instructions = obj["ms_explain"].Text();
  264. insu.ExceptContent = obj["cwnr"].Text();
  265. insu.Connotation = obj["xmnh"].Text();
  266. insu.ValidFlag = obj["spbz"].Int();
  267. insu.Note = "";
  268. insu.VersionNO = obj["sxh"].Text();
  269. insu.VersionName = obj["sxh"].Text();
  270. string cancelFlag = obj["zxbz"].Text();
  271. insu.UseFlag = "1".Equals(cancelFlag)?0:1;
  272. insu.DrugSafetyStandardCode = obj["ypbwm"].Text();
  273. insu.ApprovalNO = obj["bzwh"].Text(); ;
  274. //insu.SpecialFlag = obj[""].Int();
  275. //insu.LimitFlag = obj[""].Int();
  276. //insu.LimitRange = obj[""].Text();
  277. insu.UniqueRecordNO = obj["sxh"].Text();
  278. insu.Manufacturers = obj["scqy"].Text();
  279. insu.SelfPercent = obj["zfbl"].Text();
  280. insu.ChargeItemLevelName = obj["mldj"].Text();
  281. insu.MinPackagingQuantity = obj["zxbzsl"].Text();
  282. insu.MinPackagingUnit = obj["gjjzxbzdw"].Text();
  283. insu.UpdateTime = obj["gxsj"].Text();
  284. if (insu.SelfPercent == "0")
  285. {
  286. insu.ChargeItemLevel = "01";
  287. insu.ChargeItemLevelName = "甲";
  288. }
  289. else if (insu.ChargeItemLevelName == "1")
  290. {
  291. insu.ChargeItemLevel = "03";
  292. insu.ChargeItemLevelName = "丙";
  293. }
  294. else
  295. {
  296. insu.ChargeItemLevel = "02";
  297. insu.ChargeItemLevelName = "乙";
  298. }
  299. return insu;
  300. }
  301. private int updateLimitPrice(JArray data)
  302. {
  303. if (data?.Count < 1) return 0;
  304. string errMsg = "";
  305. JArray joArray = new JArray();
  306. try
  307. {
  308. foreach (var dir in data)
  309. {
  310. dynamic joTmp = new JObject();
  311. joTmp.HospitalDr = Global.inf.hospitalDr;
  312. joTmp.InterfaceDr = Global.inf.interfaceDr;
  313. joTmp.updateUserID = Global.user.ID;
  314. joTmp.Code = dir["ylxmbm"].Text();
  315. joTmp.PersonnelType = dir["rqlb"].Text(); //人群类别
  316. joTmp.LimitType = dir["yltclb"].Text(); //限价类型(统筹类别)
  317. joTmp.BeginDate = Utils.ConvertShortDate(dir["qsrq"].Text());
  318. joTmp.EndDate = Utils.ConvertShortDate(dir["zzrq"].Text());
  319. joTmp.UpLimitAmount = dir["xj"].Text(); //限价
  320. joArray.Add(joTmp);
  321. }
  322. JObject joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010084", joArray).ToString(), "更新限价信息");
  323. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  324. {
  325. return -1;
  326. }
  327. else
  328. {
  329. outParam = joRtn.ToString();
  330. return 0;
  331. }
  332. }
  333. catch (Exception ex)
  334. {
  335. outParam = "更新项目自费比例:" + ex.Message;
  336. return -1;
  337. }
  338. }
  339. /// <summary>
  340. /// 如果存在同一个目录多个比例,则保存在比例扩展表
  341. /// </summary>
  342. /// <param name="data"></param>
  343. /// <returns></returns>
  344. private int updateSelfPercent(JArray data)
  345. {
  346. if (data?.Count < 1) return 0;
  347. string errMsg = "";
  348. JArray joArray = new JArray();
  349. try
  350. {
  351. foreach (var dir in data)
  352. {
  353. dynamic joTmp = new JObject();
  354. joTmp.HospitalDr = Global.inf.hospitalDr;
  355. joTmp.InterfaceDr = Global.inf.interfaceDr;
  356. joTmp.updateUserID = Global.user.ID;
  357. joTmp.Code = dir["ylxmbm"].Text();
  358. string personType = dir["rqlb"].Text(); //人群类别
  359. if (string.IsNullOrEmpty(personType))
  360. {
  361. personType = "A"; //职工
  362. }
  363. joTmp.PersonnelType = personType;
  364. string proportionType = dir["yltclb"].Text(); //自费类型(统筹类别)
  365. if (string.IsNullOrEmpty(proportionType))
  366. {
  367. proportionType = "6"; //普通门诊
  368. }
  369. joTmp.ProportionType = proportionType;
  370. joTmp.BeginDate = Utils.ConvertShortDate(dir["qsrq"].Text());
  371. joTmp.EndDate = Utils.ConvertShortDate(dir["zzrq"].Text());
  372. joTmp.Proportion = dir["sxzfbl"].Text();
  373. joArray.Add(joTmp);
  374. }
  375. JObject joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010085", joArray).ToString(), "更新项目自费比例");
  376. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  377. {
  378. return -1;
  379. }
  380. else
  381. {
  382. outParam = joRtn.ToString();
  383. return 0;
  384. }
  385. }
  386. catch (Exception ex)
  387. {
  388. outParam = "更新项目自费比例:" + ex.Message;
  389. return -1;
  390. }
  391. }
  392. }
  393. }