BizComponent_DFT.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. using System;
  2. using System.Data;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. //using MediII.Adapter.BaseBiz;
  7. using System.Data.Common;
  8. using System.Transactions;
  9. using Microsoft.Practices.EnterpriseLibrary.Data;
  10. //using MediII.Adapter.Model.UE;
  11. using System.Globalization;
  12. using MediII.Adapter.BizComponent.Base;
  13. using IL.Common;
  14. using System.Xml;
  15. namespace MediII.Adapter.BizComponent.DFT
  16. {
  17. public class BizComponent_DFT : BaseBizComponent, IBizComponent
  18. {
  19. const string Insert = "B01"; //增加个人纪录
  20. //const string Update = "B02"; //更新个人记录
  21. //const string Delete = "B03"; //删除个人记录
  22. //数据库连接
  23. protected Database ctx;
  24. protected Database Scanctx;
  25. public BizComponent_DFT()
  26. {
  27. DatabaseProviderFactory factory = new DatabaseProviderFactory();
  28. ctx = factory.Create("HealthCare");
  29. Scanctx = factory.CreateDefault();
  30. }
  31. ////HealthCareContainer HealthCareContainer = new HealthCareContainer();
  32. //private Database ctx = null;
  33. //public BizComponent_PMU(Database dbCtx)
  34. //{
  35. // ctx = dbCtx;
  36. //}
  37. public override string DoProcess(string m, string msgType, string ID)
  38. {
  39. string strMsgType = null;
  40. var resultCode = string.Empty;
  41. var result = string.Empty;
  42. //try
  43. //{
  44. //try
  45. // {
  46. //取得消息类型 MAD新增 MUP更新 MDL删除 "MDC"作废 "MAC"恢复
  47. OperateXmlUtil helper = new OperateXmlUtil();
  48. WebService server = new WebService();
  49. string orgCode = System.Configuration.ConfigurationManager.AppSettings["orgCode"];
  50. var cert = System.Configuration.ConfigurationManager.AppSettings["cert"];
  51. var startTime="";
  52. var endTime = DateTime.Now.ToString("yyyy-MM-dd");
  53. var pageIndex="0";
  54. var pageSize = System.Configuration.ConfigurationManager.AppSettings["pageSize"];
  55. GetStartTime(ID,out startTime,out pageIndex);
  56. string msgBody = helper.GetMsgBody(orgCode, "startTime", startTime, "endTime", endTime, pageIndex, pageSize);
  57. string msgHead = helper.GetMsgHead("getChargeitem", cert);
  58. string rtnMsg = server.TestInterface(msgHead, msgHead);
  59. //存储访问记录
  60. MessageHelper.SaveSendMsg(Scanctx, ID, "DFT^B01[B01]", msgHead, msgBody, rtnMsg);
  61. //消息判断是否成功
  62. if (!helper.isSuccess(rtnMsg, ref resultCode, ref result))
  63. {
  64. throw new Exception(result);
  65. }
  66. XmlNodeList root = helper.XpathRead(rtnMsg, "//returnContents//returnContent");
  67. if (root.Count <= 0)
  68. return string.Empty;
  69. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
  70. {
  71. var usql = @"update item_his_original set yn_code=@yn_code,item_name=@item_name,fee_code=@fee_code,fee_name=@fee_code,spell_code=@spell_code,price=@price,status=@status,status_date=@status_date where item_code=@item_code";
  72. var sql = @"insert into item_his_original(item_code,yn_code,item_name,fee_code,fee_name,spell_code,price,status,status_date) Values(@item_code,@yn_code,@item_name,@fee_code,@fee_name,@spell_code,@price,@status,@status_date);";
  73. foreach (XmlElement xe in root)
  74. {
  75. var iSet = GetDOCT(xe.SelectSingleNode("item_code").InnerText);
  76. if (iSet <= 0)
  77. {
  78. var cmd = SqlDataAccess.GetSqlStringCommand(ctx, sql);
  79. ctx.AddInParameter(cmd, "item_code", System.Data.DbType.String, xe.SelectSingleNode("ITEM_CODE").InnerText);
  80. ctx.AddInParameter(cmd, "yn_code", System.Data.DbType.String, xe.SelectSingleNode("YN_CODE").InnerText);
  81. ctx.AddInParameter(cmd, "item_name", System.Data.DbType.String, xe.SelectSingleNode("ITEM_NAME").InnerText);
  82. ctx.AddInParameter(cmd, "fee_code", System.Data.DbType.String, xe.SelectSingleNode("FEE_CODE").InnerText);
  83. ctx.AddInParameter(cmd, "fee_name", System.Data.DbType.String, xe.SelectSingleNode("FEE_NAME").InnerText);
  84. ctx.AddInParameter(cmd, "spell_code", System.Data.DbType.String, xe.SelectSingleNode("SPELL_CODE").InnerText);
  85. decimal price = 0;
  86. try
  87. {
  88. decimal.TryParse(xe.SelectSingleNode("PRICE").InnerText, out price);
  89. this.ctx.AddInParameter(cmd, "price", System.Data.DbType.Decimal, price);
  90. }
  91. catch
  92. {
  93. this.ctx.AddInParameter(cmd, "price", System.Data.DbType.Decimal, 0);
  94. }
  95. //ctx.AddInParameter(cmd, "price", System.Data.DbType.Decimal, xe.SelectSingleNode("PRICE").InnerText);
  96. ctx.AddInParameter(cmd, "status", System.Data.DbType.String, xe.SelectSingleNode("STATUS").InnerText);
  97. var date = xe.SelectSingleNode("STATUS_DATE").InnerText;
  98. DateTime time = DateTime.Now;
  99. if (!string.IsNullOrWhiteSpace(date))
  100. {
  101. if (!DateTime.TryParse(date, out time))
  102. {
  103. time = DateTime.Now;
  104. }
  105. }
  106. ctx.AddInParameter(cmd, "status_date", System.Data.DbType.DateTime, time);
  107. SqlDataAccess.DBExecuteNonQuery(ctx, cmd);
  108. }
  109. else
  110. {
  111. var cmd = SqlDataAccess.GetSqlStringCommand(ctx, usql);
  112. ctx.AddInParameter(cmd, "item_code", System.Data.DbType.String, xe.SelectSingleNode("ITEM_CODE").InnerText);
  113. ctx.AddInParameter(cmd, "yn_code", System.Data.DbType.String, xe.SelectSingleNode("YN_CODE").InnerText);
  114. ctx.AddInParameter(cmd, "item_name", System.Data.DbType.String, xe.SelectSingleNode("ITEM_NAME").InnerText);
  115. ctx.AddInParameter(cmd, "fee_code", System.Data.DbType.String, xe.SelectSingleNode("FEE_CODE").InnerText);
  116. ctx.AddInParameter(cmd, "fee_name", System.Data.DbType.String, xe.SelectSingleNode("FEE_NAME").InnerText);
  117. ctx.AddInParameter(cmd, "spell_code", System.Data.DbType.String, xe.SelectSingleNode("SPELL_CODE").InnerText);
  118. decimal price = 0;
  119. try
  120. {
  121. decimal.TryParse(xe.SelectSingleNode("PRICE").InnerText, out price);
  122. this.ctx.AddInParameter(cmd, "price", System.Data.DbType.Decimal, price);
  123. }
  124. catch
  125. {
  126. this.ctx.AddInParameter(cmd, "price", System.Data.DbType.Decimal, 0);
  127. }
  128. //ctx.AddInParameter(cmd, "price", System.Data.DbType.Decimal, xe.SelectSingleNode("price").InnerText);
  129. ctx.AddInParameter(cmd, "status", System.Data.DbType.String, xe.SelectSingleNode("STATUS").InnerText);
  130. var date = xe.SelectSingleNode("STATUS_DATE").InnerText;
  131. DateTime time = DateTime.Now;
  132. if (!string.IsNullOrWhiteSpace(date))
  133. {
  134. if (!DateTime.TryParse(date, out time))
  135. {
  136. time = DateTime.Now;
  137. }
  138. }
  139. ctx.AddInParameter(cmd, "status_date", System.Data.DbType.DateTime, time);
  140. SqlDataAccess.DBExecuteNonQuery(ctx, cmd);
  141. }
  142. }
  143. scope.Complete();
  144. }
  145. using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
  146. {
  147. var ScanSql = @"update HL7_Scan set OtherNo2=@OtherNo2 where ID=@ID";
  148. var ucmd = SqlDataAccess.GetSqlStringCommand(Scanctx, ScanSql);
  149. Scanctx.AddInParameter(ucmd, "ID", System.Data.DbType.String, ID);
  150. Scanctx.AddInParameter(ucmd, "OtherNo2", System.Data.DbType.String, pageIndex);
  151. SqlDataAccess.DBExecuteNonQuery(Scanctx, ucmd);
  152. transactionScope.Complete();
  153. }
  154. return string.Empty;
  155. }
  156. public void AddData(string message, string id)
  157. {
  158. #region 新增
  159. string sql = @"INSERT INTO dbo.his_doct
  160. ( DOCT_CODE ,
  161. DOCT_NAME ,
  162. HIS_DEPT_CODE ,
  163. HIS_DEPT_NAME ,
  164. status
  165. )
  166. VALUES ( @DOCT_CODE,
  167. @DOCT_NAME ,
  168. @HIS_DEPT_CODE ,
  169. @HIS_DEPT_NAME ,
  170. @status)";
  171. DbCommand command = ctx.GetSqlStringCommand(sql.ToString());
  172. SetEntity(message, command, id);
  173. SqlDataAccess.ExecuteNonQuery(ctx, command);
  174. #endregion
  175. }
  176. public void UpDateData(string message, string id)
  177. {
  178. #region 修改
  179. string sql1 = @"update dbo.his_doct set
  180. DOCT_NAME =@DOCT_NAME,
  181. HIS_DEPT_CODE =@HIS_DEPT_CODE,
  182. HIS_DEPT_NAME =@HIS_DEPT_NAME,
  183. status=@status
  184. where DOCT_CODE=@DOCT_CODE";
  185. DbCommand command1 = ctx.GetSqlStringCommand(sql1.ToString());
  186. SetEntity(message, command1, id);
  187. SqlDataAccess.ExecuteNonQuery(ctx, command1);
  188. #endregion
  189. }
  190. public void SetEntity(string message, DbCommand command, string id)
  191. {
  192. string value = string.Empty;
  193. OperateXmlUtil xmlHelper = new OperateXmlUtil();
  194. ctx.AddInParameter(command, "DOCT_CODE", System.Data.DbType.String, id);
  195. var valueNode = xmlHelper.XpathRead(message, "//*[name()='healthCarePrincipalPerson']").Item(0);
  196. foreach (XmlNode xe in valueNode.ChildNodes)
  197. {
  198. if (xe.Name == "name")
  199. {
  200. value = xe.LastChild.LastChild.Attributes["value"].Value;
  201. ctx.AddInParameter(command, "DOCT_NAME", System.Data.DbType.String, value);
  202. break;
  203. }
  204. }
  205. value = xmlHelper.XpathRead(message, "//*[@root='2.16.156.10011.1.26']", "extension");
  206. ctx.AddInParameter(command, "HIS_DEPT_CODE", System.Data.DbType.AnsiString, value);
  207. valueNode = xmlHelper.XpathRead(message, "//*[name()='affiliatedPrincipalOrganization']").Item(0);
  208. foreach (XmlNode xe in valueNode.ChildNodes)
  209. {
  210. if (xe.Name == "name")
  211. {
  212. value = xe.LastChild.LastChild.Attributes["value"].Value;
  213. ctx.AddInParameter(command, "HIS_DEPT_NAME", System.Data.DbType.String, value);
  214. break;
  215. }
  216. }
  217. ctx.AddInParameter(command, "status", System.Data.DbType.String, "在用");
  218. //ctx.ExecuteNonQuery(command);
  219. }
  220. public int GetDOCT(string DOCT_Code)
  221. {
  222. var sql = "SELECT count(1) FROM dbo.item_his_original WITH(NOLOCK) WHERE item_code=@item_code";
  223. var cmd = ctx.DBGetSqlStringCommand(sql);
  224. ctx.AddInParameter(cmd, "item_code", DbType.String, DOCT_Code);
  225. var obj = int.Parse(StrHelepr.Obj2StrTrim(ctx.DBExecuteScalar(cmd)));
  226. return obj;
  227. }
  228. public void GetStartTime(string ID, out string startTime, out string pageIndex)
  229. {
  230. string text = "SELECT OtherNo1,OtherNo2 FROM dbo.HL7_Scan WITH(NOLOCK) where ID=@ID";
  231. System.Data.Common.DbCommand dbCommand = SqlDataAccess.DBGetSqlStringCommand(this.Scanctx, text);
  232. this.Scanctx.AddInParameter(dbCommand, "ID", System.Data.DbType.String, ID);
  233. System.Data.DataSet dataSet = this.Scanctx.ExecuteDataSet(dbCommand);
  234. startTime = dataSet.Tables[0].Rows[0][0].ToString();
  235. pageIndex = (int.Parse(dataSet.Tables[0].Rows[0][1].ToString()) + 1).ToString();
  236. }
  237. }
  238. }