mobile_dialysis_service.go 170KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628
  1. package service
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "strconv"
  8. "time"
  9. )
  10. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  11. // var vms []*MDialysisScheduleVM
  12. // err := readDb.
  13. // Table("xt_schedule as sch").
  14. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  15. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  16. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  17. // Preload("TreatmentMode", "status = 1").
  18. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  19. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  20. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  21. // Find(&vms).
  22. // Error
  23. // return vms, err
  24. // }
  25. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
  26. var vms []*MDialysisScheduleVMForList
  27. db := readDb.
  28. Table("xt_schedule as sch").
  29. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  30. if scheduleDate != 0 {
  31. db = db.Where("schedule_date = ?", scheduleDate)
  32. }
  33. if scheduleType != 0 {
  34. db = db.Where("schedule_type = ?", scheduleType)
  35. }
  36. err := db.Find(&vms).Error
  37. return vms, err
  38. }
  39. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  40. var vms []*MDialysisScheduleVM
  41. db := readDb.
  42. Table("xt_schedule as sch").
  43. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  44. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  45. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  46. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  47. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  48. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  49. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  50. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  51. Preload("TreatmentMode", "status = 1").
  52. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  53. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  54. if scheduleDate != 0 {
  55. db = db.Where("schedule_date = ?", scheduleDate)
  56. }
  57. err := db.Find(&vms).Error
  58. return vms, err
  59. }
  60. type VMTreatmentSummary struct {
  61. ID int64 `gorm:"column:id" json:"id"`
  62. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  63. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  64. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  65. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  66. }
  67. func (VMTreatmentSummary) TableName() string {
  68. return "xt_treatment_summary"
  69. }
  70. type AssessmentAfterDislysis struct {
  71. ID int64 `gorm:"column:id" json:"id"`
  72. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  73. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  74. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  75. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  76. Status int64 `gorm:"column:status" json:"status"`
  77. }
  78. func (AssessmentAfterDislysis) TableName() string {
  79. return "xt_assessment_after_dislysis"
  80. }
  81. type MDialysisScheduleVM struct {
  82. ID int64 `gorm:"column:id" json:"id"`
  83. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  84. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  85. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  86. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  87. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  88. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  89. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  90. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  91. Status int64 `gorm:"column:status" json:"status"`
  92. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  93. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  94. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  95. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  96. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  97. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  98. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  99. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  100. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  101. }
  102. func (MDialysisScheduleVM) TableName() string {
  103. return "xt_schedule"
  104. }
  105. type MDialysisScheduleVMForList struct {
  106. ID int64 `gorm:"column:id" json:"id"`
  107. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  108. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  109. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  110. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  111. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  112. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  113. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  114. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  115. Status int64 `gorm:"column:status" json:"status"`
  116. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  117. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  118. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  119. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  120. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  121. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  122. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  123. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  124. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  125. }
  126. func (MDialysisScheduleVMForList) TableName() string {
  127. return "xt_schedule"
  128. }
  129. type MDeviceNumberVM struct {
  130. models.DeviceNumber
  131. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  132. }
  133. func (MDeviceNumberVM) TableName() string {
  134. return "xt_device_number"
  135. }
  136. type MSchedualPatientVMList struct {
  137. ID int64 `gorm:"column:id" json:"id" form:"id"`
  138. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  139. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  140. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  141. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  142. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  143. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  144. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  145. Age int64 `gorm:"column:age" json:"age"`
  146. Name string `gorm:"column:name" json:"name" form:"name"`
  147. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  148. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  149. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  150. }
  151. func (MSchedualPatientVMList) TableName() string {
  152. return "xt_patients"
  153. }
  154. type MSchedualPatientVM struct {
  155. ID int64 `gorm:"column:id" json:"id" form:"id"`
  156. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  157. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  158. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  159. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  160. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  161. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  162. Source int64 `gorm:"column:source" json:"source" form:"source"`
  163. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  164. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  165. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  166. Name string `gorm:"column:name" json:"name" form:"name"`
  167. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  168. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  169. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  170. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  171. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  172. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  173. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  174. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  175. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  176. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  177. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  178. Height int64 `gorm:"column:height" json:"height" form:"height"`
  179. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  180. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  181. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  182. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  183. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  184. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  185. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  186. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  187. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  188. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  189. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  190. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  191. Children int64 `gorm:"column:children" json:"children" form:"children"`
  192. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  193. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  194. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  195. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  196. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  197. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  198. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  199. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  200. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  201. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  202. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  203. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  204. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  205. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  206. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  207. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  208. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  209. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  210. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  211. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  212. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  213. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  214. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  215. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  216. Status int64 `gorm:"column:status" json:"status" form:"status"`
  217. Age int64 `gorm:"column:age" json:"age"`
  218. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  219. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  220. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  221. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  222. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  223. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  224. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  225. }
  226. func (MSchedualPatientVM) TableName() string {
  227. return "xt_patients"
  228. }
  229. type MDialysisOrderVM struct {
  230. ID int64 `gorm:"column:id" json:"id"`
  231. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  232. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  233. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  234. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  235. Stage int64 `gorm:"column:stage" json:"stage"`
  236. // Remark string `gorm:"column:remark" json:"remark"`
  237. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  238. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  239. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  240. Status int64 `gorm:"column:status" json:"status"`
  241. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  242. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  243. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  244. Creator int64 `gorm:"column:creator" json:"creator"`
  245. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  246. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  247. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  248. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  249. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  250. }
  251. func (MDialysisOrderVM) TableName() string {
  252. return "xt_dialysis_order"
  253. }
  254. type MDialysisOrderVMList struct {
  255. ID int64 `gorm:"column:id" json:"id"`
  256. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  257. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  258. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  259. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  260. Stage int64 `gorm:"column:stage" json:"stage"`
  261. // Remark string `gorm:"column:remark" json:"remark"`
  262. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  263. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  264. Status int64 `gorm:"column:status" json:"status"`
  265. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  266. Creator int64 `gorm:"column:creator" json:"creator"`
  267. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  268. }
  269. func (MDialysisOrderVMList) TableName() string {
  270. return "xt_dialysis_order"
  271. }
  272. type VMDoctorAdvice struct {
  273. ID int64 `gorm:"column:id" json:"id" form:"id"`
  274. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  275. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  276. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  277. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  278. Status int64 `gorm:"column:status" json:"status" form:"status"`
  279. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  280. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  281. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  282. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  283. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  284. }
  285. func (VMDoctorAdvice) TableName() string {
  286. return "xt_doctor_advice"
  287. }
  288. type VMHisDoctorAdviceInfo struct {
  289. ID int64 `gorm:"column:id" json:"id" form:"id"`
  290. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  291. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  292. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  293. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  294. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  295. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  296. }
  297. func (VMHisDoctorAdviceInfo) TableName() string {
  298. return "his_doctor_advice_info"
  299. }
  300. type VMAssessmentAfterDislysis struct {
  301. ID int64 `gorm:"column:id" json:"id"`
  302. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  303. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  304. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  305. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  306. Status int64 `gorm:"column:status" json:"status"`
  307. }
  308. func (VMAssessmentAfterDislysis) TableName() string {
  309. return "xt_assessment_after_dislysis"
  310. }
  311. // 获取透析记录
  312. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  313. var record models.DialysisOrder
  314. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  315. if err != nil {
  316. if err == gorm.ErrRecordNotFound {
  317. return nil, nil
  318. } else {
  319. return nil, err
  320. }
  321. }
  322. return &record, nil
  323. }
  324. // 用户基本信息
  325. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  326. var patient MPatient
  327. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  328. //if err != nil {
  329. // if err == gorm.ErrRecordNotFound {
  330. // return nil, nil
  331. // } else {
  332. // return nil, err
  333. // }
  334. //}
  335. //return &patient, nil
  336. redis := RedisClient()
  337. defer redis.Close()
  338. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  339. patient_info_str, _ := redis.Get(key).Result()
  340. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  341. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  342. if err != nil {
  343. if err == gorm.ErrRecordNotFound {
  344. return &patient, nil
  345. } else {
  346. return &patient, err
  347. }
  348. } else {
  349. if patient.ID > 0 {
  350. //缓存数据
  351. patient_info_json, err := json.Marshal(&patient)
  352. if err == nil {
  353. redis.Set(key, patient_info_json, time.Second*60*60*18)
  354. }
  355. }
  356. return &patient, nil
  357. }
  358. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  359. json.Unmarshal([]byte(patient_info_str), &patient)
  360. return &patient, nil
  361. }
  362. }
  363. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  364. var vm MDialysisScheduleVM
  365. err := readDb.
  366. Table("xt_schedule").
  367. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  368. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  369. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  370. First(&vm).Error
  371. return &vm, err
  372. }
  373. // 用户排班信息
  374. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  375. var vm MDialysisScheduleVM
  376. err := readDb.
  377. Table("xt_schedule").
  378. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  379. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  380. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  381. First(&vm).Error
  382. if err != nil {
  383. if err == gorm.ErrRecordNotFound {
  384. return nil, nil
  385. } else {
  386. return nil, err
  387. }
  388. }
  389. return &vm, err
  390. }
  391. // 用户排班信息
  392. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  393. redis := RedisClient()
  394. defer redis.Close()
  395. var vm MDialysisScheduleVM
  396. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  397. schedual_detail_str, _ := redis.Get(key).Result()
  398. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  399. err := readDb.
  400. Table("xt_schedule").
  401. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  402. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  403. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  404. First(&vm).Error
  405. if err != nil {
  406. if err == gorm.ErrRecordNotFound {
  407. return nil, nil
  408. } else {
  409. return nil, err
  410. }
  411. } else {
  412. if vm.ID > 0 {
  413. //缓存数据
  414. schedual_detail_str, err := json.Marshal(vm)
  415. if err == nil {
  416. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  417. }
  418. } else {
  419. redis.Set(key, "null", time.Second*60*60*18)
  420. }
  421. return &vm, nil
  422. }
  423. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  424. if schedual_detail_str == "null" {
  425. return &vm, nil
  426. }
  427. json.Unmarshal([]byte(schedual_detail_str), &vm)
  428. return &vm, nil
  429. }
  430. }
  431. // 用户排班信息
  432. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  433. var schedule models.Schedule
  434. err := readDb.
  435. Table("xt_schedule").
  436. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  437. First(&schedule).Error
  438. if err != nil {
  439. if err == gorm.ErrRecordNotFound {
  440. return nil, nil
  441. } else {
  442. return nil, err
  443. }
  444. }
  445. return &schedule, nil
  446. }
  447. type MPatient struct {
  448. ID int64 `gorm:"column:id" json:"id" form:"id"`
  449. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  450. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  451. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  452. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  453. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  454. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  455. Source int64 `gorm:"column:source" json:"source" form:"source"`
  456. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  457. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  458. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  459. Name string `gorm:"column:name" json:"name" form:"name"`
  460. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  461. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  462. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  463. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  464. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  465. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  466. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  467. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  468. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  469. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  470. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  471. Height int64 `gorm:"column:height" json:"height" form:"height"`
  472. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  473. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  474. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  475. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  476. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  477. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  478. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  479. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  480. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  481. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  482. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  483. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  484. Children int64 `gorm:"column:children" json:"children" form:"children"`
  485. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  486. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  487. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  488. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  489. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  490. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  491. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  492. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  493. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  494. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  495. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  496. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  497. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  498. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  499. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  500. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  501. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  502. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  503. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  504. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  505. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  506. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  507. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  508. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  509. Status int64 `gorm:"column:status" json:"status" form:"status"`
  510. Age int64 `gorm:"column:age" json:"age"`
  511. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  512. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  513. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  514. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  515. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  516. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  517. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  518. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  519. }
  520. func (MPatient) TableName() string {
  521. return "xt_patients"
  522. }
  523. // 接诊评估
  524. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  525. var record models.ReceiveTreatmentAsses
  526. redis := RedisClient()
  527. defer redis.Close()
  528. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  529. receive_treatment_asses_str, _ := redis.Get(key).Result()
  530. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  531. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  532. if err != nil {
  533. if err == gorm.ErrRecordNotFound {
  534. if record.ID <= 0 {
  535. redis.Set(key, "", time.Second*60*60*18)
  536. }
  537. return nil, nil
  538. } else {
  539. return nil, err
  540. }
  541. } else {
  542. if record.ID > 0 {
  543. //缓存数据
  544. receive_treatment_asses_str, err := json.Marshal(record)
  545. if err == nil {
  546. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  547. }
  548. } else {
  549. redis.Set(key, "null", time.Second*60*60*18)
  550. }
  551. return &record, nil
  552. }
  553. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  554. if receive_treatment_asses_str == "null" {
  555. return &record, nil
  556. }
  557. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  558. return &record, nil
  559. }
  560. }
  561. // 透前评估
  562. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  563. fmt.Println("recordDate", recordDate)
  564. var record models.PredialysisEvaluation
  565. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  566. if err != nil {
  567. if err == gorm.ErrRecordNotFound {
  568. return nil, nil
  569. } else {
  570. return nil, err
  571. }
  572. }
  573. return &record, nil
  574. }
  575. // 透前评估
  576. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  577. var record models.PredialysisEvaluation
  578. redis := RedisClient()
  579. defer redis.Close()
  580. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  581. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  582. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  583. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  584. if err != nil {
  585. if err == gorm.ErrRecordNotFound {
  586. if record.ID <= 0 {
  587. redis.Set(key, "", time.Second*60*60*18)
  588. }
  589. return nil, nil
  590. } else {
  591. return nil, err
  592. }
  593. } else {
  594. if record.ID > 0 {
  595. //缓存数据
  596. assessment_before_dislysis_str, err := json.Marshal(record)
  597. if err == nil {
  598. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  599. }
  600. } else {
  601. redis.Set(key, "null", time.Second*60*60*18)
  602. }
  603. return &record, nil
  604. }
  605. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  606. if assessment_before_dislysis_str == "null" {
  607. return &record, nil
  608. } else {
  609. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  610. return &record, nil
  611. }
  612. }
  613. }
  614. // 获取 maxDate 之前一次的透前评估记录
  615. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  616. var record models.PredialysisEvaluation
  617. 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
  618. if err != nil {
  619. if err == gorm.ErrRecordNotFound {
  620. return nil, nil
  621. } else {
  622. return nil, err
  623. }
  624. }
  625. return &record, nil
  626. }
  627. // 获取 maxDate 之前一次的透前评估记录
  628. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  629. var record models.PredialysisEvaluation
  630. redis := RedisClient()
  631. defer redis.Close()
  632. // cur_date := time.Now().Format("2006-01-02")
  633. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  634. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  635. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  636. 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
  637. if err != nil {
  638. if err == gorm.ErrRecordNotFound {
  639. if record.ID <= 0 {
  640. redis.Set(key, "", time.Second*60*60*18)
  641. }
  642. return nil, nil
  643. } else {
  644. return nil, err
  645. }
  646. } else {
  647. if record.ID > 0 {
  648. //缓存数据
  649. assessment_before_dislysis_last_str, err := json.Marshal(record)
  650. if err == nil {
  651. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  652. }
  653. } else {
  654. redis.Set(key, "null", time.Second*60*60*18)
  655. }
  656. return &record, nil
  657. }
  658. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  659. if assessment_before_dislysis_last_str == "null" {
  660. return &record, nil
  661. } else {
  662. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  663. return &record, nil
  664. }
  665. }
  666. }
  667. // 临时医嘱
  668. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  669. var records []*models.DoctorAdvice
  670. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  671. err := readDb.
  672. Model(&models.DoctorAdvice{}).
  673. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  674. 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,way,drug_id,drug_name_id,IF(parent_id>0, parent_id, id) as advice_order,groupno").
  675. Order("start_time asc, groupno desc, advice_order desc, id").
  676. Scan(&records).Error
  677. if err != nil {
  678. return nil, err
  679. }
  680. return records, nil
  681. }
  682. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  683. var records []*models.DoctorAdvice
  684. redis := RedisClient()
  685. defer redis.Close()
  686. // cur_date := time.Now().Format("2006-01-02")
  687. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  688. doctor_advices_str, _ := redis.Get(key).Result()
  689. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  690. err := readDb.Model(&models.DoctorAdvice{}).
  691. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  692. 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,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
  693. Order("start_time asc, groupno desc, advice_order desc, id asc").
  694. Scan(&records).Error
  695. if err != nil {
  696. if err == gorm.ErrRecordNotFound {
  697. if len(records) <= 0 {
  698. redis.Set(key, "", time.Second*60*60*18)
  699. }
  700. return nil, nil
  701. } else {
  702. return nil, err
  703. }
  704. } else {
  705. if len(records) > 0 {
  706. //缓存数据
  707. doctor_advices_str, err := json.Marshal(records)
  708. if err == nil {
  709. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  710. return records, nil
  711. }
  712. } else {
  713. redis.Set(key, "null", time.Second*60*60*18)
  714. return records, nil
  715. }
  716. return records, nil
  717. }
  718. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  719. if doctor_advices_str == "null" {
  720. return records, nil
  721. } else {
  722. json.Unmarshal([]byte(doctor_advices_str), &records)
  723. return records, nil
  724. }
  725. }
  726. }
  727. // 透析记录
  728. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  729. var record models.DialysisOrder
  730. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ?", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  731. if err != nil {
  732. if err == gorm.ErrRecordNotFound {
  733. return nil, nil
  734. } else {
  735. return nil, err
  736. }
  737. }
  738. return &record, nil
  739. }
  740. // 透析记录
  741. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  742. var record models.DialysisOrder
  743. redis := RedisClient()
  744. defer redis.Close()
  745. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  746. dialysis_order_str, _ := redis.Get(key).Result()
  747. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  748. 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
  749. if err != nil {
  750. if err == gorm.ErrRecordNotFound {
  751. return nil, nil
  752. } else {
  753. return nil, err
  754. }
  755. } else {
  756. if record.ID > 0 {
  757. //缓存数据
  758. dialysis_order_str, err := json.Marshal(record)
  759. if err == nil {
  760. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  761. }
  762. } else {
  763. redis.Set(key, "null", time.Second*60*60*18)
  764. }
  765. return &record, nil
  766. }
  767. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  768. if dialysis_order_str == "null" {
  769. 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
  770. return &record, nil
  771. } else {
  772. json.Unmarshal([]byte(dialysis_order_str), &record)
  773. return &record, nil
  774. }
  775. }
  776. }
  777. // 双人核对
  778. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  779. var record models.DoubleCheck
  780. redis := RedisClient()
  781. defer redis.Close()
  782. // cur_date := time.Now().Format("2006-01-02")
  783. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  784. double_check_str, _ := redis.Get(key).Result()
  785. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  786. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  787. if err != nil {
  788. if err == gorm.ErrRecordNotFound {
  789. if record.ID <= 0 {
  790. redis.Set(key, "null", time.Second*60*60*18)
  791. }
  792. return nil, nil
  793. } else {
  794. return nil, err
  795. }
  796. } else {
  797. if record.ID > 0 {
  798. //缓存数据
  799. double_check_str, err := json.Marshal(record)
  800. if err == nil {
  801. redis.Set(key, double_check_str, time.Second*60*60*18)
  802. }
  803. } else {
  804. redis.Set(key, "null", time.Second*60*60*18)
  805. }
  806. return &record, nil
  807. }
  808. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  809. if double_check_str == "null" {
  810. return &record, nil
  811. } else {
  812. json.Unmarshal([]byte(double_check_str), &record)
  813. return &record, nil
  814. }
  815. }
  816. }
  817. // 透析监测记录
  818. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  819. var records []*models.MonitoringRecord
  820. redis := RedisClient()
  821. defer redis.Close()
  822. // cur_date := time.Now().Format("2006-01-02")
  823. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  824. monitor_records_str, _ := redis.Get(key).Result()
  825. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  826. 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
  827. if err != nil {
  828. if err == gorm.ErrRecordNotFound {
  829. //if len(records) <= 0 {
  830. // redis.Set(key, "null", time.Second*60*60*18)
  831. //}
  832. return nil, nil
  833. } else {
  834. return nil, err
  835. }
  836. } else {
  837. if len(records) > 0 {
  838. //缓存数据
  839. monitor_records_str, err := json.Marshal(records)
  840. if err == nil {
  841. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  842. }
  843. } else {
  844. redis.Set(key, "null", time.Second*60*60*18)
  845. }
  846. return records, nil
  847. }
  848. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  849. if monitor_records_str == "null" {
  850. return records, nil
  851. } else {
  852. json.Unmarshal([]byte(monitor_records_str), &records)
  853. return records, nil
  854. }
  855. }
  856. }
  857. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  858. var records models.MonitoringRecord
  859. 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
  860. if err != nil {
  861. return nil, err
  862. }
  863. return &records, nil
  864. }
  865. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  866. var record models.MonitoringRecord
  867. 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
  868. if err != nil {
  869. if err == gorm.ErrRecordNotFound {
  870. return nil, nil
  871. } else {
  872. return nil, err
  873. }
  874. }
  875. return &record, nil
  876. }
  877. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  878. var record models.MonitoringRecord
  879. redis := RedisClient()
  880. defer redis.Close()
  881. // cur_date := time.Now().Format("2006-01-02")
  882. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  883. monitor_record_last_str, _ := redis.Get(key).Result()
  884. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  885. 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
  886. if err != nil {
  887. if err == gorm.ErrRecordNotFound {
  888. if record.ID <= 0 {
  889. redis.Set(key, "null", time.Second*60*60*18)
  890. }
  891. return nil, nil
  892. } else {
  893. return nil, err
  894. }
  895. } else {
  896. if record.ID > 0 {
  897. //缓存数据
  898. monitor_record_last_str, err := json.Marshal(record)
  899. if err == nil {
  900. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  901. }
  902. } else {
  903. redis.Set(key, "null", time.Second*60*60*18)
  904. }
  905. return &record, nil
  906. }
  907. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  908. if monitor_record_last_str == "null" {
  909. return &record, nil
  910. } else {
  911. json.Unmarshal([]byte(monitor_record_last_str), &record)
  912. return &record, nil
  913. }
  914. }
  915. }
  916. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  917. var record models.AssessmentAfterDislysis
  918. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  919. if err != nil {
  920. if err == gorm.ErrRecordNotFound {
  921. return nil, nil
  922. } else {
  923. return nil, err
  924. }
  925. }
  926. return &record, nil
  927. }
  928. // 透后评估
  929. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  930. var record models.AssessmentAfterDislysis
  931. redis := RedisClient()
  932. defer redis.Close()
  933. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  934. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  935. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  936. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  937. if err != nil {
  938. if err == gorm.ErrRecordNotFound {
  939. if record.ID <= 0 {
  940. redis.Set(key, "null", time.Second*60*60*18)
  941. }
  942. return nil, nil
  943. } else {
  944. return nil, err
  945. }
  946. } else {
  947. if record.ID > 0 {
  948. //缓存数据
  949. assessment_after_dislysis_str, err := json.Marshal(record)
  950. if err == nil {
  951. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  952. }
  953. } else {
  954. redis.Set(key, "null", time.Second*60*60*18)
  955. }
  956. return &record, nil
  957. }
  958. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  959. if assessment_after_dislysis_str == "null" {
  960. return &record, nil
  961. } else {
  962. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  963. return &record, nil
  964. }
  965. }
  966. }
  967. // 获取 maxDate 之前一次的透后评估记录
  968. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  969. var record models.AssessmentAfterDislysis
  970. redis := RedisClient()
  971. defer redis.Close()
  972. // cur_date := time.Now().Format("2006-01-02")
  973. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  974. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  975. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  976. 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
  977. if err != nil {
  978. if err == gorm.ErrRecordNotFound {
  979. if record.ID <= 0 {
  980. redis.Set(key, "null", time.Second*60*60*18)
  981. }
  982. return nil, nil
  983. } else {
  984. return nil, err
  985. }
  986. } else {
  987. if record.ID > 0 {
  988. //缓存数据
  989. assessment_after_dislysis_last_str, err := json.Marshal(record)
  990. if err == nil {
  991. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  992. }
  993. } else {
  994. redis.Set(key, "null", time.Second*60*60*18)
  995. }
  996. return &record, nil
  997. }
  998. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  999. if assessment_after_dislysis_last_str == "null" {
  1000. return &record, nil
  1001. } else {
  1002. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1003. return &record, nil
  1004. }
  1005. }
  1006. }
  1007. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1008. var record models.AssessmentAfterDislysis
  1009. 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
  1010. if err != nil {
  1011. if err == gorm.ErrRecordNotFound {
  1012. return nil, nil
  1013. } else {
  1014. return nil, err
  1015. }
  1016. }
  1017. return &record, nil
  1018. }
  1019. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1020. dislysis := models.AssessmentAfterDislysis{}
  1021. 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
  1022. return dislysis, err
  1023. }
  1024. // 治疗小结
  1025. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1026. var record models.TreatmentSummary
  1027. redis := RedisClient()
  1028. defer redis.Close()
  1029. // cur_date := time.Now().Format("2006-01-02")
  1030. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1031. treatment_summary_str, _ := redis.Get(key).Result()
  1032. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1033. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1034. if err != nil {
  1035. if err == gorm.ErrRecordNotFound {
  1036. if record.ID <= 0 {
  1037. redis.Set(key, "null", time.Second*60*60*18)
  1038. }
  1039. return nil, nil
  1040. } else {
  1041. return nil, err
  1042. }
  1043. } else {
  1044. if record.ID > 0 {
  1045. //缓存数据
  1046. treatment_summary_str, err := json.Marshal(record)
  1047. if err == nil {
  1048. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1049. }
  1050. } else {
  1051. redis.Set(key, "null", time.Second*60*60*18)
  1052. }
  1053. return &record, nil
  1054. }
  1055. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1056. if treatment_summary_str == "null" {
  1057. return &record, nil
  1058. } else {
  1059. json.Unmarshal([]byte(treatment_summary_str), &record)
  1060. return &record, nil
  1061. }
  1062. }
  1063. }
  1064. // 透析处方
  1065. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1066. var record models.DialysisPrescription
  1067. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1068. if err != nil {
  1069. if err == gorm.ErrRecordNotFound {
  1070. return nil, nil
  1071. } else {
  1072. return nil, err
  1073. }
  1074. }
  1075. return &record, nil
  1076. }
  1077. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1078. var schedule models.XtSchedule
  1079. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1080. if err != nil {
  1081. if err == gorm.ErrRecordNotFound {
  1082. return nil, nil
  1083. } else {
  1084. return nil, err
  1085. }
  1086. }
  1087. return &schedule, nil
  1088. }
  1089. // 透析方案
  1090. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1091. var record models.DialysisSolution
  1092. err := readDb.Model(&models.DialysisSolution{}).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 MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1103. var patient models.Patients
  1104. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1105. if err != nil {
  1106. if err == gorm.ErrRecordNotFound {
  1107. return nil, nil
  1108. } else {
  1109. return nil, err
  1110. }
  1111. }
  1112. return &patient, nil
  1113. }
  1114. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1115. fmt.Println()
  1116. tx := writeDb.Begin()
  1117. updateTime := time.Now().Unix()
  1118. 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
  1119. if err != nil {
  1120. tx.Rollback()
  1121. return err
  1122. }
  1123. tx.Commit()
  1124. return nil
  1125. }
  1126. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1127. var monitor models.MonitoringRecord
  1128. var err error
  1129. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1130. if err == gorm.ErrRecordNotFound {
  1131. return nil, nil
  1132. }
  1133. if err != nil {
  1134. return nil, err
  1135. }
  1136. return &monitor, nil
  1137. }
  1138. type MScheduleDoctorAdviceVM struct {
  1139. ID int64 `gorm:"column:id" json:"id"`
  1140. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1141. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1142. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1143. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1144. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1145. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1146. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1147. Status int64 `gorm:"column:status" json:"status"`
  1148. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1149. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1150. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1151. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1152. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1153. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1154. }
  1155. func (MScheduleDoctorAdviceVM) TableName() string {
  1156. return "xt_schedule"
  1157. }
  1158. type MScheduleDoctorAdviceVMOne struct {
  1159. ID int64 `gorm:"column:id" json:"id"`
  1160. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1161. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1162. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1163. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1164. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1165. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1166. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1167. Status int64 `gorm:"column:status" json:"status"`
  1168. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1169. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1170. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1171. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1172. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1173. //DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1174. }
  1175. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1176. return "xt_schedule"
  1177. }
  1178. type MDoctorAdviceVM struct {
  1179. ID int64 `gorm:"column:id" json:"id"`
  1180. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1181. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1182. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1183. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1184. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1185. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1186. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1187. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1188. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1189. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1190. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1191. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1192. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1193. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1194. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1195. Status int64 `gorm:"column:status" json:"status"`
  1196. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1197. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1198. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1199. Remark string `gorm:"column:remark" json:"remark"`
  1200. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1201. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1202. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1203. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1204. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1205. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1206. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1207. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1208. Checker int64 `gorm:"column:checker" json:"checker"`
  1209. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1210. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1211. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1212. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1213. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1214. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1215. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1216. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1217. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1218. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1219. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1220. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1221. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1222. }
  1223. func (MDoctorAdviceVM) TableName() string {
  1224. return "xt_doctor_advice"
  1225. }
  1226. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1227. var vms []*MScheduleDoctorAdviceVM
  1228. adviceWhere := ""
  1229. adviceCondition := []interface{}{}
  1230. if adviceType == 0 {
  1231. if patientType == 0 {
  1232. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1234. } else if patientType == 1 {
  1235. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1237. } else if patientType == 2 {
  1238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1240. }
  1241. } else if adviceType == 1 {
  1242. if patientType == 0 {
  1243. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1245. } else if patientType == 1 {
  1246. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1248. } else if patientType == 2 {
  1249. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1251. }
  1252. } else if adviceType == 3 {
  1253. if patientType == 0 {
  1254. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1256. } else if patientType == 1 {
  1257. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1259. } else if patientType == 2 {
  1260. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1262. }
  1263. } else if adviceType == 2 && len(deliverWay) > 0 {
  1264. if patientType == 0 {
  1265. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1267. } else if patientType == 1 {
  1268. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1270. } else if patientType == 2 {
  1271. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1273. }
  1274. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1275. if patientType == 0 {
  1276. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1278. } else if patientType == 1 {
  1279. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1281. } else if patientType == 2 {
  1282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1284. }
  1285. }
  1286. db := readDb.
  1287. Table("xt_schedule").
  1288. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1289. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1290. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1291. }).
  1292. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1293. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1294. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1295. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1296. Preload("DoctorAdvices", adviceCondition...).
  1297. Where("status = 1 AND user_org_id = ?", orgID)
  1298. if scheduleDate != 0 {
  1299. db = db.Where("schedule_date = ?", scheduleDate)
  1300. }
  1301. err := db.Find(&vms).Error
  1302. return vms, err
  1303. }
  1304. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1305. var vms []*MScheduleDoctorAdviceVMOne
  1306. adviceWhere := ""
  1307. adviceCondition := []interface{}{}
  1308. if adviceType == 0 {
  1309. if patientType == 0 {
  1310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1312. } else if patientType == 1 {
  1313. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1315. } else if patientType == 2 {
  1316. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1318. }
  1319. } else if adviceType == 1 {
  1320. if patientType == 0 {
  1321. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1323. } else if patientType == 1 {
  1324. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1326. } else if patientType == 2 {
  1327. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1329. }
  1330. } else if adviceType == 3 {
  1331. if patientType == 0 {
  1332. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1334. } else if patientType == 1 {
  1335. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1337. } else if patientType == 2 {
  1338. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1340. }
  1341. } else if adviceType == 2 && len(deliverWay) > 0 {
  1342. if patientType == 0 {
  1343. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1345. } else if patientType == 1 {
  1346. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1348. } else if patientType == 2 {
  1349. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1351. }
  1352. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1353. if patientType == 0 {
  1354. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1356. } else if patientType == 1 {
  1357. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1359. } else if patientType == 2 {
  1360. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1362. }
  1363. }
  1364. db := readDb.
  1365. Table("xt_schedule").
  1366. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1367. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1368. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1369. //}).
  1370. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1371. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1372. //Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1373. Preload("DoctorAdvices", adviceCondition...).
  1374. Where("status = 1 AND user_org_id = ?", orgID)
  1375. if scheduleDate != 0 {
  1376. db = db.Where("schedule_date = ?", scheduleDate)
  1377. }
  1378. err := db.Find(&vms).Error
  1379. return vms, err
  1380. }
  1381. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1382. var vms []*HisMScheduleDoctorAdviceVM
  1383. if len(deliverWay) > 0 {
  1384. if patientType == 0 {
  1385. db := readDb.
  1386. Table("xt_schedule").
  1387. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1388. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1389. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1390. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1391. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1392. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1393. }).
  1394. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1395. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1396. Where("status = 1 AND user_org_id = ?", orgID)
  1397. if scheduleDate != 0 {
  1398. db = db.Where("schedule_date = ?", scheduleDate)
  1399. }
  1400. err = db.Find(&vms).Error
  1401. }
  1402. if patientType > 0 {
  1403. db := readDb.
  1404. Table("xt_schedule").
  1405. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1406. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1407. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1408. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1409. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1410. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1411. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1412. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1413. }).Where("status = 1 AND user_org_id = ?", orgID)
  1414. if scheduleDate != 0 {
  1415. db = db.Where("schedule_date = ?", scheduleDate)
  1416. }
  1417. err = db.Find(&vms).Error
  1418. }
  1419. } else {
  1420. if patientType == 0 {
  1421. db := readDb.
  1422. Table("xt_schedule").
  1423. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1424. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1425. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1426. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1427. }).
  1428. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1429. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1430. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1431. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1432. Where("status = 1 AND user_org_id = ?", orgID)
  1433. if scheduleDate != 0 {
  1434. db = db.Where("schedule_date = ?", scheduleDate)
  1435. }
  1436. err = db.Find(&vms).Error
  1437. }
  1438. if patientType > 0 {
  1439. db := readDb.
  1440. Table("xt_schedule").
  1441. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1442. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1443. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1444. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1445. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1446. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1447. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1448. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1449. Where("status = 1 AND user_org_id = ?", orgID)
  1450. if scheduleDate != 0 {
  1451. db = db.Where("schedule_date = ?", scheduleDate)
  1452. }
  1453. err = db.Find(&vms).Error
  1454. }
  1455. }
  1456. return vms, err
  1457. }
  1458. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1459. var vms []*HisMScheduleDoctorAdviceVMOne
  1460. if len(deliverWay) > 0 {
  1461. if patientType == 0 {
  1462. db := readDb.
  1463. Table("xt_schedule").
  1464. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1465. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1466. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1467. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1468. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1469. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1470. }).
  1471. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1472. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1473. Where("status = 1 AND user_org_id = ?", orgID)
  1474. if scheduleDate != 0 {
  1475. db = db.Where("schedule_date = ?", scheduleDate)
  1476. }
  1477. err = db.Find(&vms).Error
  1478. }
  1479. if patientType > 0 {
  1480. db := readDb.
  1481. Table("xt_schedule").
  1482. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1483. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1484. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1485. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1486. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1487. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1488. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1489. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1490. }).Where("status = 1 AND user_org_id = ?", orgID)
  1491. if scheduleDate != 0 {
  1492. db = db.Where("schedule_date = ?", scheduleDate)
  1493. }
  1494. err = db.Find(&vms).Error
  1495. }
  1496. } else {
  1497. if patientType == 0 {
  1498. db := readDb.
  1499. Table("xt_schedule").
  1500. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1501. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1502. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1503. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1504. }).
  1505. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1506. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1507. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1508. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1509. Where("status = 1 AND user_org_id = ?", orgID)
  1510. if scheduleDate != 0 {
  1511. db = db.Where("schedule_date = ?", scheduleDate)
  1512. }
  1513. err = db.Find(&vms).Error
  1514. }
  1515. if patientType > 0 {
  1516. db := readDb.
  1517. Table("xt_schedule").
  1518. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1519. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1520. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1521. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1522. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1523. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1524. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1525. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1526. Where("status = 1 AND user_org_id = ?", orgID)
  1527. if scheduleDate != 0 {
  1528. db = db.Where("schedule_date = ?", scheduleDate)
  1529. }
  1530. err = db.Find(&vms).Error
  1531. }
  1532. }
  1533. return vms, err
  1534. }
  1535. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1536. var vms []*HisMScheduleProjectVM
  1537. //if patientType == 0 {
  1538. // db := readDb.
  1539. // Table("xt_schedule").
  1540. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1541. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1542. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1543. // }).
  1544. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1545. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1546. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1547. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1548. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1549. // }).
  1550. // Where("status = 1 AND user_org_id = ?", orgID)
  1551. // if scheduleDate != 0 {
  1552. // db = db.Where("schedule_date = ?", scheduleDate)
  1553. // }
  1554. // err = db.Find(&vms).Error
  1555. //}
  1556. //if patientType > 0 {
  1557. // db := readDb.
  1558. // Table("xt_schedule").
  1559. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1560. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1561. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1562. // }).
  1563. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1564. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1565. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1566. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1567. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1568. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1569. // }).
  1570. // Where("status = 1 AND user_org_id = ?", orgID)
  1571. // if scheduleDate != 0 {
  1572. // db = db.Where("schedule_date = ?", scheduleDate)
  1573. // }
  1574. // err = db.Find(&vms).Error
  1575. //}
  1576. db := readDb.Table("xt_schedule").Where("status = 1")
  1577. if orgID > 0 {
  1578. db = db.Where("user_org_id = ?", orgID)
  1579. }
  1580. if scheduleDate > 0 {
  1581. db = db.Where("schedule_date =?", scheduleDate)
  1582. }
  1583. err = db.Find(&vms).Error
  1584. if patientType == 0 {
  1585. db := readDb.
  1586. Table("xt_schedule").
  1587. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1588. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1589. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1590. }).
  1591. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1592. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1593. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1594. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1595. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1596. }).
  1597. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1598. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1599. }).
  1600. Where("status = 1 AND user_org_id = ?", orgID)
  1601. if scheduleDate != 0 {
  1602. db = db.Where("schedule_date = ?", scheduleDate)
  1603. }
  1604. err = db.Find(&vms).Error
  1605. }
  1606. if patientType > 0 {
  1607. db := readDb.
  1608. Table("xt_schedule").
  1609. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1610. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1611. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1612. }).
  1613. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1614. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1615. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1616. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1617. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1618. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1619. }).
  1620. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1621. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1622. }).
  1623. Where("status = 1 AND user_org_id = ?", orgID)
  1624. if scheduleDate != 0 {
  1625. db = db.Where("schedule_date = ?", scheduleDate)
  1626. }
  1627. err = db.Find(&vms).Error
  1628. }
  1629. return vms, err
  1630. }
  1631. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1632. now := time.Now()
  1633. tx := writeDb.Begin()
  1634. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1635. tx.Rollback()
  1636. return createOrderErr
  1637. }
  1638. // 更新透析记录 ID
  1639. // 透析处方
  1640. 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 {
  1641. tx.Rollback()
  1642. return err
  1643. }
  1644. // 接诊评估
  1645. 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, "update_time": now.Unix()}).Error; err != nil {
  1646. tx.Rollback()
  1647. return err
  1648. }
  1649. // 透前评估
  1650. 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 {
  1651. tx.Rollback()
  1652. return err
  1653. }
  1654. // 临时医嘱
  1655. 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 {
  1656. tx.Rollback()
  1657. return err
  1658. }
  1659. // 双人核对
  1660. 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 {
  1661. tx.Rollback()
  1662. return err
  1663. }
  1664. // 透后评估
  1665. 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 {
  1666. tx.Rollback()
  1667. return err
  1668. }
  1669. // 治疗小结
  1670. 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 {
  1671. tx.Rollback()
  1672. return err
  1673. }
  1674. // 透析监测
  1675. 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 {
  1676. tx.Rollback()
  1677. return err
  1678. }
  1679. tx.Commit()
  1680. return nil
  1681. }
  1682. type MobileUrgentSchedulePatientVM struct {
  1683. ID int64 `gorm:"column:id" json:"id"`
  1684. Name string `gorm:"column:name" json:"name"`
  1685. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1686. }
  1687. func (MobileUrgentSchedulePatientVM) TableName() string {
  1688. return "xt_patients"
  1689. }
  1690. type MobileUrgentScheduleTreatmentModeVM struct {
  1691. ID int64 `gorm:"column:id" json:"id"`
  1692. Name string `gorm:"column:name" json:"name"`
  1693. }
  1694. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1695. return "xt_treatment_mode"
  1696. }
  1697. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1698. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1699. 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()
  1700. defer rows.Close()
  1701. if err != nil {
  1702. return nil, err
  1703. }
  1704. for rows.Next() {
  1705. var vm MobileUrgentSchedulePatientVM
  1706. readDb.ScanRows(rows, &vm)
  1707. vms = append(vms, &vm)
  1708. }
  1709. return vms, nil
  1710. }
  1711. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1712. var modes []*MobileUrgentScheduleTreatmentModeVM
  1713. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1714. if err != nil {
  1715. return nil, err
  1716. }
  1717. return modes, nil
  1718. }
  1719. type MobileUrgentScheduleScheduleListVM struct {
  1720. ID int64 `gorm:"column:id" json:"id"`
  1721. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1722. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1723. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1724. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1725. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1726. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1727. }
  1728. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1729. return "xt_schedule"
  1730. }
  1731. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1732. db := readDb.
  1733. Model(&MobileUrgentScheduleScheduleListVM{}).
  1734. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1735. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1736. err = db.Find(&schedules).Error
  1737. if err != nil {
  1738. return nil, err
  1739. }
  1740. return schedules, nil
  1741. }
  1742. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1743. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1744. 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()
  1745. defer rows.Close()
  1746. if err != nil {
  1747. return nil, err
  1748. }
  1749. for rows.Next() {
  1750. var vm MobileUrgentScheduleScheduleListVM
  1751. readDb.ScanRows(rows, &vm)
  1752. vms = append(vms, &vm)
  1753. }
  1754. return vms, nil
  1755. }
  1756. type MobileUrgentScheduleDeviceNumberVM struct {
  1757. ID int64 `gorm:"column:id" json:"id"`
  1758. Number string `gorm:"column:number" json:"number"`
  1759. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1760. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1761. }
  1762. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1763. return "xt_device_number"
  1764. }
  1765. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1766. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1767. 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()
  1768. defer rows.Close()
  1769. if err != nil {
  1770. return nil, err
  1771. }
  1772. for rows.Next() {
  1773. var vm DeviceNumberViewModel
  1774. readDb.ScanRows(rows, &vm)
  1775. vms = append(vms, &vm)
  1776. }
  1777. return vms, nil
  1778. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1779. //db := readDb.
  1780. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1781. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1782. // Where("status = 1 AND org_id = ?", orgID)
  1783. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1784. //if err != nil {
  1785. // return nil, err
  1786. //}
  1787. //return deviceNumbers, nil
  1788. }
  1789. func GetValidScheduleMonitorRecordCount() (int64, error) {
  1790. var total int64
  1791. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  1792. return total, err
  1793. }
  1794. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  1795. var monitors []*models.MonitoringRecord
  1796. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  1797. if err != nil {
  1798. return nil, err
  1799. }
  1800. return monitors, nil
  1801. }
  1802. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  1803. tx := writeDb.Begin()
  1804. for index := 0; index < len(monitors); index++ {
  1805. tx.Save(monitors[index])
  1806. }
  1807. return tx.Commit().Error
  1808. }
  1809. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  1810. tx := writeDb.Begin()
  1811. updateTime := time.Now().Unix()
  1812. 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, "washpipe_nurse": order.WashpipeNurse, "change_nurse": order.ChangeNurse, "difficult_puncture_nurse": order.DifficultPunctureNurse, "new_fistula_nurse": order.NewFistulaNurse}).Error
  1813. if err != nil {
  1814. tx.Rollback()
  1815. return err
  1816. }
  1817. tx.Commit()
  1818. return err
  1819. }
  1820. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  1821. tx := writeDb.Begin()
  1822. updateTime := time.Now().Unix()
  1823. 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, "puncture_point_haematoma": order.PuncturePointHaematoma, "blood_access_internal_fistula": order.BloodAccessInternalFistula, "catheter": order.Catheter, "cruor": order.Cruor}).Error
  1824. if err != nil {
  1825. tx.Rollback()
  1826. return err
  1827. }
  1828. tx.Commit()
  1829. return err
  1830. }
  1831. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  1832. var record models.SgjPatientDryweight
  1833. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1834. if err != nil {
  1835. if err == gorm.ErrRecordNotFound {
  1836. return nil, nil
  1837. } else {
  1838. return nil, err
  1839. }
  1840. }
  1841. return &record, nil
  1842. }
  1843. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  1844. // var record models.SgjPatientDryweight
  1845. // redis := RedisClient()
  1846. // defer redis.Close()
  1847. //
  1848. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  1849. // last_dry_weight_str, _ := redis.Get(key).Result()
  1850. //
  1851. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1852. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1853. // if err != nil {
  1854. // if err == gorm.ErrRecordNotFound {
  1855. // if record.ID <= 0 {
  1856. // redis.Set(key, "null", time.Second*60*60*18)
  1857. // }
  1858. // return nil, nil
  1859. // } else {
  1860. // return nil, err
  1861. // }
  1862. // } else {
  1863. // if record.ID > 0 {
  1864. // //缓存数据
  1865. // last_dry_weight_str, err := json.Marshal(record)
  1866. // if err == nil {
  1867. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  1868. // return nil, err
  1869. // }
  1870. // } else {
  1871. // redis.Set(key, "null", time.Second*60*60*18)
  1872. // return nil, err
  1873. // }
  1874. // return &record, nil
  1875. // }
  1876. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1877. // if last_dry_weight_str == "null" {
  1878. // return &record, nil
  1879. // } else {
  1880. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  1881. // return &record, nil
  1882. // }
  1883. //
  1884. // }
  1885. //}
  1886. // 透析方案
  1887. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1888. var record models.DialysisSolution
  1889. 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
  1890. if err != nil {
  1891. if err == gorm.ErrRecordNotFound {
  1892. return nil, nil
  1893. } else {
  1894. return nil, err
  1895. }
  1896. }
  1897. return &record, nil
  1898. }
  1899. // 透析方案
  1900. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1901. var record models.DialysisSolution
  1902. redis := RedisClient()
  1903. defer redis.Close()
  1904. // cur_date := time.Now().Format("2006-01-02")
  1905. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1906. dialysis_solution_str, _ := redis.Get(key).Result()
  1907. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1908. 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
  1909. if err != nil {
  1910. if err == gorm.ErrRecordNotFound {
  1911. if record.ID <= 0 {
  1912. redis.Set(key, "null", time.Second*60*60*18)
  1913. }
  1914. return nil, nil
  1915. } else {
  1916. return nil, err
  1917. }
  1918. } else {
  1919. if record.ID > 0 {
  1920. //缓存数据
  1921. dialysis_solution_str, err := json.Marshal(record)
  1922. if err == nil {
  1923. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  1924. }
  1925. } else {
  1926. redis.Set(key, "null", time.Second*60*60*18)
  1927. }
  1928. return &record, nil
  1929. }
  1930. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1931. if dialysis_solution_str == "null" {
  1932. return &record, nil
  1933. } else {
  1934. json.Unmarshal([]byte(dialysis_solution_str), &record)
  1935. return &record, nil
  1936. }
  1937. }
  1938. }
  1939. // 透析处方
  1940. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  1941. var record models.DialysisPrescription
  1942. redis := RedisClient()
  1943. defer redis.Close()
  1944. // cur_date := time.Now().Format("2006-01-02")
  1945. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1946. dialysis_prescribe_str, _ := redis.Get(key).Result()
  1947. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1948. 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
  1949. if err != nil {
  1950. if err == gorm.ErrRecordNotFound {
  1951. if record.ID <= 0 {
  1952. redis.Set(key, "null", time.Second*60*60*18)
  1953. }
  1954. return nil, nil
  1955. } else {
  1956. return nil, err
  1957. }
  1958. } else {
  1959. if record.ID > 0 {
  1960. //缓存数据
  1961. dialysis_prescribe_str, err := json.Marshal(record)
  1962. if err == nil {
  1963. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  1964. }
  1965. } else {
  1966. redis.Set(key, "null", time.Second*60*60*18)
  1967. }
  1968. return &record, nil
  1969. }
  1970. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1971. if dialysis_prescribe_str == "null" {
  1972. return &record, nil
  1973. } else {
  1974. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  1975. return &record, nil
  1976. }
  1977. }
  1978. }
  1979. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  1980. var record models.DialysisPrescription
  1981. 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
  1982. if err != nil {
  1983. if err == gorm.ErrRecordNotFound {
  1984. return nil, nil
  1985. } else {
  1986. return nil, err
  1987. }
  1988. }
  1989. return &record, nil
  1990. }
  1991. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1992. var record models.DialysisPrescription
  1993. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1994. if err != nil {
  1995. if err == gorm.ErrRecordNotFound {
  1996. return nil, nil
  1997. } else {
  1998. return nil, err
  1999. }
  2000. }
  2001. return &record, nil
  2002. }
  2003. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2004. // var record models.DialysisPrescription
  2005. // redis := RedisClient()
  2006. // defer redis.Close()
  2007. //
  2008. // // cur_date := time.Now().Format("2006-01-02")
  2009. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2010. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2011. //
  2012. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2013. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2014. // if err != nil {
  2015. // if err == gorm.ErrRecordNotFound {
  2016. // if record.ID <= 0 {
  2017. // redis.Set(key, "null", time.Second*60*60*18)
  2018. // }
  2019. // return nil, nil
  2020. // } else {
  2021. // return nil, err
  2022. // }
  2023. // } else {
  2024. //
  2025. // if record.ID > 0 {
  2026. // //缓存数据
  2027. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2028. //
  2029. // if err == nil {
  2030. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2031. // return nil, err
  2032. // }
  2033. // } else {
  2034. // redis.Set(key, "null", time.Second*60*60*18)
  2035. // return nil, err
  2036. // }
  2037. // return &record, nil
  2038. // }
  2039. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2040. // if dialysis_prescribe_by_mode_str == "null" {
  2041. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2042. // return &record, nil
  2043. // } else {
  2044. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2045. // return &record, nil
  2046. // }
  2047. //
  2048. // }
  2049. //}
  2050. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2051. var record models.DialysisPrescription
  2052. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2053. if err != nil {
  2054. if err == gorm.ErrRecordNotFound {
  2055. return nil, nil
  2056. } else {
  2057. return nil, err
  2058. }
  2059. }
  2060. return &record, nil
  2061. }
  2062. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2063. var record models.DialysisPrescription
  2064. 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
  2065. if err != nil {
  2066. if err == gorm.ErrRecordNotFound {
  2067. return nil, nil
  2068. } else {
  2069. return nil, err
  2070. }
  2071. }
  2072. return &record, nil
  2073. }
  2074. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2075. var record models.DialysisPrescription
  2076. redis := RedisClient()
  2077. defer redis.Close()
  2078. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2079. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2080. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2081. 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
  2082. if err != nil {
  2083. if err == gorm.ErrRecordNotFound {
  2084. if record.ID <= 0 {
  2085. redis.Set(key, "null", time.Second*60*60*18)
  2086. }
  2087. return nil, nil
  2088. } else {
  2089. return nil, err
  2090. }
  2091. } else {
  2092. if record.ID > 0 {
  2093. //缓存数据
  2094. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2095. if err == nil {
  2096. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2097. return nil, err
  2098. }
  2099. } else {
  2100. redis.Set(key, "null", time.Second*60*60*18)
  2101. return nil, err
  2102. }
  2103. return &record, nil
  2104. }
  2105. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2106. if dialysis_prescribe_by_mode_id == "null" {
  2107. return &record, nil
  2108. } else {
  2109. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2110. return &record, nil
  2111. }
  2112. }
  2113. }
  2114. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2115. var record models.DialysisPrescription
  2116. 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
  2117. return record, err
  2118. }
  2119. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2120. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2121. 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()
  2122. defer rows.Close()
  2123. if err != nil {
  2124. return nil, err
  2125. }
  2126. for rows.Next() {
  2127. var vm DeviceNumberViewModel
  2128. readDb.ScanRows(rows, &vm)
  2129. vms = append(vms, &vm)
  2130. }
  2131. return vms, nil
  2132. }
  2133. // 获取 maxDate 之前一次的透前评估记录
  2134. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2135. var record models.PredialysisEvaluation
  2136. 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
  2137. if err != nil {
  2138. if err == gorm.ErrRecordNotFound {
  2139. return nil, nil
  2140. } else {
  2141. return nil, err
  2142. }
  2143. }
  2144. return &record, nil
  2145. }
  2146. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2147. var record models.DialysisOrder
  2148. err := readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? and user_org_id = ? and status = 1 and dialysis_date < ?", patientID, orgID, maxDate).Order("dialysis_date desc").First(&record).Error
  2149. if err != nil {
  2150. if err == gorm.ErrRecordNotFound {
  2151. return nil, nil
  2152. } else {
  2153. return nil, err
  2154. }
  2155. }
  2156. return &record, nil
  2157. }
  2158. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2159. var record models.MonitoringRecord
  2160. 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
  2161. if err != nil {
  2162. if err == gorm.ErrRecordNotFound {
  2163. return nil, nil
  2164. } else {
  2165. return nil, err
  2166. }
  2167. }
  2168. return &record, nil
  2169. }
  2170. // 获取 maxDate 之前一次的透后评估记录
  2171. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2172. var record models.AssessmentAfterDislysis
  2173. 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
  2174. if err != nil {
  2175. if err == gorm.ErrRecordNotFound {
  2176. return nil, nil
  2177. } else {
  2178. return nil, err
  2179. }
  2180. }
  2181. return &record, nil
  2182. }
  2183. // 透析处方
  2184. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2185. var record models.DialysisPrescription
  2186. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2187. if err != nil {
  2188. if err == gorm.ErrRecordNotFound {
  2189. return nil, nil
  2190. } else {
  2191. return nil, err
  2192. }
  2193. }
  2194. return &record, nil
  2195. }
  2196. // 透析方案
  2197. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2198. var record models.DialysisSolution
  2199. 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
  2200. if err != nil {
  2201. if err == gorm.ErrRecordNotFound {
  2202. return nil, nil
  2203. } else {
  2204. return nil, err
  2205. }
  2206. }
  2207. return &record, nil
  2208. }
  2209. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2210. var record models.DialysisSolution
  2211. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2212. if err != nil {
  2213. if err == gorm.ErrRecordNotFound {
  2214. return nil, nil
  2215. } else {
  2216. return nil, err
  2217. }
  2218. }
  2219. return &record, nil
  2220. }
  2221. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2222. var record models.DialysisPrescription
  2223. 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
  2224. if err != nil {
  2225. if err == gorm.ErrRecordNotFound {
  2226. return nil, nil
  2227. } else {
  2228. return nil, err
  2229. }
  2230. }
  2231. return &record, nil
  2232. }
  2233. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2234. var record models.SgjPatientDryweight
  2235. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2236. if err != nil {
  2237. if err == gorm.ErrRecordNotFound {
  2238. return nil, nil
  2239. } else {
  2240. return nil, err
  2241. }
  2242. }
  2243. return &record, nil
  2244. }
  2245. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2246. var record models.SystemPrescription
  2247. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2248. if err != nil {
  2249. if err == gorm.ErrRecordNotFound {
  2250. return nil, nil
  2251. } else {
  2252. return nil, err
  2253. }
  2254. }
  2255. return &record, nil
  2256. }
  2257. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2258. var record models.SystemPrescription
  2259. redis := RedisClient()
  2260. defer redis.Close()
  2261. // cur_date := time.Now().Format("2006-01-02")
  2262. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2263. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2264. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2265. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2266. if err != nil {
  2267. if err == gorm.ErrRecordNotFound {
  2268. if record.ID <= 0 {
  2269. redis.Set(key, "null", time.Second*60*60*18)
  2270. }
  2271. return nil, nil
  2272. } else {
  2273. return nil, err
  2274. }
  2275. } else {
  2276. if record.ID > 0 {
  2277. //缓存数据
  2278. system_dialysis_prescribe_str, err := json.Marshal(record)
  2279. if err == nil {
  2280. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2281. }
  2282. } else {
  2283. redis.Set(key, "null", time.Second*60*60*18)
  2284. }
  2285. return &record, nil
  2286. }
  2287. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2288. if system_dialysis_prescribe_str == "null" {
  2289. return &record, nil
  2290. } else {
  2291. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2292. return &record, nil
  2293. }
  2294. }
  2295. }
  2296. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2297. var record models.SystemPrescription
  2298. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2299. return record, err
  2300. }
  2301. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2302. var record models.SystemPrescription
  2303. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2304. if err != nil {
  2305. if err == gorm.ErrRecordNotFound {
  2306. return nil, nil
  2307. } else {
  2308. return nil, err
  2309. }
  2310. }
  2311. return &record, nil
  2312. }
  2313. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2314. 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
  2315. return
  2316. }
  2317. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2318. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1640966400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2319. return
  2320. }
  2321. func GetFirstDateOfMonth(d time.Time) time.Time {
  2322. d = d.AddDate(0, 0, -d.Day()+1)
  2323. return GetZeroTime(d)
  2324. }
  2325. func GetZeroTime(d time.Time) time.Time {
  2326. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2327. }
  2328. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2329. db := XTReadDB().Table("xt_dialysis_order as o")
  2330. 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
  2331. return order, err
  2332. }
  2333. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2334. 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
  2335. return
  2336. }
  2337. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2338. 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
  2339. return
  2340. }
  2341. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2342. err = readDb.Model(&models.BloodAutomaticReduceDetail{}).Where("org_id = ? AND patient_id = ? AND record_time = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
  2343. return
  2344. }
  2345. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2346. // 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
  2347. // return
  2348. //}
  2349. //
  2350. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2351. 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
  2352. return
  2353. }
  2354. type GoodsType struct {
  2355. ID int64 `gorm:"column:id" json:"id"`
  2356. TypeName string `gorm:"column:type_name" json:"type_name"`
  2357. Remark string `gorm:"column:remark" json:"remark"`
  2358. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2359. Status int64 `gorm:"column:status" json:"status"`
  2360. Type int64 `gorm:"column:type" json:"type"`
  2361. }
  2362. func (GoodsType) TableName() string {
  2363. return "xt_goods_type"
  2364. }
  2365. type VMGoodInfo struct {
  2366. ID int64 `gorm:"column:id" json:"id"`
  2367. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2368. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2369. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2370. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2371. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2372. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2373. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2374. }
  2375. func (VMGoodInfo) TableName() string {
  2376. return "xt_good_information"
  2377. }
  2378. type AutomaticReduceDetail struct {
  2379. ID int64 `gorm:"column:id" json:"id"`
  2380. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2381. Status int64 `gorm:"column:status" json:"status"`
  2382. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2383. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2384. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2385. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2386. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2387. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2388. Count int64 `gorm:"column:count" json:"count"`
  2389. }
  2390. func (AutomaticReduceDetail) TableName() string {
  2391. return "xt_automatic_reduce_detail"
  2392. }
  2393. type DialysisBeforePrepare struct {
  2394. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2395. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2396. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2397. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2398. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2399. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2400. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2401. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2402. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2403. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2404. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2405. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2406. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2407. }
  2408. func (DialysisBeforePrepare) TableName() string {
  2409. return "dialysis_before_prepare"
  2410. }
  2411. type MDialysisGoodsVM struct {
  2412. ID int64 `gorm:"column:id" json:"id"`
  2413. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2414. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2415. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2416. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2417. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2418. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2419. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2420. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2421. Status int64 `gorm:"column:status" json:"status"`
  2422. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2423. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2424. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2425. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2426. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2427. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2428. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2429. }
  2430. func (MDialysisGoodsVM) TableName() string {
  2431. return "xt_schedule"
  2432. }
  2433. type VMWarehouseOutInfo struct {
  2434. ID int64 `gorm:"column:id" json:"id"`
  2435. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2436. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2437. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2438. Count int64 `gorm:"column:count" json:"count"`
  2439. Price float64 `gorm:"column:price" json:"price"`
  2440. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2441. Status int64 `gorm:"column:status" json:"status"`
  2442. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2443. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2444. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2445. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2446. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2447. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2448. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2449. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2450. }
  2451. func (VMWarehouseOutInfo) TableName() string {
  2452. return "xt_warehouse_out_info"
  2453. }
  2454. type DialysisGoodsDate struct {
  2455. RecordDate int64
  2456. }
  2457. type DialysisGoodsDetailDate struct {
  2458. RecordTime int64
  2459. }
  2460. 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) {
  2461. var vms []*MDialysisGoodsVM
  2462. var total int64
  2463. db := readDb.
  2464. Table("xt_schedule as sch").
  2465. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2466. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2467. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2468. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2469. 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)
  2470. }).
  2471. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2472. 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).Group("patient_id,good_id")
  2473. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2474. if scheduleDate != 0 {
  2475. db = db.Where("schedule_date = ?", scheduleDate)
  2476. }
  2477. if schedule_type != 0 {
  2478. db = db.Where("schedule_type = ?", schedule_type)
  2479. }
  2480. if partition_id != 0 {
  2481. db = db.Where("partition_id = ?", partition_id)
  2482. }
  2483. if patient_id != 0 {
  2484. db = db.Where("patient_id = ?", patient_id)
  2485. }
  2486. //db = db.Count(&total)
  2487. //offset := (page - 1) * limit
  2488. //
  2489. //db = db.Offset(offset).Limit(limit)
  2490. err := db.Find(&vms).Error
  2491. return vms, err, total
  2492. }
  2493. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2494. var Id []*DialysisGoodsDetailDate
  2495. 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
  2496. if len(Id) > 0 {
  2497. 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
  2498. }
  2499. return
  2500. }
  2501. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2502. var Id []*DialysisGoodsDate
  2503. 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
  2504. if len(Id) > 0 {
  2505. 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
  2506. }
  2507. return
  2508. }
  2509. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2510. db := readDb.Model(&models.StockInfo{})
  2511. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2512. 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")
  2513. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2514. 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)
  2515. })
  2516. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2517. err = db.Order("ctime desc").Find(&list).Error
  2518. return
  2519. }
  2520. 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) {
  2521. var vms []*MDialysisGoodsVM
  2522. var total int64
  2523. db := readDb.
  2524. Model(&models.Schedule{}).
  2525. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2526. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2527. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2528. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2529. 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)
  2530. }).
  2531. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2532. 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)
  2533. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2534. if scheduleDate != 0 {
  2535. db = db.Where("schedule_date = ?", scheduleDate)
  2536. }
  2537. if patient_id != 0 {
  2538. db = db.Where("patient_id = ?", patient_id)
  2539. }
  2540. if len(keywords) != 0 {
  2541. keywords = "%" + keywords + "%"
  2542. 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)
  2543. } else {
  2544. if schedule_type != 0 {
  2545. db = db.Where("schedule_type = ?", schedule_type)
  2546. }
  2547. if partition_id != 0 {
  2548. db = db.Where("partition_id = ?", partition_id)
  2549. }
  2550. db = db.Count(&total)
  2551. offset := (page - 1) * limit
  2552. db = db.Offset(offset).Limit(limit)
  2553. }
  2554. err := db.Find(&vms).Error
  2555. return vms, err, total
  2556. }
  2557. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2558. var Id []*DialysisGoodsDetailDate
  2559. 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
  2560. if len(Id) > 0 {
  2561. 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
  2562. }
  2563. return
  2564. }
  2565. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2566. var Id []*DialysisGoodsDate
  2567. 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
  2568. if len(Id) > 0 {
  2569. 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
  2570. }
  2571. return
  2572. }
  2573. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2574. evaluation := models.PredialysisEvaluation{}
  2575. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2576. if err == gorm.ErrRecordNotFound {
  2577. return nil, err
  2578. }
  2579. if err != nil {
  2580. return nil, err
  2581. }
  2582. return &evaluation, nil
  2583. }
  2584. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2585. redis := RedisClient()
  2586. defer redis.Close()
  2587. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2588. his_doctor_advice_str, _ := redis.Get(key).Result()
  2589. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2590. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
  2591. if err != nil {
  2592. if err == gorm.ErrRecordNotFound {
  2593. if len(his) <= 0 {
  2594. redis.Set(key, "null", time.Second*60*60*18)
  2595. }
  2596. return his, nil
  2597. } else {
  2598. return his, err
  2599. }
  2600. } else {
  2601. if len(his) > 0 {
  2602. //缓存数据
  2603. his_doctor_advice_str, err := json.Marshal(his)
  2604. if err == nil {
  2605. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2606. }
  2607. } else {
  2608. redis.Set(key, "null", time.Second*60*60*18)
  2609. }
  2610. return his, nil
  2611. }
  2612. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2613. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2614. return his, nil
  2615. }
  2616. }
  2617. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2618. prescription := models.DialysisPrescription{}
  2619. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2620. if err == gorm.ErrRecordNotFound {
  2621. return nil, err
  2622. }
  2623. if err != nil {
  2624. return nil, err
  2625. }
  2626. return &prescription, nil
  2627. }
  2628. type HisMScheduleDoctorAdviceVM struct {
  2629. ID int64 `gorm:"column:id" json:"id"`
  2630. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2631. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2632. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2633. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2634. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2635. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2636. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2637. Status int64 `gorm:"column:status" json:"status"`
  2638. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2639. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2640. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2641. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2642. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2643. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2644. }
  2645. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2646. return "xt_schedule"
  2647. }
  2648. type HisMScheduleDoctorAdviceVMOne struct {
  2649. ID int64 `gorm:"column:id" json:"id"`
  2650. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2651. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2652. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2653. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2654. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2655. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2656. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2657. Status int64 `gorm:"column:status" json:"status"`
  2658. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2659. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2660. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2661. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2662. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2663. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2664. }
  2665. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2666. return "xt_schedule"
  2667. }
  2668. type HisMScheduleProjectVM struct {
  2669. ID int64 `gorm:"column:id" json:"id"`
  2670. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2671. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2672. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2673. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2674. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2675. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2676. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2677. Status int64 `gorm:"column:status" json:"status"`
  2678. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2679. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2680. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2681. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2682. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2683. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2684. }
  2685. func (HisMScheduleProjectVM) TableName() string {
  2686. return "xt_schedule"
  2687. }
  2688. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2689. config := models.XtHisConfig{}
  2690. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2691. return config, err
  2692. }
  2693. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2694. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2695. if orgid > 0 {
  2696. db = db.Where("x.user_org_id = ?", orgid)
  2697. }
  2698. if patientid > 0 {
  2699. db = db.Where("x.patient_id =?", patientid)
  2700. }
  2701. if recordtime > 0 {
  2702. db = db.Where("x.advice_date = ?", recordtime)
  2703. }
  2704. err = db.Select("x.id,x.user_org_id,x.patient_id,x.his_patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,x.single_dose,x.single_dose_unit,x.single_dose_unit,x.prescribing_number_unit,x.prescribing_number,x.delivery_way,x.execution_frequency,x.advice_doctor,x.status,x.advice_affirm,x.remark,x.stop_time,x.stop_reason,x.stop_doctor,x.stop_state,x.parent_id,x.execution_time,x.execution_staff,x.checker,x.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,x.drug_id,x.price,x.prescription_id,x.med_list_codg,x.feedetl_sn,x.day").Find(&advice).Error
  2705. return advice, err
  2706. }
  2707. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2708. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2709. if startime > 0 {
  2710. db = db.Where("x.advice_date >= ?", startime)
  2711. }
  2712. if endtime > 0 {
  2713. db = db.Where("x.advice_date<=?", endtime)
  2714. }
  2715. if orgid > 0 {
  2716. db = db.Where("x.user_org_id = ?", orgid)
  2717. }
  2718. if len(deliveway) > 0 {
  2719. db = db.Where("x.delivery_way = ?", deliveway)
  2720. }
  2721. err = db.Select("x.advice_name,x.advice_desc,x.delivery_way,count(x.id) as total").Group("x.advice_name,x.advice_desc").Scan(&advice).Error
  2722. return advice, err
  2723. }
  2724. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2725. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2726. if startime > 0 {
  2727. db = db.Where("x.advice_date >= ?", startime)
  2728. }
  2729. if endtime > 0 {
  2730. db = db.Where("x.advice_date<=?", endtime)
  2731. }
  2732. if orgid > 0 {
  2733. db = db.Where("x.user_org_id = ?", orgid)
  2734. }
  2735. if len(deliveway) > 0 {
  2736. db = db.Where("x.delivery_way = ?", deliveway)
  2737. }
  2738. err = db.Select("x.advice_name,x.advice_desc,x.delivery_way,count(x.id) as total").Group("x.advice_name,x.advice_desc").Scan(&advice).Error
  2739. return advice, err
  2740. }
  2741. func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64) ([]*MScheduleDoctorAdviceVM, error) {
  2742. var vms []*MScheduleDoctorAdviceVM
  2743. adviceWhere := ""
  2744. adviceCondition := []interface{}{}
  2745. if adviceType == 0 {
  2746. if patientType == 0 {
  2747. if patient_id > 0 {
  2748. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2750. } else {
  2751. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  2752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2753. }
  2754. } else if patientType == 1 {
  2755. if patient_id > 0 {
  2756. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2758. } else {
  2759. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  2760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2761. }
  2762. } else if patientType == 2 {
  2763. if patient_id > 0 {
  2764. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
  2765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2766. } else {
  2767. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  2768. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2769. }
  2770. }
  2771. } else if adviceType == 1 {
  2772. if patientType == 0 {
  2773. if patient_id > 0 {
  2774. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  2775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2776. } else {
  2777. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  2778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2779. }
  2780. } else if patientType == 1 {
  2781. if patient_id > 0 {
  2782. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  2783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2784. } else {
  2785. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  2786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2787. }
  2788. } else if patientType == 2 {
  2789. if patient_id > 0 {
  2790. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  2791. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2792. } else {
  2793. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  2794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2795. }
  2796. }
  2797. } else if adviceType == 3 {
  2798. if patientType == 0 {
  2799. if patient_id > 0 {
  2800. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  2801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2802. } else {
  2803. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  2804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2805. }
  2806. } else if patientType == 1 {
  2807. if patient_id > 0 {
  2808. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  2809. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2810. } else {
  2811. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  2812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2813. }
  2814. } else if patientType == 2 {
  2815. if patient_id > 0 {
  2816. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  2817. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2818. } else {
  2819. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  2820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2821. }
  2822. }
  2823. } else if adviceType == 2 && len(deliverWay) > 0 {
  2824. if patientType == 0 {
  2825. if patient_id > 0 {
  2826. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  2827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  2828. } else {
  2829. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  2830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2831. }
  2832. } else if patientType == 1 {
  2833. if patient_id > 0 {
  2834. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  2835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  2836. } else {
  2837. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  2838. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  2839. }
  2840. } else if patientType == 2 {
  2841. if patient_id > 0 {
  2842. } else {
  2843. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  2844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2845. }
  2846. }
  2847. } else if adviceType == 2 && len(deliverWay) <= 0 {
  2848. if patientType == 0 {
  2849. if patient_id > 0 {
  2850. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  2851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2852. } else {
  2853. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  2854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2855. }
  2856. } else if patientType == 1 {
  2857. if patient_id > 0 {
  2858. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  2859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2860. } else {
  2861. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  2862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2863. }
  2864. } else if patientType == 2 {
  2865. if patient_id > 0 {
  2866. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  2867. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2868. } else {
  2869. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  2870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2871. }
  2872. }
  2873. }
  2874. db := readDb.Table("xt_schedule")
  2875. if scheduleType > 0 {
  2876. db = db.Where("schedule_type = ?", scheduleType)
  2877. }
  2878. if partitonType > 0 {
  2879. db = db.Where("partition_id = ?", partitonType)
  2880. }
  2881. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2882. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2883. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2884. }).
  2885. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2886. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2887. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2888. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  2889. Preload("DoctorAdvices", adviceCondition...).
  2890. Where("status = 1 AND user_org_id = ?", orgID)
  2891. if scheduleDate != 0 {
  2892. db = db.Where("schedule_date = ?", scheduleDate)
  2893. }
  2894. err := db.Find(&vms).Error
  2895. return vms, err
  2896. }
  2897. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  2898. var vms []*HisMScheduleDoctorAdviceVM
  2899. if len(deliverWay) > 0 {
  2900. db := readDb.Table("xt_schedule")
  2901. if scheduleType > 0 {
  2902. db = db.Where("schedule_type = ?", scheduleType)
  2903. }
  2904. if partitionType > 0 {
  2905. db = db.Where("partition_id = ?", partitionType)
  2906. }
  2907. if patient_id > 0 {
  2908. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  2909. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2910. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2911. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  2912. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  2913. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2914. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2915. }).
  2916. Where("status = 1 AND user_org_id = ?", orgID)
  2917. if scheduleDate != 0 {
  2918. db = db.Where("schedule_date = ?", scheduleDate)
  2919. }
  2920. err = db.Find(&vms).Error
  2921. } else {
  2922. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2923. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2924. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2925. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2926. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  2927. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2928. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2929. }).
  2930. Where("status = 1 AND user_org_id = ?", orgID)
  2931. if scheduleDate != 0 {
  2932. db = db.Where("schedule_date = ?", scheduleDate)
  2933. }
  2934. err = db.Find(&vms).Error
  2935. }
  2936. } else {
  2937. db := readDb.Table("xt_schedule")
  2938. if scheduleType > 0 {
  2939. db = db.Where("schedule_type = ?", scheduleType)
  2940. }
  2941. if partitionType > 0 {
  2942. db = db.Where("partition_id = ?", partitionType)
  2943. }
  2944. if patient_id > 0 {
  2945. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  2946. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2947. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2948. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  2949. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  2950. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2951. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2952. }).
  2953. Where("status = 1 AND user_org_id = ?", orgID)
  2954. if scheduleDate != 0 {
  2955. db = db.Where("schedule_date = ?", scheduleDate)
  2956. }
  2957. err = db.Find(&vms).Error
  2958. } else {
  2959. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2960. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2961. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2962. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2963. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  2964. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2965. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2966. }).
  2967. Where("status = 1 AND user_org_id = ?", orgID)
  2968. if scheduleDate != 0 {
  2969. db = db.Where("schedule_date = ?", scheduleDate)
  2970. }
  2971. err = db.Find(&vms).Error
  2972. }
  2973. }
  2974. return vms, err
  2975. }
  2976. func BatchDeleteMonitor(ids []string) (err error) {
  2977. if len(ids) == 1 {
  2978. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2979. } else {
  2980. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2981. }
  2982. return
  2983. }
  2984. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  2985. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  2986. //table := XTReadDB().Table("xt_schedule as s")
  2987. //fmt.Println(table)
  2988. if patientid > 0 {
  2989. db = db.Where("x.patient_id = ?", patientid)
  2990. }
  2991. if startime > 0 {
  2992. db = db.Where("x.dialysis_date>=?", startime)
  2993. }
  2994. if endtime > 0 {
  2995. db = db.Where("x.dialysis_date <= ?", endtime)
  2996. }
  2997. err = db.Select("x.id,x.dialysis_date,x.schedual_type,s.mode_id").Joins("left join xt_schedule as s on x.patient_id = s.patient_id and x.dialysis_date = s.schedule_date ").Scan(&order).Error
  2998. return order, err
  2999. }
  3000. func BatchDeleteAdvice(ids []string) (err error) {
  3001. if len(ids) == 1 {
  3002. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3003. } else {
  3004. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3005. }
  3006. return
  3007. }
  3008. func BatchDeleteHisAdvice(ids []string) (err error) {
  3009. if len(ids) == 1 {
  3010. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3011. } else {
  3012. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3013. }
  3014. return
  3015. }
  3016. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3017. detail := models.AutomaticReduceDetail{}
  3018. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_time = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3019. return detail, err
  3020. }
  3021. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3022. detail := models.AutomaticReduceDetail{}
  3023. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_time = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"status": 0}).Error
  3024. return err
  3025. }
  3026. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3027. detail := models.DialysisBeforePrepare{}
  3028. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_date = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"status": 0}).Error
  3029. return err
  3030. }
  3031. func BatchAdviceCheck(ids []string, creator int64) error {
  3032. advice := models.XtDoctorAdvice{}
  3033. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"check_state": 1, "checker": creator, "check_time": time.Now().Unix()}).Error
  3034. return err
  3035. }
  3036. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3037. advice := models.HisDoctorAdviceInfo{}
  3038. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"check_state": 1, "checker": creator, "check_time": time.Now().Unix()}).Error
  3039. return err
  3040. }
  3041. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3042. advice := models.XtDoctorAdvice{}
  3043. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"execution_state": 1, "execution_staff": creator, "execution_time": execution_state}).Error
  3044. return err
  3045. }
  3046. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3047. advice := models.HisDoctorAdviceInfo{}
  3048. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"execution_state": 1, "execution_staff": creator, "execution_time": execution_state}).Error
  3049. return err
  3050. }
  3051. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3052. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3053. return doctor, err
  3054. }
  3055. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3056. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3057. return doctor, err
  3058. }
  3059. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3060. config := models.XtHisProjectConfig{}
  3061. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3062. return config, err
  3063. }
  3064. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3065. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3066. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3067. }).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND type = 3", org_id, record_date, patient_id).Find(&project).Error
  3068. return
  3069. }
  3070. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64) ([]*HisMScheduleProjectVM, error) {
  3071. var vms []*HisMScheduleProjectVM
  3072. if patientType == 0 {
  3073. if patient_id > 0 {
  3074. db := readDb.
  3075. Table("xt_schedule").
  3076. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3077. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3078. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3079. }).
  3080. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3081. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3082. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3083. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3084. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3085. }).
  3086. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3087. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3088. }).Where("status = 1 AND user_org_id = ?", orgID)
  3089. if scheduleDate != 0 {
  3090. db = db.Where("schedule_date = ?", scheduleDate)
  3091. }
  3092. err = db.Find(&vms).Error
  3093. } else {
  3094. if patient_id > 0 {
  3095. db := readDb.
  3096. Table("xt_schedule").
  3097. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3098. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3099. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3100. }).
  3101. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3102. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3103. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3104. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3105. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3106. }).
  3107. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3108. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3109. }).Where("status = 1 AND user_org_id = ?", orgID)
  3110. if scheduleDate != 0 {
  3111. db = db.Where("schedule_date = ?", scheduleDate)
  3112. }
  3113. err = db.Find(&vms).Error
  3114. } else {
  3115. db := readDb.
  3116. Table("xt_schedule").
  3117. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3118. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3119. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3120. }).
  3121. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3122. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3123. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3124. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3125. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3126. }).
  3127. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3128. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3129. }).Where("status = 1 AND user_org_id = ?", orgID)
  3130. if scheduleDate != 0 {
  3131. db = db.Where("schedule_date = ?", scheduleDate)
  3132. }
  3133. err = db.Find(&vms).Error
  3134. }
  3135. }
  3136. }
  3137. if patientType > 0 {
  3138. db := readDb.
  3139. Table("xt_schedule").
  3140. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3141. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3142. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3143. }).
  3144. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3145. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3146. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3147. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3148. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3149. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3150. }).
  3151. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3152. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3153. }).Where("status = 1 AND user_org_id = ?", orgID)
  3154. if scheduleDate != 0 {
  3155. db = db.Where("schedule_date = ?", scheduleDate)
  3156. }
  3157. err = db.Find(&vms).Error
  3158. }
  3159. return vms, err
  3160. }
  3161. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3162. prepare := models.DialysisBeforePrepare{}
  3163. err := XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3164. return err
  3165. }
  3166. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3167. detail := models.AutomaticReduceDetail{}
  3168. err := XTWriteDB().Model(&detail).Where("good_id = ? and record_time = ? and patient_id = ? and count <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3169. return err
  3170. }
  3171. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3172. var record models.DialysisSolution
  3173. 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
  3174. if err != nil {
  3175. if err == gorm.ErrRecordNotFound {
  3176. return nil, nil
  3177. } else {
  3178. return nil, err
  3179. }
  3180. }
  3181. return &record, nil
  3182. }
  3183. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3184. var record models.DialysisPrescription
  3185. 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
  3186. if err != nil {
  3187. if err == gorm.ErrRecordNotFound {
  3188. return nil, nil
  3189. } else {
  3190. return nil, err
  3191. }
  3192. }
  3193. return &record, nil
  3194. }
  3195. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3196. var record models.SystemPrescription
  3197. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3198. if err != nil {
  3199. if err == gorm.ErrRecordNotFound {
  3200. return nil, nil
  3201. } else {
  3202. return nil, err
  3203. }
  3204. }
  3205. return &record, nil
  3206. }
  3207. // 透前评估
  3208. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3209. var record models.PredialysisEvaluation
  3210. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3211. if err != nil {
  3212. if err == gorm.ErrRecordNotFound {
  3213. return nil, nil
  3214. } else {
  3215. return nil, err
  3216. }
  3217. }
  3218. return &record, nil
  3219. }
  3220. //
  3221. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  3222. //
  3223. // err = readDb.Where("user_org_id = ? AND status=1 AND record_date = ? AND count > 0", orgID, scheduleDate).Select("patient_id,good_id,record_date").Find(&prepare).Error
  3224. // return prepare, err
  3225. //}
  3226. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3227. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  3228. return auto, err
  3229. }
  3230. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  3231. role := models.SgjUserAdminRole{}
  3232. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  3233. return role, err
  3234. }