dialysis_api_controller.go 278KB

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