dialysis_api_controller.go 271KB

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