dialysis_service.go 57KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/jinzhu/gorm"
  8. )
  9. //GetPatientList 返回患者的列表
  10. func GetSchedualPatientList(orgID int64, schedulDate int64, schedulType int64, partitionType int64, keywords string, page int64, limit int64) (schedule []*models.DialysisSchedule, err error) {
  11. var total int64
  12. //if len(keywords) > 0 {
  13. // likeKey := "%" + keywords + "%"
  14. // //db = db.Preload("MonitorPatients", "status = 1 AND user_org_id = ? AND `name` LIKE ? ", orgID, likeKey).Preload("DeviceNumber", "status = 1 AND org_id = ? ", orgID).Preload("PredialysisEvaluation", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, schedulDate).Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, schedulDate).Preload("MonitoringRecord", "status = 1 AND user_org_id = ? AND monitoring_date = ?", orgID, schedulDate).Where("status = 1 AND user_org_id = ? ", orgID)
  15. // db = readDb.
  16. // Model(&models.MonitorDialysisSchedule{}).
  17. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  18. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  19. // Preload("TreatmentMode", "status = 1").
  20. // Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  21. // Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  22. // Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  23. // Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  24. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  25. // Preload("MonitorPatients", "status = 1 AND user_org_id = ? AND `name` LIKE ?", orgID,likeKey)
  26. //
  27. //
  28. //} else {
  29. //}
  30. db := readDb.
  31. Model(&models.MonitorDialysisSchedule{}).
  32. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  33. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  34. Preload("TreatmentMode", "status = 1").
  35. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, schedulDate).
  36. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate).
  37. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate).
  38. Preload("MonitoringRecord", "status = 1 AND user_org_id = ? AND monitoring_date = ?", orgID, schedulDate).
  39. Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, schedulDate).
  40. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  41. db = db.Where("status = 1")
  42. if schedulDate > 0 {
  43. db = db.Where("schedule_date = ?", schedulDate)
  44. }
  45. db = db.Count(&total)
  46. fmt.Println(total)
  47. if schedulType > 0 {
  48. db = db.Where("schedule_type = ?", schedulType)
  49. }
  50. if partitionType > 0 {
  51. db = db.Where("partition_id = ?", partitionType)
  52. }
  53. offset := (page - 1) * limit
  54. errors := db.Offset(offset).Limit(limit).Find(&schedule).Error
  55. return schedule, errors
  56. }
  57. //用户基本信息
  58. func FindPatientInfoById(orgID int64, id int64, time int64) (patient models.SchedualPatient2, err error) {
  59. err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
  60. return db.Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).Where("patient_id = ? AND user_org_id = ? AND schedule_date = ? ", id, orgID, time)
  61. }).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
  62. return
  63. }
  64. //透析处方
  65. func FindPatientPrescribeById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescription, err error) {
  66. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
  67. return
  68. }
  69. //透析方案中的透析处方
  70. func FindDialysisSolution(orgID int64, patientsId int64) (patient models.DialysisSolution, err error) {
  71. err = readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id=? and status=1", patientsId, orgID).Last(&patient).Error
  72. return
  73. }
  74. //透析方案中的透析模式
  75. func FindTreatmentModeById(modeId int64) (mode models.TreatmentMode, err error) {
  76. err = readDb.Model(&models.TreatmentMode{}).Where("id = ? AND status=1", modeId).First(&mode).Error
  77. return
  78. }
  79. //接诊评估
  80. func FindReceiverTreatmentAccessRecordById(orgID int64, patientsId int64, recordDate int64) (receiveTreatmentAsses models.ReceiveTreatmentAsses, err error) {
  81. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ?", patientsId, orgID, recordDate).First(&receiveTreatmentAsses).Error
  82. return
  83. }
  84. //透前评估
  85. func FindPredialysisEvaluationById(orgID int64, patientsId int64, recordDate int64) (patient models.PredialysisEvaluation, err error) {
  86. err = readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date = ?", patientsId, orgID, recordDate).First(&patient).Error
  87. return
  88. }
  89. func FindPredialysisName(id int64, orgid int64) (models.Dataconfig, error) {
  90. dataconfig := models.Dataconfig{}
  91. err := readDb.Where("value = ? and org_id =? and status = 1", id, orgid).Find(&dataconfig).Error
  92. return dataconfig, err
  93. }
  94. //临时医嘱
  95. func FindDoctorAdviceById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) {
  96. err = readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? AND advice_type = 2", patientsId, orgID, recordDate).Find(&patient).Error
  97. return
  98. }
  99. func FindDoctorAdviceByInfo(orgID int64, patientsId int64, recordDate int64) (advices []*models.XtDoctorAdvice, err error) {
  100. //db := readDb.Table("xt_doctor_advice as a").Where("a.status = ?", 1)
  101. //err = db.Group("a.advice_name").Select("a.id,a.user_org_id,a.patient_id,a.advice_type,a.advice_date,a.start_time,a.advice_name,a.advice_desc,a.reminder_date,a.single_dose,a.single_dose_unit,a.prescribing_number,a.prescribing_number_unit,a.delivery_way,a.execution_frequency,a.advice_doctor,a.status,a.created_time,a.updated_time,a.advice_affirm,a.remark,a.stop_time,a.stop_reason,a.stop_doctor,a.stop_state,a.parent_id,a.execution_time,a.execution_staff,a.execution_state,a.checker,a.record_date,a.dialysis_order_id,a.check_time,a.check_state,a.drug_spec,a.drug_spec_unit,a.groupno,a.remind_type,a.frequency_type,a.day_count,a.week_day,a.template_id,r.user_name,s.user_name").Joins(" left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = a.execution_staff").Joins("left join sgj_users.sgj_user_admin_role as s on s.admin_user_id = a.checker").Where("a.user_org_id = ? and a.patient_id = ? and a.advice_date = ?", orgID, patientsId, recordDate).Find(&advices).Error
  102. //return
  103. err = readDb.Model(&models.DoctorAdvice{}).
  104. Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and advice_type = 2", patientsId, orgID, recordDate).
  105. 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, IF(parent_id > 0, parent_id, id) as advice_order").Order("start_time asc, groupno desc, advice_order desc, id asc").
  106. Find(&advices).Error
  107. return
  108. }
  109. func GetTotalDialysisCout(orgid int64, patientid int64) (order []*models.DialysisOrder, total int64, err error) {
  110. err = readDb.Model(&order).Where("user_org_id = ? and patient_id = ? and status = 1", orgid, patientid).Find(&order).Count(&total).Error
  111. return order, total, err
  112. }
  113. //临时医嘱
  114. func FindDoctorAdviceOrderById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) {
  115. err = readDb.Model(&models.DoctorAdvice{}).
  116. Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and advice_type = 2", patientsId, orgID, recordDate).
  117. 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, IF(parent_id > 0, parent_id, id) as advice_order").Order("start_time asc, groupno desc, advice_order desc, id asc").
  118. Find(&patient).Error
  119. return
  120. }
  121. //双人核对
  122. func FindDoubleCheckById(orgID int64, patientsId int64, recordDate int64) (patient models.DoubleCheck, err error) {
  123. err = readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id=? and status=1 and check_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
  124. return
  125. }
  126. //透析监测
  127. func FindAllMonitorRecord(orgID int64, patientsId int64, recordDate int64) (record []*models.MonitoringRecord, err error) {
  128. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientsId, orgID, recordDate).Order("operate_time ASC").Find(&record).Error
  129. return
  130. }
  131. func FindAllMonitor(orgID int64, patientsId int64, recordDate int64) (record []*models.MonitoringRecord, err error) {
  132. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientsId, orgID, recordDate).Order("operate_time ASC").Find(&record).Error
  133. return
  134. }
  135. //透后评估
  136. func FindAssessmentAfterDislysisById(orgID int64, patientsId int64, recordDate int64) (patient models.AssessmentAfterDislysis, err error) {
  137. err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date =?", patientsId, orgID, recordDate).First(&patient).Error
  138. return
  139. }
  140. //治疗小结
  141. func FindTreatmentSummaryById(orgID int64, patientsId int64, recordDate int64) (patient models.TreatmentSummary, err error) {
  142. err = readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
  143. return
  144. }
  145. //机构叫号配置
  146. func FindQueueCallInfo(orgID int64) (queueConfig models.QueueCallConfig, err error) {
  147. err = readDb.Model(&models.QueueCallConfig{}).Where("org_id=? ", orgID).First(&queueConfig).Error
  148. return
  149. }
  150. //修改机构叫号配置
  151. func UpDateQueueCallInfo(queueConfig models.QueueCallConfig) error {
  152. err := writeDb.Save(&queueConfig).Error
  153. return err
  154. }
  155. //所有设备信息
  156. func FindAllDeviceInfo(orgID int64) (device []*models.Device, err error) {
  157. err = readDb.Model(&models.Device{}).Where("org_id=? and status=1 and device_type = 1", orgID).Find(&device).Error
  158. return device, err
  159. }
  160. //所有设备区域
  161. func GetAllDeviceZone(orgId int64) (error, []*models.DeviceZone) {
  162. var zone []*models.DeviceZone
  163. err := readDb.Model(&zone).Where("org_id = ? AND status = 1", orgId).Find(&zone).Error
  164. return err, zone
  165. }
  166. //获取所有子药物
  167. func FindAllSubDoctorAdvice(id int64, parentId int64) (error, []models.DoctorAdvice) {
  168. var subAdvies []models.DoctorAdvice
  169. err := readDb.Model(&subAdvies).Where("patient_id = ? AND parent_id = ?", id, parentId).Find(&subAdvies).Error
  170. return err, subAdvies
  171. }
  172. func FindAdivceById(orgId int64, patientId int64, id int64) (error, models.DoctorAdvice) {
  173. advices := models.DoctorAdvice{}
  174. err := readDb.Model(&advices).Where("user_org_id = ? AND patient_id = ? AND id = ? AND status = 1", orgId, patientId, id).Find(&advices).Error
  175. return err, advices
  176. }
  177. func FindSubAdivceById(patientId int64, parentId int64) []*models.DoctorAdvice {
  178. var subAdvices []*models.DoctorAdvice
  179. readDb.Model(&subAdvices).Where("patient_id = ? AND parent_id = ?", patientId, parentId).Find(&subAdvices)
  180. return subAdvices
  181. }
  182. func AddSigleRecord(prescription *models.DialysisPrescription) (err error) {
  183. tx := writeDb.Begin()
  184. errors := tx.Model(&models.DialysisPrescription{}).Create(&prescription).Error
  185. if err != nil {
  186. tx.Rollback()
  187. }
  188. tx.Commit()
  189. return errors
  190. }
  191. func AddSigleSummaryRecord(summary *models.TreatmentSummary) (err error) {
  192. tx := writeDb.Begin()
  193. errors := tx.Model(&models.TreatmentSummary{}).Create(&summary).Error
  194. if err != nil {
  195. tx.Rollback()
  196. }
  197. tx.Commit()
  198. return errors
  199. }
  200. func AddSigleReceiveTreatmentAssesRecord(receiveTreatmentAsses *models.ReceiveTreatmentAsses) (err error) {
  201. tx := writeDb.Begin()
  202. errors := tx.Model(&models.ReceiveTreatmentAsses{}).Create(&receiveTreatmentAsses).Error
  203. if err != nil {
  204. tx.Rollback()
  205. }
  206. tx.Commit()
  207. return errors
  208. }
  209. func AddSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis *models.AssessmentAfterDislysis) (err error) {
  210. tx := writeDb.Begin()
  211. errors := tx.Model(&models.AssessmentAfterDislysis{}).Create(&assessmentAfterDislysis).Error
  212. if err != nil {
  213. tx.Rollback()
  214. }
  215. tx.Commit()
  216. return errors
  217. }
  218. func AddSigleAssessmentBeforeDislysisRecord(assessmentBeforeDislysis *models.PredialysisEvaluation) (err error) {
  219. tx := writeDb.Begin()
  220. errors := tx.Model(&models.PredialysisEvaluation{}).Create(&assessmentBeforeDislysis).Error
  221. if err != nil {
  222. tx.Rollback()
  223. }
  224. tx.Commit()
  225. return errors
  226. }
  227. func AddSigleDoubleCheck(check *models.DoubleCheck) (err error) {
  228. tx := writeDb.Begin()
  229. errors := tx.Model(&models.PredialysisEvaluation{}).Create(&check).Error
  230. if err != nil {
  231. tx.Rollback()
  232. }
  233. tx.Commit()
  234. return errors
  235. }
  236. //修改透析处方
  237. func UpDateDialysisPrescription(dialysisPrescription *models.DialysisPrescription) error {
  238. err := writeDb.Save(&dialysisPrescription).Error
  239. return err
  240. }
  241. //修改接诊评估
  242. func UpadateReceiveTreatmentAsses(receiveTreatmentAsses *models.ReceiveTreatmentAsses) error {
  243. err := writeDb.Save(receiveTreatmentAsses).Error
  244. return err
  245. }
  246. //修改透前评估
  247. func UpadatePredialysisEvaluation(predialysisEvaluation *models.PredialysisEvaluation) error {
  248. err := writeDb.Save(&predialysisEvaluation).Error
  249. return err
  250. }
  251. //修改双人核对
  252. func UpdateDoubleCheck(check *models.DoubleCheck) error {
  253. err := writeDb.Save(&check).Error
  254. return err
  255. }
  256. //修改透后评估
  257. func UpdateAssessmentAfterDislysisRecord(assessmentAfterDislysis *models.AssessmentAfterDislysis) error {
  258. err := writeDb.Save(&assessmentAfterDislysis).Error
  259. return err
  260. }
  261. //修改
  262. func UpdateSummeRecord(treatmentSummary *models.TreatmentSummary) error {
  263. err := writeDb.Save(&treatmentSummary).Error
  264. return err
  265. }
  266. // func UpdateDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
  267. // tx := writeDb.Begin()
  268. // err := tx.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND id = ? AND status = 1 ", patientId, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1, "checker": m.Checker}).Error
  269. // if err != nil {
  270. // tx.Rollback()
  271. // }
  272. // tx.Commit()
  273. // return err
  274. // }
  275. func ExceDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
  276. err := writeDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND (id = ? Or parent_id=?) AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error
  277. return err
  278. }
  279. func ExceHidDoctorAdviceById(m *models.HisDoctorAdviceInfo, id int64, patientId int64) error {
  280. err := writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND (id = ? Or parent_id=?) AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error
  281. return err
  282. }
  283. func CheckDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
  284. err := writeDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND (id = ? Or parent_id=?) AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error
  285. return err
  286. }
  287. func CheckHisDoctorAdviceById(m *models.HisDoctorAdviceInfo, id int64, patientId int64) error {
  288. err := writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND (id = ? Or parent_id=?) AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error
  289. return err
  290. }
  291. func CreateMonitor(m *models.MonitoringRecord) (err error) {
  292. return writeDb.Create(m).Error
  293. }
  294. func UpdateMonitor(m *models.MonitoringRecord) (err error) {
  295. return writeDb.Save(m).Error
  296. }
  297. func DelMonitor(patientId int64, recordId int64) error {
  298. tx := writeDb.Begin()
  299. updateTime := time.Now().Unix()
  300. err := tx.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND id = ? AND status = 1 ", patientId, recordId).Updates(map[string]interface{}{"status": 0, "updated_time": updateTime}).Error
  301. if err != nil {
  302. tx.Rollback()
  303. }
  304. tx.Commit()
  305. return err
  306. }
  307. //修改长期处方
  308. func UpdateSolution(solution *models.DialysisSolution) {
  309. writeDb.Save(&solution)
  310. }
  311. //创建长期处方
  312. func CreateSolution(solution *models.DialysisSolution) {
  313. writeDb.Create(&solution)
  314. }
  315. func SavePrescriptionAndCreateSolution(solution *models.DialysisSolution, prescription *models.DialysisPrescription) (err error) {
  316. tx := writeDb.Begin()
  317. if prescription.ID > 0 {
  318. err = tx.Save(&prescription).Error
  319. } else {
  320. err = tx.Model(&models.DialysisPrescription{}).Create(&prescription).Error
  321. }
  322. if err != nil {
  323. tx.Rollback()
  324. return
  325. }
  326. err = tx.Create(&solution).Error
  327. if err != nil {
  328. tx.Rollback()
  329. return
  330. }
  331. tx.Commit()
  332. return
  333. }
  334. //透析处方
  335. func FindDialysisPrescriptionByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DialysisPrescription) {
  336. dialysisPrescription := models.DialysisPrescription{}
  337. err := readDb.Model(&dialysisPrescription).Where("patient_id = ? AND record_date = ? AND status = 1 AND user_org_id = ? ", id, recordDate, orgId).Find(&dialysisPrescription).Error
  338. return err, &dialysisPrescription
  339. }
  340. func FindReceiveTreatmentAssesByReordDate(id int64, recordDate int64, orgId int64) (error, *models.ReceiveTreatmentAsses) {
  341. receiveTreatmentAsses := models.ReceiveTreatmentAsses{}
  342. err := readDb.Model(&receiveTreatmentAsses).Where("patient_id = ? AND record_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).Find(&receiveTreatmentAsses).Error
  343. return err, &receiveTreatmentAsses
  344. }
  345. //透前评估
  346. func FindPredialysisEvaluationByReordDate(id int64, recordDate int64, orgId int64) (error, *models.PredialysisEvaluation) {
  347. dialysisEvaluation := models.PredialysisEvaluation{}
  348. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&dialysisEvaluation).Error
  349. return err, &dialysisEvaluation
  350. }
  351. //双人核对
  352. func FindDoubleCheckByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DoubleCheck) {
  353. check := models.DoubleCheck{}
  354. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? AND check_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&check).Error
  355. return err, &check
  356. }
  357. func FindAssessmentAfterDislysisByReordDate(id int64, recordDate int64, orgId int64) (error, *models.AssessmentAfterDislysis) {
  358. assessmentAfterDislysis := models.AssessmentAfterDislysis{}
  359. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&assessmentAfterDislysis).Error
  360. return err, &assessmentAfterDislysis
  361. }
  362. func FindTreatmentSummaryByReordDate(id int64, recordDate int64, orgId int64) (error, *models.TreatmentSummary) {
  363. summary := models.TreatmentSummary{}
  364. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&summary).Error
  365. return err, &summary
  366. }
  367. func FindDoctorAdviceByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DoctorAdvice) {
  368. advice := models.DoctorAdvice{}
  369. err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND record_date = ? AND parent_id = 0 AND status = 1 AND user_org_id = ? ", id, recordDate, orgId).First(&advice).Error
  370. return err, &advice
  371. }
  372. func FindDialysisRecordById(orgId int64, id int64, recordDate int64) (error, *models.DialysisOrder) {
  373. var count int64
  374. dialysisRecord := models.DialysisOrder{}
  375. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgId, id, recordDate).Find(&dialysisRecord).Count(&count).Error
  376. if count <= 0 {
  377. return err, nil
  378. }
  379. return err, &dialysisRecord
  380. }
  381. func FindDialysisSchedualById(orgId int64, id int64, recordDate int64) (error, *models.Schedule) {
  382. var count int64
  383. schedule := models.Schedule{}
  384. err := readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND patient_id = ? AND schedule_date = ?", orgId, id, recordDate).Find(&schedule).Count(&count).Error
  385. if count <= 0 {
  386. return err, nil
  387. }
  388. return err, &schedule
  389. }
  390. func CreateDialysisRecord(id int64, orgId int64, record *models.DialysisOrder) error {
  391. err := writeDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? ", orgId, id).Create(&record).Error
  392. if err != nil {
  393. return err
  394. }
  395. dialysisPrescriptionErr := UpDateRecordIdToDialysisPrescription(id, orgId, record.DialysisDate, record.ID)
  396. if dialysisPrescriptionErr != nil {
  397. return dialysisPrescriptionErr
  398. }
  399. receiveTreatmentAssesErr := UpDateRecordIdToReceiveTreatmentAsses(id, orgId, record.DialysisDate, record.ID)
  400. if receiveTreatmentAssesErr != nil {
  401. return receiveTreatmentAssesErr
  402. }
  403. predialysisEvaluationErr := UpDateRecordIdToPredialysisEvaluation(id, orgId, record.DialysisDate, record.ID)
  404. if predialysisEvaluationErr != nil {
  405. return predialysisEvaluationErr
  406. }
  407. treatmentSummaryErr := UpDateRecordIdToTreatmentSummary(id, orgId, record.DialysisDate, record.ID)
  408. if treatmentSummaryErr != nil {
  409. return treatmentSummaryErr
  410. }
  411. doubleCheckErr := UpDateRecordIdToDoubleCheck(id, orgId, record.DialysisDate, record.ID)
  412. if doubleCheckErr != nil {
  413. return doubleCheckErr
  414. }
  415. adviceErrr := UpDateRecordIdToDoctorAdvice(id, orgId, record.DialysisDate, record.ID)
  416. if adviceErrr != nil {
  417. return adviceErrr
  418. }
  419. //透析监测
  420. records, err := FindAllMonitorRecord(orgId, id, record.DialysisDate)
  421. if err != nil {
  422. return err
  423. }
  424. var Ids []int64
  425. for _, item := range records {
  426. Ids = append(Ids, item.ID)
  427. }
  428. monitorErr := UpDateRecordIdToMonitor(Ids, record.ID)
  429. if monitorErr != nil {
  430. return monitorErr
  431. }
  432. return nil
  433. }
  434. func ModifyDialysisRecord(id int64, finishNurse int64, end_time int64, admin_user_id int64) error {
  435. err := writeDb.Model(&models.DialysisOrder{}).Where("id = ? AND status = 1 ", id).Updates(map[string]interface{}{"updated_time": time.Now().Unix(), "stage": 2, "finish_nurse": finishNurse, "end_time": end_time, "finish_creator": admin_user_id, "finish_modifier": admin_user_id}).Error
  436. return err
  437. }
  438. func UpdateSolutionByPatientId(id int64) error {
  439. err := writeDb.Model(&models.Patients{}).Where("id = ? AND status = 1 ", id).UpdateColumn("total_dialysis", gorm.Expr("total_dialysis + ?", 1)).Error
  440. return err
  441. }
  442. //更新透析处方记录ID
  443. func UpDateRecordIdToDialysisPrescription(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  444. errors := writeDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"record_id": recordId}).Error
  445. return errors
  446. }
  447. func UpDateRecordIdToReceiveTreatmentAsses(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  448. errors := writeDb.Model(&models.ReceiveTreatmentAsses{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"record_id": recordId}).Error
  449. return errors
  450. }
  451. func UpDateRecordIdToPredialysisEvaluation(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  452. errors := writeDb.Model(&models.PredialysisEvaluation{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error
  453. return errors
  454. }
  455. func UpDateRecordIdToAssessmentAfterDislysis(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  456. errors := writeDb.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error
  457. return errors
  458. }
  459. func UpDateRecordIdToTreatmentSummary(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  460. errors := writeDb.Model(&models.TreatmentSummary{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error
  461. return errors
  462. }
  463. func UpDateRecordIdToMonitor(Ids []int64, recordId int64) error {
  464. errors := writeDb.Model(&models.MonitoringRecord{}).Where("id IN (?)", Ids).Update(map[string]interface{}{"dialysis_order_id": recordId}).Error
  465. return errors
  466. }
  467. func UpDateRecordIdToDoubleCheck(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  468. errors := writeDb.Model(&models.DoubleCheck{}).Where("user_org_id = ? AND patient_id = ? AND check_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error
  469. return errors
  470. }
  471. func UpDateRecordIdToDoctorAdvice(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  472. errors := writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error
  473. return errors
  474. }
  475. //透析处方
  476. func FindPatientPrescribeWidyDevideById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescriptionAddtional, err error) {
  477. err = readDb.Preload("Device", "status = 1 AND org_id = ?", orgID).
  478. Model(&models.DialysisPrescriptionAddtional{}).
  479. Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? ", patientsId, orgID, recordDate).
  480. First(&patient).Error
  481. return
  482. }
  483. func FindDialysisMode(orgID int64, patientId int64, scheduleDate int64) (models.XtSchedule, error) {
  484. schedule := models.XtSchedule{}
  485. err = readDb.Where("user_org_id = ? and patient_id = ? and schedule_date = ? ", orgID, patientId, scheduleDate).Find(&schedule).Error
  486. return schedule, err
  487. }
  488. func FindDialysisMacher(orgid int64, patientid int64, dialysisDate int64) (models.XtDialysisOrders, error) {
  489. orders := models.XtDialysisOrders{}
  490. db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
  491. table := readDb.Table("xt_device_number as n")
  492. fmt.Print("table", table)
  493. err := db.Select("o.id,o.dialysis_date,o.user_org_id,o.patient_id,o.prescription_id,o.stage,remark,o.bed_id,o.start_nurse,o.finish_nurse,o.status,o.created_time,o.updated_time,o.start_time,o.end_time,o.puncture_nurse,o.creator,o.modifier,o.finish_creator,o.finish_modifier,o.schedual_type,n.number,r.user_name").Joins("left join xt_device_number as n on n.id = o.bed_id").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.start_nurse").Where("o.user_org_id = ? and o.patient_id = ? and o.dialysis_date =?", orgid, patientid, dialysisDate).Scan(&orders).Error
  494. return orders, err
  495. }
  496. func FindPunctureNurse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  497. role := models.App_Roles{}
  498. //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error
  499. //return role, err
  500. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status =1")
  501. err := db.Select("r.id,r.admin_user_id,r.org_id,r.role_id,r.user_name,r.avatar,r.user_type,r.user_title,r.intro,r.status,r.ctime,e.url").Joins("left join sgj_user_admin_electronic_signature as e on e.creator = r.admin_user_id").Where("r.admin_user_id = ? and r.app_id = ? and r.org_id = ?", adminid, appid, orgid).Find(&role).Error
  502. return role, err
  503. }
  504. func FindeStartNuse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  505. role := models.App_Roles{}
  506. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  507. err := db.Select("r.id,r.admin_user_id,r.org_id,r.role_id,r.user_name,r.avatar,r.user_type,r.user_title,r.intro,r.status,r.ctime,e.url").Joins("left join sgj_user_admin_electronic_signature as e on e.creator = r.admin_user_id").Where("r.admin_user_id = ? and r.app_id = ? and r.org_id = ?", adminid, appid, orgid).Find(&role).Error
  508. //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error
  509. return role, err
  510. }
  511. func FindDialysisWay(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  512. prescription := models.DialysisPrescription{}
  513. err := readDb.Where("user_org_id = ? and patient_id = ? and record_date = ? and status =1", orgid, patientid, recorddate).Find(&prescription).Error
  514. return prescription, err
  515. }
  516. func FindDoctorOrder(orgid int64, patientid int64, adviceDate int64) (models.XtDoctorAdvice, error) {
  517. advices := models.XtDoctorAdvice{}
  518. db := readDb.Table("xt_doctor_advice as a").Where("a.status = ?", 1)
  519. err := db.Select("a.id,a.user_org_id,a.patient_id,a.advice_type,a.advice_date,a.start_time,a.advice_name,a.advice_desc,a.reminder_date,a.single_dose,a.single_dose_unit,a.prescribing_number,a.prescribing_number_unit,a.delivery_way,a.execution_frequency,a.advice_doctor,a.status,a.created_time,a.updated_time,a.advice_affirm,a.remark,a.stop_time,a.stop_reason,a.stop_doctor,a.stop_state,a.parent_id,a.execution_time,a.execution_staff,a.execution_state,a.checker,a.record_date,a.dialysis_order_id,a.check_time,a.check_state,a.drug_spec,a.drug_spec_unit,a.groupno,a.remind_type,a.frequency_type,a.day_count,a.week_day,a.template_id").Where("a.user_org_id = ? and a.patient_id = ? and a.advice_date = ?", orgid, patientid, adviceDate).Find(&advices).Error
  520. return advices, err
  521. }
  522. func FindDoctor(adminuserid int64, appid int64, orgid int64) (models.App_Role, error) {
  523. role := models.App_Role{}
  524. err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminuserid, appid, orgid).Find(&role).Error
  525. return role, err
  526. }
  527. func FindDoctorName(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  528. role := models.App_Roles{}
  529. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  530. err := db.Select("r.id,r.admin_user_id,r.org_id,r.role_id,r.user_name,r.avatar,r.user_type,r.user_title,r.intro,r.status,r.ctime,e.url").Joins("left join sgj_user_admin_electronic_signature as e on e.creator = r.admin_user_id").Where("r.admin_user_id = ? and r.app_id = ? and r.org_id = ?", adminid, appid, orgid).Find(&role).Error
  531. //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error
  532. return role, err
  533. }
  534. /////////////// 新 18-10-22
  535. func GetDialysisScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  536. var vms []*MDialysisScheduleVM
  537. db := readDb.
  538. Table("xt_schedule").
  539. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  540. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  541. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  542. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  543. Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
  544. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  545. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  546. Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  547. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  548. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  549. Where("status = 1 AND user_org_id = ?", orgID)
  550. if scheduleDate != 0 {
  551. db = db.Where("schedule_date = ?", scheduleDate)
  552. }
  553. err := db.Find(&vms).Error
  554. return vms, err
  555. }
  556. func GetLastAcceptsAssessment(patient int64, orgId int64) (error, models.ReceiveTreatmentAsses) {
  557. var receiveTreatmentAsses models.ReceiveTreatmentAsses
  558. err := readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? AND status = 1 AND user_org_id = ?", patient, orgId).Last(&receiveTreatmentAsses).Error
  559. return err, receiveTreatmentAsses
  560. }
  561. func GetDialysisWatch(orgID int64, schedulDate int64, schedulType int64, partitionType int64, page int64, limit int64) (schedule []*models.DialysisSchedule, err error, total int64) {
  562. db := readDb.
  563. Model(&models.MonitorDialysisSchedule{}).
  564. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  565. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  566. Preload("TreatmentMode", "status = 1").
  567. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  568. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  569. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  570. Preload("MonitoringRecord", func(db *gorm.DB) *gorm.DB {
  571. return db.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time asc")
  572. }).
  573. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  574. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  575. db = db.Where("xt_schedule.status = 1 AND user_org_id = ?", orgID)
  576. if schedulDate > 0 {
  577. db = db.Where("schedule_date = ?", schedulDate)
  578. }
  579. if schedulType > 0 {
  580. db = db.Where("schedule_type = ?", schedulType)
  581. }
  582. if partitionType > 0 {
  583. db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ? and xt_device_number.status = 1", partitionType)
  584. // db = db.Where("partition_id = ?", partitionType)
  585. }
  586. offset := (page - 1) * limit
  587. err = db.Count(&total).Offset(offset).Limit(limit).Order("bed_id desc").Find(&schedule).Error
  588. return schedule, err, total
  589. }
  590. func GetDialysisWatchByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64) ([]*models.DialysisSchedule, error, int64) {
  591. var patients []*models.Patients
  592. getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
  593. if getPatientErr != nil {
  594. return nil, getPatientErr, 0
  595. }
  596. patientIDs := make([]int64, len(patients))
  597. for index, patient := range patients {
  598. patientIDs[index] = patient.ID
  599. }
  600. db := readDb.
  601. Model(&models.DialysisSchedule{}).
  602. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  603. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  604. Preload("TreatmentMode", "status = 1").
  605. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  606. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  607. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  608. Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  609. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  610. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  611. db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
  612. if schedulType > 0 {
  613. db = db.Where("schedule_type = ?", schedulType)
  614. }
  615. if partitionType > 0 {
  616. db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ? and d_n.status = 1", partitionType)
  617. // db = db.Where("partition_id = ?", partitionType)
  618. }
  619. var schedules []*models.DialysisSchedule
  620. total := int64(0)
  621. err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
  622. return schedules, err, total
  623. }
  624. func GetAdminUserES(orgID int64, appID int64, ids []int64) (es []*models.AdminUserElectronicSignature, err error) {
  625. err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id=? and creator in (?) and status=1", orgID, appID, ids).Find(&es).Error
  626. return
  627. }
  628. //
  629. //func GetAdminUserEsOne(orgid int64) (admin []*models.UserAdminRoles, err error) {
  630. //
  631. // db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1")
  632. // table := readUserDb.Table("sgj_user_admin_electronic_signature as s")
  633. // fmt.Println("table", table)
  634. // err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ?", orgid).Scan(&admin).Error
  635. // return admin, err
  636. //}
  637. func GetAdminUserEsOne(orgid int64) (admin []*models.UserAdminRoles, err error) {
  638. db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status =1")
  639. table := readUserDb.Table("sgj_user_admin_electronic_signature as s")
  640. fmt.Println("table", table)
  641. err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ?", orgid).Scan(&admin).Error
  642. return admin, err
  643. }
  644. func UpDateDialysisPrescriptionDoctorSign(patient int64, date int64, orgId int64, doctor_id int64) (err error) {
  645. err = writeDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? ", orgId, patient, date).Updates(map[string]interface{}{"prescription_doctor": doctor_id}).Error
  646. return
  647. }
  648. func GetAllAdminUserES(orgID int64, appId int64) (es []*models.AdminUserElectronicSignature, err error) {
  649. err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id = ? and status=1", orgID, appId).Find(&es).Error
  650. return
  651. }
  652. func GetAllStarfEs(orgid int64) (es []*models.SgjUserAdminRoles, err error) {
  653. db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1")
  654. table := readUserDb.Table("sgj_user_admin_electronic_signature as s")
  655. fmt.Println("table", table)
  656. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id and s.status = 1").Where("x.org_id = ?", orgid).Scan(&es).Error
  657. return es, err
  658. }
  659. func FindLastMonitorRecord(patient_id int64, org_id int64) (record models.MonitoringRecord, err error) {
  660. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND status = 1 AND user_org_id = ?", patient_id, org_id).Last(&record).Error
  661. return
  662. }
  663. func FindLastMonitorRecordToday(patient_id int64, org_id int64, monitoring_date int64) (record models.MonitoringRecord, err error) {
  664. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND status = 1 AND user_org_id = ? AND monitoring_date = ?", patient_id, org_id, monitoring_date).Last(&record).Error
  665. return
  666. }
  667. func FindFirstMonitorRecordToday(patient_id int64, org_id int64, monitoring_date int64) (record models.MonitoringRecord, err error) {
  668. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND status = 1 AND user_org_id = ? AND monitoring_date = ?", patient_id, org_id, monitoring_date).First(&record).Error
  669. return
  670. }
  671. func ExceDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  672. ut := writeDb.Begin()
  673. err = ut.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ? AND status = 1 AND execution_state = 2", groupNo, org_id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error
  674. if err != nil {
  675. ut.Rollback()
  676. return
  677. }
  678. ut.Commit()
  679. return err
  680. }
  681. func ExceOldDoctorAdvice(m *models.DoctorAdvice, advice_id int64) (err error) {
  682. ut := writeDb.Begin()
  683. err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND id = ?", advice_id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error
  684. if err != nil {
  685. ut.Rollback()
  686. return
  687. }
  688. err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id = ?", advice_id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error
  689. if err != nil {
  690. ut.Rollback()
  691. return
  692. }
  693. ut.Commit()
  694. return err
  695. }
  696. func CheckDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  697. ut := writeDb.Begin()
  698. err = ut.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ? AND status = 1 AND check_state = 0", groupNo, org_id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error
  699. if err != nil {
  700. ut.Rollback()
  701. return
  702. }
  703. ut.Commit()
  704. return err
  705. }
  706. func CheckOldDoctorAdvice(m *models.DoctorAdvice, advice_id int64) (err error) {
  707. ut := writeDb.Begin()
  708. err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND id = ?", advice_id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error
  709. if err != nil {
  710. ut.Rollback()
  711. return
  712. }
  713. err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id = ?", advice_id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error
  714. if err != nil {
  715. ut.Rollback()
  716. return
  717. }
  718. ut.Commit()
  719. return err
  720. }
  721. func DeleteDoctorAdviceByGroupNo(m *models.DoctorAdvice) (err error) {
  722. ut := writeDb.Begin()
  723. err = ut.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ?", m.GroupNo, m.UserOrgId).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "Status": 0, "modifier": m.Modifier}).Error
  724. if err != nil {
  725. ut.Rollback()
  726. return
  727. }
  728. ut.Commit()
  729. return
  730. }
  731. func GetDialysisBoard(orgID int64, scheduleDate int64, offset, limit int64) ([]*models.DialysisBoardVM, error) {
  732. var boards []*models.DialysisBoardVM
  733. db := readDb.
  734. Table("xt_schedule").
  735. Preload("Patient", "status = 1 AND user_org_id = ?", orgID).
  736. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  737. Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  738. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  739. Preload("SigninAndWeigh", "status = 1 AND user_org_id = ?", orgID).
  740. Preload("NextSchedules", func(db *gorm.DB) *gorm.DB {
  741. return db.Where("user_org_id = ? AND schedule_date > ? AND status = 1", orgID, scheduleDate).
  742. Order("schedule_date asc, id asc")
  743. }).
  744. Where("status = 1 AND user_org_id = ?", orgID)
  745. if scheduleDate != 0 {
  746. db = db.Where("schedule_date = ?", scheduleDate)
  747. }
  748. err := db.Offset(offset).Limit(limit).Find(&boards).Error
  749. return boards, err
  750. }
  751. func GetOneDialysisOrder(orgID, orderData int64, patient_id int64) (*models.DialysisOrder, error) {
  752. var order models.DialysisOrder
  753. var err error
  754. err = readDb.Model(&models.DialysisOrder{}).Where("user_org_id=? and dialysis_date=? and status=1 and patient_id = ?", orgID, orderData, patient_id).First(&order).Error
  755. if err == gorm.ErrRecordNotFound {
  756. return nil, nil
  757. }
  758. if err != nil {
  759. return nil, err
  760. }
  761. return &order, nil
  762. }
  763. func GetOrgInfoTemplate(orgID int64) (models.GobalTemplate, error) {
  764. var templateInfo models.GobalTemplate
  765. var err error
  766. err = readDb.Model(&models.GobalTemplate{}).Where("org_id=? and status=1", orgID).First(&templateInfo).Error
  767. return templateInfo, err
  768. }
  769. func FindAdminRoleTypeById(orgId int64, adminUserId int64, appId int64) (models.App_Role, error) {
  770. var appRole models.App_Role
  771. var err error
  772. err = readUserDb.Model(&models.App_Role{}).Where("org_id =? and app_id = ? and admin_user_id = ? and status=1", orgId, appId, adminUserId).First(&appRole).Error
  773. return appRole, err
  774. }
  775. func BatchExceOldDoctorAdvice(m *models.DoctorAdvice, ids []string) (err error) {
  776. ut := writeDb.Begin()
  777. err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?) AND execution_state = 2", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error
  778. if err != nil {
  779. ut.Rollback()
  780. return
  781. }
  782. err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?) AND execution_state = 2 ", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error
  783. if err != nil {
  784. ut.Rollback()
  785. return
  786. }
  787. ut.Commit()
  788. return err
  789. }
  790. func BatchCheckOldDoctorAdvice(m *models.DoctorAdvice, ids []string, org_id int64, date int64) (err error) {
  791. ut := writeDb.Begin()
  792. err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?) AND user_org_id = ? AND advice_date = ?", ids, org_id, date).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error
  793. if err != nil {
  794. ut.Rollback()
  795. return
  796. }
  797. err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?) AND user_org_id = ? AND advice_date = ?", ids, org_id, date).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error
  798. if err != nil {
  799. ut.Rollback()
  800. return
  801. }
  802. ut.Commit()
  803. return err
  804. }
  805. func ModifyScheduleMode(mode_id int64, patient_id int64, recordDate int64, org_id int64) {
  806. ut := writeDb.Begin()
  807. err = writeDb.Model(&models.Schedule{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND schedule_date = ? ", org_id, patient_id, recordDate).Updates(map[string]interface{}{"updated_time": time.Now().Unix(), "mode_id": mode_id}).Error
  808. if err != nil {
  809. ut.Rollback()
  810. return
  811. }
  812. ut.Commit()
  813. }
  814. func FindDialysisOrderById(id int64) (error, *models.DialysisOrder) {
  815. dialysisRecord := models.DialysisOrder{}
  816. err := readDb.Model(&models.DialysisOrder{}).Where("id = ? AND status = 1", id).Find(&dialysisRecord).Error
  817. return err, &dialysisRecord
  818. }
  819. func ModifyExceDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  820. ut := writeDb.Begin()
  821. err = ut.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ? AND status = 1 AND execution_state = 1", groupNo, org_id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error
  822. if err != nil {
  823. ut.Rollback()
  824. return
  825. }
  826. ut.Commit()
  827. return err
  828. }
  829. func BatchModifyExceOldDoctorAdvice(m *models.DoctorAdvice, ids []string) (err error) {
  830. ut := writeDb.Begin()
  831. err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?) AND execution_state = 1", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error
  832. if err != nil {
  833. ut.Rollback()
  834. return
  835. }
  836. err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?) AND execution_state = 1 ", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error
  837. if err != nil {
  838. ut.Rollback()
  839. return
  840. }
  841. ut.Commit()
  842. return err
  843. }
  844. func UpdateOrderCount(good_type_id int64, good_id int64, number string, org_id int64) {
  845. writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).UpdateColumn("count", gorm.Expr("count - ?", 1))
  846. }
  847. func UpdateOrderInfoDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, newNiprocart int64, out *models.WarehouseOutInfo) {
  848. writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"good_id": newNiprocart, "warehouse_out_id": out.ID, "warehouse_out_order_number": out.WarehouseOutOrderNumber})
  849. }
  850. func FindOrderInfoByGoodId(good_type_id int64, good_id int64, number string, org_id int64) (err error, out models.WarehouseOutInfo) {
  851. err = writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).Find(&out).Error
  852. return
  853. }
  854. func FindGoodUserById(good_type_id int64, good_id int64, id int64, org_id int64, record_time int64) (user models.AutomaticReduceDetail, err error) {
  855. err = readDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND patient_id = ? AND org_id = ? AND record_time = ? ", good_id, good_type_id, id, org_id, record_time).First(&user).Error
  856. return
  857. }
  858. func FindOldOrderInfoByGoodId(time int64, org_id int64) (err error, out models.WarehouseOutInfo) {
  859. err = readDb.Model(&models.WarehouseOutInfo{}).Where(" org_id = ? AND status = 1 AND sys_record_time = ? ", org_id, time).First(&out).Error
  860. return
  861. }
  862. func FindStockOutOrderNumberByTime(time int64, org_id int64) (err error, out models.WarehouseOut) {
  863. err = readDb.Model(&models.WarehouseOut{}).Where(" org_id = ? AND status = 1 AND warehouse_out_time = ? ", org_id, time).First(&out).Error
  864. return
  865. }
  866. func UpdateDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, newNiprocart int64, out *models.WarehouseOutInfo) {
  867. writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"good_id": newNiprocart, "warehouse_out_id": out.ID, "warehouse_out_order_number": out.WarehouseOutOrderNumber})
  868. }
  869. func FindPatientIsOpenRemindById(patient_id int64, org_id int64) (patients models.Patients, err error) {
  870. err = readDb.Model(&models.Patients{}).Where("status = 1 AND id = ? AND user_org_id = ?", patient_id, org_id).First(&patients).Error
  871. return
  872. }
  873. func GetMaxLongAdviceGroupID(orgId int64, patient_id int64) (group int64) {
  874. var advice models.DoctorAdvice
  875. err := readDb.Table("xt_doctor_advice").Where("user_org_id=? AND patient_id = ? AND status = 1 AND advice_type = 1 AND frequency_type > 0", orgId, patient_id).Select("max(groupno) as groupno").First(&advice).Error
  876. if err != nil {
  877. fmt.Println(err)
  878. group = 0
  879. }
  880. group = advice.GroupNo
  881. return
  882. }
  883. func GetLastLongAdviceByGroupNo(orgId int64, patient_id int64) (advice []*models.DoctorAdvice, err error) {
  884. err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND stop_state = 2 AND parent_id = 0", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
  885. return
  886. }
  887. func GetLastLongAdviceByGroupNoThree(orgId int64, patient_id int64) (advice []*models.DoctorAdvice, err error) {
  888. err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND frequency_type = 2 AND stop_state = 2 AND parent_id = 0 ", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
  889. return
  890. }
  891. func FindAllDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, temp_id string) (advice []*models.DoctorAdvice, err error) {
  892. err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 2 AND advice_date > ? AND advice_date <= ? AND template_id = ? ", orgId, patient_id, end, now, temp_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
  893. return
  894. }
  895. func UpdateScheduleModeId(patient_id int64, org_id int64, date int64, mode_id int64) (err error) {
  896. err = writeDb.Model(&models.Schedule{}).Where("status =1 AND user_org_id = ? AND patient_id = ? AND schedule_date = ?", org_id, patient_id, date).Updates(map[string]interface{}{"mode_id": mode_id, "updated_time": time.Now().Unix()}).Error
  897. return
  898. }
  899. func UpdateAssessmentAfterDate(patient_id int64, org_id int64, date int64, actual_treatment_hour int64, actual_treatment_minute int64) (err error) {
  900. err = writeDb.Model(&models.AssessmentAfterDislysis{}).Where("status =1 AND user_org_id = ? AND patient_id = ? AND assessment_date = ?", org_id, patient_id, date).Updates(map[string]interface{}{"actual_treatment_hour": actual_treatment_hour, "actual_treatment_minute": actual_treatment_minute}).Error
  901. return
  902. }
  903. func CreateDialysisBeforePrepare(beforePrepares []*models.DialysisBeforePrepare) (err error) {
  904. if len(beforePrepares) > 0 {
  905. utx := writeDb.Begin()
  906. if len(beforePrepares) > 0 {
  907. thisSQL := "INSERT INTO dialysis_before_prepare (user_org_id, patient_id, record_date, good_id, good_type_id,count,ctime,mtime,creater,modifier,status) VALUES "
  908. insertParams := make([]string, 0)
  909. insertData := make([]interface{}, 0)
  910. for _, prepare := range beforePrepares {
  911. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  912. insertData = append(insertData, prepare.UserOrgId)
  913. insertData = append(insertData, prepare.PatientId)
  914. insertData = append(insertData, prepare.RecordDate)
  915. insertData = append(insertData, prepare.GoodId)
  916. insertData = append(insertData, prepare.GoodTypeId)
  917. insertData = append(insertData, prepare.Count)
  918. insertData = append(insertData, prepare.Ctime)
  919. insertData = append(insertData, prepare.Mtime)
  920. insertData = append(insertData, prepare.Creater)
  921. insertData = append(insertData, prepare.Modifier)
  922. insertData = append(insertData, 1)
  923. }
  924. thisSQL += strings.Join(insertParams, ", ")
  925. err = utx.Exec(thisSQL, insertData...).Error
  926. if err != nil {
  927. utx.Rollback()
  928. return
  929. }
  930. }
  931. utx.Commit()
  932. }
  933. return
  934. }
  935. func UpdateDialysisBeforePrepare(info *models.DialysisBeforePrepare) (err error) {
  936. err = writeDb.Save(&info).Error
  937. return err
  938. }
  939. func UpdateDialysisBeforePrepareTwo(info *models.DialysisBeforePrepare) (err error) {
  940. err = writeDb.Model(&models.DialysisBeforePrepare{}).
  941. Where("status = 1 AND good_id = ? AND good_type_id = ? AND patient_id = ? AND user_org_id = ? AND record_date = ?", info.GoodId, info.GoodTypeId, info.PatientId, info.UserOrgId, info.RecordDate).
  942. Updates(map[string]interface{}{"count": info.Count, "updated_time": time.Now().Unix(), "modifier": info.Modifier}).Error
  943. return err
  944. }
  945. func UpdateOrderCountSub(good_type_id int64, good_id int64, number string, org_id int64, count int64) {
  946. writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).UpdateColumn("count", gorm.Expr("count - ?", count))
  947. }
  948. func UpdateOrderCountAdd(good_type_id int64, good_id int64, number string, org_id int64, count int64) {
  949. writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).UpdateColumn("count", gorm.Expr("count + ?", count))
  950. }
  951. func UpdateUserInfoDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.WarehouseOutInfo) {
  952. writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"count": count})
  953. //writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber).UpdateColumn("count", count)
  954. }
  955. func UpdateDrugUserInfoDetails(drug_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.DrugWarehouseOutInfo) {
  956. writeDb.Model(&models.DrugAutomaticReduceDetail{}).Where("drug_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", drug_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"count": count})
  957. //writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber).UpdateColumn("count", count)
  958. }
  959. func FindDialysisBeforePrepare(patient_id int64, good_id int64, good_type_id int64, user_org_id int64, record_time int64) (count int64) {
  960. readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND good_id = ? AND good_type_id = ? AND record_date = ? AND status = 1", user_org_id, patient_id, good_id, good_type_id, record_time).Count(&count)
  961. return
  962. }
  963. func GetExecutionDoctors(orgid int64, patientid int64, id int64) (doctorAdvice []*models.DoctorAdvice, err error) {
  964. err = readDb.Model(&doctorAdvice).Where("user_org_id = ? and patient_id = ? AND (id = ? Or parent_id=?) and status = 1", orgid, patientid, id, id).Find(&doctorAdvice).Error
  965. return doctorAdvice, err
  966. }
  967. func GetHisExecutionDoctors(orgid int64, patientid int64, id int64) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) {
  968. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and patient_id = ? AND (id = ? Or parent_id=?) and status = 1", orgid, patientid, id, id).Find(&doctorAdvice).Error
  969. return doctorAdvice, err
  970. }
  971. func FindHisDoctorAdviceById(orgID int64, id int64) (advice models.HisDoctorAdviceInfo, err error) {
  972. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error
  973. return
  974. }
  975. func SaveHisDoctorAdvice(advice *models.HisDoctorAdviceInfo) (err error) {
  976. err = writeDb.Save(&advice).Error
  977. return
  978. }