lis.go 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net"
  6. _ "strconv"
  7. "strings"
  8. "time"
  9. "IC/enums"
  10. "IC/models"
  11. "IC/service"
  12. "IC/utils"
  13. _ "github.com/astaxie/beego"
  14. _ "github.com/jinzhu/gorm"
  15. )
  16. // LisController operations for Lis
  17. type LisController struct {
  18. BaseAPIController
  19. }
  20. func (c *LisController) SyncChydLis() {
  21. service.SyncLisChyd(1)
  22. c.ServeSuccessJSON(map[string]interface{}{
  23. "resultList": "12345",
  24. })
  25. return
  26. }
  27. func (c *LisController) Test() {
  28. var ipWhitelist = []string{"192.168.2.6", "192.168.1.1"}
  29. ip := c.Ctx.Request.Header.Get("X-Forwarded-For")
  30. if ip == "" {
  31. // 如果没有 X-Forwarded-For,则使用 RemoteAddr
  32. // 注意:RemoteAddr 可能包含端口号,需要进行处理
  33. ip, _, _ = net.SplitHostPort(c.Ctx.Request.RemoteAddr)
  34. }
  35. // 如果 X-Forwarded-For 包含多个 IP 地址(逗号分隔),则通常取第一个
  36. // 这通常是因为请求经过了多个代理
  37. ips := strings.Split(ip, ",")
  38. if len(ips) > 0 {
  39. ip = strings.TrimSpace(ips[0])
  40. }
  41. utils.InfoLog("IP:%v", ip)
  42. ipFlag := false
  43. for _, allowedIP := range ipWhitelist {
  44. if ip == allowedIP {
  45. ipFlag = true
  46. }
  47. }
  48. if ipFlag {
  49. c.ServeSuccessJSON(map[string]interface{}{
  50. "flag": "1",
  51. "msg": "认证通过",
  52. })
  53. } else {
  54. c.ServeSuccessJSON(map[string]interface{}{
  55. "flag": "0",
  56. "msg": "IP认证通过未通过",
  57. })
  58. }
  59. return
  60. }
  61. func (c *LisController) Schedule() {
  62. for i := 762429; i > 0; i-- {
  63. schedule, err := service.GetScheduless(int64(i))
  64. fmt.Println(schedule.ID)
  65. if err == nil {
  66. service.UpdateSchedule(schedule.ID, schedule.Status)
  67. }
  68. }
  69. c.ServeSuccessJSON(map[string]interface{}{
  70. "resultList": "12345",
  71. })
  72. return
  73. }
  74. //// 普宁锦熹血液透析中心Lis同步
  75. //func (c *LisController) SyncPljx() {
  76. // service.SyncLisPljx(10599)
  77. // c.ServeSuccessJSON(map[string]interface{}{
  78. // "resultList": "12345",
  79. // })
  80. // return
  81. //}
  82. // 遵化仁爱医院Lis同步
  83. //func (c *LisController) SyncZhraLis() {
  84. // service.SyncTszhraLis()
  85. // c.ServeSuccessJSON(map[string]interface{}{
  86. // "resultList": "12345",
  87. // })
  88. // return
  89. //}
  90. // 北京南诚中西医结合医院Lis同步
  91. //func (c *LisController) SyncBjncLis() {
  92. // service.SyncBjncLis()
  93. // c.ServeSuccessJSON(map[string]interface{}{
  94. // "resultList": "12345",
  95. // })
  96. // return
  97. //}
  98. // 广州康允LIS同步
  99. //func (c *LisController) SyncGzky() {
  100. // service.SyncGzkyLis()
  101. // c.ServeSuccessJSON(map[string]interface{}{
  102. // "resultList": "12345",
  103. // })
  104. // return
  105. //}
  106. //func (c *LisController) SyncSzwz() {
  107. // service.SyncLisSzwz()
  108. // c.ServeSuccessJSON(map[string]interface{}{
  109. // "resultList": "12345",
  110. // })
  111. // return
  112. //}
  113. // 石狮盛誉LIS同步
  114. func (c *LisController) SyncSssy() {
  115. service.SyncSYData2()
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "resultList": "12345",
  118. })
  119. return
  120. }
  121. func (c *LisController) SyncTest() {
  122. // 获取备份库里所有的医嘱信息
  123. // service.EmrBloodDiaylOrder()
  124. // service.EmrBloodDiaylDetail()
  125. //service.SyncScpaLis()
  126. c.ServeSuccessJSON(map[string]interface{}{
  127. "resultList": "12345",
  128. })
  129. return
  130. }
  131. func (c *LisController) SyncSzblLis() {
  132. // 获取备份库里所有的医嘱信息
  133. service.GetSZBLResultDataInsertDB(10278)
  134. c.ServeSuccessJSON(map[string]interface{}{
  135. "resultList": "12345",
  136. })
  137. return
  138. }
  139. // 唐山朝阳医院LIS
  140. func (c *LisController) SyncTscyLis() {
  141. service.SyncTscyLis()
  142. c.ServeSuccessJSON(map[string]interface{}{
  143. "resultList": "12345",
  144. })
  145. return
  146. }
  147. // 唐山朝阳医院LIS
  148. func (c *LisController) SyncTscyVipLis() {
  149. service.SyncTscyVipLis()
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "resultList": "12345",
  152. })
  153. return
  154. }
  155. func (c *LisController) SyncShLis() {
  156. // 获取备份库里所有的医嘱信息
  157. service.GetSHResultDataInsertDB(10215)
  158. c.ServeSuccessJSON(map[string]interface{}{
  159. "resultList": "12345",
  160. })
  161. return
  162. }
  163. func (c *LisController) SyncAdvice() {
  164. // 获取备份库里所有的医嘱信息
  165. advices, _ := service.GetAllAdvice()
  166. for _, advice := range advices {
  167. // if index > 50 {
  168. // break
  169. // }
  170. tempAdvice := models.DoctorAdvice{
  171. ID: advice.ID,
  172. Checker: advice.Checker,
  173. CheckTime: advice.CheckTime,
  174. CheckState: advice.CheckState,
  175. }
  176. service.SyncAdvice(&tempAdvice)
  177. }
  178. c.ServeSuccessJSON(map[string]interface{}{
  179. "resultList": "12345",
  180. })
  181. return
  182. }
  183. func (c *LisController) FiledConfigSys() {
  184. orgs, _ := service.GetfiledConfigOrg()
  185. sysFiledConfig, _ := service.GetfiledConfigSys()
  186. if len(orgs) > 0 {
  187. for _, org := range orgs {
  188. for _, filed := range sysFiledConfig {
  189. filedConfig, _ := service.GetfiledConfigByOrgId(org.OrgId, filed.Module, filed.FiledName)
  190. if filedConfig.ID > 0 {
  191. continue
  192. } else {
  193. tempfiled := models.FiledConfig{
  194. OrgId: org.OrgId,
  195. Module: filed.Module,
  196. FiledName: filed.FiledName,
  197. FiledNameCn: filed.FiledNameCn,
  198. IsShow: 2,
  199. }
  200. service.CreatefiledConfig(&tempfiled)
  201. }
  202. }
  203. }
  204. }
  205. c.ServeSuccessJSON(map[string]interface{}{
  206. "resultList": "12345",
  207. })
  208. return
  209. }
  210. func (c *LisController) SyncToBase() {
  211. org_id, _ := c.GetInt64("org_id", 0)
  212. if org_id <= 0 {
  213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  214. return
  215. }
  216. // 第一步:跟进org_id 去中间库查出需要同步的数据
  217. inspection_references, _ := service.GetSyncInspectionReferenceByOrgId(org_id)
  218. inspections, _ := service.GetSyncInspectionByOrgId(org_id)
  219. // 第二步:将数据同步到业务库
  220. if len(inspection_references) > 0 {
  221. for _, inspection_reference := range inspection_references {
  222. service.SyncInspectionReference(&inspection_reference)
  223. }
  224. }
  225. if len(inspections) > 0 {
  226. for _, inspection := range inspections {
  227. service.SyncInspection(&inspection)
  228. }
  229. }
  230. c.ServeSuccessJSON(map[string]interface{}{
  231. "resultList": "12345",
  232. })
  233. return
  234. }
  235. func (c *LisController) GetList() {
  236. org_id, _ := c.GetInt64("org_id", 0)
  237. if org_id <= 0 {
  238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  239. return
  240. }
  241. // 第一步:根据机构id获取对应机构所有病人的his_user_id
  242. patients, patientError := service.GetHisUserIdByOrgID(org_id)
  243. if patientError != nil {
  244. utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError)
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  246. return
  247. }
  248. patientStr := make([]interface{}, 0)
  249. if len(patients) > 0 {
  250. // 第二步:根据病人的his_user_id来查询上次同步时间
  251. for _, patient := range patients {
  252. if len(patient.HisUserId) <= 0 {
  253. continue
  254. }
  255. // if patient.SelectType != 1 {
  256. // continue
  257. // }
  258. syncLastInfo, _ := service.GetSyncTimeByOrgID(org_id, patient.HisUserId)
  259. var sync_time int64
  260. if syncLastInfo.ID > 0 {
  261. sync_time = syncLastInfo.SyncTime
  262. } else {
  263. inspectionLastInfo, _ := service.GetInspectionLastInfoByOrgID(org_id, patient.HisUserId)
  264. if inspectionLastInfo.ID > 0 {
  265. sync_time = inspectionLastInfo.CreatedTime
  266. } else {
  267. sync_time = 1609430400
  268. }
  269. }
  270. syncTimes := time.Unix(sync_time, 0).Format("2006-01-02 15:04")
  271. utils.InfoLog("syncTimes:%v", syncTimes)
  272. // 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录
  273. resultList, _ := service.GetListByHisUserID(patient.HisUserId, syncTimes, patient.SelectType)
  274. var syncInfo models.MiddleSyncInfo
  275. if len(resultList) > 0 {
  276. // 如果有数据,则把同步过来的详情插入一条数据到同步详情表中
  277. syncInfo.OrgId = org_id
  278. syncInfo.HisUserId = patient.HisUserId
  279. syncInfo.SyncTime = time.Now().Unix()
  280. syncInfo.SyncResultType = 1
  281. syncInfo.SyncRsultRemark = "同步成功"
  282. syncInfo.SyncTotalNum = int64(len(resultList))
  283. syncInfo.SyncSuccessNum = 0
  284. SyncInfos, _ := json.Marshal(resultList)
  285. syncInfo.SyncInfo = string(SyncInfos)
  286. syncInfo.CreateTime = time.Now().Unix()
  287. syncInfo.UpdateTime = time.Now().Unix()
  288. err := service.CreateSyncInfo(&syncInfo)
  289. if err != nil {
  290. utils.ErrorLog("创建同步信息失败:%v", err)
  291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  292. return
  293. }
  294. } else {
  295. // 如果没有数据,则插入一条数据到同步详情表中
  296. syncInfo.OrgId = org_id
  297. syncInfo.HisUserId = patient.HisUserId
  298. syncInfo.SyncTime = time.Now().Unix()
  299. syncInfo.SyncResultType = 1
  300. syncInfo.SyncRsultRemark = "该患者这个时间段没有任何检验检查数据"
  301. syncInfo.CreateTime = time.Now().Unix()
  302. syncInfo.UpdateTime = time.Now().Unix()
  303. err := service.CreateSyncInfo(&syncInfo)
  304. if err != nil {
  305. utils.ErrorLog("创建同步信息失败:%v", err)
  306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  307. return
  308. }
  309. // utils.InfoLog("同步信息详情:%v",syncInfo)
  310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  311. continue
  312. }
  313. // 第四部:将同步过来的数据插入到中间库对应的表
  314. syncSuccessNum := 0
  315. for _, result := range resultList {
  316. utils.ErrorLog("result:%v", result)
  317. if (result.HisUserId == patient.HisUserId) || (result.PatientName == patient.HisUserId) {
  318. patientId := patient.XtPatientId
  319. if patientId > 0 {
  320. inspection_reference, inspection, _ := service.Sync(result, org_id, patientId)
  321. if inspection_reference.ID > 0 || inspection.ID > 0 {
  322. syncSuccessNum++
  323. }
  324. }
  325. }
  326. }
  327. syncInfo.SyncSuccessNum = int64(syncSuccessNum)
  328. service.UpdateSyncInfo(&syncInfo)
  329. // patientStr = append(patientStr,patient.HisUserId)
  330. // utils.InfoLog("patientStr:%v",patientStr)
  331. }
  332. } else {
  333. var syncInfo models.MiddleSyncInfo
  334. // 如果没有数据,则插入一条数据到同步详情表中
  335. syncInfo.OrgId = org_id
  336. syncInfo.SyncTime = time.Now().Unix()
  337. syncInfo.SyncResultType = 0
  338. syncInfo.SyncRsultRemark = "该机构没有对应的his_user_id"
  339. syncInfo.CreateTime = time.Now().Unix()
  340. syncInfo.UpdateTime = time.Now().Unix()
  341. err := service.CreateSyncInfo(&syncInfo)
  342. if err != nil {
  343. utils.ErrorLog("创建同步信息失败:%v", err)
  344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  345. return
  346. }
  347. utils.InfoLog("同步信息详情:%v", syncInfo)
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  349. return
  350. }
  351. utils.InfoLog("patientStr:%v", patientStr)
  352. // // 第一步:根据机构id获取上次同步时间
  353. // syncLastInfo,_ := service.GetSyncTimeByOrgID(org_id)
  354. // var sync_time int64
  355. // if syncLastInfo.ID > 0 {
  356. // sync_time = syncLastInfo.SyncTime
  357. // } else {
  358. // sync_time = 0
  359. // }
  360. // syncTimes := time.Unix(sync_time,0).Format("2006-01-02 15:04")
  361. // utils.InfoLog("syncTimes:%v",syncTimes)
  362. // // 第二步:根据机构id获取对应机构所有病人的his_user_id
  363. // patients,patientError := service.GetHisUserIdByOrgID(org_id)
  364. // if patientError != nil {
  365. // utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError)
  366. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. // return
  368. // }
  369. // patientStr:= make([]interface{},0)
  370. // if len(patients) > 0 {
  371. // for _ , patient := range patients {
  372. // patientStr = append(patientStr,patient.HisUserId)
  373. // utils.InfoLog("patientStr:%v",patientStr)
  374. // }
  375. // } else {
  376. // // 如果没有数据,则插入一条数据到同步详情表中
  377. // syncInfo.OrgId = org_id
  378. // syncInfo.SyncTime = time.Now().Unix()
  379. // syncInfo.SyncResultType = 0
  380. // syncInfo.SyncRsultRemark = "该机构没有对应的his_user_id"
  381. // syncInfo.CreateTime = time.Now().Unix()
  382. // syncInfo.UpdateTime = time.Now().Unix()
  383. // err := service.CreateSyncInfo(&syncInfo)
  384. // if err != nil {
  385. // utils.ErrorLog("创建同步信息失败:%v", err)
  386. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  387. // return
  388. // }
  389. // utils.InfoLog("同步信息详情:%v",syncInfo)
  390. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  391. // return
  392. // }
  393. // utils.InfoLog("patientStr:%v",patientStr)
  394. // // 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录
  395. // resultList, _ := service.GetList(patientStr,syncTimes)
  396. // if len(resultList) > 0 {
  397. // // 如果有数据,则把同步过来的详情插入一条数据到同步详情表中
  398. // syncInfo.OrgId = org_id
  399. // syncInfo.SyncTime = time.Now().Unix()
  400. // syncInfo.SyncResultType = 1
  401. // syncInfo.SyncRsultRemark = "同步成功"
  402. // syncInfo.SyncTotalNum = int64(len(resultList))
  403. // syncInfo.SyncSuccessNum = 0
  404. // SyncInfos,_ := json.Marshal(resultList)
  405. // syncInfo.SyncInfo = string(SyncInfos)
  406. // syncInfo.CreateTime = time.Now().Unix()
  407. // syncInfo.UpdateTime = time.Now().Unix()
  408. // err := service.CreateSyncInfo(&syncInfo)
  409. // if err != nil {
  410. // utils.ErrorLog("创建同步信息失败:%v", err)
  411. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  412. // return
  413. // }
  414. // } else {
  415. // // 如果没有数据,则插入一条数据到同步详情表中
  416. // syncInfo.OrgId = org_id
  417. // syncInfo.SyncTime = time.Now().Unix()
  418. // syncInfo.SyncResultType = 1
  419. // syncInfo.SyncRsultRemark = "该机构这个时间段没有任何检验检查数据"
  420. // syncInfo.CreateTime = time.Now().Unix()
  421. // syncInfo.UpdateTime = time.Now().Unix()
  422. // err := service.CreateSyncInfo(&syncInfo)
  423. // if err != nil {
  424. // utils.ErrorLog("创建同步信息失败:%v", err)
  425. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  426. // return
  427. // }
  428. // // utils.InfoLog("同步信息详情:%v",syncInfo)
  429. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  430. // return
  431. // }
  432. // // 第四部:将同步过来的数据插入到中间库对应的表
  433. // syncSuccessNum := 0
  434. // for _, result := range resultList {
  435. // patientId := int64(0)
  436. // for _ , patientInfo := range patients {
  437. // if result.HisUserId == patientInfo.HisUserId {
  438. // patientId = patientInfo.XtPatientId
  439. // break
  440. // }
  441. // }
  442. // if patientId > 0 {
  443. // inspection_reference,inspection,_ := service.Sync(result,org_id,patientId)
  444. // if (inspection_reference.ID > 0 || inspection.ID > 0 ) {
  445. // syncSuccessNum++
  446. // }
  447. // }
  448. // }
  449. // syncInfo.SyncSuccessNum = int64(syncSuccessNum)
  450. // service.UpdateSyncInfo(&syncInfo)
  451. c.ServeSuccessJSON(map[string]interface{}{
  452. "resultList": patients,
  453. })
  454. return
  455. }
  456. func (c *LisController) SyncLgth() {
  457. service.SyncLisLgty()
  458. c.ServeSuccessJSON(map[string]interface{}{
  459. "resultList": "12345",
  460. })
  461. return
  462. }
  463. func (c *LisController) SyncYstx() {
  464. service.SyncLisYstx()
  465. c.ServeSuccessJSON(map[string]interface{}{
  466. "resultList": "12345",
  467. })
  468. return
  469. }
  470. func (c *LisController) SyncGzjhyz() {
  471. service.SyncGzjhyz()
  472. c.ServeSuccessJSON(map[string]interface{}{
  473. "resultList": "12345",
  474. })
  475. return
  476. }
  477. func (c *LisController) SyncGzjhLis() {
  478. service.SyncGzjhLis()
  479. c.ServeSuccessJSON(map[string]interface{}{
  480. "resultList": "12345",
  481. })
  482. return
  483. }
  484. func (c *LisController) SyncHbJldyyz() {
  485. service.SyncHbJldyyz()
  486. c.ServeSuccessJSON(map[string]interface{}{
  487. "resultList": "12345",
  488. })
  489. return
  490. }
  491. func (c *LisController) SyncHbJldyLis() {
  492. service.SyncHbdyLis()
  493. c.ServeSuccessJSON(map[string]interface{}{
  494. "resultList": "12345",
  495. })
  496. return
  497. }
  498. func (c *LisController) SyncBlLis() {
  499. service.GetDataInsertDB(10138)
  500. c.ServeSuccessJSON(map[string]interface{}{
  501. "resultList": "同步成功",
  502. })
  503. }
  504. func (c *LisController) SyncBlResultLis() {
  505. service.GetResultDataInsertDB(10138)
  506. c.ServeSuccessJSON(map[string]interface{}{
  507. "resultList": "同步成功",
  508. })
  509. }
  510. // 肇庆三鹤
  511. func (c *LisController) SyncZQSHResultLis() {
  512. service.GetSHResultDataInsertDB(10215)
  513. c.ServeSuccessJSON(map[string]interface{}{
  514. "resultList": "同步成功",
  515. })
  516. }
  517. // 福建天福
  518. func (c *LisController) SyncFjtfLis() {
  519. service.SyncFjtfLis()
  520. c.ServeSuccessJSON(map[string]interface{}{
  521. "resultList": "同步成功",
  522. })
  523. }
  524. // 长沙南雅
  525. func (c *LisController) SyncCsnyLis() {
  526. service.SyncCsnyLis()
  527. c.ServeSuccessJSON(map[string]interface{}{
  528. "resultList": "同步成功",
  529. })
  530. }
  531. func (c *LisController) TestList() {
  532. service.SyncShuHeLis()
  533. c.ServeSuccessJSON(map[string]interface{}{
  534. "resultList": "同步成功",
  535. })
  536. }