manage_service.go 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package manage_service
  2. import (
  3. "KYA/models"
  4. "KYA/service"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "strings"
  8. "time"
  9. )
  10. func GetPatientInfoByIdCard(idcard string, orgid int64) (*models.Patients, error) {
  11. var patients models.Patients
  12. var err error
  13. err = service.XTReadDB().Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ? AND status = ?", idcard, orgid, 1).Find(&patients).Error
  14. if err == gorm.ErrRecordNotFound {
  15. return nil, err
  16. }
  17. if err != nil {
  18. return nil, err
  19. }
  20. return &patients, nil
  21. }
  22. func GetPatientInfoByPhone(phone string, orgid int64) (*models.Patients, error) {
  23. var patients models.Patients
  24. var err error
  25. err = service.XTReadDB().Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ? AND status = ?", phone, orgid, 1).Find(&patients).Error
  26. if err == gorm.ErrRecordNotFound {
  27. return nil, err
  28. }
  29. if err != nil {
  30. return nil, err
  31. }
  32. return &patients, nil
  33. }
  34. func AddPatients(patients *models.Patients) error {
  35. err := service.XTWriteDB().Create(&patients).Error
  36. return err
  37. }
  38. func GetLastData(orgid int64) (models.Patients, error) {
  39. patients := models.Patients{}
  40. err := service.XTReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Last(&patients).Error
  41. return patients, err
  42. }
  43. func GetPatientLastData(orgid int64) (models.Patients, error) {
  44. patients := models.Patients{}
  45. err := service.XTReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Find(&patients).Error
  46. return patients, err
  47. }
  48. func AddContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64) (err error) {
  49. utx := service.XTWriteDB()
  50. if len(contagions) > 0 {
  51. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  52. insertParams := make([]string, 0)
  53. insertData := make([]interface{}, 0)
  54. for _, contagion := range contagions {
  55. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  56. insertData = append(insertData, patienid)
  57. insertData = append(insertData, contagion)
  58. insertData = append(insertData, 1)
  59. insertData = append(insertData, createdtime)
  60. insertData = append(insertData, updatedtime)
  61. }
  62. thisSQL += strings.Join(insertParams, ",")
  63. err = utx.Exec(thisSQL, insertData...).Error
  64. fmt.Println("这个错误err", err)
  65. }
  66. utx.Commit()
  67. return
  68. }
  69. func AddPatientType(orgid int64, patientid int64, patientType []int64) (err error) {
  70. utx := service.XTWriteDB()
  71. if len(patientType) > 0 {
  72. thisSQL := "INSERT INTO xt_patients_type(user_org_id,patient_id,created_time,status,text) VALUES"
  73. insertParams := make([]string, 0)
  74. insertData := make([]interface{}, 0)
  75. for _, patientype := range patientType {
  76. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  77. insertData = append(insertData, orgid)
  78. insertData = append(insertData, patientid)
  79. insertData = append(insertData, time.Now().Unix())
  80. insertData = append(insertData, 1)
  81. insertData = append(insertData, patientype)
  82. }
  83. thisSQL += strings.Join(insertParams, ",")
  84. err = utx.Exec(thisSQL, insertData...).Error
  85. fmt.Println("这个错误err", err)
  86. }
  87. utx.Commit()
  88. return
  89. }
  90. func DeleteCouseManage(patientid int64, orgid int64) error {
  91. err := service.XTWriteDB().Model(models.PatientCourseOfDisease{}).Where("id = ? AND org_id = ?", patientid, orgid).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  92. return err
  93. }
  94. func GetRecordServe(patientid int64, orgid int64, startime int64, endtime int64) (record []*models.PatientRescueRecords, err error) {
  95. db := service.XTReadDB().Table("xt_patient_rescue_record as x").Where("x.status = 1")
  96. err = db.Group("x.id").Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.status,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(&record).Error
  97. return record, err
  98. }
  99. func GetLongDialysisData(patientid int64, orgid int64, startime int64, endtime int64) (dialysis []*models.DialysisPrescription, err error) {
  100. err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ? AND record_date >= ? AND record_date <=?", patientid, orgid, startime, endtime).Find(&dialysis).Error
  101. return dialysis, err
  102. }
  103. func GetDialysReCord(patientid int64, orgid int64, startime int64, endtime int64) (dialysisOrder []*models.DialysisOrder, err error) {
  104. err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ? AND dialysis_date >=? AND dialysis_date <= ?", patientid, orgid, startime, endtime).Find(&dialysisOrder).Error
  105. return dialysisOrder, err
  106. }
  107. func GetMissionInforMation(patientid int64, orgid int64, startime int64, endtime int64) (treatment []*models.TreatmentSummary, err error) {
  108. err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ? AND assessment_date >=? AND assessment_date <= ?", patientid, orgid, startime, endtime).Find(&treatment).Error
  109. return treatment, err
  110. }
  111. func ToSeacherCourseManagement(patientid int64, orgid int64, content string) (patient []*models.PatientCourseOfDiseases, err error) {
  112. likekey := "%" + content + "%"
  113. db := service.XTReadDB().Table("xt_patient_course_of_disease as x").Where("x.status = 1")
  114. 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.title like ?", patientid, orgid, likekey).Scan(&patient).Error
  115. return patient, err
  116. }
  117. func ToDeleteSaveRecord(id int64) error {
  118. err := service.XTWriteDB().Model(models.PatientRescueRecord{}).Where("id = ?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  119. return err
  120. }
  121. func ToSeacherRecord(patientid int64, orgid int64, content string) (record []*models.PatientRescueRecords, err error) {
  122. likekey := "%" + content + "%"
  123. db := service.XTReadDB().Table("xt_patient_rescue_record as x").Where("x.status = 1")
  124. err = db.Group("x.id").Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,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.content like ?", patientid, orgid, likekey).Scan(&record).Error
  125. return record, err
  126. }
  127. func DeletMissionInformation(id int64) error {
  128. err := service.XTWriteDB().Model(models.TreatmentSummary{}).Where("id = ?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  129. return err
  130. }
  131. func ToSeacherMissionInformation(patientid int64, orgid int64, seachval string) (treat []*models.TreatmentSummary, err error) {
  132. db := service.XTReadDB().Table("xt_treatment_summary as x")
  133. //if len(keywords) > 0 {
  134. // likeKey := "%" + keywords + "%"
  135. // db = db.Where("p.name LIKE ?", likeKey)
  136. //}
  137. if len(seachval) > 0 {
  138. likeKe := seachval + "%"
  139. db = db.Where("x.patient_id = ? AND x.user_org_id = ? AND x.mission LIKE ?", patientid, orgid, likeKe)
  140. }
  141. err = db.Find(&treat).Error
  142. return treat, err
  143. }
  144. func GetPatientSchedules(patientid int64, orgid int64, startime int64, endtime int64) (schedules []*models.PatientSchedule, err error) {
  145. err = service.XTReadDB().Table("xt_schedule as s").
  146. Preload("DeviceZone", "org_id = ? and status =1", orgid).
  147. Preload("DeviceNumber", "org_id = ? and status =1", orgid).
  148. Where("s.patient_id = ? and s.user_org_id = ? and s.schedule_date >= ? and s.schedule_date <= ? and status = 1", patientid, orgid, startime, endtime).
  149. Find(&schedules).Error
  150. return
  151. }
  152. func ToSeacherSheduleinformation(patientid int64, orgid int64, seachval string) (schedules []*models.PatientSchedule, err error) {
  153. db := service.XTReadDB().Table("xt_schedule as s")
  154. err = db.Preload("DeviceZone", "org_id = ? and status =1", orgid).
  155. Preload("DeviceNumber", "org_id = ? and status =1", orgid).
  156. Where("s.patient_id = ? and s.user_org_id = ? and s.bed_id = ?", patientid, orgid, seachval).Find(&schedules).Error
  157. return schedules, err
  158. }
  159. func DeleteScheduleinformationById(id int64) error {
  160. err := service.XTWriteDB().Model(models.Schedule{}).Where("id = ? ", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  161. return err
  162. }
  163. func GetPaitentType(patientid int64, orgid int64) (patientType []*models.PatientsType, err error) {
  164. err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ?", patientid, orgid).Find(&patientType).Error
  165. return patientType, err
  166. }