MedDirDownloadProcess.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Common;
  3. using PTMedicalInsurance.Helper;
  4. using PTMedicalInsurance.Variables;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace PTMedicalInsurance.Business
  12. {
  13. class MedDirDownloadProcess : AbstractProcess
  14. {
  15. public event EventHandler<string> VerChangeEvent;
  16. public override CallResult Process(JObject input)
  17. {
  18. throw new NotImplementedException();
  19. }
  20. /// <summary>
  21. /// 自动下载医保目录,直到最新版本(返回报错)
  22. /// </summary>
  23. /// <param name="directoryType"></param>
  24. /// <param name="uiProcessBar"></param>
  25. /// <param name="errorMessage"></param>
  26. /// <returns></returns>
  27. public int AutoDownload(int directoryType, Sunny.UI.UIProcessBar uiProcessBar, out string errorMessage)
  28. {
  29. int iResult = 0;
  30. errorMessage = "";
  31. try
  32. {
  33. while (iResult == 0)
  34. {
  35. JObject joMaxVerNO = mIS.getDirectoryMaxVersionNO(directoryType);
  36. string ver = joMaxVerNO["result"]["MaxVersionNO"].ToString();
  37. if (!string.IsNullOrEmpty(ver) && this.VerChangeEvent != null) {
  38. VerChangeEvent.Invoke(this, ver);
  39. }
  40. iResult = JsonHelper.parseIrisRtnValue(joMaxVerNO, out errorMessage);
  41. iResult = SingleDownload(ver, directoryType, uiProcessBar, out errorMessage);
  42. }
  43. return iResult;
  44. }
  45. catch (Exception ex)
  46. {
  47. errorMessage = ex.Message;
  48. return -1;
  49. }
  50. }
  51. public int AutoDownload(object[] o, out string errMsg, DataLoader.ProgressCallback callback, DataLoader.ProgressMaxCallback maxCallback, BackgroundWorker worker)
  52. {
  53. int directoryType = (int)o[0];
  54. Sunny.UI.UIProcessBar uiProcessBar = (Sunny.UI.UIProcessBar)o[1];
  55. int iResult = 0;
  56. errMsg = "";
  57. try
  58. {
  59. while (iResult == 0)
  60. {
  61. // 检查是否应取消操作
  62. if (worker.CancellationPending)
  63. {
  64. errMsg = "操作取消!";
  65. return -1; // 或者其他表示取消的返回值
  66. }
  67. JObject joMaxVerNO = mIS.getDirectoryMaxVersionNO(directoryType);
  68. string ver = joMaxVerNO["result"]["MaxVersionNO"].ToString();
  69. if (!string.IsNullOrEmpty(ver) && this.VerChangeEvent != null)
  70. {
  71. VerChangeEvent.Invoke(this, ver);
  72. }
  73. iResult = JsonHelper.parseIrisRtnValue(joMaxVerNO, out errMsg);
  74. iResult = SingleDownload(ver, directoryType, uiProcessBar, out errMsg);
  75. }
  76. return iResult;
  77. }
  78. catch (Exception ex)
  79. {
  80. errMsg = ex.Message;
  81. return -1;
  82. }
  83. }
  84. /// <summary>
  85. /// 医保目录单个版本号的下载
  86. /// </summary>
  87. /// <param name="ver"></param>
  88. /// <param name="directoryType"></param>
  89. /// <param name="uiProcessBar"></param>
  90. /// <param name="errorMessage"></param>
  91. /// <returns></returns>
  92. public int SingleDownload(string ver, int directoryType, Sunny.UI.UIProcessBar uiProcessBar, out string errorMessage)
  93. {
  94. string txtPath = string.Empty;
  95. errorMessage = "";
  96. int iResult = -1;
  97. TradeEnum trade = TradeEnum.DictionaryDownload;
  98. switch (directoryType)
  99. {
  100. case 0://药品
  101. {
  102. trade = TradeEnum.CMDirectory; //"1301";
  103. break;
  104. }
  105. case 1://诊疗
  106. {
  107. trade = TradeEnum.MedicalServiceDirectory;
  108. break;
  109. }
  110. case 2://材料
  111. {
  112. trade = TradeEnum.MaterialDirectory;
  113. break;
  114. }
  115. case 3://疾病诊断
  116. {
  117. trade = TradeEnum.DiseaseDiagDirectory;
  118. break;
  119. }
  120. case 4://手术
  121. {
  122. trade = TradeEnum.OperationDirectory;
  123. break;
  124. }
  125. case 5://慢性病
  126. {
  127. trade = TradeEnum.OPSDiseaseDirectory;
  128. break;
  129. }
  130. case 6://DRGs
  131. {
  132. trade = TradeEnum.DRGDiseaseDirectory;
  133. break; ;
  134. }
  135. case 7://日间手术
  136. {
  137. trade = TradeEnum.DayOperationDiseaseDirectory;
  138. break;
  139. }
  140. case 8://字典表
  141. {
  142. break;
  143. }
  144. case 9://中药饮片
  145. {
  146. trade = TradeEnum.CMPiecesDirectory;
  147. break;
  148. }
  149. case 10://医药机构制剂
  150. {
  151. trade = TradeEnum.MedOrgSelfDrug;
  152. break;
  153. }
  154. case 11://肿瘤形态学
  155. {
  156. trade = TradeEnum.TumorDirectory;
  157. break;
  158. }
  159. case 12://中医疾病目录
  160. {
  161. trade = TradeEnum.CMDiseaseDirectory;
  162. break;
  163. }
  164. case 13://中医证候目录
  165. {
  166. trade = TradeEnum.CMSyndromeDirectory;
  167. break;
  168. }
  169. }
  170. try
  171. {
  172. JObject joRtn = hBus.DownloadDirectory(trade, ver);
  173. //MessageBox.Show("往IRIS插入数据准备:" + joRtn.ToString());
  174. //if (JsonHelper.parseCenterRtnValue(joRtn, out errorMessage) == 0)
  175. if (JsonHelper.parseIrisRtnValue(joRtn, out errorMessage) == 0)
  176. {
  177. txtPath = joRtn["filePath"].ToString();
  178. //MessageBox.Show("获取txt数据往IRIS插入文件路径:"+ txtPath);
  179. DataImoport bus = new DataImoport();
  180. JObject joImportRtn = bus.importDataToIrisByTxt(txtPath, 30, directoryType + 1, uiProcessBar);
  181. //MessageBox.Show("往IRIS插入数据:" + joImportRtn.ToString());
  182. //if (JsonHelper.parseCenterRtnValue(joImportRtn, out errorMessage) == 0)
  183. if (JsonHelper.parseIrisRtnValue(joImportRtn, out errorMessage) == 0)
  184. {
  185. iResult = 0;
  186. }
  187. else
  188. {
  189. Global.writeLog(joImportRtn.ToString());
  190. errorMessage = "导入数据出现错误,请查看日志!";//joImportRtn["errorMessage"].ToString();
  191. }
  192. }
  193. return iResult;
  194. }
  195. catch (Exception ex)
  196. {
  197. errorMessage = "SingleDownload提示:" + ex.Message;
  198. return -1;
  199. }
  200. }
  201. }
  202. }