management_analyse_service.go 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package management_service
  2. import "XT_New/service"
  3. type ChartDataStruct struct {
  4. Date string `json:"date"`
  5. Value int64 `json:"value"`
  6. }
  7. //患者统计
  8. func GetPatientChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int) (datas []*ChartDataStruct, total int64, err error) {
  9. db := service.XTReadDB()
  10. switch statistics_type {
  11. case 1:
  12. err = db.Raw("select from_unixtime(lapseto_time,'%m-%d') as date, count(distinct patient_id) as value from xt_patient_lapseto lapseto JOIN `xt_patients` patient ON lapseto.`patient_id` = patient.id AND patient.user_org_id = ? Where lapseto.status = 1 AND lapseto.lapseto_type = 1 AND lapseto.lapseto_time >= ? AND lapseto.lapseto_time <= ? Group by date", user_org_id, start_time, end_time).Scan(&datas).Error
  13. break
  14. case 2:
  15. //err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, weight_after as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  16. err = db.Raw("select from_unixtime(lapseto_time,'%m-%d') as date, count(distinct patient_id) as value from xt_patient_lapseto lapseto JOIN `xt_patients` patient ON lapseto.`patient_id` = patient.id AND patient.user_org_id = ? Where lapseto.status = 1 AND lapseto.lapseto_type = 2 AND lapseto.lapseto_time >= ? AND lapseto.lapseto_time <= ? Group by date", user_org_id, start_time, end_time).Scan(&datas).Error
  17. break
  18. }
  19. for _, item := range datas {
  20. total = total + item.Value
  21. }
  22. if err != nil {
  23. return nil, 0, err
  24. }
  25. return datas, total, nil
  26. }
  27. type PatientTableStruct struct {
  28. Date string `json:"date"`
  29. Name string `json:"name"`
  30. IdCardNo string `json:"id_card_no"`
  31. Gender int `json:"gender"`
  32. }
  33. func GetPatientTableData(orgID int64, page, limit, start, end int64, statistics_type int) ([]*PatientTableStruct, int64, error) {
  34. //offset := (page - 1) * limit
  35. var total int64
  36. var err error
  37. var patients []*PatientTableStruct
  38. readDb := service.XTReadDB()
  39. db := readDb.Raw("select from_unixtime(lapseto.`lapseto_time`,'%Y-%m-%d %H:%m') as date , patient.name as name, patient.`id_card_no` as id_card_no, patient.`gender` as gender from xt_patient_lapseto lapseto JOIN `xt_patients` patient ON lapseto.`patient_id` = patient.id AND patient.user_org_id = ? Where lapseto.status = 1 AND lapseto.lapseto_type = ? AND lapseto.lapseto_time >= ? AND lapseto.lapseto_time <= ? ", orgID, statistics_type, start, end)
  40. err = db.Order("lapseto.lapseto_time desc").Scan(&patients).Error
  41. //.Offset(offset).Limit(limit)
  42. return patients, total, err
  43. }
  44. func GetLapsetoPatientTotal(orgID int64, statistics_type int) (Total int64, err error) {
  45. readDb := service.XTReadDB()
  46. err = readDb.Raw("select count(*) as total from xt_patient_lapseto lapseto JOIN `xt_patients` patient ON lapseto.`patient_id` = patient.id AND patient.user_org_id = ? Where lapseto.status = 1 AND lapseto.lapseto_type =?", orgID, statistics_type).Count(&Total).Error
  47. return Total, err
  48. }