gobal_config_service.go 61KB

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