city_data_uoload_service.go 80KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964
  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. "time"
  9. )
  10. func GetSyncTimeByOrgId(org_id int64, sync_type int64) (sync_info models.XTSyncInfo, err error) {
  11. err = readDb.Model(&models.XTSyncInfo{}).Where("org_id = ? and sync_type = ? ", org_id, sync_type).Last(&sync_info).Error
  12. return
  13. }
  14. func FindAllDataUploadConfigOrgInfo(province_id int64, city_id int64, config_type int64) (data []*sz.DataUploadConfig, err error) {
  15. 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
  16. return
  17. }
  18. func FindDataUploadOrgInfo(org_id int64, module_type int64) (data sz.DataUpload, err error) {
  19. err = readDb.Model(&sz.DataUpload{}).Where(" org_id = ? AND module_type = ?", org_id, module_type).Last(&data).Error
  20. return
  21. }
  22. func FindOrgData(org_id int64, sync_time int64) (org models.UserOrg, err error) {
  23. err = readUserDb.Model(&models.UserOrg{}).Where("status = 1 AND id = ? AND ctime > ?", org_id, sync_time).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  24. return readDb.Where("status = 1")
  25. }).Find(&org).Error
  26. return
  27. }
  28. func FindOrgRolesData(org_id int64, lastUploadTime int64, nowTime int64) (role []*models.UserAdminRole, err error) {
  29. db := readUserDb.Model(&models.UserAdminRole{}).Where("status = 1 AND org_id = ? ", org_id)
  30. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  31. err = db.Find(&role).Error
  32. return
  33. }
  34. func FindOrgDeviceZone(org_id int64, lastUploadTime int64, nowTime int64) (role []*models.DeviceZone, err error) {
  35. db := readDb.Model(&models.DeviceZone{}).Where("status = 1 AND org_id = ? ", org_id)
  36. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  37. err = db.Find(&role).Error
  38. return
  39. }
  40. func FindDrugList(org_id int64, lastUploadTime int64, nowTime int64) (drugs []*models.BaseDrugLib, err error) {
  41. db := readDb.Model(&models.BaseDrugLib{}).Where("status = 1 AND org_id = ? ", org_id)
  42. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  43. err = db.Find(&drugs).Error
  44. return
  45. }
  46. func FindProjectList(org_id int64, lastUploadTime int64, nowTime int64) (projects []*models.XtHisProject, err error) {
  47. db := readDb.Model(&models.XtHisProject{}).Where("status = 1 AND user_org_id = ? ", org_id)
  48. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  49. err = db.Find(&projects).Error
  50. return
  51. }
  52. func FindOrgRolesDataNew(org_id int64, lastUploadTime int64, nowTime int64) (role []*models.App_Role, err error) {
  53. db := readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ? ", org_id)
  54. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  55. err = db.Find(&role).Error
  56. return
  57. }
  58. func FindOrgPatientData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
  59. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", org_id)
  60. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  61. err = db.Find(&patient).Error
  62. return
  63. }
  64. func FindHisPatientData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.HisPatient, err error) {
  65. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND total_dialysis > 0", org_id)
  66. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  67. err = db.Find(&patient).Error
  68. return
  69. }
  70. func FindOrgPatientInfoById(id int64) (*models.Patients, error) {
  71. var patient models.Patients
  72. db := readDb.Model(&models.Patients{}).Where("status = 1 AND id = ?", id)
  73. err = db.First(&patient).Error
  74. return &patient, err
  75. }
  76. func FindOrgHisPatient(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.HisPatient, err error) {
  77. db := readDb.Model(&models.HisPatient{}).Where("status = 1 AND user_org_id = ?", org_id)
  78. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  79. err = db.Find(&patient).Error
  80. return
  81. }
  82. func FindOrgHisPatientCnt(org_id int64, sync_date int64) (total int64, err error) {
  83. err = readDb.Model(&models.HisPatient{}).Where("status = 1 AND user_org_id = ?", org_id).Where("record_date = ? ", sync_date).Count(&total).Error
  84. return total, err
  85. }
  86. func FindOrgHisPatientCntOne(orgid int64, startime int64) (models.ResultOne, error) {
  87. info := models.ResultOne{}
  88. db := XTReadDB().Table("his_order as x").Where("x.status = 1").Where("x.order_status = 2").Where("x.user_org_id = ?", orgid).Where("x.settle_accounts_date = ?", startime)
  89. err = db.Select("sum(p.det_item_fee_sumamt) as sumamt,sum(p.inscp_scp_amt) as amt").Joins("left join his_order_info as p on p.order_id = x.id").Scan(&info).Error
  90. return info, err
  91. }
  92. func FindOrgHisPatientCntTwo(orgid int64, startime int64) (models.ResultOne, error) {
  93. result := models.ResultOne{}
  94. db := XTReadDB().Table("his_order as x").Where("x.status = 1").Where("x.order_status = 2").Where("x.user_org_id = ?", orgid).Where("x.settle_accounts_date = ?", startime)
  95. err = db.Select("sum(p.det_item_fee_sumamt) as sumamt,sum(p.inscp_scp_amt) as amt").Joins("left join his_order_info as p on p.order_id = x.id and p.advice_id > 0").Scan(&result).Error
  96. return result, err
  97. }
  98. func FindOrgHisPrescriptionInfo(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.HisPrescriptionInfo, err error) {
  99. db := readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id)
  100. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  101. err = db.Find(&patient).Error
  102. return
  103. }
  104. func FindOrgHisPrescription(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.HisPrescription, err error) {
  105. db := readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ?", org_id)
  106. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  107. err = db.Find(&patient).Error
  108. return
  109. }
  110. func FindOrgHisDoctorAdviceInfo(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.HisDoctorAdviceInfo, err error) {
  111. db := readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ?", org_id)
  112. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  113. err = db.Find(&patient).Error
  114. return
  115. }
  116. func FindOrgHisDoctorAdviceInfoByPid(org_id int64, pid int64) (patient []*models.HisDoctorAdviceInfo, err error) {
  117. db := readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? and prescription_id = ?", org_id,pid)
  118. err = db.Find(&patient).Error
  119. return
  120. }
  121. func FindOrgHisOrder(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.HisOrder, err error) {
  122. db := readDb.Model(&models.HisOrder{}).Where("status = 1 AND user_org_id = ?", org_id)
  123. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  124. err = db.Find(&patient).Error
  125. return
  126. }
  127. func FindOrgHisOrderInfo(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.HisOrderInfo, err error) {
  128. db := readDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND user_org_id = ?", org_id)
  129. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  130. err = db.Find(&patient).Error
  131. return
  132. }
  133. func GetHisOrderByNumber(order_number string) (*models.HisOrder, error) {
  134. var order models.HisOrder
  135. db := readDb.Model(&models.HisOrder{}).Where("number = ? AND status = 1 ", order_number)
  136. err = db.First(&order).Error
  137. return &order, err
  138. }
  139. func GetHisDoctorAdviceInfo(id int64) (*models.HisDoctorAdviceInfo, error) {
  140. var order models.HisDoctorAdviceInfo
  141. db := readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id = ? AND status = 1 ", id)
  142. err = db.Find(&order).Error
  143. return &order, err
  144. }
  145. func GetHisPrescriptionProjectInfo(id int64) (*models.HisPrescriptionProject, error) {
  146. var order models.HisPrescriptionProject
  147. db := readDb.Model(&models.HisPrescriptionProject{}).Where("id = ? AND status = 1 ", id)
  148. err = db.Find(&order).Error
  149. return &order, err
  150. }
  151. func GetHisProjectInfo(id int64) (*models.HisProject, error) {
  152. var order models.HisProject
  153. db := readDb.Model(&models.HisProject{}).Where("id = ? AND status = 1 ", id)
  154. err = db.Find(&order).Error
  155. return &order, err
  156. }
  157. func GetGoodInfo(id int64) (*models.GoodInfo, error) {
  158. var order models.GoodInfo
  159. db := readDb.Model(&models.GoodInfo{}).Where("id = ? AND status = 1 ", id)
  160. err = db.Find(&order).Error
  161. return &order, err
  162. }
  163. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  164. db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  165. return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  166. })
  167. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  168. return
  169. }
  170. func FindOrgHisPrescriptionById(id int64) (*models.HisPrescription, error) {
  171. var HisPrescription models.HisPrescription
  172. db := readDb.Model(&models.HisPrescription{}).Where("status = 1 and id =? ", id)
  173. err = db.First(&HisPrescription).Error
  174. return &HisPrescription, err
  175. }
  176. func FindBaseDrugLibById(id int64) (*models.BaseDrugLib, error) {
  177. var BaseDrugLib models.BaseDrugLib
  178. db := readDb.Model(&models.BaseDrugLib{}).Where("status = 1 and id =? ", id)
  179. err = db.First(&BaseDrugLib).Error
  180. return &BaseDrugLib, err
  181. }
  182. func FindOrgHisPrescriptionInfoByNumber(org_id int64, prescription_number string) (*models.HisPrescriptionInfo, error) {
  183. var HisPrescriptionInfo models.HisPrescriptionInfo
  184. db := readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? and prescription_number =? ", org_id, prescription_number)
  185. err = db.First(&HisPrescriptionInfo).Error
  186. return &HisPrescriptionInfo, err
  187. }
  188. func FindOrgHisPatientInfo(org_id int64, record_date int64, patient_id int64) (*models.HisPatient, error) {
  189. var HisPatient models.HisPatient
  190. db := readDb.Model(&models.HisPatient{}).Where("status = 1 AND user_org_id = ? and record_date =? and patient_id = ?", org_id, record_date, patient_id)
  191. err = db.First(&HisPatient).Error
  192. return &HisPatient, err
  193. }
  194. func FindOrgPatientDataOne(org_id int64) (patient []*models.Patients, err error) {
  195. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", org_id)
  196. err = db.Find(&patient).Error
  197. return
  198. }
  199. func FindOrgPatientInfectious(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
  200. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND lapseto = 2 ", org_id)
  201. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  202. err = db.Find(&patient).Error
  203. return
  204. }
  205. func FindOrgDeviceNumber(org_id int64, lastUploadTime int64, nowTime int64) (devices []*models.DeviceNumber, err error) {
  206. db := readDb.Model(&models.DeviceNumber{}).Where("status = 1 AND org_id = ?", org_id)
  207. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  208. err = db.Find(&devices).Error
  209. return
  210. }
  211. func FindOrgPatientOutData(lastUploadTime int64, nowTime int64) (patient []*models.PatientLapseto, err error) {
  212. db := readDb.Model(&models.PatientLapseto{}).Where("status = 1 AND lapseto_type >= 2 ")
  213. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  214. err = db.Find(&patient).Error
  215. return
  216. }
  217. func FindOrgPatientOutDataTwo(lastUploadTime int64, nowTime int64) (patient []*models.XtPatientAllergic, err error) {
  218. db := readDb.Model(&models.XtPatientAllergic{}).Where("status = 1 AND patient_source >= 2 ")
  219. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  220. err = db.Find(&patient).Error
  221. return
  222. }
  223. func FindOrgPatientOutDataByID(patient_id int64) (*models.PatientLapseto, error) {
  224. var patient models.PatientLapseto
  225. db := readDb.Model(&models.PatientLapseto{}).Where("status = 1 AND lapseto_type >= 2 AND patient_id =? ", patient_id)
  226. err = db.First(&patient).Error
  227. return &patient, err
  228. }
  229. func FindOrgScheduleData(org_id int64, lastUploadTime int64, nowTime int64) (sch []*models.Schedule, err error) {
  230. db := readDb.Model(&models.Schedule{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DeviceNumber", "status = 1")
  231. if lastUploadTime != 0 && nowTime != 0 {
  232. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  233. }
  234. err = db.Find(&sch).Error
  235. return
  236. }
  237. func FindOrgDialysisPrescriptionData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.DialysisPrescription, err error) {
  238. db := readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DialysisOrder", "status = 1")
  239. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  240. err = db.Find(&ps).Error
  241. return
  242. }
  243. func FindOrgDoctorAdviceTemplateData(org_id int64, lastUploadTime int64, nowTime int64) (advice []*models.DoctorAdviceTemplate, err error) {
  244. db := readDb.Model(&models.DoctorAdviceTemplate{}).Where("status = 1 AND org_id = ? and advice_type = 0 ", org_id)
  245. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  246. err = db.Find(&advice).Error
  247. return
  248. }
  249. func FindOrgDoctorAdvice(org_id int64, lastUploadTime int64, nowTime int64) (advice []*models.DoctorAdvice, err error) {
  250. db := readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND org_id = ? ", org_id)
  251. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  252. err = db.Find(&advice).Error
  253. return
  254. }
  255. func FindAssessmentBeforeDislysis(org_id int64, patient_id int64) (before models.AssessmentBeforeDislysis, err error) {
  256. db := readDb.Model(&models.AssessmentBeforeDislysis{}).Where("status = 1 AND user_org_id = ? and patient_id = ? ", org_id, patient_id)
  257. err = db.Last(&before).Error
  258. return
  259. }
  260. func FindOrgMonitorRecordData(org_id int64, lastUploadTime int64, nowTime int64) (monitor []*models.MonitoringRecord, err error) {
  261. db := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DialysisOrder", "status = 1")
  262. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  263. err = db.Find(&monitor).Error
  264. return
  265. }
  266. func FindOrgMonitorRecordByLike(org_id int64, keyword string, lastUploadTime int64, nowTime int64) (monitor []*models.MonitoringRecord, err error) {
  267. db := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND symptom like ?", org_id, keyword)
  268. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  269. err = db.Find(&monitor).Error
  270. return
  271. }
  272. func FindOrgInspection(org_id int64, lastUploadTime int64, nowTime int64) (inspection []*models.XtInspection, err error) {
  273. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? ", org_id).Preload("Patients", "status = 1")
  274. db = db.Where("inspect_date >= ? AND inspect_date <= ?", lastUploadTime, nowTime).Group("inspect_date,project_id,patient_id")
  275. err = db.Find(&inspection).Error
  276. return
  277. }
  278. func FindLisReportByLAB(rdb *gorm.DB, lab_sno string) (lisreport []*sz.TempHdLisReport, err error) {
  279. db := rdb.Model(&sz.TempHdLisReport{}).Where("LAB_SNO = ? ", lab_sno)
  280. err = db.Find(&lisreport).Error
  281. return
  282. }
  283. func FindLisINDICATORSByNo(rdb *gorm.DB, lab_sno string, inspected_result_no string) (lisreport []*sz.TempHdLisIndicators, err error) {
  284. db := rdb.Model(&sz.TempHdLisIndicators{}).Where("LAB_SNO = ? AND INSPECTED_RESULT_NO = ?", lab_sno, inspected_result_no)
  285. err = db.Find(&lisreport).Error
  286. return
  287. }
  288. func FindLisINDICATORSByNoUpdate(rdb *gorm.DB, lab_sno string, inspected_result_no string, inspected_result_desc string, inspected_result_unit string, create_time time.Time) (err error) {
  289. err = rdb.Exec("update t_hd_lis_indicators set inspected_result_desc = ?,inspected_result_value = ?,inspected_result_unit = ?,create_time = ? "+
  290. "WHERE LAB_SNO = ? and INSPECTED_RESULT_NO = ? ", inspected_result_desc, inspected_result_desc, inspected_result_unit, create_time, lab_sno, inspected_result_no).Error
  291. return
  292. }
  293. func FindOrgInspectionTwo(org_id int64, lastUploadTime int64, nowTime int64) (inspection []*models.XtInspection, err error) {
  294. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? ", org_id).Preload("XtInspectionReference", "status = 1")
  295. db = db.Where("inspect_date >= ? AND inspect_date <= ?", lastUploadTime, nowTime)
  296. err = db.Find(&inspection).Error
  297. return
  298. }
  299. func FindOrgInspectionThree(org_id int64, lastUploadTime int64, nowTime int64, itemid string) (inspection []*models.XtInspection, err error) {
  300. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? ", org_id).Preload("XtInspectionReference", "status = 1")
  301. db = db.Where("inspect_date >= ? AND inspect_date <= ? AND item_id = ?", lastUploadTime, nowTime, itemid)
  302. err = db.Find(&inspection).Error
  303. return
  304. }
  305. // 传染病查询
  306. func FindOrgInspectionGroupOne(org_id int64, lastUploadTime int64, nowTime int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  307. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? and project_id = 14 and patient_id = ?", org_id, patient_id)
  308. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime).Group("inspect_date")
  309. err = db.Find(&inspection).Error
  310. return
  311. }
  312. // 传染病查询 龙岗二院
  313. func FindOrgInspectionGroupLgey(org_id int64, lastUploadTime int64, nowTime int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  314. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? and project_id in(14,18006,18008,18044,18051,18065,18076,18078,18114,18130,18131,18141,18142,18143,18167,18169,18175,18176,18178,18230,18241,18245,18246,14) and patient_id = ?", org_id, patient_id)
  315. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime).Group("inspect_date")
  316. err = db.Find(&inspection).Error
  317. return
  318. }
  319. // 传染病查询
  320. func FindOrgInspectionGroupLgeyTwo(org_id int64, inspect_date int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  321. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? and project_id in(18006,18008,18044,18051,18065,18076,18078,18114,18130,18131,18141,18142,18143,18167,18169,18175,18176,18178,18230,18241,18245,18246,14) and patient_id = ? and inspect_date = ?", org_id, patient_id, inspect_date)
  322. err = db.Find(&inspection).Error
  323. return
  324. }
  325. // 传染病查询 深圳百霖
  326. func FindOrgInspectionGroupSzbl(org_id int64, lastUploadTime int64, nowTime int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  327. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? and project_id in (1013800,1013870) and patient_id = ?", org_id, patient_id)
  328. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime).Group("inspect_date")
  329. err = db.Find(&inspection).Error
  330. return
  331. }
  332. // 传染病查询 深圳百霖贝尔
  333. func FindOrgInspectionGroupSzblbr(org_id int64, lastUploadTime int64, nowTime int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  334. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? and project_id in (1013803,1013856) and patient_id = ?", org_id, patient_id)
  335. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime).Group("inspect_date")
  336. err = db.Find(&inspection).Error
  337. return
  338. }
  339. // 传染病查询
  340. func FindOrgInspectionGroupSzblTwo(org_id int64, inspect_date int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  341. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? and project_id in (1013800,1013870) and patient_id = ? and inspect_date = ?", org_id, patient_id, inspect_date)
  342. err = db.Find(&inspection).Error
  343. return
  344. }
  345. // 传染病查询
  346. func FindOrgInspectionGroupSzblbrTwo(org_id int64, inspect_date int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  347. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? and project_id in (1013803,1013856) and patient_id = ? and inspect_date = ?", org_id, patient_id, inspect_date)
  348. err = db.Find(&inspection).Error
  349. return
  350. }
  351. // 传染病查询
  352. func FindOrgInspectionGroupTwo(org_id int64, inspect_date int64, patient_id int64) (inspection []*models.XtInspection, err error) {
  353. 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)
  354. err = db.Find(&inspection).Error
  355. return
  356. }
  357. func FindOrgInspectionReference(org_id int64, lastUploadTime int64, nowTime int64) (inspection []*models.XtInspection, err error) {
  358. db := readDb.Model(&models.XtInspection{}).Where("status = 1 AND org_id = ? ", org_id).Preload("XtInspectionReference", "status = 1")
  359. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  360. err = db.Find(&inspection).Error
  361. return
  362. }
  363. func CreateOrgRecord(rdb *gorm.DB, hospital *sz.TempHdHospital) (err error) {
  364. err = rdb.Model(&sz.TempHdHospital{}).Create(&hospital).Error
  365. return
  366. }
  367. func CreateUploadRecord(upload *sz.DataUpload) (err error) {
  368. err = writeDb.Model(&sz.DataUpload{}).Create(&upload).Error
  369. return
  370. }
  371. func FindOrgDialysisData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.VMDialysisOrder, err error) {
  372. db := readDb.Model(&models.VMDialysisOrder{}).Where("status = 1 AND user_org_id = ? AND stage = 2 ", org_id).
  373. Preload("DeviceNumber", "status = 1").
  374. Preload("VMDialysisPrescription", "status = 1").
  375. Preload("AssessmentBeforeDislysis", "status = 1").
  376. Preload("AssessmentAfterDislysis", "status = 1").
  377. Preload("Schedule", "status = 1").
  378. Preload("MonitoringRecord", "status = 1")
  379. if lastUploadTime != 0 && nowTime != 0 {
  380. db = db.Where("updated_time >= ? AND updated_time <= ?", lastUploadTime, nowTime)
  381. }
  382. err = db.Find(&ps).Error
  383. return
  384. }
  385. func FindOrgDeviceZoneRecordData(org_id int64, lastUploadTime int64, nowTime int64) (zone []*models.DeviceZone, err error) {
  386. db := readDb.Model(&models.DeviceZone{}).Where("status = 1 AND org_id = ?", org_id)
  387. if lastUploadTime != 0 && nowTime != 0 {
  388. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  389. }
  390. err = db.Find(&zone).Error
  391. return
  392. }
  393. func FindOrgWaterMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  394. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ? AND device_type = 2", org_id)
  395. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  396. err = db.Find(&waterMachine).Error
  397. return
  398. }
  399. func FindSyncPatientAllData(rdb *gorm.DB) (hdPatients []*sz.TempHdPatient, err error) {
  400. err = rdb.Model(&sz.TempHdPatient{}).Find(&hdPatients).Error
  401. return
  402. }
  403. func UpdateSyncPatient(patientId int64, ylyl1 string, rdb *gorm.DB) (err error) {
  404. err = rdb.Model(&sz.TempHdPatient{}).Where("patient_nk = ?", patientId).Update("ylyl1", ylyl1).Error
  405. return
  406. }
  407. func FindSyncPatient(patientId int64, rdb *gorm.DB) (hdPatients []*sz.TempHdPatient, err error) {
  408. err = rdb.Model(&sz.TempHdPatient{}).Where("patient_nk = ?", patientId).Find(&hdPatients).Error
  409. return
  410. }
  411. func FindSyncPatientOut(patientId int64, rdb *gorm.DB) (hdPatients []*sz.TempHdPatientOut, err error) {
  412. err = rdb.Model(&sz.TempHdPatientOut{}).Where("patient_nk = ?", patientId).Find(&hdPatients).Error
  413. return
  414. }
  415. func FindPatientInfoByIdno(idno string) (patient models.Patients, err error) {
  416. err = readDb.Model(&models.Patients{}).Where("id_card_no = ?", idno).First(&patient).Error
  417. return
  418. }
  419. func BatchCreateWMsRecord(wms []*sz.TempHdWm, rdb *gorm.DB) (err error) {
  420. if len(wms) > 0 {
  421. utx := rdb
  422. if len(wms) > 0 {
  423. thisSQL := "INSERT INTO t_hd_wm (hospital_id, equipment_id, equipment_brand, enable_time,equipment_type,xgbz,create_time,update_time,sjscsj) VALUES "
  424. insertParams := make([]string, 0)
  425. insertData := make([]interface{}, 0)
  426. for _, wm := range wms {
  427. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  428. insertData = append(insertData, wm.HospitalId)
  429. insertData = append(insertData, wm.EquipmentId)
  430. insertData = append(insertData, wm.EquipmentBrand)
  431. insertData = append(insertData, wm.EnableTime)
  432. insertData = append(insertData, wm.EquipmentType)
  433. insertData = append(insertData, wm.Xgbz)
  434. insertData = append(insertData, wm.CreateTime)
  435. insertData = append(insertData, wm.UpdateTime)
  436. insertData = append(insertData, wm.Sjscsj)
  437. }
  438. thisSQL += strings.Join(insertParams, ", ")
  439. // err = utx.Exec(thisSQL, insertData...).Error
  440. // if err != nil {
  441. // utx.Rollback()
  442. // return
  443. // }
  444. utx.Exec(thisSQL, insertData...)
  445. }
  446. // utx.Commit()
  447. }
  448. return
  449. }
  450. func BatchCreateStaffRecord(staffs []*sz.TempHdStaff, rdb *gorm.DB) (err error) {
  451. if len(staffs) > 0 {
  452. utx := rdb
  453. if len(staffs) > 0 {
  454. var id_no int64
  455. id_no = 429001198701091670
  456. for _, info := range staffs {
  457. 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, sjscsj, xgbz) VALUES "
  458. insertParams := make([]string, 0)
  459. insertData := make([]interface{}, 0)
  460. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  461. insertData = append(insertData, info.HospitalId)
  462. insertData = append(insertData, info.StaffId)
  463. insertData = append(insertData, id_no)
  464. insertData = append(insertData, "01")
  465. insertData = append(insertData, info.StaffName)
  466. insertData = append(insertData, info.Position)
  467. insertData = append(insertData, "0")
  468. insertData = append(insertData, info.StaffId)
  469. insertData = append(insertData, info.PermanentType)
  470. insertData = append(insertData, "2019-09-01")
  471. insertData = append(insertData, info.CreateTime)
  472. insertData = append(insertData, info.Sjscsj)
  473. insertData = append(insertData, info.Xgbz)
  474. thisSQL += strings.Join(insertParams, ", ")
  475. utx.Exec(thisSQL, insertData...)
  476. id_no++
  477. }
  478. }
  479. // utx.Commit()
  480. }
  481. return
  482. }
  483. func BatchCreateLayoutRecord(layouts []*sz.TempHdLayout, rdb *gorm.DB) (err error) {
  484. if len(layouts) > 0 {
  485. utx := rdb
  486. if len(layouts) > 0 {
  487. for _, info := range layouts {
  488. thisSQL := "INSERT INTO t_hd_layout (hospital_id,partition_name,create_time, sjscsj, xgbz) VALUES "
  489. insertParams := make([]string, 0)
  490. insertData := make([]interface{}, 0)
  491. insertParams = append(insertParams, "(?,?,?,?,?)")
  492. insertData = append(insertData, info.HospitalId)
  493. insertData = append(insertData, info.PartitionName)
  494. insertData = append(insertData, info.CreateTime)
  495. insertData = append(insertData, info.Sjscsj)
  496. insertData = append(insertData, info.Xgbz)
  497. thisSQL += strings.Join(insertParams, ", ")
  498. utx.Exec(thisSQL, insertData...)
  499. }
  500. }
  501. // utx.Commit()
  502. }
  503. return
  504. }
  505. func BatchCreatePatinet(patients []*sz.TempHdPatient, rdb *gorm.DB) (err error) {
  506. if len(patients) > 0 {
  507. utx := rdb
  508. if len(patients) > 0 {
  509. for _, info := range patients {
  510. 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,ylyl1) VALUES "
  511. insertParams := make([]string, 0)
  512. insertData := make([]interface{}, 0)
  513. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  514. insertData = append(insertData, info.HospitalId)
  515. insertData = append(insertData, info.PatientNk)
  516. insertData = append(insertData, info.CardNo)
  517. insertData = append(insertData, info.CardType)
  518. insertData = append(insertData, info.IdNo)
  519. insertData = append(insertData, info.IdType)
  520. insertData = append(insertData, info.PatientName)
  521. insertData = append(insertData, info.Gender)
  522. insertData = append(insertData, info.BornDate)
  523. insertData = append(insertData, info.DiagnosisSummary)
  524. insertData = append(insertData, info.IsCrf)
  525. insertData = append(insertData, "02")
  526. insertData = append(insertData, "1")
  527. insertData = append(insertData, info.DialysisStartTime)
  528. insertData = append(insertData, info.LocalStartTime)
  529. insertData = append(insertData, info.OutpatientNo)
  530. insertData = append(insertData, info.HospitalizedNo)
  531. insertData = append(insertData, info.Xgbz)
  532. insertData = append(insertData, info.CreateTime)
  533. insertData = append(insertData, info.UpdateTime)
  534. insertData = append(insertData, info.Sjscsj)
  535. insertData = append(insertData, info.Ylyl1)
  536. thisSQL += strings.Join(insertParams, ", ")
  537. utx.Exec(thisSQL, insertData...)
  538. }
  539. }
  540. // utx.Commit()
  541. }
  542. return
  543. }
  544. func BatchCreateSchedual(patients []*sz.TempHdShift, rdb *gorm.DB) (err error) {
  545. if len(patients) > 0 {
  546. utx := rdb
  547. if len(patients) > 0 {
  548. for _, info := range patients {
  549. 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 "
  550. insertParams := make([]string, 0)
  551. insertData := make([]interface{}, 0)
  552. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  553. insertData = append(insertData, info.PsId)
  554. insertData = append(insertData, info.HospitalId)
  555. insertData = append(insertData, info.PatientNk)
  556. insertData = append(insertData, info.ScheduleDate)
  557. insertData = append(insertData, info.ShiftType)
  558. insertData = append(insertData, info.SickbedNo)
  559. insertData = append(insertData, info.ScheduleStatus)
  560. insertData = append(insertData, info.CreateTime)
  561. insertData = append(insertData, info.Sjscsj)
  562. insertData = append(insertData, info.Xgbz)
  563. thisSQL += strings.Join(insertParams, ", ")
  564. utx.Exec(thisSQL, insertData...)
  565. }
  566. }
  567. // utx.Commit()
  568. }
  569. return
  570. }
  571. func BatchCreatePs(patients []*sz.TempHdPs, rdb *gorm.DB) (err error) {
  572. if len(patients) > 0 {
  573. utx := rdb
  574. if len(patients) > 0 {
  575. 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 "
  576. insertParams := make([]string, 0)
  577. insertData := make([]interface{}, 0)
  578. for _, info := range patients {
  579. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  580. insertData = append(insertData, info.PrescribeId)
  581. insertData = append(insertData, info.HospitalId)
  582. insertData = append(insertData, info.PatientNk)
  583. insertData = append(insertData, info.RrtType)
  584. insertData = append(insertData, info.RrtTypeName)
  585. insertData = append(insertData, info.DialysisFrequency)
  586. insertData = append(insertData, info.FrequencyUnit)
  587. insertData = append(insertData, info.PrescribeTime)
  588. insertData = append(insertData, info.CreateTime)
  589. insertData = append(insertData, info.Sjscsj)
  590. insertData = append(insertData, info.Xgbz)
  591. }
  592. thisSQL += strings.Join(insertParams, ", ")
  593. // err = utx.Exec(thisSQL, insertData...).Error
  594. // if err != nil {
  595. // utx.Rollback()
  596. // return
  597. // }
  598. utx.Exec(thisSQL, insertData...)
  599. }
  600. // utx.Commit()
  601. }
  602. return
  603. }
  604. func BatchCreatePsOther(ps *sz.TempHdPs, rdb *gorm.DB) (err error) {
  605. err = rdb.Create(&ps).Error
  606. return err
  607. }
  608. func BatchCreatePsm(psms []*sz.TempHdPsMedicine, rdb *gorm.DB) (err error) {
  609. if len(psms) > 0 {
  610. utx := rdb
  611. if len(psms) > 0 {
  612. for _, psm := range psms {
  613. thisSQL := "INSERT INTO t_hd_ps_medicine (sn,hospital_id, medicine_type_id,medicine_id,create_time,sjscsj,xgbz) VALUES "
  614. insertParams := make([]string, 0)
  615. insertData := make([]interface{}, 0)
  616. insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
  617. insertData = append(insertData, psm.Sn)
  618. insertData = append(insertData, psm.HospitalId)
  619. insertData = append(insertData, psm.MedicineTypeId)
  620. insertData = append(insertData, psm.MedicineId)
  621. insertData = append(insertData, psm.CreateTime)
  622. insertData = append(insertData, psm.Sjscsj)
  623. insertData = append(insertData, psm.Xgbz)
  624. thisSQL += strings.Join(insertParams, ", ")
  625. // err = utx.Exec(thisSQL, insertData...).Error
  626. utx.Exec(thisSQL, insertData...)
  627. }
  628. // if err != nil {
  629. // utx.Rollback()
  630. // return
  631. // }
  632. }
  633. // utx.Commit()
  634. }
  635. return
  636. }
  637. func BatchCreateDialysis(psms []*sz.TempHdDialysis, rdb *gorm.DB) (err error) {
  638. if len(psms) > 0 {
  639. utx := rdb
  640. if len(psms) > 0 {
  641. for _, psm := range psms {
  642. 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,ktv,urr,up_nurse_id,down_nurse_id,check_nurse_id,puncture_nurse_id,start_time,end_time,create_time,sjscsj,xgbz,charge_doctor_id,charge_nurse_id) VALUES "
  643. insertParams := make([]string, 0)
  644. insertData := make([]interface{}, 0)
  645. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  646. insertData = append(insertData, psm.DialysisId)
  647. insertData = append(insertData, psm.HospitalId)
  648. insertData = append(insertData, psm.PatientNk)
  649. insertData = append(insertData, psm.PsId)
  650. insertData = append(insertData, psm.DialysisDate)
  651. insertData = append(insertData, psm.SickbedNo)
  652. insertData = append(insertData, psm.DivisionId)
  653. insertData = append(insertData, psm.EquipmentId)
  654. insertData = append(insertData, psm.MixDialysis)
  655. insertData = append(insertData, psm.Ufv)
  656. insertData = append(insertData, psm.TotalTreatDuration)
  657. insertData = append(insertData, psm.IsHospitalization)
  658. insertData = append(insertData, psm.IsEmergency)
  659. insertData = append(insertData, psm.IsPerioperativePeriod)
  660. insertData = append(insertData, psm.BeforeSbp)
  661. insertData = append(insertData, psm.BeforeDbp)
  662. insertData = append(insertData, psm.AfterSbp)
  663. insertData = append(insertData, psm.AfterDbp)
  664. insertData = append(insertData, psm.BeforeWeight)
  665. insertData = append(insertData, psm.AfterWeight)
  666. insertData = append(insertData, psm.Ktv)
  667. insertData = append(insertData, psm.Urr)
  668. insertData = append(insertData, psm.UpNurseId)
  669. insertData = append(insertData, psm.DownNurseId)
  670. insertData = append(insertData, psm.CheckNurseId)
  671. insertData = append(insertData, psm.PunctureNurseId)
  672. insertData = append(insertData, psm.StartTime)
  673. insertData = append(insertData, psm.EndTime)
  674. insertData = append(insertData, psm.CreateTime)
  675. insertData = append(insertData, psm.Sjscsj)
  676. insertData = append(insertData, psm.Xgbz)
  677. insertData = append(insertData, psm.ChargeDoctorId)
  678. insertData = append(insertData, psm.ChargeNurseId)
  679. thisSQL += strings.Join(insertParams, ", ")
  680. utx.Exec(thisSQL, insertData...)
  681. }
  682. // if err != nil {
  683. // utx.Rollback()
  684. // return
  685. // }
  686. }
  687. // utx.Commit()
  688. }
  689. return
  690. }
  691. func BatchCreatePatientOut(patientOuts []*sz.TempHdPatientOut, rdb *gorm.DB) (err error) {
  692. if len(patientOuts) > 0 {
  693. utx := rdb
  694. if len(patientOuts) > 0 {
  695. 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 "
  696. insertParams := make([]string, 0)
  697. insertData := make([]interface{}, 0)
  698. for _, out := range patientOuts {
  699. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  700. insertData = append(insertData, out.Sn)
  701. insertData = append(insertData, out.HospitalId)
  702. insertData = append(insertData, out.PatientNk)
  703. insertData = append(insertData, out.SequelaeDate)
  704. insertData = append(insertData, out.SequelaeType)
  705. insertData = append(insertData, out.CreateTime)
  706. insertData = append(insertData, out.DeathReason)
  707. insertData = append(insertData, out.ExtReason)
  708. insertData = append(insertData, out.Sjscsj)
  709. insertData = append(insertData, out.Xgbz)
  710. }
  711. thisSQL += strings.Join(insertParams, ", ")
  712. utx.Exec(thisSQL, insertData...)
  713. // if err != nil {
  714. // utx.Rollback()
  715. // return
  716. // }
  717. }
  718. // utx.Commit()
  719. }
  720. return
  721. }
  722. func BatchCreateDoctorsAdvice(advices []*sz.TempHdDoctorsAdvice, rdb *gorm.DB) (err error) {
  723. if len(advices) > 0 {
  724. utx := rdb
  725. if len(advices) > 0 {
  726. for _, advice := range advices {
  727. 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 "
  728. insertParams := make([]string, 0)
  729. insertData := make([]interface{}, 0)
  730. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  731. insertData = append(insertData, advice.MedicalOrderId)
  732. insertData = append(insertData, advice.HospitalId)
  733. insertData = append(insertData, advice.DialysisId)
  734. insertData = append(insertData, advice.OrderType)
  735. insertData = append(insertData, advice.PatientNk)
  736. insertData = append(insertData, advice.DialysisDuration)
  737. insertData = append(insertData, advice.BloodVol)
  738. insertData = append(insertData, advice.Anticoagulant)
  739. insertData = append(insertData, advice.CreateTime)
  740. insertData = append(insertData, advice.Sjscsj)
  741. insertData = append(insertData, advice.Xgbz)
  742. insertData = append(insertData, advice.RrtType)
  743. insertData = append(insertData, advice.RrtTypeName)
  744. insertData = append(insertData, advice.DryWeight)
  745. thisSQL += strings.Join(insertParams, ", ")
  746. utx.Exec(thisSQL, insertData...)
  747. }
  748. // if err != nil {
  749. // utx.Rollback()
  750. // return
  751. // }
  752. }
  753. // utx.Commit()
  754. }
  755. return
  756. }
  757. func BatchCreateMonitor(advices []*sz.TempHdMiddle, rdb *gorm.DB) (err error) {
  758. if len(advices) > 0 {
  759. utx := rdb
  760. if len(advices) > 0 {
  761. for _, advice := range advices {
  762. thisSQL := "INSERT INTO t_hd_middle (sn,hospital_id, patient_nk,dialysis_id,monitor_time,sbp,dbp,create_time,sjscsj,xgbz) VALUES "
  763. insertParams := make([]string, 0)
  764. insertData := make([]interface{}, 0)
  765. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  766. insertData = append(insertData, advice.Sn)
  767. insertData = append(insertData, advice.HospitalId)
  768. insertData = append(insertData, advice.PatientNk)
  769. insertData = append(insertData, advice.DialysisId)
  770. insertData = append(insertData, advice.MonitorTime)
  771. insertData = append(insertData, advice.Sbp)
  772. insertData = append(insertData, advice.Dbp)
  773. insertData = append(insertData, advice.CreateTime)
  774. insertData = append(insertData, advice.Sjscsj)
  775. insertData = append(insertData, advice.Xgbz)
  776. thisSQL += strings.Join(insertParams, ", ")
  777. utx.Exec(thisSQL, insertData...)
  778. }
  779. // if err != nil {
  780. // utx.Rollback()
  781. // return
  782. // }
  783. }
  784. // utx.Commit()
  785. }
  786. return
  787. }
  788. func FindOrgOtherMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  789. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ? AND device_type = 3", org_id)
  790. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  791. err = db.Find(&waterMachine).Error
  792. return
  793. }
  794. func FindOrgDeviceInformationData(org_id int64, lastUploadTime int64, nowTime int64) (deviceInformation []*models.DeviceInformation, err error) {
  795. db := readUserDb.Model(&models.DeviceInformation{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("VMDeviceAddmacher", "status = 1")
  796. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  797. err = db.Find(&deviceInformation).Error
  798. return
  799. }
  800. func FindOrgMachineRepairData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.DeviceRepair, err error) {
  801. db := readUserDb.Model(&models.DeviceRepair{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("VMDeviceAddmacher", "status = 1")
  802. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  803. err = db.Find(&waterMachine).Error
  804. return
  805. }
  806. func FindOrgDevicePlan(org_id int64, lastUploadTime int64, nowTime int64) (deviceplan []*models.DevicePlan, err error) {
  807. db := readUserDb.Model(&models.DevicePlan{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("VMDeviceAddmacher", "status = 1")
  808. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  809. err = db.Find(&deviceplan).Error
  810. return
  811. }
  812. func BatchCreateOtherMachineRecord(wms []*sz.TempHdOtherMachine, rdb *gorm.DB) (err error) {
  813. if len(wms) > 0 {
  814. utx := rdb
  815. if len(wms) > 0 {
  816. for _, wm := range wms {
  817. thisSQL := "INSERT INTO t_hd_other_machine (hospital_id, equipment_id, equipment_brand, enable_time,status,equipment_type,xgbz,create_time,update_time,sjscsj) VALUES "
  818. insertParams := make([]string, 0)
  819. insertData := make([]interface{}, 0)
  820. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  821. insertData = append(insertData, wm.HospitalId)
  822. insertData = append(insertData, wm.EquipmentId)
  823. insertData = append(insertData, wm.EquipmentBrand)
  824. insertData = append(insertData, wm.EnableTime)
  825. insertData = append(insertData, wm.Status)
  826. insertData = append(insertData, wm.EquipmentType)
  827. insertData = append(insertData, wm.Xgbz)
  828. insertData = append(insertData, wm.CreateTime)
  829. insertData = append(insertData, wm.UpdateTime)
  830. insertData = append(insertData, wm.Sjscsj)
  831. thisSQL += strings.Join(insertParams, ", ")
  832. utx.Exec(thisSQL, insertData...)
  833. }
  834. }
  835. // utx.Commit()
  836. }
  837. return
  838. }
  839. func BatchCreateDmDisinfect(dfs []*sz.TempHdDmDisinfect, rdb *gorm.DB) (err error) {
  840. if len(dfs) > 0 {
  841. utx := rdb
  842. if len(dfs) > 0 {
  843. for _, df := range dfs {
  844. thisSQL := "INSERT INTO t_hd_dm_disinfect (sn,hospital_id, equipment_id, sickbed_no, inspection_time,is_qualified,case_order,xgbz,create_time,sjscsj) VALUES "
  845. insertParams := make([]string, 0)
  846. insertData := make([]interface{}, 0)
  847. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  848. insertData = append(insertData, df.Sn)
  849. insertData = append(insertData, df.HospitalId)
  850. insertData = append(insertData, df.EquipmentId)
  851. insertData = append(insertData, df.SickbedNo)
  852. insertData = append(insertData, df.InspectionTime)
  853. insertData = append(insertData, df.IsQualified)
  854. insertData = append(insertData, df.CaseOrder)
  855. insertData = append(insertData, df.Xgbz)
  856. insertData = append(insertData, df.CreateTime)
  857. insertData = append(insertData, df.Sjscsj)
  858. thisSQL += strings.Join(insertParams, ", ")
  859. utx.Exec(thisSQL, insertData...)
  860. }
  861. }
  862. // utx.Commit()
  863. }
  864. return
  865. }
  866. func BatchCreateWmDisinfect(dfs []*sz.TempWdDmDisinfect, rdb *gorm.DB) (err error) {
  867. if len(dfs) > 0 {
  868. utx := rdb
  869. if len(dfs) > 0 {
  870. for _, df := range dfs {
  871. thisSQL := "INSERT INTO t_hd_wm_disinfect (sn,hospital_id, equipment_id, inspection_time,is_qualified,case_order,xgbz,create_time,sjscsj) VALUES "
  872. insertParams := make([]string, 0)
  873. insertData := make([]interface{}, 0)
  874. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  875. insertData = append(insertData, df.Sn)
  876. insertData = append(insertData, df.HospitalId)
  877. insertData = append(insertData, df.EquipmentId)
  878. insertData = append(insertData, df.InspectionTime)
  879. insertData = append(insertData, df.IsQualified)
  880. insertData = append(insertData, df.CaseOrder)
  881. insertData = append(insertData, df.Xgbz)
  882. insertData = append(insertData, df.CreateTime)
  883. insertData = append(insertData, df.Sjscsj)
  884. thisSQL += strings.Join(insertParams, ", ")
  885. utx.Exec(thisSQL, insertData...)
  886. }
  887. }
  888. // utx.Commit()
  889. }
  890. return
  891. }
  892. func BatchCreateMainTain(maintain []*sz.TempHdMaintain, rdb *gorm.DB) (err error) {
  893. if len(maintain) > 0 {
  894. utx := rdb
  895. if len(maintain) > 0 {
  896. thisSQL := "INSERT INTO t_hd_maintain (sn,hospital_id, equipment_id, equipment_type, repair_time, xgbz,create_time,sjscsj) VALUES "
  897. insertParams := make([]string, 0)
  898. insertData := make([]interface{}, 0)
  899. for _, wm := range maintain {
  900. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?)")
  901. insertData = append(insertData, wm.Sn)
  902. insertData = append(insertData, wm.HospitalId)
  903. insertData = append(insertData, wm.EquipmentId)
  904. insertData = append(insertData, wm.EquipmentType)
  905. insertData = append(insertData, wm.RepairTime)
  906. insertData = append(insertData, wm.Xgbz)
  907. insertData = append(insertData, wm.CreateTime)
  908. insertData = append(insertData, wm.Sjscsj)
  909. }
  910. thisSQL += strings.Join(insertParams, ", ")
  911. utx.Exec(thisSQL, insertData...)
  912. // if err != nil {
  913. // utx.Rollback()
  914. // return
  915. // }
  916. }
  917. // utx.Commit()
  918. }
  919. return
  920. }
  921. func BatchCreateDisinfectMethod(disinfects []*sz.TempHdDisinfectMethod, rdb *gorm.DB) (err error) {
  922. if len(disinfects) > 0 {
  923. utx := rdb
  924. if len(disinfects) > 0 {
  925. thisSQL := "INSERT INTO t_hd_disinfect_method (hospital_id, equipment_id, equipment_type, disinfect_method,disinfector,concentration, xgbz,create_time,update_time,sjscsj) VALUES "
  926. insertParams := make([]string, 0)
  927. insertData := make([]interface{}, 0)
  928. for _, wm := range disinfects {
  929. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  930. insertData = append(insertData, wm.HospitalId)
  931. insertData = append(insertData, wm.EquipmentId)
  932. insertData = append(insertData, wm.EquipmentType)
  933. insertData = append(insertData, wm.DisinfectMethod)
  934. insertData = append(insertData, wm.Disinfector)
  935. insertData = append(insertData, wm.Concentration)
  936. insertData = append(insertData, wm.Xgbz)
  937. insertData = append(insertData, wm.CreateTime)
  938. insertData = append(insertData, wm.UpdateTime)
  939. insertData = append(insertData, wm.Sjscsj)
  940. }
  941. thisSQL += strings.Join(insertParams, ", ")
  942. utx.Exec(thisSQL, insertData...)
  943. // if err != nil {
  944. // utx.Rollback()
  945. // return
  946. // }
  947. }
  948. // utx.Commit()
  949. }
  950. return
  951. }
  952. func FindOrgMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  953. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND device_type = 1 and user_org_id = ?", org_id).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  954. return readDb.Model(&models.DeviceNumber{}).Where("status = 1")
  955. })
  956. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  957. err = db.Find(&waterMachine).Error
  958. return
  959. }
  960. func BatchCreateHDMRecord(wms []*sz.TempHdDm, rdb *gorm.DB) (err error) {
  961. if len(wms) > 0 {
  962. utx := rdb
  963. if len(wms) > 0 {
  964. for _, wm := range wms {
  965. thisSQL := "INSERT INTO t_hd_dm (hospital_id, equipment_id,sickbed_no,sickbed_type ,equipment_brand, enable_time,status,equipment_type, xgbz,bbp,create_time,update_time,sjscsj) VALUES "
  966. insertParams := make([]string, 0)
  967. insertData := make([]interface{}, 0)
  968. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  969. insertData = append(insertData, wm.HospitalId)
  970. insertData = append(insertData, wm.EquipmentId)
  971. insertData = append(insertData, wm.SickbedNo)
  972. insertData = append(insertData, wm.SickbedType)
  973. insertData = append(insertData, wm.EquipmentBrand)
  974. insertData = append(insertData, wm.EnableTime)
  975. insertData = append(insertData, wm.Status)
  976. insertData = append(insertData, wm.EquipmentType)
  977. insertData = append(insertData, wm.Xgbz)
  978. insertData = append(insertData, wm.Bbp)
  979. insertData = append(insertData, wm.CreateTime)
  980. insertData = append(insertData, wm.UpdateTime)
  981. insertData = append(insertData, wm.Sjscsj)
  982. thisSQL += strings.Join(insertParams, ", ")
  983. utx.Exec(thisSQL, insertData...)
  984. }
  985. // if err != nil {
  986. // utx.Rollback()
  987. // return
  988. // }
  989. }
  990. // utx.Commit()
  991. }
  992. return
  993. }
  994. func CreateHDDivision(wms []*sz.TempHdDivision, rdb *gorm.DB) (err error) {
  995. if len(wms) > 0 {
  996. utx := rdb
  997. if len(wms) > 0 {
  998. for _, wm := range wms {
  999. thisSQL := "INSERT INTO t_hd_division (division_id,hospital_id, division_name,division_type, xgbz,create_time,update_time,sjscsj) VALUES "
  1000. insertParams := make([]string, 0)
  1001. insertData := make([]interface{}, 0)
  1002. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?)")
  1003. insertData = append(insertData, wm.DivisionId)
  1004. insertData = append(insertData, wm.HospitalId)
  1005. insertData = append(insertData, wm.DivisionName)
  1006. insertData = append(insertData, wm.DivisionType)
  1007. insertData = append(insertData, wm.Xgbz)
  1008. insertData = append(insertData, wm.CreateTime)
  1009. insertData = append(insertData, wm.UpdateTime)
  1010. insertData = append(insertData, wm.Sjscsj)
  1011. thisSQL += strings.Join(insertParams, ", ")
  1012. utx.Exec(thisSQL, insertData...)
  1013. }
  1014. }
  1015. }
  1016. return
  1017. }
  1018. func CreateAccess(wms []*sz.TempHdAccess, rdb *gorm.DB) (err error) {
  1019. if len(wms) > 0 {
  1020. utx := rdb
  1021. if len(wms) > 0 {
  1022. for _, wm := range wms {
  1023. 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 "
  1024. insertParams := make([]string, 0)
  1025. insertData := make([]interface{}, 0)
  1026. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  1027. insertData = append(insertData, wm.AccessId)
  1028. insertData = append(insertData, wm.HospitalId)
  1029. insertData = append(insertData, wm.PatientNk)
  1030. insertData = append(insertData, wm.AccessType)
  1031. insertData = append(insertData, wm.AccessTypeName)
  1032. insertData = append(insertData, wm.AccessStatus)
  1033. insertData = append(insertData, wm.SetupDate)
  1034. insertData = append(insertData, wm.FirstUseTime)
  1035. insertData = append(insertData, wm.Xgbz)
  1036. insertData = append(insertData, wm.CreateTime)
  1037. insertData = append(insertData, wm.UpdateTime)
  1038. insertData = append(insertData, wm.Sjscsj)
  1039. thisSQL += strings.Join(insertParams, ", ")
  1040. utx.Exec(thisSQL, insertData...)
  1041. }
  1042. }
  1043. }
  1044. return
  1045. }
  1046. func CreateSickbed(wms []*sz.TempHdSickbed, rdb *gorm.DB) (err error) {
  1047. if len(wms) > 0 {
  1048. utx := rdb
  1049. if len(wms) > 0 {
  1050. for _, wm := range wms {
  1051. thisSQL := "INSERT INTO t_hd_sickbed (sickbed_no,hospital_id,division_id,sickbed_code,sickbed_type,xgbz,create_time,update_time,sjscsj) VALUES "
  1052. insertParams := make([]string, 0)
  1053. insertData := make([]interface{}, 0)
  1054. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  1055. insertData = append(insertData, wm.SickbedNo)
  1056. insertData = append(insertData, wm.HospitalId)
  1057. insertData = append(insertData, wm.DivisionId)
  1058. insertData = append(insertData, wm.SickbedCode)
  1059. insertData = append(insertData, wm.SickbedType)
  1060. insertData = append(insertData, wm.Xgbz)
  1061. insertData = append(insertData, wm.CreateTime)
  1062. insertData = append(insertData, wm.UpdateTime)
  1063. insertData = append(insertData, wm.Sjscsj)
  1064. thisSQL += strings.Join(insertParams, ", ")
  1065. utx.Exec(thisSQL, insertData...)
  1066. }
  1067. }
  1068. }
  1069. return
  1070. }
  1071. func CreateSickbed2(wms []*sz.TempHdSickbed, rdb *gorm.DB) (err error) {
  1072. if len(wms) > 0 {
  1073. utx := rdb
  1074. if len(wms) > 0 {
  1075. for _, wm := range wms {
  1076. thisSQL := "INSERT INTO t_hd_sickbed (sickbed_no,hospital_id,division_id,sickbed_code,sickbed_type,xgbz,create_time,update_time,sjscsj,ylyl1) VALUES "
  1077. insertParams := make([]string, 0)
  1078. insertData := make([]interface{}, 0)
  1079. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  1080. insertData = append(insertData, wm.SickbedNo)
  1081. insertData = append(insertData, wm.HospitalId)
  1082. insertData = append(insertData, wm.DivisionId)
  1083. insertData = append(insertData, wm.SickbedCode)
  1084. insertData = append(insertData, wm.SickbedType)
  1085. insertData = append(insertData, wm.Xgbz)
  1086. insertData = append(insertData, wm.CreateTime)
  1087. insertData = append(insertData, wm.UpdateTime)
  1088. insertData = append(insertData, wm.Sjscsj)
  1089. insertData = append(insertData, wm.Ylyl1)
  1090. thisSQL += strings.Join(insertParams, ", ")
  1091. utx.Exec(thisSQL, insertData...)
  1092. }
  1093. }
  1094. }
  1095. return
  1096. }
  1097. func CreateDiagnosis(wms []*sz.TempHdDiagnosis, rdb *gorm.DB) (err error) {
  1098. if len(wms) > 0 {
  1099. utx := rdb
  1100. if len(wms) > 0 {
  1101. for _, wm := range wms {
  1102. 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,sjscsj) VALUES "
  1103. insertParams := make([]string, 0)
  1104. insertData := make([]interface{}, 0)
  1105. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  1106. insertData = append(insertData, wm.DiagnosisId)
  1107. insertData = append(insertData, wm.HospitalId)
  1108. insertData = append(insertData, wm.PatientNk)
  1109. insertData = append(insertData, wm.DiagnosisTime)
  1110. insertData = append(insertData, wm.DiagnosisType)
  1111. insertData = append(insertData, wm.DiagnosisTypeItem)
  1112. insertData = append(insertData, wm.DiagnosisTypeDetail)
  1113. insertData = append(insertData, wm.Xgbz)
  1114. insertData = append(insertData, wm.CreateTime)
  1115. insertData = append(insertData, wm.Sjscsj)
  1116. thisSQL += strings.Join(insertParams, ", ")
  1117. utx.Exec(thisSQL, insertData...)
  1118. }
  1119. }
  1120. }
  1121. return
  1122. }
  1123. func CreateInfection(wms []*sz.TempHdInfection, rdb *gorm.DB) (err error) {
  1124. if len(wms) > 0 {
  1125. utx := rdb
  1126. if len(wms) > 0 {
  1127. for _, wm := range wms {
  1128. 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 "
  1129. insertParams := make([]string, 0)
  1130. insertData := make([]interface{}, 0)
  1131. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  1132. insertData = append(insertData, wm.Sn)
  1133. insertData = append(insertData, wm.HospitalId)
  1134. insertData = append(insertData, wm.PatientNk)
  1135. insertData = append(insertData, wm.Hbv)
  1136. insertData = append(insertData, wm.Hcv)
  1137. insertData = append(insertData, wm.Rpr)
  1138. insertData = append(insertData, wm.Hiv)
  1139. insertData = append(insertData, wm.Hbsag)
  1140. insertData = append(insertData, wm.Hbsab)
  1141. insertData = append(insertData, wm.Hbeag)
  1142. insertData = append(insertData, wm.Hbeab)
  1143. insertData = append(insertData, wm.Hbcab)
  1144. insertData = append(insertData, wm.CheckDate)
  1145. insertData = append(insertData, wm.DoctorId)
  1146. insertData = append(insertData, wm.Xgbz)
  1147. insertData = append(insertData, wm.CreateTime)
  1148. insertData = append(insertData, wm.Sjscsj)
  1149. thisSQL += strings.Join(insertParams, ", ")
  1150. utx.Exec(thisSQL, insertData...)
  1151. }
  1152. }
  1153. }
  1154. return
  1155. }
  1156. func CreateComplication(wms []*sz.TempHdComplication, rdb *gorm.DB) (err error) {
  1157. if len(wms) > 0 {
  1158. utx := rdb
  1159. if len(wms) > 0 {
  1160. for _, wm := range wms {
  1161. 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 "
  1162. insertParams := make([]string, 0)
  1163. insertData := make([]interface{}, 0)
  1164. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  1165. insertData = append(insertData, wm.Sn)
  1166. insertData = append(insertData, wm.HospitalId)
  1167. insertData = append(insertData, wm.PatientNk)
  1168. insertData = append(insertData, wm.DialysisId)
  1169. insertData = append(insertData, wm.MonitorId)
  1170. insertData = append(insertData, wm.NeopathyTime)
  1171. insertData = append(insertData, wm.NeopathyType)
  1172. insertData = append(insertData, wm.NeopathyDesc)
  1173. insertData = append(insertData, wm.Xgbz)
  1174. insertData = append(insertData, wm.CreateTime)
  1175. insertData = append(insertData, wm.Sjscsj)
  1176. thisSQL += strings.Join(insertParams, ", ")
  1177. utx.Exec(thisSQL, insertData...)
  1178. }
  1179. }
  1180. }
  1181. return
  1182. }
  1183. func CreateLisReport(wms []*sz.TempHdLisReport, rdb *gorm.DB) (err error) {
  1184. if len(wms) > 0 {
  1185. utx := rdb
  1186. if len(wms) > 0 {
  1187. for _, wm := range wms {
  1188. 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 "
  1189. insertParams := make([]string, 0)
  1190. insertData := make([]interface{}, 0)
  1191. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  1192. insertData = append(insertData, wm.LabSno)
  1193. insertData = append(insertData, wm.HospitalId)
  1194. insertData = append(insertData, wm.PatientNk)
  1195. insertData = append(insertData, wm.ReportDate)
  1196. insertData = append(insertData, wm.CheckDate)
  1197. insertData = append(insertData, wm.JzNo)
  1198. insertData = append(insertData, wm.MzFlag)
  1199. insertData = append(insertData, wm.ZyNo)
  1200. insertData = append(insertData, wm.MzNo)
  1201. insertData = append(insertData, wm.DepartmentCode)
  1202. insertData = append(insertData, wm.DepartmentName)
  1203. insertData = append(insertData, wm.CardNo)
  1204. insertData = append(insertData, wm.CardType)
  1205. insertData = append(insertData, wm.PatientName)
  1206. insertData = append(insertData, wm.DepCode)
  1207. insertData = append(insertData, wm.DepName)
  1208. insertData = append(insertData, wm.InspectedType)
  1209. insertData = append(insertData, wm.ReportCategry)
  1210. insertData = append(insertData, wm.ApplicationName)
  1211. insertData = append(insertData, wm.ApplicationType)
  1212. insertData = append(insertData, wm.CheckName)
  1213. insertData = append(insertData, wm.CheckItemName)
  1214. insertData = append(insertData, wm.CheckItemCode)
  1215. insertData = append(insertData, wm.RecordCcount)
  1216. insertData = append(insertData, wm.CheckResult)
  1217. insertData = append(insertData, wm.DiagnoseName)
  1218. insertData = append(insertData, wm.Xgbz)
  1219. insertData = append(insertData, wm.CreateTime)
  1220. insertData = append(insertData, wm.Sjscsj)
  1221. thisSQL += strings.Join(insertParams, ", ")
  1222. utx.Exec(thisSQL, insertData...)
  1223. }
  1224. }
  1225. }
  1226. return
  1227. }
  1228. func CreateLisIndicators(wms []*sz.TempHdLisIndicators, rdb *gorm.DB) (err error) {
  1229. if len(wms) > 0 {
  1230. utx := rdb
  1231. if len(wms) > 0 {
  1232. for _, wm := range wms {
  1233. 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,create_time) VALUES "
  1234. insertParams := make([]string, 0)
  1235. insertData := make([]interface{}, 0)
  1236. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  1237. insertData = append(insertData, wm.InspectedResultNo)
  1238. insertData = append(insertData, wm.HospitalId)
  1239. insertData = append(insertData, wm.LabSno)
  1240. insertData = append(insertData, wm.ReportDate)
  1241. insertData = append(insertData, wm.CheckDate)
  1242. insertData = append(insertData, wm.InspectedIndicate)
  1243. insertData = append(insertData, wm.InspectedItemEnName)
  1244. insertData = append(insertData, wm.InspectedItemCnName)
  1245. insertData = append(insertData, wm.InspectedResultDesc)
  1246. insertData = append(insertData, wm.InspectedResultValue)
  1247. insertData = append(insertData, wm.InspectedResultUnit)
  1248. insertData = append(insertData, wm.RefRange)
  1249. insertData = append(insertData, wm.UnitType)
  1250. insertData = append(insertData, wm.InspectedResult)
  1251. insertData = append(insertData, wm.CreateTime)
  1252. thisSQL += strings.Join(insertParams, ", ")
  1253. utx.Exec(thisSQL, insertData...)
  1254. }
  1255. }
  1256. }
  1257. return
  1258. }
  1259. func FindOrgCulture(org_id int64, lastUploadTime int64, nowTime int64) (culture []*models.XtDeviceCulture, err error) {
  1260. err = UserReadDB().Model(&culture).Where("status = 1 and user_org_id = ? and ctime>=? and ctime<=?", org_id, lastUploadTime, nowTime).Find(&culture).Error
  1261. return culture, err
  1262. }
  1263. func CreateLisCulture(wms []*sz.TempHdLisCulture, rdb *gorm.DB) (err error) {
  1264. if len(wms) > 0 {
  1265. utx := rdb
  1266. if len(wms) > 0 {
  1267. for _, wm := range wms {
  1268. thisSQL := "INSERT INTO t_hd_dm_dialysate_bc (sn,hospital_id,equipment_id,inspection_time,is_qualified,inspected_value,is_substitution_qualified,case_order,create_time,sjscsj,xgbz) VALUES "
  1269. insertParams := make([]string, 0)
  1270. insertData := make([]interface{}, 0)
  1271. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  1272. insertData = append(insertData, wm.Sn)
  1273. insertData = append(insertData, wm.HospitalId)
  1274. insertData = append(insertData, wm.EquitmentId)
  1275. insertData = append(insertData, wm.InspectionTime)
  1276. insertData = append(insertData, wm.IsQualified)
  1277. insertData = append(insertData, wm.InspectedValue)
  1278. insertData = append(insertData, wm.IsSubstitutionQualified)
  1279. insertData = append(insertData, wm.CaseOrder)
  1280. insertData = append(insertData, wm.CreateTime)
  1281. insertData = append(insertData, wm.Sjscsj)
  1282. insertData = append(insertData, wm.Xgbz)
  1283. thisSQL += strings.Join(insertParams, ", ")
  1284. utx.Exec(thisSQL, insertData...)
  1285. }
  1286. }
  1287. }
  1288. return
  1289. }
  1290. func FindOrgDialysate(org_id int64, lastUploadTime int64, nowTime int64) (dialysate []*models.XtDeviceDialysate, err error) {
  1291. err = UserReadDB().Model(&dialysate).Where("status = 1 and user_org_id = ? and ctime>=? and ctime<=?", org_id, lastUploadTime, nowTime).Find(&dialysate).Error
  1292. return dialysate, err
  1293. }
  1294. func CreateLisDialysate(wms []*sz.TempHdLisDialysate, rdb *gorm.DB) (err error) {
  1295. if len(wms) > 0 {
  1296. utx := rdb
  1297. if len(wms) > 0 {
  1298. for _, wm := range wms {
  1299. thisSQL := "INSERT INTO t_hd_dm_dialysate_en (sn,hospital_id,equipment_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz) VALUES "
  1300. insertParams := make([]string, 0)
  1301. insertData := make([]interface{}, 0)
  1302. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  1303. insertData = append(insertData, wm.Sn)
  1304. insertData = append(insertData, wm.HospitalId)
  1305. insertData = append(insertData, wm.EquitmentId)
  1306. insertData = append(insertData, wm.InspectionTime)
  1307. insertData = append(insertData, wm.IsQualified)
  1308. insertData = append(insertData, wm.InspectedValue)
  1309. insertData = append(insertData, wm.CaseOrder)
  1310. insertData = append(insertData, wm.CreateTime)
  1311. insertData = append(insertData, wm.Sjscsj)
  1312. insertData = append(insertData, wm.Xgbz)
  1313. thisSQL += strings.Join(insertParams, ", ")
  1314. utx.Exec(thisSQL, insertData...)
  1315. }
  1316. }
  1317. }
  1318. return
  1319. }
  1320. func FindOrgArialDetection(org_id int64, lastUploadTime int64, nowTime int64) (airdetection []*models.XtAerialDetection, err error) {
  1321. err = XTReadDB().Model(&airdetection).Where("user_org_id = ? and status=1 and created_time>=? and created_time<=?", org_id, lastUploadTime, nowTime).Find(&airdetection).Error
  1322. return airdetection, err
  1323. }
  1324. func CreateAirDisinfect(wms []*sz.TempHdLisAirDisinfect, rdb *gorm.DB) (err error) {
  1325. if len(wms) > 0 {
  1326. utx := rdb
  1327. if len(wms) > 0 {
  1328. for _, wm := range wms {
  1329. thisSQL := "INSERT INTO t_hd_air_disinfect (sn,hospital_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz) VALUES "
  1330. insertParams := make([]string, 0)
  1331. insertData := make([]interface{}, 0)
  1332. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  1333. insertData = append(insertData, wm.Sn)
  1334. insertData = append(insertData, wm.HospitalId)
  1335. insertData = append(insertData, wm.InspectionTime)
  1336. insertData = append(insertData, wm.IsQualified)
  1337. insertData = append(insertData, wm.InspectedValue)
  1338. insertData = append(insertData, wm.CaseOrder)
  1339. insertData = append(insertData, wm.CreateTime)
  1340. insertData = append(insertData, wm.Sjscsj)
  1341. insertData = append(insertData, wm.Xgbz)
  1342. thisSQL += strings.Join(insertParams, ", ")
  1343. utx.Exec(thisSQL, insertData...)
  1344. }
  1345. }
  1346. }
  1347. return
  1348. }
  1349. func FindOrgBodyDetection(org_id int64, lastUploadTime int64, nowTime int64) (body []*models.XtBodyDetection, err error) {
  1350. err = XTReadDB().Model(&body).Where("user_org_id = ? and status=1 and created_time>=? and created_time<=?", org_id, lastUploadTime, nowTime).Find(&body).Error
  1351. return body, err
  1352. }
  1353. func CreateBodyDisinfect(wms []*sz.TempHdLisBodyDisinfect, rdb *gorm.DB) (err error) {
  1354. if len(wms) > 0 {
  1355. utx := rdb
  1356. if len(wms) > 0 {
  1357. for _, wm := range wms {
  1358. thisSQL := "INSERT INTO t_hd_surface_disinfect (sn,hospital_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz) VALUES "
  1359. insertParams := make([]string, 0)
  1360. insertData := make([]interface{}, 0)
  1361. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  1362. insertData = append(insertData, wm.Sn)
  1363. insertData = append(insertData, wm.HospitalId)
  1364. insertData = append(insertData, wm.InspectionTime)
  1365. insertData = append(insertData, wm.IsQualified)
  1366. insertData = append(insertData, wm.InspectedValue)
  1367. insertData = append(insertData, wm.CaseOrder)
  1368. insertData = append(insertData, wm.CreateTime)
  1369. insertData = append(insertData, wm.Sjscsj)
  1370. insertData = append(insertData, wm.Xgbz)
  1371. thisSQL += strings.Join(insertParams, ", ")
  1372. utx.Exec(thisSQL, insertData...)
  1373. }
  1374. }
  1375. }
  1376. return
  1377. }
  1378. func FindOrgWaterFc(org_id int64, lastUploadTime int64, nowTime int64) (water []*models.XtDeviceWater, err error) {
  1379. err = UserReadDB().Model(&water).Where("user_org_id = ? and status = 1 and ctime>=? and ctime<=?", org_id, lastUploadTime, nowTime).Find(&water).Error
  1380. return water, err
  1381. }
  1382. func CreateWaterFc(wms []*sz.TempHdLisWaterFc, rdb *gorm.DB) (err error) {
  1383. if len(wms) > 0 {
  1384. utx := rdb
  1385. if len(wms) > 0 {
  1386. for _, wm := range wms {
  1387. thisSQL := "INSERT INTO t_hd_water_fc(sn,hospital_id,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz) VALUES "
  1388. insertParams := make([]string, 0)
  1389. insertData := make([]interface{}, 0)
  1390. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  1391. insertData = append(insertData, wm.Sn)
  1392. insertData = append(insertData, wm.HospitalId)
  1393. insertData = append(insertData, wm.EquitmentId)
  1394. insertData = append(insertData, wm.WaterType)
  1395. insertData = append(insertData, wm.InspectionOrgId)
  1396. insertData = append(insertData, wm.InspectionTime)
  1397. insertData = append(insertData, wm.IsQualified)
  1398. insertData = append(insertData, wm.InspectedValue)
  1399. insertData = append(insertData, wm.CaseOrder)
  1400. insertData = append(insertData, wm.CreateTime)
  1401. insertData = append(insertData, wm.Sjscsj)
  1402. insertData = append(insertData, wm.Xgbz)
  1403. thisSQL += strings.Join(insertParams, ", ")
  1404. utx.Exec(thisSQL, insertData...)
  1405. }
  1406. }
  1407. }
  1408. return
  1409. }
  1410. func FindOrgWaterEl(org_id int64, lastUploadTime int64, nowTime int64) (water []*models.DeviceIon, err error) {
  1411. err = UserReadDB().Model(&water).Where("user_org_id = ? and status = 1 and sampling_date>=? and sampling_date<=?", org_id, lastUploadTime, nowTime).Find(&water).Error
  1412. return water, err
  1413. }
  1414. func CreateWaterEl(wms []*sz.TempHdLisWaterEl, rdb *gorm.DB) (err error) {
  1415. if len(wms) > 0 {
  1416. utx := rdb
  1417. if len(wms) > 0 {
  1418. for _, wm := range wms {
  1419. thisSQL := "INSERT INTO t_hd_water_el(sn,hospital_id,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz) VALUES "
  1420. insertParams := make([]string, 0)
  1421. insertData := make([]interface{}, 0)
  1422. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  1423. insertData = append(insertData, wm.Sn)
  1424. insertData = append(insertData, wm.HospitalId)
  1425. insertData = append(insertData, wm.EquitmentId)
  1426. insertData = append(insertData, wm.WaterType)
  1427. insertData = append(insertData, wm.InspectionOrgId)
  1428. insertData = append(insertData, wm.InspectionTime)
  1429. insertData = append(insertData, wm.IsQualified)
  1430. insertData = append(insertData, wm.InspectedValue)
  1431. insertData = append(insertData, wm.CaseOrder)
  1432. insertData = append(insertData, wm.CreateTime)
  1433. insertData = append(insertData, wm.Sjscsj)
  1434. insertData = append(insertData, wm.Xgbz)
  1435. thisSQL += strings.Join(insertParams, ", ")
  1436. utx.Exec(thisSQL, insertData...)
  1437. }
  1438. }
  1439. }
  1440. return
  1441. }
  1442. func CreateWaterTe(wms []*sz.TempHdLisWaterTe, rdb *gorm.DB) (err error) {
  1443. if len(wms) > 0 {
  1444. utx := rdb
  1445. if len(wms) > 0 {
  1446. for _, wm := range wms {
  1447. thisSQL := "INSERT INTO t_hd_water_te(sn,hospital_id,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,case_order,create_time,sjscsj,xgbz) VALUES "
  1448. insertParams := make([]string, 0)
  1449. insertData := make([]interface{}, 0)
  1450. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  1451. insertData = append(insertData, wm.Sn)
  1452. insertData = append(insertData, wm.HospitalId)
  1453. insertData = append(insertData, wm.EquitmentId)
  1454. insertData = append(insertData, wm.WaterType)
  1455. insertData = append(insertData, wm.InspectionOrgId)
  1456. insertData = append(insertData, wm.InspectionTime)
  1457. insertData = append(insertData, wm.IsQualified)
  1458. insertData = append(insertData, wm.CaseOrder)
  1459. insertData = append(insertData, wm.CreateTime)
  1460. insertData = append(insertData, wm.Sjscsj)
  1461. insertData = append(insertData, wm.Xgbz)
  1462. thisSQL += strings.Join(insertParams, ", ")
  1463. utx.Exec(thisSQL, insertData...)
  1464. }
  1465. }
  1466. }
  1467. return
  1468. }
  1469. func FindOrgWaterNc(org_id int64, lastUploadTime int64, nowTime int64) (water []*models.XtDeviceOxygenates, err error) {
  1470. err = UserReadDB().Model(&water).Where("user_org_id = ? and status = 1 and ctime>=? and ctime<=?", org_id, lastUploadTime, nowTime).Find(&water).Error
  1471. return water, err
  1472. }
  1473. func CreateWaterNc(wms []*sz.TempHdLisWaterNc, rdb *gorm.DB) (err error) {
  1474. if len(wms) > 0 {
  1475. utx := rdb
  1476. if len(wms) > 0 {
  1477. for _, wm := range wms {
  1478. thisSQL := "INSERT INTO t_hd_water_nc(sn,hospital_id,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz) VALUES "
  1479. insertParams := make([]string, 0)
  1480. insertData := make([]interface{}, 0)
  1481. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  1482. insertData = append(insertData, wm.Sn)
  1483. insertData = append(insertData, wm.HospitalId)
  1484. insertData = append(insertData, wm.EquitmentId)
  1485. insertData = append(insertData, wm.WaterType)
  1486. insertData = append(insertData, wm.InspectionOrgId)
  1487. insertData = append(insertData, wm.InspectionTime)
  1488. insertData = append(insertData, wm.IsQualified)
  1489. insertData = append(insertData, wm.InspectedValue)
  1490. insertData = append(insertData, wm.CaseOrder)
  1491. insertData = append(insertData, wm.CreateTime)
  1492. insertData = append(insertData, wm.Sjscsj)
  1493. insertData = append(insertData, wm.Xgbz)
  1494. thisSQL += strings.Join(insertParams, ", ")
  1495. utx.Exec(thisSQL, insertData...)
  1496. }
  1497. }
  1498. }
  1499. return
  1500. }
  1501. func FindOrgWaterPh(org_id int64, lastUploadTime int64, nowTime int64) (water []*models.XtDevicePh, err error) {
  1502. err = UserReadDB().Model(&water).Where("user_org_id = ? and ctime>? and ctime<=?", org_id, lastUploadTime, nowTime).Find(&water).Error
  1503. return water, err
  1504. }
  1505. func CreateWaterPh(wms []*sz.TempHdLisWaterPh, rdb *gorm.DB) (err error) {
  1506. if len(wms) > 0 {
  1507. utx := rdb
  1508. if len(wms) > 0 {
  1509. for _, wm := range wms {
  1510. thisSQL := "INSERT INTO t_hd_water_ph(sn,hospital_id,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,case_order,create_time,sjscsj,xgbz) VALUES "
  1511. insertParams := make([]string, 0)
  1512. insertData := make([]interface{}, 0)
  1513. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  1514. insertData = append(insertData, wm.Sn)
  1515. insertData = append(insertData, wm.HospitalId)
  1516. insertData = append(insertData, wm.EquitmentId)
  1517. insertData = append(insertData, wm.WaterType)
  1518. insertData = append(insertData, wm.InspectionOrgId)
  1519. insertData = append(insertData, wm.InspectionTime)
  1520. insertData = append(insertData, wm.IsQualified)
  1521. insertData = append(insertData, wm.CaseOrder)
  1522. insertData = append(insertData, wm.CreateTime)
  1523. insertData = append(insertData, wm.Sjscsj)
  1524. insertData = append(insertData, wm.Xgbz)
  1525. thisSQL += strings.Join(insertParams, ", ")
  1526. utx.Exec(thisSQL, insertData...)
  1527. }
  1528. }
  1529. }
  1530. return
  1531. }
  1532. func FindOrgWaterWh(org_id int64, lastUploadTime int64, nowTime int64) (water []*models.XtDeviceHadwater, err error) {
  1533. err = UserReadDB().Model(&water).Where("user_org_id = ? and ctime>=? and ctime<=? and status =1", org_id, lastUploadTime, nowTime).Find(&water).Error
  1534. return water, err
  1535. }
  1536. func CreateWaterWh(wms []*sz.TempHdLisWaterWh, rdb *gorm.DB) (err error) {
  1537. if len(wms) > 0 {
  1538. utx := rdb
  1539. if len(wms) > 0 {
  1540. for _, wm := range wms {
  1541. thisSQL := "INSERT INTO t_hd_water_wh(sn,hospital_id,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,create_time,sjscsj,xgbz) VALUES "
  1542. insertParams := make([]string, 0)
  1543. insertData := make([]interface{}, 0)
  1544. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  1545. insertData = append(insertData, wm.Sn)
  1546. insertData = append(insertData, wm.HospitalId)
  1547. insertData = append(insertData, wm.EquitmentId)
  1548. insertData = append(insertData, wm.WaterType)
  1549. insertData = append(insertData, wm.InspectionOrgId)
  1550. insertData = append(insertData, wm.InspectionTime)
  1551. insertData = append(insertData, wm.IsQualified)
  1552. insertData = append(insertData, wm.InspectedValue)
  1553. insertData = append(insertData, wm.CaseOrder)
  1554. insertData = append(insertData, wm.CreateTime)
  1555. insertData = append(insertData, wm.Sjscsj)
  1556. insertData = append(insertData, wm.Xgbz)
  1557. thisSQL += strings.Join(insertParams, ", ")
  1558. utx.Exec(thisSQL, insertData...)
  1559. }
  1560. }
  1561. }
  1562. return
  1563. }
  1564. func FindOrgAccess(org_id int64, lastUploadTime int64, nowTime int64) (access []*models.XtPatientVascularAccess, err error) {
  1565. err = XTReadDB().Model(&access).Where("user_org_id = ? and start_time>=? and start_time<=? and status =1", org_id, lastUploadTime, nowTime).Find(&access).Error
  1566. return access, err
  1567. }
  1568. func FindOrgHdCi(org_id int64, lastUploadTime int64, nowTime int64) (access []*models.XtPatientVascularAccess, err error) {
  1569. err = XTReadDB().Model(&access).Where("user_org_id = ? and start_time>=? and start_time<=? and access_project = 2 and sequelae_type > 0 and status =1", org_id, lastUploadTime, nowTime).Find(&access).Error
  1570. return access, err
  1571. }
  1572. func CreateHdCi(wms []*sz.TempHdCi, rdb *gorm.DB) (err error) {
  1573. if len(wms) > 0 {
  1574. utx := rdb
  1575. if len(wms) > 0 {
  1576. for _, wm := range wms {
  1577. 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 "
  1578. insertParams := make([]string, 0)
  1579. insertData := make([]interface{}, 0)
  1580. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  1581. insertData = append(insertData, wm.InfectSn)
  1582. insertData = append(insertData, wm.HospitalId)
  1583. insertData = append(insertData, wm.PatientNk)
  1584. insertData = append(insertData, wm.AccessId)
  1585. insertData = append(insertData, wm.CiType)
  1586. insertData = append(insertData, wm.BloodCulture)
  1587. insertData = append(insertData, wm.InfectionDate)
  1588. insertData = append(insertData, wm.CreateTime)
  1589. insertData = append(insertData, wm.Sjscsj)
  1590. insertData = append(insertData, wm.Xgbz)
  1591. thisSQL += strings.Join(insertParams, ", ")
  1592. utx.Exec(thisSQL, insertData...)
  1593. }
  1594. }
  1595. }
  1596. return
  1597. }
  1598. func FindOrgHdCiOutCome(org_id int64, lastUploadTime int64, nowTime int64) (access []*models.XtPatientVascularAccess, err error) {
  1599. err = XTReadDB().Model(&access).Where("user_org_id = ? and start_time>=? and start_time<=? and access_project = 2 and ci_type > 0 and status =1", org_id, lastUploadTime, nowTime).Find(&access).Error
  1600. return access, err
  1601. }
  1602. func CreateHdCiOutCome(wms []*sz.TempHdCiOutCome, rdb *gorm.DB) (err error) {
  1603. if len(wms) > 0 {
  1604. utx := rdb
  1605. if len(wms) > 0 {
  1606. for _, wm := range wms {
  1607. thisSQL := "INSERT INTO t_hd_ci_outcome(hospital_id,sn,infect_sn,patient_nk,sequelae_type,sjscsj,xgbz,create_time) VALUES "
  1608. insertParams := make([]string, 0)
  1609. insertData := make([]interface{}, 0)
  1610. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?)")
  1611. insertData = append(insertData, wm.HospitalId)
  1612. insertData = append(insertData, wm.Sn)
  1613. insertData = append(insertData, wm.InfectSn)
  1614. insertData = append(insertData, wm.PatientNk)
  1615. insertData = append(insertData, wm.SequelaeType)
  1616. insertData = append(insertData, wm.Sjscsj)
  1617. insertData = append(insertData, wm.Xgbz)
  1618. insertData = append(insertData, wm.CreateTime)
  1619. thisSQL += strings.Join(insertParams, ", ")
  1620. utx.Exec(thisSQL, insertData...)
  1621. }
  1622. }
  1623. }
  1624. return
  1625. }
  1626. func CreateLisWaterBc(wms []*sz.TempHdLisWaterBc, rdb *gorm.DB) (err error) {
  1627. if len(wms) > 0 {
  1628. utx := rdb
  1629. if len(wms) > 0 {
  1630. for _, wm := range wms {
  1631. thisSQL := "INSERT INTO t_hd_water_bc (sn,hospital_id,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,sjscsj,xgbz,create_time) VALUES "
  1632. insertParams := make([]string, 0)
  1633. insertData := make([]interface{}, 0)
  1634. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  1635. insertData = append(insertData, wm.Sn)
  1636. insertData = append(insertData, wm.HospitalId)
  1637. insertData = append(insertData, wm.EquitmentId)
  1638. insertData = append(insertData, wm.WaterType)
  1639. insertData = append(insertData, wm.InspectionOrgId)
  1640. insertData = append(insertData, wm.InspectionTime)
  1641. insertData = append(insertData, wm.IsQualified)
  1642. insertData = append(insertData, wm.InspectedValue)
  1643. insertData = append(insertData, wm.CaseOrder)
  1644. insertData = append(insertData, wm.Sjscsj)
  1645. insertData = append(insertData, wm.Xgbz)
  1646. insertData = append(insertData, wm.CreateTime)
  1647. thisSQL += strings.Join(insertParams, ", ")
  1648. utx.Exec(thisSQL, insertData...)
  1649. }
  1650. }
  1651. }
  1652. return
  1653. }
  1654. func CreateLisWaterEn(wms []*sz.TempHdLisWaterEn, rdb *gorm.DB) (err error) {
  1655. if len(wms) > 0 {
  1656. utx := rdb
  1657. if len(wms) > 0 {
  1658. for _, wm := range wms {
  1659. thisSQL := "INSERT INTO t_hd_water_en (sn,hospital_id,equipment_id,water_type,inspection_org_id,inspection_time,is_qualified,inspected_value,case_order,sjscsj,xgbz,create_time) VALUES "
  1660. insertParams := make([]string, 0)
  1661. insertData := make([]interface{}, 0)
  1662. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  1663. insertData = append(insertData, wm.Sn)
  1664. insertData = append(insertData, wm.HospitalId)
  1665. insertData = append(insertData, wm.EquitmentId)
  1666. insertData = append(insertData, wm.WaterType)
  1667. insertData = append(insertData, wm.InspectionOrgId)
  1668. insertData = append(insertData, wm.InspectionTime)
  1669. insertData = append(insertData, wm.IsQualified)
  1670. insertData = append(insertData, wm.InspectedValue)
  1671. insertData = append(insertData, wm.CaseOrder)
  1672. insertData = append(insertData, wm.Sjscsj)
  1673. insertData = append(insertData, wm.Xgbz)
  1674. insertData = append(insertData, wm.CreateTime)
  1675. thisSQL += strings.Join(insertParams, ", ")
  1676. utx.Exec(thisSQL, insertData...)
  1677. }
  1678. }
  1679. }
  1680. return
  1681. }
  1682. func BatchCreateTBDICPractitioner(ps *sz.TBDICPractitioner, rdb *gorm.DB) (err error) {
  1683. err = rdb.Create(&ps).Error
  1684. return err
  1685. }
  1686. func BatchCreateTBDICMedicines(ps *sz.TBDICMedicines, rdb *gorm.DB) (err error) {
  1687. err = rdb.Create(&ps).Error
  1688. return err
  1689. }
  1690. func BatchCreateTBDICZlxmdzzd(ps *sz.TBDICZlxmdzzd, rdb *gorm.DB) (err error) {
  1691. err = rdb.Create(&ps).Error
  1692. return err
  1693. }
  1694. func BatchCreateTBDICYpdzzd(ps *sz.TBDICYpdzzd, rdb *gorm.DB) (err error) {
  1695. err = rdb.Create(&ps).Error
  1696. return err
  1697. }
  1698. func BatchCreateTBDICZlxmml(ps *sz.TBDICZlxmml, rdb *gorm.DB) (err error) {
  1699. err = rdb.Create(&ps).Error
  1700. return err
  1701. }
  1702. func BatchCreateTMDICTBED(ps *sz.TM_DICT_BED, rdb *gorm.DB) (err error) {
  1703. err = rdb.Create(&ps).Error
  1704. return err
  1705. }
  1706. func BatchCreateTB_MZ_Patient_Information(ps *sz.TB_MZ_Patient_Information, rdb *gorm.DB) (err error) {
  1707. err = rdb.Create(&ps).Error
  1708. return err
  1709. }
  1710. func BatchCreateTB_HIS_MZ_Reg(ps *sz.TB_HIS_MZ_Reg, rdb *gorm.DB) (err error) {
  1711. err = rdb.Create(&ps).Error
  1712. return err
  1713. }
  1714. func BatchCreateTB_YL_MZ_Medical_Record(ps *sz.TB_YL_MZ_Medical_Record, rdb *gorm.DB) (err error) {
  1715. err = rdb.Create(&ps).Error
  1716. return err
  1717. }
  1718. func BatchCreateTB_Diagnosis_Detail(ps *sz.TB_Diagnosis_Detail, rdb *gorm.DB) (err error) {
  1719. err = rdb.Create(&ps).Error
  1720. return err
  1721. }
  1722. func BatchCreateTB_CIS_Prescription(ps *sz.TB_CIS_Prescription, rdb *gorm.DB) (err error) {
  1723. err = rdb.Create(&ps).Error
  1724. return err
  1725. }
  1726. func BatchCreateTB_CIS_Prescription_Detail(ps *sz.TB_CIS_Prescription_Detail, rdb *gorm.DB) (err error) {
  1727. err = rdb.Create(&ps).Error
  1728. return err
  1729. }
  1730. func BatchCreateTB_HIS_MZ_Charge(ps *sz.TB_HIS_MZ_Charge, rdb *gorm.DB) (err error) {
  1731. err = rdb.Create(&ps).Error
  1732. return err
  1733. }
  1734. func BatchCreateTB_HIS_MZ_Fee_Detail(ps *sz.TB_HIS_MZ_Fee_Detail, rdb *gorm.DB) (err error) {
  1735. err = rdb.Create(&ps).Error
  1736. return err
  1737. }
  1738. func BatchCreateTB_STAT_YWL_Report(ps *sz.TB_STAT_YWL_Report, rdb *gorm.DB) (err error) {
  1739. err = rdb.Create(&ps).Error
  1740. return err
  1741. }
  1742. func FindOrgPatientDataTwo(org_id int64,ids []int64) (patient []*models.Patients, err error) {
  1743. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? and id in (?)", org_id,ids)
  1744. err = db.Find(&patient).Error
  1745. return
  1746. }
  1747. func FindNewOrgHisOrder(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.HisOrder, err error) {
  1748. db := readDb.Model(&models.HisOrder{}).Preload("HisPatient", "status = 1").Where("status = 1 AND user_org_id = ? AND med_type = 14", org_id)
  1749. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  1750. err = db.Find(&patient).Error
  1751. return
  1752. }
  1753. func FindUserRoleData(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  1754. db := readUserDb.Model(&models.UserAdminRole{}).Where("status = 1 AND org_id = ? and admin_user_id = ? ", org_id, admin_user_id)
  1755. //db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  1756. err = db.Find(&role).Error
  1757. return
  1758. }
  1759. func BatchCreateTB_HIS_MZ_BL_Detail(ps *sz.TB_HIS_MZ_BL_Detail, rdb *gorm.DB) (err error) {
  1760. err = rdb.Create(&ps).Error
  1761. return err
  1762. }