schedule_api_controller.go 156KB

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