schedule_api_controller.go 172KB

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