org_service.go 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. package service
  2. import (
  3. "XT_Admin_Api/models"
  4. "XT_Admin_Api/models/admin_models"
  5. "XT_Admin_Api/utils"
  6. "fmt"
  7. "github.com/jinzhu/gorm"
  8. "time"
  9. )
  10. func GetAllOrgList(active_status int64,depth_active_status int64,start_time int64,end_time int64,province int64,city int64,district int64,follow int64,keyword string,page int64, limit int64) (list []*models.Org, err error, total int64){
  11. offset := (page - 1) * limit
  12. fmt.Println(offset)
  13. db := readUserDb.Model(&models.Org{})
  14. if len(keyword) > 0{
  15. likeKey := "%" + keyword + "%"
  16. db = db.Where("contact_name LIKE ? Or org_name LIKE ? Or org_short_name Like ? ",likeKey,likeKey,likeKey)
  17. }else{
  18. switch active_status {
  19. case 1:
  20. now := time.Now()
  21. zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
  22. db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND sgj_user_admin_login_log.ctime >= ? AND sgj_user_admin_login_log.ctime <= ? AND sgj_user_admin_login_log.app_type = 3",zeroHourTimeOfToday.Unix(),now.Unix())
  23. break
  24. case 2:
  25. db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  26. break
  27. case 3:
  28. db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  29. break
  30. case 4:
  31. db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 Year) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  32. break
  33. }
  34. switch depth_active_status {
  35. case 1:
  36. now := time.Now()
  37. zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
  38. db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND sgj_user_admin_login_log.ctime >= ? AND sgj_user_admin_login_log.ctime <= ? AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ",zeroHourTimeOfToday.Unix(),now.Unix())
  39. db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  40. break
  41. case 2:
  42. db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  43. db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  44. break
  45. case 3:
  46. db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  47. db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  48. break
  49. case 4:
  50. db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 Year) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  51. db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
  52. break
  53. }
  54. if province > 0{
  55. db = db.Where("sgj_user_org.province = ?",province)
  56. }
  57. if city > 0{
  58. db = db.Where("sgj_user_org.city = ?",city)
  59. }
  60. if district > 0{
  61. db = db.Where("sgj_user_org.district = ?",district)
  62. }
  63. if start_time != 0 {
  64. db = db.Where("sgj_user_org.ctime>=?", start_time)
  65. }
  66. if end_time != 0 {
  67. db = db.Where("sgj_user_org.ctime<=?", end_time)
  68. }
  69. }
  70. err = db.Where("sgj_user_org.status = 1").Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
  71. return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
  72. }).Count(&total).Offset(offset).Limit(limit).Group("id").Find(&list).Error
  73. return
  74. }
  75. func GetOrgDetailInfo(org_id int64) (info models.Org, err error){
  76. err = readUserDb.Model(&models.Org{}).Where("id = ? AND status = 1",org_id).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
  77. return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
  78. }).Preload("AdminUser","status = 1").Find(&info).Error
  79. return
  80. }
  81. func GetDistrictsById(id int64)(district models.District, err error){
  82. err = readUserDb.Model(&models.District{}).Where("id = ? ", id).First(&district).Error
  83. return
  84. }
  85. func GetAllOrgType()(types []*models.OrgType, err error){
  86. err = readUserDb.Model(&models.OrgType{}).Find(&types).Error
  87. return
  88. }
  89. //设置今天和昨天的数据
  90. func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64) (count int64, err error){
  91. var counts int64
  92. switch statices_type {
  93. case 1: //病人管理
  94. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_patients WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1",org_id ,from, to).Rows()
  95. if err != nil {
  96. return 0, err
  97. }
  98. if rows.Next() {
  99. rows.Scan(&counts)
  100. }
  101. break
  102. case 2: //透析处方
  103. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_dialysis_prescription WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1",org_id ,from, to).Rows()
  104. if err != nil {
  105. return 0, err
  106. }
  107. if rows.Next() {
  108. rows.Scan(&counts)
  109. }
  110. break
  111. case 3: //接诊评估
  112. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_receive_treatment_asses WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1",org_id ,from, to).Rows()
  113. if err != nil {
  114. return 0, err
  115. }
  116. if rows.Next() {
  117. rows.Scan(&counts)
  118. }
  119. break
  120. case 4: //透前评估
  121. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_assessment_before_dislysis WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1",org_id ,from, to).Rows()
  122. if err != nil {
  123. return 0, err
  124. }
  125. if rows.Next() {
  126. rows.Scan(&counts)
  127. }
  128. break
  129. case 5://临时医嘱
  130. rows, err := readDb.Raw("SELECT COUNT(DISTINCT patient_id) AS count FROM xt_doctor_advice WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1",org_id ,from, to).Rows()
  131. if err != nil {
  132. return 0, err
  133. }
  134. if rows.Next() {
  135. rows.Scan(&counts)
  136. }
  137. break
  138. case 6: //双人核对
  139. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_double_check WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1",org_id ,from, to).Rows()
  140. if err != nil {
  141. return 0, err
  142. }
  143. if rows.Next() {
  144. rows.Scan(&counts)
  145. }
  146. break
  147. case 7: //透析上机
  148. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_dialysis_order WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1 AND (stage = 2 OR stage = 1)",org_id ,from, to).Rows()
  149. if err != nil {
  150. return 0, err
  151. }
  152. if rows.Next() {
  153. rows.Scan(&counts)
  154. }
  155. break
  156. case 8: //透析监测
  157. rows, err := readDb.Raw("SELECT COUNT(DISTINCT patient_id) AS count FROM xt_monitoring_record WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1",org_id ,from, to).Rows()
  158. if err != nil {
  159. return 0, err
  160. }
  161. if rows.Next() {
  162. rows.Scan(&counts)
  163. }
  164. break
  165. case 9: //透析下机
  166. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_dialysis_order WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND stage = 2 AND status = 1",org_id ,from, to).Rows()
  167. if err != nil {
  168. return 0, err
  169. }
  170. if rows.Next() {
  171. rows.Scan(&counts)
  172. }
  173. break
  174. case 10: //透后评估
  175. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_assessment_after_dislysis WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1",org_id ,from, to).Rows()
  176. if err != nil {
  177. return 0, err
  178. }
  179. if rows.Next() {
  180. rows.Scan(&counts)
  181. }
  182. break
  183. case 11: //入库单
  184. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_warehouse WHERE org_id = ? AND ctime >= ? AND mtime <= ? AND status = 1",org_id ,from, to).Rows()
  185. if err != nil {
  186. return 0, err
  187. }
  188. if rows.Next() {
  189. rows.Scan(&counts)
  190. }
  191. break
  192. case 12: //出库单
  193. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_warehouse_out WHERE org_id = ? AND ctime >= ? AND mtime <= ? AND status = 1",org_id ,from, to).Rows()
  194. if err != nil {
  195. return 0, err
  196. }
  197. if rows.Next() {
  198. rows.Scan(&counts)
  199. }
  200. break
  201. }
  202. return counts, nil
  203. }
  204. //获取近七天的数据
  205. func GetWeekOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
  206. fmt.Println(statices_type)
  207. switch statices_type {
  208. case 1: //病人管理
  209. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
  210. break
  211. case 2: //透析处方
  212. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  213. break
  214. case 3: //接诊评估
  215. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  216. break
  217. case 4: //透前评估
  218. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  219. break
  220. case 5://临时医嘱
  221. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_doctor_advice where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  222. break
  223. case 6: //双人核对
  224. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  225. break
  226. case 7: //透析上机
  227. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times",org_id).Scan(&weekStatistics).Error
  228. break
  229. case 8: //透析监测
  230. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  231. break
  232. case 9: //透析下机
  233. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  234. break
  235. case 10: //透后评估
  236. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  237. break
  238. case 11: //入库单
  239. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  240. break
  241. case 12: //出库单
  242. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  243. break
  244. }
  245. return
  246. }
  247. func GetMonthOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
  248. switch statices_type {
  249. case 1: //病人管理
  250. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
  251. break
  252. case 2: //透析处方
  253. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  254. break
  255. case 3: //接诊评估
  256. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  257. break
  258. case 4: //透前评估
  259. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  260. break
  261. case 5://临时医嘱
  262. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_doctor_advice where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  263. break
  264. case 6: //双人核对
  265. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  266. break
  267. case 7: //透析下机
  268. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times",org_id).Scan(&weekStatistics).Error
  269. break
  270. case 8: //透析监测
  271. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  272. break
  273. case 9: //透析下机
  274. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  275. break
  276. case 10: //透后评估
  277. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  278. break
  279. case 11: //入库单
  280. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  281. break
  282. case 12: //出库单
  283. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  284. break
  285. }
  286. return
  287. }
  288. func GetThreeMonthOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
  289. switch statices_type {
  290. case 1: //病人管理
  291. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
  292. break
  293. case 2: //透析处方
  294. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  295. break
  296. case 3: //接诊评估
  297. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  298. break
  299. case 4: //透前评估
  300. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  301. break
  302. case 5://临时医嘱
  303. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_doctor_advice where DATE_SUB(CURDATE(),INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  304. break
  305. case 6: //双人核对
  306. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  307. break
  308. case 7: //透析上机
  309. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times",org_id).Scan(&weekStatistics).Error
  310. break
  311. case 8: //透析监测
  312. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
  313. break
  314. case 9: //透析下机
  315. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  316. break
  317. case 10: //透后评估
  318. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(),INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  319. break
  320. case 11: //入库单
  321. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
  322. break
  323. case 12: //出库单
  324. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  325. break
  326. }
  327. return
  328. }
  329. func GetSixMonthOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
  330. switch statices_type {
  331. case 1: //病人管理
  332. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
  333. break
  334. case 2: //透析处方
  335. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  336. break
  337. case 3: //接诊评估
  338. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  339. break
  340. case 4: //透前评估
  341. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  342. break
  343. case 5://临时医嘱
  344. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_doctor_advice where DATE_SUB(CURDATE(),INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  345. break
  346. case 6: //双人核对
  347. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  348. break
  349. case 7: //透析上机
  350. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times",org_id).Scan(&weekStatistics).Error
  351. break
  352. case 8: //透析监测
  353. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
  354. break
  355. case 9: //透析下机
  356. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  357. break
  358. case 10: //透后评估
  359. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(),INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  360. break
  361. case 11: //入库单
  362. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
  363. break
  364. case 12: //出库单
  365. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  366. break
  367. }
  368. return
  369. }
  370. func GetYearOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
  371. switch statices_type {
  372. case 1: //病人管理
  373. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
  374. break
  375. case 2: //透析处方
  376. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  377. break
  378. case 3: //接诊评估
  379. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  380. break
  381. case 4: //透前评估
  382. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  383. break
  384. case 5://临时医嘱
  385. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_doctor_advice where DATE_SUB(CURDATE(),INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  386. break
  387. case 6: //双人核对
  388. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  389. break
  390. case 7: //透析上机
  391. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times",org_id).Scan(&weekStatistics).Error
  392. break
  393. case 8: //透析监测
  394. err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
  395. break
  396. case 9: //透析下机
  397. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  398. break
  399. case 10: //透后评估
  400. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(),INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  401. break
  402. case 11: //入库单
  403. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
  404. break
  405. case 12: //出库单
  406. err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
  407. break
  408. }
  409. return
  410. }
  411. func GetDistrictsByUpid(id int64) (dis []*models.District, err error) {
  412. err = readUserDb.Model(&models.District{}).Where("upid=?", id).Find(&dis).Error
  413. return
  414. }