123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978 |
- package service
-
- import (
- "Xcx_New/models"
- "fmt"
- "strconv"
- "strings"
- "time"
-
- "github.com/jinzhu/gorm"
- )
-
- //GetSchedulePartitionPanel 取出排班面板,分区-机号
- func GetSchedulePartitionPanel(orgID int64) (partitions []*models.Partition, err error) {
-
- err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Order("").Find(&partitions).Error
-
- return
- }
-
- func GetSchedulePartitionPanelOne(orgID int64, partionId int64) (partitions []*models.Partition, err error) {
-
- if partionId > 0 {
- err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1 and zone_id = ?", orgID, partionId).Where("org_id=? and status=1 and id = ?", orgID, partionId).Find(&partitions).Error
- }
- if partionId == 0 {
- err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
- }
-
- return
- }
-
- func GetSchedulePartitionPanelTwo(orgID int64, schIDs []string) (partitions []*models.Partition, err error) {
-
- if len(schIDs) == 0 {
- err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
- }
- if len(schIDs) > 0 {
- err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1 and zone_id in(?)", orgID, schIDs).Where("org_id=? and status=1 and id in(?)", orgID, schIDs).Find(&partitions).Error
- }
-
- return
- }
-
- func GetPatientWithScheduleAndSolution(orgID int64, keywords string, weekStart, weekEnd, schedule, contagion int64) (patients []*models.Patients, err error) {
- db := readDb.Table("xt_patients as p").
- Preload("DialysisSolutions", "user_org_id=? and initiate_mode=1 and affirm_state=1 and parent_id=0 and status=1", orgID).
- Preload("Schedules", "user_org_id=? and schedule_date>=? and schedule_date<= ? and status=1", orgID, weekStart, weekEnd).
- Preload("Contagions", "status=1").
- Where("p.user_org_id=? and p.lapseto=1 and p.status=1", orgID)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("p.name LIKE ?", likeKey)
- }
-
- if schedule == 1 {
- db = db.Where("EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.schedule_date>=? and iss.schedule_date<= ? and iss.status=1", weekStart, weekEnd).QueryExpr())
- } else if schedule == 2 {
- db = db.Where("NOT EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.schedule_date>=? and iss.schedule_date<= ? and iss.status=1", weekStart, weekEnd).QueryExpr())
- }
- if contagion > 0 {
- db = db.Where("EXISTS (?)", readDb.Table("xt_patients_infectious_diseases as pid").Where("pid.patient_id=p.id and pid.disease_id=? and pid.status=1", contagion).QueryExpr())
- }
-
- err = db.Find(&patients).Error
- return
- }
-
- func GetWeekSchedule(orgID int64, start, end int64) (schedules []*models.Schedule, err error) {
-
- err = readDb.Table("xt_schedule as s").Preload("PatientInfectiousDiseases", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("updated_time asc").
- Find(&schedules).Error
- return
- }
-
- func GetWeekScheduleOne(orgID int64, start, end int64, partionid int64, scheduletype int64) (schedules []*models.Schedule, err error) {
-
- db := readDb.Table("xt_schedule as s")
- if partionid > 0 {
- db = db.Where("s.partition_id = ?", partionid)
- }
- if scheduletype > 0 {
- db = db.Where("s.schedule_type = ?", scheduletype)
- }
- err = db.Preload("PatientInfectiousDiseases", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("updated_time asc").
- Find(&schedules).Error
- return
- }
-
- func GetWeekScheduleTwo(orgID int64, start, end int64, schIds []string, scheduletype int64) (schedules []*models.Schedule, err error) {
-
- db := readDb.Table("xt_schedule as s")
- fmt.Println("schIds2222222")
- if len(schIds) > 0 {
- db = db.Where("s.partition_id in (?)", schIds)
- }
- if scheduletype > 0 {
- db = db.Where("s.schedule_type = ?", scheduletype)
- }
- err = db.Preload("PatientInfectiousDiseases", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("updated_time asc").
- Find(&schedules).Error
- return
- }
-
- func GetDaySchedule(orgID, start, end, patientID int64) (schedule models.Schedule, err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and patient_id=? and schedule_date>=? and schedule_date<=? and status=1", orgID, patientID, start, end).First(&schedule).Error
- return
- }
-
- func GetDayScheduleTwo(orgID, start, patientID int64) (schedule models.Schedule, err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and patient_id=? and schedule_date = ? and status=1", orgID, patientID, start).Preload("DialysisOrder", "status = 1").First(&schedule).Error
- return
- }
-
- func GetDayScheduleByBedid(orgID, start, bed_id int64, schedule_type int64) (schedule models.Schedule, err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and schedule_date=? and bed_id=? and status=1 AND schedule_type = ?", orgID, start, bed_id, schedule_type).Preload("DialysisOrder", "status = 1").First(&schedule).Error
- return
- }
-
- func GetPatientScheduleFormDay(orgID, start, end, patientID int64) (schedules []*models.PatientSchedule, err error) {
-
- err = readDb.Table("xt_schedule as s").
- Preload("DeviceZone", "org_id=? and status=1", orgID).
- Preload("DeviceNumber", "org_id=? and status=1", orgID).
- Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.schedule_date < ? and s.status=1", patientID, orgID, start, end).
- Find(&schedules).Error
-
- return
- }
-
- func GetNextSchedule(orgID, end, patientID int64) (schedules []*models.PatientSchedule, err error) {
- err = readDb.Table("xt_schedule as s").
- Preload("DeviceZone", "org_id=? and status=1", orgID).
- Preload("DeviceNumber", "org_id=? and status=1", orgID).
- Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.status=1", patientID, orgID, end).
- Find(&schedules).Error
-
- return
- }
-
- func GetPointSchedule(orgID, scheduleDate, scheduleWeek, scheduleType, bedId int64) (schedule models.Schedule, err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and schedule_date=? and bed_id=? and schedule_week=? AND schedule_type=? and status=1", orgID, scheduleDate, bedId, scheduleWeek, scheduleType).First(&schedule).Error
-
- if err == gorm.ErrRecordNotFound {
- err = nil
- return
- }
- return
- }
-
- func CreateSchedule(m *models.Schedule) error {
- return writeDb.Model(&models.Schedule{}).Create(&m).Error
- }
-
- func GetTodayScheduleIsExist(patientid int64, schedudate int64, orgid int64, mode_id int64, schedule_type int64) (*models.XtSchedule, error) {
- var scheudle models.XtSchedule
- var err error
- err = XTReadDB().Model(&scheudle).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1 and mode_id = ? and schedule_type = ?", patientid, schedudate, orgid, mode_id, schedule_type).Find(&scheudle).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &scheudle, nil
- }
-
- func UpdateScheduleByOrgId(patientid int64, scheduledate int64, orgid int64, mode_id int64, schedule_type int64, sch *models.XtSchedule) error {
- err := XTWriteDB().Model(&sch).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1 and mode_id = ? and schedule_type = ?", patientid, scheduledate, orgid, mode_id, schedule_type).Updates(map[string]interface{}{"partition_id": sch.PartitionId, "bed_id": sch.BedId, "schedule_type": sch.ScheduleType, "schedule_week": sch.ScheduleWeek, "mode_id": sch.ModeId, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func GetSchedule(orgID, id int64) (*models.Schedule, error) {
- var schedule models.Schedule
- var err error
- err = readDb.Model(&models.Schedule{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&schedule).Error
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func UpdateSchedule(m *models.Schedule) error {
- return writeDb.Model(&models.Schedule{}).Save(&m).Error
- }
-
- func GetPatientScheduleFormToday(orgId, id, start int64) (schedules []*models.PatientSchedule, err error) {
-
- err = readDb.Table("xt_schedule as s").
- Preload("DeviceZone", "org_id=? and status=1", orgId).
- Preload("DeviceNumber", "org_id=? and status=1", orgId).
- Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.status=1", id, orgId, start).
- Find(&schedules).Error
-
- return
- }
-
- type WeekSchedulePrintVM struct {
- ID int64 `gorm:"column:id" json:"id"`
- ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
- DeviceNumberID int64 `gorm:"column:bed_id" json:"device_number_id"`
- PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
- ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
- ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
- ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
- ModeID int64 `gorm:"column:mode_id" json:"mode_id"`
-
- Patient *models.Patients `gorm:"ForeignKey:PatientID" json:"patient"`
- DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
- Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
- Mode *models.TreatmentMode `gorm:"ForeignKey:ModeID" json:"mode"`
- }
-
- type PrintCount struct {
- ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
- ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
- Count int64
- }
-
- func GetPrinitWeekSchedules(orgID int64, start, end int64) ([]*WeekSchedulePrintVM, error) {
- var schedules []*WeekSchedulePrintVM
- err := readDb.Table("xt_schedule as s").
- Preload("Patient", "status = 1 and user_org_id = ?", orgID).
- Preload("DeviceNumber", "status = 1 and org_id = ?", orgID).
- Preload("Zone", "status = 1 and org_id = ?", orgID).
- Preload("Mode", "status = 1").
- // Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id = ? and s.schedule_date >= ? and s.schedule_date <= ? and s.status = 1", orgID, start, end).
- // Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id").
- Find(&schedules).Error
- return schedules, err
- }
-
- func GetPrinitWeekTotal(orgid int64, startime int64, endtime int64) (print []*PrintCount, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.schedule_date <=?", endtime)
- }
- err = db.Select("x.schedule_type,x.schedule_week,count(x.patient_id) as count").Group("x.schedule_date,x.schedule_type").Scan(&print).Error
- return print, err
- }
-
- func GetBloodPrintWeekTotal(orgid int64, startime int64, endtime int64) (print []*PrintCount, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.schedule_date <=?", endtime)
- }
- db = db.Where("x.mode_id = 2")
- err = db.Select("x.schedule_type,x.schedule_week,count(x.patient_id) as count").Group("x.schedule_date,x.schedule_type").Scan(&print).Error
- return print, err
- }
-
- func GetPerfusionWeekTotal(orgid int64, startime int64, endtime int64) (print []*PrintCount, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.schedule_date <=?", endtime)
- }
- db = db.Where("x.mode_id = 3")
- err = db.Select("x.schedule_type,x.schedule_week,count(x.patient_id) as count").Group("x.schedule_date,x.schedule_type").Scan(&print).Error
- return print, err
- }
-
- // func ExchangeScheduleTimeWithWeekSchedules(orgID int64, nextWeekSchs []*models.Schedule, nextTwoWeekSchs []*models.Schedule) error {
- // templateMode, getTemplateModeErr := GetOrgPatientScheduleTemplateMode(orgID)
- // if getTemplateModeErr != nil {
- // return getTemplateModeErr
- // }
- // if templateMode == nil {
- // return errors.New("模板模式不存在")
- // }
-
- // tx := writeDb.Begin()
-
- // updateTime := time.Now().Unix()
-
- // for _, sch := range nextWeekSchs {
- // sch.PatientInfectiousDiseases = nil
-
- // date := time.Unix(sch.ScheduleDate, 0)
- // sch.ScheduleDate = date.AddDate(0, 0, 7).Unix()
- // sch.UpdatedTime = updateTime
-
- // updateSchErr := tx.Save(sch).Error
- // if updateSchErr != nil {
- // tx.Rollback()
- // return updateSchErr
- // }
- // }
-
- // for _, sch := range nextTwoWeekSchs {
- // sch.PatientInfectiousDiseases = nil
-
- // date := time.Unix(sch.ScheduleDate, 0)
- // sch.ScheduleDate = date.AddDate(0, 0, -7).Unix()
- // sch.UpdatedTime = updateTime
-
- // updateSchErr := tx.Save(sch).Error
- // if updateSchErr != nil {
- // tx.Rollback()
- // return updateSchErr
- // }
- // }
-
- // templateMode.ModifyTime = updateTime
- // templateMode.ExecuteTimes += 1
- // updateModeErr := tx.Save(templateMode).Error
- // if updateModeErr != nil {
- // tx.Rollback()
- // return updateModeErr
- // }
-
- // tx.Commit()
- // return nil
- // }
-
- func GetSchedualPatientsByKeywordsAndWeek(keywords string, org_id int64, start_time int64, end_time int64) (schedule []*models.Schedule, err error) {
- likeKey := "%" + keywords + "%"
- err = readDb.
- Table("xt_schedule as s").
- Preload("PatientInfectiousDiseases", "status = 1 ").
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("TreatmentMode", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id AND (p.name LIKE ? OR p.dialysis_no LIKE ?)", likeKey, likeKey).
- Where("s.user_org_id=? and s.schedule_date >= ? and s.schedule_date <= ? and s.status=1", org_id, start_time, end_time).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("schedule_date asc").
- Find(&schedule).Error
- return
-
- }
-
- func GetSchedualPatientsByKeywords(keywords string, org_id int64) (schedule []*models.Schedule, err error) {
- likeKey := "%" + keywords + "%"
-
- err = readDb.
- Table("xt_schedule as s").
- Preload("PatientInfectiousDiseases", "status = 1 ").
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("TreatmentMode", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id AND (p.name LIKE ? OR p.dialysis_no LIKE ?)", likeKey, likeKey).
- Where("s.user_org_id=? and s.schedule_date >= UNIX_TIMESTAMP(DATE_FORMAT(NOW(),'%Y-%m-%d 00:00:00')) and s.schedule_date <= UNIX_TIMESTAMP(DATE_FORMAT( SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),'%w')-7), '%Y-%m-%d 23:59:59')) and s.status=1", org_id).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("schedule_date asc").
- Find(&schedule).Error
- return
-
- }
-
- func GetWeekDayScheduleTwo(orgID int64, scheduleDate int64, scheduleDates *time.Time, weektime int64) (schedules []*models.WeekSchedule, err error) {
-
- db := readDb.Table("xt_schedule as s ").Where("s.status =1")
- if orgID > 0 {
- db = db.Where("s.user_org_id = ?", orgID)
- }
- if scheduleDate > 0 {
- db = db.Where("s.schedule_date = ?", scheduleDate)
-
- }
- if weektime > 0 {
- db = db.Where("s.schedule_type = ?", weektime)
- }
- err = db.
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1").Order("id asc")
- }).
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("s.partition_id asc").
- Find(&schedules).Error
-
- for _, item := range schedules {
- _, config := FindDoctorAdviceRecordByOrgId(item.UserOrgId)
- if config.IsOpenRemind > 0 {
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
- advices, _ := GetLastLongAdviceByGroupNoOther(item.UserOrgId, item.PatientId)
- advices_two, _ := GetLastLongAdviceByGroupNoThreeOther(item.UserOrgId, item.PatientId)
- for _, advice := range advices {
- advice.IsCheck = 1
- if advice.FrequencyType == 3 {
- week := int(scheduleDates.Weekday())
-
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- } else if advice.FrequencyType == 1 {
- advice_three = append(advice_three, advice)
- }
- }
-
- for _, advice := range advices_two {
- now := scheduleDates.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := scheduleDates.AddDate(0, 0, int(count)).Unix()
- advices, _ := FindAllDoctorAdviceByTimeOther(now, oldTime, item.PatientId, item.UserOrgId, advice.TemplateId)
- if len(advices) == 0 {
- advice_three = append(advice_three, advice)
- }
- }
-
- item.DoctorAdvice = append(item.DoctorAdvice, advice_three...)
- }
- }
- return
- }
-
- func GetWeekDaySchedule(orgID int64, scheduleDate int64, scheduleDates *time.Time) (schedules []*models.WeekSchedule, err error) {
-
- err = readDb.
- Table("xt_schedule as s").
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1").Order("id asc")
- }).
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date = ? and s.status=1", orgID, scheduleDate).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("schedule_type").
- Find(&schedules).Error
-
- for _, item := range schedules {
- _, config := FindDoctorAdviceRecordByOrgId(item.UserOrgId)
- if config.IsOpenRemind > 0 {
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
- advices, _ := GetLastLongAdviceByGroupNoOther(item.UserOrgId, item.PatientId)
- advices_two, _ := GetLastLongAdviceByGroupNoThreeOther(item.UserOrgId, item.PatientId)
- for _, advice := range advices {
- advice.IsCheck = 1
- if advice.FrequencyType == 3 {
- week := int(scheduleDates.Weekday())
- fmt.Println(advice.WeekDay)
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- } else if advice.FrequencyType == 1 {
- advice_three = append(advice_three, advice)
- }
- }
-
- for _, advice := range advices_two {
- now := scheduleDates.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := scheduleDates.AddDate(0, 0, int(count)).Unix()
- advices, _ := FindAllDoctorAdviceByTimeOther(now, oldTime, item.PatientId, item.UserOrgId, advice.TemplateId)
- if len(advices) == 0 {
- advice_three = append(advice_three, advice)
- }
- }
-
- item.DoctorAdvice = append(item.DoctorAdvice, advice_three...)
- }
- }
- return
- }
-
- func GetWeekDayScheduleById(orgid int64, scheduleDate int64, scheduleType int64, zone int64) (list []*models.VmSchedulesRemind, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if scheduleDate > 0 {
- db = db.Where("x.schedule_date = ?", scheduleDate)
- }
- if scheduleType > 0 {
- db = db.Where("x.schedule_type = ?", scheduleType)
- }
- if zone > 0 {
- db = db.Where("x.partition_id = ?", zone)
- }
-
- err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1").Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
- }).Preload("HisDoctorAdviceInfo", "status = 1").Preload("DialysisPrescription", "status = 1").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1").Order("id asc")
- }).Find(&list).Error
-
- return list, err
- }
-
- func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if scheduleDate > 0 {
- db = db.Where("x.schedule_date = ?", scheduleDate)
- }
- if scheduleType > 0 {
- db = db.Where("x.schedule_type = ?", scheduleType)
- }
- if len(zone) > 0 {
- db = db.Where("x.partition_id in (?)", zone)
- }
-
- err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1").Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
- }).Preload("HisDoctorAdviceInfo", "status = 1").Preload("DialysisPrescription", "status = 1").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1").Order("id asc")
- }).Find(&list).Error
-
- return list, err
- }
-
- func GetWeekDayScheduleByIdTwo(orgid int64, scheduleDate int64, scheduleType int64, startDate int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if scheduleDate > 0 {
- db = db.Where("x.schedule_date >=? and x.schedule_date<=?", startDate, scheduleDate)
- }
- if scheduleType > 0 {
- db = db.Where("x.schedule_type = ?", scheduleType)
- }
- if len(zone) > 0 {
- db = db.Where("x.partition_id in (?)", zone)
- }
-
- err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1").Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
- }).Preload("HisDoctorAdviceInfo", "status = 1").Preload("DialysisPrescription", "status = 1").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1").Order("id asc")
- }).Find(&list).Error
-
- return list, err
- }
-
- func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
- newArr = make([]*models.DoctorAdvice, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].ID == arr[j].ID {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func GetLastLongAdviceByGroupNoOther(orgId int64, patient_id int64) (advice []*models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND stop_state = 2 AND parent_id = 0", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
- return
- }
-
- func GetLastLongAdviceByGroupNoThreeOther(orgId int64, patient_id int64) (advice []*models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND frequency_type = 2 AND stop_state = 2 AND parent_id = 0 ", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
- return
- }
-
- func FindAllDoctorAdviceByTimeOther(now int64, end int64, patient_id int64, orgId int64, temp_id string) (advice []*models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 2 AND frequency_type = 2 AND advice_date > ? AND advice_date < ? AND template_id = ? ", orgId, patient_id, end, now, temp_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
- return
- }
-
- func FindSchPatientNameByName(name string, user_org_id int64) (patient []*models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND name = ? AND status = 1", user_org_id, name).Find(&patient).Error
- return
- }
-
- func UpdateScheduleStatus(date int64, org_id int64) (err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND schedule_date > ? AND status = 1", org_id, date).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func FindDeviceZoneByName(name string, org_id int64) (zone models.DeviceZone, err error) {
- err = readDb.Model(&models.DeviceZone{}).Where("org_id = ? AND name = ? AND status = 1", org_id, name).First(&zone).Error
- return
- }
-
- func FindDeviceByName(device_name string, org_id int64, zone_id int64) (devices []*models.DeviceNumber, err error) {
- err = readDb.Model(&models.DeviceNumber{}).Where("org_id = ? AND number = ? AND zone_id = ? AND status = 1", org_id, device_name, zone_id).Find(&devices).Error
- return
- }
-
- func FindSchedualExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 2", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func FindDeviceByNameTwo(device_name string, org_id int64, zone_id int64) (devices []*models.DeviceNumber, err error) {
- err = readDb.Model(&models.DeviceNumber{}).Where("org_id = ? AND number = ? AND status = 1 AND zone_id = ?", org_id, device_name, zone_id).Find(&devices).Error
- return
- }
-
- func UpdateScheduleTemplateStatus(org_id int64) (err error) {
- err = readDb.Model(&models.PatientScheduleTemplateItem{}).Where("org_id = ? AND status = 1", org_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func CreateScheduleTemplate(m *models.PatientScheduleTemplateItem) error {
- return writeDb.Model(&models.PatientScheduleTemplateItem{}).Create(&m).Error
- }
-
- func FindSchedualTemplateExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 3", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func GetDialysisOrderByBedId(orgID, start, bed_id int64, schedule_type int64) (schedule models.DialysisOrder, err error) {
- err = readDb.Model(&models.DialysisOrder{}).Where("user_org_id=? and dialysis_date=? and bed_id=? and status=1 AND schedual_type = ?", orgID, start, bed_id, schedule_type).First(&schedule).Error
- return
- }
-
- type VMDeviceNumber struct {
- ID int64 `gorm:"column:id" json:"id"`
- OrgID int64 `gorm:"column:org_id" json:"-"`
- Number string `gorm:"column:number" json:"number"`
- GroupID int64 `gorm:"column:group_id" json:"group_id"`
- ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
- Status int8 `json:"-"`
- CreateTime int64 `gorm:"column:ctime" json:"-"`
- ModifyTime int64 `gorm:"column:mtime" json:"-"`
- DeviceZone models.DeviceZone `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:ZoneID;"`
- }
-
- func (VMDeviceNumber) TableName() string {
- return "xt_device_number"
- }
-
- type VMPatientScheduleTemplateItem struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- OrgID int64 `gorm:"column:org_id" json:"-" form:"org_id"`
- TemplateID int64 `gorm:"column:template_id" json:"template_id" form:"template_id"`
- DeviceNumberID int64 `gorm:"column:device_number_id" json:"device_number_id" form:"device_number_id"`
- PatientID int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
- TreatMode int64 `gorm:"column:treat_mode" json:"treat_mode" form:"treat_mode"` // 治疗模式
- Weekday int8 `gorm:"column :weekday" json:"weekday" form:"weekday"` // 周一-周日 1-7
- TimeType int8 `gorm:"column:time_type" json:"time_type" form:"time_type"` // 上下晚 123
- Status int8 `gorm:"column:status" json:"status" form:"status"`
- CreateTime int64 `gorm:"column:ctime" json:"-" form:"ctime"`
- ModifyTime int64 `gorm:"column:mtime" json:"-" form:"mtime"`
- IsExport int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
-
- Patient string `gorm:"-" json:"patient" form:"patient"`
- DeviceNumber VMDeviceNumber `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:DeviceNumberID;"`
-
- PatientInfectiousDiseases []*models.InfectiousDiseases `json:"patient_contagions" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
- }
-
- func (VMPatientScheduleTemplateItem) TableName() string {
- return "xt_patient_schedule_template_item"
- }
-
- func GetTemplateSchedualPatientsByKeywords(keywords string, org_id int64, template_id int64) (schedule []*VMPatientScheduleTemplateItem, err error) {
- likeKey := "%" + keywords + "%"
-
- err = readDb.
- Table("xt_patient_schedule_template_item as s").
- Preload("PatientInfectiousDiseases", "status = 1 ").
- Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
- return db.Where("org_id = ? AND status = 1", org_id).Preload("DeviceZone", "org_id = ? AND status = 1", org_id)
- }).
- Joins("JOIN xt_patients as p ON p.id = s.patient_id AND (p.name LIKE ? OR p.dialysis_no LIKE ?)", likeKey, likeKey).
- Where("s.template_id = ? AND s.org_id=? and s.status=1", template_id, org_id).
- Select("s.id, s.org_id, s.template_id, s.device_number_id, s.patient_id, s.treat_mode, s.weekday, s.time_type, s.status, s.ctime, s.mtime, p.name as patient").
- Order("weekday asc").
- Find(&schedule).Error
- return
-
- }
-
- func UpdateNewScheduleTemplateStatus(id int64, org_id int64) (err error) {
- err = readDb.Model(&models.PatientScheduleTemplateItem{}).Where("org_id = ? AND id = ?", org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endtime int64, orgID int64, zone []string) (schedules []*models.WeekSchedule, err error) {
-
- db := readDb.Table("xt_schedule as s ").Where("s.status =1")
- if orgID > 0 {
- db = db.Where("s.user_org_id = ?", orgID)
- }
- if startime > 0 {
- db = db.Where("s.schedule_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("s.schedule_date <= ?", endtime)
- }
- if weektime > 0 {
- db = db.Where("s.schedule_type = ?", weektime)
- }
- if weektype > 0 {
- db = db.Where("s.schedule_week = ?", weektype)
- }
- if len(zone) > 0 {
- db = db.Where("s.partition_id in (?)", zone)
- }
- err = db.
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1").Order("id asc")
- }).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1").Order("id asc")
- }).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
- }).Preload("HisDoctorAdviceInfo", "status = 1").Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Select("s.id,s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("s.partition_id asc").
- Find(&schedules).Error
- return schedules, err
- }
-
- func GetThreeWeekList(startime int64, endtime int64, orgid int64, scheduletype int64, partionid int64) (schedule []*models.VmSchedule, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status =1")
- if startime > 0 {
- db = db.Where("x.schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.schedule_date <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if scheduletype > 0 {
- db = db.Where("x.schedule_type = ?", scheduletype)
- }
- if partionid > 0 {
- db = db.Where("x.partition_id = ?", partionid)
- }
- err = db.Select("x.schedule_date,x.schedule_type,x.schedule_week,x.bed_id,x.partition_id,t.name,n.number,z.name").Joins("left join xt_patients as t on t.id = x.patient_id and t.user_org_id = ? and t.status = 1", orgid).Joins("left join xt_device_zone as z on z.id = x.partition_id and z.org_id = ? and z.status =1", orgid).Joins("left join xt_device_number as n on n.id = x.bed_id and n.org_id = ? and n.status =1", orgid).Scan(&schedule).Error
-
- return schedule, err
- }
-
- func UpdatedDialysisPrescription(prescription *models.DialysisPrescription, recordDate int64, patientid int64, orgid int64) error {
-
- err := XTWriteDB().Model(&prescription).Where("record_date = ? and patient_id = ? and user_org_id = ?", recordDate, patientid, orgid).Update(map[string]interface{}{"mode_id": prescription.ModeId, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func GetWeekSchedules(orgid int64, startime int64, endtime int64) (scheudle []*models.XtSchedule, err error) {
-
- err = XTReadDB().Model(&scheudle).Where("user_org_id = ? and status = 1 and schedule_date>=? and schedule_date<=?", orgid, startime, endtime).Find(&scheudle).Error
- return scheudle, err
- }
-
- func GetLastWeekSchedule(orgid int64, startime int64, endtime int64) (*models.XtSchedule, error) {
- schedule := models.XtSchedule{}
- err := XTReadDB().Where("user_org_id = ? and status =1 and schedule_date>=? and schedule_date<=?", orgid, startime, endtime).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
- func AddPatientSchedule(schedule *models.XtSchedule) error {
- utx := XTWriteDB().Begin()
- err := utx.Create(&schedule).Error
- utx.Commit()
- return err
- }
-
- func UpdatePatientSchedule(orgid int64, startime int64, endtime int64) error {
-
- schedule := models.XtSchedule{}
- err := XTWriteDB().Model(&schedule).Where("user_org_id = ? and schedule_date>=? and schedule_date<=? and status =1", orgid, startime, endtime).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetSettingById(id int64) (*models.XtRemindPrintSetting, error) {
- setting := models.XtRemindPrintSetting{}
- err := XTReadDB().Model(&setting).Where("id = ? and status = 1", id).Find(&setting).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &setting, nil
- }
-
- func CreateSetting(setting *models.XtRemindPrintSetting) error {
-
- err := XTReadDB().Create(&setting).Error
- return err
- }
-
- func UpdatedRemindPrint(set *models.XtRemindPrintSetting, id int64) error {
-
- err := XTWriteDB().Model(&set).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"prescription_status": set.PrescriptionStatus, "week": set.Week, "name": set.Name, "zone": set.Zone, "classes": set.Classes, "number": set.Number, "mode": set.Mode, "dialyzers": set.Dialyzers, "perfusion_apparatus": set.PerfusionApparatus, "anticoagulant": set.Anticoagulant, "doctor_advice": set.DoctorAdvice, "anticoagulant_zongliang": set.AnticoagulantZongliang}).Error
- return err
- }
-
- func GetRemindPrintList(id int64) (models.XtRemindPrintSetting, error) {
-
- setting := models.XtRemindPrintSetting{}
- err := XTReadDB().Model(&setting).Where("user_org_id = ? and status =1", id).Find(&setting).Error
- return setting, err
- }
-
- func GetScheudleTemplateById(orgid int64) (*models.ScheduleTemplate, error) {
-
- schedule := models.ScheduleTemplate{}
- err := XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1", orgid).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func CreateXtscheduleTemplate(template *models.ScheduleTemplate) error {
-
- err := XTWriteDB().Create(&template).Error
- return err
- }
-
- func UpdateXtScheduleTemplate(template *models.ScheduleTemplate, orgid int64) error {
-
- err := XTWriteDB().Model(&template).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"template_id": template.TemplateId}).Error
- return err
- }
-
- func GetScheduleTemplate(orgid int64) (models.ScheduleTemplate, error) {
-
- template := models.ScheduleTemplate{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&template).Error
- return template, err
- }
-
- func GetDataPrintByOrgId(orgid int64) (*models.XtDataPrint, error) {
-
- dataPrint := models.XtDataPrint{}
-
- err := XTReadDB().Model(&dataPrint).Where("user_org_id = ? and status = 1", orgid).Find(&dataPrint).Error
-
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &dataPrint, nil
- }
-
- func CreateDataPrint(dataPrint *models.XtDataPrint) error {
-
- err := XTWriteDB().Create(&dataPrint).Error
- return err
- }
-
- func UpdteDataPrint(orgid int64, dataPrint *models.XtDataPrint) error {
-
- err := XTWriteDB().Model(&dataPrint).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"is_open": dataPrint.IsOpen}).Error
- return err
- }
-
- func GetDataPrint(orgid int64) (models.XtDataPrint, error) {
- dataPrint := models.XtDataPrint{}
- err := XTReadDB().Model(&dataPrint).Where("user_org_id = ? and status = 1", orgid).Find(&dataPrint).Error
- return dataPrint, err
- }
|