schedule_api_controller.go 167KB

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