mobile_dialysis_service.go 61KB

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