mobile_dialysis_service.go 78KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  36. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  37. // Preload("DialysisOrder.MonitoringRecords", func(rdb *gorm.DB) *gorm.DB {
  38. // return rdb.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time DESC")
  39. // }).
  40. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  41. if scheduleDate != 0 {
  42. db = db.Where("schedule_date = ?", scheduleDate)
  43. }
  44. if scheduleType != 0 {
  45. db = db.Where("schedule_type = ?", scheduleType)
  46. }
  47. err := db.Find(&vms).Error
  48. return vms, err
  49. }
  50. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  51. var vms []*MDialysisScheduleVM
  52. db := readDb.
  53. Table("xt_schedule as sch").
  54. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  55. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  56. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  57. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  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. Preload("TreatmentMode", "status = 1").
  63. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  64. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  65. if scheduleDate != 0 {
  66. db = db.Where("schedule_date = ?", scheduleDate)
  67. }
  68. err := db.Find(&vms).Error
  69. return vms, err
  70. }
  71. type VMTreatmentSummary struct {
  72. ID int64 `gorm:"column:id" json:"id"`
  73. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  74. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  75. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  76. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  77. }
  78. func (VMTreatmentSummary) TableName() string {
  79. return "xt_treatment_summary"
  80. }
  81. type AssessmentAfterDislysis struct {
  82. ID int64 `gorm:"column:id" json:"id"`
  83. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  84. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  85. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  86. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  87. Status int64 `gorm:"column:status" json:"status"`
  88. }
  89. func (AssessmentAfterDislysis) TableName() string {
  90. return "xt_assessment_after_dislysis"
  91. }
  92. type MDialysisScheduleVM struct {
  93. ID int64 `gorm:"column:id" json:"id"`
  94. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  95. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  96. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  97. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  98. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  99. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  100. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  101. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  102. Status int64 `gorm:"column:status" json:"status"`
  103. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  104. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  105. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
  106. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"prescription"`
  107. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:AssessmentDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"assessment_before_dislysis"`
  108. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:AssessmentDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"assessment_after_dislysis"`
  109. Advices []*VMDoctorAdvice `gorm:"ForeignKey:AdviceDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"doctor_advice"`
  110. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:AssessmentDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"treatment_summary"`
  111. }
  112. func (MDialysisScheduleVM) TableName() string {
  113. return "xt_schedule"
  114. }
  115. type MDeviceNumberVM struct {
  116. models.DeviceNumber
  117. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  118. }
  119. func (MDeviceNumberVM) TableName() string {
  120. return "xt_device_number"
  121. }
  122. type MSchedualPatientVMList struct {
  123. ID int64 `gorm:"column:id" json:"id" form:"id"`
  124. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  125. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  126. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  127. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  128. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  129. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  130. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  131. Age int64 `gorm:"column:age" json:"age"`
  132. Name string `gorm:"column:name" json:"name" form:"name"`
  133. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  134. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  135. }
  136. func (MSchedualPatientVMList) TableName() string {
  137. return "xt_patients"
  138. }
  139. type MSchedualPatientVM struct {
  140. ID int64 `gorm:"column:id" json:"id" form:"id"`
  141. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  142. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  143. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  144. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  145. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  146. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  147. Source int64 `gorm:"column:source" json:"source" form:"source"`
  148. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  149. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  150. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  151. Name string `gorm:"column:name" json:"name" form:"name"`
  152. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  153. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  154. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  155. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  156. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  157. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  158. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  159. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  160. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  161. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  162. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  163. Height int64 `gorm:"column:height" json:"height" form:"height"`
  164. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  165. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  166. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  167. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  168. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  169. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  170. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  171. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  172. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  173. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  174. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  175. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  176. Children int64 `gorm:"column:children" json:"children" form:"children"`
  177. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  178. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  179. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  180. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  181. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  182. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  183. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  184. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  185. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  186. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  187. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  188. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  189. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  190. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  191. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  192. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  193. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  194. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  195. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  196. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  197. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  198. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  199. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  200. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  201. Status int64 `gorm:"column:status" json:"status" form:"status"`
  202. Age int64 `gorm:"column:age" json:"age"`
  203. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  204. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  205. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  206. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  207. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  208. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  209. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  210. }
  211. func (MSchedualPatientVM) TableName() string {
  212. return "xt_patients"
  213. }
  214. type MDialysisOrderVM struct {
  215. ID int64 `gorm:"column:id" json:"id"`
  216. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  217. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  218. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  219. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  220. Stage int64 `gorm:"column:stage" json:"stage"`
  221. // Remark string `gorm:"column:remark" json:"remark"`
  222. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  223. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  224. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  225. Status int64 `gorm:"column:status" json:"status"`
  226. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  227. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  228. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  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. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  235. }
  236. func (MDialysisOrderVM) TableName() string {
  237. return "xt_dialysis_order"
  238. }
  239. type MDialysisOrderVMList struct {
  240. ID int64 `gorm:"column:id" json:"id"`
  241. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  242. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  243. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  244. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  245. Stage int64 `gorm:"column:stage" json:"stage"`
  246. // Remark string `gorm:"column:remark" json:"remark"`
  247. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  248. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  249. Status int64 `gorm:"column:status" json:"status"`
  250. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  251. Creator int64 `gorm:"column:creator" json:"creator"`
  252. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  253. }
  254. func (MDialysisOrderVMList) TableName() string {
  255. return "xt_dialysis_order"
  256. }
  257. type VMDoctorAdvice struct {
  258. ID int64 `gorm:"column:id" json:"id" form:"id"`
  259. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  260. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  261. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  262. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  263. Status int64 `gorm:"column:status" json:"status" form:"status"`
  264. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  265. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  266. }
  267. func (VMDoctorAdvice) TableName() string {
  268. return "xt_doctor_advice"
  269. }
  270. // 获取透析记录
  271. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  272. var record models.DialysisOrder
  273. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  274. if err != nil {
  275. if err == gorm.ErrRecordNotFound {
  276. return nil, nil
  277. } else {
  278. return nil, err
  279. }
  280. }
  281. return &record, nil
  282. }
  283. // 用户基本信息
  284. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  285. var patient MPatient
  286. err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  287. if err != nil {
  288. if err == gorm.ErrRecordNotFound {
  289. return nil, nil
  290. } else {
  291. return nil, err
  292. }
  293. }
  294. return &patient, nil
  295. }
  296. // 用户排班信息
  297. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  298. var vm MDialysisScheduleVM
  299. err := readDb.
  300. Table("xt_schedule").
  301. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  302. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  303. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  304. First(&vm).Error
  305. if err != nil {
  306. if err == gorm.ErrRecordNotFound {
  307. return nil, nil
  308. } else {
  309. return nil, err
  310. }
  311. }
  312. return &vm, err
  313. }
  314. // 用户排班信息
  315. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  316. var schedule models.Schedule
  317. err := readDb.
  318. Table("xt_schedule").
  319. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  320. First(&schedule).Error
  321. if err != nil {
  322. if err == gorm.ErrRecordNotFound {
  323. return nil, nil
  324. } else {
  325. return nil, err
  326. }
  327. }
  328. return &schedule, nil
  329. }
  330. type MPatient struct {
  331. ID int64 `gorm:"column:id" json:"id" form:"id"`
  332. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  333. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  334. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  335. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  336. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  337. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  338. Source int64 `gorm:"column:source" json:"source" form:"source"`
  339. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  340. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  341. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  342. Name string `gorm:"column:name" json:"name" form:"name"`
  343. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  344. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  345. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  346. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  347. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  348. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  349. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  350. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  351. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  352. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  353. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  354. Height int64 `gorm:"column:height" json:"height" form:"height"`
  355. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  356. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  357. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  358. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  359. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  360. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  361. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  362. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  363. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  364. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  365. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  366. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  367. Children int64 `gorm:"column:children" json:"children" form:"children"`
  368. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  369. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  370. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  371. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  372. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  373. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  374. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  375. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  376. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  377. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  378. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  379. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  380. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  381. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  382. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  383. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  384. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  385. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  386. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  387. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  388. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  389. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  390. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  391. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  392. Status int64 `gorm:"column:status" json:"status" form:"status"`
  393. Age int64 `gorm:"column:age" json:"age"`
  394. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  395. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  396. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  397. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  398. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  399. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  400. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  401. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  402. }
  403. func (MPatient) TableName() string {
  404. return "xt_patients"
  405. }
  406. // 接诊评估
  407. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  408. var record models.ReceiveTreatmentAsses
  409. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  410. if err != nil {
  411. if err == gorm.ErrRecordNotFound {
  412. return nil, nil
  413. } else {
  414. return nil, err
  415. }
  416. }
  417. return &record, nil
  418. }
  419. // 透前评估
  420. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  421. fmt.Println("recordDate", recordDate)
  422. var record models.PredialysisEvaluation
  423. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  424. if err != nil {
  425. if err == gorm.ErrRecordNotFound {
  426. return nil, nil
  427. } else {
  428. return nil, err
  429. }
  430. }
  431. return &record, nil
  432. }
  433. // 获取 maxDate 之前一次的透前评估记录
  434. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  435. var record models.PredialysisEvaluation
  436. 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
  437. if err != nil {
  438. if err == gorm.ErrRecordNotFound {
  439. return nil, nil
  440. } else {
  441. return nil, err
  442. }
  443. }
  444. return &record, nil
  445. }
  446. // 临时医嘱
  447. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  448. var records []*models.DoctorAdvice
  449. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  450. err := readDb.
  451. Model(&models.DoctorAdvice{}).
  452. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  453. 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").
  454. Order("start_time asc, groupno desc, advice_order desc, id").
  455. Scan(&records).Error
  456. if err != nil {
  457. return nil, err
  458. }
  459. return records, nil
  460. }
  461. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  462. var records []*models.DoctorAdvice
  463. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  464. err := readDb.
  465. Model(&models.DoctorAdvice{}).
  466. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
  467. 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").
  468. Order("start_time asc, groupno desc, advice_order desc, id asc").
  469. Scan(&records).Error
  470. if err != nil {
  471. return nil, err
  472. }
  473. return records, nil
  474. }
  475. // 透析记录
  476. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  477. var record models.DialysisOrder
  478. 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
  479. if err != nil {
  480. if err == gorm.ErrRecordNotFound {
  481. return nil, nil
  482. } else {
  483. return nil, err
  484. }
  485. }
  486. return &record, nil
  487. }
  488. // 双人核对
  489. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  490. var record models.DoubleCheck
  491. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  492. if err != nil {
  493. if err == gorm.ErrRecordNotFound {
  494. return nil, nil
  495. } else {
  496. return nil, err
  497. }
  498. }
  499. return &record, nil
  500. }
  501. // 透析监测记录
  502. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  503. var records []*models.MonitoringRecord
  504. 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
  505. if err != nil {
  506. return nil, err
  507. }
  508. return records, nil
  509. }
  510. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  511. var records models.MonitoringRecord
  512. 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
  513. if err != nil {
  514. return nil, err
  515. }
  516. return &records, nil
  517. }
  518. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  519. var record models.MonitoringRecord
  520. 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
  521. if err != nil {
  522. if err == gorm.ErrRecordNotFound {
  523. return nil, nil
  524. } else {
  525. return nil, err
  526. }
  527. }
  528. return &record, nil
  529. }
  530. // 透后评估
  531. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  532. var record models.AssessmentAfterDislysis
  533. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  534. if err != nil {
  535. if err == gorm.ErrRecordNotFound {
  536. return nil, nil
  537. } else {
  538. return nil, err
  539. }
  540. }
  541. return &record, nil
  542. }
  543. // 获取 maxDate 之前一次的透后评估记录
  544. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  545. var record models.AssessmentAfterDislysis
  546. 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
  547. if err != nil {
  548. if err == gorm.ErrRecordNotFound {
  549. return nil, nil
  550. } else {
  551. return nil, err
  552. }
  553. }
  554. return &record, nil
  555. }
  556. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  557. dislysis := models.AssessmentAfterDislysis{}
  558. 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
  559. return dislysis, err
  560. }
  561. // 治疗小结
  562. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  563. var record models.TreatmentSummary
  564. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  565. if err != nil {
  566. if err == gorm.ErrRecordNotFound {
  567. return nil, nil
  568. } else {
  569. return nil, err
  570. }
  571. }
  572. return &record, nil
  573. }
  574. // 透析处方
  575. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  576. var record models.DialysisPrescription
  577. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  578. if err != nil {
  579. if err == gorm.ErrRecordNotFound {
  580. return nil, nil
  581. } else {
  582. return nil, err
  583. }
  584. }
  585. return &record, nil
  586. }
  587. // 透析方案
  588. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  589. var record models.DialysisSolution
  590. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  591. if err != nil {
  592. if err == gorm.ErrRecordNotFound {
  593. return nil, nil
  594. } else {
  595. return nil, err
  596. }
  597. }
  598. return &record, nil
  599. }
  600. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  601. var patient models.Patients
  602. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  603. if err != nil {
  604. if err == gorm.ErrRecordNotFound {
  605. return nil, nil
  606. } else {
  607. return nil, err
  608. }
  609. }
  610. return &patient, nil
  611. }
  612. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  613. fmt.Println()
  614. tx := writeDb.Begin()
  615. updateTime := time.Now().Unix()
  616. 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
  617. if err != nil {
  618. tx.Rollback()
  619. return err
  620. }
  621. tx.Commit()
  622. return nil
  623. }
  624. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  625. var monitor models.MonitoringRecord
  626. var err error
  627. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  628. if err == gorm.ErrRecordNotFound {
  629. return nil, nil
  630. }
  631. if err != nil {
  632. return nil, err
  633. }
  634. return &monitor, nil
  635. }
  636. type MScheduleDoctorAdviceVM struct {
  637. ID int64 `gorm:"column:id" json:"id"`
  638. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  639. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  640. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  641. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  642. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  643. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  644. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  645. Status int64 `gorm:"column:status" json:"status"`
  646. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
  647. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  648. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  649. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  650. }
  651. func (MScheduleDoctorAdviceVM) TableName() string {
  652. return "xt_schedule"
  653. }
  654. type MDoctorAdviceVM struct {
  655. ID int64 `gorm:"column:id" json:"id"`
  656. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  657. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  658. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  659. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  660. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  661. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  662. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  663. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  664. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  665. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  666. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  667. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  668. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  669. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  670. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  671. Status int64 `gorm:"column:status" json:"status"`
  672. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  673. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  674. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  675. Remark string `gorm:"column:remark" json:"remark"`
  676. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  677. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  678. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  679. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  680. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  681. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  682. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  683. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  684. Checker int64 `gorm:"column:checker" json:"checker"`
  685. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  686. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  687. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  688. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  689. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  690. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  691. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  692. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  693. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  694. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  695. WeekDay string `gorm:"column:week_day" json:"week_day"`
  696. TemplateId string `gorm:"column:template_id" json:"template_id"`
  697. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  698. }
  699. func (MDoctorAdviceVM) TableName() string {
  700. return "xt_doctor_advice"
  701. }
  702. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64) ([]*MScheduleDoctorAdviceVM, error) {
  703. var vms []*MScheduleDoctorAdviceVM
  704. adviceWhere := ""
  705. fmt.Println("advicetype", adviceType)
  706. fmt.Println("patientType", patientType)
  707. fmt.Println("adminUserId", adminUserId)
  708. adviceCondition := []interface{}{}
  709. if adviceType == 0 {
  710. if patientType == 0 {
  711. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  712. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  713. } else if patientType == 1 {
  714. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  715. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  716. } else if patientType == 2 {
  717. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  718. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  719. }
  720. } else if adviceType == 1 {
  721. if patientType == 0 {
  722. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  723. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  724. } else if patientType == 1 {
  725. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  727. } else if patientType == 2 {
  728. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  730. }
  731. } else if adviceType == 3 {
  732. if patientType == 0 {
  733. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  735. } else if patientType == 1 {
  736. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  738. } else if patientType == 2 {
  739. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  741. }
  742. } else if adviceType == 2 {
  743. if patientType == 0 {
  744. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? "
  745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  746. } else if patientType == 1 {
  747. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? "
  748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  749. } else if patientType == 2 {
  750. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  752. }
  753. }
  754. db := readDb.
  755. Table("xt_schedule").
  756. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  757. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  758. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  759. }).
  760. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  761. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  762. Preload("DoctorAdvices", adviceCondition...).
  763. Where("status = 1 AND user_org_id = ?", orgID)
  764. if scheduleDate != 0 {
  765. db = db.Where("schedule_date = ?", scheduleDate)
  766. }
  767. err := db.Find(&vms).Error
  768. return vms, err
  769. }
  770. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  771. now := time.Now()
  772. tx := writeDb.Begin()
  773. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  774. tx.Rollback()
  775. return createOrderErr
  776. }
  777. // 更新透析记录 ID
  778. // 透析处方
  779. 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 {
  780. tx.Rollback()
  781. return err
  782. }
  783. // 接诊评估
  784. 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 {
  785. tx.Rollback()
  786. return err
  787. }
  788. // 透前评估
  789. 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 {
  790. tx.Rollback()
  791. return err
  792. }
  793. // 临时医嘱
  794. 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 {
  795. tx.Rollback()
  796. return err
  797. }
  798. // 双人核对
  799. 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 {
  800. tx.Rollback()
  801. return err
  802. }
  803. // 透后评估
  804. 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 {
  805. tx.Rollback()
  806. return err
  807. }
  808. // 治疗小结
  809. 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 {
  810. tx.Rollback()
  811. return err
  812. }
  813. // 透析监测
  814. 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 {
  815. tx.Rollback()
  816. return err
  817. }
  818. tx.Commit()
  819. return nil
  820. }
  821. type MobileUrgentSchedulePatientVM struct {
  822. ID int64 `gorm:"column:id" json:"id"`
  823. Name string `gorm:"column:name" json:"name"`
  824. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  825. }
  826. func (MobileUrgentSchedulePatientVM) TableName() string {
  827. return "xt_patients"
  828. }
  829. type MobileUrgentScheduleTreatmentModeVM struct {
  830. ID int64 `gorm:"column:id" json:"id"`
  831. Name string `gorm:"column:name" json:"name"`
  832. }
  833. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  834. return "xt_treatment_mode"
  835. }
  836. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  837. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  838. 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()
  839. defer rows.Close()
  840. if err != nil {
  841. return nil, err
  842. }
  843. for rows.Next() {
  844. var vm MobileUrgentSchedulePatientVM
  845. readDb.ScanRows(rows, &vm)
  846. vms = append(vms, &vm)
  847. }
  848. return vms, nil
  849. }
  850. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  851. var modes []*MobileUrgentScheduleTreatmentModeVM
  852. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  853. if err != nil {
  854. return nil, err
  855. }
  856. return modes, nil
  857. }
  858. type MobileUrgentScheduleScheduleListVM struct {
  859. ID int64 `gorm:"column:id" json:"id"`
  860. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  861. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  862. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  863. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  864. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  865. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  866. }
  867. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  868. return "xt_schedule"
  869. }
  870. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  871. db := readDb.
  872. Model(&MobileUrgentScheduleScheduleListVM{}).
  873. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  874. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  875. err = db.Find(&schedules).Error
  876. if err != nil {
  877. return nil, err
  878. }
  879. return schedules, nil
  880. }
  881. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  882. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  883. 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()
  884. defer rows.Close()
  885. if err != nil {
  886. return nil, err
  887. }
  888. for rows.Next() {
  889. var vm MobileUrgentScheduleScheduleListVM
  890. readDb.ScanRows(rows, &vm)
  891. vms = append(vms, &vm)
  892. }
  893. return vms, nil
  894. }
  895. type MobileUrgentScheduleDeviceNumberVM struct {
  896. ID int64 `gorm:"column:id" json:"id"`
  897. Number string `gorm:"column:number" json:"number"`
  898. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  899. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  900. }
  901. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  902. return "xt_device_number"
  903. }
  904. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  905. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  906. 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()
  907. defer rows.Close()
  908. if err != nil {
  909. return nil, err
  910. }
  911. for rows.Next() {
  912. var vm DeviceNumberViewModel
  913. readDb.ScanRows(rows, &vm)
  914. vms = append(vms, &vm)
  915. }
  916. return vms, nil
  917. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  918. //db := readDb.
  919. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  920. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  921. // Where("status = 1 AND org_id = ?", orgID)
  922. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  923. //if err != nil {
  924. // return nil, err
  925. //}
  926. //return deviceNumbers, nil
  927. }
  928. func GetValidScheduleMonitorRecordCount() (int64, error) {
  929. var total int64
  930. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  931. return total, err
  932. }
  933. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  934. var monitors []*models.MonitoringRecord
  935. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  936. if err != nil {
  937. return nil, err
  938. }
  939. return monitors, nil
  940. }
  941. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  942. tx := writeDb.Begin()
  943. for index := 0; index < len(monitors); index++ {
  944. tx.Save(monitors[index])
  945. }
  946. return tx.Commit().Error
  947. }
  948. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  949. tx := writeDb.Begin()
  950. updateTime := time.Now().Unix()
  951. 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
  952. if err != nil {
  953. tx.Rollback()
  954. return err
  955. }
  956. tx.Commit()
  957. return err
  958. }
  959. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  960. tx := writeDb.Begin()
  961. updateTime := time.Now().Unix()
  962. 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
  963. if err != nil {
  964. tx.Rollback()
  965. return err
  966. }
  967. tx.Commit()
  968. return err
  969. }
  970. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  971. var record models.SgjPatientDryweight
  972. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  973. if err != nil {
  974. if err == gorm.ErrRecordNotFound {
  975. return nil, nil
  976. } else {
  977. return nil, err
  978. }
  979. }
  980. return &record, nil
  981. }
  982. // 透析方案
  983. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  984. var record models.DialysisSolution
  985. 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
  986. if err != nil {
  987. if err == gorm.ErrRecordNotFound {
  988. return nil, nil
  989. } else {
  990. return nil, err
  991. }
  992. }
  993. return &record, nil
  994. }
  995. // 透析处方
  996. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  997. var record models.DialysisPrescription
  998. 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
  999. if err != nil {
  1000. if err == gorm.ErrRecordNotFound {
  1001. return nil, nil
  1002. } else {
  1003. return nil, err
  1004. }
  1005. }
  1006. return &record, nil
  1007. }
  1008. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  1009. var record models.DialysisPrescription
  1010. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  1011. if err != nil {
  1012. if err == gorm.ErrRecordNotFound {
  1013. return nil, nil
  1014. } else {
  1015. return nil, err
  1016. }
  1017. }
  1018. return &record, nil
  1019. }
  1020. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  1021. var record models.DialysisPrescription
  1022. 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
  1023. if err != nil {
  1024. if err == gorm.ErrRecordNotFound {
  1025. return nil, nil
  1026. } else {
  1027. return nil, err
  1028. }
  1029. }
  1030. return &record, nil
  1031. }
  1032. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1033. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1034. 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()
  1035. defer rows.Close()
  1036. if err != nil {
  1037. return nil, err
  1038. }
  1039. for rows.Next() {
  1040. var vm DeviceNumberViewModel
  1041. readDb.ScanRows(rows, &vm)
  1042. vms = append(vms, &vm)
  1043. }
  1044. return vms, nil
  1045. }
  1046. // 获取 maxDate 之前一次的透前评估记录
  1047. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  1048. var record models.PredialysisEvaluation
  1049. 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
  1050. if err != nil {
  1051. if err == gorm.ErrRecordNotFound {
  1052. return nil, nil
  1053. } else {
  1054. return nil, err
  1055. }
  1056. }
  1057. return &record, nil
  1058. }
  1059. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  1060. var record models.MonitoringRecord
  1061. 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
  1062. if err != nil {
  1063. if err == gorm.ErrRecordNotFound {
  1064. return nil, nil
  1065. } else {
  1066. return nil, err
  1067. }
  1068. }
  1069. return &record, nil
  1070. }
  1071. // 获取 maxDate 之前一次的透后评估记录
  1072. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1073. var record models.AssessmentAfterDislysis
  1074. 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
  1075. if err != nil {
  1076. if err == gorm.ErrRecordNotFound {
  1077. return nil, nil
  1078. } else {
  1079. return nil, err
  1080. }
  1081. }
  1082. return &record, nil
  1083. }
  1084. // 透析处方
  1085. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1086. var record models.DialysisPrescription
  1087. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1088. if err != nil {
  1089. if err == gorm.ErrRecordNotFound {
  1090. return nil, nil
  1091. } else {
  1092. return nil, err
  1093. }
  1094. }
  1095. return &record, nil
  1096. }
  1097. // 透析方案
  1098. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1099. var record models.DialysisSolution
  1100. 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
  1101. if err != nil {
  1102. if err == gorm.ErrRecordNotFound {
  1103. return nil, nil
  1104. } else {
  1105. return nil, err
  1106. }
  1107. }
  1108. return &record, nil
  1109. }
  1110. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  1111. var record models.DialysisPrescription
  1112. 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
  1113. if err != nil {
  1114. if err == gorm.ErrRecordNotFound {
  1115. return nil, nil
  1116. } else {
  1117. return nil, err
  1118. }
  1119. }
  1120. return &record, nil
  1121. }
  1122. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  1123. var record models.SgjPatientDryweight
  1124. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1125. if err != nil {
  1126. if err == gorm.ErrRecordNotFound {
  1127. return nil, nil
  1128. } else {
  1129. return nil, err
  1130. }
  1131. }
  1132. return &record, nil
  1133. }
  1134. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  1135. var record models.SystemPrescription
  1136. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  1137. if err != nil {
  1138. if err == gorm.ErrRecordNotFound {
  1139. return nil, nil
  1140. } else {
  1141. return nil, err
  1142. }
  1143. }
  1144. return &record, nil
  1145. }
  1146. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  1147. var record models.SystemPrescription
  1148. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  1149. if err != nil {
  1150. if err == gorm.ErrRecordNotFound {
  1151. return nil, nil
  1152. } else {
  1153. return nil, err
  1154. }
  1155. }
  1156. return &record, nil
  1157. }
  1158. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  1159. 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
  1160. return
  1161. }
  1162. func GetFirstDateOfMonth(d time.Time) time.Time {
  1163. d = d.AddDate(0, 0, -d.Day()+1)
  1164. return GetZeroTime(d)
  1165. }
  1166. func GetZeroTime(d time.Time) time.Time {
  1167. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  1168. }
  1169. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  1170. db := XTReadDB().Table("xt_dialysis_order as o")
  1171. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule AS x ON x.patient_id = o.patient_id where o.status = 1 and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1 and o.patient_id = ?", startime, endtime, orgid, patientid).Scan(&order).Group("o.patient_id").Error
  1172. return order, err
  1173. }
  1174. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  1175. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
  1176. return
  1177. }
  1178. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  1179. // err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patient_id,recordDate).Find(&consumables).Error
  1180. // return
  1181. //}
  1182. //
  1183. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  1184. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date < ?", patientID, orgID, maxDate).Order("record_date desc").Find(&prepare).Error
  1185. return
  1186. }
  1187. type GoodsType struct {
  1188. ID int64 `gorm:"column:id" json:"id"`
  1189. TypeName string `gorm:"column:type_name" json:"type_name"`
  1190. Remark string `gorm:"column:remark" json:"remark"`
  1191. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  1192. Status int64 `gorm:"column:status" json:"status"`
  1193. Type int64 `gorm:"column:type" json:"type"`
  1194. }
  1195. func (GoodsType) TableName() string {
  1196. return "xt_goods_type"
  1197. }
  1198. type VMGoodInfo struct {
  1199. ID int64 `gorm:"column:id" json:"id"`
  1200. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  1201. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  1202. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  1203. }
  1204. func (VMGoodInfo) TableName() string {
  1205. return "xt_good_information"
  1206. }
  1207. type AutomaticReduceDetail struct {
  1208. ID int64 `gorm:"column:id" json:"id"`
  1209. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1210. Status int64 `gorm:"column:status" json:"status"`
  1211. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  1212. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  1213. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  1214. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  1215. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  1216. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  1217. Count int64 `gorm:"column:count" json:"count"`
  1218. }
  1219. func (AutomaticReduceDetail) TableName() string {
  1220. return "xt_automatic_reduce_detail"
  1221. }
  1222. type DialysisBeforePrepare struct {
  1223. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1224. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1225. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1226. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1227. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  1228. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  1229. Count int64 `gorm:"column:count" json:"count" form:"count"`
  1230. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1231. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1232. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  1233. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1234. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  1235. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  1236. }
  1237. func (DialysisBeforePrepare) TableName() string {
  1238. return "dialysis_before_prepare"
  1239. }
  1240. type MDialysisGoodsVM struct {
  1241. ID int64 `gorm:"column:id" json:"id"`
  1242. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1243. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1244. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1245. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1246. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1247. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1248. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  1249. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1250. Status int64 `gorm:"column:status" json:"status"`
  1251. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1252. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  1253. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  1254. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  1255. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  1256. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  1257. }
  1258. func (MDialysisGoodsVM) TableName() string {
  1259. return "xt_schedule"
  1260. }
  1261. type VMWarehouseOutInfo struct {
  1262. ID int64 `gorm:"column:id" json:"id"`
  1263. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  1264. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  1265. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  1266. Count int64 `gorm:"column:count" json:"count"`
  1267. Price float64 `gorm:"column:price" json:"price"`
  1268. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  1269. Status int64 `gorm:"column:status" json:"status"`
  1270. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  1271. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  1272. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  1273. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  1274. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  1275. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  1276. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  1277. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  1278. }
  1279. func (VMWarehouseOutInfo) TableName() string {
  1280. return "xt_warehouse_out_info"
  1281. }
  1282. type DialysisGoodsDate struct {
  1283. RecordDate int64
  1284. }
  1285. type DialysisGoodsDetailDate struct {
  1286. RecordTime int64
  1287. }
  1288. func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64) ([]*MDialysisGoodsVM, error, int64) {
  1289. var vms []*MDialysisGoodsVM
  1290. var total int64
  1291. db := readDb.
  1292. Table("xt_schedule as sch").
  1293. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1294. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1295. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1296. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  1297. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  1298. }).
  1299. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  1300. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ? ", orgID, scheduleDate, end_time)
  1301. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  1302. if scheduleDate != 0 {
  1303. db = db.Where("schedule_date = ?", scheduleDate)
  1304. }
  1305. if schedule_type != 0 {
  1306. db = db.Where("schedule_type = ?", schedule_type)
  1307. }
  1308. if partition_id != 0 {
  1309. db = db.Where("partition_id = ?", partition_id)
  1310. }
  1311. if patient_id != 0 {
  1312. db = db.Where("patient_id = ?", patient_id)
  1313. }
  1314. //db = db.Count(&total)
  1315. //offset := (page - 1) * limit
  1316. //
  1317. //db = db.Offset(offset).Limit(limit)
  1318. err := db.Find(&vms).Error
  1319. return vms, err, total
  1320. }
  1321. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  1322. var Id []*DialysisGoodsDetailDate
  1323. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
  1324. if len(Id) > 0 {
  1325. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  1326. }
  1327. return
  1328. }
  1329. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  1330. var Id []*DialysisGoodsDate
  1331. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND count > 0", patient_id, orgID, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  1332. if len(Id) > 0 {
  1333. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordDate).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  1334. }
  1335. return
  1336. }
  1337. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  1338. db := readDb.Model(&models.StockInfo{})
  1339. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  1340. db = db.Joins("JOIN xt_warehouse_out_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgID).Group("xt_good_information.id")
  1341. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  1342. return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1 AND xt_warehouse_out_info.sys_record_time >= ? AND xt_warehouse_out_info.sys_record_time <= ?", orgID, start_time, end_time)
  1343. })
  1344. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  1345. err = db.Order("ctime desc").Find(&list).Error
  1346. return
  1347. }
  1348. func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64) ([]*MDialysisGoodsVM, error, int64) {
  1349. var vms []*MDialysisGoodsVM
  1350. var total int64
  1351. db := readDb.
  1352. Model(&models.Schedule{}).
  1353. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1354. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1355. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1356. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  1357. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  1358. }).
  1359. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  1360. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time >= ? AND record_time <=? AND count > 0", orgID, scheduleDate, end_time)
  1361. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  1362. if scheduleDate != 0 {
  1363. db = db.Where("schedule_date = ?", scheduleDate)
  1364. }
  1365. if patient_id != 0 {
  1366. db = db.Where("patient_id = ?", patient_id)
  1367. }
  1368. if len(keywords) != 0 {
  1369. keywords = "%" + keywords + "%"
  1370. db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
  1371. } else {
  1372. if schedule_type != 0 {
  1373. db = db.Where("schedule_type = ?", schedule_type)
  1374. }
  1375. if partition_id != 0 {
  1376. db = db.Where("partition_id = ?", partition_id)
  1377. }
  1378. db = db.Count(&total)
  1379. offset := (page - 1) * limit
  1380. db = db.Offset(offset).Limit(limit)
  1381. }
  1382. err := db.Find(&vms).Error
  1383. return vms, err, total
  1384. }
  1385. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  1386. var Id []*DialysisGoodsDetailDate
  1387. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
  1388. if len(Id) > 0 {
  1389. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  1390. }
  1391. return
  1392. }
  1393. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  1394. var Id []*DialysisGoodsDate
  1395. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  1396. if len(Id) > 0 {
  1397. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordDate).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  1398. }
  1399. return
  1400. }