dialysis_api_controller.go 276KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/astaxie/beego"
  6. "github.com/jinzhu/gorm"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "XT_New/enums"
  12. "XT_New/models"
  13. "XT_New/service"
  14. "XT_New/utils"
  15. "math"
  16. )
  17. // type DialysisTestAPIController struct {
  18. // MobileBaseAPIController
  19. // }
  20. // [get]/m/api/test
  21. // func (this *DialysisTestAPIController) Test() {
  22. // orgID := int64(3907)
  23. // now := time.Now()
  24. // nextWeek := now.AddDate(0, 0, 7)
  25. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  26. // nextTwoWeek := now.AddDate(0, 0, 14)
  27. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  28. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  29. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  30. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  31. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  32. // return
  33. // }
  34. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  35. // if exchangeErr != nil {
  36. // this.ErrorLog("%v", exchangeErr)
  37. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  38. // return
  39. // }
  40. // this.ServeSuccessJSON(map[string]interface{}{
  41. // // "now": now,
  42. // // "next_week": nextWeek,f
  43. // // "next_week_mon": nextWeekMon,
  44. // // "next_week_sun": nextWeekSun,
  45. // // "next_two_week_mon": nextTwoWeekMon,
  46. // // "next_two_week_sun": nextTwoWeekSun,
  47. // "next_week_schs": nextWeekSchs,
  48. // "next_two_week_schs": nextTwoWeekSchs,
  49. // })
  50. // }
  51. type DialysisAPIController struct {
  52. MobileBaseAPIAuthController
  53. }
  54. // /m/api/scheduals [get]
  55. // @param type:int
  56. // @param date:string
  57. func (this *DialysisAPIController) Scheduals() {
  58. schedualType, _ := this.GetInt64("type")
  59. schedualDate := this.GetString("date")
  60. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  61. schedualType = 0
  62. }
  63. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  64. if parseDateErr != nil {
  65. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  66. return
  67. }
  68. adminInfo := this.GetMobileAdminUserInfo()
  69. orgID := adminInfo.Org.Id
  70. redis := service.RedisClient()
  71. defer redis.Close()
  72. // cur_date := time.Now().Format("2006-01-02")
  73. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  74. scheduals_json_str, _ := redis.Get(key).Result()
  75. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  76. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  77. if err != nil {
  78. this.ErrorLog("获取排班信息失败:%v", err)
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  80. } else {
  81. if len(scheduals) > 0 {
  82. //缓存数据
  83. scheduals_json, err := json.Marshal(scheduals)
  84. if err == nil {
  85. redis.Set(key, scheduals_json, time.Minute*1)
  86. }
  87. }
  88. this.ServeSuccessJSON(map[string]interface{}{
  89. "scheduals": scheduals,
  90. })
  91. }
  92. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  93. var dat []map[string]interface{}
  94. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  95. } else {
  96. }
  97. this.ServeSuccessJSON(map[string]interface{}{
  98. "scheduals": dat,
  99. "redis": "true",
  100. "date": schedualDate,
  101. })
  102. }
  103. }
  104. // /m/api/waiting_scheduals [get]
  105. // @param date:string
  106. func (this *DialysisAPIController) WaitingScheduals() {
  107. schedualDate := this.GetString("date")
  108. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  109. if parseDateErr != nil && len(schedualDate) != 0 {
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. return
  112. }
  113. adminInfo := this.GetMobileAdminUserInfo()
  114. orgID := adminInfo.Org.Id
  115. redis := service.RedisClient()
  116. defer redis.Close()
  117. // cur_date := time.Now().Format("2006-01-02")
  118. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  119. wait_scheduals, _ := redis.Get(key).Result()
  120. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  121. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  122. if err != nil {
  123. this.ErrorLog("获取排班信息失败:%v", err)
  124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. } else {
  126. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  127. for _, s := range scheduals {
  128. returnScheduals = append(returnScheduals, s)
  129. }
  130. if len(returnScheduals) > 0 {
  131. //缓存数据
  132. wait_scheduals_json, err := json.Marshal(scheduals)
  133. if err == nil {
  134. redis.Set(key, wait_scheduals_json, time.Minute*2)
  135. }
  136. }
  137. this.ServeSuccessJSON(map[string]interface{}{
  138. "scheduals": scheduals,
  139. })
  140. }
  141. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  142. var dat []map[string]interface{}
  143. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  144. } else {
  145. }
  146. this.ServeSuccessJSON(map[string]interface{}{
  147. "scheduals": dat,
  148. "redis": "true",
  149. "date": schedualDate,
  150. })
  151. }
  152. }
  153. //else{
  154. // fmt.Println("33333333")
  155. //
  156. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  157. // if err != nil {
  158. // this.ErrorLog("获取排班信息失败:%v", err)
  159. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  160. // } else {
  161. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  162. // for _, s := range scheduals {
  163. //
  164. // returnScheduals = append(returnScheduals, s)
  165. // }
  166. //
  167. // this.ServeSuccessJSON(map[string]interface{}{
  168. // "scheduals": returnScheduals,
  169. // })
  170. // }
  171. //
  172. // }
  173. //if err == nil{
  174. //
  175. //
  176. //
  177. //
  178. //
  179. //}else{
  180. //}
  181. // /m/api/dialysis/record [get]
  182. // @param patient_id:int
  183. // @param date:string (yyyy-MM-dd)
  184. func (this *DialysisAPIController) DialysisRecord() {
  185. patientID, _ := this.GetInt64("patient_id")
  186. recordDateStr := this.GetString("date")
  187. if patientID <= 0 {
  188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  189. return
  190. }
  191. if len(recordDateStr) == 0 {
  192. recordDateStr = time.Now().Format("2006-01-02")
  193. }
  194. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  195. if parseDateErr != nil {
  196. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. adminInfo := this.GetMobileAdminUserInfo()
  201. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  202. if getPatientErr != nil {
  203. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  205. return
  206. } else if patient == nil {
  207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  208. return
  209. }
  210. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  211. // this.TraceLog("==================================%+v", schedual)
  212. if getSchedualErr != nil {
  213. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  215. return
  216. }
  217. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  218. if getRTARErr != nil {
  219. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  221. return
  222. }
  223. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  224. if getPEErr != nil {
  225. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  227. return
  228. }
  229. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  230. if getLPEErr != nil {
  231. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. return
  234. }
  235. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  236. if getDoctorAdvicesErr != nil {
  237. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  239. return
  240. }
  241. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  242. if getDialysisOrderErr != nil {
  243. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. return
  246. }
  247. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  248. if getDoubleCheckErr != nil {
  249. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  250. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  251. return
  252. }
  253. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  254. if getMonitorRecordsErr != nil {
  255. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  257. return
  258. }
  259. var lastMonitorRecord *models.MonitoringRecord
  260. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  261. if getLastErr != nil {
  262. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  264. return
  265. }
  266. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  267. if getAADErr != nil {
  268. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  270. return
  271. }
  272. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  273. if getLAADErr != nil {
  274. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  276. return
  277. }
  278. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  279. if getTreatmentSummaryErr != nil {
  280. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  282. return
  283. }
  284. dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  285. //if getDialysisPrescribeErr != nil {
  286. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  287. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  288. // return
  289. //}
  290. dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  291. //if getDialysisSolutionErr != nil {
  292. // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  293. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  294. // return
  295. //}
  296. lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  297. //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
  298. //if getDialysisPrescribeErr != nil {
  299. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  300. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  301. // return
  302. //}
  303. //获取系统透析处方模版
  304. systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  305. //if getSystemDialysisPrescribeErr != nil {
  306. // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  307. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  308. // return
  309. //}
  310. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
  311. //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
  312. if getLPEErr != nil {
  313. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  315. return
  316. }
  317. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  318. if getDryErr != nil {
  319. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  321. return
  322. }
  323. //headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
  324. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  325. goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
  326. goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
  327. operators, err := service.GetAllStarfEs(adminInfo.Org.Id)
  328. fmt.Println("报错", err)
  329. returnData := map[string]interface{}{
  330. "patient": patient,
  331. "schedual": schedual,
  332. "prescription": dialysisPrescribe,
  333. "solution": dialysisSolution,
  334. "last_prescription": lastDialysisPrescribe,
  335. "receiver_treatment_access": receiverTreatmentAccess,
  336. "predialysis_evaluation": predialysisEvaluation,
  337. "doctor_advices": doctorAdvices,
  338. "double_check": doubleCheck,
  339. "assessment_after_dislysis": assessmentAfterDislysis,
  340. "treatment_summary": treatmentSummary,
  341. "monitor_records": monitorRecords,
  342. "dialysis_order": dialysisOrder,
  343. "operators": operators,
  344. "last_predialysis_evaluation": lastPredialysisEvaluation,
  345. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  346. "last_monitor_record": lastMonitorRecord,
  347. //"special_premission": headNurses,
  348. "config": gobalConfig,
  349. "types": goodTypes,
  350. "goodInfos": goodInfos,
  351. "dry_weight": lastDryWeightDislysis,
  352. "system_prescription": systemDialysisPrescribe,
  353. }
  354. this.ServeSuccessJSON(returnData)
  355. }
  356. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  357. adminInfo := c.GetMobileAdminUserInfo()
  358. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  359. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  360. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  361. returnData := map[string]interface{}{
  362. "admin_users": adminUsers,
  363. "devices": devices,
  364. "device_numbers": device_numbers,
  365. }
  366. c.ServeSuccessJSON(returnData)
  367. }
  368. func (c *DialysisAPIController) PostAtreatmentInfo() {
  369. id, _ := c.GetInt64("patient", 0)
  370. recordDateStr := c.GetString("record_date")
  371. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  372. summaryContent := c.GetString("summaryContent")
  373. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  374. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  375. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  376. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  377. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  378. nursingRecord := c.GetString("nursing_record")
  379. fmt.Println("护理记录", nursingRecord)
  380. specialRecord := c.GetString("special_record")
  381. fmt.Println("特殊记录", specialRecord)
  382. adminUserInfo := c.GetMobileAdminUserInfo()
  383. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  384. checkStaffId = adminUserInfo.AdminUser.Id
  385. deboardNurseId = adminUserInfo.AdminUser.Id
  386. treatDoctor = adminUserInfo.AdminUser.Id
  387. if id <= 0 {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  389. return
  390. }
  391. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  392. if patient.ID == 0 {
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  394. return
  395. }
  396. if len(recordDateStr) == 0 {
  397. recordDateStr = time.Now().Format("2006-01-02")
  398. }
  399. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  400. if parseDateErr != nil {
  401. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  403. return
  404. }
  405. //now := time.Now()
  406. //year, month, day := now.Date()
  407. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  408. //todayTimeStamp := today_time.Unix()
  409. summary := models.TreatmentSummary{
  410. UserOrgId: adminUserInfo.Org.Id,
  411. PatientId: id,
  412. AssessmentDate: recordDate.Unix(),
  413. Mission: propagandaAndEducationContent,
  414. DialysisSummary: summaryContent,
  415. SjNurse: changeMedicalNurseId,
  416. ZlNurse: treatNurseId,
  417. HdNurse: checkStaffId,
  418. XjNurse: deboardNurseId,
  419. ZlDoctor: treatDoctor,
  420. CreatedTime: time.Now().Unix(),
  421. Status: 1,
  422. NursingRecord: nursingRecord,
  423. SpecialRecord: specialRecord,
  424. }
  425. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  426. if treatmentSummary.ID == 0 { //新增
  427. summary.Creater = adminUserInfo.AdminUser.Id
  428. service.AddSigleSummaryRecord(&summary)
  429. c.ServeSuccessJSON(map[string]interface{}{
  430. "summary": summary,
  431. })
  432. } else { //修改
  433. //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  434. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  435. // if getPermissionErr != nil {
  436. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  437. // return
  438. // } else if headNursePermission == nil {
  439. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  440. // return
  441. // }
  442. //}
  443. summary.Creater = treatmentSummary.Creater
  444. summary.CreatedTime = treatmentSummary.CreatedTime
  445. summary.Modifier = adminUserInfo.AdminUser.Id
  446. summary.ID = treatmentSummary.ID
  447. service.UpdateSummeRecord(&summary)
  448. c.ServeSuccessJSON(map[string]interface{}{
  449. "summary": summary,
  450. })
  451. }
  452. }
  453. func (c *DialysisAPIController) PostDoubleCheck() {
  454. id, _ := c.GetInt64("patient", 0)
  455. recordDateStr := c.GetString("record_date")
  456. checkTimeStr := c.GetString("check_time")
  457. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  458. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  459. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  460. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  461. dialysis_item_desc := c.GetString("dialysis_item_desc")
  462. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  463. vascular_access_desc := c.GetString("vascular_access_desc")
  464. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  465. collator, _ := c.GetInt64("collator", 0)
  466. if id <= 0 {
  467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  468. return
  469. }
  470. adminUserInfo := c.GetMobileAdminUserInfo()
  471. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  472. if patient.ID == 0 {
  473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  474. return
  475. }
  476. if len(recordDateStr) == 0 {
  477. recordDateStr = time.Now().Format("2006-01-02")
  478. }
  479. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  480. if parseDateErr != nil {
  481. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  483. return
  484. }
  485. if len(checkTimeStr) == 0 {
  486. checkTimeStr = time.Now().Format("2006-01-02 15:04:05")
  487. }
  488. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  489. //now := time.Now()
  490. //year, month, day := now.Date()
  491. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  492. //todayTimeStamp := today_time.Unix()
  493. doubleCheck := models.DoubleCheck{
  494. UserOrgId: adminUserInfo.Org.Id,
  495. PatientId: id,
  496. DialysisItemCheck: dialysis_item_check,
  497. DialysisParameterCheck: dialysis_parameter_check,
  498. VascularAccessVerification: vascular_access_verification,
  499. PipelineConnectionCheck: pipeline_connection_check,
  500. DialysisItemDesc: dialysis_item_desc,
  501. DialysisParameterDesc: dialysis_parameter_desc,
  502. VascularAccessDesc: vascular_access_desc,
  503. PipelineConnectionDesc: pipeline_connection_desc,
  504. Collator: collator,
  505. Status: 1,
  506. CreatedTime: time.Now().Unix(),
  507. UpdatedTime: time.Now().Unix(),
  508. CheckDate: recordDate.Unix(),
  509. }
  510. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  511. if check.ID == 0 { //新增
  512. doubleCheck.FirstCheckTime = checkDate.Unix()
  513. doubleCheck.Creater = adminUserInfo.AdminUser.Id
  514. err := service.AddSigleDoubleCheck(&doubleCheck)
  515. if err == nil {
  516. c.ServeSuccessJSON(map[string]interface{}{
  517. "doubleCheck": &doubleCheck,
  518. })
  519. }
  520. } else { //修改
  521. if check.Modifier != 0 {
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckWrong)
  523. } else {
  524. if adminUserInfo.AdminUser.Id == check.Creater {
  525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckUserWrong)
  526. return
  527. }
  528. doubleCheck.FirstCheckTime = check.FirstCheckTime
  529. doubleCheck.CheckTime = checkDate.Unix()
  530. doubleCheck.Creater = check.Creater
  531. doubleCheck.CreatedTime = check.CreatedTime
  532. doubleCheck.Modifier = adminUserInfo.AdminUser.Id
  533. doubleCheck.ID = check.ID
  534. err := service.UpdateDoubleCheck(&doubleCheck)
  535. if err == nil {
  536. c.ServeSuccessJSON(map[string]interface{}{
  537. "doubleCheck": &doubleCheck,
  538. })
  539. }
  540. }
  541. }
  542. }
  543. func (c *DialysisAPIController) PostAcceptsAssessment() {
  544. id, _ := c.GetInt64("patient", 0)
  545. recordDateStr := c.GetString("record_date")
  546. way, _ := c.GetInt64("way", 0)
  547. consciousness, _ := c.GetInt64("consciousness", 0)
  548. appetite, _ := c.GetInt64("appetite", 0)
  549. condition, _ := c.GetInt64("condition", 0)
  550. posture, _ := c.GetInt64("posture")
  551. sick_condition, _ := c.GetInt64("sick_condition", 0)
  552. danger_level, _ := c.GetInt64("danger_level", 0)
  553. intake, _ := c.GetInt64("intake", 0)
  554. nutrition, _ := c.GetInt64("nutrition", 0)
  555. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  556. psychological_assessment_other := c.GetString("psychological_assessment_other")
  557. score := c.GetString("score")
  558. sick_condition_other := c.GetString("sick_condition_other")
  559. //precaution, _ := c.GetInt64("precaution", 0)
  560. precaution := c.GetString("precaution")
  561. precaution_other := c.GetString("precaution_other")
  562. psychological_other := c.GetString("psychological_other")
  563. admission_number := c.GetString("admission_number")
  564. if id <= 0 {
  565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  566. return
  567. }
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  570. if patient.ID == 0 {
  571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  572. return
  573. }
  574. //now := time.Now()
  575. //year, month, day := now.Date()
  576. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  577. //todayTimeStamp := today_time.Unix()
  578. if len(recordDateStr) == 0 {
  579. recordDateStr = time.Now().Format("2006-01-02")
  580. }
  581. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  582. if parseDateErr != nil {
  583. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  585. return
  586. }
  587. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  588. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  589. UserOrgId: adminUserInfo.Org.Id,
  590. PatientId: id,
  591. RecordDate: recordDate.Unix(),
  592. Way: way,
  593. Consciousness: consciousness,
  594. Appetite: appetite,
  595. Condition: condition,
  596. SickCondition: sick_condition,
  597. DangerLevel: danger_level,
  598. Intake: intake,
  599. Nutrition: nutrition,
  600. PsychologicalAssessment: psychological_assessment,
  601. PsychologicalAssessmentOther: psychological_assessment_other,
  602. SickConditionOther: sick_condition_other,
  603. Posture: posture,
  604. CreatedTime: time.Now().Unix(),
  605. UpdateTime: time.Now().Unix(),
  606. Status: 1,
  607. Score: score,
  608. Precaution: precaution,
  609. PrecautionOther: precaution_other,
  610. PsychologicalOther: psychological_other,
  611. AdmissionNumber: admission_number,
  612. }
  613. if receiveTreatment.ID == 0 { //新增
  614. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  615. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  616. if err == nil {
  617. c.ServeSuccessJSON(map[string]interface{}{
  618. "receiveTreatmentAsses": receiveTreatmentAsses,
  619. })
  620. }
  621. } else { //修改
  622. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  623. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  624. // if getPermissionErr != nil {
  625. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  626. // return
  627. // } else if headNursePermission == nil {
  628. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  629. // return
  630. // }
  631. //}
  632. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  633. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  634. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  635. receiveTreatmentAsses.ID = receiveTreatment.ID
  636. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  637. if err == nil {
  638. c.ServeSuccessJSON(map[string]interface{}{
  639. "receiveTreatmentAsses": receiveTreatmentAsses,
  640. })
  641. }
  642. }
  643. }
  644. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  645. id, _ := c.GetInt64("patient", 0)
  646. recordDateStr := c.GetString("record_date")
  647. weightAfter, _ := c.GetFloat("weight_after", 0)
  648. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  649. weightReduce, _ := c.GetFloat("weight_loss", 0)
  650. temperature, _ := c.GetFloat("temperature", 0)
  651. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  652. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  653. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  654. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  655. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  656. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  657. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  658. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  659. cruor := c.GetString("cruor")
  660. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  661. internalFistula := c.GetString("internal_fistula")
  662. catheter := c.GetString("catheter")
  663. complications := c.GetString("complication")
  664. remark := c.GetString("remark")
  665. dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  666. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  667. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  668. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  669. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  670. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  671. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  672. patientGose, _ := c.GetInt64("patient_gose", 0)
  673. inpatientDepartment := c.GetString("inpatient_department")
  674. observationContent := c.GetString("observation_content")
  675. observationContentOther := c.GetString("observation_content_other")
  676. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  677. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  678. in_advance_reason := c.GetString("in_advance_reason")
  679. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  680. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  681. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  682. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  683. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  684. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  685. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  686. dialyzer, _ := c.GetInt64("dialyzer", 0)
  687. in_advance_reason_other := c.GetString("in_advance_reason_other")
  688. is_eat, _ := c.GetInt64("is_eat", 0)
  689. cvc_a, _ := c.GetFloat("cvc_a", 0)
  690. cvc_v, _ := c.GetFloat("cvc_v", 0)
  691. channels, _ := c.GetInt64("channel", 0)
  692. return_blood, _ := c.GetInt64("return_blood", 0)
  693. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  694. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  695. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  696. blood_flow, _ := c.GetInt64("blood_flow", 0)
  697. sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  698. sealing_fluid_special := c.GetString("sealing_fluid_special")
  699. if id <= 0 {
  700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. adminUserInfo := c.GetMobileAdminUserInfo()
  704. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  705. if patient.ID == 0 {
  706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  707. return
  708. }
  709. if len(recordDateStr) == 0 {
  710. recordDateStr = time.Now().Format("2006-01-02")
  711. }
  712. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  713. if parseDateErr != nil {
  714. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  716. return
  717. }
  718. //now := time.Now()
  719. //year, month, day := now.Date()
  720. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  721. //todayTimeStamp := today_time.Unix()
  722. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  723. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  724. UserOrgId: adminUserInfo.Org.Id,
  725. PatientId: id,
  726. AssessmentDate: recordDate.Unix(),
  727. Temperature: temperature,
  728. PulseFrequency: pulse_frequency,
  729. BreathingRate: breathing_rate,
  730. SystolicBloodPressure: systolic_blood_pressure,
  731. DiastolicBloodPressure: diastolic_blood_pressure,
  732. ActualUltrafiltration: actual_ultrafiltration,
  733. ActualDisplacement: actual_displacement,
  734. ActualTreatmentHour: actualtreatHour,
  735. ActualTreatmentMinute: actualtreatmin,
  736. WeightAfter: weightAfter,
  737. AdditionalWeight: additionalWeight,
  738. WeightLoss: weightReduce,
  739. Cruor: cruor,
  740. SymptomAfterDialysis: symptomsAfterDialysi,
  741. InternalFistula: internalFistula,
  742. Catheter: catheter,
  743. Complication: complications,
  744. DialysisIntakes: dialysateVolume,
  745. CreatedTime: time.Now().Unix(),
  746. Status: 1,
  747. Remark: remark,
  748. BloodAccessPartId: blood_access_part_id,
  749. BloodAccessPartOperaId: blood_access_part_opera_id,
  750. DialysisIntakesUnit: dialysis_intakes_unit,
  751. PuncturePointOozingBlood: puncturePointOozingBlood,
  752. PuncturePointHaematoma: puncturePointHaematoma,
  753. InternalFistulaTremorAc: internalFistulaTremorAc,
  754. PatientGose: patientGose,
  755. InpatientDepartment: inpatientDepartment,
  756. ObservationContent: observationContent,
  757. ObservationContentOther: observationContentOther,
  758. DialysisProcess: dialysis_process,
  759. InAdvanceMinute: in_advance_minute,
  760. InAdvanceReason: in_advance_reason,
  761. HemostasisMinute: hemostasis_minute,
  762. HemostasisOpera: hemostasis_opera,
  763. TremorNoise: tremor_noise,
  764. DisequilibriumSyndrome: disequilibrium_syndrome,
  765. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  766. ArterialTube: arterial_tube,
  767. IntravenousTube: intravenous_tube,
  768. Dialyzer: dialyzer,
  769. InAdvanceReasonOther: in_advance_reason_other,
  770. IsEat: is_eat,
  771. CvcA: cvc_a,
  772. CvcV: cvc_v,
  773. Channel: channels,
  774. ReturnBlood: return_blood,
  775. RehydrationVolume: rehydration_volume,
  776. DialysisDuring: dialysis_during,
  777. StrokeVolume: stroke_volume,
  778. BloodFlow: blood_flow,
  779. SealingFluidDispose: sealing_fluid_dispose,
  780. SealingFluidSpecial: sealing_fluid_special,
  781. }
  782. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  783. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  784. if assessmentAfter.ID == 0 { //新增
  785. if appRole.UserType == 2 || appRole.UserType == 1 {
  786. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  787. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  788. } else {
  789. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  790. }
  791. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  792. if err == nil {
  793. c.ServeSuccessJSON(map[string]interface{}{
  794. "assessmentAfterDislysis": assessmentAfterDislysis,
  795. })
  796. }
  797. } else { //修改
  798. if appRole.UserType == 2 || appRole.UserType == 1 {
  799. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  800. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  801. } else {
  802. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  803. if assessmentAfterDislysis.Creater == 0 {
  804. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  805. }
  806. }
  807. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  808. assessmentAfterDislysis.ID = assessmentAfter.ID
  809. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  810. if err == nil {
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "assessmentAfterDislysis": assessmentAfterDislysis,
  813. })
  814. }
  815. }
  816. }
  817. func (c *DialysisAPIController) PostDialysisPrescription() {
  818. id, _ := c.GetInt64("patient", 0)
  819. recordDateStr := c.GetString("record_date")
  820. if id <= 0 {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. adminUserInfo := c.GetMobileAdminUserInfo()
  825. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  826. if patient.ID == 0 {
  827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  828. return
  829. }
  830. if len(recordDateStr) == 0 {
  831. recordDateStr = time.Now().Format("2006-01-02")
  832. }
  833. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  834. if parseDateErr != nil {
  835. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  837. return
  838. }
  839. mode_id, _ := c.GetInt64("mode_id", 0)
  840. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  841. dialyzer, _ := c.GetInt64("dialyzer", 0)
  842. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  843. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  844. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  845. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  846. replacement_total, _ := c.GetFloat("replacement_total", 0)
  847. replacement_way, _ := c.GetInt64("replacement_way", 0)
  848. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  849. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  850. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  851. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  852. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  853. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  854. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  855. kalium, _ := c.GetFloat("kalium", 0)
  856. sodium, _ := c.GetFloat("sodium", 0)
  857. calcium, _ := c.GetFloat("calcium", 0)
  858. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  859. glucose, _ := c.GetFloat("glucose", 0)
  860. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  861. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  862. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  863. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  864. conductivity, _ := c.GetFloat("conductivity", 0)
  865. remark := c.GetString("remark")
  866. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  867. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  868. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  869. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  870. body_fluid, _ := c.GetInt64("body_fluid", 0)
  871. special_medicine, _ := c.GetInt64("special_medicine", 0)
  872. special_medicine_other := c.GetString("special_medicine_other")
  873. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  874. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  875. blood_access, _ := c.GetInt64("blood_access", 0)
  876. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  877. body_fluid_other := c.GetString("body_fluid_other")
  878. niprocart, _ := c.GetInt64("niprocart", 0)
  879. jms, _ := c.GetInt64("jms", 0)
  880. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  881. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  882. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  883. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  884. filtryzer, _ := c.GetInt64("filtryzer", 0)
  885. target_ktv, _ := c.GetFloat("target_ktv", 0)
  886. dialyzers, _ := c.GetInt64("dialyzers", 0)
  887. injector, _ := c.GetInt64("injector", 0)
  888. bloodlines, _ := c.GetInt64("bloodlines", 0)
  889. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  890. safe_package, _ := c.GetInt64("package", 0)
  891. a_liquid, _ := c.GetInt64("a_liquid", 0)
  892. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  893. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  894. //
  895. //if template.TemplateId == 2 || template.TemplateId == 6 {
  896. // if appRole.UserType == 3 {
  897. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  898. // if getPermissionErr != nil {
  899. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  900. // return
  901. // } else if headNursePermission == nil {
  902. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  903. // return
  904. // }
  905. // }
  906. //}
  907. //TODO 需要根据角色去判断
  908. prescription := models.DialysisPrescription{
  909. UserOrgId: adminUserInfo.Org.Id,
  910. PatientId: id,
  911. RecordDate: recordDate.Unix(),
  912. ModeId: mode_id,
  913. DialysisDuration: dialysis_duration,
  914. Dialyzer: dialyzer,
  915. PerfusionApparatus: perfusion_apparatus,
  916. BloodFlowVolume: blood_flow_volume,
  917. DewaterAmount: dewater_amount,
  918. DisplaceLiqui: displace_liqui,
  919. ReplacementWay: replacement_way,
  920. Anticoagulant: anticoagulant,
  921. AnticoagulantShouji: anticoagulant_shouji,
  922. AnticoagulantWeichi: anticoagulant_weichi,
  923. AnticoagulantZongliang: anticoagulant_zongliang,
  924. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  925. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  926. Kalium: kalium,
  927. Sodium: sodium,
  928. Calcium: calcium,
  929. Bicarbonate: bicarbonate,
  930. Glucose: glucose,
  931. // DryWeight: dry_weight,
  932. DialysateFlow: dialysate_flow,
  933. DialysateTemperature: dialysate_temperature,
  934. // PrescriptionDoctor: prescription_doctor,
  935. ReplacementTotal: replacement_total,
  936. Conductivity: conductivity,
  937. Remark: remark,
  938. Status: 1,
  939. CreatedTime: time.Now().Unix(),
  940. UpdatedTime: time.Now().Unix(),
  941. DialysisDurationMinute: dialysisDurationMinute,
  942. DialysisDurationHour: dialysisDurationHour,
  943. TargetUltrafiltration: targetUltrafiltration,
  944. DialysateFormulation: dialysateFormulation,
  945. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  946. BodyFluid: body_fluid,
  947. SpecialMedicine: special_medicine,
  948. SpecialMedicineOther: special_medicine_other,
  949. DisplaceLiquiPart: displace_liqui_part,
  950. DisplaceLiquiValue: displace_liqui_value,
  951. BloodAccess: blood_access,
  952. Ultrafiltration: ultrafiltration,
  953. BodyFluidOther: body_fluid_other,
  954. Niprocart: niprocart,
  955. Jms: jms,
  956. FistulaNeedleSet: fistula_needle_set,
  957. FistulaNeedleSet16: fistula_needle_set_16,
  958. Hemoperfusion: hemoperfusion,
  959. DialyserSterilised: dialyser_sterilised,
  960. Filtryzer: filtryzer,
  961. Dialyzers: dialyzers,
  962. Injector: injector,
  963. Bloodlines: bloodlines,
  964. TubingHemodialysis: tubing_hemodialysis,
  965. Package: safe_package,
  966. ALiquid: a_liquid,
  967. TargetKtv: target_ktv,
  968. }
  969. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  970. if dialysisPrescription.ID == 0 { //新增
  971. //if mode_id > 0 {
  972. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  973. //}
  974. if appRole.UserType == 2 || appRole.UserType == 1 {
  975. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  976. }
  977. prescription.Creater = adminUserInfo.AdminUser.Id
  978. err := service.AddSigleRecord(&prescription)
  979. if err == nil {
  980. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  981. if updateErr != nil {
  982. utils.ErrorLog("%v", updateErr)
  983. }
  984. c.ServeSuccessJSON(map[string]interface{}{
  985. "prescription": prescription,
  986. })
  987. }
  988. } else { //修改
  989. //if mode_id > 0 {
  990. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  991. //}
  992. //if template.TemplateId == 1 {
  993. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  994. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  995. // if getPermissionErr != nil {
  996. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  997. // return
  998. // } else if headNursePermission == nil {
  999. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1000. // return
  1001. // }
  1002. // }
  1003. //}
  1004. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  1005. if record.IsOpen == 1 {
  1006. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  1007. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  1008. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  1009. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  1010. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  1011. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  1012. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  1013. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  1014. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  1015. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  1016. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  1017. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  1018. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  1019. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1020. if err == nil {
  1021. if order.ID > 0 {
  1022. if dialysisPrescription.Niprocart != niprocart {
  1023. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1024. //1.用上机透析日期查出当天的订单
  1025. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1026. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1027. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1028. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1029. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1030. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1031. warehouseOutInfo := &models.WarehouseOutInfo{
  1032. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1033. WarehouseOutId: out.ID,
  1034. Count: 1,
  1035. Status: 1,
  1036. Ctime: time.Now().Unix(),
  1037. Remark: "",
  1038. OrgId: adminUserInfo.Org.Id,
  1039. Type: 1,
  1040. Manufacturer: 0,
  1041. Dealer: 0,
  1042. IsSys: 1,
  1043. SysRecordTime: order.StartTime,
  1044. }
  1045. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  1046. warehouseOutInfo.Price = stockInInfo.Price
  1047. warehouseOutInfo.GoodId = niprocart
  1048. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  1049. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1050. if err == nil {
  1051. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1052. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1053. if err == gorm.ErrRecordNotFound {
  1054. details := &models.AutomaticReduceDetail{
  1055. WarehouseOutId: warehouseOutInfo.ID,
  1056. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1057. PatientId: id,
  1058. Ctime: time.Now().Unix(),
  1059. Mtime: time.Now().Unix(),
  1060. Status: 1,
  1061. RecordTime: order.StartTime,
  1062. OrgId: adminUserInfo.Org.Id,
  1063. GoodId: niprocart,
  1064. GoodTypeId: niprocart_good_type_id,
  1065. }
  1066. service.AddSigleAutoReduceRecordInfo(details)
  1067. } else if err == nil {
  1068. if user.ID > 0 {
  1069. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  1070. }
  1071. }
  1072. }
  1073. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1074. if newOut.ID > 0 {
  1075. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1076. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1077. if err == gorm.ErrRecordNotFound {
  1078. details := &models.AutomaticReduceDetail{
  1079. WarehouseOutId: newOut.ID,
  1080. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1081. PatientId: id,
  1082. Ctime: time.Now().Unix(),
  1083. Mtime: time.Now().Unix(),
  1084. Status: 1,
  1085. RecordTime: order.StartTime,
  1086. OrgId: adminUserInfo.Org.Id,
  1087. GoodId: niprocart,
  1088. GoodTypeId: niprocart_good_type_id,
  1089. }
  1090. service.AddSigleAutoReduceRecordInfo(details)
  1091. } else if err == nil {
  1092. if user.ID > 0 {
  1093. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  1094. }
  1095. }
  1096. }
  1097. }
  1098. }
  1099. if dialysisPrescription.Jms != jms {
  1100. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1101. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1102. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1103. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1104. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  1105. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1106. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1107. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1108. warehouseOutInfo := &models.WarehouseOutInfo{
  1109. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1110. WarehouseOutId: out.ID,
  1111. Count: 1,
  1112. Status: 1,
  1113. Ctime: time.Now().Unix(),
  1114. Remark: "",
  1115. OrgId: adminUserInfo.Org.Id,
  1116. Type: 1,
  1117. Manufacturer: 0,
  1118. Dealer: 0,
  1119. IsSys: 1,
  1120. SysRecordTime: order.StartTime,
  1121. }
  1122. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  1123. warehouseOutInfo.Price = stockInInfo.Price
  1124. warehouseOutInfo.GoodId = jms
  1125. warehouseOutInfo.GoodTypeId = jms_good_type_id
  1126. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1127. if err == nil {
  1128. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1129. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1130. if err == gorm.ErrRecordNotFound {
  1131. details := &models.AutomaticReduceDetail{
  1132. WarehouseOutId: warehouseOutInfo.ID,
  1133. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1134. PatientId: id,
  1135. Ctime: time.Now().Unix(),
  1136. Mtime: time.Now().Unix(),
  1137. Status: 1,
  1138. RecordTime: order.StartTime,
  1139. OrgId: adminUserInfo.Org.Id,
  1140. GoodId: jms,
  1141. GoodTypeId: jms_good_type_id,
  1142. }
  1143. service.AddSigleAutoReduceRecordInfo(details)
  1144. } else if err == nil {
  1145. if user.ID > 0 {
  1146. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1147. }
  1148. }
  1149. }
  1150. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1151. if newOut.ID > 0 {
  1152. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1153. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1154. if err == gorm.ErrRecordNotFound {
  1155. details := &models.AutomaticReduceDetail{
  1156. WarehouseOutId: newOut.ID,
  1157. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1158. PatientId: id,
  1159. Ctime: time.Now().Unix(),
  1160. Mtime: time.Now().Unix(),
  1161. Status: 1,
  1162. RecordTime: order.StartTime,
  1163. OrgId: adminUserInfo.Org.Id,
  1164. GoodId: jms,
  1165. GoodTypeId: jms_good_type_id,
  1166. }
  1167. service.AddSigleAutoReduceRecordInfo(details)
  1168. } else if err == nil {
  1169. if user.ID > 0 {
  1170. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  1171. }
  1172. }
  1173. }
  1174. }
  1175. }
  1176. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  1177. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1178. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1179. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1180. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1181. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  1182. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1183. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1184. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1185. warehouseOutInfo := &models.WarehouseOutInfo{
  1186. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1187. WarehouseOutId: out.ID,
  1188. Count: 1,
  1189. Status: 1,
  1190. Ctime: time.Now().Unix(),
  1191. Remark: "",
  1192. OrgId: adminUserInfo.Org.Id,
  1193. Type: 1,
  1194. Manufacturer: 0,
  1195. Dealer: 0,
  1196. IsSys: 1,
  1197. SysRecordTime: order.StartTime,
  1198. }
  1199. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  1200. warehouseOutInfo.Price = stockInInfo.Price
  1201. warehouseOutInfo.GoodId = fistula_needle_set
  1202. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  1203. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1204. if err == nil {
  1205. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1206. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1207. if err == gorm.ErrRecordNotFound {
  1208. details := &models.AutomaticReduceDetail{
  1209. WarehouseOutId: warehouseOutInfo.ID,
  1210. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1211. PatientId: id,
  1212. Ctime: time.Now().Unix(),
  1213. Mtime: time.Now().Unix(),
  1214. Status: 1,
  1215. RecordTime: order.StartTime,
  1216. OrgId: adminUserInfo.Org.Id,
  1217. GoodId: fistula_needle_set,
  1218. GoodTypeId: fistula_needle_set_good_type_id,
  1219. }
  1220. service.AddSigleAutoReduceRecordInfo(details)
  1221. } else if err == nil {
  1222. if user.ID > 0 {
  1223. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1224. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1225. }
  1226. }
  1227. }
  1228. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1229. if newOut.ID > 0 {
  1230. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1231. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1232. if err == gorm.ErrRecordNotFound {
  1233. details := &models.AutomaticReduceDetail{
  1234. WarehouseOutId: newOut.ID,
  1235. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1236. PatientId: id,
  1237. Ctime: time.Now().Unix(),
  1238. Mtime: time.Now().Unix(),
  1239. Status: 1,
  1240. RecordTime: order.StartTime,
  1241. OrgId: adminUserInfo.Org.Id,
  1242. GoodId: fistula_needle_set,
  1243. GoodTypeId: fistula_needle_set_good_type_id,
  1244. }
  1245. service.AddSigleAutoReduceRecordInfo(details)
  1246. } else if err == nil {
  1247. if user.ID > 0 {
  1248. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1249. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  1256. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1257. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1258. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1259. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1260. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1261. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1262. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1263. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1264. warehouseOutInfo := &models.WarehouseOutInfo{
  1265. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1266. WarehouseOutId: out.ID,
  1267. Count: 1,
  1268. Status: 1,
  1269. Ctime: time.Now().Unix(),
  1270. Remark: "",
  1271. OrgId: adminUserInfo.Org.Id,
  1272. Type: 1,
  1273. Manufacturer: 0,
  1274. Dealer: 0,
  1275. IsSys: 1,
  1276. SysRecordTime: order.StartTime,
  1277. }
  1278. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  1279. warehouseOutInfo.Price = stockInInfo.Price
  1280. warehouseOutInfo.GoodId = fistula_needle_set_16
  1281. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  1282. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1283. if err == nil {
  1284. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1285. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1286. if err == gorm.ErrRecordNotFound {
  1287. details := &models.AutomaticReduceDetail{
  1288. WarehouseOutId: warehouseOutInfo.ID,
  1289. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1290. PatientId: id,
  1291. Ctime: time.Now().Unix(),
  1292. Mtime: time.Now().Unix(),
  1293. Status: 1,
  1294. RecordTime: order.StartTime,
  1295. OrgId: adminUserInfo.Org.Id,
  1296. GoodId: fistula_needle_set_16,
  1297. GoodTypeId: fistula_needle_set_16_good_type_id,
  1298. }
  1299. service.AddSigleAutoReduceRecordInfo(details)
  1300. } else if err == nil {
  1301. if user.ID > 0 {
  1302. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1303. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1304. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  1305. }
  1306. }
  1307. }
  1308. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1309. if newOut.ID > 0 {
  1310. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1311. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1312. if err == gorm.ErrRecordNotFound {
  1313. details := &models.AutomaticReduceDetail{
  1314. WarehouseOutId: newOut.ID,
  1315. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1316. PatientId: id,
  1317. Ctime: time.Now().Unix(),
  1318. Mtime: time.Now().Unix(),
  1319. Status: 1,
  1320. RecordTime: order.StartTime,
  1321. OrgId: adminUserInfo.Org.Id,
  1322. GoodId: fistula_needle_set_good_type_id,
  1323. GoodTypeId: fistula_needle_set_16_good_type_id,
  1324. }
  1325. service.AddSigleAutoReduceRecordInfo(details)
  1326. } else if err == nil {
  1327. if user.ID > 0 {
  1328. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  1329. }
  1330. }
  1331. }
  1332. }
  1333. }
  1334. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  1335. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1336. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1337. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1338. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1339. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  1340. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1341. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1342. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1343. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1344. warehouseOutInfo := &models.WarehouseOutInfo{
  1345. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1346. WarehouseOutId: out.ID,
  1347. Count: 1,
  1348. Status: 1,
  1349. Ctime: time.Now().Unix(),
  1350. Remark: "",
  1351. OrgId: adminUserInfo.Org.Id,
  1352. Type: 1,
  1353. Manufacturer: 0,
  1354. Dealer: 0,
  1355. IsSys: 1,
  1356. SysRecordTime: order.StartTime,
  1357. }
  1358. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  1359. warehouseOutInfo.Price = stockInInfo.Price
  1360. warehouseOutInfo.GoodId = hemoperfusion
  1361. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  1362. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1363. if err == nil {
  1364. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1365. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1366. if err == gorm.ErrRecordNotFound {
  1367. details := &models.AutomaticReduceDetail{
  1368. WarehouseOutId: warehouseOutInfo.ID,
  1369. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1370. PatientId: id,
  1371. Ctime: time.Now().Unix(),
  1372. Mtime: time.Now().Unix(),
  1373. Status: 1,
  1374. RecordTime: order.StartTime,
  1375. OrgId: adminUserInfo.Org.Id,
  1376. GoodId: hemoperfusion,
  1377. GoodTypeId: hemoperfusion_good_type_id,
  1378. }
  1379. service.AddSigleAutoReduceRecordInfo(details)
  1380. } else if err == nil {
  1381. if user.ID > 0 {
  1382. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1383. }
  1384. }
  1385. }
  1386. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1387. if newOut.ID > 0 {
  1388. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1389. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1390. if err == gorm.ErrRecordNotFound {
  1391. details := &models.AutomaticReduceDetail{
  1392. WarehouseOutId: newOut.ID,
  1393. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1394. PatientId: id,
  1395. Ctime: time.Now().Unix(),
  1396. Mtime: time.Now().Unix(),
  1397. Status: 1,
  1398. RecordTime: order.StartTime,
  1399. OrgId: adminUserInfo.Org.Id,
  1400. GoodId: hemoperfusion,
  1401. GoodTypeId: hemoperfusion_good_type_id,
  1402. }
  1403. service.AddSigleAutoReduceRecordInfo(details)
  1404. } else if err == nil {
  1405. if user.ID > 0 {
  1406. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  1407. }
  1408. }
  1409. }
  1410. }
  1411. }
  1412. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  1413. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1414. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1415. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1416. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  1417. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1418. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1419. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1420. if err == gorm.ErrRecordNotFound { //����存在,则新增出库记录,并更改使用人商品信息
  1421. warehouseOutInfo := &models.WarehouseOutInfo{
  1422. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1423. WarehouseOutId: out.WarehouseOutId,
  1424. Count: 1,
  1425. Status: 1,
  1426. Ctime: time.Now().Unix(),
  1427. Remark: "",
  1428. OrgId: adminUserInfo.Org.Id,
  1429. Type: 1,
  1430. Manufacturer: 0,
  1431. Dealer: 0,
  1432. IsSys: 1,
  1433. SysRecordTime: order.StartTime,
  1434. }
  1435. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  1436. warehouseOutInfo.Price = stockInInfo.Price
  1437. warehouseOutInfo.GoodId = dialyser_sterilised
  1438. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  1439. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1440. if err == nil {
  1441. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1442. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1443. if err == gorm.ErrRecordNotFound {
  1444. details := &models.AutomaticReduceDetail{
  1445. WarehouseOutId: warehouseOutInfo.ID,
  1446. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1447. PatientId: id,
  1448. Ctime: time.Now().Unix(),
  1449. Mtime: time.Now().Unix(),
  1450. Status: 1,
  1451. RecordTime: order.StartTime,
  1452. OrgId: adminUserInfo.Org.Id,
  1453. GoodId: dialyser_sterilised,
  1454. GoodTypeId: dialyser_sterilised_good_type_id,
  1455. }
  1456. service.AddSigleAutoReduceRecordInfo(details)
  1457. } else if err == nil {
  1458. if user.ID > 0 {
  1459. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1460. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  1461. }
  1462. }
  1463. }
  1464. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1465. if newOut.ID > 0 {
  1466. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1467. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1468. if err == gorm.ErrRecordNotFound {
  1469. details := &models.AutomaticReduceDetail{
  1470. WarehouseOutId: newOut.ID,
  1471. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1472. PatientId: id,
  1473. Ctime: time.Now().Unix(),
  1474. Mtime: time.Now().Unix(),
  1475. Status: 1,
  1476. RecordTime: order.StartTime,
  1477. OrgId: adminUserInfo.Org.Id,
  1478. GoodId: dialyser_sterilised,
  1479. GoodTypeId: dialyser_sterilised_good_type_id,
  1480. }
  1481. service.AddSigleAutoReduceRecordInfo(details)
  1482. } else if err == nil {
  1483. if user.ID > 0 {
  1484. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. if dialysisPrescription.Filtryzer != filtryzer {
  1491. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1492. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1493. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1494. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1495. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  1496. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1497. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1498. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1499. warehouseOutInfo := &models.WarehouseOutInfo{
  1500. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1501. WarehouseOutId: out.ID,
  1502. Count: 1,
  1503. Status: 1,
  1504. Ctime: time.Now().Unix(),
  1505. Remark: "",
  1506. OrgId: adminUserInfo.Org.Id,
  1507. Type: 1,
  1508. Manufacturer: 0,
  1509. Dealer: 0,
  1510. IsSys: 1,
  1511. SysRecordTime: order.StartTime,
  1512. }
  1513. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  1514. warehouseOutInfo.Price = stockInInfo.Price
  1515. warehouseOutInfo.GoodId = filtryzer
  1516. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  1517. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1518. if err == nil {
  1519. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1520. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1521. if err == gorm.ErrRecordNotFound {
  1522. details := &models.AutomaticReduceDetail{
  1523. WarehouseOutId: warehouseOutInfo.ID,
  1524. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1525. PatientId: id,
  1526. Ctime: time.Now().Unix(),
  1527. Mtime: time.Now().Unix(),
  1528. Status: 1,
  1529. RecordTime: order.StartTime,
  1530. OrgId: adminUserInfo.Org.Id,
  1531. GoodId: filtryzer,
  1532. GoodTypeId: filtryzer_good_type_id,
  1533. }
  1534. service.AddSigleAutoReduceRecordInfo(details)
  1535. } else if err == nil {
  1536. if user.ID > 0 {
  1537. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  1538. }
  1539. }
  1540. }
  1541. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1542. if newOut.ID > 0 {
  1543. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1544. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1545. if err == gorm.ErrRecordNotFound {
  1546. details := &models.AutomaticReduceDetail{
  1547. WarehouseOutId: newOut.ID,
  1548. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1549. PatientId: id,
  1550. Ctime: time.Now().Unix(),
  1551. Mtime: time.Now().Unix(),
  1552. Status: 1,
  1553. RecordTime: order.StartTime,
  1554. OrgId: adminUserInfo.Org.Id,
  1555. GoodId: filtryzer,
  1556. GoodTypeId: filtryzer_good_type_id,
  1557. }
  1558. service.AddSigleAutoReduceRecordInfo(details)
  1559. } else if err == nil {
  1560. if user.ID > 0 {
  1561. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  1562. }
  1563. }
  1564. }
  1565. }
  1566. }
  1567. if dialysisPrescription.Dialyzers != dialyzers {
  1568. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1569. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1570. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1571. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1572. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1573. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1574. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1575. warehouseOutInfo := &models.WarehouseOutInfo{
  1576. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1577. WarehouseOutId: out.ID,
  1578. Count: 1,
  1579. Status: 1,
  1580. Ctime: time.Now().Unix(),
  1581. Remark: "",
  1582. OrgId: adminUserInfo.Org.Id,
  1583. Type: 1,
  1584. Manufacturer: 0,
  1585. Dealer: 0,
  1586. IsSys: 1,
  1587. SysRecordTime: order.StartTime,
  1588. }
  1589. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  1590. warehouseOutInfo.Price = stockInInfo.Price
  1591. warehouseOutInfo.GoodId = dialyzers
  1592. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  1593. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1594. if err == nil {
  1595. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1596. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1597. if err == gorm.ErrRecordNotFound {
  1598. details := &models.AutomaticReduceDetail{
  1599. WarehouseOutId: warehouseOutInfo.ID,
  1600. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1601. PatientId: id,
  1602. Ctime: time.Now().Unix(),
  1603. Mtime: time.Now().Unix(),
  1604. Status: 1,
  1605. RecordTime: order.StartTime,
  1606. OrgId: adminUserInfo.Org.Id,
  1607. GoodId: dialyzers,
  1608. GoodTypeId: dialyzers_good_type_id,
  1609. }
  1610. service.AddSigleAutoReduceRecordInfo(details)
  1611. } else if err == nil {
  1612. if user.ID > 0 {
  1613. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  1614. }
  1615. }
  1616. }
  1617. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1618. if newOut.ID > 0 {
  1619. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1620. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1621. if err == gorm.ErrRecordNotFound {
  1622. details := &models.AutomaticReduceDetail{
  1623. WarehouseOutId: newOut.ID,
  1624. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1625. PatientId: id,
  1626. Ctime: time.Now().Unix(),
  1627. Mtime: time.Now().Unix(),
  1628. Status: 1,
  1629. RecordTime: order.StartTime,
  1630. OrgId: adminUserInfo.Org.Id,
  1631. GoodId: dialyzers,
  1632. GoodTypeId: dialyzers_good_type_id,
  1633. }
  1634. service.AddSigleAutoReduceRecordInfo(details)
  1635. } else if err == nil {
  1636. if user.ID > 0 {
  1637. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  1638. }
  1639. }
  1640. }
  1641. }
  1642. }
  1643. if dialysisPrescription.Injector != injector {
  1644. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1645. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1646. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1647. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1648. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1649. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1650. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1651. warehouseOutInfo := &models.WarehouseOutInfo{
  1652. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1653. WarehouseOutId: out.ID,
  1654. Count: 1,
  1655. Status: 1,
  1656. Ctime: time.Now().Unix(),
  1657. Remark: "",
  1658. OrgId: adminUserInfo.Org.Id,
  1659. Type: 1,
  1660. Manufacturer: 0,
  1661. Dealer: 0,
  1662. IsSys: 1,
  1663. SysRecordTime: order.StartTime,
  1664. }
  1665. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  1666. warehouseOutInfo.Price = stockInInfo.Price
  1667. warehouseOutInfo.GoodId = injector
  1668. warehouseOutInfo.GoodTypeId = injector_good_type_id
  1669. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1670. if err == nil {
  1671. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1672. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1673. if err == gorm.ErrRecordNotFound {
  1674. details := &models.AutomaticReduceDetail{
  1675. WarehouseOutId: warehouseOutInfo.ID,
  1676. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1677. PatientId: id,
  1678. Ctime: time.Now().Unix(),
  1679. Mtime: time.Now().Unix(),
  1680. Status: 1,
  1681. RecordTime: order.StartTime,
  1682. OrgId: adminUserInfo.Org.Id,
  1683. GoodId: injector,
  1684. GoodTypeId: injector_good_type_id,
  1685. }
  1686. service.AddSigleAutoReduceRecordInfo(details)
  1687. } else if err == nil {
  1688. if user.ID > 0 {
  1689. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  1690. }
  1691. }
  1692. }
  1693. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1694. if newOut.ID > 0 {
  1695. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1696. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1697. if err == gorm.ErrRecordNotFound {
  1698. details := &models.AutomaticReduceDetail{
  1699. WarehouseOutId: newOut.ID,
  1700. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1701. PatientId: id,
  1702. Ctime: time.Now().Unix(),
  1703. Mtime: time.Now().Unix(),
  1704. Status: 1,
  1705. RecordTime: order.StartTime,
  1706. OrgId: adminUserInfo.Org.Id,
  1707. GoodId: injector,
  1708. GoodTypeId: injector_good_type_id,
  1709. }
  1710. service.AddSigleAutoReduceRecordInfo(details)
  1711. } else if err == nil {
  1712. if user.ID > 0 {
  1713. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  1714. }
  1715. }
  1716. }
  1717. }
  1718. }
  1719. if dialysisPrescription.Bloodlines != bloodlines {
  1720. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1721. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1722. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1723. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1724. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1725. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1726. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1727. warehouseOutInfo := &models.WarehouseOutInfo{
  1728. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1729. WarehouseOutId: out.ID,
  1730. Count: 1,
  1731. Status: 1,
  1732. Ctime: time.Now().Unix(),
  1733. Remark: "",
  1734. OrgId: adminUserInfo.Org.Id,
  1735. Type: 1,
  1736. Manufacturer: 0,
  1737. Dealer: 0,
  1738. IsSys: 1,
  1739. SysRecordTime: order.StartTime,
  1740. }
  1741. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  1742. warehouseOutInfo.Price = stockInInfo.Price
  1743. warehouseOutInfo.GoodId = bloodlines
  1744. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  1745. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1746. if err == nil {
  1747. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1748. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1749. if err == gorm.ErrRecordNotFound {
  1750. details := &models.AutomaticReduceDetail{
  1751. WarehouseOutId: warehouseOutInfo.ID,
  1752. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1753. PatientId: id,
  1754. Ctime: time.Now().Unix(),
  1755. Mtime: time.Now().Unix(),
  1756. Status: 1,
  1757. RecordTime: order.StartTime,
  1758. OrgId: adminUserInfo.Org.Id,
  1759. GoodId: bloodlines,
  1760. GoodTypeId: bloodlines_good_type_id,
  1761. }
  1762. service.AddSigleAutoReduceRecordInfo(details)
  1763. } else if err == nil {
  1764. if user.ID > 0 {
  1765. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  1766. }
  1767. }
  1768. }
  1769. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1770. if newOut.ID > 0 {
  1771. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1772. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1773. if err == gorm.ErrRecordNotFound {
  1774. details := &models.AutomaticReduceDetail{
  1775. WarehouseOutId: newOut.ID,
  1776. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1777. PatientId: id,
  1778. Ctime: time.Now().Unix(),
  1779. Mtime: time.Now().Unix(),
  1780. Status: 1,
  1781. RecordTime: order.StartTime,
  1782. OrgId: adminUserInfo.Org.Id,
  1783. GoodId: bloodlines,
  1784. GoodTypeId: bloodlines_good_type_id,
  1785. }
  1786. service.AddSigleAutoReduceRecordInfo(details)
  1787. } else if err == nil {
  1788. if user.ID > 0 {
  1789. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  1790. }
  1791. }
  1792. }
  1793. }
  1794. }
  1795. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  1796. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1797. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1798. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1799. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1800. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1801. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1802. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1803. warehouseOutInfo := &models.WarehouseOutInfo{
  1804. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1805. WarehouseOutId: out.ID,
  1806. Count: 1,
  1807. Status: 1,
  1808. Ctime: time.Now().Unix(),
  1809. Remark: "",
  1810. OrgId: adminUserInfo.Org.Id,
  1811. Type: 1,
  1812. Manufacturer: 0,
  1813. Dealer: 0,
  1814. IsSys: 1,
  1815. SysRecordTime: order.StartTime,
  1816. }
  1817. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  1818. warehouseOutInfo.Price = stockInInfo.Price
  1819. warehouseOutInfo.GoodId = tubing_hemodialysis
  1820. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  1821. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1822. if err == nil {
  1823. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1824. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1825. if err == gorm.ErrRecordNotFound {
  1826. details := &models.AutomaticReduceDetail{
  1827. WarehouseOutId: warehouseOutInfo.ID,
  1828. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1829. PatientId: id,
  1830. Ctime: time.Now().Unix(),
  1831. Mtime: time.Now().Unix(),
  1832. Status: 1,
  1833. RecordTime: order.StartTime,
  1834. OrgId: adminUserInfo.Org.Id,
  1835. GoodId: tubing_hemodialysis,
  1836. GoodTypeId: tubingHemodialysis_good_type_id,
  1837. }
  1838. service.AddSigleAutoReduceRecordInfo(details)
  1839. } else if err == nil {
  1840. if user.ID > 0 {
  1841. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  1842. }
  1843. }
  1844. }
  1845. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1846. if newOut.ID > 0 {
  1847. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1848. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1849. if err == gorm.ErrRecordNotFound {
  1850. details := &models.AutomaticReduceDetail{
  1851. WarehouseOutId: newOut.ID,
  1852. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1853. PatientId: id,
  1854. Ctime: time.Now().Unix(),
  1855. Mtime: time.Now().Unix(),
  1856. Status: 1,
  1857. RecordTime: order.StartTime,
  1858. OrgId: adminUserInfo.Org.Id,
  1859. GoodId: tubing_hemodialysis,
  1860. GoodTypeId: tubingHemodialysis_good_type_id,
  1861. }
  1862. service.AddSigleAutoReduceRecordInfo(details)
  1863. } else if err == nil {
  1864. if user.ID > 0 {
  1865. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. if dialysisPrescription.Package != safe_package {
  1872. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1873. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1874. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1875. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1876. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1877. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1878. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1879. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1880. warehouseOutInfo := &models.WarehouseOutInfo{
  1881. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1882. WarehouseOutId: out.ID,
  1883. Count: 1,
  1884. Status: 1,
  1885. Ctime: time.Now().Unix(),
  1886. Remark: "",
  1887. OrgId: adminUserInfo.Org.Id,
  1888. Type: 1,
  1889. Manufacturer: 0,
  1890. Dealer: 0,
  1891. IsSys: 1,
  1892. SysRecordTime: order.StartTime,
  1893. }
  1894. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  1895. warehouseOutInfo.Price = stockInInfo.Price
  1896. warehouseOutInfo.GoodId = safe_package
  1897. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  1898. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1899. if err == nil {
  1900. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1901. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1902. if err == gorm.ErrRecordNotFound {
  1903. details := &models.AutomaticReduceDetail{
  1904. WarehouseOutId: warehouseOutInfo.ID,
  1905. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1906. PatientId: id,
  1907. Ctime: time.Now().Unix(),
  1908. Mtime: time.Now().Unix(),
  1909. Status: 1,
  1910. RecordTime: order.StartTime,
  1911. OrgId: adminUserInfo.Org.Id,
  1912. GoodId: safe_package,
  1913. GoodTypeId: safe_package_good_type_id,
  1914. }
  1915. service.AddSigleAutoReduceRecordInfo(details)
  1916. } else if err == nil {
  1917. if user.ID > 0 {
  1918. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  1919. }
  1920. }
  1921. }
  1922. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1923. if newOut.ID > 0 {
  1924. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1925. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1926. if err == gorm.ErrRecordNotFound {
  1927. details := &models.AutomaticReduceDetail{
  1928. WarehouseOutId: newOut.ID,
  1929. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1930. PatientId: id,
  1931. Ctime: time.Now().Unix(),
  1932. Mtime: time.Now().Unix(),
  1933. Status: 1,
  1934. RecordTime: order.StartTime,
  1935. OrgId: adminUserInfo.Org.Id,
  1936. GoodId: safe_package,
  1937. GoodTypeId: safe_package_good_type_id,
  1938. }
  1939. service.AddSigleAutoReduceRecordInfo(details)
  1940. } else if err == nil {
  1941. if user.ID > 0 {
  1942. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  1943. }
  1944. }
  1945. }
  1946. }
  1947. }
  1948. if dialysisPrescription.ALiquid != a_liquid {
  1949. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1950. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1951. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1952. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1953. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1954. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1955. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1956. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1957. warehouseOutInfo := &models.WarehouseOutInfo{
  1958. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1959. WarehouseOutId: out.ID,
  1960. Count: 1,
  1961. Status: 1,
  1962. Ctime: time.Now().Unix(),
  1963. Remark: "",
  1964. OrgId: adminUserInfo.Org.Id,
  1965. Type: 1,
  1966. Manufacturer: 0,
  1967. Dealer: 0,
  1968. IsSys: 1,
  1969. SysRecordTime: order.StartTime,
  1970. }
  1971. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  1972. warehouseOutInfo.Price = stockInInfo.Price
  1973. warehouseOutInfo.GoodId = a_liquid
  1974. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  1975. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1976. if err == nil {
  1977. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1978. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1979. if err == gorm.ErrRecordNotFound {
  1980. details := &models.AutomaticReduceDetail{
  1981. WarehouseOutId: warehouseOutInfo.ID,
  1982. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1983. PatientId: id,
  1984. Ctime: time.Now().Unix(),
  1985. Mtime: time.Now().Unix(),
  1986. Status: 1,
  1987. RecordTime: order.StartTime,
  1988. OrgId: adminUserInfo.Org.Id,
  1989. GoodId: a_liquid,
  1990. GoodTypeId: aliquid_good_type_id,
  1991. }
  1992. service.AddSigleAutoReduceRecordInfo(details)
  1993. } else if err == nil {
  1994. if user.ID > 0 {
  1995. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  1996. }
  1997. }
  1998. }
  1999. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2000. if newOut.ID > 0 {
  2001. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  2002. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  2003. if err == gorm.ErrRecordNotFound {
  2004. details := &models.AutomaticReduceDetail{
  2005. WarehouseOutId: newOut.ID,
  2006. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2007. PatientId: id,
  2008. Ctime: time.Now().Unix(),
  2009. Mtime: time.Now().Unix(),
  2010. Status: 1,
  2011. RecordTime: order.StartTime,
  2012. OrgId: adminUserInfo.Org.Id,
  2013. GoodId: a_liquid,
  2014. GoodTypeId: aliquid_good_type_id,
  2015. }
  2016. service.AddSigleAutoReduceRecordInfo(details)
  2017. } else if err == nil {
  2018. if user.ID > 0 {
  2019. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  2020. }
  2021. }
  2022. }
  2023. }
  2024. }
  2025. }
  2026. }
  2027. }
  2028. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2029. prescription.Modifier = adminUserInfo.AdminUser.Id
  2030. if appRole.UserType == 2 || appRole.UserType == 1 {
  2031. prescription_doctor := adminUserInfo.AdminUser.Id
  2032. prescription.PrescriptionDoctor = prescription_doctor
  2033. }
  2034. if dialysisPrescription.Creater == 0 { //体重称
  2035. prescription.Creater = adminUserInfo.AdminUser.Id
  2036. } else {
  2037. prescription.Creater = dialysisPrescription.Creater
  2038. }
  2039. prescription.ID = dialysisPrescription.ID
  2040. err := service.UpDateDialysisPrescription(&prescription)
  2041. if err == nil {
  2042. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2043. if updateErr != nil {
  2044. utils.ErrorLog("%v", updateErr)
  2045. }
  2046. c.ServeSuccessJSON(map[string]interface{}{
  2047. "prescription": prescription,
  2048. })
  2049. }
  2050. }
  2051. }
  2052. func (c *DialysisAPIController) Finish() {
  2053. id, _ := c.GetInt64("patient", 0)
  2054. recordDateStr := c.GetString("record_date")
  2055. nurseID, _ := c.GetInt64("nurse")
  2056. end_time := c.GetString("end_time")
  2057. if id <= 0 || nurseID <= 0 {
  2058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2059. return
  2060. }
  2061. adminUserInfo := c.GetMobileAdminUserInfo()
  2062. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2063. if patient.ID == 0 {
  2064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2065. return
  2066. }
  2067. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2068. if getNurseErr != nil {
  2069. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2071. return
  2072. } else if nurse == nil {
  2073. c.ErrorLog("护士不存在")
  2074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2075. return
  2076. }
  2077. if len(recordDateStr) == 0 {
  2078. recordDateStr = time.Now().Format("2006-01-02")
  2079. }
  2080. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2081. if parseDateErr != nil {
  2082. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2084. return
  2085. }
  2086. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2087. if parseEndDateErr != nil {
  2088. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2090. return
  2091. }
  2092. //now := time.Now()
  2093. //year, month, day := now.Date()
  2094. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2095. //todayTimeStamp := today_time.Unix()
  2096. // 获取当天的第一条透析纪录
  2097. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2098. if getMonitorRecordsErr != nil {
  2099. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2101. return
  2102. }
  2103. // 获取当前的最后一条透析纪录
  2104. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  2105. if getMonitorRecordsErr != nil {
  2106. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2108. return
  2109. }
  2110. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2111. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  2112. if getAADErr != nil {
  2113. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2115. return
  2116. }
  2117. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  2118. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2119. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2120. if assessmentAfterDislysis != nil {
  2121. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2122. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2123. } else {
  2124. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2125. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2126. tempassessmentAfterDislysis.Status = 1
  2127. tempassessmentAfterDislysis.PatientId = id
  2128. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2129. }
  2130. if dialysisOrder.Stage == 1 {
  2131. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2132. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2133. fmt.Println(value)
  2134. a, b := math.Modf(value)
  2135. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2136. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2137. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2138. fmt.Println(hour)
  2139. fmt.Println(minute)
  2140. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2141. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2142. }
  2143. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2144. //var num1 int64
  2145. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2146. //fmt.Println(num1)
  2147. //sub := float64(num1 / 3600)
  2148. //fmt.Println(sub)
  2149. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2150. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2151. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2152. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2153. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2154. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2155. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2156. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2157. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2158. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2159. }
  2160. if lastAssessmentAfterDislysis != nil {
  2161. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2162. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2163. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2164. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2165. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2166. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2167. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2168. tempassessmentAfterDislysis.Remark = lastAssessmentAfterDislysis.Remark
  2169. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2170. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2171. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2172. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2173. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2174. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2175. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2176. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2177. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2178. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2179. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2180. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2181. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2182. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2183. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2184. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2185. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2186. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2187. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2188. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2189. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2190. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2191. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2192. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2193. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2194. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2195. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2196. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2197. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2198. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2199. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2200. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2201. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2202. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2203. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2204. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2205. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2206. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2207. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2208. }
  2209. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2210. if err != nil {
  2211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2212. return
  2213. }
  2214. if dialysisOrder == nil {
  2215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2216. return
  2217. }
  2218. if dialysisOrder.Stage == 2 {
  2219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2220. return
  2221. }
  2222. if dialysisOrder.Stage == 1 {
  2223. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  2224. //结束时候透析次数加1
  2225. service.UpdateSolutionByPatientId(id)
  2226. dialysisOrder.Stage = 2
  2227. dialysisOrder.FinishNurse = nurseID
  2228. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2229. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2230. dialysisOrder.EndTime = endDate.Unix()
  2231. if err == nil {
  2232. c.ServeSuccessJSON(map[string]interface{}{
  2233. "dialysisOrder": dialysisOrder,
  2234. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2235. })
  2236. } else {
  2237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2238. }
  2239. }
  2240. }
  2241. func (c *DialysisAPIController) GetAllZone() {
  2242. adminUserInfo := c.GetMobileAdminUserInfo()
  2243. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2244. if err == nil {
  2245. c.ServeSuccessJSON(map[string]interface{}{
  2246. "zone": zone,
  2247. })
  2248. }
  2249. }
  2250. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2251. adminUserInfo := c.GetMobileAdminUserInfo()
  2252. page, _ := c.GetInt64("page", 1)
  2253. limit, _ := c.GetInt64("limit", 10)
  2254. schedulType, _ := c.GetInt64("schedul_type", 0)
  2255. startTime, _ := c.GetInt64("schedul_time", 0)
  2256. partitionType, _ := c.GetInt64("partition_type", 0)
  2257. keywords := c.GetString("keywords")
  2258. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2259. if err == nil {
  2260. c.ServeSuccessJSON(map[string]interface{}{
  2261. "schedule": dialysisSchedule,
  2262. })
  2263. }
  2264. return
  2265. }
  2266. // /m/api/dialysis/start [post]
  2267. // @param patient_id:int
  2268. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2269. // @param nurse:int 上机护士
  2270. // @param bed:int 床位号
  2271. func (this *DialysisAPIController) StartDialysis() {
  2272. patientID, _ := this.GetInt64("patient_id")
  2273. recordDateStr := this.GetString("record_date")
  2274. nurseID, _ := this.GetInt64("nurse")
  2275. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2276. blood_drawing, _ := this.GetInt64("blood_drawing")
  2277. schedual_type, _ := this.GetInt64("schedual_type")
  2278. bedID, _ := this.GetInt64("bed")
  2279. start_time := this.GetString("start_time")
  2280. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2282. return
  2283. }
  2284. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2285. if parseStartDateErr != nil {
  2286. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2288. return
  2289. }
  2290. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2291. if parseErr != nil {
  2292. this.ErrorLog("时间解析失败:%v", parseErr)
  2293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2294. return
  2295. }
  2296. adminUserInfo := this.GetMobileAdminUserInfo()
  2297. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2298. if getPatientErr != nil {
  2299. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2301. return
  2302. } else if patient == nil {
  2303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2304. return
  2305. }
  2306. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2307. if getNurseErr != nil {
  2308. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2309. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2310. return
  2311. } else if nurse == nil {
  2312. this.ErrorLog("护士不存在")
  2313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2314. return
  2315. }
  2316. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2317. if getNurseErr != nil {
  2318. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2320. return
  2321. } else if nurse == nil {
  2322. this.ErrorLog("护士不存在")
  2323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2324. return
  2325. }
  2326. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2327. if getDeviceNumberErr != nil {
  2328. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2330. return
  2331. } else if deviceNumber == nil {
  2332. this.ErrorLog("床位号不存在")
  2333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2334. return
  2335. }
  2336. _, configs := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2337. if configs.IsOpen == 1 {
  2338. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2339. if prescription.ID == 0 {
  2340. this.ErrorLog("上机失败,还没开处方")
  2341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  2342. return
  2343. }
  2344. }
  2345. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2346. if getRecordErr != nil {
  2347. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2349. return
  2350. } else if dialysisRecord != nil {
  2351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2352. return
  2353. }
  2354. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2355. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2356. timeLayout := "2006-01-02 15:04:05"
  2357. loc, _ := time.LoadLocation("Local")
  2358. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2359. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2360. schedulestartTime := theStartTime.Unix()
  2361. scheduleendTime := theEndTime.Unix()
  2362. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2363. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2364. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2365. //查询该床位是否有人用了
  2366. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2367. if err == gorm.ErrRecordNotFound { //空床位
  2368. // 修改了床位逻辑
  2369. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2370. if daySchedule.ID > 0 {
  2371. daySchedule.PartitionId = deviceNumber.ZoneID
  2372. daySchedule.BedId = bedID
  2373. daySchedule.ScheduleType = schedual_type
  2374. daySchedule.UpdatedTime = time.Now().Unix()
  2375. err := service.UpdateSchedule(&daySchedule)
  2376. if err != nil {
  2377. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2378. return
  2379. }
  2380. }
  2381. } else if err == nil {
  2382. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2383. if order_err == nil {
  2384. if order.ID > 0 { //该机位被其他人占用了
  2385. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2386. return
  2387. } else {
  2388. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2389. if daySchedule.ID > 0 {
  2390. daySchedule.PartitionId = deviceNumber.ZoneID
  2391. daySchedule.BedId = bedID
  2392. daySchedule.ScheduleType = schedual_type
  2393. daySchedule.UpdatedTime = time.Now().Unix()
  2394. err := service.UpdateSchedule(&daySchedule)
  2395. if err != nil {
  2396. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2397. return
  2398. }
  2399. }
  2400. }
  2401. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  2402. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2403. if daySchedule.ID > 0 {
  2404. daySchedule.PartitionId = deviceNumber.ZoneID
  2405. daySchedule.BedId = bedID
  2406. daySchedule.ScheduleType = schedual_type
  2407. daySchedule.UpdatedTime = time.Now().Unix()
  2408. err := service.UpdateSchedule(&daySchedule)
  2409. if err != nil {
  2410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2411. return
  2412. }
  2413. }
  2414. }
  2415. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2416. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2417. return
  2418. }
  2419. } else if err != nil {
  2420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2421. return
  2422. }
  2423. dialysisRecord = &models.DialysisOrder{
  2424. DialysisDate: recordDate.Unix(),
  2425. UserOrgId: adminUserInfo.Org.Id,
  2426. PatientId: patientID,
  2427. Stage: 1,
  2428. BedID: bedID,
  2429. StartNurse: nurseID,
  2430. Status: 1,
  2431. StartTime: startDate.Unix(),
  2432. CreatedTime: time.Now().Unix(),
  2433. UpdatedTime: time.Now().Unix(),
  2434. PunctureNurse: puncture_nurse,
  2435. Creator: adminUserInfo.AdminUser.Id,
  2436. Modifier: adminUserInfo.AdminUser.Id,
  2437. SchedualType: schedual_type,
  2438. }
  2439. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2440. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2441. var tempdispose string
  2442. // 只针对中能建
  2443. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2444. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2445. }
  2446. var ultrafiltration_rate float64
  2447. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2448. if prescription.ID > 0 {
  2449. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2450. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2451. if template.TemplateId == 6 { //adminUserInfo.Org.Id == 9538
  2452. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2453. }
  2454. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2455. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2456. }
  2457. // 只针对方济医院
  2458. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2459. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2460. ultrafiltration_rate = value
  2461. }
  2462. }
  2463. }
  2464. record := models.MonitoringRecord{
  2465. UserOrgId: adminUserInfo.Org.Id,
  2466. PatientId: patientID,
  2467. DialysisOrderId: dialysisRecord.ID,
  2468. MonitoringDate: schedulestartTime,
  2469. OperateTime: startDate.Unix(),
  2470. // MonitoringTime: recordTime,
  2471. MonitoringNurse: nurseID,
  2472. Dispose: tempdispose,
  2473. UltrafiltrationRate: ultrafiltration_rate,
  2474. UltrafiltrationVolume: 0,
  2475. Status: 1,
  2476. CreatedTime: time.Now().Unix(),
  2477. UpdatedTime: time.Now().Unix(),
  2478. }
  2479. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2480. if newdialysisRecord.ID > 0 {
  2481. err := service.CreateMonitor(&record)
  2482. if err != nil {
  2483. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2484. return
  2485. }
  2486. }
  2487. //是否启动自动扣减功能
  2488. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2489. //启动的话
  2490. if config.IsOpen == 1 {
  2491. niprocart, _ := beego.AppConfig.Int64("niprocart")
  2492. jms, _ := beego.AppConfig.Int64("jms")
  2493. fistula_needle_set, _ := beego.AppConfig.Int64("fistula_needle_set")
  2494. fistula_needle_set_16, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  2495. hemoperfusion, _ := beego.AppConfig.Int64("hemoperfusion")
  2496. dialyser_sterilised, _ := beego.AppConfig.Int64("dialyser_sterilised")
  2497. filtryzer, _ := beego.AppConfig.Int64("filtryzer")
  2498. dialyzers, _ := beego.AppConfig.Int64("dialyzers")
  2499. injector, _ := beego.AppConfig.Int64("injector")
  2500. bloodlines, _ := beego.AppConfig.Int64("bloodlines")
  2501. tubingHemodialysis, _ := beego.AppConfig.Int64("tubingHemodialysis")
  2502. safe_package, _ := beego.AppConfig.Int64("package")
  2503. aliquid, _ := beego.AppConfig.Int64("aliquid")
  2504. //库存自动扣减功能
  2505. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2506. if prescription.ID > 0 {
  2507. out, err := service.FindStockOutByIsSys(adminUserInfo.Org.Id, 1, recordDate.Unix())
  2508. if err == gorm.ErrRecordNotFound {
  2509. //没有记录,则创建出库单
  2510. timeStr := time.Now().Format("2006-01-02")
  2511. timeArr := strings.Split(timeStr, "-")
  2512. total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
  2513. total = total + 1
  2514. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2515. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2516. number = number + total
  2517. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2518. creater := adminUserInfo.AdminUser.Id
  2519. warehouseOut := models.WarehouseOut{
  2520. WarehouseOutOrderNumber: warehousing_out_order,
  2521. OperationTime: time.Now().Unix(),
  2522. OrgId: adminUserInfo.Org.Id,
  2523. Creater: creater,
  2524. Ctime: time.Now().Unix(),
  2525. Status: 1,
  2526. WarehouseOutTime: recordDate.Unix(),
  2527. Dealer: 0,
  2528. Manufacturer: 0,
  2529. Type: 1,
  2530. IsSys: 1,
  2531. }
  2532. err := service.AddSigleWarehouseOut(&warehouseOut)
  2533. if err != nil {
  2534. utils.TraceLog("创建出库单失败 err = %v", err)
  2535. } else {
  2536. if prescription.Niprocart > 0 {
  2537. warehouseOutInfo := &models.WarehouseOutInfo{
  2538. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2539. WarehouseOutId: warehouseOut.ID,
  2540. Count: 1,
  2541. Status: 1,
  2542. Ctime: time.Now().Unix(),
  2543. Remark: "",
  2544. OrgId: adminUserInfo.Org.Id,
  2545. Type: 1,
  2546. Manufacturer: 0,
  2547. Dealer: 0,
  2548. IsSys: 1,
  2549. SysRecordTime: startDate.Unix(),
  2550. }
  2551. //查出入库记录中最后一条记录
  2552. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  2553. warehouseOutInfo.Price = stockInInfo.Price
  2554. warehouseOutInfo.GoodId = prescription.Niprocart
  2555. warehouseOutInfo.GoodTypeId = niprocart
  2556. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2557. if err == nil {
  2558. details := &models.AutomaticReduceDetail{
  2559. WarehouseOutId: warehouseOutInfo.ID,
  2560. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2561. PatientId: patientID,
  2562. Ctime: time.Now().Unix(),
  2563. Mtime: time.Now().Unix(),
  2564. Status: 1,
  2565. RecordTime: startDate.Unix(),
  2566. OrgId: adminUserInfo.Org.Id,
  2567. GoodId: prescription.Niprocart,
  2568. GoodTypeId: niprocart,
  2569. }
  2570. service.AddSigleAutoReduceRecordInfo(details)
  2571. }
  2572. }
  2573. if prescription.Jms > 0 {
  2574. warehouseOutInfo := &models.WarehouseOutInfo{
  2575. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2576. WarehouseOutId: warehouseOut.ID,
  2577. Count: 1,
  2578. Status: 1,
  2579. Ctime: time.Now().Unix(),
  2580. Remark: "",
  2581. OrgId: adminUserInfo.Org.Id,
  2582. Type: 1,
  2583. Manufacturer: 0,
  2584. Dealer: 0,
  2585. IsSys: 1,
  2586. SysRecordTime: startDate.Unix(),
  2587. }
  2588. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  2589. warehouseOutInfo.Price = stockInInfo.Price
  2590. warehouseOutInfo.GoodId = prescription.Jms
  2591. warehouseOutInfo.GoodTypeId = jms
  2592. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2593. if err == nil {
  2594. details := &models.AutomaticReduceDetail{
  2595. WarehouseOutId: warehouseOutInfo.ID,
  2596. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2597. PatientId: patientID,
  2598. Ctime: time.Now().Unix(),
  2599. Mtime: time.Now().Unix(),
  2600. Status: 1,
  2601. RecordTime: startDate.Unix(),
  2602. OrgId: adminUserInfo.Org.Id,
  2603. GoodId: prescription.Jms,
  2604. GoodTypeId: jms,
  2605. }
  2606. service.AddSigleAutoReduceRecordInfo(details)
  2607. }
  2608. }
  2609. if prescription.FistulaNeedleSet > 0 {
  2610. warehouseOutInfo := &models.WarehouseOutInfo{
  2611. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2612. WarehouseOutId: warehouseOut.ID,
  2613. Count: 1,
  2614. Status: 1,
  2615. Ctime: time.Now().Unix(),
  2616. Remark: "",
  2617. OrgId: adminUserInfo.Org.Id,
  2618. Type: 1,
  2619. Manufacturer: 0,
  2620. Dealer: 0,
  2621. IsSys: 1,
  2622. SysRecordTime: startDate.Unix(),
  2623. }
  2624. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  2625. warehouseOutInfo.Price = stockInInfo.Price
  2626. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  2627. warehouseOutInfo.GoodTypeId = fistula_needle_set
  2628. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2629. if err == nil {
  2630. details := &models.AutomaticReduceDetail{
  2631. WarehouseOutId: warehouseOutInfo.ID,
  2632. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2633. PatientId: patientID,
  2634. Ctime: time.Now().Unix(),
  2635. Mtime: time.Now().Unix(),
  2636. Status: 1,
  2637. RecordTime: startDate.Unix(),
  2638. OrgId: adminUserInfo.Org.Id,
  2639. GoodId: prescription.FistulaNeedleSet,
  2640. GoodTypeId: fistula_needle_set,
  2641. }
  2642. service.AddSigleAutoReduceRecordInfo(details)
  2643. }
  2644. }
  2645. if prescription.FistulaNeedleSet16 > 0 {
  2646. warehouseOutInfo := &models.WarehouseOutInfo{
  2647. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2648. WarehouseOutId: warehouseOut.ID,
  2649. Count: 1,
  2650. Status: 1,
  2651. Ctime: time.Now().Unix(),
  2652. Remark: "",
  2653. OrgId: adminUserInfo.Org.Id,
  2654. Type: 1,
  2655. Manufacturer: 0,
  2656. Dealer: 0,
  2657. IsSys: 1,
  2658. SysRecordTime: startDate.Unix(),
  2659. }
  2660. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  2661. warehouseOutInfo.Price = stockInInfo.Price
  2662. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  2663. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  2664. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2665. if err == nil {
  2666. details := &models.AutomaticReduceDetail{
  2667. WarehouseOutId: warehouseOutInfo.ID,
  2668. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2669. PatientId: patientID,
  2670. Ctime: time.Now().Unix(),
  2671. Mtime: time.Now().Unix(),
  2672. Status: 1,
  2673. RecordTime: startDate.Unix(),
  2674. OrgId: adminUserInfo.Org.Id,
  2675. GoodId: prescription.FistulaNeedleSet16,
  2676. GoodTypeId: fistula_needle_set_16,
  2677. }
  2678. service.AddSigleAutoReduceRecordInfo(details)
  2679. }
  2680. }
  2681. if prescription.Hemoperfusion > 0 {
  2682. warehouseOutInfo := &models.WarehouseOutInfo{
  2683. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2684. WarehouseOutId: warehouseOut.ID,
  2685. Count: 1,
  2686. Status: 1,
  2687. Ctime: time.Now().Unix(),
  2688. Remark: "",
  2689. OrgId: adminUserInfo.Org.Id,
  2690. Type: 1,
  2691. Manufacturer: 0,
  2692. Dealer: 0,
  2693. IsSys: 1,
  2694. SysRecordTime: startDate.Unix(),
  2695. }
  2696. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  2697. warehouseOutInfo.Price = stockInInfo.Price
  2698. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  2699. warehouseOutInfo.GoodTypeId = hemoperfusion
  2700. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2701. if err == nil {
  2702. details := &models.AutomaticReduceDetail{
  2703. WarehouseOutId: warehouseOutInfo.ID,
  2704. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2705. PatientId: patientID,
  2706. Ctime: time.Now().Unix(),
  2707. Mtime: time.Now().Unix(),
  2708. Status: 1,
  2709. RecordTime: startDate.Unix(),
  2710. OrgId: adminUserInfo.Org.Id,
  2711. GoodId: prescription.Hemoperfusion,
  2712. GoodTypeId: hemoperfusion,
  2713. }
  2714. service.AddSigleAutoReduceRecordInfo(details)
  2715. }
  2716. }
  2717. if prescription.DialyserSterilised > 0 {
  2718. warehouseOutInfo := &models.WarehouseOutInfo{
  2719. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2720. WarehouseOutId: warehouseOut.ID,
  2721. Count: 1,
  2722. Status: 1,
  2723. Ctime: time.Now().Unix(),
  2724. Remark: "",
  2725. OrgId: adminUserInfo.Org.Id,
  2726. Type: 1,
  2727. Manufacturer: 0,
  2728. Dealer: 0,
  2729. IsSys: 1,
  2730. SysRecordTime: startDate.Unix(),
  2731. }
  2732. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  2733. warehouseOutInfo.Price = stockInInfo.Price
  2734. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  2735. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  2736. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2737. if err == nil {
  2738. details := &models.AutomaticReduceDetail{
  2739. WarehouseOutId: warehouseOutInfo.ID,
  2740. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2741. PatientId: patientID,
  2742. Ctime: time.Now().Unix(),
  2743. Mtime: time.Now().Unix(),
  2744. Status: 1,
  2745. RecordTime: startDate.Unix(),
  2746. OrgId: adminUserInfo.Org.Id,
  2747. GoodId: prescription.DialyserSterilised,
  2748. GoodTypeId: dialyser_sterilised,
  2749. }
  2750. service.AddSigleAutoReduceRecordInfo(details)
  2751. }
  2752. }
  2753. if prescription.Filtryzer > 0 {
  2754. warehouseOutInfo := &models.WarehouseOutInfo{
  2755. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2756. WarehouseOutId: warehouseOut.ID,
  2757. Count: 1,
  2758. Status: 1,
  2759. Ctime: time.Now().Unix(),
  2760. Remark: "",
  2761. OrgId: adminUserInfo.Org.Id,
  2762. Type: 1,
  2763. Manufacturer: 0,
  2764. Dealer: 0,
  2765. IsSys: 1,
  2766. SysRecordTime: startDate.Unix(),
  2767. }
  2768. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  2769. warehouseOutInfo.Price = stockInInfo.Price
  2770. warehouseOutInfo.GoodId = prescription.Filtryzer
  2771. warehouseOutInfo.GoodTypeId = filtryzer
  2772. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2773. if err == nil {
  2774. details := &models.AutomaticReduceDetail{
  2775. WarehouseOutId: warehouseOutInfo.ID,
  2776. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2777. PatientId: patientID,
  2778. Ctime: time.Now().Unix(),
  2779. Mtime: time.Now().Unix(),
  2780. Status: 1,
  2781. RecordTime: startDate.Unix(),
  2782. OrgId: adminUserInfo.Org.Id,
  2783. GoodId: prescription.Filtryzer,
  2784. GoodTypeId: filtryzer,
  2785. }
  2786. service.AddSigleAutoReduceRecordInfo(details)
  2787. }
  2788. }
  2789. if prescription.Dialyzers > 0 {
  2790. warehouseOutInfo := &models.WarehouseOutInfo{
  2791. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2792. WarehouseOutId: warehouseOut.ID,
  2793. Count: 1,
  2794. Status: 1,
  2795. Ctime: time.Now().Unix(),
  2796. Remark: "",
  2797. OrgId: adminUserInfo.Org.Id,
  2798. Type: 1,
  2799. Manufacturer: 0,
  2800. Dealer: 0,
  2801. IsSys: 1,
  2802. SysRecordTime: startDate.Unix(),
  2803. }
  2804. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  2805. warehouseOutInfo.Price = stockInInfo.Price
  2806. warehouseOutInfo.GoodId = prescription.Dialyzers
  2807. warehouseOutInfo.GoodTypeId = dialyzers
  2808. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2809. if err == nil {
  2810. details := &models.AutomaticReduceDetail{
  2811. WarehouseOutId: warehouseOutInfo.ID,
  2812. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2813. PatientId: patientID,
  2814. Ctime: time.Now().Unix(),
  2815. Mtime: time.Now().Unix(),
  2816. Status: 1,
  2817. RecordTime: startDate.Unix(),
  2818. OrgId: adminUserInfo.Org.Id,
  2819. GoodId: prescription.Dialyzers,
  2820. GoodTypeId: dialyzers,
  2821. }
  2822. service.AddSigleAutoReduceRecordInfo(details)
  2823. }
  2824. }
  2825. if prescription.Injector > 0 {
  2826. warehouseOutInfo := &models.WarehouseOutInfo{
  2827. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2828. WarehouseOutId: warehouseOut.ID,
  2829. Count: 1,
  2830. Status: 1,
  2831. Ctime: time.Now().Unix(),
  2832. Remark: "",
  2833. OrgId: adminUserInfo.Org.Id,
  2834. Type: 1,
  2835. Manufacturer: 0,
  2836. Dealer: 0,
  2837. IsSys: 1,
  2838. SysRecordTime: startDate.Unix(),
  2839. }
  2840. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  2841. warehouseOutInfo.Price = stockInInfo.Price
  2842. warehouseOutInfo.GoodId = prescription.Injector
  2843. warehouseOutInfo.GoodTypeId = injector
  2844. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2845. if err == nil {
  2846. details := &models.AutomaticReduceDetail{
  2847. WarehouseOutId: warehouseOutInfo.ID,
  2848. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2849. PatientId: patientID,
  2850. Ctime: time.Now().Unix(),
  2851. Mtime: time.Now().Unix(),
  2852. Status: 1,
  2853. RecordTime: startDate.Unix(),
  2854. OrgId: adminUserInfo.Org.Id,
  2855. GoodId: prescription.Injector,
  2856. GoodTypeId: injector,
  2857. }
  2858. service.AddSigleAutoReduceRecordInfo(details)
  2859. }
  2860. }
  2861. if prescription.Bloodlines > 0 {
  2862. warehouseOutInfo := &models.WarehouseOutInfo{
  2863. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2864. WarehouseOutId: warehouseOut.ID,
  2865. Count: 1,
  2866. Status: 1,
  2867. Ctime: time.Now().Unix(),
  2868. Remark: "",
  2869. OrgId: adminUserInfo.Org.Id,
  2870. Type: 1,
  2871. Manufacturer: 0,
  2872. Dealer: 0,
  2873. IsSys: 1,
  2874. SysRecordTime: startDate.Unix(),
  2875. }
  2876. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  2877. warehouseOutInfo.Price = stockInInfo.Price
  2878. warehouseOutInfo.GoodId = prescription.Bloodlines
  2879. warehouseOutInfo.GoodTypeId = bloodlines
  2880. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2881. if err == nil {
  2882. details := &models.AutomaticReduceDetail{
  2883. WarehouseOutId: warehouseOutInfo.ID,
  2884. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2885. PatientId: patientID,
  2886. Ctime: time.Now().Unix(),
  2887. Mtime: time.Now().Unix(),
  2888. Status: 1,
  2889. RecordTime: startDate.Unix(),
  2890. OrgId: adminUserInfo.Org.Id,
  2891. GoodId: prescription.Bloodlines,
  2892. GoodTypeId: bloodlines,
  2893. }
  2894. service.AddSigleAutoReduceRecordInfo(details)
  2895. }
  2896. }
  2897. if prescription.TubingHemodialysis > 0 {
  2898. warehouseOutInfo := &models.WarehouseOutInfo{
  2899. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2900. WarehouseOutId: warehouseOut.ID,
  2901. Count: 1,
  2902. Status: 1,
  2903. Ctime: time.Now().Unix(),
  2904. Remark: "",
  2905. OrgId: adminUserInfo.Org.Id,
  2906. Type: 1,
  2907. Manufacturer: 0,
  2908. Dealer: 0,
  2909. IsSys: 1,
  2910. SysRecordTime: startDate.Unix(),
  2911. }
  2912. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  2913. warehouseOutInfo.Price = stockInInfo.Price
  2914. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  2915. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  2916. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2917. if err == nil {
  2918. details := &models.AutomaticReduceDetail{
  2919. WarehouseOutId: warehouseOutInfo.ID,
  2920. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2921. PatientId: patientID,
  2922. Ctime: time.Now().Unix(),
  2923. Mtime: time.Now().Unix(),
  2924. Status: 1,
  2925. RecordTime: startDate.Unix(),
  2926. OrgId: adminUserInfo.Org.Id,
  2927. GoodId: prescription.TubingHemodialysis,
  2928. GoodTypeId: tubingHemodialysis,
  2929. }
  2930. service.AddSigleAutoReduceRecordInfo(details)
  2931. }
  2932. }
  2933. if prescription.Package > 0 {
  2934. warehouseOutInfo := &models.WarehouseOutInfo{
  2935. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2936. WarehouseOutId: warehouseOut.ID,
  2937. Count: 1,
  2938. Status: 1,
  2939. Ctime: time.Now().Unix(),
  2940. Remark: "",
  2941. OrgId: adminUserInfo.Org.Id,
  2942. Type: 1,
  2943. Manufacturer: 0,
  2944. Dealer: 0,
  2945. IsSys: 1,
  2946. SysRecordTime: startDate.Unix(),
  2947. }
  2948. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  2949. warehouseOutInfo.Price = stockInInfo.Price
  2950. warehouseOutInfo.GoodId = prescription.Package
  2951. warehouseOutInfo.GoodTypeId = safe_package
  2952. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2953. if err == nil {
  2954. details := &models.AutomaticReduceDetail{
  2955. WarehouseOutId: warehouseOutInfo.ID,
  2956. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2957. PatientId: patientID,
  2958. Ctime: time.Now().Unix(),
  2959. Mtime: time.Now().Unix(),
  2960. Status: 1,
  2961. RecordTime: startDate.Unix(),
  2962. OrgId: adminUserInfo.Org.Id,
  2963. GoodId: prescription.Package,
  2964. GoodTypeId: safe_package,
  2965. }
  2966. service.AddSigleAutoReduceRecordInfo(details)
  2967. }
  2968. }
  2969. if prescription.ALiquid > 0 {
  2970. warehouseOutInfo := &models.WarehouseOutInfo{
  2971. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2972. WarehouseOutId: warehouseOut.ID,
  2973. Count: 1,
  2974. Status: 1,
  2975. Ctime: time.Now().Unix(),
  2976. Remark: "",
  2977. OrgId: adminUserInfo.Org.Id,
  2978. Type: 1,
  2979. Manufacturer: 0,
  2980. Dealer: 0,
  2981. IsSys: 1,
  2982. SysRecordTime: startDate.Unix(),
  2983. }
  2984. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  2985. warehouseOutInfo.Price = stockInInfo.Price
  2986. warehouseOutInfo.GoodId = prescription.ALiquid
  2987. warehouseOutInfo.GoodTypeId = aliquid
  2988. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2989. if err == nil {
  2990. details := &models.AutomaticReduceDetail{
  2991. WarehouseOutId: warehouseOutInfo.ID,
  2992. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2993. PatientId: patientID,
  2994. Ctime: time.Now().Unix(),
  2995. Mtime: time.Now().Unix(),
  2996. Status: 1,
  2997. RecordTime: startDate.Unix(),
  2998. OrgId: adminUserInfo.Org.Id,
  2999. GoodId: prescription.ALiquid,
  3000. GoodTypeId: aliquid,
  3001. }
  3002. service.AddSigleAutoReduceRecordInfo(details)
  3003. }
  3004. }
  3005. }
  3006. } else if err == nil {
  3007. if out.ID > 0 {
  3008. if prescription.Niprocart > 0 {
  3009. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, niprocart, prescription.Niprocart, out.WarehouseOutOrderNumber)
  3010. if err == gorm.ErrRecordNotFound {
  3011. warehouseOutInfo := &models.WarehouseOutInfo{
  3012. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3013. WarehouseOutId: out.ID,
  3014. Status: 1,
  3015. Ctime: time.Now().Unix(),
  3016. Remark: "",
  3017. OrgId: adminUserInfo.Org.Id,
  3018. Type: 1,
  3019. Manufacturer: 0,
  3020. Dealer: 0,
  3021. IsSys: 1,
  3022. SysRecordTime: startDate.Unix(),
  3023. }
  3024. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  3025. warehouseOutInfo.Price = stockInInfo.Price
  3026. warehouseOutInfo.GoodId = prescription.Niprocart
  3027. warehouseOutInfo.GoodTypeId = niprocart
  3028. warehouseOutInfo.Count = 1
  3029. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3030. if err == nil {
  3031. details := &models.AutomaticReduceDetail{
  3032. WarehouseOutId: warehouseOutInfo.ID,
  3033. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3034. PatientId: patientID,
  3035. Ctime: time.Now().Unix(),
  3036. Mtime: time.Now().Unix(),
  3037. Status: 1,
  3038. RecordTime: startDate.Unix(),
  3039. OrgId: adminUserInfo.Org.Id,
  3040. GoodId: prescription.Niprocart,
  3041. GoodTypeId: niprocart,
  3042. }
  3043. service.AddSigleAutoReduceRecordInfo(details)
  3044. }
  3045. } else if err == nil { //记录存在,则将数量加1
  3046. if outInfo.ID > 0 {
  3047. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3048. }
  3049. details := &models.AutomaticReduceDetail{
  3050. WarehouseOutId: outInfo.ID,
  3051. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3052. PatientId: patientID,
  3053. Ctime: time.Now().Unix(),
  3054. Mtime: time.Now().Unix(),
  3055. Status: 1,
  3056. RecordTime: startDate.Unix(),
  3057. OrgId: adminUserInfo.Org.Id,
  3058. GoodId: prescription.Niprocart,
  3059. GoodTypeId: niprocart,
  3060. }
  3061. service.AddSigleAutoReduceRecordInfo(details)
  3062. }
  3063. }
  3064. if prescription.Jms > 0 {
  3065. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, jms, prescription.Jms, out.WarehouseOutOrderNumber)
  3066. if err == gorm.ErrRecordNotFound {
  3067. warehouseOutInfo := &models.WarehouseOutInfo{
  3068. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3069. WarehouseOutId: out.ID,
  3070. Status: 1,
  3071. Ctime: time.Now().Unix(),
  3072. Remark: "",
  3073. OrgId: adminUserInfo.Org.Id,
  3074. Type: 1,
  3075. Manufacturer: 0,
  3076. Dealer: 0,
  3077. IsSys: 1,
  3078. SysRecordTime: startDate.Unix(),
  3079. }
  3080. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  3081. warehouseOutInfo.Price = stockInInfo.Price
  3082. warehouseOutInfo.GoodId = prescription.Jms
  3083. warehouseOutInfo.GoodTypeId = jms
  3084. warehouseOutInfo.Count = 1
  3085. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3086. if err == nil {
  3087. details := &models.AutomaticReduceDetail{
  3088. WarehouseOutId: warehouseOutInfo.ID,
  3089. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3090. PatientId: patientID,
  3091. Ctime: time.Now().Unix(),
  3092. Mtime: time.Now().Unix(),
  3093. Status: 1,
  3094. RecordTime: startDate.Unix(),
  3095. OrgId: adminUserInfo.Org.Id,
  3096. GoodId: prescription.Jms,
  3097. GoodTypeId: jms,
  3098. }
  3099. service.AddSigleAutoReduceRecordInfo(details)
  3100. }
  3101. } else if err == nil { //记录存在,则将数量加1
  3102. if outInfo.ID > 0 {
  3103. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3104. }
  3105. details := &models.AutomaticReduceDetail{
  3106. WarehouseOutId: outInfo.ID,
  3107. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3108. PatientId: patientID,
  3109. Ctime: time.Now().Unix(),
  3110. Mtime: time.Now().Unix(),
  3111. Status: 1,
  3112. RecordTime: startDate.Unix(),
  3113. OrgId: adminUserInfo.Org.Id,
  3114. GoodId: prescription.Jms,
  3115. GoodTypeId: jms,
  3116. }
  3117. service.AddSigleAutoReduceRecordInfo(details)
  3118. }
  3119. }
  3120. if prescription.FistulaNeedleSet > 0 {
  3121. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set, prescription.FistulaNeedleSet, out.WarehouseOutOrderNumber)
  3122. if err == gorm.ErrRecordNotFound {
  3123. warehouseOutInfo := &models.WarehouseOutInfo{
  3124. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3125. WarehouseOutId: out.ID,
  3126. Status: 1,
  3127. Ctime: time.Now().Unix(),
  3128. Remark: "",
  3129. OrgId: adminUserInfo.Org.Id,
  3130. Type: 1,
  3131. Manufacturer: 0,
  3132. Dealer: 0,
  3133. IsSys: 1,
  3134. SysRecordTime: startDate.Unix(),
  3135. }
  3136. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  3137. warehouseOutInfo.Price = stockInInfo.Price
  3138. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  3139. warehouseOutInfo.GoodTypeId = fistula_needle_set
  3140. warehouseOutInfo.Count = 1
  3141. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3142. if err == nil {
  3143. details := &models.AutomaticReduceDetail{
  3144. WarehouseOutId: warehouseOutInfo.ID,
  3145. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3146. PatientId: patientID,
  3147. Ctime: time.Now().Unix(),
  3148. Mtime: time.Now().Unix(),
  3149. Status: 1,
  3150. RecordTime: startDate.Unix(),
  3151. OrgId: adminUserInfo.Org.Id,
  3152. GoodId: prescription.FistulaNeedleSet,
  3153. GoodTypeId: fistula_needle_set,
  3154. }
  3155. service.AddSigleAutoReduceRecordInfo(details)
  3156. }
  3157. } else if err == nil { //记录存在,则将数量加1
  3158. if outInfo.ID > 0 {
  3159. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3160. }
  3161. details := &models.AutomaticReduceDetail{
  3162. WarehouseOutId: outInfo.ID,
  3163. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3164. PatientId: patientID,
  3165. Ctime: time.Now().Unix(),
  3166. Mtime: time.Now().Unix(),
  3167. Status: 1,
  3168. RecordTime: startDate.Unix(),
  3169. OrgId: adminUserInfo.Org.Id,
  3170. GoodId: prescription.FistulaNeedleSet,
  3171. GoodTypeId: fistula_needle_set,
  3172. }
  3173. service.AddSigleAutoReduceRecordInfo(details)
  3174. }
  3175. }
  3176. if prescription.FistulaNeedleSet16 > 0 {
  3177. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set_16, prescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber)
  3178. if err == gorm.ErrRecordNotFound {
  3179. warehouseOutInfo := &models.WarehouseOutInfo{
  3180. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3181. WarehouseOutId: out.ID,
  3182. Status: 1,
  3183. Ctime: time.Now().Unix(),
  3184. Remark: "",
  3185. OrgId: adminUserInfo.Org.Id,
  3186. Type: 1,
  3187. Manufacturer: 0,
  3188. Dealer: 0,
  3189. IsSys: 1,
  3190. SysRecordTime: startDate.Unix(),
  3191. }
  3192. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  3193. warehouseOutInfo.Price = stockInInfo.Price
  3194. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  3195. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  3196. warehouseOutInfo.Count = 1
  3197. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3198. if err == nil {
  3199. details := &models.AutomaticReduceDetail{
  3200. WarehouseOutId: warehouseOutInfo.ID,
  3201. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3202. PatientId: patientID,
  3203. Ctime: time.Now().Unix(),
  3204. Mtime: time.Now().Unix(),
  3205. Status: 1,
  3206. RecordTime: startDate.Unix(),
  3207. OrgId: adminUserInfo.Org.Id,
  3208. GoodId: prescription.FistulaNeedleSet16,
  3209. GoodTypeId: fistula_needle_set_16,
  3210. }
  3211. service.AddSigleAutoReduceRecordInfo(details)
  3212. }
  3213. } else if err == nil { //记录存在,则将数量加1
  3214. if outInfo.ID > 0 {
  3215. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3216. }
  3217. details := &models.AutomaticReduceDetail{
  3218. WarehouseOutId: outInfo.ID,
  3219. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3220. PatientId: patientID,
  3221. Ctime: time.Now().Unix(),
  3222. Mtime: time.Now().Unix(),
  3223. Status: 1,
  3224. RecordTime: startDate.Unix(),
  3225. OrgId: adminUserInfo.Org.Id,
  3226. GoodId: prescription.FistulaNeedleSet16,
  3227. GoodTypeId: fistula_needle_set_16,
  3228. }
  3229. service.AddSigleAutoReduceRecordInfo(details)
  3230. }
  3231. }
  3232. if prescription.Hemoperfusion > 0 {
  3233. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, hemoperfusion, prescription.Hemoperfusion, out.WarehouseOutOrderNumber)
  3234. if err == gorm.ErrRecordNotFound {
  3235. warehouseOutInfo := &models.WarehouseOutInfo{
  3236. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3237. WarehouseOutId: out.ID,
  3238. Status: 1,
  3239. Ctime: time.Now().Unix(),
  3240. Remark: "",
  3241. OrgId: adminUserInfo.Org.Id,
  3242. Type: 1,
  3243. Manufacturer: 0,
  3244. Dealer: 0,
  3245. IsSys: 1,
  3246. SysRecordTime: startDate.Unix(),
  3247. }
  3248. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  3249. warehouseOutInfo.Price = stockInInfo.Price
  3250. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  3251. warehouseOutInfo.GoodTypeId = hemoperfusion
  3252. warehouseOutInfo.Count = 1
  3253. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3254. if err == nil {
  3255. details := &models.AutomaticReduceDetail{
  3256. WarehouseOutId: warehouseOutInfo.ID,
  3257. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3258. PatientId: patientID,
  3259. Ctime: time.Now().Unix(),
  3260. Mtime: time.Now().Unix(),
  3261. Status: 1,
  3262. RecordTime: startDate.Unix(),
  3263. OrgId: adminUserInfo.Org.Id,
  3264. GoodId: prescription.Hemoperfusion,
  3265. GoodTypeId: hemoperfusion,
  3266. }
  3267. service.AddSigleAutoReduceRecordInfo(details)
  3268. }
  3269. } else if err == nil { //记录存在,则将数量加1
  3270. if outInfo.ID > 0 {
  3271. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3272. }
  3273. details := &models.AutomaticReduceDetail{
  3274. WarehouseOutId: outInfo.ID,
  3275. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3276. PatientId: patientID,
  3277. Ctime: time.Now().Unix(),
  3278. Mtime: time.Now().Unix(),
  3279. Status: 1,
  3280. RecordTime: startDate.Unix(),
  3281. OrgId: adminUserInfo.Org.Id,
  3282. GoodId: prescription.Hemoperfusion,
  3283. GoodTypeId: hemoperfusion,
  3284. }
  3285. service.AddSigleAutoReduceRecordInfo(details)
  3286. }
  3287. }
  3288. if prescription.DialyserSterilised > 0 {
  3289. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyser_sterilised, prescription.DialyserSterilised, out.WarehouseOutOrderNumber)
  3290. if err == gorm.ErrRecordNotFound {
  3291. warehouseOutInfo := &models.WarehouseOutInfo{
  3292. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3293. WarehouseOutId: out.ID,
  3294. Status: 1,
  3295. Ctime: time.Now().Unix(),
  3296. Remark: "",
  3297. OrgId: adminUserInfo.Org.Id,
  3298. Type: 1,
  3299. Manufacturer: 0,
  3300. Dealer: 0,
  3301. IsSys: 1,
  3302. SysRecordTime: startDate.Unix(),
  3303. }
  3304. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  3305. warehouseOutInfo.Price = stockInInfo.Price
  3306. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  3307. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  3308. warehouseOutInfo.Count = 1
  3309. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3310. if err == nil {
  3311. details := &models.AutomaticReduceDetail{
  3312. WarehouseOutId: warehouseOutInfo.ID,
  3313. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3314. PatientId: patientID,
  3315. Ctime: time.Now().Unix(),
  3316. Mtime: time.Now().Unix(),
  3317. Status: 1,
  3318. RecordTime: startDate.Unix(),
  3319. OrgId: adminUserInfo.Org.Id,
  3320. GoodId: prescription.DialyserSterilised,
  3321. GoodTypeId: dialyser_sterilised,
  3322. }
  3323. service.AddSigleAutoReduceRecordInfo(details)
  3324. }
  3325. } else if err == nil { //记录存在,则将数量加1
  3326. if outInfo.ID > 0 {
  3327. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3328. }
  3329. details := &models.AutomaticReduceDetail{
  3330. WarehouseOutId: outInfo.ID,
  3331. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3332. PatientId: patientID,
  3333. Ctime: time.Now().Unix(),
  3334. Mtime: time.Now().Unix(),
  3335. Status: 1,
  3336. RecordTime: startDate.Unix(),
  3337. OrgId: adminUserInfo.Org.Id,
  3338. GoodId: prescription.DialyserSterilised,
  3339. GoodTypeId: dialyser_sterilised,
  3340. }
  3341. service.AddSigleAutoReduceRecordInfo(details)
  3342. }
  3343. }
  3344. if prescription.Filtryzer > 0 {
  3345. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, filtryzer, prescription.Filtryzer, out.WarehouseOutOrderNumber)
  3346. if err == gorm.ErrRecordNotFound {
  3347. warehouseOutInfo := &models.WarehouseOutInfo{
  3348. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3349. WarehouseOutId: out.ID,
  3350. Status: 1,
  3351. Ctime: time.Now().Unix(),
  3352. Remark: "",
  3353. OrgId: adminUserInfo.Org.Id,
  3354. Type: 1,
  3355. Manufacturer: 0,
  3356. Dealer: 0,
  3357. IsSys: 1,
  3358. SysRecordTime: startDate.Unix(),
  3359. }
  3360. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  3361. warehouseOutInfo.Price = stockInInfo.Price
  3362. warehouseOutInfo.GoodId = prescription.Filtryzer
  3363. warehouseOutInfo.GoodTypeId = filtryzer
  3364. warehouseOutInfo.Count = 1
  3365. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3366. if err == nil {
  3367. details := &models.AutomaticReduceDetail{
  3368. WarehouseOutId: warehouseOutInfo.ID,
  3369. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3370. PatientId: patientID,
  3371. Ctime: time.Now().Unix(),
  3372. Mtime: time.Now().Unix(),
  3373. Status: 1,
  3374. RecordTime: startDate.Unix(),
  3375. OrgId: adminUserInfo.Org.Id,
  3376. GoodId: prescription.Filtryzer,
  3377. GoodTypeId: filtryzer,
  3378. }
  3379. service.AddSigleAutoReduceRecordInfo(details)
  3380. }
  3381. } else if err == nil { //记录存在,则将耗材使用数量加1
  3382. if outInfo.ID > 0 {
  3383. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3384. }
  3385. //插入病人耗材使用记录
  3386. details := &models.AutomaticReduceDetail{
  3387. WarehouseOutId: outInfo.ID,
  3388. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3389. PatientId: patientID,
  3390. Ctime: time.Now().Unix(),
  3391. Mtime: time.Now().Unix(),
  3392. Status: 1,
  3393. RecordTime: startDate.Unix(),
  3394. OrgId: adminUserInfo.Org.Id,
  3395. GoodId: prescription.Filtryzer,
  3396. GoodTypeId: filtryzer,
  3397. }
  3398. service.AddSigleAutoReduceRecordInfo(details)
  3399. }
  3400. }
  3401. if prescription.Dialyzers > 0 {
  3402. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyzers, prescription.Dialyzers, out.WarehouseOutOrderNumber)
  3403. if err == gorm.ErrRecordNotFound {
  3404. warehouseOutInfo := &models.WarehouseOutInfo{
  3405. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3406. WarehouseOutId: out.ID,
  3407. Status: 1,
  3408. Ctime: time.Now().Unix(),
  3409. Remark: "",
  3410. OrgId: adminUserInfo.Org.Id,
  3411. Type: 1,
  3412. Manufacturer: 0,
  3413. Dealer: 0,
  3414. IsSys: 1,
  3415. SysRecordTime: startDate.Unix(),
  3416. }
  3417. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  3418. warehouseOutInfo.Price = stockInInfo.Price
  3419. warehouseOutInfo.GoodId = prescription.Dialyzers
  3420. warehouseOutInfo.GoodTypeId = dialyzers
  3421. warehouseOutInfo.Count = 1
  3422. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3423. if err == nil {
  3424. details := &models.AutomaticReduceDetail{
  3425. WarehouseOutId: warehouseOutInfo.ID,
  3426. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3427. PatientId: patientID,
  3428. Ctime: time.Now().Unix(),
  3429. Mtime: time.Now().Unix(),
  3430. Status: 1,
  3431. RecordTime: startDate.Unix(),
  3432. OrgId: adminUserInfo.Org.Id,
  3433. GoodId: prescription.Dialyzers,
  3434. GoodTypeId: dialyzers,
  3435. }
  3436. service.AddSigleAutoReduceRecordInfo(details)
  3437. }
  3438. } else if err == nil { //记录存在,则将耗材使用数量加1
  3439. if outInfo.ID > 0 {
  3440. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3441. }
  3442. //插入病人耗材使用记录
  3443. details := &models.AutomaticReduceDetail{
  3444. WarehouseOutId: outInfo.ID,
  3445. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3446. PatientId: patientID,
  3447. Ctime: time.Now().Unix(),
  3448. Mtime: time.Now().Unix(),
  3449. Status: 1,
  3450. RecordTime: startDate.Unix(),
  3451. OrgId: adminUserInfo.Org.Id,
  3452. GoodId: prescription.Dialyzer,
  3453. GoodTypeId: dialyzers,
  3454. }
  3455. service.AddSigleAutoReduceRecordInfo(details)
  3456. }
  3457. }
  3458. if prescription.Injector > 0 {
  3459. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, injector, prescription.Injector, out.WarehouseOutOrderNumber)
  3460. if err == gorm.ErrRecordNotFound {
  3461. warehouseOutInfo := &models.WarehouseOutInfo{
  3462. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3463. WarehouseOutId: out.ID,
  3464. Status: 1,
  3465. Ctime: time.Now().Unix(),
  3466. Remark: "",
  3467. OrgId: adminUserInfo.Org.Id,
  3468. Type: 1,
  3469. Manufacturer: 0,
  3470. Dealer: 0,
  3471. IsSys: 1,
  3472. SysRecordTime: startDate.Unix(),
  3473. }
  3474. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  3475. warehouseOutInfo.Price = stockInInfo.Price
  3476. warehouseOutInfo.GoodId = prescription.Injector
  3477. warehouseOutInfo.GoodTypeId = injector
  3478. warehouseOutInfo.Count = 1
  3479. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3480. if err == nil {
  3481. details := &models.AutomaticReduceDetail{
  3482. WarehouseOutId: warehouseOutInfo.ID,
  3483. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3484. PatientId: patientID,
  3485. Ctime: time.Now().Unix(),
  3486. Mtime: time.Now().Unix(),
  3487. Status: 1,
  3488. RecordTime: startDate.Unix(),
  3489. OrgId: adminUserInfo.Org.Id,
  3490. GoodId: prescription.Injector,
  3491. GoodTypeId: injector,
  3492. }
  3493. service.AddSigleAutoReduceRecordInfo(details)
  3494. }
  3495. } else if err == nil { //记录存在,则将耗材使用数量加1
  3496. if outInfo.ID > 0 {
  3497. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3498. }
  3499. //插入病人耗材使用记录
  3500. details := &models.AutomaticReduceDetail{
  3501. WarehouseOutId: outInfo.ID,
  3502. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3503. PatientId: patientID,
  3504. Ctime: time.Now().Unix(),
  3505. Mtime: time.Now().Unix(),
  3506. Status: 1,
  3507. RecordTime: startDate.Unix(),
  3508. OrgId: adminUserInfo.Org.Id,
  3509. GoodId: prescription.Injector,
  3510. GoodTypeId: injector,
  3511. }
  3512. service.AddSigleAutoReduceRecordInfo(details)
  3513. }
  3514. }
  3515. if prescription.Bloodlines > 0 {
  3516. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, bloodlines, prescription.Bloodlines, out.WarehouseOutOrderNumber)
  3517. if err == gorm.ErrRecordNotFound {
  3518. warehouseOutInfo := &models.WarehouseOutInfo{
  3519. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3520. WarehouseOutId: out.ID,
  3521. Status: 1,
  3522. Ctime: time.Now().Unix(),
  3523. Remark: "",
  3524. OrgId: adminUserInfo.Org.Id,
  3525. Type: 1,
  3526. Manufacturer: 0,
  3527. Dealer: 0,
  3528. IsSys: 1,
  3529. SysRecordTime: startDate.Unix(),
  3530. }
  3531. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  3532. warehouseOutInfo.Price = stockInInfo.Price
  3533. warehouseOutInfo.GoodId = prescription.Bloodlines
  3534. warehouseOutInfo.GoodTypeId = bloodlines
  3535. warehouseOutInfo.Count = 1
  3536. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3537. if err == nil {
  3538. details := &models.AutomaticReduceDetail{
  3539. WarehouseOutId: warehouseOutInfo.ID,
  3540. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3541. PatientId: patientID,
  3542. Ctime: time.Now().Unix(),
  3543. Mtime: time.Now().Unix(),
  3544. Status: 1,
  3545. RecordTime: startDate.Unix(),
  3546. OrgId: adminUserInfo.Org.Id,
  3547. GoodId: prescription.Bloodlines,
  3548. GoodTypeId: bloodlines,
  3549. }
  3550. service.AddSigleAutoReduceRecordInfo(details)
  3551. }
  3552. } else if err == nil { //记录存在,则将耗材使用数量加1
  3553. if outInfo.ID > 0 {
  3554. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3555. }
  3556. //插入病人耗材使用记录
  3557. details := &models.AutomaticReduceDetail{
  3558. WarehouseOutId: outInfo.ID,
  3559. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3560. PatientId: patientID,
  3561. Ctime: time.Now().Unix(),
  3562. Mtime: time.Now().Unix(),
  3563. Status: 1,
  3564. RecordTime: startDate.Unix(),
  3565. OrgId: adminUserInfo.Org.Id,
  3566. GoodId: prescription.Bloodlines,
  3567. GoodTypeId: bloodlines,
  3568. }
  3569. service.AddSigleAutoReduceRecordInfo(details)
  3570. }
  3571. }
  3572. if prescription.TubingHemodialysis > 0 {
  3573. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, tubingHemodialysis, prescription.TubingHemodialysis, out.WarehouseOutOrderNumber)
  3574. if err == gorm.ErrRecordNotFound {
  3575. warehouseOutInfo := &models.WarehouseOutInfo{
  3576. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3577. WarehouseOutId: out.ID,
  3578. Status: 1,
  3579. Ctime: time.Now().Unix(),
  3580. Remark: "",
  3581. OrgId: adminUserInfo.Org.Id,
  3582. Type: 1,
  3583. Manufacturer: 0,
  3584. Dealer: 0,
  3585. IsSys: 1,
  3586. SysRecordTime: startDate.Unix(),
  3587. }
  3588. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  3589. warehouseOutInfo.Price = stockInInfo.Price
  3590. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  3591. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  3592. warehouseOutInfo.Count = 1
  3593. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3594. if err == nil {
  3595. details := &models.AutomaticReduceDetail{
  3596. WarehouseOutId: warehouseOutInfo.ID,
  3597. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3598. PatientId: patientID,
  3599. Ctime: time.Now().Unix(),
  3600. Mtime: time.Now().Unix(),
  3601. Status: 1,
  3602. RecordTime: startDate.Unix(),
  3603. OrgId: adminUserInfo.Org.Id,
  3604. GoodId: prescription.TubingHemodialysis,
  3605. GoodTypeId: tubingHemodialysis,
  3606. }
  3607. service.AddSigleAutoReduceRecordInfo(details)
  3608. }
  3609. } else if err == nil { //记录存在,则将耗材使用数量加1
  3610. if outInfo.ID > 0 {
  3611. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3612. }
  3613. //插入病人耗材使用记录
  3614. details := &models.AutomaticReduceDetail{
  3615. WarehouseOutId: outInfo.ID,
  3616. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3617. PatientId: patientID,
  3618. Ctime: time.Now().Unix(),
  3619. Mtime: time.Now().Unix(),
  3620. Status: 1,
  3621. RecordTime: startDate.Unix(),
  3622. OrgId: adminUserInfo.Org.Id,
  3623. GoodId: prescription.TubingHemodialysis,
  3624. GoodTypeId: tubingHemodialysis,
  3625. }
  3626. service.AddSigleAutoReduceRecordInfo(details)
  3627. }
  3628. }
  3629. if prescription.Package > 0 {
  3630. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, safe_package, prescription.Package, out.WarehouseOutOrderNumber)
  3631. if err == gorm.ErrRecordNotFound {
  3632. warehouseOutInfo := &models.WarehouseOutInfo{
  3633. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3634. WarehouseOutId: out.ID,
  3635. Status: 1,
  3636. Ctime: time.Now().Unix(),
  3637. Remark: "",
  3638. OrgId: adminUserInfo.Org.Id,
  3639. Type: 1,
  3640. Manufacturer: 0,
  3641. Dealer: 0,
  3642. IsSys: 1,
  3643. SysRecordTime: startDate.Unix(),
  3644. }
  3645. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  3646. warehouseOutInfo.Price = stockInInfo.Price
  3647. warehouseOutInfo.GoodId = prescription.Package
  3648. warehouseOutInfo.GoodTypeId = safe_package
  3649. warehouseOutInfo.Count = 1
  3650. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3651. if err == nil {
  3652. details := &models.AutomaticReduceDetail{
  3653. WarehouseOutId: warehouseOutInfo.ID,
  3654. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3655. PatientId: patientID,
  3656. Ctime: time.Now().Unix(),
  3657. Mtime: time.Now().Unix(),
  3658. Status: 1,
  3659. RecordTime: startDate.Unix(),
  3660. OrgId: adminUserInfo.Org.Id,
  3661. GoodId: prescription.Package,
  3662. GoodTypeId: safe_package,
  3663. }
  3664. service.AddSigleAutoReduceRecordInfo(details)
  3665. }
  3666. } else if err == nil { //记录存在,则将耗材使用数量加1
  3667. if outInfo.ID > 0 {
  3668. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3669. }
  3670. //插入病人耗材使用记录
  3671. details := &models.AutomaticReduceDetail{
  3672. WarehouseOutId: outInfo.ID,
  3673. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3674. PatientId: patientID,
  3675. Ctime: time.Now().Unix(),
  3676. Mtime: time.Now().Unix(),
  3677. Status: 1,
  3678. RecordTime: startDate.Unix(),
  3679. OrgId: adminUserInfo.Org.Id,
  3680. GoodId: prescription.Package,
  3681. GoodTypeId: safe_package,
  3682. }
  3683. service.AddSigleAutoReduceRecordInfo(details)
  3684. }
  3685. }
  3686. if prescription.ALiquid > 0 {
  3687. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, aliquid, prescription.ALiquid, out.WarehouseOutOrderNumber)
  3688. if err == gorm.ErrRecordNotFound {
  3689. warehouseOutInfo := &models.WarehouseOutInfo{
  3690. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3691. WarehouseOutId: out.ID,
  3692. Status: 1,
  3693. Ctime: time.Now().Unix(),
  3694. Remark: "",
  3695. OrgId: adminUserInfo.Org.Id,
  3696. Type: 1,
  3697. Manufacturer: 0,
  3698. Dealer: 0,
  3699. IsSys: 1,
  3700. SysRecordTime: startDate.Unix(),
  3701. }
  3702. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  3703. warehouseOutInfo.Price = stockInInfo.Price
  3704. warehouseOutInfo.GoodId = prescription.ALiquid
  3705. warehouseOutInfo.GoodTypeId = aliquid
  3706. warehouseOutInfo.Count = 1
  3707. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3708. if err == nil {
  3709. details := &models.AutomaticReduceDetail{
  3710. WarehouseOutId: warehouseOutInfo.ID,
  3711. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3712. PatientId: patientID,
  3713. Ctime: time.Now().Unix(),
  3714. Mtime: time.Now().Unix(),
  3715. Status: 1,
  3716. RecordTime: startDate.Unix(),
  3717. OrgId: adminUserInfo.Org.Id,
  3718. GoodId: prescription.ALiquid,
  3719. GoodTypeId: aliquid,
  3720. }
  3721. service.AddSigleAutoReduceRecordInfo(details)
  3722. }
  3723. } else if err == nil { //记录存在,则将耗材使用数量加1
  3724. if outInfo.ID > 0 {
  3725. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3726. }
  3727. //插入病人耗材使用记录
  3728. details := &models.AutomaticReduceDetail{
  3729. WarehouseOutId: outInfo.ID,
  3730. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3731. PatientId: patientID,
  3732. Ctime: time.Now().Unix(),
  3733. Mtime: time.Now().Unix(),
  3734. Status: 1,
  3735. RecordTime: startDate.Unix(),
  3736. OrgId: adminUserInfo.Org.Id,
  3737. GoodId: prescription.ALiquid,
  3738. GoodTypeId: aliquid,
  3739. }
  3740. service.AddSigleAutoReduceRecordInfo(details)
  3741. }
  3742. }
  3743. }
  3744. }
  3745. } else {
  3746. this.ErrorLog("上机失败,还没开处方")
  3747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  3748. return
  3749. }
  3750. }
  3751. if createErr != nil {
  3752. this.ErrorLog("上机失败:%v", createErr)
  3753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3754. return
  3755. }
  3756. this.ServeSuccessJSON(map[string]interface{}{
  3757. "dialysis_order": newdialysisRecord,
  3758. "monitor": record,
  3759. })
  3760. }
  3761. func (c *DialysisAPIController) PostSolution() {
  3762. id, _ := c.GetInt64("patient", 0)
  3763. recordDateStr := c.GetString("record_date")
  3764. if id <= 0 {
  3765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3766. return
  3767. }
  3768. adminUserInfo := c.GetMobileAdminUserInfo()
  3769. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3770. if patient.ID == 0 {
  3771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3772. return
  3773. }
  3774. if len(recordDateStr) == 0 {
  3775. recordDateStr = time.Now().Format("2006-01-02")
  3776. }
  3777. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3778. if parseDateErr != nil {
  3779. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3781. return
  3782. }
  3783. mode_id, _ := c.GetInt64("mode_id", 0)
  3784. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3785. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3786. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3787. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3788. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3789. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3790. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3791. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3792. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3793. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3794. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3795. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3796. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3797. kalium, _ := c.GetFloat("kalium", 0)
  3798. sodium, _ := c.GetFloat("sodium", 0)
  3799. calcium, _ := c.GetFloat("calcium", 0)
  3800. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3801. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3802. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3803. glucose, _ := c.GetFloat("glucose", 0)
  3804. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3805. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3806. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3807. conductivity, _ := c.GetFloat("conductivity", 0)
  3808. remark := c.GetString("remark")
  3809. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3810. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3811. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3812. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3813. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3814. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3815. special_medicine_other := c.GetString("special_medicine_other")
  3816. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3817. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3818. blood_access, _ := c.GetInt64("blood_access", 0)
  3819. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3820. body_fluid_other := c.GetString("body_fluid_other")
  3821. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3822. niprocart, _ := c.GetInt64("niprocart", 0)
  3823. jms, _ := c.GetInt64("jms", 0)
  3824. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3825. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3826. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3827. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3828. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3829. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3830. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3831. injector, _ := c.GetInt64("injector", 0)
  3832. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3833. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3834. safe_package, _ := c.GetInt64("package", 0)
  3835. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3836. if mode_id > 0 {
  3837. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  3838. }
  3839. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3840. //
  3841. //if appRole.UserType == 2 || appRole.UserType == 1 {
  3842. // prescription_doctor = appRole.AdminUserId
  3843. //} else {
  3844. // prescription_doctor = 0
  3845. //}
  3846. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3847. //
  3848. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3849. // if appRole.UserType == 3 {
  3850. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3851. // if getPermissionErr != nil {
  3852. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3853. // return
  3854. // } else if headNursePermission == nil {
  3855. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3856. // return
  3857. // }
  3858. // }
  3859. //}
  3860. prescription := models.DialysisPrescription{
  3861. UserOrgId: adminUserInfo.Org.Id,
  3862. PatientId: id,
  3863. RecordDate: recordDate.Unix(),
  3864. ModeId: mode_id,
  3865. DialysisDuration: dialysis_duration,
  3866. Dialyzer: dialyzer,
  3867. PerfusionApparatus: perfusion_apparatus,
  3868. BloodFlowVolume: blood_flow_volume,
  3869. DewaterAmount: dewater_amount,
  3870. DisplaceLiqui: displace_liqui,
  3871. ReplacementWay: replacement_way,
  3872. Anticoagulant: anticoagulant,
  3873. AnticoagulantShouji: anticoagulant_shouji,
  3874. AnticoagulantWeichi: anticoagulant_weichi,
  3875. AnticoagulantZongliang: anticoagulant_zongliang,
  3876. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3877. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3878. Kalium: kalium,
  3879. Sodium: sodium,
  3880. Calcium: calcium,
  3881. Bicarbonate: bicarbonate,
  3882. Glucose: glucose,
  3883. // DryWeight: dry_weight,
  3884. DialysateFlow: dialysate_flow,
  3885. DialysateTemperature: dialysate_temperature,
  3886. Conductivity: conductivity,
  3887. Remark: remark,
  3888. PrescriptionDoctor: prescription_doctor,
  3889. Status: 1,
  3890. CreatedTime: time.Now().Unix(),
  3891. UpdatedTime: time.Now().Unix(),
  3892. DialysisDurationMinute: dialysisDurationMinute,
  3893. DialysisDurationHour: dialysisDurationHour,
  3894. TargetUltrafiltration: targetUltrafiltration,
  3895. DialysateFormulation: dialysateFormulation,
  3896. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3897. BodyFluid: body_fluid,
  3898. SpecialMedicine: special_medicine,
  3899. SpecialMedicineOther: special_medicine_other,
  3900. DisplaceLiquiPart: displace_liqui_part,
  3901. DisplaceLiquiValue: displace_liqui_value,
  3902. BloodAccess: blood_access,
  3903. Ultrafiltration: ultrafiltration,
  3904. BodyFluidOther: body_fluid_other,
  3905. ReplacementTotal: replacement_total,
  3906. Niprocart: niprocart,
  3907. Jms: jms,
  3908. FistulaNeedleSet: fistula_needle_set,
  3909. FistulaNeedleSet16: fistula_needle_set_16,
  3910. Hemoperfusion: hemoperfusion,
  3911. DialyserSterilised: dialyser_sterilised,
  3912. Filtryzer: filtryzer,
  3913. TargetKtv: target_ktv,
  3914. Dialyzers: dialyzers,
  3915. Injector: injector,
  3916. Bloodlines: bloodlines,
  3917. TubingHemodialysis: tubing_hemodialysis,
  3918. Package: safe_package,
  3919. ALiquid: a_liquid,
  3920. }
  3921. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3922. if dialysisPrescription.ID == 0 { //新增
  3923. prescription.Creater = adminUserInfo.AdminUser.Id
  3924. } else { //修改
  3925. prescription.Creater = adminUserInfo.AdminUser.Id
  3926. //if/**/
  3927. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3928. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3929. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3930. // if getPermissionErr != nil {
  3931. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3932. // return
  3933. // } else if headNursePermission == nil {
  3934. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3935. // return
  3936. // }
  3937. //}
  3938. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  3939. if record.IsOpen == 1 {
  3940. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  3941. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  3942. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  3943. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  3944. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  3945. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  3946. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  3947. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  3948. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  3949. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  3950. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  3951. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  3952. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  3953. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  3954. if err == nil {
  3955. if order.ID > 0 {
  3956. if dialysisPrescription.Niprocart != niprocart {
  3957. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  3958. //1.用上机透析日期查出当天的订单
  3959. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  3960. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  3961. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3962. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3963. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3964. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3965. warehouseOutInfo := &models.WarehouseOutInfo{
  3966. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3967. WarehouseOutId: out.ID,
  3968. Count: 1,
  3969. Status: 1,
  3970. Ctime: time.Now().Unix(),
  3971. Remark: "",
  3972. OrgId: adminUserInfo.Org.Id,
  3973. Type: 1,
  3974. Manufacturer: 0,
  3975. Dealer: 0,
  3976. IsSys: 1,
  3977. SysRecordTime: order.StartTime,
  3978. }
  3979. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  3980. warehouseOutInfo.Price = stockInInfo.Price
  3981. warehouseOutInfo.GoodId = niprocart
  3982. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  3983. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3984. if err == nil {
  3985. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3986. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  3987. if err == gorm.ErrRecordNotFound {
  3988. details := &models.AutomaticReduceDetail{
  3989. WarehouseOutId: warehouseOutInfo.ID,
  3990. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3991. PatientId: id,
  3992. Ctime: time.Now().Unix(),
  3993. Mtime: time.Now().Unix(),
  3994. Status: 1,
  3995. RecordTime: order.StartTime,
  3996. OrgId: adminUserInfo.Org.Id,
  3997. GoodId: niprocart,
  3998. GoodTypeId: niprocart_good_type_id,
  3999. }
  4000. service.AddSigleAutoReduceRecordInfo(details)
  4001. } else if err == nil {
  4002. if user.ID > 0 {
  4003. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  4004. }
  4005. }
  4006. }
  4007. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4008. if newOut.ID > 0 {
  4009. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4010. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4011. if err == gorm.ErrRecordNotFound {
  4012. details := &models.AutomaticReduceDetail{
  4013. WarehouseOutId: newOut.ID,
  4014. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4015. PatientId: id,
  4016. Ctime: time.Now().Unix(),
  4017. Mtime: time.Now().Unix(),
  4018. Status: 1,
  4019. RecordTime: order.StartTime,
  4020. OrgId: adminUserInfo.Org.Id,
  4021. GoodId: niprocart,
  4022. GoodTypeId: niprocart_good_type_id,
  4023. }
  4024. service.AddSigleAutoReduceRecordInfo(details)
  4025. } else if err == nil {
  4026. if user.ID > 0 {
  4027. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  4028. }
  4029. }
  4030. }
  4031. }
  4032. }
  4033. if dialysisPrescription.Jms != jms {
  4034. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4035. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4036. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4037. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4038. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  4039. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4040. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4041. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4042. warehouseOutInfo := &models.WarehouseOutInfo{
  4043. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4044. WarehouseOutId: out.ID,
  4045. Count: 1,
  4046. Status: 1,
  4047. Ctime: time.Now().Unix(),
  4048. Remark: "",
  4049. OrgId: adminUserInfo.Org.Id,
  4050. Type: 1,
  4051. Manufacturer: 0,
  4052. Dealer: 0,
  4053. IsSys: 1,
  4054. SysRecordTime: order.StartTime,
  4055. }
  4056. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  4057. warehouseOutInfo.Price = stockInInfo.Price
  4058. warehouseOutInfo.GoodId = jms
  4059. warehouseOutInfo.GoodTypeId = jms_good_type_id
  4060. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4061. if err == nil {
  4062. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4063. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4064. if err == gorm.ErrRecordNotFound {
  4065. details := &models.AutomaticReduceDetail{
  4066. WarehouseOutId: warehouseOutInfo.ID,
  4067. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4068. PatientId: id,
  4069. Ctime: time.Now().Unix(),
  4070. Mtime: time.Now().Unix(),
  4071. Status: 1,
  4072. RecordTime: order.StartTime,
  4073. OrgId: adminUserInfo.Org.Id,
  4074. GoodId: jms,
  4075. GoodTypeId: jms_good_type_id,
  4076. }
  4077. service.AddSigleAutoReduceRecordInfo(details)
  4078. } else if err == nil {
  4079. if user.ID > 0 {
  4080. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4081. }
  4082. }
  4083. }
  4084. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4085. if newOut.ID > 0 {
  4086. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4087. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4088. if err == gorm.ErrRecordNotFound {
  4089. details := &models.AutomaticReduceDetail{
  4090. WarehouseOutId: newOut.ID,
  4091. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4092. PatientId: id,
  4093. Ctime: time.Now().Unix(),
  4094. Mtime: time.Now().Unix(),
  4095. Status: 1,
  4096. RecordTime: order.StartTime,
  4097. OrgId: adminUserInfo.Org.Id,
  4098. GoodId: jms,
  4099. GoodTypeId: jms_good_type_id,
  4100. }
  4101. service.AddSigleAutoReduceRecordInfo(details)
  4102. } else if err == nil {
  4103. if user.ID > 0 {
  4104. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  4105. }
  4106. }
  4107. }
  4108. }
  4109. }
  4110. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  4111. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4112. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4113. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4114. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4115. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  4116. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4117. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4118. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4119. warehouseOutInfo := &models.WarehouseOutInfo{
  4120. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4121. WarehouseOutId: out.ID,
  4122. Count: 1,
  4123. Status: 1,
  4124. Ctime: time.Now().Unix(),
  4125. Remark: "",
  4126. OrgId: adminUserInfo.Org.Id,
  4127. Type: 1,
  4128. Manufacturer: 0,
  4129. Dealer: 0,
  4130. IsSys: 1,
  4131. SysRecordTime: order.StartTime,
  4132. }
  4133. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  4134. warehouseOutInfo.Price = stockInInfo.Price
  4135. warehouseOutInfo.GoodId = fistula_needle_set
  4136. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  4137. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4138. if err == nil {
  4139. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4140. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4141. if err == gorm.ErrRecordNotFound {
  4142. details := &models.AutomaticReduceDetail{
  4143. WarehouseOutId: warehouseOutInfo.ID,
  4144. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4145. PatientId: id,
  4146. Ctime: time.Now().Unix(),
  4147. Mtime: time.Now().Unix(),
  4148. Status: 1,
  4149. RecordTime: order.StartTime,
  4150. OrgId: adminUserInfo.Org.Id,
  4151. GoodId: fistula_needle_set,
  4152. GoodTypeId: fistula_needle_set_good_type_id,
  4153. }
  4154. service.AddSigleAutoReduceRecordInfo(details)
  4155. } else if err == nil {
  4156. if user.ID > 0 {
  4157. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4158. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4159. }
  4160. }
  4161. }
  4162. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4163. if newOut.ID > 0 {
  4164. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4165. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4166. if err == gorm.ErrRecordNotFound {
  4167. details := &models.AutomaticReduceDetail{
  4168. WarehouseOutId: newOut.ID,
  4169. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4170. PatientId: id,
  4171. Ctime: time.Now().Unix(),
  4172. Mtime: time.Now().Unix(),
  4173. Status: 1,
  4174. RecordTime: order.StartTime,
  4175. OrgId: adminUserInfo.Org.Id,
  4176. GoodId: fistula_needle_set,
  4177. GoodTypeId: fistula_needle_set_good_type_id,
  4178. }
  4179. service.AddSigleAutoReduceRecordInfo(details)
  4180. } else if err == nil {
  4181. if user.ID > 0 {
  4182. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4183. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  4184. }
  4185. }
  4186. }
  4187. }
  4188. }
  4189. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  4190. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4191. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4192. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4193. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4194. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4195. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4196. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4197. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4198. warehouseOutInfo := &models.WarehouseOutInfo{
  4199. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4200. WarehouseOutId: out.ID,
  4201. Count: 1,
  4202. Status: 1,
  4203. Ctime: time.Now().Unix(),
  4204. Remark: "",
  4205. OrgId: adminUserInfo.Org.Id,
  4206. Type: 1,
  4207. Manufacturer: 0,
  4208. Dealer: 0,
  4209. IsSys: 1,
  4210. SysRecordTime: order.StartTime,
  4211. }
  4212. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  4213. warehouseOutInfo.Price = stockInInfo.Price
  4214. warehouseOutInfo.GoodId = fistula_needle_set_16
  4215. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  4216. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4217. if err == nil {
  4218. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4219. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4220. if err == gorm.ErrRecordNotFound {
  4221. details := &models.AutomaticReduceDetail{
  4222. WarehouseOutId: warehouseOutInfo.ID,
  4223. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4224. PatientId: id,
  4225. Ctime: time.Now().Unix(),
  4226. Mtime: time.Now().Unix(),
  4227. Status: 1,
  4228. RecordTime: order.StartTime,
  4229. OrgId: adminUserInfo.Org.Id,
  4230. GoodId: fistula_needle_set_16,
  4231. GoodTypeId: fistula_needle_set_16_good_type_id,
  4232. }
  4233. service.AddSigleAutoReduceRecordInfo(details)
  4234. } else if err == nil {
  4235. if user.ID > 0 {
  4236. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4237. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4238. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  4239. }
  4240. }
  4241. }
  4242. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4243. if newOut.ID > 0 {
  4244. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4245. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4246. if err == gorm.ErrRecordNotFound {
  4247. details := &models.AutomaticReduceDetail{
  4248. WarehouseOutId: newOut.ID,
  4249. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4250. PatientId: id,
  4251. Ctime: time.Now().Unix(),
  4252. Mtime: time.Now().Unix(),
  4253. Status: 1,
  4254. RecordTime: order.StartTime,
  4255. OrgId: adminUserInfo.Org.Id,
  4256. GoodId: fistula_needle_set_good_type_id,
  4257. GoodTypeId: fistula_needle_set_16_good_type_id,
  4258. }
  4259. service.AddSigleAutoReduceRecordInfo(details)
  4260. } else if err == nil {
  4261. if user.ID > 0 {
  4262. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  4263. }
  4264. }
  4265. }
  4266. }
  4267. }
  4268. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  4269. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4270. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4271. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4272. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4273. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  4274. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4275. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4276. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4277. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4278. warehouseOutInfo := &models.WarehouseOutInfo{
  4279. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4280. WarehouseOutId: out.ID,
  4281. Count: 1,
  4282. Status: 1,
  4283. Ctime: time.Now().Unix(),
  4284. Remark: "",
  4285. OrgId: adminUserInfo.Org.Id,
  4286. Type: 1,
  4287. Manufacturer: 0,
  4288. Dealer: 0,
  4289. IsSys: 1,
  4290. SysRecordTime: order.StartTime,
  4291. }
  4292. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  4293. warehouseOutInfo.Price = stockInInfo.Price
  4294. warehouseOutInfo.GoodId = hemoperfusion
  4295. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  4296. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4297. if err == nil {
  4298. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4299. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4300. if err == gorm.ErrRecordNotFound {
  4301. details := &models.AutomaticReduceDetail{
  4302. WarehouseOutId: warehouseOutInfo.ID,
  4303. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4304. PatientId: id,
  4305. Ctime: time.Now().Unix(),
  4306. Mtime: time.Now().Unix(),
  4307. Status: 1,
  4308. RecordTime: order.StartTime,
  4309. OrgId: adminUserInfo.Org.Id,
  4310. GoodId: hemoperfusion,
  4311. GoodTypeId: hemoperfusion_good_type_id,
  4312. }
  4313. service.AddSigleAutoReduceRecordInfo(details)
  4314. } else if err == nil {
  4315. if user.ID > 0 {
  4316. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4317. }
  4318. }
  4319. }
  4320. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4321. if newOut.ID > 0 {
  4322. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4323. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4324. if err == gorm.ErrRecordNotFound {
  4325. details := &models.AutomaticReduceDetail{
  4326. WarehouseOutId: newOut.ID,
  4327. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4328. PatientId: id,
  4329. Ctime: time.Now().Unix(),
  4330. Mtime: time.Now().Unix(),
  4331. Status: 1,
  4332. RecordTime: order.StartTime,
  4333. OrgId: adminUserInfo.Org.Id,
  4334. GoodId: hemoperfusion,
  4335. GoodTypeId: hemoperfusion_good_type_id,
  4336. }
  4337. service.AddSigleAutoReduceRecordInfo(details)
  4338. } else if err == nil {
  4339. if user.ID > 0 {
  4340. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  4341. }
  4342. }
  4343. }
  4344. }
  4345. }
  4346. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  4347. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4348. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4349. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4350. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  4351. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4352. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4353. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4354. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4355. warehouseOutInfo := &models.WarehouseOutInfo{
  4356. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4357. WarehouseOutId: out.WarehouseOutId,
  4358. Count: 1,
  4359. Status: 1,
  4360. Ctime: time.Now().Unix(),
  4361. Remark: "",
  4362. OrgId: adminUserInfo.Org.Id,
  4363. Type: 1,
  4364. Manufacturer: 0,
  4365. Dealer: 0,
  4366. IsSys: 1,
  4367. SysRecordTime: order.StartTime,
  4368. }
  4369. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  4370. warehouseOutInfo.Price = stockInInfo.Price
  4371. warehouseOutInfo.GoodId = dialyser_sterilised
  4372. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  4373. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4374. if err == nil {
  4375. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4376. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4377. if err == gorm.ErrRecordNotFound {
  4378. details := &models.AutomaticReduceDetail{
  4379. WarehouseOutId: warehouseOutInfo.ID,
  4380. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4381. PatientId: id,
  4382. Ctime: time.Now().Unix(),
  4383. Mtime: time.Now().Unix(),
  4384. Status: 1,
  4385. RecordTime: order.StartTime,
  4386. OrgId: adminUserInfo.Org.Id,
  4387. GoodId: dialyser_sterilised,
  4388. GoodTypeId: dialyser_sterilised_good_type_id,
  4389. }
  4390. service.AddSigleAutoReduceRecordInfo(details)
  4391. } else if err == nil {
  4392. if user.ID > 0 {
  4393. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4394. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  4395. }
  4396. }
  4397. }
  4398. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4399. if newOut.ID > 0 {
  4400. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4401. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4402. if err == gorm.ErrRecordNotFound {
  4403. details := &models.AutomaticReduceDetail{
  4404. WarehouseOutId: newOut.ID,
  4405. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4406. PatientId: id,
  4407. Ctime: time.Now().Unix(),
  4408. Mtime: time.Now().Unix(),
  4409. Status: 1,
  4410. RecordTime: order.StartTime,
  4411. OrgId: adminUserInfo.Org.Id,
  4412. GoodId: dialyser_sterilised,
  4413. GoodTypeId: dialyser_sterilised_good_type_id,
  4414. }
  4415. service.AddSigleAutoReduceRecordInfo(details)
  4416. } else if err == nil {
  4417. if user.ID > 0 {
  4418. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  4419. }
  4420. }
  4421. }
  4422. }
  4423. }
  4424. if dialysisPrescription.Filtryzer != filtryzer {
  4425. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4426. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4427. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4428. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4429. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  4430. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4431. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4432. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4433. warehouseOutInfo := &models.WarehouseOutInfo{
  4434. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4435. WarehouseOutId: out.ID,
  4436. Count: 1,
  4437. Status: 1,
  4438. Ctime: time.Now().Unix(),
  4439. Remark: "",
  4440. OrgId: adminUserInfo.Org.Id,
  4441. Type: 1,
  4442. Manufacturer: 0,
  4443. Dealer: 0,
  4444. IsSys: 1,
  4445. SysRecordTime: order.StartTime,
  4446. }
  4447. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  4448. warehouseOutInfo.Price = stockInInfo.Price
  4449. warehouseOutInfo.GoodId = filtryzer
  4450. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  4451. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4452. if err == nil {
  4453. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4454. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4455. if err == gorm.ErrRecordNotFound {
  4456. details := &models.AutomaticReduceDetail{
  4457. WarehouseOutId: warehouseOutInfo.ID,
  4458. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4459. PatientId: id,
  4460. Ctime: time.Now().Unix(),
  4461. Mtime: time.Now().Unix(),
  4462. Status: 1,
  4463. RecordTime: order.StartTime,
  4464. OrgId: adminUserInfo.Org.Id,
  4465. GoodId: filtryzer,
  4466. GoodTypeId: filtryzer_good_type_id,
  4467. }
  4468. service.AddSigleAutoReduceRecordInfo(details)
  4469. } else if err == nil {
  4470. if user.ID > 0 {
  4471. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  4472. }
  4473. }
  4474. }
  4475. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4476. if newOut.ID > 0 {
  4477. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4478. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4479. if err == gorm.ErrRecordNotFound {
  4480. details := &models.AutomaticReduceDetail{
  4481. WarehouseOutId: newOut.ID,
  4482. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4483. PatientId: id,
  4484. Ctime: time.Now().Unix(),
  4485. Mtime: time.Now().Unix(),
  4486. Status: 1,
  4487. RecordTime: order.StartTime,
  4488. OrgId: adminUserInfo.Org.Id,
  4489. GoodId: filtryzer,
  4490. GoodTypeId: filtryzer_good_type_id,
  4491. }
  4492. service.AddSigleAutoReduceRecordInfo(details)
  4493. } else if err == nil {
  4494. if user.ID > 0 {
  4495. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  4496. }
  4497. }
  4498. }
  4499. }
  4500. }
  4501. if dialysisPrescription.Dialyzers != dialyzers {
  4502. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4503. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4504. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4505. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4506. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4507. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4508. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4509. warehouseOutInfo := &models.WarehouseOutInfo{
  4510. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4511. WarehouseOutId: out.ID,
  4512. Count: 1,
  4513. Status: 1,
  4514. Ctime: time.Now().Unix(),
  4515. Remark: "",
  4516. OrgId: adminUserInfo.Org.Id,
  4517. Type: 1,
  4518. Manufacturer: 0,
  4519. Dealer: 0,
  4520. IsSys: 1,
  4521. SysRecordTime: order.StartTime,
  4522. }
  4523. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  4524. warehouseOutInfo.Price = stockInInfo.Price
  4525. warehouseOutInfo.GoodId = dialyzers
  4526. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  4527. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4528. if err == nil {
  4529. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4530. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4531. if err == gorm.ErrRecordNotFound {
  4532. details := &models.AutomaticReduceDetail{
  4533. WarehouseOutId: warehouseOutInfo.ID,
  4534. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4535. PatientId: id,
  4536. Ctime: time.Now().Unix(),
  4537. Mtime: time.Now().Unix(),
  4538. Status: 1,
  4539. RecordTime: order.StartTime,
  4540. OrgId: adminUserInfo.Org.Id,
  4541. GoodId: dialyzers,
  4542. GoodTypeId: dialyzers_good_type_id,
  4543. }
  4544. service.AddSigleAutoReduceRecordInfo(details)
  4545. } else if err == nil {
  4546. if user.ID > 0 {
  4547. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  4548. }
  4549. }
  4550. }
  4551. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4552. if newOut.ID > 0 {
  4553. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4554. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4555. if err == gorm.ErrRecordNotFound {
  4556. details := &models.AutomaticReduceDetail{
  4557. WarehouseOutId: newOut.ID,
  4558. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4559. PatientId: id,
  4560. Ctime: time.Now().Unix(),
  4561. Mtime: time.Now().Unix(),
  4562. Status: 1,
  4563. RecordTime: order.StartTime,
  4564. OrgId: adminUserInfo.Org.Id,
  4565. GoodId: dialyzers,
  4566. GoodTypeId: dialyzers_good_type_id,
  4567. }
  4568. service.AddSigleAutoReduceRecordInfo(details)
  4569. } else if err == nil {
  4570. if user.ID > 0 {
  4571. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  4572. }
  4573. }
  4574. }
  4575. }
  4576. }
  4577. if dialysisPrescription.Injector != injector {
  4578. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4579. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4580. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4581. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4582. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4583. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4584. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4585. warehouseOutInfo := &models.WarehouseOutInfo{
  4586. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4587. WarehouseOutId: out.ID,
  4588. Count: 1,
  4589. Status: 1,
  4590. Ctime: time.Now().Unix(),
  4591. Remark: "",
  4592. OrgId: adminUserInfo.Org.Id,
  4593. Type: 1,
  4594. Manufacturer: 0,
  4595. Dealer: 0,
  4596. IsSys: 1,
  4597. SysRecordTime: order.StartTime,
  4598. }
  4599. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  4600. warehouseOutInfo.Price = stockInInfo.Price
  4601. warehouseOutInfo.GoodId = injector
  4602. warehouseOutInfo.GoodTypeId = injector_good_type_id
  4603. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4604. if err == nil {
  4605. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4606. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4607. if err == gorm.ErrRecordNotFound {
  4608. details := &models.AutomaticReduceDetail{
  4609. WarehouseOutId: warehouseOutInfo.ID,
  4610. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4611. PatientId: id,
  4612. Ctime: time.Now().Unix(),
  4613. Mtime: time.Now().Unix(),
  4614. Status: 1,
  4615. RecordTime: order.StartTime,
  4616. OrgId: adminUserInfo.Org.Id,
  4617. GoodId: injector,
  4618. GoodTypeId: injector_good_type_id,
  4619. }
  4620. service.AddSigleAutoReduceRecordInfo(details)
  4621. } else if err == nil {
  4622. if user.ID > 0 {
  4623. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  4624. }
  4625. }
  4626. }
  4627. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4628. if newOut.ID > 0 {
  4629. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4630. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4631. if err == gorm.ErrRecordNotFound {
  4632. details := &models.AutomaticReduceDetail{
  4633. WarehouseOutId: newOut.ID,
  4634. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4635. PatientId: id,
  4636. Ctime: time.Now().Unix(),
  4637. Mtime: time.Now().Unix(),
  4638. Status: 1,
  4639. RecordTime: order.StartTime,
  4640. OrgId: adminUserInfo.Org.Id,
  4641. GoodId: injector,
  4642. GoodTypeId: injector_good_type_id,
  4643. }
  4644. service.AddSigleAutoReduceRecordInfo(details)
  4645. } else if err == nil {
  4646. if user.ID > 0 {
  4647. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  4648. }
  4649. }
  4650. }
  4651. }
  4652. }
  4653. if dialysisPrescription.Bloodlines != bloodlines {
  4654. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4655. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4656. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4657. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4658. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4659. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4660. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4661. warehouseOutInfo := &models.WarehouseOutInfo{
  4662. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4663. WarehouseOutId: out.ID,
  4664. Count: 1,
  4665. Status: 1,
  4666. Ctime: time.Now().Unix(),
  4667. Remark: "",
  4668. OrgId: adminUserInfo.Org.Id,
  4669. Type: 1,
  4670. Manufacturer: 0,
  4671. Dealer: 0,
  4672. IsSys: 1,
  4673. SysRecordTime: order.StartTime,
  4674. }
  4675. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  4676. warehouseOutInfo.Price = stockInInfo.Price
  4677. warehouseOutInfo.GoodId = bloodlines
  4678. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  4679. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4680. if err == nil {
  4681. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4682. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4683. if err == gorm.ErrRecordNotFound {
  4684. details := &models.AutomaticReduceDetail{
  4685. WarehouseOutId: warehouseOutInfo.ID,
  4686. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4687. PatientId: id,
  4688. Ctime: time.Now().Unix(),
  4689. Mtime: time.Now().Unix(),
  4690. Status: 1,
  4691. RecordTime: order.StartTime,
  4692. OrgId: adminUserInfo.Org.Id,
  4693. GoodId: bloodlines,
  4694. GoodTypeId: bloodlines_good_type_id,
  4695. }
  4696. service.AddSigleAutoReduceRecordInfo(details)
  4697. } else if err == nil {
  4698. if user.ID > 0 {
  4699. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  4700. }
  4701. }
  4702. }
  4703. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4704. if newOut.ID > 0 {
  4705. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4706. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4707. if err == gorm.ErrRecordNotFound {
  4708. details := &models.AutomaticReduceDetail{
  4709. WarehouseOutId: newOut.ID,
  4710. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4711. PatientId: id,
  4712. Ctime: time.Now().Unix(),
  4713. Mtime: time.Now().Unix(),
  4714. Status: 1,
  4715. RecordTime: order.StartTime,
  4716. OrgId: adminUserInfo.Org.Id,
  4717. GoodId: bloodlines,
  4718. GoodTypeId: bloodlines_good_type_id,
  4719. }
  4720. service.AddSigleAutoReduceRecordInfo(details)
  4721. } else if err == nil {
  4722. if user.ID > 0 {
  4723. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  4724. }
  4725. }
  4726. }
  4727. }
  4728. }
  4729. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  4730. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4731. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4732. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4733. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4734. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4735. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4736. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4737. warehouseOutInfo := &models.WarehouseOutInfo{
  4738. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4739. WarehouseOutId: out.ID,
  4740. Count: 1,
  4741. Status: 1,
  4742. Ctime: time.Now().Unix(),
  4743. Remark: "",
  4744. OrgId: adminUserInfo.Org.Id,
  4745. Type: 1,
  4746. Manufacturer: 0,
  4747. Dealer: 0,
  4748. IsSys: 1,
  4749. SysRecordTime: order.StartTime,
  4750. }
  4751. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  4752. warehouseOutInfo.Price = stockInInfo.Price
  4753. warehouseOutInfo.GoodId = tubing_hemodialysis
  4754. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  4755. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4756. if err == nil {
  4757. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4758. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4759. if err == gorm.ErrRecordNotFound {
  4760. details := &models.AutomaticReduceDetail{
  4761. WarehouseOutId: warehouseOutInfo.ID,
  4762. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4763. PatientId: id,
  4764. Ctime: time.Now().Unix(),
  4765. Mtime: time.Now().Unix(),
  4766. Status: 1,
  4767. RecordTime: order.StartTime,
  4768. OrgId: adminUserInfo.Org.Id,
  4769. GoodId: tubing_hemodialysis,
  4770. GoodTypeId: tubingHemodialysis_good_type_id,
  4771. }
  4772. service.AddSigleAutoReduceRecordInfo(details)
  4773. } else if err == nil {
  4774. if user.ID > 0 {
  4775. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  4776. }
  4777. }
  4778. }
  4779. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4780. if newOut.ID > 0 {
  4781. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4782. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4783. if err == gorm.ErrRecordNotFound {
  4784. details := &models.AutomaticReduceDetail{
  4785. WarehouseOutId: newOut.ID,
  4786. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4787. PatientId: id,
  4788. Ctime: time.Now().Unix(),
  4789. Mtime: time.Now().Unix(),
  4790. Status: 1,
  4791. RecordTime: order.StartTime,
  4792. OrgId: adminUserInfo.Org.Id,
  4793. GoodId: tubing_hemodialysis,
  4794. GoodTypeId: tubingHemodialysis_good_type_id,
  4795. }
  4796. service.AddSigleAutoReduceRecordInfo(details)
  4797. } else if err == nil {
  4798. if user.ID > 0 {
  4799. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  4800. }
  4801. }
  4802. }
  4803. }
  4804. }
  4805. if dialysisPrescription.Package != safe_package {
  4806. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4807. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4808. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4809. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4810. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4811. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4812. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4813. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4814. warehouseOutInfo := &models.WarehouseOutInfo{
  4815. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4816. WarehouseOutId: out.ID,
  4817. Count: 1,
  4818. Status: 1,
  4819. Ctime: time.Now().Unix(),
  4820. Remark: "",
  4821. OrgId: adminUserInfo.Org.Id,
  4822. Type: 1,
  4823. Manufacturer: 0,
  4824. Dealer: 0,
  4825. IsSys: 1,
  4826. SysRecordTime: order.StartTime,
  4827. }
  4828. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  4829. warehouseOutInfo.Price = stockInInfo.Price
  4830. warehouseOutInfo.GoodId = safe_package
  4831. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  4832. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4833. if err == nil {
  4834. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4835. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4836. if err == gorm.ErrRecordNotFound {
  4837. details := &models.AutomaticReduceDetail{
  4838. WarehouseOutId: warehouseOutInfo.ID,
  4839. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4840. PatientId: id,
  4841. Ctime: time.Now().Unix(),
  4842. Mtime: time.Now().Unix(),
  4843. Status: 1,
  4844. RecordTime: order.StartTime,
  4845. OrgId: adminUserInfo.Org.Id,
  4846. GoodId: safe_package,
  4847. GoodTypeId: safe_package_good_type_id,
  4848. }
  4849. service.AddSigleAutoReduceRecordInfo(details)
  4850. } else if err == nil {
  4851. if user.ID > 0 {
  4852. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  4853. }
  4854. }
  4855. }
  4856. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4857. if newOut.ID > 0 {
  4858. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4859. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4860. if err == gorm.ErrRecordNotFound {
  4861. details := &models.AutomaticReduceDetail{
  4862. WarehouseOutId: newOut.ID,
  4863. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4864. PatientId: id,
  4865. Ctime: time.Now().Unix(),
  4866. Mtime: time.Now().Unix(),
  4867. Status: 1,
  4868. RecordTime: order.StartTime,
  4869. OrgId: adminUserInfo.Org.Id,
  4870. GoodId: safe_package,
  4871. GoodTypeId: safe_package_good_type_id,
  4872. }
  4873. service.AddSigleAutoReduceRecordInfo(details)
  4874. } else if err == nil {
  4875. if user.ID > 0 {
  4876. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  4877. }
  4878. }
  4879. }
  4880. }
  4881. }
  4882. if dialysisPrescription.ALiquid != a_liquid {
  4883. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4884. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4885. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4886. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4887. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4888. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4889. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4890. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4891. warehouseOutInfo := &models.WarehouseOutInfo{
  4892. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4893. WarehouseOutId: out.ID,
  4894. Count: 1,
  4895. Status: 1,
  4896. Ctime: time.Now().Unix(),
  4897. Remark: "",
  4898. OrgId: adminUserInfo.Org.Id,
  4899. Type: 1,
  4900. Manufacturer: 0,
  4901. Dealer: 0,
  4902. IsSys: 1,
  4903. SysRecordTime: order.StartTime,
  4904. }
  4905. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  4906. warehouseOutInfo.Price = stockInInfo.Price
  4907. warehouseOutInfo.GoodId = a_liquid
  4908. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  4909. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4910. if err == nil {
  4911. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4912. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4913. if err == gorm.ErrRecordNotFound {
  4914. details := &models.AutomaticReduceDetail{
  4915. WarehouseOutId: warehouseOutInfo.ID,
  4916. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4917. PatientId: id,
  4918. Ctime: time.Now().Unix(),
  4919. Mtime: time.Now().Unix(),
  4920. Status: 1,
  4921. RecordTime: order.StartTime,
  4922. OrgId: adminUserInfo.Org.Id,
  4923. GoodId: a_liquid,
  4924. GoodTypeId: aliquid_good_type_id,
  4925. }
  4926. service.AddSigleAutoReduceRecordInfo(details)
  4927. } else if err == nil {
  4928. if user.ID > 0 {
  4929. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  4930. }
  4931. }
  4932. }
  4933. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4934. if newOut.ID > 0 {
  4935. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4936. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4937. if err == gorm.ErrRecordNotFound {
  4938. details := &models.AutomaticReduceDetail{
  4939. WarehouseOutId: newOut.ID,
  4940. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4941. PatientId: id,
  4942. Ctime: time.Now().Unix(),
  4943. Mtime: time.Now().Unix(),
  4944. Status: 1,
  4945. RecordTime: order.StartTime,
  4946. OrgId: adminUserInfo.Org.Id,
  4947. GoodId: a_liquid,
  4948. GoodTypeId: aliquid_good_type_id,
  4949. }
  4950. service.AddSigleAutoReduceRecordInfo(details)
  4951. } else if err == nil {
  4952. if user.ID > 0 {
  4953. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  4954. }
  4955. }
  4956. }
  4957. }
  4958. }
  4959. }
  4960. }
  4961. }
  4962. //prescription.Creater = dialysisPrescription.Creater
  4963. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4964. prescription.Modifier = adminUserInfo.AdminUser.Id
  4965. prescription.ID = dialysisPrescription.ID
  4966. }
  4967. solution := models.DialysisSolution{
  4968. RegistrarsId: adminUserInfo.AdminUser.Id,
  4969. UserOrgId: adminUserInfo.Org.Id,
  4970. Doctor: prescription_doctor,
  4971. PatientId: id,
  4972. ModeId: mode_id,
  4973. DialysisDuration: dialysis_duration,
  4974. PerfusionApparatus: perfusion_apparatus,
  4975. BloodFlowVolume: blood_flow_volume,
  4976. Dewater: dewater_amount,
  4977. DisplaceLiqui: displace_liqui,
  4978. ReplacementWay: replacement_way,
  4979. Anticoagulant: anticoagulant,
  4980. AnticoagulantShouji: anticoagulant_shouji,
  4981. AnticoagulantWeichi: anticoagulant_weichi,
  4982. AnticoagulantZongliang: anticoagulant_zongliang,
  4983. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4984. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4985. Kalium: kalium,
  4986. Sodium: sodium,
  4987. Calcium: calcium,
  4988. Bicarbonate: bicarbonate,
  4989. Glucose: glucose,
  4990. // DryWeight: dry_weight,
  4991. DialysateFlow: dialysate_flow,
  4992. DialysateTemperature: dialysate_temperature,
  4993. Conductivity: conductivity,
  4994. Remark: remark,
  4995. Status: 1,
  4996. CreatedTime: time.Now().Unix(),
  4997. UpdatedTime: time.Now().Unix(),
  4998. DialysisDurationMinute: dialysisDurationMinute,
  4999. DialysisDurationHour: dialysisDurationHour,
  5000. TargetUltrafiltration: targetUltrafiltration,
  5001. DialysateFormulation: dialysateFormulation,
  5002. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  5003. BodyFluid: body_fluid,
  5004. SpecialMedicine: special_medicine,
  5005. SpecialMedicineOther: special_medicine_other,
  5006. DisplaceLiquiPart: displace_liqui_part,
  5007. DisplaceLiquiValue: displace_liqui_value,
  5008. BloodAccess: blood_access,
  5009. Ultrafiltration: ultrafiltration,
  5010. BodyFluidOther: body_fluid_other,
  5011. ReplacementTotal: replacement_total,
  5012. TargetKtv: target_ktv,
  5013. }
  5014. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  5015. c.ServeSuccessJSON(map[string]interface{}{
  5016. "solution": &solution,
  5017. "prescription": &prescription,
  5018. })
  5019. }
  5020. func (c *DialysisAPIController) GetAcceptsAssessment() {
  5021. patient, _ := c.GetInt64("patient", 0)
  5022. adminUserInfo := c.GetMobileAdminUserInfo()
  5023. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  5024. c.ServeSuccessJSON(map[string]interface{}{
  5025. "receiveTreatmentAsses": receiveTreatmentAsses,
  5026. })
  5027. }
  5028. func (this *DialysisAPIController) PostSignInfo() {
  5029. patientID, _ := this.GetInt64("patient_id")
  5030. recordDateStr := this.GetString("date")
  5031. if patientID <= 0 {
  5032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5033. return
  5034. }
  5035. if len(recordDateStr) == 0 {
  5036. recordDateStr = time.Now().Format("2006-01-02")
  5037. }
  5038. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5039. if parseDateErr != nil {
  5040. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  5041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5042. return
  5043. }
  5044. adminInfo := this.GetMobileAdminUserInfo()
  5045. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  5046. if err != nil {
  5047. this.ErrorLog("签名失败:%v", err)
  5048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5049. return
  5050. }
  5051. this.ServeSuccessJSON(map[string]interface{}{
  5052. "doctor_id": adminInfo.AdminUser.Id,
  5053. })
  5054. }
  5055. func (this *DialysisAPIController) GetLastMonitorRecord() {
  5056. patientID, _ := this.GetInt64("patient_id")
  5057. adminInfo := this.GetMobileAdminUserInfo()
  5058. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  5059. this.ServeSuccessJSON(map[string]interface{}{
  5060. "monitor": record,
  5061. })
  5062. }
  5063. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  5064. thisTime := time.Now()
  5065. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  5066. timeLayout := "2006-01-02 15:04:05"
  5067. loc, _ := time.LoadLocation("Local")
  5068. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5069. theAssessmentDateTime := theStartTime.Unix()
  5070. patientID, _ := this.GetInt64("patient_id")
  5071. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  5072. adminInfo := this.GetMobileAdminUserInfo()
  5073. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  5074. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  5075. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  5076. var ultrafiltration_rate float64
  5077. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  5078. if prescription.ID > 0 {
  5079. fmt.Println("444444444")
  5080. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  5081. fmt.Println("4444444445555")
  5082. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5083. if template.TemplateId == 6 {
  5084. fmt.Println("12222222")
  5085. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5086. record.UltrafiltrationRate = ultrafiltration_rate
  5087. }
  5088. if template.TemplateId == 20 || template.TemplateId == 22 {
  5089. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5090. record.UltrafiltrationRate = ultrafiltration_rate
  5091. }
  5092. // 只针对方济医院
  5093. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  5094. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  5095. ultrafiltration_rate = value
  5096. record.UltrafiltrationRate = ultrafiltration_rate
  5097. }
  5098. }
  5099. }
  5100. // record.UltrafiltrationRate = ultrafiltration_rate
  5101. record.UltrafiltrationVolume = 0
  5102. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  5103. if ultrafiltration_rate > 0 {
  5104. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  5105. record.UltrafiltrationVolume = value
  5106. }
  5107. }
  5108. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 { //adminInfo.Org.Id == 9538
  5109. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  5110. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5111. record.UltrafiltrationVolume = ultrafiltration_volume
  5112. }
  5113. }
  5114. this.ServeSuccessJSON(map[string]interface{}{
  5115. "monitor": record,
  5116. })
  5117. }
  5118. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5119. record_id, _ := this.GetInt64("id")
  5120. nurseID, _ := this.GetInt64("nurse")
  5121. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5122. bedID, _ := this.GetInt64("bed")
  5123. start_time := this.GetString("start_time")
  5124. schedual_type, _ := this.GetInt64("schedual_type")
  5125. if record_id == 0 {
  5126. this.ErrorLog("id:%v", record_id)
  5127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5128. return
  5129. }
  5130. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5131. if parseStartDateErr != nil {
  5132. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5134. return
  5135. }
  5136. adminUserInfo := this.GetMobileAdminUserInfo()
  5137. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5138. if getNurseErr != nil {
  5139. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5140. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5141. return
  5142. } else if nurse == nil {
  5143. this.ErrorLog("护士不存在")
  5144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5145. return
  5146. }
  5147. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5148. if getNurseErr != nil {
  5149. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5151. return
  5152. } else if nurse == nil {
  5153. this.ErrorLog("护士不存在")
  5154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5155. return
  5156. }
  5157. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5158. if getDeviceNumberErr != nil {
  5159. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5161. return
  5162. } else if deviceNumber == nil {
  5163. this.ErrorLog("床位号不存在")
  5164. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5165. return
  5166. }
  5167. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5168. //
  5169. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5170. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5171. // if getPermissionErr != nil {
  5172. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5173. // return
  5174. // } else if headNursePermission == nil {
  5175. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5176. // return
  5177. // }
  5178. //}
  5179. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5180. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5181. timeLayout := "2006-01-02 15:04:05"
  5182. loc, _ := time.LoadLocation("Local")
  5183. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5184. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5185. schedulestartTime := theStartTime.Unix()
  5186. scheduleendTime := theEndTime.Unix()
  5187. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5188. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5189. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5190. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5191. if err == gorm.ErrRecordNotFound { //空床位
  5192. // 修改了床位逻辑
  5193. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5194. if daySchedule.ID > 0 {
  5195. daySchedule.BedId = bedID
  5196. daySchedule.PartitionId = deviceNumber.ZoneID
  5197. daySchedule.ScheduleType = schedual_type
  5198. daySchedule.UpdatedTime = time.Now().Unix()
  5199. err := service.UpdateSchedule(&daySchedule)
  5200. if err != nil {
  5201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5202. return
  5203. }
  5204. }
  5205. } else if err == nil {
  5206. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5207. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5208. if daySchedule.ID > 0 {
  5209. daySchedule.BedId = bedID
  5210. daySchedule.PartitionId = deviceNumber.ZoneID
  5211. daySchedule.ScheduleType = schedual_type
  5212. daySchedule.UpdatedTime = time.Now().Unix()
  5213. err := service.UpdateSchedule(&daySchedule)
  5214. if err != nil {
  5215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5216. return
  5217. }
  5218. }
  5219. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5221. return
  5222. }
  5223. } else if err != nil {
  5224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5225. return
  5226. }
  5227. }
  5228. dialysisRecord := &models.DialysisOrder{
  5229. ID: record_id,
  5230. UserOrgId: adminUserInfo.Org.Id,
  5231. BedID: bedID,
  5232. StartNurse: nurseID,
  5233. StartTime: startDate.Unix(),
  5234. PunctureNurse: puncture_nurse,
  5235. Creator: adminUserInfo.AdminUser.Id,
  5236. Modifier: adminUserInfo.AdminUser.Id,
  5237. SchedualType: schedual_type,
  5238. }
  5239. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5240. if updateErr != nil {
  5241. this.ErrorLog("修改上机失败:%v", updateErr)
  5242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5243. return
  5244. }
  5245. if updateErr == nil {
  5246. if tempDialysisRecord.Stage == 2 {
  5247. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5248. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5249. fmt.Println(value)
  5250. a, b := math.Modf(value)
  5251. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5252. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5253. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5254. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5255. if updateAssessmentErr != nil {
  5256. utils.ErrorLog("%v", updateAssessmentErr)
  5257. }
  5258. }
  5259. }
  5260. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5261. this.ServeSuccessJSON(map[string]interface{}{
  5262. "dialysis_order": dialysisRecords,
  5263. })
  5264. }
  5265. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5266. record_id, _ := c.GetInt64("id")
  5267. nurseID, _ := c.GetInt64("nurse")
  5268. end_time := c.GetString("end_time")
  5269. if record_id <= 0 || nurseID <= 0 {
  5270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5271. return
  5272. }
  5273. adminUserInfo := c.GetMobileAdminUserInfo()
  5274. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5275. if getNurseErr != nil {
  5276. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5278. return
  5279. } else if nurse == nil {
  5280. c.ErrorLog("护士不存在")
  5281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5282. return
  5283. }
  5284. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5285. if parseEndDateErr != nil {
  5286. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5288. return
  5289. }
  5290. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5291. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5292. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5293. // if getPermissionErr != nil {
  5294. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5295. // return
  5296. // } else if headNursePermission == nil {
  5297. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5298. // return
  5299. // }
  5300. //}
  5301. dialysisRecord := &models.DialysisOrder{
  5302. ID: record_id,
  5303. UserOrgId: adminUserInfo.Org.Id,
  5304. EndTime: endDate.Unix(),
  5305. FinishNurse: nurseID,
  5306. FinishModifier: adminUserInfo.AdminUser.Id,
  5307. }
  5308. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5309. if updateErr != nil {
  5310. c.ErrorLog("修改下机失败:%v", updateErr)
  5311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5312. return
  5313. }
  5314. if updateErr == nil {
  5315. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5316. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5317. a, b := math.Modf(value)
  5318. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5319. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5320. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5321. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5322. if updateAssessmentErr != nil {
  5323. utils.ErrorLog("%v", updateAssessmentErr)
  5324. }
  5325. }
  5326. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5327. c.ServeSuccessJSON(map[string]interface{}{
  5328. "dialysis_order": dialysisRecords,
  5329. })
  5330. }
  5331. func (c *DialysisAPIController) GetLongAdvice() {
  5332. patient_id, _ := c.GetInt64("id")
  5333. adminUserInfo := c.GetMobileAdminUserInfo()
  5334. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5335. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5336. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5337. c.ServeSuccessJSON(map[string]interface{}{
  5338. "status": "1",
  5339. })
  5340. return
  5341. } else { //开启推送提醒
  5342. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5343. var advice_three []*models.DoctorAdvice
  5344. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  5345. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  5346. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  5347. for _, advice := range advices {
  5348. if advice.FrequencyType == 3 {
  5349. t := time.Now()
  5350. week := int(t.Weekday())
  5351. switch week {
  5352. case 1:
  5353. if strings.Index(advice.WeekDay, "周一") == -1 {
  5354. advice_three = append(advice_three, advice)
  5355. }
  5356. break
  5357. case 2:
  5358. if strings.Index(advice.WeekDay, "周二") == -1 {
  5359. advice_three = append(advice_three, advice)
  5360. }
  5361. break
  5362. case 3:
  5363. if strings.Index(advice.WeekDay, "周三") == -1 {
  5364. advice_three = append(advice_three, advice)
  5365. }
  5366. break
  5367. case 4:
  5368. if strings.Index(advice.WeekDay, "周四") == -1 {
  5369. advice_three = append(advice_three, advice)
  5370. }
  5371. break
  5372. case 5:
  5373. if strings.Index(advice.WeekDay, "周五") == -1 {
  5374. advice_three = append(advice_three, advice)
  5375. }
  5376. break
  5377. case 6:
  5378. if strings.Index(advice.WeekDay, "周六") == -1 {
  5379. advice_three = append(advice_three, advice)
  5380. }
  5381. break
  5382. case 0:
  5383. if strings.Index(advice.WeekDay, "周日") == -1 {
  5384. advice_three = append(advice_three, advice)
  5385. }
  5386. break
  5387. }
  5388. }
  5389. }
  5390. for _, advice := range advices_two {
  5391. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5392. now := p.Unix()
  5393. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5394. dayStr2 := "-" + dayStr
  5395. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5396. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5397. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5398. for _, ad := range advices {
  5399. advice_three = append(advice_three, ad)
  5400. }
  5401. }
  5402. if err == nil {
  5403. c.ServeSuccessJSON(map[string]interface{}{
  5404. "status": "2",
  5405. "advices": advices,
  5406. "advices_two": RemoveRepeatedElement(advice_three),
  5407. "is_open_remind": config.IsOpenRemind,
  5408. })
  5409. }
  5410. }
  5411. }
  5412. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5413. newArr = make([]*models.DoctorAdvice, 0)
  5414. for i := 0; i < len(arr); i++ {
  5415. repeat := false
  5416. for j := i + 1; j < len(arr); j++ {
  5417. if arr[i].ID == arr[j].ID {
  5418. repeat = true
  5419. break
  5420. }
  5421. }
  5422. if !repeat {
  5423. newArr = append(newArr, arr[i])
  5424. }
  5425. }
  5426. return
  5427. }
  5428. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5429. patient, _ := c.GetInt64("id", 0)
  5430. groupNo, _ := c.GetInt64("groupno", 0)
  5431. if patient <= 0 {
  5432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5433. return
  5434. }
  5435. adminUserInfo := c.GetMobileAdminUserInfo()
  5436. dataBody := make(map[string]interface{}, 0)
  5437. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5438. if err != nil {
  5439. utils.ErrorLog(err.Error())
  5440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5441. return
  5442. }
  5443. utils.ErrorLog("%v", dataBody)
  5444. timeLayout := "2006-01-02 15:04"
  5445. loc, _ := time.LoadLocation("Local")
  5446. timeLayout2 := "2006-01-02"
  5447. loc2, _ := time.LoadLocation("Local")
  5448. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5449. utils.ErrorLog("advice_type")
  5450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5451. return
  5452. }
  5453. adviceType := int64(2)
  5454. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5455. utils.ErrorLog("advice_date")
  5456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5457. return
  5458. }
  5459. adviceDate, _ := dataBody["advice_date"].(string)
  5460. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5461. AdviceDate := theTime.Unix()
  5462. RecordDate := theTime.Unix()
  5463. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5464. utils.ErrorLog("start_time")
  5465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5466. return
  5467. }
  5468. startTime, _ := dataBody["start_time"].(string)
  5469. if len(startTime) == 0 {
  5470. utils.ErrorLog("len(start_time) == 0")
  5471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5472. return
  5473. }
  5474. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5475. if err != nil {
  5476. utils.ErrorLog(err.Error())
  5477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5478. return
  5479. }
  5480. StartTime := theTime.Unix()
  5481. Remark := ""
  5482. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5483. remark, _ := dataBody["remark"].(string)
  5484. Remark = remark
  5485. }
  5486. var advices []*models.GroupAdvice
  5487. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5488. utils.ErrorLog("advices")
  5489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5490. return
  5491. }
  5492. adviceNames := dataBody["advices"].([]interface{})
  5493. for _, adviceNameMap := range adviceNames {
  5494. adviceNameM := adviceNameMap.(map[string]interface{})
  5495. var advice models.GroupAdvice
  5496. advice.Remark = Remark
  5497. advice.AdviceType = adviceType
  5498. advice.StartTime = StartTime
  5499. advice.AdviceDate = AdviceDate
  5500. advice.RecordDate = RecordDate
  5501. advice.Status = 1
  5502. advice.CreatedTime = time.Now().Unix()
  5503. advice.UpdatedTime = time.Now().Unix()
  5504. advice.StopState = 2
  5505. advice.ExecutionState = 2
  5506. advice.UserOrgId = adminUserInfo.Org.Id
  5507. advice.PatientId = patient
  5508. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5509. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5510. utils.ErrorLog("advice_name")
  5511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5512. return
  5513. }
  5514. adviceName, _ := adviceNameM["advice_name"].(string)
  5515. if len(adviceName) == 0 {
  5516. utils.ErrorLog("len(advice_name) == 0")
  5517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5518. return
  5519. }
  5520. advice.AdviceName = adviceName
  5521. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5522. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5523. advice.DrugSpec = drugSpec
  5524. }
  5525. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5526. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5527. advice.AdviceDesc = adviceDesc
  5528. }
  5529. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5530. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5531. advice.DrugSpecUnit = drugSpecUnit
  5532. }
  5533. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5534. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5535. // advice.SingleDose = singleDose
  5536. //}
  5537. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5538. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5539. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5540. }
  5541. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5542. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5543. advice.SingleDoseUnit = singleDoseUnit
  5544. }
  5545. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5546. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5547. // advice.PrescribingNumber = prescribingNumber
  5548. //}
  5549. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5550. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5551. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5552. }
  5553. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5554. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5555. advice.PrescribingNumberUnit = prescribingNumberUnit
  5556. }
  5557. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5558. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5559. advice.DeliveryWay = deliveryWay
  5560. }
  5561. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5562. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5563. advice.ExecutionFrequency = executionFrequency
  5564. }
  5565. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5566. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5567. advice.FrequencyType = frequency_type
  5568. }
  5569. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5570. day_count := int64(adviceNameM["day_count"].(float64))
  5571. advice.DayCount = day_count
  5572. }
  5573. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5574. week_day, _ := adviceNameM["week_day"].(string)
  5575. advice.WeekDay = week_day
  5576. }
  5577. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5578. template_id, _ := adviceNameM["template_id"].(string)
  5579. advice.TemplateId = template_id
  5580. }
  5581. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5582. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5583. advice.ExecutionFrequency = executionFrequency
  5584. }
  5585. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5586. children := adviceNameM["child"].([]interface{})
  5587. if len(children) > 0 {
  5588. for _, childrenMap := range children {
  5589. childMap := childrenMap.(map[string]interface{})
  5590. var child models.GroupAdvice
  5591. child.Remark = Remark
  5592. child.AdviceType = adviceType
  5593. child.StartTime = StartTime
  5594. child.AdviceDate = AdviceDate
  5595. child.RecordDate = RecordDate
  5596. child.Status = 1
  5597. child.CreatedTime = time.Now().Unix()
  5598. child.UpdatedTime = time.Now().Unix()
  5599. child.StopState = 2
  5600. child.ExecutionState = 2
  5601. child.UserOrgId = adminUserInfo.Org.Id
  5602. child.PatientId = patient
  5603. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5604. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5605. utils.ErrorLog("child advice_name")
  5606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5607. return
  5608. }
  5609. childAdviceName, _ := childMap["advice_name"].(string)
  5610. if len(childAdviceName) == 0 {
  5611. utils.ErrorLog("len(child advice_name) == 0")
  5612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5613. return
  5614. }
  5615. child.AdviceName = childAdviceName
  5616. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5617. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5618. child.AdviceDesc = childAdviceDesc
  5619. }
  5620. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5621. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5622. child.DrugSpec = childDrugSpec
  5623. }
  5624. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5625. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5626. child.DrugSpecUnit = childDrugSpecUnit
  5627. }
  5628. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5629. child.SingleDose = childMap["single_dose"].(float64)
  5630. }
  5631. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5632. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5633. child.SingleDoseUnit = childSingleDoseUnit
  5634. }
  5635. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5636. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5637. }
  5638. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5639. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5640. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5641. }
  5642. child.DeliveryWay = advice.DeliveryWay
  5643. child.ExecutionFrequency = advice.ExecutionFrequency
  5644. advice.Children = append(advice.Children, &child)
  5645. }
  5646. }
  5647. }
  5648. advices = append(advices, &advice)
  5649. }
  5650. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5651. if err != nil {
  5652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5653. return
  5654. }
  5655. c.ServeSuccessJSON(map[string]interface{}{
  5656. "msg": "ok",
  5657. "advices": list,
  5658. })
  5659. return
  5660. }
  5661. func (c *DialysisAPIController) UploadDryWeight() {
  5662. patient_id, _ := c.GetInt64("id")
  5663. dry_weight, _ := c.GetFloat("dry_weight")
  5664. doctor_id, _ := c.GetInt64("doctor_id")
  5665. remark := c.GetString("remark")
  5666. adminUserInfo := c.GetMobileAdminUserInfo()
  5667. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5668. if err == gorm.ErrRecordNotFound {
  5669. dryWeight := &models.SgjPatientDryweight{
  5670. PatientId: patient_id,
  5671. DryWeight: dry_weight,
  5672. Remakes: remark,
  5673. Ctime: time.Now().Unix(),
  5674. Mtime: time.Now().Unix(),
  5675. Creator: doctor_id,
  5676. Status: 1,
  5677. UserOrgId: adminUserInfo.Org.Id,
  5678. AdjustedValue: "/",
  5679. UserId: adminUserInfo.AdminUser.Id,
  5680. }
  5681. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5682. if createErr == nil {
  5683. c.ServeSuccessJSON(map[string]interface{}{
  5684. "msg": "提交成功",
  5685. "weight": dryWeight,
  5686. })
  5687. }
  5688. } else {
  5689. dryWeight := &models.SgjPatientDryweight{
  5690. PatientId: patient_id,
  5691. DryWeight: dry_weight,
  5692. Remakes: remark,
  5693. Ctime: time.Now().Unix(),
  5694. Mtime: time.Now().Unix(),
  5695. Creator: doctor_id,
  5696. Status: 1,
  5697. UserOrgId: adminUserInfo.Org.Id,
  5698. AdjustedValue: "/",
  5699. UserId: adminUserInfo.AdminUser.Id,
  5700. }
  5701. var value float64
  5702. value = dry_weight - weightAdjust.DryWeight
  5703. if value < 0 {
  5704. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5705. } else if value == 0 {
  5706. dryWeight.AdjustedValue = "/"
  5707. } else if value > 0 {
  5708. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5709. }
  5710. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5711. if createErr == nil {
  5712. c.ServeSuccessJSON(map[string]interface{}{
  5713. "msg": "提交成功",
  5714. "weight": dryWeight,
  5715. })
  5716. }
  5717. }
  5718. }
  5719. func (c *DialysisAPIController) GetSolution() {
  5720. patient_id, _ := c.GetInt64("patient_id")
  5721. mode_id, _ := c.GetInt64("mode_id")
  5722. adminUserInfo := c.GetMobileAdminUserInfo()
  5723. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5724. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5725. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  5726. if err != nil {
  5727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5728. return
  5729. }
  5730. c.ServeSuccessJSON(map[string]interface{}{
  5731. "solution": solution,
  5732. "prescription": prescription,
  5733. "system_prescription": system_prescription,
  5734. })
  5735. }
  5736. func (c *DialysisAPIController) GetSchedule() {
  5737. schedual_type, _ := c.GetInt64("schedual_type")
  5738. adminUserInfo := c.GetMobileAdminUserInfo()
  5739. timeLayout := "2006-01-02 15:04:05"
  5740. date := time.Now().Format("2006-01-02") + " 00:00:00"
  5741. loc, _ := time.LoadLocation("Local")
  5742. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  5743. scheduleTime := theStartTime.Unix()
  5744. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5745. c.ServeSuccessJSON(map[string]interface{}{
  5746. "number": deviceNumber,
  5747. })
  5748. }
  5749. func (c *DialysisAPIController) GetPatientId() {
  5750. id, _ := c.GetInt64("id")
  5751. patientId, _ := service.GetPatientId(id)
  5752. c.ServeSuccessJSON(map[string]interface{}{
  5753. "patient": patientId,
  5754. })
  5755. }