print_schedule_dialysis_service.go 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package schedule_dialysis
  2. import (
  3. "XT_New/models"
  4. p_service "XT_New/service"
  5. "XT_New/utils"
  6. "time"
  7. "github.com/jinzhu/gorm"
  8. )
  9. func GetSchedules(orgID int64, schIDs []string) ([]*ScheduleVM, error) {
  10. recordDateStr := time.Now().Format("2006-01-02")
  11. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  12. var schedules []*ScheduleVM
  13. db := p_service.XTReadDB()
  14. err := db.Model(&ScheduleVM{}).
  15. Preload("Patient", "user_org_id = ? AND status = 1", orgID).
  16. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  17. return db.Where("user_org_id = ? AND status = 1", orgID).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID)
  18. }).
  19. Preload("Prescription", "user_org_id = ? AND status = 1", orgID).
  20. Preload("ReceiveAssessment", "user_org_id = ? AND status = 1", orgID).
  21. Preload("XtReceiveTreatmentAsses", "user_org_id = ? AND status = 1", orgID).
  22. Preload("AssessmentBeforeDislysis", func(db *gorm.DB) *gorm.DB {
  23. return db.Where("user_org_id = ? AND status = 1", orgID)
  24. }).
  25. Preload("AssessmentAfterDislysis", "user_org_id = ? AND status = 1", orgID).
  26. Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
  27. return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, recordDate.Unix())
  28. }).Preload("MonitoringRecords", func(db *gorm.DB) *gorm.DB {
  29. return db.Where("user_org_id = ? AND status = 1", orgID).
  30. Order("operate_time asc")
  31. }).
  32. Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).
  33. Preload("DeviceZone", "org_id = ? AND status = 1", orgID).
  34. Preload("DoubleCheck", "user_org_id = ? AND status = 1", orgID).
  35. Preload("Summer", "user_org_id = ? AND status = 1", orgID).
  36. Preload("Advices", func(db *gorm.DB) *gorm.DB {
  37. return db.Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, drug_spec_unit,advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno, IF(parent_id > 0, parent_id, id) as advice_order").
  38. Where("user_org_id = ? AND advice_type = 2 AND status = 1", orgID).
  39. Order("start_time asc, groupno desc, advice_order desc, id asc")
  40. }).
  41. Where("user_org_id = ? AND status = 1 AND id in (?)", orgID, schIDs).
  42. Find(&schedules).
  43. Error
  44. if err != nil {
  45. return nil, err
  46. }
  47. return schedules, nil
  48. }
  49. func GetMedicalStaffs(orgID int64, appID int64) ([]*MedicalStaffVM, error) {
  50. var staffs []*MedicalStaffVM
  51. db := p_service.UserReadDB()
  52. // err := db.Table("sgj_user_admin_role as uar").
  53. // Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").
  54. // Joins("LEFT JOIN sgj_user_admin_electronic_signature as es ON es.creator = uar.admin_user_id and es.status = 1").
  55. // Where("uar.status = 1 and uar.org_id = ? and uar.app_id = ? and uar.user_type IN (2,3) and ua.status = 1", orgID, appID).
  56. // Where("uar.status = 1 and uar.org_id = ? and uar.app_id = ? and ua.status = 1", orgID, appID).
  57. // Select("ua.id, uar.user_name as name, uar.user_type, es.url as es_url").
  58. // Scan(&staffs).
  59. // Error
  60. err := db.Table("sgj_user_admin_electronic_signature").
  61. Where("org_id=? and app_id=? and status=1", orgID, appID).
  62. Select("creator as id, url as es_url").Scan(&staffs).Error
  63. if err != nil {
  64. return nil, err
  65. }
  66. return staffs, nil
  67. }
  68. type AdminUserList struct {
  69. Id int64 `json:"id"`
  70. Name string `json:"name"`
  71. UserType int64 `json:"user_type"`
  72. }
  73. type AdminUserListTwo struct {
  74. Id int64 `json:"id"`
  75. Name string `json:"name"`
  76. UserType int64 `json:"user_type"`
  77. Url string `json:"url"`
  78. }
  79. func GetAllAdminUsers(orgId int64, appid int64) (list []*AdminUserList, err error) {
  80. db := p_service.UserReadDB()
  81. err = db.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and uar.app_id =? and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
  82. return
  83. }
  84. func GetAllName(orgId int64, appid int64) (list []AdminUserListTwo, err error) {
  85. db := p_service.UserReadDB()
  86. err = db.Table("sgj_user_admin_role as uar").Joins("left join sgj_user_admin as ua on ua.id = uar.admin_user_id").Joins("left join sgj_user_admin_electronic_signature as e on e.creator = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and uar.app_id =? and ua.status=1 and e.status = 1 and e.org_id = ? and e.app_id = ?", orgId, appid, orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type,e.url").Scan(&list).Error
  87. return
  88. }
  89. func GetPatientCoursesRecords(orgID int64, id int64) (records models.PatientDiseaseCourse, err error) {
  90. db := p_service.XTReadDB()
  91. err = db.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and id = ? and status = 1", orgID, id).Find(&records).Error
  92. return
  93. }
  94. func FindPatientWithDeviceById(orgID int64, patient_id int64, time int64) (patient models.SchedualPatient2, err error) {
  95. db := p_service.XTReadDB()
  96. err = db.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
  97. return db.Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  98. Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  99. Where("user_org_id = ? AND schedule_date = ? ", orgID, time)
  100. }).Where("user_org_id=? and id = ? and status=1", orgID, patient_id).First(&patient).Error
  101. return
  102. }
  103. func GetLastAfterWeight(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  104. var record models.AssessmentAfterDislysis
  105. err := p_service.XTReadDB().Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  106. if err != nil {
  107. if err == gorm.ErrRecordNotFound {
  108. return nil, nil
  109. } else {
  110. return nil, err
  111. }
  112. }
  113. return &record, nil
  114. }
  115. //func GetAllName(orgid int64,appid int64)(sign,err error){
  116. //
  117. // p_service.XTReadDB().Model(&sign).Where("org_id = ? and app_id =? and status = 1")
  118. //
  119. //}
  120. func FindPrintStockGoodInfoByType(types int, startTime int64, end_time int64, orgId int64) (list []*models.StockInfo, err error) {
  121. db := p_service.XTReadDB()
  122. db = db.Model(&models.StockInfo{})
  123. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgId)
  124. if types == 1 {
  125. db = db.Joins("JOIN xt_warehouse_info AS info ON info.good_id=xt_good_information.id AND info.status = 1").Group("xt_good_information.id")
  126. db = db.Preload("QueryWarehousingInfo", func(db *gorm.DB) *gorm.DB {
  127. return db.Where("xt_warehouse_info.org_id = ? AND xt_warehouse_info.status = 1", orgId).Joins("JOIN xt_warehouse AS warehouse ON warehouse.id = xt_warehouse_info.warehousing_id AND warehouse.status = 1 AND warehouse.warehousing_time >=? AND warehouse.warehousing_time<= ?", startTime, end_time)
  128. })
  129. } else if types == 2 {
  130. db = db.Joins("JOIN xt_sales_return_info AS info ON info.good_id=xt_good_information.id AND info.status = 1").Group("xt_good_information.id")
  131. db = db.Preload("QuerySalesReturnInfo", func(db *gorm.DB) *gorm.DB {
  132. return db.Where("xt_sales_return_info.org_id = ? AND xt_sales_return_info.status = 1", orgId).Joins("JOIN xt_sales_return AS sales ON sales.id = xt_sales_return_info.sales_return_id AND sales.status = 1 AND sales.return_time >=? AND sales.return_time<= ?", startTime, end_time)
  133. })
  134. } else if types == 3 {
  135. db = db.Joins("JOIN xt_warehouse_out_info AS info ON info.good_id=xt_good_information.id AND info.status = 1").Group("xt_good_information.id")
  136. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  137. return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1", orgId).Joins("JOIN xt_warehouse_out ON xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.status = 1 AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ?", startTime, end_time)
  138. })
  139. } else if types == 4 {
  140. db = db.Joins("JOIN xt_cancel_stock_info AS info ON info.good_id=xt_good_information.id AND info.status = 1").Group("xt_good_information.id")
  141. db = db.Preload("QueryCancelStockInfo", func(db *gorm.DB) *gorm.DB {
  142. return db.Where("xt_cancel_stock_info.org_id = ? AND xt_cancel_stock_info.status = 1", orgId).Joins("JOIN xt_cancel_stock AS cancel ON cancel.id = xt_cancel_stock_info.cancel_stock_id AND cancel.status = 1 AND cancel.return_time >=? AND cancel.return_time<= ?", startTime, end_time)
  143. })
  144. }
  145. db = db.Preload("GoodsType", "(org_id = ? AND status = 1) OR (status = 1 AND type = 1)", orgId)
  146. err = db.Order("ctime desc").Find(&list).Error
  147. return
  148. }
  149. func GetOrgInfoTemplate(orgID int64) (models.GobalTemplate, error) {
  150. var templateInfo models.GobalTemplate
  151. var err error
  152. err = p_service.XTReadDB().Model(&models.GobalTemplate{}).Where("org_id=? and status=1", orgID).First(&templateInfo).Error
  153. return templateInfo, err
  154. }