sign_weigh_service.go 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. )
  7. func GetSignPatients(orgId int64, keywords string, dateTime, schedule_type int64) (patients []*models.SignPatients, err error) {
  8. db := readDb.
  9. Table("xt_patients as p").Where("p.user_org_id=?", orgId).
  10. Preload("SignWeight", "user_org_id = ? AND record_date=? AND status = 1", orgId, dateTime).
  11. Preload("DialysisOrder", "user_org_id = ? and dialysis_date = ? AND status = 1 ", orgId, dateTime).
  12. Preload("Schedule", "user_org_id = ? and schedule_date=? and status = 1", orgId, dateTime).
  13. Preload("PredialysisEvaluation", "user_org_id = ? and assessment_date = ?", orgId, dateTime)
  14. if len(keywords) > 0 {
  15. likekey := "%" + keywords + "%"
  16. db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ? ", likekey, likekey)
  17. }
  18. db = db.Where("p.status=1")
  19. if schedule_type >= 1 && schedule_type <= 3 {
  20. db = db.Joins("JOIN xt_schedule AS s ON s.patient_id=p.id").Where("s.schedule_date = ? and s.schedule_type=? and s.status=1", dateTime, schedule_type)
  21. }
  22. err = db.Select("p.id, p.user_org_id, p.user_id, p.avatar, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.predialysis_condition, p.pre_hospital_dialysis_frequency, p.pre_hospital_dialysis_times, p.hospital_first_dialysis_date, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time").Find(&patients).Error
  23. return
  24. }
  25. //GetSignPanels 签到称重班次休息
  26. func GetSignPanels(orgid, dateTime int64) (map[int64]map[string]int64, error) {
  27. fmt.Println(dateTime)
  28. fmt.Println("世界的尽头")
  29. fmt.Println(orgid)
  30. panel := map[int64]map[string]int64{
  31. 1: {"schedule": 0, "sign": 0, "before": 0, "after": 0},
  32. 2: {"schedule": 0, "sign": 0, "before": 0, "after": 0},
  33. 3: {"schedule": 0, "sign": 0, "before": 0, "after": 0},
  34. }
  35. var err error
  36. type schedule struct {
  37. ScheduleType int64
  38. ScheduleNums int64
  39. }
  40. var schedulePanels []schedule
  41. err = readDb.Model(&models.Schedule{}).Select("schedule_type, count(schedule_type) as schedule_nums").Where("schedule_date=? and user_org_id=? and status=?", dateTime, orgid, 1).Group("schedule_type").Scan(&schedulePanels).Error
  42. if err != nil {
  43. return panel, err
  44. fmt.Println("panel是什么", panel)
  45. }
  46. for _, schedulePanel := range schedulePanels {
  47. if _, exist := panel[schedulePanel.ScheduleType]; exist {
  48. panel[schedulePanel.ScheduleType]["schedule"] = schedulePanel.ScheduleNums
  49. }
  50. }
  51. type sign struct {
  52. ScheduleType int64
  53. SignNums int64
  54. }
  55. var signPanels []sign
  56. err = readDb.Table("xt_assessment_before_dislysis as sw").Joins("JOIN xt_schedule as s ON s.patient_id = sw.patient_id").Select("count(sw.id) as sign_nums,s.schedule_type").Where("s.schedule_date = ? and sw.assessment_date = ? and s.user_org_id = ? and sw.status = 1 and s.status = 1", dateTime, dateTime, orgid).Group("s.schedule_type").Scan(&signPanels).Error
  57. if err != nil {
  58. return panel, err
  59. }
  60. fmt.Println("singpanels是什么东西", signPanels)
  61. for _, signPanel := range signPanels {
  62. if _, exist := panel[signPanel.ScheduleType]; exist {
  63. panel[signPanel.ScheduleType]["sign"] = signPanel.SignNums
  64. }
  65. }
  66. type befor struct {
  67. ScheduleType int64
  68. SignNums int64
  69. }
  70. var befors []befor
  71. err = readDb.Table("xt_assessment_before_dislysis as sw").Joins("JOIN xt_schedule as s ON s.patient_id = sw.patient_id").Select("count(sw.id) as sign_nums,s.schedule_type").Where("s.schedule_date = ? and sw.assessment_date = ? and s.user_org_id = ? and sw.status = 1 and s.status = 1", dateTime, dateTime, orgid).Group("s.schedule_type").Scan(&befors).Error
  72. if err != nil {
  73. return panel, err
  74. }
  75. fmt.Println("singpanels是什么东西", befors)
  76. for _, signPanel := range befors {
  77. if _, exist := panel[signPanel.ScheduleType]; exist {
  78. panel[signPanel.ScheduleType]["before"] = signPanel.SignNums
  79. }
  80. }
  81. type after struct {
  82. ScheduleType int64
  83. AfterNums int64
  84. }
  85. var afters []after
  86. err = readDb.Table("xt_assessment_after_dislysis as sw").Joins("JOIN xt_schedule as s ON s.patient_id = sw.patient_id").Select("count(sw.id) as after_nums,s.schedule_type").Where("s.schedule_date = ? and sw.assessment_date = ? and s.user_org_id = ? and sw.status = 1 and s.status = 1", dateTime, dateTime, orgid).Group("s.schedule_type").Scan(&afters).Error
  87. if err != nil {
  88. return panel, err
  89. }
  90. fmt.Println("after是什么东西", afters)
  91. for _, signPanel := range afters {
  92. if _, exist := panel[signPanel.ScheduleType]; exist {
  93. panel[signPanel.ScheduleType]["after"] = signPanel.AfterNums
  94. }
  95. }
  96. return panel, nil
  97. }
  98. func GetPatientDateSign(orgid, dateTime, patientId int64) (*models.SigninAndWeigh, error) {
  99. var sig models.SigninAndWeigh
  100. var err error
  101. err = readDb.Model(&models.SigninAndWeigh{}).Where("record_date = ? and patient_id=? and user_org_id=?", dateTime, patientId, orgid).First(&sig).Error
  102. fmt.Println("错误", err)
  103. if err == gorm.ErrRecordNotFound {
  104. return nil, nil
  105. }
  106. if err != nil {
  107. return nil, err
  108. }
  109. return &sig, nil
  110. }
  111. func EditPatientSign(m *models.SigninAndWeigh) error {
  112. var err error
  113. if m.ID > 0 {
  114. err = writeDb.Save(&m).Error
  115. } else {
  116. err = writeDb.Create(&m).Error
  117. }
  118. return err
  119. }
  120. func GetPatientInformationList(orgid, patientId int64, datetime int64) *models.PredialysisEvaluation {
  121. var pre models.PredialysisEvaluation
  122. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id=? and user_org_id=? and assessment_date =?", patientId, orgid, datetime).First(&pre).Error
  123. if err != nil {
  124. }
  125. return &pre
  126. }
  127. func GetInforByPatient(orgid, patientId int64, datetime int64) *models.AssessmentAfterDislysis {
  128. var ass models.AssessmentAfterDislysis
  129. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id=? and user_org_id=? and assessment_date=?", patientId, orgid, datetime).First(&ass).Error
  130. if err != nil {
  131. }
  132. return &ass
  133. }
  134. func SaveData(pre *models.PredialysisEvaluation, patientId int64, orgId int64) error {
  135. err := writeDb.Model(pre).Where("patient_id=? and user_org_id=?", patientId, orgId).Update(map[string]interface{}{"weight_before": pre.WeightBefore,
  136. "dry_weight": pre.DryWeight, "temperature": pre.Temperature, "pulse_frequency": pre.PulseFrequency, "breathing_rate": pre.BreathingRate, "systolic_blood_pressure": pre.SystolicBloodPressure, "diastolic_blood_pressure": pre.DiastolicBloodPressure}).Error
  137. return err
  138. }
  139. func Editdata(dis *models.AssessmentAfterDislysis, patientId int64, orgId int64) error {
  140. err := writeDb.Model(dis).Where("patient_id=? and user_org_id=?", patientId, orgId).Update(map[string]interface{}{"weight_after": dis.WeightAfter,
  141. "dry_weight": dis.DryWeight, "temperature": dis.Temperature, "pulse_frequency": dis.PulseFrequency, "breathing_rate": dis.BreathingRate, "systolic_blood_pressure": dis.SystolicBloodPressure, "diastolic_blood_pressure": dis.DiastolicBloodPressure}).Error
  142. return err
  143. }
  144. func Savesignweigh(sw *models.SignWeight) error {
  145. var err error
  146. err = writeDb.Create(&sw).Error
  147. return err
  148. }
  149. func Updatesignweigh(sw *models.SignWeight, patientId int64, orgId int64) error {
  150. writeDb.Model(sw).Where("patient_id=? and user_org_id=?", patientId, orgId).Update(map[string]interface{}{"sign_time": sw.SignTime,
  151. "record_date": sw.RecordDate, "weightbefore": sw.WeightBefore, "dry_weight_before": sw.DryWeightBefore, "temperature_before": sw.TemperatureBefore,
  152. "pulse_frequency_before": sw.PulseFrequencyBefore, "breathing_rate_before": sw.BreathingRateBefore, "systolic_blood_pressure_before": sw.SystolicBloodPressureBefore,
  153. "diastolic_blood_pressure_before": sw.DiastolicBloodPressureBefore, "weightafter": sw.WeightAfter, "temperature_after": sw.TemperatureAfter, "pulse_frequency_after": sw.PulseFrequencyAfter,
  154. "breathing_rate_after": sw.BreathingRateAfter, "systolic_blood_pressure_after": sw.SystolicBloodPressureAfter, "diastolic_blood_pressure_after": sw.DiastolicBloodPressureAfter,
  155. "status": sw.Status, "created_time": sw.CreatedTime, "weigh_before_time": sw.WeighBeforeTime, "weigh_time": sw.WeighTime})
  156. return err
  157. }
  158. func GetSign(orgid, dateTime, patientId int64) (*models.SignWeight, error) {
  159. var sigs models.SignWeight
  160. var err error
  161. err = readDb.Model(&models.SignWeight{}).Where("record_date = ? and patient_id=? and user_org_id = ?", dateTime, patientId, orgid).First(&sigs).Error
  162. fmt.Println("错误", err)
  163. if err == gorm.ErrRecordNotFound {
  164. return nil, err
  165. }
  166. if err != nil {
  167. return nil, err
  168. }
  169. return &sigs, nil
  170. }
  171. func GetSignweigh(orgid, patientId int64) *models.SignWeight {
  172. var sw models.SignWeight
  173. err := readDb.Model(&models.SignWeight{}).Where("patient_id=? and user_org_id =?", patientId, orgid).First(&sw).Error
  174. if err != nil {
  175. }
  176. return &sw
  177. }
  178. func GetDislysisBerfore(orgid, dateTime, patientId int64) (*models.PredialysisEvaluation, error) {
  179. var pre models.PredialysisEvaluation
  180. var err error
  181. err = readDb.Model(&models.PredialysisEvaluation{}).Where("assessment_date =? and patient_id =? and user_org_id = ?", dateTime, patientId, orgid).Find(&pre).Error
  182. fmt.Println("错误", err)
  183. if err == gorm.ErrRecordNotFound {
  184. return nil, err
  185. }
  186. if err != nil {
  187. return nil, err
  188. }
  189. return &pre, nil
  190. }
  191. func SaveDislysisiBefore(pre *models.PredialysisEvaluation) error {
  192. var err error
  193. err = writeDb.Create(&pre).Error
  194. return err
  195. }
  196. func UpdataDislysisiBefore(pre *models.PredialysisEvaluation, patientId int64, orgId int64, datatime int64) error {
  197. writeDb.Model(pre).Where("patient_id=? and user_org_id=? and assessment_date =?", patientId, orgId, datatime).Update(map[string]interface{}{"weight_before": pre.WeightBefore,
  198. "dry_weight": pre.DryWeight, "temperature": pre.Temperature, "pulse_frequency": pre.PulseFrequency, "systolic_blood_pressure": pre.SystolicBloodPressure, "diastolic_blood_pressure": pre.DiastolicBloodPressure, "status": 1})
  199. return err
  200. }
  201. func GetAssessmentaafterdislysis(orgid, dateTime, patientId int64) (*models.AssessmentAfterDislysis, error) {
  202. var ass models.AssessmentAfterDislysis
  203. var err error
  204. err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("assessment_date =? and patient_id =? and user_org_id = ?", dateTime, patientId, orgid).Find(&ass).Error
  205. fmt.Println("错误", err)
  206. if err == gorm.ErrRecordNotFound {
  207. return nil, err
  208. }
  209. if err != nil {
  210. return nil, err
  211. }
  212. return &ass, nil
  213. }
  214. func SaveAssessmentafter(ass *models.AssessmentAfterDislysis) error {
  215. var err error
  216. err = writeDb.Create(&ass).Error
  217. return err
  218. }
  219. func UpdataAssessment(ass *models.AssessmentAfterDislysis, patientId int64, orgId int64, datetime int64) error {
  220. writeDb.Model(ass).Where("patient_id=? and user_org_id=? and assessment_date=? ", patientId, orgId, datetime).Update(map[string]interface{}{"weight_after": ass.WeightAfter,
  221. "dry_weight": ass.DryWeight, "temperature": ass.Temperature, "pulse_frequency": ass.PulseFrequency, "systolic_blood_pressure": ass.SystolicBloodPressure, "diastolic_blood_pressure": ass.DiastolicBloodPressure, "status": 1})
  222. return err
  223. }
  224. func GetForenoonData(dataTime int64, orgid int64, scheduleType int64) (total int64, schedule []*models.Schedule, err error) {
  225. err = readDb.Count(total).Where("schedule_date = ? AND user_org_id = ? AND schedule_type = ?", dataTime, orgid, scheduleType).Find(&scheduleType).Error
  226. fmt.Println("heeeeeeeeeehhhhh", err)
  227. return total, schedule, err
  228. }