123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- package Patient
- import (
- "FollowUp_Notice/models/Illness"
- "FollowUp_Notice/models/Tag"
- "fmt"
- "git.baozhida.cn/ERP_libs/lib"
- "github.com/astaxie/beego/logs"
- "github.com/beego/beego/v2/adapter/orm"
- orm2 "github.com/beego/beego/v2/client/orm"
- "time"
- )
- // 患者
- type Patient struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_uuid string `orm:"size(32);null"` //
- T_uid int `orm:"size(200);null"` // 关联的用户id
- T_number string `orm:"size(256);null"` // 病历号
- T_name string `orm:"size(256);null"` // 姓名
- T_age int `orm:"size(200);null"` // 年轻
- T_tag string `orm:"size(200);null"` // 标签
- T_illness int `orm:"size(200);null"` // 疾病
- T_phone string `orm:"size(256);null"` // 电话号码
- T_next_time string `orm:"size(200);null"` // 下次复诊时间
- T_notice_phone int `orm:"size(200);null"` // 手机 1通知 0不通知
- T_notice_message int `orm:"size(200);null"` // 短信 1通知 0不通知
- T_notice_interval string `orm:"size(200);null"` // 0,0,0,0 提前1天,提前2天,提前3天,提前7天
- T_notice int `orm:"size(200);null"` // 通知状态 1待通知 2已通知
- T_follow_up int `orm:"size(200);null"` // 复诊状态 1正常 2超时 3结束
- T_record string `orm:"type(text);null"` // 2022-07-27,15|2022-07-27,15| 时间,间隔天数|
- T_State int `orm:"size(200);default(1)"` // 0删除 1正常
- CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新
- UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now_add 第一次保存时才设置时间
- }
- type Patient_R struct {
- Id int
- T_uuid string //
- T_uid int // 关联的用户id
- T_number string // 病历号
- T_name string // 姓名
- T_age int // 年轻
- T_tag []int // 标签
- T_tag_List []string // 标签
- T_illness int // 疾病
- T_illness_name string // 疾病名称
- T_phone string // 电话号码
- T_next_time string // 下次复诊时间
- T_next_interval int // 下次复诊间隔天数
- T_notice_phone int // 手机 1通知 0不通知
- T_notice_message int // 短信 1通知 0不通知
- T_notice_interval string // 0,0,0,0 提前1天,提前2天,提前3天,提前7天
- T_notice int // 待通知 已通知
- T_follow_up int // 复诊 超时 结束
- T_record string // 2022-07-27,15|2022-07-27,15| 时间,间隔天数|
- T_State int // 0删除 1正常
- }
- func (t *Patient) TableName() string {
- return "patient" // 数据库名称 // ************** 替换 FormulaList **************
- }
- func init() {
- //注册模型
- orm.RegisterModel(new(Patient))
- }
- func PatientToPatient_R(r Patient) (m Patient_R) {
- m.Id = r.Id
- m.T_uuid = r.T_uuid
- m.T_uid = r.T_uid
- m.T_number = r.T_number
- m.T_name = r.T_name
- m.T_age = r.T_age
- m.T_tag = lib.SplitStringToIntIds(r.T_tag, ",")
- for _, v := range m.T_tag {
- m.T_tag_List = append(m.T_tag_List, Tag.Read_Tag_Get(v))
- }
- m.T_illness = r.T_illness
- m.T_illness_name = Illness.Read_Illness_Get(r.T_illness)
- m.T_phone = r.T_phone
- m.T_next_time = r.T_next_time
- m.T_notice_phone = r.T_notice_phone
- m.T_notice_message = r.T_notice_message
- m.T_notice_interval = r.T_notice_interval
- m.T_notice = r.T_notice
- m.T_follow_up = r.T_follow_up
- m.T_record = r.T_record
- m.T_State = r.T_State
- return
- }
- // 添加
- func Add_Patient(r Patient) (id int64, err error) {
- o := orm.NewOrm()
- //生成编号
- rand_x := 0
- for true {
- r.T_uuid = lib.GetRandstring(32, "", int64(rand_x))
- err = o.Read(&r, "T_uuid")
- if err != nil {
- break
- }
- rand_x += 1
- }
- r.T_State = 1
- id, err = o.Insert(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- return id, err
- }
- // 获取 ById
- func Read_Patient_ByT_uuid(T_uuid string) (r Patient, err error) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(Patient))
- err = qs.Filter("T_uuid", T_uuid).One(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- return
- }
- // 修改
- func Update_Patient(m Patient, cols ...string) error {
- o := orm.NewOrm()
- num, err := o.Update(&m, cols...)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return err
- }
- fmt.Println("Number of records updated in database:", num)
- return nil
- }
- // 删除
- func Delete_Patient(v Patient) error {
- o := orm.NewOrm()
- v.T_State = 0
- _, err := o.Update(&v, "T_State")
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- return err
- }
- // 获取列表
- func Read_Patient_List(T_uid int, T_number, T_name string, T_tag, T_illness, T_notice, T_follow_up, T_age_sort, T_next_time_sort, page, page_z int) (r_ []Patient_R, cnt int64) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- qs := o.QueryTable(new(Patient))
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- // 过滤
- cond := orm.NewCondition()
- cond = cond.And("T_State__gt", 0)
- if T_uid > 0 {
- cond = cond.And("T_uid", T_uid)
- }
- if len(T_number) > 0 {
- cond = cond.And("T_number__icontains", T_number)
- }
- if len(T_name) > 0 {
- cond = cond.And("T_name__icontains", T_name)
- }
- if T_tag > 0 {
- cond = cond.And("T_tag", T_tag)
- }
- if T_illness > 0 {
- cond = cond.And("T_illness", T_illness)
- }
- if T_notice > 0 {
- cond = cond.And("T_notice", T_notice)
- }
- if T_follow_up > 0 {
- cond = cond.And("T_follow_up", T_follow_up)
- }
- var order []string
- if T_age_sort == 1 {
- order = append(order, "T_age")
- } else if T_age_sort == 2 {
- order = append(order, "-T_age")
- }
- if T_next_time_sort == 1 {
- order = append(order, "T_next_time")
- } else if T_next_time_sort == 2 {
- order = append(order, "-T_next_time")
- }
- order = append(order, "-Id")
- // 查询
- var r []Patient
- var err error
- if page_z == 9999 {
- _, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy(order...).All(&r)
- } else {
- _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy(order...).All(&r)
- }
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- for _, v := range r {
- r_ = append(r_, PatientToPatient_R(v))
- }
- return r_, cnt
- }
|