zuobiao_service.go 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. )
  6. func GetNewAllUnHisZuoBiaoPatientList(org_id int64, record_date int64) (patients []*NewTempPatients, err error) {
  7. db := readDb.Model(&NewTempPatients{})
  8. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  9. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date <= ? AND order_status <> 2 AND order_status <> 3 AND order_status <> 5", org_id, record_date)
  10. err = db.Find(&patients).Error
  11. return
  12. }
  13. func GetNewAllChargeHisZuoBiaoPatientList(org_id int64, record_date int64) (patients []*NewTempPatients, err error) {
  14. db := readDb.Model(&NewTempPatients{})
  15. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  16. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND order_status = 5", org_id, record_date)
  17. err = db.Find(&patients).Error
  18. return
  19. }
  20. func GetUploadHisZuoBiaoPatientList(org_id int64, record_date int64) (patients []*models.HisZuobiaoAdvice, err error) {
  21. db := readDb.Model(&models.HisZuobiaoAdvice{})
  22. db = db.Where("status = 1 and record_date = ? and user_org_id = ?", record_date, org_id)
  23. db = db.Preload("Patient", "status = 1")
  24. err = db.Find(&patients).Error
  25. return
  26. }
  27. func GetUnUploadHisZuoBiaoPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  28. err = readDb.Model(&models.HisPrescription{}).
  29. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  30. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  31. }).
  32. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  33. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  34. }).
  35. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  36. 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")
  37. }).
  38. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND order_status<> 4 AND order_status<> 5", org_id, record_date, patient_id).
  39. Find(&prescription).Error
  40. return
  41. }
  42. func GetUploadHisZuoBiaoPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  43. err = readDb.Model(&models.HisPrescription{}).
  44. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  45. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  46. }).
  47. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  48. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  49. }).
  50. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  51. 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")
  52. }).
  53. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 5 ", org_id, record_date, patient_id).
  54. Find(&prescription).Error
  55. return
  56. }
  57. func GetMonthUnUploadHisZuoBiaoPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  58. err = readDb.Model(&models.HisPrescription{}).
  59. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  60. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  61. }).
  62. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  63. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  64. }).
  65. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  66. 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")
  67. }).
  68. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date <= ? AND record_date >= ? AND order_status <> 2 AND order_status <> 3 AND order_status<> 4 AND order_status<> 5 ", org_id, patient_id, end_time, start_time).
  69. Find(&prescription).Error
  70. return
  71. }
  72. func GetMonthUploadHisZuoBiaoPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  73. err = readDb.Model(&models.HisPrescription{}).
  74. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  75. return db.Where("status = 1 AND user_org_id = ? ", org_id).Preload("XtHisAddtionConfig", "status=1")
  76. }).
  77. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  78. return db.Where("status = 1 AND user_org_id = ? and is_self_drug <> 1 ", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  79. }).
  80. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  81. 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")
  82. }).
  83. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date <= ? AND record_date >= ? AND order_status = 5", org_id, patient_id, end_time, start_time).
  84. Find(&prescription).Error
  85. return
  86. }
  87. func GetAllMonthHisZuoBiaoPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  88. err = readDb.Model(&models.HisPrescription{}).
  89. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  90. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  91. }).
  92. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  93. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  94. }).
  95. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  96. 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")
  97. }).
  98. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date <= ? AND record_date >= ? ", org_id, patient_id, end_time, start_time).
  99. Find(&prescription).Error
  100. return
  101. }
  102. func GetZuobiaoInfoById(id int64) (err error, zuobiao models.HisZuobiaoAdvice) {
  103. err = readDb.Model(&models.HisZuobiaoAdvice{}).Where("id = ? and status = 1", id).First(&zuobiao).Error
  104. return
  105. }
  106. func GetZuoBiaoPrescriptionInfo(user_org_id int64, patient_id int64) (models.HisPrescriptionInfo, error) {
  107. info := models.HisPrescriptionInfo{}
  108. err := XTReadDB().Where("user_org_id = ? and patient_id =? and status=1", user_org_id, patient_id).Last(&info).Error
  109. return info, err
  110. }