WD_PatientInfoDataAccess.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. using System;
  2. using Dapper;
  3. using HNWD.Pregrant.Model;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace HNWD.Pregrant.DataAccess
  7. {
  8. public class WD_PatientInfoDataAccess : GenericDataAccess<WD_PatientInfo>
  9. {
  10. private WD_PatientInfo wd_DeviceInfo = null;
  11. public WD_PatientInfoExt ext = new WD_PatientInfoExt();
  12. private readonly static WD_PatientInfoDataAccess wd_PatientInfoDataAccess = new WD_PatientInfoDataAccess(null);
  13. private readonly static object lockobj = new object();
  14. public static WD_PatientInfoDataAccess GetInstance()
  15. {
  16. lock (lockobj)
  17. {
  18. return wd_PatientInfoDataAccess;
  19. }
  20. }
  21. private WD_PatientInfoDataAccess(WD_PatientInfo wd_PatientInfo)
  22. {
  23. this.wd_DeviceInfo = wd_PatientInfo;
  24. }
  25. private string webPath = string.Empty;
  26. public WD_PatientInfoDataAccess(string webPath,string r2)
  27. {
  28. this.webPath = webPath;
  29. }
  30. public List<WD_PatientInfo> Query()
  31. {
  32. string strSql = " select {0} from [WD_PatientInfo] where [ID]=" + this.wd_DeviceInfo.ID;
  33. ext.messageDataList = this.Query(strSql, new WD_PatientInfo());
  34. ext.messageDataList.ForEach(f => f.bSuccess = this.bSuccess);
  35. ext.messageDataList.ForEach(f => f.Code = this.Code);
  36. ext.messageDataList.ForEach(f => f.Message = this.Message);
  37. ext.messageDataList.ForEach(f => f.Rows = this.Rows);
  38. ext.bSuccess = this.bSuccess;
  39. ext.Code = this.Code;
  40. ext.Message = this.Message;
  41. ext.Rows = this.Rows;
  42. this.SetSexAndAge(ext);
  43. return ext.messageDataList;
  44. }
  45. public List<WD_PatientInfo> QueryAll()
  46. {
  47. string strSql = " select DATEDIFF(day,getdate(),[PATIENT_DATETIME]) DiffDays , {0} from [WD_PatientInfo] ";
  48. ext.messageDataList = this.Query(strSql, new WD_PatientInfo());
  49. ext.messageDataList.ForEach(f => f.bSuccess = this.bSuccess);
  50. ext.messageDataList.ForEach(f => f.Code = this.Code);
  51. ext.messageDataList.ForEach(f => f.Message = this.Message);
  52. ext.messageDataList.ForEach(f => f.Rows = this.Rows);
  53. ext.bSuccess = this.bSuccess;
  54. ext.Code = this.Code;
  55. ext.Message = this.Message;
  56. ext.Rows = this.Rows;
  57. this.SetSexAndAge(ext);
  58. return ext.messageDataList;
  59. }
  60. public List<WD_PatientInfo> QueryNativeAll()
  61. {
  62. string strSql = " select DATEDIFF(day,getdate(),[PATIENT_DATETIME]) DiffDays , {0} from [WD_PatientInfo] ";
  63. ext.messageDataList = this.Query(strSql, new WD_PatientInfo());
  64. ext.messageDataList.ForEach(f => f.bSuccess = this.bSuccess);
  65. ext.messageDataList.ForEach(f => f.Code = this.Code);
  66. ext.messageDataList.ForEach(f => f.Message = this.Message);
  67. ext.messageDataList.ForEach(f => f.Rows = this.Rows);
  68. ext.bSuccess = this.bSuccess;
  69. ext.Code = this.Code;
  70. ext.Message = this.Message;
  71. ext.Rows = this.Rows;
  72. return ext.messageDataList;
  73. }
  74. private void SetSexAndAge(WD_PatientInfoExt ex)
  75. {
  76. foreach (WD_PatientInfo wd in ex.messageDataList)
  77. {
  78. if (wd.PATIENT_SEX == "1")
  79. {
  80. wd.PATIENT_SEX = "男";
  81. }
  82. else if (wd.PATIENT_SEX == "2")
  83. {
  84. wd.PATIENT_SEX = "女";
  85. }
  86. else
  87. {
  88. wd.PATIENT_SEX = "未知";
  89. }
  90. if (wd.PATIENT_BABYSEX == "1")
  91. {
  92. wd.PATIENT_BABYSEX = "男";
  93. }
  94. else if (wd.PATIENT_BABYSEX == "2")
  95. {
  96. wd.PATIENT_BABYSEX = "女";
  97. }
  98. else
  99. {
  100. wd.PATIENT_BABYSEX = "未知";
  101. }
  102. if (wd.PATIENT_AGE_UNIT == "Y")
  103. {
  104. wd.PATIENT_AGE_UNIT = "岁";
  105. }
  106. else if (wd.PATIENT_AGE_UNIT == "M")
  107. {
  108. wd.PATIENT_AGE_UNIT = "月";
  109. }
  110. else if (wd.PATIENT_AGE_UNIT == "D")
  111. {
  112. wd.PATIENT_AGE_UNIT = "周";
  113. }
  114. else
  115. {
  116. wd.PATIENT_AGE_UNIT = "岁";
  117. }
  118. }
  119. }
  120. private WD_PatientInfoExt QueryMAXID()
  121. {
  122. string strSql = " select top 1 * from [WD_PatientInfo] order by ID desc ";
  123. ext.messageDataList = this.Query(strSql, new WD_PatientInfo());
  124. ext.messageDataList.ForEach(f => f.bSuccess = this.bSuccess);
  125. ext.messageDataList.ForEach(f => f.Code = this.Code);
  126. ext.messageDataList.ForEach(f => f.Message = this.Message);
  127. ext.messageDataList.ForEach(f => f.Rows = this.Rows);
  128. ext.bSuccess = this.bSuccess;
  129. ext.Code = this.Code;
  130. ext.Message = this.Message;
  131. ext.Rows = this.Rows;
  132. return ext;
  133. }
  134. public void Business(List<WD_PatientInfo> il, List<WD_PatientInfo> ul, List<WD_PatientInfo> dl)
  135. {
  136. StringBuilder sb_itemp = new StringBuilder();
  137. sb_itemp.Append(" INSERT INTO [WD_PatientInfo] ( ");
  138. sb_itemp.Append(" [PATIENT_PHOC_ID],[PATIENT_ID],[PATIENT_CARD_ID],[PATIENT_NAME],[PATIENT_NAME_PY], ");
  139. sb_itemp.Append(" [PATIENT_SEX],[PATIENT_AGE],[PATIENT_AGE_UNIT],[PATIENT_BIRTHDAY],[PATIENT_IDCARD], ");
  140. sb_itemp.Append(" [PATIENT_ADDRESS],[PATIENT_MOBLIE],[PATIENT_INDATE],[PATIENT_DOCTOR_ID],[PATIENT_NURSE_ID], ");
  141. sb_itemp.Append(" [PATIENT_WORKERS_ID],[PATIENT_NURSE_LEVEL0],[PATIENT_NURSE_LEVEL1],[PATIENT_NURSE_LEVEL2],[PATIENT_NURSE_LEVEL3], ");
  142. sb_itemp.Append(" [PATIENT_NURSE_LEVEL4],[PATIENT_INTIMES],[PATIENT_STATUS],[PATIENT_ILLNESS],[PATIENT_BABYNAME], ");
  143. sb_itemp.Append(" [PATIENT_BABYSEX],[PATIENT_DATETIME] ");
  144. sb_itemp.Append(" ) values (");
  145. sb_itemp.Append(" '{0}','{1}','{2}','{3}','{4}', ");
  146. sb_itemp.Append(" '{5}','{6}','{7}','{8}','{9}', ");
  147. sb_itemp.Append(" '{10}','{11}','{12}','{13}','{14}', ");
  148. sb_itemp.Append(" '{15}','{16}','{17}','{18}','{19}', ");
  149. sb_itemp.Append(" '{20}','{21}','{22}','{23}','{24}', ");
  150. sb_itemp.Append(" '{25}','{26}' ");
  151. StringBuilder strSql_utemp = new StringBuilder();
  152. strSql_utemp.Append(" Update WD_PatientInfo set ");
  153. strSql_utemp.Append(" PATIENT_PHOC_ID = '{0}' , PATIENT_ID = '{1}' , PATIENT_CARD_ID = '{2}' , PATIENT_NAME = '{3}' , PATIENT_NAME_PY = '{4}', ");
  154. strSql_utemp.Append(" PATIENT_SEX = '{5}' , PATIENT_AGE = '{6}' , PATIENT_AGE_UNIT = '{7}' , PATIENT_BIRTHDAY = '{8}' , PATIENT_IDCARD = '{9}', ");
  155. strSql_utemp.Append(" PATIENT_ADDRESS = '{10}' , PATIENT_MOBLIE = '{11}' , PATIENT_INDATE = '{12}' , PATIENT_DOCTOR_ID = '{13}' , PATIENT_NURSE_ID = '{14}', ");
  156. strSql_utemp.Append(" PATIENT_WORKERS_ID = '{15}' , PATIENT_NURSE_LEVEL0 = '{16}' , PATIENT_NURSE_LEVEL1 = '{17}' , PATIENT_NURSE_LEVEL2 = '{18}' , PATIENT_NURSE_LEVEL3 = '{19}', ");
  157. strSql_utemp.Append(" PATIENT_NURSE_LEVEL4 = '{20}' , PATIENT_INTIMES = '{21}' , PATIENT_STATUS = '{22}' , PATIENT_ILLNESS = '{23}' , PATIENT_BABYNAME = '{24}', ");
  158. strSql_utemp.Append(" PATIENT_BABYSEX = '{25}' , PATIENT_DATETIME = '{26}' ");
  159. strSql_utemp.Append(" where ID = '{27}' ");
  160. StringBuilder strSql_dtemp = new StringBuilder();
  161. strSql_dtemp.Append(" Update WD_PatientInfo set [PATIENT_STATUS]='3' where [ID]= '{0}' ");
  162. StringBuilder sb_append = new StringBuilder();
  163. StringBuilder sb_i = new StringBuilder();
  164. foreach (WD_PatientInfo wd in il)
  165. {
  166. sb_itemp.AppendFormat(sb_itemp.ToString(),
  167. wd.PATIENT_PHOC_ID,
  168. wd.PATIENT_ID,
  169. wd.PATIENT_CARD_ID,
  170. wd.PATIENT_NAME,
  171. wd.PATIENT_NAME_PY,
  172. wd.PATIENT_SEX,
  173. wd.PATIENT_AGE,
  174. wd.PATIENT_AGE_UNIT,
  175. wd.PATIENT_BIRTHDAY,
  176. wd.PATIENT_IDCARD,
  177. wd.PATIENT_ADDRESS,
  178. wd.PATIENT_MOBLIE,
  179. wd.PATIENT_INDATE,
  180. wd.PATIENT_DOCTOR_ID,
  181. wd.PATIENT_NURSE_ID,
  182. wd.PATIENT_WORKERS_ID,
  183. wd.PATIENT_NURSE_LEVEL0,
  184. wd.PATIENT_NURSE_LEVEL1,
  185. wd.PATIENT_NURSE_LEVEL2,
  186. wd.PATIENT_NURSE_LEVEL3,
  187. wd.PATIENT_NURSE_LEVEL4,
  188. wd.PATIENT_INTIMES,
  189. wd.PATIENT_STATUS,
  190. wd.PATIENT_ILLNESS,
  191. wd.PATIENT_BABYNAME,
  192. wd.PATIENT_BABYSEX,
  193. wd.PATIENT_DATETIME
  194. );
  195. WD_PatientInfoExt wd_extmax = this.QueryMAXID();
  196. if(wd_extmax.bSuccess && wd_extmax.Rows == 0)
  197. {
  198. wd.ID = "1";
  199. }
  200. else
  201. {
  202. wd.ID = wd_extmax.messageDataList[0].ID ;
  203. }
  204. //有问题
  205. clsOpenSIPSAccount clsopenSIPSAccount = new clsOpenSIPSAccount(this.webPath);
  206. WD_DeviceInfo wd_DeviceInfo = new WD_DeviceInfo();
  207. wd_DeviceInfo.DEVICE_SIP_ID = clsopenSIPSAccount.GetSipAccount("4", wd.ID);
  208. wd_DeviceInfo.DEVICE_SIP_PASSWORD = wd_DeviceInfo.DEVICE_SIP_ID;
  209. //wd_DeviceInfo.DEVICE_SIP_STATUS = "1";
  210. if(clsopenSIPSAccount.OpenSIPs_ConnectDefault())
  211. {
  212. if(!clsopenSIPSAccount.OpenSIPs_AccountCheck(wd_DeviceInfo.DEVICE_SIP_ID, true))
  213. {
  214. clsopenSIPSAccount.OpenSIPs_AccountAdd(wd_DeviceInfo.DEVICE_SIP_ID, wd_DeviceInfo.DEVICE_SIP_PASSWORD);
  215. }
  216. }
  217. clsopenSIPSAccount.OpenSIPs_Close();
  218. sb_append.AppendFormat(" update [WD_DeviceInfo] SET [DEVICE_HUMAN_TYPE]='1', ");
  219. sb_append.AppendFormat(" [DEVICE_HUMAN_ID]='{0}',[DEVICE_SIP_IP]='{1}',[DEVICE_SIP_ID]='{2}'," , wd.ID ,clsopenSIPSAccount.GetSIPSerIP , wd_DeviceInfo.DEVICE_SIP_ID);
  220. //sb_append.AppendFormat(" [DEVICE_SIP_PASSWORD]='{0}',[DEVICE_SIP_STATUS]='{1}' where [ID] = '{0}' " , wd_DeviceInfo.DEVICE_SIP_PASSWORD ,wd_DeviceInfo.DEVICE_SIP_STATUS , wd.BEDID);
  221. }
  222. StringBuilder sb_u = new StringBuilder();
  223. foreach (WD_PatientInfo wd in ul)
  224. {
  225. sb_u.AppendFormat(strSql_utemp.ToString(),
  226. wd.PATIENT_PHOC_ID,
  227. wd.PATIENT_ID,
  228. wd.PATIENT_CARD_ID,
  229. wd.PATIENT_NAME,
  230. wd.PATIENT_NAME_PY,
  231. wd.PATIENT_SEX,
  232. wd.PATIENT_AGE,
  233. wd.PATIENT_AGE_UNIT,
  234. wd.PATIENT_BIRTHDAY,
  235. wd.PATIENT_IDCARD,
  236. wd.PATIENT_ADDRESS,
  237. wd.PATIENT_MOBLIE,
  238. wd.PATIENT_INDATE,
  239. wd.PATIENT_DOCTOR_ID,
  240. wd.PATIENT_NURSE_ID,
  241. wd.PATIENT_WORKERS_ID,
  242. wd.PATIENT_NURSE_LEVEL0,
  243. wd.PATIENT_NURSE_LEVEL1,
  244. wd.PATIENT_NURSE_LEVEL2,
  245. wd.PATIENT_NURSE_LEVEL3,
  246. wd.PATIENT_NURSE_LEVEL4,
  247. wd.PATIENT_INTIMES,
  248. wd.PATIENT_STATUS,
  249. wd.PATIENT_ILLNESS,
  250. wd.PATIENT_BABYNAME,
  251. wd.PATIENT_BABYSEX,
  252. wd.PATIENT_DATETIME,
  253. wd.ID);
  254. }
  255. StringBuilder sb_d = new StringBuilder();
  256. foreach (WD_PatientInfo wd in dl)
  257. {
  258. sb_d.AppendFormat(strSql_dtemp.ToString(),
  259. wd.ID);
  260. sb_append.AppendFormat(" update [WD_DeviceInfo] SET [DEVICE_HUMAN_TYPE]='0', ");
  261. sb_append.AppendFormat(" [DEVICE_HUMAN_ID]='0',[DEVICE_SIP_IP]='',[DEVICE_SIP_ID]='',");
  262. sb_append.AppendFormat(" [DEVICE_SIP_PASSWORD]='',[DEVICE_SIP_STATUS]='2' where [ID] = '{0}' " , wd.BEDID);
  263. }
  264. this.Execute(sb_i.ToString(), sb_u.ToString(), sb_d.ToString(), sb_append.ToString());
  265. }
  266. }
  267. }