coordinate_service.go 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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("HisOrderInfo", "status = 1").Preload("Drug", "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("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  25. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  26. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  27. }).
  28. 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).
  29. Find(&prescription).Error
  30. return
  31. }
  32. func GetUnSettleMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
  33. err = readDb.Model(&models.HisPrescription{}).
  34. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  35. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  36. }).
  37. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  38. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  39. }).
  40. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  41. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  42. }).
  43. 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).
  44. Find(&prescription).Error
  45. return
  46. }
  47. func GetHisOrderFour(patient_id string, infoSeq string, docId string) (order models.HisOrder, err error) {
  48. if len(docId) > 0 {
  49. err = readDb.Model(&models.HisOrder{}).Where("mdtrt_id = ? AND psn_no = ? AND setl_id = ? AND status = 1", infoSeq, patient_id, docId).First(&order).Error
  50. } else {
  51. err = readDb.Model(&models.HisOrder{}).Where("mdtrt_id = ? AND psn_no = ? AND status = 1 ", infoSeq, patient_id).First(&order).Error
  52. }
  53. return
  54. }
  55. func GetHisPatientForCoordinate(id_card_no string) (string, string) {
  56. //input := make(map[string]interface{})
  57. inputData := make(map[string]interface{})
  58. inputData["idcard"] = id_card_no // 就诊凭证编号
  59. var inputLog string
  60. bytesData, err := json.Marshal(inputData)
  61. inputLog = string(bytesData)
  62. fmt.Println(string(bytesData))
  63. if err != nil {
  64. fmt.Println(err.Error())
  65. return err.Error(), ""
  66. }
  67. reader := bytes.NewReader(bytesData)
  68. var url string
  69. gdyb_url := "http://218.104.146.179:9091/esb/listener/getPatientType"
  70. url = gdyb_url
  71. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  72. request, err := http.NewRequest("GET", url, reader)
  73. if err != nil {
  74. fmt.Println(err.Error())
  75. return err.Error(), ""
  76. }
  77. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  78. request.Header.Set("code", "Xmrjyy")
  79. client := http.Client{}
  80. resp, err := client.Do(request)
  81. if err != nil {
  82. fmt.Println(err.Error())
  83. return err.Error(), ""
  84. }
  85. respBytes, err := ioutil.ReadAll(resp.Body)
  86. if err != nil {
  87. fmt.Println(err.Error())
  88. return err.Error(), ""
  89. }
  90. fmt.Println(string(respBytes))
  91. str := string(respBytes)
  92. return str, inputLog
  93. }
  94. func UploadPrescriptionForCoordinate(info models.UploadInfo) (string, string) {
  95. //input := make(map[string]interface{})
  96. inputData := make(map[string]interface{})
  97. diags := make([]map[string]interface{}, 0)
  98. //diags := make([]map[string]interface{}, 0)
  99. presInfos := make([]map[string]interface{}, 0)
  100. for _, item := range info.Diag {
  101. inputDataDiag := make(map[string]interface{})
  102. inputDataDiag["vao06"] = item.Vao06
  103. inputDataDiag["bak02"] = item.Bak02
  104. diags = append(diags, inputDataDiag)
  105. }
  106. for _, item := range info.PresInfo {
  107. inputDataPresInfo := make(map[string]interface{})
  108. inputDataPresInfo["cbm06"] = item.Cbm06
  109. inputDataPresInfo["cbm07"] = item.Cbm06
  110. inputDataPresInfo["cbmid"] = item.Cbmid
  111. presDetails := make([]map[string]interface{}, 0)
  112. for _, subItem := range item.PresDetail {
  113. inputDataPresDetail := make(map[string]interface{})
  114. inputDataPresDetail["vaf59"] = subItem.Vaf59
  115. Items := make([]map[string]interface{}, 0)
  116. for _, subSubItem := range subItem.Item {
  117. inputDataItem := make(map[string]interface{})
  118. inputDataItem["bbx01"] = subSubItem.Bbx01
  119. inputDataItem["bda01"] = subSubItem.Bda01
  120. inputDataItem["bby01"] = subSubItem.Bby01
  121. inputDataItem["bck01b"] = subSubItem.Bck01b
  122. inputDataItem["bck01d"] = subSubItem.Bck01d
  123. inputDataItem["bdi01"] = subSubItem.Bdi01
  124. inputDataItem["rownr"] = subSubItem.Rownr
  125. inputDataItem["vaf11"] = subSubItem.Vaf11
  126. inputDataItem["vaf14"] = subSubItem.Vaf14
  127. inputDataItem["vaf15"] = subSubItem.Vaf15
  128. inputDataItem["vaf17"] = subSubItem.Vaf17
  129. inputDataItem["vaf18"] = subSubItem.Vaf18
  130. inputDataItem["vaf19"] = subSubItem.Vaf19
  131. inputDataItem["vaf20"] = subSubItem.Vaf20
  132. inputDataItem["vaf21"] = subSubItem.Vaf21
  133. inputDataItem["vaf22"] = subSubItem.Vaf22
  134. inputDataItem["vaf32"] = subSubItem.Vaf32
  135. inputDataItem["vaf35"] = subSubItem.Vaf35
  136. inputDataItem["vaf36"] = subSubItem.Vaf36
  137. inputDataItem["vaf58"] = subSubItem.Vaf58
  138. inputDataItem["vaf61"] = subSubItem.Vaf61
  139. Items = append(Items, inputDataItem)
  140. }
  141. inputDataPresDetail["item"] = Items
  142. presDetails = append(presDetails, inputDataPresDetail)
  143. }
  144. inputDataPresInfo["presDetail"] = presDetails
  145. presInfos = append(presInfos, inputDataPresInfo)
  146. }
  147. inputData["vaa01"] = info.Vaa01 // 就诊凭证编号
  148. inputData["Fasong"] = info.Fasong // 就诊凭证编号
  149. inputData["vaa07"] = info.Vaa07 // 就诊凭证编号
  150. inputData["bck01c"] = info.Bck01c // 就诊凭证编号
  151. inputData["bce02a"] = "1001" // 就诊凭证编号
  152. inputData["diag"] = diags // 就诊凭证编号
  153. inputData["presInfo"] = presInfos // 就诊凭证编号
  154. var inputLog string
  155. bytesData, err := json.Marshal(inputData)
  156. inputLog = string(bytesData)
  157. fmt.Println(string(bytesData))
  158. if err != nil {
  159. fmt.Println(err.Error())
  160. return err.Error(), ""
  161. }
  162. reader := bytes.NewReader(bytesData)
  163. var url string
  164. gdyb_url := "http://218.104.146.179:9091/esb/listener/sendPretreat"
  165. url = gdyb_url
  166. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  167. request, err := http.NewRequest("POST", url, reader)
  168. if err != nil {
  169. fmt.Println(err.Error())
  170. return err.Error(), ""
  171. }
  172. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  173. request.Header.Set("code", "Xmrjyy")
  174. client := http.Client{}
  175. resp, err := client.Do(request)
  176. if err != nil {
  177. fmt.Println(err.Error())
  178. return err.Error(), ""
  179. }
  180. respBytes, err := ioutil.ReadAll(resp.Body)
  181. if err != nil {
  182. fmt.Println(err.Error())
  183. return err.Error(), ""
  184. }
  185. fmt.Println(string(respBytes))
  186. str := string(respBytes)
  187. return str, inputLog
  188. }
  189. func UploadPrescriptionForCoordinateHospital(info models.UploadInfo) (string, string) {
  190. //input := make(map[string]interface{})
  191. inputData := make(map[string]interface{})
  192. diags := make([]map[string]interface{}, 0)
  193. //diags := make([]map[string]interface{}, 0)
  194. presInfos := make([]map[string]interface{}, 0)
  195. for _, item := range info.Diag {
  196. inputDataDiag := make(map[string]interface{})
  197. inputDataDiag["vao06"] = item.Vao06
  198. inputDataDiag["bak02"] = item.Bak02
  199. diags = append(diags, inputDataDiag)
  200. }
  201. for _, item := range info.PresInfo {
  202. inputDataPresInfo := make(map[string]interface{})
  203. inputDataPresInfo["cbm06"] = item.Cbm06
  204. inputDataPresInfo["cbm07"] = item.Cbm06
  205. inputDataPresInfo["cbmid"] = item.Cbmid
  206. presDetails := make([]map[string]interface{}, 0)
  207. for _, subItem := range item.PresDetail {
  208. inputDataPresDetail := make(map[string]interface{})
  209. inputDataPresDetail["vaf59"] = subItem.Vaf59
  210. Items := make([]map[string]interface{}, 0)
  211. for _, subSubItem := range subItem.Item {
  212. inputDataItem := make(map[string]interface{})
  213. inputDataItem["bbx01"] = subSubItem.Bbx01
  214. inputDataItem["bda01"] = subSubItem.Bda01
  215. inputDataItem["bby01"] = subSubItem.Bby01
  216. inputDataItem["bck01b"] = subSubItem.Bck01b
  217. inputDataItem["bck01d"] = subSubItem.Bck01d
  218. inputDataItem["bdi01"] = subSubItem.Bdi01
  219. inputDataItem["rownr"] = subSubItem.Rownr
  220. inputDataItem["vaf11"] = subSubItem.Vaf11
  221. inputDataItem["vaf14"] = subSubItem.Vaf14
  222. inputDataItem["vaf15"] = subSubItem.Vaf15
  223. inputDataItem["vaf17"] = subSubItem.Vaf17
  224. inputDataItem["vaf18"] = subSubItem.Vaf18
  225. inputDataItem["vaf19"] = subSubItem.Vaf19
  226. inputDataItem["vaf20"] = subSubItem.Vaf20
  227. inputDataItem["vaf21"] = subSubItem.Vaf21
  228. inputDataItem["vaf22"] = subSubItem.Vaf22
  229. inputDataItem["vaf32"] = subSubItem.Vaf32
  230. inputDataItem["vaf35"] = subSubItem.Vaf35
  231. inputDataItem["vaf36"] = subSubItem.Vaf36
  232. inputDataItem["vaf58"] = subSubItem.Vaf58
  233. inputDataItem["vaf61"] = subSubItem.Vaf61
  234. Items = append(Items, inputDataItem)
  235. }
  236. inputDataPresDetail["item"] = Items
  237. presDetails = append(presDetails, inputDataPresDetail)
  238. }
  239. inputDataPresInfo["presDetail"] = presDetails
  240. presInfos = append(presInfos, inputDataPresInfo)
  241. }
  242. inputData["vaa01"] = info.Vaa01 // 就诊凭证编号
  243. inputData["Fasong"] = info.Fasong // 就诊凭证编号
  244. inputData["vaa07"] = info.Vaa07 // 就诊凭证编号
  245. inputData["bck01c"] = info.Bck01c // 就诊凭证编号
  246. inputData["bce02a"] = "1001" // 就诊凭证编号
  247. inputData["diag"] = diags // 就诊凭证编号
  248. inputData["presInfo"] = presInfos // 就诊凭证编号
  249. var inputLog string
  250. bytesData, err := json.Marshal(inputData)
  251. inputLog = string(bytesData)
  252. fmt.Println(string(bytesData))
  253. if err != nil {
  254. fmt.Println(err.Error())
  255. return err.Error(), ""
  256. }
  257. reader := bytes.NewReader(bytesData)
  258. var url string
  259. gdyb_url := "http://218.104.146.179:9091/esb/listener/saveOrdInfoIp"
  260. url = gdyb_url
  261. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  262. request, err := http.NewRequest("POST", url, reader)
  263. if err != nil {
  264. fmt.Println(err.Error())
  265. return err.Error(), ""
  266. }
  267. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  268. request.Header.Set("code", "Xmrjyy")
  269. client := http.Client{}
  270. resp, err := client.Do(request)
  271. if err != nil {
  272. fmt.Println(err.Error())
  273. return err.Error(), ""
  274. }
  275. respBytes, err := ioutil.ReadAll(resp.Body)
  276. if err != nil {
  277. fmt.Println(err.Error())
  278. return err.Error(), ""
  279. }
  280. fmt.Println(string(respBytes))
  281. str := string(respBytes)
  282. return str, inputLog
  283. }
  284. func UpDatePrescriptionNumberForCoordinate(user_org_id int64, ids []int64, number string) (err error) {
  285. 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
  286. return
  287. }
  288. func FindPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  289. 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
  290. return
  291. }
  292. func FindLastPatientPrescriptionInfoTwoTen(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  293. 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
  294. return
  295. }
  296. func GetUnSettleHisPrescriptionFive(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  297. err = readDb.Model(&models.HisPrescription{}).
  298. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  299. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  300. }).
  301. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  302. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  303. }).
  304. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  305. 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")
  306. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  307. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  308. }).
  309. 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).
  310. Find(&prescription).Error
  311. return
  312. }
  313. func UpdataHisPateintTwoTen(his *models.VMHisPatient) {
  314. writeDb.Save(&his)
  315. }
  316. func UpDateHisPrescriptionInfoNumberTen(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  317. 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
  318. return
  319. }
  320. func UpdataOrderStatusThreeTen(number string, user_org_id int64) (err error) {
  321. 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
  322. 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
  323. return
  324. }
  325. func GetExecutionFrequencyByName(name string, org_id int64) (ef models.ExecutionFrequencyDic, err error) {
  326. err = readDb.Model(&models.ExecutionFrequencyDic{}).Where("org_id = ? AND name = ?", org_id, name).First(&ef).Error
  327. return
  328. }