mobile_dialysis_service.go 61KB

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