dialysis_service.go 111KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470
  1. package service
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. // GetPatientList 返回患者的列表
  12. func GetSchedualPatientList(orgID int64, schedulDate int64, schedulType int64, partitionType int64, keywords string, page int64, limit int64) (schedule []*models.DialysisSchedule, err error) {
  13. var total int64
  14. //if len(keywords) > 0 {
  15. // likeKey := "%" + keywords + "%"
  16. // //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)
  17. // db = readDb.
  18. // Model(&models.MonitorDialysisSchedule{}).
  19. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  20. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  21. // Preload("TreatmentMode", "status = 1").
  22. // Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  23. // Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  24. // Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  25. // Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  26. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  27. // Preload("MonitorPatients", "status = 1 AND user_org_id = ? AND `name` LIKE ?", orgID,likeKey)
  28. //
  29. //
  30. //} else {
  31. //}
  32. db := readDb.
  33. Model(&models.MonitorDialysisSchedule{}).
  34. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  35. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  36. Preload("TreatmentMode", "status = 1").
  37. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, schedulDate).
  38. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate).
  39. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate).
  40. Preload("MonitoringRecord", "status = 1 AND user_org_id = ? AND monitoring_date = ?", orgID, schedulDate).
  41. Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, schedulDate).
  42. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  43. db = db.Where("status = 1")
  44. if schedulDate > 0 {
  45. db = db.Where("schedule_date = ?", schedulDate)
  46. }
  47. db = db.Count(&total)
  48. fmt.Println(total)
  49. if schedulType > 0 {
  50. db = db.Where("schedule_type = ?", schedulType)
  51. }
  52. if partitionType > 0 {
  53. db = db.Where("partition_id = ?", partitionType)
  54. }
  55. offset := (page - 1) * limit
  56. errors := db.Offset(offset).Limit(limit).Find(&schedule).Error
  57. return schedule, errors
  58. }
  59. // 用户基本信息
  60. func FindPatientInfoById(orgID int64, id int64, time int64) (patient models.SchedualPatient2, err error) {
  61. err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
  62. 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)
  63. }).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
  64. return
  65. }
  66. // 透析处方
  67. func FindPatientPrescribeById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescription, err error) {
  68. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
  69. return
  70. }
  71. // 透析方案中的透析处方
  72. func FindDialysisSolution(orgID int64, patientsId int64) (patient models.DialysisSolution, err error) {
  73. err = readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id=? and status=1", patientsId, orgID).Last(&patient).Error
  74. return
  75. }
  76. // 透析方案中的透析模式
  77. func FindTreatmentModeById(modeId int64) (mode models.TreatmentMode, err error) {
  78. err = readDb.Model(&models.TreatmentMode{}).Where("id = ? AND status=1", modeId).First(&mode).Error
  79. return
  80. }
  81. // 接诊评估
  82. func FindReceiverTreatmentAccessRecordById(orgID int64, patientsId int64, recordDate int64) (receiveTreatmentAsses models.ReceiveTreatmentAsses, err error) {
  83. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ?", patientsId, orgID, recordDate).First(&receiveTreatmentAsses).Error
  84. return
  85. }
  86. // 透前评估
  87. func FindPredialysisEvaluationById(orgID int64, patientsId int64, recordDate int64) (patient models.PredialysisEvaluation, err error) {
  88. err = readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date = ?", patientsId, orgID, recordDate).First(&patient).Error
  89. return
  90. }
  91. func FindPredialysisName(id int64, orgid int64) (models.Dataconfig, error) {
  92. dataconfig := models.Dataconfig{}
  93. err := readDb.Where("value = ? and org_id =? and status = 1", id, orgid).Find(&dataconfig).Error
  94. return dataconfig, err
  95. }
  96. // 临时医嘱
  97. func FindDoctorAdviceById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) {
  98. 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
  99. return
  100. }
  101. func FindDoctorAdviceByInfo(orgID int64, patientsId int64, recordDate int64) (advices []*models.XtDoctorAdvice, err error) {
  102. //db := readDb.Table("xt_doctor_advice as a").Where("a.status = ?", 1)
  103. //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
  104. //return
  105. err = readDb.Model(&models.DoctorAdvice{}).
  106. Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and advice_type = 2", patientsId, orgID, recordDate).
  107. 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").
  108. Find(&advices).Error
  109. return
  110. }
  111. func GetTotalDialysisCout(orgid int64, patientid int64) (order []*models.DialysisOrder, total int64, err error) {
  112. err = readDb.Model(&order).Where("user_org_id = ? and patient_id = ? and status = 1", orgid, patientid).Find(&order).Count(&total).Error
  113. return order, total, err
  114. }
  115. // 临时医嘱
  116. func FindDoctorAdviceOrderById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) {
  117. err = readDb.Model(&models.DoctorAdvice{}).
  118. Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientsId, orgID, recordDate).
  119. 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").
  120. Find(&patient).Error
  121. return
  122. }
  123. // 双人核对
  124. func FindDoubleCheckById(orgID int64, patientsId int64, recordDate int64) (patient models.DoubleCheck, err error) {
  125. err = readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id=? and status=1 and check_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
  126. return
  127. }
  128. // 透析监测
  129. func FindAllMonitorRecord(orgID int64, patientsId int64, recordDate int64) (record []*models.MonitoringRecord, err error) {
  130. 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
  131. return
  132. }
  133. func FindAllMonitor(orgID int64, patientsId int64, recordDate int64) (record []*models.MonitoringRecord, err error) {
  134. 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
  135. return
  136. }
  137. // 透后评估
  138. func FindAssessmentAfterDislysisById(orgID int64, patientsId int64, recordDate int64) (patient models.AssessmentAfterDislysis, err error) {
  139. err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date =?", patientsId, orgID, recordDate).First(&patient).Error
  140. return
  141. }
  142. // 治疗小结
  143. func FindTreatmentSummaryById(orgID int64, patientsId int64, recordDate int64) (patient models.TreatmentSummary, err error) {
  144. err = readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
  145. return
  146. }
  147. // 机构叫号配置
  148. func FindQueueCallInfo(orgID int64) (queueConfig models.QueueCallConfig, err error) {
  149. err = readDb.Model(&models.QueueCallConfig{}).Where("org_id=? ", orgID).First(&queueConfig).Error
  150. return
  151. }
  152. // 修改机构叫号配置
  153. func UpDateQueueCallInfo(queueConfig models.QueueCallConfig) error {
  154. err := writeDb.Save(&queueConfig).Error
  155. return err
  156. }
  157. // 所有设备信息
  158. func FindAllDeviceInfo(orgID int64) (device []*models.Device, err error) {
  159. err = readDb.Model(&models.Device{}).Where("org_id=? and status=1 and device_type = 1", orgID).Find(&device).Error
  160. return device, err
  161. }
  162. // 所有设备区域
  163. func GetAllDeviceZone(orgId int64) (error, []*models.DeviceZone) {
  164. var zone []*models.DeviceZone
  165. err := readDb.Model(&zone).Where("org_id = ? AND status = 1", orgId).Find(&zone).Error
  166. return err, zone
  167. }
  168. // 获取所有子药物
  169. func FindAllSubDoctorAdvice(id int64, parentId int64) (error, []models.DoctorAdvice) {
  170. var subAdvies []models.DoctorAdvice
  171. err := readDb.Model(&subAdvies).Where("patient_id = ? AND parent_id = ?", id, parentId).Find(&subAdvies).Error
  172. return err, subAdvies
  173. }
  174. func FindAdivceById(orgId int64, patientId int64, id int64) (error, models.DoctorAdvice) {
  175. advices := models.DoctorAdvice{}
  176. err := readDb.Model(&advices).Where("user_org_id = ? AND patient_id = ? AND id = ? AND status = 1", orgId, patientId, id).Find(&advices).Error
  177. return err, advices
  178. }
  179. func FindSubAdivceById(patientId int64, parentId int64) []*models.DoctorAdvice {
  180. var subAdvices []*models.DoctorAdvice
  181. readDb.Model(&subAdvices).Where("patient_id = ? AND parent_id = ?", patientId, parentId).Find(&subAdvices)
  182. return subAdvices
  183. }
  184. func AddSigleRecord(prescription *models.DialysisPrescription) (err error) {
  185. tx := writeDb.Begin()
  186. errors := tx.Model(&models.DialysisPrescription{}).Create(&prescription).Error
  187. if err != nil {
  188. tx.Rollback()
  189. }
  190. tx.Commit()
  191. return errors
  192. }
  193. func UpdateAddSigleRecord(id int64, target_ultrafiltration float64) error {
  194. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"target_ultrafiltration": target_ultrafiltration, "prescription_water": target_ultrafiltration}).Error
  195. return err
  196. }
  197. func AddSigleSummaryRecord(summary *models.TreatmentSummary) (err error) {
  198. tx := writeDb.Begin()
  199. errors := tx.Model(&models.TreatmentSummary{}).Create(&summary).Error
  200. if err != nil {
  201. tx.Rollback()
  202. }
  203. tx.Commit()
  204. return errors
  205. }
  206. func AddSigleReceiveTreatmentAssesRecord(receiveTreatmentAsses *models.ReceiveTreatmentAsses) (err error) {
  207. tx := writeDb.Begin()
  208. errors := tx.Model(&models.ReceiveTreatmentAsses{}).Create(&receiveTreatmentAsses).Error
  209. if err != nil {
  210. tx.Rollback()
  211. }
  212. tx.Commit()
  213. return errors
  214. }
  215. func AddSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis *models.AssessmentAfterDislysis) (err error) {
  216. tx := writeDb.Begin()
  217. errors := tx.Model(&models.AssessmentAfterDislysis{}).Create(&assessmentAfterDislysis).Error
  218. if err != nil {
  219. tx.Rollback()
  220. }
  221. tx.Commit()
  222. return errors
  223. }
  224. func AddSigleAssessmentBeforeDislysisRecord(assessmentBeforeDislysis *models.PredialysisEvaluation) (err error) {
  225. tx := writeDb.Begin()
  226. errors := tx.Model(&models.PredialysisEvaluation{}).Create(&assessmentBeforeDislysis).Error
  227. if err != nil {
  228. tx.Rollback()
  229. }
  230. tx.Commit()
  231. return errors
  232. }
  233. func AddSigleDoubleCheck(check *models.DoubleCheck) (err error) {
  234. tx := writeDb.Begin()
  235. errors := tx.Model(&models.DoubleCheck{}).Create(&check).Error
  236. if err != nil {
  237. tx.Rollback()
  238. }
  239. tx.Commit()
  240. return errors
  241. }
  242. // 修改透析处方
  243. func UpDateDialysisPrescription(dialysisPrescription *models.DialysisPrescription) error {
  244. tx := writeDb.Begin()
  245. err := writeDb.Save(&dialysisPrescription).Error
  246. if err != nil {
  247. tx.Rollback()
  248. }
  249. tx.Commit()
  250. return err
  251. }
  252. // 修改接诊评估
  253. func UpadateReceiveTreatmentAsses(receiveTreatmentAsses *models.ReceiveTreatmentAsses) error {
  254. err := writeDb.Save(receiveTreatmentAsses).Error
  255. return err
  256. }
  257. // 修改透前评估
  258. func UpadatePredialysisEvaluation(predialysisEvaluation *models.PredialysisEvaluation) error {
  259. err := writeDb.Save(&predialysisEvaluation).Error
  260. return err
  261. }
  262. // 修改双人核对
  263. func UpdateDoubleCheck(check *models.DoubleCheck) error {
  264. err := writeDb.Save(&check).Error
  265. return err
  266. }
  267. // 修改透后评估
  268. func UpdateAssessmentAfterDislysisRecord(assessmentAfterDislysis *models.AssessmentAfterDislysis) error {
  269. err := writeDb.Save(&assessmentAfterDislysis).Error
  270. return err
  271. }
  272. func UpdatePredialysisEvaluation(predialysisevaluation *models.PredialysisEvaluation, id int64) error {
  273. err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"systolic_blood_pressure": predialysisevaluation.SystolicBloodPressure}).Error
  274. return err
  275. }
  276. func UpdatePredialysisEvaluationTwo(predialysisevaluation *models.PredialysisEvaluation, id int64) error {
  277. err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"diastolic_blood_pressure": predialysisevaluation.DiastolicBloodPressure}).Error
  278. return err
  279. }
  280. func UpdatePredialysisEvaluationThree(predialysisevaluation *models.PredialysisEvaluation, id int64) error {
  281. err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"pulse_frequency": predialysisevaluation.PulseFrequency}).Error
  282. return err
  283. }
  284. func UpdatePredialysisEvaluationFour(predialysisevaluation *models.PredialysisEvaluation, id int64) error {
  285. err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"temperature": predialysisevaluation.Temperature}).Error
  286. return err
  287. }
  288. // 修改
  289. func UpdateSummeRecord(treatmentSummary *models.TreatmentSummary) error {
  290. err := writeDb.Save(&treatmentSummary).Error
  291. return err
  292. }
  293. // func UpdateDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
  294. // tx := writeDb.Begin()
  295. // 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
  296. // if err != nil {
  297. // tx.Rollback()
  298. // }
  299. // tx.Commit()
  300. // return err
  301. // }
  302. func ExceDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
  303. 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
  304. return err
  305. }
  306. func ExecBatchDoctorAdvice(patient_id int64, orgid int64, ids []string, creater int64) error {
  307. err := writeDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND user_org_id = ? and id in(?) AND status = 1 ", patient_id, orgid, ids).Updates(map[string]interface{}{"execution_time": time.Now().Unix(), "execution_staff": creater, "execution_state": 1}).Error
  308. return err
  309. }
  310. func ExceHidDoctorAdviceById(m *models.HisDoctorAdviceInfo, id int64, patientId int64) error {
  311. 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, "is_mobile": 2}).Error
  312. return err
  313. }
  314. func ExceHisBatchDotorAdvice(patientid int64, orgid int64, ids []string, creater int64) error {
  315. err := writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND user_org_id = ? and id in(?) AND status = 1 ", patientid, orgid, ids).Updates(map[string]interface{}{"execution_time": time.Now().Unix(), "execution_staff": creater, "execution_state": 1}).Error
  316. return err
  317. }
  318. func CheckDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
  319. 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
  320. return err
  321. }
  322. func CheckHisBathDoctorAdviceById(patientId int64, orgid int64, creater int64, ids []string) error {
  323. err := writeDb.Model(&models.HisDoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and id in(?)", patientId, orgid, ids).Updates(map[string]interface{}{"check_time": time.Now().Unix(), "checker": creater, "check_state": 1}).Error
  324. return err
  325. }
  326. func CheckBatchDoctorAdviceById(patientId int64, ids []string, orgid int64, creater int64) error {
  327. err := writeDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and id in(?)", patientId, orgid, ids).Updates(map[string]interface{}{"check_time": time.Now().Unix(), "checker": creater, "check_state": 1}).Error
  328. return err
  329. }
  330. func CheckHisDoctorAdviceById(m *models.HisDoctorAdviceInfo, id int64, patientId int64) error {
  331. 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
  332. return err
  333. }
  334. func CreateMonitor(m *models.MonitoringRecord) (err error) {
  335. return writeDb.Create(m).Error
  336. }
  337. func UpdateMonitor(m *models.MonitoringRecord) (err error) {
  338. return writeDb.Save(m).Error
  339. }
  340. func DelMonitor(patientId int64, recordId int64) error {
  341. tx := writeDb.Begin()
  342. updateTime := time.Now().Unix()
  343. 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
  344. if err != nil {
  345. tx.Rollback()
  346. }
  347. tx.Commit()
  348. return err
  349. }
  350. //修改长期处方
  351. func UpdateSolution(solution *models.DialysisSolution) {
  352. writeDb.Save(&solution)
  353. }
  354. // 创建长期处方
  355. func CreateSolution(solution *models.DialysisSolution) {
  356. writeDb.Create(&solution)
  357. }
  358. func SavePrescriptionAndCreateSolution(solution *models.DialysisSolution, prescription *models.DialysisPrescription) (err error) {
  359. tx := writeDb.Begin()
  360. if prescription.ID > 0 {
  361. err = tx.Save(&prescription).Error
  362. } else {
  363. err = tx.Model(&models.DialysisPrescription{}).Create(&prescription).Error
  364. }
  365. if err != nil {
  366. tx.Rollback()
  367. return
  368. }
  369. err = tx.Create(&solution).Error
  370. if err != nil {
  371. tx.Rollback()
  372. return
  373. }
  374. tx.Commit()
  375. return
  376. }
  377. // 透析处方
  378. func FindDialysisPrescriptionByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DialysisPrescription) {
  379. dialysisPrescription := models.DialysisPrescription{}
  380. err := readDb.Model(&dialysisPrescription).Where("patient_id = ? AND record_date = ? AND status = 1 AND user_org_id = ? ", id, recordDate, orgId).Find(&dialysisPrescription).Error
  381. return err, &dialysisPrescription
  382. }
  383. func FindReceiveTreatmentAssesByReordDate(id int64, recordDate int64, orgId int64) (error, *models.ReceiveTreatmentAsses) {
  384. receiveTreatmentAsses := models.ReceiveTreatmentAsses{}
  385. err := readDb.Model(&receiveTreatmentAsses).Where("patient_id = ? AND record_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).Find(&receiveTreatmentAsses).Error
  386. return err, &receiveTreatmentAsses
  387. }
  388. // 透前评估
  389. func FindPredialysisEvaluationByReordDate(id int64, recordDate int64, orgId int64) (error, *models.PredialysisEvaluation) {
  390. dialysisEvaluation := models.PredialysisEvaluation{}
  391. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&dialysisEvaluation).Error
  392. return err, &dialysisEvaluation
  393. }
  394. // 双人核对
  395. func FindDoubleCheckByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DoubleCheck) {
  396. check := models.DoubleCheck{}
  397. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? AND check_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&check).Error
  398. return err, &check
  399. }
  400. func FindAssessmentAfterDislysisByReordDate(id int64, recordDate int64, orgId int64) (error, *models.AssessmentAfterDislysis) {
  401. assessmentAfterDislysis := models.AssessmentAfterDislysis{}
  402. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&assessmentAfterDislysis).Error
  403. return err, &assessmentAfterDislysis
  404. }
  405. func FindTreatmentSummaryByReordDate(id int64, recordDate int64, orgId int64) (error, *models.TreatmentSummary) {
  406. summary := models.TreatmentSummary{}
  407. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&summary).Error
  408. return err, &summary
  409. }
  410. func FindDoctorAdviceByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DoctorAdvice) {
  411. advice := models.DoctorAdvice{}
  412. 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
  413. return err, &advice
  414. }
  415. func FindDialysisRecordById(orgId int64, id int64, recordDate int64) (error, *models.DialysisOrder) {
  416. var count int64
  417. dialysisRecord := models.DialysisOrder{}
  418. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgId, id, recordDate).Find(&dialysisRecord).Count(&count).Error
  419. if count <= 0 {
  420. return err, nil
  421. }
  422. return err, &dialysisRecord
  423. }
  424. func FindDialysisSchedualById(orgId int64, id int64, recordDate int64) (error, *models.Schedule) {
  425. var count int64
  426. schedule := models.Schedule{}
  427. err := readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND patient_id = ? AND schedule_date = ?", orgId, id, recordDate).Find(&schedule).Count(&count).Error
  428. if count <= 0 {
  429. return err, nil
  430. }
  431. return err, &schedule
  432. }
  433. func CreateDialysisRecord(id int64, orgId int64, record *models.DialysisOrder) error {
  434. err := writeDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? ", orgId, id).Create(&record).Error
  435. if err != nil {
  436. return err
  437. }
  438. dialysisPrescriptionErr := UpDateRecordIdToDialysisPrescription(id, orgId, record.DialysisDate, record.ID)
  439. if dialysisPrescriptionErr != nil {
  440. return dialysisPrescriptionErr
  441. }
  442. receiveTreatmentAssesErr := UpDateRecordIdToReceiveTreatmentAsses(id, orgId, record.DialysisDate, record.ID)
  443. if receiveTreatmentAssesErr != nil {
  444. return receiveTreatmentAssesErr
  445. }
  446. predialysisEvaluationErr := UpDateRecordIdToPredialysisEvaluation(id, orgId, record.DialysisDate, record.ID)
  447. if predialysisEvaluationErr != nil {
  448. return predialysisEvaluationErr
  449. }
  450. treatmentSummaryErr := UpDateRecordIdToTreatmentSummary(id, orgId, record.DialysisDate, record.ID)
  451. if treatmentSummaryErr != nil {
  452. return treatmentSummaryErr
  453. }
  454. doubleCheckErr := UpDateRecordIdToDoubleCheck(id, orgId, record.DialysisDate, record.ID)
  455. if doubleCheckErr != nil {
  456. return doubleCheckErr
  457. }
  458. adviceErrr := UpDateRecordIdToDoctorAdvice(id, orgId, record.DialysisDate, record.ID)
  459. if adviceErrr != nil {
  460. return adviceErrr
  461. }
  462. //透析监测
  463. records, err := FindAllMonitorRecord(orgId, id, record.DialysisDate)
  464. if err != nil {
  465. return err
  466. }
  467. var Ids []int64
  468. for _, item := range records {
  469. Ids = append(Ids, item.ID)
  470. }
  471. monitorErr := UpDateRecordIdToMonitor(Ids, record.ID)
  472. if monitorErr != nil {
  473. return monitorErr
  474. }
  475. return nil
  476. }
  477. func ModifyDialysisRecord(id int64, finishNurse int64, end_time int64, admin_user_id int64, puncture_point_haematoma int64, internal_fistula string, catheter string, cruor string, mission string, condenser string) error {
  478. 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, "puncture_point_haematoma": puncture_point_haematoma, "blood_access_internal_fistula": internal_fistula, "catheter": catheter, "cruor": cruor, "mission": mission, "condenser": condenser}).Error
  479. return err
  480. }
  481. //func ModifyDialysisRecord(id int64, finishNurse int64, end_time int64, admin_user_id int64) error {
  482. // 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
  483. // return err
  484. //
  485. //}
  486. func UpdateSolutionByPatientId(id int64) error {
  487. err := writeDb.Model(&models.Patients{}).Where("id = ? AND status = 1 ", id).UpdateColumn("total_dialysis", gorm.Expr("total_dialysis + ?", 1)).Error
  488. return err
  489. }
  490. // 更新透析处方记录ID
  491. func UpDateRecordIdToDialysisPrescription(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  492. 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
  493. return errors
  494. }
  495. func UpDateRecordIdToReceiveTreatmentAsses(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  496. 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
  497. return errors
  498. }
  499. func UpDateRecordIdToPredialysisEvaluation(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  500. 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
  501. return errors
  502. }
  503. func UpDateRecordIdToAssessmentAfterDislysis(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  504. 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
  505. return errors
  506. }
  507. func UpDateRecordIdToTreatmentSummary(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  508. 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
  509. return errors
  510. }
  511. func UpDateRecordIdToMonitor(Ids []int64, recordId int64) error {
  512. errors := writeDb.Model(&models.MonitoringRecord{}).Where("id IN (?)", Ids).Update(map[string]interface{}{"dialysis_order_id": recordId}).Error
  513. return errors
  514. }
  515. func UpDateRecordIdToDoubleCheck(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  516. 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
  517. return errors
  518. }
  519. func UpDateRecordIdToDoctorAdvice(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  520. 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
  521. return errors
  522. }
  523. // 透析处方
  524. func FindPatientPrescribeWidyDevideById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescriptionAddtional, err error) {
  525. err = readDb.Preload("Device", "status = 1 AND org_id = ?", orgID).
  526. Model(&models.DialysisPrescriptionAddtional{}).
  527. Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? ", patientsId, orgID, recordDate).
  528. First(&patient).Error
  529. return
  530. }
  531. func FindDialysisMode(orgID int64, patientId int64, scheduleDate int64) (models.XtSchedule, error) {
  532. schedule := models.XtSchedule{}
  533. err = readDb.Where("user_org_id = ? and patient_id = ? and schedule_date = ? ", orgID, patientId, scheduleDate).Find(&schedule).Error
  534. return schedule, err
  535. }
  536. func FindDialysisMacher(orgid int64, patientid int64, dialysisDate int64) (models.XtDialysisOrders, error) {
  537. orders := models.XtDialysisOrders{}
  538. db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
  539. table := readDb.Table("xt_device_number as n")
  540. fmt.Print("table", table)
  541. 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,o.quality_nurse_id,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
  542. return orders, err
  543. }
  544. func FindPunctureNurse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  545. role := models.App_Roles{}
  546. //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error
  547. //return role, err
  548. db := UserReadDB().Table("sgj_user_admin_role as r")
  549. 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
  550. return role, err
  551. }
  552. func FindeStartNuse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  553. role := models.App_Roles{}
  554. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  555. 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
  556. //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error
  557. return role, err
  558. }
  559. func FindeQualityNurse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  560. role := models.App_Roles{}
  561. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  562. 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
  563. return role, err
  564. }
  565. func FindDialysisWay(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  566. prescription := models.DialysisPrescription{}
  567. err := readDb.Where("user_org_id = ? and patient_id = ? and record_date = ? and status =1", orgid, patientid, recorddate).Find(&prescription).Error
  568. return prescription, err
  569. }
  570. func FindDoctorOrder(orgid int64, patientid int64, adviceDate int64) (models.XtDoctorAdvice, error) {
  571. advices := models.XtDoctorAdvice{}
  572. db := readDb.Table("xt_doctor_advice as a").Where("a.status = ?", 1)
  573. 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
  574. return advices, err
  575. }
  576. func FindDoctor(adminuserid int64, appid int64, orgid int64) (models.App_Role, error) {
  577. role := models.App_Role{}
  578. err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminuserid, appid, orgid).Find(&role).Error
  579. return role, err
  580. }
  581. func FindDoctorName(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  582. role := models.App_Roles{}
  583. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  584. 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
  585. //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error
  586. return role, err
  587. }
  588. // ///////////// 新 18-10-22
  589. func GetDialysisScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  590. var vms []*MDialysisScheduleVM
  591. db := readDb.
  592. Table("xt_schedule").
  593. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  594. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  595. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  596. Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
  597. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  598. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  599. Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  600. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  601. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  602. Where("status = 1 AND user_org_id = ?", orgID)
  603. if scheduleDate != 0 {
  604. db = db.Where("schedule_date = ?", scheduleDate)
  605. }
  606. err := db.Find(&vms).Error
  607. return vms, err
  608. }
  609. func GetDialysisSchedualsOne(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  610. var vms []*MDialysisScheduleVM
  611. db := readDb.
  612. Table("xt_schedule").
  613. Preload("DeviceNumber", "org_id = ?", orgID).
  614. Preload("DeviceNumber.Zone", "org_id = ?", orgID).
  615. //Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
  616. //Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  617. //Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  618. //Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  619. //Preload("Advices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  620. //Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  621. Where("status = 1 AND user_org_id = ?", orgID)
  622. if scheduleDate != 0 {
  623. db = db.Where("schedule_date = ?", scheduleDate)
  624. }
  625. err := db.Find(&vms).Error
  626. return vms, err
  627. }
  628. func GetLastAcceptsAssessment(patient int64, orgId int64) (error, models.ReceiveTreatmentAsses) {
  629. var receiveTreatmentAsses models.ReceiveTreatmentAsses
  630. err := readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? AND status = 1 AND user_org_id = ?", patient, orgId).Last(&receiveTreatmentAsses).Error
  631. return err, receiveTreatmentAsses
  632. }
  633. func GetDialysisWatch(orgID int64, schedulDate int64, schedulType int64, partitionType int64, page int64, limit int64, start int64, end int64) (schedule []*models.DialysisSchedule, err error, total int64) {
  634. db := readDb.Model(&models.MonitorDialysisSchedule{})
  635. if start > 0 && end > 0 {
  636. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  637. Preload("TreatmentMode", "status = 1").
  638. Preload("MonitoringRecord", func(db *gorm.DB) *gorm.DB {
  639. return db.Where("status = 1 AND user_org_id = ? and monitoring_date >=? and monitoring_date<=? ", orgID, start, end).Order("operate_time asc")
  640. })
  641. db = db.Where("xt_schedule.status = 1")
  642. }
  643. if schedulDate > 0 {
  644. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  645. Preload("TreatmentMode", "status = 1").
  646. Preload("MonitoringRecord", func(db *gorm.DB) *gorm.DB {
  647. return db.Where("status = 1 AND user_org_id = ? and monitoring_date >=? and monitoring_date<=? ", orgID, schedulDate, schedulDate).Order("operate_time asc")
  648. })
  649. db = db.Where("xt_schedule.status = 1")
  650. db = db.Where("schedule_date = ?", schedulDate)
  651. }
  652. if schedulType > 0 {
  653. db = db.Where("schedule_type = ?", schedulType)
  654. }
  655. if start > 0 {
  656. db = db.Where("schedule_date >= ?", start)
  657. }
  658. if end > 0 {
  659. db = db.Where("schedule_date <= ?", end)
  660. }
  661. if orgID > 0 {
  662. db = db.Where("user_org_id = ?", orgID)
  663. }
  664. if partitionType > 0 {
  665. db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ?", partitionType)
  666. }
  667. offset := (page - 1) * limit
  668. err = db.Count(&total).Offset(offset).Limit(limit).Order("bed_id desc").Find(&schedule).Error
  669. return schedule, err, total
  670. }
  671. //func GetDialysisWatchByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64) (schedules []*models.DialysisSchedule, err error, total int64) {
  672. // db := readDb.Model(&models.DialysisSchedule{}).Where("status = 1")
  673. //
  674. // if schedulType > 0 {
  675. // db = db.Where("scheudle_type = ?", schedulType)
  676. // }
  677. //
  678. // if partitionType > 0 {
  679. // db = db.Where("partition_id = ?", partitionType)
  680. // }
  681. //
  682. // err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
  683. // return schedules, err, total
  684. //}
  685. func GetDialysisWatchByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64, start int64, end int64) ([]*models.DialysisSchedule, error, int64) {
  686. var patients []*models.Patients
  687. 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
  688. if getPatientErr != nil {
  689. return nil, getPatientErr, 0
  690. }
  691. patientIDs := make([]int64, len(patients))
  692. for index, patient := range patients {
  693. patientIDs[index] = patient.ID
  694. }
  695. db := readDb.Model(&models.DialysisSchedule{})
  696. if start > 0 && end > 0 {
  697. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  698. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  699. Preload("TreatmentMode", "status = 1").
  700. Preload("Prescription", "status = 1 AND user_org_id = ? and record_date>=? and record_date<=?", orgID, start, end).
  701. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date>=? and assessment_date<=?", orgID, start, end).
  702. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date>=? and assessment_date<=?", orgID, start, end).
  703. Preload("MonitoringRecord", "status = 1 AND user_org_id = ? and monitoring_date>=? and monitoring_date<=?", orgID, start, end).
  704. Preload("DialysisOrder", "status = 1 AND user_org_id = ? and dialysis_date >= ? and dialysis_date<=?", orgID, start, end).
  705. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  706. } else {
  707. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  708. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  709. Preload("TreatmentMode", "status = 1").
  710. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  711. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  712. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  713. Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  714. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  715. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  716. }
  717. db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
  718. if schedulType > 0 {
  719. db = db.Where("schedule_type = ?", schedulType)
  720. }
  721. if start > 0 {
  722. db = db.Where("schedule_date >= ?", start)
  723. }
  724. if end > 0 {
  725. db = db.Where("schedule_date<=?", end)
  726. }
  727. if partitionType > 0 {
  728. db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ?", partitionType)
  729. // db = db.Where("partition_id = ?", partitionType)
  730. }
  731. var schedules []*models.DialysisSchedule
  732. total := int64(0)
  733. err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
  734. return schedules, err, total
  735. }
  736. func GetAdminUserES(orgID int64, appID int64, ids []int64) (es []*models.AdminUserElectronicSignature, err error) {
  737. err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id=? and creator in (?) and status=1", orgID, appID, ids).Find(&es).Error
  738. return
  739. }
  740. //
  741. //func GetAdminUserEsOne(orgid int64) (admin []*models.UserAdminRoles, err error) {
  742. //
  743. // db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1")
  744. // table := readUserDb.Table("sgj_user_admin_electronic_signature as s")
  745. // fmt.Println("table", table)
  746. // 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
  747. // return admin, err
  748. //}
  749. func GetAdminUserEsOne(orgid int64) (admin []*models.UserAdminRoles, err error) {
  750. db := readUserDb.Table("sgj_user_admin_role as x")
  751. table := readUserDb.Table("sgj_user_admin_electronic_signature as s")
  752. fmt.Println("table", table)
  753. 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
  754. return admin, err
  755. }
  756. func UpDateDialysisPrescriptionDoctorSign(patient int64, date int64, orgId int64, doctor_id int64) (err error) {
  757. 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
  758. return
  759. }
  760. func GetAllAdminUserES(orgID int64, appId int64) (es []*models.AdminUserElectronicSignature, err error) {
  761. err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id = ? and status=1", orgID, appId).Find(&es).Error
  762. return
  763. }
  764. func GetAllStarfEs(orgid int64) (es []*models.SgjUserAdminRoles, err error) {
  765. redis := RedisClient()
  766. defer redis.Close()
  767. // cur_date := time.Now().Format("2006-01-02")
  768. key := strconv.FormatInt(orgid, 10) + ":starfes"
  769. starfes_str, _ := redis.Get(key).Result()
  770. redis.Set(key, "", time.Second)
  771. if len(starfes_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  772. db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1")
  773. 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
  774. if err != nil {
  775. if err == gorm.ErrRecordNotFound {
  776. if len(es) <= 0 {
  777. redis.Set(key, "starfes_str_null", time.Second*60*60*18)
  778. }
  779. return nil, nil
  780. } else {
  781. return nil, err
  782. }
  783. } else {
  784. if len(es) > 0 {
  785. //缓存数据
  786. starfes_str, err := json.Marshal(es)
  787. if err == nil {
  788. redis.Set(key, starfes_str, time.Second*60*60*18)
  789. return es, nil
  790. }
  791. } else {
  792. redis.Set(key, "starfes_str_null", time.Second*60*60*18)
  793. return es, nil
  794. }
  795. return es, nil
  796. }
  797. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  798. if starfes_str == "starfes_str_null" {
  799. return es, nil
  800. } else {
  801. json.Unmarshal([]byte(starfes_str), &es)
  802. return es, nil
  803. }
  804. }
  805. }
  806. func FindLastMonitorRecord(patient_id int64, org_id int64) (record models.MonitoringRecord, err error) {
  807. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND status = 1 AND user_org_id = ?", patient_id, org_id).Last(&record).Error
  808. return
  809. }
  810. func FindLastMonitorRecordToday(patient_id int64, org_id int64, monitoring_date int64) (record models.MonitoringRecord, err error) {
  811. 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
  812. return
  813. }
  814. func FindFirstMonitorRecordToday(patient_id int64, org_id int64, monitoring_date int64) (record models.MonitoringRecord, err error) {
  815. 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
  816. return
  817. }
  818. func ExceDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  819. ut := writeDb.Begin()
  820. 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
  821. if err != nil {
  822. ut.Rollback()
  823. return
  824. }
  825. ut.Commit()
  826. return err
  827. }
  828. func GetExceDoctorAdviceGroupNo(groupNo int64, org_id int64) (advice []*models.DoctorAdvice, err error) {
  829. err = XTReadDB().Where("groupno = ? AND user_org_id = ? AND status = 1", groupNo, org_id).Find(&advice).Error
  830. return advice, err
  831. }
  832. func ExceOldDoctorAdvice(m *models.DoctorAdvice, advice_id int64) (err error) {
  833. ut := writeDb.Begin()
  834. 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
  835. if err != nil {
  836. ut.Rollback()
  837. return
  838. }
  839. 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
  840. if err != nil {
  841. ut.Rollback()
  842. return
  843. }
  844. ut.Commit()
  845. return err
  846. }
  847. func CheckDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  848. ut := writeDb.Begin()
  849. 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
  850. if err != nil {
  851. ut.Rollback()
  852. return
  853. }
  854. ut.Commit()
  855. return err
  856. }
  857. func CheckDoctorAdviceByGroupNoOne(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  858. ut := writeDb.Begin()
  859. err = ut.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ? AND status = 1", groupNo, org_id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error
  860. if err != nil {
  861. ut.Rollback()
  862. return
  863. }
  864. ut.Commit()
  865. return err
  866. }
  867. func CheckOldDoctorAdvice(m *models.DoctorAdvice, advice_id int64) (err error) {
  868. ut := writeDb.Begin()
  869. 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
  870. if err != nil {
  871. ut.Rollback()
  872. return
  873. }
  874. 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
  875. if err != nil {
  876. ut.Rollback()
  877. return
  878. }
  879. ut.Commit()
  880. return err
  881. }
  882. func DeleteDoctorAdviceByGroupNo(m *models.DoctorAdvice) (err error) {
  883. ut := writeDb.Begin()
  884. 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
  885. if err != nil {
  886. ut.Rollback()
  887. return
  888. }
  889. ut.Commit()
  890. return
  891. }
  892. func GetDialysisBoard(orgID int64, scheduleDate int64, offset, limit int64) ([]*models.DialysisBoardVM, error) {
  893. var boards []*models.DialysisBoardVM
  894. db := readDb.
  895. Table("xt_schedule").
  896. Preload("Patient", "status = 1 AND user_org_id = ?", orgID).
  897. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  898. Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  899. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  900. Preload("SigninAndWeigh", "status = 1 AND user_org_id = ?", orgID).
  901. Preload("NextSchedules", func(db *gorm.DB) *gorm.DB {
  902. return db.Where("user_org_id = ? AND schedule_date > ? AND status = 1", orgID, scheduleDate).
  903. Order("schedule_date asc, id asc")
  904. }).
  905. Where("status = 1 AND user_org_id = ?", orgID)
  906. if scheduleDate != 0 {
  907. db = db.Where("schedule_date = ?", scheduleDate)
  908. }
  909. err := db.Offset(offset).Limit(limit).Find(&boards).Error
  910. return boards, err
  911. }
  912. func GetOneDialysisOrder(orgID, orderData int64, patient_id int64) (*models.DialysisOrder, error) {
  913. var order models.DialysisOrder
  914. var err error
  915. 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
  916. if err == gorm.ErrRecordNotFound {
  917. return nil, nil
  918. }
  919. if err != nil {
  920. return nil, err
  921. }
  922. return &order, nil
  923. }
  924. func GetOneDialysisOrderOne(orgID, orderData int64, patient_id int64) (models.DialysisOrder, error) {
  925. order := models.DialysisOrder{}
  926. err := readDb.Where("user_org_id=? and dialysis_date=? and status=1 and patient_id = ?", orgID, orderData, patient_id).Find(&order).Error
  927. return order, err
  928. }
  929. func GetPscheduleDate(schedule_date int64, patient_id int64, user_org_id int64) (models.XtSchedule, error) {
  930. schedule := models.XtSchedule{}
  931. err := XTReadDB().Where("schedule_date = ? and patient_id = ? and user_org_id =? and status =1").Find(&schedule).Error
  932. return schedule, err
  933. }
  934. func UpdateDialysiOrderByPatientId(id int64, schedule_type int64, partion_id int64, bed_id int64) error {
  935. err := XTWriteDB().Model(&models.DialysisOrder{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"schedual_type": schedule_type, "zone_id": partion_id, "bed_id": bed_id}).Error
  936. return err
  937. }
  938. func GetOrgInfoTemplate(orgID int64) (models.GobalTemplate, error) {
  939. var templateInfo models.GobalTemplate
  940. var err error
  941. err = readDb.Model(&models.GobalTemplate{}).Where("org_id=? and status=1", orgID).First(&templateInfo).Error
  942. return templateInfo, err
  943. }
  944. func FindAdminRoleTypeById(orgId int64, adminUserId int64, appId int64) (models.App_Role, error) {
  945. var appRole models.App_Role
  946. var err error
  947. 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
  948. return appRole, err
  949. }
  950. func BatchExceOldDoctorAdvice(m *models.DoctorAdvice, ids []string) (err error) {
  951. ut := writeDb.Begin()
  952. 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
  953. if err != nil {
  954. ut.Rollback()
  955. return
  956. }
  957. 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
  958. if err != nil {
  959. ut.Rollback()
  960. return
  961. }
  962. ut.Commit()
  963. return err
  964. }
  965. func BatchCheckOldDoctorAdvice(m *models.DoctorAdvice, ids []string, org_id int64, date int64) (err error) {
  966. ut := writeDb.Begin()
  967. 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
  968. if err != nil {
  969. ut.Rollback()
  970. return
  971. }
  972. 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
  973. if err != nil {
  974. ut.Rollback()
  975. return
  976. }
  977. ut.Commit()
  978. return err
  979. }
  980. func ModifyScheduleMode(mode_id int64, patient_id int64, recordDate int64, org_id int64, dialysis_machine_name string) {
  981. ut := writeDb.Begin()
  982. 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, "dialysis_machine_name": dialysis_machine_name}).Error
  983. if err != nil {
  984. ut.Rollback()
  985. return
  986. }
  987. ut.Commit()
  988. }
  989. func ModifyScheduleModeOne(mode_id int64, patient_id int64, recordDate int64, org_id int64, dialysis_machine_name string) {
  990. ut := writeDb.Begin()
  991. err = writeDb.Model(&models.Schedule{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND schedule_date >= ? mode_id= ?", org_id, patient_id, recordDate, mode_id).Updates(map[string]interface{}{"updated_time": time.Now().Unix(), "dialysis_machine_name": dialysis_machine_name}).Error
  992. if err != nil {
  993. ut.Rollback()
  994. return
  995. }
  996. ut.Commit()
  997. }
  998. func FindDialysisOrderById(id int64) (error, *models.DialysisOrder) {
  999. dialysisRecord := models.DialysisOrder{}
  1000. err := readDb.Model(&models.DialysisOrder{}).Where("id = ? AND status = 1", id).Find(&dialysisRecord).Error
  1001. return err, &dialysisRecord
  1002. }
  1003. func ModifyExceDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  1004. ut := writeDb.Begin()
  1005. 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
  1006. if err != nil {
  1007. ut.Rollback()
  1008. return
  1009. }
  1010. ut.Commit()
  1011. return err
  1012. }
  1013. func ModifyExceDoctorAdviceByGroupNoOne(m *models.DoctorAdvice, ids []string) (err error) {
  1014. ut := writeDb.Begin()
  1015. err = ut.Model(&models.DoctorAdvice{}).Where("id in(?) and status =1", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error
  1016. if err != nil {
  1017. ut.Rollback()
  1018. return
  1019. }
  1020. ut.Commit()
  1021. return err
  1022. }
  1023. func BatchModifyExceOldDoctorAdvice(m *models.DoctorAdvice, ids []string) (err error) {
  1024. ut := writeDb.Begin()
  1025. 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
  1026. if err != nil {
  1027. ut.Rollback()
  1028. return
  1029. }
  1030. 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
  1031. if err != nil {
  1032. ut.Rollback()
  1033. return
  1034. }
  1035. ut.Commit()
  1036. return err
  1037. }
  1038. func UpdateOrderCount(good_type_id int64, good_id int64, number string, org_id int64) {
  1039. 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))
  1040. }
  1041. func UpdateOrderInfoDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, newNiprocart int64, out *models.WarehouseOutInfo) {
  1042. 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})
  1043. }
  1044. func FindOrderInfoByGoodId(good_type_id int64, good_id int64, number string, org_id int64) (err error, out models.WarehouseOutInfo) {
  1045. 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
  1046. return
  1047. }
  1048. func FindGoodUserById(good_type_id int64, good_id int64, id int64, org_id int64, record_time int64) (user models.AutomaticReduceDetail, err error) {
  1049. 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
  1050. return
  1051. }
  1052. func FindOldOrderInfoByGoodId(time int64, org_id int64) (err error, out models.WarehouseOutInfo) {
  1053. err = readDb.Model(&models.WarehouseOutInfo{}).Where(" org_id = ? AND status = 1 AND sys_record_time = ? ", org_id, time).First(&out).Error
  1054. return
  1055. }
  1056. func FindStockOutOrderNumberByTime(time int64, org_id int64) (err error, out models.WarehouseOut) {
  1057. err = readDb.Model(&models.WarehouseOut{}).Where(" org_id = ? AND status = 1 AND warehouse_out_time = ? ", org_id, time).First(&out).Error
  1058. return
  1059. }
  1060. func UpdateDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, newNiprocart int64, out *models.WarehouseOutInfo) {
  1061. 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})
  1062. }
  1063. func FindPatientIsOpenRemindById(patient_id int64, org_id int64) (patients models.Patients, err error) {
  1064. err = readDb.Model(&models.Patients{}).Where("status = 1 AND id = ? AND user_org_id = ?", patient_id, org_id).First(&patients).Error
  1065. return
  1066. }
  1067. func GetMaxLongAdviceGroupID(orgId int64, patient_id int64) (group int64) {
  1068. var advice models.DoctorAdvice
  1069. 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
  1070. if err != nil {
  1071. fmt.Println(err)
  1072. group = 0
  1073. }
  1074. group = advice.GroupNo
  1075. return
  1076. }
  1077. func GetLastLongAdviceByGroupNo(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  1078. 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 AND frequency_type <> 0 and (push_start_time >=? or push_start_time = 0) ", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0)", advice_date).Find(&advice).Error
  1079. return
  1080. }
  1081. func GetLastLongAdviceByGroupNoOne(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  1082. redis := RedisClient()
  1083. defer redis.Close()
  1084. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":long_advice"
  1085. long_advice_str, _ := redis.Get(key).Result()
  1086. if len(long_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1087. 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 AND frequency_type <> 0 and (push_start_time >=? or push_start_time = 0) ", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0) ", advice_date).Find(&advice).Error
  1088. if err != nil {
  1089. if err == gorm.ErrRecordNotFound {
  1090. return nil, nil
  1091. } else {
  1092. return nil, err
  1093. }
  1094. } else {
  1095. if len(advice) > 0 {
  1096. //缓存数据
  1097. starfes_str, err := json.Marshal(advice)
  1098. if err == nil {
  1099. redis.Set(key, starfes_str, time.Second*60*60*18)
  1100. return advice, nil
  1101. }
  1102. } else {
  1103. redis.Set(key, "null", time.Second*60*60*18)
  1104. return advice, nil
  1105. }
  1106. return advice, nil
  1107. }
  1108. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1109. if long_advice_str == "null" {
  1110. return advice, nil
  1111. } else {
  1112. json.Unmarshal([]byte(long_advice_str), &advice)
  1113. return advice, nil
  1114. }
  1115. }
  1116. 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 AND frequency_type <> 0 and (push_start_time >=? or push_start_time = 0) ", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0) ", advice_date).Find(&advice).Error
  1117. return
  1118. }
  1119. func GetLastLongAdviceByGroupNoThree(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  1120. 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 and (push_start_time>=? or push_start_time = 0) ", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time>=? or push_start_time = 0) ", advice_date).Find(&advice).Error
  1121. return
  1122. }
  1123. func GetLastLongAdviceByGroupNoFour(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  1124. //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
  1125. //return
  1126. redis := RedisClient()
  1127. defer redis.Close()
  1128. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":long_advice"
  1129. long_advice_str, _ := redis.Get(key).Result()
  1130. if len(long_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1131. 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 and (push_start_time >=? or push_start_time = 0)", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0)", advice_date).Find(&advice).Error
  1132. if err != nil {
  1133. if err == gorm.ErrRecordNotFound {
  1134. return nil, nil
  1135. } else {
  1136. return nil, err
  1137. }
  1138. } else {
  1139. if len(advice) > 0 {
  1140. //缓存数据
  1141. starfes_str, err := json.Marshal(advice)
  1142. if err == nil {
  1143. redis.Set(key, starfes_str, time.Second*60*60*18)
  1144. return advice, nil
  1145. }
  1146. } else {
  1147. redis.Set(key, "null", time.Second*60*60*18)
  1148. return advice, nil
  1149. }
  1150. return advice, nil
  1151. }
  1152. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1153. if long_advice_str == "null" {
  1154. return advice, nil
  1155. } else {
  1156. json.Unmarshal([]byte(long_advice_str), &advice)
  1157. return advice, nil
  1158. }
  1159. }
  1160. 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 AND frequency_type <> 0 and (push_start_time >=? or push_start_time = 0)", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0)", advice_date).Find(&advice).Error
  1161. return
  1162. }
  1163. func FindAllDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, temp_id string) (advice []*models.DoctorAdvice, err error) {
  1164. 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
  1165. return
  1166. }
  1167. func UpdateScheduleModeId(patient_id int64, org_id int64, date int64, mode_id int64) (err error) {
  1168. 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
  1169. return
  1170. }
  1171. func UpdateAssessmentAfterDate(patient_id int64, org_id int64, date int64, actual_treatment_hour int64, actual_treatment_minute int64) (err error) {
  1172. 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
  1173. return
  1174. }
  1175. func UpdateAssessmentAfterDateOne(patient_id int64, org_id int64, date int64, actual_treatment_hour int64, actual_treatment_minute int64, BreathingRate string) (err error) {
  1176. 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, "breathing_rate": BreathingRate}).Error
  1177. return
  1178. }
  1179. func CreateDialysisBeforePrepare(beforePrepares []*models.DialysisBeforePrepare) (err error) {
  1180. if len(beforePrepares) > 0 {
  1181. utx := writeDb.Begin()
  1182. if len(beforePrepares) > 0 {
  1183. thisSQL := "INSERT INTO dialysis_before_prepare (user_org_id, patient_id, record_date, good_id, good_type_id,count,ctime,mtime,creater,modifier,status,commdity_code) VALUES "
  1184. insertParams := make([]string, 0)
  1185. insertData := make([]interface{}, 0)
  1186. for _, prepare := range beforePrepares {
  1187. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  1188. insertData = append(insertData, prepare.UserOrgId)
  1189. insertData = append(insertData, prepare.PatientId)
  1190. insertData = append(insertData, prepare.RecordDate)
  1191. insertData = append(insertData, prepare.GoodId)
  1192. insertData = append(insertData, prepare.GoodTypeId)
  1193. insertData = append(insertData, prepare.Count)
  1194. insertData = append(insertData, prepare.Ctime)
  1195. insertData = append(insertData, prepare.Mtime)
  1196. insertData = append(insertData, prepare.Creater)
  1197. insertData = append(insertData, prepare.Modifier)
  1198. insertData = append(insertData, 1)
  1199. insertData = append(insertData, prepare.CommdityCode)
  1200. }
  1201. thisSQL += strings.Join(insertParams, ", ")
  1202. err = utx.Exec(thisSQL, insertData...).Error
  1203. if err != nil {
  1204. utx.Rollback()
  1205. return
  1206. }
  1207. }
  1208. utx.Commit()
  1209. }
  1210. return
  1211. }
  1212. func UpdateDialysisBeforePrepare(info *models.DialysisBeforePrepare) (err error) {
  1213. err = writeDb.Save(&info).Error
  1214. return err
  1215. }
  1216. func UpdateDialysisBeforePrepareTwo(info *models.DialysisBeforePrepare) (err error) {
  1217. err = writeDb.Model(&models.DialysisBeforePrepare{}).
  1218. 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).
  1219. Updates(map[string]interface{}{"count": info.Count, "updated_time": time.Now().Unix(), "modifier": info.Modifier, "commdity_code": info.CommdityCode, "status": 1}).Error
  1220. return err
  1221. }
  1222. func UpdateAutoReduceDetailSix(detail *models.AutomaticReduceDetail) (err error) {
  1223. err = writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? and good_type_id = ? And patient_id = ? and org_id =? and record_time = ?", detail.GoodId, detail.GoodTypeId, detail.PatientId, detail.OrgId, detail.RecordTime).Updates(map[string]interface{}{"count": detail.Count, "mtime": detail.Mtime, "status": 1}).Error
  1224. return err
  1225. }
  1226. func UpdateOrderCountSub(good_type_id int64, good_id int64, number string, org_id int64, count int64) {
  1227. 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))
  1228. }
  1229. func UpdateOrderCountAdd(good_type_id int64, good_id int64, number string, org_id int64, count int64) {
  1230. 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))
  1231. }
  1232. func UpdateUserInfoDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.WarehouseOutInfo) {
  1233. 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, "status": 1})
  1234. //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)
  1235. }
  1236. func UpdateDrugUserInfoDetails(drug_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.DrugWarehouseOutInfo) {
  1237. 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})
  1238. //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)
  1239. }
  1240. func FindDialysisBeforePrepare(patient_id int64, good_id int64, good_type_id int64, user_org_id int64, record_time int64) (count int64) {
  1241. readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND good_id = ? AND good_type_id = ? AND record_date = ? AND status = 1 AND count<> 0", user_org_id, patient_id, good_id, good_type_id, record_time).Count(&count)
  1242. return
  1243. }
  1244. func GetExecutionDoctors(orgid int64, patientid int64, id int64) (doctorAdvice []*models.DoctorAdvice, err error) {
  1245. 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
  1246. return doctorAdvice, err
  1247. }
  1248. func GetHisExecutionDoctors(orgid int64, patientid int64, id int64) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) {
  1249. 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
  1250. return doctorAdvice, err
  1251. }
  1252. func GetHisExecutionDoctorsTwo(orgid int64, patientid int64, id int64) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) {
  1253. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and patient_id = ? AND id = ? and status = 1 and execution_state = 1", orgid, patientid, id).Find(&doctorAdvice).Error
  1254. return doctorAdvice, err
  1255. }
  1256. func FindHisDoctorAdviceById(orgID int64, id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1257. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error
  1258. return
  1259. }
  1260. func FindHisDoctorAdviceByIds(orgID int64, ids []string) (advice []*models.HisDoctorAdviceInfo, err error) {
  1261. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id in (?)", orgID, ids).Find(&advice).Error
  1262. return
  1263. }
  1264. func SaveHisDoctorAdvice(advice *models.HisDoctorAdviceInfo) (err error) {
  1265. err = writeDb.Save(&advice).Error
  1266. return
  1267. }
  1268. func GetGoodInfoMation(orgid int64) (goodinfo []*models.GoodInfo, err error) {
  1269. err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Preload("GoodSotckInfo", "stock_count > 0 and status = 1").Find(&goodinfo).Error
  1270. //err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Find(&goodinfo).Error
  1271. return goodinfo, err
  1272. }
  1273. func GetGoodInfoMationSix(orgid int64, storehouse_id int64) (goodinfo []*models.GoodInfo, err error) {
  1274. err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Preload("GoodSotckInfo", "stock_count > 0 and status = 1 and storehouse_id = ?", storehouse_id).Find(&goodinfo).Error
  1275. return goodinfo, err
  1276. }
  1277. func GetGoodInfoMationSeven(orgid int64, storehouse_id int64) (goodinfo []*models.GoodInfo, err error) {
  1278. err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Preload("GoodSotckInfo", "status = 1 and storehouse_id = ? and stock_count>0", storehouse_id).Find(&goodinfo).Error
  1279. return goodinfo, err
  1280. }
  1281. func GetDialysisBeforePrepare(goodTypeId int64, goodId int64, orgid int64, patientId int64) (*models.DialysisBeforePrepare, error) {
  1282. prepare := models.DialysisBeforePrepare{}
  1283. err := XTReadDB().Where("good_type_id = ? and good_id = ? and user_org_id = ? and status =1 and patient_id = ?", goodTypeId, goodId, orgid, patientId).Last(&prepare).Error
  1284. if err == gorm.ErrRecordNotFound {
  1285. return nil, err
  1286. }
  1287. if err != nil {
  1288. return nil, err
  1289. }
  1290. return &prepare, nil
  1291. }
  1292. func CreateDialysisBeforePrepareOne(prepare *models.DialysisBeforePrepare) error {
  1293. err := XTWriteDB().Create(&prepare).Error
  1294. return err
  1295. }
  1296. func ModifyExceDoctorAdviceById(m *models.HisDoctorAdviceInfo, ids []string) (err error) {
  1297. ut := writeDb.Begin()
  1298. err = ut.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id IN (?) AND execution_state = 1", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error
  1299. if err != nil {
  1300. ut.Rollback()
  1301. return
  1302. }
  1303. err = ut.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND parent_id IN (?) AND execution_state = 1 ", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error
  1304. if err != nil {
  1305. ut.Rollback()
  1306. return
  1307. }
  1308. ut.Commit()
  1309. return err
  1310. }
  1311. func FindHisDoctorAdviceByIdOne(orgID int64, ids []string) (advice []models.HisDoctorAdviceInfo, err error) {
  1312. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id IN (?) AND user_org_id = ? AND status = 1", ids, orgID).Find(&advice).Error
  1313. return
  1314. }
  1315. func ModifyHisPrescriptionProject(m *models.HisPrescriptionProject, ids []string) (err error) {
  1316. ut := writeDb.Begin()
  1317. err = ut.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id IN (?) AND execution_state = 1", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error
  1318. if err != nil {
  1319. ut.Rollback()
  1320. return
  1321. }
  1322. ut.Commit()
  1323. return err
  1324. }
  1325. func FindHisProjectById(orgID int64, id int64) (advice models.HisPrescriptionProject, err error) {
  1326. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error
  1327. return
  1328. }
  1329. func SaveHisProject(advice *models.HisPrescriptionProject) (err error) {
  1330. err = writeDb.Save(&advice).Error
  1331. return
  1332. }
  1333. func FindAllHisProjectById(orgID int64, patient_id int64, record_time int64) (advice []*models.HisPrescriptionProject, err error) {
  1334. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1 and user_org_id = ?", orgID).Preload("XtHisProjectTeam", "user_org_id=? and status=1", orgID).Preload("GoodInfo", "status = 1 and org_id = ?", orgID).Where("user_org_id=? and status=1 and patient_id = ? AND record_date = ?", orgID, patient_id, record_time).Find(&advice).Error
  1335. return
  1336. }
  1337. func GetAllPcPatientListByListSeven(orgID int64) (patients []*MSchedualPatientVMList, err error) {
  1338. err = readDb.Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
  1339. return patients, err
  1340. }
  1341. func GetAllPcPatientListByListEight(orgID int64) (patients []*MSchedualPatientVMList, err error) {
  1342. err = readDb.Where("user_org_id=? and status=1", orgID).Find(&patients).Error
  1343. return patients, err
  1344. }
  1345. func GetAllPcPatientListByList(orgID int64) (patients []*MSchedualPatientVMList, err error) {
  1346. redis := RedisClient()
  1347. defer redis.Close()
  1348. key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
  1349. patient_info_str, _ := redis.Get(key).Result()
  1350. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1351. err = readDb.Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
  1352. if err != nil {
  1353. if err == gorm.ErrRecordNotFound {
  1354. if len(patients) <= 0 {
  1355. redis.Set(key, "null", time.Second*60*60*18)
  1356. }
  1357. return nil, nil
  1358. } else {
  1359. return nil, err
  1360. }
  1361. } else {
  1362. if len(patients) > 0 {
  1363. //缓存数据
  1364. patient_info_json, err := json.Marshal(&patients)
  1365. if err == nil {
  1366. redis.Set(key, patient_info_json, time.Second*60*60*18)
  1367. }
  1368. } else {
  1369. redis.Set(key, "null", time.Second*60*60*18)
  1370. }
  1371. return patients, nil
  1372. }
  1373. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1374. if patient_info_str == "null" {
  1375. return nil, nil
  1376. } else {
  1377. json.Unmarshal([]byte(patient_info_str), &patients)
  1378. return patients, nil
  1379. }
  1380. }
  1381. }
  1382. func GetAllPcAdvicestByList(orgID int64, scheduleDate int64) (advices []*VMDoctorAdvice, err error) {
  1383. redis := RedisClient()
  1384. defer redis.Close()
  1385. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":advice_list_all"
  1386. advice_list_str, _ := redis.Get(key).Result()
  1387. if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1388. err = readDb.Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ?", orgID, scheduleDate).Find(&advices).Error
  1389. if err != nil {
  1390. if err == gorm.ErrRecordNotFound {
  1391. if len(advices) <= 0 {
  1392. redis.Set(key, "null", time.Second*60*60*18)
  1393. }
  1394. return nil, nil
  1395. } else {
  1396. return nil, err
  1397. }
  1398. } else {
  1399. if len(advices) > 0 {
  1400. //缓存数据
  1401. advice_list_str, err := json.Marshal(&advices)
  1402. if err == nil {
  1403. redis.Set(key, advice_list_str, time.Second*60*60*18)
  1404. }
  1405. } else {
  1406. redis.Set(key, "null", time.Second*60*60*18)
  1407. }
  1408. return advices, nil
  1409. }
  1410. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1411. if advice_list_str == "null" {
  1412. return nil, nil
  1413. } else {
  1414. json.Unmarshal([]byte(advice_list_str), &advices)
  1415. return advices, nil
  1416. }
  1417. }
  1418. }
  1419. func GetAllPcDialysisOrdersByList(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVMList, err error) {
  1420. redis := RedisClient()
  1421. defer redis.Close()
  1422. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
  1423. dialysis_orders_list_all, _ := redis.Get(key).Result()
  1424. if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1425. err = readDb.Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
  1426. if err != nil {
  1427. if err == gorm.ErrRecordNotFound {
  1428. return nil, nil
  1429. } else {
  1430. return nil, err
  1431. }
  1432. } else {
  1433. if len(dialysisOrders) > 0 {
  1434. //缓存数据
  1435. dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
  1436. if err == nil {
  1437. redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
  1438. }
  1439. } else {
  1440. redis.Set(key, "null", time.Second*60*60*18)
  1441. }
  1442. return dialysisOrders, nil
  1443. }
  1444. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1445. if dialysis_orders_list_all == "null" {
  1446. return nil, nil
  1447. } else {
  1448. json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
  1449. return dialysisOrders, nil
  1450. }
  1451. }
  1452. }
  1453. func GetAllPcAssessmentAfterDislysisByList(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*AssessmentAfterDislysis, err error) {
  1454. redis := RedisClient()
  1455. defer redis.Close()
  1456. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1457. assessment_after_dislysis__all, _ := redis.Get(key).Result()
  1458. if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1459. err = readDb.Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
  1460. if err != nil {
  1461. if err == gorm.ErrRecordNotFound {
  1462. if len(assessmentAfterDislysis) <= 0 {
  1463. redis.Set(key, "null", time.Second*60*60*18)
  1464. }
  1465. return nil, nil
  1466. } else {
  1467. return nil, err
  1468. }
  1469. } else {
  1470. if len(assessmentAfterDislysis) > 0 {
  1471. //缓存数据
  1472. assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
  1473. if err == nil {
  1474. redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
  1475. }
  1476. } else {
  1477. redis.Set(key, "null", time.Second*60*60*18)
  1478. }
  1479. return assessmentAfterDislysis, nil
  1480. }
  1481. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1482. if assessment_after_dislysis__all == "null" {
  1483. return nil, nil
  1484. } else {
  1485. json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
  1486. return assessmentAfterDislysis, nil
  1487. }
  1488. }
  1489. }
  1490. func GetAllPcTreatmentSummarysByList(orgID int64, scheduleDate int64) (treatmentSummarys []*VMTreatmentSummary, err error) {
  1491. redis := RedisClient()
  1492. defer redis.Close()
  1493. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":treatment_summarys_list_all"
  1494. treatment_summarys_all, _ := redis.Get(key).Result()
  1495. if len(treatment_summarys_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1496. err = readDb.Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&treatmentSummarys).Error
  1497. if err != nil {
  1498. if err == gorm.ErrRecordNotFound {
  1499. if len(treatment_summarys_all) <= 0 {
  1500. redis.Set(key, "null", time.Second*60*60*18)
  1501. }
  1502. return nil, nil
  1503. } else {
  1504. return nil, err
  1505. }
  1506. } else {
  1507. if len(treatmentSummarys) > 0 {
  1508. //缓存数据
  1509. treatment_summarys_all, err := json.Marshal(&treatmentSummarys)
  1510. if err == nil {
  1511. redis.Set(key, treatment_summarys_all, time.Second*60*60*18)
  1512. }
  1513. } else {
  1514. redis.Set(key, "null", time.Second*60*60*18)
  1515. }
  1516. return treatmentSummarys, nil
  1517. }
  1518. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1519. if treatment_summarys_all == "null" {
  1520. return nil, nil
  1521. } else {
  1522. json.Unmarshal([]byte(treatment_summarys_all), &treatmentSummarys)
  1523. return treatmentSummarys, nil
  1524. }
  1525. }
  1526. }
  1527. func UpdateTeamProjectExceStatus(ids []int64, admin_user_id int64, execution_time int64) (err error) {
  1528. ut := writeDb.Begin()
  1529. db := ut.Model(&models.HisPrescriptionProject{})
  1530. err = db.Where("status = 1 AND id IN (?)", ids).Updates(map[string]interface{}{"execution_time": execution_time, "execution_state": 1, "execution_staff": admin_user_id}).Error
  1531. if err != nil {
  1532. ut.Rollback()
  1533. return
  1534. }
  1535. ut.Commit()
  1536. return err
  1537. }
  1538. func UpdateTeamProjectCheckStatus(ids []int64, patient_id int64, record_date int64, user_org_id int64, admin_user_id int64, check_time int64) (err error) {
  1539. ut := writeDb.Begin()
  1540. err = ut.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id IN (?) AND patient_id = ? AND user_org_id = ? AND record_date = ?", ids, patient_id, user_org_id, record_date).Updates(map[string]interface{}{"check_time": check_time, "check_state": 1, "checker": admin_user_id}).Error
  1541. if err != nil {
  1542. ut.Rollback()
  1543. return
  1544. }
  1545. ut.Commit()
  1546. return err
  1547. }
  1548. func GetCheckTeamProject(team_id int64, patient_id int64, record_date int64, user_org_id int64) (ps []*models.HisPrescriptionProject, err error) {
  1549. err = readDb.Model(&models.HisPrescriptionProject{}).Joins("JOIN xt_his_project as p On p.id = his_prescription_project.project_id AND p.cost_classify = 3").Where("his_prescription_project.team_id IN (?) AND his_prescription_project.patient_id = ? AND his_prescription_project.user_org_id = ? AND his_prescription_project.record_date = ? AND his_prescription_project.status = 1", team_id, patient_id, user_org_id, record_date).Find(&ps).Error
  1550. return
  1551. }
  1552. func GetAdminUserRoleInformation(orgid int64) (models.SgjOrgFollow, error) {
  1553. follow := models.SgjOrgFollow{}
  1554. db := UserReadDB().Table("sgj_org_follow as f").Where("f.status = 1")
  1555. table := UserReadDB().Table("sgj_admin as a").Where("a.status = 1")
  1556. fmt.Println(table)
  1557. if orgid > 0 {
  1558. db = db.Where("org_id = ?", orgid)
  1559. }
  1560. if orgid == 0 {
  1561. db = db.Where("org_id = ?", 0)
  1562. }
  1563. err := db.Select("f.org_id,f.admin_user_id,a.name,a.phone,a.camera,a.wechat,a.qqchat,a.email,a.wechat_link").Joins("left join sgj_admin as a on a.id = f.admin_user_id").Scan(&follow).Error
  1564. return follow, err
  1565. }
  1566. func GetOrgFollowIsExist(orgid int64) (*models.SgjOrgFollowOne, error) {
  1567. follow := models.SgjOrgFollowOne{}
  1568. err := UserReadDB().Where("org_id = ? and status = 1", orgid).Find(&follow).Error
  1569. if err == gorm.ErrRecordNotFound {
  1570. return nil, err
  1571. }
  1572. if err != nil {
  1573. return nil, err
  1574. }
  1575. return &follow, nil
  1576. }
  1577. func UpdatePatientSign(patient_id int64, dialysis_date int64, order models.DialysisOrder, orgid int64) error {
  1578. err := XTWriteDB().Model(&order).Where("patient_id = ? and dialysis_date= ? and status = 1 and user_org_id = ?", patient_id, dialysis_date, orgid).Update(map[string]interface{}{"url": order.Url, "hash": order.Hash}).Error
  1579. return err
  1580. }
  1581. func GetPatientSign(patient_id int64, dialysis_date int64, orgid int64) (models.DialysisOrder, error) {
  1582. order := models.DialysisOrder{}
  1583. err := XTReadDB().Where("patient_id=? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, orgid).Find(&order).Error
  1584. return order, err
  1585. }
  1586. func GetScheduleByPatient(patient_id int64, schedule_date int64, orgid int64) (models.XtScheduleSix, error) {
  1587. schedule := models.XtScheduleSix{}
  1588. err := XTReadDB().Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status = 1", patient_id, schedule_date, orgid).Find(&schedule).Error
  1589. return schedule, err
  1590. }
  1591. func GetSchedulePrintList(page int64, limit int64, schedulType int64, partitionType int64, keywords string, schedule_date int64, orgID int64) (list []*models.DialysisScheduleSix, total int64, err error) {
  1592. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  1593. table := XTReadDB().Table("xt_patients as p").Where("p.status = 1")
  1594. fmt.Println("table", table)
  1595. if schedulType > 0 {
  1596. db = db.Where("x.schedule_type = ?", schedulType)
  1597. }
  1598. if partitionType > 0 {
  1599. db = db.Where("x.partition_id = ?", partitionType)
  1600. }
  1601. if orgID > 0 {
  1602. db = db.Where("x.user_org_id = ?", orgID)
  1603. }
  1604. if schedule_date > 0 {
  1605. db = db.Where("x.schedule_date = ?", schedule_date)
  1606. }
  1607. db = db.Joins("left join xt_patients as p on p.id = x.patient_id")
  1608. likeKey := "%" + keywords + "%"
  1609. if len(keywords) > 0 {
  1610. db = db.Where("p.name like ?", likeKey)
  1611. }
  1612. err = db.Count(&total).Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.status,p.name").Offset(limit * (page - 1)).Limit(limit).Order("x.schedule_date desc").Find(&list).Error
  1613. return list, total, err
  1614. }
  1615. func GetSchedulePrintListOne(page int64, limit int64, schedulType int64, partitionType int64, keywords string, schedule_date int64, orgID int64) (list []*models.DialysisScheduleSeven, err error) {
  1616. db := XTReadDB().Model(&list).Where("status = 1")
  1617. if orgID > 0 {
  1618. db = db.Where("user_org_id = ?", orgID)
  1619. }
  1620. if schedulType > 0 {
  1621. db = db.Where("schedule_type = ?", schedulType)
  1622. }
  1623. if partitionType > 0 {
  1624. db = db.Where("partition_id = ?", partitionType)
  1625. }
  1626. err = db.Group("schedule_type,partition_id").Find(&list).Error
  1627. return list, err
  1628. }
  1629. func GetDialysisRecordOrder(org_id int64, patient_id int64, dialysis_date int64) (models.MDialysisOrderForListSix, error) {
  1630. order := models.MDialysisOrderForListSix{}
  1631. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date = ? and status =1 ", org_id, patient_id, dialysis_date).Find(&order).Error
  1632. return order, err
  1633. }
  1634. func GetSolutionListByOrgId(orgid int64) (list []*models.DialysisSolution, err error) {
  1635. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Group("patient_id,mode_id").Order("id desc").Find(&list).Error
  1636. return list, err
  1637. }
  1638. func GetScheduleTypeById(org_id int64, schedule_date int64, schedule_type int64) (list []*models.XtScheduleSeven, err error) {
  1639. db := XTReadDB().Model(&list).Where("status = 1")
  1640. if org_id > 0 {
  1641. db = db.Where("user_org_id = ?", org_id)
  1642. }
  1643. if schedule_date > 0 {
  1644. db = db.Where("schedule_date = ?", schedule_date)
  1645. }
  1646. if schedule_type > 0 {
  1647. db = db.Where("schedule_type = ?", schedule_type)
  1648. }
  1649. err = db.Select("partition_id,count(id) as count").Group("partition_id").Scan(&list).Error
  1650. return list, err
  1651. }
  1652. func GetHisExcutionDoctorAdviceListGroupList(patients []string, advice_date int64, user_org_id int64) (advice []*models.HisDoctorAdvice, err error) {
  1653. err = XTReadDB().Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1 and execution_state = 2", patients, advice_date, user_org_id).Group("drug_id").Find(&advice).Error
  1654. return advice, err
  1655. }
  1656. func GetHisExcutionDoctorAdviceList(patients []string, advice_date int64, user_org_id int64) (advice []*models.HisDoctorAdvice, err error) {
  1657. err = XTReadDB().Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1 and execution_state = 2", patients, advice_date, user_org_id).Find(&advice).Error
  1658. return advice, err
  1659. }
  1660. func UpdateHisDoctorAdviceExecution(info models.HisDoctorAdviceInfo, id int64) error {
  1661. err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Update(map[string]interface{}{"execution_staff": info.ExecutionStaff, "execution_state": info.ExecutionState, "execution_time": info.ExecutionTime, "updated_time": info.ExecutionTime}).Error
  1662. return err
  1663. }
  1664. func UpdateDoctorAdviceExecution(info models.DoctorAdvice, id int64) error {
  1665. err := XTWriteDB().Model(&models.DoctorAdvice{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"execution_staff": info.ExecutionStaff, "execution_state": info.ExecutionState, "execution_time": info.ExecutionTime, "updated_time": info.ExecutionTime}).Error
  1666. return err
  1667. }
  1668. func GetExcutionDoctorAdviceGroupList(patients []string, advice_date int64, user_org_id int64) (advice []*models.DoctorAdviceThrity, err error) {
  1669. err = XTReadDB().Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1 and execution_state = 2", patients, advice_date, user_org_id).Group("drug_id").Find(&advice).Error
  1670. return advice, err
  1671. }
  1672. func GetExcutionDoctorAdviceList(patients []string, advice_date int64, user_org_id int64) (advice []*models.DoctorAdviceThrity, err error) {
  1673. err = XTReadDB().Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1 and execution_state = 2", patients, advice_date, user_org_id).Find(&advice).Error
  1674. return advice, err
  1675. }
  1676. func GetHisCheckDoctorAdvice(orgid int64, patinentids []string, advice_date int64) (advice []*models.HisDoctorAdviceThirty, err error) {
  1677. err = XTReadDB().Where("user_org_id = ? and patient_id in(?) and advice_date = ? and status =1", orgid, patinentids, advice_date).Find(&advice).Error
  1678. return advice, err
  1679. }
  1680. func CheckDoctorAdvice(id int64, creater int64) (models.DoctorAdviceThrity, error) {
  1681. doctoradvice := models.DoctorAdviceThrity{}
  1682. err := XTWriteDB().Model(&doctoradvice).Where("id = ? and status = 1", id).Update(map[string]interface{}{"checker": creater, "check_time": time.Now().Unix()}).Error
  1683. return doctoradvice, err
  1684. }
  1685. func CheckHisDoctorAdvice(id int64, creater int64) (models.HisDoctorAdviceThirty, error) {
  1686. doctoradvice := models.HisDoctorAdviceThirty{}
  1687. err := XTWriteDB().Model(&doctoradvice).Where("id = ? and status = 1", id).Update(map[string]interface{}{"checker": creater, "check_time": time.Now().Unix()}).Error
  1688. return doctoradvice, err
  1689. }
  1690. func GetCheckDoctorAdvice(orgid int64, patinentids []string, advice_date int64) (advice []*models.DoctorAdviceThrity, err error) {
  1691. err = XTReadDB().Where("user_org_id = ? and patient_id in(?) and advice_date = ? and status=1", orgid, patinentids, advice_date).Find(&advice).Error
  1692. return advice, err
  1693. }
  1694. func SettleHisNewDoctorAdvice(patinentids []string, advice_date int64, orgid int64) (advice []*models.HisDoctorAdviceThirty, err error) {
  1695. err = XTWriteDB().Model(&advice).Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1", patinentids, advice_date, orgid).Update(map[string]interface{}{"is_settle": 1}).Error
  1696. return advice, err
  1697. }
  1698. func SettleNewDoctorAdvice(patinentids []string, advice_date int64, orgid int64) (advice []*models.DoctorAdviceThrity, err error) {
  1699. err = XTWriteDB().Model(&advice).Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1", patinentids, advice_date, orgid).Update(map[string]interface{}{"is_settle": 1}).Error
  1700. return advice, err
  1701. }
  1702. func GetHisMobileAdviceGroupList(orgid int64, ids []string) (advice []*models.HisDoctorAdvice, err error) {
  1703. err = XTReadDB().Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Group("drug_id").Find(&advice).Error
  1704. return advice, err
  1705. }
  1706. func GetHisMobileAdviceList(orgid int64, ids []string) (advice []*models.HisDoctorAdvice, err error) {
  1707. err = XTReadDB().Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Find(&advice).Error
  1708. return advice, err
  1709. }
  1710. func ExectionMobileAdvice(orgid int64, ids []string, execution_time int64, execution_staff int64) error {
  1711. advice := models.HisDoctorAdvice{}
  1712. err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Updates(map[string]interface{}{"execution_time": execution_time, "execution_staff": execution_staff, "execution_state": 1, "is_mobile": 3}).Error
  1713. return err
  1714. }
  1715. func GetBloodMobileAdviceGroupList(orgid int64, ids []string) (advice []*models.DoctorAdviceThrity, err error) {
  1716. err = XTReadDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Group("drug_id").Find(&advice).Error
  1717. return advice, err
  1718. }
  1719. func GetBloodMobileAdviceList(orgid int64, ids []string) (advice []*models.DoctorAdviceThrity, err error) {
  1720. err = XTReadDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Find(&advice).Error
  1721. return advice, err
  1722. }
  1723. func FindAllDoctorAdviceByIds(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
  1724. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND id in(?) AND status = 1", orgID, ids).Find(&advice).Error
  1725. return
  1726. }
  1727. func ExectionBloodMobileAdvice(orgid int64, ids []string, execution_time int64, execution_staff int64) error {
  1728. advice := models.DoctorAdviceThrity{}
  1729. err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Updates(map[string]interface{}{"execution_time": execution_time, "execution_staff": execution_staff, "execution_state": 1}).Error
  1730. return err
  1731. }
  1732. func UpdateSettleMobileHisAdvice(orgid int64, ids []string) error {
  1733. advice := models.HisDoctorAdviceThirty{}
  1734. err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status =1", orgid, ids).Updates(map[string]interface{}{"is_settle": 1}).Error
  1735. return err
  1736. }
  1737. func UpdateSettleMobileBloodAdvice(orgid int64, ids []string) error {
  1738. advice := models.DoctorAdvice{}
  1739. err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status =1", orgid, ids).Updates(map[string]interface{}{"is_settle": 1}).Error
  1740. return err
  1741. }
  1742. func CheckBloodDoctorAdvice(orgid int64, ids []string, advice models.DoctorAdvice) error {
  1743. err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Updates(map[string]interface{}{"check_time": advice.CheckTime, "checker": advice.Checker, "check_state": 1}).Error
  1744. return err
  1745. }
  1746. func CheckHisMobileDoctorAdvice(orgid int64, ids []string, advice models.HisDoctorAdviceThirty) error {
  1747. err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Updates(map[string]interface{}{"check_time": advice.CheckTime, "checker": advice.Checker, "check_state": 1}).Error
  1748. return err
  1749. }
  1750. func GetLastOrder(user_org_id int64, patient_id int64, dialysis_date int64) (models.DialysisOrderTwenty, error) {
  1751. twenty := models.DialysisOrderTwenty{}
  1752. err := XTReadDB().Where("user_org_id = ? and patient_id =? and dialysis_date < ? and status = 1", user_org_id, patient_id, dialysis_date).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  1753. return db.Preload("DeviceZone", "status =1").Where("org_id = ? AND status = 1", user_org_id)
  1754. }).Order("id desc").First(&twenty).Error
  1755. return twenty, err
  1756. }
  1757. func UpdateDoctorSix(start_time int64, patient_id int64, dialysis_date int64, user_org_id int64) (models.DoctorAdvice, error) {
  1758. advice := models.DoctorAdvice{}
  1759. err := XTWriteDB().Model(&advice).Where("patient_id = ? and advice_date=? and user_org_id =? and status=1 and advice_name ='低分子肝素钠注射液'", patient_id, dialysis_date, user_org_id).Updates(map[string]interface{}{"execution_time": start_time}).Error
  1760. return advice, err
  1761. }
  1762. func GetTodayInforMation(orgid int64, record_date int64) (list []*NewDeviceInformation, err error) {
  1763. err = UserReadDB().Where("user_org_id = ? and date = ? and status = 1", orgid, record_date).Find(&list).Error
  1764. return list, err
  1765. }
  1766. func GetFiledConfig(orgid int64) (models.FiledConfig, error) {
  1767. config := models.FiledConfig{}
  1768. err := XTReadDB().Where("filed_name = 'dialyzer_perfusion_apparatus' and org_id = ? and module =1 and is_show = 1", orgid).First(&config).Error
  1769. return config, err
  1770. }
  1771. func GetDoctorAdviceCheckList(patient_id int64, advice_date int64, user_org_id int64) (doctor []*models.DoctorAdvice, err error) {
  1772. err = XTReadDB().Where("patient_id = ? and advice_date = ? and user_org_id =? and status= 1 and checker= 0", patient_id, advice_date, user_org_id).Find(&doctor).Error
  1773. return doctor, err
  1774. }
  1775. func UpdateDoctorAdviceList(id int64, checker int64) error {
  1776. advice := models.DoctorAdvice{}
  1777. err := XTWriteDB().Model(&advice).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": checker, "check_state": 1, "check_time": time.Now().Unix()}).Error
  1778. return err
  1779. }
  1780. func UpdateLastMonitorRecordToday(accumulated_blood_volume float64, id int64) error {
  1781. err := XTWriteDB().Model(&models.MonitoringRecord{}).Where(" id = ? and status= 1", id).Update(map[string]interface{}{"accumulated_blood_volume": accumulated_blood_volume}).Error
  1782. return err
  1783. }
  1784. func GetDialysisFinish(user_org_id int64, record_date int64, module int64, patient_id int64) (models.XtDialysisFinish, error) {
  1785. finish := models.XtDialysisFinish{}
  1786. err := XTReadDB().Where("user_org_id = ? and record_date = ? and status =1 and module = ? and patient_id = ?", user_org_id, record_date, module, patient_id).Find(&finish).Error
  1787. return finish, err
  1788. }
  1789. func CreateDialysisFinish(finish models.XtDialysisFinish) error {
  1790. err := XTWriteDB().Create(&finish).Error
  1791. return err
  1792. }
  1793. func GetDialysisInformationSetting(user_org_id int64) (models.XtDialysisInformaitonSetting, error) {
  1794. setting := models.XtDialysisInformaitonSetting{}
  1795. err := XTReadDB().Where("user_org_id =? and status = 1", user_org_id).Find(&setting).Error
  1796. return setting, err
  1797. }
  1798. func CreatedDialysisInformation(information models.XtDialysisInformation) error {
  1799. err := XTWriteDB().Create(&information).Error
  1800. return err
  1801. }
  1802. func GetDialysisInoformationById(patient_id int64, record_date int64, user_org_id int64, module int64) (models.XtDialysisInformation, error) {
  1803. information := models.XtDialysisInformation{}
  1804. err := XTReadDB().Where("patient_id = ? and record_date = ? and user_org_id = ? and module = ? and status = 1", patient_id, record_date, user_org_id, module).Find(&information).Error
  1805. return information, err
  1806. }
  1807. func UpdateDialysisInformationById(patient_id int64, record_date int64, user_org_id int64, module int64, advice_date int64, remark string) error {
  1808. information := models.XtDialysisInformation{}
  1809. err := XTWriteDB().Model(&information).Where("patient_id = ? and record_date = ? and user_org_id =? and module = ? and status=1", patient_id, record_date, user_org_id, module).Update(map[string]interface{}{"application_date": advice_date, "remark": remark}).Error
  1810. return err
  1811. }
  1812. func UpdateDoctorAdviceByExcecute(id int64, user_org_id int64) error {
  1813. err := XTWriteDB().Model(models.DoctorAdvice{}).Where("id = ? and user_org_id = ? and status =1", id, user_org_id).Updates(map[string]interface{}{"execution_time": 0, "execution_staff": 0, "execution_state": 2}).Error
  1814. return err
  1815. }
  1816. func UpdateInformationSettingById(orgid int64, week_day int64) error {
  1817. err := XTWriteDB().Model(&models.XtDialysisInformaitonSetting{}).Where("user_org_id = ? and status =1", orgid).Updates(map[string]interface{}{"week_day": week_day}).Error
  1818. return err
  1819. }
  1820. func CreateInformationSetting(setting models.XtDialysisInformaitonSetting) error {
  1821. err := XTWriteDB().Create(&setting).Error
  1822. return err
  1823. }
  1824. func GetInformationSettingByOrgId(user_org_id int64) (models.XtDialysisInformaitonSetting, error) {
  1825. setting := models.XtDialysisInformaitonSetting{}
  1826. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&setting).Error
  1827. return setting, err
  1828. }
  1829. func GetDialysisInformationSettingList(user_org_id int64) (infor []*models.XtDialysisInformaitonSetting, err error) {
  1830. err = XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&infor).Error
  1831. return infor, err
  1832. }
  1833. func GetDialysisInformationIsNoCheck(user_org_id int64, limit int64, page int64, application_status int64) (infor []*models.DialysisInformation, total int64, err error) {
  1834. db := XTReadDB().Model(&infor).Where("status= 1")
  1835. if application_status > 0 {
  1836. db = db.Where("application_status = ?", application_status)
  1837. }
  1838. if user_org_id > 0 {
  1839. db = db.Where("user_org_id = ?", user_org_id)
  1840. }
  1841. err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Find(&infor).Error
  1842. return infor, total, err
  1843. }
  1844. func GetDialysisInformationIsNoCheckOne(user_org_id int64, limit int64, page int64, application_status int64) (infor []*models.DialysisInformation, total int64, err error) {
  1845. db := XTReadDB().Model(&infor).Where("status= 1")
  1846. if application_status > 0 {
  1847. db = db.Where("application_status = ? or application_status= 3", application_status)
  1848. }
  1849. if user_org_id > 0 {
  1850. db = db.Where("user_org_id = ?", user_org_id)
  1851. }
  1852. err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Find(&infor).Error
  1853. return infor, total, err
  1854. }
  1855. func CheckDialysisInformation(id int64, application_status int64, timenow int64, checker int64) (models.DialysisInformation, error) {
  1856. information := models.DialysisInformation{}
  1857. err := XTWriteDB().Model(&information).Where("id=? and status = 1", id).Updates(map[string]interface{}{"application_status": application_status, "check_time": timenow, "checker": checker}).Error
  1858. return information, err
  1859. }
  1860. func GetDialysisWatchByKeywordFlow(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64, start int64, end int64) ([]*models.DialysisScheduleFlow, error, int64) {
  1861. var patients []*models.Patients
  1862. 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
  1863. if getPatientErr != nil {
  1864. return nil, getPatientErr, 0
  1865. }
  1866. patientIDs := make([]int64, len(patients))
  1867. for index, patient := range patients {
  1868. patientIDs[index] = patient.ID
  1869. }
  1870. db := readDb.Model(&models.DialysisScheduleFlow{})
  1871. if start > 0 && end > 0 {
  1872. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  1873. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  1874. Preload("TreatmentMode", "status = 1").
  1875. Preload("DialysisFinish", "status = 1 AND user_org_id = ? and record_date >= ? and record_date<=?", orgID, start, end).
  1876. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  1877. } else {
  1878. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  1879. Preload("TreatmentMode", "status = 1").
  1880. Preload("DialysisFinish", "status = 1 AND user_org_id = ?", orgID).
  1881. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  1882. }
  1883. db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
  1884. if schedulType > 0 {
  1885. db = db.Where("schedule_type = ?", schedulType)
  1886. }
  1887. if start > 0 {
  1888. db = db.Where("schedule_date >= ?", start)
  1889. }
  1890. if end > 0 {
  1891. db = db.Where("schedule_date<=?", end)
  1892. }
  1893. if partitionType > 0 {
  1894. db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ?", partitionType)
  1895. }
  1896. var schedules []*models.DialysisScheduleFlow
  1897. total := int64(0)
  1898. err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
  1899. return schedules, err, total
  1900. }
  1901. func GetDialysisWatchFlow(orgID int64, schedulDate int64, schedulType int64, partitionType int64, page int64, limit int64, start int64, end int64) (schedule []*models.DialysisScheduleFlow, err error, total int64) {
  1902. db := readDb.Model(&models.DialysisScheduleFlow{})
  1903. if schedulDate > 0 {
  1904. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  1905. Preload("TreatmentMode", "status = 1").
  1906. Preload("DialysisFinish", "status = 1 AND user_org_id = ? and record_date =?", orgID, schedulDate).
  1907. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  1908. db = db.Where("xt_schedule.status = 1")
  1909. db = db.Where("schedule_date = ?", schedulDate)
  1910. }
  1911. if schedulType > 0 {
  1912. db = db.Where("schedule_type = ?", schedulType)
  1913. }
  1914. if start > 0 {
  1915. db = db.Where("schedule_date >= ?", start)
  1916. }
  1917. if end > 0 {
  1918. db = db.Where("schedule_date <= ?", end)
  1919. }
  1920. if orgID > 0 {
  1921. db = db.Where("user_org_id = ?", orgID)
  1922. }
  1923. if partitionType > 0 {
  1924. db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ?", partitionType)
  1925. }
  1926. offset := (page - 1) * limit
  1927. err = db.Count(&total).Offset(offset).Limit(limit).Order("bed_id desc").Find(&schedule).Error
  1928. return schedule, err, total
  1929. }
  1930. func GetPrescriptionInfo(user_org_id int64, patient_id int64, record_date int64) (models.HisPrescriptionInfo, error) {
  1931. info := models.HisPrescriptionInfo{}
  1932. err := XTReadDB().Where("user_org_id = ? and patient_id =? and record_date = ? and status=1", user_org_id, patient_id, record_date).Find(&info).Error
  1933. return info, err
  1934. }
  1935. func FindLastSchedule(user_org_id int64, patient_id int64, schedule_date int64) (models.XtSchedules, error) {
  1936. schedules := models.XtSchedules{}
  1937. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and schedule_date < ? and status =1", user_org_id, patient_id, schedule_date).Order("schedule_date desc").First(&schedules).Error
  1938. return schedules, err
  1939. }
  1940. func GetMonitorPatients(patient_id int64) (*models.MonitorPatients, error) {
  1941. patients := models.MonitorPatients{}
  1942. err := XTReadDB().Where("id = ? and status = 1", patient_id).Find(&patients).Error
  1943. return &patients, err
  1944. }
  1945. func GetMonitorDialysisOrderObj(patient_id int64, schedule_date int64) (*models.MonitorDialysisOrder, error) {
  1946. order := models.MonitorDialysisOrder{}
  1947. err := XTReadDB().Where("patient_id = ? and dialysis_date = ? and status = 1", patient_id, schedule_date).Find(&order).Error
  1948. return &order, err
  1949. }
  1950. func GetMonitorDialysisPrescription(patient_id int64, record_date int64) (*models.DialysisPrescription, error) {
  1951. prescription := models.DialysisPrescription{}
  1952. err := XTReadDB().Where("patient_id = ? and status =1 and record_date = ?", patient_id, record_date).Find(&prescription).Error
  1953. return &prescription, err
  1954. }
  1955. func GetMonitorPredialysisEvaluation(patient_id int64, record_date int64) (*models.PredialysisEvaluation, error) {
  1956. evaluation := models.PredialysisEvaluation{}
  1957. err := XTReadDB().Where("patient_id = ? and status =1 and assessment_date = ?", patient_id, record_date).Find(&evaluation).Error
  1958. return &evaluation, err
  1959. }
  1960. func GetMonitorAssessmentAfterDislysis(patient_id int64, record_date int64) (*models.AssessmentAfterDislysis, error) {
  1961. dislysis := models.AssessmentAfterDislysis{}
  1962. err = XTReadDB().Where("patient_id = ? and status =1 and assessment_date = ?", patient_id, record_date).Find(&dislysis).Error
  1963. return &dislysis, err
  1964. }
  1965. func GetMonitoringRecordList(patient_id int64, record_date int64) (record []*models.MonitoringRecord, err error) {
  1966. err = XTReadDB().Where("patient_id = ? and monitoring_date=? and status =1", patient_id, record_date).Find(&record).Error
  1967. return record, err
  1968. }
  1969. func GetDoctorAdviceListNoExecution(patient_id int64, dialysis_date int64, user_org_id int64) (doctor []*models.XtDoctorAdvice, err error) {
  1970. err = XTReadDB().Where("patient_id = ? and advice_date = ? and user_org_id = ? and execution_state = 2 and status =1", patient_id, dialysis_date, user_org_id).Find(&doctor).Error
  1971. return doctor, err
  1972. }
  1973. func UpdateDoctorAdviceNoExecution(id int64, creator int64, end_time int64) error {
  1974. err := XTWriteDB().Model(&models.XtDoctorAdvice{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"execution_state": 1, "execution_staff": creator, "execution_time": end_time}).Error
  1975. return err
  1976. }
  1977. func CreatePrescriptionLog(log models.XtDialysisPrescriptionLog) error {
  1978. ut := writeDb.Begin()
  1979. err := ut.Create(&log).Error
  1980. if err != nil {
  1981. ut.Rollback()
  1982. return err
  1983. }
  1984. ut.Commit()
  1985. return err
  1986. }
  1987. func CreateBeforLog(log models.XtAssessmentBeforeDislysisLog) error {
  1988. ut := writeDb.Begin()
  1989. err := XTWriteDB().Create(&log).Error
  1990. if err != nil {
  1991. ut.Rollback()
  1992. return err
  1993. }
  1994. ut.Commit()
  1995. return err
  1996. }
  1997. func CreateAfterDialysisLog(log models.XtAssessmentAfterDialysisLog) error {
  1998. ut := writeDb.Begin()
  1999. err := XTWriteDB().Create(&log).Error
  2000. if err != nil {
  2001. ut.Rollback()
  2002. return err
  2003. }
  2004. ut.Commit()
  2005. return err
  2006. }
  2007. func CreateDoctorAdviceLog(log models.XtDoctorAdviceLog) error {
  2008. ut := writeDb.Begin()
  2009. err := XTWriteDB().Create(&log).Error
  2010. if err != nil {
  2011. ut.Rollback()
  2012. return err
  2013. }
  2014. ut.Commit()
  2015. return err
  2016. }
  2017. func CreateMonitorRecordLog(log models.XtMonitorRecordLog) error {
  2018. ut := writeDb.Begin()
  2019. err := XTWriteDB().Create(&log).Error
  2020. if err != nil {
  2021. ut.Rollback()
  2022. return err
  2023. }
  2024. ut.Commit()
  2025. return err
  2026. }