gzjhtxzx_service.go 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. package service
  2. import (
  3. "IC/models"
  4. "IC/utils"
  5. "encoding/json"
  6. "encoding/xml"
  7. "github.com/astaxie/beego/httplib"
  8. "net/url"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type RequestResultGzjh struct {
  14. Msg string `json:"msg"`
  15. ResultGzjh []struct {
  16. AdviceId int64 `json:"医嘱ID"`
  17. OtherId int64 `json:"相关ID"`
  18. Source int `json:"病人来源"`
  19. PatientId int64 `json:"病人ID"`
  20. JzId int64 `json:"就诊ID"`
  21. BabyId int `json:"婴儿ID"`
  22. PatientDepartmentId int `json:"病人科室ID"`
  23. OrderId int `json:"次序"`
  24. AdviceStatus int `json:"医嘱状态"`
  25. AdviceType int `json:"医嘱类型"`
  26. DiagnosisType string `json:"诊疗类型"`
  27. DiagnosisItemId int `json:"诊疗项目ID"`
  28. CheckMethd string `json:"检查方法"`
  29. ChargeItemId int `json:"收费项目ID"`
  30. Day int `json:"天数"`
  31. JiLiang float64 `json:"剂量"`
  32. YongLiang string `json:"用量"`
  33. DanLiang float64 `json:"单量"`
  34. Shuliang float64 `json:"数量"`
  35. Advice string `json:"医嘱"`
  36. GeiYaoTuJing string `json:"给药途径"`
  37. ShuoMing string `json:"说明"`
  38. ZhiXingKeShiId int `json:"执行科室ID"`
  39. ZhiXingKeShi string `json:"执行科室"`
  40. PN string `json:"P(+)或N(-)表示阳性或阴性"`
  41. ZhiXingPinCi string `json:"执行频次"`
  42. PinLvCiShu int `json:"频率次数"`
  43. PinLvJianGe int `json:"频率间隔"`
  44. JianGeDanWei string `json:"间隔单位"`
  45. ZhiXingShiJianFangAn string `json:"执行时间方案"`
  46. JiJiaTeXing int `json:"计价特性"`
  47. ZhiXingXingZhi int `json:"执行性质"`
  48. ZhiXingBiaoZhi int `json:"执行标记"`
  49. KeFouFenLing int `json:"可否分零"`
  50. JinJiBiaoZhi int `json:"紧急标志"`
  51. KaiShiZhiXingShiJian int64 `json:"开始执行时间"`
  52. ZhiXingZhongZhiShiJian int64 `json:"执行终止时间"`
  53. ShangCiZhiXingShiJian int64 `json:"上次执行时间"`
  54. KaiZhuKeShiId int `json:"开嘱科室ID"`
  55. DoctorCode string `json:"医师编码"`
  56. Doctor string `json:"开嘱医师"`
  57. AdviceTime int64 `json:"开嘱时间"`
  58. StopTime int64 `json:"停嘱时间"`
  59. ApplyId int `json:"申请ID"`
  60. UploadLable int `json:"上传标志"`
  61. CheckResult int `json:"审查结果"`
  62. NoPrint int `json:"忽略打印"`
  63. Summary string `json:"摘要"`
  64. AdviceOrderId int64 `json:"医嘱单id"`
  65. GeiYaoKeShi int `json:"给药科室"`
  66. GeiYaoXingZhi int `json:"给药性质"`
  67. GroupNo int `json:"组号"`
  68. Speed string `json:"滴速"`
  69. ShouRiCiShu float64 `json:"首日次数"`
  70. MoRiCiShu float64 `json:"末日次数"`
  71. AdviceDoctorId int `json:"开嘱医师ID"`
  72. AdviceNurseId int `json:"开嘱护士ID"`
  73. OperaId int `json:"操作员ID"`
  74. Opera string `json:"操作员"`
  75. CheckTime int64 `json:"审核时间"`
  76. ReplyAdviceTime int64 `json:"重整医嘱时间"`
  77. } `json:"result"`
  78. Code string `json:"code"`
  79. }
  80. type XmlKeyGzjh struct {
  81. XMLName xml.Name `xml:"string"`
  82. StringName string `xml:"name,attr"`
  83. InnerText string `xml:",innerxml"`
  84. }
  85. // 获取艾迪康的key
  86. func GetGzjhAdKey(logid string, password string) (key string) {
  87. Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/Login?"
  88. apiurl := "logid=" + logid + "&password=" + password
  89. apiurl = url.PathEscape(apiurl)
  90. utils.InfoLog("apiUrl: %v", apiurl)
  91. apiurl = Domain + apiurl
  92. xmlKey := XmlKeyGzjh{}
  93. httplib.Get(apiurl).ToXML(&xmlKey)
  94. utils.InfoLog("xmlKey: %v", xmlKey)
  95. return xmlKey.InnerText
  96. }
  97. type ADStringGzjh struct {
  98. XMLName xml.Name `xml:"string" json:"string"`
  99. NewDataSet rpnewDataSetGzjh `xml:"NewDataSet" json:"NewDataSetGzjh"`
  100. }
  101. type rpnewDataSetGzjh struct {
  102. ListTable []rplisttableGzjh `xml:"listtable" json:"listtableGzjh"`
  103. }
  104. type rplisttableGzjh struct {
  105. Id string `xml:"Id" json:"Id"`
  106. PatientName string `xml:"PatientName" json:"PatientName"`
  107. Bgrq string `xml:"Bgrq" json:"Bgrq"`
  108. Instrument string `xml:"Instrument" json:"Instrument"`
  109. LisDate string `xml:"LisDate" json:"LisDate"`
  110. Sampleid string `xml:"Sampleid" json:"Sampleid"`
  111. }
  112. type ReportListXml struct {
  113. XMLName xml.Name `xml:"GetReportList"`
  114. Key string `xml:"Key"`
  115. BeginDateTime string `xml:"BeginDateTime"`
  116. EndDateTime string `xml:"EndDateTime"`
  117. TypeDateTime string `xml:"TypeDateTime"`
  118. AgainFlag string `xml:"AgainFlag"`
  119. }
  120. // 获取机构一段时间内检验检查列表
  121. func GetAdGetReportListGzjh(Key string, BeginDateTime string, EndDateTime string, TypeDateTime string, AgainFlag string) (key ADStringGzjh) {
  122. Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetReportList"
  123. var xmlKey ADStringGzjh
  124. reportPost := httplib.Post(Domain)
  125. reportPost.Param("Key", Key)
  126. reportPost.Param("BeginDateTime", BeginDateTime)
  127. reportPost.Param("EndDateTime", EndDateTime)
  128. reportPost.Param("TypeDateTime", TypeDateTime)
  129. reportPost.Param("AgainFlag", AgainFlag)
  130. reportPost.Header("Content-Type", "application/xml")
  131. xmlString, _ := reportPost.String()
  132. xmlString = strings.Replace(xmlString, "&lt;", "<", -1)
  133. xmlString = strings.Replace(xmlString, "&gt;", ">", -1)
  134. xml.Unmarshal([]byte(xmlString), &xmlKey)
  135. return xmlKey
  136. }
  137. type adkCheckGzjh struct {
  138. ApplyId string `json:"applyid"`
  139. ReportNo string `json:"reportno"`
  140. PatName string `json:"patname"`
  141. Sex string `json:"sex"`
  142. Age string `json:"age"`
  143. DptName string `json:"dptname"`
  144. Testtype string `json:"testtype"`
  145. Testcode string `json:"testcode"`
  146. ExecuteTime string `json:"receivetime"`
  147. Checktime string `json:"checktime"`
  148. Checkcode string `json:"checkcode"`
  149. Result []adkResultGzjh `json:"result"`
  150. }
  151. func GetAdkInfoGzjh(key string, id string) (str []adkCheckGzjh, checkStr string) {
  152. Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetJSONReportItemListById"
  153. reportPost := httplib.Post(Domain)
  154. reportPost.Param("Key", key)
  155. reportPost.Param("id", id)
  156. reportPost.Header("Content-Type", "application/xml")
  157. xmlKey := XmlKey{}
  158. reportPost.ToXML(&xmlKey)
  159. var checkJSON []adkCheckGzjh
  160. json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
  161. return checkJSON, xmlKey.InnerText
  162. }
  163. // 广州暨华血液透析中心Lis同步
  164. func SyncLisGzjhtx() (err error) {
  165. // 第一步:获取艾迪康下发的Key
  166. org_id := int64(10015)
  167. login := "RH0046"
  168. password := "Abc123123"
  169. key := GetGzjhAdKey(login, password)
  170. utils.InfoLog("key: %v", key)
  171. // 第二步:获e取上一次同步的时间点
  172. syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
  173. var sync_time int64
  174. if syncLastInfo.ID > 0 {
  175. sync_time = syncLastInfo.SyncTime + 86400
  176. } else {
  177. sync_time = 1672502400
  178. }
  179. nowTimes := time.Now().Unix()
  180. // syncTimes := time.Unix(sync_time,0).Format("2006-01-02")
  181. if sync_time < nowTimes {
  182. for i := sync_time; i < nowTimes; i = i + 86400 {
  183. tempsyncTimes := time.Unix(i, 0).Format("2006-01-02")
  184. utils.InfoLog("tempsyncTimes:%v", tempsyncTimes)
  185. adString := GetAdGetReportListGzjh(key, tempsyncTimes, tempsyncTimes, "2", "2")
  186. listtable := adString.NewDataSet.ListTable
  187. utils.InfoLog("listtable: %v", listtable)
  188. if len(listtable) > 3 {
  189. // 第三步:根据检查列表获取的ID来获取检验检查详情
  190. for _, list := range listtable {
  191. listId := list.Id
  192. utils.InfoLog("listId: %v", listId)
  193. checkInfo, checkStr := GetAdkInfoGzjh(key, listId)
  194. utils.InfoLog("checkInfo: %v", checkInfo)
  195. for _, info := range checkInfo {
  196. // 根据姓名 去查询对应的patient_id
  197. patient, _ := GetPatientIDGzjh(org_id, info.PatName)
  198. utils.InfoLog("patient: %v", patient)
  199. if patient.ID > 0 {
  200. middleReportHandle := models.MiddleReportHandle{
  201. OrgId: org_id,
  202. HisUserId: strconv.FormatInt(patient.ID, 10),
  203. ApplyNo: info.ApplyId,
  204. ReportId: info.ReportNo,
  205. Name: info.PatName,
  206. Sex: info.Sex,
  207. Age: info.Age,
  208. Dept: info.DptName,
  209. PatientId: strconv.FormatInt(patient.ID, 10),
  210. RequestTime: info.ExecuteTime,
  211. ExecuteTime: info.ExecuteTime,
  212. ReceiveTime: info.ExecuteTime,
  213. CheckTime: info.ExecuteTime,
  214. ReportInfo: checkStr,
  215. CreatedTime: time.Now().Unix(),
  216. UpdatedTime: time.Now().Unix(),
  217. }
  218. handleerr := CreateReportHandle(&middleReportHandle)
  219. if handleerr != nil {
  220. utils.ErrorLog("创建检验检查操作数据失败:%v", handleerr)
  221. return
  222. }
  223. GzjhReportInfoHandle(info, org_id, patient.ID)
  224. }
  225. }
  226. }
  227. var syncInfo models.MiddleSyncInfo
  228. syncInfo.OrgId = org_id
  229. syncInfo.SyncTime = i
  230. syncInfo.SyncResultType = 1
  231. syncInfo.SyncRsultRemark = "同步成功"
  232. syncInfo.SyncTotalNum = 0
  233. syncInfo.SyncSuccessNum = 0
  234. syncInfo.SyncInfo = ""
  235. syncInfo.CreateTime = time.Now().Unix()
  236. syncInfo.UpdateTime = time.Now().Unix()
  237. cwderr := CreateSyncInfo(&syncInfo)
  238. if cwderr != nil {
  239. utils.ErrorLog("创建同步信息失败:%v", cwderr)
  240. return
  241. }
  242. }
  243. }
  244. }
  245. SyncToGzczjhtx()
  246. return
  247. }
  248. // 根据姓名获取patient_id
  249. func GetPatientIDGzjh(org_id int64, patient_name string) (patient models.Patients, err error) {
  250. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1 and name = ? ", org_id, patient_name).First(&patient).Error
  251. return
  252. }
  253. func GetProjectInfoGzjh(item_id int64, org_id int64) (project_info models.MiddleInspectionReference, err error) {
  254. err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and item_id = ?", org_id, item_id).First(&project_info).Error
  255. return
  256. }
  257. // 修改配置信息
  258. // func UpdateInspectionReference(InspectionReference *models.MiddleInspectionReference) error {
  259. // err := readMiddleDb.Model(&models.MiddleInspectionReference{}).Updates(&InspectionReference).Error
  260. // return err
  261. // }
  262. // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
  263. func GetGzzcjhProjectID(org_id int64, project_name string) (project_id int64, err error) {
  264. var inspection_reference models.MiddleInspectionReference
  265. err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
  266. if inspection_reference.ID > 0 {
  267. return inspection_reference.ProjectId, err
  268. } else {
  269. err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
  270. utils.InfoLog("inspection_reference: %v", inspection_reference)
  271. if inspection_reference.ProjectId > 0 {
  272. return inspection_reference.ProjectId + 1, err
  273. } else {
  274. return 1001501, err
  275. }
  276. }
  277. }
  278. // // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
  279. // func GetGzjhProjectID(org_id int64, project_name string) (project_id int64, err error) {
  280. // var inspection_reference models.MiddleInspectionReference
  281. // err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
  282. // if inspection_reference.ID > 0 {
  283. // return inspection_reference.ProjectId, err
  284. // } else {
  285. // err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
  286. // if inspection_reference.ProjectId > 0 {
  287. // return inspection_reference.ProjectId + 1, err
  288. // } else {
  289. // return 116001, err
  290. // }
  291. // }
  292. // }
  293. func GzjhReportInfoHandle(CheckInfo adkCheckGzjh, org_id int64, patientId int64) {
  294. // 1.先把所有的检查项弄出来
  295. for _, info := range CheckInfo.Result {
  296. // 根据project_id和item_id 判断该项是否存在
  297. curitemcode, _ := strconv.ParseInt(info.Itemcode, 10, 64)
  298. reference, _ := GetProjectInfoGzjh(curitemcode, org_id)
  299. utils.InfoLog("info: %v", info)
  300. utils.InfoLog("reference: %v", info)
  301. if reference.ID > 0 {
  302. if reference.ProjectId > 0 {
  303. LgthYsSyncGzjh(info, reference.ProjectId, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
  304. } else {
  305. project_id := int64(0)
  306. if len(info.Groupitemcode) > 0 {
  307. // 对没有project信息的项目进行修改
  308. project_id, _ = GetGzzcjhProjectID(org_id, info.Groupitemname)
  309. reference.ProjectId = project_id
  310. reference.ProjectName = info.Groupitemcode
  311. reference.Project = info.Groupitemcode
  312. // 修改配置信息
  313. UpdateInspectionReference(&reference)
  314. }
  315. LgthYsSyncGzjh(info, project_id, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
  316. }
  317. } else {
  318. project_id := int64(0)
  319. if len(info.Groupitemcode) > 0 {
  320. project_id, _ = GetGzzcjhProjectID(org_id, info.Groupitemname)
  321. }
  322. LgthYsSyncGzjh(info, project_id, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
  323. }
  324. }
  325. // SyncLisGzjhtx()
  326. }
  327. type adkResultGzjh struct {
  328. Testno string `json:"testno"`
  329. Reportno string `json:"reportno"`
  330. Itemord string `json:"itemord"`
  331. Itemcode string `json:"itemcode"`
  332. Itemname string `json:"itemname"`
  333. ItemEname string `json:"itemename"`
  334. Result string `json:"result"`
  335. Units string `json:"units"`
  336. Testdate string `json:"testdate"`
  337. Eqpname string `json:"eqpname"`
  338. Groupitemcode string `json:"groupitemcode"`
  339. Groupitemname string `json:"groupitemname"`
  340. Limit string `json:"limit"`
  341. Resultstate string `json:"resultstate"`
  342. Criticalflag string `json:"criticalflag"`
  343. Itemename string `json:"itemename"`
  344. }
  345. // 从机构将数据同步到中间库
  346. func LgthYsSyncGzjh(report adkResultGzjh, project_id int64, item_id int64, org_id int64, patient_id int64, receivetime string) (*models.MiddleInspectionReference, error) {
  347. tx := writeMiddleDb.Begin()
  348. var inspection models.MiddleInspection
  349. var inspection_reference models.MiddleInspectionReference
  350. recordDateStr := receivetime
  351. if len(receivetime) == 0 {
  352. recordDateStr = time.Now().Format("2006-01-02 15:04")
  353. }
  354. record_date_str, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  355. record_date := record_date_str.Unix()
  356. inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
  357. // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
  358. // record_date,_ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
  359. var total int
  360. var RangeOptions string
  361. var RangeMin string
  362. var RangeMax string
  363. // // 判断检查类型
  364. ItemType := 1
  365. Range := strings.Split(report.Limit, "-")
  366. if len(Range) > 1 {
  367. RangeMin = Range[0]
  368. RangeMax = Range[1]
  369. ItemType = 1
  370. } else {
  371. ItemType = 2
  372. RangeOptions = report.Limit
  373. }
  374. err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
  375. if inspection_reference.ID > 0 {
  376. ItemType = inspection_reference.RangeType
  377. }
  378. if total <= 0 {
  379. inspection_reference.OrgId = org_id
  380. inspection_reference.ProjectName = report.Groupitemname
  381. inspection_reference.Project = report.Groupitemcode
  382. inspection_reference.ProjectId = project_id
  383. inspection_reference.ItemName = report.Itemname
  384. inspection_reference.ItemNameAddition = report.ItemEname
  385. inspection_reference.ItemId = item_id
  386. inspection_reference.RangeType = ItemType
  387. inspection_reference.RangeMin = RangeMin
  388. inspection_reference.RangeMax = RangeMax
  389. // inspection_reference.RangeValue = RangeValue
  390. inspection_reference.RangeOptions = RangeOptions
  391. inspection_reference.Unit = report.Units
  392. inspection_reference.Status = 1
  393. inspection_reference.CreatedTime = time.Now().Unix()
  394. inspection_reference.UpdatedTime = time.Now().Unix()
  395. inspection_reference.InspectDate = inspect_date
  396. inspection_reference.UTime = inspect_date
  397. err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  398. if err != nil {
  399. tx.Rollback()
  400. }
  401. }
  402. var itotal int
  403. err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ? and status = 1", org_id, project_id, item_id, record_date, patient_id).Find(&inspection).Count(&itotal).Error
  404. if itotal <= 0 {
  405. report.Result = strings.Replace(report.Result, "&gt;", ">", -1)
  406. report.Result = strings.Replace(report.Result, "&lt;", "<", -1)
  407. inspection.PatientId = patient_id
  408. inspection.OrgId = org_id
  409. inspection.ProjectId = project_id
  410. inspection.ItemName = inspection_reference.ItemName
  411. inspection.ProjectName = inspection_reference.ProjectName
  412. inspection.InspectType = ItemType
  413. inspection.ItemId = item_id
  414. inspection.InspectValue = report.Result
  415. inspection.InspectDate = inspect_date
  416. inspection.RecordDate = record_date
  417. inspection.InspectTips = report.Resultstate
  418. inspection.Status = 1
  419. inspection.CreatedTime = time.Now().Unix()
  420. inspection.UpdatedTime = time.Now().Unix()
  421. inspection.UTime = inspect_date
  422. inspection.HisUserId = strconv.FormatInt(patient_id, 10)
  423. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  424. if err != nil {
  425. tx.Rollback()
  426. }
  427. }
  428. // //处理检验检查操作表里同步条数和状态
  429. // cur_num := Head.ReportInfoItemHandleNum + 1
  430. // Head.ReportInfoItemHandleNum = cur_num
  431. // handleType := 2
  432. // if cur_num == Head.ReportInfoItemNum {
  433. // handleType = 1
  434. // }
  435. // middleReportHandle := models.MiddleReportHandle{
  436. // ID: Head.ID,
  437. // ReportInfoItemHandleNum: cur_num,
  438. // HandleType: int64(handleType),
  439. // UpdatedTime: time.Now().Unix(),
  440. // }
  441. // err = UpdateReportHandleListyOrgID(&middleReportHandle)
  442. // if err != nil {
  443. // tx.Rollback()
  444. // }
  445. // }
  446. tx.Commit()
  447. return nil, err
  448. }
  449. // 根据姓名获取patient_id
  450. func GetPatientGzjhListGzjh(org_id int64, schedulesTime int64) (schedules []*models.DialysisSchedule, err error) {
  451. err = readDb.Model(&models.DialysisSchedule{}).Where("user_org_id = ? and status = 1 and schedule_date = ?", org_id, schedulesTime).Preload("Patients", "status = 1").Find(&schedules).Error
  452. return
  453. }
  454. // 根据姓名获取admin_user_id
  455. func GetAdminUserIdGzjh(org_id int64, doctor_name string) (doctor models.UserAdminRole, err error) {
  456. err = writeUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? and status = 1 and user_name = ?", org_id, doctor_name).First(&doctor).Error
  457. return
  458. }
  459. func GetPatientGzjhByOrgIdGzjh(org_id int64) (patientList []*models.Patients, err error) {
  460. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patientList).Error
  461. return
  462. }
  463. func SyncToGzczjhtx() {
  464. utils.TraceLog("检验检查同步任务开始执行")
  465. org_id := int64(10015)
  466. // 第一步:跟进org_id 去中间库查出需要同步的数据
  467. inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
  468. inspections, _ := GetSyncInspectionByOrgId(org_id)
  469. // 第二步:将数据同步到业务库
  470. if len(inspection_references) > 0 {
  471. for _, inspection_reference := range inspection_references {
  472. SyncInspectionReference(&inspection_reference)
  473. }
  474. }
  475. if len(inspections) > 0 {
  476. for _, inspection := range inspections {
  477. SyncInspection(&inspection)
  478. }
  479. }
  480. utils.SuccessLog("检验检查同步任务完成")
  481. }