mobile_dialysis_service.go 60KB

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