BizComponent_PMU.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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.PMU
  16. {
  17. public class BizComponent_PMU : BaseBizComponent, IBizComponent
  18. {
  19. const string Insert = "B01"; //增加个人纪录
  20. //const string Update = "B02"; //更新个人记录
  21. //const string Delete = "B03"; //删除个人记录
  22. //数据库连接
  23. protected Database ctx
  24. {
  25. get { return base.HealthCarectx; }
  26. }
  27. public BizComponent_PMU()
  28. {
  29. }
  30. ////HealthCareContainer HealthCareContainer = new HealthCareContainer();
  31. //private Database ctx = null;
  32. //public BizComponent_PMU(Database dbCtx)
  33. //{
  34. // ctx = dbCtx;
  35. //}
  36. public override string DoProcess(string m, string msgType)
  37. {
  38. string strMsgType = null;
  39. //try
  40. //{
  41. //try
  42. // {
  43. //取得消息类型 MAD新增 MUP更新 MDL删除 "MDC"作废 "MAC"恢复
  44. OperateXmlUtil helper = new OperateXmlUtil();
  45. string qurysql = "select count(*) from his_doct where DOCT_CODE=?DOCT_CODE";
  46. DbCommand command = ctx.GetSqlStringCommand(qurysql.ToString());
  47. string pkid = helper.XpathRead(m, "//*[@root='2.16.156.10011.1.4']", "extension");
  48. ctx.AddInParameter(command, "DOCT_CODE", System.Data.DbType.String, pkid);
  49. int counts = Convert.ToInt32(ctx.ExecuteScalar(command));
  50. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
  51. {
  52. //for (int i = 0; i < pmuB01.EDURepetitionsUsed; i++)
  53. //{
  54. if (counts == 0)
  55. {
  56. //没有查询到记录则新增,否则修改
  57. AddData(m, pkid);
  58. }
  59. else
  60. {
  61. UpDateData(m, pkid);
  62. }
  63. scope.Complete();
  64. }
  65. return string.Empty;
  66. }
  67. public void AddData(string message, string id)
  68. {
  69. #region 新增
  70. string sql = @"INSERT INTO his_doct
  71. ( DOCT_CODE ,
  72. DOCT_NAME
  73. )
  74. VALUES ( ?DOCT_CODE,
  75. ?DOCT_NAME)";
  76. DbCommand command = ctx.GetSqlStringCommand(sql.ToString());
  77. SetEntity(message, command, id);
  78. MySqlDataAccess.ExecuteNonQuery(ctx, command);
  79. #endregion
  80. }
  81. public void UpDateData(string message, string id)
  82. {
  83. #region 修改
  84. // string sql1 = @"update his_doct set
  85. // DOCT_NAME =?DOCT_NAME,
  86. // HIS_DEPT_CODE =?HIS_DEPT_CODE,
  87. // HIS_DEPT_NAME =?HIS_DEPT_NAME,
  88. // status=?status
  89. // where DOCT_CODE=?DOCT_CODE";
  90. string sql1 = @"update his_doct set
  91. DOCT_NAME =?DOCT_NAME
  92. where DOCT_CODE=?DOCT_CODE";
  93. DbCommand command1 = ctx.GetSqlStringCommand(sql1.ToString());
  94. SetEntity(message, command1, id);
  95. MySqlDataAccess.ExecuteNonQuery(ctx, command1);
  96. #endregion
  97. }
  98. public void SetEntity(string message, DbCommand command, string id)
  99. {
  100. string value = string.Empty;
  101. OperateXmlUtil xmlHelper = new OperateXmlUtil();
  102. ctx.AddInParameter(command, "DOCT_CODE", System.Data.DbType.String, id);
  103. var valueNode = xmlHelper.XpathRead(message, "//*[name()='healthCarePrincipalPerson']").Item(0);
  104. foreach (XmlNode xe in valueNode.ChildNodes)
  105. {
  106. if (xe.Name == "name")
  107. {
  108. value = xe.LastChild.LastChild.Attributes["value"].Value;
  109. ctx.AddInParameter(command, "DOCT_NAME", System.Data.DbType.String, value);
  110. break;
  111. }
  112. }
  113. value = xmlHelper.XpathRead(message, "//*[@root='2.16.156.10011.1.26']", "extension");
  114. ctx.AddInParameter(command, "HIS_DEPT_CODE", System.Data.DbType.AnsiString, value);
  115. valueNode = xmlHelper.XpathRead(message, "//*[name()='affiliatedPrincipalOrganization']").Item(0);
  116. foreach (XmlNode xe in valueNode.ChildNodes)
  117. {
  118. if (xe.Name == "name")
  119. {
  120. value = xe.LastChild.LastChild.Attributes["value"].Value;
  121. ctx.AddInParameter(command, "HIS_DEPT_NAME", System.Data.DbType.String, value);
  122. break;
  123. }
  124. }
  125. ctx.AddInParameter(command, "status", System.Data.DbType.String, "在用");
  126. //ctx.ExecuteNonQuery(command);
  127. }
  128. ///// <summary>
  129. ///// 获取当前时间
  130. ///// </summary>
  131. //internal DateTime GetNow(Database ctx)
  132. //{
  133. // object obj = (DateTime)MySqlDataAccess.ExecuteScalar(ctx, CommandType.Text, "select GETDATE()");
  134. // if (obj != null)
  135. // return Convert.ToDateTime(obj.ToString());
  136. // else
  137. // return DateTime.Now;
  138. //}
  139. //获取性别,转化
  140. public string GetSex(string value)
  141. {
  142. string sex = "0";
  143. switch (value)
  144. {
  145. case "F":
  146. sex = "1";//男
  147. break;
  148. case "男":
  149. sex = "1";//男
  150. break;
  151. case "M":
  152. sex = "2";//女
  153. break;
  154. case "女":
  155. sex = "2";//女
  156. break;
  157. default:
  158. sex = "9";//不定
  159. break;
  160. }
  161. return sex;
  162. }
  163. public string GetYsdj(string hiscodeid)
  164. {
  165. var sql = "SELECT CodeID FROM HealthCare.dbo.V_UserLevel WHERE HisCodeID=@HisCodeID";
  166. var cmd = MySqlDataAccess.GetSqlStringCommand(ctx, sql);
  167. MySqlDataAccess.AddInParameter(ctx, cmd, "HisCodeID", DbType.AnsiString, hiscodeid);
  168. string codeid = StrHelepr.Obj2StrTrim(MySqlDataAccess.DBExecuteScalar(ctx, cmd));
  169. if (codeid != null)
  170. {
  171. return codeid;
  172. }
  173. else
  174. {
  175. throw new Exception("V_UserLevel没有找到对应的医生等级");
  176. }
  177. }
  178. public string GetEmpType(string value)
  179. {
  180. string emptype = "";
  181. switch (value) // 员工分类
  182. {
  183. case "1"://1 医生
  184. emptype = "1";
  185. break;
  186. case "2"://2 护士
  187. emptype = "2";
  188. break;
  189. case "3"://3 财务人员
  190. emptype = "3";
  191. break;
  192. case "4"://4 药剂人员
  193. emptype = "4";
  194. break;
  195. case "5"://5 技师(检验)
  196. emptype = "5";
  197. break;
  198. case "6"://6 技师(影像)
  199. emptype = "6";
  200. break;
  201. case "7"://7 管理人员
  202. emptype = "7";
  203. break;
  204. case "8"://8 其他卫生技术人员
  205. emptype = "8";
  206. break;
  207. case "9"://9 其他人员
  208. emptype = "9";
  209. break;
  210. }
  211. return emptype;
  212. }
  213. }
  214. }
  215. #region 此为老版本代码
  216. /*
  217. Employee Module_Employee = new Employee();
  218. strMsgType = pmuB01.EVN.EventTypeCode.Value;
  219. #region STG
  220. STF stf = pmuB01.STF;
  221. Module_Employee.EmpNo = Convert.ToInt16(stf.PrimaryKeyValueSTF.Identifier.Value);// 员工代号
  222. Module_Employee.EmpCode = stf.GetStaffIDCode(0).ID.Value;// 员工代码
  223. Module_Employee.EmpName = stf.GetStaffName(0).GivenName.Value;// 姓名
  224. Module_Employee.EngName = stf.GetStaffName(0).GivenName.Value;// 英文姓名
  225. Module_Employee.IdNo = stf.DriverSLicenseNumberStaff.DriverSLicenseNumber.Value.Trim() ;// 身份证号 <<<<<<<<<<<<<<<<<<<<<< 目前ISNULL
  226. #region 性别转换
  227. // 1:男 2:女
  228. Module_Employee.Sex = His.MediIITransfer.MediII2Ue.GetSex(stf.AdministrativeSex.Value);
  229. #endregion
  230. Module_Employee.Birthday = His.Time.TryParseExact(stf.DateTimeOfBirth.TimeOfAnEvent.Value, "yyyyMMddhhmmss");
  231. #region 婚姻状况
  232. // 婚姻状况 (0:未婚,1:已婚,2:离婚)
  233. switch (stf.MaritalStatus.Text.Value)
  234. {
  235. case "S"://S 独身
  236. case "P"://P 同性恋
  237. case "G"://G 同居
  238. case "B"://B 未婚
  239. case "U"://U 未知
  240. case "O"://O 其他
  241. case "T"://T 未报告
  242. Module_Employee.MaritalStatus = "0";
  243. break;
  244. case "M"://M 结婚
  245. case "A": //A 分居
  246. case "W"://W 丧偶
  247. case "R"://R 已登记同性恋
  248. case "E"://E 合法分居
  249. // case "C"://C 普通法律
  250. case "I"://I 诉讼中
  251. Module_Employee.MaritalStatus = "1";
  252. break;
  253. case "D"://D 离婚
  254. Module_Employee.MaritalStatus = "2";
  255. break;
  256. default:
  257. Module_Employee.MaritalStatus = "0";
  258. break;
  259. }
  260. #endregion
  261. Module_Employee.HomeAdrArea = 0;// 住处区域代码 <<<<<<<<<<<<<<<<<<<<<<<<<<<
  262. Module_Employee.HomeAdrDesc = stf.GetOfficeHomeAddress(0).StreetAddress.StreetOrMailingAddress.Value;// 住处地址
  263. Module_Employee.HomeTel1 = stf.GetPhone(0).PhoneNumber.Value;// 住处电话1
  264. Module_Employee.HomeTel2 = "0"; // 住处电话2(不同步)
  265. Module_Employee.MobilePhone = stf.GetPhone(0).PhoneNumber.Value; // 移动电话
  266. Module_Employee.NativeAdrArea = 0;// 户籍区域代码(不同步)
  267. Module_Employee.NativeAdrDesc = "";// 户籍地址(不同步)
  268. Module_Employee.NativeTel = "";// 户籍电话(不同步)
  269. Module_Employee.ConName = "";// 联系人姓名(不同步)
  270. Module_Employee.ConTel1 = "";// 络人电话(不同步)
  271. Module_Employee.ConTel2 = "";// 络人电话(不同步)
  272. Module_Employee.ConAdrArea = 0;// 联系人区域代码(不同步)
  273. Module_Employee.ConAdrDesc = "";// 联系人地址(不同步)
  274. Module_Employee.Affiliation = "";// 与联系人关系(不同步)
  275. try
  276. {
  277. string sHireDate =stf.GetInstitutionActivationDate(0).Date.TimeOfAnEvent.Value;
  278. DateTime dtHireDate = His.Time.TryParseExact(sHireDate, "yyyyMMddhhmmss");
  279. Module_Employee.HireDate = dtHireDate == His.Time.MaxDateTime ? Convert.ToDateTime("1911-01-01 00:00:00") : dtHireDate; // 到职日期
  280. }
  281. catch
  282. {
  283. Module_Employee.HireDate = Convert.ToDateTime("1911-01-01 00:00:00");
  284. }
  285. Module_Employee.Zone = "A";// 归属院区(联众会开栏位**********)<<<<<<<<<<<<<<<<<<<<<<
  286. string tmp = stf.GetDepartment(0).Identifier.Value;
  287. try
  288. {
  289. string sDepartNo = His.MediIITransfer.MediII2Ue.GetDepartNo(stf.GetDepartment(0).Identifier.Value);
  290. Module_Employee.DepartNo = Convert.ToInt16(sDepartNo);// 部门代码
  291. }
  292. catch (Exception ex)
  293. {
  294. Module_Employee.DepartNo = -1;
  295. }
  296. Module_Employee.EmpType = stf.GetStaffType(0).Value;
  297. #region 员工分类
  298. switch (stf.GetStaffType(0).Value) // 员工分类
  299. {
  300. case "1"://1 医生
  301. Module_Employee.EmpType = "1";
  302. break;
  303. case "2"://2 护士
  304. Module_Employee.EmpType = "2";
  305. break;
  306. case "3"://3 财务人员
  307. Module_Employee.EmpType = "3";
  308. break;
  309. case "4"://4 药剂人员
  310. Module_Employee.EmpType = "4";
  311. break;
  312. case "5"://5 技师(检验)
  313. case "6"://6 技师(影像)
  314. case "7"://7 管理人员
  315. case "8"://8 其他卫生技术人员
  316. case "9"://9 其他人员
  317. Module_Employee.EmpType = "0";
  318. break;
  319. }
  320. #endregion
  321. string tmp2 = stf.JobCodeClass.JobCode.Value;
  322. try
  323. {
  324. Module_Employee.Title = Convert.ToInt16(stf.JobCodeClass.JobCode.Value);// 职称
  325. }
  326. catch (Exception ex)
  327. {
  328. Module_Employee.Title = -1;
  329. }
  330. Module_Employee.ChiefNo = Convert.ToInt16(stf.GetHospitalService(0).Identifier.Value);// 职位
  331. string tmp3 = stf.GetDepartment(0).Identifier.Value;
  332. try
  333. {
  334. string sWorkDepartNo = His.MediIITransfer.MediII2Ue.GetDepartNo(stf.GetDepartment(0).Identifier.Value);
  335. Module_Employee.WorkDepartNo = Convert.ToInt16(sWorkDepartNo);// 工作单位代号 <<<<<<<<<<<<<
  336. }
  337. catch
  338. {
  339. Module_Employee.WorkDepartNo = -1;
  340. }
  341. Module_Employee.SimpleTel = stf.GetPhone(0).PhoneNumber.Value;// 速拨码
  342. Module_Employee.SubTel = stf.GetPhone(0).PhoneNumber.Value;// 分机
  343. string sPassword = stf.GetBackupPersonID(0).Identifier.Value;
  344. Module_Employee.Password = sPassword == null ? "" : sPassword;
  345. Module_Employee.PasswordTime = DateTime.Now; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  346. Module_Employee.PressCard = 0;// 工作卡号(暫時不填)
  347. string sActiveInactiveFlag = stf.ActiveInactiveFlag.Value; // A,在职;I,离职
  348. Module_Employee.ResignDate = sActiveInactiveFlag == "A" ? His.Time.MaxDateTime : His.Time.MaxDateTime;
  349. int iIntParse;
  350. int.TryParse(stf.PreferredMethodOfContact.Identifier.Value, out iIntParse);
  351. if (iIntParse != 0)
  352. {
  353. Module_Employee.UpdateUser = Convert.ToInt16(iIntParse);// 最后修改人
  354. }
  355. Module_Employee.UpdateTime = DateTime.Now;
  356. Module_Employee.EMail = "";// 电子信箱(不同步)
  357. Module_Employee.Remark = "";// 备注说明(不同步)
  358. Module_Employee.Team = 0;// 组别
  359. #endregion
  360. #region 測試
  361. string sErrMsg;
  362. if (string.IsNullOrEmpty(Module_Employee.IdNo))
  363. {
  364. sErrMsg = "【身份证】无法为空";
  365. SetACK(m, "ACK", strMsgType, "ACK", sErrMsg);
  366. }
  367. if (string.IsNullOrEmpty(Module_Employee.HomeAdrDesc))
  368. {
  369. Module_Employee.HomeAdrDesc = "";
  370. }
  371. if (string.IsNullOrEmpty(Module_Employee.HomeTel1))
  372. {
  373. Module_Employee.HomeTel1 = "";
  374. }
  375. if (string.IsNullOrEmpty(Module_Employee.HomeTel1))
  376. {
  377. Module_Employee.HomeTel1 = ""; // 住处电话1
  378. }
  379. if (string.IsNullOrEmpty(Module_Employee.MobilePhone))
  380. {
  381. Module_Employee.MobilePhone = ""; // 移动电话1
  382. }
  383. if (string.IsNullOrEmpty(Module_Employee.MobilePhone))
  384. {
  385. Module_Employee.MobilePhone = ""; // 移动电话1
  386. }
  387. //Module_Employee.HireDate = His.Time.TryParseExact(sHireDate, "yyyyMMdd"); // 到职日期
  388. //Module_Employee.Title = Convert.ToInt16(stf.JobCodeClass.JobCode.Value);// 职称
  389. //Module_Employee.ChiefNo = Convert.ToInt16(stf.GetHospitalService(0).Identifier.Value);// 职位
  390. if (string.IsNullOrEmpty(Module_Employee.MobilePhone))
  391. {
  392. Module_Employee.SimpleTel = "";// 速拨码
  393. }
  394. if (string.IsNullOrEmpty(Module_Employee.MobilePhone))
  395. {
  396. Module_Employee.SubTel = "";// 分机
  397. }
  398. if (string.IsNullOrEmpty(Module_Employee.Password))
  399. {
  400. sErrMsg = "【密碼】无法为空";
  401. SetACK(m, "ACK", strMsgType, "ACK", sErrMsg);
  402. }
  403. //if (Module_Employee.HireDate == DateTime.MinValue)
  404. //{
  405. // Module_Employee.HireDate = His.Time.MaxDateTime;
  406. //}
  407. if (Module_Employee.PasswordTime == DateTime.MinValue)
  408. {
  409. Module_Employee.PasswordTime = His.Time.MaxDateTime;
  410. }
  411. if (Module_Employee.UpdateTime == DateTime.MinValue)
  412. {
  413. Module_Employee.UpdateTime = His.Time.MaxDateTime;
  414. }
  415. if (Module_Employee.ResignDate == DateTime.MinValue)
  416. {
  417. Module_Employee.ResignDate = His.Time.MaxDateTime;
  418. }
  419. //Module_Employee.ResignDate = His.Time.TryParseExact(sResignDate, "yyyyMMdd"); // 离职日期
  420. #endregion
  421. // 開始存入資料庫
  422. int iEmpNo = Convert.ToInt16(stf.PrimaryKeyValueSTF.Identifier.Value);// 员工代号
  423. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
  424. {
  425. switch (strMsgType)
  426. {
  427. case Insert:
  428. case Update:
  429. EmployeeDelete(iEmpNo, ref HealthCareContainer, scope, ref Module_Employee);
  430. EmployeeInsert(iEmpNo, ref HealthCareContainer, scope, ref Module_Employee);
  431. break;
  432. case Delete:
  433. EmployeeDelete(iEmpNo, ref HealthCareContainer, scope, ref Module_Employee);
  434. break;
  435. }
  436. #region 存入資料庫
  437. try
  438. {
  439. HealthCareContainer.SaveChanges();
  440. }
  441. catch (System.Data.Entity.Validation.DbEntityValidationException ex)
  442. {
  443. scope.Dispose();
  444. throw ex;
  445. }
  446. #endregion
  447. scope.Complete();
  448. }
  449. */
  450. // return string.Empty;
  451. // }
  452. // catch (Exception ex)
  453. // {
  454. // string errMsg = string.Empty;
  455. // if (ex.InnerException == null)
  456. // {
  457. // errMsg = ex.Message + "\r\n" + ex.StackTrace;
  458. // }
  459. // else
  460. // {
  461. // errMsg = ex.Message + "\r\n" + ex.InnerException.Message + "\r\n" + ex.InnerException.StackTrace;
  462. // }
  463. // return errMsg;
  464. // }
  465. //}
  466. // catch (System.Data.Entity.Validation.DbEntityValidationException ex)
  467. //{
  468. //var tmp = ex.EntityValidationErrors.FirstOrDefault().ValidationErrors;
  469. //string errString = "";
  470. //foreach (var item in tmp)
  471. //{
  472. // errString += item.ErrorMessage;
  473. //}
  474. //string ack = SetACK(m, "ACK", mType, "ACK", ex.EntityValidationErrors.ToString());
  475. //throw new Exception(string.Format("{0}\r\n{1}", ex.EntityValidationErrors.ToString()));
  476. //return ex.Message;
  477. //}
  478. //}
  479. /*
  480. public void EmployeeInsert(int iEmpNo, ref HealthCareContainer HealthCareContainer, TransactionScope scope, ref Employee Module_Employee)
  481. {
  482. try
  483. {
  484. HealthCareContainer.Employee.Add(Module_Employee);
  485. }
  486. catch (Exception ex)
  487. {
  488. scope.Dispose();
  489. throw ex;
  490. }
  491. }
  492. public void EmployeeDelete(int iEmpNo, ref HealthCareContainer HealthCareContainer, TransactionScope scope, ref Employee Module_Employee)
  493. {
  494. try
  495. {
  496. IEnumerable<Employee> EmployeeList = HealthCareContainer.Employee.Where(x => x.EmpNo == iEmpNo);
  497. if (EmployeeList.Count() != 0)
  498. {
  499. Employee Module_Employee_Del = EmployeeList.FirstOrDefault();
  500. HealthCareContainer.Employee.Remove(Module_Employee_Del);
  501. HealthCareContainer.SaveChanges();
  502. }
  503. }
  504. catch (Exception ex)
  505. {
  506. scope.Dispose();
  507. throw ex;
  508. }
  509. }
  510. */
  511. // }
  512. //}
  513. #endregion