123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929 |
- // 统计后台的 service
-
- package service
-
- import (
- "Data_Upload_Api/models"
- "Data_Upload_Api/models/sz"
-
- "github.com/jinzhu/gorm"
- "strings"
- )
-
- func GetSyncTimeByOrgId(org_id int64, sync_type int64) (sync_info models.XTSyncInfo, err error) {
- err = readDb.Model(&models.XTSyncInfo{}).Where("org_id = ? and sync_type = ? ", org_id, sync_type).Last(&sync_info).Error
- return
- }
-
- func FindAllDataUploadConfigOrgInfo(province_id int64, city_id int64, config_type int64) (data []*sz.DataUploadConfig, err error) {
- err = readDb.Model(&sz.DataUploadConfig{}).Where("status = 1 AND province_id = ? AND city_id = ? AND config_type = ?", province_id, city_id, config_type).Find(&data).Error
- return
- }
-
- func FindDataUploadOrgInfo(org_id int64, module_type int64) (data sz.DataUpload, err error) {
- err = readDb.Model(&sz.DataUpload{}).Where(" org_id = ? AND module_type = ?", org_id, module_type).Last(&data).Error
- return
- }
-
- func FindOrgData(org_id int64, sync_time int64) (org models.UserOrg, err error) {
- err = readUserDb.Model(&models.UserOrg{}).Where("status = 1 AND id = ? AND ctime > ?", org_id, sync_time).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
- return readDb.Where("status = 1")
- }).Find(&org).Error
- return
- }
- func FindOrgRolesData(org_id int64, lastUploadTime int64, nowTime int64) (role []*models.UserAdminRole, err error) {
- db := readUserDb.Model(&models.UserAdminRole{}).Where("status = 1 AND org_id = ? ", org_id)
- db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
- err = db.Find(&role).Error
- return
- }
- func FindOrgPatientData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
- db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", org_id)
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- err = db.Find(&patient).Error
-
- return
- }
-
- func FindOrgPatientInfectious(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
- db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND lapseto = 2 ", org_id).Preload("InfectiousDiseases", "status = 1")
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- err = db.Find(&patient).Error
- return
- }
-
- func FindOrgDeviceNumber(org_id int64, lastUploadTime int64, nowTime int64) (devices []*models.DeviceNumber, err error) {
- db := readDb.Model(&models.DeviceNumber{}).Where("status = 1 AND org_id = ?", org_id)
- db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
- err = db.Find(&devices).Error
-
- return
- }
-
- func FindOrgPatientOutData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
- db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND lapseto = 2 ", org_id).Preload("PatientLapseto", "status = 1")
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- err = db.Find(&patient).Error
- return
- }
-
- func FindOrgScheduleData(org_id int64, lastUploadTime int64, nowTime int64) (sch []*models.Schedule, err error) {
- db := readDb.Model(&models.Schedule{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DeviceNumber", "status = 1")
-
- if lastUploadTime != 0 && nowTime != 0 {
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- }
- err = db.Find(&sch).Error
- return
- }
-
- func FindOrgDialysisPrescriptionData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.DialysisPrescription, err error) {
- db := readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DialysisOrder", "status = 1")
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- err = db.Find(&ps).Error
- return
- }
-
- func FindOrgDoctorAdviceTemplateData(org_id int64, lastUploadTime int64, nowTime int64) (advice []*models.DoctorAdviceTemplate, err error) {
- db := readDb.Model(&models.DoctorAdviceTemplate{}).Where("status = 1 AND org_id = ? and advice_type = 0 ", org_id)
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- err = db.Find(&advice).Error
- return
- }
-
- func FindAssessmentBeforeDislysis(org_id int64, patient_id int64) (before models.AssessmentBeforeDislysis, err error) {
- db := readDb.Model(&models.AssessmentBeforeDislysis{}).Where("status = 1 AND user_org_id = ? and patient_id = ? ", org_id,patient_id)
- err = db.Last(&before).Error
- return
- }
-
- func FindOrgMonitorRecordData(org_id int64, lastUploadTime int64, nowTime int64) (monitor []*models.MonitoringRecord, err error) {
- db := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DialysisOrder", "status = 1")
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- err = db.Find(&monitor).Error
- return
- }
-
- func FindOrgMonitorRecordByLike(org_id int64, keyword string, lastUploadTime int64, nowTime int64) (monitor []*models.MonitoringRecord, err error) {
- db := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND symptom like ?", org_id,keyword)
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- err = db.Find(&monitor).Error
- return
- }
-
- func FindOrgInspection(org_id int64, lastUploadTime int64, nowTime int64) (inspection []*models.XtInspection, err error) {
- db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? ", org_id).Preload("Patients", "status = 1")
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- err = db.Find(&inspection).Error
- return
- }
-
- func FindOrgInspectionReference(org_id int64, lastUploadTime int64, nowTime int64) (inspection []*models.XtInspection, err error) {
- db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? ", org_id).Preload("XtInspectionReference", "status = 1")
- db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
- err = db.Find(&inspection).Error
- return
- }
-
- func CreateOrgRecord(rdb *gorm.DB, hospital *sz.TempHdHospital) (err error) {
- err = rdb.Model(&sz.TempHdHospital{}).Create(&hospital).Error
- return
- }
-
- func CreateUploadRecord(upload *sz.DataUpload) (err error) {
- err = writeDb.Model(&sz.DataUpload{}).Create(&upload).Error
- return
- }
-
- func FindOrgDialysisData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.VMDialysisOrder, err error) {
- db := readDb.Model(&models.VMDialysisOrder{}).Where("status = 1 AND user_org_id = ? AND stage = 2 ", org_id).
- Preload("DeviceNumber", "status = 1").
- Preload("VMDialysisPrescription", "status = 1").
- Preload("AssessmentBeforeDislysis", "status = 1").
- Preload("AssessmentAfterDislysis", "status = 1").
- Preload("Schedule", "status = 1").
- Preload("MonitoringRecord", "status = 1")
-
- if lastUploadTime != 0 && nowTime != 0 {
- db = db.Where("updated_time >= ? AND updated_time <= ?", lastUploadTime, nowTime)
- }
- err = db.Find(&ps).Error
- return
- }
- func FindOrgDeviceZoneRecordData(org_id int64, lastUploadTime int64, nowTime int64) (zone []*models.DeviceZone, err error) {
- db := readDb.Model(&models.DeviceZone{}).Where("status = 1 AND org_id = ?", org_id)
- if lastUploadTime != 0 && nowTime != 0 {
- db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
- }
- err = db.Find(&zone).Error
-
- return
- }
-
- func FindOrgWaterMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
-
- db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ? AND device_type = 2", org_id)
-
- db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
-
- err = db.Find(&waterMachine).Error
-
- return
- }
-
- func BatchCreateWMsRecord(wms []*sz.TempHdWm, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
- thisSQL := "INSERT INTO t_hd_wm (hospital_id, equipment_id, equipment_brand, equipment_model, enable_time,discarded_time,equipment_type,xgbz,create_time,update_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, wm := range wms {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.EquipmentId)
- insertData = append(insertData, wm.EquipmentBrand)
- insertData = append(insertData, wm.EquipmentModel)
- insertData = append(insertData, wm.EnableTime)
- insertData = append(insertData, wm.DiscardedTime)
- insertData = append(insertData, wm.EquipmentType)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.UpdateTime)
- insertData = append(insertData, wm.Sjscsj)
-
- }
- thisSQL += strings.Join(insertParams, ", ")
- // err = utx.Exec(thisSQL, insertData...).Error
- // if err != nil {
- // utx.Rollback()
- // return
- // }
- utx.Exec(thisSQL, insertData...)
- }
- utx.Commit()
- }
- return
- }
-
- func BatchCreateStaffRecord(staffs []*sz.TempHdStaff, rdb *gorm.DB) (err error) {
- if len(staffs) > 0 {
- utx := rdb
- if len(staffs) > 0 {
- id_no := 429001198701091670
- for _, info := range staffs {
- thisSQL := "INSERT INTO t_hd_staff (hospital_id,staff_id, id_no,id_type,staff_name, position, staff_status, staff_no, permanent_type, in_date ,create_time, update_time, sjscsj, xgbz) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
-
- insertData = append(insertData, info.HospitalId)
- insertData = append(insertData, info.StaffId)
- insertData = append(insertData, id_no)
- insertData = append(insertData, "01")
- insertData = append(insertData, info.StaffName)
- insertData = append(insertData, info.Position)
- insertData = append(insertData, "0")
- insertData = append(insertData, info.StaffId)
- insertData = append(insertData, info.PermanentType)
- insertData = append(insertData, "2019-09-01")
- insertData = append(insertData, info.CreateTime)
- insertData = append(insertData, info.UpdateTime)
- insertData = append(insertData, info.Sjscsj)
- insertData = append(insertData, info.Xgbz)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- id_no++
- }
-
- }
- // utx.Commit()
- }
- return
- }
-
- func BatchCreatePatinet(patients []*sz.TempHdPatient, rdb *gorm.DB) (err error) {
- if len(patients) > 0 {
- utx := rdb
- if len(patients) > 0 {
-
- for _, info := range patients {
- thisSQL := "INSERT INTO t_hd_patient ( hospital_id, patient_nk, card_no, card_type, id_no, id_type, patient_name, gender, born_date, diagnosis_summary, is_crf, pay_method, local_insurance, dialysis_start_time, local_start_time, outpatient_no, hospitalized_no, xgbz, create_time, update_time, sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.HospitalId)
- insertData = append(insertData, info.PatientNk)
- insertData = append(insertData, info.CardNo)
- insertData = append(insertData, info.CardType)
- insertData = append(insertData, info.IdNo)
- insertData = append(insertData, info.IdType)
- insertData = append(insertData, info.PatientName)
- insertData = append(insertData, info.Gender)
- insertData = append(insertData, info.BornDate)
- insertData = append(insertData, info.DiagnosisSummary)
- insertData = append(insertData, info.IsCrf)
- insertData = append(insertData, "02")
- insertData = append(insertData, "1")
- insertData = append(insertData, info.DialysisStartTime)
- insertData = append(insertData, info.LocalStartTime)
- insertData = append(insertData, info.OutpatientNo)
- insertData = append(insertData, info.HospitalizedNo)
- insertData = append(insertData, info.Xgbz)
- insertData = append(insertData, info.CreateTime)
- insertData = append(insertData, info.UpdateTime)
- insertData = append(insertData, info.Sjscsj)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
-
-
-
- }
- // utx.Commit()
- }
- return
- }
-
- func BatchCreateSchedual(patients []*sz.TempHdShift, rdb *gorm.DB) (err error) {
- if len(patients) > 0 {
- utx := rdb
- if len(patients) > 0 {
- for _, info := range patients {
- thisSQL := "INSERT INTO t_hd_shift (ps_id, hospital_id, patient_nk, schedule_date, shift_type,sickbed_no,schedule_status,create_time,sjscsj,xgbz) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.PsId)
- insertData = append(insertData, info.HospitalId)
- insertData = append(insertData, info.PatientNk)
- insertData = append(insertData, info.ScheduleDate)
- insertData = append(insertData, info.ShiftType)
- insertData = append(insertData, info.SickbedNo)
- insertData = append(insertData, info.ScheduleStatus)
- insertData = append(insertData, info.CreateTime)
- insertData = append(insertData, info.Sjscsj)
- insertData = append(insertData, info.Xgbz)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
-
-
- }
- // utx.Commit()
- }
- return
- }
-
- func BatchCreatePs(patients []*sz.TempHdPs, rdb *gorm.DB) (err error) {
- if len(patients) > 0 {
- utx := rdb
- if len(patients) > 0 {
- thisSQL := "INSERT INTO t_hd_ps (prescribe_id,hospital_id,patient_nk,rrt_type,rrt_type_name,dialysis_frequency,frequency_unit,prescribe_time,create_time,sjscsj,xgbz) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range patients {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.PrescribeId)
- insertData = append(insertData, info.HospitalId)
- insertData = append(insertData, info.PatientNk)
- insertData = append(insertData, info.RrtType)
- insertData = append(insertData, info.RrtTypeName)
- insertData = append(insertData, info.DialysisFrequency)
- insertData = append(insertData, info.FrequencyUnit)
- insertData = append(insertData, info.PrescribeTime)
- insertData = append(insertData, info.CreateTime)
- insertData = append(insertData, info.Sjscsj)
- insertData = append(insertData, info.Xgbz)
-
-
- }
- thisSQL += strings.Join(insertParams, ", ")
- // err = utx.Exec(thisSQL, insertData...).Error
- // if err != nil {
- // utx.Rollback()
- // return
- // }
- utx.Exec(thisSQL, insertData...)
- }
- // utx.Commit()
- }
- return
- }
-
- func BatchCreatePsOther(ps *sz.TempHdPs, rdb *gorm.DB)(err error){
- err = rdb.Create(&ps).Error
- return err
- }
-
- func BatchCreatePsm(psms []*sz.TempHdPsMedicine, rdb *gorm.DB) (err error) {
- if len(psms) > 0 {
- utx := rdb
- if len(psms) > 0 {
-
- for _, psm := range psms {
- thisSQL := "INSERT INTO t_hd_ps_medicine (hospital_id, medicine_type_id,medicine_id,create_time,sjscsj,xgbz,sn) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
- insertData = append(insertData, psm.HospitalId)
- insertData = append(insertData, psm.MedicineTypeId)
- insertData = append(insertData, psm.MedicineId)
- insertData = append(insertData, psm.CreateTime)
- insertData = append(insertData, psm.Sjscsj)
- insertData = append(insertData, psm.Xgbz)
- insertData = append(insertData, psm.Sn)
- thisSQL += strings.Join(insertParams, ", ")
- // err = utx.Exec(thisSQL, insertData...).Error
- utx.Exec(thisSQL, insertData...)
- }
-
- // if err != nil {
- // utx.Rollback()
- // return
- // }
- }
- // utx.Commit()
- }
- return
- }
-
- func BatchCreateDialysis(psms []*sz.TempHdDialysis, rdb *gorm.DB) (err error) {
- if len(psms) > 0 {
- utx := rdb
- if len(psms) > 0 {
-
- for _, psm := range psms {
- thisSQL := "INSERT INTO t_hd_dialysis (dialysis_id,hospital_id,patient_nk,ps_id,dialysis_date,sickbed_no,division_id,equipment_id,mix_dialysis,ufv,total_treat_duration,is_hospitalization,is_emergency,is_perioperative_period,before_sbp,before_dbp,after_sbp,after_dbp,before_weight,after_weight,up_nurse_id,down_nurse_id,check_nurse_id,puncture_nurse_id,start_time,end_time,create_time,sjscsj,xgbz) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, psm.DialysisId)
- insertData = append(insertData, psm.HospitalId)
- insertData = append(insertData, psm.PatientNk)
- insertData = append(insertData, psm.PsId)
- insertData = append(insertData, psm.DialysisDate)
- insertData = append(insertData, psm.SickbedNo)
- insertData = append(insertData, psm.DivisionId)
- insertData = append(insertData, psm.EquipmentId)
- insertData = append(insertData, psm.MixDialysis)
- insertData = append(insertData, psm.Ufv)
- insertData = append(insertData, psm.TotalTreatDuration)
- insertData = append(insertData, psm.IsHospitalization)
- insertData = append(insertData, psm.IsEmergency)
- insertData = append(insertData, psm.IsPerioperativePeriod)
- insertData = append(insertData, psm.BeforeSbp)
- insertData = append(insertData, psm.BeforeDbp)
- insertData = append(insertData, psm.AfterSbp)
- insertData = append(insertData, psm.AfterDbp)
- insertData = append(insertData, psm.BeforeWeight)
- insertData = append(insertData, psm.AfterWeight)
- insertData = append(insertData, psm.UpNurseId)
- insertData = append(insertData, psm.DownNurseId)
- insertData = append(insertData, psm.CheckNurseId)
- insertData = append(insertData, psm.PunctureNurseId)
- insertData = append(insertData, psm.StartTime)
- insertData = append(insertData, psm.EndTime)
- insertData = append(insertData, psm.CreateTime)
- insertData = append(insertData, psm.Sjscsj)
- insertData = append(insertData, psm.Xgbz)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
-
- }
-
- // if err != nil {
- // utx.Rollback()
- // return
- // }
- }
- // utx.Commit()
- }
- return
- }
-
- func BatchCreatePatientOut(patientOuts []*sz.TempHdPatientOut, rdb *gorm.DB) (err error) {
- if len(patientOuts) > 0 {
- utx := rdb
- if len(patientOuts) > 0 {
- thisSQL := "INSERT INTO t_hd_patient_quit (sn,hospital_id,patient_nk,sequelae_date,sequelae_type,create_time,death_reason,ext_reason,sjscsj,xgbz) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, out := range patientOuts {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, out.Sn)
- insertData = append(insertData, out.HospitalId)
- insertData = append(insertData, out.PatientNk)
- insertData = append(insertData, out.SequelaeDate)
- insertData = append(insertData, out.SequelaeType)
- insertData = append(insertData, out.CreateTime)
- insertData = append(insertData, out.DeathReason)
- insertData = append(insertData, out.ExtReason)
- insertData = append(insertData, out.Sjscsj)
- insertData = append(insertData, out.Xgbz)
-
- }
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- // if err != nil {
- // utx.Rollback()
- // return
- // }
- }
- // utx.Commit()
- }
- return
- }
-
- func BatchCreateDoctorsAdvice(advices []*sz.TempHdDoctorsAdvice, rdb *gorm.DB) (err error) {
- if len(advices) > 0 {
- utx := rdb
- if len(advices) > 0 {
- for _, advice := range advices {
- thisSQL := "INSERT INTO t_hd_doctors_advice (medical_order_id, hospital_id,dialysis_id,order_type,patient_nk,dialysis_duration,blood_vol,anticoagulant,create_time,sjscsj,xgbz,rrt_type,rrt_type_name,dry_weight) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, advice.MedicalOrderId)
- insertData = append(insertData, advice.HospitalId)
- insertData = append(insertData, advice.DialysisId)
- insertData = append(insertData, advice.OrderType)
- insertData = append(insertData, advice.PatientNk)
- insertData = append(insertData, advice.DialysisDuration)
- insertData = append(insertData, advice.BloodVol)
- insertData = append(insertData, advice.Anticoagulant)
- insertData = append(insertData, advice.CreateTime)
- insertData = append(insertData, advice.Sjscsj)
- insertData = append(insertData, advice.Xgbz)
- insertData = append(insertData, advice.RrtType)
- insertData = append(insertData, advice.RrtTypeName)
- insertData = append(insertData, advice.DryWeight)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
- // if err != nil {
- // utx.Rollback()
- // return
- // }
- }
- // utx.Commit()
- }
- return
- }
-
- func BatchCreateMonitor(advices []*sz.TempHdMiddle, rdb *gorm.DB) (err error) {
- if len(advices) > 0 {
- utx := rdb
- if len(advices) > 0 {
-
- for _, advice := range advices {
- thisSQL := "INSERT INTO t_hd_middle (sn,hospital_id, patient_nk,dialysis_id,monitor_time,sbp,dbp,create_time,sjscsj,xgbz) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, advice.Sn)
- insertData = append(insertData, advice.HospitalId)
- insertData = append(insertData, advice.PatientNk)
- insertData = append(insertData, advice.DialysisId)
- insertData = append(insertData, advice.MonitorTime)
- insertData = append(insertData, advice.Sbp)
- insertData = append(insertData, advice.Dbp)
- insertData = append(insertData, advice.CreateTime)
- insertData = append(insertData, advice.Sjscsj)
- insertData = append(insertData, advice.Xgbz)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
-
- // if err != nil {
- // utx.Rollback()
- // return
- // }
- }
- // utx.Commit()
- }
- return
- }
-
- func FindOrgOtherMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
-
- db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ? AND (device_type = 1 OR device_type = 3)", org_id)
-
- db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
-
- err = db.Find(&waterMachine).Error
-
- return
- }
-
- func FindOrgMachineRepairData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.DeviceRepair, err error) {
- db := readUserDb.Model(&models.DeviceRepair{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("VMDeviceAddmacher", "status = 1")
- db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
- err = db.Find(&waterMachine).Error
- return
- }
-
- func BatchCreateOtherMachineRecord(wms []*sz.TempHdOtherMachine, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
-
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_other_machine (hospital_id, equipment_id, equipment_brand, equipment_model, enable_time,status,equipment_type,xgbz,create_time,update_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.EquipmentId)
- insertData = append(insertData, wm.EquipmentBrand)
- insertData = append(insertData, wm.EquipmentModel)
- insertData = append(insertData, wm.EnableTime)
- insertData = append(insertData, wm.Status)
- insertData = append(insertData, wm.EquipmentType)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.UpdateTime)
- insertData = append(insertData, wm.Sjscsj)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
-
- }
- // utx.Commit()
- }
- return
- }
-
- func BatchCreateMainTain(maintain []*sz.TempHdMaintain, rdb *gorm.DB) (err error) {
- if len(maintain) > 0 {
- utx := rdb
- if len(maintain) > 0 {
- thisSQL := "INSERT INTO t_hd_maintain (hospital_id, equipment_id, equipment_type, repair_time, xgbz,create_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, wm := range maintain {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.EquipmentId)
- insertData = append(insertData, wm.EquipmentType)
- insertData = append(insertData, wm.RepairTime)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.Sjscsj)
- }
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- // if err != nil {
- // utx.Rollback()
- // return
- // }
- }
- // utx.Commit()
- }
- return
- }
-
- func FindOrgMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
- db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DeviceNumber",func(db *gorm.DB) *gorm.DB {
- return readDb.Model(&models.DeviceNumber{}).Where("status = 1")
- } )
-
- db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
-
- err = db.Find(&waterMachine).Error
-
- return
- }
-
- func BatchCreateHDMRecord(wms []*sz.TempHdDm, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
-
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_dm (hospital_id, equipment_id,sickbed_no,sickbed_type ,equipment_brand, equipment_model, enable_time,status,equipment_type, xgbz,bbp,create_time,update_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.EquipmentId)
- insertData = append(insertData, wm.SickbedNo)
- insertData = append(insertData, wm.SickbedType)
- insertData = append(insertData, wm.EquipmentBrand)
- insertData = append(insertData, wm.EquipmentModel)
- insertData = append(insertData, wm.EnableTime)
- insertData = append(insertData, wm.Status)
- insertData = append(insertData, wm.EquipmentType)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.Bbp)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.UpdateTime)
- insertData = append(insertData, wm.Sjscsj)
-
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
-
- // if err != nil {
- // utx.Rollback()
- // return
- // }
- }
- // utx.Commit()
- }
- return
- }
-
-
- func CreateHDDivision(wms []*sz.TempHdDivision, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_division (division_id,hospital_id, division_name,division_type, xgbz,create_time,update_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.DivisionId)
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.DivisionName)
- insertData = append(insertData, wm.DivisionType)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.UpdateTime)
- insertData = append(insertData, wm.Sjscsj)
-
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
-
- }
- }
- return
- }
-
- func CreateAccess(wms []*sz.TempHdAccess, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_access (access_id,hospital_id,patient_nk,access_type,access_type_name,access_status,setup_date,first_use_time,xgbz,create_time,update_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.AccessId)
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.PatientNk)
- insertData = append(insertData, wm.AccessType)
- insertData = append(insertData, wm.AccessTypeName)
- insertData = append(insertData, wm.AccessStatus)
- insertData = append(insertData, wm.SetupDate)
- insertData = append(insertData, wm.FirstUseTime)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.UpdateTime)
- insertData = append(insertData, wm.Sjscsj)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
- }
- }
- return
- }
-
- func CreateSickbed(wms []*sz.TempHdSickbed, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_sickbed (sickbed_no,hospital_id,division_id,sickbed_code,sickbed_type,xgbz,create_time,update_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.SickbedNo)
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.DivisionId)
- insertData = append(insertData, wm.SickbedCode)
- insertData = append(insertData, wm.SickbedType)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.UpdateTime)
- insertData = append(insertData, wm.Sjscsj)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
- }
- }
- return
- }
-
- func CreateDiagnosis(wms []*sz.TempHdDiagnosis, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_diagnosis (diagnosis_id,hospital_id,patient_nk,diagnosis_time,diagnosis_type,diagnosis_type_item,diagnosis_type_detail,xgbz,create_time,update_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.DiagnosisId)
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.PatientNk)
- insertData = append(insertData, wm.DiagnosisTime)
- insertData = append(insertData, wm.DiagnosisType)
- insertData = append(insertData, wm.DiagnosisTypeItem)
- insertData = append(insertData, wm.DiagnosisTypeDetail)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.UpdateTime)
- insertData = append(insertData, wm.Sjscsj)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
- }
- }
- return
- }
-
-
- func CreateInfection(wms []*sz.TempHdInfection, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_infection (sn,hospital_id,patient_nk,hbv,hcv,rpr,hiv,hbsag,hbsab,hbeag,hbeab,hbcab,check_date,doctor_id,xgbz,create_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.Sn)
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.PatientNk)
- insertData = append(insertData, wm.Hbv)
- insertData = append(insertData, wm.Hcv)
- insertData = append(insertData, wm.Rpr)
- insertData = append(insertData, wm.Hiv)
- insertData = append(insertData, wm.Hbsag)
- insertData = append(insertData, wm.Hbsab)
- insertData = append(insertData, wm.Hbeag)
- insertData = append(insertData, wm.Hbeab)
- insertData = append(insertData, wm.Hbcab)
- insertData = append(insertData, wm.CheckDate)
- insertData = append(insertData, wm.DoctorId)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.Sjscsj)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
- }
- }
- return
- }
-
- func CreateComplication(wms []*sz.TempHdComplication, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_complication (sn,hospital_id,patient_nk,dialysis_id,monitor_id,neopathy_time,neopathy_type,neopathy_desc,xgbz,create_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.Sn)
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.PatientNk)
- insertData = append(insertData, wm.DialysisId)
- insertData = append(insertData, wm.MonitorId)
- insertData = append(insertData, wm.NeopathyTime)
- insertData = append(insertData, wm.NeopathyType)
- insertData = append(insertData, wm.NeopathyDesc)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.Sjscsj)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
- }
- }
- return
- }
-
- func CreateLisReport(wms []*sz.TempHdLisReport, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_lis_report (lab_sno,hospital_id,patient_nk,report_date,check_date,jz_no,mz_flag,zy_no,mz_no,department_code,department_name,card_no,card_type,patient_name,dep_code,dep_name,inspected_type,report_categry,application_name,application_type,check_name,check_item_name,check_item_code,record_ccount,check_result,diagnose_name,xgbz,create_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.LabSno)
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.PatientNk)
- insertData = append(insertData, wm.ReportDate)
- insertData = append(insertData, wm.CheckDate)
- insertData = append(insertData, wm.JzNo)
- insertData = append(insertData, wm.MzFlag)
- insertData = append(insertData, wm.ZyNo)
- insertData = append(insertData, wm.MzNo)
- insertData = append(insertData, wm.DepartmentCode)
- insertData = append(insertData, wm.DepartmentName)
- insertData = append(insertData, wm.CardNo)
- insertData = append(insertData, wm.CardType)
- insertData = append(insertData, wm.PatientName)
- insertData = append(insertData, wm.DepCode)
- insertData = append(insertData, wm.DepName)
- insertData = append(insertData, wm.InspectedType)
- insertData = append(insertData, wm.ReportCategry)
- insertData = append(insertData, wm.ApplicationName)
- insertData = append(insertData, wm.ApplicationType)
- insertData = append(insertData, wm.CheckName)
- insertData = append(insertData, wm.CheckItemName)
- insertData = append(insertData, wm.CheckItemCode)
- insertData = append(insertData, wm.RecordCcount)
- insertData = append(insertData, wm.CheckResult)
- insertData = append(insertData, wm.DiagnoseName)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.Sjscsj)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
- }
- }
- return
- }
-
- func CreateLisIndicators(wms []*sz.TempHdLisIndicators, rdb *gorm.DB) (err error) {
- if len(wms) > 0 {
- utx := rdb
- if len(wms) > 0 {
- for _, wm := range wms {
- thisSQL := "INSERT INTO t_hd_lis_indicators (inspected_result_no,hospital_id,lab_sno,report_date,check_date,inspected_indicate,inspected_item_en_name,inspected_item_cn_name,inspected_result_desc,inspected_result_value,inspected_result_unit,ref_range,unit_type,inspected_result,xgbz,create_time,sjscsj) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, wm.InspectedResultNo)
- insertData = append(insertData, wm.HospitalId)
- insertData = append(insertData, wm.LabSno)
- insertData = append(insertData, wm.ReportDate)
- insertData = append(insertData, wm.CheckDate)
- insertData = append(insertData, wm.InspectedIndicate)
- insertData = append(insertData, wm.InspectedItemEnName)
- insertData = append(insertData, wm.InspectedItemCnName)
- insertData = append(insertData, wm.InspectedResultDesc)
- insertData = append(insertData, wm.InspectedResultValue)
- insertData = append(insertData, wm.InspectedResultUnit)
- insertData = append(insertData, wm.RefRange)
- insertData = append(insertData, wm.UnitType)
- insertData = append(insertData, wm.InspectedResult)
- insertData = append(insertData, wm.Xgbz)
- insertData = append(insertData, wm.CreateTime)
- insertData = append(insertData, wm.Sjscsj)
- thisSQL += strings.Join(insertParams, ", ")
- utx.Exec(thisSQL, insertData...)
- }
- }
- }
- return
- }
|