dialysis_api_controller.go 277KB

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