manage_service.go 73KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544
  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.DisinfectanWay, "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,x.sort,x.pass_examination,x.modifications,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,x.sort,x.pass_examination,x.modifications,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,x.sort,x.pass_examination,x.modifications,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, "sort": culture.Sort, "pass_examination": culture.PassExamination, "modifications": culture.Modifications, "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, "sort": dialysate.Sort, "pass_examination": dialysate.PassExamination, "modifications": dialysate.Modifications, "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, "sort": ion.Sort, "pass_examination": ion.PassExamination, "modifications": ion.Modifications, "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 GetDeviceIonData(bedid int64, start int64, end int64, orgId int64) (ions []*models.DeviceIons, err error) {
  494. db := UserReadDB().Table("xt_device_ion 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.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
  510. return ions, err
  511. }
  512. func CreateRepair(repair *models.DeviceRepair) error {
  513. err = writeUserDb.Create(&repair).Error
  514. return err
  515. }
  516. func GetAllRepair(orgid int64, limit int64, page int64) (repair []*models.DeviceRepairs, total int64, err error) {
  517. db := UserReadDB().Table("xt_device_repair as r").Where("r.status = ?", 1)
  518. table := XTReadDB().Table("xt_device_number as x")
  519. offset := (page - 1) * limit
  520. fmt.Print("table", table)
  521. if orgid > 0 {
  522. db = db.Where("r.user_org_id = ?", orgid)
  523. }
  524. 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
  525. // err = UserReadDB().Where("user_org_id = ? AND status = 1", orgid).Find(&repair).Error
  526. return repair, total, err
  527. }
  528. func EditRepair(id int64) (models.DeviceRepair, error) {
  529. repair := models.DeviceRepair{}
  530. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&repair).Error
  531. return repair, err
  532. }
  533. func UpdateRepair(id int64, orgid int64, repair *models.DeviceRepair) error {
  534. 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
  535. return err
  536. }
  537. func DeleteRepairs(id int64) (err error) {
  538. err = UserWriteDB().Model(models.DeviceRepair{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  539. return
  540. }
  541. func DeleteRepair(orgid int64, ids []int64) (err error) {
  542. if len(ids) == 1 {
  543. 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
  544. } else {
  545. 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
  546. }
  547. return
  548. }
  549. func GetRepair(bedid int64, start int64, end int64, orgid int64) (repair []*models.DeviceRepairs, err error) {
  550. db := UserReadDB().Table("xt_device_repair as r").Where("r.status = 1")
  551. sb := UserReadDB().Table("xt_device_addmacher as x")
  552. fmt.Print("sb", sb)
  553. if orgid > 0 {
  554. db = db.Where("r.user_org_id = ?", orgid)
  555. }
  556. if bedid > 0 {
  557. db = db.Where("r.bed_id = ?", bedid)
  558. }
  559. if start > 0 {
  560. db = db.Where("r.guarantee_date >= ?", start)
  561. }
  562. if end > 0 {
  563. db = db.Where("r.guarantee_date <= ?", end)
  564. }
  565. //err = db.Model(&repair).Find(&repair).Error
  566. 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
  567. return repair, err
  568. }
  569. func GetUserInformation(id int64) (models.DeviceInformation, error) {
  570. information := models.DeviceInformation{}
  571. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&information).Error
  572. return information, err
  573. }
  574. func GetPatientInfoMation(patieintid int64) (models.Patients, error) {
  575. patients := models.Patients{}
  576. err := XTReadDB().Where("id = ? AND status = 1", patieintid).Find(&patients).Error
  577. return patients, err
  578. }
  579. func DeleteUserLogin(id int64) (err error) {
  580. err = UserWriteDB().Model(&models.DeviceInformation{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  581. return
  582. }
  583. func DeleteForm(orgid int64, ids []int64) (err error) {
  584. if len(ids) == 1 {
  585. 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
  586. } else {
  587. 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
  588. }
  589. return
  590. }
  591. func GetLastInformationdata(eid int64, startdate int64, orgid int64) (models.DeviceInformation, error) {
  592. information := models.DeviceInformation{}
  593. err := UserReadDB().Model(&information).Where("equiment_id = ? and date = ? and user_org_id = ? and status = 1", eid, startdate, orgid).Last(&information).Error
  594. return information, err
  595. }
  596. func UpdateAddMacherBedID(id int64, orgid int64, addmacher *models.DeviceAddmacher) error {
  597. 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
  598. return err
  599. }
  600. func UpdatedZoneID(bedid int64, orgid int64, number *models.DeviceNumber) error {
  601. err := XTWriteDB().Model(&number).Where("id=? and org_id = ?", bedid, orgid).Update(map[string]interface{}{"zone_id": number.ZoneID, "mtime": time.Now().Unix()}).Error
  602. return err
  603. }
  604. func UpadateForm(id int64, orgid int64, infor *models.DeviceInformation) error {
  605. 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.DisinfectantType, "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,
  606. "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
  607. return err
  608. }
  609. func QueryInfo(bed int64, start int64, end int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
  610. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  611. table := XTReadDB().Table("xt_patients as p")
  612. fmt.Println("table", table)
  613. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  614. fmt.Println("dbs", dbs)
  615. if orgId > 0 {
  616. db = db.Where("x.user_org_id = ?", orgId)
  617. }
  618. //if zone > 0 {
  619. // db = db.Where("x.zone = ?", zone)
  620. //}
  621. if bed > 0 {
  622. db = db.Where("x.bed_number = ?", bed)
  623. }
  624. if start > 0 {
  625. db = db.Where("x.date >= ?", start)
  626. }
  627. if end > 0 {
  628. db = db.Where("x.date <= ?", end)
  629. }
  630. offset := (page - 1) * limit
  631. 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
  632. if err != nil {
  633. return
  634. }
  635. return
  636. }
  637. func GetPatientID(bedid int64, orgId int64, nowtime int64) (dialysis []*models.DialysisOrder, err error) {
  638. err = XTReadDB().Model(&dialysis).Where("bed_id = ? AND user_org_id = ? AND dialysis_date = ?", bedid, orgId, nowtime).Find(&dialysis).Error
  639. return dialysis, err
  640. }
  641. //func GetAllEquitType(orgId int64) (addmacher []*models.DeviceAddmacher, err error) {
  642. //
  643. // db := UserReadDB().Table("xt_device_addmacher as a").Where("a.status = 1")
  644. // if orgId > 0 {
  645. // db = db.Where("a.user_org_id = ?", orgId)
  646. // }
  647. // 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
  648. // return addmacher, err
  649. //}
  650. func GetAllEquitType(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
  651. //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
  652. //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
  653. //err = UserReadDB().Where("user_org_id = ? and status =1", orgid).Find(&equiment).Error
  654. 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
  655. return equiment, err
  656. }
  657. func GetAllEquitName(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
  658. 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
  659. return equiment, err
  660. }
  661. func GetUserForm(id int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
  662. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  663. table := XTReadDB().Table("xt_patients as p")
  664. fmt.Println("table", table)
  665. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  666. fmt.Println("dbs", dbs)
  667. offset := (page - 1) * limit
  668. if id > 0 {
  669. db = db.Where("x.equiment_id = ?", id)
  670. }
  671. if orgId > 0 {
  672. db = db.Where("x.user_org_id = ?", orgId)
  673. }
  674. 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
  675. if err != nil {
  676. return
  677. }
  678. return
  679. }
  680. func GetBedNumber(id int64, orgid int64) (models.DeviceAddmacher, error) {
  681. addmacher := models.DeviceAddmacher{}
  682. err := UserReadDB().Where("id= ? AND user_org_id = ?", id, orgid).Find(&addmacher).Error
  683. return addmacher, err
  684. }
  685. func GetNumbers(id int64, orgid int64) (models.DeviceNumber, error) {
  686. number := models.DeviceNumber{}
  687. err := XTReadDB().Where("id = ? AND org_id = ?", id, orgid).Find(&number).Error
  688. return number, err
  689. }
  690. func GetZoneForm(id int64) (models.DeviceAddmacher, error) {
  691. macher := models.DeviceAddmacher{}
  692. err := UserReadDB().Where("id=? AND status = 1", id).Find(&macher).Error
  693. return macher, err
  694. }
  695. func GetBedForm(id int64) (number []*models.DeviceNumber, err error) {
  696. err = XTReadDB().Where("zone_id = ? AND status = 1", id).Find(&number).Error
  697. return number, err
  698. }
  699. func GetTotalCount(orgid int64) (repair []*models.DeviceRepair, total int64, err error) {
  700. err = UserReadDB().Model(&repair).Where("user_org_id = ? and status = 1", orgid).Find(&repair).Count(&total).Error
  701. return repair, total, err
  702. }
  703. func GetTotalNumber(id int64, orgid int64) (total int64, err error) {
  704. var device models.DeviceInformation
  705. err = UserReadDB().Model(&device).Where("equiment_id = ? AND user_org_id = ? AND status = 1", id, orgid).Find(&device).Count(&total).Error
  706. return total, err
  707. }
  708. func GetTimeWarning(equitid int64, orgId int64) (models.DeviceInformation, error) {
  709. //fmt.Print("equitid是什么码字--------------------------------------------------------------------",equitid)
  710. information := models.DeviceInformation{}
  711. 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
  712. return information, err
  713. }
  714. func GetTimeLast(equitid int64, orgId int64) (models.DeviceInformation, error) {
  715. information := models.DeviceInformation{}
  716. 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
  717. return information, err
  718. }
  719. func GetTimeLastData(equitid int64, orgId int64) (models.DeviceInformation, error) {
  720. information := models.DeviceInformation{}
  721. 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
  722. return information, err
  723. }
  724. func GetAllpatient(orgid int64) (patients []*models.Patients, err error) {
  725. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patients).Error
  726. return patients, err
  727. }
  728. //func GetInformation(id int64, orgid int64) (*models.DeviceInformation, error) {
  729. //// var information models.DeviceInformation
  730. //// var err error
  731. //// err = UserReadDB().Model(&information).Where("id = ? and user_org_id = ? and status = ?", id, orgid, 1).Find(&information).Error
  732. //// fmt.Print("", err)
  733. //// if err == gorm.ErrRecordNotFound {
  734. //// return nil, err
  735. //// }
  736. //// if err != nil {
  737. //// return nil, err
  738. //// }
  739. //// return &information, nil
  740. ////}
  741. func GetInformation(eid int64, startdate int64, orgid int64) (*models.DeviceInformation, error) {
  742. var information models.DeviceInformation
  743. var err error
  744. err = UserReadDB().Model(&information).Where("equiment_id = ? and user_org_id = ? and status = ? and date = ? ", eid, orgid, 1, startdate).Find(&information).Error
  745. fmt.Print("", err)
  746. if err == gorm.ErrRecordNotFound {
  747. return nil, err
  748. }
  749. if err != nil {
  750. return nil, err
  751. }
  752. return &information, nil
  753. }
  754. func ChangeBed(id int64, org int64) (number []*models.DeviceNumber, err error) {
  755. err = XTReadDB().Model(&number).Where("zone_id = ? AND status = 1 AND org_id = ? ", id, org).Find(&number).Error
  756. return number, err
  757. }
  758. func GetPatientDetail(id int64, orgid int64) (models.Patients, error) {
  759. patients := models.Patients{}
  760. err := XTReadDB().Where("id=? and user_org_id = ?", id, orgid).Find(&patients).Error
  761. return patients, err
  762. }
  763. func GetRemanderData(orgid int64) (remander models.DeviceRemander, err error) {
  764. err = UserReadDB().Model(&models.DeviceRemander{}).Where("user_org_id = ? and status = 1", orgid).Find(&remander).Error
  765. return
  766. }
  767. func CreateRemander(remander *models.DeviceRemander) (err error) {
  768. err = UserWriteDB().Create(&remander).Error
  769. return
  770. }
  771. func UpdateRemander(remander *models.DeviceRemander) (err error) {
  772. err = UserWriteDB().Save(&remander).Error
  773. return
  774. }
  775. func GetMode(mode string, orgid int64) (*models.DeviceMode, error) {
  776. var information models.DeviceMode
  777. var err error
  778. err = UserReadDB().Model(&information).Where("device_mode = ? and user_org_id = ? and status = ?", mode, orgid, 1).Find(&information).Error
  779. fmt.Print("", err)
  780. if err == gorm.ErrRecordNotFound {
  781. return nil, err
  782. }
  783. if err != nil {
  784. return nil, err
  785. }
  786. return &information, nil
  787. }
  788. func SaveMode(mode *models.DeviceMode) (err error) {
  789. err = UserWriteDB().Save(&mode).Error
  790. return
  791. }
  792. func GetAllMode(orgid int64) (mode []*models.DeviceMode, err error) {
  793. err = UserReadDB().Where("user_org_id = ? and status = ?", orgid, 1).Find(&mode).Error
  794. return mode, err
  795. }
  796. func GetModeById(id int64) (models.DeviceMode, error) {
  797. mode := models.DeviceMode{}
  798. err := UserReadDB().Where("id = ?", id).Find(&mode).Error
  799. return mode, err
  800. }
  801. func UpdateMode(id int64, mode models.DeviceMode) error {
  802. err := UserWriteDB().Model(&mode).Where("id=?", id).Update(map[string]interface{}{"device_mode": mode.DeviceMode, "mtime": time.Now().Unix()}).Error
  803. return err
  804. }
  805. func QueryDeviceMode(id int64, orgid int64) (*models.DeviceAddmacher, error) {
  806. addmacher := models.DeviceAddmacher{}
  807. var err error
  808. err = UserReadDB().Model(&addmacher).Where("unit_type = ? and user_org_id = ?", id, orgid).Find(&addmacher).Error
  809. if err == gorm.ErrRecordNotFound {
  810. return nil, err
  811. }
  812. if err != nil {
  813. return nil, err
  814. }
  815. return &addmacher, nil
  816. }
  817. func DeleteMode(id int64) error {
  818. err := UserWriteDB().Model(models.DeviceMode{}).Where("id=?", id).Update(map[string]interface{}{"status": 0}).Error
  819. return err
  820. }
  821. func SelectChange(id int64, orgid int64) (number []*models.DeviceNumber, err error) {
  822. //err = XTReadDB().Where("zone_id = ? and org_id = ? and status = ?", id, orgid, 1).Find(&number).Error
  823. db := XTReadDB().Table("xt_device_number as x").Where("x.status = ?", 1)
  824. err = db.Select("org_id,number,group_id,zone_id as id").Where("zone_id = ? and org_id = ?", id, orgid).Find(&number).Error
  825. return number, err
  826. }
  827. func SelectBed(id int64, orgid int64) (models.DeviceNumber, error) {
  828. number := models.DeviceNumber{}
  829. err := XTReadDB().Where("id = ? and org_id = ?", id, orgid).Find(&number).Error
  830. return number, err
  831. }
  832. func GetTimeData(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  833. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  834. //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
  835. day := time.Now().Day()
  836. oldMonth := day - 30
  837. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  838. 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
  839. return information, err
  840. }
  841. func GetTimeTwo(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  842. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  843. //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
  844. day := time.Now().Day()
  845. oldMonth := day - 30
  846. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  847. 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
  848. return information, err
  849. }
  850. func GetTimeThree(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  851. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  852. //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
  853. day := time.Now().Day()
  854. oldMonth := day - 30
  855. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  856. 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
  857. return information, err
  858. }
  859. func DeleteImages(id int64) error {
  860. repair := models.DeviceRepair{}
  861. err := UserWriteDB().Model(&repair).Where("id=?", id).Update(map[string]interface{}{"images": "", "image_name": ""}).Error
  862. return err
  863. }
  864. func GetActivtyCreator(creator int64) (*models.KyActivityTable, error) {
  865. table := models.KyActivityTable{}
  866. err := UserReadDB().Model(&table).Where("admin_user_id = ? and status =1", creator).Find(&table).Error
  867. if err == gorm.ErrRecordNotFound {
  868. return nil, err
  869. }
  870. if err != nil {
  871. return nil, err
  872. }
  873. return &table, nil
  874. }
  875. func CreateTable(table *models.KyActivityTable) error {
  876. err := UserWriteDB().Model(&table).Create(&table).Error
  877. return err
  878. }
  879. func GetAdminUserRole(id int64, orgid int64) (models.SgjUserAdminRole, error) {
  880. role := models.SgjUserAdminRole{}
  881. err := UserReadDB().Where("admin_user_id = ? and org_id = ? and status = 1", id, orgid).Find(&role).Error
  882. return role, err
  883. }
  884. func GetRolePosition(id int64) (models.SgjUserRole, error) {
  885. role := models.SgjUserRole{}
  886. err := UserReadDB().Where("id = ? And status =1", id).Find(&role).Error
  887. return role, err
  888. }
  889. func GetMobile(id int64) (models.SgjUserAdmin, error) {
  890. admin := models.SgjUserAdmin{}
  891. err := UserReadDB().Where("id=? and status = 1", id).Find(&admin).Error
  892. return admin, err
  893. }
  894. func GetOrgs(id int64) (roles []*models.SgjUserAdminRole, err error) {
  895. db := UserReadDB().Table("sgj_user_admin_role as s").Where("s.status = 1")
  896. 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
  897. return roles, err
  898. }
  899. func GetUserMachTotalCount(orgid int64) (vm []*models.VmDeviceInformation, err error) {
  900. 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
  901. return vm, err
  902. }
  903. func GetUserTotalByMacher(id int64) (models.DeviceAddmacher, error) {
  904. addmacher := models.DeviceAddmacher{}
  905. err := UserReadDB().Model(&addmacher).Where("id=? and status = 1", id).Find(&addmacher).Error
  906. return addmacher, err
  907. }
  908. func GetUserTotalCount(orgid int64, bedid int64) (vm []*models.VmDeviceInformation, err error) {
  909. 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
  910. return vm, err
  911. }
  912. func GetUserTotal(orgid int64, id int64) (models.DeviceAddmacher, error) {
  913. addmacher := models.DeviceAddmacher{}
  914. err := UserReadDB().Model(&addmacher).Where("user_org_id = ? and bed_id = ? and status = 1", orgid, id).Find(&addmacher).Error
  915. return addmacher, err
  916. }
  917. func GetDisInfectionTime(orgid int64, unitype int64, scheduletype int64, scheduleweek int64) (*models.DevicePlan, error) {
  918. plan := models.DevicePlan{}
  919. 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
  920. if err == gorm.ErrRecordNotFound {
  921. return nil, err
  922. }
  923. if err != nil {
  924. return nil, err
  925. }
  926. return &plan, nil
  927. }
  928. func GetUnitType(bedid int64, orgid int64) (models.DeviceAddmacher, error) {
  929. addmacher := models.DeviceAddmacher{}
  930. err := UserReadDB().Model(&addmacher).Where("bed_id = ? and user_org_id = ? and status = 1", bedid, orgid).Find(&addmacher).Error
  931. return addmacher, err
  932. }
  933. func GetLaseDeviceInfomation(orgid int64, bedid int64, date int64, scheduletype int64) (*models.DeviceInformation, error) {
  934. information := models.DeviceInformation{}
  935. 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
  936. if err == gorm.ErrRecordNotFound {
  937. return nil, err
  938. }
  939. if err != nil {
  940. return nil, err
  941. }
  942. return &information, nil
  943. }
  944. func GetLaseDeviceInfomationTwo(orgid int64, bedid int64, scheduletype int64) (models.DeviceInformation, error) {
  945. information := models.DeviceInformation{}
  946. err = UserReadDB().Model(&information).Where("bed_number= ? and user_org_id = ? and status = 1 and class = ?", bedid, orgid, scheduletype).Last(&information).Error
  947. return information, err
  948. }
  949. func GetAssessmentAfterDissDataTwo(patientid int64, orgID int64, timenow int64) (models.XtAssessmentAfterDislysis, error) {
  950. dislysis := models.XtAssessmentAfterDislysis{}
  951. err := XTReadDB().Where("patient_id = ? AND user_org_id = ? AND assessment_date = ?", patientid, orgID, timenow).Find(&dislysis).Error
  952. return dislysis, err
  953. }
  954. func GetEquimentIDTwo(bedId int64, orgID int64) (models.DeviceAddmacher, error) {
  955. addmacher := models.DeviceAddmacher{}
  956. err := readUserDb.Model(&addmacher).Where("bed_id = ? AND user_org_id = ? AND status = ?", bedId, orgID, 1).Find(&addmacher).Error
  957. return addmacher, err
  958. }
  959. func GetDisinfectionTwo(equitType int64, enquitType int64, orgID int64) (*models.DevicePlan, error) {
  960. var plan models.DevicePlan
  961. var err error
  962. err = readUserDb.Model(&plan).Where("device_type = ? AND classtime = ? AND user_org_id = ? AND status = 1", equitType, enquitType, orgID).Find(&plan).Error
  963. if err == gorm.ErrRecordNotFound {
  964. return nil, err
  965. }
  966. if err != nil {
  967. return nil, err
  968. }
  969. return &plan, nil
  970. }
  971. func GetInforTwo(patientid int64, timenow int64, orgid int64, class int64) (*models.DeviceInformation, error) {
  972. var pre models.DeviceInformation
  973. var err error
  974. 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
  975. if err == gorm.ErrRecordNotFound {
  976. return nil, err
  977. }
  978. if err != nil {
  979. return nil, err
  980. }
  981. return &pre, nil
  982. }
  983. func GetPatientOrderInfo(schduledate int64, patientid int64, orgid int64) (models.XtDialysisOrder, error) {
  984. order := models.XtDialysisOrder{}
  985. err := XTReadDB().Model(&order).Where("dialysis_date = ? and patient_id = ? and user_org_id = ? and status = 1", schduledate, patientid, orgid).Find(&order).Error
  986. return order, err
  987. }
  988. func CreateInformationTwo(information *models.DeviceInformation) error {
  989. err := UserWriteDB().Create(&information).Error
  990. return err
  991. }
  992. func UpdateInformation(information *models.DeviceInformation, scheduledate int64, bedid int64, scheduletype int64) error {
  993. 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
  994. return err
  995. }
  996. func DeleteEquit(id int64) (models.DeviceAddmacher, error) {
  997. addmacher := models.DeviceAddmacher{}
  998. err := UserWriteDB().Model(&addmacher).Where("id=?", id).Updates(map[string]interface{}{"status": 0}).Error
  999. return addmacher, err
  1000. }
  1001. func GetDeviceInfomation(orgid int64, scheduledate int64) (information []*models.DeviceInformation, err error) {
  1002. err = UserReadDB().Model(&information).Where("user_org_id = ? and date = ? and status =1", orgid, scheduledate).Find(&information).Error
  1003. return information, err
  1004. }
  1005. func CreateOxygenates(oxygenates *models.XtDeviceOxygenates) error {
  1006. err := UserWriteDB().Create(&oxygenates).Error
  1007. return err
  1008. }
  1009. func CreateHadWater(hadwater *models.XtDeviceHadwater) error {
  1010. err := UserWriteDB().Create(&hadwater).Error
  1011. return err
  1012. }
  1013. func CreateWater(water *models.XtDeviceWater) error {
  1014. err := UserWriteDB().Create(&water).Error
  1015. return err
  1016. }
  1017. func CreateDevicePh(ph *models.XtDevicePh) error {
  1018. err := UserWriteDB().Create(&ph).Error
  1019. return err
  1020. }
  1021. func GetAllDeviceOxygenates(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1022. db := UserReadDB().Table("xt_device_oxygenates as x").Where("x.status = 1")
  1023. table := UserReadDB().Table("sgj_user_admin_role as r")
  1024. fmt.Println("table", table)
  1025. if orgId > 0 {
  1026. db = db.Where("x.user_org_id = ?", orgId)
  1027. }
  1028. 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,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1029. return dialysate, err
  1030. }
  1031. func GetAllHadWater(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1032. db := UserReadDB().Table("xt_device_hadwater as x").Where("x.status = 1")
  1033. table := UserReadDB().Table("sgj_user_admin_role as r")
  1034. fmt.Println("table", table)
  1035. if orgId > 0 {
  1036. db = db.Where("x.user_org_id = ?", orgId)
  1037. }
  1038. 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,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1039. return dialysate, err
  1040. }
  1041. func GetDeviceWater(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1042. db := UserReadDB().Table("xt_device_water as x").Where("x.status = 1")
  1043. table := UserReadDB().Table("sgj_user_admin_role as r")
  1044. fmt.Println("table", table)
  1045. if orgId > 0 {
  1046. db = db.Where("x.user_org_id = ?", orgId)
  1047. }
  1048. 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,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1049. return dialysate, err
  1050. }
  1051. func GetDevicePH(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1052. db := UserReadDB().Table("xt_device_ph as x").Where("x.status = 1")
  1053. table := UserReadDB().Table("sgj_user_admin_role as r")
  1054. fmt.Println("table", table)
  1055. if orgId > 0 {
  1056. db = db.Where("x.user_org_id = ?", orgId)
  1057. }
  1058. 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,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1059. return dialysate, err
  1060. }
  1061. func GetDialysateData(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1062. db := UserReadDB().Table("xt_device_dialysate as x").Where("x.status = 1")
  1063. table := UserReadDB().Table("sgj_user_admin_role as r")
  1064. fmt.Println("table", table)
  1065. if orgId > 0 {
  1066. db = db.Where("x.user_org_id = ?", orgId)
  1067. }
  1068. if bedid > 0 {
  1069. db = db.Where("x.bed_id = ?", bedid)
  1070. }
  1071. if start > 0 {
  1072. db = db.Where("x.sampling_date >= ?", start)
  1073. }
  1074. if end > 0 {
  1075. db = db.Where("x.sampling_date <= ?", end)
  1076. }
  1077. 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
  1078. return dialysate, err
  1079. }
  1080. func GetOxygenates(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1081. db := UserReadDB().Table("xt_device_oxygenates as x").Where("x.status = 1")
  1082. table := UserReadDB().Table("sgj_user_admin_role as r")
  1083. fmt.Println("table", table)
  1084. if orgId > 0 {
  1085. db = db.Where("x.user_org_id = ?", orgId)
  1086. }
  1087. if bedid > 0 {
  1088. db = db.Where("x.bed_id = ?", bedid)
  1089. }
  1090. if start > 0 {
  1091. db = db.Where("x.sampling_date >= ?", start)
  1092. }
  1093. if end > 0 {
  1094. db = db.Where("x.sampling_date <= ?", end)
  1095. }
  1096. 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
  1097. return dialysate, err
  1098. }
  1099. func GetHardWater(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1100. db := UserReadDB().Table("xt_device_hadwater as x").Where("x.status = 1")
  1101. table := UserReadDB().Table("sgj_user_admin_role as r")
  1102. fmt.Println("table", table)
  1103. if orgId > 0 {
  1104. db = db.Where("x.user_org_id = ?", orgId)
  1105. }
  1106. if bedid > 0 {
  1107. db = db.Where("x.bed_id = ?", bedid)
  1108. }
  1109. if start > 0 {
  1110. db = db.Where("x.sampling_date >= ?", start)
  1111. }
  1112. if end > 0 {
  1113. db = db.Where("x.sampling_date <= ?", end)
  1114. }
  1115. 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
  1116. return dialysate, err
  1117. }
  1118. func GetWater(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1119. db := UserReadDB().Table("xt_device_water as x").Where("x.status = 1")
  1120. table := UserReadDB().Table("sgj_user_admin_role as r")
  1121. fmt.Println("table", table)
  1122. if orgId > 0 {
  1123. db = db.Where("x.user_org_id = ?", orgId)
  1124. }
  1125. if bedid > 0 {
  1126. db = db.Where("x.bed_id = ?", bedid)
  1127. }
  1128. if start > 0 {
  1129. db = db.Where("x.sampling_date >= ?", start)
  1130. }
  1131. if end > 0 {
  1132. db = db.Where("x.sampling_date <= ?", end)
  1133. }
  1134. 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
  1135. return dialysate, err
  1136. }
  1137. func GetDevicePh(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1138. db := UserReadDB().Table("xt_device_ph as x").Where("x.status = 1")
  1139. table := UserReadDB().Table("sgj_user_admin_role as r")
  1140. fmt.Println("table", table)
  1141. if orgId > 0 {
  1142. db = db.Where("x.user_org_id = ?", orgId)
  1143. }
  1144. if bedid > 0 {
  1145. db = db.Where("x.bed_id = ?", bedid)
  1146. }
  1147. if start > 0 {
  1148. db = db.Where("x.sampling_date >= ?", start)
  1149. }
  1150. if end > 0 {
  1151. db = db.Where("x.sampling_date <= ?", end)
  1152. }
  1153. 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
  1154. return dialysate, err
  1155. }
  1156. func GetOxygenatesById(id int64) (models.XtDeviceOxygenates, error) {
  1157. oxygenates := models.XtDeviceOxygenates{}
  1158. err := UserReadDB().Model(&oxygenates).Where("id = ? and status = 1", id).Find(&oxygenates).Error
  1159. return oxygenates, err
  1160. }
  1161. func UpdateOxygenates(id int64, orgid int64, dialysate *models.XtDeviceOxygenates) error {
  1162. 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, "sort": dialysate.Sort, "pass_examination": dialysate.PassExamination, "modifications": dialysate.Modifications, "mtime": time.Now().Unix()}).Error
  1163. return err
  1164. }
  1165. func GetHardWaterById(id int64) (models.XtDeviceHadwater, error) {
  1166. hadwater := models.XtDeviceHadwater{}
  1167. err := UserReadDB().Model(&hadwater).Where("id = ? and status = 1", id).Find(&hadwater).Error
  1168. return hadwater, err
  1169. }
  1170. func GetWaterById(id int64) (models.XtDeviceWater, error) {
  1171. water := models.XtDeviceWater{}
  1172. err := UserReadDB().Model(&water).Where("id=? and status =1", id).Find(&water).Error
  1173. return water, err
  1174. }
  1175. func GetDevicePhById(id int64) (models.XtDevicePh, error) {
  1176. devicePh := models.XtDevicePh{}
  1177. err := UserReadDB().Model(&devicePh).Where("id = ? and status =1", id).Find(&devicePh).Error
  1178. return devicePh, err
  1179. }
  1180. func CreateAerialDetection(detection *models.XtAerialDetection) error {
  1181. err := XTWriteDB().Create(&detection).Error
  1182. return err
  1183. }
  1184. func GetAirList(limit int64, page int64, orgid int64) (airlist []*models.XtAerialDetection, total int64, err error) {
  1185. offset := (page - 1) * limit
  1186. err = XTReadDB().Model(&airlist).Where("user_org_id = ? and status =1", orgid).Count(&total).Limit(limit).Offset(offset).Order("created_time desc").Find(&airlist).Error
  1187. return airlist, total, err
  1188. }
  1189. func GetAirDisinfectDetail(id int64) (models.XtAerialDetection, error) {
  1190. detection := models.XtAerialDetection{}
  1191. err := XTReadDB().Model(&detection).Where("id = ? and status = 1", id).Find(&detection).Error
  1192. return detection, err
  1193. }
  1194. func UpdateAeriaDetection(detection *models.XtAerialDetection, id int64) error {
  1195. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"start_time": detection.StartTime, "created_time": detection.CreatedTime, "class": detection.Class, "disinfection_methods": detection.DisinfectionMethods, "disinfection_fluid": detection.DisinfectionFluid, "sort": detection.Sort, "creator": detection.Creator, "detection_time": detection.DetectionTime, "detection_result": detection.DetectionResult, "upload_time": detection.UploadTime, "check_out": detection.CheckOut, "modifications": detection.Modifications}).Error
  1196. return err
  1197. }
  1198. func DeleteAirDisinfect(id int64) error {
  1199. detection := models.XtAerialDetection{}
  1200. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1201. return err
  1202. }
  1203. func SaveBodyDetection(detection *models.XtBodyDetection) error {
  1204. err := XTWriteDB().Create(&detection).Error
  1205. return err
  1206. }
  1207. func GetBodyList(limit int64, page int64, orgid int64) (body []*models.XtBodyDetection, total int64, err error) {
  1208. offset := (page - 1) * limit
  1209. err = XTReadDB().Model(&body).Where("user_org_id = ? and status =1", orgid).Count(&total).Limit(limit).Offset(offset).Order("created_time desc").Find(&body).Error
  1210. return body, total, err
  1211. }
  1212. func GetBodyDisinfectDetail(id int64) (models.XtBodyDetection, error) {
  1213. detection := models.XtBodyDetection{}
  1214. err := XTReadDB().Model(&detection).Where("id = ? and status = 1", id).Find(&detection).Error
  1215. return detection, err
  1216. }
  1217. func UpdateBodyDetection(detection *models.XtBodyDetection, id int64) error {
  1218. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"start_time": detection.StartTime, "created_time": detection.CreatedTime, "class": detection.Class, "disinfection_methods": detection.DisinfectionMethods, "disinfection_fluid": detection.DisinfectionFluid, "sort": detection.Sort, "creator": detection.Creator, "detection_time": detection.DetectionTime, "detection_result": detection.DetectionResult, "upload_time": detection.UploadTime, "check_out": detection.CheckOut, "modifications": detection.Modifications}).Error
  1219. return err
  1220. }
  1221. func DeleteBodyDisInfect(id int64) error {
  1222. detection := models.XtBodyDetection{}
  1223. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1224. return err
  1225. }
  1226. func UpdateHadWater(id int64, orgid int64, hadwater *models.XtDeviceHadwater) error {
  1227. err := writeUserDb.Model(&hadwater).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": hadwater.SamplingDate, "specimenb": hadwater.Specimenb, "concentrate_noc": hadwater.ConcentrateNoc, "concentrateb_nod": hadwater.ConcentratebNod, "sampling_locationb": hadwater.SamplingLocationb, "detection_unit": hadwater.DetectionUnit, "samplerb": hadwater.Samplerb, "reporting_dateb": hadwater.ReportingDateb, "detection_resultb": hadwater.DetectionResultb, "sort": hadwater.Sort, "pass_examination": hadwater.PassExamination, "modifications": hadwater.Modifications, "mtime": time.Now().Unix()}).Error
  1228. return err
  1229. }
  1230. func UpdateDeviceWater(id int64, orgid int64, hadwater *models.XtDeviceWater) error {
  1231. err := writeUserDb.Model(&hadwater).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": hadwater.SamplingDate, "specimenb": hadwater.Specimenb, "concentrate_noc": hadwater.ConcentrateNoc, "concentrateb_nod": hadwater.ConcentratebNod, "sampling_locationb": hadwater.SamplingLocationb, "detection_unit": hadwater.DetectionUnit, "samplerb": hadwater.Samplerb, "reporting_dateb": hadwater.ReportingDateb, "detection_resultb": hadwater.DetectionResultb, "sort": hadwater.Sort, "pass_examination": hadwater.PassExamination, "modifications": hadwater.Modifications, "mtime": time.Now().Unix()}).Error
  1232. return err
  1233. }
  1234. func UpdateDivicePh(id int64, orgid int64, hadwater *models.XtDevicePh) error {
  1235. err := writeUserDb.Model(&hadwater).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": hadwater.SamplingDate, "specimenb": hadwater.Specimenb, "concentrate_noc": hadwater.ConcentrateNoc, "concentrateb_nod": hadwater.ConcentratebNod, "sampling_locationb": hadwater.SamplingLocationb, "detection_unit": hadwater.DetectionUnit, "samplerb": hadwater.Samplerb, "reporting_dateb": hadwater.ReportingDateb, "detection_resultb": hadwater.DetectionResultb, "sort": hadwater.Sort, "pass_examination": hadwater.PassExamination, "modifications": hadwater.Modifications, "mtime": time.Now().Unix()}).Error
  1236. return err
  1237. }
  1238. func DeleteOxygenates(id int64) error {
  1239. oxygenates := models.XtDeviceOxygenates{}
  1240. err := writeUserDb.Model(&oxygenates).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
  1241. return err
  1242. }
  1243. func DeleteHadWater(id int64) error {
  1244. hadwater := models.XtDeviceHadwater{}
  1245. err := writeUserDb.Model(&hadwater).Where("id =?", id).Updates(map[string]interface{}{"status": 0}).Error
  1246. return err
  1247. }
  1248. func DeleteWater(id int64) error {
  1249. water := models.XtDeviceWater{}
  1250. err := writeUserDb.Model(&water).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
  1251. return err
  1252. }
  1253. func DeleteDevicePh(id int64) error {
  1254. ph := models.XtDevicePh{}
  1255. err := writeUserDb.Model(&ph).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
  1256. return err
  1257. }