xcx_mobile_api_service.go 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. "net/http"
  13. )
  14. func GetXcxMobileInformation(mobile string) (*models.XcxAdminUserRole, error) {
  15. role := models.XcxAdminUserRole{}
  16. err := UserReadDB().Model(&role).Where("mobile = ? and status = 1", mobile).Find(&role).Error
  17. if err == gorm.ErrRecordNotFound {
  18. return nil, err
  19. }
  20. if err != nil {
  21. return nil, err
  22. }
  23. return &role, nil
  24. }
  25. func CreateXcxAdminUser(role models.XcxAdminUserRole) error {
  26. err := UserReadDB().Create(&role).Error
  27. return err
  28. }
  29. func GetLoginInfor(mobile string) (models.XcxAdminUserRole, error) {
  30. role := models.XcxAdminUserRole{}
  31. err := UserReadDB().Model(&role).Where("mobile = ? and status = 1", mobile).Find(&role).Error
  32. return role, err
  33. }
  34. func GetMobilePatientInfo(mobile string) (models.XcxPatients, error) {
  35. patients := models.XcxPatients{}
  36. err := XTReadDB().Model(&patients).Where("(phone = ? or home_telephone = ? ) and status = 1", mobile, mobile).Find(&patients).Error
  37. return patients, err
  38. }
  39. func GetPatientListByPatientId(id int64) (models.XcxPatients, error) {
  40. patients := models.XcxPatients{}
  41. err := XTReadDB().Model(&patients).Where("id = ? and status = 1", id).Find(&patients).Error
  42. return patients, err
  43. }
  44. func DecryptData(app_id, session_key, iv, encrypted_data string) (map[string]interface{}, error) {
  45. aesKey, err := base64.StdEncoding.DecodeString(session_key)
  46. if err != nil {
  47. return nil, err
  48. }
  49. ivKey, err := base64.StdEncoding.DecodeString(iv)
  50. if err != nil {
  51. return nil, err
  52. }
  53. decodeData, err := base64.StdEncoding.DecodeString(encrypted_data)
  54. if err != nil {
  55. return nil, err
  56. }
  57. dataBytes, err := AesDecrypt(decodeData, aesKey, ivKey)
  58. if err != nil {
  59. return nil, err
  60. }
  61. var result map[string]interface{}
  62. err = json.Unmarshal(dataBytes, &result)
  63. watermark := result["watermark"].(map[string]interface{})
  64. if watermark["appid"] != app_id {
  65. return nil, errors.New("Invalid appid data!")
  66. }
  67. return result, err
  68. }
  69. func AesDecrypt(crypted, key, iv []byte) ([]byte, error) {
  70. block, err := aes.NewCipher(key)
  71. fmt.Println("w2222", err)
  72. if err != nil {
  73. return nil, err
  74. }
  75. blockMode := cipher.NewCBCDecrypter(block, iv)
  76. origData := make([]byte, len(crypted))
  77. blockMode.CryptBlocks(origData, crypted)
  78. // 去除填充
  79. length := len(origData)
  80. unp := int(origData[length-1])
  81. return origData[:(length - unp)], nil
  82. }
  83. func GetFirstDateOfWeek() (weekMonday string) {
  84. now := time.Now()
  85. offset := int(time.Monday - now.Weekday())
  86. if offset > 0 {
  87. offset = -6
  88. }
  89. weekStartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
  90. weekMonday = weekStartDate.Format("2006-01-02")
  91. return
  92. }
  93. func GetWeekDayOfWeek() (weekMonday string) {
  94. now := time.Now()
  95. offset := int(time.Monday - now.Weekday())
  96. if offset > 0 {
  97. offset = -6
  98. }
  99. weekStartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
  100. weekMonday = weekStartDate.Format("2006-01-02")
  101. return
  102. }
  103. func GetMobilePatient(mobile string, idcard string) (*models.XcxPatients, error) {
  104. patient := models.XcxPatients{}
  105. err := XTReadDB().Model(&patient).Where("(phone = ? or relative_phone =?) and id_card_no =?", mobile, mobile, idcard).Find(&patient).Error
  106. //err := XTReadDB().Model(&patient).Where("id_card_no = ? and status = 1", mobile).Find(&patient).Error
  107. if err == gorm.ErrRecordNotFound {
  108. return nil, err
  109. }
  110. if err != nil {
  111. return nil, err
  112. }
  113. return &patient, nil
  114. }
  115. func GetTemplateMode(orgid int64) (models.XcxGobalTemplate, error) {
  116. template := models.XcxGobalTemplate{}
  117. err := XTReadDB().Model(&template).Where("org_id = ? and status = 1", orgid).Find(&template).Error
  118. return template, err
  119. }
  120. func GetMobilePatientOne(mobile string) (*models.XcxAdminUserRole, error) {
  121. patient := models.XcxAdminUserRole{}
  122. err := XTReadDB().Model(&patient).Where("mobile = ? and status = 1", mobile).Find(&patient).Error
  123. if err == gorm.ErrRecordNotFound {
  124. return nil, err
  125. }
  126. if err != nil {
  127. return nil, err
  128. }
  129. return &patient, nil
  130. }
  131. func Dncrypt(rawData, key, iv string) (string, error) {
  132. data, err := base64.StdEncoding.DecodeString(rawData)
  133. key_b, err_1 := base64.StdEncoding.DecodeString(key)
  134. iv_b, _ := base64.StdEncoding.DecodeString(iv)
  135. if err != nil {
  136. return "", err
  137. }
  138. if err_1 != nil {
  139. return "", err_1
  140. }
  141. dnData, err := AesCBCDncrypt(data, key_b, iv_b)
  142. if err != nil {
  143. return "", err
  144. }
  145. return string(dnData), nil
  146. }
  147. // 解密
  148. func AesCBCDncrypt(encryptData, key, iv []byte) ([]byte, error) {
  149. block, err := aes.NewCipher(key)
  150. if err != nil {
  151. panic(err)
  152. }
  153. blockSize := block.BlockSize()
  154. if len(encryptData) < blockSize {
  155. panic("ciphertext too short")
  156. }
  157. if len(encryptData)%blockSize != 0 {
  158. panic("ciphertext is not a multiple of the block size")
  159. }
  160. mode := cipher.NewCBCDecrypter(block, iv)
  161. mode.CryptBlocks(encryptData, encryptData)
  162. // 解填充
  163. encryptData = PKCS7UnPadding(encryptData)
  164. return encryptData, nil
  165. }
  166. //去除填充
  167. func PKCS7UnPadding(origData []byte) []byte {
  168. length := len(origData)
  169. unpadding := int(origData[length-1])
  170. if length-unpadding < 0 {
  171. return origData[:0]
  172. }
  173. fmt.Println("changdu", length)
  174. fmt.Println("data", unpadding)
  175. return origData[:(length - unpadding)]
  176. }
  177. func GetScheduleInfo(startime int64, endtime int64, patient_id int64) (schedule []*models.VmBloodSchedule, err error) {
  178. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  179. table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
  180. fmt.Println(table)
  181. if startime > 0 {
  182. db = db.Where("x.schedule_date >=?", startime)
  183. }
  184. if endtime > 0 {
  185. db = db.Where("x.schedule_date <=?", endtime)
  186. }
  187. if patient_id > 0 {
  188. db = db.Where("x.patient_id = ?", patient_id)
  189. }
  190. 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
  191. return schedule, err
  192. }
  193. func GetTodayDialysis(recordDate int64, patient_id int64) (models.XcXDialysisOrder, error) {
  194. order := models.XcXDialysisOrder{}
  195. err := XTReadDB().Model(&order).Where("dialysis_date = ? and patient_id = ? and status = 1", recordDate, patient_id).Find(&order).Error
  196. return order, err
  197. }
  198. func GetTodayPrescription(recordDate int64, patient_id int64) (models.XcxXtDialysisPrescription, error) {
  199. prescription := models.XcxXtDialysisPrescription{}
  200. err := XTReadDB().Model(&prescription).Where("record_date = ? and patient_id = ? and status = 1", recordDate, patient_id).Find(&prescription).Error
  201. return prescription, err
  202. }
  203. func GetNextPatientSchedule(patient_id int64, dialysis_date int64) (models.BloodSchedule, error) {
  204. schedule := models.BloodSchedule{}
  205. //err := XTReadDB().Model(&schedule).Where("patient_id = ? and status = 1 and schedule_date>?", patient_id, dialysis_date).Order("schedule_date asc").First(&schedule).Error
  206. //return schedule, err
  207. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  208. table := XTReadDB().Table("xt_device_zone as z").Where("z.status =1")
  209. tables := XTReadDB().Table("xt_device_number as n").Where("n.status =1")
  210. fmt.Println(table, tables)
  211. if patient_id > 0 {
  212. db = db.Where("x.patient_id = ?", patient_id)
  213. }
  214. if dialysis_date > 0 {
  215. db = db.Where("x.schedule_date >?", dialysis_date)
  216. }
  217. 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
  218. return schedule, err
  219. }
  220. func GetXcxPatientInfo(patient_id int64) (models.XcxPatients, error) {
  221. patients := models.XcxPatients{}
  222. err := XTReadDB().Model(&patients).Where("id = ? and status = 1 ", patient_id).Find(&patients).Error
  223. return patients, err
  224. }
  225. func GetOrgInfo(id int64) (models.XcxSgjUserOrg, error) {
  226. org := models.XcxSgjUserOrg{}
  227. err := UserReadDB().Model(&org).Where("id = ? and status= 1", id).Find(&org).Error
  228. return org, err
  229. }
  230. func GetEducationList(startime int64, endtime int64, patient_id int64) (treatment []*models.XcxTreatmentSummary, err error) {
  231. 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
  232. return treatment, err
  233. }
  234. func GetDoctorAdviceConfig(orgid int64) (models.XcxDoctorAdviceConfig, error) {
  235. config := models.XcxDoctorAdviceConfig{}
  236. err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
  237. return config, err
  238. }
  239. func GetDoctorAdviceGroup(patient_id int64, startime int64, endtime int64) (advice []*models.XcxDoctorAdvice, err error) {
  240. 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
  241. return advice, err
  242. }
  243. func GetHisDoctorAdviceGroup(patient_id int64, startime int64, endtime int64) (advice []*models.XcxHisDoctorAdviceInfo, err error) {
  244. 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
  245. return advice, err
  246. }
  247. func GetDoctorAdvice(patient_id int64, startime int64, endtime int64) (advice []*models.XcxDoctorAdvice, err error) {
  248. err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Find(&advice).Error
  249. return advice, err
  250. }
  251. func GetHisDoctorAdvice(patient_id int64, startime int64, endtime int64) (advice []*models.XcxHisDoctorAdviceInfo, err error) {
  252. err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Find(&advice).Error
  253. return advice, err
  254. }
  255. // 用户排班信息
  256. func MobileGetSchedualDetailOne(orgID int64, patientID int64) (*MDialysisScheduleVM, error) {
  257. var vm MDialysisScheduleVM
  258. err := readDb.
  259. Table("xt_schedule").
  260. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  261. Where("status = 1 AND user_org_id = ? AND patient_id = ?", orgID, patientID).
  262. First(&vm).Error
  263. if err != nil {
  264. if err == gorm.ErrRecordNotFound {
  265. return nil, nil
  266. } else {
  267. return nil, err
  268. }
  269. }
  270. return &vm, err
  271. }
  272. // 接诊评估
  273. func MobileGetReceiverTreatmentAccessRecordOne(orgID int64, patientID int64, record_date int64) (*models.ReceiveTreatmentAsses, error) {
  274. var record models.ReceiveTreatmentAsses
  275. 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
  276. if err != nil {
  277. if err == gorm.ErrRecordNotFound {
  278. return nil, nil
  279. } else {
  280. return nil, err
  281. }
  282. }
  283. return &record, nil
  284. }
  285. // 透前评估
  286. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, assessment_date int64) (*models.PredialysisEvaluation, error) {
  287. var record models.PredialysisEvaluation
  288. 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
  289. if err != nil {
  290. if err == gorm.ErrRecordNotFound {
  291. return nil, nil
  292. } else {
  293. return nil, err
  294. }
  295. }
  296. return &record, nil
  297. }
  298. // 获取 maxDate 之前一次的透前评估记录
  299. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64) (*models.PredialysisEvaluation, error) {
  300. var record models.PredialysisEvaluation
  301. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Order("assessment_date desc").Last(&record).Error
  302. if err != nil {
  303. if err == gorm.ErrRecordNotFound {
  304. return nil, nil
  305. } else {
  306. return nil, err
  307. }
  308. }
  309. return &record, nil
  310. }
  311. func MobileGetDoctorAdvicesByGroupsOne(orgID int64, patientID int64, advicedate int64) ([]*models.DoctorAdvice, error) {
  312. var records []*models.DoctorAdvice
  313. err := readDb.
  314. Model(&models.DoctorAdvice{}).
  315. Where("patient_id = ? and user_org_id = ? and status = 1 and (advice_type = 2 || advice_type = 3) and advice_date = ?", patientID, orgID, advicedate).
  316. 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").
  317. Order("start_time asc, groupno desc, advice_order desc, id asc").
  318. Scan(&records).Error
  319. if err != nil {
  320. return nil, err
  321. }
  322. return records, nil
  323. }
  324. // 透析记录
  325. func MobileGetSchedualDialysisRecordOne(orgID int64, patientID int64, dialysis_date int64) (*models.DialysisOrder, error) {
  326. var record models.DialysisOrder
  327. 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
  328. if err != nil {
  329. if err == gorm.ErrRecordNotFound {
  330. return nil, nil
  331. } else {
  332. return nil, err
  333. }
  334. }
  335. return &record, nil
  336. }
  337. // 双人核对
  338. func MobileGetDoubleCheckOne(orgID int64, patientID int64, check_date int64) (*models.DoubleCheck, error) {
  339. var record models.DoubleCheck
  340. 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
  341. if err != nil {
  342. if err == gorm.ErrRecordNotFound {
  343. return nil, nil
  344. } else {
  345. return nil, err
  346. }
  347. }
  348. return &record, nil
  349. }
  350. // 透析监测记录
  351. func MobileGetMonitorRecordsOne(orgID int64, patientID int64, monitoring_date int64) ([]*models.MonitoringRecord, error) {
  352. var records []*models.MonitoringRecord
  353. 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
  354. if err != nil {
  355. return nil, err
  356. }
  357. return records, nil
  358. }
  359. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64) (*models.MonitoringRecord, error) {
  360. var record models.MonitoringRecord
  361. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Order("operate_time desc").Last(&record).Error
  362. if err != nil {
  363. if err == gorm.ErrRecordNotFound {
  364. return nil, nil
  365. } else {
  366. return nil, err
  367. }
  368. }
  369. return &record, nil
  370. }
  371. // 透后评估
  372. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, assessment_date int64) (*models.AssessmentAfterDislysis, error) {
  373. var record models.AssessmentAfterDislysis
  374. 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
  375. if err != nil {
  376. if err == gorm.ErrRecordNotFound {
  377. return nil, nil
  378. } else {
  379. return nil, err
  380. }
  381. }
  382. return &record, nil
  383. }
  384. // 治疗小结
  385. func MobileGetTreatmentSummaryOne(orgID int64, patientID int64, assessment_date int64) (*models.TreatmentSummary, error) {
  386. var record models.TreatmentSummary
  387. 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
  388. if err != nil {
  389. if err == gorm.ErrRecordNotFound {
  390. return nil, nil
  391. } else {
  392. return nil, err
  393. }
  394. }
  395. return &record, nil
  396. }
  397. // 透析处方
  398. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64, record_date int64) (*models.DialysisPrescription, error) {
  399. var record models.DialysisPrescription
  400. 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
  401. if err != nil {
  402. if err == gorm.ErrRecordNotFound {
  403. return nil, nil
  404. } else {
  405. return nil, err
  406. }
  407. }
  408. return &record, nil
  409. }
  410. func GetHisPrescriptionProjectsOne(user_org_id int64, patient_id int64) (projects []*models.HisPrescriptionProject, err error) {
  411. 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
  412. return
  413. }
  414. func GetDialyStockOutOne(orgid int64, patientId int64) (prepare []*models.XtDialysisBeforePrepare, err error) {
  415. db := XTReadDB().Table("dialysis_before_prepare as x").Where("x.status = 1")
  416. if orgid > 0 {
  417. db = db.Where("x.user_org_id = ?", orgid)
  418. }
  419. if patientId > 0 {
  420. db = db.Where("x.patient_id = ?", patientId)
  421. }
  422. 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
  423. return prepare, err
  424. }
  425. func MobileGetDialysisPrescribeByModeIdFive(orgID int64, patientID int64, record_date int64) (*models.DialysisPrescription, error) {
  426. var record models.DialysisPrescription
  427. 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
  428. if err != nil {
  429. if err == gorm.ErrRecordNotFound {
  430. return nil, nil
  431. } else {
  432. return nil, err
  433. }
  434. }
  435. return &record, nil
  436. }
  437. func GetAllHisDoctorAdviceOne(orgid int64, patientid int64, advice_date int64) (his []*models.HisDoctorAdviceInfo, err error) {
  438. 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
  439. return
  440. }
  441. func GetDoctorName(orgid int64) (role []*models.XcxSgjUserAdminRole, err error) {
  442. err = UserReadDB().Where("org_id = ? and status = 1", orgid).Find(&role).Error
  443. return role, err
  444. }
  445. func GetPrescripionFieldConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  446. err = XTReadDB().Model(&list).Where("org_id = ? and module = 1 ", orgid).Find(&list).Error
  447. return list, err
  448. }
  449. func GetReceiveTreatmentAssess(orgid int64) (list []*models.XcxFiledConfig, err error) {
  450. err = XTReadDB().Model(&list).Where("org_id = ? and module = 2 ", orgid).Find(&list).Error
  451. return list, err
  452. }
  453. func GetDialysisBefor(orgid int64) (list []*models.XcxFiledConfig, err error) {
  454. err = XTReadDB().Model(&list).Where("org_id = ? and module = 3", orgid).Find(&list).Error
  455. return list, err
  456. }
  457. func GetDialysisOrderConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  458. err = XTReadDB().Model(&list).Where("org_id = ? and module = 7"+
  459. "", orgid).Find(&list).Error
  460. return list, err
  461. }
  462. func GetMonitorRecordConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  463. err = XTReadDB().Model(&list).Where("org_id = ? and module = 4", orgid).Find(&list).Error
  464. return list, err
  465. }
  466. func GetDialysisAfeterConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  467. err = XTReadDB().Model(&list).Where("org_id = ? and module = 5", orgid).Find(&list).Error
  468. return list, err
  469. }
  470. func GetTreatMentConfig(orgid int64) (list []*models.XcxFiledConfig, err error) {
  471. err = XTReadDB().Model(&list).Where("org_id = ? and module = 6", orgid).Find(&list).Error
  472. return list, err
  473. }
  474. func GetDataConfig(orgid int64) (list []*models.XcxDataConfig, err error) {
  475. err = XTReadDB().Model(&list).Where("(org_id = ? or org_id = 0) and status = 1", orgid).Find(&list).Error
  476. return list, err
  477. }
  478. func GetLastScheduleListOne(patient_id int64, schedule_date int64) (models.XcxSchedule, error) {
  479. schedule := models.XcxSchedule{}
  480. err := XTReadDB().Model(&schedule).Where("patient_id = ? and status = 1 and schedule_date <=?", patient_id, schedule_date).Order("schedule_date desc").Last(&schedule).Error
  481. return schedule, err
  482. }
  483. func GetInspectionGroupList(patientid int64, startime int64, endtime int64) (inspection []*models.XcxInspection, err error) {
  484. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  485. if patientid > 0 {
  486. db = db.Where("x.patient_id = ?", patientid)
  487. }
  488. if startime > 0 {
  489. db = db.Where("x.inspect_date >= ?", startime)
  490. }
  491. if endtime > 0 {
  492. db = db.Where("x.inspect_date <= ?", endtime)
  493. }
  494. err = db.Group("x.inspect_date,x.project_id").Find(&inspection).Error
  495. return inspection, err
  496. }
  497. func GetInsepctionList(patientid int64, startime int64, endtime int64) (inspection []*models.XcxInspection, err error) {
  498. db := XTReadDB().Table("xt_inspection as x").Where("x.status =1")
  499. table := XTReadDB().Table("xt_inspection_reference as r")
  500. fmt.Print("table", table)
  501. if patientid > 0 {
  502. db = db.Where("x.patient_id = ?", patientid)
  503. }
  504. if startime > 0 {
  505. db = db.Where("x.inspect_date >= ?", startime)
  506. }
  507. if endtime > 0 {
  508. db = db.Where("x.inspect_date <= ?", endtime)
  509. }
  510. err = db.Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0) ").Scan(&inspection).Error
  511. return inspection, err
  512. }
  513. func GetArticList(activityID int64, page int64, limit int64) (story []*models.SybStory, total int64, err error) {
  514. offset := (page - 1) * limit
  515. err = UserReadDB().Model(&story).Where("activity_id = ? and audit_status = 2", activityID).Count(&total).Order("ctime desc").Offset(offset).Limit(limit).Find(&story).Error
  516. return story, total, err
  517. }
  518. func GetArticListDetail(id int64) (models.SybStory, error) {
  519. story := models.SybStory{}
  520. err := UserReadDB().Where("id = ?", id).Find(&story).Error
  521. return story, err
  522. }
  523. func GetStoryScoreList(activityID int64, page int64, limit int64) (score []*models.SybStoryScore, total int64, err error) {
  524. offset := (page - 1) * limit
  525. err = UserReadDB().Model(&score).Where("activity_id = ?", activityID).Count(&total).Offset(offset).Limit(limit).Preload("SybStory").Find(&score).Error
  526. return score, total, err
  527. }
  528. func SendWxAuthAPI(appID string, appSecret string, grant_type string, code string) (map[string]string, error) {
  529. var code2sessionURL = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appID + "&secret=" + appSecret + "&js_code=" + code + "&grant_type=" + grant_type
  530. var url = fmt.Sprintf(code2sessionURL, appID, appSecret, code)
  531. fmt.Println("url233232323322323", url)
  532. resp, err := http.DefaultClient.Get(code2sessionURL)
  533. fmt.Println("resp32332232332322", resp)
  534. var wxMap map[string]string
  535. err = json.NewDecoder(resp.Body).Decode(&wxMap)
  536. if err != nil {
  537. return wxMap, err
  538. }
  539. defer resp.Body.Close()
  540. return wxMap, err
  541. }
  542. func SendWxAuthAPIOne(appID string, appSecret string, grant_type string, code string) (string, error) {
  543. var code2sessionURL = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appID + "&secret=" + appSecret + "&js_code=" + code + "&grant_type=" + grant_type
  544. var url = fmt.Sprintf(code2sessionURL, appID, appSecret, code)
  545. fmt.Println(url)
  546. resp, err := http.DefaultClient.Get(code2sessionURL)
  547. if err != nil {
  548. return "", err
  549. }
  550. var wxMap map[string]string
  551. err = json.NewDecoder(resp.Body).Decode(&wxMap)
  552. if err != nil {
  553. return "", err
  554. }
  555. defer resp.Body.Close()
  556. fmt.Println("2333232232", wxMap)
  557. return wxMap["session_key"], nil
  558. }