management_analyse_service.go 4.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package management_service
  2. import "Xcx_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(created_time,'%m-%d') as date, count(distinct id) as value from xt_patients patient Where patient.user_org_id = ? AND patient.created_time >=? AND patient.created_time <=? AND patient.status = 1 AND patient.lapseto = 1 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. //err = db.Raw("select from_unixtime(updated_time,'%m-%d') as date, count(distinct id) as value from xt_patients patient Where patient.user_org_id = ? AND patient.updated_time >=? AND patient.updated_time <=? AND patient.status = 1 AND patient.lapseto = 2 Group by date", user_org_id, start_time, end_time).Scan(&datas).Error
  18. break
  19. }
  20. for _, item := range datas {
  21. total = total + item.Value
  22. }
  23. if err != nil {
  24. return nil, 0, err
  25. }
  26. return datas, total, nil
  27. }
  28. type PatientTableStruct struct {
  29. Date string `json:"date"`
  30. Name string `json:"name"`
  31. IdCardNo string `json:"id_card_no"`
  32. Gender int `json:"gender"`
  33. }
  34. func GetPatientTableData(orgID int64, page, limit, start, end int64, statistics_type int) ([]*PatientTableStruct, int64, error) {
  35. //offset := (page - 1) * limit
  36. var total int64
  37. var err error
  38. var patients []*PatientTableStruct
  39. readDb := service.XTReadDB()
  40. if statistics_type == 1 {
  41. db := readDb.Raw("select from_unixtime(patient.`created_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_patients` patient Where patient.user_org_id = ? AND patient.status = 1 AND patient.lapseto = ? AND patient.created_time >= ? AND patient.created_time <= ? ", orgID, statistics_type, start, end)
  42. err = db.Order("patient.created_time desc").Scan(&patients).Error
  43. } else {
  44. 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)
  45. //db := readDb.Raw("select from_unixtime(patient.`updated_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_patients` patient Where patient.user_org_id = ? AND patient.status = 1 AND patient.lapseto = ? AND patient.updated_time >= ? AND patient.updated_time <= ? ", orgID, statistics_type, start, end)
  46. err = db.Group("lapseto.`patient_id`").Order("lapseto.lapseto_time desc").Scan(&patients).Error
  47. }
  48. return patients, total, err
  49. }
  50. func GetLapsetoPatientTotal(orgID int64, statistics_type int) (Total int64, err error) {
  51. readDb := service.XTReadDB()
  52. //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
  53. err = readDb.Raw("select count(*) as total from `xt_patients` patient Where patient.user_org_id = ? AND patient.status = 1 AND patient.lapseto = ?", orgID, statistics_type).Count(&Total).Error
  54. return Total, err
  55. }