mobile_dialysis_service.go 188KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955
  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. fmt.Println("key23322323232323", key)
  1947. dialysis_prescribe_str, _ := redis.Get(key).Result()
  1948. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1949. 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
  1950. if err != nil {
  1951. if err == gorm.ErrRecordNotFound {
  1952. if record.ID <= 0 {
  1953. redis.Set(key, "null", time.Second*60*60*18)
  1954. }
  1955. return nil, nil
  1956. } else {
  1957. return nil, err
  1958. }
  1959. } else {
  1960. if record.ID > 0 {
  1961. //缓存数据
  1962. dialysis_prescribe_str, err := json.Marshal(record)
  1963. if err == nil {
  1964. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  1965. }
  1966. } else {
  1967. redis.Set(key, "null", time.Second*60*60*18)
  1968. }
  1969. return &record, nil
  1970. }
  1971. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1972. if dialysis_prescribe_str == "null" {
  1973. return &record, nil
  1974. } else {
  1975. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  1976. return &record, nil
  1977. }
  1978. }
  1979. }
  1980. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  1981. var record models.DialysisPrescription
  1982. 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
  1983. if err != nil {
  1984. if err == gorm.ErrRecordNotFound {
  1985. return nil, nil
  1986. } else {
  1987. return nil, err
  1988. }
  1989. }
  1990. return &record, nil
  1991. }
  1992. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1993. var record models.DialysisPrescription
  1994. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1995. if err != nil {
  1996. if err == gorm.ErrRecordNotFound {
  1997. return nil, nil
  1998. } else {
  1999. return nil, err
  2000. }
  2001. }
  2002. return &record, nil
  2003. }
  2004. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2005. // var record models.DialysisPrescription
  2006. // redis := RedisClient()
  2007. // defer redis.Close()
  2008. //
  2009. // // cur_date := time.Now().Format("2006-01-02")
  2010. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2011. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2012. //
  2013. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2014. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2015. // if err != nil {
  2016. // if err == gorm.ErrRecordNotFound {
  2017. // if record.ID <= 0 {
  2018. // redis.Set(key, "null", time.Second*60*60*18)
  2019. // }
  2020. // return nil, nil
  2021. // } else {
  2022. // return nil, err
  2023. // }
  2024. // } else {
  2025. //
  2026. // if record.ID > 0 {
  2027. // //缓存数据
  2028. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2029. //
  2030. // if err == nil {
  2031. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2032. // return nil, err
  2033. // }
  2034. // } else {
  2035. // redis.Set(key, "null", time.Second*60*60*18)
  2036. // return nil, err
  2037. // }
  2038. // return &record, nil
  2039. // }
  2040. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2041. // if dialysis_prescribe_by_mode_str == "null" {
  2042. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2043. // return &record, nil
  2044. // } else {
  2045. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2046. // return &record, nil
  2047. // }
  2048. //
  2049. // }
  2050. //}
  2051. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2052. var record models.DialysisPrescription
  2053. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2054. if err != nil {
  2055. if err == gorm.ErrRecordNotFound {
  2056. return nil, nil
  2057. } else {
  2058. return nil, err
  2059. }
  2060. }
  2061. return &record, nil
  2062. }
  2063. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2064. var record models.DialysisPrescription
  2065. 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
  2066. if err != nil {
  2067. if err == gorm.ErrRecordNotFound {
  2068. return nil, nil
  2069. } else {
  2070. return nil, err
  2071. }
  2072. }
  2073. return &record, nil
  2074. }
  2075. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2076. var record models.DialysisPrescription
  2077. redis := RedisClient()
  2078. defer redis.Close()
  2079. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2080. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2081. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2082. 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
  2083. if err != nil {
  2084. if err == gorm.ErrRecordNotFound {
  2085. if record.ID <= 0 {
  2086. redis.Set(key, "null", time.Second*60*60*18)
  2087. }
  2088. return nil, nil
  2089. } else {
  2090. return nil, err
  2091. }
  2092. } else {
  2093. if record.ID > 0 {
  2094. //缓存数据
  2095. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2096. if err == nil {
  2097. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2098. return nil, err
  2099. }
  2100. } else {
  2101. redis.Set(key, "null", time.Second*60*60*18)
  2102. return nil, err
  2103. }
  2104. return &record, nil
  2105. }
  2106. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2107. if dialysis_prescribe_by_mode_id == "null" {
  2108. return &record, nil
  2109. } else {
  2110. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2111. return &record, nil
  2112. }
  2113. }
  2114. }
  2115. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2116. var record models.DialysisPrescription
  2117. 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
  2118. return record, err
  2119. }
  2120. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2121. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2122. 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()
  2123. defer rows.Close()
  2124. if err != nil {
  2125. return nil, err
  2126. }
  2127. for rows.Next() {
  2128. var vm DeviceNumberViewModel
  2129. readDb.ScanRows(rows, &vm)
  2130. vms = append(vms, &vm)
  2131. }
  2132. return vms, nil
  2133. }
  2134. // 获取 maxDate 之前一次的透前评估记录
  2135. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2136. var record models.PredialysisEvaluation
  2137. 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
  2138. if err != nil {
  2139. if err == gorm.ErrRecordNotFound {
  2140. return nil, nil
  2141. } else {
  2142. return nil, err
  2143. }
  2144. }
  2145. return &record, nil
  2146. }
  2147. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2148. var record models.DialysisOrder
  2149. 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
  2150. if err != nil {
  2151. if err == gorm.ErrRecordNotFound {
  2152. return nil, nil
  2153. } else {
  2154. return nil, err
  2155. }
  2156. }
  2157. return &record, nil
  2158. }
  2159. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2160. var record models.MonitoringRecord
  2161. 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
  2162. if err != nil {
  2163. if err == gorm.ErrRecordNotFound {
  2164. return nil, nil
  2165. } else {
  2166. return nil, err
  2167. }
  2168. }
  2169. return &record, nil
  2170. }
  2171. // 获取 maxDate 之前一次的透后评估记录
  2172. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2173. var record models.AssessmentAfterDislysis
  2174. 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
  2175. if err != nil {
  2176. if err == gorm.ErrRecordNotFound {
  2177. return nil, nil
  2178. } else {
  2179. return nil, err
  2180. }
  2181. }
  2182. return &record, nil
  2183. }
  2184. // 透析处方
  2185. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2186. var record models.DialysisPrescription
  2187. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2188. if err != nil {
  2189. if err == gorm.ErrRecordNotFound {
  2190. return nil, nil
  2191. } else {
  2192. return nil, err
  2193. }
  2194. }
  2195. return &record, nil
  2196. }
  2197. // 透析方案
  2198. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2199. var record models.DialysisSolution
  2200. 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
  2201. if err != nil {
  2202. if err == gorm.ErrRecordNotFound {
  2203. return nil, nil
  2204. } else {
  2205. return nil, err
  2206. }
  2207. }
  2208. return &record, nil
  2209. }
  2210. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2211. var record models.DialysisSolution
  2212. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2213. if err != nil {
  2214. if err == gorm.ErrRecordNotFound {
  2215. return nil, nil
  2216. } else {
  2217. return nil, err
  2218. }
  2219. }
  2220. return &record, nil
  2221. }
  2222. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2223. var record models.DialysisPrescription
  2224. 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
  2225. if err != nil {
  2226. if err == gorm.ErrRecordNotFound {
  2227. return nil, nil
  2228. } else {
  2229. return nil, err
  2230. }
  2231. }
  2232. return &record, nil
  2233. }
  2234. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2235. var record models.SgjPatientDryweight
  2236. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2237. if err != nil {
  2238. if err == gorm.ErrRecordNotFound {
  2239. return nil, nil
  2240. } else {
  2241. return nil, err
  2242. }
  2243. }
  2244. return &record, nil
  2245. }
  2246. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2247. var record models.SystemPrescription
  2248. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2249. if err != nil {
  2250. if err == gorm.ErrRecordNotFound {
  2251. return nil, nil
  2252. } else {
  2253. return nil, err
  2254. }
  2255. }
  2256. return &record, nil
  2257. }
  2258. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2259. var record models.SystemPrescription
  2260. redis := RedisClient()
  2261. defer redis.Close()
  2262. // cur_date := time.Now().Format("2006-01-02")
  2263. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2264. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2265. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2266. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2267. if err != nil {
  2268. if err == gorm.ErrRecordNotFound {
  2269. if record.ID <= 0 {
  2270. redis.Set(key, "null", time.Second*60*60*18)
  2271. }
  2272. return nil, nil
  2273. } else {
  2274. return nil, err
  2275. }
  2276. } else {
  2277. if record.ID > 0 {
  2278. //缓存数据
  2279. system_dialysis_prescribe_str, err := json.Marshal(record)
  2280. if err == nil {
  2281. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2282. }
  2283. } else {
  2284. redis.Set(key, "null", time.Second*60*60*18)
  2285. }
  2286. return &record, nil
  2287. }
  2288. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2289. if system_dialysis_prescribe_str == "null" {
  2290. return &record, nil
  2291. } else {
  2292. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2293. return &record, nil
  2294. }
  2295. }
  2296. }
  2297. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2298. var record models.SystemPrescription
  2299. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2300. return record, err
  2301. }
  2302. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2303. var record models.SystemPrescription
  2304. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2305. if err != nil {
  2306. if err == gorm.ErrRecordNotFound {
  2307. return nil, nil
  2308. } else {
  2309. return nil, err
  2310. }
  2311. }
  2312. return &record, nil
  2313. }
  2314. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2315. 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
  2316. return
  2317. }
  2318. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2319. 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
  2320. return
  2321. }
  2322. func GetFirstDateOfMonth(d time.Time) time.Time {
  2323. d = d.AddDate(0, 0, -d.Day()+1)
  2324. return GetZeroTime(d)
  2325. }
  2326. func GetZeroTime(d time.Time) time.Time {
  2327. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2328. }
  2329. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2330. db := XTReadDB().Table("xt_dialysis_order as o")
  2331. 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
  2332. return order, err
  2333. }
  2334. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2335. 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
  2336. return
  2337. }
  2338. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2339. 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
  2340. return
  2341. }
  2342. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2343. 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
  2344. return
  2345. }
  2346. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2347. // 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
  2348. // return
  2349. //}
  2350. //
  2351. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2352. 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
  2353. return
  2354. }
  2355. type GoodsType struct {
  2356. ID int64 `gorm:"column:id" json:"id"`
  2357. TypeName string `gorm:"column:type_name" json:"type_name"`
  2358. Remark string `gorm:"column:remark" json:"remark"`
  2359. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2360. Status int64 `gorm:"column:status" json:"status"`
  2361. Type int64 `gorm:"column:type" json:"type"`
  2362. }
  2363. func (GoodsType) TableName() string {
  2364. return "xt_goods_type"
  2365. }
  2366. type VMGoodInfo struct {
  2367. ID int64 `gorm:"column:id" json:"id"`
  2368. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2369. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2370. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2371. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2372. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2373. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2374. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2375. }
  2376. func (VMGoodInfo) TableName() string {
  2377. return "xt_good_information"
  2378. }
  2379. type AutomaticReduceDetail struct {
  2380. ID int64 `gorm:"column:id" json:"id"`
  2381. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2382. Status int64 `gorm:"column:status" json:"status"`
  2383. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2384. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2385. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2386. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2387. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2388. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2389. Count int64 `gorm:"column:count" json:"count"`
  2390. }
  2391. func (AutomaticReduceDetail) TableName() string {
  2392. return "xt_automatic_reduce_detail"
  2393. }
  2394. type DialysisBeforePrepare struct {
  2395. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2396. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2397. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2398. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2399. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2400. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2401. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2402. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2403. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2404. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2405. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2406. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2407. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2408. }
  2409. func (DialysisBeforePrepare) TableName() string {
  2410. return "dialysis_before_prepare"
  2411. }
  2412. type MDialysisGoodsVM struct {
  2413. ID int64 `gorm:"column:id" json:"id"`
  2414. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2415. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2416. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2417. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2418. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2419. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2420. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2421. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2422. Status int64 `gorm:"column:status" json:"status"`
  2423. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2424. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2425. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2426. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2427. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2428. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2429. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2430. }
  2431. func (MDialysisGoodsVM) TableName() string {
  2432. return "xt_schedule"
  2433. }
  2434. type VMWarehouseOutInfo struct {
  2435. ID int64 `gorm:"column:id" json:"id"`
  2436. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2437. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2438. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2439. Count int64 `gorm:"column:count" json:"count"`
  2440. Price float64 `gorm:"column:price" json:"price"`
  2441. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2442. Status int64 `gorm:"column:status" json:"status"`
  2443. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2444. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2445. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2446. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2447. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2448. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2449. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2450. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2451. }
  2452. func (VMWarehouseOutInfo) TableName() string {
  2453. return "xt_warehouse_out_info"
  2454. }
  2455. type DialysisGoodsDate struct {
  2456. RecordDate int64
  2457. }
  2458. type DialysisGoodsDetailDate struct {
  2459. RecordTime int64
  2460. }
  2461. 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) {
  2462. var vms []*MDialysisGoodsVM
  2463. var total int64
  2464. db := readDb.
  2465. Table("xt_schedule as sch").
  2466. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2467. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2468. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2469. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2470. 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)
  2471. }).
  2472. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2473. 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")
  2474. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2475. if scheduleDate != 0 {
  2476. db = db.Where("schedule_date = ?", scheduleDate)
  2477. }
  2478. if schedule_type != 0 {
  2479. db = db.Where("schedule_type = ?", schedule_type)
  2480. }
  2481. if partition_id != 0 {
  2482. db = db.Where("partition_id = ?", partition_id)
  2483. }
  2484. if patient_id != 0 {
  2485. db = db.Where("patient_id = ?", patient_id)
  2486. }
  2487. //db = db.Count(&total)
  2488. //offset := (page - 1) * limit
  2489. //
  2490. //db = db.Offset(offset).Limit(limit)
  2491. err := db.Find(&vms).Error
  2492. return vms, err, total
  2493. }
  2494. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2495. var Id []*DialysisGoodsDetailDate
  2496. 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
  2497. if len(Id) > 0 {
  2498. 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
  2499. }
  2500. return
  2501. }
  2502. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2503. var Id []*DialysisGoodsDate
  2504. 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
  2505. if len(Id) > 0 {
  2506. 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
  2507. }
  2508. return
  2509. }
  2510. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2511. db := readDb.Model(&models.StockInfo{})
  2512. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2513. 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")
  2514. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2515. 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)
  2516. })
  2517. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2518. err = db.Order("ctime desc").Find(&list).Error
  2519. return
  2520. }
  2521. func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64, good_type int64, ids []int64) ([]*MDialysisGoodsVM, error, int64) {
  2522. var vms []*MDialysisGoodsVM
  2523. var total int64
  2524. db := readDb.
  2525. Model(&models.Schedule{}).
  2526. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2527. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2528. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2529. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2530. 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)
  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. if good_type == 1 {
  2551. db = db.Where("patient_id in(?)", ids)
  2552. }
  2553. if good_type == 2 {
  2554. db = db.Where("patient_id not in(?)", ids)
  2555. }
  2556. db = db.Count(&total)
  2557. offset := (page - 1) * limit
  2558. db = db.Offset(offset).Limit(limit)
  2559. }
  2560. err := db.Find(&vms).Error
  2561. return vms, err, total
  2562. }
  2563. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2564. var Id []*DialysisGoodsDetailDate
  2565. 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
  2566. if len(Id) > 0 {
  2567. 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
  2568. }
  2569. return
  2570. }
  2571. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2572. var Id []*DialysisGoodsDate
  2573. 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
  2574. if len(Id) > 0 {
  2575. 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
  2576. }
  2577. return
  2578. }
  2579. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2580. evaluation := models.PredialysisEvaluation{}
  2581. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2582. if err == gorm.ErrRecordNotFound {
  2583. return nil, err
  2584. }
  2585. if err != nil {
  2586. return nil, err
  2587. }
  2588. return &evaluation, nil
  2589. }
  2590. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2591. redis := RedisClient()
  2592. defer redis.Close()
  2593. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2594. his_doctor_advice_str, _ := redis.Get(key).Result()
  2595. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2596. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
  2597. if err != nil {
  2598. if err == gorm.ErrRecordNotFound {
  2599. if len(his) <= 0 {
  2600. redis.Set(key, "null", time.Second*60*60*18)
  2601. }
  2602. return his, nil
  2603. } else {
  2604. return his, err
  2605. }
  2606. } else {
  2607. if len(his) > 0 {
  2608. //缓存数据
  2609. his_doctor_advice_str, err := json.Marshal(his)
  2610. if err == nil {
  2611. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2612. }
  2613. } else {
  2614. redis.Set(key, "null", time.Second*60*60*18)
  2615. }
  2616. return his, nil
  2617. }
  2618. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2619. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2620. return his, nil
  2621. }
  2622. }
  2623. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2624. prescription := models.DialysisPrescription{}
  2625. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2626. if err == gorm.ErrRecordNotFound {
  2627. return nil, err
  2628. }
  2629. if err != nil {
  2630. return nil, err
  2631. }
  2632. return &prescription, nil
  2633. }
  2634. type HisMScheduleDoctorAdviceVM struct {
  2635. ID int64 `gorm:"column:id" json:"id"`
  2636. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2637. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2638. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2639. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2640. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2641. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2642. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2643. Status int64 `gorm:"column:status" json:"status"`
  2644. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2645. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2646. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2647. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2648. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2649. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2650. }
  2651. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2652. return "xt_schedule"
  2653. }
  2654. type HisMScheduleDoctorAdviceVMOne struct {
  2655. ID int64 `gorm:"column:id" json:"id"`
  2656. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2657. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2658. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2659. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2660. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2661. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2662. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2663. Status int64 `gorm:"column:status" json:"status"`
  2664. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2665. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2666. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2667. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2668. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2669. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2670. }
  2671. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2672. return "xt_schedule"
  2673. }
  2674. type HisMScheduleProjectVM struct {
  2675. ID int64 `gorm:"column:id" json:"id"`
  2676. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2677. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2678. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2679. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2680. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2681. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2682. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2683. Status int64 `gorm:"column:status" json:"status"`
  2684. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2685. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2686. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2687. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2688. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2689. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2690. }
  2691. func (HisMScheduleProjectVM) TableName() string {
  2692. return "xt_schedule"
  2693. }
  2694. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2695. config := models.XtHisConfig{}
  2696. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2697. return config, err
  2698. }
  2699. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2700. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2701. if orgid > 0 {
  2702. db = db.Where("x.user_org_id = ?", orgid)
  2703. }
  2704. if patientid > 0 {
  2705. db = db.Where("x.patient_id =?", patientid)
  2706. }
  2707. if recordtime > 0 {
  2708. db = db.Where("x.advice_date = ?", recordtime)
  2709. }
  2710. 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
  2711. return advice, err
  2712. }
  2713. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2714. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2715. if startime > 0 {
  2716. db = db.Where("x.advice_date >= ?", startime)
  2717. }
  2718. if endtime > 0 {
  2719. db = db.Where("x.advice_date<=?", endtime)
  2720. }
  2721. if orgid > 0 {
  2722. db = db.Where("x.user_org_id = ?", orgid)
  2723. }
  2724. if len(deliveway) > 0 {
  2725. db = db.Where("x.delivery_way = ?", deliveway)
  2726. }
  2727. 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
  2728. return advice, err
  2729. }
  2730. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2731. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2732. if startime > 0 {
  2733. db = db.Where("x.advice_date >= ?", startime)
  2734. }
  2735. if endtime > 0 {
  2736. db = db.Where("x.advice_date<=?", endtime)
  2737. }
  2738. if orgid > 0 {
  2739. db = db.Where("x.user_org_id = ?", orgid)
  2740. }
  2741. if len(deliveway) > 0 {
  2742. db = db.Where("x.delivery_way = ?", deliveway)
  2743. }
  2744. 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
  2745. return advice, err
  2746. }
  2747. func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64) ([]*MScheduleDoctorAdviceVM, error) {
  2748. var vms []*MScheduleDoctorAdviceVM
  2749. adviceWhere := ""
  2750. adviceCondition := []interface{}{}
  2751. if adviceType == 0 {
  2752. if patientType == 0 {
  2753. if patient_id > 0 {
  2754. if execution_state > 0 {
  2755. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  2756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2757. } else {
  2758. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2760. }
  2761. } else {
  2762. if execution_state > 0 {
  2763. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  2764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2765. } else {
  2766. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  2767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2768. }
  2769. }
  2770. } else if patientType == 1 {
  2771. if patient_id > 0 {
  2772. if execution_state > 0 {
  2773. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  2774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  2775. } else {
  2776. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2777. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2778. }
  2779. } else {
  2780. if execution_state > 0 {
  2781. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  2782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  2783. } else {
  2784. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  2785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2786. }
  2787. }
  2788. } else if patientType == 2 {
  2789. if patient_id > 0 {
  2790. if execution_state > 0 {
  2791. 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 = ?) and execution_state = ?"
  2792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2793. } else {
  2794. 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 = ?)"
  2795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2796. }
  2797. } else {
  2798. if execution_state > 0 {
  2799. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  2800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2801. } else {
  2802. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  2803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2804. }
  2805. }
  2806. }
  2807. } else if adviceType == 1 {
  2808. if patientType == 0 {
  2809. if patient_id > 0 {
  2810. if execution_state > 0 {
  2811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  2812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2813. } else {
  2814. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  2815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2816. }
  2817. } else {
  2818. if execution_state > 0 {
  2819. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  2820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2821. } else {
  2822. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  2823. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2824. }
  2825. }
  2826. } else if patientType == 1 {
  2827. if patient_id > 0 {
  2828. if execution_state > 0 {
  2829. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  2830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  2831. } else {
  2832. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  2833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2834. }
  2835. } else {
  2836. if execution_state > 0 {
  2837. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  2838. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  2839. } else {
  2840. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  2841. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2842. }
  2843. }
  2844. } else if patientType == 2 {
  2845. if patient_id > 0 {
  2846. if execution_state > 0 {
  2847. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  2848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2849. } else {
  2850. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  2851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2852. }
  2853. } else {
  2854. if execution_state > 0 {
  2855. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  2856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2857. } else {
  2858. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  2859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2860. }
  2861. }
  2862. }
  2863. } else if adviceType == 3 {
  2864. if patientType == 0 {
  2865. if patient_id > 0 {
  2866. if execution_state > 0 {
  2867. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  2868. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2869. } else {
  2870. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  2871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2872. }
  2873. } else {
  2874. if execution_state > 0 {
  2875. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  2876. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2877. } else {
  2878. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  2879. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2880. }
  2881. }
  2882. } else if patientType == 1 {
  2883. if patient_id > 0 {
  2884. if execution_state > 0 {
  2885. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  2886. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  2887. } else {
  2888. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  2889. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2890. }
  2891. } else {
  2892. if execution_state > 0 {
  2893. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  2894. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  2895. } else {
  2896. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  2897. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2898. }
  2899. }
  2900. } else if patientType == 2 {
  2901. if patient_id > 0 {
  2902. if execution_state > 0 {
  2903. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  2904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2905. } else {
  2906. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  2907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2908. }
  2909. } else {
  2910. if execution_state > 0 {
  2911. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  2912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2913. } else {
  2914. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  2915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2916. }
  2917. }
  2918. }
  2919. } else if adviceType == 2 && len(deliverWay) > 0 {
  2920. if patientType == 0 {
  2921. if patient_id > 0 {
  2922. if execution_state > 0 {
  2923. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  2924. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  2925. } else {
  2926. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  2927. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  2928. }
  2929. } else {
  2930. if execution_state > 0 {
  2931. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  2932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  2933. } else {
  2934. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  2935. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2936. }
  2937. }
  2938. } else if patientType == 1 {
  2939. if patient_id > 0 {
  2940. if execution_state > 0 {
  2941. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  2942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  2943. } else {
  2944. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  2945. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  2946. }
  2947. } else {
  2948. if execution_state > 0 {
  2949. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  2950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  2951. } else {
  2952. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  2953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  2954. }
  2955. }
  2956. } else if patientType == 2 {
  2957. if patient_id > 0 {
  2958. if execution_state > 0 {
  2959. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  2960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  2961. } else {
  2962. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  2963. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  2964. }
  2965. } else {
  2966. if execution_state > 0 {
  2967. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  2968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  2969. } else {
  2970. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  2971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2972. }
  2973. }
  2974. }
  2975. } else if adviceType == 2 && len(deliverWay) <= 0 {
  2976. if patientType == 0 {
  2977. if patient_id > 0 {
  2978. if execution_state > 0 {
  2979. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  2980. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2981. } else {
  2982. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  2983. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2984. }
  2985. } else {
  2986. if execution_state > 0 {
  2987. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  2988. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2989. } else {
  2990. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  2991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2992. }
  2993. }
  2994. } else if patientType == 1 {
  2995. if patient_id > 0 {
  2996. if execution_state > 0 {
  2997. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  2998. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  2999. } else {
  3000. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3001. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3002. }
  3003. } else {
  3004. if execution_state > 0 {
  3005. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3007. } else {
  3008. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3010. }
  3011. }
  3012. } else if patientType == 2 {
  3013. if patient_id > 0 {
  3014. if execution_state > 0 {
  3015. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3016. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3017. } else {
  3018. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3020. }
  3021. } else {
  3022. if execution_state > 0 {
  3023. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3024. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3025. } else {
  3026. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3027. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3028. }
  3029. }
  3030. }
  3031. }
  3032. db := readDb.Table("xt_schedule")
  3033. if scheduleType > 0 {
  3034. db = db.Where("schedule_type = ?", scheduleType)
  3035. }
  3036. if partitonType > 0 {
  3037. db = db.Where("partition_id = ?", partitonType)
  3038. }
  3039. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3040. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3041. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3042. }).
  3043. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3044. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3045. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3046. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3047. Preload("DoctorAdvices", adviceCondition...).
  3048. Where("status = 1 AND user_org_id = ?", orgID)
  3049. if scheduleDate != 0 {
  3050. db = db.Where("schedule_date = ?", scheduleDate)
  3051. }
  3052. err := db.Find(&vms).Error
  3053. return vms, err
  3054. }
  3055. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3056. var vms []*HisMScheduleDoctorAdviceVM
  3057. if len(deliverWay) > 0 {
  3058. db := readDb.Table("xt_schedule")
  3059. if scheduleType > 0 {
  3060. db = db.Where("schedule_type = ?", scheduleType)
  3061. }
  3062. if partitionType > 0 {
  3063. db = db.Where("partition_id = ?", partitionType)
  3064. }
  3065. if patient_id > 0 {
  3066. if execution_state > 0 {
  3067. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3068. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3069. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3070. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3071. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, deliverWay, patient_id, execution_state).
  3072. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3073. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3074. }).
  3075. Where("status = 1 AND user_org_id = ?", orgID)
  3076. if scheduleDate != 0 {
  3077. db = db.Where("schedule_date = ?", scheduleDate)
  3078. }
  3079. err = db.Find(&vms).Error
  3080. } else {
  3081. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3082. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3083. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3084. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3085. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3086. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3087. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3088. }).
  3089. Where("status = 1 AND user_org_id = ?", orgID)
  3090. if scheduleDate != 0 {
  3091. db = db.Where("schedule_date = ?", scheduleDate)
  3092. }
  3093. err = db.Find(&vms).Error
  3094. }
  3095. } else {
  3096. if execution_state > 0 {
  3097. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3098. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3099. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3100. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3101. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3102. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3103. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3104. }).
  3105. Where("status = 1 AND user_org_id = ?", orgID)
  3106. if scheduleDate != 0 {
  3107. db = db.Where("schedule_date = ?", scheduleDate)
  3108. }
  3109. err = db.Find(&vms).Error
  3110. } else {
  3111. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3112. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3113. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3114. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3115. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3116. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3117. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3118. }).
  3119. Where("status = 1 AND user_org_id = ?", orgID)
  3120. if scheduleDate != 0 {
  3121. db = db.Where("schedule_date = ?", scheduleDate)
  3122. }
  3123. err = db.Find(&vms).Error
  3124. }
  3125. }
  3126. } else {
  3127. db := readDb.Table("xt_schedule")
  3128. if scheduleType > 0 {
  3129. db = db.Where("schedule_type = ?", scheduleType)
  3130. }
  3131. if partitionType > 0 {
  3132. db = db.Where("partition_id = ?", partitionType)
  3133. }
  3134. if patient_id > 0 {
  3135. if execution_state > 0 {
  3136. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3137. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3138. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3139. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3140. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3141. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3142. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3143. }).
  3144. Where("status = 1 AND user_org_id = ?", orgID)
  3145. if scheduleDate != 0 {
  3146. db = db.Where("schedule_date = ?", scheduleDate)
  3147. }
  3148. err = db.Find(&vms).Error
  3149. } else {
  3150. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3151. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3152. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3153. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3154. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3155. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3156. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3157. }).
  3158. Where("status = 1 AND user_org_id = ?", orgID)
  3159. if scheduleDate != 0 {
  3160. db = db.Where("schedule_date = ?", scheduleDate)
  3161. }
  3162. err = db.Find(&vms).Error
  3163. }
  3164. } else {
  3165. if execution_state > 0 {
  3166. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3167. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3168. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3169. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3170. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3171. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3172. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3173. }).
  3174. Where("status = 1 AND user_org_id = ?", orgID)
  3175. if scheduleDate != 0 {
  3176. db = db.Where("schedule_date = ?", scheduleDate)
  3177. }
  3178. err = db.Find(&vms).Error
  3179. } else {
  3180. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3181. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3182. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3183. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3184. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3185. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3186. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3187. }).
  3188. Where("status = 1 AND user_org_id = ?", orgID)
  3189. if scheduleDate != 0 {
  3190. db = db.Where("schedule_date = ?", scheduleDate)
  3191. }
  3192. err = db.Find(&vms).Error
  3193. }
  3194. }
  3195. }
  3196. return vms, err
  3197. }
  3198. func BatchDeleteMonitor(ids []string) (err error) {
  3199. if len(ids) == 1 {
  3200. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3201. } else {
  3202. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3203. }
  3204. return
  3205. }
  3206. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3207. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3208. //table := XTReadDB().Table("xt_schedule as s")
  3209. //fmt.Println(table)
  3210. if patientid > 0 {
  3211. db = db.Where("x.patient_id = ?", patientid)
  3212. }
  3213. if startime > 0 {
  3214. db = db.Where("x.dialysis_date>=?", startime)
  3215. }
  3216. if endtime > 0 {
  3217. db = db.Where("x.dialysis_date <= ?", endtime)
  3218. }
  3219. 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
  3220. return order, err
  3221. }
  3222. func BatchDeleteAdvice(ids []string) (err error) {
  3223. if len(ids) == 1 {
  3224. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3225. } else {
  3226. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3227. }
  3228. return
  3229. }
  3230. func BatchDeleteHisAdvice(ids []string) (err error) {
  3231. if len(ids) == 1 {
  3232. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3233. } else {
  3234. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3235. }
  3236. return
  3237. }
  3238. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3239. detail := models.AutomaticReduceDetail{}
  3240. 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
  3241. return detail, err
  3242. }
  3243. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3244. detail := models.AutomaticReduceDetail{}
  3245. 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
  3246. return err
  3247. }
  3248. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3249. detail := models.DialysisBeforePrepare{}
  3250. 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
  3251. return err
  3252. }
  3253. func BatchAdviceCheck(ids []string, creator int64) error {
  3254. advice := models.XtDoctorAdvice{}
  3255. 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
  3256. return err
  3257. }
  3258. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3259. advice := models.HisDoctorAdviceInfo{}
  3260. 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
  3261. return err
  3262. }
  3263. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3264. advice := models.XtDoctorAdvice{}
  3265. 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
  3266. return err
  3267. }
  3268. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3269. advice := models.HisDoctorAdviceInfo{}
  3270. 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
  3271. return err
  3272. }
  3273. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3274. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3275. return doctor, err
  3276. }
  3277. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3278. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3279. return doctor, err
  3280. }
  3281. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3282. config := models.XtHisProjectConfig{}
  3283. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3284. return config, err
  3285. }
  3286. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3287. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3288. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3289. }).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
  3290. return
  3291. }
  3292. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3293. var vms []*HisMScheduleProjectVM
  3294. if patientType == 0 {
  3295. if patient_id > 0 {
  3296. if execution_state > 0 {
  3297. db := readDb.
  3298. Table("xt_schedule").
  3299. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3300. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3301. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3302. }).
  3303. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3304. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3305. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3306. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3307. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3308. }).
  3309. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3310. 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")
  3311. }).Where("status = 1 AND user_org_id = ?", orgID)
  3312. if scheduleDate != 0 {
  3313. db = db.Where("schedule_date = ?", scheduleDate)
  3314. }
  3315. err = db.Find(&vms).Error
  3316. } else {
  3317. db := readDb.
  3318. Table("xt_schedule").
  3319. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3320. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3321. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3322. }).
  3323. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3324. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3325. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3326. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3327. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3328. }).
  3329. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3330. 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")
  3331. }).Where("status = 1 AND user_org_id = ?", orgID)
  3332. if scheduleDate != 0 {
  3333. db = db.Where("schedule_date = ?", scheduleDate)
  3334. }
  3335. err = db.Find(&vms).Error
  3336. }
  3337. } else {
  3338. if patient_id > 0 {
  3339. if execution_state > 0 {
  3340. db := readDb.
  3341. Table("xt_schedule").
  3342. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3343. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3344. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3345. }).
  3346. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3347. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3348. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3349. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3350. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3351. }).
  3352. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3353. 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")
  3354. }).Where("status = 1 AND user_org_id = ?", orgID)
  3355. if scheduleDate != 0 {
  3356. db = db.Where("schedule_date = ?", scheduleDate)
  3357. }
  3358. err = db.Find(&vms).Error
  3359. } else {
  3360. db := readDb.
  3361. Table("xt_schedule").
  3362. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3363. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3364. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3365. }).
  3366. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3367. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3368. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3369. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3370. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3371. }).
  3372. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3373. 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")
  3374. }).Where("status = 1 AND user_org_id = ?", orgID)
  3375. if scheduleDate != 0 {
  3376. db = db.Where("schedule_date = ?", scheduleDate)
  3377. }
  3378. err = db.Find(&vms).Error
  3379. }
  3380. } else {
  3381. if execution_state > 0 {
  3382. db := readDb.
  3383. Table("xt_schedule").
  3384. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3385. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3386. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3387. }).
  3388. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3389. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3390. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3391. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3392. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3393. }).
  3394. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3395. 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")
  3396. }).Where("status = 1 AND user_org_id = ?", orgID)
  3397. if scheduleDate != 0 {
  3398. db = db.Where("schedule_date = ?", scheduleDate)
  3399. }
  3400. err = db.Find(&vms).Error
  3401. } else {
  3402. db := readDb.
  3403. Table("xt_schedule").
  3404. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3405. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3406. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3407. }).
  3408. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3409. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3410. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3411. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3412. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3413. }).
  3414. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3415. 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")
  3416. }).Where("status = 1 AND user_org_id = ?", orgID)
  3417. if scheduleDate != 0 {
  3418. db = db.Where("schedule_date = ?", scheduleDate)
  3419. }
  3420. err = db.Find(&vms).Error
  3421. }
  3422. }
  3423. }
  3424. }
  3425. if patientType > 0 {
  3426. db := readDb.
  3427. Table("xt_schedule").
  3428. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3429. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3430. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3431. }).
  3432. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3433. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3434. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3435. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3436. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3437. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3438. }).
  3439. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3440. 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")
  3441. }).Where("status = 1 AND user_org_id = ?", orgID)
  3442. if scheduleDate != 0 {
  3443. db = db.Where("schedule_date = ?", scheduleDate)
  3444. }
  3445. err = db.Find(&vms).Error
  3446. }
  3447. return vms, err
  3448. }
  3449. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3450. prepare := models.DialysisBeforePrepare{}
  3451. 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
  3452. return err
  3453. }
  3454. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3455. detail := models.AutomaticReduceDetail{}
  3456. 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
  3457. return err
  3458. }
  3459. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3460. var record models.DialysisSolution
  3461. 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
  3462. if err != nil {
  3463. if err == gorm.ErrRecordNotFound {
  3464. return nil, nil
  3465. } else {
  3466. return nil, err
  3467. }
  3468. }
  3469. return &record, nil
  3470. }
  3471. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3472. var record models.DialysisPrescription
  3473. 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
  3474. if err != nil {
  3475. if err == gorm.ErrRecordNotFound {
  3476. return nil, nil
  3477. } else {
  3478. return nil, err
  3479. }
  3480. }
  3481. return &record, nil
  3482. }
  3483. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3484. var record models.SystemPrescription
  3485. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3486. if err != nil {
  3487. if err == gorm.ErrRecordNotFound {
  3488. return nil, nil
  3489. } else {
  3490. return nil, err
  3491. }
  3492. }
  3493. return &record, nil
  3494. }
  3495. // 透前评估
  3496. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3497. var record models.PredialysisEvaluation
  3498. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3499. if err != nil {
  3500. if err == gorm.ErrRecordNotFound {
  3501. return nil, nil
  3502. } else {
  3503. return nil, err
  3504. }
  3505. }
  3506. return &record, nil
  3507. }
  3508. //
  3509. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  3510. //
  3511. // 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
  3512. // return prepare, err
  3513. //}
  3514. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3515. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  3516. return auto, err
  3517. }
  3518. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  3519. role := models.SgjUserAdminRole{}
  3520. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  3521. return role, err
  3522. }
  3523. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3524. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  3525. return auto, err
  3526. }