mobile_dialysis_service.go 61KB

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