lis.go 12KB

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