lis.go 13KB

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