mobile_dialysis_service.go 262KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251
  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.Preload("DialysisLastOrder", func(db *gorm.DB) *gorm.DB {
  37. return db.Order("dialysis_date desc").Where("status = 1 AND user_org_id = ? and dialysis_date < ?", orgID, scheduleDate)
  38. }).Preload("DialysisSolution", "status = 1 and user_org_id = ? and solution_status = 1", orgID).Find(&vms).Error
  39. return vms, err
  40. }
  41. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  42. var vms []*MDialysisScheduleVM
  43. db := readDb.
  44. Table("xt_schedule as sch").
  45. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  46. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  47. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  48. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  49. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  50. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  51. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  52. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  53. Preload("TreatmentMode", "status = 1").
  54. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  55. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  56. if scheduleDate != 0 {
  57. db = db.Where("schedule_date = ?", scheduleDate)
  58. }
  59. err := db.Find(&vms).Error
  60. return vms, err
  61. }
  62. type VMTreatmentSummary struct {
  63. ID int64 `gorm:"column:id" json:"id"`
  64. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  65. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  66. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  67. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  68. }
  69. func (VMTreatmentSummary) TableName() string {
  70. return "xt_treatment_summary"
  71. }
  72. type AssessmentAfterDislysis struct {
  73. ID int64 `gorm:"column:id" json:"id"`
  74. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  75. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  76. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  77. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  78. Status int64 `gorm:"column:status" json:"status"`
  79. }
  80. func (AssessmentAfterDislysis) TableName() string {
  81. return "xt_assessment_after_dislysis"
  82. }
  83. type MDialysisScheduleVM struct {
  84. ID int64 `gorm:"column:id" json:"id"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  86. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  87. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  88. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  89. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  90. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  91. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  92. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  93. Status int64 `gorm:"column:status" json:"status"`
  94. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  95. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  96. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  97. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  98. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  99. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  100. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  101. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  102. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  103. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  104. }
  105. func (MDialysisScheduleVM) TableName() string {
  106. return "xt_schedule"
  107. }
  108. type MDialysisScheduleVMForList struct {
  109. ID int64 `gorm:"column:id" json:"id"`
  110. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  111. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  112. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  113. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  114. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  115. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  116. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  117. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  118. Status int64 `gorm:"column:status" json:"status"`
  119. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  120. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  121. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  122. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  123. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  124. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  125. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  126. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  127. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  128. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  129. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  130. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  131. }
  132. func (MDialysisScheduleVMForList) TableName() string {
  133. return "xt_schedule"
  134. }
  135. type MDeviceNumberVM struct {
  136. models.DeviceNumber
  137. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  138. }
  139. func (MDeviceNumberVM) TableName() string {
  140. return "xt_device_number"
  141. }
  142. type MSchedualPatientVMList struct {
  143. ID int64 `gorm:"column:id" json:"id" form:"id"`
  144. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  145. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  146. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  147. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  148. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  149. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  150. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  151. Age int64 `gorm:"column:age" json:"age"`
  152. Name string `gorm:"column:name" json:"name" form:"name"`
  153. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  154. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  155. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  156. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  157. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  158. }
  159. func (MSchedualPatientVMList) TableName() string {
  160. return "xt_patients"
  161. }
  162. type MSchedualPatientVM struct {
  163. ID int64 `gorm:"column:id" json:"id" form:"id"`
  164. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  165. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  166. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  167. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  168. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  169. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  170. Source int64 `gorm:"column:source" json:"source" form:"source"`
  171. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  172. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  173. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  174. Name string `gorm:"column:name" json:"name" form:"name"`
  175. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  176. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  177. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  178. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  179. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  180. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  181. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  182. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  183. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  184. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  185. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  186. Height int64 `gorm:"column:height" json:"height" form:"height"`
  187. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  188. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  189. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  190. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  191. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  192. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  193. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  194. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  195. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  196. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  197. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  198. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  199. Children int64 `gorm:"column:children" json:"children" form:"children"`
  200. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  201. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  202. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  203. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  204. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  205. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  206. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  207. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  208. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  209. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  210. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  211. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  212. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  213. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  214. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  215. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  216. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  217. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  218. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  219. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  220. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  221. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  222. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  223. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  224. Status int64 `gorm:"column:status" json:"status" form:"status"`
  225. Age int64 `gorm:"column:age" json:"age"`
  226. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  227. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  228. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  229. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  230. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  231. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  232. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  233. }
  234. func (MSchedualPatientVM) TableName() string {
  235. return "xt_patients"
  236. }
  237. type MDialysisOrderVM struct {
  238. ID int64 `gorm:"column:id" json:"id"`
  239. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  240. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  241. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  242. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  243. Stage int64 `gorm:"column:stage" json:"stage"`
  244. // Remark string `gorm:"column:remark" json:"remark"`
  245. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  246. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  247. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  248. Status int64 `gorm:"column:status" json:"status"`
  249. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  250. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  251. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  252. Creator int64 `gorm:"column:creator" json:"creator"`
  253. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  254. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  255. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  256. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  257. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  258. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  259. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  260. }
  261. func (MDialysisOrderVM) TableName() string {
  262. return "xt_dialysis_order"
  263. }
  264. type MDialysisOrderVMList struct {
  265. ID int64 `gorm:"column:id" json:"id"`
  266. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  267. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  268. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  269. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  270. Stage int64 `gorm:"column:stage" json:"stage"`
  271. // Remark string `gorm:"column:remark" json:"remark"`
  272. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  273. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  274. Status int64 `gorm:"column:status" json:"status"`
  275. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  276. Creator int64 `gorm:"column:creator" json:"creator"`
  277. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  278. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  279. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  280. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  281. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  282. }
  283. func (MDialysisOrderVMList) TableName() string {
  284. return "xt_dialysis_order"
  285. }
  286. type VMDoctorAdvice struct {
  287. ID int64 `gorm:"column:id" json:"id" form:"id"`
  288. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  289. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  290. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  291. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  292. Status int64 `gorm:"column:status" json:"status" form:"status"`
  293. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  294. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  295. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  296. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  297. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  298. }
  299. func (VMDoctorAdvice) TableName() string {
  300. return "xt_doctor_advice"
  301. }
  302. type VMHisDoctorAdviceInfo struct {
  303. ID int64 `gorm:"column:id" json:"id" form:"id"`
  304. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  305. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  306. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  307. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  308. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  309. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  310. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  311. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  312. }
  313. func (VMHisDoctorAdviceInfo) TableName() string {
  314. return "his_doctor_advice_info"
  315. }
  316. type VMAssessmentAfterDislysis struct {
  317. ID int64 `gorm:"column:id" json:"id"`
  318. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  319. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  320. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  321. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  322. Status int64 `gorm:"column:status" json:"status"`
  323. }
  324. func (VMAssessmentAfterDislysis) TableName() string {
  325. return "xt_assessment_after_dislysis"
  326. }
  327. type NewDeviceInformation struct {
  328. ID int64 `gorm:"column:id" json:"id" form:"id"`
  329. Date int64 `gorm:"column:date" json:"date" form:"date"`
  330. Class int64 `gorm:"column:class" json:"class" form:"class"`
  331. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  332. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  333. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  334. Status int64 `gorm:"column:status" json:"status" form:"status"`
  335. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  336. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  337. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  338. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  339. }
  340. func (NewDeviceInformation) TableName() string {
  341. return "xt_device_information"
  342. }
  343. // 获取透析记录
  344. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  345. var record models.DialysisOrder
  346. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  347. if err != nil {
  348. if err == gorm.ErrRecordNotFound {
  349. return nil, nil
  350. } else {
  351. return nil, err
  352. }
  353. }
  354. return &record, nil
  355. }
  356. // 用户基本信息
  357. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  358. var patient MPatient
  359. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  360. //if err != nil {
  361. // if err == gorm.ErrRecordNotFound {
  362. // return nil, nil
  363. // } else {
  364. // return nil, err
  365. // }
  366. //}
  367. //return &patient, nil
  368. redis := RedisClient()
  369. defer redis.Close()
  370. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  371. patient_info_str, _ := redis.Get(key).Result()
  372. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  373. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  374. if err != nil {
  375. if err == gorm.ErrRecordNotFound {
  376. return &patient, nil
  377. } else {
  378. return &patient, err
  379. }
  380. } else {
  381. if patient.ID > 0 {
  382. //缓存数据
  383. patient_info_json, err := json.Marshal(&patient)
  384. if err == nil {
  385. redis.Set(key, patient_info_json, time.Second*60*60*18)
  386. }
  387. }
  388. return &patient, nil
  389. }
  390. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  391. json.Unmarshal([]byte(patient_info_str), &patient)
  392. return &patient, nil
  393. }
  394. }
  395. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  396. var vm MDialysisScheduleVM
  397. err := readDb.
  398. Table("xt_schedule").
  399. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  400. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  401. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  402. First(&vm).Error
  403. return &vm, err
  404. }
  405. // 用户排班信息
  406. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  407. var vm MDialysisScheduleVM
  408. err := readDb.
  409. Table("xt_schedule").
  410. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  411. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  412. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  413. First(&vm).Error
  414. if err != nil {
  415. if err == gorm.ErrRecordNotFound {
  416. return nil, nil
  417. } else {
  418. return nil, err
  419. }
  420. }
  421. return &vm, err
  422. }
  423. // 用户排班信息
  424. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  425. redis := RedisClient()
  426. defer redis.Close()
  427. var vm MDialysisScheduleVM
  428. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  429. redis.Set(key, "", time.Second)
  430. schedual_detail_str, _ := redis.Get(key).Result()
  431. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  432. err := readDb.
  433. Table("xt_schedule").
  434. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  435. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  436. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  437. First(&vm).Error
  438. if err != nil {
  439. if err == gorm.ErrRecordNotFound {
  440. return nil, nil
  441. } else {
  442. return nil, err
  443. }
  444. } else {
  445. if vm.ID > 0 {
  446. //缓存数据
  447. schedual_detail_str, err := json.Marshal(vm)
  448. if err == nil {
  449. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  450. }
  451. } else {
  452. redis.Set(key, "null", time.Second*60*60*18)
  453. }
  454. return &vm, nil
  455. }
  456. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  457. if schedual_detail_str == "null" {
  458. return &vm, nil
  459. }
  460. json.Unmarshal([]byte(schedual_detail_str), &vm)
  461. return &vm, nil
  462. }
  463. }
  464. // 用户排班信息
  465. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  466. var schedule models.Schedule
  467. err := readDb.
  468. Table("xt_schedule").
  469. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  470. First(&schedule).Error
  471. if err != nil {
  472. if err == gorm.ErrRecordNotFound {
  473. return nil, nil
  474. } else {
  475. return nil, err
  476. }
  477. }
  478. return &schedule, nil
  479. }
  480. type MPatient struct {
  481. ID int64 `gorm:"column:id" json:"id" form:"id"`
  482. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  483. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  484. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  485. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  486. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  487. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  488. Source int64 `gorm:"column:source" json:"source" form:"source"`
  489. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  490. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  491. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  492. Name string `gorm:"column:name" json:"name" form:"name"`
  493. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  494. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  495. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  496. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  497. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  498. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  499. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  500. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  501. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  502. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  503. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  504. Height int64 `gorm:"column:height" json:"height" form:"height"`
  505. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  506. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  507. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  508. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  509. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  510. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  511. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  512. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  513. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  514. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  515. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  516. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  517. Children int64 `gorm:"column:children" json:"children" form:"children"`
  518. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  519. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  520. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  521. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  522. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  523. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  524. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  525. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  526. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  527. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  528. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  529. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  530. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  531. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  532. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  533. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  534. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  535. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  536. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  537. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  538. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  539. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  540. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  541. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  542. Status int64 `gorm:"column:status" json:"status" form:"status"`
  543. Age int64 `gorm:"column:age" json:"age"`
  544. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  545. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  546. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  547. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  548. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  549. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  550. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  551. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  552. }
  553. func (MPatient) TableName() string {
  554. return "xt_patients"
  555. }
  556. // 接诊评估
  557. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  558. var record models.ReceiveTreatmentAsses
  559. redis := RedisClient()
  560. defer redis.Close()
  561. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  562. receive_treatment_asses_str, _ := redis.Get(key).Result()
  563. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  564. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  565. if err != nil {
  566. if err == gorm.ErrRecordNotFound {
  567. if record.ID <= 0 {
  568. redis.Set(key, "", time.Second*60*60*18)
  569. }
  570. return nil, nil
  571. } else {
  572. return nil, err
  573. }
  574. } else {
  575. if record.ID > 0 {
  576. //缓存数据
  577. receive_treatment_asses_str, err := json.Marshal(record)
  578. if err == nil {
  579. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  580. }
  581. } else {
  582. redis.Set(key, "null", time.Second*60*60*18)
  583. }
  584. return &record, nil
  585. }
  586. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  587. if receive_treatment_asses_str == "null" {
  588. return &record, nil
  589. }
  590. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  591. return &record, nil
  592. }
  593. }
  594. // 透前评估
  595. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  596. var record models.PredialysisEvaluation
  597. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  598. if err != nil {
  599. if err == gorm.ErrRecordNotFound {
  600. return nil, nil
  601. } else {
  602. return nil, err
  603. }
  604. }
  605. return &record, nil
  606. }
  607. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  608. var record models.PredialysisEvaluation
  609. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  610. return record, err
  611. }
  612. // 透前评估
  613. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  614. var record models.PredialysisEvaluation
  615. redis := RedisClient()
  616. defer redis.Close()
  617. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  618. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  619. redis.Set(key, "", time.Second)
  620. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  621. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  622. if err != nil {
  623. if err == gorm.ErrRecordNotFound {
  624. if record.ID <= 0 {
  625. redis.Set(key, "", time.Second*60*60*18)
  626. }
  627. return nil, nil
  628. } else {
  629. return nil, err
  630. }
  631. } else {
  632. if record.ID > 0 {
  633. //缓存数据
  634. assessment_before_dislysis_str, err := json.Marshal(record)
  635. if err == nil {
  636. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  637. }
  638. } else {
  639. redis.Set(key, "null", time.Second*60*60*18)
  640. }
  641. return &record, nil
  642. }
  643. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  644. if assessment_before_dislysis_str == "null" {
  645. return &record, nil
  646. } else {
  647. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  648. return &record, nil
  649. }
  650. }
  651. }
  652. // 获取 maxDate 之前一次的透前评估记录
  653. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  654. var record models.PredialysisEvaluation
  655. 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
  656. if err != nil {
  657. if err == gorm.ErrRecordNotFound {
  658. return nil, nil
  659. } else {
  660. return nil, err
  661. }
  662. }
  663. return &record, nil
  664. }
  665. // 获取 maxDate 之前一次的透前评估记录
  666. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  667. var record models.PredialysisEvaluation
  668. redis := RedisClient()
  669. defer redis.Close()
  670. // cur_date := time.Now().Format("2006-01-02")
  671. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  672. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  673. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  674. 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
  675. if err != nil {
  676. if err == gorm.ErrRecordNotFound {
  677. if record.ID <= 0 {
  678. redis.Set(key, "", time.Second*60*60*18)
  679. }
  680. return nil, nil
  681. } else {
  682. return nil, err
  683. }
  684. } else {
  685. if record.ID > 0 {
  686. //缓存数据
  687. assessment_before_dislysis_last_str, err := json.Marshal(record)
  688. if err == nil {
  689. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  690. }
  691. } else {
  692. redis.Set(key, "null", time.Second*60*60*18)
  693. }
  694. return &record, nil
  695. }
  696. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  697. if assessment_before_dislysis_last_str == "null" {
  698. return &record, nil
  699. } else {
  700. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  701. return &record, nil
  702. }
  703. }
  704. }
  705. // 临时医嘱
  706. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  707. var records []*models.DoctorAdvice
  708. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  709. err := readDb.
  710. Model(&models.DoctorAdvice{}).
  711. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  712. 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").
  713. Order("start_time asc, groupno desc, advice_order desc, id").
  714. Scan(&records).Error
  715. if err != nil {
  716. return nil, err
  717. }
  718. return records, nil
  719. }
  720. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  721. var records []*models.DoctorAdvice
  722. redis := RedisClient()
  723. defer redis.Close()
  724. // cur_date := time.Now().Format("2006-01-02")
  725. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  726. fmt.Println("key23233232323323wi", key)
  727. doctor_advices_str, _ := redis.Get(key).Result()
  728. redis.Set(doctor_advices_str, "", time.Second)
  729. redis.Set(doctor_advices_str, "", time.Second)
  730. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  731. err := readDb.Model(&models.DoctorAdvice{}).
  732. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  733. 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").
  734. Order("start_time asc, groupno desc, advice_order desc, id asc").
  735. Scan(&records).Error
  736. if err != nil {
  737. if err == gorm.ErrRecordNotFound {
  738. if len(records) <= 0 {
  739. redis.Set(key, "", time.Second*60*60*18)
  740. }
  741. return nil, nil
  742. } else {
  743. return nil, err
  744. }
  745. } else {
  746. if len(records) > 0 {
  747. //缓存数据
  748. doctor_advices_str, err := json.Marshal(records)
  749. if err == nil {
  750. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  751. return records, nil
  752. }
  753. } else {
  754. redis.Set(key, "null", time.Second*60*60*18)
  755. return records, nil
  756. }
  757. return records, nil
  758. }
  759. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  760. if doctor_advices_str == "null" {
  761. return records, nil
  762. } else {
  763. json.Unmarshal([]byte(doctor_advices_str), &records)
  764. return records, nil
  765. }
  766. }
  767. }
  768. // 透析记录
  769. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  770. var record models.DialysisOrder
  771. 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
  772. if err != nil {
  773. if err == gorm.ErrRecordNotFound {
  774. return nil, nil
  775. } else {
  776. return nil, err
  777. }
  778. }
  779. return &record, nil
  780. }
  781. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  782. // var record models.DialysisOrder
  783. //
  784. // 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
  785. //
  786. //
  787. // return &record,err
  788. //}
  789. // 透析记录
  790. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  791. var record models.DialysisOrder
  792. redis := RedisClient()
  793. defer redis.Close()
  794. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  795. dialysis_order_str, _ := redis.Get(key).Result()
  796. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  797. 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
  798. if err != nil {
  799. if err == gorm.ErrRecordNotFound {
  800. return nil, nil
  801. } else {
  802. return nil, err
  803. }
  804. } else {
  805. if record.ID > 0 {
  806. //缓存数据
  807. dialysis_order_str, err := json.Marshal(record)
  808. if err == nil {
  809. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  810. }
  811. } else {
  812. redis.Set(key, "null", time.Second*60*60*18)
  813. }
  814. return &record, nil
  815. }
  816. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  817. if dialysis_order_str == "null" {
  818. 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
  819. return &record, nil
  820. } else {
  821. json.Unmarshal([]byte(dialysis_order_str), &record)
  822. return &record, nil
  823. }
  824. }
  825. }
  826. // 双人核对
  827. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  828. var record models.DoubleCheck
  829. redis := RedisClient()
  830. defer redis.Close()
  831. // cur_date := time.Now().Format("2006-01-02")
  832. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  833. double_check_str, _ := redis.Get(key).Result()
  834. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  835. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  836. if err != nil {
  837. if err == gorm.ErrRecordNotFound {
  838. if record.ID <= 0 {
  839. redis.Set(key, "null", time.Second*60*60*18)
  840. }
  841. return nil, nil
  842. } else {
  843. return nil, err
  844. }
  845. } else {
  846. if record.ID > 0 {
  847. //缓存数据
  848. double_check_str, err := json.Marshal(record)
  849. if err == nil {
  850. redis.Set(key, double_check_str, time.Second*60*60*18)
  851. }
  852. } else {
  853. redis.Set(key, "null", time.Second*60*60*18)
  854. }
  855. return &record, nil
  856. }
  857. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  858. if double_check_str == "null" {
  859. return &record, nil
  860. } else {
  861. json.Unmarshal([]byte(double_check_str), &record)
  862. return &record, nil
  863. }
  864. }
  865. }
  866. // 透析监测记录
  867. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  868. var records []*models.MonitoringRecord
  869. redis := RedisClient()
  870. defer redis.Close()
  871. // cur_date := time.Now().Format("2006-01-02")
  872. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  873. redis.Set(key, "", time.Second)
  874. monitor_records_str, _ := redis.Get(key).Result()
  875. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  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").Find(&records).Error
  877. if err != nil {
  878. if err == gorm.ErrRecordNotFound {
  879. //if len(records) <= 0 {
  880. // redis.Set(key, "null", time.Second*60*60*18)
  881. //}
  882. return nil, nil
  883. } else {
  884. return nil, err
  885. }
  886. } else {
  887. if len(records) > 0 {
  888. //缓存数据
  889. monitor_records_str, err := json.Marshal(records)
  890. if err == nil {
  891. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  892. }
  893. } else {
  894. redis.Set(key, "null", time.Second*60*60*18)
  895. }
  896. return records, nil
  897. }
  898. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  899. if monitor_records_str == "null" {
  900. return records, nil
  901. } else {
  902. json.Unmarshal([]byte(monitor_records_str), &records)
  903. return records, nil
  904. }
  905. }
  906. }
  907. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  908. var records models.MonitoringRecord
  909. 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
  910. if err != nil {
  911. return nil, err
  912. }
  913. return &records, nil
  914. }
  915. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  916. var record models.MonitoringRecord
  917. 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
  918. if err != nil {
  919. if err == gorm.ErrRecordNotFound {
  920. return nil, nil
  921. } else {
  922. return nil, err
  923. }
  924. }
  925. return &record, nil
  926. }
  927. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  928. var record models.MonitoringRecord
  929. redis := RedisClient()
  930. defer redis.Close()
  931. // cur_date := time.Now().Format("2006-01-02")
  932. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  933. monitor_record_last_str, _ := redis.Get(key).Result()
  934. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  935. 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
  936. if err != nil {
  937. if err == gorm.ErrRecordNotFound {
  938. if record.ID <= 0 {
  939. redis.Set(key, "null", time.Second*60*60*18)
  940. }
  941. return nil, nil
  942. } else {
  943. return nil, err
  944. }
  945. } else {
  946. if record.ID > 0 {
  947. //缓存数据
  948. monitor_record_last_str, err := json.Marshal(record)
  949. if err == nil {
  950. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  951. }
  952. } else {
  953. redis.Set(key, "null", time.Second*60*60*18)
  954. }
  955. return &record, nil
  956. }
  957. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  958. if monitor_record_last_str == "null" {
  959. return &record, nil
  960. } else {
  961. json.Unmarshal([]byte(monitor_record_last_str), &record)
  962. return &record, nil
  963. }
  964. }
  965. }
  966. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  967. var record models.AssessmentAfterDislysis
  968. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  969. if err != nil {
  970. if err == gorm.ErrRecordNotFound {
  971. return nil, nil
  972. } else {
  973. return nil, err
  974. }
  975. }
  976. return &record, nil
  977. }
  978. // 透后评估
  979. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  980. var record models.AssessmentAfterDislysis
  981. redis := RedisClient()
  982. defer redis.Close()
  983. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  984. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  985. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  986. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  987. if err != nil {
  988. if err == gorm.ErrRecordNotFound {
  989. if record.ID <= 0 {
  990. redis.Set(key, "null", time.Second*60*60*18)
  991. }
  992. return nil, nil
  993. } else {
  994. return nil, err
  995. }
  996. } else {
  997. if record.ID > 0 {
  998. //缓存数据
  999. assessment_after_dislysis_str, err := json.Marshal(record)
  1000. if err == nil {
  1001. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1002. }
  1003. } else {
  1004. redis.Set(key, "null", time.Second*60*60*18)
  1005. }
  1006. return &record, nil
  1007. }
  1008. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1009. if assessment_after_dislysis_str == "null" {
  1010. return &record, nil
  1011. } else {
  1012. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1013. return &record, nil
  1014. }
  1015. }
  1016. }
  1017. // 获取 maxDate 之前一次的透后评估记录
  1018. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1019. var record models.AssessmentAfterDislysis
  1020. redis := RedisClient()
  1021. defer redis.Close()
  1022. // cur_date := time.Now().Format("2006-01-02")
  1023. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1024. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1025. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  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. if record.ID <= 0 {
  1030. redis.Set(key, "null", time.Second*60*60*18)
  1031. }
  1032. return nil, nil
  1033. } else {
  1034. return nil, err
  1035. }
  1036. } else {
  1037. if record.ID > 0 {
  1038. //缓存数据
  1039. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1040. if err == nil {
  1041. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1042. }
  1043. } else {
  1044. redis.Set(key, "null", time.Second*60*60*18)
  1045. }
  1046. return &record, nil
  1047. }
  1048. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1049. if assessment_after_dislysis_last_str == "null" {
  1050. return &record, nil
  1051. } else {
  1052. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1053. return &record, nil
  1054. }
  1055. }
  1056. }
  1057. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1058. var record models.AssessmentAfterDislysis
  1059. 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
  1060. if err != nil {
  1061. if err == gorm.ErrRecordNotFound {
  1062. return nil, nil
  1063. } else {
  1064. return nil, err
  1065. }
  1066. }
  1067. return &record, nil
  1068. }
  1069. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1070. dislysis := models.AssessmentAfterDislysis{}
  1071. 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
  1072. return dislysis, err
  1073. }
  1074. // 治疗小结
  1075. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1076. var record models.TreatmentSummary
  1077. redis := RedisClient()
  1078. defer redis.Close()
  1079. // cur_date := time.Now().Format("2006-01-02")
  1080. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1081. treatment_summary_str, _ := redis.Get(key).Result()
  1082. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1083. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1084. if err != nil {
  1085. if err == gorm.ErrRecordNotFound {
  1086. if record.ID <= 0 {
  1087. redis.Set(key, "null", time.Second*60*60*18)
  1088. }
  1089. return nil, nil
  1090. } else {
  1091. return nil, err
  1092. }
  1093. } else {
  1094. if record.ID > 0 {
  1095. //缓存数据
  1096. treatment_summary_str, err := json.Marshal(record)
  1097. if err == nil {
  1098. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1099. }
  1100. } else {
  1101. redis.Set(key, "null", time.Second*60*60*18)
  1102. }
  1103. return &record, nil
  1104. }
  1105. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1106. if treatment_summary_str == "null" {
  1107. return &record, nil
  1108. } else {
  1109. json.Unmarshal([]byte(treatment_summary_str), &record)
  1110. return &record, nil
  1111. }
  1112. }
  1113. }
  1114. // 透析处方
  1115. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1116. var record models.DialysisPrescription
  1117. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1118. if err != nil {
  1119. if err == gorm.ErrRecordNotFound {
  1120. return nil, nil
  1121. } else {
  1122. return nil, err
  1123. }
  1124. }
  1125. return &record, nil
  1126. }
  1127. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1128. var schedule models.XtSchedule
  1129. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1130. if err != nil {
  1131. if err == gorm.ErrRecordNotFound {
  1132. return nil, nil
  1133. } else {
  1134. return nil, err
  1135. }
  1136. }
  1137. return &schedule, nil
  1138. }
  1139. // 透析方案
  1140. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1141. var record models.DialysisSolution
  1142. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1143. if err != nil {
  1144. if err == gorm.ErrRecordNotFound {
  1145. return nil, nil
  1146. } else {
  1147. return nil, err
  1148. }
  1149. }
  1150. return &record, nil
  1151. }
  1152. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1153. var patient models.Patients
  1154. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1155. if err != nil {
  1156. if err == gorm.ErrRecordNotFound {
  1157. return nil, nil
  1158. } else {
  1159. return nil, err
  1160. }
  1161. }
  1162. return &patient, nil
  1163. }
  1164. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1165. fmt.Println()
  1166. tx := writeDb.Begin()
  1167. updateTime := time.Now().Unix()
  1168. 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
  1169. if err != nil {
  1170. tx.Rollback()
  1171. return err
  1172. }
  1173. tx.Commit()
  1174. return nil
  1175. }
  1176. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1177. var monitor models.MonitoringRecord
  1178. var err error
  1179. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1180. if err == gorm.ErrRecordNotFound {
  1181. return nil, nil
  1182. }
  1183. if err != nil {
  1184. return nil, err
  1185. }
  1186. return &monitor, nil
  1187. }
  1188. type MScheduleDoctorAdviceVM struct {
  1189. ID int64 `gorm:"column:id" json:"id"`
  1190. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1191. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1192. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1193. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1194. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1195. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1196. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1197. Status int64 `gorm:"column:status" json:"status"`
  1198. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1199. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1200. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1201. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1202. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1203. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1204. }
  1205. func (MScheduleDoctorAdviceVM) TableName() string {
  1206. return "xt_schedule"
  1207. }
  1208. type MScheduleDoctorAdviceVMOne struct {
  1209. ID int64 `gorm:"column:id" json:"id"`
  1210. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1211. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1212. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1213. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1214. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1215. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1216. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1217. Status int64 `gorm:"column:status" json:"status"`
  1218. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1219. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1220. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1221. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1222. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1223. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1224. }
  1225. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1226. return "xt_schedule"
  1227. }
  1228. type MDoctorAdviceVM struct {
  1229. ID int64 `gorm:"column:id" json:"id"`
  1230. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1231. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1232. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1233. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1234. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1235. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1236. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1237. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1238. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1239. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1240. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1241. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1242. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1243. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1244. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1245. Status int64 `gorm:"column:status" json:"status"`
  1246. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1247. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1248. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1249. Remark string `gorm:"column:remark" json:"remark"`
  1250. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1251. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1252. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1253. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1254. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1255. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1256. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1257. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1258. Checker int64 `gorm:"column:checker" json:"checker"`
  1259. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1260. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1261. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1262. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1263. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1264. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1265. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1266. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1267. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1268. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1269. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1270. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1271. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1272. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1273. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1274. }
  1275. func (MDoctorAdviceVM) TableName() string {
  1276. return "xt_doctor_advice"
  1277. }
  1278. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1279. var vms []*MScheduleDoctorAdviceVM
  1280. adviceWhere := ""
  1281. adviceCondition := []interface{}{}
  1282. if adviceType == 0 {
  1283. if patientType == 0 {
  1284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1286. } else if patientType == 1 {
  1287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1289. } else if patientType == 2 {
  1290. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1292. }
  1293. } else if adviceType == 1 {
  1294. if patientType == 0 {
  1295. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1297. } else if patientType == 1 {
  1298. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1300. } else if patientType == 2 {
  1301. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1303. }
  1304. } else if adviceType == 3 {
  1305. if patientType == 0 {
  1306. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1308. } else if patientType == 1 {
  1309. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1311. } else if patientType == 2 {
  1312. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1314. }
  1315. } else if adviceType == 2 && len(deliverWay) > 0 {
  1316. if patientType == 0 {
  1317. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1319. } else if patientType == 1 {
  1320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1322. } else if patientType == 2 {
  1323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1325. }
  1326. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1327. if patientType == 0 {
  1328. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  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_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1333. } else if patientType == 2 {
  1334. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1336. }
  1337. }
  1338. db := readDb.
  1339. Table("xt_schedule").
  1340. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1341. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1342. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1343. }).
  1344. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1345. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1346. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1347. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1348. Preload("DoctorAdvices", adviceCondition...).
  1349. Where("status = 1 AND user_org_id = ?", orgID)
  1350. if scheduleDate != 0 {
  1351. db = db.Where("schedule_date = ?", scheduleDate)
  1352. }
  1353. err := db.Find(&vms).Error
  1354. return vms, err
  1355. }
  1356. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1357. var vms []*MScheduleDoctorAdviceVMOne
  1358. adviceWhere := ""
  1359. adviceCondition := []interface{}{}
  1360. if adviceType == 0 {
  1361. if patientType == 0 {
  1362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1364. } else if patientType == 1 {
  1365. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1367. } else if patientType == 2 {
  1368. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1369. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1370. } else if patientType == 3 {
  1371. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = 1"
  1372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1373. } else if patientType == 4 {
  1374. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and (is_settle = 0 or is_settle = 2)"
  1375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1376. }
  1377. } else if adviceType == 1 {
  1378. if patientType == 0 {
  1379. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1381. } else if patientType == 1 {
  1382. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1384. } else if patientType == 2 {
  1385. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1387. } else if patientType == 3 {
  1388. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1390. } else if patientType == 4 {
  1391. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1393. }
  1394. } else if adviceType == 3 {
  1395. if patientType == 0 {
  1396. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1398. } else if patientType == 1 {
  1399. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1401. } else if patientType == 2 {
  1402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1404. } else if patientType == 3 {
  1405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1407. } else if patientType == 4 {
  1408. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1410. }
  1411. } else if adviceType == 2 && len(deliverWay) > 0 {
  1412. if patientType == 0 {
  1413. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1415. } else if patientType == 1 {
  1416. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1418. } else if patientType == 2 {
  1419. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1421. } else if patientType == 3 {
  1422. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1424. } else if patientType == 4 {
  1425. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and (is_settle = 0 or is_settle =2)"
  1426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1427. }
  1428. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1429. if patientType == 0 {
  1430. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1432. } else if patientType == 1 {
  1433. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1435. } else if patientType == 2 {
  1436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1438. } else if patientType == 3 {
  1439. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1441. } else if patientType == 4 {
  1442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1444. }
  1445. }
  1446. db := readDb.
  1447. Table("xt_schedule").
  1448. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1449. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1450. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1451. //}).
  1452. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1453. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1454. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1455. Preload("DoctorAdvices", adviceCondition...).
  1456. Where("status = 1 AND user_org_id = ?", orgID)
  1457. if scheduleDate != 0 {
  1458. db = db.Where("schedule_date = ?", scheduleDate)
  1459. }
  1460. err := db.Find(&vms).Error
  1461. return vms, err
  1462. }
  1463. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1464. var vms []*HisMScheduleDoctorAdviceVM
  1465. if len(deliverWay) > 0 {
  1466. if patientType == 0 {
  1467. db := readDb.
  1468. Table("xt_schedule").
  1469. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1470. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1471. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1472. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1473. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1474. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1475. }).
  1476. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1477. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1478. Where("status = 1 AND user_org_id = ?", orgID)
  1479. if scheduleDate != 0 {
  1480. db = db.Where("schedule_date = ?", scheduleDate)
  1481. }
  1482. err = db.Find(&vms).Error
  1483. }
  1484. if patientType > 0 {
  1485. db := readDb.
  1486. Table("xt_schedule").
  1487. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1488. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1489. 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).
  1490. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1491. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1492. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1493. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1494. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1495. }).Where("status = 1 AND user_org_id = ?", orgID)
  1496. if scheduleDate != 0 {
  1497. db = db.Where("schedule_date = ?", scheduleDate)
  1498. }
  1499. err = db.Find(&vms).Error
  1500. }
  1501. } else {
  1502. if patientType == 0 {
  1503. db := readDb.
  1504. Table("xt_schedule").
  1505. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1506. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1507. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1508. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1509. }).
  1510. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1511. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1512. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1513. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1514. Where("status = 1 AND user_org_id = ?", orgID)
  1515. if scheduleDate != 0 {
  1516. db = db.Where("schedule_date = ?", scheduleDate)
  1517. }
  1518. err = db.Find(&vms).Error
  1519. }
  1520. if patientType > 0 {
  1521. db := readDb.
  1522. Table("xt_schedule").
  1523. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1524. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1525. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1526. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1527. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1528. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1529. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1530. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1531. Where("status = 1 AND user_org_id = ?", orgID)
  1532. if scheduleDate != 0 {
  1533. db = db.Where("schedule_date = ?", scheduleDate)
  1534. }
  1535. err = db.Find(&vms).Error
  1536. }
  1537. }
  1538. return vms, err
  1539. }
  1540. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1541. var vms []*HisMScheduleDoctorAdviceVMOne
  1542. if len(deliverWay) > 0 {
  1543. if patientType == 0 {
  1544. db := readDb.
  1545. Table("xt_schedule").
  1546. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1547. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1548. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1549. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1550. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1551. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1552. }).
  1553. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1554. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1555. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1556. Where("status = 1 AND user_org_id = ?", orgID)
  1557. if scheduleDate != 0 {
  1558. db = db.Where("schedule_date = ?", scheduleDate)
  1559. }
  1560. err = db.Find(&vms).Error
  1561. }
  1562. if patientType > 0 {
  1563. if patientType == 1 {
  1564. db := readDb.
  1565. Table("xt_schedule").
  1566. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1567. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1568. 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).
  1569. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1570. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1571. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1572. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1573. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1574. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1575. Where("status = 1 AND user_org_id = ?", orgID)
  1576. if scheduleDate != 0 {
  1577. db = db.Where("schedule_date = ?", scheduleDate)
  1578. }
  1579. err = db.Find(&vms).Error
  1580. }
  1581. if patientType == 2 {
  1582. db := readDb.
  1583. Table("xt_schedule").
  1584. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1585. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1586. 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).
  1587. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1588. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1589. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1590. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1591. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1592. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1593. if scheduleDate != 0 {
  1594. db = db.Where("schedule_date = ?", scheduleDate)
  1595. }
  1596. err = db.Find(&vms).Error
  1597. }
  1598. if patientType == 3 {
  1599. db := readDb.
  1600. Table("xt_schedule").
  1601. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1602. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1603. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) and is_settle = 1", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1604. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1605. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1606. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1607. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1608. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1609. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1610. if scheduleDate != 0 {
  1611. db = db.Where("schedule_date = ?", scheduleDate)
  1612. }
  1613. err = db.Find(&vms).Error
  1614. }
  1615. if patientType == 4 {
  1616. db := readDb.
  1617. Table("xt_schedule").
  1618. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1619. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1620. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) and (is_settle = 0 or is_settle = 2)", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1621. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1622. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1623. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1624. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1625. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1626. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1627. if scheduleDate != 0 {
  1628. db = db.Where("schedule_date = ?", scheduleDate)
  1629. }
  1630. err = db.Find(&vms).Error
  1631. }
  1632. }
  1633. } else {
  1634. if patientType == 0 {
  1635. db := readDb.
  1636. Table("xt_schedule").
  1637. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1638. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1639. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1640. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1641. }).
  1642. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1643. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1644. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1645. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1646. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1647. Where("status = 1 AND user_org_id = ?", orgID)
  1648. if scheduleDate != 0 {
  1649. db = db.Where("schedule_date = ?", scheduleDate)
  1650. }
  1651. err = db.Find(&vms).Error
  1652. }
  1653. if patientType > 0 {
  1654. if patientType == 1 {
  1655. db := readDb.
  1656. Table("xt_schedule").
  1657. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1658. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1659. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1660. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1661. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1662. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1663. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1664. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1665. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1666. Where("status = 1 AND user_org_id = ?", orgID)
  1667. if scheduleDate != 0 {
  1668. db = db.Where("schedule_date = ?", scheduleDate)
  1669. }
  1670. err = db.Find(&vms).Error
  1671. }
  1672. if patientType == 2 {
  1673. db := readDb.
  1674. Table("xt_schedule").
  1675. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1676. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1677. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1678. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1679. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1680. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1681. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1682. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1683. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1684. Where("status = 1 AND user_org_id = ?", orgID)
  1685. if scheduleDate != 0 {
  1686. db = db.Where("schedule_date = ?", scheduleDate)
  1687. }
  1688. err = db.Find(&vms).Error
  1689. }
  1690. if patientType == 3 {
  1691. db := readDb.
  1692. Table("xt_schedule").
  1693. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1694. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) and is_settle = 1", orgID, scheduleDate, adminUserId, adminUserId).
  1695. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1696. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1697. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1698. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1699. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1700. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1701. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1702. Where("status = 1 AND user_org_id = ?", orgID)
  1703. if scheduleDate != 0 {
  1704. db = db.Where("schedule_date = ?", scheduleDate)
  1705. }
  1706. err = db.Find(&vms).Error
  1707. }
  1708. if patientType == 4 {
  1709. db := readDb.
  1710. Table("xt_schedule").
  1711. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1712. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) and (is_settle = 0 or is_settle =2) ", orgID, scheduleDate, adminUserId, adminUserId).
  1713. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1714. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1715. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1716. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1717. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1718. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1719. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1720. Where("status = 1 AND user_org_id = ?", orgID)
  1721. if scheduleDate != 0 {
  1722. db = db.Where("schedule_date = ?", scheduleDate)
  1723. }
  1724. err = db.Find(&vms).Error
  1725. }
  1726. }
  1727. }
  1728. return vms, err
  1729. }
  1730. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1731. var vms []*HisMScheduleProjectVM
  1732. //if patientType == 0 {
  1733. // db := readDb.
  1734. // Table("xt_schedule").
  1735. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1736. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1737. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1738. // }).
  1739. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1740. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1741. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1742. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1743. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1744. // }).
  1745. // Where("status = 1 AND user_org_id = ?", orgID)
  1746. // if scheduleDate != 0 {
  1747. // db = db.Where("schedule_date = ?", scheduleDate)
  1748. // }
  1749. // err = db.Find(&vms).Error
  1750. //}
  1751. //if patientType > 0 {
  1752. // db := readDb.
  1753. // Table("xt_schedule").
  1754. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1755. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1756. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1757. // }).
  1758. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1759. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1760. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1761. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1762. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1763. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1764. // }).
  1765. // Where("status = 1 AND user_org_id = ?", orgID)
  1766. // if scheduleDate != 0 {
  1767. // db = db.Where("schedule_date = ?", scheduleDate)
  1768. // }
  1769. // err = db.Find(&vms).Error
  1770. //}
  1771. db := readDb.Table("xt_schedule").Where("status = 1")
  1772. if orgID > 0 {
  1773. db = db.Where("user_org_id = ?", orgID)
  1774. }
  1775. if scheduleDate > 0 {
  1776. db = db.Where("schedule_date =?", scheduleDate)
  1777. }
  1778. err = db.Find(&vms).Error
  1779. if patientType == 0 {
  1780. db := readDb.
  1781. Table("xt_schedule").
  1782. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1783. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1784. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1785. }).
  1786. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1787. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1788. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1789. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1790. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1791. }).
  1792. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1793. 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")
  1794. }).
  1795. Where("status = 1 AND user_org_id = ?", orgID)
  1796. if scheduleDate != 0 {
  1797. db = db.Where("schedule_date = ?", scheduleDate)
  1798. }
  1799. err = db.Find(&vms).Error
  1800. }
  1801. if patientType > 0 {
  1802. db := readDb.
  1803. Table("xt_schedule").
  1804. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1805. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1806. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1807. }).
  1808. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1809. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1810. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1811. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1812. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1813. }).
  1814. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1815. 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")
  1816. }).
  1817. Where("status = 1 AND user_org_id = ?", orgID)
  1818. if scheduleDate != 0 {
  1819. db = db.Where("schedule_date = ?", scheduleDate)
  1820. }
  1821. err = db.Find(&vms).Error
  1822. }
  1823. return vms, err
  1824. }
  1825. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1826. now := time.Now()
  1827. tx := writeDb.Begin()
  1828. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1829. tx.Rollback()
  1830. return createOrderErr
  1831. }
  1832. // 更新透析记录 ID
  1833. // 透析处方
  1834. 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 {
  1835. tx.Rollback()
  1836. return err
  1837. }
  1838. // 接诊评估
  1839. 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 {
  1840. tx.Rollback()
  1841. return err
  1842. }
  1843. // 透前评估
  1844. 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 {
  1845. tx.Rollback()
  1846. return err
  1847. }
  1848. // 临时医嘱
  1849. 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 {
  1850. tx.Rollback()
  1851. return err
  1852. }
  1853. // 双人核对
  1854. 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 {
  1855. tx.Rollback()
  1856. return err
  1857. }
  1858. // 透后评估
  1859. 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 {
  1860. tx.Rollback()
  1861. return err
  1862. }
  1863. // 治疗小结
  1864. 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 {
  1865. tx.Rollback()
  1866. return err
  1867. }
  1868. // 透析监测
  1869. 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 {
  1870. tx.Rollback()
  1871. return err
  1872. }
  1873. tx.Commit()
  1874. return nil
  1875. }
  1876. type MobileUrgentSchedulePatientVM struct {
  1877. ID int64 `gorm:"column:id" json:"id"`
  1878. Name string `gorm:"column:name" json:"name"`
  1879. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1880. }
  1881. func (MobileUrgentSchedulePatientVM) TableName() string {
  1882. return "xt_patients"
  1883. }
  1884. type MobileUrgentScheduleTreatmentModeVM struct {
  1885. ID int64 `gorm:"column:id" json:"id"`
  1886. Name string `gorm:"column:name" json:"name"`
  1887. }
  1888. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1889. return "xt_treatment_mode"
  1890. }
  1891. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1892. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1893. 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()
  1894. defer rows.Close()
  1895. if err != nil {
  1896. return nil, err
  1897. }
  1898. for rows.Next() {
  1899. var vm MobileUrgentSchedulePatientVM
  1900. readDb.ScanRows(rows, &vm)
  1901. vms = append(vms, &vm)
  1902. }
  1903. return vms, nil
  1904. }
  1905. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1906. var modes []*MobileUrgentScheduleTreatmentModeVM
  1907. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1908. if err != nil {
  1909. return nil, err
  1910. }
  1911. return modes, nil
  1912. }
  1913. type MobileUrgentScheduleScheduleListVM struct {
  1914. ID int64 `gorm:"column:id" json:"id"`
  1915. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1916. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1917. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1918. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1919. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1920. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1921. }
  1922. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1923. return "xt_schedule"
  1924. }
  1925. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1926. db := readDb.
  1927. Model(&MobileUrgentScheduleScheduleListVM{}).
  1928. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1929. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1930. err = db.Find(&schedules).Error
  1931. if err != nil {
  1932. return nil, err
  1933. }
  1934. return schedules, nil
  1935. }
  1936. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1937. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1938. 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()
  1939. defer rows.Close()
  1940. if err != nil {
  1941. return nil, err
  1942. }
  1943. for rows.Next() {
  1944. var vm MobileUrgentScheduleScheduleListVM
  1945. readDb.ScanRows(rows, &vm)
  1946. vms = append(vms, &vm)
  1947. }
  1948. return vms, nil
  1949. }
  1950. type MobileUrgentScheduleDeviceNumberVM struct {
  1951. ID int64 `gorm:"column:id" json:"id"`
  1952. Number string `gorm:"column:number" json:"number"`
  1953. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1954. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1955. }
  1956. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1957. return "xt_device_number"
  1958. }
  1959. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1960. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1961. 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()
  1962. defer rows.Close()
  1963. if err != nil {
  1964. return nil, err
  1965. }
  1966. for rows.Next() {
  1967. var vm DeviceNumberViewModel
  1968. readDb.ScanRows(rows, &vm)
  1969. vms = append(vms, &vm)
  1970. }
  1971. return vms, nil
  1972. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1973. //db := readDb.
  1974. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1975. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1976. // Where("status = 1 AND org_id = ?", orgID)
  1977. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1978. //if err != nil {
  1979. // return nil, err
  1980. //}
  1981. //return deviceNumbers, nil
  1982. }
  1983. func GetValidScheduleMonitorRecordCount() (int64, error) {
  1984. var total int64
  1985. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  1986. return total, err
  1987. }
  1988. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  1989. var monitors []*models.MonitoringRecord
  1990. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  1991. if err != nil {
  1992. return nil, err
  1993. }
  1994. return monitors, nil
  1995. }
  1996. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  1997. tx := writeDb.Begin()
  1998. for index := 0; index < len(monitors); index++ {
  1999. tx.Save(monitors[index])
  2000. }
  2001. return tx.Commit().Error
  2002. }
  2003. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2004. tx := writeDb.Begin()
  2005. updateTime := time.Now().Unix()
  2006. 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, "schedule_remark": order.ScheduleRemark, "order_remark": order.OrderRemark}).Error
  2007. if err != nil {
  2008. tx.Rollback()
  2009. return err
  2010. }
  2011. tx.Commit()
  2012. return err
  2013. }
  2014. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2015. tx := writeDb.Begin()
  2016. updateTime := time.Now().Unix()
  2017. 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
  2018. if err != nil {
  2019. tx.Rollback()
  2020. return err
  2021. }
  2022. tx.Commit()
  2023. return err
  2024. }
  2025. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2026. var record models.SgjPatientDryweight
  2027. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2028. if err != nil {
  2029. if err == gorm.ErrRecordNotFound {
  2030. return nil, nil
  2031. } else {
  2032. return nil, err
  2033. }
  2034. }
  2035. return &record, nil
  2036. }
  2037. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2038. // var record models.SgjPatientDryweight
  2039. // redis := RedisClient()
  2040. // defer redis.Close()
  2041. //
  2042. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2043. // last_dry_weight_str, _ := redis.Get(key).Result()
  2044. //
  2045. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2046. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2047. // if err != nil {
  2048. // if err == gorm.ErrRecordNotFound {
  2049. // if record.ID <= 0 {
  2050. // redis.Set(key, "null", time.Second*60*60*18)
  2051. // }
  2052. // return nil, nil
  2053. // } else {
  2054. // return nil, err
  2055. // }
  2056. // } else {
  2057. // if record.ID > 0 {
  2058. // //缓存数据
  2059. // last_dry_weight_str, err := json.Marshal(record)
  2060. // if err == nil {
  2061. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2062. // return nil, err
  2063. // }
  2064. // } else {
  2065. // redis.Set(key, "null", time.Second*60*60*18)
  2066. // return nil, err
  2067. // }
  2068. // return &record, nil
  2069. // }
  2070. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2071. // if last_dry_weight_str == "null" {
  2072. // return &record, nil
  2073. // } else {
  2074. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2075. // return &record, nil
  2076. // }
  2077. //
  2078. // }
  2079. //}
  2080. // 透析方案
  2081. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2082. var record models.DialysisSolution
  2083. 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
  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. // 透析方案
  2094. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2095. var record models.DialysisSolution
  2096. redis := RedisClient()
  2097. defer redis.Close()
  2098. // cur_date := time.Now().Format("2006-01-02")
  2099. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2100. dialysis_solution_str, _ := redis.Get(key).Result()
  2101. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2102. 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
  2103. if err != nil {
  2104. if err == gorm.ErrRecordNotFound {
  2105. if record.ID <= 0 {
  2106. redis.Set(key, "null", time.Second*60*60*18)
  2107. }
  2108. return nil, nil
  2109. } else {
  2110. return nil, err
  2111. }
  2112. } else {
  2113. if record.ID > 0 {
  2114. //缓存数据
  2115. dialysis_solution_str, err := json.Marshal(record)
  2116. if err == nil {
  2117. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2118. }
  2119. } else {
  2120. redis.Set(key, "null", time.Second*60*60*18)
  2121. }
  2122. return &record, nil
  2123. }
  2124. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2125. if dialysis_solution_str == "null" {
  2126. return &record, nil
  2127. } else {
  2128. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2129. return &record, nil
  2130. }
  2131. }
  2132. }
  2133. // 透析处方
  2134. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2135. var record models.DialysisPrescription
  2136. redis := RedisClient()
  2137. defer redis.Close()
  2138. // cur_date := time.Now().Format("2006-01-02")
  2139. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2140. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2141. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2142. 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
  2143. if err != nil {
  2144. if err == gorm.ErrRecordNotFound {
  2145. if record.ID <= 0 {
  2146. redis.Set(key, "null", time.Second*60*60*18)
  2147. }
  2148. return nil, nil
  2149. } else {
  2150. return nil, err
  2151. }
  2152. } else {
  2153. if record.ID > 0 {
  2154. //缓存数据
  2155. dialysis_prescribe_str, err := json.Marshal(record)
  2156. if err == nil {
  2157. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2158. }
  2159. } else {
  2160. redis.Set(key, "null", time.Second*60*60*18)
  2161. }
  2162. return &record, nil
  2163. }
  2164. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2165. if dialysis_prescribe_str == "null" {
  2166. return &record, nil
  2167. } else {
  2168. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2169. return &record, nil
  2170. }
  2171. }
  2172. }
  2173. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2174. var record models.DialysisPrescription
  2175. 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
  2176. if err != nil {
  2177. if err == gorm.ErrRecordNotFound {
  2178. return nil, nil
  2179. } else {
  2180. return nil, err
  2181. }
  2182. }
  2183. return &record, nil
  2184. }
  2185. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2186. var record models.DialysisPrescription
  2187. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2188. if err != nil {
  2189. if err == gorm.ErrRecordNotFound {
  2190. return nil, nil
  2191. } else {
  2192. return nil, err
  2193. }
  2194. }
  2195. return &record, nil
  2196. }
  2197. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2198. // var record models.DialysisPrescription
  2199. // redis := RedisClient()
  2200. // defer redis.Close()
  2201. //
  2202. // // cur_date := time.Now().Format("2006-01-02")
  2203. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2204. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2205. //
  2206. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2207. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2208. // if err != nil {
  2209. // if err == gorm.ErrRecordNotFound {
  2210. // if record.ID <= 0 {
  2211. // redis.Set(key, "null", time.Second*60*60*18)
  2212. // }
  2213. // return nil, nil
  2214. // } else {
  2215. // return nil, err
  2216. // }
  2217. // } else {
  2218. //
  2219. // if record.ID > 0 {
  2220. // //缓存数据
  2221. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2222. //
  2223. // if err == nil {
  2224. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2225. // return nil, err
  2226. // }
  2227. // } else {
  2228. // redis.Set(key, "null", time.Second*60*60*18)
  2229. // return nil, err
  2230. // }
  2231. // return &record, nil
  2232. // }
  2233. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2234. // if dialysis_prescribe_by_mode_str == "null" {
  2235. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2236. // return &record, nil
  2237. // } else {
  2238. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2239. // return &record, nil
  2240. // }
  2241. //
  2242. // }
  2243. //}
  2244. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2245. var record models.DialysisPrescription
  2246. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2247. if err != nil {
  2248. if err == gorm.ErrRecordNotFound {
  2249. return nil, nil
  2250. } else {
  2251. return nil, err
  2252. }
  2253. }
  2254. return &record, nil
  2255. }
  2256. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2257. var record models.DialysisPrescription
  2258. 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
  2259. if err != nil {
  2260. if err == gorm.ErrRecordNotFound {
  2261. return nil, nil
  2262. } else {
  2263. return nil, err
  2264. }
  2265. }
  2266. return &record, nil
  2267. }
  2268. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2269. var record models.DialysisPrescription
  2270. redis := RedisClient()
  2271. defer redis.Close()
  2272. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2273. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2274. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2275. 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
  2276. if err != nil {
  2277. if err == gorm.ErrRecordNotFound {
  2278. if record.ID <= 0 {
  2279. redis.Set(key, "null", time.Second*60*60*18)
  2280. }
  2281. return nil, nil
  2282. } else {
  2283. return nil, err
  2284. }
  2285. } else {
  2286. if record.ID > 0 {
  2287. //缓存数据
  2288. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2289. if err == nil {
  2290. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2291. return nil, err
  2292. }
  2293. } else {
  2294. redis.Set(key, "null", time.Second*60*60*18)
  2295. return nil, err
  2296. }
  2297. return &record, nil
  2298. }
  2299. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2300. if dialysis_prescribe_by_mode_id == "null" {
  2301. return &record, nil
  2302. } else {
  2303. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2304. return &record, nil
  2305. }
  2306. }
  2307. }
  2308. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2309. var record models.DialysisPrescription
  2310. 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
  2311. return record, err
  2312. }
  2313. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2314. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2315. 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()
  2316. defer rows.Close()
  2317. if err != nil {
  2318. return nil, err
  2319. }
  2320. for rows.Next() {
  2321. var vm DeviceNumberViewModel
  2322. readDb.ScanRows(rows, &vm)
  2323. vms = append(vms, &vm)
  2324. }
  2325. return vms, nil
  2326. }
  2327. // 获取 maxDate 之前一次的透前评估记录
  2328. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2329. var record models.PredialysisEvaluation
  2330. 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
  2331. if err != nil {
  2332. if err == gorm.ErrRecordNotFound {
  2333. return nil, nil
  2334. } else {
  2335. return nil, err
  2336. }
  2337. }
  2338. return &record, nil
  2339. }
  2340. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2341. var record models.DialysisOrder
  2342. 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
  2343. if err != nil {
  2344. if err == gorm.ErrRecordNotFound {
  2345. return nil, nil
  2346. } else {
  2347. return nil, err
  2348. }
  2349. }
  2350. return &record, nil
  2351. }
  2352. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2353. var record models.MonitoringRecord
  2354. 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
  2355. if err != nil {
  2356. if err == gorm.ErrRecordNotFound {
  2357. return nil, nil
  2358. } else {
  2359. return nil, err
  2360. }
  2361. }
  2362. return &record, nil
  2363. }
  2364. // 获取 maxDate 之前一次的透后评估记录
  2365. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2366. var record models.AssessmentAfterDislysis
  2367. 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
  2368. if err != nil {
  2369. if err == gorm.ErrRecordNotFound {
  2370. return nil, nil
  2371. } else {
  2372. return nil, err
  2373. }
  2374. }
  2375. return &record, nil
  2376. }
  2377. // 透析处方
  2378. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2379. var record models.DialysisPrescription
  2380. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2381. if err != nil {
  2382. if err == gorm.ErrRecordNotFound {
  2383. return nil, nil
  2384. } else {
  2385. return nil, err
  2386. }
  2387. }
  2388. return &record, nil
  2389. }
  2390. // 透析方案
  2391. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2392. var record models.DialysisSolution
  2393. 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
  2394. if err != nil {
  2395. if err == gorm.ErrRecordNotFound {
  2396. return nil, nil
  2397. } else {
  2398. return nil, err
  2399. }
  2400. }
  2401. return &record, nil
  2402. }
  2403. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2404. var record models.DialysisSolution
  2405. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2406. if err != nil {
  2407. if err == gorm.ErrRecordNotFound {
  2408. return nil, nil
  2409. } else {
  2410. return nil, err
  2411. }
  2412. }
  2413. return &record, nil
  2414. }
  2415. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2416. var record models.DialysisPrescription
  2417. 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
  2418. if err != nil {
  2419. if err == gorm.ErrRecordNotFound {
  2420. return nil, nil
  2421. } else {
  2422. return nil, err
  2423. }
  2424. }
  2425. return &record, nil
  2426. }
  2427. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2428. var record models.SgjPatientDryweight
  2429. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2430. if err != nil {
  2431. if err == gorm.ErrRecordNotFound {
  2432. return nil, nil
  2433. } else {
  2434. return nil, err
  2435. }
  2436. }
  2437. return &record, nil
  2438. }
  2439. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2440. var record models.SystemPrescription
  2441. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2442. if err != nil {
  2443. if err == gorm.ErrRecordNotFound {
  2444. return nil, nil
  2445. } else {
  2446. return nil, err
  2447. }
  2448. }
  2449. return &record, nil
  2450. }
  2451. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2452. var record models.SystemPrescription
  2453. redis := RedisClient()
  2454. defer redis.Close()
  2455. // cur_date := time.Now().Format("2006-01-02")
  2456. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2457. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2458. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2459. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2460. if err != nil {
  2461. if err == gorm.ErrRecordNotFound {
  2462. if record.ID <= 0 {
  2463. redis.Set(key, "null", time.Second*60*60*18)
  2464. }
  2465. return nil, nil
  2466. } else {
  2467. return nil, err
  2468. }
  2469. } else {
  2470. if record.ID > 0 {
  2471. //缓存数据
  2472. system_dialysis_prescribe_str, err := json.Marshal(record)
  2473. if err == nil {
  2474. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2475. }
  2476. } else {
  2477. redis.Set(key, "null", time.Second*60*60*18)
  2478. }
  2479. return &record, nil
  2480. }
  2481. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2482. if system_dialysis_prescribe_str == "null" {
  2483. return &record, nil
  2484. } else {
  2485. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2486. return &record, nil
  2487. }
  2488. }
  2489. }
  2490. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2491. var record models.SystemPrescription
  2492. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2493. return record, err
  2494. }
  2495. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2496. var record models.SystemPrescription
  2497. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2498. if err != nil {
  2499. if err == gorm.ErrRecordNotFound {
  2500. return nil, nil
  2501. } else {
  2502. return nil, err
  2503. }
  2504. }
  2505. return &record, nil
  2506. }
  2507. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2508. 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
  2509. return
  2510. }
  2511. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2512. 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
  2513. return
  2514. }
  2515. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2516. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1672502400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2517. return
  2518. }
  2519. func GetFirstDateOfMonth(d time.Time) time.Time {
  2520. d = d.AddDate(0, 0, -d.Day()+1)
  2521. return GetZeroTime(d)
  2522. }
  2523. func GetZeroTime(d time.Time) time.Time {
  2524. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2525. }
  2526. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2527. db := XTReadDB().Table("xt_dialysis_order as o")
  2528. 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
  2529. return order, err
  2530. }
  2531. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2532. 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
  2533. return
  2534. }
  2535. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2536. 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
  2537. return
  2538. }
  2539. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2540. 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
  2541. return
  2542. }
  2543. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2544. // 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
  2545. // return
  2546. //}
  2547. //
  2548. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2549. 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
  2550. return
  2551. }
  2552. type GoodsType struct {
  2553. ID int64 `gorm:"column:id" json:"id"`
  2554. TypeName string `gorm:"column:type_name" json:"type_name"`
  2555. Remark string `gorm:"column:remark" json:"remark"`
  2556. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2557. Status int64 `gorm:"column:status" json:"status"`
  2558. Type int64 `gorm:"column:type" json:"type"`
  2559. }
  2560. func (GoodsType) TableName() string {
  2561. return "xt_goods_type"
  2562. }
  2563. type VMGoodInfo struct {
  2564. ID int64 `gorm:"column:id" json:"id"`
  2565. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2566. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2567. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2568. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2569. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2570. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2571. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2572. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2573. }
  2574. func (VMGoodInfo) TableName() string {
  2575. return "xt_good_information"
  2576. }
  2577. type AutomaticReduceDetail struct {
  2578. ID int64 `gorm:"column:id" json:"id"`
  2579. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2580. Status int64 `gorm:"column:status" json:"status"`
  2581. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2582. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2583. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2584. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2585. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2586. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2587. Count int64 `gorm:"column:count" json:"count"`
  2588. }
  2589. func (AutomaticReduceDetail) TableName() string {
  2590. return "xt_automatic_reduce_detail"
  2591. }
  2592. type DialysisBeforePrepare struct {
  2593. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2594. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2595. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2596. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2597. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2598. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2599. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2600. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2601. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2602. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2603. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2604. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2605. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2606. }
  2607. func (DialysisBeforePrepare) TableName() string {
  2608. return "dialysis_before_prepare"
  2609. }
  2610. type MDialysisGoodsVM struct {
  2611. ID int64 `gorm:"column:id" json:"id"`
  2612. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2613. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2614. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2615. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2616. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2617. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2618. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2619. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2620. Status int64 `gorm:"column:status" json:"status"`
  2621. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2622. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2623. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2624. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2625. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2626. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2627. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2628. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2629. }
  2630. func (MDialysisGoodsVM) TableName() string {
  2631. return "xt_schedule"
  2632. }
  2633. type VMWarehouseOutInfo struct {
  2634. ID int64 `gorm:"column:id" json:"id"`
  2635. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2636. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2637. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2638. Count int64 `gorm:"column:count" json:"count"`
  2639. Price float64 `gorm:"column:price" json:"price"`
  2640. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2641. Status int64 `gorm:"column:status" json:"status"`
  2642. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2643. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2644. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2645. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2646. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2647. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2648. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2649. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2650. }
  2651. func (VMWarehouseOutInfo) TableName() string {
  2652. return "xt_warehouse_out_info"
  2653. }
  2654. type DialysisGoodsDate struct {
  2655. RecordDate int64
  2656. }
  2657. type DialysisGoodsDetailDate struct {
  2658. RecordTime int64
  2659. }
  2660. 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) {
  2661. var vms []*MDialysisGoodsVM
  2662. var total int64
  2663. db := readDb.
  2664. Table("xt_schedule as sch").
  2665. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2666. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2667. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2668. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2669. 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)
  2670. }).
  2671. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2672. 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")
  2673. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2674. if scheduleDate != 0 {
  2675. db = db.Where("schedule_date = ?", scheduleDate)
  2676. }
  2677. if schedule_type != 0 {
  2678. db = db.Where("schedule_type = ?", schedule_type)
  2679. }
  2680. if partition_id != 0 {
  2681. db = db.Where("partition_id = ?", partition_id)
  2682. }
  2683. if patient_id != 0 {
  2684. db = db.Where("patient_id = ?", patient_id)
  2685. }
  2686. err := db.Find(&vms).Error
  2687. return vms, err, total
  2688. }
  2689. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2690. var Id []*DialysisGoodsDetailDate
  2691. 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
  2692. if len(Id) > 0 {
  2693. 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
  2694. }
  2695. return
  2696. }
  2697. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2698. var Id []*DialysisGoodsDate
  2699. 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
  2700. if len(Id) > 0 {
  2701. 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
  2702. }
  2703. return
  2704. }
  2705. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2706. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2707. return info, err
  2708. }
  2709. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2710. db := readDb.Model(&models.StockInfo{})
  2711. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2712. 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")
  2713. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2714. 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)
  2715. })
  2716. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2717. err = db.Order("ctime desc").Find(&list).Error
  2718. return
  2719. }
  2720. 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) {
  2721. var vms []*MDialysisGoodsVM
  2722. var total int64
  2723. db := readDb.
  2724. Model(&models.Schedule{}).
  2725. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2726. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2727. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2728. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2729. 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)
  2730. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2731. 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)
  2732. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2733. if scheduleDate != 0 {
  2734. db = db.Where("schedule_date = ?", scheduleDate)
  2735. }
  2736. if patient_id != 0 {
  2737. db = db.Where("patient_id = ?", patient_id)
  2738. }
  2739. if len(keywords) != 0 {
  2740. keywords = "%" + keywords + "%"
  2741. 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)
  2742. if schedule_type != 0 {
  2743. db = db.Where("schedule_type = ?", schedule_type)
  2744. }
  2745. if partition_id != 0 {
  2746. db = db.Where("partition_id = ?", partition_id)
  2747. }
  2748. if good_type == 1 {
  2749. db = db.Where("patient_id in(?)", ids)
  2750. }
  2751. if good_type == 2 {
  2752. if len(ids) > 0 {
  2753. db = db.Where("patient_id not in(?)", ids)
  2754. }
  2755. }
  2756. } else {
  2757. if schedule_type != 0 {
  2758. db = db.Where("schedule_type = ?", schedule_type)
  2759. }
  2760. if partition_id != 0 {
  2761. db = db.Where("partition_id = ?", partition_id)
  2762. }
  2763. if good_type == 1 {
  2764. db = db.Where("patient_id in(?)", ids)
  2765. }
  2766. if good_type == 2 {
  2767. if len(ids) > 0 {
  2768. db = db.Where("patient_id not in(?)", ids)
  2769. }
  2770. }
  2771. db = db.Count(&total)
  2772. offset := (page - 1) * limit
  2773. db = db.Offset(offset).Limit(limit)
  2774. }
  2775. err := db.Find(&vms).Error
  2776. return vms, err, total
  2777. }
  2778. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2779. var Id []*DialysisGoodsDetailDate
  2780. 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
  2781. if len(Id) > 0 {
  2782. 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
  2783. }
  2784. return
  2785. }
  2786. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2787. var Id []*DialysisGoodsDate
  2788. 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
  2789. if len(Id) > 0 {
  2790. 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
  2791. }
  2792. return
  2793. }
  2794. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2795. evaluation := models.PredialysisEvaluation{}
  2796. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2797. if err == gorm.ErrRecordNotFound {
  2798. return nil, err
  2799. }
  2800. if err != nil {
  2801. return nil, err
  2802. }
  2803. return &evaluation, nil
  2804. }
  2805. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2806. evaluation := models.PredialysisEvaluation{}
  2807. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2808. return evaluation, err
  2809. }
  2810. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2811. redis := RedisClient()
  2812. defer redis.Close()
  2813. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2814. his_doctor_advice_str, _ := redis.Get(key).Result()
  2815. redis.Set(key, "", time.Second)
  2816. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2817. 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
  2818. if err != nil {
  2819. if err == gorm.ErrRecordNotFound {
  2820. if len(his) <= 0 {
  2821. redis.Set(key, "null", time.Second*60*60*18)
  2822. }
  2823. return his, nil
  2824. } else {
  2825. return his, err
  2826. }
  2827. } else {
  2828. if len(his) > 0 {
  2829. //缓存数据
  2830. his_doctor_advice_str, err := json.Marshal(his)
  2831. if err == nil {
  2832. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2833. }
  2834. } else {
  2835. redis.Set(key, "null", time.Second*60*60*18)
  2836. }
  2837. return his, nil
  2838. }
  2839. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2840. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2841. return his, nil
  2842. }
  2843. }
  2844. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2845. prescription := models.DialysisPrescription{}
  2846. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2847. if err == gorm.ErrRecordNotFound {
  2848. return nil, err
  2849. }
  2850. if err != nil {
  2851. return nil, err
  2852. }
  2853. return &prescription, nil
  2854. }
  2855. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2856. prescription := models.DialysisPrescription{}
  2857. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2858. return prescription, err
  2859. }
  2860. type HisMScheduleDoctorAdviceVM struct {
  2861. ID int64 `gorm:"column:id" json:"id"`
  2862. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2863. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2864. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2865. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2866. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2867. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2868. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2869. Status int64 `gorm:"column:status" json:"status"`
  2870. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2871. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2872. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2873. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2874. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2875. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2876. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2877. }
  2878. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2879. return "xt_schedule"
  2880. }
  2881. type HisMScheduleDoctorAdviceVMOne struct {
  2882. ID int64 `gorm:"column:id" json:"id"`
  2883. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2884. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2885. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2886. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2887. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2888. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2889. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2890. Status int64 `gorm:"column:status" json:"status"`
  2891. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2892. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2893. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2894. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2895. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2896. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2897. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2898. }
  2899. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2900. return "xt_schedule"
  2901. }
  2902. type HisMScheduleProjectVM struct {
  2903. ID int64 `gorm:"column:id" json:"id"`
  2904. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2905. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2906. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2907. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2908. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2909. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2910. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2911. Status int64 `gorm:"column:status" json:"status"`
  2912. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2913. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2914. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2915. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2916. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2917. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2918. }
  2919. func (HisMScheduleProjectVM) TableName() string {
  2920. return "xt_schedule"
  2921. }
  2922. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2923. config := models.XtHisConfig{}
  2924. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2925. return config, err
  2926. }
  2927. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2928. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2929. if orgid > 0 {
  2930. db = db.Where("x.user_org_id = ?", orgid)
  2931. }
  2932. if patientid > 0 {
  2933. db = db.Where("x.patient_id =?", patientid)
  2934. }
  2935. if recordtime > 0 {
  2936. db = db.Where("x.advice_date = ?", recordtime)
  2937. }
  2938. 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
  2939. return advice, err
  2940. }
  2941. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2942. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2943. if startime > 0 {
  2944. db = db.Where("x.advice_date >= ?", startime)
  2945. }
  2946. if endtime > 0 {
  2947. db = db.Where("x.advice_date<=?", endtime)
  2948. }
  2949. if orgid > 0 {
  2950. db = db.Where("x.user_org_id = ?", orgid)
  2951. }
  2952. if len(deliveway) > 0 {
  2953. db = db.Where("x.delivery_way = ?", deliveway)
  2954. }
  2955. 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
  2956. return advice, err
  2957. }
  2958. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2959. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2960. if startime > 0 {
  2961. db = db.Where("x.advice_date >= ?", startime)
  2962. }
  2963. if endtime > 0 {
  2964. db = db.Where("x.advice_date<=?", endtime)
  2965. }
  2966. if orgid > 0 {
  2967. db = db.Where("x.user_org_id = ?", orgid)
  2968. }
  2969. if len(deliveway) > 0 {
  2970. db = db.Where("x.delivery_way = ?", deliveway)
  2971. }
  2972. 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
  2973. return advice, err
  2974. }
  2975. func MobileGetScheduleDoctorAdvicesSix(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64) ([]*MScheduleDoctorAdviceVM, error) {
  2976. var vms []*MScheduleDoctorAdviceVM
  2977. adviceWhere := ""
  2978. adviceCondition := []interface{}{}
  2979. if adviceType == 0 {
  2980. if patientType == 0 {
  2981. if patient_id > 0 {
  2982. if execution_state > 0 {
  2983. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  2984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2985. } else {
  2986. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2988. }
  2989. } else {
  2990. if execution_state > 0 {
  2991. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  2992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2993. } else {
  2994. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  2995. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2996. }
  2997. }
  2998. } else if patientType == 1 {
  2999. if patient_id > 0 {
  3000. if execution_state > 0 {
  3001. 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= ?"
  3002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3003. } else {
  3004. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3006. }
  3007. } else {
  3008. if execution_state > 0 {
  3009. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3011. } else {
  3012. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3013. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3014. }
  3015. }
  3016. } else if patientType == 2 {
  3017. if patient_id > 0 {
  3018. if execution_state > 0 {
  3019. 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 = ?"
  3020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3021. } else {
  3022. 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 = ?)"
  3023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3024. }
  3025. } else {
  3026. if execution_state > 0 {
  3027. 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 = ?"
  3028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3029. } else {
  3030. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3032. }
  3033. }
  3034. }
  3035. } else if adviceType == 1 {
  3036. if patientType == 0 {
  3037. if patient_id > 0 {
  3038. if execution_state > 0 {
  3039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3041. } else {
  3042. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3044. }
  3045. } else {
  3046. if execution_state > 0 {
  3047. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3049. } else {
  3050. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3051. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3052. }
  3053. }
  3054. } else if patientType == 1 {
  3055. if patient_id > 0 {
  3056. if execution_state > 0 {
  3057. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3059. } else {
  3060. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3062. }
  3063. } else {
  3064. if execution_state > 0 {
  3065. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3067. } else {
  3068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3070. }
  3071. }
  3072. } else if patientType == 2 {
  3073. if patient_id > 0 {
  3074. if execution_state > 0 {
  3075. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3076. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3077. } else {
  3078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3080. }
  3081. } else {
  3082. if execution_state > 0 {
  3083. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3085. } else {
  3086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3088. }
  3089. }
  3090. }
  3091. } else if adviceType == 3 {
  3092. if patientType == 0 {
  3093. if patient_id > 0 {
  3094. if execution_state > 0 {
  3095. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3097. } else {
  3098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3100. }
  3101. } else {
  3102. if execution_state > 0 {
  3103. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3105. } else {
  3106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3108. }
  3109. }
  3110. } else if patientType == 1 {
  3111. if patient_id > 0 {
  3112. if execution_state > 0 {
  3113. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3114. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3115. } else {
  3116. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3117. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3118. }
  3119. } else {
  3120. if execution_state > 0 {
  3121. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3123. } else {
  3124. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3125. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3126. }
  3127. }
  3128. } else if patientType == 2 {
  3129. if patient_id > 0 {
  3130. if execution_state > 0 {
  3131. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3133. } else {
  3134. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3136. }
  3137. } else {
  3138. if execution_state > 0 {
  3139. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3141. } else {
  3142. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3144. }
  3145. }
  3146. }
  3147. } else if adviceType == 2 && len(deliverWay) > 0 {
  3148. if patientType == 0 {
  3149. if patient_id > 0 {
  3150. if execution_state > 0 {
  3151. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3153. } else {
  3154. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3156. }
  3157. } else {
  3158. if execution_state > 0 {
  3159. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3161. } else {
  3162. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3164. }
  3165. }
  3166. } else if patientType == 1 {
  3167. if patient_id > 0 {
  3168. if execution_state > 0 {
  3169. 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 = ?"
  3170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3171. } else {
  3172. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3174. }
  3175. } else {
  3176. if execution_state > 0 {
  3177. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3179. } else {
  3180. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3182. }
  3183. }
  3184. } else if patientType == 2 {
  3185. if patient_id > 0 {
  3186. if execution_state > 0 {
  3187. 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 = ?"
  3188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3189. } else {
  3190. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3192. }
  3193. } else {
  3194. if execution_state > 0 {
  3195. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3197. } else {
  3198. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3200. }
  3201. }
  3202. }
  3203. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3204. if patientType == 0 {
  3205. if patient_id > 0 {
  3206. if execution_state > 0 {
  3207. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3209. } else {
  3210. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3212. }
  3213. } else {
  3214. if execution_state > 0 {
  3215. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3217. } else {
  3218. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3220. }
  3221. }
  3222. } else if patientType == 1 {
  3223. if patient_id > 0 {
  3224. if execution_state > 0 {
  3225. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3226. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3227. } else {
  3228. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3230. }
  3231. } else {
  3232. if execution_state > 0 {
  3233. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3235. } else {
  3236. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3237. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3238. }
  3239. }
  3240. } else if patientType == 2 {
  3241. if patient_id > 0 {
  3242. if execution_state > 0 {
  3243. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3245. } else {
  3246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3248. }
  3249. } else {
  3250. if execution_state > 0 {
  3251. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3253. } else {
  3254. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3256. }
  3257. }
  3258. }
  3259. }
  3260. db := readDb.Table("xt_schedule")
  3261. if scheduleType > 0 {
  3262. db = db.Where("schedule_type = ?", scheduleType)
  3263. }
  3264. if partitonType > 0 {
  3265. db = db.Where("partition_id = ?", partitonType)
  3266. }
  3267. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3268. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3269. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3270. }).
  3271. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3272. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3273. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3274. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3275. Preload("DoctorAdvices", adviceCondition...).
  3276. Where("status = 1 AND user_org_id = ?", orgID)
  3277. if scheduleDate != 0 {
  3278. db = db.Where("schedule_date = ?", scheduleDate)
  3279. }
  3280. err := db.Find(&vms).Error
  3281. return vms, err
  3282. }
  3283. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3284. var vms []*HisMScheduleDoctorAdviceVM
  3285. if len(deliverWay) > 0 {
  3286. db := readDb.Table("xt_schedule")
  3287. if scheduleType > 0 {
  3288. db = db.Where("schedule_type = ?", scheduleType)
  3289. }
  3290. if partitionType > 0 {
  3291. db = db.Where("partition_id = ?", partitionType)
  3292. }
  3293. if patient_id > 0 {
  3294. if execution_state > 0 {
  3295. if cost_type > 0 {
  3296. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3297. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3298. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3299. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3300. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle", orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type).
  3301. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3302. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3303. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3304. Where("status = 1 AND user_org_id = ?", orgID)
  3305. if scheduleDate != 0 {
  3306. db = db.Where("schedule_date = ?", scheduleDate)
  3307. }
  3308. err = db.Find(&vms).Error
  3309. } else {
  3310. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3311. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3312. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3313. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3314. 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).
  3315. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3316. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3317. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3318. Where("status = 1 AND user_org_id = ?", orgID)
  3319. if scheduleDate != 0 {
  3320. db = db.Where("schedule_date = ?", scheduleDate)
  3321. }
  3322. err = db.Find(&vms).Error
  3323. }
  3324. } else {
  3325. if cost_type > 0 {
  3326. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3327. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3328. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3329. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3330. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and is_settle", orgID, scheduleDate, deliverWay, patient_id, cost_type).
  3331. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3332. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3333. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3334. Where("status = 1 AND user_org_id = ?", orgID)
  3335. if scheduleDate != 0 {
  3336. db = db.Where("schedule_date = ?", scheduleDate)
  3337. }
  3338. err = db.Find(&vms).Error
  3339. } else {
  3340. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3341. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3342. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3343. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3344. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  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. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3348. Where("status = 1 AND user_org_id = ?", orgID)
  3349. if scheduleDate != 0 {
  3350. db = db.Where("schedule_date = ?", scheduleDate)
  3351. }
  3352. err = db.Find(&vms).Error
  3353. }
  3354. }
  3355. } else {
  3356. if execution_state > 0 {
  3357. if cost_type > 0 {
  3358. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3359. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3360. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3361. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3362. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, deliverWay, execution_state, cost_type).
  3363. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3364. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3365. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3366. Where("status = 1 AND user_org_id = ?", orgID)
  3367. if scheduleDate != 0 {
  3368. db = db.Where("schedule_date = ?", scheduleDate)
  3369. }
  3370. err = db.Find(&vms).Error
  3371. } else {
  3372. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3373. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3374. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3375. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3376. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3377. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3378. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3379. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3380. Where("status = 1 AND user_org_id = ?", orgID)
  3381. if scheduleDate != 0 {
  3382. db = db.Where("schedule_date = ?", scheduleDate)
  3383. }
  3384. err = db.Find(&vms).Error
  3385. }
  3386. } else {
  3387. if cost_type > 0 {
  3388. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3389. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3390. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3391. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3392. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3393. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3394. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3395. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3396. Where("status = 1 AND user_org_id = ?", orgID)
  3397. if scheduleDate != 0 {
  3398. db = db.Where("schedule_date = ?", scheduleDate)
  3399. }
  3400. err = db.Find(&vms).Error
  3401. } else {
  3402. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3403. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3404. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3405. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3406. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3407. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3408. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3409. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3410. Where("status = 1 AND user_org_id = ?", orgID)
  3411. if scheduleDate != 0 {
  3412. db = db.Where("schedule_date = ?", scheduleDate)
  3413. }
  3414. err = db.Find(&vms).Error
  3415. }
  3416. }
  3417. }
  3418. } else {
  3419. db := readDb.Table("xt_schedule")
  3420. if scheduleType > 0 {
  3421. db = db.Where("schedule_type = ?", scheduleType)
  3422. }
  3423. if partitionType > 0 {
  3424. db = db.Where("partition_id = ?", partitionType)
  3425. }
  3426. if patient_id > 0 {
  3427. if execution_state > 0 {
  3428. if cost_type > 0 {
  3429. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3430. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3431. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3432. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3433. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, patient_id, execution_state, cost_type).
  3434. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3435. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3436. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3437. Where("status = 1 AND user_org_id = ?", orgID)
  3438. if scheduleDate != 0 {
  3439. db = db.Where("schedule_date = ?", scheduleDate)
  3440. }
  3441. err = db.Find(&vms).Error
  3442. } else {
  3443. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3444. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3445. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3446. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3447. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  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. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3451. Where("status = 1 AND user_org_id = ?", orgID)
  3452. if scheduleDate != 0 {
  3453. db = db.Where("schedule_date = ?", scheduleDate)
  3454. }
  3455. err = db.Find(&vms).Error
  3456. }
  3457. } else {
  3458. if cost_type > 0 {
  3459. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3460. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3461. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3462. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3463. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3464. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3465. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3466. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3467. Where("status = 1 AND user_org_id = ?", orgID)
  3468. if scheduleDate != 0 {
  3469. db = db.Where("schedule_date = ?", scheduleDate)
  3470. }
  3471. err = db.Find(&vms).Error
  3472. } else {
  3473. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3474. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3475. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3476. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3477. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3478. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3479. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3480. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  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. }
  3487. }
  3488. } else {
  3489. if execution_state > 0 {
  3490. if cost_type > 0 {
  3491. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3492. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3493. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3494. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3495. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3496. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3497. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3498. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3499. Where("status = 1 AND user_org_id = ?", orgID)
  3500. if scheduleDate != 0 {
  3501. db = db.Where("schedule_date = ?", scheduleDate)
  3502. }
  3503. err = db.Find(&vms).Error
  3504. } else {
  3505. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3506. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3507. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3508. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3509. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3510. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3511. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3512. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3513. Where("status = 1 AND user_org_id = ?", orgID)
  3514. if scheduleDate != 0 {
  3515. db = db.Where("schedule_date = ?", scheduleDate)
  3516. }
  3517. err = db.Find(&vms).Error
  3518. }
  3519. } else {
  3520. if cost_type > 0 {
  3521. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3522. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3523. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3524. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3525. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3526. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3527. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3528. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3529. Where("status = 1 AND user_org_id = ?", orgID)
  3530. if scheduleDate != 0 {
  3531. db = db.Where("schedule_date = ?", scheduleDate)
  3532. }
  3533. err = db.Find(&vms).Error
  3534. } else {
  3535. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3536. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3537. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3538. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3539. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3540. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3541. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3542. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3543. Where("status = 1 AND user_org_id = ?", orgID)
  3544. if scheduleDate != 0 {
  3545. db = db.Where("schedule_date = ?", scheduleDate)
  3546. }
  3547. err = db.Find(&vms).Error
  3548. }
  3549. }
  3550. }
  3551. }
  3552. return vms, err
  3553. }
  3554. func BatchDeleteMonitor(ids []string) (err error) {
  3555. if len(ids) == 1 {
  3556. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3557. } else {
  3558. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3559. }
  3560. return
  3561. }
  3562. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3563. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3564. //table := XTReadDB().Table("xt_schedule as s")
  3565. //fmt.Println(table)
  3566. if patientid > 0 {
  3567. db = db.Where("x.patient_id = ?", patientid)
  3568. }
  3569. if startime > 0 {
  3570. db = db.Where("x.dialysis_date>=?", startime)
  3571. }
  3572. if endtime > 0 {
  3573. db = db.Where("x.dialysis_date <= ?", endtime)
  3574. }
  3575. 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
  3576. return order, err
  3577. }
  3578. func BatchDeleteAdvice(ids []string) (err error) {
  3579. if len(ids) == 1 {
  3580. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3581. } else {
  3582. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3583. }
  3584. return
  3585. }
  3586. func BatchDeleteHisAdvice(ids []string) (err error) {
  3587. if len(ids) == 1 {
  3588. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3589. } else {
  3590. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3591. }
  3592. return
  3593. }
  3594. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3595. detail := models.AutomaticReduceDetail{}
  3596. 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
  3597. return detail, err
  3598. }
  3599. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3600. detail := models.AutomaticReduceDetail{}
  3601. 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
  3602. return err
  3603. }
  3604. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3605. detail := models.DialysisBeforePrepare{}
  3606. 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
  3607. return err
  3608. }
  3609. func BatchAdviceCheck(ids []string, creator int64) error {
  3610. advice := models.XtDoctorAdvice{}
  3611. 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
  3612. return err
  3613. }
  3614. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3615. advice := models.HisDoctorAdviceInfo{}
  3616. 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
  3617. return err
  3618. }
  3619. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3620. advice := models.XtDoctorAdvice{}
  3621. 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
  3622. return err
  3623. }
  3624. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3625. advice := models.HisDoctorAdviceInfo{}
  3626. 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
  3627. return err
  3628. }
  3629. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3630. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3631. return doctor, err
  3632. }
  3633. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3634. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3635. return doctor, err
  3636. }
  3637. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3638. config := models.XtHisProjectConfig{}
  3639. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3640. return config, err
  3641. }
  3642. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3643. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3644. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3645. }).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
  3646. return
  3647. }
  3648. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3649. var vms []*HisMScheduleProjectVM
  3650. if patientType == 0 {
  3651. if patient_id > 0 {
  3652. if execution_state == 1 {
  3653. db := readDb.
  3654. Table("xt_schedule").
  3655. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3656. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3657. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3658. }).
  3659. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3660. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3661. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3662. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3663. 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")
  3664. }).
  3665. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3666. 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")
  3667. }).Where("status = 1 AND user_org_id = ?", orgID)
  3668. if scheduleDate != 0 {
  3669. db = db.Where("schedule_date = ?", scheduleDate)
  3670. }
  3671. err = db.Find(&vms).Error
  3672. } else if execution_state == 2 {
  3673. db := readDb.
  3674. Table("xt_schedule").
  3675. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3676. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3677. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3678. }).
  3679. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3680. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3681. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3682. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3683. 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")
  3684. }).
  3685. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3686. 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")
  3687. }).Where("status = 1 AND user_org_id = ?", orgID)
  3688. if scheduleDate != 0 {
  3689. db = db.Where("schedule_date = ?", scheduleDate)
  3690. }
  3691. err = db.Find(&vms).Error
  3692. } else if execution_state == 0 {
  3693. db := readDb.
  3694. Table("xt_schedule").
  3695. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3696. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3697. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3698. }).
  3699. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3700. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3701. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3702. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3703. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3704. }).
  3705. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3706. 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")
  3707. }).Where("status = 1 AND user_org_id = ?", orgID)
  3708. if scheduleDate != 0 {
  3709. db = db.Where("schedule_date = ?", scheduleDate)
  3710. }
  3711. err = db.Find(&vms).Error
  3712. }
  3713. } else {
  3714. if patient_id > 0 {
  3715. if execution_state == 1 {
  3716. db := readDb.
  3717. Table("xt_schedule").
  3718. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3719. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3720. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3721. }).
  3722. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3723. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3724. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3725. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3726. 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")
  3727. }).
  3728. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3729. 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")
  3730. }).Where("status = 1 AND user_org_id = ?", orgID)
  3731. if scheduleDate != 0 {
  3732. db = db.Where("schedule_date = ?", scheduleDate)
  3733. }
  3734. err = db.Find(&vms).Error
  3735. } else if execution_state == 2 {
  3736. db := readDb.
  3737. Table("xt_schedule").
  3738. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3739. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3740. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3741. }).
  3742. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3743. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3744. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3745. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3746. 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")
  3747. }).
  3748. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3749. 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")
  3750. }).Where("status = 1 AND user_org_id = ?", orgID)
  3751. if scheduleDate != 0 {
  3752. db = db.Where("schedule_date = ?", scheduleDate)
  3753. }
  3754. err = db.Find(&vms).Error
  3755. } else if execution_state == 0 {
  3756. db := readDb.
  3757. Table("xt_schedule").
  3758. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3759. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3760. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3761. }).
  3762. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3763. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3764. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3765. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3766. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3767. }).
  3768. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3769. 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")
  3770. }).Where("status = 1 AND user_org_id = ?", orgID)
  3771. if scheduleDate != 0 {
  3772. db = db.Where("schedule_date = ?", scheduleDate)
  3773. }
  3774. err = db.Find(&vms).Error
  3775. }
  3776. } else {
  3777. if execution_state == 1 {
  3778. db := readDb.
  3779. Table("xt_schedule").
  3780. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3781. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3782. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3783. }).
  3784. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3785. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3786. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3787. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3788. 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")
  3789. }).
  3790. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3791. 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")
  3792. }).Where("status = 1 AND user_org_id = ?", orgID)
  3793. if scheduleDate != 0 {
  3794. db = db.Where("schedule_date = ?", scheduleDate)
  3795. }
  3796. err = db.Find(&vms).Error
  3797. } else if execution_state == 2 {
  3798. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3799. db := readDb.
  3800. Table("xt_schedule").
  3801. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3802. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3803. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3804. }).
  3805. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3806. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3807. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3808. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3809. 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")
  3810. }).
  3811. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3812. 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")
  3813. }).Where("status = 1 AND user_org_id = ?", orgID)
  3814. if scheduleDate != 0 {
  3815. db = db.Where("schedule_date = ?", scheduleDate)
  3816. }
  3817. err = db.Find(&vms).Error
  3818. } else if execution_state == 0 {
  3819. db := readDb.
  3820. Table("xt_schedule").
  3821. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3822. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3823. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3824. }).
  3825. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3826. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3827. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3828. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3829. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3830. }).
  3831. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3832. 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")
  3833. }).Where("status = 1 AND user_org_id = ?", orgID)
  3834. if scheduleDate != 0 {
  3835. db = db.Where("schedule_date = ?", scheduleDate)
  3836. }
  3837. err = db.Find(&vms).Error
  3838. }
  3839. }
  3840. }
  3841. }
  3842. if patientType > 0 {
  3843. if execution_state == 1 {
  3844. db := readDb.
  3845. Table("xt_schedule").
  3846. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3847. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3848. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3849. }).
  3850. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3851. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3852. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3853. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3854. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3855. 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")
  3856. }).
  3857. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3858. 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")
  3859. }).Where("status = 1 AND user_org_id = ?", orgID)
  3860. if scheduleDate != 0 {
  3861. db = db.Where("schedule_date = ?", scheduleDate)
  3862. }
  3863. err = db.Find(&vms).Error
  3864. } else if execution_state == 2 {
  3865. db := readDb.
  3866. Table("xt_schedule").
  3867. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3868. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3869. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3870. }).
  3871. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3872. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3873. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3874. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3875. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3876. 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")
  3877. }).
  3878. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3879. 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")
  3880. }).Where("status = 1 AND user_org_id = ?", orgID)
  3881. if scheduleDate != 0 {
  3882. db = db.Where("schedule_date = ?", scheduleDate)
  3883. }
  3884. err = db.Find(&vms).Error
  3885. } else if execution_state == 0 {
  3886. db := readDb.
  3887. Table("xt_schedule").
  3888. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3889. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3890. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3891. }).
  3892. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3893. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3894. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3895. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3896. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3897. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3898. }).
  3899. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3900. 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")
  3901. }).Where("status = 1 AND user_org_id = ?", orgID)
  3902. if scheduleDate != 0 {
  3903. db = db.Where("schedule_date = ?", scheduleDate)
  3904. }
  3905. err = db.Find(&vms).Error
  3906. }
  3907. }
  3908. return vms, err
  3909. }
  3910. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3911. prepare := models.DialysisBeforePrepare{}
  3912. 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
  3913. return err
  3914. }
  3915. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3916. detail := models.AutomaticReduceDetail{}
  3917. 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
  3918. return err
  3919. }
  3920. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3921. var record models.DialysisSolution
  3922. 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
  3923. if err != nil {
  3924. if err == gorm.ErrRecordNotFound {
  3925. return nil, nil
  3926. } else {
  3927. return nil, err
  3928. }
  3929. }
  3930. return &record, nil
  3931. }
  3932. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3933. var record models.DialysisPrescription
  3934. 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
  3935. if err != nil {
  3936. if err == gorm.ErrRecordNotFound {
  3937. return nil, nil
  3938. } else {
  3939. return nil, err
  3940. }
  3941. }
  3942. return &record, nil
  3943. }
  3944. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  3945. prescription := models.DialysisPrescriptionThrity{}
  3946. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  3947. return prescription, err
  3948. }
  3949. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3950. var record models.SystemPrescription
  3951. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3952. if err != nil {
  3953. if err == gorm.ErrRecordNotFound {
  3954. return nil, nil
  3955. } else {
  3956. return nil, err
  3957. }
  3958. }
  3959. return &record, nil
  3960. }
  3961. // 透前评估
  3962. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3963. var record models.PredialysisEvaluation
  3964. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3965. if err != nil {
  3966. if err == gorm.ErrRecordNotFound {
  3967. return nil, nil
  3968. } else {
  3969. return nil, err
  3970. }
  3971. }
  3972. return &record, nil
  3973. }
  3974. //
  3975. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  3976. //
  3977. // 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
  3978. // return prepare, err
  3979. //}
  3980. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3981. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  3982. return auto, err
  3983. }
  3984. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  3985. role := models.SgjUserAdminRole{}
  3986. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  3987. return role, err
  3988. }
  3989. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3990. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  3991. return auto, err
  3992. }
  3993. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  3994. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  3995. return outifno, err
  3996. }
  3997. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  3998. order := models.DialysisOrder{}
  3999. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4000. return order, err
  4001. }
  4002. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4003. record := models.MonitoringRecord{}
  4004. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4005. return record, err
  4006. }
  4007. func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64) ([]*MScheduleDoctorAdviceVM, error) {
  4008. var vms []*MScheduleDoctorAdviceVM
  4009. adviceWhere := ""
  4010. adviceCondition := []interface{}{}
  4011. if adviceType == 0 {
  4012. if patientType == 0 {
  4013. if patient_id > 0 {
  4014. if execution_state > 0 {
  4015. if cost_type > 0 {
  4016. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ?"
  4017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4018. } else {
  4019. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4021. }
  4022. } else {
  4023. if cost_type > 0 {
  4024. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4026. } else {
  4027. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4029. }
  4030. }
  4031. } else {
  4032. if execution_state > 0 {
  4033. if cost_type > 0 {
  4034. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4036. } else {
  4037. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4038. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4039. }
  4040. } else {
  4041. if cost_type > 0 {
  4042. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4044. } else {
  4045. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4046. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4047. }
  4048. }
  4049. }
  4050. } else if patientType == 1 {
  4051. if patient_id > 0 {
  4052. if execution_state > 0 {
  4053. if cost_type > 0 {
  4054. 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= ? and is_settle = ?"
  4055. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4056. } else {
  4057. 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= ?"
  4058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4059. }
  4060. } else {
  4061. if cost_type > 0 {
  4062. 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 is_settle=?"
  4063. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4064. } else {
  4065. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4067. }
  4068. }
  4069. } else {
  4070. if execution_state > 0 {
  4071. if cost_type > 0 {
  4072. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=?"
  4073. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4074. } else {
  4075. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4076. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4077. }
  4078. } else {
  4079. if cost_type > 0 {
  4080. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4082. } else {
  4083. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4085. }
  4086. }
  4087. }
  4088. } else if patientType == 2 {
  4089. if patient_id > 0 {
  4090. if execution_state > 0 {
  4091. if cost_type > 0 {
  4092. 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 = ? and is_settle=?"
  4093. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4094. } else {
  4095. 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 = ?"
  4096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4097. }
  4098. } else {
  4099. if cost_type > 0 {
  4100. 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 is_settle=?"
  4101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4102. } else {
  4103. 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 = ?)"
  4104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4105. }
  4106. }
  4107. } else {
  4108. if execution_state > 0 {
  4109. if cost_type > 0 {
  4110. 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 = ? and is_settle=?"
  4111. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4112. } else {
  4113. 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 = ?"
  4114. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4115. }
  4116. } else {
  4117. if cost_type > 0 {
  4118. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4120. } else {
  4121. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4123. }
  4124. }
  4125. }
  4126. }
  4127. } else if adviceType == 1 {
  4128. if patientType == 0 {
  4129. if patient_id > 0 {
  4130. if execution_state > 0 {
  4131. if cost_type > 0 {
  4132. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4133. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4134. } else {
  4135. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4137. }
  4138. } else {
  4139. if cost_type > 0 {
  4140. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4142. } else {
  4143. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4145. }
  4146. }
  4147. } else {
  4148. if execution_state > 0 {
  4149. if cost_type > 0 {
  4150. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4152. } else {
  4153. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4155. }
  4156. } else {
  4157. if cost_type > 0 {
  4158. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4160. } else {
  4161. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4163. }
  4164. }
  4165. }
  4166. } else if patientType == 1 {
  4167. if patient_id > 0 {
  4168. if execution_state > 0 {
  4169. if cost_type > 0 {
  4170. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4172. } else {
  4173. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4175. }
  4176. } else {
  4177. if cost_type > 0 {
  4178. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4180. } else {
  4181. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4183. }
  4184. }
  4185. } else {
  4186. if execution_state > 0 {
  4187. if cost_type > 0 {
  4188. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4190. } else {
  4191. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4193. }
  4194. } else {
  4195. if cost_type > 0 {
  4196. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4198. } else {
  4199. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4200. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4201. }
  4202. }
  4203. }
  4204. } else if patientType == 2 {
  4205. if patient_id > 0 {
  4206. if execution_state > 0 {
  4207. if cost_type > 0 {
  4208. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  4209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4210. } else {
  4211. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4213. }
  4214. } else {
  4215. if cost_type > 0 {
  4216. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4218. } else {
  4219. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4221. }
  4222. }
  4223. } else {
  4224. if execution_state > 0 {
  4225. if cost_type > 0 {
  4226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4228. } else {
  4229. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4231. }
  4232. } else {
  4233. if cost_type > 0 {
  4234. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4236. } else {
  4237. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4239. }
  4240. }
  4241. }
  4242. }
  4243. } else if adviceType == 3 {
  4244. if patientType == 0 {
  4245. if patient_id > 0 {
  4246. if execution_state > 0 {
  4247. if cost_type > 0 {
  4248. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4250. } else {
  4251. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  4252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4253. }
  4254. } else {
  4255. if cost_type > 0 {
  4256. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  4257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4258. } else {
  4259. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  4260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4261. }
  4262. }
  4263. } else {
  4264. if execution_state > 0 {
  4265. if cost_type > 0 {
  4266. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  4267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4268. } else {
  4269. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  4270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4271. }
  4272. } else {
  4273. if cost_type > 0 {
  4274. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  4275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4276. } else {
  4277. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  4278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4279. }
  4280. }
  4281. }
  4282. } else if patientType == 1 {
  4283. if patient_id > 0 {
  4284. if execution_state > 0 {
  4285. if cost_type > 0 {
  4286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4288. } else {
  4289. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4291. }
  4292. } else {
  4293. if cost_type > 0 {
  4294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4296. } else {
  4297. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  4298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4299. }
  4300. }
  4301. } else {
  4302. if execution_state > 0 {
  4303. if cost_type > 0 {
  4304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  4305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4306. } else {
  4307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  4308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4309. }
  4310. } else {
  4311. if cost_type > 0 {
  4312. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  4313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4314. } else {
  4315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  4316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4317. }
  4318. }
  4319. }
  4320. } else if patientType == 2 {
  4321. if patient_id > 0 {
  4322. if execution_state > 0 {
  4323. if cost_type > 0 {
  4324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  4325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4326. } else {
  4327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4329. }
  4330. } else {
  4331. if cost_type > 0 {
  4332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4334. } else {
  4335. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  4336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4337. }
  4338. }
  4339. } else {
  4340. if execution_state > 0 {
  4341. if cost_type > 0 {
  4342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  4343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4344. } else {
  4345. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  4346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4347. }
  4348. } else {
  4349. if cost_type > 0 {
  4350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  4351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4352. } else {
  4353. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  4354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4355. }
  4356. }
  4357. }
  4358. }
  4359. } else if adviceType == 2 && len(deliverWay) > 0 {
  4360. if patientType == 0 {
  4361. if patient_id > 0 {
  4362. if execution_state > 0 {
  4363. if cost_type > 0 {
  4364. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4366. } else {
  4367. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  4368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4369. }
  4370. } else {
  4371. if cost_type > 0 {
  4372. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  4373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4374. } else {
  4375. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  4376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4377. }
  4378. }
  4379. } else {
  4380. if execution_state > 0 {
  4381. if cost_type > 0 {
  4382. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  4383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4384. } else {
  4385. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  4386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4387. }
  4388. } else {
  4389. if cost_type > 0 {
  4390. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  4391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4392. } else {
  4393. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  4394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4395. }
  4396. }
  4397. }
  4398. } else if patientType == 1 {
  4399. if patient_id > 0 {
  4400. if execution_state > 0 {
  4401. if cost_type > 0 {
  4402. 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 = ? and is_settle = ?"
  4403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  4404. } else {
  4405. 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 = ?"
  4406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  4407. }
  4408. } else {
  4409. if cost_type > 0 {
  4410. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  4411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  4412. } else {
  4413. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  4414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  4415. }
  4416. }
  4417. } else {
  4418. if execution_state > 0 {
  4419. if cost_type > 0 {
  4420. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  4421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  4422. } else {
  4423. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  4424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  4425. }
  4426. } else {
  4427. if cost_type > 0 {
  4428. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  4429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  4430. } else {
  4431. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  4432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  4433. }
  4434. }
  4435. }
  4436. } else if patientType == 2 {
  4437. if patient_id > 0 {
  4438. if execution_state > 0 {
  4439. if cost_type > 0 {
  4440. 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 = ? and is_settle = ?"
  4441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4442. } else {
  4443. 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 = ?"
  4444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4445. }
  4446. } else {
  4447. if cost_type > 0 {
  4448. 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 is_settle = ?"
  4449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4450. } else {
  4451. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  4452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4453. }
  4454. }
  4455. } else {
  4456. if execution_state > 0 {
  4457. if cost_type > 0 {
  4458. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ?"
  4459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4460. } else {
  4461. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  4462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4463. }
  4464. } else {
  4465. if cost_type > 0 {
  4466. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4468. } else {
  4469. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  4470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4471. }
  4472. }
  4473. }
  4474. }
  4475. } else if adviceType == 2 && len(deliverWay) <= 0 {
  4476. if patientType == 0 {
  4477. if patient_id > 0 {
  4478. if execution_state > 0 {
  4479. if cost_type > 0 {
  4480. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4482. } else {
  4483. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  4484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4485. }
  4486. } else {
  4487. if cost_type > 0 {
  4488. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  4489. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4490. } else {
  4491. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  4492. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4493. }
  4494. }
  4495. } else {
  4496. if execution_state > 0 {
  4497. if cost_type > 0 {
  4498. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  4499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4500. } else {
  4501. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  4502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4503. }
  4504. } else {
  4505. if cost_type > 0 {
  4506. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  4507. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4508. } else {
  4509. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  4510. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4511. }
  4512. }
  4513. }
  4514. } else if patientType == 1 {
  4515. if patient_id > 0 {
  4516. if execution_state > 0 {
  4517. if cost_type > 0 {
  4518. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4519. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4520. } else {
  4521. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4523. }
  4524. } else {
  4525. if cost_type > 0 {
  4526. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4527. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4528. } else {
  4529. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  4530. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4531. }
  4532. }
  4533. } else {
  4534. if execution_state > 0 {
  4535. if cost_type > 0 {
  4536. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  4537. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4538. } else {
  4539. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  4540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4541. }
  4542. } else {
  4543. if cost_type > 0 {
  4544. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  4545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4546. } else {
  4547. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  4548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4549. }
  4550. }
  4551. }
  4552. } else if patientType == 2 {
  4553. if patient_id > 0 {
  4554. if execution_state > 0 {
  4555. if cost_type > 0 {
  4556. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  4557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4558. } else {
  4559. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4561. }
  4562. } else {
  4563. if cost_type > 0 {
  4564. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4566. } else {
  4567. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  4568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4569. }
  4570. }
  4571. } else {
  4572. if execution_state > 0 {
  4573. if cost_type > 0 {
  4574. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4576. } else {
  4577. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  4578. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4579. }
  4580. } else {
  4581. if cost_type > 0 {
  4582. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  4583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4584. } else {
  4585. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  4586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4587. }
  4588. }
  4589. }
  4590. }
  4591. }
  4592. db := readDb.Table("xt_schedule")
  4593. if scheduleType > 0 {
  4594. db = db.Where("schedule_type = ?", scheduleType)
  4595. }
  4596. if partitonType > 0 {
  4597. db = db.Where("partition_id = ?", partitonType)
  4598. }
  4599. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4600. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4601. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4602. }).
  4603. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4604. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4605. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4606. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  4607. Preload("DoctorAdvices", adviceCondition...).
  4608. Where("status = 1 AND user_org_id = ?", orgID)
  4609. if scheduleDate != 0 {
  4610. db = db.Where("schedule_date = ?", scheduleDate)
  4611. }
  4612. err := db.Find(&vms).Error
  4613. return vms, err
  4614. }
  4615. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  4616. order := models.XtDialysisOrder{}
  4617. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  4618. return order, err
  4619. }
  4620. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  4621. order := models.XtPatients{}
  4622. err := XTWriteDB().Model(&order).Where("user_org_id = ? and id = ? and status = 1", org_id, patient_id).Updates(map[string]interface{}{"schedule_remark": schedule_remark}).Error
  4623. err = XTWriteDB().Model(models.XtPatientsNew{}).Where("user_org_id = ? and id = ? and status = 1", org_id, patient_id).Updates(map[string]interface{}{"schedule_remark": schedule_remark}).Error
  4624. return err
  4625. }
  4626. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  4627. order := models.BloodDialysisOrderCount{}
  4628. db := XTReadDB().Table("xt_dialysis_order as o")
  4629. 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.user_org_id = ? and o.patient_id = ? and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  4630. return order, err
  4631. }
  4632. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  4633. order := models.BloodDialysisOrderCount{}
  4634. db := XTReadDB().Table("xt_dialysis_order as o")
  4635. 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.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1672502400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  4636. return order, err
  4637. }
  4638. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  4639. order := models.DialysisOrder{}
  4640. err := XTWriteDB().Model(&order).Where("patient_id = ? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, user_org_id).Updates(map[string]interface{}{"dialysis_total": dialysis_total}).Error
  4641. return order, err
  4642. }
  4643. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  4644. information := models.DeviceInformation{}
  4645. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  4646. return err
  4647. }