schedule_api_controller.go 146KB

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