schedule_api_controller.go 185KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "XT_New/enums"
  10. "XT_New/models"
  11. "XT_New/service"
  12. "XT_New/utils"
  13. "github.com/jinzhu/gorm"
  14. "github.com/astaxie/beego"
  15. )
  16. type ScheduleApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func ScheduleApiRegistRouters() {
  20. beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
  21. beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
  22. beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
  23. beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
  24. beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
  25. beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
  26. beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
  27. beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
  28. beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
  29. beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
  30. beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
  31. beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
  32. beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
  33. beego.Router("/api/schedule_template/search", &ScheduleApiController{}, "get:SearchTemplateSchedulePatients")
  34. beego.Router("/api/schedule_template/cancel", &ScheduleApiController{}, "post:CancelScheduleTemplate")
  35. beego.Router("/api/schedule/getnextscheduleweekday", &ScheduleApiController{}, "Get:GetNextWeekDaySchedule")
  36. beego.Router("/api/schedule/getnextscheduleweekdayone", &ScheduleApiController{}, "Get:GetNextWeekDayScheduleOne")
  37. beego.Router("/api/schedule/getthreeweeklist", &ScheduleApiController{}, "Get:GetThreeWeekList")
  38. beego.Router("/api/schedule/getallzones", &ScheduleApiController{}, "Get:GetAllZones")
  39. beego.Router("/api/schedule/copypatientschedules", &ScheduleApiController{}, "Get:GetCopyPatientSchedules")
  40. beego.Router("/api/schedule/saveremindprint", &ScheduleApiController{}, "Get:SaveRemindPrint")
  41. beego.Router("/api/schedule/getremindprintlist", &ScheduleApiController{}, "Get:GetRemindPrintList")
  42. beego.Router("/api/schedule/getbloodschedulelist", &ScheduleApiController{}, "Get:GetBloodScheduleList")
  43. beego.Router("/api/schedule/getprintlist", &ScheduleApiController{}, "Get:GetPrintList")
  44. beego.Router("/api/schedule/getallzonelist", &ScheduleApiController{}, "Get:GetAllZoneList")
  45. beego.Router("/api/schedule/getpatientschedulecount", &ScheduleApiController{}, "Get:GetPatientScheduleCount")
  46. beego.Router("/api/schedule/weekpanelone", &ScheduleApiController{}, "Get:GetWeekPanelsOne")
  47. beego.Router("/api/schedule/schedulesone", &ScheduleApiController{}, "Get:GetScheduleOne")
  48. beego.Router("/api/schedule/scheduletwo", &ScheduleApiController{}, "Get:GetScheduleTwo")
  49. beego.Router("/api/schedule/getschedulethreeone", &ScheduleApiController{}, "Get:GetScheduleThreeList")
  50. beego.Router("/api/schedule/postscheduletemplate", &ScheduleApiController{}, "Get:SaveScheduleTemplate")
  51. beego.Router("/api/schedule/getscheduletemplate", &ScheduleApiController{}, "Get:GetScheduleTemplate")
  52. beego.Router("/api/order/changefuncprint", &ScheduleApiController{}, "Get:ChangeFuncPrint")
  53. beego.Router("/api/order/getdataprint", &ScheduleApiController{}, "Get:GetDataPrint")
  54. beego.Router("/api/schedule/getnextweekpanels", &ScheduleApiController{}, "Get:GetNextWeekPanels")
  55. beego.Router("/api/schedule/synchroschedule", &ScheduleApiController{}, "Get:SynchroSchedule")
  56. beego.Router("/api/schedule/getpatientscheduletemplate", &ScheduleApiController{}, "Get:GetPatientScheduleTempalate")
  57. beego.Router("/api/schedule/getsolutionschedule", &ScheduleApiController{}, "Get:GetSolutionSchedule")
  58. beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatient")
  59. beego.Router("/api/schedule/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSchTemplate")
  60. beego.Router("/api/patient/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSmartSch")
  61. beego.Router("/api/patient/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSmartSchTemplate")
  62. beego.Router("/api/device/get", &ScheduleApiController{}, "Get:GetDevicesNumbers")
  63. beego.Router("/api/smartsch/batch", &ScheduleApiController{}, "Post:BatchPostSmartSch")
  64. beego.Router("/api/smartsch/get", &ScheduleApiController{}, "Get:GetSmartSch")
  65. beego.Router("/api/sch/exchange", &ScheduleApiController{}, "Get:ExchangeSch")
  66. beego.Router("/api/sch/coversch", &ScheduleApiController{}, "Get:CoverSch")
  67. beego.Router("/api/schedule/delete_two", &ScheduleApiController{}, "Delete:DeleteScheduleTwo")
  68. beego.Router("/api/schedule/create_two", &ScheduleApiController{}, "Post:CreateScheduleTwo")
  69. beego.Router("/api/schedule/changeschedule", &ScheduleApiController{}, "Put:ChangeScheduleTen")
  70. beego.Router("/api/schedule/getordernumber", &ScheduleApiController{}, "Get:GetNumberListById")
  71. }
  72. func (c *ScheduleApiController) CoverSch() {
  73. id_one, _ := c.GetInt64("id_one")
  74. id_two, _ := c.GetInt64("id_two")
  75. sch, _ := service.GetScheduleTen(c.GetAdminUserInfo().CurrentOrgId, id_one)
  76. orgId := c.GetAdminUserInfo().CurrentOrgId
  77. //针对凤凰医院
  78. if orgId == 10579 || orgId == 10344 || orgId == 10206 {
  79. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, orgId)
  80. if len(advice) > 0 {
  81. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, orgId)
  82. }
  83. }
  84. if orgId == 10206 || orgId == 10344 {
  85. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, orgId)
  86. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, orgId)
  87. if len(hisAdvice) > 0 {
  88. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, orgId)
  89. }
  90. if len(project) > 0 {
  91. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, orgId)
  92. }
  93. }
  94. sch_two, _ := service.GetScheduleTen(c.GetAdminUserInfo().CurrentOrgId, id_two)
  95. //order, _ := service.GetDialysisOrder(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  96. //if order.ID > 0 {
  97. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  98. // return
  99. //}
  100. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  101. if order.ID > 0 {
  102. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  103. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  104. redis := service.RedisClient()
  105. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  106. redis.Set(key, "", time.Second)
  107. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  108. //清空key 值
  109. redis.Set(keyOne, "", time.Second)
  110. }
  111. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  112. if orderOne.ID > 0 {
  113. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  114. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  115. redis := service.RedisClient()
  116. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  117. redis.Set(key, "", time.Second)
  118. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  119. //清空key 值
  120. redis.Set(keyOne, "", time.Second)
  121. }
  122. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  123. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  124. count, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch.PatientId)
  125. if count > 0 {
  126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  127. return
  128. }
  129. }
  130. var new_sch models.Schedule
  131. new_sch = sch
  132. new_sch.BedId = sch_two.BedId
  133. new_sch.ScheduleDate = sch_two.ScheduleDate
  134. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  135. new_sch.PartitionId = sch_two.PartitionId
  136. new_sch.ScheduleType = sch_two.ScheduleType
  137. new_sch.ID = 0
  138. //删除原来的排班
  139. err := service.SaveSchTwo(sch, sch_two)
  140. //生成新的排班
  141. if err == nil {
  142. err2 := service.SaveSch(&new_sch)
  143. if err2 == nil {
  144. //去除当天患者排班中重复数据,保留最后一条数据
  145. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  146. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  147. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  148. c.ServeSuccessJSON(map[string]interface{}{
  149. "msg": "覆盖成功",
  150. "new_sch": new_sch,
  151. })
  152. } else {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  154. return
  155. }
  156. } else {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  158. return
  159. }
  160. }
  161. func (c *ScheduleApiController) ExchangeSch() {
  162. id_one, _ := c.GetInt64("id_one")
  163. id_two, _ := c.GetInt64("id_two")
  164. sch, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_one)
  165. sch_two, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_two)
  166. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  167. //if order2.ID > 0 {
  168. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  169. // return
  170. //}
  171. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  172. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  173. count, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch.PatientId)
  174. if count > 0 {
  175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  176. return
  177. }
  178. count1, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch.ScheduleDate, sch_two.PatientId)
  179. if count1 > 0 {
  180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  181. return
  182. }
  183. }
  184. err := service.UpdateScheduleThree(sch, sch_two)
  185. fmt.Println("id_one======================", sch.PatientId)
  186. fmt.Println("id_one======================", sch_two.PatientId)
  187. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  188. if order.ID > 0 {
  189. //查询该患者的排班机位
  190. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  191. service.UpdateDialysiOrderByPatientId(order.ID, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  192. redis := service.RedisClient()
  193. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  194. redis.Set(key, "", time.Second)
  195. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  196. //清空key 值
  197. redis.Set(keyOne, "", time.Second)
  198. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  199. //return
  200. }
  201. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  202. if orderOne.ID > 0 {
  203. //查询该患者的排班机位
  204. pSchedule, _ := service.GetPscheduleDate(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  205. service.UpdateDialysiOrderByPatientId(orderOne.ID, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  206. redis := service.RedisClient()
  207. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  208. redis.Set(key, "", time.Second)
  209. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  210. //清空key 值
  211. redis.Set(keyOne, "", time.Second)
  212. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  213. //return
  214. }
  215. if err == nil {
  216. //去除当天患者排班中重复数据,保留最后一条数据
  217. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  218. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  219. c.ServeSuccessJSON(map[string]interface{}{
  220. "msg": "交换成功",
  221. })
  222. } else {
  223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  224. return
  225. }
  226. }
  227. func (c *ScheduleApiController) BatchPostSmartSch() {
  228. patient_id, _ := c.GetInt64("patient_id")
  229. adminInfo := c.GetAdminUserInfo()
  230. patientInfo, _ := service.FindPatientById(adminInfo.CurrentOrgId, patient_id)
  231. if patientInfo.ID == 0 {
  232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  233. return
  234. }
  235. dataBody := make(map[string]interface{}, 0)
  236. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  237. if err != nil {
  238. utils.ErrorLog(err.Error())
  239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  240. return
  241. }
  242. //drugOutConfig, _ := service.FindDrugOutConfigById(adminInfo.CurrentOrgId)
  243. //
  244. //recordDateStr := time.Now().Format("2006-01-02")
  245. //
  246. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  247. //退库
  248. //if drugOutConfig.IsOpen == 1 {
  249. // hisAdvice, _ := service.GetPatientDrugCountToday(patient_id, recordDate.Unix(), adminInfo.CurrentOrgId)
  250. //
  251. // if len(hisAdvice) > 0 {
  252. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
  253. // return
  254. // }
  255. //}
  256. //list, _ := service.GetPatientGoodCountToday(patient_id, recordDate.Unix(), adminInfo.CurrentOrgId)
  257. //if len(list) > 0 {
  258. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
  259. // return
  260. //}
  261. //数据校验
  262. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  263. schs, _ := dataBody["smart_schs"].([]interface{})
  264. if len(schs) > 0 {
  265. for _, item := range schs {
  266. items := item.(map[string]interface{})
  267. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  268. utils.ErrorLog("id")
  269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  270. return
  271. }
  272. var schedule models.Schedule
  273. //var oldSchedule *models.Schedule
  274. sch_id := int64(items["sch_id"].(float64))
  275. if sch_id > 0 { //修改排班信息
  276. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  277. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  278. utils.ErrorLog("mode_id")
  279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  280. return
  281. }
  282. modeId := int64(items["mode_id"].(float64))
  283. if modeId < 1 {
  284. utils.ErrorLog("modeId < 1")
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  286. return
  287. }
  288. schedule.ModeId = modeId
  289. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  290. if err != nil {
  291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  292. return
  293. }
  294. if order != nil {
  295. week_type, _ := items["week_type"].(string)
  296. week_name, _ := items["week_name"].(string)
  297. switch week_type {
  298. case "1":
  299. json := make(map[string]interface{})
  300. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  301. json["state"] = 0
  302. c.Data["json"] = json
  303. c.ServeJSON()
  304. break
  305. case "2":
  306. json := make(map[string]interface{})
  307. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  308. json["state"] = 0
  309. c.Data["json"] = json
  310. c.ServeJSON()
  311. break
  312. case "3":
  313. json := make(map[string]interface{})
  314. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  315. json["state"] = 0
  316. c.Data["json"] = json
  317. c.ServeJSON()
  318. break
  319. }
  320. return
  321. }
  322. if order != nil {
  323. week_type, _ := items["week_type"].(string)
  324. week_name, _ := items["week_name"].(string)
  325. switch week_type {
  326. case "1":
  327. json := make(map[string]interface{})
  328. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  329. json["state"] = 0
  330. c.Data["json"] = json
  331. c.ServeJSON()
  332. break
  333. case "2":
  334. json := make(map[string]interface{})
  335. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  336. json["state"] = 0
  337. c.Data["json"] = json
  338. c.ServeJSON()
  339. break
  340. case "3":
  341. json := make(map[string]interface{})
  342. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  343. json["state"] = 0
  344. c.Data["json"] = json
  345. c.ServeJSON()
  346. break
  347. }
  348. return
  349. }
  350. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  351. utils.ErrorLog("schedule_type")
  352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  353. return
  354. }
  355. scheduleType := int64(items["schedule_type"].(float64))
  356. if scheduleType < 1 || scheduleType > 3 {
  357. utils.ErrorLog("scheduleType < 3")
  358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  359. return
  360. }
  361. schedule.ScheduleType = scheduleType
  362. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  363. utils.ErrorLog("bed_id")
  364. fmt.Println("~~~~~~333333333")
  365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  366. return
  367. }
  368. bedId := int64(items["bed_id"].(float64))
  369. if bedId < 1 {
  370. utils.ErrorLog("bedId < 1")
  371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  372. return
  373. }
  374. schedule.BedId = bedId
  375. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  376. utils.ErrorLog("zone_id")
  377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  378. return
  379. }
  380. partitionId := int64(items["zone_id"].(float64))
  381. if partitionId < 1 {
  382. utils.ErrorLog("partitionId < 1")
  383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  384. return
  385. }
  386. schedule.PartitionId = partitionId
  387. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  388. if bed == nil {
  389. week_type, _ := items["week_type"].(string)
  390. week_name, _ := items["week_name"].(string)
  391. switch week_type {
  392. case "1":
  393. json := make(map[string]interface{})
  394. json["msg"] = "本周" + week_name + "的机号不存在,无法保存"
  395. json["state"] = 0
  396. c.Data["json"] = json
  397. c.ServeJSON()
  398. break
  399. case "2":
  400. json := make(map[string]interface{})
  401. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  402. json["state"] = 0
  403. c.Data["json"] = json
  404. c.ServeJSON()
  405. break
  406. case "3":
  407. json := make(map[string]interface{})
  408. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  409. json["state"] = 0
  410. c.Data["json"] = json
  411. c.ServeJSON()
  412. break
  413. }
  414. return
  415. }
  416. if bed.ZoneID != schedule.PartitionId {
  417. week_type, _ := items["week_type"].(string)
  418. week_name, _ := items["week_name"].(string)
  419. switch week_type {
  420. case "1":
  421. json := make(map[string]interface{})
  422. json["msg"] = "本周" + week_name + "所选机号不在选择分区中,无法保存"
  423. json["state"] = 0
  424. c.Data["json"] = json
  425. c.ServeJSON()
  426. break
  427. case "2":
  428. json := make(map[string]interface{})
  429. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  430. json["state"] = 0
  431. c.Data["json"] = json
  432. c.ServeJSON()
  433. break
  434. case "3":
  435. json := make(map[string]interface{})
  436. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  437. json["state"] = 0
  438. c.Data["json"] = json
  439. c.ServeJSON()
  440. break
  441. }
  442. return
  443. }
  444. startTime := schedule.ScheduleDate
  445. endTime := startTime + 86399
  446. //一天只有排班一次
  447. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  448. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  449. week_type, _ := items["week_type"].(string)
  450. week_name, _ := items["week_name"].(string)
  451. switch week_type {
  452. case "1":
  453. json := make(map[string]interface{})
  454. json["msg"] = "本周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  455. json["state"] = 0
  456. c.Data["json"] = json
  457. c.ServeJSON()
  458. break
  459. case "2":
  460. json := make(map[string]interface{})
  461. json["msg"] = "下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  462. json["state"] = 0
  463. c.Data["json"] = json
  464. c.ServeJSON()
  465. break
  466. case "3":
  467. json := make(map[string]interface{})
  468. json["msg"] = "下下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  469. json["state"] = 0
  470. c.Data["json"] = json
  471. c.ServeJSON()
  472. break
  473. }
  474. return
  475. }
  476. //同天同位置只能排一个
  477. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  478. if err != nil {
  479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  480. return
  481. }
  482. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  483. week_type, _ := items["week_type"].(string)
  484. week_name, _ := items["week_name"].(string)
  485. switch week_type {
  486. case "1":
  487. json := make(map[string]interface{})
  488. json["msg"] = "本周" + week_name + "所先位置排班已经存在,无法保存"
  489. json["state"] = 0
  490. c.Data["json"] = json
  491. c.ServeJSON()
  492. break
  493. case "2":
  494. json := make(map[string]interface{})
  495. json["msg"] = "下周" + week_name + "所先位置排班已经存在,无法保存"
  496. json["state"] = 0
  497. c.Data["json"] = json
  498. c.ServeJSON()
  499. break
  500. case "3":
  501. json := make(map[string]interface{})
  502. json["msg"] = "下下周" + week_name + "所先位置排班已经存在,无法保存"
  503. json["state"] = 0
  504. c.Data["json"] = json
  505. c.ServeJSON()
  506. break
  507. }
  508. return
  509. }
  510. } else { //新的排班信息
  511. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  513. return
  514. }
  515. scheduleDate, _ := items["schedule_date"].(string)
  516. if len(scheduleDate) == 0 {
  517. utils.ErrorLog("len(schedule_date) == 0")
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  519. return
  520. }
  521. timeLayout := "2006-01-02"
  522. loc, _ := time.LoadLocation("Local")
  523. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  524. if err != nil {
  525. utils.ErrorLog(err.Error())
  526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  527. return
  528. }
  529. schedule.ScheduleDate = theTime.Unix()
  530. //existSch,_ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId,schedule.ScheduleDate,patient_id)
  531. //
  532. //if existSch.ID > 0{
  533. // fmt.Println("555555555")
  534. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  535. // return
  536. //
  537. //}
  538. timeNow := time.Now().Format("2006-01-02")
  539. if timeNow > scheduleDate {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  541. return
  542. }
  543. scheduleType := int64(items["schedule_type"].(float64))
  544. if scheduleType < 1 || scheduleType > 3 {
  545. utils.ErrorLog("scheduleType < 3")
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  547. return
  548. }
  549. schedule.ScheduleType = scheduleType
  550. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  552. return
  553. }
  554. bedId := int64(items["bed_id"].(float64))
  555. if bedId < 1 {
  556. utils.ErrorLog("bedId < 1")
  557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  558. return
  559. }
  560. schedule.BedId = bedId
  561. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  562. utils.ErrorLog("zone_id")
  563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  564. return
  565. }
  566. partitionId := int64(items["zone_id"].(float64))
  567. if partitionId < 1 {
  568. utils.ErrorLog("zone_id < 1")
  569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  570. return
  571. }
  572. schedule.PartitionId = partitionId
  573. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  574. utils.ErrorLog("schedule_week")
  575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  576. return
  577. }
  578. scheduleWeek := int64(items["schedule_week"].(float64))
  579. if scheduleWeek < 1 || scheduleWeek > 7 {
  580. utils.ErrorLog("scheduleWeek < 1")
  581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  582. return
  583. }
  584. schedule.ScheduleWeek = scheduleWeek
  585. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  586. utils.ErrorLog("mode_id")
  587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  588. return
  589. }
  590. modeId := int64(items["mode_id"].(float64))
  591. if modeId < 1 && modeId > 14 {
  592. utils.ErrorLog("modeId < 1")
  593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  594. return
  595. }
  596. //校验当天改床位是否有排班,如果有排班则不能替换排班
  597. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  598. fmt.Println(sch.PatientId)
  599. fmt.Println(schedule.PatientId)
  600. if sch.ID > 0 && sch.PatientId != patient_id {
  601. week_type, _ := items["week_type"].(string)
  602. week_name, _ := items["week_name"].(string)
  603. switch week_type {
  604. case "1":
  605. json := make(map[string]interface{})
  606. json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
  607. json["state"] = 0
  608. c.Data["json"] = json
  609. c.ServeJSON()
  610. break
  611. case "2":
  612. json := make(map[string]interface{})
  613. json["msg"] = "下周" + week_name + "该床位已经有人排班,无法保存"
  614. json["state"] = 0
  615. c.Data["json"] = json
  616. c.ServeJSON()
  617. break
  618. case "3":
  619. json := make(map[string]interface{})
  620. json["msg"] = "下下周" + week_name + "该床位已经有人排班,无法保存"
  621. json["state"] = 0
  622. c.Data["json"] = json
  623. c.ServeJSON()
  624. break
  625. }
  626. return
  627. }
  628. //daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
  629. //if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  630. // week_type, _ := items["week_type"].(string)
  631. // week_name, _ := items["week_name"].(string)
  632. //
  633. // switch week_type {
  634. // case "1":
  635. // json := make(map[string]interface{})
  636. // json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
  637. // json["state"] = 0
  638. // c.Data["json"] = json
  639. // c.ServeJSON()
  640. // break
  641. // case "2":
  642. // json := make(map[string]interface{})
  643. // json["msg"] = "下周" + week_name + "当天该患者已经排班,无法保存"
  644. // json["state"] = 0
  645. // c.Data["json"] = json
  646. // c.ServeJSON()
  647. // break
  648. // case "3":
  649. // json := make(map[string]interface{})
  650. // json["msg"] = "下下周" + week_name + "当天该患者已经排班,无法保存"
  651. // json["state"] = 0
  652. // c.Data["json"] = json
  653. // c.ServeJSON()
  654. // break
  655. // }
  656. //
  657. // return
  658. //
  659. //
  660. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  661. // return
  662. //}
  663. //
  664. }
  665. }
  666. }
  667. }
  668. ////删除数据
  669. if dataBody["del_schs"] != nil && reflect.TypeOf(dataBody["del_schs"]).String() == "[]interface {}" {
  670. schs, _ := dataBody["del_schs"].([]interface{})
  671. if len(schs) > 0 {
  672. for _, item := range schs {
  673. items := item.(map[string]interface{})
  674. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  675. utils.ErrorLog("id")
  676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  677. return
  678. }
  679. var schedule models.Schedule
  680. sch_id := int64(items["sch_id"].(float64))
  681. if sch_id > 0 { //修改排班信息
  682. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  683. order, _ := service.GetDialysisOrderByPatientAndBed(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.BedId, schedule.PatientId)
  684. if order.ID > 0 {
  685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  686. return
  687. }
  688. schedule.Status = 0
  689. //针对凤凰医院
  690. if adminInfo.CurrentOrgId == 10579 || adminInfo.CurrentOrgId == 10344 || adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10679 {
  691. advice, _ := service.GetDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  692. if len(advice) > 0 {
  693. service.UpdateAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  694. }
  695. }
  696. //if adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10344 {
  697. // hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  698. // project, _ := service.GetHisPrescriptionProjectList(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  699. // if len(hisAdvice) > 0 {
  700. // service.UpdateHisAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  701. // }
  702. // if len(project) > 0 {
  703. // service.UpdateProjectObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  704. // }
  705. //}
  706. service.SaveSch(&schedule)
  707. }
  708. HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  709. //去除当天患者排班中重复数据,保留最后一条数据
  710. service.UpdateRepeatSchStatus(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  711. }
  712. }
  713. }
  714. ////修改或保存数据
  715. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  716. schs, _ := dataBody["smart_schs"].([]interface{})
  717. if len(schs) > 0 {
  718. for _, item := range schs {
  719. items := item.(map[string]interface{})
  720. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  721. utils.ErrorLog("id")
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  723. return
  724. }
  725. var schedule models.Schedule
  726. //var oldSchedule *models.Schedule
  727. sch_id := int64(items["sch_id"].(float64))
  728. if sch_id > 0 { //修改排班信息
  729. fmt.Println("!!!!!!!")
  730. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  731. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  732. fmt.Println(reflect.TypeOf(items["mode_id"]))
  733. utils.ErrorLog("mode_id")
  734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  735. return
  736. }
  737. modeId := int64(items["mode_id"].(float64))
  738. if modeId < 1 {
  739. utils.ErrorLog("modeId < 1")
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. schedule.ModeId = modeId
  744. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  745. if err != nil {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  747. return
  748. }
  749. if order != nil {
  750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  751. return
  752. }
  753. if order != nil {
  754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  755. return
  756. }
  757. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  758. utils.ErrorLog("schedule_type")
  759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  760. return
  761. }
  762. scheduleType := int64(items["schedule_type"].(float64))
  763. if scheduleType < 1 || scheduleType > 3 {
  764. utils.ErrorLog("scheduleType < 3")
  765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  766. return
  767. }
  768. schedule.ScheduleType = scheduleType
  769. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  770. utils.ErrorLog("bed_id")
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. bedId := int64(items["bed_id"].(float64))
  775. if bedId < 1 {
  776. utils.ErrorLog("bedId < 1")
  777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  778. return
  779. }
  780. schedule.BedId = bedId
  781. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  782. utils.ErrorLog("zone_id")
  783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  784. return
  785. }
  786. partitionId := int64(items["zone_id"].(float64))
  787. if partitionId < 1 {
  788. utils.ErrorLog("partitionId < 1")
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  790. return
  791. }
  792. schedule.PartitionId = partitionId
  793. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  794. if bed == nil {
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  796. return
  797. }
  798. if bed.ZoneID != schedule.PartitionId {
  799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  800. return
  801. }
  802. startTime := schedule.ScheduleDate
  803. endTime := startTime + 86399
  804. //一天只有排班一次
  805. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  806. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  808. return
  809. }
  810. //同天同位置只能排一个
  811. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  812. if err != nil {
  813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  814. return
  815. }
  816. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  818. return
  819. }
  820. var DialysisMachineName string
  821. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  822. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  823. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  824. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  825. if filedRecordOne.IsShow == 1 {
  826. DialysisMachineName = so.DialysisDialyszers
  827. }
  828. if filedRecordThree.IsShow == 1 {
  829. if len(DialysisMachineName) > 0 {
  830. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  831. } else {
  832. DialysisMachineName = so.DialyzerPerfusionApparatus
  833. }
  834. }
  835. if filedRecordTwo.IsShow == 1 {
  836. if len(DialysisMachineName) > 0 {
  837. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  838. } else {
  839. DialysisMachineName = so.DialysisIrrigation
  840. }
  841. }
  842. schedule.DialysisMachineName = DialysisMachineName
  843. schedule.IsExport = 3000
  844. service.SaveSch(&schedule)
  845. //去除当天患者排班中重复数据,保留最后一条数据
  846. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  847. } else { //新的排班信息
  848. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  850. return
  851. }
  852. scheduleDate, _ := items["schedule_date"].(string)
  853. if len(scheduleDate) == 0 {
  854. utils.ErrorLog("len(schedule_date) == 0")
  855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  856. return
  857. }
  858. timeLayout := "2006-01-02"
  859. loc, _ := time.LoadLocation("Local")
  860. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  861. if err != nil {
  862. utils.ErrorLog(err.Error())
  863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  864. return
  865. }
  866. schedule.ScheduleDate = theTime.Unix()
  867. timeNow := time.Now().Format("2006-01-02")
  868. if timeNow > scheduleDate {
  869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  870. return
  871. }
  872. scheduleType := int64(items["schedule_type"].(float64))
  873. if scheduleType < 1 || scheduleType > 3 {
  874. utils.ErrorLog("scheduleType < 3")
  875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  876. return
  877. }
  878. schedule.ScheduleType = scheduleType
  879. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  880. utils.ErrorLog("bed_id")
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  882. return
  883. }
  884. bedId := int64(items["bed_id"].(float64))
  885. if bedId < 1 {
  886. utils.ErrorLog("bedId < 1")
  887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  888. return
  889. }
  890. schedule.BedId = bedId
  891. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  892. utils.ErrorLog("zone_id")
  893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  894. return
  895. }
  896. partitionId := int64(items["zone_id"].(float64))
  897. if partitionId < 1 {
  898. utils.ErrorLog("zone_id < 1")
  899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  900. return
  901. }
  902. schedule.PartitionId = partitionId
  903. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  904. utils.ErrorLog("schedule_week")
  905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  906. return
  907. }
  908. scheduleWeek := int64(items["schedule_week"].(float64))
  909. if scheduleWeek < 1 || scheduleWeek > 7 {
  910. utils.ErrorLog("scheduleWeek < 1")
  911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  912. return
  913. }
  914. schedule.ScheduleWeek = scheduleWeek
  915. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  916. fmt.Println(reflect.TypeOf(items["mode_id"]))
  917. utils.ErrorLog("mode_id")
  918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  919. return
  920. }
  921. modeId := int64(items["mode_id"].(float64))
  922. if modeId < 1 && modeId > 14 {
  923. utils.ErrorLog("modeId < 1")
  924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  925. return
  926. }
  927. //校验当天改床位是否有排班,如果有排班则不能替换排班
  928. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  929. if sch.ID > 0 && sch.PatientId != patient_id {
  930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
  931. return
  932. }
  933. var DialysisMachineName string
  934. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  935. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  936. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  937. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  938. if filedRecordOne.IsShow == 1 {
  939. DialysisMachineName = so.DialysisDialyszers
  940. }
  941. if filedRecordThree.IsShow == 1 {
  942. if len(schedule.DialysisMachineName) > 0 {
  943. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  944. } else {
  945. DialysisMachineName = so.DialyzerPerfusionApparatus
  946. }
  947. }
  948. if filedRecordTwo.IsShow == 1 {
  949. if len(DialysisMachineName) > 0 {
  950. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  951. } else {
  952. DialysisMachineName = so.DialysisIrrigation
  953. }
  954. }
  955. schedule.DialysisMachineName = DialysisMachineName
  956. //判断当前保存的患者是否已经有排班
  957. existSchedule, _ := service.GetScheduleByDate(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  958. if existSchedule.ID > 0 {
  959. existSchedule.ModeId = modeId
  960. existSchedule.BedId = schedule.BedId
  961. existSchedule.PartitionId = schedule.PartitionId
  962. existSchedule.ScheduleType = schedule.ScheduleType
  963. existSchedule.DialysisMachineName = schedule.DialysisMachineName
  964. existSchedule.IsExport = 3001
  965. service.SaveSmartSch(existSchedule)
  966. } else {
  967. schedule.ModeId = modeId
  968. schedule.PatientId = patient_id
  969. schedule.CreatedTime = time.Now().Unix()
  970. schedule.UpdatedTime = time.Now().Unix()
  971. schedule.Status = 1
  972. schedule.UserOrgId = adminInfo.CurrentOrgId
  973. var DialysisMachineName string
  974. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  975. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  976. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  977. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  978. if filedRecordOne.IsShow == 1 {
  979. DialysisMachineName = so.DialysisDialyszers
  980. }
  981. if filedRecordThree.IsShow == 1 {
  982. if len(DialysisMachineName) > 0 {
  983. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  984. } else {
  985. DialysisMachineName = so.DialyzerPerfusionApparatus
  986. }
  987. }
  988. if filedRecordTwo.IsShow == 1 {
  989. if len(DialysisMachineName) > 0 {
  990. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  991. } else {
  992. DialysisMachineName = so.DialysisIrrigation
  993. }
  994. }
  995. schedule.DialysisMachineName = DialysisMachineName
  996. //schedule.DialysisMachineName = schedule.DialysisMachineName
  997. daySchedule, _ := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
  998. if daySchedule.ID > 0 {
  999. daySchedule.ModeId = schedule.ModeId
  1000. daySchedule.ScheduleType = schedule.ScheduleType
  1001. daySchedule.PartitionId = schedule.PartitionId
  1002. daySchedule.BedId = schedule.BedId
  1003. daySchedule.DialysisMachineName = schedule.DialysisMachineName
  1004. existSchedule.IsExport = 3002
  1005. service.SaveSch(&daySchedule)
  1006. } else {
  1007. existSchedule.IsExport = 3003
  1008. service.CreateScheduleTwo(&schedule)
  1009. }
  1010. }
  1011. }
  1012. //去除当天患者排班中重复数据,保留最后一条数据
  1013. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  1014. c.ServeSuccessJSON(map[string]interface{}{
  1015. "msg": "保存成功",
  1016. })
  1017. HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  1018. }
  1019. } else {
  1020. c.ServeSuccessJSON(map[string]interface{}{
  1021. "msg": "保存成功",
  1022. })
  1023. }
  1024. }
  1025. }
  1026. func HandleRedis(org_id int64, sch_date int64) {
  1027. redis := service.RedisClient()
  1028. //处方
  1029. keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":prescriptions_list_all"
  1030. redis.Set(keyOne, "", time.Second)
  1031. //医嘱
  1032. keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":advice_list_all"
  1033. redis.Set(keyTwo, "", time.Second)
  1034. keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_befores_list_all"
  1035. redis.Set(keySix, "", time.Second)
  1036. keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_after_dislysis_list_all"
  1037. redis.Set(keyThree, "", time.Second)
  1038. keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":monitor_record_list_all"
  1039. redis.Set(keyFour, "", time.Second)
  1040. keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":treatment_summarys_list_all"
  1041. redis.Set(keyFive, "", time.Second)
  1042. keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":dialysis_orders_list_all"
  1043. redis.Set(keySeven, "", time.Second)
  1044. defer redis.Close()
  1045. }
  1046. func (c *ScheduleApiController) GetSmartSch() {
  1047. patient_id, _ := c.GetInt64("patient_id")
  1048. fmt.Println("~~~~~~")
  1049. fmt.Println(patient_id)
  1050. fmt.Println("~~~~~~")
  1051. adminUserInfo := c.GetAdminUserInfo()
  1052. sch, err := service.GetSmartSchPatientByPatientID(adminUserInfo.CurrentOrgId, patient_id)
  1053. if err != nil {
  1054. utils.ErrorLog(err.Error())
  1055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1056. return
  1057. }
  1058. c.ServeSuccessJSON(map[string]interface{}{
  1059. "sch": sch,
  1060. })
  1061. }
  1062. func (c *ScheduleApiController) GetPatient() {
  1063. keyWord := c.GetString("keyword")
  1064. adminUserInfo := c.GetAdminUserInfo()
  1065. patient, err := service.GetSmartSchPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  1066. if err != nil {
  1067. utils.ErrorLog(err.Error())
  1068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1069. return
  1070. }
  1071. c.ServeSuccessJSON(map[string]interface{}{
  1072. "patient": patient,
  1073. })
  1074. }
  1075. func (c *ScheduleApiController) GetPatientSchTemplate() {
  1076. //patient_id, _ := c.GetInt64("patient_id",0)
  1077. keyWord := c.GetString("keyword")
  1078. adminUserInfo := c.GetAdminUserInfo()
  1079. patient, err := service.GetSmartSchTemplatePatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  1080. if err != nil {
  1081. utils.ErrorLog(err.Error())
  1082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1083. return
  1084. }
  1085. c.ServeSuccessJSON(map[string]interface{}{
  1086. "patient": patient,
  1087. })
  1088. }
  1089. func (c *ScheduleApiController) GetPatientSmartSch() {
  1090. patient_id, _ := c.GetInt64("patient_id", 0)
  1091. adminUserInfo := c.GetAdminUserInfo()
  1092. schs, err := service.GetSmartSchPatientByID(adminUserInfo.CurrentOrgId, patient_id)
  1093. if err != nil {
  1094. utils.ErrorLog(err.Error())
  1095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1096. return
  1097. }
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "schedules": schs,
  1100. })
  1101. }
  1102. func (c *ScheduleApiController) GetPatientSmartSchTemplate() {
  1103. patient_id, _ := c.GetInt64("patient_id", 0)
  1104. adminUserInfo := c.GetAdminUserInfo()
  1105. mode, _ := service.GetOrgPatientScheduleTemplateModeTwo(adminUserInfo.CurrentOrgId)
  1106. if mode.ID > 0 {
  1107. if mode.Mode == 0 {
  1108. //schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id)
  1109. c.ServeSuccessJSON(map[string]interface{}{
  1110. "status": 0,
  1111. })
  1112. } else if mode.Mode == 1 {
  1113. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 1)
  1114. c.ServeSuccessJSON(map[string]interface{}{
  1115. "status": 0,
  1116. "schedules_template": schs,
  1117. })
  1118. } else if mode.Mode == 2 {
  1119. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 2)
  1120. c.ServeSuccessJSON(map[string]interface{}{
  1121. "status": 1,
  1122. "schedules_template": schs,
  1123. })
  1124. } else if mode.Mode == 3 {
  1125. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 3)
  1126. c.ServeSuccessJSON(map[string]interface{}{
  1127. "status": 1,
  1128. "schedules_template": schs,
  1129. })
  1130. } else if mode.Mode == 4 {
  1131. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 4)
  1132. c.ServeSuccessJSON(map[string]interface{}{
  1133. "status": 1,
  1134. "schedules_template": schs,
  1135. })
  1136. }
  1137. } else {
  1138. c.ServeSuccessJSON(map[string]interface{}{
  1139. "status": 0,
  1140. })
  1141. }
  1142. }
  1143. func (c *ScheduleApiController) GetDevicesNumbers() {
  1144. sch_type, _ := c.GetInt("sch_type", 0)
  1145. zone_id, _ := c.GetInt64("zone_id", 0)
  1146. patient_id, _ := c.GetInt64("patient_id", 0)
  1147. schedule_date := c.GetString("schedule_date")
  1148. timeLayout := "2006-01-02"
  1149. loc, _ := time.LoadLocation("Local")
  1150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  1151. if err != nil {
  1152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1153. return
  1154. }
  1155. recordDateTime := theTime.Unix()
  1156. deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, sch_type, zone_id, patient_id)
  1157. if getDeviceNumbersErr != nil {
  1158. c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1160. return
  1161. }
  1162. c.ServeSuccessJSON(map[string]interface{}{
  1163. "devices": deviceNumbers,
  1164. })
  1165. }
  1166. func (c *ScheduleApiController) GetWeekPanels() {
  1167. data, _ := c.GetInt64("data", 1)
  1168. patitionIdStr := c.GetString("patitionid")
  1169. var ids []string
  1170. if len(patitionIdStr) > 0 {
  1171. ids = strings.Split(patitionIdStr, ",")
  1172. }
  1173. adminInfo := c.GetAdminUserInfo()
  1174. thisTime := time.Now()
  1175. year, monthTime, day := thisTime.Date()
  1176. month := int(monthTime)
  1177. _, theWeek := thisTime.ISOWeek()
  1178. lastWeek := thisTime.AddDate(0, 0, -7)
  1179. nextWeek := thisTime.AddDate(0, 0, 7)
  1180. nextSecWeek := thisTime.AddDate(0, 0, 14)
  1181. _, theLastWeek := lastWeek.ISOWeek()
  1182. _, theNextWeek := nextWeek.ISOWeek()
  1183. _, theNextSecWeek := nextSecWeek.ISOWeek()
  1184. weekDay := int(thisTime.Weekday())
  1185. if weekDay == 0 {
  1186. weekDay = 7
  1187. }
  1188. weekEnd := 7 - weekDay
  1189. weekStart := weekEnd - 6
  1190. weekDays := make([]string, 0)
  1191. for index := weekStart; index <= weekEnd; index++ {
  1192. theDay := thisTime.AddDate(0, 0, index)
  1193. indexYear, indexMonthTime, indexDay := theDay.Date()
  1194. indexMonth := int(indexMonthTime)
  1195. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1196. weekDays = append(weekDays, indexWeek)
  1197. }
  1198. returnData := map[string]interface{}{
  1199. "year": year,
  1200. "month": month,
  1201. "day": day,
  1202. "theWeek": theWeek,
  1203. "theNextWeek": theNextWeek,
  1204. "theNextSecWeek": theNextSecWeek,
  1205. "theLastWeek": theLastWeek,
  1206. "weekDay": weekDay,
  1207. "weekDays": weekDays,
  1208. }
  1209. if data == 1 {
  1210. partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, ids)
  1211. returnData["partitions"] = partitions
  1212. }
  1213. c.ServeSuccessJSON(returnData)
  1214. return
  1215. }
  1216. func (c *ScheduleApiController) GetSchedules() {
  1217. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  1218. partition_id, _ := c.GetInt64("partition_id")
  1219. schedule_type, _ := c.GetInt64("schedule_type")
  1220. is_before, _ := c.GetInt64("is_before")
  1221. start_time := c.GetString("start_time")
  1222. end_time := c.GetString("end_time")
  1223. adminInfo := c.GetAdminUserInfo()
  1224. thisTime := time.Now()
  1225. today := thisTime.Format("2006-01-02")
  1226. if week < 1 || week > 4 {
  1227. week = 2
  1228. }
  1229. if week == 1 {
  1230. thisTime = thisTime.AddDate(0, 0, -7)
  1231. } else if week == 3 {
  1232. thisTime = thisTime.AddDate(0, 0, 7)
  1233. } else if week == 4 {
  1234. thisTime = thisTime.AddDate(0, 0, 14)
  1235. }
  1236. weekDay := int(thisTime.Weekday())
  1237. if weekDay == 0 {
  1238. weekDay = 7
  1239. }
  1240. weekEnd := 7 - weekDay
  1241. weekStart := weekEnd - 6
  1242. weekTitle := make([]string, 0)
  1243. days := make([]string, 0)
  1244. for index := weekStart; index <= weekEnd; index++ {
  1245. theDay := thisTime.AddDate(0, 0, index)
  1246. indexYear, indexMonthTime, indexDay := theDay.Date()
  1247. indexMonth := int(indexMonthTime)
  1248. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1249. weekTitle = append(weekTitle, indexWeek)
  1250. days = append(days, theDay.Format("2006-01-02"))
  1251. }
  1252. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  1253. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  1254. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1255. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1256. timeLayout := "2006-01-02 15:04:05"
  1257. loc, _ := time.LoadLocation("Local")
  1258. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1259. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1260. weekStartPoint := theStarTime.Unix()
  1261. weekEndPoint := theEndTime.Unix()
  1262. if is_before > 0 {
  1263. timeLayout := "2006-01-02 15:04:05"
  1264. loc, _ := time.LoadLocation("Local")
  1265. theStarTime, _ := time.ParseInLocation(timeLayout, start_time, loc)
  1266. theEndTime, _ := time.ParseInLocation(timeLayout, end_time, loc)
  1267. weekStartPoint = theStarTime.Unix()
  1268. weekEndPoint = theEndTime.Unix()
  1269. }
  1270. schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
  1271. c.ServeSuccessJSON(map[string]interface{}{
  1272. "days": days,
  1273. "weekTitle": weekTitle,
  1274. "schdules": schdules,
  1275. "today": today,
  1276. })
  1277. return
  1278. }
  1279. func (c *ScheduleApiController) GetPatients() {
  1280. keywords := c.GetString("keywords", "")
  1281. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  1282. contagion, _ := c.GetInt64("contagion", 0)
  1283. adminInfo := c.GetAdminUserInfo()
  1284. thisTime := time.Now()
  1285. weekDay := int(thisTime.Weekday())
  1286. if weekDay == 0 {
  1287. weekDay = 7
  1288. }
  1289. thisWeekEnd := 7 - weekDay
  1290. weekStartPoint := thisWeekEnd - 6
  1291. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  1292. weekEndPoint := thisWeekEnd + 7
  1293. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  1294. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  1295. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1296. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1297. fmt.Println(weekStartTime, weekEndTime)
  1298. timeLayout := "2006-01-02 15:04:05"
  1299. loc, _ := time.LoadLocation("Local")
  1300. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1301. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1302. weekStart := theStarTime.Unix()
  1303. weekEnd := theEndTime.Unix()
  1304. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  1305. c.ServeSuccessJSON(map[string]interface{}{
  1306. "patients": patients,
  1307. })
  1308. return
  1309. }
  1310. func (c *ScheduleApiController) CreateSchedule() {
  1311. patientID, _ := c.GetInt64("patient_id", 0)
  1312. if patientID <= 0 {
  1313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1314. return
  1315. }
  1316. adminUserInfo := c.GetAdminUserInfo()
  1317. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  1318. if patientInfo.ID == 0 {
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1320. return
  1321. }
  1322. var schedule models.Schedule
  1323. dataBody := make(map[string]interface{}, 0)
  1324. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1325. if err != nil {
  1326. utils.ErrorLog(err.Error())
  1327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1328. return
  1329. }
  1330. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1332. return
  1333. }
  1334. scheduleDate, _ := dataBody["schedule_date"].(string)
  1335. if len(scheduleDate) == 0 {
  1336. utils.ErrorLog("len(schedule_date) == 0")
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. timeLayout := "2006-01-02"
  1341. loc, _ := time.LoadLocation("Local")
  1342. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  1343. if err != nil {
  1344. utils.ErrorLog(err.Error())
  1345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1346. return
  1347. }
  1348. schedule.ScheduleDate = theTime.Unix()
  1349. timeNow := time.Now().Format("2006-01-02")
  1350. if timeNow > scheduleDate {
  1351. utils.ErrorLog(timeNow)
  1352. utils.ErrorLog(scheduleDate)
  1353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1354. return
  1355. }
  1356. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1357. utils.ErrorLog("schedule_type")
  1358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1359. return
  1360. }
  1361. scheduleType := int64(dataBody["schedule_type"].(float64))
  1362. if scheduleType < 1 || scheduleType > 3 {
  1363. utils.ErrorLog("scheduleType < 3")
  1364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1365. return
  1366. }
  1367. schedule.ScheduleType = scheduleType
  1368. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1369. utils.ErrorLog("bed_id")
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1371. return
  1372. }
  1373. bedId := int64(dataBody["bed_id"].(float64))
  1374. if bedId < 1 {
  1375. utils.ErrorLog("bedId < 1")
  1376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1377. return
  1378. }
  1379. schedule.BedId = bedId
  1380. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1381. utils.ErrorLog("partition_id")
  1382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1383. return
  1384. }
  1385. partitionId := int64(dataBody["partition_id"].(float64))
  1386. if partitionId < 1 {
  1387. utils.ErrorLog("partitionId < 1")
  1388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1389. return
  1390. }
  1391. schedule.PartitionId = partitionId
  1392. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  1393. utils.ErrorLog("schedule_week")
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1395. return
  1396. }
  1397. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  1398. if scheduleWeek < 1 || scheduleWeek > 7 {
  1399. utils.ErrorLog("scheduleWeek < 1")
  1400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1401. return
  1402. }
  1403. schedule.ScheduleWeek = scheduleWeek
  1404. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1405. utils.ErrorLog("mode_id")
  1406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1407. return
  1408. }
  1409. modeId := int64(dataBody["mode_id"].(float64))
  1410. if modeId < 1 && modeId > 14 {
  1411. utils.ErrorLog("modeId < 1")
  1412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1413. return
  1414. }
  1415. schedule.ModeId = modeId
  1416. schedule.PatientId = patientID
  1417. schedule.CreatedTime = time.Now().Unix()
  1418. schedule.UpdatedTime = time.Now().Unix()
  1419. schedule.Status = 1
  1420. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  1421. schedule.IsExport = 5
  1422. var DialysisMachineName string
  1423. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1424. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  1425. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  1426. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  1427. if filedRecordOne.IsShow == 1 {
  1428. DialysisMachineName = so.DialysisDialyszers
  1429. }
  1430. if filedRecordThree.IsShow == 1 {
  1431. if len(DialysisMachineName) > 0 {
  1432. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1433. } else {
  1434. DialysisMachineName = so.DialyzerPerfusionApparatus
  1435. }
  1436. }
  1437. if filedRecordTwo.IsShow == 1 {
  1438. if len(DialysisMachineName) > 0 {
  1439. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1440. } else {
  1441. DialysisMachineName = so.DialysisIrrigation
  1442. }
  1443. }
  1444. schedule.DialysisMachineName = DialysisMachineName
  1445. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  1446. if bed == nil {
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1448. return
  1449. }
  1450. if bed.ZoneID != schedule.PartitionId {
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1452. return
  1453. }
  1454. scheduleDateStart := scheduleDate + " 00:00:00"
  1455. scheduleDateEnd := scheduleDate + " 23:59:59"
  1456. timeLayout = "2006-01-02 15:04:05"
  1457. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1458. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1459. startTime := theStartTime.Unix()
  1460. endTime := theEndTime.Unix()
  1461. //一天只有排班一次
  1462. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  1463. if daySchedule.ID > 0 {
  1464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1465. return
  1466. }
  1467. //同天同位置只能排一个
  1468. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1469. if err != nil {
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1471. return
  1472. }
  1473. if pointSchedule.ID > 0 {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1475. return
  1476. }
  1477. redis := service.RedisClient()
  1478. schedule.IsExport = 1000
  1479. err = service.CreateScheduleTwo(&schedule)
  1480. //记录日志
  1481. byterequest, _ := json.Marshal(schedule)
  1482. scheduleLog := models.XtScheduleLog{
  1483. UserOrgId: adminUserInfo.CurrentOrgId,
  1484. RecordDate: schedule.ScheduleDate,
  1485. Status: 1,
  1486. PatientId: schedule.PatientId,
  1487. Ctime: time.Now().Unix(),
  1488. Mtime: 0,
  1489. ErrLog: string(byterequest),
  1490. Source: "电脑端新增排班",
  1491. Module: 1,
  1492. AdminUserId: adminUserInfo.AdminUser.Id,
  1493. }
  1494. service.CreateScheduleLog(scheduleLog)
  1495. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1496. redis.Set(key, "", time.Second)
  1497. //处方
  1498. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1499. redis.Set(keyOne, "", time.Second)
  1500. //医嘱
  1501. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1502. redis.Set(keyTwo, "", time.Second)
  1503. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1504. redis.Set(keySix, "", time.Second)
  1505. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1506. redis.Set(keyThree, "", time.Second)
  1507. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1508. redis.Set(keyFour, "", time.Second)
  1509. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1510. redis.Set(keyFive, "", time.Second)
  1511. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1512. redis.Set(keySeven, "", time.Second)
  1513. fmt.Println(err)
  1514. defer redis.Close()
  1515. if err != nil {
  1516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  1517. return
  1518. }
  1519. schedule.Patient = patientInfo.Name
  1520. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  1521. c.ServeSuccessJSON(map[string]interface{}{
  1522. "msg": "ok",
  1523. "schedule": schedule,
  1524. })
  1525. return
  1526. }
  1527. func (c *ScheduleApiController) CreateScheduleTwo() {
  1528. patientID, _ := c.GetInt64("patient_id", 0)
  1529. id, _ := c.GetInt64("id_two", 0)
  1530. if id <= 0 {
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. adminINfo := c.GetAdminUserInfo()
  1535. schedule_two, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1536. timeNow := time.Now().Format("2006-01-02")
  1537. timeTemplate := "2006-01-02"
  1538. tm := time.Unix(int64(schedule_two.ScheduleDate), 0)
  1539. timeStr := tm.Format(timeTemplate)
  1540. if timeNow > timeStr {
  1541. utils.ErrorLog(timeNow)
  1542. utils.ErrorLog(timeStr)
  1543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1544. return
  1545. }
  1546. //if schedule_two == nil {
  1547. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1548. // return
  1549. //}
  1550. //order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule_two.ScheduleDate, schedule_two.PatientId)
  1551. //if err != nil {
  1552. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1553. // return
  1554. //}
  1555. //
  1556. //if order != nil {
  1557. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  1558. // return
  1559. //}
  1560. schedule_two.Status = 0
  1561. schedule_two.UpdatedTime = time.Now().Unix()
  1562. if patientID <= 0 {
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1564. return
  1565. }
  1566. adminUserInfo := c.GetAdminUserInfo()
  1567. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  1568. if patientInfo.ID == 0 {
  1569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1570. return
  1571. }
  1572. var schedule models.Schedule
  1573. dataBody := make(map[string]interface{}, 0)
  1574. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1575. if err != nil {
  1576. utils.ErrorLog(err.Error())
  1577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1578. return
  1579. }
  1580. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  1581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1582. return
  1583. }
  1584. scheduleDate, _ := dataBody["schedule_date"].(string)
  1585. if len(scheduleDate) == 0 {
  1586. utils.ErrorLog("len(schedule_date) == 0")
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1588. return
  1589. }
  1590. timeLayout := "2006-01-02"
  1591. loc, _ := time.LoadLocation("Local")
  1592. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  1593. if err != nil {
  1594. utils.ErrorLog(err.Error())
  1595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1596. return
  1597. }
  1598. schedule.ScheduleDate = theTime.Unix()
  1599. timeNow = time.Now().Format("2006-01-02")
  1600. if timeNow > scheduleDate {
  1601. utils.ErrorLog(timeNow)
  1602. utils.ErrorLog(scheduleDate)
  1603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1604. return
  1605. }
  1606. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1607. utils.ErrorLog("schedule_type")
  1608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1609. return
  1610. }
  1611. scheduleType := int64(dataBody["schedule_type"].(float64))
  1612. if scheduleType < 1 || scheduleType > 3 {
  1613. utils.ErrorLog("scheduleType < 3")
  1614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1615. return
  1616. }
  1617. schedule.ScheduleType = scheduleType
  1618. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1619. utils.ErrorLog("bed_id")
  1620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1621. return
  1622. }
  1623. bedId := int64(dataBody["bed_id"].(float64))
  1624. if bedId < 1 {
  1625. utils.ErrorLog("bedId < 1")
  1626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1627. return
  1628. }
  1629. schedule.BedId = bedId
  1630. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1631. utils.ErrorLog("partition_id")
  1632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1633. return
  1634. }
  1635. partitionId := int64(dataBody["partition_id"].(float64))
  1636. if partitionId < 1 {
  1637. utils.ErrorLog("partitionId < 1")
  1638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1639. return
  1640. }
  1641. schedule.PartitionId = partitionId
  1642. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  1643. utils.ErrorLog("schedule_week")
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1645. return
  1646. }
  1647. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  1648. if scheduleWeek < 1 || scheduleWeek > 7 {
  1649. utils.ErrorLog("scheduleWeek < 1")
  1650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1651. return
  1652. }
  1653. schedule.ScheduleWeek = scheduleWeek
  1654. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1655. utils.ErrorLog("mode_id")
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1657. return
  1658. }
  1659. modeId := int64(dataBody["mode_id"].(float64))
  1660. if modeId < 1 && modeId > 14 {
  1661. utils.ErrorLog("modeId < 1")
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1663. return
  1664. }
  1665. schedule.ModeId = modeId
  1666. schedule.PatientId = patientID
  1667. schedule.CreatedTime = time.Now().Unix()
  1668. schedule.UpdatedTime = time.Now().Unix()
  1669. schedule.Status = 1
  1670. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  1671. schedule.IsExport = 5
  1672. var DialysisMachineName string
  1673. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1674. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  1675. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  1676. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  1677. if filedRecordOne.IsShow == 1 {
  1678. DialysisMachineName = so.DialysisDialyszers
  1679. }
  1680. if filedRecordThree.IsShow == 1 {
  1681. if len(DialysisMachineName) > 0 {
  1682. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1683. } else {
  1684. DialysisMachineName = so.DialyzerPerfusionApparatus
  1685. }
  1686. }
  1687. if filedRecordTwo.IsShow == 1 {
  1688. if len(DialysisMachineName) > 0 {
  1689. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1690. } else {
  1691. DialysisMachineName = so.DialysisIrrigation
  1692. }
  1693. }
  1694. schedule.DialysisMachineName = DialysisMachineName
  1695. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  1696. if bed == nil {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1698. return
  1699. }
  1700. if bed.ZoneID != schedule.PartitionId {
  1701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1702. return
  1703. }
  1704. //scheduleDateStart := scheduleDate + " 00:00:00"
  1705. //scheduleDateEnd := scheduleDate + " 23:59:59"
  1706. timeLayout = "2006-01-02 15:04:05"
  1707. //theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1708. //theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1709. //startTime := theStartTime.Unix()
  1710. //endTime := theEndTime.Unix()
  1711. ////一天只有排班一次
  1712. //daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  1713. //if daySchedule.ID > 0 {
  1714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1715. // return
  1716. //}
  1717. //同天同位置只能排一个
  1718. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1719. if err != nil {
  1720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1721. return
  1722. }
  1723. if pointSchedule.ID > 0 {
  1724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1725. return
  1726. }
  1727. schedule.IsExport = 1000
  1728. err = service.CreateSchedule(&schedule, id)
  1729. lastSchedule, _ := service.GetLastSchedule(patientID, adminUserInfo.CurrentOrgId)
  1730. //查询上机床位号 更改床位号
  1731. order, err := service.GetOneDialysisOrderOne(adminINfo.CurrentOrgId, schedule_two.ScheduleDate, schedule_two.PatientId)
  1732. scheduleObj, _ := service.GetPatientScheduleByPatientId(patientID, adminUserInfo.CurrentOrgId, schedule_two.ScheduleDate)
  1733. if order.ID > 0 {
  1734. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  1735. redis := service.RedisClient()
  1736. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_order"
  1737. redis.Set(key, "", time.Second)
  1738. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1739. //清空key 值
  1740. redis.Set(keyOne, "", time.Second)
  1741. keySix := "scheduals_" + timeNow + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1742. redis.Set(keySix, "", time.Second)
  1743. }
  1744. redis := service.RedisClient()
  1745. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1746. redis.Set(key, "", time.Second)
  1747. //处方
  1748. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1749. redis.Set(keyOne, "", time.Second)
  1750. //医嘱
  1751. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1752. redis.Set(keyTwo, "", time.Second)
  1753. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1754. redis.Set(keySix, "", time.Second)
  1755. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1756. redis.Set(keyThree, "", time.Second)
  1757. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1758. redis.Set(keyFour, "", time.Second)
  1759. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1760. redis.Set(keyFive, "", time.Second)
  1761. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1762. redis.Set(keySeven, "", time.Second)
  1763. defer redis.Close()
  1764. schedule.Patient = patientInfo.Name
  1765. //去除当天患者排班中重复数据,保留最后一条数据
  1766. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  1767. c.ServeSuccessJSON(map[string]interface{}{
  1768. "msg": "ok",
  1769. "schedule": schedule,
  1770. "schedule_two": schedule_two,
  1771. "lastSchedule": lastSchedule,
  1772. })
  1773. return
  1774. }
  1775. func (c *ScheduleApiController) DeleteSchedule() {
  1776. id, _ := c.GetInt64("id", 0)
  1777. if id <= 0 {
  1778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1779. return
  1780. }
  1781. adminINfo := c.GetAdminUserInfo()
  1782. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1783. timeNow := time.Now().Format("2006-01-02")
  1784. timeTemplate := "2006-01-02"
  1785. tm := time.Unix(int64(schedule.ScheduleDate), 0)
  1786. timeStr := tm.Format(timeTemplate)
  1787. if timeNow > timeStr {
  1788. utils.ErrorLog(timeNow)
  1789. utils.ErrorLog(timeStr)
  1790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1791. return
  1792. }
  1793. if schedule == nil {
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1795. return
  1796. }
  1797. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1798. if err != nil {
  1799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1800. return
  1801. }
  1802. if order != nil {
  1803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  1804. return
  1805. }
  1806. schedule.Status = 0
  1807. schedule.UpdatedTime = time.Now().Unix()
  1808. //如果使用的是保存出库功能
  1809. drugOutConfig, _ := service.FindDrugOutConfigById(adminINfo.CurrentOrgId)
  1810. //退库
  1811. if drugOutConfig.IsOpen == 1 {
  1812. hisAdvice, _ := service.GetPatientDrugCountToday(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1813. if len(hisAdvice) > 0 {
  1814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
  1815. return
  1816. }
  1817. //for _, item := range hisAdvice {
  1818. // creater := adminINfo.AdminUser.Id
  1819. // err = service.DrugAutoAddCancelInfo(item, creater)
  1820. // if err != nil {
  1821. // err = fmt.Errorf("!:%v", err)
  1822. // return
  1823. // }
  1824. //}
  1825. ////查询是否有出库记录
  1826. //service.GetPatientGoodStockCount(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1827. }
  1828. //查询该患者当天是否开耗材
  1829. list, _ := service.GetPatientGoodCountToday(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1830. if len(list) > 0 {
  1831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
  1832. return
  1833. //operation_time := time.Now().Unix()
  1834. //creater := c.GetAdminUserInfo().AdminUser.Id
  1835. ////创建退库单
  1836. //timeStr := time.Now().Format("2006-01-02")
  1837. //timeArr := strings.Split(timeStr, "-")
  1838. //total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1839. //total = total + 1
  1840. //orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1841. //houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1842. //cancelStock := models.CancelStock{
  1843. // OrderNumber: orderNumber,
  1844. // OperaTime: operation_time,
  1845. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1846. // Creater: creater,
  1847. // Ctime: time.Now().Unix(),
  1848. // Status: 1,
  1849. // ReturnTime: schedule.ScheduleDate,
  1850. // Type: 1,
  1851. // StorehouseId: houseConfig.StorehouseOutInfo,
  1852. // IsCheck: 1,
  1853. //}
  1854. //_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(schedule.ScheduleDate, c.GetAdminUserInfo().CurrentOrgId)
  1855. //if msgerrkonde == gorm.ErrRecordNotFound {
  1856. // service.AddSigleCancelStock(&cancelStock)
  1857. //}
  1858. //cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1859. ////进行退库操作
  1860. //for _, item := range list {
  1861. // good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  1862. // manufacturer, _ := service.GetManufactureById(item.Manufacturer)
  1863. // deaerler, _ := service.GetDealerById(item.Dealer)
  1864. // //回退库存
  1865. // service.UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
  1866. // goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId)
  1867. // var flush_count int64
  1868. // for _, it := range goodList {
  1869. // flush_count += it.StockCount
  1870. // }
  1871. // cancelStockInfo := models.CancelStockInfo{
  1872. // GoodId: item.GoodId,
  1873. // CancelStockId: cancel.ID,
  1874. // GoodTypeId: good.GoodTypeId,
  1875. // Count: item.Count,
  1876. // Price: item.Price,
  1877. // Total: 0,
  1878. // ProductDate: item.ProductDate,
  1879. // ExpiryDate: item.ExpiryDate,
  1880. // Ctime: time.Now().Unix(),
  1881. // Status: 1,
  1882. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1883. // OrderNumber: cancel.OrderNumber,
  1884. // Type: 0,
  1885. // Dealer: deaerler.DealerName,
  1886. // Manufacturer: manufacturer.ManufacturerName,
  1887. // Number: item.Number,
  1888. // RegisterAccount: "",
  1889. // Remark: "",
  1890. // WarehouseInfoId: item.WarehouseInfotId,
  1891. // PatientId: item.PatientId,
  1892. // RecordDate: item.SysRecordTime,
  1893. // StorehouseId: houseConfig.StorehouseOutInfo,
  1894. // IsCheck: 1,
  1895. // }
  1896. //
  1897. // service.CreateCancelStockInfoOne(&cancelStockInfo)
  1898. //
  1899. // cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  1900. //
  1901. // flow := models.VmStockFlow{
  1902. // WarehousingId: item.WarehouseInfotId,
  1903. // GoodId: item.GoodId,
  1904. // Number: item.Number,
  1905. // LicenseNumber: item.LicenseNumber,
  1906. // Count: item.Count,
  1907. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1908. // PatientId: item.PatientId,
  1909. // SystemTime: item.SysRecordTime,
  1910. // ConsumableType: 7,
  1911. // IsSys: 0,
  1912. // WarehousingOrder: "",
  1913. // WarehouseOutId: item.WarehouseOutId,
  1914. // WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1915. // IsEdit: 0,
  1916. // CancelStockId: cancel.ID,
  1917. // CancelOrderNumber: cancel.OrderNumber,
  1918. // Manufacturer: manufacturer.ID,
  1919. // Dealer: 0,
  1920. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  1921. // UpdateCreator: 0,
  1922. // Status: 1,
  1923. // Ctime: time.Now().Unix(),
  1924. // Mtime: 0,
  1925. // Price: item.Price,
  1926. // WarehousingDetailId: item.WarehouseInfotId,
  1927. // WarehouseOutDetailId: item.ID,
  1928. // CancelOutDetailId: cancelInfo.ID,
  1929. // ProductDate: item.ProductDate,
  1930. // ExpireDate: item.ExpiryDate,
  1931. // StorehouseId: houseConfig.StorehouseOutInfo,
  1932. // OverCount: flush_count,
  1933. // }
  1934. // service.CreateStockFlowOne(flow)
  1935. //
  1936. // //退库数量增加
  1937. // service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.GoodId, houseConfig.StorehouseOutInfo, item.Count)
  1938. // //出库数量减少
  1939. // service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId, item.Count)
  1940. //
  1941. // //更新库存
  1942. // service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  1943. //
  1944. // //更新基础库库存
  1945. // service.UpdateGoodInfoSumCountSix(item.GoodId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  1946. //}
  1947. }
  1948. err = service.UpdateSchedule(schedule)
  1949. //记录日志
  1950. byterequest, _ := json.Marshal(schedule)
  1951. scheduleLog := models.XtScheduleLog{
  1952. UserOrgId: adminINfo.CurrentOrgId,
  1953. RecordDate: schedule.ScheduleDate,
  1954. Status: 1,
  1955. PatientId: schedule.PatientId,
  1956. Ctime: time.Now().Unix(),
  1957. Mtime: 0,
  1958. ErrLog: string(byterequest),
  1959. Source: "电脑端删除排班",
  1960. Module: 5,
  1961. AdminUserId: adminINfo.AdminUser.Id,
  1962. }
  1963. service.CreateScheduleLog(scheduleLog)
  1964. //针对凤凰医院
  1965. if adminINfo.CurrentOrgId == 10579 || adminINfo.CurrentOrgId == 10344 || adminINfo.CurrentOrgId == 10206 || adminINfo.CurrentOrgId == 10679 {
  1966. advice, _ := service.GetDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1967. if len(advice) > 0 {
  1968. service.UpdateAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1969. }
  1970. }
  1971. if adminINfo.CurrentOrgId == 10206 || adminINfo.CurrentOrgId == 10344 {
  1972. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1973. project, _ := service.GetHisPrescriptionProjectList(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1974. if len(hisAdvice) > 0 {
  1975. service.UpdateHisAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1976. }
  1977. if len(project) > 0 {
  1978. service.UpdateProjectObj(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1979. }
  1980. }
  1981. redis := service.RedisClient()
  1982. //处方
  1983. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1984. redis.Set(keyOne, "", time.Second)
  1985. //医嘱
  1986. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1987. redis.Set(keyTwo, "", time.Second)
  1988. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1989. redis.Set(keySix, "", time.Second)
  1990. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1991. redis.Set(keyThree, "", time.Second)
  1992. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1993. redis.Set(keyFour, "", time.Second)
  1994. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1995. redis.Set(keyFive, "", time.Second)
  1996. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1997. redis.Set(keySeven, "", time.Second)
  1998. fmt.Println(err)
  1999. defer redis.Close()
  2000. if err != nil {
  2001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  2002. return
  2003. }
  2004. c.ServeSuccessJSON(map[string]interface{}{
  2005. "msg": "ok",
  2006. "schedule": &schedule,
  2007. })
  2008. }
  2009. func (c *ScheduleApiController) ChangeSchedule() {
  2010. id, _ := c.GetInt64("id", 0)
  2011. if id <= 0 {
  2012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2013. return
  2014. }
  2015. adminINfo := c.GetAdminUserInfo()
  2016. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  2017. if schedule == nil {
  2018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  2019. return
  2020. }
  2021. dataBody := make(map[string]interface{}, 0)
  2022. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2023. if err != nil {
  2024. utils.ErrorLog(err.Error())
  2025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2026. return
  2027. }
  2028. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  2029. utils.ErrorLog("change_action")
  2030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2031. return
  2032. }
  2033. changeAction := dataBody["change_action"].(string)
  2034. if changeAction == "change_mode" {
  2035. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  2036. utils.ErrorLog("mode_id")
  2037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  2038. return
  2039. }
  2040. modeId := int64(dataBody["mode_id"].(float64))
  2041. if modeId < 1 {
  2042. utils.ErrorLog("modeId < 1")
  2043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  2044. return
  2045. }
  2046. schedule.ModeId = modeId
  2047. so, _ := service.GetDialysisSolutionTwo(adminINfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  2048. filedRecordOne, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器")
  2049. filedRecordTwo, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "灌流器")
  2050. filedRecordThree, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器/灌流器")
  2051. var DialysisMachineName string
  2052. if filedRecordOne.IsShow == 1 {
  2053. DialysisMachineName = so.DialysisDialyszers
  2054. //fmt.Println("1111")
  2055. fmt.Println(DialysisMachineName)
  2056. }
  2057. if filedRecordThree.IsShow == 1 {
  2058. if len(schedule.DialysisMachineName) > 0 {
  2059. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  2060. //fmt.Println("22222")
  2061. fmt.Println(DialysisMachineName)
  2062. } else {
  2063. DialysisMachineName = so.DialyzerPerfusionApparatus
  2064. //fmt.Println("333333")
  2065. fmt.Println(DialysisMachineName)
  2066. }
  2067. }
  2068. if filedRecordTwo.IsShow == 1 {
  2069. if len(DialysisMachineName) > 0 {
  2070. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  2071. //fmt.Println("55555555")
  2072. fmt.Println(DialysisMachineName)
  2073. } else {
  2074. DialysisMachineName = so.DialysisIrrigation
  2075. //fmt.Println("66666666")
  2076. fmt.Println(DialysisMachineName)
  2077. }
  2078. }
  2079. schedule.DialysisMachineName = DialysisMachineName
  2080. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  2081. if err != nil {
  2082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2083. return
  2084. }
  2085. if order != nil {
  2086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  2087. return
  2088. }
  2089. //记录日志
  2090. byterequest, _ := json.Marshal(schedule)
  2091. scheduleLog := models.XtScheduleLog{
  2092. UserOrgId: adminINfo.CurrentOrgId,
  2093. RecordDate: schedule.ScheduleDate,
  2094. Status: 1,
  2095. PatientId: schedule.PatientId,
  2096. Ctime: time.Now().Unix(),
  2097. Mtime: 0,
  2098. ErrLog: string(byterequest),
  2099. Source: "电脑端改变模式排班",
  2100. Module: 1,
  2101. AdminUserId: adminINfo.AdminUser.Id,
  2102. }
  2103. service.CreateScheduleLog(scheduleLog)
  2104. } else if changeAction == "change_device" {
  2105. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  2106. if err != nil {
  2107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2108. return
  2109. }
  2110. if order != nil {
  2111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  2112. return
  2113. }
  2114. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  2115. utils.ErrorLog("schedule_type")
  2116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2117. return
  2118. }
  2119. scheduleType := int64(dataBody["schedule_type"].(float64))
  2120. if scheduleType < 1 || scheduleType > 3 {
  2121. utils.ErrorLog("scheduleType < 3")
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2123. return
  2124. }
  2125. schedule.ScheduleType = scheduleType
  2126. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  2127. utils.ErrorLog("bed_id")
  2128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2129. return
  2130. }
  2131. bedId := int64(dataBody["bed_id"].(float64))
  2132. if bedId < 1 {
  2133. utils.ErrorLog("bedId < 1")
  2134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2135. return
  2136. }
  2137. schedule.BedId = bedId
  2138. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  2139. utils.ErrorLog("partition_id")
  2140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2141. return
  2142. }
  2143. partitionId := int64(dataBody["partition_id"].(float64))
  2144. if partitionId < 1 {
  2145. utils.ErrorLog("partitionId < 1")
  2146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2147. return
  2148. }
  2149. schedule.PartitionId = partitionId
  2150. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  2151. if bed == nil {
  2152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  2153. return
  2154. }
  2155. if bed.ZoneID != schedule.PartitionId {
  2156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  2157. return
  2158. }
  2159. startTime := schedule.ScheduleDate
  2160. endTime := startTime + 86399
  2161. //一天只有排班一次
  2162. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  2163. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  2164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  2165. return
  2166. }
  2167. //同天同位置只能排一个
  2168. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  2169. if err != nil {
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2171. return
  2172. }
  2173. if pointSchedule.ID > 0 {
  2174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  2175. return
  2176. }
  2177. //记录日志
  2178. byterequest, _ := json.Marshal(schedule)
  2179. scheduleLog := models.XtScheduleLog{
  2180. UserOrgId: adminINfo.CurrentOrgId,
  2181. RecordDate: schedule.ScheduleDate,
  2182. Status: 1,
  2183. PatientId: schedule.PatientId,
  2184. Ctime: time.Now().Unix(),
  2185. Mtime: 0,
  2186. ErrLog: string(byterequest),
  2187. Source: "电脑端改变分区床位",
  2188. Module: 4,
  2189. AdminUserId: adminINfo.AdminUser.Id,
  2190. }
  2191. service.CreateScheduleLog(scheduleLog)
  2192. } else {
  2193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2194. return
  2195. }
  2196. schedule.UpdatedTime = time.Now().Unix()
  2197. err = service.UpdateSchedule(schedule)
  2198. prescription := models.DialysisPrescription{
  2199. ModeId: schedule.ModeId,
  2200. }
  2201. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  2202. if errcode == gorm.ErrRecordNotFound {
  2203. if err != nil {
  2204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  2205. return
  2206. }
  2207. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  2208. c.ServeSuccessJSON(map[string]interface{}{
  2209. "msg": "ok",
  2210. "schedule": &schedule,
  2211. })
  2212. } else if errcode == nil {
  2213. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  2214. if err != nil {
  2215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  2216. return
  2217. }
  2218. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  2219. c.ServeSuccessJSON(map[string]interface{}{
  2220. "msg": "ok",
  2221. "schedule": &schedule,
  2222. })
  2223. }
  2224. }
  2225. // /api/schedule/print/initdata [get]
  2226. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  2227. func (this *ScheduleApiController) PrintInitData() {
  2228. dateStr := this.GetString("date")
  2229. //week_type, _ := this.GetInt64("type", 0)
  2230. var date *time.Time
  2231. if len(dateStr) == 0 {
  2232. now := time.Now()
  2233. date = &now
  2234. } else {
  2235. var parseErr error
  2236. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  2237. if parseErr != nil {
  2238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2239. return
  2240. }
  2241. }
  2242. adminUserInfo := this.GetAdminUserInfo()
  2243. // 获取本周的排班
  2244. var monday time.Time
  2245. var sunday time.Time
  2246. //switch week_type {
  2247. //case 1:
  2248. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  2249. // break
  2250. //case 2:
  2251. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  2252. //
  2253. // break
  2254. //case 3:
  2255. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  2256. // break
  2257. //}
  2258. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  2259. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  2260. if getScheduleErr != nil {
  2261. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  2262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2263. return
  2264. }
  2265. thisTime := date
  2266. weekDay := int(thisTime.Weekday())
  2267. if weekDay == 0 {
  2268. weekDay = 7
  2269. }
  2270. weekEnd := 7 - weekDay
  2271. weekStart := weekEnd - 6
  2272. days := make([]string, 0)
  2273. for index := weekStart; index <= weekEnd; index++ {
  2274. theDay := thisTime.AddDate(0, 0, index)
  2275. days = append(days, theDay.Format("2006-01-02"))
  2276. }
  2277. this.ServeSuccessJSON(map[string]interface{}{
  2278. "total": total,
  2279. "schedules": schedules,
  2280. "monday": monday.Unix(),
  2281. "days": days,
  2282. })
  2283. }
  2284. func (this *ScheduleApiController) UrgentScheduleData() {
  2285. schedule_type, _ := this.GetInt("type", 0)
  2286. schedule_date := this.GetString("date")
  2287. var date *time.Time
  2288. if len(schedule_date) == 0 {
  2289. now := time.Now()
  2290. date = &now
  2291. } else {
  2292. var parseErr error
  2293. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2294. if parseErr != nil {
  2295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2296. return
  2297. }
  2298. }
  2299. adminUserInfo := this.GetAdminUserInfo()
  2300. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  2301. if getDeviceNumbersErr != nil {
  2302. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  2303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2304. return
  2305. }
  2306. // today := utils.ZeroHourTimeOfDay(time.Now())
  2307. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  2308. if getSchedulesErr != nil {
  2309. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  2310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2311. return
  2312. }
  2313. this.ServeSuccessJSON(map[string]interface{}{
  2314. "device_numbers": deviceNumbers,
  2315. "schedules": schedules,
  2316. })
  2317. }
  2318. func (this *ScheduleApiController) SearchSchedulePatients() {
  2319. keywords := this.GetString("keywords")
  2320. week_type, _ := this.GetInt64("week_type", 0)
  2321. start_sch := this.GetString("start_sch")
  2322. end_sch := this.GetString("end_sch")
  2323. thisTime1 := time.Now()
  2324. thisTime2 := time.Now()
  2325. thisTime1 = thisTime1.AddDate(0, 0, 7)
  2326. thisTime2 = thisTime2.AddDate(0, 0, 14)
  2327. var start_time string
  2328. var end_time string
  2329. switch week_type {
  2330. case 1:
  2331. timeLayout := "2006-01-02"
  2332. loc, _ := time.LoadLocation("Local")
  2333. var startSchTime int64
  2334. if len(start_sch) > 0 {
  2335. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_sch+" 00:00:00", loc)
  2336. startSchTime = theTime.Unix()
  2337. }
  2338. var endSchTime int64
  2339. if len(end_sch) > 0 {
  2340. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_sch+" 00:00:00", loc)
  2341. endSchTime = theTime.Unix()
  2342. }
  2343. adminUserInfo := this.GetAdminUserInfo()
  2344. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId, startSchTime, endSchTime)
  2345. this.ServeSuccessJSON(map[string]interface{}{
  2346. "schdules": list,
  2347. })
  2348. break
  2349. case 2:
  2350. days := make([]string, 0)
  2351. weekDay1 := int(thisTime1.Weekday())
  2352. if weekDay1 == 0 {
  2353. weekDay1 = 7
  2354. }
  2355. weekEnd1 := 7 - weekDay1
  2356. weekStart1 := weekEnd1 - 6
  2357. for index := weekStart1; index <= weekEnd1; index++ {
  2358. fmt.Println(index)
  2359. theDay := thisTime1.AddDate(0, 0, index)
  2360. days = append(days, theDay.Format("2006-01-02"))
  2361. }
  2362. fmt.Println(days)
  2363. start_time = days[0]
  2364. end_time = days[len(days)-1]
  2365. timeLayout := "2006-01-02"
  2366. loc, _ := time.LoadLocation("Local")
  2367. var theStartTime int64
  2368. if len(start_time) > 0 {
  2369. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2370. theStartTime = theTime.Unix()
  2371. }
  2372. var theEndtTime int64
  2373. if len(end_time) > 0 {
  2374. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2375. theEndtTime = theTime.Unix()
  2376. }
  2377. adminUserInfo := this.GetAdminUserInfo()
  2378. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  2379. this.ServeSuccessJSON(map[string]interface{}{
  2380. "schdules": list,
  2381. })
  2382. break
  2383. case 3:
  2384. days := make([]string, 0)
  2385. weekDay2 := int(thisTime2.Weekday())
  2386. if weekDay2 == 0 {
  2387. weekDay2 = 7
  2388. }
  2389. weekEnd2 := 7 - weekDay2
  2390. weekStart2 := weekEnd2 - 6
  2391. for index := weekStart2; index <= weekEnd2; index++ {
  2392. theDay := thisTime2.AddDate(0, 0, index)
  2393. days = append(days, theDay.Format("2006-01-02"))
  2394. }
  2395. start_time = days[0]
  2396. end_time = days[len(days)-1]
  2397. timeLayout := "2006-01-02"
  2398. loc, _ := time.LoadLocation("Local")
  2399. var theStartTime int64
  2400. if len(start_time) > 0 {
  2401. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2402. theStartTime = theTime.Unix()
  2403. }
  2404. var theEndtTime int64
  2405. if len(end_time) > 0 {
  2406. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2407. theEndtTime = theTime.Unix()
  2408. }
  2409. adminUserInfo := this.GetAdminUserInfo()
  2410. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  2411. this.ServeSuccessJSON(map[string]interface{}{
  2412. "schdules": list,
  2413. })
  2414. break
  2415. }
  2416. }
  2417. func (this *ScheduleApiController) GetWeekDaySchedule() {
  2418. week_type, _ := this.GetInt64("week_type", -1)
  2419. week_time, _ := this.GetInt64("week_time")
  2420. thisTime := time.Now()
  2421. weekDay := int(thisTime.Weekday())
  2422. if weekDay == 0 {
  2423. weekDay = 7
  2424. }
  2425. weekEnd := 7 - weekDay
  2426. weekStart := weekEnd - 6
  2427. weekTitle := make([]string, 0)
  2428. days := make([]string, 0)
  2429. for index := weekStart; index <= weekEnd; index++ {
  2430. theDay := thisTime.AddDate(0, 0, index)
  2431. indexYear, indexMonthTime, indexDay := theDay.Date()
  2432. indexMonth := int(indexMonthTime)
  2433. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2434. weekTitle = append(weekTitle, indexWeek)
  2435. days = append(days, theDay.Format("2006-01-02"))
  2436. }
  2437. fmt.Println(days)
  2438. var targetDayStr string
  2439. var startTime string
  2440. var endTime string
  2441. switch week_type {
  2442. case 0:
  2443. {
  2444. startTime = days[0]
  2445. endTime = days[6]
  2446. }
  2447. case 1:
  2448. targetDayStr = days[0]
  2449. break
  2450. case 2:
  2451. targetDayStr = days[1]
  2452. break
  2453. case 3:
  2454. targetDayStr = days[2]
  2455. break
  2456. case 4:
  2457. targetDayStr = days[3]
  2458. break
  2459. case 5:
  2460. targetDayStr = days[4]
  2461. break
  2462. case 6:
  2463. targetDayStr = days[5]
  2464. break
  2465. case 7:
  2466. targetDayStr = days[6]
  2467. break
  2468. }
  2469. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  2470. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  2471. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  2472. fmt.Println(startDay, endDay)
  2473. if parseErr != nil {
  2474. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2475. return
  2476. }
  2477. orgId := this.GetAdminUserInfo().CurrentOrgId
  2478. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  2479. this.ServeSuccessJSON(map[string]interface{}{
  2480. "schdules": list,
  2481. "day": targetDayStr,
  2482. })
  2483. }
  2484. func Struct2Map(obj interface{}) map[string]interface{} {
  2485. t := reflect.TypeOf(obj)
  2486. v := reflect.ValueOf(obj)
  2487. var data = make(map[string]interface{})
  2488. for i := 0; i < t.NumField(); i++ {
  2489. data[t.Field(i).Name] = v.Field(i).Interface()
  2490. }
  2491. return data
  2492. }
  2493. func (this *ScheduleApiController) ExportSchedule() {
  2494. dataBody := make(map[string]interface{}, 0)
  2495. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2496. if err != nil {
  2497. utils.ErrorLog(err.Error())
  2498. return
  2499. }
  2500. utils.ErrorLog("%v", dataBody)
  2501. export_time := time.Now().Unix()
  2502. var schedules []*models.Schedule
  2503. var failed_total int
  2504. var total_schedule []interface{}
  2505. var patients []*models.Patients
  2506. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  2507. start_time := dataBody["start_time"].(string)
  2508. end_time := dataBody["end_time"].(string)
  2509. delete_type := int64(dataBody["delete_type"].(float64))
  2510. fmt.Println("delete_type", delete_type)
  2511. timeLayout := "2006-01-02"
  2512. loc, _ := time.LoadLocation("Local")
  2513. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2514. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2515. fmt.Println("theTimeStart", theTimeStart.Unix())
  2516. fmt.Println("theTimeEnd", theTimeEnd.Unix())
  2517. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  2518. tempSchedule := dataBody["failed_schedule"].([]interface{})
  2519. failed_total = len(tempSchedule)
  2520. }
  2521. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  2522. tempSchedule := dataBody["schedule"].([]interface{})
  2523. total_schedule = tempSchedule
  2524. for _, schMap := range tempSchedule {
  2525. schMapM := schMap.(map[string]interface{})
  2526. var sch models.Schedule
  2527. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  2528. utils.ErrorLog("name")
  2529. return
  2530. }
  2531. name, _ := schMapM["name"].(string)
  2532. fmt.Println(name)
  2533. if len(name) == 0 { //名字为空则生成一条导入错误日志
  2534. err_log := models.ExportErrLog{
  2535. LogType: 2,
  2536. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2537. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  2538. Status: 1,
  2539. CreateTime: time.Now().Unix(),
  2540. UpdateTime: time.Now().Unix(),
  2541. ExportTime: export_time,
  2542. }
  2543. service.CreateExportErrLog(&err_log)
  2544. continue
  2545. } else {
  2546. var patient []*models.Patients
  2547. for _, item := range patients {
  2548. if strings.Replace(item.Name, " ", "", -1) == name {
  2549. patient = append(patient, item)
  2550. }
  2551. }
  2552. if len(patient) == 0 { //错误日志
  2553. err_log := models.ExportErrLog{
  2554. LogType: 2,
  2555. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2556. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  2557. Status: 1,
  2558. CreateTime: time.Now().Unix(),
  2559. UpdateTime: time.Now().Unix(),
  2560. ExportTime: export_time,
  2561. }
  2562. service.CreateExportErrLog(&err_log)
  2563. continue
  2564. } else if len(patient) == 1 { //
  2565. sch.PatientId = patient[0].ID
  2566. } else if len(patient) > 1 { //出现同名的情况
  2567. err_log := models.ExportErrLog{
  2568. LogType: 2,
  2569. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2570. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  2571. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  2572. Status: 1,
  2573. CreateTime: time.Now().Unix(),
  2574. UpdateTime: time.Now().Unix(),
  2575. ExportTime: export_time,
  2576. }
  2577. service.CreateExportErrLog(&err_log)
  2578. continue
  2579. }
  2580. }
  2581. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  2582. utils.ErrorLog("schedule_type")
  2583. return
  2584. }
  2585. schedule_type := int64(schMapM["schedule_type"].(float64))
  2586. if schedule_type <= 0 { //班次格式有误,插入日志
  2587. log := models.ExportLog{
  2588. LogType: 2,
  2589. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2590. TotalNum: int64(len(total_schedule) + failed_total),
  2591. FailNum: 1 + int64(failed_total),
  2592. SuccessNum: int64(len(schedules)),
  2593. CreateTime: time.Now().Unix(),
  2594. UpdateTime: time.Now().Unix(),
  2595. ExportTime: export_time,
  2596. Status: 1,
  2597. }
  2598. service.CreateExportLog(&log)
  2599. err_log := models.ExportErrLog{
  2600. LogType: 2,
  2601. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2602. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  2603. Status: 1,
  2604. CreateTime: time.Now().Unix(),
  2605. UpdateTime: time.Now().Unix(),
  2606. ExportTime: export_time,
  2607. }
  2608. service.CreateExportErrLog(&err_log)
  2609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2610. return
  2611. } else {
  2612. sch.ScheduleType = schedule_type
  2613. }
  2614. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  2615. utils.ErrorLog("partition_name")
  2616. return
  2617. }
  2618. partition_name, _ := schMapM["partition_name"].(string)
  2619. if len(partition_name) == 0 { //分区为空
  2620. log := models.ExportLog{
  2621. LogType: 2,
  2622. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2623. TotalNum: int64(len(total_schedule) + failed_total),
  2624. FailNum: 1 + int64(failed_total),
  2625. SuccessNum: int64(len(schedules)),
  2626. CreateTime: time.Now().Unix(),
  2627. UpdateTime: time.Now().Unix(),
  2628. ExportTime: export_time,
  2629. Status: 1,
  2630. }
  2631. service.CreateExportLog(&log)
  2632. err_log := models.ExportErrLog{
  2633. LogType: 2,
  2634. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2635. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2636. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  2637. Status: 1,
  2638. CreateTime: time.Now().Unix(),
  2639. UpdateTime: time.Now().Unix(),
  2640. ExportTime: export_time,
  2641. }
  2642. service.CreateExportErrLog(&err_log)
  2643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2644. return
  2645. } else {
  2646. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  2647. if err == nil {
  2648. sch.PartitionId = zone.ID
  2649. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  2650. log := models.ExportLog{
  2651. LogType: 2,
  2652. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2653. TotalNum: int64(len(total_schedule) + failed_total),
  2654. FailNum: 1 + int64(failed_total),
  2655. SuccessNum: int64(len(schedules)),
  2656. CreateTime: time.Now().Unix(),
  2657. UpdateTime: time.Now().Unix(),
  2658. ExportTime: export_time,
  2659. Status: 1,
  2660. }
  2661. service.CreateExportLog(&log)
  2662. err_log := models.ExportErrLog{
  2663. LogType: 2,
  2664. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2665. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2666. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  2667. Status: 1,
  2668. CreateTime: time.Now().Unix(),
  2669. UpdateTime: time.Now().Unix(),
  2670. ExportTime: export_time,
  2671. }
  2672. service.CreateExportErrLog(&err_log)
  2673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2674. return
  2675. }
  2676. }
  2677. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  2678. utils.ErrorLog("device_number_name")
  2679. return
  2680. }
  2681. device_number_name, _ := schMapM["device_number_name"].(string)
  2682. if len(device_number_name) == 0 { //分区为空
  2683. log := models.ExportLog{
  2684. LogType: 2,
  2685. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2686. TotalNum: int64(len(total_schedule) + failed_total),
  2687. FailNum: 1 + int64(failed_total),
  2688. SuccessNum: int64(len(schedules)),
  2689. CreateTime: time.Now().Unix(),
  2690. UpdateTime: time.Now().Unix(),
  2691. ExportTime: export_time,
  2692. Status: 1,
  2693. }
  2694. service.CreateExportLog(&log)
  2695. err_log := models.ExportErrLog{
  2696. LogType: 2,
  2697. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2698. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2699. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2700. Status: 1,
  2701. CreateTime: time.Now().Unix(),
  2702. UpdateTime: time.Now().Unix(),
  2703. ExportTime: export_time,
  2704. }
  2705. service.CreateExportErrLog(&err_log)
  2706. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2707. return
  2708. } else {
  2709. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  2710. if err == nil {
  2711. if len(device) == 0 { //没查到数据,插入错误日志
  2712. log := models.ExportLog{
  2713. LogType: 2,
  2714. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2715. TotalNum: int64(len(total_schedule) + failed_total),
  2716. FailNum: 1 + int64(failed_total),
  2717. SuccessNum: int64(len(schedules)),
  2718. CreateTime: time.Now().Unix(),
  2719. UpdateTime: time.Now().Unix(),
  2720. ExportTime: export_time,
  2721. Status: 1,
  2722. }
  2723. service.CreateExportLog(&log)
  2724. err_log := models.ExportErrLog{
  2725. LogType: 2,
  2726. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2727. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2728. Status: 1,
  2729. CreateTime: time.Now().Unix(),
  2730. UpdateTime: time.Now().Unix(),
  2731. ExportTime: export_time,
  2732. }
  2733. service.CreateExportErrLog(&err_log)
  2734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2735. return
  2736. } else if len(device) == 1 {
  2737. sch.BedId = device[0].ID
  2738. } else if len(device) > 1 { //出现重名,插入错误日志
  2739. log := models.ExportLog{
  2740. LogType: 2,
  2741. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2742. TotalNum: int64(len(total_schedule) + failed_total),
  2743. FailNum: 1 + int64(failed_total),
  2744. SuccessNum: int64(len(schedules)),
  2745. CreateTime: time.Now().Unix(),
  2746. UpdateTime: time.Now().Unix(),
  2747. ExportTime: export_time,
  2748. Status: 1,
  2749. }
  2750. service.CreateExportLog(&log)
  2751. err_log := models.ExportErrLog{
  2752. LogType: 2,
  2753. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2754. ErrMsg: "出现两个床位号相同的床位",
  2755. Status: 1,
  2756. CreateTime: time.Now().Unix(),
  2757. UpdateTime: time.Now().Unix(),
  2758. ExportTime: export_time,
  2759. }
  2760. service.CreateExportErrLog(&err_log)
  2761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2762. return
  2763. }
  2764. }
  2765. }
  2766. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2767. utils.ErrorLog("schedule_week")
  2768. return
  2769. }
  2770. schedule_week, _ := schMapM["schedule_week"].(string)
  2771. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2772. log := models.ExportLog{
  2773. LogType: 2,
  2774. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2775. TotalNum: int64(len(total_schedule) + failed_total),
  2776. FailNum: 1 + int64(failed_total),
  2777. SuccessNum: int64(len(schedules)),
  2778. CreateTime: time.Now().Unix(),
  2779. UpdateTime: time.Now().Unix(),
  2780. ExportTime: export_time,
  2781. Status: 1,
  2782. }
  2783. service.CreateExportLog(&log)
  2784. err_log := models.ExportErrLog{
  2785. LogType: 2,
  2786. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2787. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2788. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2789. Status: 1,
  2790. CreateTime: time.Now().Unix(),
  2791. UpdateTime: time.Now().Unix(),
  2792. ExportTime: export_time,
  2793. }
  2794. service.CreateExportErrLog(&err_log)
  2795. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2796. return
  2797. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2798. log := models.ExportLog{
  2799. LogType: 2,
  2800. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2801. TotalNum: int64(len(total_schedule) + failed_total),
  2802. FailNum: 1 + int64(failed_total),
  2803. SuccessNum: int64(len(schedules)),
  2804. CreateTime: time.Now().Unix(),
  2805. UpdateTime: time.Now().Unix(),
  2806. ExportTime: export_time,
  2807. Status: 1,
  2808. }
  2809. service.CreateExportLog(&log)
  2810. err_log := models.ExportErrLog{
  2811. LogType: 2,
  2812. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2813. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2814. Status: 1,
  2815. CreateTime: time.Now().Unix(),
  2816. UpdateTime: time.Now().Unix(),
  2817. ExportTime: export_time,
  2818. }
  2819. service.CreateExportErrLog(&err_log)
  2820. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2821. return
  2822. } else {
  2823. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2824. sch.ScheduleWeek = schedule_week
  2825. }
  2826. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  2827. utils.ErrorLog("schedule_date")
  2828. return
  2829. }
  2830. schedule_date, _ := schMapM["schedule_date"].(string)
  2831. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  2832. log := models.ExportLog{
  2833. LogType: 2,
  2834. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2835. TotalNum: int64(len(total_schedule) + failed_total),
  2836. FailNum: 1 + int64(failed_total),
  2837. SuccessNum: int64(len(schedules)),
  2838. CreateTime: time.Now().Unix(),
  2839. UpdateTime: time.Now().Unix(),
  2840. ExportTime: export_time,
  2841. Status: 1,
  2842. }
  2843. service.CreateExportLog(&log)
  2844. err_log := models.ExportErrLog{
  2845. LogType: 2,
  2846. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2847. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2848. Status: 1,
  2849. CreateTime: time.Now().Unix(),
  2850. UpdateTime: time.Now().Unix(),
  2851. ExportTime: export_time,
  2852. }
  2853. service.CreateExportErrLog(&err_log)
  2854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2855. return
  2856. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  2857. log := models.ExportLog{
  2858. LogType: 2,
  2859. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2860. TotalNum: int64(len(total_schedule) + failed_total),
  2861. FailNum: 1 + int64(failed_total),
  2862. SuccessNum: int64(len(schedules)),
  2863. CreateTime: time.Now().Unix(),
  2864. UpdateTime: time.Now().Unix(),
  2865. ExportTime: export_time,
  2866. Status: 1,
  2867. }
  2868. service.CreateExportLog(&log)
  2869. err_log := models.ExportErrLog{
  2870. LogType: 2,
  2871. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2872. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2873. Status: 1,
  2874. CreateTime: time.Now().Unix(),
  2875. UpdateTime: time.Now().Unix(),
  2876. ExportTime: export_time,
  2877. }
  2878. service.CreateExportErrLog(&err_log)
  2879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2880. return
  2881. } else {
  2882. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2883. sch.ScheduleDate = date.Unix()
  2884. }
  2885. sch.CreatedTime = time.Now().Unix()
  2886. sch.UpdatedTime = time.Now().Unix()
  2887. sch.ModeId = 1
  2888. sch.Status = 1
  2889. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  2890. sch.IsExport = 1
  2891. var DialysisMachineName string
  2892. so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
  2893. filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
  2894. filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
  2895. filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
  2896. if filedRecordOne.IsShow == 1 {
  2897. DialysisMachineName = so.DialysisDialyszers
  2898. }
  2899. if filedRecordThree.IsShow == 1 {
  2900. if len(DialysisMachineName) > 0 {
  2901. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  2902. } else {
  2903. DialysisMachineName = so.DialyzerPerfusionApparatus
  2904. }
  2905. }
  2906. if filedRecordTwo.IsShow == 1 {
  2907. if len(DialysisMachineName) > 0 {
  2908. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  2909. } else {
  2910. DialysisMachineName = so.DialysisIrrigation
  2911. }
  2912. }
  2913. sch.DialysisMachineName = DialysisMachineName
  2914. schedules = append(schedules, &sch)
  2915. }
  2916. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2917. if len(schedules) > 0 {
  2918. schedule_date := time.Now().Format("2006-01-02")
  2919. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2920. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  2921. service.UpdateScheduleByExport(this.GetAdminUserInfo().CurrentOrgId, clear_schedule_date)
  2922. if err == nil {
  2923. for _, item := range schedules {
  2924. if item.ScheduleDate > clear_schedule_date {
  2925. //查询该患者是否转出获取死亡
  2926. //查找当天日期是否存在
  2927. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  2928. if errcode == gorm.ErrRecordNotFound {
  2929. //查询该床位是否有患者
  2930. sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
  2931. if errcodes == gorm.ErrRecordNotFound {
  2932. service.CreateScheduleTwo(item)
  2933. } else if errcodes == nil {
  2934. //清除当天该床位已有的患者
  2935. service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
  2936. service.CreateScheduleTwo(item)
  2937. }
  2938. } else if errcode == nil {
  2939. schedule := models.XtSchedule{
  2940. PartitionId: item.PartitionId,
  2941. BedId: item.BedId,
  2942. PatientId: item.PatientId,
  2943. ScheduleDate: item.ScheduleDate,
  2944. ScheduleType: item.ScheduleType,
  2945. ScheduleWeek: item.ScheduleWeek,
  2946. ModeId: 1,
  2947. Status: 1,
  2948. DialysisMachineName: item.DialysisMachineName,
  2949. }
  2950. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  2951. }
  2952. }
  2953. }
  2954. log := models.ExportLog{
  2955. LogType: 2,
  2956. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2957. TotalNum: int64(len(total_schedule) + failed_total),
  2958. FailNum: int64(len(errLogs) + failed_total),
  2959. SuccessNum: int64(len(schedules)),
  2960. CreateTime: time.Now().Unix(),
  2961. UpdateTime: time.Now().Unix(),
  2962. ExportTime: export_time,
  2963. Status: 1,
  2964. }
  2965. service.CreateExportLog(&log)
  2966. if failed_total > 0 {
  2967. err_log := models.ExportErrLog{
  2968. LogType: 2,
  2969. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2970. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2971. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2972. Status: 1,
  2973. CreateTime: time.Now().Unix(),
  2974. UpdateTime: time.Now().Unix(),
  2975. ExportTime: export_time,
  2976. }
  2977. service.CreateExportErrLog(&err_log)
  2978. }
  2979. this.ServeSuccessJSON(map[string]interface{}{
  2980. "msg": "导入成功",
  2981. "total_num": len(total_schedule) + failed_total,
  2982. "success_num": len(schedules),
  2983. "fail_num": int64(len(errLogs)),
  2984. })
  2985. } else {
  2986. log := models.ExportLog{
  2987. LogType: 2,
  2988. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2989. TotalNum: int64(len(total_schedule) + failed_total),
  2990. FailNum: int64(len(errLogs) + failed_total),
  2991. SuccessNum: int64(len(schedules)),
  2992. CreateTime: time.Now().Unix(),
  2993. UpdateTime: time.Now().Unix(),
  2994. ExportTime: export_time,
  2995. Status: 1,
  2996. }
  2997. service.CreateExportLog(&log)
  2998. if failed_total > 0 {
  2999. err_log := models.ExportErrLog{
  3000. LogType: 2,
  3001. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3002. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  3003. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  3004. Status: 1,
  3005. CreateTime: time.Now().Unix(),
  3006. UpdateTime: time.Now().Unix(),
  3007. ExportTime: export_time,
  3008. }
  3009. service.CreateExportErrLog(&err_log)
  3010. }
  3011. this.ServeSuccessJSON(map[string]interface{}{
  3012. "msg": "导入成功",
  3013. "total_num": len(total_schedule),
  3014. "success_num": len(schedules),
  3015. "fail_num": int64(len(errLogs)),
  3016. })
  3017. }
  3018. } else {
  3019. log := models.ExportLog{
  3020. LogType: 2,
  3021. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3022. TotalNum: int64(len(total_schedule) + failed_total),
  3023. FailNum: int64(len(errLogs) + failed_total),
  3024. SuccessNum: int64(len(schedules)),
  3025. CreateTime: time.Now().Unix(),
  3026. UpdateTime: time.Now().Unix(),
  3027. ExportTime: export_time,
  3028. Status: 1,
  3029. }
  3030. service.CreateExportLog(&log)
  3031. if failed_total > 0 {
  3032. err_log := models.ExportErrLog{
  3033. LogType: 2,
  3034. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3035. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  3036. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  3037. Status: 1,
  3038. CreateTime: time.Now().Unix(),
  3039. UpdateTime: time.Now().Unix(),
  3040. ExportTime: export_time,
  3041. }
  3042. service.CreateExportErrLog(&err_log)
  3043. }
  3044. this.ServeSuccessJSON(map[string]interface{}{
  3045. "msg": "导入成功",
  3046. "total_num": len(total_schedule),
  3047. "success_num": len(schedules),
  3048. "fail_num": int64(len(errLogs)),
  3049. })
  3050. }
  3051. }
  3052. }
  3053. func (this *ScheduleApiController) ExportScheduleTemplate() {
  3054. dataBody := make(map[string]interface{}, 0)
  3055. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3056. if err != nil {
  3057. utils.ErrorLog(err.Error())
  3058. return
  3059. }
  3060. utils.ErrorLog("%v", dataBody)
  3061. export_time := time.Now().Unix()
  3062. var schedules []*models.PatientScheduleTemplateItem
  3063. var total_schedule []interface{}
  3064. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  3065. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  3066. tempSchedule := dataBody["schedule"].([]interface{})
  3067. total_schedule = tempSchedule
  3068. for _, schMap := range tempSchedule {
  3069. schMapM := schMap.(map[string]interface{})
  3070. var sch models.PatientScheduleTemplateItem
  3071. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  3072. utils.ErrorLog("name")
  3073. return
  3074. }
  3075. name, _ := schMapM["name"].(string)
  3076. fmt.Println(name)
  3077. if len(name) == 0 { //名字为空则生成一条导入错误日志
  3078. err_log := models.ExportErrLog{
  3079. LogType: 3,
  3080. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3081. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  3082. Status: 1,
  3083. CreateTime: time.Now().Unix(),
  3084. UpdateTime: time.Now().Unix(),
  3085. ExportTime: export_time,
  3086. }
  3087. service.CreateExportErrLog(&err_log)
  3088. continue
  3089. } else {
  3090. var patient []*models.Patients
  3091. for _, item := range patients {
  3092. if strings.Replace(item.Name, " ", "", -1) == name {
  3093. patient = append(patient, item)
  3094. }
  3095. }
  3096. if len(patient) == 0 { //错误日志
  3097. err_log := models.ExportErrLog{
  3098. LogType: 3,
  3099. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3100. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  3101. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  3102. Status: 1,
  3103. CreateTime: time.Now().Unix(),
  3104. UpdateTime: time.Now().Unix(),
  3105. ExportTime: export_time,
  3106. }
  3107. service.CreateExportErrLog(&err_log)
  3108. continue
  3109. } else if len(patient) == 1 { //
  3110. sch.PatientID = patient[0].ID
  3111. } else if len(patient) > 1 { //出现同名的情况
  3112. err_log := models.ExportErrLog{
  3113. LogType: 3,
  3114. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3115. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  3116. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  3117. Status: 1,
  3118. CreateTime: time.Now().Unix(),
  3119. UpdateTime: time.Now().Unix(),
  3120. ExportTime: export_time,
  3121. }
  3122. service.CreateExportErrLog(&err_log)
  3123. continue
  3124. }
  3125. }
  3126. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  3127. utils.ErrorLog("schedule_type")
  3128. return
  3129. }
  3130. schedule_type := int64(schMapM["schedule_type"].(float64))
  3131. if schedule_type <= 0 { //班次格式有误,插入日志
  3132. log := models.ExportLog{
  3133. LogType: 3,
  3134. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3135. TotalNum: int64(len(total_schedule)),
  3136. FailNum: 1,
  3137. SuccessNum: int64(len(schedules)),
  3138. CreateTime: time.Now().Unix(),
  3139. UpdateTime: time.Now().Unix(),
  3140. ExportTime: export_time,
  3141. Status: 1,
  3142. }
  3143. service.CreateExportLog(&log)
  3144. err_log := models.ExportErrLog{
  3145. LogType: 3,
  3146. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3147. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  3148. Status: 1,
  3149. CreateTime: time.Now().Unix(),
  3150. UpdateTime: time.Now().Unix(),
  3151. ExportTime: export_time,
  3152. }
  3153. service.CreateExportErrLog(&err_log)
  3154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3155. return
  3156. } else {
  3157. sch.TimeType = int8(schedule_type)
  3158. }
  3159. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  3160. utils.ErrorLog("template_id")
  3161. return
  3162. }
  3163. template_id := int64(schMapM["template_id"].(float64))
  3164. sch.TemplateID = template_id
  3165. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  3166. utils.ErrorLog("device_number_name")
  3167. return
  3168. }
  3169. partition_name, _ := schMapM["partition_name"].(string)
  3170. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  3171. device_number_name, _ := schMapM["device_number_name"].(string)
  3172. if len(device_number_name) == 0 { //分区为空
  3173. log := models.ExportLog{
  3174. LogType: 3,
  3175. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3176. TotalNum: int64(len(total_schedule)),
  3177. FailNum: 1,
  3178. SuccessNum: int64(len(schedules)),
  3179. CreateTime: time.Now().Unix(),
  3180. UpdateTime: time.Now().Unix(),
  3181. ExportTime: export_time,
  3182. Status: 1,
  3183. }
  3184. service.CreateExportLog(&log)
  3185. err_log := models.ExportErrLog{
  3186. LogType: 3,
  3187. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3188. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  3189. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  3190. Status: 1,
  3191. CreateTime: time.Now().Unix(),
  3192. UpdateTime: time.Now().Unix(),
  3193. ExportTime: export_time,
  3194. }
  3195. service.CreateExportErrLog(&err_log)
  3196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3197. return
  3198. } else {
  3199. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  3200. if err == nil {
  3201. if len(device) == 0 { //没查到数据,插入错误日志
  3202. log := models.ExportLog{
  3203. LogType: 3,
  3204. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3205. TotalNum: int64(len(total_schedule)),
  3206. FailNum: 1,
  3207. SuccessNum: int64(len(schedules)),
  3208. CreateTime: time.Now().Unix(),
  3209. UpdateTime: time.Now().Unix(),
  3210. ExportTime: export_time,
  3211. Status: 1,
  3212. }
  3213. service.CreateExportLog(&log)
  3214. err_log := models.ExportErrLog{
  3215. LogType: 3,
  3216. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3217. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  3218. Status: 1,
  3219. CreateTime: time.Now().Unix(),
  3220. UpdateTime: time.Now().Unix(),
  3221. ExportTime: export_time,
  3222. }
  3223. service.CreateExportErrLog(&err_log)
  3224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3225. return
  3226. } else if len(device) == 1 {
  3227. sch.DeviceNumberID = device[0].ID
  3228. } else if len(device) > 1 { //出现重名,插入错误日志
  3229. log := models.ExportLog{
  3230. LogType: 3,
  3231. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3232. TotalNum: int64(len(total_schedule)),
  3233. FailNum: 1,
  3234. SuccessNum: int64(len(schedules)),
  3235. CreateTime: time.Now().Unix(),
  3236. UpdateTime: time.Now().Unix(),
  3237. ExportTime: export_time,
  3238. Status: 1,
  3239. }
  3240. service.CreateExportLog(&log)
  3241. err_log := models.ExportErrLog{
  3242. LogType: 3,
  3243. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3244. ErrMsg: "出现两个床位号相同的床位",
  3245. Status: 1,
  3246. CreateTime: time.Now().Unix(),
  3247. UpdateTime: time.Now().Unix(),
  3248. ExportTime: export_time,
  3249. }
  3250. service.CreateExportErrLog(&err_log)
  3251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3252. return
  3253. }
  3254. }
  3255. }
  3256. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  3257. utils.ErrorLog("schedule_week")
  3258. return
  3259. }
  3260. schedule_week, _ := schMapM["schedule_week"].(string)
  3261. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  3262. log := models.ExportLog{
  3263. LogType: 3,
  3264. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3265. TotalNum: int64(len(total_schedule)),
  3266. FailNum: 1,
  3267. SuccessNum: int64(len(schedules)),
  3268. CreateTime: time.Now().Unix(),
  3269. UpdateTime: time.Now().Unix(),
  3270. ExportTime: export_time,
  3271. Status: 1,
  3272. }
  3273. service.CreateExportLog(&log)
  3274. err_log := models.ExportErrLog{
  3275. LogType: 3,
  3276. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3277. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  3278. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  3279. Status: 1,
  3280. CreateTime: time.Now().Unix(),
  3281. UpdateTime: time.Now().Unix(),
  3282. ExportTime: export_time,
  3283. }
  3284. service.CreateExportErrLog(&err_log)
  3285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3286. return
  3287. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  3288. log := models.ExportLog{
  3289. LogType: 3,
  3290. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3291. TotalNum: int64(len(total_schedule)),
  3292. FailNum: 1,
  3293. SuccessNum: int64(len(schedules)),
  3294. CreateTime: time.Now().Unix(),
  3295. UpdateTime: time.Now().Unix(),
  3296. ExportTime: export_time,
  3297. Status: 1,
  3298. }
  3299. service.CreateExportLog(&log)
  3300. err_log := models.ExportErrLog{
  3301. LogType: 3,
  3302. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3303. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  3304. Status: 1,
  3305. CreateTime: time.Now().Unix(),
  3306. UpdateTime: time.Now().Unix(),
  3307. ExportTime: export_time,
  3308. }
  3309. service.CreateExportErrLog(&err_log)
  3310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3311. return
  3312. } else {
  3313. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  3314. sch.Weekday = int8(schedule_week)
  3315. }
  3316. treat_mode, _ := schMapM["treat_mode"].(string)
  3317. treat_mode_int, _ := strconv.ParseInt(treat_mode, 10, 64)
  3318. sch.CreateTime = time.Now().Unix()
  3319. sch.ModifyTime = time.Now().Unix()
  3320. sch.TreatMode = treat_mode_int
  3321. sch.Status = 1
  3322. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  3323. sch.IsExport = 1
  3324. schedules = append(schedules, &sch)
  3325. }
  3326. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3327. //for _, item := range schedules {
  3328. //
  3329. //}
  3330. if len(schedules) > 0 {
  3331. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  3332. if err == nil {
  3333. for _, item := range schedules {
  3334. //判斷某個模板下,當天是否有排版,沒有的話就新增
  3335. total := service.ExportScheduleTemplate(item)
  3336. if total == 0 {
  3337. service.CreateScheduleTemplate(item)
  3338. }
  3339. }
  3340. ////查询已经转出或者死亡的患者
  3341. //patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  3342. //for _, it := range patientList {
  3343. // timeStr := time.Now().Format("2006-01-02")
  3344. // timeLayout := "2006-01-02 15:04:05"
  3345. // timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  3346. // timenow := timeStringToTime.Unix()
  3347. // service.UpdateScheduleByDeathTime(it.ID, timenow)
  3348. // service.UpdateScheduleItemByPatientId(it.ID)
  3349. //}
  3350. log := models.ExportLog{
  3351. LogType: 3,
  3352. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3353. TotalNum: int64(len(total_schedule)),
  3354. FailNum: int64(len(errLogs)),
  3355. SuccessNum: int64(len(schedules)),
  3356. CreateTime: time.Now().Unix(),
  3357. UpdateTime: time.Now().Unix(),
  3358. ExportTime: export_time,
  3359. Status: 1,
  3360. }
  3361. service.CreateExportLog(&log)
  3362. this.ServeSuccessJSON(map[string]interface{}{
  3363. "msg": "导入成功",
  3364. "total_num": len(total_schedule),
  3365. "success_num": len(schedules),
  3366. "fail_num": int64(len(errLogs)),
  3367. })
  3368. } else {
  3369. log := models.ExportLog{
  3370. LogType: 3,
  3371. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3372. TotalNum: int64(len(total_schedule)),
  3373. FailNum: int64(len(errLogs)),
  3374. SuccessNum: int64(len(schedules)),
  3375. CreateTime: time.Now().Unix(),
  3376. UpdateTime: time.Now().Unix(),
  3377. ExportTime: export_time,
  3378. Status: 1,
  3379. }
  3380. service.CreateExportLog(&log)
  3381. this.ServeSuccessJSON(map[string]interface{}{
  3382. "msg": "导入成功",
  3383. "total_num": len(total_schedule),
  3384. "success_num": len(schedules),
  3385. "fail_num": int64(len(errLogs)),
  3386. })
  3387. }
  3388. } else {
  3389. log := models.ExportLog{
  3390. LogType: 3,
  3391. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3392. TotalNum: int64(len(total_schedule)),
  3393. FailNum: int64(len(errLogs)),
  3394. SuccessNum: int64(len(schedules)),
  3395. CreateTime: time.Now().Unix(),
  3396. UpdateTime: time.Now().Unix(),
  3397. ExportTime: export_time,
  3398. Status: 1,
  3399. }
  3400. service.CreateExportLog(&log)
  3401. this.ServeSuccessJSON(map[string]interface{}{
  3402. "msg": "导入成功",
  3403. "total_num": len(total_schedule),
  3404. "success_num": len(schedules),
  3405. "fail_num": int64(len(errLogs)),
  3406. })
  3407. }
  3408. }
  3409. }
  3410. func (c *ScheduleApiController) GetInitExcelInitDate() {
  3411. thisTime := time.Now()
  3412. thisTime1 := time.Now()
  3413. thisTime2 := time.Now()
  3414. thisTime3 := time.Now()
  3415. thisTime4 := time.Now()
  3416. thisTime1 = thisTime1.AddDate(0, 0, 7)
  3417. thisTime2 = thisTime2.AddDate(0, 0, 14)
  3418. thisTime3 = thisTime3.AddDate(0, 0, 21)
  3419. thisTime4 = thisTime4.AddDate(0, 0, 28)
  3420. weekDay := int(thisTime.Weekday())
  3421. if weekDay == 0 {
  3422. weekDay = 7
  3423. }
  3424. weekEnd := 7 - weekDay
  3425. weekStart := weekEnd - 6
  3426. days := make([]string, 0)
  3427. for index := weekStart; index <= weekEnd; index++ {
  3428. theDay := thisTime.AddDate(0, 0, index)
  3429. days = append(days, theDay.Format("2006-01-02"))
  3430. }
  3431. weekDay1 := int(thisTime1.Weekday())
  3432. if weekDay1 == 0 {
  3433. weekDay1 = 7
  3434. }
  3435. weekEnd1 := 7 - weekDay1
  3436. weekStart1 := weekEnd1 - 6
  3437. for index := weekStart1; index <= weekEnd1; index++ {
  3438. theDay := thisTime1.AddDate(0, 0, index)
  3439. days = append(days, theDay.Format("2006-01-02"))
  3440. }
  3441. weekDay2 := int(thisTime2.Weekday())
  3442. if weekDay2 == 0 {
  3443. weekDay2 = 7
  3444. }
  3445. weekEnd2 := 7 - weekDay2
  3446. weekStart2 := weekEnd2 - 6
  3447. for index := weekStart2; index <= weekEnd2; index++ {
  3448. theDay := thisTime2.AddDate(0, 0, index)
  3449. days = append(days, theDay.Format("2006-01-02"))
  3450. }
  3451. weekDay3 := int(thisTime3.Weekday())
  3452. if weekDay3 == 0 {
  3453. weekDay3 = 7
  3454. }
  3455. weekEnd3 := 7 - weekDay3
  3456. weekStart3 := weekEnd3 - 6
  3457. for index := weekStart3; index <= weekEnd3; index++ {
  3458. theDay := thisTime3.AddDate(0, 0, index)
  3459. days = append(days, theDay.Format("2006-01-02"))
  3460. }
  3461. weekDay4 := int(thisTime4.Weekday())
  3462. if weekDay4 == 0 {
  3463. weekDay4 = 7
  3464. }
  3465. weekEnd4 := 7 - weekDay4
  3466. weekStart4 := weekEnd4 - 6
  3467. for index := weekStart4; index <= weekEnd4; index++ {
  3468. theDay := thisTime4.AddDate(0, 0, index)
  3469. days = append(days, theDay.Format("2006-01-02"))
  3470. }
  3471. c.ServeSuccessJSON(map[string]interface{}{
  3472. "days": days,
  3473. })
  3474. return
  3475. }
  3476. func GetWeekString(week string) string {
  3477. var weekStr string
  3478. switch week {
  3479. case "Sunday":
  3480. weekStr = "周日"
  3481. break
  3482. case "Monday":
  3483. weekStr = "周一"
  3484. break
  3485. case "Tuesday":
  3486. weekStr = "周二"
  3487. break
  3488. case "Wednesday":
  3489. weekStr = "周三"
  3490. break
  3491. case "Thursday":
  3492. weekStr = "周四"
  3493. break
  3494. case "Friday":
  3495. weekStr = "周五"
  3496. break
  3497. case "Saturday":
  3498. weekStr = "周六"
  3499. break
  3500. default:
  3501. weekStr = ""
  3502. break
  3503. }
  3504. return weekStr
  3505. }
  3506. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  3507. template_id, _ := c.GetInt64("template_id", 0)
  3508. keywords := c.GetString("keywords")
  3509. adminInfo := c.GetAdminUserInfo()
  3510. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  3511. c.ServeSuccessJSON(map[string]interface{}{
  3512. "schdules": scheduleItems,
  3513. })
  3514. }
  3515. func (c *ScheduleApiController) CancelScheduleTemplate() {
  3516. item_id, _ := c.GetInt64("id")
  3517. adminInfo := c.GetAdminUserInfo()
  3518. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  3519. if err == nil {
  3520. c.ServeSuccessJSON(map[string]interface{}{
  3521. "msg": "取消成功",
  3522. })
  3523. return
  3524. } else {
  3525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3526. return
  3527. }
  3528. }
  3529. func (this *ScheduleApiController) GetNextWeekDayScheduleOne() {
  3530. week_type, _ := this.GetInt64("week_type", -1)
  3531. week_time, _ := this.GetInt64("week_time")
  3532. record_date := this.GetString("record_date")
  3533. zons := this.GetString("zone")
  3534. zone := strings.Split(zons, ",")
  3535. start_time, _ := this.GetInt64("start_time")
  3536. end_time, _ := this.GetInt64("end_time")
  3537. timeLayout := "2006-01-02"
  3538. loc, _ := time.LoadLocation("Local")
  3539. //theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3540. //theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  3541. ids := this.GetString("ids")
  3542. var idStr []string
  3543. if len(ids) > 0 {
  3544. idStr = strings.Split(ids, ",")
  3545. }
  3546. adminUserInfo := this.GetAdminUserInfo()
  3547. var theStartTIme int64
  3548. if len(record_date) > 0 {
  3549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3550. if err != nil {
  3551. utils.ErrorLog(err.Error())
  3552. }
  3553. theStartTIme = theTime.Unix()
  3554. }
  3555. schedule, err := service.GetNextWeekDayScheduleSix(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone, theStartTIme, idStr)
  3556. for _, item := range schedule {
  3557. order, _ := service.GetLastDialysisOrder(adminUserInfo.CurrentOrgId, item.PatientId, theStartTIme)
  3558. item.XtDialysisOrderSix = order
  3559. solutionLastWeek, _ := service.GetDialysisSolutionLastWeek(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId)
  3560. item.DialysisSolution = solutionLastWeek
  3561. prescription, _ := service.GetLastDialysisPrescriptionTwo(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3562. item.DialysisPrescription = prescription
  3563. }
  3564. if err != nil {
  3565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3566. return
  3567. }
  3568. this.ServeSuccessJSON(map[string]interface{}{
  3569. "schedule": schedule,
  3570. })
  3571. }
  3572. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  3573. week_type, _ := this.GetInt64("week_type", -1)
  3574. week_time, _ := this.GetInt64("week_time")
  3575. record_date := this.GetString("record_date")
  3576. zons := this.GetString("zone")
  3577. zone := strings.Split(zons, ",")
  3578. start_time := this.GetString("start_time")
  3579. end_time := this.GetString("end_time")
  3580. timeLayout := "2006-01-02"
  3581. loc, _ := time.LoadLocation("Local")
  3582. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3583. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  3584. ids := this.GetString("ids")
  3585. var idStr []string
  3586. if len(ids) > 0 {
  3587. idStr = strings.Split(ids, ",")
  3588. }
  3589. adminUserInfo := this.GetAdminUserInfo()
  3590. var theStartTIme int64
  3591. if len(record_date) > 0 {
  3592. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3593. if err != nil {
  3594. utils.ErrorLog(err.Error())
  3595. }
  3596. theStartTIme = theTime.Unix()
  3597. }
  3598. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme, idStr)
  3599. for _, item := range schedule {
  3600. AssessmentBefor, _ := service.GetAssessmentBeforListLastWeek(item.ScheduleDate, item.PatientId, item.UserOrgId)
  3601. item.XtAssessmentBeforeDislysis = AssessmentBefor
  3602. doctorAdvices, _ := service.GetDoctorAdviceLastWeek(item.UserOrgId, item.PatientId, item.ScheduleDate)
  3603. item.DoctorAdvice = doctorAdvices
  3604. hisDoctorAdvice, _ := service.GetHisDoctorAdviceListLastWeek(item.UserOrgId, item.PatientId, item.ScheduleDate)
  3605. item.HisDoctorAdviceInfo = hisDoctorAdvice
  3606. solutionLastWeek, _ := service.GetDialysisSolutionLastWeek(item.UserOrgId, item.PatientId, item.ModeId)
  3607. item.DialysisSolution = solutionLastWeek
  3608. templateList, _ := service.GetHisPrescriptionTemplateList(item.UserOrgId, item.PatientId, item.ModeId)
  3609. item.HisPrescriptionTemplate = templateList
  3610. }
  3611. if err != nil {
  3612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3613. return
  3614. }
  3615. this.ServeSuccessJSON(map[string]interface{}{
  3616. "schedule": schedule,
  3617. })
  3618. }
  3619. func (this *ScheduleApiController) GetThreeWeekList() {
  3620. start_time := this.GetString("start_time")
  3621. end_time := this.GetString("end_time")
  3622. partition_id, _ := this.GetInt64("partition_id")
  3623. schedule_type, _ := this.GetInt64("schedule_type")
  3624. fmt.Println(partition_id, schedule_type)
  3625. timeLayout := "2006-01-02"
  3626. loc, _ := time.LoadLocation("Local")
  3627. var theStartTIme int64
  3628. if len(start_time) > 0 {
  3629. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3630. if err != nil {
  3631. utils.ErrorLog(err.Error())
  3632. }
  3633. theStartTIme = theTime.Unix()
  3634. }
  3635. var theEndtTIme int64
  3636. if len(end_time) > 0 {
  3637. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  3638. if err != nil {
  3639. utils.ErrorLog(err.Error())
  3640. }
  3641. theEndtTIme = theTime.Unix()
  3642. }
  3643. adminUserInfo := this.GetAdminUserInfo()
  3644. orgId := adminUserInfo.CurrentOrgId
  3645. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  3646. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  3647. if err != nil {
  3648. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3649. return
  3650. }
  3651. this.ServeSuccessJSON(map[string]interface{}{
  3652. "list": list,
  3653. "partitions": partitions,
  3654. })
  3655. }
  3656. func (this *ScheduleApiController) GetAllZones() {
  3657. adminUserInfo := this.GetAdminUserInfo()
  3658. orgId := adminUserInfo.CurrentOrgId
  3659. zones, err := service.GetAllZoneOne(orgId)
  3660. devicenumber, err := service.GetAllBedNumberList(orgId)
  3661. if err != nil {
  3662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3663. return
  3664. }
  3665. this.ServeSuccessJSON(map[string]interface{}{
  3666. "zones": zones,
  3667. "devicenumber": devicenumber,
  3668. })
  3669. }
  3670. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  3671. adminUserInfo := this.GetAdminUserInfo()
  3672. orgId := adminUserInfo.CurrentOrgId
  3673. start_time, _ := this.GetInt64("start_time")
  3674. end_time, _ := this.GetInt64("end_time")
  3675. copy_startime, _ := this.GetInt64("copy_startime")
  3676. copy_endtime, _ := this.GetInt64("copy_endtime")
  3677. //获取本周患者排班
  3678. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  3679. //先清除复制周的排班
  3680. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  3681. fmt.Println(errcode)
  3682. var err error
  3683. for _, item := range schedules {
  3684. //fmt.Println(item.StartTime+604800)
  3685. //礼拜1
  3686. if item.ScheduleWeek == 1 {
  3687. item.ScheduleDate = copy_startime
  3688. }
  3689. if item.ScheduleWeek == 2 {
  3690. item.ScheduleDate = copy_startime + 86400
  3691. }
  3692. if item.ScheduleWeek == 3 {
  3693. item.ScheduleDate = copy_startime + 172800
  3694. }
  3695. if item.ScheduleWeek == 4 {
  3696. item.ScheduleDate = copy_startime + 259200
  3697. }
  3698. if item.ScheduleWeek == 5 {
  3699. item.ScheduleDate = copy_startime + 345600
  3700. }
  3701. if item.ScheduleWeek == 6 {
  3702. item.ScheduleDate = copy_startime + 432000
  3703. }
  3704. //礼拜天
  3705. if item.ScheduleWeek == 7 {
  3706. item.ScheduleDate = copy_endtime
  3707. }
  3708. schedule := models.XtSchedule{
  3709. UserOrgId: item.UserOrgId,
  3710. PartitionId: item.PartitionId,
  3711. BedId: item.BedId,
  3712. PatientId: item.PatientId,
  3713. ScheduleDate: item.ScheduleDate,
  3714. ScheduleType: item.ScheduleType,
  3715. ScheduleWeek: item.ScheduleWeek,
  3716. ModeId: item.ModeId,
  3717. Status: 1,
  3718. CreatedTime: time.Now().Unix(),
  3719. }
  3720. var DialysisMachineName string
  3721. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3722. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  3723. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  3724. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  3725. if filedRecordOne.IsShow == 1 {
  3726. DialysisMachineName = so.DialysisDialyszers
  3727. }
  3728. if filedRecordThree.IsShow == 1 {
  3729. if len(DialysisMachineName) > 0 {
  3730. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3731. } else {
  3732. DialysisMachineName = so.DialyzerPerfusionApparatus
  3733. }
  3734. }
  3735. if filedRecordTwo.IsShow == 1 {
  3736. if len(DialysisMachineName) > 0 {
  3737. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3738. } else {
  3739. DialysisMachineName = so.DialysisIrrigation
  3740. }
  3741. }
  3742. schedule.DialysisMachineName = DialysisMachineName
  3743. schedule.IsExport = 4000
  3744. err = service.AddPatientSchedule(&schedule)
  3745. }
  3746. patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  3747. timeStr := time.Now().Format("2006-01-02")
  3748. timeLayout := "2006-01-02 15:04:05"
  3749. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  3750. timenow := timeStringToTime.Unix()
  3751. for _, it := range patientList {
  3752. service.UpdateScheduleByDeathTime(it.ID, timenow)
  3753. service.UpdateScheduleItemByPatientId(it.ID)
  3754. }
  3755. if err != nil {
  3756. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3757. return
  3758. }
  3759. this.ServeSuccessJSON(map[string]interface{}{
  3760. "msg": "msg",
  3761. })
  3762. return
  3763. //查询复制中的排班日期是否存在
  3764. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  3765. //
  3766. //if errcode == gorm.ErrRecordNotFound {
  3767. // //如果没有直接新增
  3768. //
  3769. // for _, item := range schedules {
  3770. // //fmt.Println(item.StartTime+604800)
  3771. // //礼拜1
  3772. // if item.ScheduleWeek == 1 {
  3773. // item.ScheduleDate = copy_startime
  3774. // }
  3775. // if item.ScheduleWeek == 2 {
  3776. // item.ScheduleDate = copy_startime + 86400
  3777. // }
  3778. // if item.ScheduleWeek == 3 {
  3779. // item.ScheduleDate = copy_startime + 172800
  3780. // }
  3781. // if item.ScheduleWeek == 4 {
  3782. // item.ScheduleDate = copy_startime + 259200
  3783. // }
  3784. // if item.ScheduleWeek == 5 {
  3785. // item.ScheduleDate = copy_startime + 345600
  3786. // }
  3787. //
  3788. // if item.ScheduleWeek == 6 {
  3789. // item.ScheduleDate = copy_startime + 432000
  3790. // }
  3791. // //礼拜天
  3792. // if item.ScheduleWeek == 0 {
  3793. // item.ScheduleDate = copy_endtime
  3794. // }
  3795. // schedule := models.XtSchedule{
  3796. // UserOrgId: item.UserOrgId,
  3797. // PartitionId: item.PartitionId,
  3798. // BedId: item.BedId,
  3799. // PatientId: item.PatientId,
  3800. // ScheduleDate: item.ScheduleDate,
  3801. // ScheduleType: item.ScheduleType,
  3802. // ScheduleWeek: item.ScheduleWeek,
  3803. // ModeId: item.ModeId,
  3804. // Status: 1,
  3805. // CreatedTime: time.Now().Unix(),
  3806. // }
  3807. //
  3808. // err := service.AddPatientSchedule(&schedule)
  3809. // if err != nil {
  3810. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3811. // return
  3812. // }
  3813. // this.ServeSuccessJSON(map[string]interface{}{
  3814. // "schedule": schedule,
  3815. // })
  3816. // }
  3817. //} else if errcode == nil {
  3818. //
  3819. // //先清除复制周的排班
  3820. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  3821. // fmt.Println(errcode)
  3822. // for _, item := range schedules {
  3823. // //fmt.Println(item.StartTime+604800)
  3824. // //礼拜1
  3825. // if item.ScheduleWeek == 1 {
  3826. // item.ScheduleDate = copy_startime
  3827. // }
  3828. // if item.ScheduleWeek == 2 {
  3829. // item.ScheduleDate = copy_startime + 86400
  3830. // }
  3831. // if item.ScheduleWeek == 3 {
  3832. // item.ScheduleDate = copy_startime + 172800
  3833. // }
  3834. // if item.ScheduleWeek == 4 {
  3835. // item.ScheduleDate = copy_startime + 259200
  3836. // }
  3837. // if item.ScheduleWeek == 5 {
  3838. // item.ScheduleDate = copy_startime + 345600
  3839. // }
  3840. //
  3841. // if item.ScheduleWeek == 6 {
  3842. // item.ScheduleDate = copy_startime + 432000
  3843. // }
  3844. // //礼拜天
  3845. // if item.ScheduleWeek == 0 {
  3846. // item.ScheduleDate = copy_endtime
  3847. // }
  3848. // schedule := models.XtSchedule{
  3849. // UserOrgId: item.UserOrgId,
  3850. // PartitionId: item.PartitionId,
  3851. // BedId: item.BedId,
  3852. // PatientId: item.PatientId,
  3853. // ScheduleDate: item.ScheduleDate,
  3854. // ScheduleType: item.ScheduleType,
  3855. // ScheduleWeek: item.ScheduleWeek,
  3856. // ModeId: item.ModeId,
  3857. // Status: 1,
  3858. // CreatedTime: time.Now().Unix(),
  3859. // }
  3860. //
  3861. // err := service.AddPatientSchedule(&schedule)
  3862. // if err != nil {
  3863. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3864. // return
  3865. // }
  3866. // this.ServeSuccessJSON(map[string]interface{}{
  3867. // "schedule": schedule,
  3868. // })
  3869. // }
  3870. //}
  3871. }
  3872. func (this *ScheduleApiController) SaveRemindPrint() {
  3873. id, _ := this.GetInt64("id")
  3874. anticoagulants, _ := this.GetInt64("anticoagulant")
  3875. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  3876. classes, _ := this.GetInt64("classes")
  3877. dialyzers, _ := this.GetInt64("dialyzers")
  3878. doctor_advice, _ := this.GetInt64("doctor_advice")
  3879. mode, _ := this.GetInt64("mode")
  3880. name, _ := this.GetInt64("name")
  3881. number, _ := this.GetInt64("number")
  3882. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  3883. prescription_status, _ := this.GetInt64("prescription_status")
  3884. week, _ := this.GetInt64("week")
  3885. zone, _ := this.GetInt64("zone")
  3886. adminUserInfo := this.GetAdminUserInfo()
  3887. orgId := adminUserInfo.CurrentOrgId
  3888. setting := models.XtRemindPrintSetting{
  3889. Anticoagulant: anticoagulants,
  3890. Classes: classes,
  3891. AnticoagulantZongliang: anticoagulant_zongliang,
  3892. Dialyzers: dialyzers,
  3893. DoctorAdvice: doctor_advice,
  3894. Mode: mode,
  3895. Name: name,
  3896. Number: number,
  3897. PerfusionApparatus: perfusion_apparatus,
  3898. PrescriptionStatus: prescription_status,
  3899. Week: week,
  3900. Zone: zone,
  3901. UserOrgId: orgId,
  3902. Status: 1,
  3903. Ctime: time.Now().Unix(),
  3904. }
  3905. _, errcode := service.GetSettingById(id)
  3906. if errcode == gorm.ErrRecordNotFound {
  3907. err := service.CreateSetting(&setting)
  3908. if err != nil {
  3909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3910. return
  3911. }
  3912. this.ServeSuccessJSON(map[string]interface{}{
  3913. "setting": setting,
  3914. })
  3915. } else if errcode == nil {
  3916. err := service.UpdatedRemindPrint(&setting, id)
  3917. if err != nil {
  3918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3919. return
  3920. }
  3921. this.ServeSuccessJSON(map[string]interface{}{
  3922. "setting": setting,
  3923. })
  3924. }
  3925. }
  3926. func (this *ScheduleApiController) GetRemindPrintList() {
  3927. adminUserInfo := this.GetAdminUserInfo()
  3928. orgId := adminUserInfo.CurrentOrgId
  3929. list, err := service.GetRemindPrintList(orgId)
  3930. if err != nil {
  3931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3932. return
  3933. }
  3934. this.ServeSuccessJSON(map[string]interface{}{
  3935. "list": list,
  3936. })
  3937. }
  3938. func (this *ScheduleApiController) GetBloodScheduleList() {
  3939. week_type, _ := this.GetInt64("week_type", -1)
  3940. week_time, _ := this.GetInt64("week_time")
  3941. zones := this.GetString("zone")
  3942. zone := strings.Split(zones, ",")
  3943. limit, _ := this.GetInt64("limit")
  3944. page, _ := this.GetInt64("page")
  3945. ids := this.GetString("ids")
  3946. var idStr []string
  3947. if len(ids) > 0 {
  3948. idStr = strings.Split(ids, ",")
  3949. }
  3950. thisTime := time.Now()
  3951. weekDay := int(thisTime.Weekday())
  3952. if weekDay == 0 {
  3953. weekDay = 7
  3954. }
  3955. weekEnd := 7 - weekDay
  3956. weekStart := weekEnd - 6
  3957. weekTitle := make([]string, 0)
  3958. days := make([]string, 0)
  3959. for index := weekStart; index <= weekEnd; index++ {
  3960. theDay := thisTime.AddDate(0, 0, index)
  3961. indexYear, indexMonthTime, indexDay := theDay.Date()
  3962. indexMonth := int(indexMonthTime)
  3963. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3964. weekTitle = append(weekTitle, indexWeek)
  3965. days = append(days, theDay.Format("2006-01-02"))
  3966. }
  3967. var targetDayStr string
  3968. var startTime string
  3969. switch week_type {
  3970. case 0:
  3971. startTime = days[0]
  3972. targetDayStr = days[6]
  3973. break
  3974. case 1:
  3975. targetDayStr = days[0]
  3976. break
  3977. case 2:
  3978. targetDayStr = days[1]
  3979. break
  3980. case 3:
  3981. targetDayStr = days[2]
  3982. break
  3983. case 4:
  3984. targetDayStr = days[3]
  3985. break
  3986. case 5:
  3987. targetDayStr = days[4]
  3988. break
  3989. case 6:
  3990. targetDayStr = days[5]
  3991. break
  3992. case 7:
  3993. targetDayStr = days[6]
  3994. break
  3995. }
  3996. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  3997. if parseErr != nil {
  3998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3999. return
  4000. }
  4001. orgId := this.GetAdminUserInfo().CurrentOrgId
  4002. if week_type > 0 {
  4003. list, total, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone, limit, page, idStr)
  4004. for _, item := range list {
  4005. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  4006. item.XtDialysisOrderSix = order
  4007. advicehisList, _ := service.GetHisDoctorAdviceList(orgId, item.PatientId, targetDay.Unix())
  4008. item.HisDoctorAdviceInfo = advicehisList
  4009. advices, _ := service.GetDoctorAdviceListSchedule(orgId, item.PatientId)
  4010. item.DoctorAdvice = advices
  4011. prescription, _ := service.GetLastDialysisPrescriptionTwo(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  4012. item.DialysisPrescription = prescription
  4013. dialysisSolution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId)
  4014. item.DialysisSolution = dialysisSolution
  4015. lastDialysisAfter, _ := service.GetLastDialysisAfter(orgId, item.PatientId, item.ScheduleDate)
  4016. item.LastAfterWeight = lastDialysisAfter
  4017. assessmentBeforFourty, _ := service.GetAssessmentBeforFourty(orgId, item.PatientId, item.ScheduleDate)
  4018. item.XtAssessmentBeforeDislysis = assessmentBeforFourty
  4019. templateList, _ := service.GetHisPrescriptionTemplateList(orgId, item.PatientId, item.ModeId)
  4020. item.HisPrescriptionTemplate = templateList
  4021. }
  4022. if err != nil {
  4023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4024. return
  4025. }
  4026. this.ServeSuccessJSON(map[string]interface{}{
  4027. "list": list,
  4028. "day": targetDayStr,
  4029. "total": total,
  4030. })
  4031. }
  4032. if week_type == 0 {
  4033. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  4034. list, total, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone, limit, page, idStr)
  4035. for _, item := range list {
  4036. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  4037. item.XtDialysisOrderSix = order
  4038. advicehisList, _ := service.GetHisDoctorAdviceList(orgId, item.PatientId, targetDay.Unix())
  4039. item.HisDoctorAdviceInfo = advicehisList
  4040. advices, _ := service.GetDoctorAdviceListSchedule(orgId, item.PatientId)
  4041. item.DoctorAdvice = advices
  4042. prescription, _ := service.GetLastDialysisPrescriptionTwo(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  4043. item.DialysisPrescription = prescription
  4044. dialysisSolution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId)
  4045. item.DialysisSolution = dialysisSolution
  4046. lastDialysisAfter, _ := service.GetLastDialysisAfter(orgId, item.PatientId, item.ScheduleDate)
  4047. item.LastAfterWeight = lastDialysisAfter
  4048. assessmentBeforFourty, _ := service.GetAssessmentBeforFourty(orgId, item.PatientId, item.ScheduleDate)
  4049. item.XtAssessmentBeforeDislysis = assessmentBeforFourty
  4050. templateList, _ := service.GetHisPrescriptionTemplateList(orgId, item.PatientId, item.ModeId)
  4051. item.HisPrescriptionTemplate = templateList
  4052. }
  4053. if err != nil {
  4054. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4055. return
  4056. }
  4057. this.ServeSuccessJSON(map[string]interface{}{
  4058. "list": list,
  4059. "day": targetDayStr,
  4060. "total": total,
  4061. })
  4062. }
  4063. }
  4064. func (this *ScheduleApiController) GetPrintList() {
  4065. adminUserInfo := this.GetAdminUserInfo()
  4066. orgId := adminUserInfo.CurrentOrgId
  4067. list, err := service.GetRemindPrintList(orgId)
  4068. if err != nil {
  4069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4070. return
  4071. }
  4072. this.ServeSuccessJSON(map[string]interface{}{
  4073. "list": list,
  4074. })
  4075. }
  4076. func (this *ScheduleApiController) GetAllZoneList() {
  4077. adminUserInfo := this.GetAdminUserInfo()
  4078. orgId := adminUserInfo.CurrentOrgId
  4079. zoneList, err := service.GetAllZoneOne(orgId)
  4080. if err != nil {
  4081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4082. return
  4083. }
  4084. this.ServeSuccessJSON(map[string]interface{}{
  4085. "zoneList": zoneList,
  4086. })
  4087. }
  4088. func (this *ScheduleApiController) GetPatientScheduleCount() {
  4089. patitionIdStr := this.GetString("partition_id")
  4090. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  4091. ids := strings.Split(patitionIdStr, ",")
  4092. adminUserInfo := this.GetAdminUserInfo()
  4093. orgId := adminUserInfo.CurrentOrgId
  4094. thisTime := time.Now()
  4095. weekDay := int(thisTime.Weekday())
  4096. if week < 1 || week > 4 {
  4097. week = 2
  4098. }
  4099. if week == 1 {
  4100. thisTime = thisTime.AddDate(0, 0, -7)
  4101. } else if week == 3 {
  4102. thisTime = thisTime.AddDate(0, 0, 7)
  4103. } else if week == 4 {
  4104. thisTime = thisTime.AddDate(0, 0, 14)
  4105. }
  4106. if weekDay == 0 {
  4107. weekDay = 7
  4108. }
  4109. weekEnd := 7 - weekDay
  4110. weekStart := weekEnd - 6
  4111. weekTitle := make([]string, 0)
  4112. days := make([]string, 0)
  4113. for index := weekStart; index <= weekEnd; index++ {
  4114. theDay := thisTime.AddDate(0, 0, index)
  4115. indexYear, indexMonthTime, indexDay := theDay.Date()
  4116. indexMonth := int(indexMonthTime)
  4117. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4118. weekTitle = append(weekTitle, indexWeek)
  4119. days = append(days, theDay.Format("2006-01-02"))
  4120. }
  4121. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  4122. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  4123. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  4124. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  4125. timeLayout := "2006-01-02 15:04:05"
  4126. loc, _ := time.LoadLocation("Local")
  4127. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  4128. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  4129. weekStartPoint := theStarTime.Unix()
  4130. weekEndPoint := theEndTime.Unix()
  4131. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  4132. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  4133. if err != nil {
  4134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4135. return
  4136. }
  4137. this.ServeSuccessJSON(map[string]interface{}{
  4138. "list": list,
  4139. "total": total,
  4140. })
  4141. }
  4142. func (c *ScheduleApiController) GetWeekPanelsOne() {
  4143. data, _ := c.GetInt64("data", 1)
  4144. patitionIdStr := c.GetString("patitionid")
  4145. ids := strings.Split(patitionIdStr, ",")
  4146. adminInfo := c.GetAdminUserInfo()
  4147. thisTime := time.Now()
  4148. year, monthTime, day := thisTime.Date()
  4149. month := int(monthTime)
  4150. _, theWeek := thisTime.ISOWeek()
  4151. weekDay := int(thisTime.Weekday())
  4152. if weekDay == 0 {
  4153. weekDay = 7
  4154. }
  4155. weekEnd := 7 - weekDay
  4156. weekStart := weekEnd - 6
  4157. weekDays := make([]string, 0)
  4158. for index := weekStart; index <= weekEnd; index++ {
  4159. theDay := thisTime.AddDate(0, 0, index)
  4160. indexYear, indexMonthTime, indexDay := theDay.Date()
  4161. indexMonth := int(indexMonthTime)
  4162. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4163. weekDays = append(weekDays, indexWeek)
  4164. }
  4165. returnData := map[string]interface{}{
  4166. "year": year,
  4167. "month": month,
  4168. "day": day,
  4169. "theWeek": theWeek,
  4170. "weekDay": weekDay,
  4171. "weekDays": weekDays,
  4172. }
  4173. if data == 1 {
  4174. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  4175. returnData["partitions"] = partitions
  4176. }
  4177. c.ServeSuccessJSON(returnData)
  4178. return
  4179. }
  4180. func (c *ScheduleApiController) GetScheduleOne() {
  4181. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  4182. patitionIdStr := c.GetString("patitionid")
  4183. ids := strings.Split(patitionIdStr, ",")
  4184. //fmt.Println("patitonStr", ids)
  4185. schedule_type, _ := c.GetInt64("schedule_type")
  4186. is_before, _ := c.GetInt64("is_before")
  4187. start_time := c.GetString("start_time")
  4188. end_time := c.GetString("end_time")
  4189. adminInfo := c.GetAdminUserInfo()
  4190. thisTime := time.Now()
  4191. today := thisTime.Format("2006-01-02")
  4192. if week < 1 || week > 4 {
  4193. week = 2
  4194. }
  4195. if week == 1 {
  4196. thisTime = thisTime.AddDate(0, 0, -7)
  4197. } else if week == 3 {
  4198. thisTime = thisTime.AddDate(0, 0, 7)
  4199. } else if week == 4 {
  4200. thisTime = thisTime.AddDate(0, 0, 14)
  4201. }
  4202. weekDay := int(thisTime.Weekday())
  4203. if weekDay == 0 {
  4204. weekDay = 7
  4205. }
  4206. weekEnd := 7 - weekDay
  4207. weekStart := weekEnd - 6
  4208. weekTitle := make([]string, 0)
  4209. days := make([]string, 0)
  4210. for index := weekStart; index <= weekEnd; index++ {
  4211. theDay := thisTime.AddDate(0, 0, index)
  4212. indexYear, indexMonthTime, indexDay := theDay.Date()
  4213. indexMonth := int(indexMonthTime)
  4214. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4215. weekTitle = append(weekTitle, indexWeek)
  4216. days = append(days, theDay.Format("2006-01-02"))
  4217. }
  4218. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  4219. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  4220. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  4221. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  4222. timeLayout := "2006-01-02 15:04:05"
  4223. loc, _ := time.LoadLocation("Local")
  4224. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  4225. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  4226. weekStartPoint := theStarTime.Unix()
  4227. weekEndPoint := theEndTime.Unix()
  4228. if is_before > 0 {
  4229. timeLayout := "2006-01-02 15:04:05"
  4230. loc, _ := time.LoadLocation("Local")
  4231. theStarTime, _ := time.ParseInLocation(timeLayout, start_time, loc)
  4232. theEndTime, _ := time.ParseInLocation(timeLayout, end_time, loc)
  4233. weekStartPoint = theStarTime.Unix()
  4234. weekEndPoint = theEndTime.Unix()
  4235. }
  4236. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  4237. timenow := time.Now().Format("2006-01-02")
  4238. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timenow)
  4239. if adminInfo.CurrentOrgId == 10346 || adminInfo.CurrentOrgId == 10585 || adminInfo.CurrentOrgId == 10495 {
  4240. if len(schdules) > 0 {
  4241. //获取长期医嘱里面的透析器灌流器
  4242. for _, item := range schdules {
  4243. if item.ScheduleDate >= timeNewDate.Unix() {
  4244. solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
  4245. service.UpdateScheduleByDialysis(item.PatientId, item.ModeId, item.ScheduleDate, item.UserOrgId, solution.DialyzerPerfusionApparatus, item.ScheduleType)
  4246. }
  4247. }
  4248. }
  4249. }
  4250. //查询排班里面的空透析器
  4251. if adminInfo.CurrentOrgId == 10375 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 9538 || adminInfo.CurrentOrgId == 10742 || adminInfo.CurrentOrgId == 10387 || adminInfo.CurrentOrgId == 10740 {
  4252. schedulesFive, _ := service.GetWeekScheduleFive(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  4253. for _, item := range schedulesFive {
  4254. if item.ScheduleDate >= timeNewDate.Unix() {
  4255. solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
  4256. var DialysisMachineName string
  4257. if len(solution.DialysisDialyszers) > 0 {
  4258. DialysisMachineName = solution.DialysisDialyszers
  4259. }
  4260. if len(solution.DialyzerPerfusionApparatus) > 0 {
  4261. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  4262. }
  4263. if len(solution.DialysisIrrigation) > 0 {
  4264. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  4265. }
  4266. if len(solution.DialysisStrainer) > 0 {
  4267. DialysisMachineName = DialysisMachineName + "," + solution.DialysisStrainer
  4268. }
  4269. item.DialysisMachineName = DialysisMachineName
  4270. service.UpdateSchOne(item.ID, item.DialysisMachineName)
  4271. }
  4272. if item.ScheduleDate < timeNewDate.Unix() {
  4273. prescriptionList, _ := service.GetDialysisPrescriptionList(item.PatientId, item.UserOrgId, item.ScheduleDate)
  4274. var DialysisMachineName string
  4275. if len(prescriptionList.DialysisDialyszers) > 0 {
  4276. DialysisMachineName = prescriptionList.DialysisDialyszers
  4277. }
  4278. if len(prescriptionList.DialyzerPerfusionApparatus) > 0 {
  4279. DialysisMachineName = DialysisMachineName + "," + prescriptionList.DialyzerPerfusionApparatus
  4280. }
  4281. if len(prescriptionList.DialysisIrrigation) > 0 {
  4282. DialysisMachineName = DialysisMachineName + "," + prescriptionList.DialysisIrrigation
  4283. }
  4284. if len(prescriptionList.DialysisStrainer) > 0 {
  4285. DialysisMachineName = DialysisMachineName + "," + prescriptionList.DialysisStrainer
  4286. }
  4287. item.DialysisMachineName = DialysisMachineName
  4288. service.UpdateSchOne(item.ID, item.DialysisMachineName)
  4289. }
  4290. }
  4291. }
  4292. schedulesGroup, _ := service.GetScheduleTotalCount(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  4293. c.ServeSuccessJSON(map[string]interface{}{
  4294. "days": days,
  4295. "weekTitle": weekTitle,
  4296. "schdules": schdules,
  4297. "today": today,
  4298. "schedulesGroup": schedulesGroup,
  4299. })
  4300. return
  4301. }
  4302. func (c *ScheduleApiController) GetScheduleTwo() {
  4303. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  4304. patitionIdStr := c.GetString("patitionid")
  4305. ids := strings.Split(patitionIdStr, ",")
  4306. schedule_type, _ := c.GetInt64("schedule_type")
  4307. adminInfo := c.GetAdminUserInfo()
  4308. weekDateStr := c.GetString("week_date")
  4309. WeekDayIds := strings.Split(weekDateStr, ",")
  4310. thisTime := time.Now()
  4311. today := thisTime.Format("2006-01-02")
  4312. if week < 1 || week > 4 {
  4313. week = 2
  4314. }
  4315. if week == 1 {
  4316. thisTime = thisTime.AddDate(0, 0, -7)
  4317. } else if week == 3 {
  4318. thisTime = thisTime.AddDate(0, 0, 7)
  4319. } else if week == 4 {
  4320. thisTime = thisTime.AddDate(0, 0, 14)
  4321. }
  4322. weekDay := int(thisTime.Weekday())
  4323. if weekDay == 0 {
  4324. weekDay = 7
  4325. }
  4326. weekEnd := 7 - weekDay
  4327. weekStart := weekEnd - 6
  4328. weekTitle := make([]string, 0)
  4329. days := make([]string, 0)
  4330. for index := weekStart; index <= weekEnd; index++ {
  4331. theDay := thisTime.AddDate(0, 0, index)
  4332. indexYear, indexMonthTime, indexDay := theDay.Date()
  4333. indexMonth := int(indexMonthTime)
  4334. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4335. weekTitle = append(weekTitle, indexWeek)
  4336. days = append(days, theDay.Format("2006-01-02"))
  4337. }
  4338. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  4339. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  4340. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  4341. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  4342. timeLayout := "2006-01-02 15:04:05"
  4343. loc, _ := time.LoadLocation("Local")
  4344. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  4345. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  4346. weekStartPoint := theStarTime.Unix()
  4347. weekEndPoint := theEndTime.Unix()
  4348. schdules, _ := service.GetWeekScheduleThree(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
  4349. c.ServeSuccessJSON(map[string]interface{}{
  4350. "days": days,
  4351. "weekTitle": weekTitle,
  4352. "schdules": schdules,
  4353. "today": today,
  4354. })
  4355. return
  4356. }
  4357. func (c *ScheduleApiController) GetScheduleThreeList() {
  4358. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  4359. patitionIdStr := c.GetString("patitionid")
  4360. ids := strings.Split(patitionIdStr, ",")
  4361. schedule_type, _ := c.GetInt64("schedule_type")
  4362. adminInfo := c.GetAdminUserInfo()
  4363. weekDateStr := c.GetString("week_date")
  4364. WeekDayIds := strings.Split(weekDateStr, ",")
  4365. thisTime := time.Now()
  4366. today := thisTime.Format("2006-01-02")
  4367. if week < 1 || week > 4 {
  4368. week = 2
  4369. }
  4370. if week == 1 {
  4371. thisTime = thisTime.AddDate(0, 0, -7)
  4372. } else if week == 3 {
  4373. thisTime = thisTime.AddDate(0, 0, 7)
  4374. } else if week == 4 {
  4375. thisTime = thisTime.AddDate(0, 0, 14)
  4376. }
  4377. weekDay := int(thisTime.Weekday())
  4378. if weekDay == 0 {
  4379. weekDay = 7
  4380. }
  4381. weekEnd := 7 - weekDay
  4382. weekStart := weekEnd - 6
  4383. weekTitle := make([]string, 0)
  4384. days := make([]string, 0)
  4385. for index := weekStart; index <= weekEnd; index++ {
  4386. theDay := thisTime.AddDate(0, 0, index)
  4387. indexYear, indexMonthTime, indexDay := theDay.Date()
  4388. indexMonth := int(indexMonthTime)
  4389. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4390. weekTitle = append(weekTitle, indexWeek)
  4391. days = append(days, theDay.Format("2006-01-02"))
  4392. }
  4393. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  4394. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  4395. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  4396. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  4397. timeLayout := "2006-01-02 15:04:05"
  4398. loc, _ := time.LoadLocation("Local")
  4399. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  4400. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  4401. weekStartPoint := theStarTime.Unix()
  4402. weekEndPoint := theEndTime.Unix()
  4403. schdules, _ := service.GetWeekScheduleFour(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
  4404. if len(schdules) > 0 {
  4405. for _, item := range schdules {
  4406. listObj, _ := service.GetNextScheduleByList(item.PatientId, item.ScheduleDate, item.UserOrgId)
  4407. item.SchedulePatientsOne = listObj
  4408. }
  4409. }
  4410. c.ServeSuccessJSON(map[string]interface{}{
  4411. "days": days,
  4412. "weekTitle": weekTitle,
  4413. "schdules": schdules,
  4414. "today": today,
  4415. })
  4416. return
  4417. }
  4418. func (c *ScheduleApiController) SaveScheduleTemplate() {
  4419. template_id, _ := c.GetInt64("template_id")
  4420. orgId := c.GetAdminUserInfo().CurrentOrgId
  4421. template := models.ScheduleTemplate{
  4422. TemplateId: template_id,
  4423. UserOrgId: orgId,
  4424. Status: 1,
  4425. Ctime: time.Now().Unix(),
  4426. }
  4427. _, errcodes := service.GetScheudleTemplateById(orgId)
  4428. if errcodes == gorm.ErrRecordNotFound {
  4429. service.CreateXtscheduleTemplate(&template)
  4430. } else if errcodes == nil {
  4431. service.UpdateXtScheduleTemplate(&template, orgId)
  4432. }
  4433. c.ServeSuccessJSON(map[string]interface{}{
  4434. "template": template,
  4435. })
  4436. return
  4437. }
  4438. func (c *ScheduleApiController) GetScheduleTemplate() {
  4439. adminUserInfo := c.GetAdminUserInfo()
  4440. orgId := adminUserInfo.CurrentOrgId
  4441. template, _ := service.GetScheduleTemplate(orgId)
  4442. c.ServeSuccessJSON(map[string]interface{}{
  4443. "template": template,
  4444. })
  4445. return
  4446. }
  4447. func (c *ScheduleApiController) ChangeFuncPrint() {
  4448. adminUserInfo := c.GetAdminUserInfo()
  4449. orgId := adminUserInfo.CurrentOrgId
  4450. is_open, _ := c.GetInt64("is_open")
  4451. dataPrint := models.XtDataPrint{
  4452. UserOrgId: orgId,
  4453. IsOpen: is_open,
  4454. Status: 1,
  4455. Ctime: time.Now().Unix(),
  4456. }
  4457. _, errcode := service.GetDataPrintByOrgId(orgId)
  4458. if errcode == gorm.ErrRecordNotFound {
  4459. service.CreateDataPrint(&dataPrint)
  4460. c.ServeSuccessJSON(map[string]interface{}{
  4461. "dataPrint": dataPrint,
  4462. })
  4463. return
  4464. } else if errcode == nil {
  4465. service.UpdteDataPrint(orgId, &dataPrint)
  4466. c.ServeSuccessJSON(map[string]interface{}{
  4467. "dataPrint": dataPrint,
  4468. })
  4469. return
  4470. }
  4471. }
  4472. func (c *ScheduleApiController) GetDataPrint() {
  4473. adminUserInfo := c.GetAdminUserInfo()
  4474. orgId := adminUserInfo.CurrentOrgId
  4475. dataPrint, _ := service.GetDataPrint(orgId)
  4476. c.ServeSuccessJSON(map[string]interface{}{
  4477. "dataPrint": dataPrint,
  4478. })
  4479. return
  4480. }
  4481. func (c *ScheduleApiController) GetNextWeekPanels() {
  4482. start_time, _ := c.GetInt64("start_time")
  4483. fmt.Println("start_time", start_time)
  4484. end_time, _ := c.GetInt64("end_time")
  4485. fmt.Println("end_time", end_time)
  4486. orgId := c.GetAdminUserInfo().CurrentOrgId
  4487. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  4488. c.ServeSuccessJSON(map[string]interface{}{
  4489. "schedule": schedule,
  4490. })
  4491. }
  4492. func (c *ScheduleApiController) SynchroSchedule() {
  4493. template_id, _ := c.GetInt64("template_id")
  4494. copy_startime, _ := c.GetInt64("copy_startime")
  4495. copy_endtime, _ := c.GetInt64("copy_endtime")
  4496. orgId := c.GetAdminUserInfo().CurrentOrgId
  4497. //根据模板ID获取模板数据
  4498. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  4499. fmt.Println(len(list))
  4500. //数据去重操作
  4501. list = RemoveRepeatedScheduleTemplate(list)
  4502. recordDateStr := time.Now().Format("2006-01-02")
  4503. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4504. nowtime := recordDate.Unix()
  4505. fmt.Println("今日时间", nowtime)
  4506. fmt.Println("后期日期", copy_startime)
  4507. var tuesday int64
  4508. var wednesday int64
  4509. var thursday int64
  4510. var friday int64
  4511. var saturday int64
  4512. //
  4513. //如果选择的开始日期大于当前日期
  4514. if copy_startime > nowtime {
  4515. //清空该时间段的所有排班数据
  4516. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  4517. tuesday = copy_startime + 86400
  4518. wednesday = copy_startime + 172800
  4519. thursday = copy_startime + 259200
  4520. friday = copy_startime + 345600
  4521. saturday = copy_startime + 432000
  4522. for _, item := range list {
  4523. if item.Weekday == 1 {
  4524. item.ScheduleDate = copy_startime
  4525. }
  4526. if item.Weekday == 2 {
  4527. item.ScheduleDate = tuesday
  4528. }
  4529. if item.Weekday == 3 {
  4530. item.ScheduleDate = wednesday
  4531. }
  4532. if item.Weekday == 4 {
  4533. item.ScheduleDate = thursday
  4534. }
  4535. if item.Weekday == 5 {
  4536. item.ScheduleDate = friday
  4537. }
  4538. if item.Weekday == 6 {
  4539. item.ScheduleDate = saturday
  4540. }
  4541. if item.Weekday == 7 {
  4542. item.ScheduleDate = copy_endtime
  4543. }
  4544. //根据床位号获取区号
  4545. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  4546. item.ZoneId = number.ZoneID
  4547. }
  4548. for _, item := range list {
  4549. schedule := models.XtSchedule{
  4550. UserOrgId: orgId,
  4551. PartitionId: item.ZoneId,
  4552. BedId: item.DeviceNumberID,
  4553. PatientId: item.PatientID,
  4554. ScheduleDate: item.ScheduleDate,
  4555. ScheduleType: item.TimeType,
  4556. ScheduleWeek: item.Weekday,
  4557. ModeId: item.TreatMode,
  4558. Status: 1,
  4559. CreatedTime: time.Now().Unix(),
  4560. UpdatedTime: 0,
  4561. IsExport: 200000,
  4562. }
  4563. var DialysisMachineName string
  4564. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  4565. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  4566. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  4567. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  4568. if filedRecordOne.IsShow == 1 {
  4569. DialysisMachineName = so.DialysisDialyszers
  4570. }
  4571. if filedRecordThree.IsShow == 1 {
  4572. if len(DialysisMachineName) > 0 {
  4573. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  4574. } else {
  4575. DialysisMachineName = so.DialyzerPerfusionApparatus
  4576. }
  4577. }
  4578. if filedRecordTwo.IsShow == 1 {
  4579. if len(DialysisMachineName) > 0 {
  4580. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  4581. } else {
  4582. DialysisMachineName = so.DialysisIrrigation
  4583. }
  4584. }
  4585. schedule.DialysisMachineName = DialysisMachineName
  4586. service.CreatePatientSchedule(&schedule)
  4587. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  4588. }
  4589. }
  4590. //如果选择的日期小于当前日期,只同步今日以后的数据
  4591. if copy_startime <= nowtime {
  4592. //清空今日以后的数据
  4593. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  4594. var tuesday int64
  4595. var wednesday int64
  4596. var thursday int64
  4597. var friday int64
  4598. var saturday int64
  4599. tuesday = copy_startime + 86400
  4600. wednesday = copy_startime + 172800
  4601. thursday = copy_startime + 259200
  4602. friday = copy_startime + 345600
  4603. saturday = copy_startime + 432000
  4604. for _, item := range list {
  4605. if item.Weekday == 1 {
  4606. item.ScheduleDate = copy_startime
  4607. }
  4608. if item.Weekday == 2 {
  4609. item.ScheduleDate = tuesday
  4610. }
  4611. if item.Weekday == 3 {
  4612. item.ScheduleDate = wednesday
  4613. }
  4614. if item.Weekday == 4 {
  4615. item.ScheduleDate = thursday
  4616. }
  4617. if item.Weekday == 5 {
  4618. item.ScheduleDate = friday
  4619. }
  4620. if item.Weekday == 6 {
  4621. item.ScheduleDate = saturday
  4622. }
  4623. if item.Weekday == 7 {
  4624. item.ScheduleDate = copy_endtime
  4625. }
  4626. //根据床位号获取区号
  4627. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  4628. item.ZoneId = number.ZoneID
  4629. }
  4630. for _, item := range list {
  4631. // 同步今日以后的数据
  4632. if item.ScheduleDate > nowtime {
  4633. schedule := models.XtSchedule{
  4634. UserOrgId: orgId,
  4635. PartitionId: item.ZoneId,
  4636. BedId: item.DeviceNumberID,
  4637. PatientId: item.PatientID,
  4638. ScheduleDate: item.ScheduleDate,
  4639. ScheduleType: item.TimeType,
  4640. ScheduleWeek: item.Weekday,
  4641. ModeId: item.TreatMode,
  4642. Status: 1,
  4643. CreatedTime: time.Now().Unix(),
  4644. UpdatedTime: 0,
  4645. }
  4646. var DialysisMachineName string
  4647. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  4648. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  4649. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  4650. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  4651. if filedRecordOne.IsShow == 1 {
  4652. DialysisMachineName = so.DialysisDialyszers
  4653. }
  4654. if filedRecordThree.IsShow == 1 {
  4655. if len(DialysisMachineName) > 0 {
  4656. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  4657. } else {
  4658. DialysisMachineName = so.DialyzerPerfusionApparatus
  4659. }
  4660. }
  4661. if filedRecordTwo.IsShow == 1 {
  4662. if len(schedule.DialysisMachineName) > 0 {
  4663. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  4664. } else {
  4665. DialysisMachineName = so.DialysisIrrigation
  4666. }
  4667. }
  4668. schedule.DialysisMachineName = DialysisMachineName
  4669. service.CreatePatientSchedule(&schedule)
  4670. }
  4671. }
  4672. }
  4673. returnData := make(map[string]interface{}, 0)
  4674. returnData["list"] = list
  4675. c.ServeSuccessJSON(returnData)
  4676. return
  4677. }
  4678. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  4679. orgId := c.GetAdminUserInfo().CurrentOrgId
  4680. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  4681. c.ServeSuccessJSON(map[string]interface{}{
  4682. "schedule": tempalate,
  4683. })
  4684. }
  4685. func (c *ScheduleApiController) GetSolutionSchedule() {
  4686. orgId := c.GetAdminUserInfo().CurrentOrgId
  4687. solution, _ := service.GetSolutionSchedule(orgId)
  4688. c.ServeSuccessJSON(map[string]interface{}{
  4689. "solution": solution,
  4690. })
  4691. return
  4692. }
  4693. func RemoveRepeatedScheduleTemplate(arr []*models.VmPatientScheduleTemplateItem) (newArr []*models.VmPatientScheduleTemplateItem) {
  4694. newArr = make([]*models.VmPatientScheduleTemplateItem, 0)
  4695. for i := 0; i < len(arr); i++ {
  4696. repeat := false
  4697. for j := i + 1; j < len(arr); j++ {
  4698. if arr[i].TemplateID == arr[j].TemplateID && arr[i].PatientID == arr[j].PatientID && arr[i].Weekday == arr[j].Weekday {
  4699. repeat = true
  4700. break
  4701. }
  4702. }
  4703. if !repeat {
  4704. newArr = append(newArr, arr[i])
  4705. }
  4706. }
  4707. return
  4708. }
  4709. func (c *ScheduleApiController) DeleteScheduleTwo() {
  4710. id, _ := c.GetInt64("id", 0)
  4711. if id <= 0 {
  4712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4713. return
  4714. }
  4715. adminINfo := c.GetAdminUserInfo()
  4716. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  4717. timeNow := time.Now().Format("2006-01-02")
  4718. timeTemplate := "2006-01-02"
  4719. tm := time.Unix(int64(schedule.ScheduleDate), 0)
  4720. timeStr := tm.Format(timeTemplate)
  4721. if timeNow > timeStr {
  4722. utils.ErrorLog(timeNow)
  4723. utils.ErrorLog(timeStr)
  4724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  4725. return
  4726. }
  4727. if schedule == nil {
  4728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  4729. return
  4730. }
  4731. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  4732. if err != nil {
  4733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4734. return
  4735. }
  4736. if order != nil {
  4737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysisTwo)
  4738. return
  4739. }
  4740. schedule.Status = 0
  4741. schedule.UpdatedTime = time.Now().Unix()
  4742. err = service.UpdateSchedule(schedule)
  4743. if err == nil {
  4744. redis := service.RedisClient()
  4745. //处方
  4746. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  4747. redis.Set(keyOne, "", time.Second)
  4748. //医嘱
  4749. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  4750. redis.Set(keyTwo, "", time.Second)
  4751. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  4752. redis.Set(keySix, "", time.Second)
  4753. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  4754. redis.Set(keyThree, "", time.Second)
  4755. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  4756. redis.Set(keyFour, "", time.Second)
  4757. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  4758. redis.Set(keyFive, "", time.Second)
  4759. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  4760. redis.Set(keySeven, "", time.Second)
  4761. defer redis.Close()
  4762. if err != nil {
  4763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  4764. return
  4765. }
  4766. c.ServeSuccessJSON(map[string]interface{}{
  4767. "msg": "ok",
  4768. "schedule": &schedule,
  4769. })
  4770. } else {
  4771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4772. return
  4773. }
  4774. }
  4775. func (c *ScheduleApiController) ChangeScheduleTen() {
  4776. id, _ := c.GetInt64("id", 0)
  4777. bed_id, _ := c.GetInt64("bed_id")
  4778. mode_id, _ := c.GetInt64("mode_id")
  4779. schedule_type, _ := c.GetInt64("schedule_type")
  4780. if id <= 0 {
  4781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4782. return
  4783. }
  4784. adminINfo := c.GetAdminUserInfo()
  4785. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  4786. //获取分区号
  4787. number, _ := service.GetZoneId(bed_id, adminINfo.CurrentOrgId)
  4788. if schedule == nil {
  4789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  4790. return
  4791. }
  4792. //如果透析模式相等 床位号相等,班次相等
  4793. if mode_id == schedule.ModeId && bed_id == schedule.BedId && schedule_type == schedule.ScheduleType && number.ZoneID == schedule.PartitionId {
  4794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorScheduleCode)
  4795. return
  4796. } else {
  4797. //如果床位未发生改变
  4798. if bed_id == schedule.BedId {
  4799. //查询该床位今天是否存在排班
  4800. sch, _ := service.GetScheduleByBedId(bed_id, schedule_type, adminINfo.CurrentOrgId, schedule.ScheduleDate)
  4801. if sch.ID == 0 {
  4802. ////删除排班
  4803. //service.UpdateScheduleByScheduleId(id)
  4804. //五四的床位
  4805. xtSchedule := models.XtSchedule{
  4806. UserOrgId: adminINfo.CurrentOrgId,
  4807. PartitionId: number.ZoneID,
  4808. BedId: bed_id,
  4809. PatientId: schedule.PatientId,
  4810. ScheduleDate: schedule.ScheduleDate,
  4811. ScheduleType: schedule_type,
  4812. ScheduleWeek: schedule.ScheduleWeek,
  4813. ModeId: mode_id,
  4814. Status: 1,
  4815. CreatedTime: time.Now().Unix(),
  4816. UpdatedTime: 0,
  4817. IsExport: 999999,
  4818. DialysisMachineName: "",
  4819. }
  4820. //service.CreateNewSchedule(xtSchedule)
  4821. service.UpdateScheduleSixTy(id, xtSchedule)
  4822. }
  4823. if schedule_type != schedule.ScheduleType && sch.ID > 0 {
  4824. //存在排班
  4825. if sch.ID > 0 {
  4826. xtSchedule := models.XtSchedule{
  4827. UserOrgId: adminINfo.CurrentOrgId,
  4828. PartitionId: number.ZoneID,
  4829. BedId: sch.BedId,
  4830. PatientId: schedule.PatientId,
  4831. ScheduleDate: sch.ScheduleDate,
  4832. ScheduleType: sch.ScheduleType,
  4833. ScheduleWeek: sch.ScheduleWeek,
  4834. ModeId: sch.ModeId,
  4835. Status: 1,
  4836. CreatedTime: time.Now().Unix(),
  4837. UpdatedTime: time.Now().Unix(),
  4838. IsExport: 8888,
  4839. DialysisMachineName: "",
  4840. }
  4841. fmt.Println("汪涵我我我哦", id)
  4842. //赵云的ID
  4843. // 该床位存在的患者
  4844. service.UpdateScheduleSixTy(id, xtSchedule)
  4845. //赵云的排班
  4846. msch := models.XtSchedule{
  4847. UserOrgId: adminINfo.CurrentOrgId,
  4848. PartitionId: schedule.PartitionId,
  4849. BedId: schedule.BedId,
  4850. PatientId: sch.PatientId,
  4851. ScheduleDate: schedule.ScheduleDate,
  4852. ScheduleType: schedule.ScheduleType,
  4853. ScheduleWeek: schedule.ScheduleWeek,
  4854. ModeId: schedule.ModeId,
  4855. IsExport: 88888,
  4856. CreatedTime: time.Now().Unix(),
  4857. UpdatedTime: time.Now().Unix(),
  4858. }
  4859. // 历史床位的患者
  4860. service.UpdateScheduleSixTy(sch.ID, msch)
  4861. }
  4862. }
  4863. }
  4864. //如果床位发生改变
  4865. if bed_id != schedule.BedId {
  4866. //查询该床位今天是否存在排班
  4867. sch, _ := service.GetScheduleByBedId(bed_id, schedule_type, adminINfo.CurrentOrgId, schedule.ScheduleDate)
  4868. if sch.ID == 0 {
  4869. ////删除排班
  4870. //service.UpdateScheduleByScheduleId(id)
  4871. //五四的床位
  4872. xtSchedule := models.XtSchedule{
  4873. UserOrgId: adminINfo.CurrentOrgId,
  4874. PartitionId: number.ZoneID,
  4875. BedId: bed_id,
  4876. PatientId: schedule.PatientId,
  4877. ScheduleDate: schedule.ScheduleDate,
  4878. ScheduleType: schedule_type,
  4879. ScheduleWeek: schedule.ScheduleWeek,
  4880. ModeId: mode_id,
  4881. Status: 1,
  4882. CreatedTime: time.Now().Unix(),
  4883. UpdatedTime: 0,
  4884. IsExport: 999999,
  4885. DialysisMachineName: "",
  4886. }
  4887. //service.CreateNewSchedule(xtSchedule)
  4888. service.UpdateScheduleSixTy(id, xtSchedule)
  4889. }
  4890. //存在排班
  4891. if sch.ID > 0 {
  4892. xtSchedule := models.XtSchedule{
  4893. UserOrgId: adminINfo.CurrentOrgId,
  4894. PartitionId: number.ZoneID,
  4895. BedId: sch.BedId,
  4896. PatientId: schedule.PatientId,
  4897. ScheduleDate: sch.ScheduleDate,
  4898. ScheduleType: sch.ScheduleType,
  4899. ScheduleWeek: sch.ScheduleWeek,
  4900. ModeId: sch.ModeId,
  4901. Status: 1,
  4902. CreatedTime: time.Now().Unix(),
  4903. UpdatedTime: time.Now().Unix(),
  4904. IsExport: 8888,
  4905. DialysisMachineName: "",
  4906. }
  4907. //赵云的ID
  4908. // 该床位存在的患者
  4909. service.UpdateScheduleSixTy(id, xtSchedule)
  4910. //赵云的排班
  4911. msch := models.XtSchedule{
  4912. UserOrgId: adminINfo.CurrentOrgId,
  4913. PartitionId: schedule.PartitionId,
  4914. BedId: schedule.BedId,
  4915. PatientId: sch.PatientId,
  4916. ScheduleDate: schedule.ScheduleDate,
  4917. ScheduleType: schedule.ScheduleType,
  4918. ScheduleWeek: schedule.ScheduleWeek,
  4919. ModeId: schedule.ModeId,
  4920. IsExport: 88888,
  4921. CreatedTime: time.Now().Unix(),
  4922. UpdatedTime: time.Now().Unix(),
  4923. }
  4924. // 历史床位的患者
  4925. service.UpdateScheduleSixTy(sch.ID, msch)
  4926. }
  4927. }
  4928. }
  4929. //去除当天患者排班中重复数据,保留最后一条数据
  4930. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  4931. scheduletwo, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  4932. c.ServeSuccessJSON(map[string]interface{}{
  4933. "msg": "ok",
  4934. "schedule": scheduletwo,
  4935. })
  4936. }
  4937. func (c *ScheduleApiController) GetNumberListById() {
  4938. id, _ := c.GetInt64("id")
  4939. orgId := c.GetAdminUserInfo().CurrentOrgId
  4940. number, _ := service.GetNumberListById(id, orgId)
  4941. c.ServeSuccessJSON(map[string]interface{}{
  4942. "number": number,
  4943. })
  4944. }