city_data_uoload_service.go 55KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. // 统计后台的 service
  2. package service
  3. import (
  4. "Data_Upload_Api/models"
  5. "Data_Upload_Api/models/sz"
  6. "github.com/jinzhu/gorm"
  7. "strings"
  8. )
  9. func GetSyncTimeByOrgId(org_id int64, sync_type int64) (sync_info models.XTSyncInfo, err error) {
  10. err = readDb.Model(&models.XTSyncInfo{}).Where("org_id = ? and sync_type = ? ", org_id, sync_type).Last(&sync_info).Error
  11. return
  12. }
  13. func FindAllDataUploadConfigOrgInfo(province_id int64, city_id int64, config_type int64) (data []*sz.DataUploadConfig, err error) {
  14. err = readDb.Model(&sz.DataUploadConfig{}).Where("status = 1 AND province_id = ? AND city_id = ? AND config_type = ?", province_id, city_id, config_type).Find(&data).Error
  15. return
  16. }
  17. func FindDataUploadOrgInfo(org_id int64, module_type int64) (data sz.DataUpload, err error) {
  18. err = readDb.Model(&sz.DataUpload{}).Where(" org_id = ? AND module_type = ?", org_id, module_type).Last(&data).Error
  19. return
  20. }
  21. func FindOrgData(org_id int64, sync_time int64) (org models.UserOrg, err error) {
  22. err = readUserDb.Model(&models.UserOrg{}).Where("status = 1 AND id = ? AND ctime > ?", org_id, sync_time).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  23. return readDb.Where("status = 1")
  24. }).Find(&org).Error
  25. return
  26. }
  27. func FindOrgRolesData(org_id int64, lastUploadTime int64, nowTime int64) (role []*models.UserAdminRole, err error) {
  28. db := readUserDb.Model(&models.UserAdminRole{}).Where("status = 1 AND org_id = ? ", org_id)
  29. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  30. err = db.Find(&role).Error
  31. return
  32. }
  33. func FindOrgPatientData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
  34. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", org_id)
  35. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  36. err = db.Find(&patient).Error
  37. return
  38. }
  39. func FindOrgPatientDataOne(org_id int64) (patient []*models.Patients, err error) {
  40. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", org_id)
  41. err = db.Find(&patient).Error
  42. return
  43. }
  44. func FindOrgPatientInfectious(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
  45. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND lapseto = 2 ", org_id)
  46. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  47. err = db.Find(&patient).Error
  48. return
  49. }
  50. func FindOrgDeviceNumber(org_id int64, lastUploadTime int64, nowTime int64) (devices []*models.DeviceNumber, err error) {
  51. db := readDb.Model(&models.DeviceNumber{}).Where("status = 1 AND org_id = ?", org_id)
  52. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  53. err = db.Find(&devices).Error
  54. return
  55. }
  56. func FindOrgPatientOutData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
  57. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND lapseto = 2 ", org_id).Preload("PatientLapseto", "status = 1")
  58. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  59. err = db.Find(&patient).Error
  60. return
  61. }
  62. func FindOrgScheduleData(org_id int64, lastUploadTime int64, nowTime int64) (sch []*models.Schedule, err error) {
  63. db := readDb.Model(&models.Schedule{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DeviceNumber", "status = 1")
  64. if lastUploadTime != 0 && nowTime != 0 {
  65. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  66. }
  67. err = db.Find(&sch).Error
  68. return
  69. }
  70. func FindOrgDialysisPrescriptionData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.DialysisPrescription, err error) {
  71. db := readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DialysisOrder", "status = 1")
  72. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  73. err = db.Find(&ps).Error
  74. return
  75. }
  76. func FindOrgDoctorAdviceTemplateData(org_id int64, lastUploadTime int64, nowTime int64) (advice []*models.DoctorAdviceTemplate, err error) {
  77. db := readDb.Model(&models.DoctorAdviceTemplate{}).Where("status = 1 AND org_id = ? and advice_type = 0 ", org_id)
  78. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  79. err = db.Find(&advice).Error
  80. return
  81. }
  82. func FindAssessmentBeforeDislysis(org_id int64, patient_id int64) (before models.AssessmentBeforeDislysis, err error) {
  83. db := readDb.Model(&models.AssessmentBeforeDislysis{}).Where("status = 1 AND user_org_id = ? and patient_id = ? ", org_id, patient_id)
  84. err = db.Last(&before).Error
  85. return
  86. }
  87. func FindOrgMonitorRecordData(org_id int64, lastUploadTime int64, nowTime int64) (monitor []*models.MonitoringRecord, err error) {
  88. db := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DialysisOrder", "status = 1")
  89. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  90. err = db.Find(&monitor).Error
  91. return
  92. }
  93. func FindOrgMonitorRecordByLike(org_id int64, keyword string, lastUploadTime int64, nowTime int64) (monitor []*models.MonitoringRecord, err error) {
  94. db := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND symptom like ?", org_id, keyword)
  95. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  96. err = db.Find(&monitor).Error
  97. return
  98. }
  99. func FindOrgInspection(org_id int64, lastUploadTime int64, nowTime int64) (inspection []*models.XtInspection, err error) {
  100. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? ", org_id).Preload("Patients", "status = 1")
  101. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  102. err = db.Find(&inspection).Error
  103. return
  104. }
  105. // 传染病查询
  106. func FindOrgInspectionGroupOne(org_id int64, lastUploadTime int64, nowTime int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  107. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? and project_id = 14 and patient_id = ?", org_id, patient_id)
  108. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime).Group("inspect_date")
  109. err = db.Find(&inspection).Error
  110. return
  111. }
  112. // 传染病查询
  113. func FindOrgInspectionGroupTwo(org_id int64, inspect_date int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  114. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? and project_id = 14 and patient_id = ? and inspect_date = ?", org_id, patient_id, inspect_date)
  115. err = db.Find(&inspection).Error
  116. return
  117. }
  118. func FindOrgInspectionReference(org_id int64, lastUploadTime int64, nowTime int64) (inspection []*models.XtInspection, err error) {
  119. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? ", org_id).Preload("XtInspectionReference", "status = 1")
  120. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  121. err = db.Find(&inspection).Error
  122. return
  123. }
  124. func CreateOrgRecord(rdb *gorm.DB, hospital *sz.TempHdHospital) (err error) {
  125. err = rdb.Model(&sz.TempHdHospital{}).Create(&hospital).Error
  126. return
  127. }
  128. func CreateUploadRecord(upload *sz.DataUpload) (err error) {
  129. err = writeDb.Model(&sz.DataUpload{}).Create(&upload).Error
  130. return
  131. }
  132. func FindOrgDialysisData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.VMDialysisOrder, err error) {
  133. db := readDb.Model(&models.VMDialysisOrder{}).Where("status = 1 AND user_org_id = ? AND stage = 2 ", org_id).
  134. Preload("DeviceNumber", "status = 1").
  135. Preload("VMDialysisPrescription", "status = 1").
  136. Preload("AssessmentBeforeDislysis", "status = 1").
  137. Preload("AssessmentAfterDislysis", "status = 1").
  138. Preload("Schedule", "status = 1").
  139. Preload("MonitoringRecord", "status = 1")
  140. if lastUploadTime != 0 && nowTime != 0 {
  141. db = db.Where("updated_time >= ? AND updated_time <= ?", lastUploadTime, nowTime)
  142. }
  143. err = db.Find(&ps).Error
  144. return
  145. }
  146. func FindOrgDeviceZoneRecordData(org_id int64, lastUploadTime int64, nowTime int64) (zone []*models.DeviceZone, err error) {
  147. db := readDb.Model(&models.DeviceZone{}).Where("status = 1 AND org_id = ?", org_id)
  148. if lastUploadTime != 0 && nowTime != 0 {
  149. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  150. }
  151. err = db.Find(&zone).Error
  152. return
  153. }
  154. func FindOrgWaterMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  155. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ? AND device_type = 2", org_id)
  156. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  157. err = db.Find(&waterMachine).Error
  158. return
  159. }
  160. func BatchCreateWMsRecord(wms []*sz.TempHdWm, rdb *gorm.DB) (err error) {
  161. if len(wms) > 0 {
  162. utx := rdb
  163. if len(wms) > 0 {
  164. thisSQL := "INSERT INTO t_hd_wm (hospital_id, equipment_id, equipment_brand, equipment_model, enable_time,discarded_time,equipment_type,xgbz,create_time,update_time,sjscsj) VALUES "
  165. insertParams := make([]string, 0)
  166. insertData := make([]interface{}, 0)
  167. for _, wm := range wms {
  168. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  169. insertData = append(insertData, wm.HospitalId)
  170. insertData = append(insertData, wm.EquipmentId)
  171. insertData = append(insertData, wm.EquipmentBrand)
  172. insertData = append(insertData, wm.EquipmentModel)
  173. insertData = append(insertData, wm.EnableTime)
  174. insertData = append(insertData, wm.DiscardedTime)
  175. insertData = append(insertData, wm.EquipmentType)
  176. insertData = append(insertData, wm.Xgbz)
  177. insertData = append(insertData, wm.CreateTime)
  178. insertData = append(insertData, wm.UpdateTime)
  179. insertData = append(insertData, wm.Sjscsj)
  180. }
  181. thisSQL += strings.Join(insertParams, ", ")
  182. // err = utx.Exec(thisSQL, insertData...).Error
  183. // if err != nil {
  184. // utx.Rollback()
  185. // return
  186. // }
  187. utx.Exec(thisSQL, insertData...)
  188. }
  189. utx.Commit()
  190. }
  191. return
  192. }
  193. func BatchCreateStaffRecord(staffs []*sz.TempHdStaff, rdb *gorm.DB) (err error) {
  194. if len(staffs) > 0 {
  195. utx := rdb
  196. if len(staffs) > 0 {
  197. id_no := 429001198701091670
  198. for _, info := range staffs {
  199. thisSQL := "INSERT INTO t_hd_staff (hospital_id,staff_id, id_no,id_type,staff_name, position, staff_status, staff_no, permanent_type, in_date ,create_time, update_time, sjscsj, xgbz) VALUES "
  200. insertParams := make([]string, 0)
  201. insertData := make([]interface{}, 0)
  202. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  203. insertData = append(insertData, info.HospitalId)
  204. insertData = append(insertData, info.StaffId)
  205. insertData = append(insertData, id_no)
  206. insertData = append(insertData, "01")
  207. insertData = append(insertData, info.StaffName)
  208. insertData = append(insertData, info.Position)
  209. insertData = append(insertData, "0")
  210. insertData = append(insertData, info.StaffId)
  211. insertData = append(insertData, info.PermanentType)
  212. insertData = append(insertData, "2019-09-01")
  213. insertData = append(insertData, info.CreateTime)
  214. insertData = append(insertData, info.UpdateTime)
  215. insertData = append(insertData, info.Sjscsj)
  216. insertData = append(insertData, info.Xgbz)
  217. thisSQL += strings.Join(insertParams, ", ")
  218. utx.Exec(thisSQL, insertData...)
  219. id_no++
  220. }
  221. }
  222. // utx.Commit()
  223. }
  224. return
  225. }
  226. func BatchCreatePatinet(patients []*sz.TempHdPatient, rdb *gorm.DB) (err error) {
  227. if len(patients) > 0 {
  228. utx := rdb
  229. if len(patients) > 0 {
  230. for _, info := range patients {
  231. thisSQL := "INSERT INTO t_hd_patient ( hospital_id, patient_nk, card_no, card_type, id_no, id_type, patient_name, gender, born_date, diagnosis_summary, is_crf, pay_method, local_insurance, dialysis_start_time, local_start_time, outpatient_no, hospitalized_no, xgbz, create_time, update_time, sjscsj) VALUES "
  232. insertParams := make([]string, 0)
  233. insertData := make([]interface{}, 0)
  234. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  235. insertData = append(insertData, info.HospitalId)
  236. insertData = append(insertData, info.PatientNk)
  237. insertData = append(insertData, info.CardNo)
  238. insertData = append(insertData, info.CardType)
  239. insertData = append(insertData, info.IdNo)
  240. insertData = append(insertData, info.IdType)
  241. insertData = append(insertData, info.PatientName)
  242. insertData = append(insertData, info.Gender)
  243. insertData = append(insertData, info.BornDate)
  244. insertData = append(insertData, info.DiagnosisSummary)
  245. insertData = append(insertData, info.IsCrf)
  246. insertData = append(insertData, "02")
  247. insertData = append(insertData, "1")
  248. insertData = append(insertData, info.DialysisStartTime)
  249. insertData = append(insertData, info.LocalStartTime)
  250. insertData = append(insertData, info.OutpatientNo)
  251. insertData = append(insertData, info.HospitalizedNo)
  252. insertData = append(insertData, info.Xgbz)
  253. insertData = append(insertData, info.CreateTime)
  254. insertData = append(insertData, info.UpdateTime)
  255. insertData = append(insertData, info.Sjscsj)
  256. thisSQL += strings.Join(insertParams, ", ")
  257. utx.Exec(thisSQL, insertData...)
  258. }
  259. }
  260. // utx.Commit()
  261. }
  262. return
  263. }
  264. func BatchCreateSchedual(patients []*sz.TempHdShift, rdb *gorm.DB) (err error) {
  265. if len(patients) > 0 {
  266. utx := rdb
  267. if len(patients) > 0 {
  268. for _, info := range patients {
  269. thisSQL := "INSERT INTO t_hd_shift (ps_id, hospital_id, patient_nk, schedule_date, shift_type,sickbed_no,schedule_status,create_time,sjscsj,xgbz) VALUES "
  270. insertParams := make([]string, 0)
  271. insertData := make([]interface{}, 0)
  272. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  273. insertData = append(insertData, info.PsId)
  274. insertData = append(insertData, info.HospitalId)
  275. insertData = append(insertData, info.PatientNk)
  276. insertData = append(insertData, info.ScheduleDate)
  277. insertData = append(insertData, info.ShiftType)
  278. insertData = append(insertData, info.SickbedNo)
  279. insertData = append(insertData, info.ScheduleStatus)
  280. insertData = append(insertData, info.CreateTime)
  281. insertData = append(insertData, info.Sjscsj)
  282. insertData = append(insertData, info.Xgbz)
  283. thisSQL += strings.Join(insertParams, ", ")
  284. utx.Exec(thisSQL, insertData...)
  285. }
  286. }
  287. // utx.Commit()
  288. }
  289. return
  290. }
  291. func BatchCreatePs(patients []*sz.TempHdPs, rdb *gorm.DB) (err error) {
  292. if len(patients) > 0 {
  293. utx := rdb
  294. if len(patients) > 0 {
  295. thisSQL := "INSERT INTO t_hd_ps (prescribe_id,hospital_id,patient_nk,rrt_type,rrt_type_name,dialysis_frequency,frequency_unit,prescribe_time,create_time,sjscsj,xgbz) VALUES "
  296. insertParams := make([]string, 0)
  297. insertData := make([]interface{}, 0)
  298. for _, info := range patients {
  299. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  300. insertData = append(insertData, info.PrescribeId)
  301. insertData = append(insertData, info.HospitalId)
  302. insertData = append(insertData, info.PatientNk)
  303. insertData = append(insertData, info.RrtType)
  304. insertData = append(insertData, info.RrtTypeName)
  305. insertData = append(insertData, info.DialysisFrequency)
  306. insertData = append(insertData, info.FrequencyUnit)
  307. insertData = append(insertData, info.PrescribeTime)
  308. insertData = append(insertData, info.CreateTime)
  309. insertData = append(insertData, info.Sjscsj)
  310. insertData = append(insertData, info.Xgbz)
  311. }
  312. thisSQL += strings.Join(insertParams, ", ")
  313. // err = utx.Exec(thisSQL, insertData...).Error
  314. // if err != nil {
  315. // utx.Rollback()
  316. // return
  317. // }
  318. utx.Exec(thisSQL, insertData...)
  319. }
  320. // utx.Commit()
  321. }
  322. return
  323. }
  324. func BatchCreatePsOther(ps *sz.TempHdPs, rdb *gorm.DB) (err error) {
  325. err = rdb.Create(&ps).Error
  326. return err
  327. }
  328. func BatchCreatePsm(psms []*sz.TempHdPsMedicine, rdb *gorm.DB) (err error) {
  329. if len(psms) > 0 {
  330. utx := rdb
  331. if len(psms) > 0 {
  332. for _, psm := range psms {
  333. thisSQL := "INSERT INTO t_hd_ps_medicine (hospital_id, medicine_type_id,medicine_id,create_time,sjscsj,xgbz,sn) VALUES "
  334. insertParams := make([]string, 0)
  335. insertData := make([]interface{}, 0)
  336. insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
  337. insertData = append(insertData, psm.HospitalId)
  338. insertData = append(insertData, psm.MedicineTypeId)
  339. insertData = append(insertData, psm.MedicineId)
  340. insertData = append(insertData, psm.CreateTime)
  341. insertData = append(insertData, psm.Sjscsj)
  342. insertData = append(insertData, psm.Xgbz)
  343. insertData = append(insertData, psm.Sn)
  344. thisSQL += strings.Join(insertParams, ", ")
  345. // err = utx.Exec(thisSQL, insertData...).Error
  346. utx.Exec(thisSQL, insertData...)
  347. }
  348. // if err != nil {
  349. // utx.Rollback()
  350. // return
  351. // }
  352. }
  353. // utx.Commit()
  354. }
  355. return
  356. }
  357. func BatchCreateDialysis(psms []*sz.TempHdDialysis, rdb *gorm.DB) (err error) {
  358. if len(psms) > 0 {
  359. utx := rdb
  360. if len(psms) > 0 {
  361. for _, psm := range psms {
  362. thisSQL := "INSERT INTO t_hd_dialysis (dialysis_id,hospital_id,patient_nk,ps_id,dialysis_date,sickbed_no,division_id,equipment_id,mix_dialysis,ufv,total_treat_duration,is_hospitalization,is_emergency,is_perioperative_period,before_sbp,before_dbp,after_sbp,after_dbp,before_weight,after_weight,up_nurse_id,down_nurse_id,check_nurse_id,puncture_nurse_id,start_time,end_time,create_time,sjscsj,xgbz) VALUES "
  363. insertParams := make([]string, 0)
  364. insertData := make([]interface{}, 0)
  365. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  366. insertData = append(insertData, psm.DialysisId)
  367. insertData = append(insertData, psm.HospitalId)
  368. insertData = append(insertData, psm.PatientNk)
  369. insertData = append(insertData, psm.PsId)
  370. insertData = append(insertData, psm.DialysisDate)
  371. insertData = append(insertData, psm.SickbedNo)
  372. insertData = append(insertData, psm.DivisionId)
  373. insertData = append(insertData, psm.EquipmentId)
  374. insertData = append(insertData, psm.MixDialysis)
  375. insertData = append(insertData, psm.Ufv)
  376. insertData = append(insertData, psm.TotalTreatDuration)
  377. insertData = append(insertData, psm.IsHospitalization)
  378. insertData = append(insertData, psm.IsEmergency)
  379. insertData = append(insertData, psm.IsPerioperativePeriod)
  380. insertData = append(insertData, psm.BeforeSbp)
  381. insertData = append(insertData, psm.BeforeDbp)
  382. insertData = append(insertData, psm.AfterSbp)
  383. insertData = append(insertData, psm.AfterDbp)
  384. insertData = append(insertData, psm.BeforeWeight)
  385. insertData = append(insertData, psm.AfterWeight)
  386. insertData = append(insertData, psm.UpNurseId)
  387. insertData = append(insertData, psm.DownNurseId)
  388. insertData = append(insertData, psm.CheckNurseId)
  389. insertData = append(insertData, psm.PunctureNurseId)
  390. insertData = append(insertData, psm.StartTime)
  391. insertData = append(insertData, psm.EndTime)
  392. insertData = append(insertData, psm.CreateTime)
  393. insertData = append(insertData, psm.Sjscsj)
  394. insertData = append(insertData, psm.Xgbz)
  395. thisSQL += strings.Join(insertParams, ", ")
  396. utx.Exec(thisSQL, insertData...)
  397. }
  398. // if err != nil {
  399. // utx.Rollback()
  400. // return
  401. // }
  402. }
  403. // utx.Commit()
  404. }
  405. return
  406. }
  407. func BatchCreatePatientOut(patientOuts []*sz.TempHdPatientOut, rdb *gorm.DB) (err error) {
  408. if len(patientOuts) > 0 {
  409. utx := rdb
  410. if len(patientOuts) > 0 {
  411. thisSQL := "INSERT INTO t_hd_patient_quit (sn,hospital_id,patient_nk,sequelae_date,sequelae_type,create_time,death_reason,ext_reason,sjscsj,xgbz) VALUES "
  412. insertParams := make([]string, 0)
  413. insertData := make([]interface{}, 0)
  414. for _, out := range patientOuts {
  415. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  416. insertData = append(insertData, out.Sn)
  417. insertData = append(insertData, out.HospitalId)
  418. insertData = append(insertData, out.PatientNk)
  419. insertData = append(insertData, out.SequelaeDate)
  420. insertData = append(insertData, out.SequelaeType)
  421. insertData = append(insertData, out.CreateTime)
  422. insertData = append(insertData, out.DeathReason)
  423. insertData = append(insertData, out.ExtReason)
  424. insertData = append(insertData, out.Sjscsj)
  425. insertData = append(insertData, out.Xgbz)
  426. }
  427. thisSQL += strings.Join(insertParams, ", ")
  428. utx.Exec(thisSQL, insertData...)
  429. // if err != nil {
  430. // utx.Rollback()
  431. // return
  432. // }
  433. }
  434. // utx.Commit()
  435. }
  436. return
  437. }
  438. func BatchCreateDoctorsAdvice(advices []*sz.TempHdDoctorsAdvice, rdb *gorm.DB) (err error) {
  439. if len(advices) > 0 {
  440. utx := rdb
  441. if len(advices) > 0 {
  442. for _, advice := range advices {
  443. thisSQL := "INSERT INTO t_hd_doctors_advice (medical_order_id, hospital_id,dialysis_id,order_type,patient_nk,dialysis_duration,blood_vol,anticoagulant,create_time,sjscsj,xgbz,rrt_type,rrt_type_name,dry_weight) VALUES "
  444. insertParams := make([]string, 0)
  445. insertData := make([]interface{}, 0)
  446. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  447. insertData = append(insertData, advice.MedicalOrderId)
  448. insertData = append(insertData, advice.HospitalId)
  449. insertData = append(insertData, advice.DialysisId)
  450. insertData = append(insertData, advice.OrderType)
  451. insertData = append(insertData, advice.PatientNk)
  452. insertData = append(insertData, advice.DialysisDuration)
  453. insertData = append(insertData, advice.BloodVol)
  454. insertData = append(insertData, advice.Anticoagulant)
  455. insertData = append(insertData, advice.CreateTime)
  456. insertData = append(insertData, advice.Sjscsj)
  457. insertData = append(insertData, advice.Xgbz)
  458. insertData = append(insertData, advice.RrtType)
  459. insertData = append(insertData, advice.RrtTypeName)
  460. insertData = append(insertData, advice.DryWeight)
  461. thisSQL += strings.Join(insertParams, ", ")
  462. utx.Exec(thisSQL, insertData...)
  463. }
  464. // if err != nil {
  465. // utx.Rollback()
  466. // return
  467. // }
  468. }
  469. // utx.Commit()
  470. }
  471. return
  472. }
  473. func BatchCreateMonitor(advices []*sz.TempHdMiddle, rdb *gorm.DB) (err error) {
  474. if len(advices) > 0 {
  475. utx := rdb
  476. if len(advices) > 0 {
  477. for _, advice := range advices {
  478. thisSQL := "INSERT INTO t_hd_middle (sn,hospital_id, patient_nk,dialysis_id,monitor_time,sbp,dbp,create_time,sjscsj,xgbz) VALUES "
  479. insertParams := make([]string, 0)
  480. insertData := make([]interface{}, 0)
  481. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  482. insertData = append(insertData, advice.Sn)
  483. insertData = append(insertData, advice.HospitalId)
  484. insertData = append(insertData, advice.PatientNk)
  485. insertData = append(insertData, advice.DialysisId)
  486. insertData = append(insertData, advice.MonitorTime)
  487. insertData = append(insertData, advice.Sbp)
  488. insertData = append(insertData, advice.Dbp)
  489. insertData = append(insertData, advice.CreateTime)
  490. insertData = append(insertData, advice.Sjscsj)
  491. insertData = append(insertData, advice.Xgbz)
  492. thisSQL += strings.Join(insertParams, ", ")
  493. utx.Exec(thisSQL, insertData...)
  494. }
  495. // if err != nil {
  496. // utx.Rollback()
  497. // return
  498. // }
  499. }
  500. // utx.Commit()
  501. }
  502. return
  503. }
  504. func FindOrgOtherMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  505. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ? AND (device_type = 1 OR device_type = 3)", org_id)
  506. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  507. err = db.Find(&waterMachine).Error
  508. return
  509. }
  510. func FindOrgMachineRepairData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.DeviceRepair, err error) {
  511. db := readUserDb.Model(&models.DeviceRepair{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("VMDeviceAddmacher", "status = 1")
  512. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  513. err = db.Find(&waterMachine).Error
  514. return
  515. }
  516. func BatchCreateOtherMachineRecord(wms []*sz.TempHdOtherMachine, rdb *gorm.DB) (err error) {
  517. if len(wms) > 0 {
  518. utx := rdb
  519. if len(wms) > 0 {
  520. for _, wm := range wms {
  521. thisSQL := "INSERT INTO t_hd_other_machine (hospital_id, equipment_id, equipment_brand, equipment_model, enable_time,status,equipment_type,xgbz,create_time,update_time,sjscsj) VALUES "
  522. insertParams := make([]string, 0)
  523. insertData := make([]interface{}, 0)
  524. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  525. insertData = append(insertData, wm.HospitalId)
  526. insertData = append(insertData, wm.EquipmentId)
  527. insertData = append(insertData, wm.EquipmentBrand)
  528. insertData = append(insertData, wm.EquipmentModel)
  529. insertData = append(insertData, wm.EnableTime)
  530. insertData = append(insertData, wm.Status)
  531. insertData = append(insertData, wm.EquipmentType)
  532. insertData = append(insertData, wm.Xgbz)
  533. insertData = append(insertData, wm.CreateTime)
  534. insertData = append(insertData, wm.UpdateTime)
  535. insertData = append(insertData, wm.Sjscsj)
  536. thisSQL += strings.Join(insertParams, ", ")
  537. utx.Exec(thisSQL, insertData...)
  538. }
  539. }
  540. // utx.Commit()
  541. }
  542. return
  543. }
  544. func BatchCreateMainTain(maintain []*sz.TempHdMaintain, rdb *gorm.DB) (err error) {
  545. if len(maintain) > 0 {
  546. utx := rdb
  547. if len(maintain) > 0 {
  548. thisSQL := "INSERT INTO t_hd_maintain (hospital_id, equipment_id, equipment_type, repair_time, xgbz,create_time,sjscsj) VALUES "
  549. insertParams := make([]string, 0)
  550. insertData := make([]interface{}, 0)
  551. for _, wm := range maintain {
  552. insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
  553. insertData = append(insertData, wm.HospitalId)
  554. insertData = append(insertData, wm.EquipmentId)
  555. insertData = append(insertData, wm.EquipmentType)
  556. insertData = append(insertData, wm.RepairTime)
  557. insertData = append(insertData, wm.Xgbz)
  558. insertData = append(insertData, wm.CreateTime)
  559. insertData = append(insertData, wm.Sjscsj)
  560. }
  561. thisSQL += strings.Join(insertParams, ", ")
  562. utx.Exec(thisSQL, insertData...)
  563. // if err != nil {
  564. // utx.Rollback()
  565. // return
  566. // }
  567. }
  568. // utx.Commit()
  569. }
  570. return
  571. }
  572. func FindOrgMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  573. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  574. return readDb.Model(&models.DeviceNumber{}).Where("status = 1")
  575. })
  576. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  577. err = db.Find(&waterMachine).Error
  578. return
  579. }
  580. func BatchCreateHDMRecord(wms []*sz.TempHdDm, rdb *gorm.DB) (err error) {
  581. if len(wms) > 0 {
  582. utx := rdb
  583. if len(wms) > 0 {
  584. for _, wm := range wms {
  585. thisSQL := "INSERT INTO t_hd_dm (hospital_id, equipment_id,sickbed_no,sickbed_type ,equipment_brand, equipment_model, enable_time,status,equipment_type, xgbz,bbp,create_time,update_time,sjscsj) VALUES "
  586. insertParams := make([]string, 0)
  587. insertData := make([]interface{}, 0)
  588. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  589. insertData = append(insertData, wm.HospitalId)
  590. insertData = append(insertData, wm.EquipmentId)
  591. insertData = append(insertData, wm.SickbedNo)
  592. insertData = append(insertData, wm.SickbedType)
  593. insertData = append(insertData, wm.EquipmentBrand)
  594. insertData = append(insertData, wm.EquipmentModel)
  595. insertData = append(insertData, wm.EnableTime)
  596. insertData = append(insertData, wm.Status)
  597. insertData = append(insertData, wm.EquipmentType)
  598. insertData = append(insertData, wm.Xgbz)
  599. insertData = append(insertData, wm.Bbp)
  600. insertData = append(insertData, wm.CreateTime)
  601. insertData = append(insertData, wm.UpdateTime)
  602. insertData = append(insertData, wm.Sjscsj)
  603. thisSQL += strings.Join(insertParams, ", ")
  604. utx.Exec(thisSQL, insertData...)
  605. }
  606. // if err != nil {
  607. // utx.Rollback()
  608. // return
  609. // }
  610. }
  611. // utx.Commit()
  612. }
  613. return
  614. }
  615. func CreateHDDivision(wms []*sz.TempHdDivision, rdb *gorm.DB) (err error) {
  616. if len(wms) > 0 {
  617. utx := rdb
  618. if len(wms) > 0 {
  619. for _, wm := range wms {
  620. thisSQL := "INSERT INTO t_hd_division (division_id,hospital_id, division_name,division_type, xgbz,create_time,update_time,sjscsj) VALUES "
  621. insertParams := make([]string, 0)
  622. insertData := make([]interface{}, 0)
  623. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?)")
  624. insertData = append(insertData, wm.DivisionId)
  625. insertData = append(insertData, wm.HospitalId)
  626. insertData = append(insertData, wm.DivisionName)
  627. insertData = append(insertData, wm.DivisionType)
  628. insertData = append(insertData, wm.Xgbz)
  629. insertData = append(insertData, wm.CreateTime)
  630. insertData = append(insertData, wm.UpdateTime)
  631. insertData = append(insertData, wm.Sjscsj)
  632. thisSQL += strings.Join(insertParams, ", ")
  633. utx.Exec(thisSQL, insertData...)
  634. }
  635. }
  636. }
  637. return
  638. }
  639. func CreateAccess(wms []*sz.TempHdAccess, rdb *gorm.DB) (err error) {
  640. if len(wms) > 0 {
  641. utx := rdb
  642. if len(wms) > 0 {
  643. for _, wm := range wms {
  644. thisSQL := "INSERT INTO t_hd_access (access_id,hospital_id,patient_nk,access_type,access_type_name,access_status,setup_date,first_use_time,xgbz,create_time,update_time,sjscsj) VALUES "
  645. insertParams := make([]string, 0)
  646. insertData := make([]interface{}, 0)
  647. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  648. insertData = append(insertData, wm.AccessId)
  649. insertData = append(insertData, wm.HospitalId)
  650. insertData = append(insertData, wm.PatientNk)
  651. insertData = append(insertData, wm.AccessType)
  652. insertData = append(insertData, wm.AccessTypeName)
  653. insertData = append(insertData, wm.AccessStatus)
  654. insertData = append(insertData, wm.SetupDate)
  655. insertData = append(insertData, wm.FirstUseTime)
  656. insertData = append(insertData, wm.Xgbz)
  657. insertData = append(insertData, wm.CreateTime)
  658. insertData = append(insertData, wm.UpdateTime)
  659. insertData = append(insertData, wm.Sjscsj)
  660. thisSQL += strings.Join(insertParams, ", ")
  661. utx.Exec(thisSQL, insertData...)
  662. }
  663. }
  664. }
  665. return
  666. }
  667. func CreateSickbed(wms []*sz.TempHdSickbed, rdb *gorm.DB) (err error) {
  668. if len(wms) > 0 {
  669. utx := rdb
  670. if len(wms) > 0 {
  671. for _, wm := range wms {
  672. thisSQL := "INSERT INTO t_hd_sickbed (sickbed_no,hospital_id,division_id,sickbed_code,sickbed_type,xgbz,create_time,update_time,sjscsj) VALUES "
  673. insertParams := make([]string, 0)
  674. insertData := make([]interface{}, 0)
  675. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  676. insertData = append(insertData, wm.SickbedNo)
  677. insertData = append(insertData, wm.HospitalId)
  678. insertData = append(insertData, wm.DivisionId)
  679. insertData = append(insertData, wm.SickbedCode)
  680. insertData = append(insertData, wm.SickbedType)
  681. insertData = append(insertData, wm.Xgbz)
  682. insertData = append(insertData, wm.CreateTime)
  683. insertData = append(insertData, wm.UpdateTime)
  684. insertData = append(insertData, wm.Sjscsj)
  685. thisSQL += strings.Join(insertParams, ", ")
  686. utx.Exec(thisSQL, insertData...)
  687. }
  688. }
  689. }
  690. return
  691. }
  692. func CreateDiagnosis(wms []*sz.TempHdDiagnosis, rdb *gorm.DB) (err error) {
  693. if len(wms) > 0 {
  694. utx := rdb
  695. if len(wms) > 0 {
  696. for _, wm := range wms {
  697. thisSQL := "INSERT INTO t_hd_diagnosis (diagnosis_id,hospital_id,patient_nk,diagnosis_time,diagnosis_type,diagnosis_type_item,diagnosis_type_detail,xgbz,create_time,update_time,sjscsj) VALUES "
  698. insertParams := make([]string, 0)
  699. insertData := make([]interface{}, 0)
  700. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  701. insertData = append(insertData, wm.DiagnosisId)
  702. insertData = append(insertData, wm.HospitalId)
  703. insertData = append(insertData, wm.PatientNk)
  704. insertData = append(insertData, wm.DiagnosisTime)
  705. insertData = append(insertData, wm.DiagnosisType)
  706. insertData = append(insertData, wm.DiagnosisTypeItem)
  707. insertData = append(insertData, wm.DiagnosisTypeDetail)
  708. insertData = append(insertData, wm.Xgbz)
  709. insertData = append(insertData, wm.CreateTime)
  710. insertData = append(insertData, wm.UpdateTime)
  711. insertData = append(insertData, wm.Sjscsj)
  712. thisSQL += strings.Join(insertParams, ", ")
  713. utx.Exec(thisSQL, insertData...)
  714. }
  715. }
  716. }
  717. return
  718. }
  719. func CreateInfection(wms []*sz.TempHdInfection, rdb *gorm.DB) (err error) {
  720. if len(wms) > 0 {
  721. utx := rdb
  722. if len(wms) > 0 {
  723. for _, wm := range wms {
  724. thisSQL := "INSERT INTO t_hd_infection (sn,hospital_id,patient_nk,hbv,hcv,rpr,hiv,hbsag,hbsab,hbeag,hbeab,hbcab,check_date,doctor_id,xgbz,create_time,sjscsj) VALUES "
  725. insertParams := make([]string, 0)
  726. insertData := make([]interface{}, 0)
  727. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  728. insertData = append(insertData, wm.Sn)
  729. insertData = append(insertData, wm.HospitalId)
  730. insertData = append(insertData, wm.PatientNk)
  731. insertData = append(insertData, wm.Hbv)
  732. insertData = append(insertData, wm.Hcv)
  733. insertData = append(insertData, wm.Rpr)
  734. insertData = append(insertData, wm.Hiv)
  735. insertData = append(insertData, wm.Hbsag)
  736. insertData = append(insertData, wm.Hbsab)
  737. insertData = append(insertData, wm.Hbeag)
  738. insertData = append(insertData, wm.Hbeab)
  739. insertData = append(insertData, wm.Hbcab)
  740. insertData = append(insertData, wm.CheckDate)
  741. insertData = append(insertData, wm.DoctorId)
  742. insertData = append(insertData, wm.Xgbz)
  743. insertData = append(insertData, wm.CreateTime)
  744. insertData = append(insertData, wm.Sjscsj)
  745. thisSQL += strings.Join(insertParams, ", ")
  746. utx.Exec(thisSQL, insertData...)
  747. }
  748. }
  749. }
  750. return
  751. }
  752. func CreateComplication(wms []*sz.TempHdComplication, rdb *gorm.DB) (err error) {
  753. if len(wms) > 0 {
  754. utx := rdb
  755. if len(wms) > 0 {
  756. for _, wm := range wms {
  757. thisSQL := "INSERT INTO t_hd_complication (sn,hospital_id,patient_nk,dialysis_id,monitor_id,neopathy_time,neopathy_type,neopathy_desc,xgbz,create_time,sjscsj) VALUES "
  758. insertParams := make([]string, 0)
  759. insertData := make([]interface{}, 0)
  760. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  761. insertData = append(insertData, wm.Sn)
  762. insertData = append(insertData, wm.HospitalId)
  763. insertData = append(insertData, wm.PatientNk)
  764. insertData = append(insertData, wm.DialysisId)
  765. insertData = append(insertData, wm.MonitorId)
  766. insertData = append(insertData, wm.NeopathyTime)
  767. insertData = append(insertData, wm.NeopathyType)
  768. insertData = append(insertData, wm.NeopathyDesc)
  769. insertData = append(insertData, wm.Xgbz)
  770. insertData = append(insertData, wm.CreateTime)
  771. insertData = append(insertData, wm.Sjscsj)
  772. thisSQL += strings.Join(insertParams, ", ")
  773. utx.Exec(thisSQL, insertData...)
  774. }
  775. }
  776. }
  777. return
  778. }
  779. func CreateLisReport(wms []*sz.TempHdLisReport, rdb *gorm.DB) (err error) {
  780. if len(wms) > 0 {
  781. utx := rdb
  782. if len(wms) > 0 {
  783. for _, wm := range wms {
  784. thisSQL := "INSERT INTO t_hd_lis_report (lab_sno,hospital_id,patient_nk,report_date,check_date,jz_no,mz_flag,zy_no,mz_no,department_code,department_name,card_no,card_type,patient_name,dep_code,dep_name,inspected_type,report_categry,application_name,application_type,check_name,check_item_name,check_item_code,record_ccount,check_result,diagnose_name,xgbz,create_time,sjscsj) VALUES "
  785. insertParams := make([]string, 0)
  786. insertData := make([]interface{}, 0)
  787. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  788. insertData = append(insertData, wm.LabSno)
  789. insertData = append(insertData, wm.HospitalId)
  790. insertData = append(insertData, wm.PatientNk)
  791. insertData = append(insertData, wm.ReportDate)
  792. insertData = append(insertData, wm.CheckDate)
  793. insertData = append(insertData, wm.JzNo)
  794. insertData = append(insertData, wm.MzFlag)
  795. insertData = append(insertData, wm.ZyNo)
  796. insertData = append(insertData, wm.MzNo)
  797. insertData = append(insertData, wm.DepartmentCode)
  798. insertData = append(insertData, wm.DepartmentName)
  799. insertData = append(insertData, wm.CardNo)
  800. insertData = append(insertData, wm.CardType)
  801. insertData = append(insertData, wm.PatientName)
  802. insertData = append(insertData, wm.DepCode)
  803. insertData = append(insertData, wm.DepName)
  804. insertData = append(insertData, wm.InspectedType)
  805. insertData = append(insertData, wm.ReportCategry)
  806. insertData = append(insertData, wm.ApplicationName)
  807. insertData = append(insertData, wm.ApplicationType)
  808. insertData = append(insertData, wm.CheckName)
  809. insertData = append(insertData, wm.CheckItemName)
  810. insertData = append(insertData, wm.CheckItemCode)
  811. insertData = append(insertData, wm.RecordCcount)
  812. insertData = append(insertData, wm.CheckResult)
  813. insertData = append(insertData, wm.DiagnoseName)
  814. insertData = append(insertData, wm.Xgbz)
  815. insertData = append(insertData, wm.CreateTime)
  816. insertData = append(insertData, wm.Sjscsj)
  817. thisSQL += strings.Join(insertParams, ", ")
  818. utx.Exec(thisSQL, insertData...)
  819. }
  820. }
  821. }
  822. return
  823. }
  824. func CreateLisIndicators(wms []*sz.TempHdLisIndicators, rdb *gorm.DB) (err error) {
  825. if len(wms) > 0 {
  826. utx := rdb
  827. if len(wms) > 0 {
  828. for _, wm := range wms {
  829. thisSQL := "INSERT INTO t_hd_lis_indicators (inspected_result_no,hospital_id,lab_sno,report_date,check_date,inspected_indicate,inspected_item_en_name,inspected_item_cn_name,inspected_result_desc,inspected_result_value,inspected_result_unit,ref_range,unit_type,inspected_result,xgbz,create_time,sjscsj) VALUES "
  830. insertParams := make([]string, 0)
  831. insertData := make([]interface{}, 0)
  832. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  833. insertData = append(insertData, wm.InspectedResultNo)
  834. insertData = append(insertData, wm.HospitalId)
  835. insertData = append(insertData, wm.LabSno)
  836. insertData = append(insertData, wm.ReportDate)
  837. insertData = append(insertData, wm.CheckDate)
  838. insertData = append(insertData, wm.InspectedIndicate)
  839. insertData = append(insertData, wm.InspectedItemEnName)
  840. insertData = append(insertData, wm.InspectedItemCnName)
  841. insertData = append(insertData, wm.InspectedResultDesc)
  842. insertData = append(insertData, wm.InspectedResultValue)
  843. insertData = append(insertData, wm.InspectedResultUnit)
  844. insertData = append(insertData, wm.RefRange)
  845. insertData = append(insertData, wm.UnitType)
  846. insertData = append(insertData, wm.InspectedResult)
  847. insertData = append(insertData, wm.Xgbz)
  848. insertData = append(insertData, wm.CreateTime)
  849. insertData = append(insertData, wm.Sjscsj)
  850. thisSQL += strings.Join(insertParams, ", ")
  851. utx.Exec(thisSQL, insertData...)
  852. }
  853. }
  854. }
  855. return
  856. }
  857. func FindOrgCulture(org_id int64, lastUploadTime int64, nowTime int64) (culture []*models.XtDeviceCulture, err error) {
  858. err = UserReadDB().Model(&culture).Where("status = 1 and user_org_id = ? and speling_date>=? and speling_date<=?", org_id, lastUploadTime, nowTime).Find(&culture).Error
  859. return culture, err
  860. }
  861. func CreateLisCulture(wms []*sz.TempHdLisCulture, rdb *gorm.DB) (err error) {
  862. if len(wms) > 0 {
  863. utx := rdb
  864. if len(wms) > 0 {
  865. for _, wm := range wms {
  866. thisSQL := "INSERT INTO t_hd_dm_dialysate_bc (sn,hospital_id,equipment_id,inspection_time,is_qualified,is_substitution_qualified,case_order,create_time,sjscsj,xgbz) VALUES "
  867. insertParams := make([]string, 0)
  868. insertData := make([]interface{}, 0)
  869. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  870. insertData = append(insertData, wm.Sn)
  871. insertData = append(insertData, wm.HospitalId)
  872. insertData = append(insertData, wm.EquitmentId)
  873. insertData = append(insertData, wm.InspectionTime)
  874. insertData = append(insertData, wm.IsQualified)
  875. insertData = append(insertData, wm.IsSubstitutionQualified)
  876. insertData = append(insertData, wm.CaseOrder)
  877. insertData = append(insertData, wm.CreateTime)
  878. insertData = append(insertData, wm.Sjscsj)
  879. insertData = append(insertData, wm.Xgbz)
  880. thisSQL += strings.Join(insertParams, ", ")
  881. utx.Exec(thisSQL, insertData...)
  882. }
  883. }
  884. }
  885. return
  886. }
  887. func FindOrgDialysate(org_id int64, lastUploadTime int64, nowTime int64) (dialysate []*models.XtDeviceDialysate, err error) {
  888. err = UserReadDB().Model(&dialysate).Where("status = 1 and user_org_id = ? and sampling_date>=? and sampling_date<=?", org_id, lastUploadTime, nowTime).Find(&dialysate).Error
  889. return dialysate, err
  890. }
  891. func CreateLisDialysate(wms []*sz.TempHdLisDialysate, rdb *gorm.DB) (err error) {
  892. if len(wms) > 0 {
  893. utx := rdb
  894. if len(wms) > 0 {
  895. for _, wm := range wms {
  896. thisSQL := "INSERT INTO t_hd_dm_dialysate_en (sn,hospital_id,equipment_id,inspection_time,is_qualified,case_order,create_time,sjscsj,xgbz) VALUES "
  897. insertParams := make([]string, 0)
  898. insertData := make([]interface{}, 0)
  899. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  900. insertData = append(insertData, wm.Sn)
  901. insertData = append(insertData, wm.HospitalId)
  902. insertData = append(insertData, wm.EquitmentId)
  903. insertData = append(insertData, wm.InspectionTime)
  904. insertData = append(insertData, wm.IsQualified)
  905. insertData = append(insertData, wm.CaseOrder)
  906. insertData = append(insertData, wm.CreateTime)
  907. insertData = append(insertData, wm.Sjscsj)
  908. insertData = append(insertData, wm.Xgbz)
  909. thisSQL += strings.Join(insertParams, ", ")
  910. utx.Exec(thisSQL, insertData...)
  911. }
  912. }
  913. }
  914. return
  915. }
  916. func FindOrgArialDetection(org_id int64, lastUploadTime int64, nowTime int64) (airdetection []*models.XtAerialDetection, err error) {
  917. err = XTReadDB().Model(&airdetection).Where("user_org_id = ? and status=1 and created_time>=? and created_time<=?", org_id, lastUploadTime, nowTime).Find(&airdetection).Error
  918. return airdetection, err
  919. }
  920. func CreateAirDisinfect(wms []*sz.TempHdLisAirDisinfect, rdb *gorm.DB) (err error) {
  921. if len(wms) > 0 {
  922. utx := rdb
  923. if len(wms) > 0 {
  924. for _, wm := range wms {
  925. thisSQL := "INSERT INTO t_hd_air_disinfect (sn,hospital_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz) VALUES "
  926. insertParams := make([]string, 0)
  927. insertData := make([]interface{}, 0)
  928. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  929. insertData = append(insertData, wm.Sn)
  930. insertData = append(insertData, wm.HospitalId)
  931. insertData = append(insertData, wm.InspectionTime)
  932. insertData = append(insertData, wm.IsQualified)
  933. insertData = append(insertData, wm.InspectedValue)
  934. insertData = append(insertData, wm.CaseOrder)
  935. insertData = append(insertData, wm.CreateTime)
  936. insertData = append(insertData, wm.Sjscsj)
  937. insertData = append(insertData, wm.Xgbz)
  938. thisSQL += strings.Join(insertParams, ", ")
  939. utx.Exec(thisSQL, insertData...)
  940. }
  941. }
  942. }
  943. return
  944. }
  945. func FindOrgBodyDetection(org_id int64, lastUploadTime int64, nowTime int64) (body []*models.XtBodyDetection, err error) {
  946. err = XTReadDB().Model(&body).Where("user_org_id = ? and status=1 and created_time>=? and created_time<=?", org_id, lastUploadTime, nowTime).Find(&body).Error
  947. return body, err
  948. }
  949. func CreateBodyDisinfect(wms []*sz.TempHdLisBodyDisinfect, rdb *gorm.DB) (err error) {
  950. if len(wms) > 0 {
  951. utx := rdb
  952. if len(wms) > 0 {
  953. for _, wm := range wms {
  954. thisSQL := "INSERT INTO t_hd_surface_disinfect (sn,hospital_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz,update_time) VALUES "
  955. insertParams := make([]string, 0)
  956. insertData := make([]interface{}, 0)
  957. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  958. insertData = append(insertData, wm.Sn)
  959. insertData = append(insertData, wm.HospitalId)
  960. insertData = append(insertData, wm.InspectionTime)
  961. insertData = append(insertData, wm.IsQualified)
  962. insertData = append(insertData, wm.InspectedValue)
  963. insertData = append(insertData, wm.CaseOrder)
  964. insertData = append(insertData, wm.CreateTime)
  965. insertData = append(insertData, wm.Sjscsj)
  966. insertData = append(insertData, wm.Xgbz)
  967. insertData = append(insertData, wm.UpdateTime)
  968. thisSQL += strings.Join(insertParams, ", ")
  969. utx.Exec(thisSQL, insertData...)
  970. }
  971. }
  972. }
  973. return
  974. }
  975. func FindOrgWaterFc(org_id int64, lastUploadTime int64, nowTime int64) (water []*models.XtDeviceWater, err error) {
  976. err = UserReadDB().Model(&water).Where("user_org_id = ? and status = 1 and sampling_date>=? and sampling_date<=?", org_id, lastUploadTime, nowTime).Find(&water).Error
  977. return water, err
  978. }
  979. func CreateWaterFc(wms []*sz.TempHdLisWaterFc, rdb *gorm.DB) (err error) {
  980. if len(wms) > 0 {
  981. utx := rdb
  982. if len(wms) > 0 {
  983. for _, wm := range wms {
  984. thisSQL := "INSERT INTO t_hd_water_fc(sn,hospital_id,equitpment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz,update_time) VALUES "
  985. insertParams := make([]string, 0)
  986. insertData := make([]interface{}, 0)
  987. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  988. insertData = append(insertData, wm.Sn)
  989. insertData = append(insertData, wm.HospitalId)
  990. insertData = append(insertData, wm.EquitmentId)
  991. insertData = append(insertData, wm.WaterType)
  992. insertData = append(insertData, wm.InspectionOrgId)
  993. insertData = append(insertData, wm.InspectionTime)
  994. insertData = append(insertData, wm.IsQualified)
  995. insertData = append(insertData, wm.InspectedValue)
  996. insertData = append(insertData, wm.CaseOrder)
  997. insertData = append(insertData, wm.CreateTime)
  998. insertData = append(insertData, wm.Sjscsj)
  999. insertData = append(insertData, wm.Xgbz)
  1000. insertData = append(insertData, wm.UpdateTime)
  1001. thisSQL += strings.Join(insertParams, ", ")
  1002. utx.Exec(thisSQL, insertData...)
  1003. }
  1004. }
  1005. }
  1006. return
  1007. }
  1008. func FindOrgWaterNc(org_id int64, lastUploadTime int64, nowTime int64) (water []*models.XtDeviceOxygenates, err error) {
  1009. err = UserReadDB().Model(&water).Where("user_org_id = ? and status = 1 and sampling_date>=? and sampling_date<=?", org_id, lastUploadTime, nowTime).Find(&water).Error
  1010. return water, err
  1011. }
  1012. func CreateWaterNc(wms []*sz.TempHdLisWaterNc, rdb *gorm.DB) (err error) {
  1013. if len(wms) > 0 {
  1014. utx := rdb
  1015. if len(wms) > 0 {
  1016. for _, wm := range wms {
  1017. thisSQL := "INSERT INTO t_hd_water_nc(sn,hospital_id,equitpment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz,update_time) VALUES "
  1018. insertParams := make([]string, 0)
  1019. insertData := make([]interface{}, 0)
  1020. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  1021. insertData = append(insertData, wm.Sn)
  1022. insertData = append(insertData, wm.HospitalId)
  1023. insertData = append(insertData, wm.EquitmentId)
  1024. insertData = append(insertData, wm.WaterType)
  1025. insertData = append(insertData, wm.InspectionOrgId)
  1026. insertData = append(insertData, wm.InspectionTime)
  1027. insertData = append(insertData, wm.IsQualified)
  1028. insertData = append(insertData, wm.InspectedValue)
  1029. insertData = append(insertData, wm.CaseOrder)
  1030. insertData = append(insertData, wm.CreateTime)
  1031. insertData = append(insertData, wm.Sjscsj)
  1032. insertData = append(insertData, wm.Xgbz)
  1033. insertData = append(insertData, wm.UpdateTime)
  1034. thisSQL += strings.Join(insertParams, ", ")
  1035. utx.Exec(thisSQL, insertData...)
  1036. }
  1037. }
  1038. }
  1039. return
  1040. }
  1041. func FindOrgWaterPh(org_id int64, lastUploadTime int64, nowTime int64) (water []*models.XtDevicePh, err error) {
  1042. err = UserReadDB().Model(&water).Where("user_org_id = ? and sampling_date>? and sampling_date<=?", org_id, lastUploadTime, nowTime).Find(&water).Error
  1043. return water, err
  1044. }
  1045. func CreateWaterPh(wms []*sz.TempHdLisWaterPh, rdb *gorm.DB) (err error) {
  1046. if len(wms) > 0 {
  1047. utx := rdb
  1048. if len(wms) > 0 {
  1049. for _, wm := range wms {
  1050. thisSQL := "INSERT INTO t_hd_water_ph(sn,hospital_id,equitpment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz,update_time) VALUES "
  1051. insertParams := make([]string, 0)
  1052. insertData := make([]interface{}, 0)
  1053. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  1054. insertData = append(insertData, wm.Sn)
  1055. insertData = append(insertData, wm.HospitalId)
  1056. insertData = append(insertData, wm.EquitmentId)
  1057. insertData = append(insertData, wm.WaterType)
  1058. insertData = append(insertData, wm.InspectionOrgId)
  1059. insertData = append(insertData, wm.InspectionTime)
  1060. insertData = append(insertData, wm.IsQualified)
  1061. insertData = append(insertData, wm.InspectedValue)
  1062. insertData = append(insertData, wm.CaseOrder)
  1063. insertData = append(insertData, wm.CreateTime)
  1064. insertData = append(insertData, wm.Sjscsj)
  1065. insertData = append(insertData, wm.Xgbz)
  1066. insertData = append(insertData, wm.UpdateTime)
  1067. thisSQL += strings.Join(insertParams, ", ")
  1068. utx.Exec(thisSQL, insertData...)
  1069. }
  1070. }
  1071. }
  1072. return
  1073. }
  1074. func FindOrgWaterWh(org_id int64, lastUploadTime int64, nowTime int64) (water []*models.XtDeviceHadwater, err error) {
  1075. err = UserReadDB().Model(&water).Where("user_org_id = ? and sampling_date>=? and sampling_date<=? and status =1", org_id, lastUploadTime, nowTime).Find(&water).Error
  1076. return water, err
  1077. }
  1078. func CreateWaterWh(wms []*sz.TempHdLisWaterWh, rdb *gorm.DB) (err error) {
  1079. if len(wms) > 0 {
  1080. utx := rdb
  1081. if len(wms) > 0 {
  1082. for _, wm := range wms {
  1083. thisSQL := "INSERT INTO t_hd_water_wh(sn,hospital_id,equitpment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz,update_time) VALUES "
  1084. insertParams := make([]string, 0)
  1085. insertData := make([]interface{}, 0)
  1086. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  1087. insertData = append(insertData, wm.Sn)
  1088. insertData = append(insertData, wm.HospitalId)
  1089. insertData = append(insertData, wm.EquitmentId)
  1090. insertData = append(insertData, wm.WaterType)
  1091. insertData = append(insertData, wm.InspectionOrgId)
  1092. insertData = append(insertData, wm.InspectionTime)
  1093. insertData = append(insertData, wm.IsQualified)
  1094. insertData = append(insertData, wm.InspectedValue)
  1095. insertData = append(insertData, wm.CaseOrder)
  1096. insertData = append(insertData, wm.CreateTime)
  1097. insertData = append(insertData, wm.Sjscsj)
  1098. insertData = append(insertData, wm.Xgbz)
  1099. insertData = append(insertData, wm.UpdateTime)
  1100. thisSQL += strings.Join(insertParams, ", ")
  1101. utx.Exec(thisSQL, insertData...)
  1102. }
  1103. }
  1104. }
  1105. return
  1106. }
  1107. func FindOrgHdCi(org_id int64, lastUploadTime int64, nowTime int64) (access []*models.XtPatientVascularAccess, err error) {
  1108. err = XTReadDB().Model(&access).Where("user_org_id = ? and start_time>=? and start_time<=? and access_project = 2 and status =1", org_id, lastUploadTime, nowTime).Find(&access).Error
  1109. return access, err
  1110. }
  1111. func CreateHdCi(wms []*sz.TempHdCi, rdb *gorm.DB) (err error) {
  1112. if len(wms) > 0 {
  1113. utx := rdb
  1114. if len(wms) > 0 {
  1115. for _, wm := range wms {
  1116. thisSQL := "INSERT INTO t_hd_ci(infect_sn,hospital_id,patient_nk,access_id,ci_type,blood_culture,infection_date,create_time,sjscsj,xgbz) VALUES "
  1117. insertParams := make([]string, 0)
  1118. insertData := make([]interface{}, 0)
  1119. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  1120. insertData = append(insertData, wm.InfectSn)
  1121. insertData = append(insertData, wm.HospitalId)
  1122. insertData = append(insertData, wm.PatientNk)
  1123. insertData = append(insertData, wm.AccessId)
  1124. insertData = append(insertData, wm.CiType)
  1125. insertData = append(insertData, wm.BloodCulture)
  1126. insertData = append(insertData, wm.InfectionDate)
  1127. insertData = append(insertData, wm.CreateTime)
  1128. insertData = append(insertData, wm.Sjscsj)
  1129. insertData = append(insertData, wm.Xgbz)
  1130. thisSQL += strings.Join(insertParams, ", ")
  1131. utx.Exec(thisSQL, insertData...)
  1132. }
  1133. }
  1134. }
  1135. return
  1136. }
  1137. func FindOrgHdCiOutCome(org_id int64, lastUploadTime int64, nowTime int64) (access []*models.XtPatientVascularAccess, err error) {
  1138. err = XTReadDB().Model(&access).Where("user_org_id = ? and start_time>=? and start_time<=? and access_project = 2 and status =1", org_id, lastUploadTime, nowTime).Find(&access).Error
  1139. return access, err
  1140. }
  1141. func CreateHdCiOutCome(wms []*sz.TempHdCiOutCome, rdb *gorm.DB) (err error) {
  1142. if len(wms) > 0 {
  1143. utx := rdb
  1144. if len(wms) > 0 {
  1145. for _, wm := range wms {
  1146. thisSQL := "INSERT INTO t_hd_ci_outcome(hospital_id,sn,infect_sn,patient_nk,sequelae_type,sjscsj,xgbz,create_time,update_time) VALUES "
  1147. insertParams := make([]string, 0)
  1148. insertData := make([]interface{}, 0)
  1149. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  1150. insertData = append(insertData, wm.HospitalId)
  1151. insertData = append(insertData, wm.Sn)
  1152. insertData = append(insertData, wm.InfectSn)
  1153. insertData = append(insertData, wm.PatientNk)
  1154. insertData = append(insertData, wm.SequelaeType)
  1155. insertData = append(insertData, wm.Sjscsj)
  1156. insertData = append(insertData, wm.Xgbz)
  1157. insertData = append(insertData, wm.CreateTime)
  1158. insertData = append(insertData, wm.UpdateTime)
  1159. thisSQL += strings.Join(insertParams, ", ")
  1160. utx.Exec(thisSQL, insertData...)
  1161. }
  1162. }
  1163. }
  1164. return
  1165. }
  1166. func CreateLisWaterBc(wms []*sz.TempHdLisWaterBc, rdb *gorm.DB) (err error) {
  1167. if len(wms) > 0 {
  1168. utx := rdb
  1169. if len(wms) > 0 {
  1170. for _, wm := range wms {
  1171. thisSQL := "INSERT INTO t_hd_water_bc (hospital_id,sn,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,sjscsj,xgbz,create_time,update_time) VALUES "
  1172. insertParams := make([]string, 0)
  1173. insertData := make([]interface{}, 0)
  1174. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  1175. insertData = append(insertData, wm.HospitalId)
  1176. insertData = append(insertData, wm.Sn)
  1177. insertData = append(insertData, wm.EquitmentId)
  1178. insertData = append(insertData, wm.WaterType)
  1179. insertData = append(insertData, wm.InspectionOrgId)
  1180. insertData = append(insertData, wm.InspectionTime)
  1181. insertData = append(insertData, wm.IsQualified)
  1182. insertData = append(insertData, wm.InspectedValue)
  1183. insertData = append(insertData, wm.CaseOrder)
  1184. insertData = append(insertData, wm.Sjscsj)
  1185. insertData = append(insertData, wm.Xgbz)
  1186. insertData = append(insertData, wm.CreateTime)
  1187. insertData = append(insertData, wm.UpdateTime)
  1188. thisSQL += strings.Join(insertParams, ", ")
  1189. utx.Exec(thisSQL, insertData...)
  1190. }
  1191. }
  1192. }
  1193. return
  1194. }
  1195. func CreateLisWaterEn(wms []*sz.TempHdLisWaterEn, rdb *gorm.DB) (err error) {
  1196. if len(wms) > 0 {
  1197. utx := rdb
  1198. if len(wms) > 0 {
  1199. for _, wm := range wms {
  1200. thisSQL := "INSERT INTO t_hd_water_en (hospital_id,sn,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,sjscsj,xgbz,create_time,update_time) VALUES "
  1201. insertParams := make([]string, 0)
  1202. insertData := make([]interface{}, 0)
  1203. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  1204. insertData = append(insertData, wm.HospitalId)
  1205. insertData = append(insertData, wm.Sn)
  1206. insertData = append(insertData, wm.EquitmentId)
  1207. insertData = append(insertData, wm.WaterType)
  1208. insertData = append(insertData, wm.InspectionOrgId)
  1209. insertData = append(insertData, wm.InspectionTime)
  1210. insertData = append(insertData, wm.IsQualified)
  1211. insertData = append(insertData, wm.InspectedValue)
  1212. insertData = append(insertData, wm.CaseOrder)
  1213. insertData = append(insertData, wm.Sjscsj)
  1214. insertData = append(insertData, wm.Xgbz)
  1215. insertData = append(insertData, wm.CreateTime)
  1216. insertData = append(insertData, wm.UpdateTime)
  1217. thisSQL += strings.Join(insertParams, ", ")
  1218. utx.Exec(thisSQL, insertData...)
  1219. }
  1220. }
  1221. }
  1222. return
  1223. }