dialysis_service.go 97KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054
  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 AddSigleSummaryRecord(summary *models.TreatmentSummary) (err error) {
  194. tx := writeDb.Begin()
  195. errors := tx.Model(&models.TreatmentSummary{}).Create(&summary).Error
  196. if err != nil {
  197. tx.Rollback()
  198. }
  199. tx.Commit()
  200. return errors
  201. }
  202. func AddSigleReceiveTreatmentAssesRecord(receiveTreatmentAsses *models.ReceiveTreatmentAsses) (err error) {
  203. tx := writeDb.Begin()
  204. errors := tx.Model(&models.ReceiveTreatmentAsses{}).Create(&receiveTreatmentAsses).Error
  205. if err != nil {
  206. tx.Rollback()
  207. }
  208. tx.Commit()
  209. return errors
  210. }
  211. func AddSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis *models.AssessmentAfterDislysis) (err error) {
  212. tx := writeDb.Begin()
  213. errors := tx.Model(&models.AssessmentAfterDislysis{}).Create(&assessmentAfterDislysis).Error
  214. if err != nil {
  215. tx.Rollback()
  216. }
  217. tx.Commit()
  218. return errors
  219. }
  220. func AddSigleAssessmentBeforeDislysisRecord(assessmentBeforeDislysis *models.PredialysisEvaluation) (err error) {
  221. tx := writeDb.Begin()
  222. errors := tx.Model(&models.PredialysisEvaluation{}).Create(&assessmentBeforeDislysis).Error
  223. if err != nil {
  224. tx.Rollback()
  225. }
  226. tx.Commit()
  227. return errors
  228. }
  229. func AddSigleDoubleCheck(check *models.DoubleCheck) (err error) {
  230. tx := writeDb.Begin()
  231. errors := tx.Model(&models.DoubleCheck{}).Create(&check).Error
  232. if err != nil {
  233. tx.Rollback()
  234. }
  235. tx.Commit()
  236. return errors
  237. }
  238. //修改透析处方
  239. func UpDateDialysisPrescription(dialysisPrescription *models.DialysisPrescription) error {
  240. tx := writeDb.Begin()
  241. err := writeDb.Save(&dialysisPrescription).Error
  242. if err != nil {
  243. tx.Rollback()
  244. }
  245. tx.Commit()
  246. return err
  247. }
  248. //修改接诊评估
  249. func UpadateReceiveTreatmentAsses(receiveTreatmentAsses *models.ReceiveTreatmentAsses) error {
  250. err := writeDb.Save(receiveTreatmentAsses).Error
  251. return err
  252. }
  253. //修改透前评估
  254. func UpadatePredialysisEvaluation(predialysisEvaluation *models.PredialysisEvaluation) error {
  255. err := writeDb.Save(&predialysisEvaluation).Error
  256. return err
  257. }
  258. //修改双人核对
  259. func UpdateDoubleCheck(check *models.DoubleCheck) error {
  260. err := writeDb.Save(&check).Error
  261. return err
  262. }
  263. //修改透后评估
  264. func UpdateAssessmentAfterDislysisRecord(assessmentAfterDislysis *models.AssessmentAfterDislysis) error {
  265. err := writeDb.Save(&assessmentAfterDislysis).Error
  266. return err
  267. }
  268. func UpdatePredialysisEvaluation(predialysisevaluation *models.PredialysisEvaluation, id int64) error {
  269. err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"systolic_blood_pressure": predialysisevaluation.SystolicBloodPressure}).Error
  270. return err
  271. }
  272. func UpdatePredialysisEvaluationTwo(predialysisevaluation *models.PredialysisEvaluation, id int64) error {
  273. err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"diastolic_blood_pressure": predialysisevaluation.DiastolicBloodPressure}).Error
  274. return err
  275. }
  276. func UpdatePredialysisEvaluationThree(predialysisevaluation *models.PredialysisEvaluation, id int64) error {
  277. err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"pulse_frequency": predialysisevaluation.PulseFrequency}).Error
  278. return err
  279. }
  280. func UpdatePredialysisEvaluationFour(predialysisevaluation *models.PredialysisEvaluation, id int64) error {
  281. err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"temperature": predialysisevaluation.Temperature}).Error
  282. return err
  283. }
  284. //修改
  285. func UpdateSummeRecord(treatmentSummary *models.TreatmentSummary) error {
  286. err := writeDb.Save(&treatmentSummary).Error
  287. return err
  288. }
  289. // func UpdateDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
  290. // tx := writeDb.Begin()
  291. // 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
  292. // if err != nil {
  293. // tx.Rollback()
  294. // }
  295. // tx.Commit()
  296. // return err
  297. // }
  298. func ExceDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
  299. 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
  300. return err
  301. }
  302. func ExecBatchDoctorAdvice(patient_id int64, orgid int64, ids []string, creater int64) error {
  303. 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
  304. return err
  305. }
  306. func ExceHidDoctorAdviceById(m *models.HisDoctorAdviceInfo, id int64, patientId int64) error {
  307. err := writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND (id = ? Or parent_id=?) AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error
  308. return err
  309. }
  310. func ExceHisBatchDotorAdvice(patientid int64, orgid int64, ids []string, creater int64) error {
  311. 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
  312. return err
  313. }
  314. func CheckDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
  315. 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
  316. return err
  317. }
  318. func CheckHisBathDoctorAdviceById(patientId int64, orgid int64, creater int64, ids []string) error {
  319. 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
  320. return err
  321. }
  322. func CheckBatchDoctorAdviceById(patientId int64, ids []string, orgid int64, creater int64) error {
  323. 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
  324. return err
  325. }
  326. func CheckHisDoctorAdviceById(m *models.HisDoctorAdviceInfo, id int64, patientId int64) error {
  327. 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
  328. return err
  329. }
  330. func CreateMonitor(m *models.MonitoringRecord) (err error) {
  331. return writeDb.Create(m).Error
  332. }
  333. func UpdateMonitor(m *models.MonitoringRecord) (err error) {
  334. return writeDb.Save(m).Error
  335. }
  336. func DelMonitor(patientId int64, recordId int64) error {
  337. tx := writeDb.Begin()
  338. updateTime := time.Now().Unix()
  339. 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
  340. if err != nil {
  341. tx.Rollback()
  342. }
  343. tx.Commit()
  344. return err
  345. }
  346. //修改长期处方
  347. func UpdateSolution(solution *models.DialysisSolution) {
  348. writeDb.Save(&solution)
  349. }
  350. //创建长期处方
  351. func CreateSolution(solution *models.DialysisSolution) {
  352. writeDb.Create(&solution)
  353. }
  354. func SavePrescriptionAndCreateSolution(solution *models.DialysisSolution, prescription *models.DialysisPrescription) (err error) {
  355. tx := writeDb.Begin()
  356. if prescription.ID > 0 {
  357. err = tx.Save(&prescription).Error
  358. } else {
  359. err = tx.Model(&models.DialysisPrescription{}).Create(&prescription).Error
  360. }
  361. if err != nil {
  362. tx.Rollback()
  363. return
  364. }
  365. err = tx.Create(&solution).Error
  366. if err != nil {
  367. tx.Rollback()
  368. return
  369. }
  370. tx.Commit()
  371. return
  372. }
  373. //透析处方
  374. func FindDialysisPrescriptionByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DialysisPrescription) {
  375. dialysisPrescription := models.DialysisPrescription{}
  376. err := readDb.Model(&dialysisPrescription).Where("patient_id = ? AND record_date = ? AND status = 1 AND user_org_id = ? ", id, recordDate, orgId).Find(&dialysisPrescription).Error
  377. return err, &dialysisPrescription
  378. }
  379. func FindReceiveTreatmentAssesByReordDate(id int64, recordDate int64, orgId int64) (error, *models.ReceiveTreatmentAsses) {
  380. receiveTreatmentAsses := models.ReceiveTreatmentAsses{}
  381. err := readDb.Model(&receiveTreatmentAsses).Where("patient_id = ? AND record_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).Find(&receiveTreatmentAsses).Error
  382. return err, &receiveTreatmentAsses
  383. }
  384. //透前评估
  385. func FindPredialysisEvaluationByReordDate(id int64, recordDate int64, orgId int64) (error, *models.PredialysisEvaluation) {
  386. dialysisEvaluation := models.PredialysisEvaluation{}
  387. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&dialysisEvaluation).Error
  388. return err, &dialysisEvaluation
  389. }
  390. //双人核对
  391. func FindDoubleCheckByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DoubleCheck) {
  392. check := models.DoubleCheck{}
  393. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? AND check_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&check).Error
  394. return err, &check
  395. }
  396. func FindAssessmentAfterDislysisByReordDate(id int64, recordDate int64, orgId int64) (error, *models.AssessmentAfterDislysis) {
  397. assessmentAfterDislysis := models.AssessmentAfterDislysis{}
  398. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&assessmentAfterDislysis).Error
  399. return err, &assessmentAfterDislysis
  400. }
  401. func FindTreatmentSummaryByReordDate(id int64, recordDate int64, orgId int64) (error, *models.TreatmentSummary) {
  402. summary := models.TreatmentSummary{}
  403. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&summary).Error
  404. return err, &summary
  405. }
  406. func FindDoctorAdviceByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DoctorAdvice) {
  407. advice := models.DoctorAdvice{}
  408. 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
  409. return err, &advice
  410. }
  411. func FindDialysisRecordById(orgId int64, id int64, recordDate int64) (error, *models.DialysisOrder) {
  412. var count int64
  413. dialysisRecord := models.DialysisOrder{}
  414. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgId, id, recordDate).Find(&dialysisRecord).Count(&count).Error
  415. if count <= 0 {
  416. return err, nil
  417. }
  418. return err, &dialysisRecord
  419. }
  420. func FindDialysisSchedualById(orgId int64, id int64, recordDate int64) (error, *models.Schedule) {
  421. var count int64
  422. schedule := models.Schedule{}
  423. err := readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND patient_id = ? AND schedule_date = ?", orgId, id, recordDate).Find(&schedule).Count(&count).Error
  424. if count <= 0 {
  425. return err, nil
  426. }
  427. return err, &schedule
  428. }
  429. func CreateDialysisRecord(id int64, orgId int64, record *models.DialysisOrder) error {
  430. err := writeDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? ", orgId, id).Create(&record).Error
  431. if err != nil {
  432. return err
  433. }
  434. dialysisPrescriptionErr := UpDateRecordIdToDialysisPrescription(id, orgId, record.DialysisDate, record.ID)
  435. if dialysisPrescriptionErr != nil {
  436. return dialysisPrescriptionErr
  437. }
  438. receiveTreatmentAssesErr := UpDateRecordIdToReceiveTreatmentAsses(id, orgId, record.DialysisDate, record.ID)
  439. if receiveTreatmentAssesErr != nil {
  440. return receiveTreatmentAssesErr
  441. }
  442. predialysisEvaluationErr := UpDateRecordIdToPredialysisEvaluation(id, orgId, record.DialysisDate, record.ID)
  443. if predialysisEvaluationErr != nil {
  444. return predialysisEvaluationErr
  445. }
  446. treatmentSummaryErr := UpDateRecordIdToTreatmentSummary(id, orgId, record.DialysisDate, record.ID)
  447. if treatmentSummaryErr != nil {
  448. return treatmentSummaryErr
  449. }
  450. doubleCheckErr := UpDateRecordIdToDoubleCheck(id, orgId, record.DialysisDate, record.ID)
  451. if doubleCheckErr != nil {
  452. return doubleCheckErr
  453. }
  454. adviceErrr := UpDateRecordIdToDoctorAdvice(id, orgId, record.DialysisDate, record.ID)
  455. if adviceErrr != nil {
  456. return adviceErrr
  457. }
  458. //透析监测
  459. records, err := FindAllMonitorRecord(orgId, id, record.DialysisDate)
  460. if err != nil {
  461. return err
  462. }
  463. var Ids []int64
  464. for _, item := range records {
  465. Ids = append(Ids, item.ID)
  466. }
  467. monitorErr := UpDateRecordIdToMonitor(Ids, record.ID)
  468. if monitorErr != nil {
  469. return monitorErr
  470. }
  471. return nil
  472. }
  473. 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) error {
  474. 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}).Error
  475. return err
  476. }
  477. //func ModifyDialysisRecord(id int64, finishNurse int64, end_time int64, admin_user_id int64) 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}).Error
  479. // return err
  480. //
  481. //}
  482. func UpdateSolutionByPatientId(id int64) error {
  483. err := writeDb.Model(&models.Patients{}).Where("id = ? AND status = 1 ", id).UpdateColumn("total_dialysis", gorm.Expr("total_dialysis + ?", 1)).Error
  484. return err
  485. }
  486. //更新透析处方记录ID
  487. func UpDateRecordIdToDialysisPrescription(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  488. 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
  489. return errors
  490. }
  491. func UpDateRecordIdToReceiveTreatmentAsses(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  492. 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
  493. return errors
  494. }
  495. func UpDateRecordIdToPredialysisEvaluation(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  496. 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
  497. return errors
  498. }
  499. func UpDateRecordIdToAssessmentAfterDislysis(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  500. 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
  501. return errors
  502. }
  503. func UpDateRecordIdToTreatmentSummary(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  504. 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
  505. return errors
  506. }
  507. func UpDateRecordIdToMonitor(Ids []int64, recordId int64) error {
  508. errors := writeDb.Model(&models.MonitoringRecord{}).Where("id IN (?)", Ids).Update(map[string]interface{}{"dialysis_order_id": recordId}).Error
  509. return errors
  510. }
  511. func UpDateRecordIdToDoubleCheck(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  512. 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
  513. return errors
  514. }
  515. func UpDateRecordIdToDoctorAdvice(patientId int64, orgId int64, recordTime int64, recordId int64) error {
  516. 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
  517. return errors
  518. }
  519. //透析处方
  520. func FindPatientPrescribeWidyDevideById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescriptionAddtional, err error) {
  521. err = readDb.Preload("Device", "status = 1 AND org_id = ?", orgID).
  522. Model(&models.DialysisPrescriptionAddtional{}).
  523. Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? ", patientsId, orgID, recordDate).
  524. First(&patient).Error
  525. return
  526. }
  527. func FindDialysisMode(orgID int64, patientId int64, scheduleDate int64) (models.XtSchedule, error) {
  528. schedule := models.XtSchedule{}
  529. err = readDb.Where("user_org_id = ? and patient_id = ? and schedule_date = ? ", orgID, patientId, scheduleDate).Find(&schedule).Error
  530. return schedule, err
  531. }
  532. func FindDialysisMacher(orgid int64, patientid int64, dialysisDate int64) (models.XtDialysisOrders, error) {
  533. orders := models.XtDialysisOrders{}
  534. db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
  535. table := readDb.Table("xt_device_number as n")
  536. fmt.Print("table", table)
  537. 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
  538. return orders, err
  539. }
  540. func FindPunctureNurse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  541. role := models.App_Roles{}
  542. //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error
  543. //return role, err
  544. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status =1")
  545. 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
  546. return role, err
  547. }
  548. func FindeStartNuse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  549. role := models.App_Roles{}
  550. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  551. 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
  552. //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error
  553. return role, err
  554. }
  555. func FindeQualityNurse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  556. role := models.App_Roles{}
  557. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  558. 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
  559. return role, err
  560. }
  561. func FindDialysisWay(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  562. prescription := models.DialysisPrescription{}
  563. err := readDb.Where("user_org_id = ? and patient_id = ? and record_date = ? and status =1", orgid, patientid, recorddate).Find(&prescription).Error
  564. return prescription, err
  565. }
  566. func FindDoctorOrder(orgid int64, patientid int64, adviceDate int64) (models.XtDoctorAdvice, error) {
  567. advices := models.XtDoctorAdvice{}
  568. db := readDb.Table("xt_doctor_advice as a").Where("a.status = ?", 1)
  569. 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
  570. return advices, err
  571. }
  572. func FindDoctor(adminuserid int64, appid int64, orgid int64) (models.App_Role, error) {
  573. role := models.App_Role{}
  574. err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminuserid, appid, orgid).Find(&role).Error
  575. return role, err
  576. }
  577. func FindDoctorName(adminid int64, appid int64, orgid int64) (models.App_Roles, error) {
  578. role := models.App_Roles{}
  579. db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  580. 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
  581. //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error
  582. return role, err
  583. }
  584. /////////////// 新 18-10-22
  585. func GetDialysisScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  586. var vms []*MDialysisScheduleVM
  587. db := readDb.
  588. Table("xt_schedule").
  589. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  590. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  591. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  592. Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
  593. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  594. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  595. Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  596. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  597. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  598. Where("status = 1 AND user_org_id = ?", orgID)
  599. if scheduleDate != 0 {
  600. db = db.Where("schedule_date = ?", scheduleDate)
  601. }
  602. err := db.Find(&vms).Error
  603. return vms, err
  604. }
  605. func GetDialysisSchedualsOne(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  606. var vms []*MDialysisScheduleVM
  607. db := readDb.
  608. Table("xt_schedule").
  609. Preload("DeviceNumber", "org_id = ?", orgID).
  610. Preload("DeviceNumber.Zone", "org_id = ?", orgID).
  611. //Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
  612. //Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  613. //Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  614. //Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  615. //Preload("Advices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  616. //Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  617. Where("status = 1 AND user_org_id = ?", orgID)
  618. if scheduleDate != 0 {
  619. db = db.Where("schedule_date = ?", scheduleDate)
  620. }
  621. err := db.Find(&vms).Error
  622. return vms, err
  623. }
  624. func GetLastAcceptsAssessment(patient int64, orgId int64) (error, models.ReceiveTreatmentAsses) {
  625. var receiveTreatmentAsses models.ReceiveTreatmentAsses
  626. err := readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? AND status = 1 AND user_org_id = ?", patient, orgId).Last(&receiveTreatmentAsses).Error
  627. return err, receiveTreatmentAsses
  628. }
  629. 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) {
  630. db := readDb.Model(&models.MonitorDialysisSchedule{})
  631. if start > 0 && end > 0 {
  632. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  633. Preload("TreatmentMode", "status = 1").
  634. Preload("Prescription", "status = 1 AND user_org_id = ? and record_date>=? and record_date <=?", orgID, start, end).
  635. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date >=? and assessment_date <=?", orgID, start, end).
  636. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date >=? and assessment_date <=?", orgID, start, end).
  637. Preload("MonitoringRecord", func(db *gorm.DB) *gorm.DB {
  638. return db.Where("status = 1 AND user_org_id = ? and monitoring_date >=? and monitoring_date<=? ", orgID, start, end).Order("operate_time asc")
  639. }).
  640. Preload("DialysisOrder", "status = 1 AND user_org_id = ? and dialysis_date>=? and dialysis_date<=?", orgID, start, end).
  641. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  642. db = db.Where("xt_schedule.status = 1")
  643. }
  644. if schedulDate > 0 {
  645. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  646. Preload("TreatmentMode", "status = 1").
  647. Preload("Prescription", "status = 1 AND user_org_id = ? and record_date>=? and record_date <=?", orgID, schedulDate, schedulDate).
  648. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date >=? and assessment_date <=?", orgID, schedulDate, schedulDate).
  649. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date >=? and assessment_date <=?", orgID, schedulDate, schedulDate).
  650. Preload("MonitoringRecord", func(db *gorm.DB) *gorm.DB {
  651. return db.Where("status = 1 AND user_org_id = ? and monitoring_date >=? and monitoring_date<=? ", orgID, schedulDate, schedulDate).Order("operate_time asc")
  652. }).
  653. Preload("DialysisOrder", "status = 1 AND user_org_id = ? and dialysis_date>=? and dialysis_date<=?", orgID, schedulDate, schedulDate).
  654. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  655. db = db.Where("xt_schedule.status = 1")
  656. db = db.Where("schedule_date = ?", schedulDate)
  657. }
  658. if schedulType > 0 {
  659. db = db.Where("schedule_type = ?", schedulType)
  660. }
  661. if start > 0 {
  662. db = db.Where("schedule_date >= ?", start)
  663. }
  664. if end > 0 {
  665. db = db.Where("schedule_date <= ?", end)
  666. }
  667. if orgID > 0 {
  668. db = db.Where("user_org_id = ?", orgID)
  669. }
  670. if partitionType > 0 {
  671. db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ?", partitionType)
  672. // db = db.Where("partition_id = ?", partitionType)
  673. }
  674. offset := (page - 1) * limit
  675. err = db.Count(&total).Offset(offset).Limit(limit).Order("bed_id desc").Find(&schedule).Error
  676. return schedule, err, total
  677. }
  678. //func GetDialysisWatchByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64) (schedules []*models.DialysisSchedule, err error, total int64) {
  679. // db := readDb.Model(&models.DialysisSchedule{}).Where("status = 1")
  680. //
  681. // if schedulType > 0 {
  682. // db = db.Where("scheudle_type = ?", schedulType)
  683. // }
  684. //
  685. // if partitionType > 0 {
  686. // db = db.Where("partition_id = ?", partitionType)
  687. // }
  688. //
  689. // err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
  690. // return schedules, err, total
  691. //}
  692. func GetDialysisWatchByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64, start int64, end int64) ([]*models.DialysisSchedule, error, int64) {
  693. var patients []*models.Patients
  694. 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
  695. if getPatientErr != nil {
  696. return nil, getPatientErr, 0
  697. }
  698. patientIDs := make([]int64, len(patients))
  699. for index, patient := range patients {
  700. patientIDs[index] = patient.ID
  701. }
  702. db := readDb.Model(&models.DialysisSchedule{})
  703. if start > 0 && end > 0 {
  704. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  705. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  706. Preload("TreatmentMode", "status = 1").
  707. Preload("Prescription", "status = 1 AND user_org_id = ? and record_date>=? and record_date<=?", orgID, start, end).
  708. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date>=? and assessment_date<=?", orgID, start, end).
  709. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date>=? and assessment_date<=?", orgID, start, end).
  710. Preload("MonitoringRecord", "status = 1 AND user_org_id = ? and monitoring_date>=? and monitoring_date<=?", orgID, start, end).
  711. Preload("DialysisOrder", "status = 1 AND user_org_id = ? and dialysis_date >= ? and dialysis_date<=?", orgID, start, end).
  712. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  713. } else {
  714. db = db.Preload("DeviceNumber", "org_id = ?", orgID).
  715. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  716. Preload("TreatmentMode", "status = 1").
  717. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  718. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  719. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  720. Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  721. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  722. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  723. }
  724. db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
  725. if schedulType > 0 {
  726. db = db.Where("schedule_type = ?", schedulType)
  727. }
  728. if start > 0 {
  729. db = db.Where("schedule_date >= ?", start)
  730. }
  731. if end > 0 {
  732. db = db.Where("schedule_date<=?", end)
  733. }
  734. if partitionType > 0 {
  735. 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)
  736. // db = db.Where("partition_id = ?", partitionType)
  737. }
  738. var schedules []*models.DialysisSchedule
  739. total := int64(0)
  740. err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
  741. return schedules, err, total
  742. }
  743. func GetAdminUserES(orgID int64, appID int64, ids []int64) (es []*models.AdminUserElectronicSignature, err error) {
  744. err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id=? and creator in (?) and status=1", orgID, appID, ids).Find(&es).Error
  745. return
  746. }
  747. //
  748. //func GetAdminUserEsOne(orgid int64) (admin []*models.UserAdminRoles, err error) {
  749. //
  750. // db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1")
  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 GetAdminUserEsOne(orgid int64) (admin []*models.UserAdminRoles, err error) {
  757. db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status =1")
  758. table := readUserDb.Table("sgj_user_admin_electronic_signature as s")
  759. fmt.Println("table", table)
  760. 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
  761. return admin, err
  762. }
  763. func UpDateDialysisPrescriptionDoctorSign(patient int64, date int64, orgId int64, doctor_id int64) (err error) {
  764. 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
  765. return
  766. }
  767. func GetAllAdminUserES(orgID int64, appId int64) (es []*models.AdminUserElectronicSignature, err error) {
  768. err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id = ? and status=1", orgID, appId).Find(&es).Error
  769. return
  770. }
  771. func GetAllStarfEs(orgid int64) (es []*models.SgjUserAdminRoles, err error) {
  772. redis := RedisClient()
  773. defer redis.Close()
  774. // cur_date := time.Now().Format("2006-01-02")
  775. key := strconv.FormatInt(orgid, 10) + ":starfes"
  776. starfes_str, _ := redis.Get(key).Result()
  777. if len(starfes_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  778. db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1")
  779. 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
  780. if err != nil {
  781. if err == gorm.ErrRecordNotFound {
  782. if len(es) <= 0 {
  783. redis.Set(key, "starfes_str_null", time.Second*60*60*18)
  784. }
  785. return nil, nil
  786. } else {
  787. return nil, err
  788. }
  789. } else {
  790. if len(es) > 0 {
  791. //缓存数据
  792. starfes_str, err := json.Marshal(es)
  793. if err == nil {
  794. redis.Set(key, starfes_str, time.Second*60*60*18)
  795. return es, nil
  796. }
  797. } else {
  798. redis.Set(key, "starfes_str_null", time.Second*60*60*18)
  799. return es, nil
  800. }
  801. return es, nil
  802. }
  803. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  804. if starfes_str == "starfes_str_null" {
  805. return es, nil
  806. } else {
  807. json.Unmarshal([]byte(starfes_str), &es)
  808. return es, nil
  809. }
  810. }
  811. }
  812. func FindLastMonitorRecord(patient_id int64, org_id int64) (record models.MonitoringRecord, err error) {
  813. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND status = 1 AND user_org_id = ?", patient_id, org_id).Last(&record).Error
  814. return
  815. }
  816. func FindLastMonitorRecordToday(patient_id int64, org_id int64, monitoring_date int64) (record models.MonitoringRecord, err error) {
  817. 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
  818. return
  819. }
  820. func FindFirstMonitorRecordToday(patient_id int64, org_id int64, monitoring_date int64) (record models.MonitoringRecord, err error) {
  821. 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
  822. return
  823. }
  824. func ExceDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  825. ut := writeDb.Begin()
  826. 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
  827. if err != nil {
  828. ut.Rollback()
  829. return
  830. }
  831. ut.Commit()
  832. return err
  833. }
  834. func GetExceDoctorAdviceGroupNo(groupNo int64, org_id int64) (advice []*models.DoctorAdvice, err error) {
  835. err = XTReadDB().Where("groupno = ? AND user_org_id = ? AND status = 1", groupNo, org_id).Find(&advice).Error
  836. return advice, err
  837. }
  838. func ExceOldDoctorAdvice(m *models.DoctorAdvice, advice_id int64) (err error) {
  839. ut := writeDb.Begin()
  840. 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
  841. if err != nil {
  842. ut.Rollback()
  843. return
  844. }
  845. 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
  846. if err != nil {
  847. ut.Rollback()
  848. return
  849. }
  850. ut.Commit()
  851. return err
  852. }
  853. func CheckDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  854. ut := writeDb.Begin()
  855. 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
  856. if err != nil {
  857. ut.Rollback()
  858. return
  859. }
  860. ut.Commit()
  861. return err
  862. }
  863. func CheckOldDoctorAdvice(m *models.DoctorAdvice, advice_id int64) (err error) {
  864. ut := writeDb.Begin()
  865. 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
  866. if err != nil {
  867. ut.Rollback()
  868. return
  869. }
  870. 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
  871. if err != nil {
  872. ut.Rollback()
  873. return
  874. }
  875. ut.Commit()
  876. return err
  877. }
  878. func DeleteDoctorAdviceByGroupNo(m *models.DoctorAdvice) (err error) {
  879. ut := writeDb.Begin()
  880. 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
  881. if err != nil {
  882. ut.Rollback()
  883. return
  884. }
  885. ut.Commit()
  886. return
  887. }
  888. func GetDialysisBoard(orgID int64, scheduleDate int64, offset, limit int64) ([]*models.DialysisBoardVM, error) {
  889. var boards []*models.DialysisBoardVM
  890. db := readDb.
  891. Table("xt_schedule").
  892. Preload("Patient", "status = 1 AND user_org_id = ?", orgID).
  893. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  894. Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  895. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  896. Preload("SigninAndWeigh", "status = 1 AND user_org_id = ?", orgID).
  897. Preload("NextSchedules", func(db *gorm.DB) *gorm.DB {
  898. return db.Where("user_org_id = ? AND schedule_date > ? AND status = 1", orgID, scheduleDate).
  899. Order("schedule_date asc, id asc")
  900. }).
  901. Where("status = 1 AND user_org_id = ?", orgID)
  902. if scheduleDate != 0 {
  903. db = db.Where("schedule_date = ?", scheduleDate)
  904. }
  905. err := db.Offset(offset).Limit(limit).Find(&boards).Error
  906. return boards, err
  907. }
  908. func GetOneDialysisOrder(orgID, orderData int64, patient_id int64) (*models.DialysisOrder, error) {
  909. var order models.DialysisOrder
  910. var err error
  911. 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
  912. if err == gorm.ErrRecordNotFound {
  913. return nil, nil
  914. }
  915. if err != nil {
  916. return nil, err
  917. }
  918. return &order, nil
  919. }
  920. func GetOrgInfoTemplate(orgID int64) (models.GobalTemplate, error) {
  921. var templateInfo models.GobalTemplate
  922. var err error
  923. err = readDb.Model(&models.GobalTemplate{}).Where("org_id=? and status=1", orgID).First(&templateInfo).Error
  924. return templateInfo, err
  925. }
  926. func FindAdminRoleTypeById(orgId int64, adminUserId int64, appId int64) (models.App_Role, error) {
  927. var appRole models.App_Role
  928. var err error
  929. 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
  930. return appRole, err
  931. }
  932. func BatchExceOldDoctorAdvice(m *models.DoctorAdvice, ids []string) (err error) {
  933. ut := writeDb.Begin()
  934. 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
  935. if err != nil {
  936. ut.Rollback()
  937. return
  938. }
  939. 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
  940. if err != nil {
  941. ut.Rollback()
  942. return
  943. }
  944. ut.Commit()
  945. return err
  946. }
  947. func BatchCheckOldDoctorAdvice(m *models.DoctorAdvice, ids []string, org_id int64, date int64) (err error) {
  948. ut := writeDb.Begin()
  949. 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
  950. if err != nil {
  951. ut.Rollback()
  952. return
  953. }
  954. 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
  955. if err != nil {
  956. ut.Rollback()
  957. return
  958. }
  959. ut.Commit()
  960. return err
  961. }
  962. func ModifyScheduleMode(mode_id int64, patient_id int64, recordDate int64, org_id int64, dialysis_machine_name string) {
  963. ut := writeDb.Begin()
  964. 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
  965. if err != nil {
  966. ut.Rollback()
  967. return
  968. }
  969. ut.Commit()
  970. }
  971. func FindDialysisOrderById(id int64) (error, *models.DialysisOrder) {
  972. dialysisRecord := models.DialysisOrder{}
  973. err := readDb.Model(&models.DialysisOrder{}).Where("id = ? AND status = 1", id).Find(&dialysisRecord).Error
  974. return err, &dialysisRecord
  975. }
  976. func ModifyExceDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) {
  977. ut := writeDb.Begin()
  978. 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
  979. if err != nil {
  980. ut.Rollback()
  981. return
  982. }
  983. ut.Commit()
  984. return err
  985. }
  986. func BatchModifyExceOldDoctorAdvice(m *models.DoctorAdvice, ids []string) (err error) {
  987. ut := writeDb.Begin()
  988. 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
  989. if err != nil {
  990. ut.Rollback()
  991. return
  992. }
  993. 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
  994. if err != nil {
  995. ut.Rollback()
  996. return
  997. }
  998. ut.Commit()
  999. return err
  1000. }
  1001. func UpdateOrderCount(good_type_id int64, good_id int64, number string, org_id int64) {
  1002. 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))
  1003. }
  1004. func UpdateOrderInfoDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, newNiprocart int64, out *models.WarehouseOutInfo) {
  1005. 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})
  1006. }
  1007. func FindOrderInfoByGoodId(good_type_id int64, good_id int64, number string, org_id int64) (err error, out models.WarehouseOutInfo) {
  1008. 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
  1009. return
  1010. }
  1011. func FindGoodUserById(good_type_id int64, good_id int64, id int64, org_id int64, record_time int64) (user models.AutomaticReduceDetail, err error) {
  1012. 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
  1013. return
  1014. }
  1015. func FindOldOrderInfoByGoodId(time int64, org_id int64) (err error, out models.WarehouseOutInfo) {
  1016. err = readDb.Model(&models.WarehouseOutInfo{}).Where(" org_id = ? AND status = 1 AND sys_record_time = ? ", org_id, time).First(&out).Error
  1017. return
  1018. }
  1019. func FindStockOutOrderNumberByTime(time int64, org_id int64) (err error, out models.WarehouseOut) {
  1020. err = readDb.Model(&models.WarehouseOut{}).Where(" org_id = ? AND status = 1 AND warehouse_out_time = ? ", org_id, time).First(&out).Error
  1021. return
  1022. }
  1023. func UpdateDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, newNiprocart int64, out *models.WarehouseOutInfo) {
  1024. 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})
  1025. }
  1026. func FindPatientIsOpenRemindById(patient_id int64, org_id int64) (patients models.Patients, err error) {
  1027. err = readDb.Model(&models.Patients{}).Where("status = 1 AND id = ? AND user_org_id = ?", patient_id, org_id).First(&patients).Error
  1028. return
  1029. }
  1030. func GetMaxLongAdviceGroupID(orgId int64, patient_id int64) (group int64) {
  1031. var advice models.DoctorAdvice
  1032. 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
  1033. if err != nil {
  1034. fmt.Println(err)
  1035. group = 0
  1036. }
  1037. group = advice.GroupNo
  1038. return
  1039. }
  1040. func GetLastLongAdviceByGroupNo(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  1041. 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
  1042. return
  1043. }
  1044. func GetLastLongAdviceByGroupNoOne(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  1045. redis := RedisClient()
  1046. defer redis.Close()
  1047. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":long_advice"
  1048. long_advice_str, _ := redis.Get(key).Result()
  1049. if len(long_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1050. 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
  1051. if err != nil {
  1052. if err == gorm.ErrRecordNotFound {
  1053. return nil, nil
  1054. } else {
  1055. return nil, err
  1056. }
  1057. } else {
  1058. if len(advice) > 0 {
  1059. //缓存数据
  1060. starfes_str, err := json.Marshal(advice)
  1061. if err == nil {
  1062. redis.Set(key, starfes_str, time.Second*60*60*18)
  1063. return advice, nil
  1064. }
  1065. } else {
  1066. redis.Set(key, "null", time.Second*60*60*18)
  1067. return advice, nil
  1068. }
  1069. return advice, nil
  1070. }
  1071. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1072. if long_advice_str == "null" {
  1073. return advice, nil
  1074. } else {
  1075. json.Unmarshal([]byte(long_advice_str), &advice)
  1076. return advice, nil
  1077. }
  1078. }
  1079. 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
  1080. return
  1081. }
  1082. func GetLastLongAdviceByGroupNoThree(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  1083. 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
  1084. return
  1085. }
  1086. func GetLastLongAdviceByGroupNoFour(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  1087. //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
  1088. //return
  1089. redis := RedisClient()
  1090. defer redis.Close()
  1091. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":long_advice"
  1092. long_advice_str, _ := redis.Get(key).Result()
  1093. if len(long_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1094. 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
  1095. if err != nil {
  1096. if err == gorm.ErrRecordNotFound {
  1097. return nil, nil
  1098. } else {
  1099. return nil, err
  1100. }
  1101. } else {
  1102. if len(advice) > 0 {
  1103. //缓存数据
  1104. starfes_str, err := json.Marshal(advice)
  1105. if err == nil {
  1106. redis.Set(key, starfes_str, time.Second*60*60*18)
  1107. return advice, nil
  1108. }
  1109. } else {
  1110. redis.Set(key, "null", time.Second*60*60*18)
  1111. return advice, nil
  1112. }
  1113. return advice, nil
  1114. }
  1115. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1116. if long_advice_str == "null" {
  1117. return advice, nil
  1118. } else {
  1119. json.Unmarshal([]byte(long_advice_str), &advice)
  1120. return advice, nil
  1121. }
  1122. }
  1123. 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
  1124. return
  1125. }
  1126. func FindAllDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, temp_id string) (advice []*models.DoctorAdvice, err error) {
  1127. 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
  1128. return
  1129. }
  1130. func UpdateScheduleModeId(patient_id int64, org_id int64, date int64, mode_id int64) (err error) {
  1131. 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
  1132. return
  1133. }
  1134. func UpdateAssessmentAfterDate(patient_id int64, org_id int64, date int64, actual_treatment_hour int64, actual_treatment_minute int64) (err error) {
  1135. 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
  1136. return
  1137. }
  1138. func UpdateAssessmentAfterDateOne(patient_id int64, org_id int64, date int64, actual_treatment_hour int64, actual_treatment_minute int64, BreathingRate string) (err error) {
  1139. 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
  1140. return
  1141. }
  1142. func CreateDialysisBeforePrepare(beforePrepares []*models.DialysisBeforePrepare) (err error) {
  1143. if len(beforePrepares) > 0 {
  1144. utx := writeDb.Begin()
  1145. if len(beforePrepares) > 0 {
  1146. 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 "
  1147. insertParams := make([]string, 0)
  1148. insertData := make([]interface{}, 0)
  1149. for _, prepare := range beforePrepares {
  1150. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)")
  1151. insertData = append(insertData, prepare.UserOrgId)
  1152. insertData = append(insertData, prepare.PatientId)
  1153. insertData = append(insertData, prepare.RecordDate)
  1154. insertData = append(insertData, prepare.GoodId)
  1155. insertData = append(insertData, prepare.GoodTypeId)
  1156. insertData = append(insertData, prepare.Count)
  1157. insertData = append(insertData, prepare.Ctime)
  1158. insertData = append(insertData, prepare.Mtime)
  1159. insertData = append(insertData, prepare.Creater)
  1160. insertData = append(insertData, prepare.Modifier)
  1161. insertData = append(insertData, 1)
  1162. insertData = append(insertData, prepare.CommdityCode)
  1163. }
  1164. thisSQL += strings.Join(insertParams, ", ")
  1165. err = utx.Exec(thisSQL, insertData...).Error
  1166. if err != nil {
  1167. utx.Rollback()
  1168. return
  1169. }
  1170. }
  1171. utx.Commit()
  1172. }
  1173. return
  1174. }
  1175. func UpdateDialysisBeforePrepare(info *models.DialysisBeforePrepare) (err error) {
  1176. err = writeDb.Save(&info).Error
  1177. return err
  1178. }
  1179. func UpdateDialysisBeforePrepareTwo(info *models.DialysisBeforePrepare) (err error) {
  1180. err = writeDb.Model(&models.DialysisBeforePrepare{}).
  1181. 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).
  1182. Updates(map[string]interface{}{"count": info.Count, "updated_time": time.Now().Unix(), "modifier": info.Modifier, "commdity_code": info.CommdityCode, "status": 1}).Error
  1183. return err
  1184. }
  1185. func UpdateAutoReduceDetailSix(detail *models.AutomaticReduceDetail) (err error) {
  1186. 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
  1187. return err
  1188. }
  1189. func UpdateOrderCountSub(good_type_id int64, good_id int64, number string, org_id int64, count int64) {
  1190. 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))
  1191. }
  1192. func UpdateOrderCountAdd(good_type_id int64, good_id int64, number string, org_id int64, count int64) {
  1193. 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))
  1194. }
  1195. func UpdateUserInfoDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.WarehouseOutInfo) {
  1196. 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})
  1197. //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)
  1198. }
  1199. func UpdateDrugUserInfoDetails(drug_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.DrugWarehouseOutInfo) {
  1200. 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})
  1201. //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)
  1202. }
  1203. func FindDialysisBeforePrepare(patient_id int64, good_id int64, good_type_id int64, user_org_id int64, record_time int64) (count int64) {
  1204. 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)
  1205. return
  1206. }
  1207. func GetExecutionDoctors(orgid int64, patientid int64, id int64) (doctorAdvice []*models.DoctorAdvice, err error) {
  1208. 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
  1209. return doctorAdvice, err
  1210. }
  1211. func GetHisExecutionDoctors(orgid int64, patientid int64, id int64) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) {
  1212. 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
  1213. return doctorAdvice, err
  1214. }
  1215. func GetHisExecutionDoctorsTwo(orgid int64, patientid int64, id int64) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) {
  1216. 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
  1217. return doctorAdvice, err
  1218. }
  1219. func FindHisDoctorAdviceById(orgID int64, id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1220. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error
  1221. return
  1222. }
  1223. func FindHisDoctorAdviceByIds(orgID int64, ids []string) (advice []*models.HisDoctorAdviceInfo, err error) {
  1224. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id in (?)", orgID, ids).Find(&advice).Error
  1225. return
  1226. }
  1227. func SaveHisDoctorAdvice(advice *models.HisDoctorAdviceInfo) (err error) {
  1228. err = writeDb.Save(&advice).Error
  1229. return
  1230. }
  1231. func GetGoodInfoMation(orgid int64) (goodinfo []*models.GoodInfo, err error) {
  1232. 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
  1233. //err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Find(&goodinfo).Error
  1234. return goodinfo, err
  1235. }
  1236. func GetGoodInfoMationSix(orgid int64, storehouse_id int64) (goodinfo []*models.GoodInfo, err error) {
  1237. 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
  1238. return goodinfo, err
  1239. }
  1240. func GetGoodInfoMationSeven(orgid int64, storehouse_id int64) (goodinfo []*models.GoodInfo, err error) {
  1241. 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 = ?", storehouse_id).Find(&goodinfo).Error
  1242. return goodinfo, err
  1243. }
  1244. func GetDialysisBeforePrepare(goodTypeId int64, goodId int64, orgid int64, patientId int64) (*models.DialysisBeforePrepare, error) {
  1245. prepare := models.DialysisBeforePrepare{}
  1246. 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
  1247. if err == gorm.ErrRecordNotFound {
  1248. return nil, err
  1249. }
  1250. if err != nil {
  1251. return nil, err
  1252. }
  1253. return &prepare, nil
  1254. }
  1255. func CreateDialysisBeforePrepareOne(prepare *models.DialysisBeforePrepare) error {
  1256. err := XTReadDB().Create(&prepare).Error
  1257. return err
  1258. }
  1259. func ModifyExceDoctorAdviceById(m *models.HisDoctorAdviceInfo, ids []string) (err error) {
  1260. ut := writeDb.Begin()
  1261. 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
  1262. if err != nil {
  1263. ut.Rollback()
  1264. return
  1265. }
  1266. 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
  1267. if err != nil {
  1268. ut.Rollback()
  1269. return
  1270. }
  1271. ut.Commit()
  1272. return err
  1273. }
  1274. func FindHisDoctorAdviceByIdOne(orgID int64, ids []string) (advice []models.HisDoctorAdviceInfo, err error) {
  1275. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id IN (?) AND user_org_id = ? AND status = 1", ids, orgID).Find(&advice).Error
  1276. return
  1277. }
  1278. func ModifyHisPrescriptionProject(m *models.HisPrescriptionProject, ids []string) (err error) {
  1279. ut := writeDb.Begin()
  1280. 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
  1281. if err != nil {
  1282. ut.Rollback()
  1283. return
  1284. }
  1285. ut.Commit()
  1286. return err
  1287. }
  1288. func FindHisProjectById(orgID int64, id int64) (advice models.HisPrescriptionProject, err error) {
  1289. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error
  1290. return
  1291. }
  1292. func SaveHisProject(advice *models.HisPrescriptionProject) (err error) {
  1293. err = writeDb.Save(&advice).Error
  1294. return
  1295. }
  1296. func FindAllHisProjectById(orgID int64, patient_id int64, record_time int64) (advice []*models.HisPrescriptionProject, err error) {
  1297. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1 and user_org_id = ?", 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
  1298. return
  1299. }
  1300. func GetAllPcPatientListByListSeven(orgID int64) (patients []*MSchedualPatientVMList, err error) {
  1301. err = readDb.Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
  1302. return patients, err
  1303. }
  1304. func GetAllPcPatientListByListEight(orgID int64) (patients []*MSchedualPatientVMList, err error) {
  1305. err = readDb.Where("user_org_id=? and status=1", orgID).Find(&patients).Error
  1306. return patients, err
  1307. }
  1308. func GetAllPcPatientListByList(orgID int64) (patients []*MSchedualPatientVMList, err error) {
  1309. redis := RedisClient()
  1310. defer redis.Close()
  1311. key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
  1312. patient_info_str, _ := redis.Get(key).Result()
  1313. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1314. err = readDb.Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
  1315. if err != nil {
  1316. if err == gorm.ErrRecordNotFound {
  1317. if len(patients) <= 0 {
  1318. redis.Set(key, "null", time.Second*60*60*18)
  1319. }
  1320. return nil, nil
  1321. } else {
  1322. return nil, err
  1323. }
  1324. } else {
  1325. if len(patients) > 0 {
  1326. //缓存数据
  1327. patient_info_json, err := json.Marshal(&patients)
  1328. if err == nil {
  1329. redis.Set(key, patient_info_json, time.Second*60*60*18)
  1330. }
  1331. } else {
  1332. redis.Set(key, "null", time.Second*60*60*18)
  1333. }
  1334. return patients, nil
  1335. }
  1336. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1337. if patient_info_str == "null" {
  1338. return nil, nil
  1339. } else {
  1340. json.Unmarshal([]byte(patient_info_str), &patients)
  1341. return patients, nil
  1342. }
  1343. }
  1344. }
  1345. func GetAllPcAdvicestByList(orgID int64, scheduleDate int64) (advices []*VMDoctorAdvice, err error) {
  1346. redis := RedisClient()
  1347. defer redis.Close()
  1348. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":advice_list_all"
  1349. advice_list_str, _ := redis.Get(key).Result()
  1350. if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1351. err = readDb.Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).Find(&advices).Error
  1352. if err != nil {
  1353. if err == gorm.ErrRecordNotFound {
  1354. if len(advices) <= 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(advices) > 0 {
  1363. //缓存数据
  1364. advice_list_str, err := json.Marshal(&advices)
  1365. if err == nil {
  1366. redis.Set(key, advice_list_str, time.Second*60*60*18)
  1367. }
  1368. } else {
  1369. redis.Set(key, "null", time.Second*60*60*18)
  1370. }
  1371. return advices, nil
  1372. }
  1373. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1374. if advice_list_str == "null" {
  1375. return nil, nil
  1376. } else {
  1377. json.Unmarshal([]byte(advice_list_str), &advices)
  1378. return advices, nil
  1379. }
  1380. }
  1381. }
  1382. func GetAllPcDialysisOrdersByList(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVMList, err error) {
  1383. redis := RedisClient()
  1384. defer redis.Close()
  1385. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
  1386. dialysis_orders_list_all, _ := redis.Get(key).Result()
  1387. if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1388. 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
  1389. if err != nil {
  1390. if err == gorm.ErrRecordNotFound {
  1391. return nil, nil
  1392. } else {
  1393. return nil, err
  1394. }
  1395. } else {
  1396. if len(dialysisOrders) > 0 {
  1397. //缓存数据
  1398. dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
  1399. if err == nil {
  1400. redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
  1401. }
  1402. } else {
  1403. redis.Set(key, "null", time.Second*60*60*18)
  1404. }
  1405. return dialysisOrders, nil
  1406. }
  1407. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1408. if dialysis_orders_list_all == "null" {
  1409. return nil, nil
  1410. } else {
  1411. json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
  1412. return dialysisOrders, nil
  1413. }
  1414. }
  1415. }
  1416. func GetAllPcAssessmentAfterDislysisByList(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*AssessmentAfterDislysis, err error) {
  1417. redis := RedisClient()
  1418. defer redis.Close()
  1419. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1420. assessment_after_dislysis__all, _ := redis.Get(key).Result()
  1421. if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1422. err = readDb.Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
  1423. if err != nil {
  1424. if err == gorm.ErrRecordNotFound {
  1425. if len(assessmentAfterDislysis) <= 0 {
  1426. redis.Set(key, "null", time.Second*60*60*18)
  1427. }
  1428. return nil, nil
  1429. } else {
  1430. return nil, err
  1431. }
  1432. } else {
  1433. if len(assessmentAfterDislysis) > 0 {
  1434. //缓存数据
  1435. assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
  1436. if err == nil {
  1437. redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
  1438. }
  1439. } else {
  1440. redis.Set(key, "null", time.Second*60*60*18)
  1441. }
  1442. return assessmentAfterDislysis, nil
  1443. }
  1444. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1445. if assessment_after_dislysis__all == "null" {
  1446. return nil, nil
  1447. } else {
  1448. json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
  1449. return assessmentAfterDislysis, nil
  1450. }
  1451. }
  1452. }
  1453. func GetAllPcTreatmentSummarysByList(orgID int64, scheduleDate int64) (treatmentSummarys []*VMTreatmentSummary, err error) {
  1454. redis := RedisClient()
  1455. defer redis.Close()
  1456. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":treatment_summarys_list_all"
  1457. treatment_summarys_all, _ := redis.Get(key).Result()
  1458. if len(treatment_summarys_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1459. err = readDb.Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&treatmentSummarys).Error
  1460. if err != nil {
  1461. if err == gorm.ErrRecordNotFound {
  1462. if len(treatment_summarys_all) <= 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(treatmentSummarys) > 0 {
  1471. //缓存数据
  1472. treatment_summarys_all, err := json.Marshal(&treatmentSummarys)
  1473. if err == nil {
  1474. redis.Set(key, treatment_summarys_all, time.Second*60*60*18)
  1475. }
  1476. } else {
  1477. redis.Set(key, "null", time.Second*60*60*18)
  1478. }
  1479. return treatmentSummarys, nil
  1480. }
  1481. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1482. if treatment_summarys_all == "null" {
  1483. return nil, nil
  1484. } else {
  1485. json.Unmarshal([]byte(treatment_summarys_all), &treatmentSummarys)
  1486. return treatmentSummarys, nil
  1487. }
  1488. }
  1489. }
  1490. func UpdateTeamProjectExceStatus(ids []int64, admin_user_id int64, execution_time int64) (err error) {
  1491. ut := writeDb.Begin()
  1492. db := ut.Model(&models.HisPrescriptionProject{})
  1493. 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
  1494. if err != nil {
  1495. ut.Rollback()
  1496. return
  1497. }
  1498. ut.Commit()
  1499. return err
  1500. }
  1501. func UpdateTeamProjectCheckStatus(ids []int64, patient_id int64, record_date int64, user_org_id int64, admin_user_id int64, check_time int64) (err error) {
  1502. ut := writeDb.Begin()
  1503. 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
  1504. if err != nil {
  1505. ut.Rollback()
  1506. return
  1507. }
  1508. ut.Commit()
  1509. return err
  1510. }
  1511. func GetCheckTeamProject(team_id int64, patient_id int64, record_date int64, user_org_id int64) (ps []*models.HisPrescriptionProject, err error) {
  1512. 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
  1513. return
  1514. }
  1515. func GetAdminUserRoleInformation(orgid int64) (models.SgjOrgFollow, error) {
  1516. follow := models.SgjOrgFollow{}
  1517. db := UserReadDB().Table("sgj_org_follow as f").Where("f.status = 1")
  1518. table := UserReadDB().Table("sgj_admin as a").Where("a.status = 1")
  1519. fmt.Println(table)
  1520. if orgid > 0 {
  1521. db = db.Where("org_id = ?", orgid)
  1522. }
  1523. if orgid == 0 {
  1524. db = db.Where("org_id = ?", 0)
  1525. }
  1526. 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
  1527. return follow, err
  1528. }
  1529. func GetOrgFollowIsExist(orgid int64) (*models.SgjOrgFollowOne, error) {
  1530. follow := models.SgjOrgFollowOne{}
  1531. err := UserReadDB().Where("org_id = ? and status = 1", orgid).Find(&follow).Error
  1532. if err == gorm.ErrRecordNotFound {
  1533. return nil, err
  1534. }
  1535. if err != nil {
  1536. return nil, err
  1537. }
  1538. return &follow, nil
  1539. }
  1540. func UpdatePatientSign(patient_id int64, dialysis_date int64, order models.DialysisOrder, orgid int64) error {
  1541. 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
  1542. return err
  1543. }
  1544. func GetPatientSign(patient_id int64, dialysis_date int64, orgid int64) (models.DialysisOrder, error) {
  1545. order := models.DialysisOrder{}
  1546. err := XTReadDB().Where("patient_id=? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, orgid).Find(&order).Error
  1547. return order, err
  1548. }
  1549. func GetScheduleByPatient(patient_id int64, schedule_date int64, orgid int64) (models.XtScheduleSix, error) {
  1550. schedule := models.XtScheduleSix{}
  1551. err := XTReadDB().Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status = 1", patient_id, schedule_date, orgid).Find(&schedule).Error
  1552. return schedule, err
  1553. }
  1554. func GetSchedulePrintList(page int64, limit int64, schedulType int64, partitionType int64, keywords string, schedule_date int64, orgID int64) (list []*models.DialysisScheduleSix, total int64, err error) {
  1555. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  1556. table := XTReadDB().Table("xt_patients as p").Where("p.status = 1")
  1557. fmt.Println("table", table)
  1558. if schedulType > 0 {
  1559. db = db.Where("x.schedule_type = ?", schedulType)
  1560. }
  1561. if partitionType > 0 {
  1562. db = db.Where("x.partition_id = ?", partitionType)
  1563. }
  1564. if orgID > 0 {
  1565. db = db.Where("x.user_org_id = ?", orgID)
  1566. }
  1567. if schedule_date > 0 {
  1568. db = db.Where("x.schedule_date = ?", schedule_date)
  1569. }
  1570. db = db.Joins("left join xt_patients as p on p.id = x.patient_id")
  1571. likeKey := "%" + keywords + "%"
  1572. if len(keywords) > 0 {
  1573. db = db.Where("p.name like ?", likeKey)
  1574. }
  1575. err = db.Count(&total).Select("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
  1576. return list, total, err
  1577. }
  1578. func GetSchedulePrintListOne(page int64, limit int64, schedulType int64, partitionType int64, keywords string, schedule_date int64, orgID int64) (list []*models.DialysisScheduleSeven, err error) {
  1579. db := XTReadDB().Model(&list).Where("status = 1")
  1580. if orgID > 0 {
  1581. db = db.Where("user_org_id = ?", orgID)
  1582. }
  1583. if schedulType > 0 {
  1584. db = db.Where("schedule_type = ?", schedulType)
  1585. }
  1586. if partitionType > 0 {
  1587. db = db.Where("partition_id = ?", partitionType)
  1588. }
  1589. err = db.Group("schedule_type,partition_id").Find(&list).Error
  1590. return list, err
  1591. }
  1592. func GetDialysisRecordOrder(org_id int64, patient_id int64, dialysis_date int64) (models.MDialysisOrderForListSix, error) {
  1593. order := models.MDialysisOrderForListSix{}
  1594. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date = ? and status =1 ", org_id, patient_id, dialysis_date).Find(&order).Error
  1595. return order, err
  1596. }
  1597. func GetSolutionListByOrgId(orgid int64) (list []*models.DialysisSolution, err error) {
  1598. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Group("patient_id,mode_id").Order("id desc").Find(&list).Error
  1599. return list, err
  1600. }
  1601. func GetScheduleTypeById(org_id int64, schedule_date int64, schedule_type int64) (list []*models.XtScheduleSeven, err error) {
  1602. db := XTReadDB().Model(&list).Where("status = 1")
  1603. if org_id > 0 {
  1604. db = db.Where("user_org_id = ?", org_id)
  1605. }
  1606. if schedule_date > 0 {
  1607. db = db.Where("schedule_date = ?", schedule_date)
  1608. }
  1609. if schedule_type > 0 {
  1610. db = db.Where("schedule_type = ?", schedule_type)
  1611. }
  1612. err = db.Select("partition_id,count(id) as count").Group("partition_id").Scan(&list).Error
  1613. return list, err
  1614. }
  1615. func GetHisExcutionDoctorAdviceListGroupList(patients []string, advice_date int64, user_org_id int64) (advice []*models.HisDoctorAdvice, err error) {
  1616. 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
  1617. return advice, err
  1618. }
  1619. func GetHisExcutionDoctorAdviceList(patients []string, advice_date int64, user_org_id int64) (advice []*models.HisDoctorAdvice, err error) {
  1620. 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
  1621. return advice, err
  1622. }
  1623. func UpdateHisDoctorAdviceExecution(info models.HisDoctorAdviceInfo, id int64) error {
  1624. 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
  1625. return err
  1626. }
  1627. func UpdateDoctorAdviceExecution(info models.DoctorAdvice, id int64) error {
  1628. 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
  1629. return err
  1630. }
  1631. func GetExcutionDoctorAdviceGroupList(patients []string, advice_date int64, user_org_id int64) (advice []*models.DoctorAdviceThrity, err error) {
  1632. 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
  1633. return advice, err
  1634. }
  1635. func GetExcutionDoctorAdviceList(patients []string, advice_date int64, user_org_id int64) (advice []*models.DoctorAdviceThrity, err error) {
  1636. 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
  1637. return advice, err
  1638. }
  1639. func GetHisCheckDoctorAdvice(orgid int64, patinentids []string, advice_date int64) (advice []*models.HisDoctorAdviceThirty, err error) {
  1640. err = XTReadDB().Where("user_org_id = ? and patient_id in(?) and advice_date = ? and status =1", orgid, patinentids, advice_date).Find(&advice).Error
  1641. return advice, err
  1642. }
  1643. func CheckDoctorAdvice(id int64, creater int64) (models.DoctorAdviceThrity, error) {
  1644. doctoradvice := models.DoctorAdviceThrity{}
  1645. err := XTWriteDB().Model(&doctoradvice).Where("id = ? and status = 1", id).Update(map[string]interface{}{"checker": creater, "check_time": time.Now().Unix()}).Error
  1646. return doctoradvice, err
  1647. }
  1648. func CheckHisDoctorAdvice(id int64, creater int64) (models.HisDoctorAdviceThirty, error) {
  1649. doctoradvice := models.HisDoctorAdviceThirty{}
  1650. err := XTWriteDB().Model(&doctoradvice).Where("id = ? and status = 1", id).Update(map[string]interface{}{"checker": creater, "check_time": time.Now().Unix()}).Error
  1651. return doctoradvice, err
  1652. }
  1653. func GetCheckDoctorAdvice(orgid int64, patinentids []string, advice_date int64) (advice []*models.DoctorAdviceThrity, err error) {
  1654. err = XTReadDB().Where("user_org_id = ? and patient_id in(?) and advice_date = ? and status=1", orgid, patinentids, advice_date).Find(&advice).Error
  1655. return advice, err
  1656. }
  1657. func SettleHisNewDoctorAdvice(patinentids []string, advice_date int64, orgid int64) (advice []*models.HisDoctorAdviceThirty, err error) {
  1658. 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
  1659. return advice, err
  1660. }
  1661. func SettleNewDoctorAdvice(patinentids []string, advice_date int64, orgid int64) (advice []*models.DoctorAdviceThrity, err error) {
  1662. 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
  1663. return advice, err
  1664. }
  1665. func GetHisMobileAdviceGroupList(orgid int64, ids []string) (advice []*models.HisDoctorAdvice, err error) {
  1666. err = XTReadDB().Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Group("drug_id").Find(&advice).Error
  1667. return advice, err
  1668. }
  1669. func GetHisMobileAdviceList(orgid int64, ids []string) (advice []*models.HisDoctorAdvice, err error) {
  1670. err = XTReadDB().Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Find(&advice).Error
  1671. return advice, err
  1672. }
  1673. func ExectionMobileAdvice(orgid int64, ids []string, execution_time int64, execution_staff int64) error {
  1674. advice := models.HisDoctorAdvice{}
  1675. 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
  1676. return err
  1677. }
  1678. func GetBloodMobileAdviceGroupList(orgid int64, ids []string) (advice []*models.DoctorAdviceThrity, err error) {
  1679. err = XTReadDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Group("drug_id").Find(&advice).Error
  1680. return advice, err
  1681. }
  1682. func GetBloodMobileAdviceList(orgid int64, ids []string) (advice []*models.DoctorAdviceThrity, err error) {
  1683. err = XTReadDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Find(&advice).Error
  1684. return advice, err
  1685. }
  1686. func FindAllDoctorAdviceByIds(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
  1687. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND id in(?) AND status = 1", orgID, ids).Find(&advice).Error
  1688. return
  1689. }
  1690. func ExectionBloodMobileAdvice(orgid int64, ids []string, execution_time int64, execution_staff int64) error {
  1691. fmt.Println("ids2323232323323223233223wode", ids)
  1692. advice := models.DoctorAdviceThrity{}
  1693. 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
  1694. return err
  1695. }
  1696. func UpdateSettleMobileHisAdvice(orgid int64, ids []string) error {
  1697. advice := models.HisDoctorAdviceThirty{}
  1698. err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status =1", orgid, ids).Updates(map[string]interface{}{"is_settle": 1}).Error
  1699. return err
  1700. }
  1701. func UpdateSettleMobileBloodAdvice(orgid int64, ids []string) error {
  1702. advice := models.DoctorAdvice{}
  1703. err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status =1", orgid, ids).Updates(map[string]interface{}{"is_settle": 1}).Error
  1704. return err
  1705. }
  1706. func CheckBloodDoctorAdvice(orgid int64, ids []string, advice models.DoctorAdvice) error {
  1707. 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
  1708. return err
  1709. }
  1710. func CheckHisMobileDoctorAdvice(orgid int64, ids []string, advice models.HisDoctorAdviceThirty) error {
  1711. 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
  1712. return err
  1713. }
  1714. func GetLastOrder(user_org_id int64, patient_id int64, dialysis_date int64) (models.DialysisOrderTwenty, error) {
  1715. twenty := models.DialysisOrderTwenty{}
  1716. 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 {
  1717. return db.Preload("DeviceZone", "status =1").Where("org_id = ? AND status = 1", user_org_id)
  1718. }).Order("id desc").First(&twenty).Error
  1719. return twenty, err
  1720. }
  1721. func GetTodayInforMation(orgid int64, record_date int64) (list []*NewDeviceInformation, err error) {
  1722. err = UserReadDB().Where("user_org_id = ? and date = ? and status = 1", orgid, record_date).Find(&list).Error
  1723. return list, err
  1724. }
  1725. func GetFiledConfig(orgid int64) (models.FiledConfig, error) {
  1726. config := models.FiledConfig{}
  1727. err := XTReadDB().Where("filed_name = 'dialyzer_perfusion_apparatus' and org_id = ? and module =1 and is_show = 1", orgid).First(&config).Error
  1728. return config, err
  1729. }