schedule_api_controller.go 183KB

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