schedule_api_controller.go 179KB

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