MedDirDownloadProcess.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Helper;
  3. using PTMedicalInsurance.Variables;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace PTMedicalInsurance.Business
  10. {
  11. class MedDirDownloadProcess : AbstractProcess
  12. {
  13. public event EventHandler<string> VerChangeEvent;
  14. public override CallResult Process(JObject input)
  15. {
  16. throw new NotImplementedException();
  17. }
  18. /// <summary>
  19. /// 自动下载医保目录,直到最新版本(返回报错)
  20. /// </summary>
  21. /// <param name="directoryType"></param>
  22. /// <param name="uiProcessBar"></param>
  23. /// <param name="errorMessage"></param>
  24. /// <returns></returns>
  25. public int AutoDownload(int directoryType, Sunny.UI.UIProcessBar uiProcessBar, out string errorMessage)
  26. {
  27. int iResult = 0;
  28. errorMessage = "";
  29. try
  30. {
  31. while (iResult == 0)
  32. {
  33. JObject joMaxVerNO = mIS.getDirectoryMaxVersionNO(directoryType);
  34. string ver = joMaxVerNO["result"]["MaxVersionNO"].ToString();
  35. if (!string.IsNullOrEmpty(ver) && this.VerChangeEvent != null) {
  36. VerChangeEvent.Invoke(this, ver);
  37. }
  38. iResult = JsonHelper.parseIrisRtnValue(joMaxVerNO, out errorMessage);
  39. iResult = SingleDownload(ver, directoryType, uiProcessBar, out errorMessage);
  40. }
  41. return iResult;
  42. }
  43. catch (Exception ex)
  44. {
  45. errorMessage = ex.Message;
  46. return -1;
  47. }
  48. }
  49. /// <summary>
  50. /// 医保目录单个版本号的下载
  51. /// </summary>
  52. /// <param name="ver"></param>
  53. /// <param name="directoryType"></param>
  54. /// <param name="uiProcessBar"></param>
  55. /// <param name="errorMessage"></param>
  56. /// <returns></returns>
  57. public int SingleDownload(string ver, int directoryType, Sunny.UI.UIProcessBar uiProcessBar, out string errorMessage)
  58. {
  59. string txtPath = string.Empty;
  60. errorMessage = "";
  61. int iResult = -1;
  62. TradeEnum trade = TradeEnum.DictionaryDownload;
  63. switch (directoryType)
  64. {
  65. case 0://药品
  66. {
  67. trade = TradeEnum.CMDirectory; //"1301";
  68. break;
  69. }
  70. case 1://诊疗
  71. {
  72. trade = TradeEnum.MedicalServiceDirectory;
  73. break;
  74. }
  75. case 2://材料
  76. {
  77. trade = TradeEnum.MaterialDirectory;
  78. break;
  79. }
  80. case 3://疾病诊断
  81. {
  82. trade = TradeEnum.DiseaseDiagDirectory;
  83. break;
  84. }
  85. case 4://手术
  86. {
  87. trade = TradeEnum.OperationDirectory;
  88. break;
  89. }
  90. case 5://慢性病
  91. {
  92. trade = TradeEnum.OPSDiseaseDirectory;
  93. break;
  94. }
  95. case 6://DRGs
  96. {
  97. trade = TradeEnum.DRGDiseaseDirectory;
  98. break; ;
  99. }
  100. case 7://日间手术
  101. {
  102. trade = TradeEnum.DayOperationDiseaseDirectory;
  103. break;
  104. }
  105. case 8://字典表
  106. {
  107. break;
  108. }
  109. case 9://中药饮片
  110. {
  111. trade = TradeEnum.CMPiecesDirectory;
  112. break;
  113. }
  114. case 10://医药机构制剂
  115. {
  116. trade = TradeEnum.MedOrgSelfDrug;
  117. break;
  118. }
  119. }
  120. try
  121. {
  122. JObject joRtn = hBus.DownloadDirectory(trade, ver);
  123. //MessageBox.Show("往IRIS插入数据准备:" + joRtn.ToString());
  124. //if (JsonHelper.parseCenterRtnValue(joRtn, out errorMessage) == 0)
  125. if (JsonHelper.parseIrisRtnValue(joRtn, out errorMessage) == 0)
  126. {
  127. txtPath = joRtn["filePath"].ToString();
  128. //MessageBox.Show("获取txt数据往IRIS插入文件路径:"+ txtPath);
  129. DataImoport bus = new DataImoport();
  130. JObject joImportRtn = bus.importDataToIrisByTxt(txtPath, 50, directoryType + 1, uiProcessBar);
  131. //MessageBox.Show("往IRIS插入数据:" + joImportRtn.ToString());
  132. //if (JsonHelper.parseCenterRtnValue(joImportRtn, out errorMessage) == 0)
  133. if (JsonHelper.parseIrisRtnValue(joImportRtn, out errorMessage) == 0)
  134. {
  135. iResult = 0;
  136. }
  137. else
  138. {
  139. Global.writeLog(joImportRtn.ToString());
  140. errorMessage = "导入数据出现错误,请查看日志!";//joImportRtn["errorMessage"].ToString();
  141. }
  142. }
  143. return iResult;
  144. }
  145. catch (Exception ex)
  146. {
  147. errorMessage = "SingleDownload提示:" + ex.Message;
  148. return -1;
  149. }
  150. }
  151. }
  152. }