doctor_advice_service.go 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. package service
  2. import (
  3. "Xcx_New/models"
  4. "strings"
  5. "time"
  6. "github.com/jinzhu/gorm"
  7. )
  8. func GetPublicDrugDics() (drugs []*models.DrugDic, total int64, err error) {
  9. err = readDb.Model(&models.DrugDic{}).Where("org_id = 0 and status=1").Count(&total).Order("id desc").Find(&drugs).Error
  10. return
  11. }
  12. func GetPublicDrugWayDics() (drugways []*models.DrugwayDic, total int64, err error) {
  13. err = readDb.Model(&models.DrugwayDic{}).Where("org_id = 0 and status=1").Count(&total).Order("id desc").Find(&drugways).Error
  14. return
  15. }
  16. func GetPublicExecutionFrequencyDics() (dics []*models.ExecutionFrequencyDic, total int64, err error) {
  17. err = readDb.Model(&models.ExecutionFrequencyDic{}).Where("org_id = 0 and status=1").Count(&total).Order("id desc").Find(&dics).Error
  18. return
  19. }
  20. func GetDrugDics(orgid int64) (drugs []*models.DrugDic, total int64, err error) {
  21. err = readDb.Model(&models.DrugDic{}).Where("org_id =? and status=1", orgid).Count(&total).Order("id desc").Find(&drugs).Error
  22. return
  23. }
  24. func GetAdviceTemplates(orgid int64) (templates []*models.DoctorAdviceTemplate, total int64, err error) {
  25. err = readDb.Model(&models.DoctorAdviceTemplate{}).Where("org_id =? and status=1", orgid).Count(&total).Order("id desc").Find(&templates).Error
  26. return
  27. }
  28. func GetDrugWayDics(orgid int64) (drugways []*models.DrugwayDic, total int64, err error) {
  29. err = readDb.Model(&models.DrugwayDic{}).Where("(org_id =? or org_id = 0) and status=1", orgid).Count(&total).Order("id desc").Find(&drugways).Error
  30. return
  31. }
  32. func GetExecutionFrequencyDics(orgid int64) (dics []*models.ExecutionFrequencyDic, total int64, err error) {
  33. err = readDb.Model(&models.ExecutionFrequencyDic{}).Where("(org_id =? or org_id = 0) and status=1", orgid).Count(&total).Order("id desc").Find(&dics).Error
  34. return
  35. }
  36. func CreateDrugDic(d *models.DrugDic) (err error) {
  37. err = readDb.Create(&d).Error
  38. return
  39. }
  40. func UpdateDrugDic(d *models.DrugDic) (err error) {
  41. err = readDb.Save(&d).Error
  42. return
  43. }
  44. func FindDrugDic(orgid, id int64) (*models.DrugDic, error) {
  45. var drugdic models.DrugDic
  46. err := readDb.Model(&models.DrugDic{}).Where("id=? and org_id =? and status=1", id, orgid).First(&drugdic).Error
  47. if err == gorm.ErrRecordNotFound {
  48. return nil, nil
  49. }
  50. if err != nil {
  51. return nil, err
  52. }
  53. return &drugdic, nil
  54. }
  55. func CreateDrugWay(d *models.DrugwayDic) (err error) {
  56. err = readDb.Create(&d).Error
  57. return
  58. }
  59. func FindDrugWay(orgid, id int64) (*models.DrugwayDic, error) {
  60. var drugway models.DrugwayDic
  61. err := readDb.Model(&models.DrugwayDic{}).Where("id=? and org_id =? and status=1", id, orgid).First(&drugway).Error
  62. if err == gorm.ErrRecordNotFound {
  63. return nil, nil
  64. }
  65. if err != nil {
  66. return nil, err
  67. }
  68. return &drugway, nil
  69. }
  70. func UpdateDrugWay(d *models.DrugwayDic) (err error) {
  71. err = readDb.Save(&d).Error
  72. return
  73. }
  74. func CreateExecutionFrequency(d *models.ExecutionFrequencyDic) (err error) {
  75. err = readDb.Create(&d).Error
  76. return
  77. }
  78. func FindExecutionFrequency(orgid, id int64) (*models.ExecutionFrequencyDic, error) {
  79. var ef models.ExecutionFrequencyDic
  80. err := readDb.Model(&models.ExecutionFrequencyDic{}).Where("id=? and org_id =? and status=1", id, orgid).First(&ef).Error
  81. if err == gorm.ErrRecordNotFound {
  82. return nil, nil
  83. }
  84. if err != nil {
  85. return nil, err
  86. }
  87. return &ef, nil
  88. }
  89. func UpdateExecutionFrequency(d *models.ExecutionFrequencyDic) (err error) {
  90. err = readDb.Save(&d).Error
  91. return
  92. }
  93. func CreateAdviceTemplate(d *models.DoctorAdviceTemplate) (err error) {
  94. err = readDb.Create(&d).Error
  95. return
  96. }
  97. func CreateHisAdviceTemplate(d *models.HisDoctorAdviceTemplate) (err error) {
  98. err = readDb.Create(&d).Error
  99. return
  100. }
  101. func FindAdviceTemplate(orgid, id int64) (*models.DoctorAdviceTemplate, error) {
  102. var template models.DoctorAdviceTemplate
  103. err := readDb.Model(&models.DoctorAdviceTemplate{}).Where("id=? and org_id =? and status=1", id, orgid).First(&template).Error
  104. if err == gorm.ErrRecordNotFound {
  105. return nil, nil
  106. }
  107. if err != nil {
  108. return nil, err
  109. }
  110. return &template, nil
  111. }
  112. func FindHisAdviceTemplate(orgid, id int64) (*models.HisDoctorAdviceTemplate, error) {
  113. var template models.HisDoctorAdviceTemplate
  114. err := readDb.Model(&models.HisDoctorAdviceTemplate{}).Where("id=? and org_id =? and status=1", id, orgid).First(&template).Error
  115. if err == gorm.ErrRecordNotFound {
  116. return nil, nil
  117. }
  118. if err != nil {
  119. return nil, err
  120. }
  121. return &template, nil
  122. }
  123. func UpdateAdviceTemplate(d *models.DoctorAdviceTemplate) (err error) {
  124. err = writeDb.Save(&d).Error
  125. return
  126. }
  127. func UpdateHisAdviceTemplate(d *models.HisDoctorAdviceTemplate) (err error) {
  128. err = writeDb.Save(&d).Error
  129. return
  130. }
  131. func UpdateAdviceAndSubAdviceTemplate(d *models.DoctorAdviceTemplate) (err error) {
  132. err = writeDb.Save(&d).Error
  133. err = writeDb.Model(&models.DoctorAdviceTemplate{}).Where("status=1 AND parent_id = ?", d.ID).Updates(map[string]interface{}{"status": 2, "updated_time": time.Now().Unix()}).Error
  134. return
  135. }
  136. func UpdateHisAdviceAndSubAdviceTemplate(d *models.HisDoctorAdviceTemplate) (err error) {
  137. err = writeDb.Save(&d).Error
  138. err = writeDb.Model(&models.HisDoctorAdviceTemplate{}).Where("status=1 AND parent_id = ?", d.ID).Updates(map[string]interface{}{"status": 2, "updated_time": time.Now().Unix()}).Error
  139. return
  140. }
  141. func CreateTemplate(template *models.DoctorAdviceParentTemplate) (err error) {
  142. err = readDb.Create(&template).Error
  143. return
  144. }
  145. func CreateHisDoctorAdviceTemplate(template *models.HisDoctorAdviceParentTemplate) (err error) {
  146. err = readDb.Create(&template).Error
  147. return
  148. }
  149. func CreateHisSubDoctorAdviceTemplate(template []*models.HisDoctorAdviceTemplate) (err error) {
  150. if len(template) > 0 {
  151. utx := writeDb.Begin()
  152. if len(template) > 0 {
  153. thisSQL := "INSERT INTO his_doctor_advice_template (org_id, advice_name, advice_desc, single_dose, single_dose_unit,prescribing_number," +
  154. "prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,drug_id,way) VALUES "
  155. insertParams := make([]string, 0)
  156. insertData := make([]interface{}, 0)
  157. for _, info := range template {
  158. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  159. insertData = append(insertData, info.OrgId)
  160. insertData = append(insertData, info.AdviceName)
  161. insertData = append(insertData, info.AdviceDesc)
  162. insertData = append(insertData, info.SingleDose)
  163. insertData = append(insertData, info.SingleDoseUnit)
  164. insertData = append(insertData, info.PrescribingNumber)
  165. insertData = append(insertData, info.PrescribingNumberUnit)
  166. insertData = append(insertData, info.DeliveryWay)
  167. insertData = append(insertData, info.ExecutionFrequency)
  168. insertData = append(insertData, info.AdviceDoctor)
  169. insertData = append(insertData, info.Status)
  170. insertData = append(insertData, info.CreatedTime)
  171. insertData = append(insertData, info.UpdatedTime)
  172. insertData = append(insertData, info.TemplateId)
  173. insertData = append(insertData, info.DrugSpec)
  174. insertData = append(insertData, info.DrugSpecUnit)
  175. insertData = append(insertData, info.AdviceType)
  176. insertData = append(insertData, info.DayCount)
  177. insertData = append(insertData, info.WeekDays)
  178. insertData = append(insertData, info.FrequencyType)
  179. insertData = append(insertData, info.DrugId)
  180. insertData = append(insertData, info.Way)
  181. }
  182. thisSQL += strings.Join(insertParams, ", ")
  183. err = utx.Exec(thisSQL, insertData...).Error
  184. if err != nil {
  185. utx.Rollback()
  186. return
  187. }
  188. }
  189. utx.Commit()
  190. }
  191. return
  192. }
  193. //func CreateBatchRecord(template []*models.DoctorAdviceTemplate) (err error) {
  194. // err = writeDb.Create(template).Error
  195. // return
  196. //}
  197. func CreateSubTemplate(template []*models.DoctorAdviceTemplate) (err error) {
  198. if len(template) > 0 {
  199. utx := writeDb.Begin()
  200. if len(template) > 0 {
  201. thisSQL := "INSERT INTO xt_doctor_advice_template (org_id, advice_name, advice_desc, single_dose, single_dose_unit,prescribing_number," +
  202. "prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,drug_id,way) VALUES "
  203. insertParams := make([]string, 0)
  204. insertData := make([]interface{}, 0)
  205. for _, info := range template {
  206. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  207. insertData = append(insertData, info.OrgId)
  208. insertData = append(insertData, info.AdviceName)
  209. insertData = append(insertData, info.AdviceDesc)
  210. insertData = append(insertData, info.SingleDose)
  211. insertData = append(insertData, info.SingleDoseUnit)
  212. insertData = append(insertData, info.PrescribingNumber)
  213. insertData = append(insertData, info.PrescribingNumberUnit)
  214. insertData = append(insertData, info.DeliveryWay)
  215. insertData = append(insertData, info.ExecutionFrequency)
  216. insertData = append(insertData, info.AdviceDoctor)
  217. insertData = append(insertData, info.Status)
  218. insertData = append(insertData, info.CreatedTime)
  219. insertData = append(insertData, info.UpdatedTime)
  220. insertData = append(insertData, info.TemplateId)
  221. insertData = append(insertData, info.DrugSpec)
  222. insertData = append(insertData, info.DrugSpecUnit)
  223. insertData = append(insertData, info.AdviceType)
  224. insertData = append(insertData, info.DayCount)
  225. insertData = append(insertData, info.WeekDays)
  226. insertData = append(insertData, info.FrequencyType)
  227. insertData = append(insertData, info.DrugId)
  228. insertData = append(insertData, info.Way)
  229. }
  230. thisSQL += strings.Join(insertParams, ", ")
  231. err = utx.Exec(thisSQL, insertData...).Error
  232. if err != nil {
  233. utx.Rollback()
  234. return
  235. }
  236. }
  237. utx.Commit()
  238. }
  239. return
  240. }
  241. func FindDoctorAdviceTemplateById(id int64, org_id int64) (temps models.DoctorAdviceParentTemplate, err error) {
  242. err = readDb.Model(&models.DoctorAdviceParentTemplate{}).Preload("DoctorAdviceTemplate", "status = 1").Where("org_id = ? AND status=1 AND id = ?", org_id, id).Order("id desc").First(&temps).Error
  243. return
  244. }
  245. func FindHisDoctorAdviceTemplateById(id int64, org_id int64) (temps models.HisDoctorAdviceParentTemplate, err error) {
  246. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", "status = 1").Where("org_id = ? AND status=1 AND id = ?", org_id, id).Order("id desc").First(&temps).Error
  247. return
  248. }
  249. func FindAllAdviceTemplate(org_id int64, advice_type int64) (temps []*models.DoctorAdviceParentTemplate, err error) {
  250. err = readDb.Model(&models.DoctorAdviceParentTemplate{}).Preload("DoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  251. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id,drug_name_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  252. }).Where("org_id = ? AND status=1 AND advice_type = ?", org_id, advice_type).Find(&temps).Error
  253. return
  254. }
  255. func GetAllAdviceSubTemplates(orgid int64, template_id int64) (total int64, err error) {
  256. err = readDb.Model(&models.DoctorAdviceTemplate{}).Where("org_id =? AND status=1 AND template_id = ?", orgid, template_id).Count(&total).Error
  257. return
  258. }
  259. func UpdateParentAdviceTemplates(orgid int64, tempelate_id int64) (err error) {
  260. err = readDb.Model(&models.DoctorAdviceParentTemplate{}).Where("org_id =? AND status=1 AND id = ?", orgid, tempelate_id).Updates(map[string]interface{}{"status": "0", "updated_time": time.Now().Unix()}).Error
  261. return
  262. }
  263. func FindTemplateRecordByName(orgid int64, name string) (total int64) {
  264. readDb.Model(&models.DoctorAdviceParentTemplate{}).Where("name = ? AND org_id = ? AND status= 1 ", name, orgid).Count(&total)
  265. return
  266. }
  267. func FindParentTemplateRecordById(orgid int64, template_id int64) (parentTemplate models.DoctorAdviceParentTemplate, err error) {
  268. err = readDb.Model(&models.DoctorAdviceParentTemplate{}).Where("id = ? AND org_id = ? AND status= 1 ", template_id, orgid).First(&parentTemplate).Error
  269. return
  270. }
  271. func FindParentHisTemplateRecordById(orgid int64, template_id int64) (parentTemplate models.HisDoctorAdviceParentTemplate, err error) {
  272. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Where("id = ? AND org_id = ? AND status= 1 ", template_id, orgid).First(&parentTemplate).Error
  273. return
  274. }
  275. func DeleteParentDoctorAdviceByTemplateId(template_id int64, org_id int64) (err error) {
  276. ut := writeDb.Begin()
  277. err = writeDb.Model(&models.DoctorAdviceParentTemplate{}).Where("status=1 AND id = ? AND org_id = ?", template_id, org_id).Updates(map[string]interface{}{"status": "0", "updated_time": time.Now().Unix()}).Error
  278. if err != nil {
  279. ut.Rollback()
  280. return
  281. }
  282. err = writeDb.Model(&models.DoctorAdviceTemplate{}).Where("status=1 AND template_id = ? AND org_id = ?", template_id, org_id).Updates(map[string]interface{}{"status": "2", "updated_time": time.Now().Unix()}).Error
  283. if err != nil {
  284. ut.Rollback()
  285. return
  286. }
  287. ut.Commit()
  288. return err
  289. }
  290. func DeleteHisParentDoctorAdviceByTemplateId(template_id int64, org_id int64) (err error) {
  291. ut := writeDb.Begin()
  292. err = writeDb.Model(&models.HisDoctorAdviceParentTemplate{}).Where("status=1 AND id = ? AND org_id = ?", template_id, org_id).Updates(map[string]interface{}{"status": "0", "updated_time": time.Now().Unix()}).Error
  293. if err != nil {
  294. ut.Rollback()
  295. return
  296. }
  297. err = writeDb.Model(&models.HisDoctorAdviceTemplate{}).Where("status=1 AND template_id = ? AND org_id = ?", template_id, org_id).Updates(map[string]interface{}{"status": "2", "updated_time": time.Now().Unix()}).Error
  298. if err != nil {
  299. ut.Rollback()
  300. return
  301. }
  302. ut.Commit()
  303. return err
  304. }
  305. func ModifyTemplateName(id int64, template_name string) (err error) {
  306. err = writeDb.Model(&models.DoctorAdviceParentTemplate{}).Where("status=1 AND id = ?", id).Updates(map[string]interface{}{"name": template_name, "updated_time": time.Now().Unix()}).Error
  307. return err
  308. }
  309. func ModifyTemplateNameOne(id int64, template_name string, sort int64) (err error) {
  310. err = writeDb.Model(&models.DoctorAdviceParentTemplate{}).Where("status=1 AND id = ?", id).Updates(map[string]interface{}{"name": template_name, "updated_time": time.Now().Unix(), "sort": sort}).Error
  311. return err
  312. }
  313. func ModifyHisTemplateName(id int64, template_name string) (err error) {
  314. err = writeDb.Model(&models.HisDoctorAdviceParentTemplate{}).Where("status=1 AND id = ?", id).Updates(map[string]interface{}{"name": template_name, "updated_time": time.Now().Unix()}).Error
  315. return err
  316. }
  317. func FindOtherAllAdviceTemplate(org_id int64) (temps []*models.DoctorAdviceParentTemplate, err error) {
  318. err = readDb.Model(&models.DoctorAdviceParentTemplate{}).Preload("DoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  319. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,drug_id,way, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  320. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  321. return
  322. //.Scan(&advices).Error
  323. }
  324. func FindHisAllAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  325. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  326. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,drug_id,way, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  327. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  328. return
  329. //.Scan(&advices).Error
  330. }
  331. func GetHandleData(id int64) (models.ConfigViewModel, error) {
  332. config := models.ConfigViewModel{}
  333. err := readDb.Model(&config).Where("id=?", id).Find(&config).Error
  334. return config, err
  335. }
  336. func UpdateDataTwo(id int64, model models.ConfigViewModel) error {
  337. err := writeDb.Model(&model).Where("id=?", id).Update(map[string]interface{}{"name": model.Name, "orders": model.Order, "remark": model.Remark, "update_time": time.Now().Unix()}).Error
  338. return err
  339. }
  340. type AdviceDate struct {
  341. RecordDate int64
  342. }
  343. type DoctorAdvice struct {
  344. ID int64 `gorm:"column:id" json:"id" form:"id"`
  345. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  346. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  347. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  348. AdviceType int64 `gorm:"column:advice_type" json:"advice_type" form:"advice_type"`
  349. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  350. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  351. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  352. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  353. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date" form:"reminder_date"`
  354. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  355. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  356. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  357. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  358. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  359. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  360. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  361. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  362. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor" form:"advice_doctor"`
  363. Status int64 `gorm:"column:status" json:"status" form:"status"`
  364. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  365. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  366. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm" form:"advice_affirm"`
  367. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  368. StopTime int64 `gorm:"column:stop_time" json:"stop_time" form:"stop_time"`
  369. StopReason string `gorm:"column:stop_reason" json:"stop_reason" form:"stop_reason"`
  370. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor" form:"stop_doctor"`
  371. StopState int64 `gorm:"column:stop_state" json:"stop_state" form:"stop_state"`
  372. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  373. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  374. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  375. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  376. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  377. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  378. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  379. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  380. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  381. AdviceId int64 `gorm:"-"`
  382. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  383. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  384. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  385. WeekDay string `gorm:"column:week_day" json:"week_day"`
  386. DoctorAdvice []*DoctorAdvice `gorm:"ForeignKey:ParentId;AssociationForeignKey:ID" json:"children"`
  387. TemplateId string `gorm:"column:template_id" json:"template_id"`
  388. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  389. IsCheck int64 `gorm:"-" json:"is_check" form:"is_check"`
  390. Way int64 `gorm:"column:way" json:"way" form:"way"`
  391. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  392. DrugNameId int64 `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
  393. }
  394. func (DoctorAdvice) TableName() string {
  395. return "xt_doctor_advice"
  396. }
  397. func GetDoctorAdviceByType(change_type int64, record_time int64, org_id int64, patient_id int64) (advice []*DoctorAdvice, sch models.Schedule, err error) {
  398. if change_type == 1 { //根据日期取出上一方数据
  399. var Id AdviceDate
  400. err = readDb.Model(&DoctorAdvice{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ?", patient_id, org_id, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  401. err = readDb.Model(&models.Schedule{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND schedule_date = ?", patient_id, org_id, Id.RecordDate).Find(&sch).Error
  402. err = readDb.Model(&DoctorAdvice{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND parent_id= 0", patient_id, org_id, Id.RecordDate).Preload("DoctorAdvice", "status = 1 AND user_org_id = ? AND patient_id = ?", org_id, patient_id).Find(&advice).Error
  403. } else if change_type == 2 {
  404. var Id AdviceDate
  405. err = readDb.Model(&DoctorAdvice{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date > ?", patient_id, org_id, record_time).Select("record_date").Group("record_date").Order("record_date desc").Scan(&Id).Error
  406. err = readDb.Model(&models.Schedule{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND schedule_date = ?", patient_id, org_id, Id.RecordDate).Find(&sch).Error
  407. err = readDb.Model(&DoctorAdvice{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND parent_id= 0", patient_id, org_id, Id.RecordDate).Preload("DoctorAdvice", "status = 1 AND user_org_id = ? AND patient_id = ?", org_id, patient_id).Find(&advice).Error
  408. }
  409. return
  410. }
  411. func GetDict(orgid int64) (drugways []*models.DrugwayDic, total int64, err error) {
  412. err = readDb.Model(&models.DrugwayDic{}).Where("(org_id =? or org_id = 0) and status=1", orgid).Count(&total).Order("id desc").Find(&drugways).Error
  413. return
  414. }