gobal_config_service.go 62KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  1. package service
  2. import (
  3. "fmt"
  4. "time"
  5. "XT_New/models"
  6. "github.com/jinzhu/gorm"
  7. )
  8. func CreateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
  9. err = writeDb.Model(&models.GobalConfig{}).Create(config).Error
  10. return
  11. }
  12. func CreateDrugAutomaticReduceRecord(config *models.DrugStockConfig) (err error) {
  13. err = writeDb.Model(&models.DrugStockConfig{}).Create(config).Error
  14. return
  15. }
  16. func FindAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.GobalConfig) {
  17. err = readDb.Model(&models.GobalConfig{}).Where("status = 1 AND org_id = ?", org_id).First(&config).Error
  18. return
  19. }
  20. func FindDrugStockAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.DrugStockConfig) {
  21. err = readDb.Model(&models.DrugStockConfig{}).Where("status = 1 AND org_id = ?", org_id).First(&config).Error
  22. return
  23. }
  24. func UpdateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
  25. err = writeDb.Save(config).Error
  26. return
  27. }
  28. func UpdateGobalConfig(user_org_id int64) error {
  29. config := models.GobalConfig{}
  30. err := XTWriteDB().Model(&config).Where("org_id = ? and status = 1").Updates(map[string]interface{}{"is_open": 2}).Error
  31. return err
  32. }
  33. func UpdateDrugStockAutomaticReduceRecord(config *models.DrugStockConfig) (err error) {
  34. err = writeDb.Save(config).Error
  35. return
  36. }
  37. func CreatePrintTemplateRecord(template *models.GobalTemplate) (err error) {
  38. err = writeDb.Model(&models.GobalTemplate{}).Create(template).Error
  39. return
  40. }
  41. func FindPrintTemplateByOrgId(org_id int64) (err error, template models.GobalTemplate) {
  42. err = readDb.Model(&models.GobalTemplate{}).Where("status = 1 AND org_id = ?", org_id).Find(&template).Error
  43. return
  44. }
  45. func UpdatePrintTemplate(template *models.GobalTemplate) (err error) {
  46. err = writeDb.Save(template).Error
  47. return
  48. }
  49. func CreateConfigData(config *models.DataUploadConfig) (err error) {
  50. err = writeDb.Create(config).Error
  51. return
  52. }
  53. func SaveConfigData(config *models.DataUploadConfig) (err error) {
  54. err = writeDb.Save(config).Error
  55. return
  56. }
  57. func GetConfigData(org_id int64, config_type int64) (config models.DataUploadConfig, err error) {
  58. err = readDb.Model(&models.DataUploadConfig{}).Where("status = 1 AND org_id = ? AND config_type = ?", org_id, config_type).First(&config).Error
  59. return
  60. }
  61. func GetDockingStatus(config_type int64, province int64, city int64) (config models.DockingStatus, err error) {
  62. err = readDb.Model(&models.DockingStatus{}).Where("status = 1 AND docking_type = ? AND province_id = ? AND city_id = ?", config_type, province, city).First(&config).Error
  63. return
  64. }
  65. func GetConfigDataById(id int64) (config models.DataUploadConfig, err error) {
  66. err = readDb.Model(&models.DataUploadConfig{}).Where("id = ?", id).First(&config).Error
  67. return
  68. }
  69. func FindDoctorAdviceRecordByOrgId(org_id int64) (err error, config models.DoctorAdviceConfig) {
  70. err = readDb.Model(&models.DoctorAdviceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
  71. return
  72. }
  73. func CreateDoctorAdviceRecord(config *models.DoctorAdviceConfig) (err error) {
  74. err = writeDb.Model(&models.DoctorAdviceConfig{}).Create(config).Error
  75. return
  76. }
  77. func UpdateDoctorAdviceRecord(config *models.DoctorAdviceConfig) (err error) {
  78. err = writeDb.Save(config).Error
  79. return
  80. }
  81. func UpdateFiledConfig(org_id int64) (err error) {
  82. err = writeDb.Model(&models.FiledConfig{}).Where("org_id = ? AND sys_module = 0", org_id).Updates(map[string]interface{}{"is_show": 1}).Error
  83. return
  84. }
  85. func FindAllHideFiledConfig(template_id int64) (err error, config []*models.FiledConfig) {
  86. err = readDb.Model(&models.FiledConfig{}).Where("sys_module = ? AND is_show = 2", template_id).Find(&config).Error
  87. return
  88. }
  89. func UpdateShowFieldConfig(org_id int64, fileds []string) (err error) {
  90. err = writeDb.Model(&models.FiledConfig{}).Where("org_id = ? AND filed_name in (?) AND sys_module = 0 ", org_id, fileds).Updates(map[string]interface{}{"is_show": 2}).Error
  91. return
  92. }
  93. func FindAllAdviceParentTemplate(org_id int64) (template []*models.DoctorAdviceParentTemplate) {
  94. readDb.Model(&models.DoctorAdviceParentTemplate{}).Preload("DoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  95. return db.Preload("SubDoctorAdviceTemplate", "status = 1 AND org_id = ?", org_id).Where("status = 1 AND parent_id = 0 AND org_id = ?", org_id)
  96. }).Where("status = 1 AND org_id = ? ", org_id).Find(&template)
  97. return
  98. }
  99. func CreateDoctorParentTemplate(template *models.DoctorAdviceParentTemplate) (err error) {
  100. err = writeDb.Create(&template).Error
  101. return
  102. }
  103. func FindAllAdviceTemplates(org_id int64, parent_template_id int64) (template []*models.DoctorAdviceTemplate, err error) {
  104. err = readDb.Model(&models.DoctorAdviceTemplate{}).Where("status = 1 AND org_id = ? AND template_id = ?", org_id, parent_template_id).Find(&template).Error
  105. return
  106. }
  107. func CreateDoctorTemplate(template *models.DoctorAdviceTemplate) (err error) {
  108. err = writeDb.Create(&template).Error
  109. return
  110. }
  111. func CreateSystemDialysisSolution(solution *models.SystemPrescription) (err error) {
  112. err = writeDb.Create(solution).Error
  113. return
  114. }
  115. func UpdateSystemDialysisSolution(solution *models.SystemPrescription) (err error) {
  116. err = writeDb.Save(solution).Error
  117. return
  118. }
  119. func FindSystemDialysisSolution(orgID int64, id int64) (solution models.SystemPrescription, err error) {
  120. err = readDb.Model(&models.SystemPrescription{}).Where("id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
  121. return
  122. }
  123. func FindAllSystemPrescription(orgID int64) (solution []*models.SystemPrescription, err error) {
  124. err = readDb.Model(&models.SystemPrescription{}).Where("status=1 and user_org_id=?", orgID).Find(&solution).Error
  125. return
  126. }
  127. func FindSystemDialysisPrescriptionByMode(orgID int64, id int64) (solution models.SystemPrescription, err error) {
  128. err = readDb.Model(&models.SystemPrescription{}).Where("mode_id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
  129. return
  130. }
  131. func CreateAdviceInitConfig(adviceInit *models.AdviceInit) (err error) {
  132. err = writeDb.Create(&adviceInit).Error
  133. return
  134. }
  135. func FindAdviceInitConfig(org_id int64) (adviceInit models.AdviceInit, err error) {
  136. err = readDb.Model(&models.AdviceInit{}).Where("user_org_id = ? AND status = 1 ", org_id).First(&adviceInit).Error
  137. return
  138. }
  139. func GetPrint(ids []int64, orgid int64, advicetype int64, stoptype int64) (doctor []*models.DoctorAdvice, err error) {
  140. db := XTReadDB().Model(&doctor).Where("status =1")
  141. if len(ids) == 1 {
  142. if orgid > 0 {
  143. db = db.Where("user_org_id = ?", orgid)
  144. }
  145. if advicetype > 0 {
  146. db = db.Where("advice_type = ?", advicetype)
  147. }
  148. if stoptype > 0 {
  149. db = db.Where("stop_state = ?", stoptype)
  150. }
  151. err = db.Where("groupno = ?", ids[0]).Order("advice_date asc").Find(&doctor).Error
  152. } else {
  153. if orgid > 0 {
  154. db = db.Where("user_org_id = ?", orgid)
  155. }
  156. if advicetype > 0 {
  157. db = db.Where("advice_type = ?", advicetype)
  158. }
  159. if stoptype > 0 {
  160. db = db.Where("stop_state = ?", stoptype)
  161. }
  162. err = db.Where("groupno IN(?)", ids).Order("advice_date asc").Find(&doctor).Error
  163. }
  164. return doctor, err
  165. }
  166. func GetExportLogByType(org_id int64, log_type int64) (log []*models.ExportLog, err error) {
  167. err = readDb.Model(&models.ExportLog{}).Where("user_org_id = ? AND status = 1 AND log_type = ?", org_id, log_type).
  168. Preload("ExportErrLog", "status = 1").Order("export_time desc").Find(&log).Error
  169. return
  170. }
  171. func FindXTHisRecordByOrgId(org_id int64) (err error, config models.XtHisConfig) {
  172. err = readDb.Model(&models.XtHisConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
  173. return
  174. }
  175. func FindHisStockPriceRecordByOrgId(org_id int64) (err error, config models.HisStockPriceConfig) {
  176. err = readDb.Model(&models.HisStockPriceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
  177. return
  178. }
  179. func UpdateXTHisRecord(config *models.XtHisConfig) (err error) {
  180. err = writeDb.Save(config).Error
  181. return
  182. }
  183. func CreateXTHisRecord(config *models.XtHisConfig) (err error) {
  184. err = writeDb.Model(&models.XtHisConfig{}).Create(config).Error
  185. return
  186. }
  187. func CreateHisStockPriceRecord(config *models.HisStockPriceConfig) (err error) {
  188. err = writeDb.Model(&models.HisStockPriceConfig{}).Create(config).Error
  189. return
  190. }
  191. func UpdateHisStockPriceRecord(config *models.HisStockPriceConfig) (err error) {
  192. err = writeDb.Save(config).Error
  193. return
  194. }
  195. // TODO:项目开关
  196. func FindXTHisProjectByOrgId(org_id int64) (err error, config models.XtHisProjectConfig) {
  197. err = readDb.Model(&models.XtHisProjectConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
  198. return
  199. }
  200. func FindXTHisProjectByOrgIdOne(org_id int64) (err error, config models.XtHisProjectConfig) {
  201. err = readDb.Model(&models.XtHisProjectConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
  202. return
  203. }
  204. func UpdateXTHisProjectRecord(config *models.XtHisProjectConfig) (err error) {
  205. err = writeDb.Save(config).Error
  206. return
  207. }
  208. func CreateXTHisProjectRecord(config *models.XtHisProjectConfig) (err error) {
  209. err = writeDb.Model(&models.XtHisProjectConfig{}).Create(config).Error
  210. return
  211. }
  212. func GetExportHisOrderList(user_org_id int64, start_time int64, end_time int64, p_type int64) (order []*models.HisOrder, err error) {
  213. db := readDb.Model(&models.HisOrder{})
  214. if start_time != 0 {
  215. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  216. }
  217. if end_time != 0 {
  218. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  219. }
  220. if p_type > 0 {
  221. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2 AND p_type = ? ", user_org_id, p_type)
  222. } else {
  223. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2", user_org_id)
  224. }
  225. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  226. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  227. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  228. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ? AND in_hospital_status = 1 AND out_hospital_status = 1 ", user_org_id).
  229. Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
  230. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
  231. })
  232. err = db.Order("setl_time asc").Find(&order).Error
  233. return
  234. }
  235. func GetExportHisOrderListBySetlTIME(user_org_id int64, start_time string, end_time string, p_type int64) (order []*models.HisOrder, err error) {
  236. db := readDb.Model(&models.HisOrder{})
  237. if len(start_time) > 0 {
  238. db = db.Where("his_order.setl_time >= ?", start_time)
  239. }
  240. if len(end_time) > 0 {
  241. db = db.Where("his_order.setl_time <= ?", end_time)
  242. }
  243. if p_type > 0 {
  244. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2 AND p_type = ? ", user_org_id, p_type)
  245. } else {
  246. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2", user_org_id)
  247. }
  248. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  249. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  250. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  251. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ? AND in_hospital_status = 1 AND out_hospital_status = 1 ", user_org_id).
  252. Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
  253. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
  254. })
  255. err = db.Order("setl_time asc").Find(&order).Error
  256. return
  257. }
  258. func GetDrugInOrderDetail(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, page int64, limit int64, storehouse_id int64, drug_id int64) (drugInfo []*models.BloodDrugWarehouseInfo, total int64, err error) {
  259. likeKey := "%" + keyword + "%"
  260. offset := (page - 1) * limit
  261. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1")
  262. dbOne := XTReadDB().Table("xt_base_drug as t").Where("t.status =1")
  263. dbTwo := XTReadDB().Table("xt_drug_warehouse as s").Where("s.status = 1")
  264. dbThree := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  265. fmt.Print(dbOne, dbTwo, dbThree)
  266. if startime > 0 {
  267. db = db.Where("x.ctime >=?", startime)
  268. }
  269. if endtime > 0 {
  270. db = db.Where("x.ctime <=?", endtime)
  271. }
  272. if orgid > 0 {
  273. db = db.Where("x.org_id =?", orgid)
  274. }
  275. if storehouse_id > 0 {
  276. db = db.Where("x.storehouse_id = ?", storehouse_id)
  277. }
  278. if drug_id > 0 {
  279. db = db.Where("x.drug_id = ?", drug_id)
  280. }
  281. if len(keyword) > 0 {
  282. db = db.Joins("left join sgj_xt.xt_drug_warehouse as o on o.id = x.warehousing_id left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.creater")
  283. db = db.Where("x.warehousing_order like ? or t.drug_name like ? or r.user_name like ? ", likeKey, likeKey, likeKey)
  284. }
  285. if manufacturerId > 0 {
  286. err = db.Select("x.id,x.warehousing_id,x.drug_id,x.batch_number,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.storehouse_id,x.max_unit as count_unit,t.drug_type,t.drug_name,t.drug_spec,t.min_unit,t.dose,t.dose_unit,t.max_unit,t.min_number,s.creater,x.drug_code").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Joins("left join xt_drug_warehouse as s on s.id = x.warehousing_id and s.org_id = ? and s.status =1", orgid).Order("x.id desc").Count(&total).Offset(offset).Limit(limit).Group("x.id").Scan(&drugInfo).Error
  287. } else {
  288. err = db.Select("x.id,x.warehousing_id,x.drug_id,x.batch_number,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.storehouse_id,x.max_unit as count_unit,t.drug_type,t.drug_name,t.drug_spec,t.min_unit,t.dose,t.dose_unit,t.max_unit,t.min_number,s.creater,x.drug_code").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ? and t.status =1", orgid).Joins("left join xt_drug_warehouse as s on s.id = x.warehousing_id and s.org_id = ? and s.status =1", orgid).Order("x.id desc").Count(&total).Offset(offset).Limit(limit).Group("x.id").Scan(&drugInfo).Error
  289. }
  290. return drugInfo, total, err
  291. }
  292. func GetDrugReturnOrder(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, limit int64, page int64) (returninfo []*models.BloodDrugSalesReturnInfo, total int64, err error) {
  293. likeKey := "%" + keyword + "%"
  294. offset := (page - 1) * limit
  295. db := XTReadDB().Table("xt_drug_sales_return_info as x").Where("x.status =1")
  296. dbOne := XTReadDB().Table("xt_base_drug as s").Where("s.status =1")
  297. dbTwo := XTReadDB().Table("xt_drug_sales_return as r").Where("r.status = 1")
  298. fmt.Print(dbOne, dbTwo)
  299. if startime > 0 {
  300. db = db.Where("x.ctime >= ?", startime)
  301. }
  302. if endtime > 0 {
  303. db = db.Where("x.ctime <=?", endtime)
  304. }
  305. if orgid > 0 {
  306. db = db.Where("x.org_id = ?", orgid)
  307. }
  308. if orderType > 0 {
  309. db = db.Where("x.type = ?", orderType)
  310. }
  311. if len(keyword) > 0 {
  312. db = db.Where("x.order_number like ? or s.drug_spec like ? or r.creater like ?", likeKey, likeKey, likeKey)
  313. }
  314. if manufacturerId > 0 {
  315. err = db.Select("x.id,x.drug_id,x.sales_return_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_spec,s.drug_type,s.min_unit,r.creater").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_sales_return as r on r.id = x.sales_return_id and r.org_id = ? and r.status =1", orgid).Where("r.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&returninfo).Error
  316. } else {
  317. err = db.Select("x.id,x.drug_id,x.sales_return_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_spec,s.drug_type,s.min_unit,r.creater").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_sales_return as r on r.id = x.sales_return_id and r.org_id = ? and r.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&returninfo).Error
  318. }
  319. return returninfo, total, err
  320. }
  321. func GetDrugOutOrder(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, page int64, limit int64, storehouse_id int64, drug_id int64, order_way int64) (outinfo []*models.BloodDrugWarehouseOutInfo, total int64, err error) {
  322. likeKey := "%" + keyword + "%"
  323. offset := (page - 1) * limit
  324. db := XTReadDB().Table("sgj_xt.xt_drug_warehouse_out_info as x").Where("x.status =1 and x.is_check = 1")
  325. dbOne := XTReadDB().Table("sgj_xt.xt_base_drug as b").Where("b.status =1")
  326. dbTwo := XTReadDB().Table("sgj_xt.xt_drug_warehouse_out as t").Where("t.status = 1")
  327. dbThree := XTReadDB().Table("sgj_xt.xt_drug_warehouse_info as p").Where("p.status=1")
  328. fmt.Print(dbOne, dbTwo, dbThree)
  329. if startime > 0 {
  330. db = db.Where("x.sys_record_time >=?", startime)
  331. }
  332. if endtime > 0 {
  333. db = db.Where("x.sys_record_time <=?", endtime)
  334. }
  335. if orgid > 0 {
  336. db = db.Where("x.org_id = ?", orgid)
  337. }
  338. if orderType > 0 {
  339. db = db.Where("x.type = ?", orderType)
  340. }
  341. if storehouse_id > 0 {
  342. db = db.Where("x.storehouse_id = ?", storehouse_id)
  343. }
  344. if drug_id > 0 {
  345. db = db.Where("x.drug_id = ?", drug_id)
  346. }
  347. if order_way == 1 {
  348. db = db.Where("x.is_sys!=1")
  349. }
  350. if order_way == 2 {
  351. db = db.Where("x.is_sys=1")
  352. }
  353. if len(keyword) > 0 {
  354. db = db.Joins("left join sgj_xt.xt_drug_warehouse_out as o on o.id = x.warehouse_out_id left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.creater").Group("x.id")
  355. db = db.Where("x.warehouse_out_order_number like ? or b.drug_name like ? or r.user_name like ?", likeKey, likeKey, likeKey)
  356. }
  357. db = db.Joins("left join sgj_xt.xt_drug_warehouse_info as p on p.id =x.warehouse_info_id")
  358. if manufacturerId > 0 {
  359. err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.storehouse_id,x.patient_id,x.batch_number,b.drug_name,b.drug_spec,b.drug_type,b.min_unit,b.max_unit,b.min_number,b.dose,b.dose_unit,b.last_price,t.creater,p.price as infor_price").Joins("left join xt_base_drug as b on b.id = x.drug_id and b.org_id = ? and b.status =1", orgid).Joins("left join xt_drug_warehouse_out as t on t.id = x.warehouse_out_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&outinfo).Error
  360. } else {
  361. err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.storehouse_id,x.patient_id,x.batch_number,b.drug_name,b.drug_spec,b.drug_type,b.min_unit,b.max_unit,b.min_number,b.dose,b.dose_unit,b.last_price,t.creater,p.price as infor_price").Joins("left join xt_base_drug as b on b.id = x.drug_id and b.org_id = ? and b.status =1", orgid).Joins("left join xt_drug_warehouse_out as t on t.id = x.warehouse_out_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&outinfo).Error
  362. }
  363. return outinfo, total, err
  364. }
  365. func GetDrugCancelOrderPrint(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, storehouse_id int64, drug_id int64) (info []*models.BloodDrugCancelStockInfo, err error) {
  366. likeKey := "%" + keyword + "%"
  367. db := XTReadDB().Table("xt_drug_cancel_stock_info as x").Where("x.status =1")
  368. dbOne := XTReadDB().Table("xt_base_drug as s").Where("s.status =1")
  369. dbTwo := XTReadDB().Table("xt_drug_cancel_stock as t").Where("t.status = 1")
  370. fmt.Print(dbOne, dbTwo)
  371. if startime > 0 {
  372. db = db.Where("x.ctime >= ?", startime)
  373. }
  374. if endtime > 0 {
  375. db = db.Where("x.ctime<=?", endtime)
  376. }
  377. if orgid > 0 {
  378. db = db.Where("x.org_id = ?", orgid)
  379. }
  380. if orderType > 0 {
  381. db = db.Where("x.type = ? ", orderType)
  382. }
  383. if len(keyword) > 0 {
  384. db = db.Where("x.order_number like ? or s.drug_spec like ? or t.creater like ?", likeKey, likeKey, likeKey)
  385. }
  386. if storehouse_id > 0 {
  387. db = db.Where("x.storehouse_id = ?", storehouse_id)
  388. }
  389. if drug_id > 0 {
  390. db = db.Where("x.drug_id = ?", drug_id)
  391. }
  392. if manufacturerId > 0 {
  393. err = db.Select("x.id,x.max_unit as unit,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,s.dealer,s.manufacturer,x.retail_price,x.retail_total_price,x.number,x.storehouse_id,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Group("x.drug_id").Scan(&info).Error
  394. } else {
  395. err = db.Select("x.id,x.max_unit as unit,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,s.dealer,s.manufacturer,x.retail_price,x.retail_total_price,x.number,x.storehouse_id,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Group("x.drug_id").Scan(&info).Error
  396. }
  397. return info, err
  398. }
  399. func GetDrugCancelOrder(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, page int64, limit int64, storehouse_id int64, drug_id int64) (cancel []*models.BloodDrugCancelStockInfo, total int64, err error) {
  400. likeKey := "%" + keyword + "%"
  401. offset := (page - 1) * limit
  402. db := XTReadDB().Table("xt_drug_cancel_stock_info as x").Where("x.status =1")
  403. dbOne := XTReadDB().Table("xt_base_drug as s").Where("s.status =1")
  404. dbTwo := XTReadDB().Table("xt_drug_cancel_stock as t").Where("t.status = 1")
  405. fmt.Print(dbOne, dbTwo)
  406. if startime > 0 {
  407. db = db.Where("x.ctime >= ?", startime)
  408. }
  409. if endtime > 0 {
  410. db = db.Where("x.ctime<=?", endtime)
  411. }
  412. if orgid > 0 {
  413. db = db.Where("x.org_id = ?", orgid)
  414. }
  415. if orderType > 0 {
  416. db = db.Where("x.type = ? ", orderType)
  417. }
  418. if storehouse_id > 0 {
  419. db = db.Where("x.storehouse_id = ?", storehouse_id)
  420. }
  421. if drug_id > 0 {
  422. db = db.Where("x.drug_id = ?", drug_id)
  423. }
  424. if len(keyword) > 0 {
  425. db = db.Joins("left join sgj_xt.xt_drug_cancel_stock as o on o.id = x.cancel_stock_id left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.creater").Group("o.id")
  426. db = db.Where("x.order_number like ? or s.drug_spec like ? or r.user_name like ? or s.drug_name like ?", likeKey, likeKey, likeKey, likeKey)
  427. }
  428. if manufacturerId > 0 {
  429. err = db.Select("x.id,x.max_unit as unit,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,s.dealer,s.manufacturer,x.retail_price,x.retail_total_price,x.number,x.storehouse_id,x.patient_id,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
  430. } else {
  431. err = db.Select("x.id,x.max_unit as unit,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,s.dealer,s.manufacturer,x.retail_price,x.retail_total_price,x.number,x.storehouse_id,x.patient_id,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
  432. }
  433. return cancel, total, err
  434. }
  435. func FindPrintStockGoodInfoByType(types int, startTime int64, end_time int64, orgId int64) (list []*models.StockInfo, err error) {
  436. db := XTReadDB().Model(&models.StockInfo{})
  437. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgId)
  438. if types == 1 {
  439. db = db.Joins("JOIN xt_warehouse_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgId).Group("xt_good_information.id")
  440. db = db.Preload("QueryWarehousingInfo", func(db *gorm.DB) *gorm.DB {
  441. return db.Where("xt_warehouse_info.org_id = ? AND xt_warehouse_info.status = 1", orgId).Joins("JOIN xt_warehouse AS warehouse ON warehouse.id = xt_warehouse_info.warehousing_id AND warehouse.status = 1 AND warehouse.warehousing_time >=? AND warehouse.warehousing_time<= ? AND warehouse.org_id = ?", startTime, end_time, orgId)
  442. })
  443. } else if types == 2 {
  444. db = db.Joins("JOIN xt_sales_return_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgId).Group("xt_good_information.id")
  445. db = db.Preload("QuerySalesReturnInfo", func(db *gorm.DB) *gorm.DB {
  446. return db.Where("xt_sales_return_info.org_id = ? AND xt_sales_return_info.status = 1", orgId).Joins("JOIN xt_sales_return AS sales ON sales.id = xt_sales_return_info.sales_return_id AND sales.status = 1 AND sales.return_time >=? AND sales.return_time<= ? AND sales.org_id = ?", startTime, end_time, orgId)
  447. })
  448. } else if types == 3 {
  449. db = db.Joins("JOIN xt_warehouse_out_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgId).Group("xt_good_information.id")
  450. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  451. return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1", orgId).Joins("JOIN xt_warehouse_out ON xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.status = 1 AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.org_id = ? ", startTime, end_time, orgId)
  452. })
  453. } else if types == 4 {
  454. db = db.Joins("JOIN xt_cancel_stock_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgId).Group("xt_good_information.id")
  455. db = db.Preload("QueryCancelStockInfo", func(db *gorm.DB) *gorm.DB {
  456. return db.Where("xt_cancel_stock_info.org_id = ? AND xt_cancel_stock_info.status = 1", orgId).Joins("JOIN xt_cancel_stock AS cancel ON cancel.id = xt_cancel_stock_info.cancel_stock_id AND cancel.status = 1 AND cancel.return_time >=? AND cancel.return_time<= ? AND cancel.org_id = ?", startTime, end_time, orgId)
  457. })
  458. }
  459. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgId)
  460. err = db.Order("ctime desc").Find(&list).Error
  461. return
  462. }
  463. func GetMobileScheduleListOne(start_time int64, end_time int64, org_id int64, schedule_type int64, partion_id int64) (schedulelist []*models.XtScheduleList, err error) {
  464. db := XTReadDB().Model(&schedulelist).Where("status =1 and user_org_id =?", org_id)
  465. if start_time > 0 {
  466. db = db.Where("schedule_date>=?", start_time)
  467. }
  468. if end_time > 0 {
  469. db = db.Where("schedule_date<=?", end_time)
  470. }
  471. if schedule_type > 0 {
  472. db = db.Where("schedule_type =?", schedule_type)
  473. }
  474. if partion_id > 0 {
  475. db = db.Where("partition_id = ?", partion_id)
  476. }
  477. err = db.Preload("DialysisSolution", "status=1 and user_org_id =? and solution_status =1", org_id).Preload("DialysisPrescription", "status=1 and user_org_id =?", org_id).Find(&schedulelist).Error
  478. return schedulelist, err
  479. }
  480. func GetMobileDialysisPrescriptionList(start_time int64, end_time int64, org_id int64) (prescription []*models.DialysisPrescription, err error) {
  481. db := XTReadDB().Model(&prescription).Where("status =1 and user_org_id =?", org_id)
  482. if start_time > 0 {
  483. db = db.Where("record_date>=?", start_time)
  484. }
  485. if end_time > 0 {
  486. db = db.Where("record_date<=?", end_time)
  487. }
  488. err = db.Find(&prescription).Error
  489. return prescription, err
  490. }
  491. func GetOutStockTotalCountTwo(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
  492. err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.record_time,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time<=? and `status` = 1) as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
  493. return autoMatic, err
  494. }
  495. func AddMonitorOpen(config *models.XtMonitorConfig) error {
  496. err := XTWriteDB().Create(&config).Error
  497. return err
  498. }
  499. func UpdateMonitorOpen(orgid int64, config *models.XtMonitorConfig) error {
  500. err := XTWriteDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"is_open": config.IsOpen, "mtime": time.Now().Unix()}).Error
  501. return err
  502. }
  503. func GetMonitorConfig(orgid int64) (models.XtMonitorConfig, error) {
  504. config := models.XtMonitorConfig{}
  505. err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  506. return config, err
  507. }
  508. func AddOrderConfig(config *models.XtOrderConfig) error {
  509. err := XTWriteDB().Create(&config).Error
  510. return err
  511. }
  512. func UpdateOrderConfig(orgid int64, config *models.XtOrderConfig) error {
  513. err := XTWriteDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"is_open": config.IsOpen, "mtime": time.Now().Unix()}).Error
  514. return err
  515. }
  516. func GetOrderConfigById(orgid int64) (*models.XtOrderConfig, error) {
  517. config := models.XtOrderConfig{}
  518. err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  519. if err == gorm.ErrRecordNotFound {
  520. return nil, err
  521. }
  522. if err != nil {
  523. return nil, err
  524. }
  525. return &config, nil
  526. }
  527. func GetOrderConfig(orgid int64) (models.XtOrderConfig, error) {
  528. config := models.XtOrderConfig{}
  529. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  530. return config, err
  531. }
  532. func GetMonitorConfigById(orgid int64) (*models.XtMonitorConfig, error) {
  533. config := models.XtMonitorConfig{}
  534. err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  535. if err == gorm.ErrRecordNotFound {
  536. return nil, err
  537. }
  538. if err != nil {
  539. return nil, err
  540. }
  541. return &config, nil
  542. }
  543. func GetDrugAutoMaticList(orgid int64, warehouse_out_id int64, record_time int64, warehouse_out_order_number string) (auto []*models.VmDrugAutomaticReduceDetail, err error) {
  544. db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
  545. err = db.Select("x.org_id,x.warehouse_out_id,x.record_time,x.drug_id,sum(x.count) as total").Where("x.org_id = ? and x.record_time = ? and x.status= 1 and x.warehouse_out_order_number = ?", orgid, record_time, warehouse_out_order_number).Group("x.drug_id").Scan(&auto).Error
  546. return auto, err
  547. }
  548. func GetAllBaseDrugList(orgid int64) (drug []*models.BaseDrugLib, err error) {
  549. err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1", orgid).Find(&drug).Error
  550. return drug, err
  551. }
  552. func GetAllBaseDrugListTwo(orgid int64) (drug []*models.BaseDrugLibEleven, err error) {
  553. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  554. if orgid > 0 {
  555. db = db.Where("x.org_id =?", orgid)
  556. }
  557. err = db.Select("x.id,x.drug_name,p.manufacturer_name,x.dose,x.dose_unit,x.min_number,x.max_unit,x.min_unit,x.scan_code,x.drug_identification_code").Joins("left join xt_manufacturer as p on p.id =x.manufacturer").Scan(&drug).Error
  558. return drug, err
  559. }
  560. func GetDrugWarehuseOrderInfo(orgid int64) (drug []*models.DrugWarehouseInfo, err error) {
  561. err = XTReadDB().Where("org_id = ? and status = 1", orgid).Group("drug_id").Find(&drug).Error
  562. return drug, err
  563. }
  564. func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
  565. offset := (page - 1) * limit
  566. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  567. likeKey := "%" + keyword + "%"
  568. if orgid > 0 {
  569. db = db.Where("x.org_id = ?", orgid)
  570. }
  571. if startime > 0 {
  572. db = db.Where("x.ctime >=?", startime)
  573. }
  574. if endtime > 0 {
  575. db = db.Where("x.ctime<=?", endtime)
  576. }
  577. if drugcategory > 0 && len(keyword) == 0 {
  578. err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id =?", orgid).Where("t.drug_type = ?", drugcategory).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
  579. return
  580. }
  581. if drugcategory <= 0 && len(keyword) == 0 {
  582. err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
  583. return
  584. }
  585. if len(keyword) > 0 && drugcategory == 0 {
  586. err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id=?", orgid).Where("t.drug_name like ?", likeKey).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
  587. return
  588. }
  589. if len(keyword) <= 0 && drugcategory == 0 {
  590. err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
  591. return
  592. }
  593. if len(keyword) > 0 && drugcategory > 0 {
  594. err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Where("t.drug_type = ? or t.drug_name like ?", drugcategory, likeKey).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
  595. return
  596. }
  597. return list, total, err
  598. }
  599. func GetAllBaseDurgListCount(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64, storehouse_id int64, drug_id int64) (drug []*models.VmBaseDrug, total int64, err error) {
  600. offset := (page - 1) * limit
  601. db := XTReadDB().Table("xt_base_drug").Where("status = 1")
  602. likeKey := "%" + keyword + "%"
  603. if orgid > 0 {
  604. db = db.Where("org_id = ?", orgid)
  605. }
  606. if drugcategory > 0 {
  607. db = db.Where("drug_type = ?", drugcategory)
  608. }
  609. if len(keyword) > 0 {
  610. db = db.Where("drug_name like ?", likeKey)
  611. }
  612. if drug_id > 0 {
  613. db = db.Where("id = ?", drug_id)
  614. }
  615. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  616. if startime > 0 {
  617. db = db.Where("ctime>=?", startime)
  618. }
  619. if endtime > 0 {
  620. db = db.Where("ctime<=?", endtime)
  621. }
  622. if storehouse_id > 0 {
  623. db = db.Where("storehouse_id = ?", storehouse_id)
  624. }
  625. return db.Where("status = 1 and is_check = 1")
  626. }).Preload("DrugCancelStockInfo", func(db *gorm.DB) *gorm.DB {
  627. if startime > 0 {
  628. db = db.Where("ctime>=?", startime)
  629. }
  630. if endtime > 0 {
  631. db = db.Where("ctime<=?", endtime)
  632. }
  633. return db.Where("status = 1")
  634. }).Preload("DrugWarehouse", func(db *gorm.DB) *gorm.DB {
  635. if startime > 0 {
  636. db = db.Where("ctime>=?", startime)
  637. }
  638. if endtime > 0 {
  639. db = db.Where("ctime<=?", endtime)
  640. }
  641. if storehouse_id > 0 {
  642. db = db.Where("storehouse_id = ?", storehouse_id)
  643. }
  644. return db.Group("drug_id,storehouse_id").Where("status = 1")
  645. }).Preload("DrugWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  646. if startime > 0 {
  647. db = db.Where("ctime>=?", startime)
  648. }
  649. if endtime > 0 {
  650. db = db.Where("ctime<=?", endtime)
  651. }
  652. return db.Where("status = 1")
  653. }).Find(&drug).Error
  654. return drug, total, err
  655. }
  656. func GetDrugStockFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
  657. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  658. table := XTReadDB().Table("xt_base_drug as t").Where("t.status =1 ")
  659. fmt.Println(table)
  660. offset := (page - 1) * limit
  661. if startime > 0 {
  662. db = db.Where("x.ctime >=?", startime)
  663. }
  664. if endtime > 0 {
  665. db = db.Where("x.ctime<=?", endtime)
  666. }
  667. if orgid > 0 {
  668. db = db.Where("x.org_id = ?", orgid)
  669. }
  670. if drugid > 0 {
  671. db = db.Where("x.drug_id = ?", drugid)
  672. }
  673. err = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status = 1 and t.org_id = ?", orgid).Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,x.ctime,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Offset(offset).Count(&total).Order("x.ctime desc").Scan(&list).Error
  674. return list, total, err
  675. }
  676. func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64, stocktype int64) (list []*models.VmDrugWarehouseOutInfo, total int64, err error) {
  677. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
  678. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  679. fmt.Println(table)
  680. offset := (page - 1) * limit
  681. if startime > 0 {
  682. db = db.Where("x.ctime >=?", startime)
  683. }
  684. if endtime > 0 {
  685. db = db.Where("x.ctime<=?", endtime)
  686. }
  687. if orgid > 0 {
  688. db = db.Where("x.org_id = ?", orgid)
  689. }
  690. if drugid > 0 {
  691. db = db.Where("x.drug_id = ?", drugid)
  692. }
  693. if stocktype == 1 {
  694. db = db.Where("x.is_sys = 0")
  695. }
  696. if stocktype == 2 {
  697. db = db.Where("x.is_sys = 1")
  698. }
  699. err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.warehouse_info_id,x.ctime,x.batch_number,x.count_unit,t.drug_name,t.drug_type,t.min_number,t.min_unit,t.max_unit").Joins("left join xt_base_drug as t on t.id = x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
  700. return list, total, err
  701. }
  702. func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64, startime int64, endtime int64, start_first_time int64, end_first_time int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
  703. offset := (page - 1) * limit
  704. db := XTReadDB().Model(&drug).Where("status = 1 and is_check = 1")
  705. if drugid > 0 {
  706. db = db.Where("drug_id = ?", drugid)
  707. }
  708. if orgid > 0 {
  709. db = db.Where("org_id = ?", orgid)
  710. }
  711. if startime > 0 {
  712. db = db.Where("ctime >=?", startime)
  713. }
  714. if endtime > 0 {
  715. db = db.Where("ctime <=?", endtime)
  716. }
  717. if start_first_time > 0 {
  718. db = db.Where("expiry_date >=?", start_first_time)
  719. }
  720. if end_first_time > 0 {
  721. db = db.Where("expiry_date <=?", end_first_time)
  722. }
  723. err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Find(&drug).Error
  724. return drug, total, err
  725. }
  726. func GetDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
  727. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  728. if startime > 0 {
  729. db = db.Where("x.ctime >=?", startime)
  730. }
  731. if endtime > 0 {
  732. db = db.Where("x.ctime<=?", endtime)
  733. }
  734. if orgid > 0 {
  735. db = db.Where("x.org_id = ?", orgid)
  736. }
  737. err = db.Select("sum(x.warehousing_count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
  738. return info, err
  739. }
  740. func GetMinCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
  741. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  742. if startime > 0 {
  743. db = db.Where("x.ctime >=?", startime)
  744. }
  745. if endtime > 0 {
  746. db = db.Where("x.ctime<=?", endtime)
  747. }
  748. if orgid > 0 {
  749. db = db.Where("x.org_id = ?", orgid)
  750. }
  751. err = db.Select("sum(x.warehousing_count) as warehousing_count,x.drug_id").Group("x.drug_id").Scan(&info).Error
  752. return info, err
  753. }
  754. func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
  755. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
  756. if startime > 0 {
  757. db = db.Where("x.ctime >=?", startime)
  758. }
  759. if endtime > 0 {
  760. db = db.Where("x.ctime<=?", endtime)
  761. }
  762. if orgid > 0 {
  763. db = db.Where("x.org_id = ?", orgid)
  764. }
  765. err = db.Select("sum(x.count) as count,x.drug_id,x.count_unit").Group("x.drug_id").Find(&info).Error
  766. return info, err
  767. }
  768. func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugAutomaticReduceDetail, err error) {
  769. db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
  770. if startime > 0 {
  771. db = db.Where("x.record_time >=?", startime)
  772. }
  773. if endtime > 0 {
  774. db = db.Where("x.record_time<=?", endtime)
  775. }
  776. if orgid > 0 {
  777. db = db.Where("x.org_id = ?", orgid)
  778. }
  779. err = db.Select("sum(x.count) as count,x.drug_id,x.count_unit").Find(&info).Error
  780. return info, err
  781. }
  782. func GetCancelDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
  783. db := XTReadDB().Table(" xt_drug_cancel_stock_info as x").Where("x.status = 1")
  784. if startime > 0 {
  785. db = db.Where("x.ctime >=?", startime)
  786. }
  787. if endtime > 0 {
  788. db = db.Where("x.ctime<=?", endtime)
  789. }
  790. if orgid > 0 {
  791. db = db.Where("x.org_id = ?", orgid)
  792. }
  793. err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
  794. return info, err
  795. }
  796. func GetAllCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
  797. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  798. if startime > 0 {
  799. db = db.Where("x.ctime >=?", startime)
  800. }
  801. if endtime > 0 {
  802. db = db.Where("x.ctime<=?", endtime)
  803. }
  804. if orgid > 0 {
  805. db = db.Where("x.org_id = ?", orgid)
  806. }
  807. err = db.Find(&info).Error
  808. return info, err
  809. }
  810. func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
  811. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1 and x.count>0")
  812. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  813. fmt.Println(table)
  814. if orgid > 0 {
  815. db = db.Where("x.org_id = ?", orgid)
  816. }
  817. if id > 0 {
  818. db = db.Where("x.warehouse_out_id in(?)", id)
  819. }
  820. err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.count_unit,x.price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price as total_price,x.retail_total_price,x.storehouse_id,x.stock_count,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,x.admin_user_id,t.dose,t.dose_unit,t.last_price,t.min_price,t.medical_insurance_number,t.retail_price ,x.warehouse_info_id,x.class_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
  821. return info, err
  822. }
  823. func GetDrugWarehouseOutDetailSeventy(id int64, org_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
  824. err = XTReadDB().Where("warehouse_out_id in(?) and org_id = ? and status =1", id, org_id).Find(&info).Error
  825. return info, err
  826. }
  827. func GetDrugWarehouseOutDetailNighty(id int64, org_id int64) (info []*models.DrugWarehouseOutInfoNight, err error) {
  828. err = XTReadDB().Where("warehouse_out_id in(?) and org_id = ? and status =1", id, org_id).Preload("Drug", "org_id = ? and status = 1", org_id).Find(&info).Error
  829. return info, err
  830. }
  831. func GetDrugStockFlowDetail(record_time int64, orgid int64) (drugflow []*models.XtDrugAutomaticReduceDetail, err error) {
  832. err = XTReadDB().Where("record_time = ? and org_id = ? and status = 1", record_time, orgid).Preload("XtBaseDrug", "status = 1").Find(&drugflow).Error
  833. return drugflow, err
  834. }
  835. func GetSingeOrderFlow(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
  836. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
  837. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  838. fmt.Println(table)
  839. if orgid > 0 {
  840. db = db.Where("x.org_id = ?", orgid)
  841. }
  842. if id > 0 {
  843. db = db.Where("x.warehouse_out_id in(?)", id)
  844. }
  845. err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.retail_price,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price,t.min_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&outInfo).Error
  846. return outInfo, err
  847. }
  848. func GetAllSingleDrugDetail(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
  849. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
  850. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  851. fmt.Println(table)
  852. if orgid > 0 {
  853. db = db.Where("x.org_id = ?", orgid)
  854. }
  855. if id > 0 {
  856. db = db.Where("x.warehouse_out_id = ?", id)
  857. }
  858. err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price,t.min_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&outInfo).Error
  859. return outInfo, err
  860. }
  861. func GetDrugFlowList(id int64, orgid int64) (stockflow []*models.DrugFlow, err error) {
  862. err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Preload("BaseDrugLib", "org_id = ? and status = 1", orgid).Preload("DrugWarehouseInfoOne", "org_id = ? and status = 1", orgid).Find(&stockflow).Error
  863. return stockflow, err
  864. }
  865. func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlowNight, err error) {
  866. err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
  867. return drugFlow, err
  868. }
  869. func GetDrugFlowListGroupByIdOne(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
  870. err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
  871. return drugFlow, err
  872. }
  873. func FindDrugStockUserDetailByIdThree(id int64, record_time int64, org_id int64) (user []*DrugAutomaticReduceDetail, err error, total int64) {
  874. db := readDb.Model(&user)
  875. db = db.Preload("Drug", "org_id = ? AND status = 1", org_id)
  876. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  877. db = db.Preload("DrugWarehouseOutInfo", "drug_id = ? and sys_record_time = ? and status = 1 and org_id = ?", id, record_time, org_id)
  878. db = db.Where("status = 1 AND org_id = ? AND drug_id = ? AND record_time =?", org_id, id, record_time)
  879. db = db.Count(&total)
  880. err = db.Find(&user).Error
  881. return user, err, total
  882. }
  883. func FindeDrugWarehouserInfo(ware_out_id int64, drug_id int64, orgid int64) (outInfo []*models.DrugWarehouseOutInfo, err error) {
  884. err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and org_id = ? and status = 1", ware_out_id, drug_id, orgid).Find(&outInfo).Error
  885. return outInfo, err
  886. }
  887. func GetDrugFlowBatch(ware_out_id int64, drug_id int64, orgid int64) (flow []*models.DrugFlow, err error) {
  888. err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and user_org_id = ? and status = 1", ware_out_id, drug_id, orgid).Find(&flow).Error
  889. return flow, err
  890. }
  891. func GetDrugWarehouseOutInfoFlow(drug_id int64, start_time int64, end_time int64, user_org_id int64) (info []*models.XtDrugWarehouseOutInfo, err error) {
  892. db := XTReadDB().Model(&info).Where("status = 1")
  893. if start_time > 0 {
  894. db = db.Where("sys_record_time >=?", start_time)
  895. }
  896. if end_time > 0 {
  897. db = db.Where("sys_record_time <=?", end_time)
  898. }
  899. if user_org_id > 0 {
  900. db = db.Where("user_org_id = ?", user_org_id)
  901. }
  902. err = db.Find(&info).Error
  903. return info, err
  904. }
  905. func GetAllBaseDrugListTwenty(orgid int64) (drug []*models.BaseDrugLibTwenty, err error) {
  906. err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1 AND find_in_set('停用',drug_status) = 0", orgid).Find(&drug).Error
  907. return drug, err
  908. }
  909. func GetAllBaseDrugListTwentyOne(orgid int64) (drug []*models.BaseDrugLibTwenty, err error) {
  910. err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1", orgid).Find(&drug).Error
  911. return drug, err
  912. }
  913. func UpdateBaseDrugList(drug_id int64, specification_name string) error {
  914. err := XTWriteDB().Model(&models.XtBaseDrug{}).Where("id = ? and status=1", drug_id).Updates(map[string]interface{}{"specification_name": specification_name}).Error
  915. return err
  916. }
  917. func GetScheduleConfigByOrgId(org_id int64) (config models.ScheduleConfig, err error) {
  918. err = XTReadDB().Model(&models.ScheduleConfig{}).Where("user_org_id = ?", org_id).First(&config).Error
  919. return config, err
  920. }
  921. func SaveScheduleConfig(config models.ScheduleConfig) (err error) {
  922. err = XTWriteDB().Save(&config).Error
  923. return err
  924. }
  925. func CreateScheduleConfig(config models.ScheduleConfig) (err error) {
  926. err = XTWriteDB().Create(&config).Error
  927. return err
  928. }
  929. func GetScheduleConfigById(id int64) (config models.ScheduleConfig, err error) {
  930. err = XTReadDB().Model(&models.ScheduleConfig{}).Where("id = ?", id).First(&config).Error
  931. return config, err
  932. }
  933. func CreateCheckRemindConfig(config *models.XtCheckRemindCinfig) (err error) {
  934. err = XTWriteDB().Create(&config).Error
  935. return err
  936. }
  937. func GetCheckRemindConfigById(user_org_id int64) (config models.XtCheckRemindCinfig, err error) {
  938. err = XTReadDB().Model(&models.XtCheckRemindCinfig{}).Where("user_org_id = ?", user_org_id).First(&config).Error
  939. return config, err
  940. }
  941. func GetCheckRemindConfigByIdTwo(id int64) (config models.XtCheckRemindCinfig, err error) {
  942. err = XTReadDB().Model(&models.XtCheckRemindCinfig{}).Where("id = ?", id).First(&config).Error
  943. return config, err
  944. }
  945. func SaveCheckRemindConfig(config *models.XtCheckRemindCinfig) (err error) {
  946. err = XTWriteDB().Save(&config).Error
  947. return err
  948. }
  949. //func Get(id int64)(config models.ScheduleConfig, err error){
  950. // err = XTReadDB().Model(&models.ScheduleConfig{}).Where("id = ?", id).First(&config).Error
  951. // return config, err
  952. //}
  953. func GetMobileScheduleList(orgid int64) (schedule []*models.MyVmBloodSchedule, err error) {
  954. err = XTReadDB().Where("user_org_id = ? and status= 1 and schedule_date=1676563200", orgid).Preload("SchedualPatient", "user_org_id = ? and status = 1", orgid).Find(&schedule).Error
  955. return schedule, err
  956. }
  957. func GetPrescriptionList(patient_id int64, schedule_date int64, user_org_id int64) (models.DialysisPrescription, error) {
  958. prescription := models.DialysisPrescription{}
  959. err := XTReadDB().Where("patient_id = ? and record_date =? and user_org_id = ? and status =1", patient_id, schedule_date, user_org_id).Find(&prescription).Error
  960. return prescription, err
  961. }
  962. func GetLastMonitorRecordList(patient_id int64, schedule_date int64, user_org_id int64) (models.MonitoringRecord, error) {
  963. record := models.MonitoringRecord{}
  964. var err error
  965. if user_org_id != 10060 {
  966. err = XTReadDB().Where("patient_id =? and monitoring_date = ? and user_org_id = ? and status = 1", patient_id, schedule_date, user_org_id).Order("operate_time desc").Last(&record).Error
  967. }
  968. if user_org_id == 10060 {
  969. err = XTReadDB().Where("patient_id =? and monitoring_date = ? and user_org_id = ? and status = 1", patient_id, schedule_date, user_org_id).Order("id desc").Last(&record).Error
  970. }
  971. return record, err
  972. }
  973. func GetLastAfter(patient_id int64, schedule_date int64, user_org_id int64) (models.XtAssessmentAfterDislysis, error) {
  974. dislysis := models.XtAssessmentAfterDislysis{}
  975. err := XTReadDB().Where("patient_id = ? and assessment_date = ? and user_org_id =? and status= 1", patient_id, schedule_date, user_org_id).Find(&dislysis).Error
  976. return dislysis, err
  977. }
  978. func GetDialysisInformationByRecordDate(patient_id int64, record_date int64, user_org_id int64, module int64) (models.XtDialysisInformation, error) {
  979. information := models.XtDialysisInformation{}
  980. err := XTReadDB().Where("patient_id = ? and record_date = ? and user_org_id = ? and status=1 and module = ?", patient_id, record_date, user_org_id, module).Find(&information).Error
  981. return information, err
  982. }
  983. func GetDialysisInformationByRecordDateOne(patient_id int64, record_date int64, user_org_id int64) (models.XtDialysisInformation, error) {
  984. information := models.XtDialysisInformation{}
  985. err := XTReadDB().Where("patient_id = ? and record_date = ? and user_org_id = ? and status=1", patient_id, record_date, user_org_id).Find(&information).Error
  986. return information, err
  987. }
  988. func SaveDialysisInformation(information models.XtDialysisInformation) error {
  989. err := XTWriteDB().Create(&information).Error
  990. return err
  991. }
  992. func UpdateInformationByRecordDate(patient_id int64, record_date int64, user_org_id int64, application_date int64, remark string) error {
  993. err := XTWriteDB().Model(&models.XtDialysisInformation{}).Where("patient_id = ? and record_date = ? and user_org_id = ? and status = 1", patient_id, record_date, user_org_id).Update(map[string]interface{}{"application_status": 2, "application_date": application_date, "remark": remark}).Error
  994. return err
  995. }
  996. func GetMobileInformation(limit int64, page int64, application_status int64, orgid int64) (infor []*models.XtDialysisInformation, total int64, err error) {
  997. db := XTReadDB().Model(&infor).Where("status=1")
  998. if orgid > 0 {
  999. db = db.Where("user_org_id = ?", orgid)
  1000. }
  1001. if application_status > 0 {
  1002. db = db.Where("application_status = ?", application_status)
  1003. }
  1004. err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("ctime desc").Find(&infor).Error
  1005. return infor, total, err
  1006. }
  1007. func GetMobileInformationOne(limit int64, page int64, orgid int64) (infor []*models.XtDialysisInformation, total int64, err error) {
  1008. db := XTReadDB().Model(&infor).Where("status=1")
  1009. if orgid > 0 {
  1010. db = db.Where("user_org_id = ?", orgid)
  1011. }
  1012. err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("ctime desc").Find(&infor).Error
  1013. return infor, total, err
  1014. }
  1015. func CheckMobileInformation(id int64, application_status int64, checker int64, checker_time int64) error {
  1016. err := XTWriteDB().Model(&models.XtDialysisInformation{}).Where("id = ? and status= 1", id).Update(map[string]interface{}{"application_status": application_status, "checker": checker, "check_time": checker_time}).Error
  1017. return err
  1018. }
  1019. func GetPrescriptionPatientList(orgID int64, keywords string) (patient []*models.Patients, err error) {
  1020. fmt.Println("keyworsosososo", keywords)
  1021. db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1", orgID)
  1022. if len(keywords) > 0 {
  1023. likekey := "%" + keywords + "%"
  1024. err = db.Where("(name LIKE ?)", likekey).Find(&patient).Error
  1025. } else {
  1026. err = db.Find(&patient).Error
  1027. }
  1028. return
  1029. }
  1030. func GetPrescriptionLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (prescriptionlog []*models.XtDialysisPrescriptionLog, total int64, err error) {
  1031. offset := (page - 1) * limit
  1032. db := XTReadDB().Model(prescriptionlog).Where("status =1")
  1033. if patient_id > 0 {
  1034. db = db.Where("patient_id = ?", patient_id)
  1035. }
  1036. if record_date > 0 {
  1037. db = db.Where("record_date = ?", record_date)
  1038. }
  1039. if orgId > 0 {
  1040. db = db.Where("user_org_id = ? ", orgId)
  1041. }
  1042. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&prescriptionlog).Error
  1043. return prescriptionlog, total, err
  1044. }
  1045. func GetBeforLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (befor []*models.XtAssessmentBeforeDislysisLog, total int64, err error) {
  1046. offset := (page - 1) * limit
  1047. db := XTReadDB().Model(befor).Where("status =1")
  1048. if patient_id > 0 {
  1049. db = db.Where("patient_id = ?", patient_id)
  1050. }
  1051. if record_date > 0 {
  1052. db = db.Where("record_date = ?", record_date)
  1053. }
  1054. if orgId > 0 {
  1055. db = db.Where("user_org_id = ? ", orgId)
  1056. }
  1057. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&befor).Error
  1058. return befor, total, err
  1059. }
  1060. func GetAllPatientLog(orgid int64) (patients []*models.VMMonitorPatients, err error) {
  1061. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&patients).Error
  1062. return patients, err
  1063. }
  1064. func GetAllDoctorLog(orgid int64) (appRole []*models.App_Role, err error) {
  1065. err = UserReadDB().Where("org_id = ? AND status = 1", orgid).Find(&appRole).Error
  1066. return appRole, err
  1067. }
  1068. func GetDocLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (doctorlist []*models.XtDoctorAdviceLog, total int64, err error) {
  1069. offset := (page - 1) * limit
  1070. db := XTReadDB().Model(doctorlist).Where("status =1")
  1071. if patient_id > 0 {
  1072. db = db.Where("patient_id = ?", patient_id)
  1073. }
  1074. if record_date > 0 {
  1075. db = db.Where("record_date = ?", record_date)
  1076. }
  1077. if orgId > 0 {
  1078. db = db.Where("user_org_id = ? ", orgId)
  1079. }
  1080. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&doctorlist).Error
  1081. return doctorlist, total, err
  1082. }
  1083. func GetMonitorLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (monitorlist []*models.XtMonitorRecordLog, total int64, err error) {
  1084. offset := (page - 1) * limit
  1085. db := XTReadDB().Model(monitorlist).Where("status =1")
  1086. if patient_id > 0 {
  1087. db = db.Where("patient_id = ?", patient_id)
  1088. }
  1089. if record_date > 0 {
  1090. db = db.Where("record_date = ?", record_date)
  1091. }
  1092. if orgId > 0 {
  1093. db = db.Where("user_org_id = ? ", orgId)
  1094. }
  1095. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&monitorlist).Error
  1096. return monitorlist, total, err
  1097. }
  1098. func GetAfterLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (afterlist []*models.XtMonitorRecordLog, total int64, err error) {
  1099. offset := (page - 1) * limit
  1100. db := XTReadDB().Model(afterlist).Where("status =1")
  1101. if patient_id > 0 {
  1102. db = db.Where("patient_id = ?", patient_id)
  1103. }
  1104. if record_date > 0 {
  1105. db = db.Where("record_date = ?", record_date)
  1106. }
  1107. if orgId > 0 {
  1108. db = db.Where("user_org_id = ? ", orgId)
  1109. }
  1110. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&afterlist).Error
  1111. return afterlist, total, err
  1112. }
  1113. func GetGatherSettingByOrgId(user_org_id int64) (models.XtDialysisGatherSetting, error) {
  1114. gatherSetting := models.XtDialysisGatherSetting{}
  1115. err := XTReadDB().Where("user_org_id =? and status =1", user_org_id).Find(&gatherSetting).Error
  1116. return gatherSetting, err
  1117. }
  1118. func CreateGather(setting models.XtDialysisGatherSetting) error {
  1119. err := XTWriteDB().Create(&setting).Error
  1120. return err
  1121. }
  1122. func SaveGather(setting models.XtDialysisGatherSetting) error {
  1123. err := XTWriteDB().Save(&setting).Error
  1124. return err
  1125. }
  1126. func GetGatherSetting(user_org_id int64) (models.XtDialysisGatherSetting, error) {
  1127. gatherSetting := models.XtDialysisGatherSetting{}
  1128. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&gatherSetting).Error
  1129. return gatherSetting, err
  1130. }
  1131. func GetMobiledialysiOrder(user_org_id int64, patient_id int64, record_date int64) (models.Schedule, error) {
  1132. dialysisOrder := models.Schedule{}
  1133. err := XTReadDB().Where("user_org_id =? and patient_id =? and schedule_date =? and status=1", user_org_id, patient_id, record_date).Find(&dialysisOrder).Error
  1134. return dialysisOrder, err
  1135. }
  1136. func GetPrescriptionListByToDay(user_org_id int64, patient_id int64, record_Date int64) (models.HisPrescriptionInfo, error) {
  1137. prescriptionInfo := models.HisPrescriptionInfo{}
  1138. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and record_date = ? and status =1", user_org_id, patient_id, record_Date).Find(&prescriptionInfo).Error
  1139. return prescriptionInfo, err
  1140. }