mobile_dialysis_service.go 59KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  9. // var vms []*MDialysisScheduleVM
  10. // err := readDb.
  11. // Table("xt_schedule as sch").
  12. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  13. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  14. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  15. // Preload("TreatmentMode", "status = 1").
  16. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  17. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  18. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  19. // Find(&vms).
  20. // Error
  21. // return vms, err
  22. // }
  23. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVM, error) {
  24. var vms []*MDialysisScheduleVM
  25. db := readDb.
  26. Table("xt_schedule as sch").
  27. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  28. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  29. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  30. Preload("TreatmentMode", "status = 1").
  31. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2", orgID).
  32. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  33. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  34. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  35. Preload("DialysisOrder.DeviceNumber", "status = 1 AND org_id = ?", orgID).
  36. // Preload("DialysisOrder.MonitoringRecords", func(rdb *gorm.DB) *gorm.DB {
  37. // return rdb.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time DESC")
  38. // }).
  39. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  40. if scheduleDate != 0 {
  41. db = db.Where("schedule_date = ?", scheduleDate)
  42. }
  43. if scheduleType != 0 {
  44. db = db.Where("schedule_type = ?", scheduleType)
  45. }
  46. err := db.Find(&vms).Error
  47. return vms, err
  48. }
  49. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  50. var vms []*MDialysisScheduleVM
  51. db := readDb.
  52. Table("xt_schedule as sch").
  53. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  54. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  55. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  56. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  57. Preload("TreatmentMode", "status = 1").
  58. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  59. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  60. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  61. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  62. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  63. if scheduleDate != 0 {
  64. db = db.Where("schedule_date = ?", scheduleDate)
  65. }
  66. err := db.Find(&vms).Error
  67. return vms, err
  68. }
  69. type MDialysisScheduleVM struct {
  70. ID int64 `gorm:"column:id" json:"id"`
  71. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  72. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  73. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  74. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  75. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  76. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  77. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  78. Status int64 `gorm:"column:status" json:"status"`
  79. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  80. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  81. DeviceZone *models.DeviceZone `gorm:"ForeignKey:PartitionId" json:"device_zone"`
  82. TreatmentMode *models.TreatmentMode `gorm:"ForeignKey:ModeId" json:"treatment_mode"`
  83. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
  84. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  85. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  86. Advices []*models.DoctorAdvice `gorm:"ForeignKey:AdviceDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"doctor_advice"`
  87. }
  88. func (MDialysisScheduleVM) TableName() string {
  89. return "xt_schedule"
  90. }
  91. type MDeviceNumberVM struct {
  92. models.DeviceNumber
  93. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  94. }
  95. func (MDeviceNumberVM) TableName() string {
  96. return "xt_device_number"
  97. }
  98. type MSchedualPatientVMList struct {
  99. ID int64 `gorm:"column:id" json:"id" form:"id"`
  100. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  101. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  102. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  103. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  104. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  105. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  106. Age int64 `gorm:"column:age" json:"age"`
  107. Name string `gorm:"column:name" json:"name" form:"name"`
  108. }
  109. func (MSchedualPatientVMList) TableName() string {
  110. return "xt_patients"
  111. }
  112. type MSchedualPatientVM struct {
  113. ID int64 `gorm:"column:id" json:"id" form:"id"`
  114. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  115. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  116. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  117. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  118. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  119. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  120. Source int64 `gorm:"column:source" json:"source" form:"source"`
  121. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  122. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  123. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  124. Name string `gorm:"column:name" json:"name" form:"name"`
  125. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  126. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  127. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  128. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  129. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  130. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  131. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  132. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  133. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  134. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  135. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  136. Height int64 `gorm:"column:height" json:"height" form:"height"`
  137. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  138. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  139. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  140. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  141. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  142. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  143. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  144. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  145. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  146. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  147. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  148. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  149. Children int64 `gorm:"column:children" json:"children" form:"children"`
  150. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  151. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  152. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  153. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  154. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  155. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  156. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  157. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  158. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  159. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  160. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  161. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  162. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  163. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  164. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  165. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  166. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  167. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  168. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  169. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  170. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  171. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  172. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  173. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  174. Status int64 `gorm:"column:status" json:"status" form:"status"`
  175. Age int64 `gorm:"column:age" json:"age"`
  176. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  177. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  178. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  179. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  180. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  181. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  182. }
  183. func (MSchedualPatientVM) TableName() string {
  184. return "xt_patients"
  185. }
  186. type MDialysisOrderVM struct {
  187. ID int64 `gorm:"column:id" json:"id"`
  188. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  189. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  190. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  191. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  192. Stage int64 `gorm:"column:stage" json:"stage"`
  193. // Remark string `gorm:"column:remark" json:"remark"`
  194. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  195. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  196. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  197. Status int64 `gorm:"column:status" json:"status"`
  198. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  199. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  200. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  201. Creator int64 `gorm:"column:creator" json:"creator"`
  202. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  203. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  204. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  205. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  206. }
  207. func (MDialysisOrderVM) TableName() string {
  208. return "xt_dialysis_order"
  209. }
  210. type MDialysisOrderVMList struct {
  211. ID int64 `gorm:"column:id" json:"id"`
  212. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  213. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  214. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  215. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  216. Stage int64 `gorm:"column:stage" json:"stage"`
  217. // Remark string `gorm:"column:remark" json:"remark"`
  218. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  219. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  220. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  221. Status int64 `gorm:"column:status" json:"status"`
  222. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  223. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  224. Creator int64 `gorm:"column:creator" json:"creator"`
  225. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  226. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  227. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  228. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  229. }
  230. func (MDialysisOrderVMList) TableName() string {
  231. return "xt_dialysis_order"
  232. }
  233. // 获取透析记录
  234. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  235. var record models.DialysisOrder
  236. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  237. if err != nil {
  238. if err == gorm.ErrRecordNotFound {
  239. return nil, nil
  240. } else {
  241. return nil, err
  242. }
  243. }
  244. return &record, nil
  245. }
  246. // 用户基本信息
  247. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  248. var patient MPatient
  249. err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  250. if err != nil {
  251. if err == gorm.ErrRecordNotFound {
  252. return nil, nil
  253. } else {
  254. return nil, err
  255. }
  256. }
  257. return &patient, nil
  258. }
  259. // 用户排班信息
  260. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  261. var vm MDialysisScheduleVM
  262. err := readDb.
  263. Table("xt_schedule").
  264. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  265. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  266. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  267. First(&vm).Error
  268. if err != nil {
  269. if err == gorm.ErrRecordNotFound {
  270. return nil, nil
  271. } else {
  272. return nil, err
  273. }
  274. }
  275. return &vm, err
  276. }
  277. // 用户排班信息
  278. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  279. var schedule models.Schedule
  280. err := readDb.
  281. Table("xt_schedule").
  282. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  283. First(&schedule).Error
  284. if err != nil {
  285. if err == gorm.ErrRecordNotFound {
  286. return nil, nil
  287. } else {
  288. return nil, err
  289. }
  290. }
  291. return &schedule, nil
  292. }
  293. type MPatient struct {
  294. ID int64 `gorm:"column:id" json:"id" form:"id"`
  295. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  296. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  297. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  298. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  299. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  300. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  301. Source int64 `gorm:"column:source" json:"source" form:"source"`
  302. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  303. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  304. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  305. Name string `gorm:"column:name" json:"name" form:"name"`
  306. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  307. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  308. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  309. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  310. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  311. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  312. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  313. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  314. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  315. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  316. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  317. Height int64 `gorm:"column:height" json:"height" form:"height"`
  318. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  319. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  320. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  321. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  322. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  323. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  324. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  325. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  326. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  327. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  328. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  329. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  330. Children int64 `gorm:"column:children" json:"children" form:"children"`
  331. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  332. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  333. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  334. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  335. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  336. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  337. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  338. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  339. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  340. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  341. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  342. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  343. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  344. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  345. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  346. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  347. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  348. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  349. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  350. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  351. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  352. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  353. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  354. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  355. Status int64 `gorm:"column:status" json:"status" form:"status"`
  356. Age int64 `gorm:"column:age" json:"age"`
  357. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  358. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  359. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  360. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  361. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  362. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  363. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  364. }
  365. func (MPatient) TableName() string {
  366. return "xt_patients"
  367. }
  368. // 接诊评估
  369. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  370. var record models.ReceiveTreatmentAsses
  371. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  372. if err != nil {
  373. if err == gorm.ErrRecordNotFound {
  374. return nil, nil
  375. } else {
  376. return nil, err
  377. }
  378. }
  379. return &record, nil
  380. }
  381. // 透前评估
  382. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  383. fmt.Println("recordDate", recordDate)
  384. var record models.PredialysisEvaluation
  385. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  386. if err != nil {
  387. if err == gorm.ErrRecordNotFound {
  388. return nil, nil
  389. } else {
  390. return nil, err
  391. }
  392. }
  393. return &record, nil
  394. }
  395. // 获取 maxDate 之前一次的透前评估记录
  396. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  397. var record models.PredialysisEvaluation
  398. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  399. if err != nil {
  400. if err == gorm.ErrRecordNotFound {
  401. return nil, nil
  402. } else {
  403. return nil, err
  404. }
  405. }
  406. return &record, nil
  407. }
  408. // 临时医嘱
  409. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  410. var records []*models.DoctorAdvice
  411. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  412. err := readDb.
  413. Model(&models.DoctorAdvice{}).
  414. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
  415. 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,IF(parent_id>0, parent_id, id) as advice_order,groupno").
  416. Order("start_time asc, groupno desc, advice_order desc, id").
  417. Scan(&records).Error
  418. if err != nil {
  419. return nil, err
  420. }
  421. return records, nil
  422. }
  423. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  424. var records []*models.DoctorAdvice
  425. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  426. err := readDb.
  427. Model(&models.DoctorAdvice{}).
  428. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
  429. 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").
  430. Order("start_time asc, groupno desc, advice_order desc, id asc").
  431. Scan(&records).Error
  432. if err != nil {
  433. return nil, err
  434. }
  435. return records, nil
  436. }
  437. // 透析记录
  438. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  439. var record models.DialysisOrder
  440. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  441. if err != nil {
  442. if err == gorm.ErrRecordNotFound {
  443. return nil, nil
  444. } else {
  445. return nil, err
  446. }
  447. }
  448. return &record, nil
  449. }
  450. // 双人核对
  451. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  452. var record models.DoubleCheck
  453. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  454. if err != nil {
  455. if err == gorm.ErrRecordNotFound {
  456. return nil, nil
  457. } else {
  458. return nil, err
  459. }
  460. }
  461. return &record, nil
  462. }
  463. // 透析监测记录
  464. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  465. var records []*models.MonitoringRecord
  466. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
  467. if err != nil {
  468. return nil, err
  469. }
  470. return records, nil
  471. }
  472. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  473. var records models.MonitoringRecord
  474. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").First(&records).Error
  475. if err != nil {
  476. return nil, err
  477. }
  478. return &records, nil
  479. }
  480. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  481. var record models.MonitoringRecord
  482. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  483. if err != nil {
  484. if err == gorm.ErrRecordNotFound {
  485. return nil, nil
  486. } else {
  487. return nil, err
  488. }
  489. }
  490. return &record, nil
  491. }
  492. // 透后评估
  493. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  494. var record models.AssessmentAfterDislysis
  495. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  496. if err != nil {
  497. if err == gorm.ErrRecordNotFound {
  498. return nil, nil
  499. } else {
  500. return nil, err
  501. }
  502. }
  503. return &record, nil
  504. }
  505. // 获取 maxDate 之前一次的透后评估记录
  506. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  507. var record models.AssessmentAfterDislysis
  508. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  509. if err != nil {
  510. if err == gorm.ErrRecordNotFound {
  511. return nil, nil
  512. } else {
  513. return nil, err
  514. }
  515. }
  516. return &record, nil
  517. }
  518. // 治疗小结
  519. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  520. var record models.TreatmentSummary
  521. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  522. if err != nil {
  523. if err == gorm.ErrRecordNotFound {
  524. return nil, nil
  525. } else {
  526. return nil, err
  527. }
  528. }
  529. return &record, nil
  530. }
  531. // 透析处方
  532. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  533. var record models.DialysisPrescription
  534. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  535. if err != nil {
  536. if err == gorm.ErrRecordNotFound {
  537. return nil, nil
  538. } else {
  539. return nil, err
  540. }
  541. }
  542. return &record, nil
  543. }
  544. // 透析方案
  545. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  546. var record models.DialysisSolution
  547. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  548. if err != nil {
  549. if err == gorm.ErrRecordNotFound {
  550. return nil, nil
  551. } else {
  552. return nil, err
  553. }
  554. }
  555. return &record, nil
  556. }
  557. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  558. var patient models.Patients
  559. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  560. if err != nil {
  561. if err == gorm.ErrRecordNotFound {
  562. return nil, nil
  563. } else {
  564. return nil, err
  565. }
  566. }
  567. return &patient, nil
  568. }
  569. func DisableMonitor(orgID int64, patientID int64, recordID int64) error {
  570. fmt.Println()
  571. tx := writeDb.Begin()
  572. updateTime := time.Now().Unix()
  573. err := tx.Model(&models.MonitoringRecord{}).Where("user_org_id = ? AND patient_id = ? AND id = ? AND status = 1 ", orgID, patientID, recordID).Updates(map[string]interface{}{"status": 0, "updated_time": updateTime}).Error
  574. if err != nil {
  575. tx.Rollback()
  576. return err
  577. }
  578. tx.Commit()
  579. return nil
  580. }
  581. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  582. var monitor models.MonitoringRecord
  583. var err error
  584. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  585. if err == gorm.ErrRecordNotFound {
  586. return nil, nil
  587. }
  588. if err != nil {
  589. return nil, err
  590. }
  591. return &monitor, nil
  592. }
  593. type MScheduleDoctorAdviceVM struct {
  594. ID int64 `gorm:"column:id" json:"id"`
  595. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  596. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  597. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  598. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  599. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  600. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  601. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  602. Status int64 `gorm:"column:status" json:"status"`
  603. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
  604. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  605. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  606. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  607. }
  608. func (MScheduleDoctorAdviceVM) TableName() string {
  609. return "xt_schedule"
  610. }
  611. type MDoctorAdviceVM struct {
  612. ID int64 `gorm:"column:id" json:"id"`
  613. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  614. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  615. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  616. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  617. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  618. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  619. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  620. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  621. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  622. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  623. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  624. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  625. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  626. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  627. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  628. Status int64 `gorm:"column:status" json:"status"`
  629. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  630. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  631. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  632. Remark string `gorm:"column:remark" json:"remark"`
  633. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  634. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  635. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  636. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  637. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  638. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  639. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  640. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  641. Checker int64 `gorm:"column:checker" json:"checker"`
  642. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  643. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  644. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  645. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  646. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  647. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  648. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  649. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  650. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  651. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  652. WeekDay string `gorm:"column:week_day" json:"week_day"`
  653. TemplateId string `gorm:"column:template_id" json:"template_id"`
  654. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  655. }
  656. func (MDoctorAdviceVM) TableName() string {
  657. return "xt_doctor_advice"
  658. }
  659. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64) ([]*MScheduleDoctorAdviceVM, error) {
  660. var vms []*MScheduleDoctorAdviceVM
  661. adviceWhere := ""
  662. adviceCondition := []interface{}{}
  663. if adviceType == 0 {
  664. if patientType == 0 {
  665. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  667. } else if patientType == 1 {
  668. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  669. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  670. } else if patientType == 2 {
  671. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  672. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  673. }
  674. } else if adviceType == 1 {
  675. if patientType == 0 {
  676. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  677. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  678. } else if patientType == 1 {
  679. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  680. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  681. } else if patientType == 2 {
  682. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  684. }
  685. } else if adviceType == 3 {
  686. if patientType == 0 {
  687. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  688. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  689. } else if patientType == 1 {
  690. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  692. } else if patientType == 2 {
  693. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  695. }
  696. } else if adviceType == 2 {
  697. if patientType == 0 {
  698. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? "
  699. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  700. } else if patientType == 1 {
  701. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? "
  702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  703. } else if patientType == 2 {
  704. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  705. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  706. }
  707. }
  708. db := readDb.
  709. Table("xt_schedule").
  710. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  711. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  712. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  713. }).
  714. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  715. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  716. Preload("DoctorAdvices", adviceCondition...).
  717. Where("status = 1 AND user_org_id = ?", orgID)
  718. if scheduleDate != 0 {
  719. db = db.Where("schedule_date = ?", scheduleDate)
  720. }
  721. err := db.Find(&vms).Error
  722. return vms, err
  723. }
  724. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  725. now := time.Now()
  726. tx := writeDb.Begin()
  727. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  728. tx.Rollback()
  729. return createOrderErr
  730. }
  731. // 更新透析记录 ID
  732. // 透析处方
  733. if err := tx.Model(&models.DialysisPrescription{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"record_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  734. tx.Rollback()
  735. return err
  736. }
  737. // 接诊评估
  738. if err := tx.Model(&models.ReceiveTreatmentAsses{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"record_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  739. tx.Rollback()
  740. return err
  741. }
  742. // 透前评估
  743. if err := tx.Model(&models.PredialysisEvaluation{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  744. tx.Rollback()
  745. return err
  746. }
  747. // 临时医嘱
  748. if err := tx.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND advice_type = 2", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  749. tx.Rollback()
  750. return err
  751. }
  752. // 双人核对
  753. if err := tx.Model(&models.DoubleCheck{}).Where("user_org_id = ? AND patient_id = ? AND check_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  754. tx.Rollback()
  755. return err
  756. }
  757. // 透后评估
  758. if err := tx.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  759. tx.Rollback()
  760. return err
  761. }
  762. // 治疗小结
  763. if err := tx.Model(&models.TreatmentSummary{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  764. tx.Rollback()
  765. return err
  766. }
  767. // 透析监测
  768. if err := tx.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientID, orgID, order.DialysisDate).Update(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  769. tx.Rollback()
  770. return err
  771. }
  772. tx.Commit()
  773. return nil
  774. }
  775. type MobileUrgentSchedulePatientVM struct {
  776. ID int64 `gorm:"column:id" json:"id"`
  777. Name string `gorm:"column:name" json:"name"`
  778. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  779. }
  780. func (MobileUrgentSchedulePatientVM) TableName() string {
  781. return "xt_patients"
  782. }
  783. type MobileUrgentScheduleTreatmentModeVM struct {
  784. ID int64 `gorm:"column:id" json:"id"`
  785. Name string `gorm:"column:name" json:"name"`
  786. }
  787. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  788. return "xt_treatment_mode"
  789. }
  790. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  791. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  792. rows, err := readDb.Raw("SELECT p.* FROM xt_patients as p WHERE (p.user_org_id = ? AND p.status = 1 AND p.lapseto = 1) AND NOT EXISTS (Select * FROM `xt_dialysis_order` as d Where d.`dialysis_date` = ? AND d.`status` = 1 AND d.`patient_id` = p.id AND d.user_org_id = p.user_org_id )", orgID, record_date).Rows()
  793. defer rows.Close()
  794. if err != nil {
  795. return nil, err
  796. }
  797. for rows.Next() {
  798. var vm MobileUrgentSchedulePatientVM
  799. readDb.ScanRows(rows, &vm)
  800. vms = append(vms, &vm)
  801. }
  802. return vms, nil
  803. }
  804. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  805. var modes []*MobileUrgentScheduleTreatmentModeVM
  806. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  807. if err != nil {
  808. return nil, err
  809. }
  810. return modes, nil
  811. }
  812. type MobileUrgentScheduleScheduleListVM struct {
  813. ID int64 `gorm:"column:id" json:"id"`
  814. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  815. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  816. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  817. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  818. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  819. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  820. }
  821. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  822. return "xt_schedule"
  823. }
  824. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  825. db := readDb.
  826. Model(&MobileUrgentScheduleScheduleListVM{}).
  827. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  828. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  829. err = db.Find(&schedules).Error
  830. if err != nil {
  831. return nil, err
  832. }
  833. return schedules, nil
  834. }
  835. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  836. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  837. rows, err := readDb.Raw("SELECT * FROM xt_schedule as s WHERE s.user_org_id = ? AND s.status = 1 AND s.schedule_date = ? ", orgID, scheduleDate).Rows()
  838. defer rows.Close()
  839. if err != nil {
  840. return nil, err
  841. }
  842. for rows.Next() {
  843. var vm MobileUrgentScheduleScheduleListVM
  844. readDb.ScanRows(rows, &vm)
  845. vms = append(vms, &vm)
  846. }
  847. return vms, nil
  848. }
  849. type MobileUrgentScheduleDeviceNumberVM struct {
  850. ID int64 `gorm:"column:id" json:"id"`
  851. Number string `gorm:"column:number" json:"number"`
  852. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  853. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  854. }
  855. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  856. return "xt_device_number"
  857. }
  858. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  859. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  860. rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_schedule as s Where s.`schedule_date` = ? AND s.user_org_id = n.org_id AND s.`bed_id` = n.id AND s.`schedule_type` = ? AND s.status = 1 )", orgID, record_date, schedule_type).Rows()
  861. defer rows.Close()
  862. if err != nil {
  863. return nil, err
  864. }
  865. for rows.Next() {
  866. var vm DeviceNumberViewModel
  867. readDb.ScanRows(rows, &vm)
  868. vms = append(vms, &vm)
  869. }
  870. return vms, nil
  871. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  872. //db := readDb.
  873. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  874. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  875. // Where("status = 1 AND org_id = ?", orgID)
  876. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  877. //if err != nil {
  878. // return nil, err
  879. //}
  880. //return deviceNumbers, nil
  881. }
  882. func GetValidScheduleMonitorRecordCount() (int64, error) {
  883. var total int64
  884. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  885. return total, err
  886. }
  887. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  888. var monitors []*models.MonitoringRecord
  889. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  890. if err != nil {
  891. return nil, err
  892. }
  893. return monitors, nil
  894. }
  895. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  896. tx := writeDb.Begin()
  897. for index := 0; index < len(monitors); index++ {
  898. tx.Save(monitors[index])
  899. }
  900. return tx.Commit().Error
  901. }
  902. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  903. tx := writeDb.Begin()
  904. updateTime := time.Now().Unix()
  905. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"start_nurse": order.StartNurse, "updated_time": updateTime, "bed_id": order.BedID, "puncture_nurse": order.PunctureNurse, "start_time": order.StartTime, "modifier": order.Modifier, "schedual_type": order.SchedualType}).Error
  906. if err != nil {
  907. tx.Rollback()
  908. return err
  909. }
  910. tx.Commit()
  911. return err
  912. }
  913. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  914. tx := writeDb.Begin()
  915. updateTime := time.Now().Unix()
  916. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"finish_nurse": order.FinishNurse, "updated_time": updateTime, "end_time": order.EndTime, "finish_modifier": order.FinishModifier}).Error
  917. if err != nil {
  918. tx.Rollback()
  919. return err
  920. }
  921. tx.Commit()
  922. return err
  923. }
  924. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  925. var record models.SgjPatientDryweight
  926. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  927. if err != nil {
  928. if err == gorm.ErrRecordNotFound {
  929. return nil, nil
  930. } else {
  931. return nil, err
  932. }
  933. }
  934. return &record, nil
  935. }
  936. // 透析方案
  937. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  938. var record models.DialysisSolution
  939. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  940. if err != nil {
  941. if err == gorm.ErrRecordNotFound {
  942. return nil, nil
  943. } else {
  944. return nil, err
  945. }
  946. }
  947. return &record, nil
  948. }
  949. // 透析处方
  950. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  951. var record models.DialysisPrescription
  952. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
  953. if err != nil {
  954. if err == gorm.ErrRecordNotFound {
  955. return nil, nil
  956. } else {
  957. return nil, err
  958. }
  959. }
  960. return &record, nil
  961. }
  962. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  963. var record models.DialysisPrescription
  964. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  965. if err != nil {
  966. if err == gorm.ErrRecordNotFound {
  967. return nil, nil
  968. } else {
  969. return nil, err
  970. }
  971. }
  972. return &record, nil
  973. }
  974. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  975. var record models.DialysisPrescription
  976. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  977. if err != nil {
  978. if err == gorm.ErrRecordNotFound {
  979. return nil, nil
  980. } else {
  981. return nil, err
  982. }
  983. }
  984. return &record, nil
  985. }
  986. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  987. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  988. rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_schedule as s Where s.`schedule_date` = ? AND s.user_org_id = n.org_id AND s.`bed_id` = n.id AND s.`schedule_type` = ? AND s.status = 1 )", orgID, record_date, schedule_type).Rows()
  989. defer rows.Close()
  990. if err != nil {
  991. return nil, err
  992. }
  993. for rows.Next() {
  994. var vm DeviceNumberViewModel
  995. readDb.ScanRows(rows, &vm)
  996. vms = append(vms, &vm)
  997. }
  998. return vms, nil
  999. }
  1000. // 获取 maxDate 之前一次的透前评估记录
  1001. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  1002. var record models.PredialysisEvaluation
  1003. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1004. if err != nil {
  1005. if err == gorm.ErrRecordNotFound {
  1006. return nil, nil
  1007. } else {
  1008. return nil, err
  1009. }
  1010. }
  1011. return &record, nil
  1012. }
  1013. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  1014. var record models.MonitoringRecord
  1015. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  1016. if err != nil {
  1017. if err == gorm.ErrRecordNotFound {
  1018. return nil, nil
  1019. } else {
  1020. return nil, err
  1021. }
  1022. }
  1023. return &record, nil
  1024. }
  1025. // 获取 maxDate 之前一次的透后评估记录
  1026. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1027. var record models.AssessmentAfterDislysis
  1028. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1029. if err != nil {
  1030. if err == gorm.ErrRecordNotFound {
  1031. return nil, nil
  1032. } else {
  1033. return nil, err
  1034. }
  1035. }
  1036. return &record, nil
  1037. }
  1038. // 透析处方
  1039. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1040. var record models.DialysisPrescription
  1041. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1042. if err != nil {
  1043. if err == gorm.ErrRecordNotFound {
  1044. return nil, nil
  1045. } else {
  1046. return nil, err
  1047. }
  1048. }
  1049. return &record, nil
  1050. }
  1051. // 透析方案
  1052. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1053. var record models.DialysisSolution
  1054. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  1055. if err != nil {
  1056. if err == gorm.ErrRecordNotFound {
  1057. return nil, nil
  1058. } else {
  1059. return nil, err
  1060. }
  1061. }
  1062. return &record, nil
  1063. }
  1064. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  1065. var record models.DialysisPrescription
  1066. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  1067. if err != nil {
  1068. if err == gorm.ErrRecordNotFound {
  1069. return nil, nil
  1070. } else {
  1071. return nil, err
  1072. }
  1073. }
  1074. return &record, nil
  1075. }
  1076. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  1077. var record models.SgjPatientDryweight
  1078. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1079. if err != nil {
  1080. if err == gorm.ErrRecordNotFound {
  1081. return nil, nil
  1082. } else {
  1083. return nil, err
  1084. }
  1085. }
  1086. return &record, nil
  1087. }
  1088. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  1089. var record models.SystemPrescription
  1090. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  1091. if err != nil {
  1092. if err == gorm.ErrRecordNotFound {
  1093. return nil, nil
  1094. } else {
  1095. return nil, err
  1096. }
  1097. }
  1098. return &record, nil
  1099. }
  1100. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  1101. var record models.SystemPrescription
  1102. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  1103. if err != nil {
  1104. if err == gorm.ErrRecordNotFound {
  1105. return nil, nil
  1106. } else {
  1107. return nil, err
  1108. }
  1109. }
  1110. return &record, nil
  1111. }