gobal_config_service.go 58KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "time"
  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]).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).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 GetDrugInOrderDetail(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, page int64, limit int64, storehouse_id int64) (drugInfo []*models.BloodDrugWarehouseInfo, total int64, err error) {
  236. likeKey := "%" + keyword + "%"
  237. offset := (page - 1) * limit
  238. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1")
  239. dbOne := XTReadDB().Table("xt_base_drug as t").Where("t.status =1")
  240. dbTwo := XTReadDB().Table("xt_drug_warehouse as s").Where("s.status = 1")
  241. dbThree := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  242. fmt.Print(dbOne, dbTwo, dbThree)
  243. if startime > 0 {
  244. db = db.Where("x.ctime >=?", startime)
  245. }
  246. if endtime > 0 {
  247. db = db.Where("x.ctime <=?", endtime)
  248. }
  249. if orgid > 0 {
  250. db = db.Where("x.org_id =?", orgid)
  251. }
  252. if storehouse_id > 0 {
  253. db = db.Where("x.storehouse_id = ?", storehouse_id)
  254. }
  255. if len(keyword) > 0 {
  256. 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").Group("s.id")
  257. db = db.Where("x.warehousing_order like ? or t.drug_name like ? or r.user_name like ? ", likeKey, likeKey, likeKey)
  258. }
  259. if manufacturerId > 0 {
  260. err = db.Select("x.id,x.warehousing_id,x.drug_id,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").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).Scan(&drugInfo).Error
  261. } else {
  262. err = db.Select("x.id,x.warehousing_id,x.drug_id,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").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).Scan(&drugInfo).Error
  263. }
  264. return drugInfo, total, err
  265. }
  266. 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) {
  267. likeKey := "%" + keyword + "%"
  268. offset := (page - 1) * limit
  269. db := XTReadDB().Table("xt_drug_sales_return_info as x").Where("x.status =1")
  270. dbOne := XTReadDB().Table("xt_base_drug as s").Where("s.status =1")
  271. dbTwo := XTReadDB().Table("xt_drug_sales_return as r").Where("r.status = 1")
  272. fmt.Print(dbOne, dbTwo)
  273. if startime > 0 {
  274. db = db.Where("x.ctime >= ?", startime)
  275. }
  276. if endtime > 0 {
  277. db = db.Where("x.ctime <=?", endtime)
  278. }
  279. if orgid > 0 {
  280. db = db.Where("x.org_id = ?", orgid)
  281. }
  282. if orderType > 0 {
  283. db = db.Where("x.type = ?", orderType)
  284. }
  285. if len(keyword) > 0 {
  286. db = db.Where("x.order_number like ? or s.drug_spec like ? or r.creater like ?", likeKey, likeKey, likeKey)
  287. }
  288. if manufacturerId > 0 {
  289. 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
  290. } else {
  291. 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
  292. }
  293. return returninfo, total, err
  294. }
  295. func GetDrugOutOrder(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, page int64, limit int64, storehouse_id int64) (outinfo []*models.BloodDrugWarehouseOutInfo, total int64, err error) {
  296. likeKey := "%" + keyword + "%"
  297. offset := (page - 1) * limit
  298. db := XTReadDB().Table("sgj_xt.xt_drug_warehouse_out_info as x").Where("x.status =1 and x.is_check = 1")
  299. dbOne := XTReadDB().Table("sgj_xt.xt_base_drug as b").Where("b.status =1")
  300. dbTwo := XTReadDB().Table("sgj_xt.xt_drug_warehouse_out as t").Where("t.status = 1")
  301. dbThree := XTReadDB().Table("sgj_xt.xt_drug_warehouse_info as p").Where("p.status=1")
  302. fmt.Print(dbOne, dbTwo, dbThree)
  303. if startime > 0 {
  304. db = db.Where("x.sys_record_time >=?", startime)
  305. }
  306. if endtime > 0 {
  307. db = db.Where("x.sys_record_time <=?", endtime)
  308. }
  309. if orgid > 0 {
  310. db = db.Where("x.org_id = ?", orgid)
  311. }
  312. if orderType > 0 {
  313. db = db.Where("x.type = ?", orderType)
  314. }
  315. if storehouse_id > 0 {
  316. db = db.Where("x.storehouse_id = ?", storehouse_id)
  317. }
  318. if len(keyword) > 0 {
  319. 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")
  320. db = db.Where("x.warehouse_out_order_number like ? or b.drug_name like ? or r.user_name like ?", likeKey, likeKey, likeKey)
  321. }
  322. db = db.Joins("left join sgj_xt.xt_drug_warehouse_info as p on p.id =x.warehouse_info_id")
  323. if manufacturerId > 0 {
  324. 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,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").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
  325. } else {
  326. 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,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").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
  327. }
  328. return outinfo, total, err
  329. }
  330. func GetDrugCancelOrderPrint(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, storehouse_id int64) (info []*models.BloodDrugCancelStockInfo, err error) {
  331. likeKey := "%" + keyword + "%"
  332. db := XTReadDB().Table("xt_drug_cancel_stock_info as x").Where("x.status =1")
  333. dbOne := XTReadDB().Table("xt_base_drug as s").Where("s.status =1")
  334. dbTwo := XTReadDB().Table("xt_drug_cancel_stock as t").Where("t.status = 1")
  335. fmt.Print(dbOne, dbTwo)
  336. if startime > 0 {
  337. db = db.Where("x.ctime >= ?", startime)
  338. }
  339. if endtime > 0 {
  340. db = db.Where("x.ctime<=?", endtime)
  341. }
  342. if orgid > 0 {
  343. db = db.Where("x.org_id = ?", orgid)
  344. }
  345. if orderType > 0 {
  346. db = db.Where("x.type = ? ", orderType)
  347. }
  348. if len(keyword) > 0 {
  349. db = db.Where("x.order_number like ? or s.drug_spec like ? or t.creater like ?", likeKey, likeKey, likeKey)
  350. }
  351. if storehouse_id > 0 {
  352. db = db.Where("x.storehouse_id = ?", storehouse_id)
  353. }
  354. if manufacturerId > 0 {
  355. 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
  356. } else {
  357. 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
  358. }
  359. return info, err
  360. }
  361. func GetDrugCancelOrder(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, page int64, limit int64, storehouse_id int64) (cancel []*models.BloodDrugCancelStockInfo, total int64, err error) {
  362. likeKey := "%" + keyword + "%"
  363. offset := (page - 1) * limit
  364. db := XTReadDB().Table("xt_drug_cancel_stock_info as x").Where("x.status =1")
  365. dbOne := XTReadDB().Table("xt_base_drug as s").Where("s.status =1")
  366. dbTwo := XTReadDB().Table("xt_drug_cancel_stock as t").Where("t.status = 1")
  367. fmt.Print(dbOne, dbTwo)
  368. if startime > 0 {
  369. db = db.Where("x.ctime >= ?", startime)
  370. }
  371. if endtime > 0 {
  372. db = db.Where("x.ctime<=?", endtime)
  373. }
  374. if orgid > 0 {
  375. db = db.Where("x.org_id = ?", orgid)
  376. }
  377. if orderType > 0 {
  378. db = db.Where("x.type = ? ", orderType)
  379. }
  380. if storehouse_id > 0 {
  381. db = db.Where("x.storehouse_id = ?", storehouse_id)
  382. }
  383. if len(keyword) > 0 {
  384. 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")
  385. 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)
  386. }
  387. if manufacturerId > 0 {
  388. 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
  389. } else {
  390. 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
  391. }
  392. return cancel, total, err
  393. }
  394. func FindPrintStockGoodInfoByType(types int, startTime int64, end_time int64, orgId int64) (list []*models.StockInfo, err error) {
  395. db := XTReadDB().Model(&models.StockInfo{})
  396. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgId)
  397. if types == 1 {
  398. 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")
  399. db = db.Preload("QueryWarehousingInfo", func(db *gorm.DB) *gorm.DB {
  400. 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)
  401. })
  402. } else if types == 2 {
  403. 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")
  404. db = db.Preload("QuerySalesReturnInfo", func(db *gorm.DB) *gorm.DB {
  405. 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)
  406. })
  407. } else if types == 3 {
  408. 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")
  409. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  410. 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)
  411. })
  412. } else if types == 4 {
  413. 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")
  414. db = db.Preload("QueryCancelStockInfo", func(db *gorm.DB) *gorm.DB {
  415. 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)
  416. })
  417. }
  418. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgId)
  419. err = db.Order("ctime desc").Find(&list).Error
  420. return
  421. }
  422. func GetMobileScheduleListOne(start_time int64, end_time int64, org_id int64, schedule_type int64, partion_id int64) (schedulelist []*models.XtScheduleList, err error) {
  423. db := XTReadDB().Model(&schedulelist).Where("status =1 and user_org_id =?", org_id)
  424. if start_time > 0 {
  425. db = db.Where("schedule_date>=?", start_time)
  426. }
  427. if end_time > 0 {
  428. db = db.Where("schedule_date<=?", end_time)
  429. }
  430. if schedule_type > 0 {
  431. db = db.Where("schedule_type =?", schedule_type)
  432. }
  433. if partion_id > 0 {
  434. db = db.Where("partition_id = ?", partion_id)
  435. }
  436. 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
  437. return schedulelist, err
  438. }
  439. func GetMobileDialysisPrescriptionList(start_time int64, end_time int64, org_id int64) (prescription []*models.DialysisPrescription, err error) {
  440. db := XTReadDB().Model(&prescription).Where("status =1 and user_org_id =?", org_id)
  441. if start_time > 0 {
  442. db = db.Where("record_date>=?", start_time)
  443. }
  444. if end_time > 0 {
  445. db = db.Where("record_date<=?", end_time)
  446. }
  447. err = db.Find(&prescription).Error
  448. return prescription, err
  449. }
  450. func GetOutStockTotalCountTwo(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
  451. 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
  452. return autoMatic, err
  453. }
  454. func AddMonitorOpen(config *models.XtMonitorConfig) error {
  455. err := XTWriteDB().Create(&config).Error
  456. return err
  457. }
  458. func UpdateMonitorOpen(orgid int64, config *models.XtMonitorConfig) error {
  459. 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
  460. return err
  461. }
  462. func GetMonitorConfig(orgid int64) (models.XtMonitorConfig, error) {
  463. config := models.XtMonitorConfig{}
  464. err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  465. return config, err
  466. }
  467. func AddOrderConfig(config *models.XtOrderConfig) error {
  468. err := XTWriteDB().Create(&config).Error
  469. return err
  470. }
  471. func UpdateOrderConfig(orgid int64, config *models.XtOrderConfig) error {
  472. 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
  473. return err
  474. }
  475. func GetOrderConfigById(orgid int64) (*models.XtOrderConfig, error) {
  476. config := models.XtOrderConfig{}
  477. err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  478. if err == gorm.ErrRecordNotFound {
  479. return nil, err
  480. }
  481. if err != nil {
  482. return nil, err
  483. }
  484. return &config, nil
  485. }
  486. func GetOrderConfig(orgid int64) (models.XtOrderConfig, error) {
  487. config := models.XtOrderConfig{}
  488. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  489. return config, err
  490. }
  491. func GetMonitorConfigById(orgid int64) (*models.XtMonitorConfig, error) {
  492. config := models.XtMonitorConfig{}
  493. err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  494. if err == gorm.ErrRecordNotFound {
  495. return nil, err
  496. }
  497. if err != nil {
  498. return nil, err
  499. }
  500. return &config, nil
  501. }
  502. func GetDrugAutoMaticList(orgid int64, warehouse_out_id int64, record_time int64, warehouse_out_order_number string) (auto []*models.VmDrugAutomaticReduceDetail, err error) {
  503. db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
  504. 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
  505. return auto, err
  506. }
  507. func GetAllBaseDrugList(orgid int64) (drug []*models.BaseDrugLib, err error) {
  508. err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1", orgid).Find(&drug).Error
  509. return drug, err
  510. }
  511. func GetAllBaseDrugListTwo(orgid int64) (drug []*models.BaseDrugLibEleven, err error) {
  512. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  513. if orgid > 0 {
  514. db = db.Where("x.org_id =?", orgid)
  515. }
  516. 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").Joins("left join xt_manufacturer as p on p.id =x.manufacturer").Scan(&drug).Error
  517. return drug, err
  518. }
  519. func GetDrugWarehuseOrderInfo(orgid int64) (drug []*models.DrugWarehouseInfo, err error) {
  520. err = XTReadDB().Where("org_id = ? and status = 1", orgid).Group("drug_id").Find(&drug).Error
  521. return drug, err
  522. }
  523. func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
  524. offset := (page - 1) * limit
  525. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  526. likeKey := "%" + keyword + "%"
  527. if orgid > 0 {
  528. db = db.Where("x.org_id = ?", orgid)
  529. }
  530. if startime > 0 {
  531. db = db.Where("x.ctime >=?", startime)
  532. }
  533. if endtime > 0 {
  534. db = db.Where("x.ctime<=?", endtime)
  535. }
  536. if drugcategory > 0 && len(keyword) == 0 {
  537. 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
  538. return
  539. }
  540. if drugcategory <= 0 && len(keyword) == 0 {
  541. 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
  542. return
  543. }
  544. if len(keyword) > 0 && drugcategory == 0 {
  545. 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
  546. return
  547. }
  548. if len(keyword) <= 0 && drugcategory == 0 {
  549. 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
  550. return
  551. }
  552. if len(keyword) > 0 && drugcategory > 0 {
  553. 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
  554. return
  555. }
  556. return list, total, err
  557. }
  558. 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) {
  559. offset := (page - 1) * limit
  560. db := XTReadDB().Table("xt_base_drug").Where("status = 1")
  561. likeKey := "%" + keyword + "%"
  562. if orgid > 0 {
  563. db = db.Where("org_id = ?", orgid)
  564. }
  565. if drugcategory > 0 {
  566. db = db.Where("drug_type = ?", drugcategory)
  567. }
  568. if len(keyword) > 0 {
  569. db = db.Where("drug_name like ?", likeKey)
  570. }
  571. if drug_id > 0 {
  572. db = db.Where("id = ?", drug_id)
  573. }
  574. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  575. if startime > 0 {
  576. db = db.Where("ctime>=?", startime)
  577. }
  578. if endtime > 0 {
  579. db = db.Where("ctime<=?", endtime)
  580. }
  581. if storehouse_id > 0 {
  582. db = db.Where("storehouse_id = ?", storehouse_id)
  583. }
  584. return db.Where("status = 1 and is_check = 1")
  585. }).Preload("DrugCancelStockInfo", func(db *gorm.DB) *gorm.DB {
  586. if startime > 0 {
  587. db = db.Where("ctime>=?", startime)
  588. }
  589. if endtime > 0 {
  590. db = db.Where("ctime<=?", endtime)
  591. }
  592. return db.Where("status = 1")
  593. }).Preload("DrugWarehouse", func(db *gorm.DB) *gorm.DB {
  594. if startime > 0 {
  595. db = db.Where("ctime>=?", startime)
  596. }
  597. if endtime > 0 {
  598. db = db.Where("ctime<=?", endtime)
  599. }
  600. if storehouse_id > 0 {
  601. db = db.Where("storehouse_id = ?", storehouse_id)
  602. }
  603. return db.Group("drug_id,storehouse_id").Where("status = 1")
  604. }).Preload("DrugWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  605. if startime > 0 {
  606. db = db.Where("ctime>=?", startime)
  607. }
  608. if endtime > 0 {
  609. db = db.Where("ctime<=?", endtime)
  610. }
  611. return db.Where("status = 1")
  612. }).Find(&drug).Error
  613. return drug, total, err
  614. }
  615. func GetDrugStockFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
  616. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  617. table := XTReadDB().Table("xt_base_drug as t").Where("t.status =1 ")
  618. fmt.Println(table)
  619. offset := (page - 1) * limit
  620. if startime > 0 {
  621. db = db.Where("x.ctime >=?", startime)
  622. }
  623. if endtime > 0 {
  624. db = db.Where("x.ctime<=?", endtime)
  625. }
  626. if orgid > 0 {
  627. db = db.Where("x.org_id = ?", orgid)
  628. }
  629. if drugid > 0 {
  630. db = db.Where("x.drug_id = ?", drugid)
  631. }
  632. 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
  633. return list, total, err
  634. }
  635. func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64, stocktype int64) (list []*models.VmDrugWarehouseOutInfo, total int64, err error) {
  636. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
  637. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  638. fmt.Println(table)
  639. offset := (page - 1) * limit
  640. if startime > 0 {
  641. db = db.Where("x.ctime >=?", startime)
  642. }
  643. if endtime > 0 {
  644. db = db.Where("x.ctime<=?", endtime)
  645. }
  646. if orgid > 0 {
  647. db = db.Where("x.org_id = ?", orgid)
  648. }
  649. if drugid > 0 {
  650. db = db.Where("x.drug_id = ?", drugid)
  651. }
  652. if stocktype == 1 {
  653. db = db.Where("x.is_sys = 0")
  654. }
  655. if stocktype == 2 {
  656. db = db.Where("x.is_sys = 1")
  657. }
  658. 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
  659. return list, total, err
  660. }
  661. 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) {
  662. offset := (page - 1) * limit
  663. db := XTReadDB().Model(&drug).Where("status = 1 and is_check = 1")
  664. if drugid > 0 {
  665. db = db.Where("drug_id = ?", drugid)
  666. }
  667. if orgid > 0 {
  668. db = db.Where("org_id = ?", orgid)
  669. }
  670. if startime > 0 {
  671. db = db.Where("ctime >=?", startime)
  672. }
  673. if endtime > 0 {
  674. db = db.Where("ctime <=?", endtime)
  675. }
  676. if start_first_time > 0 {
  677. db = db.Where("expiry_date >=?", start_first_time)
  678. }
  679. if end_first_time > 0 {
  680. db = db.Where("expiry_date <=?", end_first_time)
  681. }
  682. err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Find(&drug).Error
  683. return drug, total, err
  684. }
  685. func GetDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
  686. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  687. if startime > 0 {
  688. db = db.Where("x.ctime >=?", startime)
  689. }
  690. if endtime > 0 {
  691. db = db.Where("x.ctime<=?", endtime)
  692. }
  693. if orgid > 0 {
  694. db = db.Where("x.org_id = ?", orgid)
  695. }
  696. err = db.Select("sum(x.warehousing_count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
  697. return info, err
  698. }
  699. func GetMinCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
  700. db := readDb2.Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  701. if startime > 0 {
  702. db = db.Where("x.ctime >=?", startime)
  703. }
  704. if endtime > 0 {
  705. db = db.Where("x.ctime<=?", endtime)
  706. }
  707. if orgid > 0 {
  708. db = db.Where("x.org_id = ?", orgid)
  709. }
  710. err = db.Select("sum(x.warehousing_count) as warehousing_count,x.drug_id").Group("x.drug_id").Scan(&info).Error
  711. return info, err
  712. }
  713. func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
  714. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
  715. if startime > 0 {
  716. db = db.Where("x.ctime >=?", startime)
  717. }
  718. if endtime > 0 {
  719. db = db.Where("x.ctime<=?", endtime)
  720. }
  721. if orgid > 0 {
  722. db = db.Where("x.org_id = ?", orgid)
  723. }
  724. err = db.Select("sum(x.count) as count,x.drug_id,x.count_unit").Group("x.drug_id").Find(&info).Error
  725. return info, err
  726. }
  727. func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugAutomaticReduceDetail, err error) {
  728. db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
  729. if startime > 0 {
  730. db = db.Where("x.record_time >=?", startime)
  731. }
  732. if endtime > 0 {
  733. db = db.Where("x.record_time<=?", endtime)
  734. }
  735. if orgid > 0 {
  736. db = db.Where("x.org_id = ?", orgid)
  737. }
  738. err = db.Select("sum(x.count) as count,x.drug_id,x.count_unit").Find(&info).Error
  739. return info, err
  740. }
  741. func GetCancelDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
  742. db := XTReadDB().Table(" xt_drug_cancel_stock_info as x").Where("x.status = 1")
  743. if startime > 0 {
  744. db = db.Where("x.ctime >=?", startime)
  745. }
  746. if endtime > 0 {
  747. db = db.Where("x.ctime<=?", endtime)
  748. }
  749. if orgid > 0 {
  750. db = db.Where("x.org_id = ?", orgid)
  751. }
  752. err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
  753. return info, err
  754. }
  755. func GetAllCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
  756. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  757. if startime > 0 {
  758. db = db.Where("x.ctime >=?", startime)
  759. }
  760. if endtime > 0 {
  761. db = db.Where("x.ctime<=?", endtime)
  762. }
  763. if orgid > 0 {
  764. db = db.Where("x.org_id = ?", orgid)
  765. }
  766. err = db.Find(&info).Error
  767. return info, err
  768. }
  769. func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
  770. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1 and x.count>0")
  771. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  772. fmt.Println(table)
  773. if orgid > 0 {
  774. db = db.Where("x.org_id = ?", orgid)
  775. }
  776. if id > 0 {
  777. db = db.Where("x.warehouse_out_id in(?)", id)
  778. }
  779. 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").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
  780. return info, err
  781. }
  782. func GetDrugWarehouseOutDetailSeventy(id int64, org_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
  783. err = XTReadDB().Where("warehouse_out_id in(?) and org_id = ? and status =1", id, org_id).Find(&info).Error
  784. return info, err
  785. }
  786. func GetDrugWarehouseOutDetailNighty(id int64, org_id int64) (info []*models.DrugWarehouseOutInfoNight, err error) {
  787. 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
  788. return info, err
  789. }
  790. func GetDrugStockFlowDetail(record_time int64, orgid int64) (drugflow []*models.XtDrugAutomaticReduceDetail, err error) {
  791. err = XTReadDB().Where("record_time = ? and org_id = ? and status = 1", record_time, orgid).Preload("XtBaseDrug", "status = 1").Find(&drugflow).Error
  792. return drugflow, err
  793. }
  794. func GetSingeOrderFlow(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
  795. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
  796. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  797. fmt.Println(table)
  798. if orgid > 0 {
  799. db = db.Where("x.org_id = ?", orgid)
  800. }
  801. if id > 0 {
  802. db = db.Where("x.warehouse_out_id in(?)", id)
  803. }
  804. 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
  805. return outInfo, err
  806. }
  807. func GetAllSingleDrugDetail(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
  808. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
  809. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  810. fmt.Println(table)
  811. if orgid > 0 {
  812. db = db.Where("x.org_id = ?", orgid)
  813. }
  814. if id > 0 {
  815. db = db.Where("x.warehouse_out_id = ?", id)
  816. }
  817. 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
  818. return outInfo, err
  819. }
  820. func GetDrugFlowList(id int64, orgid int64) (stockflow []*models.DrugFlow, err error) {
  821. 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
  822. return stockflow, err
  823. }
  824. func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlowNight, err error) {
  825. err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
  826. return drugFlow, err
  827. }
  828. func GetDrugFlowListGroupByIdOne(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
  829. err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
  830. return drugFlow, err
  831. }
  832. func FindDrugStockUserDetailByIdThree(id int64, record_time int64, org_id int64) (user []*DrugAutomaticReduceDetail, err error, total int64) {
  833. db := readDb.Model(&user)
  834. db = db.Preload("Drug", "org_id = ? AND status = 1", org_id)
  835. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  836. db = db.Preload("DrugWarehouseOutInfo", "drug_id = ? and sys_record_time = ? and status = 1 and org_id = ?", id, record_time, org_id)
  837. db = db.Where("status = 1 AND org_id = ? AND drug_id = ? AND record_time =?", org_id, id, record_time)
  838. db = db.Count(&total)
  839. err = db.Find(&user).Error
  840. return user, err, total
  841. }
  842. func FindeDrugWarehouserInfo(ware_out_id int64, drug_id int64, orgid int64) (outInfo []*models.DrugWarehouseOutInfo, err error) {
  843. err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and org_id = ? and status = 1", ware_out_id, drug_id, orgid).Find(&outInfo).Error
  844. return outInfo, err
  845. }
  846. func GetDrugFlowBatch(ware_out_id int64, drug_id int64, orgid int64) (flow []*models.DrugFlow, err error) {
  847. 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
  848. return flow, err
  849. }
  850. func GetDrugWarehouseOutInfoFlow(drug_id int64, start_time int64, end_time int64, user_org_id int64) (info []*models.XtDrugWarehouseOutInfo, err error) {
  851. db := XTReadDB().Model(&info).Where("status = 1")
  852. if start_time > 0 {
  853. db = db.Where("sys_record_time >=?", start_time)
  854. }
  855. if end_time > 0 {
  856. db = db.Where("sys_record_time <=?", end_time)
  857. }
  858. if user_org_id > 0 {
  859. db = db.Where("user_org_id = ?", user_org_id)
  860. }
  861. err = db.Find(&info).Error
  862. return info, err
  863. }
  864. func GetAllBaseDrugListTwenty(orgid int64) (drug []*models.BaseDrugLibTwenty, err error) {
  865. err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1 AND find_in_set('停用',drug_status) = 0", orgid).Find(&drug).Error
  866. return drug, err
  867. }
  868. func GetScheduleConfigByOrgId(org_id int64) (config models.ScheduleConfig, err error) {
  869. err = XTReadDB().Model(&models.ScheduleConfig{}).Where("user_org_id = ?", org_id).First(&config).Error
  870. return config, err
  871. }
  872. func SaveScheduleConfig(config models.ScheduleConfig) (err error) {
  873. err = XTWriteDB().Save(&config).Error
  874. return err
  875. }
  876. func CreateScheduleConfig(config models.ScheduleConfig) (err error) {
  877. err = XTWriteDB().Create(&config).Error
  878. return err
  879. }
  880. func GetScheduleConfigById(id int64) (config models.ScheduleConfig, err error) {
  881. err = XTReadDB().Model(&models.ScheduleConfig{}).Where("id = ?", id).First(&config).Error
  882. return config, err
  883. }
  884. func CreateCheckRemindConfig(config *models.XtCheckRemindCinfig) (err error) {
  885. err = XTWriteDB().Create(&config).Error
  886. return err
  887. }
  888. func GetCheckRemindConfigById(user_org_id int64) (config models.XtCheckRemindCinfig, err error) {
  889. err = XTReadDB().Model(&models.XtCheckRemindCinfig{}).Where("user_org_id = ?", user_org_id).First(&config).Error
  890. return config, err
  891. }
  892. func GetCheckRemindConfigByIdTwo(id int64) (config models.XtCheckRemindCinfig, err error) {
  893. err = XTReadDB().Model(&models.XtCheckRemindCinfig{}).Where("id = ?", id).First(&config).Error
  894. return config, err
  895. }
  896. func SaveCheckRemindConfig(config *models.XtCheckRemindCinfig) (err error) {
  897. err = XTWriteDB().Save(&config).Error
  898. return err
  899. }
  900. //func Get(id int64)(config models.ScheduleConfig, err error){
  901. // err = XTReadDB().Model(&models.ScheduleConfig{}).Where("id = ?", id).First(&config).Error
  902. // return config, err
  903. //}
  904. func GetMobileScheduleList(orgid int64) (schedule []*models.MyVmBloodSchedule, err error) {
  905. 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
  906. return schedule, err
  907. }
  908. func GetPrescriptionList(patient_id int64, schedule_date int64, user_org_id int64) (models.DialysisPrescription, error) {
  909. prescription := models.DialysisPrescription{}
  910. 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
  911. return prescription, err
  912. }
  913. func GetLastMonitorRecordList(patient_id int64, schedule_date int64, user_org_id int64) (models.MonitoringRecord, error) {
  914. record := models.MonitoringRecord{}
  915. err := XTReadDB().Where("patient_id =? and monitoring_date = ? and user_org_id = ? and status = 1", patient_id, schedule_date, user_org_id).Last(&record).Error
  916. return record, err
  917. }
  918. func GetLastAfter(patient_id int64, schedule_date int64, user_org_id int64) (models.XtAssessmentAfterDislysis, error) {
  919. dislysis := models.XtAssessmentAfterDislysis{}
  920. 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
  921. return dislysis, err
  922. }
  923. func GetDialysisInformationByRecordDate(patient_id int64, record_date int64, user_org_id int64, module int64) (models.XtDialysisInformation, error) {
  924. information := models.XtDialysisInformation{}
  925. 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
  926. return information, err
  927. }
  928. func GetDialysisInformationByRecordDateOne(patient_id int64, record_date int64, user_org_id int64) (models.XtDialysisInformation, error) {
  929. information := models.XtDialysisInformation{}
  930. 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
  931. return information, err
  932. }
  933. func SaveDialysisInformation(information models.XtDialysisInformation) error {
  934. err := XTWriteDB().Create(&information).Error
  935. return err
  936. }
  937. func UpdateInformationByRecordDate(patient_id int64, record_date int64, user_org_id int64, application_date int64, remark string) error {
  938. 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
  939. return err
  940. }
  941. func GetMobileInformation(limit int64, page int64, application_status int64, orgid int64) (infor []*models.XtDialysisInformation, total int64, err error) {
  942. db := XTReadDB().Model(&infor).Where("status=1")
  943. if orgid > 0 {
  944. db = db.Where("user_org_id = ?", orgid)
  945. }
  946. if application_status > 0 {
  947. db = db.Where("application_status = ?", application_status)
  948. }
  949. err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("ctime desc").Find(&infor).Error
  950. return infor, total, err
  951. }
  952. func GetMobileInformationOne(limit int64, page int64, orgid int64) (infor []*models.XtDialysisInformation, total int64, err error) {
  953. db := XTReadDB().Model(&infor).Where("status=1")
  954. if orgid > 0 {
  955. db = db.Where("user_org_id = ?", orgid)
  956. }
  957. err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("ctime desc").Find(&infor).Error
  958. return infor, total, err
  959. }
  960. func CheckMobileInformation(id int64, application_status int64, checker int64, checker_time int64) error {
  961. 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
  962. return err
  963. }
  964. func GetPrescriptionPatientList(orgID int64, keywords string) (patient []*models.Patients, err error) {
  965. fmt.Println("keyworsosososo", keywords)
  966. db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1", orgID)
  967. if len(keywords) > 0 {
  968. likekey := "%" + keywords + "%"
  969. err = db.Where("(name LIKE ?)", likekey).Find(&patient).Error
  970. } else {
  971. err = db.Find(&patient).Error
  972. }
  973. return
  974. }
  975. func GetPrescriptionLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (prescriptionlog []*models.XtDialysisPrescriptionLog, total int64, err error) {
  976. offset := (page - 1) * limit
  977. db := XTReadDB().Model(prescriptionlog).Where("status =1")
  978. if patient_id > 0 {
  979. db = db.Where("patient_id = ?", patient_id)
  980. }
  981. if record_date > 0 {
  982. db = db.Where("record_date = ?", record_date)
  983. }
  984. if orgId > 0 {
  985. db = db.Where("user_org_id = ? ", orgId)
  986. }
  987. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&prescriptionlog).Error
  988. return prescriptionlog, total, err
  989. }
  990. func GetBeforLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (befor []*models.XtAssessmentBeforeDislysisLog, total int64, err error) {
  991. offset := (page - 1) * limit
  992. db := XTReadDB().Model(befor).Where("status =1")
  993. if patient_id > 0 {
  994. db = db.Where("patient_id = ?", patient_id)
  995. }
  996. if record_date > 0 {
  997. db = db.Where("record_date = ?", record_date)
  998. }
  999. if orgId > 0 {
  1000. db = db.Where("user_org_id = ? ", orgId)
  1001. }
  1002. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&befor).Error
  1003. return befor, total, err
  1004. }
  1005. func GetAllPatientLog(orgid int64) (patients []*models.VMMonitorPatients, err error) {
  1006. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&patients).Error
  1007. return patients, err
  1008. }
  1009. func GetAllDoctorLog(orgid int64) (appRole []*models.App_Role, err error) {
  1010. err = UserReadDB().Where("org_id = ? AND status = 1", orgid).Find(&appRole).Error
  1011. return appRole, err
  1012. }
  1013. func GetDocLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (doctorlist []*models.XtDoctorAdviceLog, total int64, err error) {
  1014. offset := (page - 1) * limit
  1015. db := XTReadDB().Model(doctorlist).Where("status =1")
  1016. if patient_id > 0 {
  1017. db = db.Where("patient_id = ?", patient_id)
  1018. }
  1019. if record_date > 0 {
  1020. db = db.Where("record_date = ?", record_date)
  1021. }
  1022. if orgId > 0 {
  1023. db = db.Where("user_org_id = ? ", orgId)
  1024. }
  1025. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&doctorlist).Error
  1026. return doctorlist, total, err
  1027. }
  1028. func GetMonitorLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (monitorlist []*models.XtMonitorRecordLog, total int64, err error) {
  1029. offset := (page - 1) * limit
  1030. db := XTReadDB().Model(monitorlist).Where("status =1")
  1031. if patient_id > 0 {
  1032. db = db.Where("patient_id = ?", patient_id)
  1033. }
  1034. if record_date > 0 {
  1035. db = db.Where("record_date = ?", record_date)
  1036. }
  1037. if orgId > 0 {
  1038. db = db.Where("user_org_id = ? ", orgId)
  1039. }
  1040. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&monitorlist).Error
  1041. return monitorlist, total, err
  1042. }
  1043. func GetAfterLogList(patient_id int64, page int64, limit int64, record_date int64, orgId int64) (afterlist []*models.XtMonitorRecordLog, total int64, err error) {
  1044. offset := (page - 1) * limit
  1045. db := XTReadDB().Model(afterlist).Where("status =1")
  1046. if patient_id > 0 {
  1047. db = db.Where("patient_id = ?", patient_id)
  1048. }
  1049. if record_date > 0 {
  1050. db = db.Where("record_date = ?", record_date)
  1051. }
  1052. if orgId > 0 {
  1053. db = db.Where("user_org_id = ? ", orgId)
  1054. }
  1055. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&afterlist).Error
  1056. return afterlist, total, err
  1057. }
  1058. func GetGatherSettingByOrgId(user_org_id int64) (models.XtDialysisGatherSetting, error) {
  1059. gatherSetting := models.XtDialysisGatherSetting{}
  1060. err := XTReadDB().Where("user_org_id =? and status =1", user_org_id).Find(&gatherSetting).Error
  1061. return gatherSetting, err
  1062. }
  1063. func CreateGather(setting models.XtDialysisGatherSetting) error {
  1064. err := XTWriteDB().Create(&setting).Error
  1065. return err
  1066. }
  1067. func SaveGather(setting models.XtDialysisGatherSetting) error {
  1068. err := XTWriteDB().Save(&setting).Error
  1069. return err
  1070. }
  1071. func GetGatherSetting(user_org_id int64) (models.XtDialysisGatherSetting, error) {
  1072. gatherSetting := models.XtDialysisGatherSetting{}
  1073. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&gatherSetting).Error
  1074. return gatherSetting, err
  1075. }