新增问诊病例,患者列表(未完成)
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type PatientFamilyHealthDao struct {
|
||||
}
|
||||
|
||||
func (r *PatientFamilyHealthDao) GetPatientFamilyHealthById(familyHealthId int64) (m *model.PatientFamilyHealth, err error) {
|
||||
err = global.Db.First(&m, familyHealthId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyHealthDao) DeletePatientFamilyHealth(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.PatientFamilyHealth{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyHealthDao) GetPatientFamilyHealthByFamilyId(familyId int64) (m *model.PatientFamilyHealth, err error) {
|
||||
err = global.Db.Where("family_id = ?", familyId).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyHealthDao) GetPatientFamilyHealthByPatientId(patientId int64) (m *model.PatientFamilyHealth, err error) {
|
||||
err = global.Db.Where("patient_id = ?", patientId).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyHealthDao) EditPatientFamilyHealth(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.PatientFamilyHealth{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyHealthDao) EditPatientFamilyHealthById(tx *gorm.DB, familyHealthId int64, data interface{}) error {
|
||||
err := tx.Model(&model.PatientFamilyHealth{}).Where("family_health_id = ?", familyHealthId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyHealthDao) GetPatientFamilyHealthList(maps interface{}) (m []*model.PatientFamilyHealth, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyHealthDao) AddPatientFamilyHealth(tx *gorm.DB, model *model.PatientFamilyHealth) (*model.PatientFamilyHealth, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyHealthDao) AddPatientFamilyHealthByMap(tx *gorm.DB, data map[string]interface{}) (*model.PatientFamilyHealth, error) {
|
||||
userDoctorInfo := &model.PatientFamilyHealth{}
|
||||
if err := tx.Model(&model.PatientFamilyHealth{}).Create(data).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userDoctorInfo, nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type PatientFamilyPersonalDao struct {
|
||||
}
|
||||
|
||||
func (r *PatientFamilyPersonalDao) GetPatientFamilyPersonalById(familyPersonalId int64) (m *model.PatientFamilyPersonal, err error) {
|
||||
err = global.Db.First(&m, familyPersonalId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyPersonalDao) DeletePatientFamilyPersonal(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.PatientFamilyPersonal{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyPersonalDao) GetPatientFamilyPersonalByFamilyId(familyId int64) (m *model.PatientFamilyPersonal, err error) {
|
||||
err = global.Db.Where("family_id = ?", familyId).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyPersonalDao) GetPatientFamilyPersonalByPatientId(patientId int64) (m *model.PatientFamilyPersonal, err error) {
|
||||
err = global.Db.Where("patient_id = ?", patientId).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyPersonalDao) EditPatientFamilyPersonal(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.PatientFamilyPersonal{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyPersonalDao) EditPatientFamilyPersonalById(tx *gorm.DB, familyPersonalId int64, data interface{}) error {
|
||||
err := tx.Model(&model.PatientFamilyPersonal{}).Where("family_personal_id = ?", familyPersonalId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyPersonalDao) GetPatientFamilyPersonalList(maps interface{}) (m []*model.PatientFamilyPersonal, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyPersonalDao) AddPatientFamilyPersonal(tx *gorm.DB, model *model.PatientFamilyPersonal) (*model.PatientFamilyPersonal, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
func (r *PatientFamilyPersonalDao) AddPatientFamilyPersonalByMap(tx *gorm.DB, data map[string]interface{}) (*model.PatientFamilyPersonal, error) {
|
||||
userDoctorInfo := &model.PatientFamilyPersonal{}
|
||||
if err := tx.Model(&model.PatientFamilyPersonal{}).Create(data).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userDoctorInfo, nil
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type UserPatientDao struct {
|
||||
}
|
||||
|
||||
// GetUserPatientById 获取患者数据-患者id
|
||||
func (r *UserPatientDao) GetUserPatientById(patientId int64) (m *model.UserPatient, err error) {
|
||||
err = global.Db.First(&m, patientId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserPatientPreloadById 获取患者数据-加载全部关联-患者id
|
||||
func (r *UserPatientDao) GetUserPatientPreloadById(patientId int64) (m *model.UserPatient, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, patientId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteUserPatient 删除患者
|
||||
func (r *UserPatientDao) DeleteUserPatient(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.UserPatient{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteUserPatientById 删除患者-患者id
|
||||
func (r *UserPatientDao) DeleteUserPatientById(tx *gorm.DB, patientId int64) error {
|
||||
if err := tx.Delete(&model.UserPatient{}, patientId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditUserPatient 修改患者
|
||||
func (r *UserPatientDao) EditUserPatient(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.UserPatient{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditUserPatientById 修改患者-患者id
|
||||
func (r *UserPatientDao) EditUserPatientById(tx *gorm.DB, patientId int64, data interface{}) error {
|
||||
err := tx.Model(&model.UserPatient{}).Where("patient_id = ?", patientId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUserPatientList 获取患者列表
|
||||
func (r *UserPatientDao) GetUserPatientList(maps interface{}) (m []*model.UserPatient, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserPatientPageSearch 获取患者列表-分页
|
||||
func (r *UserPatientDao) GetUserPatientPageSearch(req requests.GetUserPatientPage, page, pageSize int) (m []*model.UserPatient, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.UserPatient{}).Omit("open_id", "union_id", "wx_session_key")
|
||||
|
||||
// 用户表
|
||||
query = query.Preload("User", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Omit("user_password", "salt")
|
||||
})
|
||||
|
||||
// 家庭成员表
|
||||
query = query.Preload("PatientFamily")
|
||||
|
||||
// 手机号
|
||||
if req.Mobile != "" {
|
||||
subQuery := global.Db.Model(&model.User{}).
|
||||
Select("user_id").
|
||||
Where("mobile LIKE ?", "%"+req.Mobile+"%")
|
||||
|
||||
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
|
||||
}
|
||||
|
||||
// 用户名称-用户-就诊人
|
||||
if req.UserName != "" {
|
||||
// 用户
|
||||
query = query.Where("user_name LIKE ?", "%"+req.UserName+"%")
|
||||
|
||||
// 就诊人
|
||||
patientFamilySubQuery := global.Db.Model(&model.PatientFamily{}).
|
||||
Select("patient_id").
|
||||
Where("card_name LIKE ?", "%"+req.UserName+"%")
|
||||
|
||||
query = query.Or("patient_id IN (?)", patientFamilySubQuery).Or(query)
|
||||
}
|
||||
|
||||
// 用户状态
|
||||
if req.Status != nil {
|
||||
query = query.Where("status = ?", req.Status)
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// AddUserPatient 新增患者
|
||||
func (r *UserPatientDao) AddUserPatient(tx *gorm.DB, model *model.UserPatient) (*model.UserPatient, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
Reference in New Issue
Block a user