patient_service.go 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package patient_service
  2. import (
  3. "Kya_New/models"
  4. "Kya_New/service"
  5. "fmt"
  6. "strconv"
  7. "strings"
  8. )
  9. func GetCreatorId(phone string) (models.SgjUserAdmin, error) {
  10. admin := models.SgjUserAdmin{}
  11. err := service.UserReadDB().Where("mobile = ? AND status = ?", phone, 1).Find(&admin).Error
  12. return admin, err
  13. }
  14. func GetOrgId(id int64) (models.SgjUserOrg, error) {
  15. org := models.SgjUserOrg{}
  16. err := service.UserReadDB().Where("creator = ? AND status = ?", id, 1).Find(&org).Error
  17. return org, err
  18. }
  19. func GetneratedDialysisNo(orgID int64) (dialysisNo int64) {
  20. fmt.Println("orgid", orgID)
  21. var patient models.Patients
  22. err := service.XTReadDB().Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", orgID).Order("dialysis_no desc").First(&patient).Error
  23. fmt.Println("自动生成透析号错误", err)
  24. if err != nil {
  25. return
  26. }
  27. if patient.ID == 0 {
  28. return
  29. }
  30. dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
  31. return
  32. }
  33. func AddPatients(patients *models.Patients) error {
  34. err := service.XTWriteDB().Create(&patients).Error
  35. return err
  36. }
  37. func GetPatientsLastData(orgid int64) (models.Patients, error) {
  38. patients := models.Patients{}
  39. err := service.XTReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Find(&patients).Error
  40. return patients, err
  41. }
  42. func AddContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64) (err error) {
  43. utx := service.XTWriteDB().Begin()
  44. //btx := service.UserWriteDB().Begin()
  45. if len(contagions) > 0 {
  46. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  47. insertParams := make([]string, 0)
  48. insertData := make([]interface{}, 0)
  49. for _, contagion := range contagions {
  50. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  51. insertData = append(insertData, patienid)
  52. insertData = append(insertData, contagion)
  53. insertData = append(insertData, 1)
  54. insertData = append(insertData, createdtime)
  55. insertData = append(insertData, updatedtime)
  56. }
  57. thisSQL += strings.Join(insertParams, ",")
  58. err = utx.Exec(thisSQL, insertData...).Error
  59. fmt.Println("这个错误err", err)
  60. }
  61. return
  62. }
  63. func GetCourseManagementData(patientid int64, orgid int64, startime int64, endtime int64) (patientCourse []*models.PatientCourseOfDiseases, err error) {
  64. db := service.XTReadDB().Table("xt_patient_course_of_disease as x").Where("x.status = 1")
  65. err = db.Group("x.id").Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.title,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Where("x.patient_id = ? and x.org_id = ? and x.record_time >=? and x.record_time <=?", patientid, orgid, startime, endtime).Scan(&patientCourse).Error
  66. return patientCourse, err
  67. }
  68. func GetCheckPatientData(patientid int64, orgid int64, stattime int64, endtime int64) (inspection []*models.Inspection, err error) {
  69. err = service.XTReadDB().Group("inspect_date").Where("patient_id = ? and org_id = ? and inspect_date >=? and inspect_date <= ? and status = 1", patientid, orgid, stattime, endtime).Find(&inspection).Error
  70. return inspection, err
  71. }
  72. func GetCheckData(time int64, patientid int64, orgid int64) (inspection []*models.Inspection, err error) {
  73. err = service.XTReadDB().Group("project_name").Where("patient_id = ? and org_id = ? and inspect_date = ?", patientid, orgid, time).Order("id asc").Find(&inspection).Error
  74. return inspection, err
  75. }
  76. func GetPatientInfectious(patientid int64) (infectious []*models.PatientsInfectiousDiseases, err error) {
  77. err = service.XTReadDB().Model(&models.PatientsInfectiousDiseases{}).Where("patient_id = ?", patientid).Find(&infectious).Error
  78. return infectious, err
  79. }