xcx_mobile_api_service.go 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. package service
  2. import (
  3. "Xcx_New/models"
  4. "crypto/aes"
  5. "crypto/cipher"
  6. "encoding/base64"
  7. "encoding/json"
  8. "errors"
  9. "fmt"
  10. "github.com/jinzhu/gorm"
  11. "time"
  12. )
  13. func GetXcxMobileInformation(mobile string) (*models.XcxAdminUserRole, error) {
  14. role := models.XcxAdminUserRole{}
  15. err := UserReadDB().Model(&role).Where("mobile = ? and status = 1", mobile).Find(&role).Error
  16. if err == gorm.ErrRecordNotFound {
  17. return nil, err
  18. }
  19. if err != nil {
  20. return nil, err
  21. }
  22. return &role, nil
  23. }
  24. func CreateXcxAdminUser(role models.XcxAdminUserRole) error {
  25. err := UserReadDB().Create(&role).Error
  26. return err
  27. }
  28. func GetLoginInfor(mobile string) (models.XcxAdminUserRole, error) {
  29. role := models.XcxAdminUserRole{}
  30. err := UserReadDB().Model(&role).Where("mobile = ? and status = 1", mobile).Find(&role).Error
  31. return role, err
  32. }
  33. func GetMobilePatientInfo(mobile string) (models.XcxPatients, error) {
  34. patients := models.XcxPatients{}
  35. err := XTReadDB().Model(&patients).Where("(phone = ? or home_telephone = ? ) and status = 1", mobile, mobile).Find(&patients).Error
  36. return patients, err
  37. }
  38. func GetPatientListByPatientId(id int64) (models.XcxPatients, error) {
  39. patients := models.XcxPatients{}
  40. err := XTReadDB().Model(&patients).Where("id = ? and status = 1", id).Find(&patients).Error
  41. return patients, err
  42. }
  43. func DecryptData(app_id, session_key, iv, encrypted_data string) (map[string]interface{}, error) {
  44. aesKey, err := base64.StdEncoding.DecodeString(session_key)
  45. if err != nil {
  46. return nil, err
  47. }
  48. ivKey, err := base64.StdEncoding.DecodeString(iv)
  49. if err != nil {
  50. return nil, err
  51. }
  52. decodeData, err := base64.StdEncoding.DecodeString(encrypted_data)
  53. if err != nil {
  54. return nil, err
  55. }
  56. dataBytes, err := AesDecrypt(decodeData, aesKey, ivKey)
  57. if err != nil {
  58. return nil, err
  59. }
  60. var result map[string]interface{}
  61. err = json.Unmarshal(dataBytes, &result)
  62. watermark := result["watermark"].(map[string]interface{})
  63. if watermark["appid"] != app_id {
  64. return nil, errors.New("Invalid appid data!")
  65. }
  66. return result, err
  67. }
  68. func AesDecrypt(crypted, key, iv []byte) ([]byte, error) {
  69. block, err := aes.NewCipher(key)
  70. fmt.Println("w2222", err)
  71. if err != nil {
  72. return nil, err
  73. }
  74. blockMode := cipher.NewCBCDecrypter(block, iv)
  75. origData := make([]byte, len(crypted))
  76. blockMode.CryptBlocks(origData, crypted)
  77. // 去除填充
  78. length := len(origData)
  79. unp := int(origData[length-1])
  80. return origData[:(length - unp)], nil
  81. }
  82. func GetFirstDateOfWeek() (weekMonday string) {
  83. now := time.Now()
  84. offset := int(time.Monday - now.Weekday())
  85. if offset > 0 {
  86. offset = -6
  87. }
  88. weekStartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
  89. weekMonday = weekStartDate.Format("2006-01-02")
  90. return
  91. }
  92. func GetWeekDayOfWeek() (weekMonday string) {
  93. now := time.Now()
  94. offset := int(time.Monday - now.Weekday())
  95. if offset > 0 {
  96. offset = -6
  97. }
  98. weekStartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
  99. weekMonday = weekStartDate.Format("2006-01-02")
  100. return
  101. }
  102. func GetMobilePatient(mobile string, idcard string) (*models.XcxPatients, error) {
  103. patient := models.XcxPatients{}
  104. err := XTReadDB().Model(&patient).Where("(phone = ? or relative_phone =?) and id_card_no = ?", mobile, mobile, idcard).Find(&patient).Error
  105. if err == gorm.ErrRecordNotFound {
  106. return nil, err
  107. }
  108. if err != nil {
  109. return nil, err
  110. }
  111. return &patient, nil
  112. }
  113. func GetTemplateMode(orgid int64) (models.XcxGobalTemplate, error) {
  114. template := models.XcxGobalTemplate{}
  115. err := XTReadDB().Model(&template).Where("org_id = ? and status = 1", orgid).Find(&template).Error
  116. return template, err
  117. }
  118. func GetMobilePatientOne(mobile string) (*models.XcxAdminUserRole, error) {
  119. patient := models.XcxAdminUserRole{}
  120. err := UserReadDB().Model(&patient).Where("mobile = ? and status = 1", mobile).Find(&patient).Error
  121. if err == gorm.ErrRecordNotFound {
  122. return nil, err
  123. }
  124. if err != nil {
  125. return nil, err
  126. }
  127. return &patient, nil
  128. }
  129. func Dncrypt(rawData, key, iv string) (string, error) {
  130. data, err := base64.StdEncoding.DecodeString(rawData)
  131. key_b, err_1 := base64.StdEncoding.DecodeString(key)
  132. iv_b, _ := base64.StdEncoding.DecodeString(iv)
  133. if err != nil {
  134. return "", err
  135. }
  136. if err_1 != nil {
  137. return "", err_1
  138. }
  139. dnData, err := AesCBCDncrypt(data, key_b, iv_b)
  140. if err != nil {
  141. return "", err
  142. }
  143. return string(dnData), nil
  144. }
  145. // 解密
  146. func AesCBCDncrypt(encryptData, key, iv []byte) ([]byte, error) {
  147. block, err := aes.NewCipher(key)
  148. if err != nil {
  149. panic(err)
  150. }
  151. blockSize := block.BlockSize()
  152. if len(encryptData) < blockSize {
  153. panic("ciphertext too short")
  154. }
  155. if len(encryptData)%blockSize != 0 {
  156. panic("ciphertext is not a multiple of the block size")
  157. }
  158. mode := cipher.NewCBCDecrypter(block, iv)
  159. mode.CryptBlocks(encryptData, encryptData)
  160. // 解填充
  161. encryptData = PKCS7UnPadding(encryptData)
  162. return encryptData, nil
  163. }
  164. //去除填充
  165. func PKCS7UnPadding(origData []byte) []byte {
  166. length := len(origData)
  167. unpadding := int(origData[length-1])
  168. if length-unpadding < 0 {
  169. return origData[:0]
  170. }
  171. fmt.Println("changdu", length)
  172. fmt.Println("data", unpadding)
  173. return origData[:(length - unpadding)]
  174. }
  175. func GetScheduleInfo(startime int64, endtime int64, patient_id int64) (schedule []*models.VmBloodSchedule, err error) {
  176. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  177. table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
  178. fmt.Println(table)
  179. if startime > 0 {
  180. db = db.Where("x.schedule_date >=?", startime)
  181. }
  182. if endtime > 0 {
  183. db = db.Where("x.schedule_date <=?", endtime)
  184. }
  185. if patient_id > 0 {
  186. db = db.Where("x.patient_id = ?", patient_id)
  187. }
  188. err = db.Select("x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,t.name").Joins("left join xt_patients as t on t.id = x.patient_id").Scan(&schedule).Error
  189. return schedule, err
  190. }
  191. func GetTodayDialysis(recordDate int64, patient_id int64) (models.XcXDialysisOrder, error) {
  192. order := models.XcXDialysisOrder{}
  193. err := XTReadDB().Model(&order).Where("dialysis_date = ? and patient_id = ? and status = 1", recordDate, patient_id).Find(&order).Error
  194. return order, err
  195. }
  196. func GetTodayPrescription(recordDate int64, patient_id int64) (models.XcxXtDialysisPrescription, error) {
  197. prescription := models.XcxXtDialysisPrescription{}
  198. err := XTReadDB().Model(&prescription).Where("record_date = ? and patient_id = ? and status = 1", recordDate, patient_id).Find(&prescription).Error
  199. return prescription, err
  200. }
  201. func GetNextPatientSchedule(patient_id int64, dialysis_date int64) (models.BloodSchedule, error) {
  202. schedule := models.BloodSchedule{}
  203. //err := XTReadDB().Model(&schedule).Where("patient_id = ? and status = 1 and schedule_date>?", patient_id, dialysis_date).Order("schedule_date asc").First(&schedule).Error
  204. //return schedule, err
  205. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  206. table := XTReadDB().Table("xt_device_zone as z").Where("z.status =1")
  207. tables := XTReadDB().Table("xt_device_number as n").Where("n.status =1")
  208. fmt.Println(table, tables)
  209. if patient_id > 0 {
  210. db = db.Where("x.patient_id = ?", patient_id)
  211. }
  212. if dialysis_date > 0 {
  213. db = db.Where("x.schedule_date >?", dialysis_date)
  214. }
  215. err := db.Select("x.patient_id,x.schedule_type,x.schedule_date,x.mode_id,z.name,n.number").Joins("left join xt_device_zone as z on z.id = x.partition_id").Joins("left join xt_device_number as n on n.id = x.bed_id").Order("x.schedule_date asc").Limit(1).Scan(&schedule).Error
  216. return schedule, err
  217. }
  218. func GetXcxPatientInfo(patient_id int64) (models.XcxPatients, error) {
  219. patients := models.XcxPatients{}
  220. err := XTReadDB().Model(&patients).Where("id = ? and status = 1 ", patient_id).Find(&patients).Error
  221. return patients, err
  222. }
  223. func GetOrgInfo(id int64) (models.XcxSgjUserOrg, error) {
  224. org := models.XcxSgjUserOrg{}
  225. err := UserReadDB().Model(&org).Where("id = ? and status= 1", id).Find(&org).Error
  226. return org, err
  227. }
  228. func GetEducationList(startime int64, endtime int64, patient_id int64) (treatment []*models.XcxTreatmentSummary, err error) {
  229. err = XTReadDB().Model(&treatment).Where("assessment_date>=? and assessment_date<=? and patient_id = ? and status =1", startime, endtime, patient_id).Order("assessment_date desc").Find(&treatment).Error
  230. return treatment, err
  231. }
  232. func GetDoctorAdviceConfig(orgid int64) (models.XcxDoctorAdviceConfig, error) {
  233. config := models.XcxDoctorAdviceConfig{}
  234. err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  235. return config, err
  236. }
  237. func GetDoctorAdviceGroup(patient_id int64, startime int64, endtime int64) (advice []*models.XcxDoctorAdvice, err error) {
  238. err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Group("advice_date").Order("advice_date desc").Find(&advice).Error
  239. return advice, err
  240. }
  241. func GetHisDoctorAdviceGroup(patient_id int64, startime int64, endtime int64) (advice []*models.XcxHisDoctorAdviceInfo, err error) {
  242. err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Group("advice_date").Order("advice_date desc").Find(&advice).Error
  243. return advice, err
  244. }
  245. func GetDoctorAdvice(patient_id int64, startime int64, endtime int64) (advice []*models.XcxDoctorAdvice, err error) {
  246. err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Find(&advice).Error
  247. return advice, err
  248. }
  249. func GetHisDoctorAdvice(patient_id int64, startime int64, endtime int64) (advice []*models.XcxHisDoctorAdviceInfo, err error) {
  250. err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Find(&advice).Error
  251. return advice, err
  252. }
  253. // 用户排班信息
  254. func MobileGetSchedualDetailOne(orgID int64, patientID int64) (*MDialysisScheduleVM, error) {
  255. var vm MDialysisScheduleVM
  256. err := readDb.
  257. Table("xt_schedule").
  258. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  259. Where("status = 1 AND user_org_id = ? AND patient_id = ?", orgID, patientID).
  260. First(&vm).Error
  261. if err != nil {
  262. if err == gorm.ErrRecordNotFound {
  263. return nil, nil
  264. } else {
  265. return nil, err
  266. }
  267. }
  268. return &vm, err
  269. }
  270. // 接诊评估
  271. func MobileGetReceiverTreatmentAccessRecordOne(orgID int64, patientID int64, record_date int64) (*models.ReceiveTreatmentAsses, error) {
  272. var record models.ReceiveTreatmentAsses
  273. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, record_date).Find(&record).Error
  274. if err != nil {
  275. if err == gorm.ErrRecordNotFound {
  276. return nil, nil
  277. } else {
  278. return nil, err
  279. }
  280. }
  281. return &record, nil
  282. }
  283. // 透前评估
  284. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, assessment_date int64) (*models.PredialysisEvaluation, error) {
  285. var record models.PredialysisEvaluation
  286. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, assessment_date).Find(&record).Error
  287. if err != nil {
  288. if err == gorm.ErrRecordNotFound {
  289. return nil, nil
  290. } else {
  291. return nil, err
  292. }
  293. }
  294. return &record, nil
  295. }
  296. // 获取 maxDate 之前一次的透前评估记录
  297. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64) (*models.PredialysisEvaluation, error) {
  298. var record models.PredialysisEvaluation
  299. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Order("assessment_date desc").Last(&record).Error
  300. if err != nil {
  301. if err == gorm.ErrRecordNotFound {
  302. return nil, nil
  303. } else {
  304. return nil, err
  305. }
  306. }
  307. return &record, nil
  308. }
  309. func MobileGetDoctorAdvicesByGroupsOne(orgID int64, patientID int64, advicedate int64) ([]*models.DoctorAdvice, error) {
  310. var records []*models.DoctorAdvice
  311. err := readDb.
  312. Model(&models.DoctorAdvice{}).
  313. Where("patient_id = ? and user_org_id = ? and status = 1 and (advice_type = 2 || advice_type = 3) and advice_date = ?", patientID, orgID, advicedate).
  314. Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
  315. Order("start_time asc, groupno desc, advice_order desc, id asc").
  316. Scan(&records).Error
  317. if err != nil {
  318. return nil, err
  319. }
  320. return records, nil
  321. }
  322. // 透析记录
  323. func MobileGetSchedualDialysisRecordOne(orgID int64, patientID int64, dialysis_date int64) (*models.DialysisOrder, error) {
  324. var record models.DialysisOrder
  325. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1 ", orgID).Where("user_org_id = ? AND patient_id = ? and dialysis_date = ? ", orgID, patientID, dialysis_date).Find(&record).Error
  326. if err != nil {
  327. if err == gorm.ErrRecordNotFound {
  328. return nil, nil
  329. } else {
  330. return nil, err
  331. }
  332. }
  333. return &record, nil
  334. }
  335. // 双人核对
  336. func MobileGetDoubleCheckOne(orgID int64, patientID int64, check_date int64) (*models.DoubleCheck, error) {
  337. var record models.DoubleCheck
  338. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, check_date).Find(&record).Error
  339. if err != nil {
  340. if err == gorm.ErrRecordNotFound {
  341. return nil, nil
  342. } else {
  343. return nil, err
  344. }
  345. }
  346. return &record, nil
  347. }
  348. // 透析监测记录
  349. func MobileGetMonitorRecordsOne(orgID int64, patientID int64, monitoring_date int64) ([]*models.MonitoringRecord, error) {
  350. var records []*models.MonitoringRecord
  351. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, monitoring_date).Order("operate_time asc").Find(&records).Error
  352. if err != nil {
  353. return nil, err
  354. }
  355. return records, nil
  356. }
  357. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64) (*models.MonitoringRecord, error) {
  358. var record models.MonitoringRecord
  359. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Order("operate_time desc").Last(&record).Error
  360. if err != nil {
  361. if err == gorm.ErrRecordNotFound {
  362. return nil, nil
  363. } else {
  364. return nil, err
  365. }
  366. }
  367. return &record, nil
  368. }
  369. // 透后评估
  370. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, assessment_date int64) (*models.AssessmentAfterDislysis, error) {
  371. var record models.AssessmentAfterDislysis
  372. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date =? ", patientID, orgID, assessment_date).Find(&record).Error
  373. if err != nil {
  374. if err == gorm.ErrRecordNotFound {
  375. return nil, nil
  376. } else {
  377. return nil, err
  378. }
  379. }
  380. return &record, nil
  381. }
  382. // 治疗小结
  383. func MobileGetTreatmentSummaryOne(orgID int64, patientID int64, assessment_date int64) (*models.TreatmentSummary, error) {
  384. var record models.TreatmentSummary
  385. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date= ?", patientID, orgID, assessment_date).Find(&record).Error
  386. if err != nil {
  387. if err == gorm.ErrRecordNotFound {
  388. return nil, nil
  389. } else {
  390. return nil, err
  391. }
  392. }
  393. return &record, nil
  394. }
  395. // 透析处方
  396. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64, record_date int64) (*models.DialysisPrescription, error) {
  397. var record models.DialysisPrescription
  398. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and record_date = ?", patientID, orgID, mode_id, record_date).Find(&record).Error
  399. if err != nil {
  400. if err == gorm.ErrRecordNotFound {
  401. return nil, nil
  402. } else {
  403. return nil, err
  404. }
  405. }
  406. return &record, nil
  407. }
  408. func GetHisPrescriptionProjectsOne(user_org_id int64, patient_id int64) (projects []*models.HisPrescriptionProject, err error) {
  409. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND status = 1", user_org_id, patient_id).Find(&projects).Error
  410. return
  411. }
  412. func GetDialyStockOutOne(orgid int64, patientId int64) (prepare []*models.XtDialysisBeforePrepare, err error) {
  413. db := XTReadDB().Table("dialysis_before_prepare as x").Where("x.status = 1")
  414. if orgid > 0 {
  415. db = db.Where("x.user_org_id = ?", orgid)
  416. }
  417. if patientId > 0 {
  418. db = db.Where("x.patient_id = ?", patientId)
  419. }
  420. err = db.Select("x.id,x.user_org_id,x.patient_id,x.record_date,x.good_id,x.good_type_id,x.count,x.commdity_code,t.specification_name").Joins("left join xt_good_information as t on t.id = x.good_id and t.org_id = ? and t.status = 1", orgid).Scan(&prepare).Error
  421. return prepare, err
  422. }
  423. func MobileGetDialysisPrescribeByModeIdFive(orgID int64, patientID int64, record_date int64) (*models.DialysisPrescription, error) {
  424. var record models.DialysisPrescription
  425. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, record_date).Find(&record).Error
  426. if err != nil {
  427. if err == gorm.ErrRecordNotFound {
  428. return nil, nil
  429. } else {
  430. return nil, err
  431. }
  432. }
  433. return &record, nil
  434. }
  435. func GetAllHisDoctorAdviceOne(orgid int64, patientid int64, advice_date int64) (his []*models.HisDoctorAdviceInfo, err error) {
  436. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 and advice_date = ?", patientid, orgid, advice_date).Find(&his).Error
  437. return
  438. }
  439. func GetDoctorName(orgid int64) (role []*models.XcxSgjUserAdminRole, err error) {
  440. err = UserReadDB().Where("org_id = ? and status = 1", orgid).Find(&role).Error
  441. return role, err
  442. }
  443. func GetPrescripionFieldConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  444. err = XTReadDB().Model(&list).Where("org_id = ? and module = 1 ", orgid).Find(&list).Error
  445. return list, err
  446. }
  447. func GetReceiveTreatmentAssess(orgid int64) (list []*models.XcxFiledConfig, err error) {
  448. err = XTReadDB().Model(&list).Where("org_id = ? and module = 2 ", orgid).Find(&list).Error
  449. return list, err
  450. }
  451. func GetDialysisBefor(orgid int64) (list []*models.XcxFiledConfig, err error) {
  452. err = XTReadDB().Model(&list).Where("org_id = ? and module = 3", orgid).Find(&list).Error
  453. return list, err
  454. }
  455. func GetDialysisOrderConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  456. err = XTReadDB().Model(&list).Where("org_id = ? and module = 7"+
  457. "", orgid).Find(&list).Error
  458. return list, err
  459. }
  460. func GetMonitorRecordConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  461. err = XTReadDB().Model(&list).Where("org_id = ? and module = 4", orgid).Find(&list).Error
  462. return list, err
  463. }
  464. func GetDialysisAfeterConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  465. err = XTReadDB().Model(&list).Where("org_id = ? and module = 5", orgid).Find(&list).Error
  466. return list, err
  467. }
  468. func GetTreatMentConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  469. err = XTReadDB().Model(&list).Where("org_id = ? and module = 6", orgid).Find(&list).Error
  470. return list, err
  471. }
  472. func GetDataConfig(orgid int64) (list []*models.XcxDataConfig, err error) {
  473. err = XTReadDB().Model(&list).Where("(org_id = ? or org_id = 0) and status = 1", orgid).Find(&list).Error
  474. return list, err
  475. }
  476. func GetLastScheduleListOne(patient_id int64, schedule_date int64) (models.XcxSchedule, error) {
  477. schedule := models.XcxSchedule{}
  478. err := XTReadDB().Model(&schedule).Where("patient_id = ? and status = 1 and schedule_date <=?", patient_id, schedule_date).Last(&schedule).Error
  479. return schedule, err
  480. }