LocalMedDirDownloadProcess.cs 16 KB

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