mobile_dialysis_service.go 199KB

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