schedule_api_controller.go 162KB

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