manage_service.go 58KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. package service
  2. import (
  3. "Xcx_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strings"
  7. "time"
  8. )
  9. func GetEquitmentName(unit_type string, orgid int64) (*models.DeviceEquimentname, error) {
  10. var equimentname models.DeviceEquimentname
  11. var err error
  12. err = UserReadDB().Model(&equimentname).Where("equitment_name = ? and user_org_id = ? and status = 1", unit_type, orgid).Find(&equimentname).Error
  13. if err == gorm.ErrRecordNotFound {
  14. return nil, err
  15. }
  16. if err != nil {
  17. return nil, err
  18. }
  19. return &equimentname, nil
  20. }
  21. func CreateEquimentName(equimentname models.DeviceEquimentname) error {
  22. //err := XTWriteDB().Create(&equimentname).Error
  23. //return err
  24. err := writeUserDb.Create(&equimentname).Error
  25. return err
  26. }
  27. func GetEquitmentByBedID(bedid int64, orgid int64) (models.DeviceAddmacher, error) {
  28. addmacher := models.DeviceAddmacher{}
  29. err := UserReadDB().Model(&addmacher).Where("bed_id = ? and user_org_id = ? and status = 1", bedid, orgid).First(&addmacher).Error
  30. return addmacher, err
  31. }
  32. func CreateMacher(machers *models.DeviceAddmacher) error {
  33. //err := writeDb.Create(&machers).Error
  34. //xt := writeDb.Begin()
  35. // //fmt.Println("hhhhhhhh",xt)
  36. // //err := xt.Model(&models.DeviceAddmacher{}).Create(machers).Error
  37. // //fmt.Println("err",err)
  38. // //if err !=nil{
  39. // // xt.Rollback()
  40. // //}
  41. // //xt.Commit()
  42. // //return err
  43. err := writeUserDb.Create(&machers).Error
  44. return err
  45. }
  46. func UpdateMachine(id int64, orgid int64, addmacher *models.DeviceAddmacher) error {
  47. err := writeUserDb.Model(&addmacher).Where("id = ? AND user_org_id = ? AND status = ?", id, orgid, 1).Updates(map[string]interface{}{"serial_number": addmacher.SerialNumber, "device_type": addmacher.DeviceType, "bed_number": addmacher.BedNumber, "device_name": addmacher.DeviceName, "manufacture_factory": addmacher.ManufactureFactory, "service_manufacturer": addmacher.ServiceManufacturer, "unit_type": addmacher.UnitType, "use_section": addmacher.UseSection, "section_number": addmacher.SectionNumber, "buy_date": addmacher.BuyDate, "install_date": addmacher.InstallDate, "start_date": addmacher.StartDate, "maintenace_engineer": addmacher.MaintenaceEngineer, "telephone": addmacher.Telephone, "guarantee_date": addmacher.GuaranteeDate, "machine_status": addmacher.MachineStatus, "user_total": addmacher.UserTotal, "remarks": addmacher.Remarks, "rubbish_date": addmacher.RubbishDate, "rubbish_reason": addmacher.RubbishReason, "user_year": addmacher.UserYear, "work_time": addmacher.WorkTime, "bed_id": addmacher.BedId, "disinfection_mode": addmacher.DisinfectionMode, "revers_mode": addmacher.ReversMode, "mtime": time.Now().Unix()}).Error
  48. return err
  49. }
  50. func GetZoneName(zoneid int64, orgid int64) (models.DeviceZone, error) {
  51. zone := models.DeviceZone{}
  52. err := XTReadDB().Where("id = ? AND org_id = ?", zoneid, orgid).Find(&zone).Error
  53. return zone, err
  54. }
  55. func UpdateTreatMode(id int64, orgid int64, treatmodes []int64) (err error) {
  56. utx := XTWriteDB().Begin()
  57. err = utx.Model(models.DeviceTreatmentmode{}).Where("machine_id = ? AND user_org_id = ?", id, orgid).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
  58. fmt.Println("错误是什么", err)
  59. if err != nil {
  60. utx.Rollback()
  61. return
  62. }
  63. if len(treatmodes) > 0 {
  64. thisSQL := "INSERT INTO xt_device_treatmentmode(machine_id,treate_mode,status,ctime,user_org_id) VALUES "
  65. insertParams := make([]string, 0)
  66. insertData := make([]interface{}, 0)
  67. for _, treatmode := range treatmodes {
  68. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  69. insertData = append(insertData, id)
  70. insertData = append(insertData, treatmode)
  71. insertData = append(insertData, 1)
  72. insertData = append(insertData, time.Now().Unix())
  73. insertData = append(insertData, orgid)
  74. }
  75. thisSQL += strings.Join(insertParams, ",")
  76. err = utx.Exec(thisSQL, insertData...).Error
  77. if err != nil {
  78. utx.Rollback()
  79. return
  80. }
  81. }
  82. utx.Commit()
  83. return
  84. }
  85. func GetAllEquimentName(orgid int64) (equit []*models.DeviceEquimentname, err error) {
  86. err = readUserDb.Model(&equit).Where("user_org_id = ? AND status = ?", orgid, 1).Group("equitment_name").Find(&equit).Error
  87. return equit, err
  88. }
  89. func GetBed(equitid int64) (models.DeviceAddmacher, error) {
  90. addmacher := models.DeviceAddmacher{}
  91. err := UserReadDB().Where("id=? AND status = ?", equitid, 1).Find(&addmacher).Error
  92. return addmacher, err
  93. }
  94. func QueryPlan(orgid int64, devicetype int64, ids []int64, classids []int64, equitid int64) (*models.DevicePlan, error) {
  95. var pre models.DevicePlan
  96. var err error
  97. //for _, id := range ids {
  98. // for _, classids := range classids {
  99. // err = UserReadDB().Model(&pre).Where("user_org_id = ? AND device_type = ? AND time = ? AND classtime = ? AND equiment_id = ? AND status = 1", orgid, devicetype, id, classids, equitid).Find(&pre).Error
  100. // }
  101. //}
  102. //if err == gorm.ErrRecordNotFound {
  103. // return nil, err
  104. //}
  105. //if err != nil {
  106. // return nil, err
  107. //}
  108. //return &pre, nil
  109. if len(ids) == 1 && len(classids) == 1 {
  110. err = UserWriteDB().Model(&models.DevicePlan{}).Where("user_org_id = ? and device_type = ? and time = ? and classtime = ? and status = 1 ", orgid, devicetype, ids[0], classids[0]).Find(&pre).Error
  111. if err == gorm.ErrRecordNotFound {
  112. return nil, err
  113. }
  114. if err != nil {
  115. return nil, err
  116. }
  117. } else {
  118. err = UserWriteDB().Model(models.DevicePlan{}).Where("time IN(?) and user_org_id = ? and device_type = ? AND classtime IN(?) and status = 1", ids, orgid, devicetype, classids).Find(&pre).Error
  119. if err == gorm.ErrRecordNotFound {
  120. return nil, err
  121. }
  122. if err != nil {
  123. return nil, err
  124. }
  125. }
  126. return &pre, nil
  127. }
  128. func AddPlan(orgid int64, deviceType int64, disinfecTime string, ids []int64, classids []int64, way int64, machinedisinfectant int64, disinfectantway int64, disinfectant int64, equimentid int64, bedid int64) (err error) {
  129. xt := UserWriteDB().Begin()
  130. if len(ids) > 0 {
  131. thisSQL := "INSERT INTO xt_device_plan(device_type,disinfec_time,time,classtime,way,machine_disinfectant,disinfectan_way,disinfectant,status,ctime,user_org_id,equiment_id,bed_id) VALUES "
  132. insertParams := make([]string, 0)
  133. insertData := make([]interface{}, 0)
  134. for _, id := range ids {
  135. for _, classids := range classids {
  136. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  137. insertData = append(insertData, deviceType)
  138. insertData = append(insertData, disinfecTime)
  139. insertData = append(insertData, id)
  140. insertData = append(insertData, classids)
  141. insertData = append(insertData, way)
  142. insertData = append(insertData, machinedisinfectant)
  143. insertData = append(insertData, disinfectantway)
  144. insertData = append(insertData, disinfectant)
  145. insertData = append(insertData, 1)
  146. insertData = append(insertData, time.Now().Unix())
  147. insertData = append(insertData, orgid)
  148. insertData = append(insertData, equimentid)
  149. insertData = append(insertData, bedid)
  150. }
  151. }
  152. thisSQL += strings.Join(insertParams, ",")
  153. err = xt.Exec(thisSQL, insertData...).Error
  154. if err != nil {
  155. xt.Rollback()
  156. return
  157. }
  158. }
  159. xt.Commit()
  160. return
  161. }
  162. func GetAllPlan(orgid int64) (plan []*models.DevicePlans, err error) {
  163. //db := readUserDb.Table("xt_device_plan as p").Where("p.status = 1")
  164. // //table := readUserDb.Table("xt_device_addmacher as e")
  165. // //fmt.Println("table", table)
  166. // //if orgid > 0 {
  167. // // db = db.Where("p.user_org_id = ?", orgid)
  168. // //}
  169. // //err = db.Select("p.id,p.device_type,p.disinfec_time,p.time,p.classtime,p.way,p.machine_disinfectant,p.disinfectan_way,p.disinfectant,e.unit_type").Group("p.id").Joins("Left JOIN xt_device_addmacher as e On e.id = p.device_type").Order("e.unit_type asc,p.time").Scan(&plan).Error
  170. // //return plan, err
  171. err = readUserDb.Raw("select DISTINCT p.id,p.device_type,p.disinfec_time,p.time,p.classtime,p.way,p.machine_disinfectant,p.disinfectan_way,p.disinfectant,p.equiment_id,p.bed_id,e.device_mode from xt_device_plan as p left join xt_device_mode as e On e.id = p.device_type where p.user_org_id = ? and p.status = 1", orgid).Order("e.device_mode asc,p.time").Scan(&plan).Error
  172. return plan, err
  173. }
  174. func GetDeviceType(unitype string) (models.DeviceMode, error) {
  175. equimentname := models.DeviceMode{}
  176. err := UserReadDB().Where("id = ?", unitype).Find(&equimentname).Error
  177. return equimentname, err
  178. }
  179. func GetAllPlanDetail(id int64, orgid int64) (plan []*models.DevicePlans, err error) {
  180. //db := readUserDb.Table("xt_device_plan as p").Where("p.status = 1")
  181. //table := readUserDb.Table("xt_device_addmacher as e")
  182. //fmt.Println("table", table)
  183. //if orgid > 0 {
  184. // db = db.Where("p.user_org_id = ?", orgid)
  185. //}
  186. //if id > 0 {
  187. // db = db.Where("p.equiment_id = ?", id)
  188. //}
  189. //err = db.Select("p.id,p.device_type,p.disinfec_time,p.time,p.classtime,p.way,p.machine_disinfectant,p.disinfectan_way,p.disinfectant,e.unit_type").Group("p.id").Joins("Left JOIN xt_device_addmacher as e On e.id = p.equiment_id").Order("p.time asc").Scan(&plan).Error
  190. //return plan, err
  191. err = readUserDb.Raw("select DISTINCT p.id,p.device_type,p.disinfec_time,p.time,p.classtime,p.way,p.machine_disinfectant,p.disinfectan_way,p.disinfectant,p.equiment_id,p.bed_id,e.device_mode from xt_device_plan as p left join xt_device_mode as e On e.id = p.device_type where p.user_org_id = ? and p.device_type = ? and p.status = 1", orgid, id).Order("p.time asc,p.classtime asc").Scan(&plan).Error
  192. return plan, err
  193. }
  194. func DeletePlan(id int64) (err error) {
  195. err = UserWriteDB().Model(&models.DevicePlan{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  196. return
  197. }
  198. func DeletePlans(orgid int64, ids []int64) (err error) {
  199. if len(ids) == 1 {
  200. err = UserWriteDB().Model(&models.DevicePlan{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  201. } else {
  202. err = UserWriteDB().Model(models.DevicePlan{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  203. }
  204. return
  205. }
  206. func GetPlanDetailById(id int64, orgid int64) (models.DevicePlanss, error) {
  207. plans := models.DevicePlanss{}
  208. db := UserReadDB().Table("xt_device_plan as x").Where("x.status = 1")
  209. table := UserReadDB().Table("xt_device_addmacher as a").Where("a.status = 1")
  210. fmt.Println("table", table)
  211. if id > 0 {
  212. db = db.Where("x.id = ?", id)
  213. }
  214. if orgid > 0 {
  215. db = db.Where("x.user_org_id = ?", orgid)
  216. }
  217. err := db.Select("x.id,x.device_type,x.disinfec_time,x.time,x.classtime,x.way,x.machine_disinfectant,x.disinfectan_way,x.disinfectant,x.status,x.user_org_id,x.equiment_id,a.unit_type").Joins("Left Join xt_device_addmacher as a ON a.id = x.equiment_id").Scan(&plans).Error
  218. return plans, err
  219. }
  220. func UpdatePlanInfo(id int64, orgid int64, plan models.DevicePlan) error {
  221. err := writeUserDb.Model(&plan).Where("id = ? AND user_org_id = ?", id, orgid).Updates(map[string]interface{}{"device_type": plan.DeviceType, "disinfec_time": plan.DisinfecTime, "time": plan.Time, "classtime": plan.Classtime, "way": plan.Way, "machine_disinfectant": plan.MachineDisinfectant, "disinfectan_way": plan.MachineDisinfectant, "disinfectant": plan.Disinfectant, "mtime": time.Now().Unix()}).Error
  222. return err
  223. }
  224. func GetComprehensive(zone int64, number int64, devicetype int64, year int64, starttime int64, endtime int64, orgid int64) (macher []*models.DeviceAddmachers, err error) {
  225. db := readUserDb.Table("xt_device_addmacher as a").Where("a.status = 1")
  226. table := XTReadDB().Table("xt_device_zone as x")
  227. fmt.Println(table)
  228. if orgid > 0 {
  229. db = db.Where("a.user_org_id = ?", orgid)
  230. }
  231. if zone > 0 {
  232. db = db.Where("a.zone_id = ?", zone)
  233. }
  234. if number > 0 {
  235. db = db.Where("a.bed_id = ?", number)
  236. }
  237. if devicetype > 0 {
  238. db = db.Where("a.device_type = ?", devicetype)
  239. }
  240. if year == 1 {
  241. db = db.Where("a.user_year >= 0 AND a.user_year <= 1")
  242. }
  243. if year == 2 {
  244. db = db.Where("a.user_year >=1 AND a.user_year <= 3")
  245. }
  246. if year == 3 {
  247. db = db.Where("a.user_year >=3 AND a.user_year <= 10")
  248. }
  249. if year == 4 {
  250. db = db.Where("a.user_year >=10")
  251. }
  252. if starttime > 0 {
  253. db = db.Where("a.ctime >= ?", starttime)
  254. }
  255. if endtime > 0 {
  256. db = db.Where("a.ctime <= ?", endtime)
  257. }
  258. err = db.Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,a.zone_id,a.bed_id,x.name,m.device_mode").Joins("Left JOIN sgj_xt.xt_device_zone as x On x.id = a.zone_id").Joins("Left JOIN xt_device_mode as m on m.id = a.unit_type").Scan(&macher).Error
  259. return macher, err
  260. }
  261. func GetBedId(id int64) (models.DeviceAddmacher, error) {
  262. addmacher := models.DeviceAddmacher{}
  263. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&addmacher).Error
  264. return addmacher, err
  265. }
  266. func GetPatientInfo(bedid int64, nowtime int64, orgid int64) (schedules []*models.Schedules, err error) {
  267. db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
  268. table := XTReadDB().Table("xt_patients as x")
  269. fmt.Println("table", table)
  270. if bedid > 0 {
  271. db = db.Where("s.bed_id = ?", bedid)
  272. }
  273. if nowtime > 0 {
  274. db = db.Where("s.schedule_date = ?", nowtime)
  275. }
  276. if orgid > 0 {
  277. db = db.Where("s.user_org_id = ?", orgid)
  278. }
  279. err = db.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,x.name").Joins("Left Join xt_patients as x On x.id = s.patient_id").Scan(&schedules).Error
  280. return schedules, err
  281. }
  282. func GetPatient(bedid int64, orgid int64, classid int64, nowtime int64) (schedules models.Schedules, err error) {
  283. db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
  284. table := XTReadDB().Table("xt_patients as x")
  285. fmt.Println("table", table)
  286. err = db.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,x.name,x.is_infectious").Joins("Left Join xt_patients as x On x.id = s.patient_id").Where("s.bed_id = ? AND s.user_org_id = ? AND s.schedule_type = ? AND s.schedule_date = ?", bedid, orgid, classid, nowtime).Scan(&schedules).Error
  287. return schedules, err
  288. }
  289. func GetPartitionName(id int64) (models.DeviceZone, error) {
  290. zone := models.DeviceZone{}
  291. err := XTReadDB().Where("id = ? AND status = 1", id).Find(&zone).Error
  292. return zone, err
  293. }
  294. func GetPatientNumber(id int64) (models.DeviceNumber, error) {
  295. number := models.DeviceNumber{}
  296. err := XTReadDB().Where("id = ? AND status = 1", id).Find(&number).Error
  297. return number, err
  298. }
  299. func GetDialysisOrder(time int64, patientid int64, orgid int64) (models.DialysisOrder, error) {
  300. order := models.DialysisOrder{}
  301. err := XTReadDB().Where("dialysis_date = ? AND patient_id = ? AND user_org_id = ? ", time, patientid, orgid).Find(&order).Error
  302. return order, err
  303. }
  304. func GetDialysisWay(time int64, patientid int64, orgid int64) (models.DialysisPrescription, error) {
  305. prescription := models.DialysisPrescription{}
  306. err := XTReadDB().Where("record_date = ? AND patient_id = ? AND user_org_id = ?", time, patientid, orgid).Find(&prescription).Error
  307. return prescription, err
  308. }
  309. func GetDialysisTime(time int64, patientid int64, orgid int64) (models.AssessmentAfterDislysis, error) {
  310. dislysis := models.AssessmentAfterDislysis{}
  311. err := XTReadDB().Where("assessment_date = ? AND patient_id = ? AND user_org_id = ?", time, patientid, orgid).Find(&dislysis).Error
  312. return dislysis, err
  313. }
  314. func GetAllOrganization(orgid int64, appid int64) (approle []*models.App_Role, err error) {
  315. err = UserReadDB().Where("org_id = ? AND app_id = ? AND status = 1", orgid, appid).Find(&approle).Error
  316. return approle, err
  317. }
  318. func CreateUserInformation(information *models.DeviceInformation) error {
  319. err := writeUserDb.Create(&information).Error
  320. return err
  321. }
  322. func GetRegisterInfo(orgid int64, id int64, timenow int64) (models.DeviceInformations, error) {
  323. //information := models.DeviceInformations{}
  324. var information models.DeviceInformations
  325. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  326. table := XTReadDB().Table("xt_patients as p")
  327. fmt.Println("table", table)
  328. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  329. fmt.Print("dbs", dbs)
  330. err = db.Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,p.name,r.user_name,r.admin_user_id").Joins("Left join sgj_xt.xt_patients as p On p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Where("x.user_org_id = ? AND x.equiment_id = ? AND x.date = ?", orgid, id, timenow).Scan(&information).Error
  331. return information, err
  332. }
  333. func GetSignName(id int64, orgid int64, appid int64) (models.App_Role, error) {
  334. role := models.App_Role{}
  335. err := UserReadDB().Model(&role).Where("admin_user_id = ? AND org_id = ? AND app_id = ?", id, orgid, appid).Find(&role).Error
  336. return role, err
  337. }
  338. func GetInformationData(limit int64, page int64, orgId int64) (information []*models.DeviceInformations, total int64, err error) {
  339. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  340. table := XTReadDB().Table("xt_patients as p")
  341. fmt.Println("table", table)
  342. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  343. fmt.Println("dbs", dbs)
  344. offset := (page - 1) * limit
  345. if orgId > 0 {
  346. db = db.Where("x.user_org_id = ?", orgId)
  347. }
  348. err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Order("x.ctime desc").Offset(offset).Limit(limit).Scan(&information).Error
  349. if err != nil {
  350. return
  351. }
  352. return
  353. }
  354. func GetOrgName(orgid int64) (models.Org, error) {
  355. org := models.Org{}
  356. err := UserReadDB().Where("id= ? AND status = 1", orgid).Find(&org).Error
  357. return org, err
  358. }
  359. func GetMyMobile(id int64) (models.SgjUserAdmin, error) {
  360. admin := models.SgjUserAdmin{}
  361. err := UserReadDB().Model(&admin).Where("id=? and status = 1", id).Find(&admin).Error
  362. return admin, err
  363. }
  364. func CreateCulture(culture *models.DeviceCulture) error {
  365. err := writeUserDb.Create(&culture).Error
  366. return err
  367. }
  368. func CreateDialysate(dialysate *models.DeviceDialysate) error {
  369. err := writeUserDb.Create(&dialysate).Error
  370. return err
  371. }
  372. func CreateIon(ion *models.DeviceIon) error {
  373. err := writeUserDb.Create(&ion).Error
  374. return err
  375. }
  376. func GetAllCulture(orgId int64) (cultures []*models.DeviceCultures, err error) {
  377. db := UserReadDB().Table("xt_device_culture as x").Where("x.status = 1")
  378. table := UserReadDB().Table("sgj_user_admin_role as r")
  379. fmt.Println("table", table)
  380. if orgId > 0 {
  381. db = db.Where("x.user_org_id = ?", orgId)
  382. }
  383. err = db.Group("x.id").Select("x.id,x.speling_date,x.specimen,x.concentrate_noa,x.concentrate_nob,x.sampling_locationa,x.detection_unit,x.sampler,x.reporting_date,x.detection_result,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sampler").Scan(&cultures).Error
  384. return cultures, err
  385. }
  386. func GetAllDialysate(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  387. db := UserReadDB().Table("xt_device_dialysate as x").Where("x.status = 1")
  388. table := UserReadDB().Table("sgj_user_admin_role as r")
  389. fmt.Println("table", table)
  390. if orgId > 0 {
  391. db = db.Where("x.user_org_id = ?", orgId)
  392. }
  393. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  394. return dialysate, err
  395. }
  396. func GetAllDeviceIon(orgId int64) (ions []*models.DeviceIons, err error) {
  397. db := UserReadDB().Table("xt_device_ion as x").Where("x.status = 1")
  398. table := UserReadDB().Table("sgj_user_admin_role as r")
  399. fmt.Println("table", table)
  400. if orgId > 0 {
  401. db = db.Where("x.user_org_id = ?", orgId)
  402. }
  403. err = db.Group("x.id").Select("x.id,x.sampling_date,x.samplerc,x.detection_unit,x.concentrate_nof,x.concentrate_nog,x.date_reportc,x.actual_na,x.actual_pna,x.actual_k,x.actual_ca,x.actual_ci,x.actual_hco,x.actual_mg,x.actual_ph,x.remakes,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerc").Scan(&ions).Error
  404. return ions, err
  405. }
  406. func GetCultureById(id int64) (models.DeviceCulture, error) {
  407. culture := models.DeviceCulture{}
  408. err := UserReadDB().Model(&culture).Where("id=? AND status = 1", id).Find(&culture).Error
  409. return culture, err
  410. }
  411. func GetSampler(id int64) (models.App_Role, error) {
  412. role := models.App_Role{}
  413. err := UserReadDB().Model(&role).Where("id= ? AND status =1", id).Find(&role).Error
  414. return role, err
  415. }
  416. func UpdateCulture(id int64, orgid int64, culture *models.DeviceCulture) error {
  417. err := writeUserDb.Model(&culture).Where("id= ? AND user_org_id = ? AND status = ?", id, orgid, 1).Updates(map[string]interface{}{"speling_date": culture.SpelingDate, "specimen": culture.Specimen, "concentrate_noa": culture.ConcentrateNoa, "concentrate_nob": culture.ConcentrateNob, "sampling_locationa": culture.SamplingLocationa, "detection_unit": culture.DetectionUnit, "sampler": culture.Sampler, "reporting_date": culture.ReportingDate, "detection_result": culture.DetectionResult, "mtime": time.Now().Unix()}).Error
  418. return err
  419. }
  420. func DeleteCultrues(id int64) (err error) {
  421. err = UserWriteDB().Model(models.DeviceCulture{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  422. return
  423. }
  424. func DeleteCultrue(orgid int64, ids []int64) (err error) {
  425. if len(ids) == 1 {
  426. err = UserWriteDB().Model(&models.DeviceCulture{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  427. } else {
  428. err = UserWriteDB().Model(models.DeviceCulture{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  429. }
  430. return
  431. }
  432. func GetDialystate(id int64) (models.DeviceDialysate, error) {
  433. dialysate := models.DeviceDialysate{}
  434. err := readUserDb.Where("id= ? AND status = 1", id).Find(&dialysate).Error
  435. return dialysate, err
  436. }
  437. func Updatedialystate(id int64, orgid int64, dialysate *models.DeviceDialysate) error {
  438. err := writeUserDb.Model(&dialysate).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": dialysate.SamplingDate, "specimenb": dialysate.Specimenb, "concentrate_noc": dialysate.ConcentrateNoc, "concentrateb_nod": dialysate.ConcentratebNod, "sampling_locationb": dialysate.SamplingLocationb, "detection_unit": dialysate.DetectionUnit, "samplerb": dialysate.Samplerb, "reporting_dateb": dialysate.ReportingDateb, "detection_resultb": dialysate.DetectionResultb, "mtime": time.Now().Unix()}).Error
  439. return err
  440. }
  441. func DeleteDialystates(id int64) (err error) {
  442. err = UserWriteDB().Model(&models.DeviceDialysate{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  443. return
  444. }
  445. func DeleteDialystate(orgid int64, ids []int64) (err error) {
  446. if len(ids) == 1 {
  447. err = UserWriteDB().Model(&models.DeviceDialysate{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  448. } else {
  449. err = UserWriteDB().Model(models.DeviceDialysate{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  450. }
  451. return
  452. }
  453. func GetIon(id int64) (models.DeviceIon, error) {
  454. ion := models.DeviceIon{}
  455. err := UserReadDB().Model(&ion).Where("id = ? AND status = 1", id).Find(&ion).Error
  456. return ion, err
  457. }
  458. func UpdateIon(id int64, orgid int64, ion *models.DeviceIon) error {
  459. err := writeUserDb.Model(&ion).Where("id = ? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": ion.SamplingDate, "samplerc": ion.Samplerc, "detection_unit": ion.DetectionUnit, "concentrate_nof": ion.ConcentrateNof, "concentrate_nog": ion.ConcentrateNog, "date_reportc": ion.DateReportc, "actual_na": ion.ActualNa, "actual_pna": ion.ActualPna, "actual_k": ion.ActualK, "actual_ca": ion.ActualCa, "actual_ci": ion.ActualCi, "actual_hco": ion.ActualCi, "actual_mg": ion.ActualMg, "actual_ph": ion.ActualPh, "remakes": ion.Remakes, "mtime": time.Now().Unix()}).Error
  460. return err
  461. }
  462. func DeleteIons(id int64) (err error) {
  463. err = UserWriteDB().Model(&models.DeviceIon{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  464. return
  465. }
  466. func DeleteIon(orgid int64, ids []int64) (err error) {
  467. if len(ids) == 1 {
  468. err = UserWriteDB().Model(&models.DeviceIon{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  469. } else {
  470. err = UserWriteDB().Model(models.DeviceIon{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  471. }
  472. return
  473. }
  474. func GetCultureData(bedid int64, start int64, end int64, orgId int64) (cultures []*models.DeviceCultures, err error) {
  475. db := UserReadDB().Table("xt_device_culture as x").Where("x.status = 1")
  476. table := UserReadDB().Table("sgj_user_admin_role as r")
  477. fmt.Println("table", table)
  478. if orgId > 0 {
  479. db = db.Where("x.user_org_id = ?", orgId)
  480. }
  481. if bedid > 0 {
  482. db = db.Where("x.bed_id = ?", bedid)
  483. }
  484. if start > 0 {
  485. db = db.Where("x.speling_date >= ?", start)
  486. }
  487. if end > 0 {
  488. db = db.Where("x.speling_date <= ?", end)
  489. }
  490. err = db.Group("x.id").Select("x.id,x.speling_date,x.specimen,x.concentrate_noa,x.concentrate_nob,x.sampling_locationa,x.detection_unit,x.sampler,x.reporting_date,x.detection_result,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sampler").Scan(&cultures).Error
  491. return cultures, err
  492. }
  493. func GetDialysateData(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  494. db := UserReadDB().Table("xt_device_dialysate as x").Where("x.status = 1")
  495. table := UserReadDB().Table("sgj_user_admin_role as r")
  496. fmt.Println("table", table)
  497. if orgId > 0 {
  498. db = db.Where("x.user_org_id = ?", orgId)
  499. }
  500. if bedid > 0 {
  501. db = db.Where("x.bed_id = ?", bedid)
  502. }
  503. if start > 0 {
  504. db = db.Where("x.sampling_date >= ?", start)
  505. }
  506. if end > 0 {
  507. db = db.Where("x.sampling_date <= ?", end)
  508. }
  509. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  510. return dialysate, err
  511. }
  512. func GetDeviceIonData(bedid int64, start int64, end int64, orgId int64) (ions []*models.DeviceIons, err error) {
  513. db := UserReadDB().Table("xt_device_ion as x").Where("x.status = 1")
  514. table := UserReadDB().Table("sgj_user_admin_role as r")
  515. fmt.Println("table", table)
  516. if orgId > 0 {
  517. db = db.Where("x.user_org_id = ?", orgId)
  518. }
  519. if bedid > 0 {
  520. db = db.Where("x.bed_id = ?", bedid)
  521. }
  522. if start > 0 {
  523. db = db.Where("x.sampling_date >= ?", start)
  524. }
  525. if end > 0 {
  526. db = db.Where("x.sampling_date <= ?", end)
  527. }
  528. err = db.Group("x.id").Select("x.id,x.sampling_date,x.samplerc,x.detection_unit,x.concentrate_nof,x.concentrate_nog,x.date_reportc,x.actual_na,x.actual_pna,x.actual_k,x.actual_ca,x.actual_ci,x.actual_hco,x.actual_mg,x.actual_ph,x.remakes,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerc").Scan(&ions).Error
  529. return ions, err
  530. }
  531. func CreateRepair(repair *models.DeviceRepair) error {
  532. err = writeUserDb.Create(&repair).Error
  533. return err
  534. }
  535. func GetAllRepair(orgid int64, limit int64, page int64) (repair []*models.DeviceRepairs, total int64, err error) {
  536. db := UserReadDB().Table("xt_device_repair as r").Where("r.status = ?", 1)
  537. table := XTReadDB().Table("xt_device_number as x")
  538. offset := (page - 1) * limit
  539. fmt.Print("table", table)
  540. if orgid > 0 {
  541. db = db.Where("r.user_org_id = ?", orgid)
  542. }
  543. err = db.Count(&total).Select("r.id,r.guarantee_date,r.start_time,r.arrive_time,r.finish_time,r.total_distance,r.failure_stage,r.fault_description,r.cause_analysis,r.treatment_process,r.images,r.exclude,r.reason,r.ctime,r.mtime,r.status,r.user_org_id,r.bed_id,r.equitment_id,r.code_information,x.number").Joins("Left join sgj_xt.xt_device_number as x on x.id = r.bed_id").Offset(offset).Limit(limit).Scan(&repair).Error
  544. // err = UserReadDB().Where("user_org_id = ? AND status = 1", orgid).Find(&repair).Error
  545. return repair, total, err
  546. }
  547. func EditRepair(id int64) (models.DeviceRepair, error) {
  548. repair := models.DeviceRepair{}
  549. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&repair).Error
  550. return repair, err
  551. }
  552. func UpdateRepair(id int64, orgid int64, repair *models.DeviceRepair) error {
  553. err := writeUserDb.Model(&repair).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"guarantee_date": repair.GuaranteeDate, "start_time": repair.StartTime, "arrive_time": repair.ArriveTime, "finish_time": repair.FinishTime, "total_distance": repair.TotalDistance, "failure_stage": repair.FailureStage, "fault_description": repair.FaultDescription, "cause_analysis": repair.CauseAnalysis, "treatment_process": repair.TreatmentProcess, "images": repair.Images, "exclude": repair.Exclude, "reason": repair.Reason, "code_information": repair.CodeInformation, "image_name": repair.ImageName, "mtime": time.Now().Unix()}).Error
  554. return err
  555. }
  556. func DeleteRepairs(id int64) (err error) {
  557. err = UserWriteDB().Model(models.DeviceRepair{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  558. return
  559. }
  560. func DeleteRepair(orgid int64, ids []int64) (err error) {
  561. if len(ids) == 1 {
  562. err = UserWriteDB().Model(&models.DeviceRepair{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  563. } else {
  564. err = UserWriteDB().Model(models.DeviceRepair{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  565. }
  566. return
  567. }
  568. func GetRepair(bedid int64, start int64, end int64, orgid int64) (repair []*models.DeviceRepairs, err error) {
  569. db := UserReadDB().Table("xt_device_repair as r").Where("r.status = 1")
  570. sb := UserReadDB().Table("xt_device_addmacher as x")
  571. fmt.Print("sb", sb)
  572. if orgid > 0 {
  573. db = db.Where("r.user_org_id = ?", orgid)
  574. }
  575. if bedid > 0 {
  576. db = db.Where("r.bed_id = ?", bedid)
  577. }
  578. if start > 0 {
  579. db = db.Where("r.guarantee_date >= ?", start)
  580. }
  581. if end > 0 {
  582. db = db.Where("r.guarantee_date <= ?", end)
  583. }
  584. //err = db.Model(&repair).Find(&repair).Error
  585. err = db.Select("r.id,r.guarantee_date,r.start_time,r.arrive_time,r.finish_time,r.total_distance,r.failure_stage,r.fault_description,r.cause_analysis,r.treatment_process,r.images,r.exclude,r.reason,r.ctime,r.mtime,r.status,r.user_org_id,r.bed_id,r.equitment_id,r.code_information,x.number").Joins("Left join sgj_xt.xt_device_number as x on x.id = r.bed_id").Scan(&repair).Error
  586. return repair, err
  587. }
  588. func GetUserInformation(id int64) (models.DeviceInformation, error) {
  589. information := models.DeviceInformation{}
  590. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&information).Error
  591. return information, err
  592. }
  593. func GetPatientInfoMation(patieintid int64) (models.Patients, error) {
  594. patients := models.Patients{}
  595. err := XTReadDB().Where("id = ? AND status = 1", patieintid).Find(&patients).Error
  596. return patients, err
  597. }
  598. func DeleteUserLogin(id int64) (err error) {
  599. err = UserWriteDB().Model(&models.DeviceInformation{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  600. return
  601. }
  602. func DeleteForm(orgid int64, ids []int64) (err error) {
  603. if len(ids) == 1 {
  604. err = UserWriteDB().Model(&models.DeviceInformation{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  605. } else {
  606. err = UserWriteDB().Model(models.DeviceInformation{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  607. }
  608. return
  609. }
  610. func GetLastInformationdata(eid int64, startdate int64, orgid int64) (models.DeviceInformation, error) {
  611. information := models.DeviceInformation{}
  612. err := UserReadDB().Model(&information).Where("equiment_id = ? and date = ? and user_org_id = ? and status = 1", eid, startdate, orgid).Last(&information).Error
  613. return information, err
  614. }
  615. func UpdateAddMacherBedID(id int64, orgid int64, addmacher *models.DeviceAddmacher) error {
  616. err := UserWriteDB().Model(&addmacher).Where("id=? and user_org_id = ? and status =1", id, orgid).Update(map[string]interface{}{"bed_id": addmacher.BedId, "mtime": addmacher.Mtime}).Error
  617. return err
  618. }
  619. func UpdatedZoneID(bedid int64, orgid int64, number *models.DeviceNumber) error {
  620. err := XTWriteDB().Model(&number).Where("id=? and org_id = ?", bedid, orgid).Update(map[string]interface{}{"zone_id": number.ZoneID, "mtime": time.Now().Unix()}).Error
  621. return err
  622. }
  623. func UpadateForm(id int64, orgid int64, infor *models.DeviceInformation) error {
  624. err := UserWriteDB().Model(&infor).Where("id = ? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"date": infor.Date, "class": infor.Class, "zone": infor.Zone, "bed_number": infor.BedNumber, "contagion": infor.Contagion, "dialysis_mode": infor.DialysisMode, "start_time": infor.StartTime, "end_time": infor.EndTime, "dialysis_hour": infor.DialysisHour, "hyperfiltratio": infor.Hyperfiltratio, "weight_loss": infor.WeightLoss, "warning_value": infor.WarningValue, "user_total": infor.UserTotal, "move": infor.Move, "failure_stage": infor.FailureStage, "fault_description": infor.FaultDescription, "code_information": infor.CodeInformation, "disinfect_type": infor.DisinfectType, "disinfectant_type": infor.DisinfectType, "disinfection": infor.Disinfection, "machine_run": infor.MachineRun, "fluid_path": infor.FluidPath, "disinfectant": infor.Disinfectant, "disinfection_status": infor.DisinfectionStatus, "disinfection_residue": infor.DisinfectionResidue, "long_time": infor.LongTime, "disinfec_startime": infor.DisinfecStartime, "disinfec_endtime": infor.DisinfecEndtime, "dialysis_checked": infor.DialysisChecked, "dialysis_name": infor.DialysisName, "norms": infor.Norms, "dialysis_concentration": infor.DialysisConcentration,
  625. "germ_checked": infor.GermChecked, "germ_name": infor.GermName, "germ_number": infor.GermNumber, "clean": infor.Clean, "sign_name": infor.SignName, "bed": infor.Bed, "patient_id": infor.PatientId, "mtime": time.Now().Unix()}).Error
  626. return err
  627. }
  628. func QueryInfo(bed int64, start int64, end int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
  629. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  630. table := XTReadDB().Table("xt_patients as p")
  631. fmt.Println("table", table)
  632. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  633. fmt.Println("dbs", dbs)
  634. if orgId > 0 {
  635. db = db.Where("x.user_org_id = ?", orgId)
  636. }
  637. //if zone > 0 {
  638. // db = db.Where("x.zone = ?", zone)
  639. //}
  640. if bed > 0 {
  641. db = db.Where("x.bed_number = ?", bed)
  642. }
  643. if start > 0 {
  644. db = db.Where("x.date >= ?", start)
  645. }
  646. if end > 0 {
  647. db = db.Where("x.date <= ?", end)
  648. }
  649. offset := (page - 1) * limit
  650. err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Order("x.ctime desc").Offset(offset).Limit(limit).Scan(&infor).Error
  651. if err != nil {
  652. return
  653. }
  654. return
  655. }
  656. func GetPatientID(bedid int64, orgId int64, nowtime int64) (dialysis []*models.DialysisOrder, err error) {
  657. err = XTReadDB().Model(&dialysis).Where("bed_id = ? AND user_org_id = ? AND dialysis_date = ?", bedid, orgId, nowtime).Find(&dialysis).Error
  658. return dialysis, err
  659. }
  660. //func GetAllEquitType(orgId int64) (addmacher []*models.DeviceAddmacher, err error) {
  661. //
  662. // db := UserReadDB().Table("xt_device_addmacher as a").Where("a.status = 1")
  663. // if orgId > 0 {
  664. // db = db.Where("a.user_org_id = ?", orgId)
  665. // }
  666. // err = db.Group("a.unit_type").Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,a.zone_id,a.bed_id").Where("a.device_type <> 2 AND a.device_type <> 3").Scan(&addmacher).Error
  667. // return addmacher, err
  668. //}
  669. func GetAllEquitType(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
  670. //err = UserReadDB().Raw("select equitment_name,id,user_org_id,equitment_id from xt_device_equimentname where user_org_id = ? GROUP BY equitment_name ",orgid).Scan(&equiment).Error
  671. //err = UserReadDB().Raw("SELECT e.id,e.equitment_name,e.user_org_id,e.equitment_id FROM xt_device_equimentname as e LEFT JOIN xt_device_addmacher as a ON a.id = e.equitment_id WHERE a.status = 1 AND a.device_type <> 2 AND a.device_type <> 3 AND e.user_org_id = ? GROUP BY equitment_name", orgid).Scan(&equiment).Error
  672. //err = UserReadDB().Where("user_org_id = ? and status =1", orgid).Find(&equiment).Error
  673. err = UserReadDB().Raw("select x.equitment_name,x.id,x.user_org_id,x.equitment_id,x.bed_id from xt_device_equimentname as x where x.user_org_id = ? and x.status = ? GROUP BY x.equitment_name", orgid, 1).Scan(&equiment).Error
  674. return equiment, err
  675. }
  676. func GetAllEquitName(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
  677. err = UserReadDB().Raw("select id,equitment_name,status,ctime,mtime,user_org_id,equitment_id from xt_device_equimentname as e Where EXISTS (select id from xt_device_addmacher as a where a.id = e.equitment_id and a.status = 1) AND e.user_org_id = ? AND e.status = 1 ", orgid).Scan(&equiment).Error
  678. return equiment, err
  679. }
  680. func GetUserForm(id int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
  681. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  682. table := XTReadDB().Table("xt_patients as p")
  683. fmt.Println("table", table)
  684. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  685. fmt.Println("dbs", dbs)
  686. offset := (page - 1) * limit
  687. if id > 0 {
  688. db = db.Where("x.equiment_id = ?", id)
  689. }
  690. if orgId > 0 {
  691. db = db.Where("x.user_org_id = ?", orgId)
  692. }
  693. err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Offset(offset).Limit(limit).Scan(&infor).Error
  694. if err != nil {
  695. return
  696. }
  697. return
  698. }
  699. func GetBedNumber(id int64, orgid int64) (models.DeviceAddmacher, error) {
  700. addmacher := models.DeviceAddmacher{}
  701. err := UserReadDB().Where("id= ? AND user_org_id = ?", id, orgid).Find(&addmacher).Error
  702. return addmacher, err
  703. }
  704. func GetNumbers(id int64, orgid int64) (models.DeviceNumber, error) {
  705. number := models.DeviceNumber{}
  706. err := XTReadDB().Where("id = ? AND org_id = ?", id, orgid).Find(&number).Error
  707. return number, err
  708. }
  709. func GetZoneForm(id int64) (models.DeviceAddmacher, error) {
  710. macher := models.DeviceAddmacher{}
  711. err := UserReadDB().Where("id=? AND status = 1", id).Find(&macher).Error
  712. return macher, err
  713. }
  714. func GetBedForm(id int64) (number []*models.DeviceNumber, err error) {
  715. err = XTReadDB().Where("zone_id = ? AND status = 1", id).Find(&number).Error
  716. return number, err
  717. }
  718. func GetTotalCount(orgid int64) (repair []*models.DeviceRepair, total int64, err error) {
  719. err = UserReadDB().Model(&repair).Where("user_org_id = ? and status = 1", orgid).Find(&repair).Count(&total).Error
  720. return repair, total, err
  721. }
  722. func GetTotalNumber(id int64, orgid int64) (total int64, err error) {
  723. var device models.DeviceInformation
  724. err = UserReadDB().Model(&device).Where("equiment_id = ? AND user_org_id = ? AND status = 1", id, orgid).Find(&device).Count(&total).Error
  725. return total, err
  726. }
  727. func GetTimeWarning(equitid int64, orgId int64) (models.DeviceInformation, error) {
  728. //fmt.Print("equitid是什么码字--------------------------------------------------------------------",equitid)
  729. information := models.DeviceInformation{}
  730. err = UserReadDB().Where(" user_org_id = ? AND status = 1 AND equiment_id = ? AND (dialysis_checked = 1 or dialysis_checked = 0)", orgId, equitid).Last(&information).Error
  731. return information, err
  732. }
  733. func GetTimeLast(equitid int64, orgId int64) (models.DeviceInformation, error) {
  734. information := models.DeviceInformation{}
  735. err := UserReadDB().Model(&information).Where("equiment_id = ? AND user_org_id = ? AND status = 1 AND (germ_checked = 1 or germ_checked = 0)", equitid, orgId).Last(&information).Error
  736. return information, err
  737. }
  738. func GetTimeLastData(equitid int64, orgId int64) (models.DeviceInformation, error) {
  739. information := models.DeviceInformation{}
  740. err := UserReadDB().Model(&information).Where("equiment_id = ? AND user_org_id = ? AND status = 1 AND (clean = 1 or clean = 0)", equitid, orgId).Last(&information).Error
  741. return information, err
  742. }
  743. func GetAllpatient(orgid int64) (patients []*models.Patients, err error) {
  744. err = XTReadDB().Where("user_org_id = ?", orgid).Find(&patients).Error
  745. return patients, err
  746. }
  747. //func GetInformation(id int64, orgid int64) (*models.DeviceInformation, error) {
  748. //// var information models.DeviceInformation
  749. //// var err error
  750. //// err = UserReadDB().Model(&information).Where("id = ? and user_org_id = ? and status = ?", id, orgid, 1).Find(&information).Error
  751. //// fmt.Print("", err)
  752. //// if err == gorm.ErrRecordNotFound {
  753. //// return nil, err
  754. //// }
  755. //// if err != nil {
  756. //// return nil, err
  757. //// }
  758. //// return &information, nil
  759. ////}
  760. func GetInformation(eid int64, startdate int64, orgid int64) (*models.DeviceInformation, error) {
  761. var information models.DeviceInformation
  762. var err error
  763. err = UserReadDB().Model(&information).Where("equiment_id = ? and user_org_id = ? and status = ? and date = ? ", eid, orgid, 1, startdate).Find(&information).Error
  764. fmt.Print("", err)
  765. if err == gorm.ErrRecordNotFound {
  766. return nil, err
  767. }
  768. if err != nil {
  769. return nil, err
  770. }
  771. return &information, nil
  772. }
  773. func ChangeBed(id int64, org int64) (number []*models.DeviceNumber, err error) {
  774. err = XTReadDB().Model(&number).Where("zone_id = ? AND status = 1 AND org_id = ? ", id, org).Find(&number).Error
  775. return number, err
  776. }
  777. func GetPatientDetail(id int64, orgid int64) (models.Patients, error) {
  778. patients := models.Patients{}
  779. err := XTReadDB().Where("id=? and user_org_id = ?", id, orgid).Find(&patients).Error
  780. return patients, err
  781. }
  782. func GetRemanderData(orgid int64) (remander models.DeviceRemander, err error) {
  783. err = UserReadDB().Model(&models.DeviceRemander{}).Where("user_org_id = ? and status = 1", orgid).Find(&remander).Error
  784. return
  785. }
  786. func CreateRemander(remander *models.DeviceRemander) (err error) {
  787. err = UserWriteDB().Create(&remander).Error
  788. return
  789. }
  790. func UpdateRemander(remander *models.DeviceRemander) (err error) {
  791. err = UserWriteDB().Save(&remander).Error
  792. return
  793. }
  794. func GetMode(mode string, orgid int64) (*models.DeviceMode, error) {
  795. var information models.DeviceMode
  796. var err error
  797. err = UserReadDB().Model(&information).Where("device_mode = ? and user_org_id = ? and status = ?", mode, orgid, 1).Find(&information).Error
  798. fmt.Print("", err)
  799. if err == gorm.ErrRecordNotFound {
  800. return nil, err
  801. }
  802. if err != nil {
  803. return nil, err
  804. }
  805. return &information, nil
  806. }
  807. func SaveMode(mode *models.DeviceMode) (err error) {
  808. err = UserWriteDB().Save(&mode).Error
  809. return
  810. }
  811. func GetAllMode(orgid int64) (mode []*models.DeviceMode, err error) {
  812. err = UserReadDB().Where("user_org_id = ? and status = ?", orgid, 1).Find(&mode).Error
  813. return mode, err
  814. }
  815. func GetModeById(id int64) (models.DeviceMode, error) {
  816. mode := models.DeviceMode{}
  817. err := UserReadDB().Where("id = ?", id).Find(&mode).Error
  818. return mode, err
  819. }
  820. func UpdateMode(id int64, mode models.DeviceMode) error {
  821. err := UserWriteDB().Model(&mode).Where("id=?", id).Update(map[string]interface{}{"device_mode": mode.DeviceMode, "mtime": time.Now().Unix()}).Error
  822. return err
  823. }
  824. func QueryDeviceMode(id int64, orgid int64) (*models.DeviceAddmacher, error) {
  825. addmacher := models.DeviceAddmacher{}
  826. var err error
  827. err = UserReadDB().Model(&addmacher).Where("unit_type = ? and user_org_id = ?", id, orgid).Find(&addmacher).Error
  828. if err == gorm.ErrRecordNotFound {
  829. return nil, err
  830. }
  831. if err != nil {
  832. return nil, err
  833. }
  834. return &addmacher, nil
  835. }
  836. func DeleteMode(id int64) error {
  837. err := UserWriteDB().Model(models.DeviceMode{}).Where("id=?", id).Update(map[string]interface{}{"status": 0}).Error
  838. return err
  839. }
  840. func SelectChange(id int64, orgid int64) (number []*models.DeviceNumber, err error) {
  841. //err = XTReadDB().Where("zone_id = ? and org_id = ? and status = ?", id, orgid, 1).Find(&number).Error
  842. db := XTReadDB().Table("xt_device_number as x").Where("x.status = ?", 1)
  843. err = db.Select("org_id,number,group_id,zone_id as id").Where("zone_id = ? and org_id = ?", id, orgid).Find(&number).Error
  844. return number, err
  845. }
  846. func SelectBed(id int64, orgid int64) (models.DeviceNumber, error) {
  847. number := models.DeviceNumber{}
  848. err := XTReadDB().Where("id = ? and org_id = ?", id, orgid).Find(&number).Error
  849. return number, err
  850. }
  851. func GetTimeData(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  852. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  853. //err = db.Raw("select id,date,class,zone,bed_number,patient_id,contagion,dialysis_mode,start_time,end_time,dialysis_hour,hyperfiltratio,weight_loss,warning_value,user_total,move,failure_stage,fault_description,code_information,disinfect_type,disinfectant_type,disinfection,machine_run,fluid_path,disinfectant,disinfection_status,disinfection_residue,long_time,disinfec_startime,disinfec_endtime,dialysis_checked,dialysis_name,norms,dialysis_concentration,germ_checked,germ_name,germ_number,clean,sign_name,status,ctime,mtime,user_org_id,equiment_id,bed,stime from xt_device_information where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= ? and equiment_id = ? and user_org_id = ?",timenow,equitid, orgid).Error
  854. day := time.Now().Day()
  855. oldMonth := day - 30
  856. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  857. err = UserReadDB().Model(&information).Where("date>= ? and date <= ? and equiment_id = ? and user_org_id = ? and dialysis_checked = 1 ", t.Unix(), timenow, equitid, orgid).Find(&information).Error
  858. return information, err
  859. }
  860. func GetTimeTwo(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  861. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  862. //err = db.Raw("select id,date,class,zone,bed_number,patient_id,contagion,dialysis_mode,start_time,end_time,dialysis_hour,hyperfiltratio,weight_loss,warning_value,user_total,move,failure_stage,fault_description,code_information,disinfect_type,disinfectant_type,disinfection,machine_run,fluid_path,disinfectant,disinfection_status,disinfection_residue,long_time,disinfec_startime,disinfec_endtime,dialysis_checked,dialysis_name,norms,dialysis_concentration,germ_checked,germ_name,germ_number,clean,sign_name,status,ctime,mtime,user_org_id,equiment_id,bed,stime from xt_device_information where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= ? and equiment_id = ? and user_org_id = ?",timenow,equitid, orgid).Error
  863. day := time.Now().Day()
  864. oldMonth := day - 30
  865. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  866. err = UserReadDB().Model(&information).Where("date >= ? and date<= ? and equiment_id = ? and user_org_id = ? and germ_checked = 1 ", t.Unix(), timenow, equitid, orgid).Find(&information).Error
  867. return information, err
  868. }
  869. func GetTimeThree(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  870. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  871. //err = db.Raw("select id,date,class,zone,bed_number,patient_id,contagion,dialysis_mode,start_time,end_time,dialysis_hour,hyperfiltratio,weight_loss,warning_value,user_total,move,failure_stage,fault_description,code_information,disinfect_type,disinfectant_type,disinfection,machine_run,fluid_path,disinfectant,disinfection_status,disinfection_residue,long_time,disinfec_startime,disinfec_endtime,dialysis_checked,dialysis_name,norms,dialysis_concentration,germ_checked,germ_name,germ_number,clean,sign_name,status,ctime,mtime,user_org_id,equiment_id,bed,stime from xt_device_information where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= ? and equiment_id = ? and user_org_id = ?",timenow,equitid, orgid).Error
  872. day := time.Now().Day()
  873. oldMonth := day - 30
  874. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  875. err = UserReadDB().Model(&information).Where("date >= ? and date <= ? and equiment_id = ? and user_org_id = ? and clean = 1 ", t.Unix(), timenow, equitid, orgid).Find(&information).Error
  876. return information, err
  877. }
  878. func DeleteImages(id int64) error {
  879. repair := models.DeviceRepair{}
  880. err := UserWriteDB().Model(&repair).Where("id=?", id).Update(map[string]interface{}{"images": "", "image_name": ""}).Error
  881. return err
  882. }
  883. func GetActivtyCreator(creator int64) (*models.KyActivityTable, error) {
  884. table := models.KyActivityTable{}
  885. err := UserReadDB().Model(&table).Where("admin_user_id = ? and status =1", creator).Find(&table).Error
  886. if err == gorm.ErrRecordNotFound {
  887. return nil, err
  888. }
  889. if err != nil {
  890. return nil, err
  891. }
  892. return &table, nil
  893. }
  894. func CreateTable(table *models.KyActivityTable) error {
  895. err := UserWriteDB().Model(&table).Create(&table).Error
  896. return err
  897. }
  898. func GetAdminUserRole(id int64, orgid int64) (models.SgjUserAdminRole, error) {
  899. role := models.SgjUserAdminRole{}
  900. err := UserReadDB().Where("admin_user_id = ? and org_id = ? and status = 1", id, orgid).Find(&role).Error
  901. return role, err
  902. }
  903. func GetRolePosition(id int64) (models.SgjUserRole, error) {
  904. role := models.SgjUserRole{}
  905. err := UserReadDB().Where("id = ? And status =1", id).Find(&role).Error
  906. return role, err
  907. }
  908. func GetMobile(id int64) (models.SgjUserAdmin, error) {
  909. admin := models.SgjUserAdmin{}
  910. err := UserReadDB().Where("id=? and status = 1", id).Find(&admin).Error
  911. return admin, err
  912. }
  913. func GetOrgs(id int64) (roles []*models.SgjUserAdminRole, err error) {
  914. db := UserReadDB().Table("sgj_user_admin_role as s").Where("s.status = 1")
  915. err = db.Group("s.org_id").Select("s.admin_user_id,s.org_id,s.app_id,s.role_id,s.user_name,s.avatar,s.user_type,s.user_title,s.intro,s.user_title_name,s.role_ids,s.message,s.sex,s.birthday,x.org_name,x.org_logo,x.creator,x.id").Where("s.admin_user_id = ?", id).Joins("left join sgj_user_org as x on x.id = s.org_id").Scan(&roles).Error
  916. return roles, err
  917. }
  918. func GetUserMachTotalCount(orgid int64) (vm []*models.VmDeviceInformation, err error) {
  919. err = UserReadDB().Raw("SELECT x.bed_number,count(*) as total FROM xt_device_information as x WHERE user_org_id = ? and `status` = 1 GROUP BY x.bed_number ", orgid).Scan(&vm).Error
  920. return vm, err
  921. }
  922. func GetUserTotalByMacher(id int64) (models.DeviceAddmacher, error) {
  923. addmacher := models.DeviceAddmacher{}
  924. err := UserReadDB().Model(&addmacher).Where("id=? and status = 1", id).Find(&addmacher).Error
  925. return addmacher, err
  926. }
  927. func GetUserTotalCount(orgid int64, bedid int64) (vm []*models.VmDeviceInformation, err error) {
  928. err = UserReadDB().Raw("SELECT x.bed_number,count(*) as total FROM xt_device_information as x WHERE user_org_id = ? and `status` = 1 and bed_number= ? GROUP BY x.bed_number ", orgid, bedid).Scan(&vm).Error
  929. return vm, err
  930. }
  931. func GetUserTotal(orgid int64, id int64) (models.DeviceAddmacher, error) {
  932. addmacher := models.DeviceAddmacher{}
  933. err := UserReadDB().Model(&addmacher).Where("user_org_id = ? and bed_id = ? and status = 1", orgid, id).Find(&addmacher).Error
  934. return addmacher, err
  935. }
  936. func GetDisInfectionTime(orgid int64, unitype int64, scheduletype int64, scheduleweek int64) (*models.DevicePlan, error) {
  937. plan := models.DevicePlan{}
  938. err = UserReadDB().Model(&plan).Where("user_org_id = ? and device_type = ? and classtime = ? and time = ? and status = 1", orgid, unitype, scheduletype, scheduleweek).Find(&plan).Error
  939. if err == gorm.ErrRecordNotFound {
  940. return nil, err
  941. }
  942. if err != nil {
  943. return nil, err
  944. }
  945. return &plan, nil
  946. }
  947. func GetUnitType(bedid int64, orgid int64) (models.DeviceAddmacher, error) {
  948. addmacher := models.DeviceAddmacher{}
  949. err := UserReadDB().Model(&addmacher).Where("bed_id = ? and user_org_id = ? and status = 1", bedid, orgid).Find(&addmacher).Error
  950. return addmacher, err
  951. }
  952. func GetLaseDeviceInfomation(orgid int64, bedid int64, date int64, scheduletype int64) (*models.DeviceInformation, error) {
  953. information := models.DeviceInformation{}
  954. err := UserReadDB().Model(&information).Where("bed_number = ? and user_org_id =? and status = 1 and date = ? and class = ? ", bedid, orgid, date, scheduletype).Find(&information).Error
  955. if err == gorm.ErrRecordNotFound {
  956. return nil, err
  957. }
  958. if err != nil {
  959. return nil, err
  960. }
  961. return &information, nil
  962. }
  963. func GetLaseDeviceInfomationTwo(orgid int64, bedid int64, scheduletype int64) (models.DeviceInformation, error) {
  964. information := models.DeviceInformation{}
  965. err = UserReadDB().Model(&information).Where("bed_number= ? and user_org_id = ? and status = 1 and class = ?", bedid, orgid, scheduletype).Last(&information).Error
  966. return information, err
  967. }
  968. func GetAssessmentAfterDissDataTwo(patientid int64, orgID int64, timenow int64) (models.XtAssessmentAfterDislysis, error) {
  969. dislysis := models.XtAssessmentAfterDislysis{}
  970. err := XTReadDB().Where("patient_id = ? AND user_org_id = ? AND assessment_date = ?", patientid, orgID, timenow).Find(&dislysis).Error
  971. return dislysis, err
  972. }
  973. func GetEquimentIDTwo(bedId int64, orgID int64) (models.DeviceAddmacher, error) {
  974. addmacher := models.DeviceAddmacher{}
  975. err := readUserDb.Model(&addmacher).Where("bed_id = ? AND user_org_id = ? AND status = ?", bedId, orgID, 1).Find(&addmacher).Error
  976. return addmacher, err
  977. }
  978. func GetDisinfectionTwo(equitType int64, enquitType int64, orgID int64) (*models.DevicePlan, error) {
  979. var plan models.DevicePlan
  980. var err error
  981. err = readUserDb.Model(&plan).Where("device_type = ? AND classtime = ? AND user_org_id = ? AND status = 1", equitType, enquitType, orgID).Find(&plan).Error
  982. if err == gorm.ErrRecordNotFound {
  983. return nil, err
  984. }
  985. if err != nil {
  986. return nil, err
  987. }
  988. return &plan, nil
  989. }
  990. func GetInforTwo(patientid int64, timenow int64, orgid int64, class int64) (*models.DeviceInformation, error) {
  991. var pre models.DeviceInformation
  992. var err error
  993. err = readUserDb.Model(&pre).Where("patient_id = ? AND date = ? AND user_org_id = ? AND class = ? AND status = 1", patientid, timenow, orgid, class).Find(&pre).Error
  994. if err == gorm.ErrRecordNotFound {
  995. return nil, err
  996. }
  997. if err != nil {
  998. return nil, err
  999. }
  1000. return &pre, nil
  1001. }
  1002. func GetPatientOrderInfo(schduledate int64, patientid int64, orgid int64) (models.XtDialysisOrder, error) {
  1003. order := models.XtDialysisOrder{}
  1004. err := XTReadDB().Model(&order).Where("dialysis_date = ? and patient_id = ? and user_org_id = ? and status = 1", schduledate, patientid, orgid).Find(&order).Error
  1005. return order, err
  1006. }
  1007. func CreateInformationTwo(information *models.DeviceInformation) error {
  1008. err := UserWriteDB().Create(&information).Error
  1009. return err
  1010. }
  1011. func UpdateInformation(information *models.DeviceInformation, scheduledate int64, bedid int64, scheduletype int64) error {
  1012. err := UserWriteDB().Model(&information).Where("date = ? and bed_number = ? and class = ?", scheduledate, bedid, scheduletype).Updates(map[string]interface{}{"long_time": information.LongTime, "disinfec_startime": information.DisinfecStartime, "disinfec_endtime": information.DisinfecEndtime}).Error
  1013. return err
  1014. }
  1015. func DeleteEquit(id int64) (models.DeviceAddmacher, error) {
  1016. addmacher := models.DeviceAddmacher{}
  1017. err := UserWriteDB().Model(&addmacher).Where("id=?", id).Updates(map[string]interface{}{"status": 0}).Error
  1018. return addmacher, err
  1019. }