his_config_service.go 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package service
  2. import (
  3. "XT_New/models"
  4. "time"
  5. )
  6. func GetHisPrescriptionTemplatesList(patient_id int64, org_id int64, page int64, limit int64) (templates []*models.HisPrescriptionTemplate, total int64, err error) {
  7. offset := (page - 1) * limit
  8. db := readDb.Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? AND patient_id= ? AND status = 1", org_id, patient_id)
  9. err = db.Count(&total).Offset(offset).Limit(limit).Find(&templates).Error
  10. return
  11. }
  12. func GetHisPrescriptionTemplateByID(template_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  13. err = readDb.Model(&models.HisPrescriptionTemplate{}).Where("id = ? AND status = 1 ", template_id).First(&prescription).Error
  14. return
  15. }
  16. func GetHisPrescriptionTemplateByModeId(mode_id int64, patient_id int64, user_org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  17. err = readDb.Model(&models.HisPrescriptionTemplate{}).Where("mode = ? AND status = 1 AND patient_id = ? and user_org_id = ?", mode_id, patient_id, user_org_id).First(&prescription).Error
  18. return
  19. }
  20. func GetHisPrescriptionTemplateByModeIdTwo(mode_id int64, patient_id int64, user_org_id int64, id int64) (prescription models.HisPrescriptionTemplate, err error) {
  21. err = readDb.Model(&models.HisPrescriptionTemplate{}).Where("mode = ? AND status = 1 AND patient_id = ? and user_org_id = ? and id <> ?", mode_id, patient_id, user_org_id, id).First(&prescription).Error
  22. return
  23. }
  24. func SaveHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  25. err = writeDb.Save(&template).Error
  26. return
  27. }
  28. func DelelteHisPrescriptionInfoTemplate(id int64, user_org_id int64) (err error) {
  29. err = writeDb.Model(&models.HisPrescriptionInfoTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  30. err = writeDb.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  31. err = writeDb.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  32. return
  33. }
  34. func DelelteHisPrescriptionTemplate(id int64, user_org_id int64) (err error) {
  35. err = writeDb.Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0}).Error
  36. err = writeDb.Model(&models.HisPrescriptionInfoTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  37. return
  38. }
  39. func DelelteHisPrescriptionAdviceTemplate(id int64, user_org_id int64) (err error) {
  40. err = writeDb.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  41. return
  42. }
  43. func DelelteHisPrescriptionProjectTemplate(id int64, user_org_id int64) (err error) {
  44. err = writeDb.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  45. return
  46. }