90 lines
3.0 KiB
Go
90 lines
3.0 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/global"
|
|
)
|
|
|
|
type OrderPrescriptionIcdDao struct {
|
|
}
|
|
|
|
// GetOrderPrescriptionIcdById 获取处方关联疾病数据-处方关联疾病id
|
|
func (r *OrderPrescriptionIcdDao) GetOrderPrescriptionIcdById(PrescriptionIcdId int64) (m *model.OrderPrescriptionIcd, err error) {
|
|
err = global.Db.First(&m, PrescriptionIcdId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (r *OrderPrescriptionIcdDao) GetOrderPrescriptionIcdByOrderPrescriptionId(orderPrescriptionId int64) (m *model.OrderPrescriptionIcd, err error) {
|
|
err = global.Db.Where("order_prescription_id = ?", orderPrescriptionId).First(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (r *OrderPrescriptionIcdDao) GetOrderPrescriptionIcdListByOrderPrescriptionId(orderPrescriptionId int64) (m []*model.OrderPrescriptionIcd, err error) {
|
|
err = global.Db.Where("order_prescription_id = ?", orderPrescriptionId).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetOrderPrescriptionIcdPreloadById 获取处方关联疾病数据-加载全部关联-处方关联疾病id
|
|
func (r *OrderPrescriptionIcdDao) GetOrderPrescriptionIcdPreloadById(PrescriptionIcdId int64) (m *model.OrderPrescriptionIcd, err error) {
|
|
err = global.Db.Preload(clause.Associations).First(&m, PrescriptionIcdId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// DeleteOrderPrescriptionIcd 删除处方关联疾病
|
|
func (r *OrderPrescriptionIcdDao) DeleteOrderPrescriptionIcd(tx *gorm.DB, maps interface{}) error {
|
|
err := tx.Where(maps).Delete(&model.OrderPrescriptionIcd{}).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditOrderPrescriptionIcd 修改处方关联疾病
|
|
func (r *OrderPrescriptionIcdDao) EditOrderPrescriptionIcd(tx *gorm.DB, maps interface{}, data interface{}) error {
|
|
err := tx.Model(&model.OrderPrescriptionIcd{}).Where(maps).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditOrderPrescriptionIcdByOrderPrescriptionId 修改处方关联疾病-处方关联疾病id
|
|
func (r *OrderPrescriptionIcdDao) EditOrderPrescriptionIcdByOrderPrescriptionId(tx *gorm.DB, PrescriptionIcdId int64, data interface{}) error {
|
|
err := tx.Model(&model.OrderPrescriptionIcd{}).Where("order_prescription_id = ?", PrescriptionIcdId).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetOrderPrescriptionIcdList 获取处方关联疾病列表
|
|
func (r *OrderPrescriptionIcdDao) GetOrderPrescriptionIcdList(maps interface{}) (m []*model.OrderPrescriptionIcd, err error) {
|
|
err = global.Db.Where(maps).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// AddOrderPrescriptionIcd 新增处方关联疾病
|
|
func (r *OrderPrescriptionIcdDao) AddOrderPrescriptionIcd(tx *gorm.DB, model *model.OrderPrescriptionIcd) (*model.OrderPrescriptionIcd, error) {
|
|
if err := tx.Create(model).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|