lis.go 12KB

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