schedule_api_controller.go 164KB

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