schedule_api_controller.go 168KB

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