lis.go 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. package controllers
  2. import (
  3. "IC/enums"
  4. "IC/models"
  5. "IC/service"
  6. "IC/utils"
  7. "encoding/json"
  8. "fmt"
  9. _ "github.com/astaxie/beego"
  10. _ "github.com/jinzhu/gorm"
  11. _ "strconv"
  12. "time"
  13. )
  14. // LisController operations for Lis
  15. type LisController struct {
  16. BaseAPIController
  17. }
  18. func (c *LisController) Schedule() {
  19. for i := 762429; i > 0; i-- {
  20. schedule,err := service.GetScheduless(int64(i))
  21. fmt.Println(schedule.ID)
  22. if err == nil {
  23. service.UpdateSchedule(schedule.ID,schedule.Status)
  24. }
  25. }
  26. c.ServeSuccessJSON(map[string]interface{}{
  27. "resultList": "12345",
  28. })
  29. return
  30. }
  31. func (c *LisController) SyncSzblLis() {
  32. // 获取备份库里所有的医嘱信息
  33. service.GetSZBLResultDataInsertDB(10138)
  34. c.ServeSuccessJSON(map[string]interface{}{
  35. "resultList": "12345",
  36. })
  37. return
  38. }
  39. func (c *LisController) SyncShLis() {
  40. // 获取备份库里所有的医嘱信息
  41. service.GetSHResultDataInsertDB(10215)
  42. c.ServeSuccessJSON(map[string]interface{}{
  43. "resultList": "12345",
  44. })
  45. return
  46. }
  47. func (c *LisController) SyncAdvice() {
  48. // 获取备份库里所有的医嘱信息
  49. advices, _ := service.GetAllAdvice()
  50. for _, advice := range advices {
  51. // if index > 50 {
  52. // break
  53. // }
  54. tempAdvice := models.DoctorAdvice{
  55. ID: advice.ID,
  56. Checker: advice.Checker,
  57. CheckTime: advice.CheckTime,
  58. CheckState: advice.CheckState,
  59. }
  60. service.SyncAdvice(&tempAdvice)
  61. }
  62. c.ServeSuccessJSON(map[string]interface{}{
  63. "resultList": "12345",
  64. })
  65. return
  66. }
  67. func (c *LisController) FiledConfigSys() {
  68. orgs, _ := service.GetfiledConfigOrg()
  69. sysFiledConfig, _ := service.GetfiledConfigSys()
  70. if len(orgs) > 0 {
  71. for _, org := range orgs {
  72. for _, filed := range sysFiledConfig {
  73. filedConfig, _ := service.GetfiledConfigByOrgId(org.OrgId, filed.Module, filed.FiledName)
  74. if filedConfig.ID > 0 {
  75. continue
  76. } else {
  77. tempfiled := models.FiledConfig{
  78. OrgId: org.OrgId,
  79. Module: filed.Module,
  80. FiledName: filed.FiledName,
  81. FiledNameCn: filed.FiledNameCn,
  82. IsShow: 2,
  83. }
  84. service.CreatefiledConfig(&tempfiled)
  85. }
  86. }
  87. }
  88. }
  89. c.ServeSuccessJSON(map[string]interface{}{
  90. "resultList": "12345",
  91. })
  92. return
  93. }
  94. func (c *LisController) SyncToBase() {
  95. org_id, _ := c.GetInt64("org_id", 0)
  96. if org_id <= 0 {
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  98. return
  99. }
  100. // 第一步:跟进org_id 去中间库查出需要同步的数据
  101. inspection_references, _ := service.GetSyncInspectionReferenceByOrgId(org_id)
  102. inspections, _ := service.GetSyncInspectionByOrgId(org_id)
  103. // 第二步:将数据同步到业务库
  104. if len(inspection_references) > 0 {
  105. for _, inspection_reference := range inspection_references {
  106. service.SyncInspectionReference(&inspection_reference)
  107. }
  108. }
  109. if len(inspections) > 0 {
  110. for _, inspection := range inspections {
  111. service.SyncInspection(&inspection)
  112. }
  113. }
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "resultList": "12345",
  116. })
  117. return
  118. }
  119. func (c *LisController) GetList() {
  120. org_id, _ := c.GetInt64("org_id", 0)
  121. if org_id <= 0 {
  122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  123. return
  124. }
  125. // 第一步:根据机构id获取对应机构所有病人的his_user_id
  126. patients, patientError := service.GetHisUserIdByOrgID(org_id)
  127. if patientError != nil {
  128. utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError)
  129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  130. return
  131. }
  132. patientStr := make([]interface{}, 0)
  133. if len(patients) > 0 {
  134. // 第二步:根据病人的his_user_id来查询上次同步时间
  135. for _, patient := range patients {
  136. if len(patient.HisUserId) <= 0 {
  137. continue
  138. }
  139. // if patient.SelectType != 1 {
  140. // continue
  141. // }
  142. syncLastInfo, _ := service.GetSyncTimeByOrgID(org_id, patient.HisUserId)
  143. var sync_time int64
  144. if syncLastInfo.ID > 0 {
  145. sync_time = syncLastInfo.SyncTime
  146. } else {
  147. inspectionLastInfo, _ := service.GetInspectionLastInfoByOrgID(org_id, patient.HisUserId)
  148. if inspectionLastInfo.ID > 0 {
  149. sync_time = inspectionLastInfo.CreatedTime
  150. } else {
  151. sync_time = 1609430400
  152. }
  153. }
  154. syncTimes := time.Unix(sync_time, 0).Format("2006-01-02 15:04")
  155. utils.InfoLog("syncTimes:%v", syncTimes)
  156. // 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录
  157. resultList, _ := service.GetListByHisUserID(patient.HisUserId, syncTimes, patient.SelectType)
  158. var syncInfo models.MiddleSyncInfo
  159. if len(resultList) > 0 {
  160. // 如果有数据,则把同步过来的详情插入一条数据到同步详情表中
  161. syncInfo.OrgId = org_id
  162. syncInfo.HisUserId = patient.HisUserId
  163. syncInfo.SyncTime = time.Now().Unix()
  164. syncInfo.SyncResultType = 1
  165. syncInfo.SyncRsultRemark = "同步成功"
  166. syncInfo.SyncTotalNum = int64(len(resultList))
  167. syncInfo.SyncSuccessNum = 0
  168. SyncInfos, _ := json.Marshal(resultList)
  169. syncInfo.SyncInfo = string(SyncInfos)
  170. syncInfo.CreateTime = time.Now().Unix()
  171. syncInfo.UpdateTime = time.Now().Unix()
  172. err := service.CreateSyncInfo(&syncInfo)
  173. if err != nil {
  174. utils.ErrorLog("创建同步信息失败:%v", err)
  175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  176. return
  177. }
  178. } else {
  179. // 如果没有数据,则插入一条数据到同步详情表中
  180. syncInfo.OrgId = org_id
  181. syncInfo.HisUserId = patient.HisUserId
  182. syncInfo.SyncTime = time.Now().Unix()
  183. syncInfo.SyncResultType = 1
  184. syncInfo.SyncRsultRemark = "该患者这个时间段没有任何检验检查数据"
  185. syncInfo.CreateTime = time.Now().Unix()
  186. syncInfo.UpdateTime = time.Now().Unix()
  187. err := service.CreateSyncInfo(&syncInfo)
  188. if err != nil {
  189. utils.ErrorLog("创建同步信息失败:%v", err)
  190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  191. return
  192. }
  193. // utils.InfoLog("同步信息详情:%v",syncInfo)
  194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  195. continue
  196. }
  197. // 第四部:将同步过来的数据插入到中间库对应的表
  198. syncSuccessNum := 0
  199. for _, result := range resultList {
  200. utils.ErrorLog("result:%v", result)
  201. if (result.HisUserId == patient.HisUserId) || (result.PatientName == patient.HisUserId) {
  202. patientId := patient.XtPatientId
  203. if patientId > 0 {
  204. inspection_reference, inspection, _ := service.Sync(result, org_id, patientId)
  205. if inspection_reference.ID > 0 || inspection.ID > 0 {
  206. syncSuccessNum++
  207. }
  208. }
  209. }
  210. }
  211. syncInfo.SyncSuccessNum = int64(syncSuccessNum)
  212. service.UpdateSyncInfo(&syncInfo)
  213. // patientStr = append(patientStr,patient.HisUserId)
  214. // utils.InfoLog("patientStr:%v",patientStr)
  215. }
  216. } else {
  217. var syncInfo models.MiddleSyncInfo
  218. // 如果没有数据,则插入一条数据到同步详情表中
  219. syncInfo.OrgId = org_id
  220. syncInfo.SyncTime = time.Now().Unix()
  221. syncInfo.SyncResultType = 0
  222. syncInfo.SyncRsultRemark = "该机构没有对应的his_user_id"
  223. syncInfo.CreateTime = time.Now().Unix()
  224. syncInfo.UpdateTime = time.Now().Unix()
  225. err := service.CreateSyncInfo(&syncInfo)
  226. if err != nil {
  227. utils.ErrorLog("创建同步信息失败:%v", err)
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  229. return
  230. }
  231. utils.InfoLog("同步信息详情:%v", syncInfo)
  232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. return
  234. }
  235. utils.InfoLog("patientStr:%v", patientStr)
  236. // // 第一步:根据机构id获取上次同步时间
  237. // syncLastInfo,_ := service.GetSyncTimeByOrgID(org_id)
  238. // var sync_time int64
  239. // if syncLastInfo.ID > 0 {
  240. // sync_time = syncLastInfo.SyncTime
  241. // } else {
  242. // sync_time = 0
  243. // }
  244. // syncTimes := time.Unix(sync_time,0).Format("2006-01-02 15:04")
  245. // utils.InfoLog("syncTimes:%v",syncTimes)
  246. // // 第二步:根据机构id获取对应机构所有病人的his_user_id
  247. // patients,patientError := service.GetHisUserIdByOrgID(org_id)
  248. // if patientError != nil {
  249. // utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError)
  250. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  251. // return
  252. // }
  253. // patientStr:= make([]interface{},0)
  254. // if len(patients) > 0 {
  255. // for _ , patient := range patients {
  256. // patientStr = append(patientStr,patient.HisUserId)
  257. // utils.InfoLog("patientStr:%v",patientStr)
  258. // }
  259. // } else {
  260. // // 如果没有数据,则插入一条数据到同步详情表中
  261. // syncInfo.OrgId = org_id
  262. // syncInfo.SyncTime = time.Now().Unix()
  263. // syncInfo.SyncResultType = 0
  264. // syncInfo.SyncRsultRemark = "该机构没有对应的his_user_id"
  265. // syncInfo.CreateTime = time.Now().Unix()
  266. // syncInfo.UpdateTime = time.Now().Unix()
  267. // err := service.CreateSyncInfo(&syncInfo)
  268. // if err != nil {
  269. // utils.ErrorLog("创建同步信息失败:%v", err)
  270. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  271. // return
  272. // }
  273. // utils.InfoLog("同步信息详情:%v",syncInfo)
  274. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  275. // return
  276. // }
  277. // utils.InfoLog("patientStr:%v",patientStr)
  278. // // 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录
  279. // resultList, _ := service.GetList(patientStr,syncTimes)
  280. // if len(resultList) > 0 {
  281. // // 如果有数据,则把同步过来的详情插入一条数据到同步详情表中
  282. // syncInfo.OrgId = org_id
  283. // syncInfo.SyncTime = time.Now().Unix()
  284. // syncInfo.SyncResultType = 1
  285. // syncInfo.SyncRsultRemark = "同步成功"
  286. // syncInfo.SyncTotalNum = int64(len(resultList))
  287. // syncInfo.SyncSuccessNum = 0
  288. // SyncInfos,_ := json.Marshal(resultList)
  289. // syncInfo.SyncInfo = string(SyncInfos)
  290. // syncInfo.CreateTime = time.Now().Unix()
  291. // syncInfo.UpdateTime = time.Now().Unix()
  292. // err := service.CreateSyncInfo(&syncInfo)
  293. // if err != nil {
  294. // utils.ErrorLog("创建同步信息失败:%v", err)
  295. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  296. // return
  297. // }
  298. // } else {
  299. // // 如果没有数据,则插入一条数据到同步详情表中
  300. // syncInfo.OrgId = org_id
  301. // syncInfo.SyncTime = time.Now().Unix()
  302. // syncInfo.SyncResultType = 1
  303. // syncInfo.SyncRsultRemark = "该机构这个时间段没有任何检验检查数据"
  304. // syncInfo.CreateTime = time.Now().Unix()
  305. // syncInfo.UpdateTime = time.Now().Unix()
  306. // err := service.CreateSyncInfo(&syncInfo)
  307. // if err != nil {
  308. // utils.ErrorLog("创建同步信息失败:%v", err)
  309. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  310. // return
  311. // }
  312. // // utils.InfoLog("同步信息详情:%v",syncInfo)
  313. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  314. // return
  315. // }
  316. // // 第四部:将同步过来的数据插入到中间库对应的表
  317. // syncSuccessNum := 0
  318. // for _, result := range resultList {
  319. // patientId := int64(0)
  320. // for _ , patientInfo := range patients {
  321. // if result.HisUserId == patientInfo.HisUserId {
  322. // patientId = patientInfo.XtPatientId
  323. // break
  324. // }
  325. // }
  326. // if patientId > 0 {
  327. // inspection_reference,inspection,_ := service.Sync(result,org_id,patientId)
  328. // if (inspection_reference.ID > 0 || inspection.ID > 0 ) {
  329. // syncSuccessNum++
  330. // }
  331. // }
  332. // }
  333. // syncInfo.SyncSuccessNum = int64(syncSuccessNum)
  334. // service.UpdateSyncInfo(&syncInfo)
  335. c.ServeSuccessJSON(map[string]interface{}{
  336. "resultList": patients,
  337. })
  338. return
  339. }
  340. func (c *LisController) SyncLgth() {
  341. service.SyncLisLgty()
  342. c.ServeSuccessJSON(map[string]interface{}{
  343. "resultList": "12345",
  344. })
  345. return
  346. }
  347. func (c *LisController) SyncYstx() {
  348. service.SyncLisYstx()
  349. c.ServeSuccessJSON(map[string]interface{}{
  350. "resultList": "12345",
  351. })
  352. return
  353. }
  354. func (c *LisController) SyncGzjhyz() {
  355. service.SyncGzjhyz()
  356. c.ServeSuccessJSON(map[string]interface{}{
  357. "resultList": "12345",
  358. })
  359. return
  360. }
  361. func (c *LisController) SyncGzjhLis() {
  362. service.SyncGzjhLis()
  363. c.ServeSuccessJSON(map[string]interface{}{
  364. "resultList": "12345",
  365. })
  366. return
  367. }
  368. func (c *LisController) SyncHbJldyyz() {
  369. service.SyncHbJldyyz()
  370. c.ServeSuccessJSON(map[string]interface{}{
  371. "resultList": "12345",
  372. })
  373. return
  374. }
  375. func (c *LisController) SyncHbJldyLis() {
  376. service.SyncHbdyLis()
  377. c.ServeSuccessJSON(map[string]interface{}{
  378. "resultList": "12345",
  379. })
  380. return
  381. }
  382. func (c *LisController) SyncBlLis() {
  383. service.GetDataInsertDB(10138)
  384. c.ServeSuccessJSON(map[string]interface{}{
  385. "resultList": "同步成功",
  386. })
  387. }
  388. func (c *LisController) SyncBlResultLis() {
  389. service.GetResultDataInsertDB(10138)
  390. c.ServeSuccessJSON(map[string]interface{}{
  391. "resultList": "同步成功",
  392. })
  393. }
  394. //肇庆三鹤
  395. func (c *LisController) SyncZQSHResultLis() {
  396. service.GetResultDataInsertDB(10215)
  397. c.ServeSuccessJSON(map[string]interface{}{
  398. "resultList": "同步成功",
  399. })
  400. }