coordinate_service.go 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. package service
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "gdyb/models"
  7. "github.com/jinzhu/gorm"
  8. "io/ioutil"
  9. "net/http"
  10. "time"
  11. )
  12. func UpdateHisPatientStatusTwo(his *models.VMHisPatient) {
  13. writeDb.Save(&his)
  14. }
  15. func GetUnSettleHisPrescriptionFiveTen(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  16. err = readDb.Model(&models.HisPrescription{}).
  17. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  18. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  19. }).
  20. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  21. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  22. }).
  23. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  24. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  25. }).
  26. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 and order_status <> 5 AND p_type = ?", org_id, record_date, patient_id, p_type).
  27. Find(&prescription).Error
  28. return
  29. }
  30. func GetUnSettleMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
  31. err = readDb.Model(&models.HisPrescription{}).
  32. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  33. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  34. }).
  35. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  36. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  37. }).
  38. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  39. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  40. }).
  41. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 5 AND p_type <> 1", org_id, start_date, end_date, patient_id).
  42. Find(&prescription).Error
  43. return
  44. }
  45. func GetHisOrderFour(patient_id string, infoSeq string, docId string) (order models.HisOrder, err error) {
  46. if len(docId) > 0 {
  47. err = readDb.Model(&models.HisOrder{}).Where("mdtrt_id = ? AND psn_no = ? AND setl_id = ? AND status = 1", infoSeq, patient_id, docId).First(&order).Error
  48. } else {
  49. err = readDb.Model(&models.HisOrder{}).Where("mdtrt_id = ? AND psn_no = ? AND status = 1 ", infoSeq, patient_id).First(&order).Error
  50. }
  51. return
  52. }
  53. func GetHisPatientForCoordinate(id_card_no string) (string, string) {
  54. //input := make(map[string]interface{})
  55. inputData := make(map[string]interface{})
  56. inputData["idcard"] = id_card_no // 就诊凭证编号
  57. var inputLog string
  58. bytesData, err := json.Marshal(inputData)
  59. inputLog = string(bytesData)
  60. fmt.Println(string(bytesData))
  61. if err != nil {
  62. fmt.Println(err.Error())
  63. return err.Error(), ""
  64. }
  65. reader := bytes.NewReader(bytesData)
  66. var url string
  67. gdyb_url := "http://218.104.146.179:9091/esb/listener/getPatientType"
  68. url = gdyb_url
  69. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  70. request, err := http.NewRequest("GET", url, reader)
  71. if err != nil {
  72. fmt.Println(err.Error())
  73. return err.Error(), ""
  74. }
  75. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  76. request.Header.Set("code", "Xmrjyy")
  77. client := http.Client{}
  78. resp, err := client.Do(request)
  79. if err != nil {
  80. fmt.Println(err.Error())
  81. return err.Error(), ""
  82. }
  83. respBytes, err := ioutil.ReadAll(resp.Body)
  84. if err != nil {
  85. fmt.Println(err.Error())
  86. return err.Error(), ""
  87. }
  88. fmt.Println(string(respBytes))
  89. str := string(respBytes)
  90. return str, inputLog
  91. }
  92. func UploadPrescriptionForCoordinate(info models.UploadInfo) (string, string) {
  93. //input := make(map[string]interface{})
  94. inputData := make(map[string]interface{})
  95. diags := make([]map[string]interface{}, 0)
  96. //diags := make([]map[string]interface{}, 0)
  97. presInfos := make([]map[string]interface{}, 0)
  98. for _, item := range info.Diag {
  99. inputDataDiag := make(map[string]interface{})
  100. inputDataDiag["vao06"] = item.Vao06
  101. inputDataDiag["bak02"] = item.Bak02
  102. diags = append(diags, inputDataDiag)
  103. }
  104. for _, item := range info.PresInfo {
  105. inputDataPresInfo := make(map[string]interface{})
  106. inputDataPresInfo["cbm06"] = item.Cbm06
  107. inputDataPresInfo["cbm07"] = item.Cbm07
  108. inputDataPresInfo["cbmid"] = item.Cbmid
  109. presDetails := make([]map[string]interface{}, 0)
  110. for _, subItem := range item.PresDetail {
  111. inputDataPresDetail := make(map[string]interface{})
  112. inputDataPresDetail["vaf59"] = subItem.Vaf59
  113. Items := make([]map[string]interface{}, 0)
  114. for _, subSubItem := range subItem.Item {
  115. inputDataItem := make(map[string]interface{})
  116. inputDataItem["bbx01"] = subSubItem.Bbx01
  117. inputDataItem["bda01"] = subSubItem.Bda01
  118. inputDataItem["bby01"] = subSubItem.Bby01
  119. inputDataItem["bck01b"] = subSubItem.Bck01b
  120. inputDataItem["bck01d"] = subSubItem.Bck01d
  121. inputDataItem["bdi01"] = subSubItem.Bdi01
  122. inputDataItem["rownr"] = subSubItem.Rownr
  123. inputDataItem["vaf11"] = subSubItem.Vaf11
  124. inputDataItem["vaf14"] = subSubItem.Vaf14
  125. inputDataItem["vaf15"] = subSubItem.Vaf15
  126. inputDataItem["vaf17"] = subSubItem.Vaf17
  127. inputDataItem["vaf18"] = subSubItem.Vaf18
  128. inputDataItem["vaf19"] = subSubItem.Vaf19
  129. inputDataItem["vaf20"] = subSubItem.Vaf20
  130. inputDataItem["vaf21"] = subSubItem.Vaf21
  131. inputDataItem["vaf22"] = subSubItem.Vaf22
  132. inputDataItem["vaf32"] = subSubItem.Vaf32
  133. inputDataItem["vaf35"] = subSubItem.Vaf35
  134. inputDataItem["vaf36"] = subSubItem.Vaf36
  135. inputDataItem["vaf58"] = subSubItem.Vaf58
  136. inputDataItem["vaf61"] = subSubItem.Vaf61
  137. Items = append(Items, inputDataItem)
  138. }
  139. inputDataPresDetail["item"] = Items
  140. presDetails = append(presDetails, inputDataPresDetail)
  141. }
  142. inputDataPresInfo["presDetail"] = presDetails
  143. presInfos = append(presInfos, inputDataPresInfo)
  144. }
  145. inputData["vaa01"] = info.Vaa01 // 就诊凭证编号
  146. inputData["Fasong"] = info.Fasong // 就诊凭证编号
  147. inputData["vaa07"] = info.Vaa07 // 就诊凭证编号
  148. inputData["bck01c"] = info.Bck01c // 就诊凭证编号
  149. inputData["bce02a"] = "1001" // 就诊凭证编号
  150. inputData["diag"] = diags // 就诊凭证编号
  151. inputData["presInfo"] = presInfos // 就诊凭证编号
  152. var inputLog string
  153. bytesData, err := json.Marshal(inputData)
  154. inputLog = string(bytesData)
  155. fmt.Println(string(bytesData))
  156. if err != nil {
  157. fmt.Println(err.Error())
  158. return err.Error(), ""
  159. }
  160. reader := bytes.NewReader(bytesData)
  161. var url string
  162. gdyb_url := "http://218.104.146.179:9091/esb/listener/sendPretreat"
  163. url = gdyb_url
  164. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  165. request, err := http.NewRequest("POST", url, reader)
  166. if err != nil {
  167. fmt.Println(err.Error())
  168. return err.Error(), ""
  169. }
  170. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  171. request.Header.Set("code", "Xmrjyy")
  172. client := http.Client{}
  173. resp, err := client.Do(request)
  174. if err != nil {
  175. fmt.Println(err.Error())
  176. return err.Error(), ""
  177. }
  178. respBytes, err := ioutil.ReadAll(resp.Body)
  179. if err != nil {
  180. fmt.Println(err.Error())
  181. return err.Error(), ""
  182. }
  183. fmt.Println(string(respBytes))
  184. str := string(respBytes)
  185. return str, inputLog
  186. }
  187. func UploadPrescriptionForCoordinateHospital(info models.UploadInfo) (string, string) {
  188. //input := make(map[string]interface{})
  189. inputData := make(map[string]interface{})
  190. diags := make([]map[string]interface{}, 0)
  191. //diags := make([]map[string]interface{}, 0)
  192. presInfos := make([]map[string]interface{}, 0)
  193. for _, item := range info.Diag {
  194. inputDataDiag := make(map[string]interface{})
  195. inputDataDiag["vao06"] = item.Vao06
  196. inputDataDiag["bak02"] = item.Bak02
  197. diags = append(diags, inputDataDiag)
  198. }
  199. for _, item := range info.PresInfo {
  200. inputDataPresInfo := make(map[string]interface{})
  201. inputDataPresInfo["cbm06"] = item.Cbm06
  202. inputDataPresInfo["cbm07"] = item.Cbm06
  203. inputDataPresInfo["cbmid"] = item.Cbmid
  204. presDetails := make([]map[string]interface{}, 0)
  205. for _, subItem := range item.PresDetail {
  206. inputDataPresDetail := make(map[string]interface{})
  207. inputDataPresDetail["vaf59"] = subItem.Vaf59
  208. Items := make([]map[string]interface{}, 0)
  209. for _, subSubItem := range subItem.Item {
  210. inputDataItem := make(map[string]interface{})
  211. inputDataItem["bbx01"] = subSubItem.Bbx01
  212. inputDataItem["bda01"] = subSubItem.Bda01
  213. inputDataItem["bby01"] = subSubItem.Bby01
  214. inputDataItem["bck01b"] = subSubItem.Bck01b
  215. inputDataItem["bck01d"] = subSubItem.Bck01d
  216. inputDataItem["bdi01"] = subSubItem.Bdi01
  217. inputDataItem["rownr"] = subSubItem.Rownr
  218. inputDataItem["vaf11"] = subSubItem.Vaf11
  219. inputDataItem["vaf14"] = subSubItem.Vaf14
  220. inputDataItem["vaf15"] = subSubItem.Vaf15
  221. inputDataItem["vaf17"] = subSubItem.Vaf17
  222. inputDataItem["vaf18"] = subSubItem.Vaf18
  223. inputDataItem["vaf19"] = subSubItem.Vaf19
  224. inputDataItem["vaf20"] = subSubItem.Vaf20
  225. inputDataItem["vaf21"] = subSubItem.Vaf21
  226. inputDataItem["vaf22"] = subSubItem.Vaf22
  227. inputDataItem["vaf32"] = subSubItem.Vaf32
  228. inputDataItem["vaf35"] = subSubItem.Vaf35
  229. inputDataItem["vaf36"] = subSubItem.Vaf36
  230. inputDataItem["vaf58"] = subSubItem.Vaf58
  231. inputDataItem["vaf61"] = subSubItem.Vaf61
  232. Items = append(Items, inputDataItem)
  233. }
  234. inputDataPresDetail["item"] = Items
  235. presDetails = append(presDetails, inputDataPresDetail)
  236. }
  237. inputDataPresInfo["presDetail"] = presDetails
  238. presInfos = append(presInfos, inputDataPresInfo)
  239. }
  240. inputData["vaa01"] = info.Vaa01 // 就诊凭证编号
  241. inputData["Fasong"] = info.Fasong // 就诊凭证编号
  242. inputData["vaa07"] = info.Vaa07 // 就诊凭证编号
  243. inputData["bck01c"] = info.Bck01c // 就诊凭证编号
  244. inputData["bce02a"] = "1001" // 就诊凭证编号
  245. inputData["diag"] = diags // 就诊凭证编号
  246. inputData["presInfo"] = presInfos // 就诊凭证编号
  247. var inputLog string
  248. bytesData, err := json.Marshal(inputData)
  249. inputLog = string(bytesData)
  250. fmt.Println(string(bytesData))
  251. if err != nil {
  252. fmt.Println(err.Error())
  253. return err.Error(), ""
  254. }
  255. reader := bytes.NewReader(bytesData)
  256. var url string
  257. gdyb_url := "http://218.104.146.179:90911/esb/listener/saveOrdInfoIp"
  258. url = gdyb_url
  259. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  260. request, err := http.NewRequest("POST", url, reader)
  261. if err != nil {
  262. fmt.Println(err.Error())
  263. return err.Error(), ""
  264. }
  265. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  266. request.Header.Set("code", "Xmrjyy")
  267. client := http.Client{}
  268. resp, err := client.Do(request)
  269. if err != nil {
  270. fmt.Println(err.Error())
  271. return err.Error(), ""
  272. }
  273. respBytes, err := ioutil.ReadAll(resp.Body)
  274. if err != nil {
  275. fmt.Println(err.Error())
  276. return err.Error(), ""
  277. }
  278. fmt.Println(string(respBytes))
  279. str := string(respBytes)
  280. return str, inputLog
  281. }
  282. func UpDatePrescriptionNumberForCoordinate(user_org_id int64, ids []int64, number string) (err error) {
  283. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix(), "order_status": 6}).Error
  284. return
  285. }
  286. func GetDrugInfo(bbx01 string) (string, string) {
  287. //input := make(map[string]interface{})
  288. inputData := make(map[string]interface{})
  289. inputData["bbx01"] = bbx01 // 就诊凭证编号
  290. inputData["name"] = "" // 就诊凭证编号
  291. var inputLog string
  292. bytesData, err := json.Marshal(inputData)
  293. inputLog = string(bytesData)
  294. fmt.Println(string(bytesData))
  295. if err != nil {
  296. fmt.Println(err.Error())
  297. return err.Error(), ""
  298. }
  299. reader := bytes.NewReader(bytesData)
  300. var url string
  301. gdyb_url := "http://218.104.146.179:9091/esb/listener/getGrug"
  302. url = gdyb_url
  303. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  304. request, err := http.NewRequest("GET", url, reader)
  305. if err != nil {
  306. fmt.Println(err.Error())
  307. return err.Error(), ""
  308. }
  309. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  310. request.Header.Set("code", "Xmrjyy")
  311. client := http.Client{}
  312. resp, err := client.Do(request)
  313. if err != nil {
  314. fmt.Println(err.Error())
  315. return err.Error(), ""
  316. }
  317. respBytes, err := ioutil.ReadAll(resp.Body)
  318. if err != nil {
  319. fmt.Println(err.Error())
  320. return err.Error(), ""
  321. }
  322. fmt.Println(string(respBytes))
  323. str := string(respBytes)
  324. return str, inputLog
  325. }
  326. func GetGoodInfo(bbx01 string) (string, string) {
  327. //input := make(map[string]interface{})
  328. inputData := make(map[string]interface{})
  329. inputData["bbx01"] = bbx01 // 就诊凭证编号
  330. inputData["name"] = "" // 就诊凭证编号
  331. var inputLog string
  332. bytesData, err := json.Marshal(inputData)
  333. inputLog = string(bytesData)
  334. fmt.Println(string(bytesData))
  335. if err != nil {
  336. fmt.Println(err.Error())
  337. return err.Error(), ""
  338. }
  339. reader := bytes.NewReader(bytesData)
  340. var url string
  341. gdyb_url := "http://218.104.146.179:9091/esb/listener/getMaterial"
  342. url = gdyb_url
  343. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  344. request, err := http.NewRequest("GET", url, reader)
  345. if err != nil {
  346. fmt.Println(err.Error())
  347. return err.Error(), ""
  348. }
  349. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  350. request.Header.Set("code", "Xmrjyy")
  351. client := http.Client{}
  352. resp, err := client.Do(request)
  353. if err != nil {
  354. fmt.Println(err.Error())
  355. return err.Error(), ""
  356. }
  357. respBytes, err := ioutil.ReadAll(resp.Body)
  358. if err != nil {
  359. fmt.Println(err.Error())
  360. return err.Error(), ""
  361. }
  362. fmt.Println(string(respBytes))
  363. str := string(respBytes)
  364. return str, inputLog
  365. }
  366. func FindPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  367. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).First(&info).Error
  368. return
  369. }
  370. func FindLastPatientPrescriptionInfoTwoTen(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  371. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ?", org_id, record_date, patient_id).Order("record_date desc").First(&info).Error
  372. return
  373. }
  374. func GetUnSettleHisPrescriptionFive(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  375. err = readDb.Model(&models.HisPrescription{}).
  376. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  377. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  378. }).
  379. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  380. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  381. }).
  382. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  383. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  384. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  385. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  386. }).
  387. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 and order_status <> 5 AND p_type = ?", org_id, record_date, patient_id, p_type).
  388. Find(&prescription).Error
  389. return
  390. }
  391. func UpdataHisPateintTwoTen(his *models.VMHisPatient) {
  392. writeDb.Save(&his)
  393. }
  394. func UpDateHisPrescriptionInfoNumberTen(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  395. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  396. return
  397. }
  398. func UpdataOrderStatusThreeTen(number string, user_org_id int64) (err error) {
  399. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 5, "mtime": time.Now().Unix()}).Error
  400. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 5, "mtime": time.Now().Unix()}).Error
  401. return
  402. }
  403. func GetExecutionFrequencyByName(name string, org_id int64) (ef models.ExecutionFrequencyDic, err error) {
  404. err = readDb.Model(&models.ExecutionFrequencyDic{}).Where("(org_id = ? OR org_id = 0) AND name = ?", org_id, name).First(&ef).Error
  405. return
  406. }
  407. func GetWayInfoByName(name string, org_id int64) (ef models.HisProject, err error) {
  408. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND project_name = ? AND status= 1 AND cost_classify = 100", org_id, name).First(&ef).Error
  409. return
  410. }