mobile_dialysis_service.go 259KB

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