bjnc_service.go 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. package service
  2. import (
  3. "IC/models"
  4. _ "IC/models"
  5. "IC/utils"
  6. "bytes"
  7. "encoding/json"
  8. _ "encoding/json"
  9. _ "encoding/xml"
  10. "fmt"
  11. _ "github.com/jinzhu/gorm"
  12. "io/ioutil"
  13. "net/http"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. func GetbjncProjectID(org_id int64, project_name string) (project_id int64, err error) {
  19. var inspection_reference models.MiddleInspectionReference
  20. err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ?", org_id, project_name).First(&inspection_reference).Error
  21. if inspection_reference.ID > 0 {
  22. return inspection_reference.ProjectId, err
  23. } else {
  24. err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ? ", org_id, project_name).First(&inspection_reference).Error
  25. if inspection_reference.ID > 0 {
  26. return inspection_reference.ProjectId, err
  27. } else {
  28. err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
  29. if inspection_reference.ProjectId > 0 {
  30. return inspection_reference.ProjectId + 1, err
  31. } else {
  32. return 1060601, err
  33. }
  34. }
  35. }
  36. }
  37. // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
  38. func GetbjncItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
  39. var inspection_reference models.MiddleInspectionReference
  40. err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ? and item_name = ?", org_id, project_name, item_name).First(&inspection_reference).Error
  41. if inspection_reference.ID > 0 {
  42. return inspection_reference.ItemId, err
  43. } else {
  44. err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
  45. if inspection_reference.ItemId > 0 {
  46. return inspection_reference.ItemId + 1, err
  47. } else {
  48. return project_id*100 + 1, err
  49. }
  50. }
  51. }
  52. // 北京南诚中西医结合医院Lis同步
  53. func SyncBjncLis() (err error) {
  54. org_id := int64(10606)
  55. // 第一步:获取上一次同步的时间点
  56. syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
  57. var sync_time int64
  58. if syncLastInfo.ID > 0 {
  59. sync_time = syncLastInfo.SyncTime - 60*60*6
  60. } else {
  61. sync_time = 1714492800
  62. }
  63. loc, _ := time.LoadLocation("Local") //重要:获取时区
  64. sync_time_temp := time.Unix(sync_time, 0)
  65. startTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
  66. end_time := time.Now().Unix()
  67. end_time_temp := time.Unix(end_time, 0)
  68. endTimeStr := end_time_temp.Format("2006-01-02 15:04:05")
  69. // 第二步:获取所有患者的病历号
  70. patientList, _ := GetPatientGzjhByOrgId(org_id)
  71. if len(patientList) > 0 {
  72. for _, patient := range patientList {
  73. if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
  74. //patient_id := patient.ID
  75. utils.InfoLog("startTimeStr:%v", startTimeStr)
  76. // utils.InfoLog("VipStr:%v", VipStr)
  77. // 跟进身份证获取patientID
  78. patientList, _ := BjncGetPatientInfo(patient.IdCardNo, endTimeStr)
  79. var bjncPatient BjncPatientInfo
  80. if err := json.Unmarshal([]byte(patientList), &bjncPatient); err != nil {
  81. utils.ErrorLog("解析失败:%v", err)
  82. }
  83. utils.InfoLog("patientId:%v", bjncPatient.Result[0].Patientid)
  84. reportList, _ := BjncGetLisReport(bjncPatient.Result[0].Patientid, startTimeStr, endTimeStr)
  85. var lisReport BjncLisReport
  86. if err := json.Unmarshal([]byte(reportList), &lisReport); err != nil {
  87. utils.ErrorLog("解析失败:%v", err)
  88. }
  89. utils.InfoLog("reportList:%v", lisReport)
  90. if len(lisReport.Result) > 0 {
  91. for _, linfo := range lisReport.Result {
  92. infoReprot, _ := BjncGetReportInfo(linfo.Reportno, startTimeStr, endTimeStr)
  93. var reportInfo ReportDetail
  94. if err := json.Unmarshal([]byte(infoReprot), &reportInfo); err != nil {
  95. utils.ErrorLog("解析失败:%v", err)
  96. }
  97. for _, ivalue := range reportInfo.Result {
  98. theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", ivalue.Testtime, loc) //使用模板在对应时区转化为time.time类型
  99. start_temp_Time := theTime.Format("2006-01-02 15:04")
  100. SxTime, _ := time.ParseInLocation("2006-01-02 15:04", start_temp_Time, loc)
  101. start_time := SxTime.Unix()
  102. project_id, _ := GetbjncProjectID(org_id, ivalue.Combinationname)
  103. item_id, _ := GetbjncItemID(org_id, ivalue.Combinationname, ivalue.Itemname, project_id)
  104. tx := writeMiddleDb.Begin()
  105. var inspection models.MiddleInspection
  106. var inspection_reference models.MiddleInspectionReference
  107. var total int
  108. var RangeOptions string
  109. var RangeMin string
  110. var RangeMax string
  111. var ItemType int
  112. Range := strings.Split(ivalue.Referscope, "-")
  113. if len(Range) > 1 {
  114. RangeMin = Range[0]
  115. RangeMax = Range[1]
  116. ItemType = 1
  117. } else {
  118. ItemType = 2
  119. RangeOptions = ivalue.Referscope
  120. }
  121. 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
  122. if total <= 0 {
  123. inspection_reference.OrgId = org_id
  124. inspection_reference.ProjectName = ivalue.Combinationname
  125. inspection_reference.Project = ivalue.Combinationname
  126. inspection_reference.ProjectId = project_id
  127. inspection_reference.ItemName = ivalue.Itemname
  128. // inspection_reference.ItemNameAddition = strconv.FormatInt(info.ItemId, 10)
  129. inspection_reference.ItemId = item_id
  130. inspection_reference.RangeType = ItemType
  131. inspection_reference.RangeMin = RangeMin
  132. inspection_reference.RangeMax = RangeMax
  133. // inspection_reference.RangeValue = RangeValue
  134. inspection_reference.RangeOptions = RangeOptions
  135. inspection_reference.Unit = ivalue.Unit
  136. inspection_reference.Status = 1
  137. inspection_reference.CreatedTime = time.Now().Unix()
  138. inspection_reference.UpdatedTime = time.Now().Unix()
  139. inspection_reference.InspectDate = ivalue.Testtime
  140. inspection_reference.UTime = ivalue.Testtime
  141. err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  142. if err != nil {
  143. tx.Rollback()
  144. }
  145. }
  146. var itotal int
  147. 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, start_time, patient.ID).Find(&inspection).Count(&itotal).Error
  148. if itotal <= 0 {
  149. // inspection.InspectValue = strings.Replace(LisInfo.Testresult, "&gt;", ">", -1)
  150. // inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "&lt;", "<", -1)
  151. inspection.PatientId = patient.ID
  152. inspection.OrgId = org_id
  153. inspection.ProjectId = project_id
  154. inspection.ItemName = inspection_reference.ItemName
  155. inspection.ProjectName = inspection_reference.ProjectName
  156. inspection.InspectType = ItemType
  157. inspection.ItemId = item_id
  158. inspection.InspectValue = ivalue.Itemreportresult
  159. inspection.InspectDate = start_temp_Time
  160. inspection.RecordDate = start_time
  161. // inspection.InspectTips = report.Resultstate
  162. inspection.Status = 1
  163. inspection.CreatedTime = time.Now().Unix()
  164. inspection.UpdatedTime = time.Now().Unix()
  165. // inspection.UTime = record_date.Format(timeLayout)
  166. // inspection.HisUserId = strconv.FormatInt(patient_id, 10)
  167. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  168. if err != nil {
  169. tx.Rollback()
  170. }
  171. }
  172. tx.Commit()
  173. }
  174. }
  175. }
  176. } else {
  177. continue
  178. }
  179. }
  180. }
  181. var syncInfo models.MiddleSyncInfo
  182. syncInfo.OrgId = org_id
  183. syncInfo.SyncTime = time.Now().Unix()
  184. syncInfo.SyncResultType = 1
  185. syncInfo.SyncRsultRemark = "同步成功"
  186. syncInfo.SyncTotalNum = 0
  187. syncInfo.SyncSuccessNum = 0
  188. syncInfo.SyncInfo = ""
  189. syncInfo.CreateTime = time.Now().Unix()
  190. syncInfo.UpdateTime = time.Now().Unix()
  191. cwderr := CreateSyncInfo(&syncInfo)
  192. if cwderr != nil {
  193. utils.ErrorLog("创建同步信息失败:%v", cwderr)
  194. return
  195. }
  196. SyncToFjtftx()
  197. return
  198. }
  199. type BjncPatientInfo struct {
  200. Msg string `json:"msg"`
  201. Code string `json:"code"`
  202. Result []struct {
  203. Patientid int64 `json:"patientId"`
  204. Visitid int64 `json:"visitId"`
  205. Outpatientno string `json:"outPatientNo"`
  206. Patientname string `json:"patientName"`
  207. Idcardno string `json:"idCardNo"`
  208. } `json:"result"`
  209. }
  210. func BjncGetPatientInfo(id_card_no string, endTime string) (string, string) {
  211. // 1.生成签名sign
  212. var sync_time int64
  213. sync_time = 1690819200 // 2023-08-01 00:00:00
  214. sync_time_temp := time.Unix(sync_time, 0)
  215. startTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
  216. signData := make(map[string]interface{})
  217. //signData["dateType"] = "07"
  218. signData["startTime"] = startTimeStr
  219. signData["idCardNo"] = id_card_no
  220. signData["endTime"] = endTime
  221. bytesData, _ := json.Marshal(signData)
  222. inputLog := string(bytesData)
  223. signStr := "body=" + inputLog + "&operUserCode=100&serv=getRegisterInfo&key=A3195B3D179B01F66C86703E0890A95F"
  224. signTemp := utils.String2md5(signStr)
  225. sign := strings.ToUpper(signTemp)
  226. // 2.请求参数
  227. inputData := make(map[string]interface{})
  228. inputData["body"] = signData
  229. inputData["serv"] = "getRegisterInfo"
  230. inputData["operUserCode"] = "100"
  231. inputData["sign"] = sign
  232. postData, err := json.Marshal(inputData)
  233. postStr := string(postData)
  234. utils.InfoLog("1111111111:%v", postStr)
  235. if err != nil {
  236. fmt.Println(err.Error())
  237. return err.Error(), ""
  238. }
  239. reader := bytes.NewReader(postData)
  240. url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
  241. request, err := http.NewRequest("POST", url, reader)
  242. if err != nil {
  243. fmt.Println(err.Error())
  244. return err.Error(), ""
  245. }
  246. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  247. request.Header.Set("code", "XTXT")
  248. client := http.Client{}
  249. resp, err := client.Do(request)
  250. if err != nil {
  251. fmt.Println(err.Error())
  252. return err.Error(), ""
  253. }
  254. respBytes, err := ioutil.ReadAll(resp.Body)
  255. if err != nil {
  256. fmt.Println(err.Error())
  257. return err.Error(), ""
  258. }
  259. str := string(respBytes)
  260. utils.InfoLog("22222222:%v", str)
  261. return str, inputLog
  262. }
  263. type BjncLisReport struct {
  264. Code string `json:"code"`
  265. Msg string `json:"msg"`
  266. Result []struct {
  267. Patientid string `json:"patientId"`
  268. Patientname string `json:"patientName"`
  269. Reportno int64 `json:"reportNo"`
  270. Visitid string `json:"visitId"`
  271. Applydeptname string `json:"applyDeptName"`
  272. Reportname string `json:"reportName"`
  273. } `json:"result"`
  274. }
  275. func BjncGetLisReport(id_card_no int64, startTime string, endTime string) (string, string) {
  276. // 1.生成签名sign
  277. signData := make(map[string]interface{})
  278. signData["patientId"] = strconv.FormatInt(id_card_no, 10)
  279. signData["dateType"] = "16"
  280. signData["startTime"] = startTime
  281. signData["endTime"] = endTime
  282. bytesData, _ := json.Marshal(signData)
  283. inputLog := string(bytesData)
  284. signStr := "body=" + inputLog + "&operUserCode=100&serv=getLisReport&key=A3195B3D179B01F66C86703E0890A95F"
  285. signTemp := utils.String2md5(signStr)
  286. sign := strings.ToUpper(signTemp)
  287. // 2.请求参数
  288. inputData := make(map[string]interface{})
  289. inputData["body"] = signData
  290. inputData["serv"] = "getLisReport"
  291. inputData["operUserCode"] = "100"
  292. inputData["sign"] = sign
  293. postData, err := json.Marshal(inputData)
  294. postStr := string(postData)
  295. utils.InfoLog("1111111111:%v", postStr)
  296. if err != nil {
  297. fmt.Println(err.Error())
  298. return err.Error(), ""
  299. }
  300. reader := bytes.NewReader(postData)
  301. url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
  302. request, err := http.NewRequest("POST", url, reader)
  303. if err != nil {
  304. fmt.Println(err.Error())
  305. return err.Error(), ""
  306. }
  307. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  308. request.Header.Set("code", "XTXT")
  309. client := http.Client{}
  310. resp, err := client.Do(request)
  311. if err != nil {
  312. fmt.Println(err.Error())
  313. return err.Error(), ""
  314. }
  315. respBytes, err := ioutil.ReadAll(resp.Body)
  316. if err != nil {
  317. fmt.Println(err.Error())
  318. return err.Error(), ""
  319. }
  320. str := string(respBytes)
  321. utils.InfoLog("22222222:%v", str)
  322. return str, inputLog
  323. }
  324. type ReportDetail struct {
  325. Msg string `json:"msg"`
  326. Code string `json:"code"`
  327. Result []struct {
  328. Detailid string `json:"detailId"`
  329. Reportno string `json:"reportNo"`
  330. Testtime string `json:"testTime"`
  331. Combinationcode string `json:"combinationCode"`
  332. Combinationname string `json:"combinationName"`
  333. Itemcode string `json:"itemCode"`
  334. Itemname string `json:"itemName"`
  335. Abbreviation string `json:"abbreviation"`
  336. Itemreportresult string `json:"itemReportResult"`
  337. Unit string `json:"unit"`
  338. Resultpoint string `json:"resultPoint"`
  339. Rownr string `json:"rownr"`
  340. Referlow string `json:"referLow"`
  341. Referhigh string `json:"referHigh"`
  342. Referscope string `json:"referScope"`
  343. Low string `json:"low"`
  344. High string `json:"high"`
  345. } `json:"result"`
  346. }
  347. func BjncGetReportInfo(report_no int64, startTime string, endTime string) (string, string) {
  348. // 1.生成签名sign
  349. signData := make(map[string]interface{})
  350. signData["reportNo"] = strconv.FormatInt(report_no, 10)
  351. signData["dateType"] = "16"
  352. signData["startTime"] = startTime
  353. signData["endTime"] = endTime
  354. bytesData, _ := json.Marshal(signData)
  355. inputLog := string(bytesData)
  356. signStr := "body=" + inputLog + "&operUserCode=100&serv=getLisReportDetail&key=A3195B3D179B01F66C86703E0890A95F"
  357. signTemp := utils.String2md5(signStr)
  358. sign := strings.ToUpper(signTemp)
  359. // 2.请求参数
  360. inputData := make(map[string]interface{})
  361. inputData["body"] = signData
  362. inputData["serv"] = "getLisReportDetail"
  363. inputData["operUserCode"] = "100"
  364. inputData["sign"] = sign
  365. postData, err := json.Marshal(inputData)
  366. postStr := string(postData)
  367. utils.InfoLog("1111111111:%v", postStr)
  368. if err != nil {
  369. fmt.Println(err.Error())
  370. return err.Error(), ""
  371. }
  372. reader := bytes.NewReader(postData)
  373. url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
  374. request, err := http.NewRequest("POST", url, reader)
  375. if err != nil {
  376. fmt.Println(err.Error())
  377. return err.Error(), ""
  378. }
  379. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  380. request.Header.Set("code", "XTXT")
  381. client := http.Client{}
  382. resp, err := client.Do(request)
  383. if err != nil {
  384. fmt.Println(err.Error())
  385. return err.Error(), ""
  386. }
  387. respBytes, err := ioutil.ReadAll(resp.Body)
  388. if err != nil {
  389. fmt.Println(err.Error())
  390. return err.Error(), ""
  391. }
  392. str := string(respBytes)
  393. utils.InfoLog("22222222:%v", str)
  394. return str, inputLog
  395. }
  396. func SyncBjncHis() (err error) {
  397. org_id := int64(10606)
  398. redisClient := RedisClient()
  399. defer redisClient.Close()
  400. // 第一步:获取上一次同步的时间点
  401. sync_time_tt, _ := redisClient.Get("bjncyyyy_sync_time").Result()
  402. sync_time, _ := strconv.ParseInt(sync_time_tt, 10, 64)
  403. if sync_time == 0 {
  404. sync_time = time.Now().Unix() - 60*60*10
  405. //sync_time = 1719763200
  406. }
  407. loc, _ := time.LoadLocation("Local") //重要:获取时区
  408. sync_time_temp := time.Unix(sync_time, 0)
  409. startTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
  410. end_time := time.Now().Unix()
  411. end_time_temp := time.Unix(end_time, 0)
  412. endTimeStr := end_time_temp.Format("2006-01-02 15:04:05")
  413. new_sync_time := time.Now().Unix() - 60*60
  414. redisClient.Set("bjncyyyy_sync_time", new_sync_time, time.Minute*60*24)
  415. // 第二步:获取所有患者的病历号
  416. patientList, _ := GetPatientGzjhByOrgId(org_id)
  417. if len(patientList) > 0 {
  418. for _, patient := range patientList {
  419. if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
  420. //patient_id := patient.ID
  421. utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
  422. // utils.InfoLog("VipStr:%v", VipStr)
  423. result, _ := BjncGetHis(patient.IdCardNo, startTimeStr, endTimeStr)
  424. var bjncHis BjncHis
  425. if err := json.Unmarshal([]byte(result), &bjncHis); err != nil {
  426. utils.ErrorLog("解析失败:%v", err)
  427. }
  428. fmt.Println(bjncHis)
  429. for _, cinfo := range bjncHis.Result {
  430. fmt.Println(cinfo.Patientid)
  431. // 查询该患者当天是否有排班信息
  432. STime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Itemeffectivetimelow, loc) //使用模板在对应时区转化为time.time类型
  433. formattedTime := STime.Format("2006-01-02")
  434. StTime, _ := time.ParseInLocation("2006-01-02", formattedTime, loc)
  435. schedulesTime := StTime.Unix()
  436. theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Itemeffectivetimelow, loc) //使用模板在对应时区转化为time.time类型
  437. start_temp_Time := theTime.Format("2006-01-02 15:04")
  438. SxTime, _ := time.ParseInLocation("2006-01-02 15:04", start_temp_Time, loc)
  439. start_time := SxTime.Unix()
  440. utils.InfoLog("start_time:%v", start_time)
  441. schedulesInfo, _ := GetSchedulesByPatientID(org_id, schedulesTime, patient.ID)
  442. if schedulesInfo.ID > 0 {
  443. start_time = theTime.Unix()
  444. } else {
  445. continue
  446. }
  447. // 根据同步来的 advice_id 来查询库里是否已经存在
  448. advice_info, _ := GetAdviceBySyncAdviceIdForScyyyy(org_id, cinfo.Medicaladviceid, schedulesTime, patient.ID)
  449. utils.InfoLog("Orderstatuscode:%v", cinfo.Orderstatuscode)
  450. utils.InfoLog("AdviceName:%v", cinfo.Diagproname)
  451. if advice_info.ID > 0 {
  452. if cinfo.Orderstatuscode == 4 || cinfo.Orderstatuscode == 5 {
  453. advice_info.Status = 0
  454. SaveDoctorAdviceHandle(&advice_info)
  455. } else {
  456. continue
  457. }
  458. } else {
  459. if cinfo.Orderstatuscode == 1 || cinfo.Orderstatuscode == 8 {
  460. // 根据姓名获取医生ID
  461. var doctor_id int64
  462. temp_doctor_id, _ := redisClient.Get("bjncyyyy_doctor_id_" + cinfo.Orderdoctorcode).Result()
  463. if len(temp_doctor_id) == 0 {
  464. doctor, _ := GetAdminUserId(org_id, cinfo.Orderdoctorname)
  465. doctor_id = doctor.AdminUserId
  466. if doctor_id > 0 {
  467. redisClient.Set("bjncyyyy_doctor_id_"+cinfo.Orderdoctorcode, doctor_id, time.Minute*60*2)
  468. } else {
  469. continue
  470. }
  471. } else {
  472. doctor_id, _ = strconv.ParseInt(temp_doctor_id, 10, 64)
  473. }
  474. //
  475. // // 根据排班班次,固定医嘱时间
  476. advice := models.XtDoctorAdvice{
  477. UserOrgId: org_id,
  478. PatientId: patient.ID,
  479. AdviceType: 2,
  480. AdviceDate: schedulesTime,
  481. StartTime: start_time,
  482. AdviceName: cinfo.Diagproname,
  483. RecordDate: schedulesTime,
  484. SingleDose: cinfo.Dosequantity,
  485. SingleDoseUnit: cinfo.Dosequantityunit,
  486. PrescribingNumber: cinfo.Amount,
  487. PrescribingNumberUnit: cinfo.Unit,
  488. DeliveryWay: cinfo.Routename,
  489. ExecutionFrequency: cinfo.Executefrequencyname,
  490. AdviceDoctor: doctor_id,
  491. CreatedTime: time.Now().Unix(),
  492. UpdatedTime: time.Now().Unix(),
  493. SyncAdviceId: cinfo.Medicaladviceid,
  494. ExecutionState: 2,
  495. Status: 1,
  496. IsSync: 1,
  497. }
  498. utils.InfoLog("advice:%v", advice)
  499. if len(cinfo.Diagproname) > 0 {
  500. handleerr := CreateDoctorAdviceHandle(&advice)
  501. if handleerr != nil {
  502. utils.ErrorLog("添加医嘱信息失败:%v", handleerr)
  503. continue
  504. }
  505. } else {
  506. continue
  507. }
  508. } else {
  509. continue
  510. }
  511. }
  512. }
  513. }
  514. }
  515. }
  516. //var syncInfo models.MiddleSyncInfo
  517. //syncInfo.OrgId = org_id
  518. //syncInfo.SyncTime = time.Now().Unix()
  519. //syncInfo.SyncResultType = 1
  520. //syncInfo.SyncRsultRemark = "同步成功"
  521. //syncInfo.SyncTotalNum = 0
  522. //syncInfo.SyncSuccessNum = 0
  523. //syncInfo.SyncInfo = ""
  524. //syncInfo.CreateTime = time.Now().Unix()
  525. //syncInfo.UpdateTime = time.Now().Unix()
  526. //
  527. //cwderr := CreateSyncInfo(&syncInfo)
  528. //if cwderr != nil {
  529. // utils.ErrorLog("创建同步信息失败:%v", cwderr)
  530. // return
  531. //}
  532. //SyncToFjtftx()
  533. return
  534. }
  535. type BjncHis struct {
  536. Msg string `json:"msg"`
  537. Code string `json:"code"`
  538. Result []struct {
  539. Patientid string `json:"patientId"`
  540. Visitid string `json:"visitId"`
  541. Outpatientno string `json:"outPatientNo"`
  542. Patientname string `json:"patientName"`
  543. Idcardno string `json:"idCardNo"`
  544. Orderstatuscode int64 `json:"orderStatusCode"`
  545. Ordercreatetime string `json:"orderCreateTime"`
  546. Orderdoctorcode string `json:"orderDoctorCode"`
  547. Orderdoctorname string `json:"orderDoctorName"`
  548. Medicaladviceid int64 `json:"medicalAdviceId"`
  549. Medicalordername string `json:"medicalOrderName"`
  550. Itemname string `json:"itemName"`
  551. Itemeffectivetimelow string `json:"itemEffectiveTimeLow"`
  552. Executefrequencyname string `json:"executeFrequencyName"`
  553. Routename string `json:"routeName"`
  554. Dosequantity float64 `json:"doseQuantity"`
  555. Dosequantityunit string `json:"doseQuantityUnit"`
  556. Totaldosequantity float64 `json:"totalDoseQuantity"`
  557. Totaldosequantityunit string `json:"totalDoseQuantityUnit"`
  558. Diagproname string `json:"diagProName"`
  559. Amount float64 `json:"amount"`
  560. Unit string `json:"unit"`
  561. } `json:"result"`
  562. }
  563. func BjncGetHis(id_card_no string, startTime string, endTime string) (string, string) {
  564. // 1.生成签名sign
  565. signData := make(map[string]interface{})
  566. signData["dateType"] = "07"
  567. signData["medicalOrderType"] = "1,2,3,A,B,D,E,L,N,O"
  568. signData["idCardNo"] = id_card_no
  569. signData["startTime"] = startTime
  570. signData["endTime"] = endTime
  571. bytesData, _ := json.Marshal(signData)
  572. inputLog := string(bytesData)
  573. signStr := "body=" + inputLog + "&operUserCode=100&serv=getMedicalAdvice&key=A3195B3D179B01F66C86703E0890A95F"
  574. signTemp := utils.String2md5(signStr)
  575. sign := strings.ToUpper(signTemp)
  576. // 2.请求参数
  577. inputData := make(map[string]interface{})
  578. inputData["body"] = signData
  579. inputData["serv"] = "getMedicalAdvice"
  580. inputData["operUserCode"] = "100"
  581. inputData["sign"] = sign
  582. postData, err := json.Marshal(inputData)
  583. postStr := string(postData)
  584. utils.InfoLog("1111111111:%v", postStr)
  585. if err != nil {
  586. fmt.Println(err.Error())
  587. return err.Error(), ""
  588. }
  589. reader := bytes.NewReader(postData)
  590. url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
  591. request, err := http.NewRequest("POST", url, reader)
  592. if err != nil {
  593. fmt.Println(err.Error())
  594. return err.Error(), ""
  595. }
  596. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  597. request.Header.Set("code", "XTXT")
  598. client := http.Client{}
  599. resp, err := client.Do(request)
  600. if err != nil {
  601. fmt.Println(err.Error())
  602. return err.Error(), ""
  603. }
  604. respBytes, err := ioutil.ReadAll(resp.Body)
  605. if err != nil {
  606. fmt.Println(err.Error())
  607. return err.Error(), ""
  608. }
  609. str := string(respBytes)
  610. utils.InfoLog("22222222:%v", str)
  611. return str, inputLog
  612. }
  613. //
  614. //func FjtjGetLac(lab01 int64) (string, string) {
  615. // inputData := make(map[string]interface{})
  616. //
  617. // inputData["lab01"] = lab01
  618. //
  619. // var inputLog string
  620. // bytesData, err := json.Marshal(inputData)
  621. // inputLog = string(bytesData)
  622. // fmt.Println(string(bytesData))
  623. // if err != nil {
  624. // fmt.Println(err.Error())
  625. // return err.Error(), ""
  626. // }
  627. // reader := bytes.NewReader(bytesData)
  628. // url := "http://hip.zptfyy.com/esb/listener/getLac1"
  629. //
  630. // request, err := http.NewRequest("POST", url, reader)
  631. // if err != nil {
  632. // fmt.Println(err.Error())
  633. // return err.Error(), ""
  634. // }
  635. //
  636. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  637. // request.Header.Set("code", "xt")
  638. //
  639. // client := http.Client{}
  640. // resp, err := client.Do(request)
  641. // if err != nil {
  642. // fmt.Println(err.Error())
  643. // return err.Error(), ""
  644. // }
  645. // respBytes, err := ioutil.ReadAll(resp.Body)
  646. // if err != nil {
  647. // fmt.Println(err.Error())
  648. // return err.Error(), ""
  649. // }
  650. // str := string(respBytes)
  651. // return str, inputLog
  652. //}
  653. //
  654. //// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
  655. //func GetfjtfProjectID(org_id int64, project_name string) (project_id int64, err error) {
  656. // var inspection_reference models.MiddleInspectionReference
  657. // err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
  658. // if inspection_reference.ID > 0 {
  659. // return inspection_reference.ProjectId, err
  660. // } else {
  661. // err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
  662. // if inspection_reference.ProjectId > 0 {
  663. // return inspection_reference.ProjectId + 1, err
  664. // } else {
  665. // return 330001, err
  666. // }
  667. // }
  668. //}
  669. //
  670. //// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
  671. //func GetFjtfItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
  672. // var inspection_reference models.MiddleInspectionReference
  673. // err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ? and item_name = ?", org_id, project_name, item_name).First(&inspection_reference).Error
  674. // if inspection_reference.ID > 0 {
  675. // return inspection_reference.ItemId, err
  676. // } else {
  677. // err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
  678. // utils.InfoLog("inspection_reference: %v", inspection_reference)
  679. // if inspection_reference.ItemId > 0 {
  680. // return inspection_reference.ItemId + 1, err
  681. // } else {
  682. // return project_id*100 + 1, err
  683. // }
  684. // }
  685. //}
  686. //
  687. //func SyncToFjtftx() {
  688. // utils.TraceLog("检验检查同步任务开始执行")
  689. // org_id := int64(10330)
  690. //
  691. // // 第一步:跟进org_id 去中间库查出需要同步的数据
  692. // inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
  693. // inspections, _ := GetSyncInspectionByOrgId(org_id)
  694. //
  695. // // 第二步:将数据同步到业务库
  696. // if len(inspection_references) > 0 {
  697. // for _, inspection_reference := range inspection_references {
  698. // SyncInspectionReference(&inspection_reference)
  699. // }
  700. // }
  701. //
  702. // if len(inspections) > 0 {
  703. // for _, inspection := range inspections {
  704. // SyncInspection(&inspection)
  705. // }
  706. // }
  707. // utils.SuccessLog("检验检查同步任务完成")
  708. //}