sign_weigh_service.go 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 ? OR first_letter LIKE ?", likekey, 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 GetPatientLastDryWeight(patient_id int64, org_id int64) (models.SgjPatientDryweight, error) {
  128. dryweight := models.SgjPatientDryweight{}
  129. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status =1", patient_id, org_id).Last(&dryweight).Error
  130. return dryweight, err
  131. }
  132. func GetInforByPatient(orgid, patientId int64, datetime int64) *models.AssessmentAfterDislysis {
  133. var ass models.AssessmentAfterDislysis
  134. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id=? and user_org_id=? and assessment_date=?", patientId, orgid, datetime).First(&ass).Error
  135. if err != nil {
  136. }
  137. return &ass
  138. }
  139. func SaveData(pre *models.PredialysisEvaluation, patientId int64, orgId int64) error {
  140. err := writeDb.Model(pre).Where("patient_id=? and user_org_id=?", patientId, orgId).Update(map[string]interface{}{"weight_before": pre.WeightBefore,
  141. "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
  142. return err
  143. }
  144. func Editdata(dis *models.AssessmentAfterDislysis, patientId int64, orgId int64) error {
  145. err := writeDb.Model(dis).Where("patient_id=? and user_org_id=?", patientId, orgId).Update(map[string]interface{}{"weight_after": dis.WeightAfter,
  146. "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
  147. return err
  148. }
  149. func Savesignweigh(sw *models.SignWeight) error {
  150. var err error
  151. err = writeDb.Create(&sw).Error
  152. return err
  153. }
  154. func Updatesignweigh(sw *models.SignWeight, patientId int64, orgId int64) error {
  155. writeDb.Model(sw).Where("patient_id=? and user_org_id=?", patientId, orgId).Update(map[string]interface{}{"sign_time": sw.SignTime,
  156. "record_date": sw.RecordDate, "weightbefore": sw.WeightBefore, "dry_weight_before": sw.DryWeightBefore, "temperature_before": sw.TemperatureBefore,
  157. "pulse_frequency_before": sw.PulseFrequencyBefore, "breathing_rate_before": sw.BreathingRateBefore, "systolic_blood_pressure_before": sw.SystolicBloodPressureBefore,
  158. "diastolic_blood_pressure_before": sw.DiastolicBloodPressureBefore, "weightafter": sw.WeightAfter, "temperature_after": sw.TemperatureAfter, "pulse_frequency_after": sw.PulseFrequencyAfter,
  159. "breathing_rate_after": sw.BreathingRateAfter, "systolic_blood_pressure_after": sw.SystolicBloodPressureAfter, "diastolic_blood_pressure_after": sw.DiastolicBloodPressureAfter,
  160. "status": sw.Status, "created_time": sw.CreatedTime, "weigh_before_time": sw.WeighBeforeTime, "weigh_time": sw.WeighTime})
  161. return err
  162. }
  163. func GetSign(orgid, dateTime, patientId int64) (*models.SignWeight, error) {
  164. var sigs models.SignWeight
  165. var err error
  166. err = readDb.Model(&models.SignWeight{}).Where("record_date = ? and patient_id=? and user_org_id = ?", dateTime, patientId, orgid).First(&sigs).Error
  167. fmt.Println("错误", err)
  168. if err == gorm.ErrRecordNotFound {
  169. return nil, err
  170. }
  171. if err != nil {
  172. return nil, err
  173. }
  174. return &sigs, nil
  175. }
  176. func GetSignweigh(orgid, patientId int64) *models.SignWeight {
  177. var sw models.SignWeight
  178. err := readDb.Model(&models.SignWeight{}).Where("patient_id=? and user_org_id =?", patientId, orgid).First(&sw).Error
  179. if err != nil {
  180. }
  181. return &sw
  182. }
  183. func GetDislysisBerfore(orgid, dateTime, patientId int64) (*models.PredialysisEvaluation, error) {
  184. var pre models.PredialysisEvaluation
  185. var err error
  186. err = readDb.Model(&models.PredialysisEvaluation{}).Where("assessment_date =? and patient_id =? and user_org_id = ?", dateTime, patientId, orgid).Find(&pre).Error
  187. fmt.Println("错误", err)
  188. if err == gorm.ErrRecordNotFound {
  189. return nil, err
  190. }
  191. if err != nil {
  192. return nil, err
  193. }
  194. return &pre, nil
  195. }
  196. func SaveDislysisiBefore(pre *models.PredialysisEvaluation) error {
  197. var err error
  198. err = writeDb.Create(&pre).Error
  199. return err
  200. }
  201. func UpdataDislysisiBefore(pre *models.PredialysisEvaluation, patientId int64, orgId int64, datatime int64) error {
  202. writeDb.Model(pre).Where("patient_id=? and user_org_id=? and assessment_date =?", patientId, orgId, datatime).Update(map[string]interface{}{"weight_before": pre.WeightBefore,
  203. "dry_weight": pre.DryWeight, "temperature": pre.Temperature, "pulse_frequency": pre.PulseFrequency, "systolic_blood_pressure": pre.SystolicBloodPressure, "diastolic_blood_pressure": pre.DiastolicBloodPressure, "status": 1})
  204. return err
  205. }
  206. func GetAssessmentaafterdislysis(orgid, dateTime, patientId int64) (*models.AssessmentAfterDislysis, error) {
  207. var ass models.AssessmentAfterDislysis
  208. var err error
  209. err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("assessment_date =? and patient_id =? and user_org_id = ?", dateTime, patientId, orgid).Find(&ass).Error
  210. fmt.Println("错误", err)
  211. if err == gorm.ErrRecordNotFound {
  212. return nil, err
  213. }
  214. if err != nil {
  215. return nil, err
  216. }
  217. return &ass, nil
  218. }
  219. func SaveAssessmentafter(ass *models.AssessmentAfterDislysis) error {
  220. var err error
  221. err = writeDb.Create(&ass).Error
  222. return err
  223. }
  224. func UpdataAssessment(ass *models.AssessmentAfterDislysis, patientId int64, orgId int64, datetime int64) error {
  225. writeDb.Model(ass).Where("patient_id=? and user_org_id=? and assessment_date=? ", patientId, orgId, datetime).Update(map[string]interface{}{"weight_after": ass.WeightAfter,
  226. "dry_weight": ass.DryWeight, "temperature": ass.Temperature, "pulse_frequency": ass.PulseFrequency, "systolic_blood_pressure": ass.SystolicBloodPressure, "diastolic_blood_pressure": ass.DiastolicBloodPressure, "status": 1})
  227. return err
  228. }
  229. func GetForenoonData(dataTime int64, orgid int64, scheduleType int64) (total int64, schedule []*models.Schedule, err error) {
  230. err = readDb.Count(total).Where("schedule_date = ? AND user_org_id = ? AND schedule_type = ?", dataTime, orgid, scheduleType).Find(&scheduleType).Error
  231. fmt.Println("heeeeeeeeeehhhhh", err)
  232. return total, schedule, err
  233. }