DataImport.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Helper;
  3. using PTMedicalInsurance.Variables;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace PTMedicalInsurance.Business.MI
  12. {
  13. class DataImport
  14. {
  15. //PTMedicalInsurance.Services.MIIrisServices mis = new PTMedicalInsurance.Services.MIIrisServices();
  16. MIIrisServices mis = new MIIrisServices();
  17. /// <summary>
  18. /// 读取TXT后,Array中的空值会返回NULL,将其转换为"".应有其他方式处理,后面再优化
  19. /// 明天试试Convert.ToString(a)
  20. /// </summary>
  21. /// <param name="arrayValue"></param>
  22. /// <returns></returns>
  23. private string convertArrayNull(string arrayValue)
  24. {
  25. string returnValue = string.Empty;
  26. if (arrayValue == "null")
  27. {
  28. returnValue = "";
  29. }
  30. else
  31. {
  32. returnValue = arrayValue;
  33. }
  34. return returnValue;
  35. }
  36. private void convertChrgItmTypeToMIType(string chrgItmType,out string hisType,out string hisTypeName)
  37. {
  38. hisType = "";
  39. hisTypeName = "";
  40. switch (chrgItmType)
  41. {
  42. case "301"://卫生材料
  43. {
  44. hisType = "3";
  45. hisTypeName = "材料";
  46. break;
  47. }
  48. case "101"://西药
  49. {
  50. hisType = "1";
  51. hisTypeName = "药品";
  52. break;
  53. }
  54. case "102"://中药
  55. {
  56. hisType = "1";
  57. hisTypeName = "药品";
  58. break;
  59. }
  60. case "103"://中成药
  61. {
  62. hisType = "1";
  63. hisTypeName = "药品";
  64. break;
  65. }
  66. case "104"://中成药
  67. {
  68. hisType = "1";
  69. hisTypeName = "药品";
  70. break;
  71. }
  72. case "106"://草药
  73. {
  74. hisType = "1";
  75. hisTypeName = "药品";
  76. break;
  77. }
  78. default:
  79. {
  80. hisType = "2";
  81. hisTypeName = "诊疗";
  82. break;
  83. }
  84. }
  85. }
  86. private string convertDictionaryValue(string type, string code)
  87. {
  88. try
  89. {
  90. JObject joRtn = mis.getSpecDictionary(Global.inf.interfaceDr.ToString(), type, code);
  91. string errMsg = "";
  92. JArray ja = JArray.Parse(JsonHelper.getDestValue(joRtn, "result.data"));
  93. if (ja.Count == 1)
  94. {
  95. return ja[0]["name"].ToString();
  96. }
  97. else
  98. {
  99. return code;
  100. }
  101. }
  102. catch (Exception ex)
  103. {
  104. Global.writeLog("convertDictionaryValue", ex.Message, "");
  105. return code;
  106. }
  107. }
  108. /// <summary>
  109. /// 从TXT文件中获取医保目录,并组装成JSON
  110. /// </summary>
  111. /// <param name="arr"></param>
  112. /// <returns></returns>
  113. private JObject GetMIDirectorynByTxt(string[] arr)
  114. {
  115. string hisType = "";string hisTypeName ="";
  116. dynamic jsonTemp;
  117. jsonTemp = new JObject();
  118. jsonTemp.ID = "";
  119. jsonTemp.updateUserID = Global.user.ID;
  120. jsonTemp.HospitalDr = Global.inf.hospitalDr;
  121. jsonTemp.InterfaceDr = Global.inf.interfaceDr;
  122. jsonTemp.Code = arr[1];
  123. jsonTemp.Name = arr[2];
  124. convertChrgItmTypeToMIType(arr[23],out hisType,out hisTypeName);
  125. jsonTemp.HisType = hisType;
  126. jsonTemp.HisTypeName = hisTypeName;
  127. jsonTemp.LocateCode = "";
  128. jsonTemp.LocateName = "";
  129. jsonTemp.DosageFormCode = arr[28];
  130. jsonTemp.DosageFormName = arr[9];
  131. jsonTemp.CategoryCode = arr[4];//
  132. jsonTemp.CategoryName = convertDictionaryValue("medChrgitmType", arr[4]);
  133. jsonTemp.Specification = arr[8];
  134. //jsonTemp.SpecificationCode = arr[24];
  135. jsonTemp.UnitOfPackag = arr[26];
  136. jsonTemp.UnitOfValuation = "";
  137. jsonTemp.StartDate = convertArrayNull(arr[21]);
  138. jsonTemp.EndDate = convertArrayNull(arr[22]);
  139. jsonTemp.PinyinSearchCode = "";
  140. jsonTemp.Instructions = arr[18];
  141. jsonTemp.ExceptContent = arr[17];
  142. jsonTemp.Connotation = arr[16];
  143. jsonTemp.ValidFlag = "1";
  144. jsonTemp.Note = arr[10];
  145. jsonTemp.VersionNO = arr[0];
  146. jsonTemp.VersionName = "";
  147. jsonTemp.UseFlag = 1;
  148. jsonTemp.DrugSafetyStandardCode = arr[29];
  149. jsonTemp.ApprovalNO = arr[15];
  150. jsonTemp.SpecialFlag = "";
  151. jsonTemp.LimitFlag = "";
  152. jsonTemp.LimitRange = arr[18];
  153. jsonTemp.UniqueRecordNO = "";
  154. jsonTemp.Manufacturers = arr[12];
  155. jsonTemp.Company = arr[13];
  156. jsonTemp.ChargeItemLevel = arr[5];
  157. jsonTemp.ChargeItemLevelName = convertDictionaryValue("chrgitmLv", arr[5]);
  158. jsonTemp.ListType = arr[23];
  159. jsonTemp.MinPackagingQuantity = arr[25];
  160. jsonTemp.MinPackagingUnit = arr[26];
  161. jsonTemp.PlaceOfProduct = arr[13];
  162. jsonTemp.ChargeItemType = arr[4];//大类编码
  163. return jsonTemp;
  164. }
  165. /// <summary>
  166. /// 从TXT文件中获取医保目录自付比例信息,并组装成JSON
  167. /// </summary>
  168. /// <param name="arr"></param>
  169. /// <returns></returns>
  170. private JObject GetMIDirSelfPersentInfoByTxt(string[] arr)
  171. {
  172. dynamic jsonTemp;
  173. jsonTemp = new JObject();
  174. jsonTemp.ID = "";
  175. jsonTemp.updateUserID = Global.user.ID;
  176. jsonTemp.HospitalDr = Global.inf.hospitalDr;
  177. jsonTemp.InterfaceDr = Global.inf.interfaceDr;
  178. jsonTemp.Code = arr[1];
  179. jsonTemp.Name = "";
  180. jsonTemp.PersonnelType = arr[2];
  181. jsonTemp.ProportionType = arr[5];
  182. jsonTemp.InsuranceAreaCode = arr[4];
  183. jsonTemp.BeginDate = arr[3];
  184. jsonTemp.EndDate = arr[6];
  185. jsonTemp.PoolAreaNO = "";
  186. jsonTemp.ValidFlag = 1;
  187. jsonTemp.RequiredID = arr[0]; //存版本号
  188. jsonTemp.SelfProportion = arr[7];
  189. return jsonTemp;
  190. }
  191. /// <summary>
  192. /// 从TXT文件中获取医保目录限价信息,并组装成JSON
  193. /// </summary>
  194. /// <param name="arr"></param>
  195. /// <returns></returns>
  196. private JObject GetMIDirLimitPriceByTxt(string[] arr)
  197. {
  198. dynamic jsonTemp;
  199. jsonTemp = new JObject();
  200. jsonTemp.ID = "";
  201. jsonTemp.updateUserID = Global.user.ID;
  202. jsonTemp.HospitalDr = Global.inf.hospitalDr;
  203. jsonTemp.InterfaceDr = Global.inf.interfaceDr;
  204. jsonTemp.Code = arr[1];
  205. jsonTemp.Name = "";
  206. jsonTemp.LimitType = arr[2];
  207. jsonTemp.DisposeWay = arr[5];
  208. jsonTemp.InsuranceAreaCode = arr[4];
  209. jsonTemp.BeginDate = arr[3];
  210. jsonTemp.EndDate = arr[6];
  211. jsonTemp.ValidFlag = 1;
  212. jsonTemp.RequiredID = arr[0];
  213. jsonTemp.UpLimitAmount = arr[7];
  214. return jsonTemp;
  215. }
  216. /// <summary>
  217. /// 从TXT文件中获取医保诊断,并组装成JSON
  218. /// </summary>
  219. /// <param name="arr"></param>
  220. /// <returns></returns>
  221. private JObject GetMIDiseByTxt(string[] arr)
  222. {
  223. dynamic jsonTemp;
  224. jsonTemp = new JObject();
  225. jsonTemp.ID = "";
  226. jsonTemp.updateUserID = Global.user.ID;
  227. jsonTemp.HospitalDr = Global.inf.hospitalDr;
  228. jsonTemp.InterfaceDr = Global.inf.interfaceDr;
  229. jsonTemp.Code = arr[0];
  230. jsonTemp.Name = arr[2];
  231. jsonTemp.HisType = 4;
  232. jsonTemp.HisTypeName = "疾病诊断";
  233. jsonTemp.LocateCode = "";
  234. jsonTemp.LocateName = "";
  235. jsonTemp.DosageFormCode = "";
  236. jsonTemp.DosageFormName = ""; ;
  237. jsonTemp.CategoryCode = arr[5];
  238. jsonTemp.CategoryName = "";
  239. jsonTemp.Specification = ""; ;
  240. jsonTemp.SpecificationCode = "";
  241. jsonTemp.UnitOfPackag = ""; ;
  242. jsonTemp.UnitOfValuation = "";
  243. jsonTemp.StartDate = ""; ;
  244. jsonTemp.EndDate = ""; ;
  245. jsonTemp.PinyinSearchCode = arr[3];
  246. jsonTemp.Instructions = ""; ;
  247. jsonTemp.ExceptContent = ""; ;
  248. jsonTemp.Connotation = ""; ;
  249. jsonTemp.ValidFlag = "1";
  250. jsonTemp.Note = "";;
  251. jsonTemp.VersionNO = "";
  252. jsonTemp.VersionName = "";
  253. jsonTemp.UseFlag = 1;
  254. jsonTemp.DrugSafetyStandardCode = "";
  255. jsonTemp.ApprovalNO = "";
  256. jsonTemp.SpecialFlag = "";
  257. jsonTemp.LimitFlag = "";
  258. jsonTemp.LimitRange = "";
  259. jsonTemp.UniqueRecordNO = "";
  260. jsonTemp.Manufacturers = "";
  261. jsonTemp.Company = "";
  262. return jsonTemp;
  263. }
  264. /// <summary>
  265. /// 从TXT导出目录到医保平台IRIS
  266. /// </summary>
  267. /// <param name="txtPath"></param>
  268. /// <param name="singleRows"></param>
  269. /// <param name="direcType"></param>
  270. /// <param name="processBar"></param>
  271. /// <returns></returns>
  272. public JObject insertDirectoryToMIIrisByTxt(string txtPath, int size, int direcType, Sunny.UI.UIProcessBar processBar,out string currentMaxVerNO)
  273. {
  274. int errorCount = 0;
  275. string errorMsg = "";
  276. currentMaxVerNO = "";
  277. JObject joRtn = new JObject();
  278. int defaultColumns = 0;
  279. switch (direcType)
  280. {
  281. case 0:
  282. {
  283. defaultColumns = 31;
  284. break;
  285. }
  286. case 1:
  287. {
  288. defaultColumns = 6;
  289. break;
  290. }
  291. //case 6:
  292. // {
  293. // defaultColumns = 8;
  294. // break;
  295. // }
  296. //case 7:
  297. // {
  298. // defaultColumns = 8;
  299. // break;
  300. // }
  301. }
  302. try
  303. {
  304. /*据说速度更快
  305. * https://www.cnblogs.com/eniac12/p/4398310.html
  306. * using (StreamReader sr = File.OpenText(fileName))
  307. {
  308. string s = String.Empty;
  309. while ((s = sr.ReadLine()) != null)
  310. {
  311. //do what you have to here
  312. }
  313. }
  314. Convert.ToString(a)
  315. */
  316. long lSize = new FileInfo(txtPath).Length;
  317. if (lSize == 0)
  318. {
  319. joRtn = JsonHelper.setExceptionJson(-99999999, "检查到文件大小为0", null);
  320. return joRtn;
  321. }
  322. string[] lines = System.IO.File.ReadAllLines(txtPath,Encoding.GetEncoding("GB2312"));
  323. dynamic jaParams = new JArray();
  324. int rows = lines.Length;
  325. processBar.Maximum = rows;
  326. for (int i = 0; i < rows; i++)
  327. {
  328. processBar.Value = i + 1;
  329. Application.DoEvents();
  330. string lineTmp = lines[i];
  331. string[] arr = lineTmp.Split('\t');
  332. //判断是不是除外内容里的\r\n
  333. if (arr.Length < defaultColumns)
  334. {
  335. continue;
  336. }
  337. //判断是哪种目录类型
  338. switch (direcType)
  339. {
  340. //s收费项目
  341. case 0:
  342. {
  343. if (i == rows - 1)
  344. {
  345. currentMaxVerNO = arr[0];
  346. }
  347. jaParams.Add(GetMIDirectorynByTxt(arr));
  348. break;
  349. }
  350. case 1:
  351. {
  352. jaParams.Add(GetMIDiseByTxt(arr));
  353. break;
  354. }
  355. case 6://自付比例
  356. {
  357. if (i == rows - 1)
  358. {
  359. currentMaxVerNO = arr[0];
  360. }
  361. jaParams.Add(GetMIDirSelfPersentInfoByTxt(arr));
  362. break;
  363. }
  364. case 7://医保限价
  365. {
  366. if (i == rows - 1)
  367. {
  368. currentMaxVerNO = arr[0];
  369. }
  370. jaParams.Add(GetMIDirLimitPriceByTxt(arr));
  371. break;
  372. }
  373. }
  374. //每50行提交一次给后台
  375. int currentRows = i + 1;
  376. if ((currentRows % size == 0) && (i != 0))
  377. {
  378. switch (direcType)
  379. {
  380. case 6:
  381. {
  382. joRtn = mis.UpdateSelfPercent(jaParams);
  383. break;
  384. }
  385. case 7:
  386. {
  387. joRtn = mis.UpdateLimitPrice(jaParams);
  388. break;
  389. }
  390. default:
  391. {
  392. joRtn = mis.insertDirectory(jaParams);
  393. break;
  394. }
  395. }
  396. if (joRtn["errorCode"].ToString() != "0")
  397. {
  398. errorCount = errorCount + 1;
  399. errorMsg = "\r\n" + errorMsg + joRtn["errorMessage"].ToString();
  400. }
  401. jaParams = new JArray();
  402. }
  403. if ((currentRows == rows) && (currentRows % size != 0))
  404. {
  405. switch (direcType)
  406. {
  407. case 6:
  408. {
  409. joRtn = mis.UpdateSelfPercent(jaParams);
  410. break;
  411. }
  412. case 7:
  413. {
  414. joRtn = mis.UpdateLimitPrice(jaParams);
  415. break;
  416. }
  417. default:
  418. {
  419. joRtn = mis.insertDirectory(jaParams);
  420. break;
  421. }
  422. }
  423. if (joRtn["errorCode"].ToString() != "0")
  424. {
  425. errorCount = errorCount + 1;
  426. errorMsg = "\r\n" + errorMsg + joRtn["errorMessage"].ToString();
  427. }
  428. jaParams = new JArray();
  429. }
  430. }
  431. joRtn = JsonHelper.setExceptionJson(0 - errorCount, errorMsg, null);
  432. return joRtn;
  433. }
  434. catch (Exception ex)
  435. {
  436. joRtn = JsonHelper.setExceptionJson(-1, "insertDirectoryToMIIrisByTxt", ex.Message);
  437. return joRtn;
  438. }
  439. finally
  440. {
  441. Global.writeLog("PTMedicalInsurance.Business.MI.insertDirectoryToMIIrisByTxt", txtPath,joRtn.ToString());
  442. }
  443. }
  444. /// <summary>
  445. /// 字典导入
  446. /// </summary>
  447. /// <param name="uiProcessBar"></param>
  448. /// <param name="jaList"></param>
  449. /// <param name="type"></param>
  450. /// <returns></returns>
  451. public JObject importDictionary(Sunny.UI.UIProcessBar uiProcessBar, JArray jaList)
  452. {
  453. int errorCount = 0;
  454. JObject joRtn = new JObject();
  455. string errorMsg = "", outParam = "",errMsgList ="";
  456. Boolean bFail = false;
  457. try
  458. {
  459. int rows = jaList.Count;
  460. uiProcessBar.Maximum = rows;
  461. for (int i = 0; i < rows; i++)
  462. {
  463. uiProcessBar.Value = i + 1;
  464. Application.DoEvents();
  465. JObject joData = (JObject)jaList[i];
  466. joData.Add("HospitalDr", Global.inf.hospitalDr);
  467. joData.Add("InterfaceDr", Global.inf.interfaceDr);
  468. joRtn = mis.insertDictionarys(joData);
  469. if (JsonHelper.parseIrisRtnValue(joRtn, out errorMsg) != 0)
  470. {
  471. bFail = true;
  472. errMsgList = errMsgList + errorMsg;
  473. }
  474. }
  475. if (bFail)
  476. return JsonHelper.setExceptionJson(-1, "importDictionary", errMsgList);
  477. else
  478. return JsonHelper.setExceptionJson(0, "", "");
  479. }
  480. catch (Exception ex)
  481. {
  482. joRtn = JsonHelper.setExceptionJson(-1, "importDictinary", ex.Message);
  483. outParam = joRtn.ToString();
  484. return joRtn;
  485. }
  486. }
  487. }
  488. }