dialysis_api_controller.go 302KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  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. "github.com/astaxie/beego"
  16. "math"
  17. "net/http"
  18. "net/url"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. if err != nil {
  82. this.ErrorLog("获取排班信息失败:%v", err)
  83. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  84. } else {
  85. if len(scheduals) > 0 {
  86. devices, _ := service.GetAllDevicetByListSix(orgID)
  87. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  88. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  89. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  90. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  91. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  92. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  93. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  94. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  95. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  96. for key, item := range scheduals {
  97. for _, infor := range inforMation {
  98. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  99. scheduals[key].NewDeviceInformation = infor
  100. break
  101. }
  102. }
  103. // 获取患者信息
  104. for _, patient := range patients {
  105. if item.PatientId == patient.ID {
  106. scheduals[key].SchedualPatient = patient
  107. break
  108. }
  109. }
  110. // 床位信息
  111. for _, device := range devices {
  112. if item.BedId == device.ID {
  113. scheduals[key].DeviceNumber = device
  114. break
  115. }
  116. }
  117. // 医嘱信息
  118. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  119. for _, advice := range advices {
  120. if item.PatientId == advice.PatientId {
  121. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  126. for _, hisAdvice := range hisAdvices {
  127. if item.PatientId == hisAdvice.PatientId {
  128. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  129. }
  130. }
  131. // 医嘱信息
  132. for _, prescription := range prescriptions {
  133. if item.PatientId == prescription.PatientId {
  134. scheduals[key].Prescription = prescription
  135. break
  136. }
  137. }
  138. // 透前评估
  139. for _, assessmentBefore := range assessmentBefores {
  140. if item.PatientId == assessmentBefore.PatientId {
  141. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  142. break
  143. }
  144. }
  145. // 透析上下机
  146. for _, dialysisOrder := range dialysisOrders {
  147. if item.PatientId == dialysisOrder.PatientId {
  148. scheduals[key].DialysisOrder = dialysisOrder
  149. break
  150. }
  151. }
  152. // 治疗小节
  153. for _, afterDislysis := range AssessmentAfterDislysis {
  154. if item.PatientId == afterDislysis.PatientId {
  155. scheduals[key].AssessmentAfterDislysis = afterDislysis
  156. break
  157. }
  158. }
  159. // 透后评估
  160. for _, treatmentSummary := range treatmentSummarys {
  161. if item.PatientId == treatmentSummary.PatientId {
  162. scheduals[key].TreatmentSummary = treatmentSummary
  163. break
  164. }
  165. }
  166. for _, check := range dobulecheck {
  167. if item.PatientId == check.PatientId {
  168. scheduals[key].DoubleCheck = check
  169. break
  170. }
  171. }
  172. }
  173. //缓存数据
  174. scheduals_json, err := json.Marshal(&scheduals)
  175. if err == nil {
  176. redis.Set(key, scheduals_json, time.Second*60)
  177. }
  178. }
  179. //获取今日所有的处方开的耗材
  180. _, configs := service.FindXTHisProjectByOrgId(orgID)
  181. project := make([]*models.HisPrescriptionProjectTwo, 0)
  182. if configs.ID > 0 && configs.IsOpen == 1 {
  183. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  184. }
  185. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  186. this.ServeSuccessJSON(map[string]interface{}{
  187. "scheduals": scheduals,
  188. "project": project,
  189. })
  190. }
  191. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  192. var dat []map[string]interface{}
  193. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  194. } else {
  195. }
  196. //获取今日所有的处方开的耗材
  197. _, configs := service.FindXTHisProjectByOrgId(orgID)
  198. project := make([]*models.HisPrescriptionProjectTwo, 0)
  199. if configs.ID > 0 && configs.IsOpen == 1 {
  200. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  201. }
  202. this.ServeSuccessJSON(map[string]interface{}{
  203. "scheduals": dat,
  204. "redis": "true",
  205. "date": schedualDate,
  206. "project": project,
  207. })
  208. }
  209. }
  210. // /m/api/waiting_scheduals [get]
  211. // @param date:string
  212. func (this *DialysisAPIController) WaitingScheduals() {
  213. schedualDate := this.GetString("date")
  214. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  215. if parseDateErr != nil && len(schedualDate) != 0 {
  216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  217. return
  218. }
  219. adminInfo := this.GetMobileAdminUserInfo()
  220. orgID := adminInfo.Org.Id
  221. redis := service.RedisClient()
  222. defer redis.Close()
  223. // cur_date := time.Now().Format("2006-01-02")
  224. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  225. wait_scheduals, _ := redis.Get(key).Result()
  226. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  227. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  228. if err != nil {
  229. this.ErrorLog("获取排班信息失败:%v", err)
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  231. } else {
  232. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  233. for _, s := range scheduals {
  234. returnScheduals = append(returnScheduals, s)
  235. }
  236. if len(returnScheduals) > 0 {
  237. //缓存数据
  238. wait_scheduals_json, err := json.Marshal(scheduals)
  239. if err == nil {
  240. redis.Set(key, wait_scheduals_json, time.Second*30)
  241. }
  242. }
  243. this.ServeSuccessJSON(map[string]interface{}{
  244. "scheduals": scheduals,
  245. })
  246. }
  247. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  248. var dat []map[string]interface{}
  249. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  250. } else {
  251. }
  252. this.ServeSuccessJSON(map[string]interface{}{
  253. "scheduals": dat,
  254. "redis": "true",
  255. "date": schedualDate,
  256. })
  257. }
  258. }
  259. //else{
  260. // fmt.Println("33333333")
  261. //
  262. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  263. // if err != nil {
  264. // this.ErrorLog("获取排班信息失败:%v", err)
  265. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  266. // } else {
  267. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  268. // for _, s := range scheduals {
  269. //
  270. // returnScheduals = append(returnScheduals, s)
  271. // }
  272. //
  273. // this.ServeSuccessJSON(map[string]interface{}{
  274. // "scheduals": returnScheduals,
  275. // })
  276. // }
  277. //
  278. // }
  279. //if err == nil{
  280. //
  281. //
  282. //
  283. //
  284. //
  285. //}else{
  286. //}
  287. // /m/api/dialysis/record [get]
  288. // @param patient_id:int
  289. // @param date:string (yyyy-MM-dd)
  290. func (this *DialysisAPIController) DialysisRecord() {
  291. patientID, _ := this.GetInt64("patient_id")
  292. recordDateStr := this.GetString("date")
  293. if patientID <= 0 {
  294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  295. return
  296. }
  297. if len(recordDateStr) == 0 {
  298. recordDateStr = time.Now().Format("2006-01-02")
  299. }
  300. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  301. if parseDateErr != nil {
  302. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  304. return
  305. }
  306. adminInfo := this.GetMobileAdminUserInfo()
  307. ch := make(chan struct{})
  308. count := 24 // count 表示活动的协程个数
  309. var patient models.Patients
  310. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  311. var predialysisEvaluation *models.PredialysisEvaluation
  312. var lastPredialysisEvaluation *models.PredialysisEvaluation
  313. var doctorAdvices []*models.DoctorAdvice
  314. var dialysisOrder *models.DialysisOrder
  315. var doubleCheck *models.DoubleCheck
  316. var monitorRecords []*models.MonitoringRecord
  317. var lastMonitorRecord *models.MonitoringRecord
  318. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  319. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  320. var treatmentSummary *models.TreatmentSummary
  321. var dialysisPrescribe *models.DialysisPrescription
  322. var dialysisSolution *models.DialysisSolution
  323. var lastDialysisPrescribe *models.DialysisPrescription
  324. var systemDialysisPrescribe *models.SystemPrescription
  325. var is_project_open_config models.XtHisProjectConfig
  326. var projects []*models.HisPrescriptionProject
  327. var stockType []*models.GoodsTypeOne
  328. var prepare []*models.XtDialysisBeforePrepare
  329. var lastAssessment models.XtPatientVascularAccess
  330. var lastDryWeightDislysis *models.SgjPatientDryweight
  331. var gobalConfig models.GobalConfig
  332. var operators []*models.SgjUserAdminRoles
  333. // 先走redis,没有走数据库
  334. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  335. go func() {
  336. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  337. ch <- struct{}{}
  338. }()
  339. go func() {
  340. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  341. ch <- struct{}{}
  342. }()
  343. go func() {
  344. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  345. ch <- struct{}{}
  346. }()
  347. go func() {
  348. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  349. ch <- struct{}{}
  350. }()
  351. go func() {
  352. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  353. ch <- struct{}{}
  354. }()
  355. go func() {
  356. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  357. ch <- struct{}{}
  358. }()
  359. go func() {
  360. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  361. ch <- struct{}{}
  362. }()
  363. go func() {
  364. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  365. ch <- struct{}{}
  366. }()
  367. go func() {
  368. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  369. ch <- struct{}{}
  370. }()
  371. go func() {
  372. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  373. ch <- struct{}{}
  374. }()
  375. go func() {
  376. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  377. ch <- struct{}{}
  378. }()
  379. go func() {
  380. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  381. ch <- struct{}{}
  382. }()
  383. go func() {
  384. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  385. ch <- struct{}{}
  386. }()
  387. go func() {
  388. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  389. ch <- struct{}{}
  390. }()
  391. go func() {
  392. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  393. ch <- struct{}{}
  394. }()
  395. go func() {
  396. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  397. ch <- struct{}{}
  398. }()
  399. go func() {
  400. // 先走redis,没有走数据库
  401. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  402. ch <- struct{}{}
  403. }()
  404. go func() {
  405. // 先走redis,没有走数据库
  406. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. // // 先走redis,没有走数据库
  411. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // //获取最后一次血管通路
  421. // 先走redis,没有走数据库
  422. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  423. ch <- struct{}{}
  424. }()
  425. go func() {
  426. // 先走redis,没有走数据库
  427. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  428. ch <- struct{}{}
  429. }()
  430. go func() {
  431. // 先走redis,没有走数据库
  432. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  433. ch <- struct{}{}
  434. }()
  435. go func() {
  436. // 先走redis,没有走数据库
  437. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  438. ch <- struct{}{}
  439. }()
  440. for range ch {
  441. // 每次从ch中接收数据,表明一个活动的协程结束
  442. count--
  443. // 当所有活动的协程都结束时,关闭管道
  444. if count == 0 {
  445. close(ch)
  446. }
  447. }
  448. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  449. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  450. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  451. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  452. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  453. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  454. var team_projects []*models.HisPrescriptionProject
  455. //var index int64 = 0
  456. for _, item := range temp_team_projects {
  457. //组套里面非检验项目的
  458. if item.HisProject.CostClassify != 3 {
  459. projects = append(projects, item)
  460. }
  461. //组套里面检验项目的
  462. if item.HisProject.CostClassify == 3 {
  463. team_projects = append(team_projects, item)
  464. }
  465. }
  466. team_projects = RemoveRepeatedCheckRecod(team_projects)
  467. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  468. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  469. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  470. var his_advices []*models.HisDoctorAdviceInfo
  471. if is_open_config.IsOpen == 1 {
  472. // 先走redis,没有走数据库
  473. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  474. }
  475. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  476. if is_advice_open.IsAdviceOpen == 1 {
  477. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  478. }
  479. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  480. returnData := map[string]interface{}{
  481. "patient": patient,
  482. "schedual": schedual,
  483. "prescription": dialysisPrescribe,
  484. "solution": dialysisSolution,
  485. "last_prescription": lastDialysisPrescribe,
  486. "receiver_treatment_access": receiverTreatmentAccess,
  487. "predialysis_evaluation": predialysisEvaluation,
  488. "doctor_advices": doctorAdvices,
  489. "double_check": doubleCheck,
  490. "assessment_after_dislysis": assessmentAfterDislysis,
  491. "treatment_summary": treatmentSummary,
  492. "monitor_records": monitorRecords,
  493. "dialysis_order": dialysisOrder,
  494. "operators": operators,
  495. "last_predialysis_evaluation": lastPredialysisEvaluation,
  496. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  497. "last_monitor_record": lastMonitorRecord,
  498. "config": gobalConfig,
  499. "dry_weight": lastDryWeightDislysis,
  500. "system_prescription": systemDialysisPrescribe,
  501. "his_advices": his_advices,
  502. "is_open_config": is_open_config,
  503. "stockType": stockType,
  504. "prepare": prepare,
  505. "lastAssessment": lastAssessment,
  506. "prescribeOne": prescribeOne,
  507. "is_project_open_config": is_project_open_config,
  508. "project": projects,
  509. "team_projects": team_projects,
  510. "is_advice_open": is_advice_open,
  511. "prescription_open": prescriptionConfig.IsOpen,
  512. "lastOrder": lastOrder,
  513. }
  514. this.ServeSuccessJSON(returnData)
  515. }
  516. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  517. adminInfo := c.GetMobileAdminUserInfo()
  518. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  519. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  520. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  521. returnData := map[string]interface{}{
  522. "admin_users": adminUsers,
  523. "devices": devices,
  524. "device_numbers": device_numbers,
  525. }
  526. c.ServeSuccessJSON(returnData)
  527. }
  528. func (c *DialysisAPIController) PostAtreatmentInfo() {
  529. id, _ := c.GetInt64("patient", 0)
  530. recordDateStr := c.GetString("record_date")
  531. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  532. summaryContent := c.GetString("summaryContent")
  533. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  534. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  535. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  536. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  537. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  538. nursingRecord := c.GetString("nursing_record")
  539. fmt.Println("护理记录", nursingRecord)
  540. specialRecord := c.GetString("special_record")
  541. fmt.Println("特殊记录", specialRecord)
  542. adminUserInfo := c.GetMobileAdminUserInfo()
  543. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  544. checkStaffId = adminUserInfo.AdminUser.Id
  545. deboardNurseId = adminUserInfo.AdminUser.Id
  546. treatDoctor = adminUserInfo.AdminUser.Id
  547. if id <= 0 {
  548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  549. return
  550. }
  551. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  552. if patient.ID == 0 {
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  554. return
  555. }
  556. if len(recordDateStr) == 0 {
  557. recordDateStr = time.Now().Format("2006-01-02")
  558. }
  559. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  560. if parseDateErr != nil {
  561. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  563. return
  564. }
  565. summary := models.TreatmentSummary{
  566. UserOrgId: adminUserInfo.Org.Id,
  567. PatientId: id,
  568. AssessmentDate: recordDate.Unix(),
  569. Mission: propagandaAndEducationContent,
  570. DialysisSummary: summaryContent,
  571. SjNurse: changeMedicalNurseId,
  572. ZlNurse: treatNurseId,
  573. HdNurse: checkStaffId,
  574. XjNurse: deboardNurseId,
  575. ZlDoctor: treatDoctor,
  576. CreatedTime: time.Now().Unix(),
  577. Status: 1,
  578. NursingRecord: nursingRecord,
  579. SpecialRecord: specialRecord,
  580. }
  581. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  582. if treatmentSummary.ID == 0 { //新增
  583. summary.Creater = adminUserInfo.AdminUser.Id
  584. service.AddSigleSummaryRecord(&summary)
  585. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  586. redis := service.RedisClient()
  587. //清空key 值
  588. redis.Set(key, "", time.Second)
  589. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  590. redis.Set(keyOne, "", time.Second)
  591. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  592. redis.Set(keyThree, "", time.Second)
  593. defer redis.Close()
  594. c.ServeSuccessJSON(map[string]interface{}{
  595. "summary": summary,
  596. })
  597. } else { //修改
  598. summary.Creater = treatmentSummary.Creater
  599. summary.CreatedTime = treatmentSummary.CreatedTime
  600. summary.Modifier = adminUserInfo.AdminUser.Id
  601. summary.ID = treatmentSummary.ID
  602. service.UpdateSummeRecord(&summary)
  603. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  604. redis := service.RedisClient()
  605. //清空key 值
  606. redis.Set(key, "", time.Second)
  607. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  608. redis.Set(keyOne, "", time.Second)
  609. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  610. redis.Set(keyThree, "", time.Second)
  611. defer redis.Close()
  612. c.ServeSuccessJSON(map[string]interface{}{
  613. "summary": summary,
  614. })
  615. }
  616. }
  617. func (c *DialysisAPIController) PostDoubleCheck() {
  618. id, _ := c.GetInt64("patient", 0)
  619. recordDateStr := c.GetString("record_date")
  620. checkTimeStr := c.GetString("check_time")
  621. firstCheckTimeStr := c.GetString("first_check_time")
  622. creater, _ := c.GetInt64("creater", 0)
  623. modifier, _ := c.GetInt64("modifier", 0)
  624. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  625. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  626. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  627. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  628. dialysis_item_desc := c.GetString("dialysis_item_desc")
  629. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  630. vascular_access_desc := c.GetString("vascular_access_desc")
  631. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  632. collator, _ := c.GetInt64("collator", 0)
  633. employee_number := c.GetString("employee_number")
  634. if id <= 0 {
  635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  636. return
  637. }
  638. adminUserInfo := c.GetMobileAdminUserInfo()
  639. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  640. if patient.ID == 0 {
  641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  642. return
  643. }
  644. if len(recordDateStr) == 0 {
  645. recordDateStr = time.Now().Format("2006-01-02")
  646. }
  647. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  648. if parseDateErr != nil {
  649. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  651. return
  652. }
  653. var checkDate int64
  654. if len(checkTimeStr) == 0 {
  655. checkDate = 0
  656. } else {
  657. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  658. checkDate = checkDateUnix.Unix()
  659. }
  660. var firstCheckDate int64
  661. if len(firstCheckTimeStr) == 0 {
  662. firstCheckDate = 0
  663. } else {
  664. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  665. firstCheckDate = firstCheckDateUnix.Unix()
  666. }
  667. if adminUserInfo.Org.Id == 10340 {
  668. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  669. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if check.ID == 0 {
  671. if employee_number != list.JobNumber {
  672. c.ServeSuccessJSON(map[string]interface{}{
  673. "doubleCheck": check,
  674. "msg": "2",
  675. })
  676. return
  677. }
  678. }
  679. if check.ID > 0 {
  680. if employee_number != list.JobNumber {
  681. c.ServeSuccessJSON(map[string]interface{}{
  682. "doubleCheck": check,
  683. "msg": "2",
  684. })
  685. return
  686. }
  687. }
  688. }
  689. doubleCheck := models.DoubleCheck{
  690. UserOrgId: adminUserInfo.Org.Id,
  691. PatientId: id,
  692. DialysisItemCheck: dialysis_item_check,
  693. DialysisParameterCheck: dialysis_parameter_check,
  694. VascularAccessVerification: vascular_access_verification,
  695. PipelineConnectionCheck: pipeline_connection_check,
  696. DialysisItemDesc: dialysis_item_desc,
  697. DialysisParameterDesc: dialysis_parameter_desc,
  698. VascularAccessDesc: vascular_access_desc,
  699. PipelineConnectionDesc: pipeline_connection_desc,
  700. Collator: collator,
  701. Status: 1,
  702. CreatedTime: time.Now().Unix(),
  703. CheckDate: recordDate.Unix(),
  704. UpdatedTime: time.Now().Unix(),
  705. EmployeeNumber: employee_number,
  706. }
  707. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  708. if check.ID == 0 { //新增
  709. doubleCheck.FirstCheckTime = firstCheckDate
  710. doubleCheck.CheckTime = checkDate
  711. doubleCheck.Creater = creater
  712. doubleCheck.Modifier = modifier
  713. err := service.AddSigleDoubleCheck(&doubleCheck)
  714. //针对长沙南雅
  715. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  716. //查询未核对的医嘱
  717. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  718. if len(doctorList) > 0 && modifier > 0 {
  719. for _, advice := range doctorList {
  720. service.UpdateDoctorAdviceList(advice.ID, modifier)
  721. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  722. redis := service.RedisClient()
  723. //清空key 值
  724. redis.Set(key, "", time.Second)
  725. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  726. redis.Set(keyTwo, "", time.Second)
  727. theTime := time.Now()
  728. recordDate := theTime.Format("2006-01-02")
  729. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  730. redis.Set(keyFour, "", time.Second)
  731. defer redis.Close()
  732. }
  733. }
  734. }
  735. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  736. redis := service.RedisClient()
  737. defer redis.Close()
  738. //清空key 值
  739. redis.Set(key, "", time.Second)
  740. if err == nil {
  741. c.ServeSuccessJSON(map[string]interface{}{
  742. "doubleCheck": &doubleCheck,
  743. })
  744. }
  745. } else { //修改
  746. doubleCheck.FirstCheckTime = firstCheckDate
  747. doubleCheck.CheckTime = checkDate
  748. doubleCheck.Creater = creater
  749. doubleCheck.Modifier = modifier
  750. doubleCheck.CreatedTime = check.CreatedTime
  751. doubleCheck.ID = check.ID
  752. doubleCheck.EmployeeNumber = employee_number
  753. err := service.UpdateDoubleCheck(&doubleCheck)
  754. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  755. redis := service.RedisClient()
  756. defer redis.Close()
  757. //清空key 值
  758. redis.Set(key, "", time.Second)
  759. if err == nil {
  760. c.ServeSuccessJSON(map[string]interface{}{
  761. "doubleCheck": &doubleCheck,
  762. "msg": "1",
  763. })
  764. }
  765. }
  766. }
  767. func (c *DialysisAPIController) PostAcceptsAssessment() {
  768. id, _ := c.GetInt64("patient", 0)
  769. recordDateStr := c.GetString("record_date")
  770. way, _ := c.GetInt64("way", 0)
  771. consciousness, _ := c.GetInt64("consciousness", 0)
  772. appetite, _ := c.GetInt64("appetite", 0)
  773. condition, _ := c.GetInt64("condition", 0)
  774. posture, _ := c.GetInt64("posture")
  775. sick_condition, _ := c.GetInt64("sick_condition", 0)
  776. danger_level, _ := c.GetInt64("danger_level", 0)
  777. intake, _ := c.GetInt64("intake", 0)
  778. nutrition, _ := c.GetInt64("nutrition", 0)
  779. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  780. psychological_assessment_other := c.GetString("psychological_assessment_other")
  781. score := c.GetString("score")
  782. sick_condition_other := c.GetString("sick_condition_other")
  783. //precaution, _ := c.GetInt64("precaution", 0)
  784. precaution := c.GetString("precaution")
  785. precaution_other := c.GetString("precaution_other")
  786. psychological_other := c.GetString("psychological_other")
  787. admission_number := c.GetString("admission_number")
  788. tumble, _ := c.GetInt64("tumble")
  789. diacrisis := c.GetString("diacrisis")
  790. his_department := c.GetString("his_department")
  791. his_bed := c.GetString("his_bed")
  792. if id <= 0 {
  793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  794. return
  795. }
  796. adminUserInfo := c.GetMobileAdminUserInfo()
  797. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  798. if patient.ID == 0 {
  799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  800. return
  801. }
  802. //now := time.Now()
  803. //year, month, day := now.Date()
  804. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  805. //todayTimeStamp := today_time.Unix()
  806. if len(recordDateStr) == 0 {
  807. recordDateStr = time.Now().Format("2006-01-02")
  808. }
  809. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  810. if parseDateErr != nil {
  811. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  813. return
  814. }
  815. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  816. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  817. UserOrgId: adminUserInfo.Org.Id,
  818. PatientId: id,
  819. RecordDate: recordDate.Unix(),
  820. Way: way,
  821. Consciousness: consciousness,
  822. Appetite: appetite,
  823. Condition: condition,
  824. SickCondition: sick_condition,
  825. DangerLevel: danger_level,
  826. Intake: intake,
  827. Nutrition: nutrition,
  828. PsychologicalAssessment: psychological_assessment,
  829. PsychologicalAssessmentOther: psychological_assessment_other,
  830. SickConditionOther: sick_condition_other,
  831. Posture: posture,
  832. CreatedTime: time.Now().Unix(),
  833. UpdateTime: time.Now().Unix(),
  834. Status: 1,
  835. Score: score,
  836. Precaution: precaution,
  837. PrecautionOther: precaution_other,
  838. PsychologicalOther: psychological_other,
  839. AdmissionNumber: admission_number,
  840. Tumble: tumble,
  841. Diacrisis: diacrisis,
  842. HisBed: his_bed,
  843. HisDepartment: his_department,
  844. }
  845. if receiveTreatment.ID == 0 { //新增
  846. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  847. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  848. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  849. redis := service.RedisClient()
  850. defer redis.Close()
  851. //清空key 值
  852. redis.Set(key, "", time.Second)
  853. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  854. redis.Set(keyOne, "", time.Second)
  855. if err == nil {
  856. c.ServeSuccessJSON(map[string]interface{}{
  857. "receiveTreatmentAsses": receiveTreatmentAsses,
  858. })
  859. }
  860. } else { //修改
  861. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  862. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  863. // if getPermissionErr != nil {
  864. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  865. // return
  866. // } else if headNursePermission == nil {
  867. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  868. // return
  869. // }
  870. //}
  871. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  872. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  873. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  874. receiveTreatmentAsses.ID = receiveTreatment.ID
  875. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  877. redis := service.RedisClient()
  878. defer redis.Close()
  879. //清空key 值
  880. redis.Set(key, "", time.Second)
  881. fmt.Println("--------------------------------", recordDateStr)
  882. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  883. redis.Set(keyOne, "", time.Second)
  884. if err == nil {
  885. c.ServeSuccessJSON(map[string]interface{}{
  886. "receiveTreatmentAsses": receiveTreatmentAsses,
  887. })
  888. }
  889. }
  890. }
  891. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  892. id, _ := c.GetInt64("patient", 0)
  893. recordDateStr := c.GetString("record_date")
  894. weightAfter, _ := c.GetFloat("weight_after", 0)
  895. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  896. weightReduce, _ := c.GetFloat("weight_loss", 0)
  897. temperature, _ := c.GetFloat("temperature", 0)
  898. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  899. breathing_rate := c.GetString("breathing_rate")
  900. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  901. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  902. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  903. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  904. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  905. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  906. cruor := c.GetString("cruor")
  907. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  908. internalFistula := c.GetString("internal_fistula")
  909. catheter := c.GetString("catheter")
  910. complications := c.GetString("complication")
  911. remark := c.GetString("remark")
  912. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  913. dialysis_intakes := c.GetString("dialysis_intakes")
  914. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  915. fmt.Println("dialysateVolumewode 23323233223232wode", dialysateVolume)
  916. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  917. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  918. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  919. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  920. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  921. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  922. patientGose, _ := c.GetInt64("patient_gose", 0)
  923. inpatientDepartment := c.GetString("inpatient_department")
  924. observationContent := c.GetString("observation_content")
  925. observationContentOther := c.GetString("observation_content_other")
  926. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  927. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  928. in_advance_reason := c.GetString("in_advance_reason")
  929. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  930. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  931. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  932. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  933. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  934. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  935. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  936. dialyzer, _ := c.GetInt64("dialyzer", 0)
  937. in_advance_reason_other := c.GetString("in_advance_reason_other")
  938. is_eat, _ := c.GetInt64("is_eat", 0)
  939. cvc_a, _ := c.GetFloat("cvc_a", 0)
  940. cvc_v, _ := c.GetFloat("cvc_v", 0)
  941. channels, _ := c.GetInt64("channel", 0)
  942. return_blood, _ := c.GetInt64("return_blood", 0)
  943. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  944. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  945. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  946. blood_flow, _ := c.GetInt64("blood_flow", 0)
  947. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  948. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  949. sealing_fluid_special := c.GetString("sealing_fluid_special")
  950. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  951. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  952. setting_pressure := c.GetString("setting_pressure")
  953. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  954. diastolic_pressure := c.GetString("diastolic_pressure")
  955. other_complication := c.GetString("other_complication")
  956. ktv := c.GetString("ktv")
  957. urr := c.GetString("urr")
  958. hypertenison, _ := c.GetInt64("hypertenison")
  959. hypopiesia, _ := c.GetInt64("hypopiesia")
  960. leave_office_method, _ := c.GetInt64("leave_office_method")
  961. lapse, _ := c.GetInt64("lapse")
  962. consciousness, _ := c.GetInt64("consciousness")
  963. fallrisk, _ := c.GetInt64("fallrisk")
  964. machine_run := c.GetString("machine_run")
  965. after_urea := c.GetString("after_urea")
  966. pip_coagulation := c.GetString("pip_coagulation")
  967. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  968. if id <= 0 {
  969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  970. return
  971. }
  972. adminUserInfo := c.GetMobileAdminUserInfo()
  973. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  974. if patient.ID == 0 {
  975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  976. return
  977. }
  978. if len(recordDateStr) == 0 {
  979. recordDateStr = time.Now().Format("2006-01-02")
  980. }
  981. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  982. if parseDateErr != nil {
  983. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  985. return
  986. }
  987. //now := time.Now()
  988. //year, month, day := now.Date()
  989. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  990. //todayTimeStamp := today_time.Unix()
  991. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  992. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  993. UserOrgId: adminUserInfo.Org.Id,
  994. PatientId: id,
  995. AssessmentDate: recordDate.Unix(),
  996. Temperature: temperature,
  997. PulseFrequency: pulse_frequency,
  998. BreathingRate: breathing_rate,
  999. SystolicBloodPressure: systolic_blood_pressure,
  1000. DiastolicBloodPressure: diastolic_blood_pressure,
  1001. ActualUltrafiltration: actual_ultrafiltration,
  1002. ActualDisplacement: actual_displacement,
  1003. ActualTreatmentHour: actualtreatHour,
  1004. ActualTreatmentMinute: actualtreatmin,
  1005. WeightAfter: weightAfter,
  1006. AdditionalWeight: additionalWeight,
  1007. WeightLoss: weightReduce,
  1008. Cruor: cruor,
  1009. SymptomAfterDialysis: symptomsAfterDialysi,
  1010. InternalFistula: internalFistula,
  1011. Catheter: catheter,
  1012. Complication: complications,
  1013. DialysisIntakes: dialysateVolume,
  1014. CreatedTime: time.Now().Unix(),
  1015. UpdatedTime: time.Now().Unix(),
  1016. Status: 1,
  1017. Remark: remark,
  1018. BloodAccessPartId: blood_access_part_id,
  1019. BloodAccessPartOperaId: blood_access_part_opera_id,
  1020. DialysisIntakesUnit: dialysis_intakes_unit,
  1021. PuncturePointOozingBlood: puncturePointOozingBlood,
  1022. PuncturePointHaematoma: puncturePointHaematoma,
  1023. InternalFistulaTremorAc: internalFistulaTremorAc,
  1024. PatientGose: patientGose,
  1025. InpatientDepartment: inpatientDepartment,
  1026. ObservationContent: observationContent,
  1027. ObservationContentOther: observationContentOther,
  1028. DialysisProcess: dialysis_process,
  1029. InAdvanceMinute: in_advance_minute,
  1030. InAdvanceReason: in_advance_reason,
  1031. HemostasisMinute: hemostasis_minute,
  1032. HemostasisOpera: hemostasis_opera,
  1033. TremorNoise: tremor_noise,
  1034. DisequilibriumSyndrome: disequilibrium_syndrome,
  1035. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1036. ArterialTube: arterial_tube,
  1037. IntravenousTube: intravenous_tube,
  1038. Dialyzer: dialyzer,
  1039. InAdvanceReasonOther: in_advance_reason_other,
  1040. IsEat: is_eat,
  1041. CvcA: cvc_a,
  1042. CvcV: cvc_v,
  1043. Channel: channels,
  1044. ReturnBlood: return_blood,
  1045. RehydrationVolume: rehydration_volume,
  1046. DialysisDuring: dialysis_during,
  1047. StrokeVolume: stroke_volume,
  1048. BloodFlow: blood_flow,
  1049. SealingFluidDispose: sealing_fluid_dispose,
  1050. SealingFluidSpecial: sealing_fluid_special,
  1051. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1052. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1053. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1054. SettingPressure: setting_pressure,
  1055. DiastolicPressure: diastolic_pressure,
  1056. OtherComplication: other_complication,
  1057. Ktv: ktv,
  1058. Urr: urr,
  1059. Hypopiesia: hypopiesia,
  1060. Hypertenison: hypertenison,
  1061. Lapse: lapse,
  1062. LeaveOfficeMethod: leave_office_method,
  1063. Consciousness: consciousness,
  1064. Fallrisk: fallrisk,
  1065. MachineRun: machine_run,
  1066. AfterUrea: after_urea,
  1067. PipCoagulation: pip_coagulation,
  1068. AccumulatedBloodVolume: accumulated_blood_volume,
  1069. }
  1070. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1071. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1072. if assessmentAfter.ID == 0 { //新增
  1073. if appRole.UserType == 2 || appRole.UserType == 1 {
  1074. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1075. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1076. } else {
  1077. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1078. }
  1079. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1080. redis := service.RedisClient()
  1081. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1082. redis.Set(keyTwo, "", time.Second)
  1083. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1084. //清空key 值
  1085. redis.Set(key, "", time.Second)
  1086. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1087. redis.Set(keyOne, "", time.Second)
  1088. defer redis.Close()
  1089. if err == nil {
  1090. c.ServeSuccessJSON(map[string]interface{}{
  1091. "assessmentAfterDislysis": assessmentAfterDislysis,
  1092. })
  1093. }
  1094. } else { //修改
  1095. if appRole.UserType == 2 || appRole.UserType == 1 {
  1096. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1097. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1098. } else {
  1099. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1100. if assessmentAfterDislysis.Creater == 0 {
  1101. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1102. }
  1103. }
  1104. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1105. assessmentAfterDislysis.ID = assessmentAfter.ID
  1106. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1107. redis := service.RedisClient()
  1108. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1109. redis.Set(keyTwo, "", time.Second)
  1110. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1111. //清空key 值
  1112. redis.Set(key, "", time.Second)
  1113. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1114. redis.Set(keyOne, "", time.Second)
  1115. fmt.Println("err233332323232232323", err)
  1116. if err == nil {
  1117. c.ServeSuccessJSON(map[string]interface{}{
  1118. "assessmentAfterDislysis": assessmentAfterDislysis,
  1119. })
  1120. }
  1121. }
  1122. }
  1123. func (c *DialysisAPIController) PostDialysisPrescription() {
  1124. id, _ := c.GetInt64("patient", 0)
  1125. recordDateStr := c.GetString("record_date")
  1126. if id <= 0 {
  1127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1128. return
  1129. }
  1130. adminUserInfo := c.GetMobileAdminUserInfo()
  1131. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1132. if patient.ID == 0 {
  1133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1134. return
  1135. }
  1136. if len(recordDateStr) == 0 {
  1137. recordDateStr = time.Now().Format("2006-01-02")
  1138. }
  1139. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1140. if parseDateErr != nil {
  1141. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1143. return
  1144. }
  1145. mode_id, _ := c.GetInt64("mode_id", 0)
  1146. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1147. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1148. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1149. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1150. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1151. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1152. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1153. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1154. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1155. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1156. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1157. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1158. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1159. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1160. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1161. kalium, _ := c.GetFloat("kalium", 0)
  1162. sodium, _ := c.GetFloat("sodium", 0)
  1163. calcium, _ := c.GetFloat("calcium", 0)
  1164. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1165. glucose, _ := c.GetFloat("glucose", 0)
  1166. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1167. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1168. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1169. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1170. conductivity, _ := c.GetFloat("conductivity", 0)
  1171. remark := c.GetString("remark")
  1172. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1173. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1174. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1175. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1176. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1177. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1178. special_medicine_other := c.GetString("special_medicine_other")
  1179. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1180. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1181. blood_access, _ := c.GetInt64("blood_access", 0)
  1182. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1183. body_fluid_other := c.GetString("body_fluid_other")
  1184. niprocart, _ := c.GetInt64("niprocart", 0)
  1185. jms, _ := c.GetInt64("jms", 0)
  1186. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1187. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1188. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1189. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1190. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1191. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1192. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1193. injector, _ := c.GetInt64("injector", 0)
  1194. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1195. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1196. safe_package, _ := c.GetInt64("package", 0)
  1197. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1198. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1199. fmt.Println("预冲量", pre_impulse)
  1200. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1201. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1202. blood := c.GetString("blood")
  1203. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1204. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1205. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1206. displace_speed := c.GetString("displace_speed")
  1207. illness, _ := c.GetInt64("illness")
  1208. amylaceum := c.GetString("amylaceum")
  1209. single_time := c.GetString("single_time")
  1210. single_water := c.GetString("single_water")
  1211. replacement_flow := c.GetString("replacement_flow")
  1212. plasma_separator := c.GetString("plasma_separator")
  1213. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1214. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1215. oxygen_flow := c.GetString("oxygen_flow")
  1216. oxygen_time := c.GetString("oxygen_time")
  1217. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1218. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1219. puncture_needle := c.GetString("puncture_needle")
  1220. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1221. epo := c.GetString("epo")
  1222. epo_count, _ := c.GetFloat("epo_count", 0)
  1223. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1224. admin_user_id, _ := c.GetInt64("admin_user_id")
  1225. is_water := c.GetString("is_water")
  1226. var is_war int64
  1227. if is_water == "是" {
  1228. is_war = 1
  1229. }
  1230. if is_water == "否" {
  1231. is_war = 2
  1232. }
  1233. if is_water == "请选择" {
  1234. is_war = 0
  1235. }
  1236. drhy_water := c.GetString("drhy_water")
  1237. dry_water_hour := c.GetString("dry_water_hour")
  1238. water_machine := c.GetString("water_machine")
  1239. add_amount, _ := c.GetFloat("add_amount")
  1240. reduce_amount, _ := c.GetFloat("reduce_amount")
  1241. dialysis_remark := c.GetString("dialysis_remark")
  1242. prescribing_number, _ := c.GetFloat("prescribing_number")
  1243. prescription_sodium := c.GetString("prescription_sodium")
  1244. start_sodium := c.GetString("start_sodium")
  1245. sodium_curve := c.GetString("sodium_curve")
  1246. treatment_remark := c.GetString("treatment_remark")
  1247. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1248. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1249. //
  1250. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1251. // if appRole.UserType == 3 {
  1252. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1253. // if getPermissionErr != nil {
  1254. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1255. // return
  1256. // } else if headNursePermission == nil {
  1257. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1258. // return
  1259. // }
  1260. // }
  1261. //}
  1262. if mode_id > 0 {
  1263. var str string
  1264. //查找该机构用的是什么透析器
  1265. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1266. if filedConfig.ID > 0 {
  1267. str = dialyzerPerfusionApparatus
  1268. } else {
  1269. str = dialysis_dialyszers + "/" + dialysis_irrigation
  1270. }
  1271. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1272. }
  1273. //TODO 需要根据角色去判断
  1274. prescription := models.DialysisPrescription{
  1275. UserOrgId: adminUserInfo.Org.Id,
  1276. PatientId: id,
  1277. RecordDate: recordDate.Unix(),
  1278. ModeId: mode_id,
  1279. DialysisDuration: dialysis_duration,
  1280. Dialyzer: dialyzer,
  1281. PerfusionApparatus: perfusion_apparatus,
  1282. BloodFlowVolume: blood_flow_volume,
  1283. DewaterAmount: dewater_amount,
  1284. DisplaceLiqui: displace_liqui,
  1285. ReplacementWay: replacement_way,
  1286. Anticoagulant: anticoagulant,
  1287. AnticoagulantShouji: anticoagulant_shouji,
  1288. AnticoagulantWeichi: anticoagulant_weichi,
  1289. AnticoagulantZongliang: anticoagulant_zongliang,
  1290. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1291. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1292. Kalium: kalium,
  1293. Sodium: sodium,
  1294. Calcium: calcium,
  1295. Bicarbonate: bicarbonate,
  1296. Glucose: glucose,
  1297. // DryWeight: dry_weight,
  1298. DialysateFlow: dialysate_flow,
  1299. DialysateTemperature: dialysate_temperature,
  1300. // PrescriptionDoctor: prescription_doctor,
  1301. ReplacementTotal: replacement_total,
  1302. Conductivity: conductivity,
  1303. Remark: remark,
  1304. Status: 1,
  1305. CreatedTime: time.Now().Unix(),
  1306. UpdatedTime: time.Now().Unix(),
  1307. DialysisDurationMinute: dialysisDurationMinute,
  1308. DialysisDurationHour: dialysisDurationHour,
  1309. TargetUltrafiltration: targetUltrafiltration,
  1310. DialysateFormulation: dialysateFormulation,
  1311. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1312. BodyFluid: body_fluid,
  1313. SpecialMedicine: special_medicine,
  1314. SpecialMedicineOther: special_medicine_other,
  1315. DisplaceLiquiPart: displace_liqui_part,
  1316. DisplaceLiquiValue: displace_liqui_value,
  1317. BloodAccess: blood_access,
  1318. Ultrafiltration: ultrafiltration,
  1319. BodyFluidOther: body_fluid_other,
  1320. Niprocart: niprocart,
  1321. Jms: jms,
  1322. FistulaNeedleSet: fistula_needle_set,
  1323. FistulaNeedleSet16: fistula_needle_set_16,
  1324. Hemoperfusion: hemoperfusion,
  1325. DialyserSterilised: dialyser_sterilised,
  1326. Filtryzer: filtryzer,
  1327. Dialyzers: dialyzers,
  1328. Injector: injector,
  1329. Bloodlines: bloodlines,
  1330. TubingHemodialysis: tubing_hemodialysis,
  1331. Package: safe_package,
  1332. ALiquid: a_liquid,
  1333. TargetKtv: target_ktv,
  1334. PreImpulse: pre_impulse,
  1335. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1336. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1337. Blood: blood,
  1338. DialysisDialyszers: dialysis_dialyszers,
  1339. DialysisIrrigation: dialysis_irrigation,
  1340. AntioxidantCommodityName: antioxidant_commodity_name,
  1341. DisplaceSpeed: displace_speed,
  1342. Illness: illness,
  1343. Amylaceum: amylaceum,
  1344. SingleTime: single_time,
  1345. SingleWater: single_water,
  1346. ReplacementFlow: replacement_flow,
  1347. PlasmaSeparator: plasma_separator,
  1348. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1349. OxygenUptake: oxygen_uptake,
  1350. OxygenFlow: oxygen_flow,
  1351. OxygenTime: oxygen_time,
  1352. HemodialysisPipelines: hemodialysis_pipelines,
  1353. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1354. PunctureNeedle: puncture_needle,
  1355. PunctureNeedleCount: puncture_needle_count,
  1356. Epo: epo,
  1357. EpoCount: epo_count,
  1358. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1359. AdminUserId: admin_user_id,
  1360. IsWater: is_war,
  1361. DrhyWater: drhy_water,
  1362. DryWaterHour: dry_water_hour,
  1363. WaterMachine: water_machine,
  1364. AddAmount: add_amount,
  1365. ReduceAmount: reduce_amount,
  1366. DialysisRemark: dialysis_remark,
  1367. PrescribingNumber: prescribing_number,
  1368. StartSodium: start_sodium,
  1369. SodiumCurve: sodium_curve,
  1370. TreatmentRemark: treatment_remark,
  1371. PrescriptionSodium: prescription_sodium,
  1372. }
  1373. //查询最近透析准备表里是否存在 透析器 灌流器
  1374. //
  1375. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1376. //
  1377. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1378. //
  1379. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1380. //if len(mation)>0{
  1381. // for _, item := range splitStr {
  1382. // for _,it := range mation{
  1383. // if(item == it.SpecificationName){
  1384. //
  1385. // //查询最近一次的透析器
  1386. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1387. //
  1388. // if errcode == gorm.ErrRecordNotFound{
  1389. // //插入数据
  1390. // prepare := models.DialysisBeforePrepare{
  1391. // UserOrgId: adminUserInfo.Org.Id,
  1392. // PatientId: id,
  1393. // RecordDate: recordDate.Unix(),
  1394. // GoodTypeId: it.GoodTypeId,
  1395. // GoodId: it.ID,
  1396. // Count: 1,
  1397. // Ctime: time.Now().Unix(),
  1398. // Creater: adminUserInfo.AdminUser.Id,
  1399. // Status:1,
  1400. //
  1401. // }
  1402. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1403. // fmt.Println("",errcode)
  1404. // }
  1405. // }
  1406. // }
  1407. //
  1408. // }
  1409. //
  1410. // for _, item := range splitIrrigation {
  1411. // for _,it := range mation{
  1412. // if(item == it.SpecificationName){
  1413. // //查询最近一次的透析器
  1414. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1415. // if errcode == gorm.ErrRecordNotFound{
  1416. // //插入数据
  1417. // prepare := models.DialysisBeforePrepare{
  1418. // UserOrgId: adminUserInfo.Org.Id,
  1419. // PatientId: id,
  1420. // RecordDate: recordDate.Unix(),
  1421. // GoodTypeId: it.GoodTypeId,
  1422. // GoodId: it.ID,
  1423. // Count: 1,
  1424. // Ctime: time.Now().Unix(),
  1425. // Creater: adminUserInfo.AdminUser.Id,
  1426. // Status:1,
  1427. //
  1428. // }
  1429. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1430. // fmt.Println(errcode)
  1431. // }
  1432. // }
  1433. // }
  1434. // }
  1435. //}
  1436. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1437. if dialysisPrescription.ID == 0 { //新增
  1438. if appRole.UserType == 2 || appRole.UserType == 1 {
  1439. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1440. }
  1441. prescription.Creater = adminUserInfo.AdminUser.Id
  1442. //针对河间咸得
  1443. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1444. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1445. prescription.DisplaceLiquiPart = 0
  1446. prescription.DisplaceLiquiValue = 0
  1447. }
  1448. }
  1449. err := service.AddSigleRecord(&prescription)
  1450. //长沙南雅医院,自动生成抗凝剂的临时处方
  1451. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  1452. advice := models.DoctorAdvice{
  1453. UserOrgId: adminUserInfo.Org.Id,
  1454. PatientId: id,
  1455. GroupNo: 0,
  1456. AdviceType: 2,
  1457. RecordDate: recordDate.Unix(),
  1458. AdviceDate: recordDate.Unix(),
  1459. StartTime: recordDate.Unix() + 7*60*60, // 根据排班班次,给默认时间
  1460. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1461. AdviceDesc: "",
  1462. ReminderDate: 0,
  1463. SingleDose: 5000,
  1464. SingleDoseUnit: "iu",
  1465. DrugSpec: 0,
  1466. DrugSpecUnit: "",
  1467. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1468. PrescribingNumberUnit: "支",
  1469. DeliveryWay: "静脉注射",
  1470. ExecutionFrequency: "上机前",
  1471. AdviceDoctor: 0,
  1472. Status: 1,
  1473. CreatedTime: time.Now().Unix(),
  1474. UpdatedTime: time.Now().Unix(),
  1475. IsPrescription: 1,
  1476. }
  1477. // 查询排班信息
  1478. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1479. if schedulePatient.ID > 0 {
  1480. if schedulePatient.ScheduleType == 1 {
  1481. advice.StartTime = recordDate.Unix() + 7*60*60
  1482. }
  1483. if schedulePatient.ScheduleType == 2 {
  1484. advice.StartTime = recordDate.Unix() + 11*60*60
  1485. }
  1486. }
  1487. // 抗凝剂名称
  1488. switch anticoagulant {
  1489. case 1:
  1490. advice.AdviceName = "无肝素"
  1491. break
  1492. case 2:
  1493. advice.AdviceName = "普通肝素"
  1494. break
  1495. case 3:
  1496. advice.AdviceName = "低分子肝素"
  1497. break
  1498. case 4:
  1499. advice.AdviceName = "阿加曲班"
  1500. break
  1501. case 5:
  1502. advice.AdviceName = "枸橼酸钠"
  1503. break
  1504. case 6:
  1505. advice.AdviceName = "低分子肝素钙"
  1506. break
  1507. case 7:
  1508. advice.AdviceName = "低分子肝素钠"
  1509. break
  1510. case 8:
  1511. advice.AdviceName = "依诺肝素"
  1512. break
  1513. case 9:
  1514. advice.AdviceName = "达肝素"
  1515. break
  1516. case 10:
  1517. advice.AdviceName = "体外抗凝"
  1518. break
  1519. case 11:
  1520. advice.AdviceName = "那曲肝素"
  1521. break
  1522. case 12:
  1523. advice.AdviceName = "无抗凝剂"
  1524. break
  1525. }
  1526. advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1527. if appRole.UserType == 2 || appRole.UserType == 1 {
  1528. advice.AdviceDoctor = appRole.AdminUserId
  1529. }
  1530. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1531. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1532. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 5 || anticoagulant == 7) {
  1533. advice.AdviceName = "低分子肝素钠注射液"
  1534. // 修改患者临时医嘱里的抗凝剂医嘱
  1535. advice.ID = advicePrescription.ID
  1536. service.UpdateDoctorAdvice(&advice)
  1537. } else {
  1538. if anticoagulant == 3 || anticoagulant == 5 || anticoagulant == 7 {
  1539. advice.AdviceName = "低分子肝素钠注射液"
  1540. }
  1541. // 新增患者临时医嘱里的抗凝剂医嘱
  1542. service.CreateDoctorAdvice(&advice)
  1543. }
  1544. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1545. redis := service.RedisClient()
  1546. defer redis.Close()
  1547. //清空key 值
  1548. redis.Set(key, "", time.Second)
  1549. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1550. redis.Set(keyOne, "", time.Second)
  1551. }
  1552. //获取key,清空redis
  1553. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1554. redis := service.RedisClient()
  1555. //清空key 值
  1556. redis.Set(key, "", time.Second)
  1557. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1558. //清空key 值
  1559. redis.Set(keyOne, "", time.Second)
  1560. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1561. //清空key 值
  1562. redis.Set(keyTwo, "", time.Second)
  1563. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1564. redis.Set(keySix, "", time.Second)
  1565. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1566. redis.Set(keySeven, "", time.Second)
  1567. if err == nil {
  1568. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1569. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1570. //清空key 值
  1571. redis.Set(keyThree, "", time.Second)
  1572. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1573. //清空key 值
  1574. redis.Set(keyFour, "", time.Second)
  1575. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1576. redis.Set(keyFive, "", time.Second)
  1577. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1578. redis.Set(keySix, "", time.Second)
  1579. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1580. redis.Set(keySeven, "", time.Second)
  1581. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1582. //清空key 值
  1583. redis.Set(keyOne, "", time.Second)
  1584. if updateErr != nil {
  1585. utils.ErrorLog("%v", updateErr)
  1586. }
  1587. defer redis.Close()
  1588. c.ServeSuccessJSON(map[string]interface{}{
  1589. "prescription": prescription,
  1590. })
  1591. }
  1592. } else { //修改
  1593. //if mode_id > 0 {
  1594. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1595. //}
  1596. //if template.TemplateId == 1 {
  1597. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1598. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1599. // if getPermissionErr != nil {
  1600. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1601. // return
  1602. // } else if headNursePermission == nil {
  1603. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1604. // return
  1605. // }
  1606. // }
  1607. //}
  1608. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1609. prescription.Modifier = adminUserInfo.AdminUser.Id
  1610. if appRole.UserType == 2 || appRole.UserType == 1 {
  1611. prescription_doctor := adminUserInfo.AdminUser.Id
  1612. prescription.PrescriptionDoctor = prescription_doctor
  1613. } else {
  1614. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1615. }
  1616. if dialysisPrescription.Creater == 0 { //体重称
  1617. prescription.Creater = adminUserInfo.AdminUser.Id
  1618. } else {
  1619. prescription.Creater = dialysisPrescription.Creater
  1620. }
  1621. prescription.ID = dialysisPrescription.ID
  1622. err := service.UpDateDialysisPrescription(&prescription)
  1623. //获取key,清空redis
  1624. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1625. redis := service.RedisClient()
  1626. //清空key 值
  1627. redis.Set(key, "", time.Second)
  1628. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1629. //清空key 值
  1630. redis.Set(keyOne, "", time.Second)
  1631. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1632. redis.Set(keySix, "", time.Second)
  1633. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1634. redis.Set(keySeven, "", time.Second)
  1635. if err == nil {
  1636. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1637. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1638. //清空key 值
  1639. redis.Set(keyOne, "", time.Second)
  1640. defer redis.Close()
  1641. if updateErr != nil {
  1642. utils.ErrorLog("%v", updateErr)
  1643. }
  1644. c.ServeSuccessJSON(map[string]interface{}{
  1645. "prescription": prescription,
  1646. })
  1647. }
  1648. }
  1649. }
  1650. func (c *DialysisAPIController) Finish() {
  1651. id, _ := c.GetInt64("patient", 0)
  1652. recordDateStr := c.GetString("record_date")
  1653. nurseID, _ := c.GetInt64("nurse")
  1654. end_time := c.GetString("end_time")
  1655. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1656. internal_fistula := c.GetString("blood_access_internal_fistula")
  1657. catheter := c.GetString("catheter")
  1658. cruor := c.GetString("cruor")
  1659. mission := c.GetString("mission")
  1660. if id <= 0 || nurseID <= 0 {
  1661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1662. return
  1663. }
  1664. adminUserInfo := c.GetMobileAdminUserInfo()
  1665. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1666. if patient.ID == 0 {
  1667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1668. return
  1669. }
  1670. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1671. if getNurseErr != nil {
  1672. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1674. return
  1675. } else if nurse == nil {
  1676. c.ErrorLog("护士不存在")
  1677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1678. return
  1679. }
  1680. if len(recordDateStr) == 0 {
  1681. recordDateStr = time.Now().Format("2006-01-02")
  1682. }
  1683. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1684. if parseDateErr != nil {
  1685. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1687. return
  1688. }
  1689. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1690. if parseEndDateErr != nil {
  1691. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1693. return
  1694. }
  1695. //now := time.Now()
  1696. //year, month, day := now.Date()
  1697. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1698. //todayTimeStamp := today_time.Unix()
  1699. // 获取当天的第一条透析纪录
  1700. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1701. if getMonitorRecordsErr != nil {
  1702. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1704. return
  1705. }
  1706. // 获取当前的最后一条透析纪录
  1707. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1708. if getMonitorRecordsErr != nil {
  1709. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1711. return
  1712. }
  1713. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1714. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1715. if getAADErr != nil {
  1716. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1718. return
  1719. }
  1720. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1721. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1722. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1723. if assessmentAfterDislysis != nil {
  1724. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1725. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1726. } else {
  1727. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1728. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1729. tempassessmentAfterDislysis.Status = 1
  1730. tempassessmentAfterDislysis.PatientId = id
  1731. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1732. }
  1733. //长沙南雅
  1734. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  1735. //获取最后一条透析处方数据
  1736. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1737. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1738. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  1739. }
  1740. if dialysisOrder.Stage == 1 {
  1741. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1742. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1743. fmt.Println(value)
  1744. a, b := math.Modf(value)
  1745. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1746. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1747. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1748. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1749. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1750. }
  1751. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1752. //var num1 int64
  1753. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1754. //fmt.Println(num1)
  1755. //sub := float64(num1 / 3600)
  1756. //fmt.Println(sub)
  1757. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1758. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1759. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1760. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1761. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1762. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1763. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1764. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1765. if adminUserInfo.Org.Id != 10445 {
  1766. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1767. }
  1768. //北方营口医院
  1769. if adminUserInfo.Org.Id == 10445 {
  1770. //获取最后一条透析处方数据
  1771. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1772. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  1773. } else {
  1774. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1775. }
  1776. //新化博翔
  1777. if adminUserInfo.Org.Id == 10447 {
  1778. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1779. }
  1780. }
  1781. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 {
  1782. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1783. if evaluation.SystolicBloodPressure == 0 {
  1784. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  1785. pre := models.PredialysisEvaluation{
  1786. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  1787. }
  1788. fmt.Println("prew", pre)
  1789. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1790. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1791. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1792. redis := service.RedisClient()
  1793. redis.Set(key, "", time.Second)
  1794. redis.Set(keyOne, "", time.Second)
  1795. defer redis.Close()
  1796. fmt.Println(getNurseErr)
  1797. }
  1798. if evaluation.DiastolicBloodPressure == 0 {
  1799. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  1800. pres := models.PredialysisEvaluation{
  1801. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  1802. }
  1803. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1804. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1805. redis := service.RedisClient()
  1806. redis.Set(key, "", time.Second)
  1807. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1808. redis.Set(keyOne, "", time.Second)
  1809. defer redis.Close()
  1810. fmt.Println(getNurseErr)
  1811. }
  1812. if evaluation.PulseFrequency == 0 {
  1813. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1814. press := models.PredialysisEvaluation{
  1815. PulseFrequency: evaluation.PulseFrequency,
  1816. }
  1817. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1818. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1819. redis := service.RedisClient()
  1820. redis.Set(key, "", time.Second)
  1821. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1822. redis.Set(keyOne, "", time.Second)
  1823. defer redis.Close()
  1824. fmt.Println(getNurseErr)
  1825. }
  1826. if evaluation.Temperature == 0 {
  1827. evaluation.Temperature = fmonitorRecords.Temperature
  1828. press := models.PredialysisEvaluation{
  1829. Temperature: evaluation.Temperature,
  1830. }
  1831. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1832. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1833. redis := service.RedisClient()
  1834. redis.Set(key, "", time.Second)
  1835. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1836. redis.Set(keyOne, "", time.Second)
  1837. defer redis.Close()
  1838. fmt.Println(getNurseErr)
  1839. }
  1840. }
  1841. if adminUserInfo.Org.Id == 9583 {
  1842. //获取透析处方的最后一条数据
  1843. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  1844. if diaerr != nil {
  1845. c.ErrorLog("获取透析处方失败:%v", diaerr)
  1846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1847. return
  1848. }
  1849. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  1850. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  1851. }
  1852. }
  1853. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  1854. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1855. }
  1856. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  1857. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1858. }
  1859. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  1860. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1861. }
  1862. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  1863. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1864. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1865. }
  1866. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  1867. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1868. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1869. }
  1870. if lastAssessmentAfterDislysis != nil {
  1871. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1872. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1873. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1874. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1875. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1876. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1877. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1878. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1879. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1880. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1881. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1882. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1883. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1884. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1885. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1886. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1887. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1888. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1889. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1890. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1891. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1892. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1893. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1894. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1895. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1896. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1897. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1898. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1899. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1900. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1901. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1902. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1903. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1904. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1905. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1906. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1907. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1908. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1909. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1910. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1911. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1912. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1913. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1914. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1915. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1916. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1917. }
  1918. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1919. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1920. redis := service.RedisClient()
  1921. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1922. redis.Set(keyOne, "", time.Second)
  1923. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  1924. redis.Set(keyTwo, "", time.Second)
  1925. defer redis.Close()
  1926. //清空key 值
  1927. redis.Set(key, "", time.Second)
  1928. if err != nil {
  1929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1930. return
  1931. }
  1932. if dialysisOrder == nil {
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1934. return
  1935. }
  1936. if dialysisOrder.Stage == 2 {
  1937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1938. return
  1939. }
  1940. if dialysisOrder.Stage == 1 {
  1941. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  1942. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1943. redis := service.RedisClient()
  1944. defer redis.Close()
  1945. //清空key 值
  1946. redis.Set(key, "", time.Second)
  1947. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1948. redis.Set(keyOne, "", time.Second)
  1949. //结束时候透析次数加1
  1950. service.UpdateSolutionByPatientId(id)
  1951. //下机完自动消毒,针对长沙南雅
  1952. if dialysisOrder.Stage == 1 {
  1953. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1954. //根据床位号获取设备型号
  1955. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  1956. //查询使用消毒最后一条消毒记录
  1957. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  1958. fmt.Println("err", err)
  1959. if err == gorm.ErrRecordNotFound {
  1960. //查找排班
  1961. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  1962. //查询改设备是否有消毒计划
  1963. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  1964. //根据床位号获取设备id
  1965. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  1966. //查询病人信息
  1967. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  1968. var con = ""
  1969. if patients.IsInfectious == 0 {
  1970. con = ""
  1971. }
  1972. if patients.IsInfectious == 1 {
  1973. con = "无"
  1974. }
  1975. if patients.IsInfectious == 2 {
  1976. con = "有"
  1977. }
  1978. if errcode == nil {
  1979. var end_time int64
  1980. end_time = endDate.Unix() + plan.DisinfecTime*60
  1981. //新增消毒
  1982. information := models.DeviceInformation{
  1983. Date: dialysisOrder.DialysisDate,
  1984. Zone: dialysisOrder.ZoneId,
  1985. Class: dialysisOrder.SchedualType,
  1986. BedNumber: dialysisOrder.BedID,
  1987. PatientId: dialysisOrder.PatientId,
  1988. DialysisMode: scheduleByPatient.ModeId,
  1989. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  1990. Disinfection: 1,
  1991. DialysisConcentration: 1,
  1992. DisinfectionStatus: 1,
  1993. Move: 1,
  1994. UserOrgId: dialysisOrder.UserOrgId,
  1995. DisinfectType: plan.Way,
  1996. DisinfectantType: plan.MachineDisinfectant,
  1997. FluidPath: plan.DisinfectanWay, //液路消毒方式
  1998. Disinfectant: plan.Disinfectant,
  1999. Ctime: time.Now().Unix(),
  2000. Status: 1,
  2001. SignName: nurseID,
  2002. EquimentId: addmacher.ID,
  2003. DisinfectionResidue: 2,
  2004. Bed: addmacher.BedNumber,
  2005. StartTime: dialysisOrder.StartTime,
  2006. EndTime: dialysisOrder.EndTime,
  2007. Contagion: con,
  2008. WeightLoss: 0,
  2009. Hyperfiltratio: 0,
  2010. DialysisHour: "",
  2011. MachineRun: 1,
  2012. DisinfecStartime: endDate.Unix(),
  2013. DisinfecEndtime: end_time,
  2014. }
  2015. err := service.CreateInformationTwo(&information)
  2016. fmt.Println("报错", err)
  2017. }
  2018. }
  2019. }
  2020. }
  2021. dialysisOrder.Stage = 2
  2022. dialysisOrder.FinishNurse = nurseID
  2023. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2024. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2025. dialysisOrder.EndTime = endDate.Unix()
  2026. go func() {
  2027. ssoDomain := beego.AppConfig.String("call_domain")
  2028. api := ssoDomain + "/index/downpatient"
  2029. values := make(url.Values)
  2030. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2031. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2032. values.Set("patient_id", strconv.FormatInt(id, 10))
  2033. http.PostForm(api, values)
  2034. }()
  2035. if err == nil {
  2036. c.ServeSuccessJSON(map[string]interface{}{
  2037. "dialysisOrder": dialysisOrder,
  2038. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2039. })
  2040. } else {
  2041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2042. }
  2043. }
  2044. }
  2045. func (c *DialysisAPIController) GetAllZone() {
  2046. adminUserInfo := c.GetMobileAdminUserInfo()
  2047. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2048. if err == nil {
  2049. c.ServeSuccessJSON(map[string]interface{}{
  2050. "zone": zone,
  2051. })
  2052. }
  2053. }
  2054. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2055. adminUserInfo := c.GetMobileAdminUserInfo()
  2056. page, _ := c.GetInt64("page", 1)
  2057. limit, _ := c.GetInt64("limit", 10)
  2058. schedulType, _ := c.GetInt64("schedul_type", 0)
  2059. startTime, _ := c.GetInt64("schedul_time", 0)
  2060. partitionType, _ := c.GetInt64("partition_type", 0)
  2061. keywords := c.GetString("keywords")
  2062. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2063. if err == nil {
  2064. c.ServeSuccessJSON(map[string]interface{}{
  2065. "schedule": dialysisSchedule,
  2066. })
  2067. }
  2068. return
  2069. }
  2070. // /m/api/dialysis/start [post]
  2071. // @param patient_id:int
  2072. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2073. // @param nurse:int 上机护士
  2074. // @param bed:int 床位号
  2075. func (this *DialysisAPIController) StartDialysis() {
  2076. patientID, _ := this.GetInt64("patient_id")
  2077. recordDateStr := this.GetString("record_date")
  2078. nurseID, _ := this.GetInt64("nurse")
  2079. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2080. blood_drawing, _ := this.GetInt64("blood_drawing")
  2081. schedual_type, _ := this.GetInt64("schedual_type")
  2082. bedID, _ := this.GetInt64("bed")
  2083. start_time := this.GetString("start_time")
  2084. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2085. change_nurse, _ := this.GetInt64("change_nurse")
  2086. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2087. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2088. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2089. puncture_needle := this.GetString("puncture_needle")
  2090. puncture_way := this.GetString("puncture_way")
  2091. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2092. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2093. blood_access_id, _ := this.GetInt64("blood_access_id")
  2094. zone_id, _ := this.GetInt64("zone_id")
  2095. elecsign := this.GetString("url")
  2096. nuclein_date_str := this.GetString("nuclein_date_str")
  2097. schedule_remark := this.GetString("schedule_remark")
  2098. order_remark := this.GetString("order_remark")
  2099. catheter_operation := this.GetString("catheter_operation")
  2100. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2102. return
  2103. }
  2104. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2105. if parseStartDateErr != nil {
  2106. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2107. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2108. return
  2109. }
  2110. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2111. if parseErr != nil {
  2112. this.ErrorLog("时间解析失败:%v", parseErr)
  2113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2114. return
  2115. }
  2116. adminUserInfo := this.GetMobileAdminUserInfo()
  2117. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2118. if getPatientErr != nil {
  2119. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2120. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2121. return
  2122. } else if patient == nil {
  2123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2124. return
  2125. }
  2126. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2127. if getNurseErr != nil {
  2128. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2130. return
  2131. } else if nurse == nil {
  2132. this.ErrorLog("护士不存在")
  2133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2134. return
  2135. }
  2136. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2137. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2138. if getDeviceNumberErr != nil {
  2139. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2140. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2141. return
  2142. } else if deviceNumber == nil {
  2143. this.ErrorLog("床位号不存在")
  2144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2145. return
  2146. }
  2147. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2148. if getRecordErr != nil {
  2149. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2151. return
  2152. } else if dialysisRecord != nil {
  2153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2154. return
  2155. }
  2156. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2157. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2158. timeLayout := "2006-01-02 15:04:05"
  2159. loc, _ := time.LoadLocation("Local")
  2160. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2161. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2162. schedulestartTime := theStartTime.Unix()
  2163. scheduleendTime := theEndTime.Unix()
  2164. var theNucleinDate int64
  2165. timeLayoutOne := "2006-01-02"
  2166. if len(nuclein_date_str) > 0 {
  2167. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2168. if err != nil {
  2169. utils.ErrorLog(err.Error())
  2170. }
  2171. theNucleinDate = theTime.Unix()
  2172. }
  2173. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2174. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2175. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2176. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2177. //查询该床位是否有人用了
  2178. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2179. if err == gorm.ErrRecordNotFound { //空床位
  2180. // 修改了床位逻辑
  2181. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2182. if daySchedule.ID > 0 {
  2183. daySchedule.PartitionId = deviceNumber.ZoneID
  2184. daySchedule.BedId = bedID
  2185. daySchedule.ScheduleType = schedual_type
  2186. daySchedule.UpdatedTime = time.Now().Unix()
  2187. xtSchedule := models.Schedule{
  2188. PartitionId: deviceNumber.ZoneID,
  2189. BedId: bedID,
  2190. ScheduleType: schedual_type,
  2191. UpdatedTime: time.Now().Unix(),
  2192. }
  2193. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2194. if err != nil {
  2195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2196. return
  2197. }
  2198. }
  2199. } else if err == nil {
  2200. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2201. if order.ID > 0 { //该机位被其他人占用了
  2202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2203. return
  2204. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2205. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2206. if daySchedule.ID > 0 {
  2207. //daySchedule.PartitionId = deviceNumber.ZoneID
  2208. //daySchedule.BedId = bedID
  2209. //daySchedule.ScheduleType = schedual_type
  2210. //daySchedule.UpdatedTime = time.Now().Unix()
  2211. //err := service.UpdateSchedule(&daySchedule)
  2212. //xtSchedule := models.Schedule{
  2213. // PartitionId: deviceNumber.ZoneID,
  2214. // BedId: bedID,
  2215. // ScheduleType: schedual_type,
  2216. // UpdatedTime: time.Now().Unix(),
  2217. //}
  2218. //err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2219. service.UpdateScheduleTwo(daySchedule, schedule)
  2220. }
  2221. }
  2222. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2224. return
  2225. }
  2226. //else if order.ID == 0 { //该床位没被占用
  2227. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2228. // if daySchedule.ID > 0 {
  2229. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2230. // //daySchedule.BedId = bedID
  2231. // //daySchedule.ScheduleType = schedual_type
  2232. // //daySchedule.UpdatedTime = time.Now().Unix()
  2233. // //err := service.UpdateSchedule(&daySchedule)
  2234. // xtSchedule := models.Schedule{
  2235. // PartitionId: deviceNumber.ZoneID,
  2236. // BedId: bedID,
  2237. // ScheduleType: schedual_type,
  2238. // UpdatedTime: time.Now().Unix(),
  2239. // }
  2240. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2241. // if err != nil {
  2242. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2243. // return
  2244. // }
  2245. // }
  2246. //}
  2247. //}
  2248. } else if err != nil {
  2249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2250. return
  2251. }
  2252. dialysisRecord = &models.DialysisOrder{
  2253. DialysisDate: recordDate.Unix(),
  2254. UserOrgId: adminUserInfo.Org.Id,
  2255. PatientId: patientID,
  2256. Stage: 1,
  2257. BedID: bedID,
  2258. StartNurse: nurseID,
  2259. Status: 1,
  2260. StartTime: startDate.Unix(),
  2261. CreatedTime: time.Now().Unix(),
  2262. UpdatedTime: time.Now().Unix(),
  2263. PunctureNurse: puncture_nurse,
  2264. Creator: adminUserInfo.AdminUser.Id,
  2265. Modifier: adminUserInfo.AdminUser.Id,
  2266. SchedualType: schedual_type,
  2267. WashpipeNurse: washpipe_nurse,
  2268. ChangeNurse: change_nurse,
  2269. DifficultPunctureNurse: difficult_puncture_nurse,
  2270. NewFistulaNurse: new_fistula_nurse,
  2271. ZoneId: zone_id,
  2272. QualityNurseId: quality_nurse_id,
  2273. PunctureNeedle: puncture_needle,
  2274. PunctureWay: puncture_way,
  2275. DialysisIrrigation: dialysis_irrigation,
  2276. DialysisDialyszers: dialysis_dialyszers,
  2277. BloodAccessId: blood_access_id,
  2278. Url: elecsign,
  2279. NucleinDate: theNucleinDate,
  2280. ScheduleRemark: schedule_remark,
  2281. OrderRemark: order_remark,
  2282. CatheterOperation: catheter_operation,
  2283. }
  2284. //查询该床位是否有人用了
  2285. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2286. if errorscode == gorm.ErrRecordNotFound {
  2287. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2288. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2289. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2290. //统计该患者总次数
  2291. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2292. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2293. }
  2294. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2295. //统计该患者总次数
  2296. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2297. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2298. }
  2299. redis := service.RedisClient()
  2300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2301. redis.Set(key, "", time.Second)
  2302. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2303. //清空key 值
  2304. redis.Set(keyOne, "", time.Second)
  2305. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2306. //清空key 值
  2307. redis.Set(keyTwo, "", time.Second)
  2308. if createErr != nil {
  2309. this.ErrorLog("上机失败:%v", createErr)
  2310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2311. return
  2312. }
  2313. }
  2314. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2315. var tempdispose string
  2316. // 只针对中能建
  2317. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2318. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2319. }
  2320. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2321. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2322. }
  2323. var ultrafiltration_rate float64
  2324. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2325. //后期预增脱水量
  2326. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2327. if prescription.ID > 0 {
  2328. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2329. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2330. if (template.TemplateId == 6 || template.TemplateId == 32) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2331. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2332. }
  2333. //针对医师汇
  2334. if adminUserInfo.Org.Id == 10121 {
  2335. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2336. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2337. }
  2338. //针对通道
  2339. if adminUserInfo.Org.Id == 10234 {
  2340. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2341. }
  2342. //针对监利大垸医院
  2343. if template.TemplateId == 41 {
  2344. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2345. }
  2346. //针对肇庆三鹤血液透析中心
  2347. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 {
  2348. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2349. }
  2350. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2351. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2352. }
  2353. // 只针对方济医院
  2354. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2355. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2356. ultrafiltration_rate = value
  2357. }
  2358. }
  2359. }
  2360. record := models.MonitoringRecord{
  2361. UserOrgId: adminUserInfo.Org.Id,
  2362. PatientId: patientID,
  2363. DialysisOrderId: dialysisRecord.ID,
  2364. MonitoringDate: schedulestartTime,
  2365. OperateTime: startDate.Unix(),
  2366. // MonitoringTime: recordTime,
  2367. MonitoringNurse: nurseID,
  2368. Dispose: tempdispose,
  2369. UltrafiltrationRate: ultrafiltration_rate,
  2370. UltrafiltrationVolume: 0,
  2371. Status: 1,
  2372. CreatedTime: time.Now().Unix(),
  2373. UpdatedTime: time.Now().Unix(),
  2374. }
  2375. //只针对广慈医院
  2376. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 {
  2377. // 查询病人是否有透前评估数据
  2378. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2379. //如果有数据就插入
  2380. if errcode == nil {
  2381. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2382. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2383. record.BreathingRate = befor.BreathingRate
  2384. record.PulseFrequency = befor.PulseFrequency
  2385. record.Temperature = befor.Temperature
  2386. }
  2387. }
  2388. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2389. if newdialysisRecord.ID > 0 {
  2390. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2391. record.Temperature = 36.5
  2392. record.ArterialPressure = -100
  2393. record.DialysateTemperature = 36.5
  2394. record.Conductivity = 14
  2395. record.BreathingRate = "20"
  2396. record.VenousPressure = 80
  2397. record.TransmembranePressure = 60
  2398. }
  2399. //针对新化博翔
  2400. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2401. record.BloodOxygenSaturation = "99"
  2402. record.Conductivity = 14
  2403. record.DialysateTemperature = 36.5
  2404. record.BreathingRate = "20"
  2405. }
  2406. //针对兰溪人民医院的需求
  2407. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2408. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2409. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2410. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2411. record.Temperature = befor.Temperature
  2412. record.PulseFrequency = befor.PulseFrequency
  2413. record.BreathingRate = befor.BreathingRate
  2414. }
  2415. //新化博翔
  2416. if adminUserInfo.Org.Id == 10447 {
  2417. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2418. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2419. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2420. record.BreathingRate = befor.BreathingRate
  2421. }
  2422. if adminUserInfo.Org.Id == 9829 {
  2423. record.PulseFrequency = 80
  2424. record.Temperature = 36.5
  2425. }
  2426. err := service.CreateMonitor(&record)
  2427. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  2428. redis := service.RedisClient()
  2429. //清空key 值
  2430. redis.Set(key, "", time.Second)
  2431. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  2432. redis.Set(keyOne, "", time.Second)
  2433. defer redis.Close()
  2434. if err != nil {
  2435. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2436. return
  2437. }
  2438. }
  2439. go func() {
  2440. ssoDomain := beego.AppConfig.String("call_domain")
  2441. api := ssoDomain + "/index/uppatient"
  2442. values := make(url.Values)
  2443. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  2444. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2445. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  2446. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  2447. http.PostForm(api, values)
  2448. }()
  2449. this.ServeSuccessJSON(map[string]interface{}{
  2450. "dialysis_order": newdialysisRecord,
  2451. "monitor": record,
  2452. })
  2453. return
  2454. }
  2455. func (c *DialysisAPIController) PostSolution() {
  2456. id, _ := c.GetInt64("patient", 0)
  2457. recordDateStr := c.GetString("record_date")
  2458. if id <= 0 {
  2459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2460. return
  2461. }
  2462. adminUserInfo := c.GetMobileAdminUserInfo()
  2463. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2464. if patient.ID == 0 {
  2465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2466. return
  2467. }
  2468. if len(recordDateStr) == 0 {
  2469. recordDateStr = time.Now().Format("2006-01-02")
  2470. }
  2471. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2472. if parseDateErr != nil {
  2473. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2475. return
  2476. }
  2477. mode_id, _ := c.GetInt64("mode_id", 0)
  2478. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  2479. dialyzer, _ := c.GetInt64("dialyzer", 0)
  2480. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  2481. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2482. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  2483. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  2484. replacement_way, _ := c.GetInt64("replacement_way", 0)
  2485. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  2486. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  2487. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  2488. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  2489. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  2490. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  2491. kalium, _ := c.GetFloat("kalium", 0)
  2492. sodium, _ := c.GetFloat("sodium", 0)
  2493. calcium, _ := c.GetFloat("calcium", 0)
  2494. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  2495. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  2496. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  2497. glucose, _ := c.GetFloat("glucose", 0)
  2498. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  2499. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2500. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2501. conductivity, _ := c.GetFloat("conductivity", 0)
  2502. remark := c.GetString("remark")
  2503. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  2504. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  2505. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  2506. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  2507. body_fluid, _ := c.GetInt64("body_fluid", 0)
  2508. special_medicine, _ := c.GetInt64("special_medicine", 0)
  2509. special_medicine_other := c.GetString("special_medicine_other")
  2510. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  2511. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  2512. blood_access, _ := c.GetInt64("blood_access", 0)
  2513. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  2514. body_fluid_other := c.GetString("body_fluid_other")
  2515. replacement_total, _ := c.GetFloat("replacement_total", 0)
  2516. niprocart, _ := c.GetInt64("niprocart", 0)
  2517. jms, _ := c.GetInt64("jms", 0)
  2518. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  2519. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  2520. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  2521. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  2522. filtryzer, _ := c.GetInt64("filtryzer", 0)
  2523. target_ktv, _ := c.GetFloat("target_ktv", 0)
  2524. dialyzers, _ := c.GetInt64("dialyzers", 0)
  2525. injector, _ := c.GetInt64("injector", 0)
  2526. bloodlines, _ := c.GetInt64("bloodlines", 0)
  2527. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  2528. safe_package, _ := c.GetInt64("package", 0)
  2529. a_liquid, _ := c.GetInt64("a_liquid", 0)
  2530. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  2531. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  2532. blood := c.GetString("blood")
  2533. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  2534. dialysis_irrigation := c.GetString("dialysis_irrigation")
  2535. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  2536. displace_speed := c.GetString("displace_speed")
  2537. illness, _ := c.GetInt64("illness")
  2538. amylaceum := c.GetString("amylaceum")
  2539. single_time := c.GetString("single_time")
  2540. single_water := c.GetString("single_water")
  2541. replacement_flow := c.GetString("replacement_flow")
  2542. plasma_separator := c.GetString("plasma_separator")
  2543. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  2544. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  2545. oxygen_flow := c.GetString("oxygen_flow")
  2546. oxygen_time := c.GetString("oxygen_time")
  2547. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  2548. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  2549. puncture_needle := c.GetString("puncture_needle")
  2550. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  2551. epo := c.GetString("epo")
  2552. epo_count, _ := c.GetFloat("epo_count", 0)
  2553. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  2554. pre_impulse := c.GetString("pre_impulse")
  2555. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  2556. admin_user_id, _ := c.GetInt64("admin_user_id")
  2557. is_water := c.GetString("is_water")
  2558. add_amount, _ := c.GetFloat("add_amount")
  2559. reduce_amount, _ := c.GetFloat("reduce_amount")
  2560. prescribing_number, _ := c.GetFloat("prescribing_number")
  2561. treatment_remark := c.GetString("treatment_remark")
  2562. prescription_sodium := c.GetString("prescription_sodium")
  2563. start_sodium := c.GetString("start_sodium")
  2564. sodium_curve := c.GetString("sodium_curve")
  2565. var is_war int64
  2566. if is_water == "是" {
  2567. is_war = 1
  2568. }
  2569. if is_water == "否" {
  2570. is_war = 2
  2571. }
  2572. if is_water == "请选择" {
  2573. is_war = 0
  2574. }
  2575. drhy_water := c.GetString("drhy_water")
  2576. dry_water_hour := c.GetString("dry_water_hour")
  2577. water_machine := c.GetString("water_machine")
  2578. dialysis_remark := c.GetString("dialysis_remark")
  2579. if mode_id > 0 {
  2580. var str string
  2581. //查找该机构用的是什么透析器
  2582. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  2583. if filedConfig.ID > 0 {
  2584. str = dialyzerPerfusionApparatus
  2585. } else {
  2586. str = dialysis_dialyszers + "/" + dialysis_irrigation
  2587. }
  2588. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  2589. }
  2590. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2591. //
  2592. //if template.TemplateId == 2 || template.TemplateId == 6 {
  2593. // if appRole.UserType == 3 {
  2594. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2595. // if getPermissionErr != nil {
  2596. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2597. // return
  2598. // } else if headNursePermission == nil {
  2599. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2600. // return
  2601. // }
  2602. // }
  2603. //}
  2604. prescription := models.DialysisPrescription{
  2605. UserOrgId: adminUserInfo.Org.Id,
  2606. PatientId: id,
  2607. RecordDate: recordDate.Unix(),
  2608. ModeId: mode_id,
  2609. DialysisDuration: dialysis_duration,
  2610. Dialyzer: dialyzer,
  2611. PerfusionApparatus: perfusion_apparatus,
  2612. BloodFlowVolume: blood_flow_volume,
  2613. DewaterAmount: dewater_amount,
  2614. DisplaceLiqui: displace_liqui,
  2615. ReplacementWay: replacement_way,
  2616. Anticoagulant: anticoagulant,
  2617. AnticoagulantShouji: anticoagulant_shouji,
  2618. AnticoagulantWeichi: anticoagulant_weichi,
  2619. AnticoagulantZongliang: anticoagulant_zongliang,
  2620. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2621. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2622. Kalium: kalium,
  2623. Sodium: sodium,
  2624. Calcium: calcium,
  2625. Bicarbonate: bicarbonate,
  2626. Glucose: glucose,
  2627. // DryWeight: dry_weight,
  2628. DialysateFlow: dialysate_flow,
  2629. DialysateTemperature: dialysate_temperature,
  2630. Conductivity: conductivity,
  2631. Remark: remark,
  2632. Status: 1,
  2633. CreatedTime: time.Now().Unix(),
  2634. UpdatedTime: time.Now().Unix(),
  2635. DialysisDurationMinute: dialysisDurationMinute,
  2636. DialysisDurationHour: dialysisDurationHour,
  2637. TargetUltrafiltration: targetUltrafiltration,
  2638. DialysateFormulation: dialysateFormulation,
  2639. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2640. BodyFluid: body_fluid,
  2641. SpecialMedicine: special_medicine,
  2642. SpecialMedicineOther: special_medicine_other,
  2643. DisplaceLiquiPart: displace_liqui_part,
  2644. DisplaceLiquiValue: displace_liqui_value,
  2645. BloodAccess: blood_access,
  2646. Ultrafiltration: ultrafiltration,
  2647. BodyFluidOther: body_fluid_other,
  2648. ReplacementTotal: replacement_total,
  2649. Niprocart: niprocart,
  2650. Jms: jms,
  2651. FistulaNeedleSet: fistula_needle_set,
  2652. FistulaNeedleSet16: fistula_needle_set_16,
  2653. Hemoperfusion: hemoperfusion,
  2654. DialyserSterilised: dialyser_sterilised,
  2655. Filtryzer: filtryzer,
  2656. TargetKtv: target_ktv,
  2657. Dialyzers: dialyzers,
  2658. Injector: injector,
  2659. Bloodlines: bloodlines,
  2660. TubingHemodialysis: tubing_hemodialysis,
  2661. Package: safe_package,
  2662. ALiquid: a_liquid,
  2663. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  2664. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  2665. Blood: blood,
  2666. DialysisDialyszers: dialysis_dialyszers,
  2667. DialysisIrrigation: dialysis_irrigation,
  2668. AntioxidantCommodityName: antioxidant_commodity_name,
  2669. DisplaceSpeed: displace_speed,
  2670. Illness: illness,
  2671. Amylaceum: amylaceum,
  2672. SingleWater: single_water,
  2673. SingleTime: single_time,
  2674. ReplacementFlow: replacement_flow,
  2675. PlasmaSeparator: plasma_separator,
  2676. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  2677. OxygenUptake: oxygen_uptake,
  2678. OxygenTime: oxygen_time,
  2679. OxygenFlow: oxygen_flow,
  2680. HemodialysisPipelines: hemodialysis_pipelines,
  2681. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2682. PunctureNeedle: puncture_needle,
  2683. PunctureNeedleCount: puncture_needle_count,
  2684. Epo: epo,
  2685. EpoCount: epo_count,
  2686. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2687. PreImpulse: impulse,
  2688. AdminUserId: admin_user_id,
  2689. IsWater: is_war,
  2690. DrhyWater: drhy_water,
  2691. DryWaterHour: dry_water_hour,
  2692. WaterMachine: water_machine,
  2693. AddAmount: add_amount,
  2694. ReduceAmount: reduce_amount,
  2695. DialysisRemark: dialysis_remark,
  2696. PrescribingNumber: prescribing_number,
  2697. PrescriptionSodium: prescription_sodium,
  2698. StartSodium: start_sodium,
  2699. SodiumCurve: sodium_curve,
  2700. TreatmentRemark: treatment_remark,
  2701. }
  2702. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2703. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2704. //
  2705. if appRole.UserType == 2 || appRole.UserType == 1 {
  2706. prescription_doctor = adminUserInfo.AdminUser.Id
  2707. prescription.PrescriptionDoctor = prescription_doctor
  2708. }
  2709. if dialysisPrescription.ID == 0 { //新增
  2710. prescription.Creater = adminUserInfo.AdminUser.Id
  2711. } else { //修改
  2712. if dialysisPrescription.Creater == 0 {
  2713. prescription.Creater = adminUserInfo.AdminUser.Id
  2714. } else {
  2715. prescription.Creater = dialysisPrescription.Creater
  2716. }
  2717. //if/**/
  2718. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2719. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  2720. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2721. // if getPermissionErr != nil {
  2722. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2723. // return
  2724. // } else if headNursePermission == nil {
  2725. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2726. // return
  2727. // }
  2728. //}
  2729. //prescription.Creater = dialysisPrescription.Creater
  2730. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2731. prescription.Modifier = adminUserInfo.AdminUser.Id
  2732. prescription.ID = dialysisPrescription.ID
  2733. }
  2734. solution := models.DialysisSolution{
  2735. RegistrarsId: adminUserInfo.AdminUser.Id,
  2736. UserOrgId: adminUserInfo.Org.Id,
  2737. Doctor: prescription_doctor,
  2738. PatientId: id,
  2739. ModeId: mode_id,
  2740. DialysisDuration: dialysis_duration,
  2741. PerfusionApparatus: perfusion_apparatus,
  2742. BloodFlowVolume: blood_flow_volume,
  2743. Dewater: dewater_amount,
  2744. DisplaceLiqui: displace_liqui,
  2745. ReplacementWay: replacement_way,
  2746. Anticoagulant: anticoagulant,
  2747. AnticoagulantShouji: anticoagulant_shouji,
  2748. AnticoagulantWeichi: anticoagulant_weichi,
  2749. AnticoagulantZongliang: anticoagulant_zongliang,
  2750. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2751. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2752. Kalium: kalium,
  2753. Sodium: sodium,
  2754. Calcium: calcium,
  2755. Bicarbonate: bicarbonate,
  2756. Glucose: glucose,
  2757. // DryWeight: dry_weight,
  2758. DialysateFlow: dialysate_flow,
  2759. DialysateTemperature: dialysate_temperature,
  2760. Conductivity: conductivity,
  2761. Remark: remark,
  2762. Status: 1,
  2763. CreatedTime: time.Now().Unix(),
  2764. UpdatedTime: time.Now().Unix(),
  2765. DialysisDurationMinute: dialysisDurationMinute,
  2766. DialysisDurationHour: dialysisDurationHour,
  2767. TargetUltrafiltration: targetUltrafiltration,
  2768. DialysateFormulation: dialysateFormulation,
  2769. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2770. BodyFluid: body_fluid,
  2771. SpecialMedicine: special_medicine,
  2772. SpecialMedicineOther: special_medicine_other,
  2773. DisplaceLiquiPart: displace_liqui_part,
  2774. DisplaceLiquiValue: displace_liqui_value,
  2775. BloodAccess: blood_access,
  2776. Ultrafiltration: ultrafiltration,
  2777. BodyFluidOther: body_fluid_other,
  2778. ReplacementTotal: replacement_total,
  2779. TargetKtv: target_ktv,
  2780. DialysisDialyszers: dialysis_dialyszers,
  2781. DialysisIrrigation: dialysis_irrigation,
  2782. HemodialysisPipelines: hemodialysis_pipelines,
  2783. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2784. PunctureNeedle: puncture_needle,
  2785. PunctureNeedleCount: puncture_needle_count,
  2786. Epo: epo,
  2787. EpoCount: epo_count,
  2788. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2789. PreImpulse: impulse,
  2790. SolutionStatus: 1,
  2791. DialysisRemark: dialysis_remark,
  2792. PrescribingNumber: prescribing_number,
  2793. PrescriptionSodium: prescription_sodium,
  2794. StartSodium: start_sodium,
  2795. SodiumCurve: sodium_curve,
  2796. TreatmentRemark: treatment_remark,
  2797. }
  2798. //针对河间咸的
  2799. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  2800. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  2801. solution.DisplaceLiquiPart = 0
  2802. solution.DisplaceLiquiValue = 0
  2803. }
  2804. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2805. prescription.DisplaceLiquiPart = 0
  2806. prescription.DisplaceLiquiValue = 0
  2807. }
  2808. }
  2809. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  2810. //获取最新1条
  2811. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  2812. //更新状态
  2813. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  2814. //长沙南雅医院,自动生成抗凝剂的临时处方
  2815. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2816. advice := models.DoctorAdvice{
  2817. UserOrgId: adminUserInfo.Org.Id,
  2818. PatientId: id,
  2819. GroupNo: 0,
  2820. AdviceType: 2,
  2821. RecordDate: recordDate.Unix(),
  2822. AdviceDate: recordDate.Unix(),
  2823. StartTime: recordDate.Unix() + 7*60*60, // 根据排班班次,给默认时间
  2824. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2825. AdviceDesc: "",
  2826. ReminderDate: 0,
  2827. SingleDose: 5000,
  2828. SingleDoseUnit: "iu",
  2829. DrugSpec: 0,
  2830. DrugSpecUnit: "",
  2831. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2832. PrescribingNumberUnit: "支",
  2833. DeliveryWay: "静脉注射",
  2834. ExecutionFrequency: "上机前",
  2835. AdviceDoctor: 0,
  2836. Status: 1,
  2837. CreatedTime: time.Now().Unix(),
  2838. UpdatedTime: time.Now().Unix(),
  2839. IsPrescription: 1,
  2840. }
  2841. // 查询排班信息
  2842. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2843. if schedulePatient.ID > 0 {
  2844. if schedulePatient.ScheduleType == 1 {
  2845. advice.StartTime = recordDate.Unix() + 7*60*60
  2846. }
  2847. if schedulePatient.ScheduleType == 2 {
  2848. advice.StartTime = recordDate.Unix() + 11*60*60
  2849. }
  2850. }
  2851. // 抗凝剂名称
  2852. switch anticoagulant {
  2853. case 1:
  2854. advice.AdviceName = "无肝素"
  2855. break
  2856. case 2:
  2857. advice.AdviceName = "普通肝素"
  2858. break
  2859. case 3:
  2860. advice.AdviceName = "低分子肝素"
  2861. break
  2862. case 4:
  2863. advice.AdviceName = "阿加曲班"
  2864. break
  2865. case 5:
  2866. advice.AdviceName = "枸橼酸钠"
  2867. break
  2868. case 6:
  2869. advice.AdviceName = "低分子肝素钙"
  2870. break
  2871. case 7:
  2872. advice.AdviceName = "低分子肝素钠"
  2873. break
  2874. case 8:
  2875. advice.AdviceName = "依诺肝素"
  2876. break
  2877. case 9:
  2878. advice.AdviceName = "达肝素"
  2879. break
  2880. case 10:
  2881. advice.AdviceName = "体外抗凝"
  2882. break
  2883. case 11:
  2884. advice.AdviceName = "那曲肝素"
  2885. break
  2886. case 12:
  2887. advice.AdviceName = "无抗凝剂"
  2888. break
  2889. }
  2890. advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2891. if appRole.UserType == 2 || appRole.UserType == 1 {
  2892. advice.AdviceDoctor = appRole.AdminUserId
  2893. }
  2894. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2895. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2896. if advicePrescription.ID > 0 {
  2897. // 修改患者临时医嘱里的抗凝剂医嘱
  2898. advice.ID = advicePrescription.ID
  2899. service.UpdateDoctorAdvice(&advice)
  2900. } else {
  2901. // 新增患者临时医嘱里的抗凝剂医嘱
  2902. service.CreateDoctorAdvice(&advice)
  2903. }
  2904. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2905. redis := service.RedisClient()
  2906. defer redis.Close()
  2907. //清空key 值
  2908. redis.Set(key, "", time.Second)
  2909. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2910. redis.Set(keyOne, "", time.Second)
  2911. }
  2912. //获取key,清空redis
  2913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2914. redis := service.RedisClient()
  2915. defer redis.Close()
  2916. //清空key 值
  2917. redis.Set(key, "", time.Second)
  2918. //清空长期医嘱的key
  2919. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2920. redis.Set(soulution_key, "", time.Second)
  2921. //查询最近透析准备表里是否存在 透析器 灌流器
  2922. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2923. redis.Set(keyOne, "", time.Second)
  2924. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2925. redis.Set(keyTwo, "", time.Second)
  2926. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2927. redis.Set(keyThree, "", time.Second)
  2928. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2929. redis.Set(keyFour, "", time.Second)
  2930. //splitStr := strings.Split(dialysis_dialyszers, ",")
  2931. //
  2932. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  2933. //
  2934. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  2935. //if len(mation)>0{
  2936. // for _, item := range splitStr {
  2937. // for _,it := range mation{
  2938. // if(item == it.SpecificationName){
  2939. //
  2940. // //查询最近一次的透析器
  2941. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2942. //
  2943. // if errcode == gorm.ErrRecordNotFound{
  2944. // //插入数据
  2945. // prepare := models.DialysisBeforePrepare{
  2946. // UserOrgId: adminUserInfo.Org.Id,
  2947. // PatientId: id,
  2948. // RecordDate: recordDate.Unix(),
  2949. // GoodTypeId: it.GoodTypeId,
  2950. // GoodId: it.ID,
  2951. // Count: 1,
  2952. // Ctime: time.Now().Unix(),
  2953. // Creater: adminUserInfo.AdminUser.Id,
  2954. // Status:1,
  2955. //
  2956. // }
  2957. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2958. // fmt.Println("",errcode)
  2959. // }
  2960. // }
  2961. // }
  2962. //
  2963. // }
  2964. //
  2965. // for _, item := range splitIrrigation {
  2966. // for _,it := range mation{
  2967. // if(item == it.SpecificationName){
  2968. // //查询最近一次的透析器
  2969. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2970. // if errcode == gorm.ErrRecordNotFound{
  2971. // //插入数据
  2972. // prepare := models.DialysisBeforePrepare{
  2973. // UserOrgId: adminUserInfo.Org.Id,
  2974. // PatientId: id,
  2975. // RecordDate: recordDate.Unix(),
  2976. // GoodTypeId: it.GoodTypeId,
  2977. // GoodId: it.ID,
  2978. // Count: 1,
  2979. // Ctime: time.Now().Unix(),
  2980. // Creater: adminUserInfo.AdminUser.Id,
  2981. // Status:1,
  2982. //
  2983. // }
  2984. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2985. // fmt.Println(errcode)
  2986. // }
  2987. // }
  2988. // }
  2989. // }
  2990. //}
  2991. c.ServeSuccessJSON(map[string]interface{}{
  2992. "solution": &solution,
  2993. "prescription": &prescription,
  2994. })
  2995. }
  2996. func (c *DialysisAPIController) GetAcceptsAssessment() {
  2997. patient, _ := c.GetInt64("patient", 0)
  2998. adminUserInfo := c.GetMobileAdminUserInfo()
  2999. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3000. c.ServeSuccessJSON(map[string]interface{}{
  3001. "receiveTreatmentAsses": receiveTreatmentAsses,
  3002. })
  3003. }
  3004. func (this *DialysisAPIController) PostSignInfo() {
  3005. patientID, _ := this.GetInt64("patient_id")
  3006. recordDateStr := this.GetString("date")
  3007. if patientID <= 0 {
  3008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3009. return
  3010. }
  3011. if len(recordDateStr) == 0 {
  3012. recordDateStr = time.Now().Format("2006-01-02")
  3013. }
  3014. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3015. if parseDateErr != nil {
  3016. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3018. return
  3019. }
  3020. adminInfo := this.GetMobileAdminUserInfo()
  3021. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3022. if err != nil {
  3023. this.ErrorLog("签名失败:%v", err)
  3024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3025. return
  3026. }
  3027. this.ServeSuccessJSON(map[string]interface{}{
  3028. "doctor_id": adminInfo.AdminUser.Id,
  3029. })
  3030. }
  3031. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3032. patientID, _ := this.GetInt64("patient_id")
  3033. adminInfo := this.GetMobileAdminUserInfo()
  3034. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3035. this.ServeSuccessJSON(map[string]interface{}{
  3036. "monitor": record,
  3037. })
  3038. }
  3039. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3040. thisTime := time.Now()
  3041. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3042. timeLayout := "2006-01-02 15:04:05"
  3043. loc, _ := time.LoadLocation("Local")
  3044. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3045. theAssessmentDateTime := theStartTime.Unix()
  3046. patientID, _ := this.GetInt64("patient_id")
  3047. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3048. adminInfo := this.GetMobileAdminUserInfo()
  3049. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3050. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3051. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3052. var ultrafiltration_rate float64
  3053. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3054. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3055. fmt.Println(evaluation)
  3056. if prescription.ID > 0 {
  3057. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3058. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3059. if template.TemplateId == 6 && adminInfo.Org.Id != 9538 {
  3060. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3061. record.UltrafiltrationRate = ultrafiltration_rate
  3062. }
  3063. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3064. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3065. record.UltrafiltrationRate = ultrafiltration_rate
  3066. }
  3067. if template.TemplateId == 20 || template.TemplateId == 22 {
  3068. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3069. record.UltrafiltrationRate = ultrafiltration_rate
  3070. }
  3071. // 只针对方济医院
  3072. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3073. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3074. ultrafiltration_rate = value
  3075. record.UltrafiltrationRate = ultrafiltration_rate
  3076. }
  3077. if template.TemplateId == 41 || template.TemplateId == 47 {
  3078. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3079. record.UltrafiltrationRate = ultrafiltration_rate
  3080. }
  3081. if template.TemplateId == 43 {
  3082. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3083. record.UltrafiltrationRate = ultrafiltration_rate
  3084. }
  3085. if template.TemplateId == 46 || template.TemplateId == 54 {
  3086. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3087. record.UltrafiltrationRate = ultrafiltration_rate
  3088. }
  3089. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 {
  3090. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3091. record.UltrafiltrationRate = ultrafiltration_rate
  3092. }
  3093. //if template.TemplateId == 47 {
  3094. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3095. // record.UltrafiltrationRate = ultrafiltration_rate
  3096. //}
  3097. }
  3098. }
  3099. // record.UltrafiltrationRate = ultrafiltration_rate
  3100. record.UltrafiltrationVolume = 0
  3101. 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
  3102. if ultrafiltration_rate > 0 {
  3103. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3104. record.UltrafiltrationVolume = value
  3105. }
  3106. }
  3107. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 { //adminInfo.Org.Id == 9538
  3108. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3109. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3110. record.UltrafiltrationVolume = ultrafiltration_volume
  3111. }
  3112. }
  3113. //长沙南雅
  3114. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 {
  3115. if ultrafiltration_rate > 0 {
  3116. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3117. record.UltrafiltrationVolume = ultrafiltration_volume
  3118. }
  3119. }
  3120. if template.TemplateId == 47 || template.TemplateId == 54 {
  3121. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3122. }
  3123. this.ServeSuccessJSON(map[string]interface{}{
  3124. "monitor": record,
  3125. })
  3126. }
  3127. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3128. record_id, _ := this.GetInt64("id")
  3129. nurseID, _ := this.GetInt64("nurse")
  3130. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3131. bedID, _ := this.GetInt64("bed")
  3132. start_time := this.GetString("start_time")
  3133. schedual_type, _ := this.GetInt64("schedual_type")
  3134. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3135. change_nurse, _ := this.GetInt64("change_nurse")
  3136. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3137. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3138. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3139. patient_id, _ := this.GetInt64("patient_id")
  3140. record_date, _ := this.GetInt64("record_date")
  3141. puncture_needle := this.GetString("puncture_needle")
  3142. puncture_way := this.GetString("puncture_way")
  3143. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3144. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3145. blood_access_id, _ := this.GetInt64("blood_access_id")
  3146. nuclein_date_str := this.GetString("nuclein_date_str")
  3147. order_remark := this.GetString("order_remark")
  3148. schedule_remark := this.GetString("schedule_remark")
  3149. catheter_operation := this.GetString("catheter_operation")
  3150. if record_id == 0 {
  3151. this.ErrorLog("id:%v", record_id)
  3152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3153. return
  3154. }
  3155. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3156. if parseStartDateErr != nil {
  3157. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3159. return
  3160. }
  3161. adminUserInfo := this.GetMobileAdminUserInfo()
  3162. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3163. if getNurseErr != nil {
  3164. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3166. return
  3167. } else if nurse == nil {
  3168. this.ErrorLog("护士不存在")
  3169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3170. return
  3171. }
  3172. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3173. //if getNurseErr != nil {
  3174. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3175. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3176. // return
  3177. //} else if nurse == nil {
  3178. // this.ErrorLog("护士不存在")
  3179. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3180. // return
  3181. //}
  3182. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3183. if getDeviceNumberErr != nil {
  3184. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3186. return
  3187. } else if deviceNumber == nil {
  3188. this.ErrorLog("床位号不存在")
  3189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3190. return
  3191. }
  3192. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  3193. //
  3194. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  3195. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3196. // if getPermissionErr != nil {
  3197. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3198. // return
  3199. // } else if headNursePermission == nil {
  3200. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3201. // return
  3202. // }
  3203. //}
  3204. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3205. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3206. timeLayout := "2006-01-02 15:04:05"
  3207. loc, _ := time.LoadLocation("Local")
  3208. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3209. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3210. schedulestartTime := theStartTime.Unix()
  3211. scheduleendTime := theEndTime.Unix()
  3212. var theNucleinDate int64
  3213. timeLayoutOne := "2006-01-02"
  3214. if len(nuclein_date_str) > 0 {
  3215. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3216. if err != nil {
  3217. utils.ErrorLog(err.Error())
  3218. }
  3219. theNucleinDate = theTime.Unix()
  3220. }
  3221. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3222. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3223. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3224. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  3225. if err == gorm.ErrRecordNotFound { //空床位
  3226. // 修改了床位逻辑
  3227. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3228. if daySchedule.ID > 0 {
  3229. //daySchedule.BedId = bedID
  3230. //daySchedule.PartitionId = deviceNumber.ZoneID
  3231. //daySchedule.ScheduleType = schedual_type
  3232. //daySchedule.UpdatedTime = time.Now().Unix()
  3233. //err := service.UpdateSchedule(&daySchedule)
  3234. xtSchedule := models.Schedule{
  3235. PartitionId: deviceNumber.ZoneID,
  3236. BedId: bedID,
  3237. ScheduleType: schedual_type,
  3238. UpdatedTime: time.Now().Unix(),
  3239. }
  3240. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3241. if err != nil {
  3242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3243. return
  3244. }
  3245. }
  3246. } else if err == nil {
  3247. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3248. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3249. if daySchedule.ID > 0 {
  3250. //daySchedule.BedId = bedID
  3251. //daySchedule.PartitionId = deviceNumber.ZoneID
  3252. //
  3253. //daySchedule.ScheduleType = schedual_type
  3254. //daySchedule.UpdatedTime = time.Now().Unix()
  3255. //err := service.UpdateSchedule(&daySchedule)
  3256. xtSchedule := models.Schedule{
  3257. PartitionId: deviceNumber.ZoneID,
  3258. BedId: bedID,
  3259. ScheduleType: schedual_type,
  3260. UpdatedTime: time.Now().Unix(),
  3261. }
  3262. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3263. if err != nil {
  3264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3265. return
  3266. }
  3267. }
  3268. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3270. return
  3271. }
  3272. } else if err != nil {
  3273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3274. return
  3275. }
  3276. }
  3277. dialysisRecord := &models.DialysisOrder{
  3278. ID: record_id,
  3279. UserOrgId: adminUserInfo.Org.Id,
  3280. BedID: bedID,
  3281. StartNurse: nurseID,
  3282. StartTime: startDate.Unix(),
  3283. PunctureNurse: puncture_nurse,
  3284. Creator: adminUserInfo.AdminUser.Id,
  3285. Modifier: adminUserInfo.AdminUser.Id,
  3286. WashpipeNurse: washpipe_nurse,
  3287. SchedualType: schedual_type,
  3288. ChangeNurse: change_nurse,
  3289. DifficultPunctureNurse: difficult_puncture_nurse,
  3290. NewFistulaNurse: new_fistula_nurse,
  3291. QualityNurseId: quality_nurse_id,
  3292. PunctureNeedle: puncture_needle,
  3293. PunctureWay: puncture_way,
  3294. DialysisDialyszers: dialysis_dialyszers,
  3295. DialysisIrrigation: dialysis_irrigation,
  3296. BloodAccessId: blood_access_id,
  3297. NucleinDate: theNucleinDate,
  3298. OrderRemark: order_remark,
  3299. ScheduleRemark: schedule_remark,
  3300. CatheterOperation: catheter_operation,
  3301. }
  3302. //修改床位号需要重新消毒
  3303. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 {
  3304. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  3305. }
  3306. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  3307. order, _ := service.GetLastPatientOrder(record_id)
  3308. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  3309. redis := service.RedisClient()
  3310. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  3311. redis.Set(key, "", time.Second)
  3312. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  3313. //清空key 值
  3314. redis.Set(keyOne, "", time.Second)
  3315. scheduleDateStartOne := startDate.Format("2006-01-02")
  3316. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3317. redis.Set(keyTwo, "", time.Second)
  3318. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  3319. redis.Set(keyThree, "", time.Second)
  3320. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  3321. redis.Set(keyFour, "", time.Second)
  3322. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  3323. redis.Set(keyFive, "", time.Second)
  3324. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  3325. redis.Set(keySix, "", time.Second)
  3326. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  3327. redis.Set(keySeven, "", time.Second)
  3328. if updateErr != nil {
  3329. this.ErrorLog("修改上机失败:%v", updateErr)
  3330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3331. return
  3332. }
  3333. if updateErr == nil {
  3334. if tempDialysisRecord.Stage == 2 {
  3335. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  3336. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  3337. fmt.Println(value)
  3338. a, b := math.Modf(value)
  3339. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  3340. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  3341. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  3342. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  3343. redis := service.RedisClient()
  3344. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  3345. redis.Set(key, "", time.Second)
  3346. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  3347. redis.Set(keyOne, "", time.Second)
  3348. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  3349. //清空key 值
  3350. redis.Set(keySix, "", time.Second)
  3351. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  3352. redis.Set(keySeven, "", time.Second)
  3353. redis.Close()
  3354. if updateAssessmentErr != nil {
  3355. utils.ErrorLog("%v", updateAssessmentErr)
  3356. }
  3357. }
  3358. }
  3359. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  3360. this.ServeSuccessJSON(map[string]interface{}{
  3361. "dialysis_order": dialysisRecords,
  3362. })
  3363. }
  3364. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  3365. record_id, _ := c.GetInt64("id")
  3366. nurseID, _ := c.GetInt64("nurse")
  3367. end_time := c.GetString("end_time")
  3368. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  3369. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  3370. catheter := c.GetString("catheter")
  3371. cruor := c.GetString("cruor")
  3372. mission := c.GetString("mission")
  3373. if record_id <= 0 || nurseID <= 0 {
  3374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3375. return
  3376. }
  3377. adminUserInfo := c.GetMobileAdminUserInfo()
  3378. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3379. if getNurseErr != nil {
  3380. c.ErrorLog("获取护士失败:%v", getNurseErr)
  3381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3382. return
  3383. } else if nurse == nil {
  3384. c.ErrorLog("护士不存在")
  3385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3386. return
  3387. }
  3388. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  3389. if parseEndDateErr != nil {
  3390. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  3391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3392. return
  3393. }
  3394. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  3395. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  3396. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3397. // if getPermissionErr != nil {
  3398. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3399. // return
  3400. // } else if headNursePermission == nil {
  3401. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3402. // return
  3403. // }
  3404. //}
  3405. dialysisRecord := &models.DialysisOrder{
  3406. ID: record_id,
  3407. UserOrgId: adminUserInfo.Org.Id,
  3408. EndTime: endDate.Unix(),
  3409. FinishNurse: nurseID,
  3410. FinishModifier: adminUserInfo.AdminUser.Id,
  3411. PuncturePointHaematoma: puncture_point_haematoma,
  3412. BloodAccessInternalFistula: blood_access_internal_fistula,
  3413. Catheter: catheter,
  3414. Cruor: cruor,
  3415. Mission: mission,
  3416. }
  3417. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  3418. redis := service.RedisClient()
  3419. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  3420. //清空key 值
  3421. redis.Set(key, "", time.Second)
  3422. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  3423. //清空key 值
  3424. redis.Set(keyOne, "", time.Second)
  3425. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  3426. redis.Set(keySeven, "", time.Second)
  3427. redis.Close()
  3428. if updateErr != nil {
  3429. c.ErrorLog("修改下机失败:%v", updateErr)
  3430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3431. return
  3432. }
  3433. if updateErr == nil {
  3434. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  3435. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  3436. a, b := math.Modf(value)
  3437. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  3438. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  3439. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  3440. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  3441. redis := service.RedisClient()
  3442. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  3443. redis.Set(keyTen, "", time.Second)
  3444. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  3445. redis.Set(keyTwo, "", time.Second)
  3446. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  3447. redis.Set(key, "", time.Second)
  3448. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  3449. redis.Set(keyThree, "", time.Second)
  3450. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  3451. redis.Set(keySeven, "", time.Second)
  3452. defer redis.Close()
  3453. if updateAssessmentErr != nil {
  3454. utils.ErrorLog("%v", updateAssessmentErr)
  3455. }
  3456. }
  3457. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  3458. c.ServeSuccessJSON(map[string]interface{}{
  3459. "dialysis_order": dialysisRecords,
  3460. })
  3461. }
  3462. func (c *DialysisAPIController) GetLongAdvice() {
  3463. patient_id, _ := c.GetInt64("id")
  3464. adminUserInfo := c.GetMobileAdminUserInfo()
  3465. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  3466. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  3467. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  3468. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  3469. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3470. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3471. c.ServeSuccessJSON(map[string]interface{}{
  3472. "status": "1",
  3473. })
  3474. return
  3475. } else { //开启推送提醒
  3476. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3477. var advice_three []*models.DoctorAdvice
  3478. recordDateStr := time.Now().Format("2006-01-02")
  3479. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3480. nowtime := recordDate.Unix()
  3481. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  3482. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  3483. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  3484. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  3485. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  3486. for _, advice := range advices {
  3487. if advice.FrequencyType == 3 {
  3488. t := time.Now()
  3489. week := int(t.Weekday())
  3490. fmt.Println(t.Weekday())
  3491. fmt.Println(week)
  3492. switch week {
  3493. case 1:
  3494. if strings.Index(advice.WeekDay, "周一") == -1 {
  3495. advice_three = append(advice_three, advice)
  3496. }
  3497. break
  3498. case 2:
  3499. if strings.Index(advice.WeekDay, "周二") == -1 {
  3500. advice_three = append(advice_three, advice)
  3501. }
  3502. break
  3503. case 3:
  3504. if strings.Index(advice.WeekDay, "周三") == -1 {
  3505. advice_three = append(advice_three, advice)
  3506. }
  3507. break
  3508. case 4:
  3509. if strings.Index(advice.WeekDay, "周四") == -1 {
  3510. advice_three = append(advice_three, advice)
  3511. }
  3512. break
  3513. case 5:
  3514. if strings.Index(advice.WeekDay, "周五") == -1 {
  3515. advice_three = append(advice_three, advice)
  3516. }
  3517. break
  3518. case 6:
  3519. if strings.Index(advice.WeekDay, "周六") == -1 {
  3520. advice_three = append(advice_three, advice)
  3521. }
  3522. break
  3523. case 0:
  3524. if strings.Index(advice.WeekDay, "周日") == -1 {
  3525. advice_three = append(advice_three, advice)
  3526. }
  3527. break
  3528. }
  3529. }
  3530. }
  3531. for _, advice := range advices_two {
  3532. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3533. now := p.Unix()
  3534. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3535. dayStr2 := "-" + dayStr
  3536. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3537. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3538. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  3539. for _, ad := range advices {
  3540. advice_three = append(advice_three, ad)
  3541. }
  3542. }
  3543. if err == nil {
  3544. c.ServeSuccessJSON(map[string]interface{}{
  3545. "status": "2",
  3546. "advices": advices,
  3547. "advices_two": RemoveRepeatedElement(advice_three),
  3548. "is_open_remind": config.IsOpenRemind,
  3549. "his_config_open": hisConfig.IsOpen,
  3550. "is_advice_open": is_advice_open.IsAdviceOpen,
  3551. "prescription_open": prescription_open.IsOpen,
  3552. })
  3553. }
  3554. }
  3555. }
  3556. func (c *DialysisAPIController) GetLongAdviceOne() {
  3557. patient_id, _ := c.GetInt64("id")
  3558. startTime := c.GetString("schedule_date")
  3559. timeLayout := "2006-01-02"
  3560. loc, _ := time.LoadLocation("Local")
  3561. var theStartTime int64
  3562. if len(startTime) > 0 {
  3563. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3564. if err != nil {
  3565. utils.ErrorLog(err.Error())
  3566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3567. return
  3568. }
  3569. theStartTime = theTime.Unix()
  3570. }
  3571. adminUserInfo := c.GetMobileAdminUserInfo()
  3572. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  3573. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  3574. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  3575. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  3576. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3577. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3578. c.ServeSuccessJSON(map[string]interface{}{
  3579. "status": "1",
  3580. })
  3581. return
  3582. } else { //开启推送提醒
  3583. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3584. var advice_three []*models.DoctorAdvice
  3585. //fmt.Println("theStartTime23434343433434433443434343434334", theStartTime)
  3586. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  3587. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  3588. for _, advice := range advices {
  3589. if advice.FrequencyType == 3 {
  3590. t := time.Now()
  3591. week := int(t.Weekday())
  3592. fmt.Println(t.Weekday())
  3593. fmt.Println(week)
  3594. switch week {
  3595. case 1:
  3596. if strings.Index(advice.WeekDay, "周一") == -1 {
  3597. advice_three = append(advice_three, advice)
  3598. }
  3599. break
  3600. case 2:
  3601. if strings.Index(advice.WeekDay, "周二") == -1 {
  3602. advice_three = append(advice_three, advice)
  3603. }
  3604. break
  3605. case 3:
  3606. if strings.Index(advice.WeekDay, "周三") == -1 {
  3607. advice_three = append(advice_three, advice)
  3608. }
  3609. break
  3610. case 4:
  3611. if strings.Index(advice.WeekDay, "周四") == -1 {
  3612. advice_three = append(advice_three, advice)
  3613. }
  3614. break
  3615. case 5:
  3616. if strings.Index(advice.WeekDay, "周五") == -1 {
  3617. advice_three = append(advice_three, advice)
  3618. }
  3619. break
  3620. case 6:
  3621. if strings.Index(advice.WeekDay, "周六") == -1 {
  3622. advice_three = append(advice_three, advice)
  3623. }
  3624. break
  3625. case 0:
  3626. if strings.Index(advice.WeekDay, "周日") == -1 {
  3627. advice_three = append(advice_three, advice)
  3628. }
  3629. break
  3630. }
  3631. }
  3632. }
  3633. for _, advice := range advices_two {
  3634. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3635. now := p.Unix()
  3636. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3637. dayStr2 := "-" + dayStr
  3638. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3639. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3640. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  3641. for _, ad := range advices {
  3642. advice_three = append(advice_three, ad)
  3643. }
  3644. }
  3645. if err == nil {
  3646. c.ServeSuccessJSON(map[string]interface{}{
  3647. "status": "2",
  3648. "advices": advices,
  3649. "advices_two": RemoveRepeatedElement(advice_three),
  3650. "is_open_remind": config.IsOpenRemind,
  3651. "his_config_open": hisConfig.IsOpen,
  3652. "is_advice_open": is_advice_open.IsAdviceOpen,
  3653. "prescription_open": prescription_open.IsOpen,
  3654. })
  3655. }
  3656. }
  3657. }
  3658. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3659. newArr = make([]*models.DoctorAdvice, 0)
  3660. for i := 0; i < len(arr); i++ {
  3661. repeat := false
  3662. for j := i + 1; j < len(arr); j++ {
  3663. if arr[i].ID == arr[j].ID {
  3664. repeat = true
  3665. break
  3666. }
  3667. }
  3668. if !repeat {
  3669. newArr = append(newArr, arr[i])
  3670. }
  3671. }
  3672. return
  3673. }
  3674. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  3675. patient, _ := c.GetInt64("id", 0)
  3676. groupNo, _ := c.GetInt64("groupno", 0)
  3677. if patient <= 0 {
  3678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3679. return
  3680. }
  3681. adminUserInfo := c.GetMobileAdminUserInfo()
  3682. dataBody := make(map[string]interface{}, 0)
  3683. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3684. if err != nil {
  3685. utils.ErrorLog(err.Error())
  3686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3687. return
  3688. }
  3689. utils.ErrorLog("%v", dataBody)
  3690. timeLayout := "2006-01-02 15:04"
  3691. loc, _ := time.LoadLocation("Local")
  3692. timeLayout2 := "2006-01-02"
  3693. loc2, _ := time.LoadLocation("Local")
  3694. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3695. utils.ErrorLog("advice_type")
  3696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3697. return
  3698. }
  3699. adviceType := int64(2)
  3700. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3701. utils.ErrorLog("advice_date")
  3702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3703. return
  3704. }
  3705. adviceDate, _ := dataBody["advice_date"].(string)
  3706. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3707. AdviceDate := theTime.Unix()
  3708. RecordDate := theTime.Unix()
  3709. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3710. utils.ErrorLog("start_time")
  3711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3712. return
  3713. }
  3714. startTime, _ := dataBody["start_time"].(string)
  3715. if len(startTime) == 0 {
  3716. utils.ErrorLog("len(start_time) == 0")
  3717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3718. return
  3719. }
  3720. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  3721. if err != nil {
  3722. utils.ErrorLog(err.Error())
  3723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3724. return
  3725. }
  3726. StartTime := theTime.Unix()
  3727. Remark := ""
  3728. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3729. remark, _ := dataBody["remark"].(string)
  3730. Remark = remark
  3731. }
  3732. var advices []*models.GroupAdvice
  3733. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3734. utils.ErrorLog("advices")
  3735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3736. return
  3737. }
  3738. adviceNames := dataBody["advices"].([]interface{})
  3739. for _, adviceNameMap := range adviceNames {
  3740. adviceNameM := adviceNameMap.(map[string]interface{})
  3741. var advice models.GroupAdvice
  3742. advice.Remark = Remark
  3743. advice.AdviceType = adviceType
  3744. advice.StartTime = StartTime
  3745. advice.AdviceDate = AdviceDate
  3746. advice.RecordDate = RecordDate
  3747. advice.Status = 1
  3748. advice.CreatedTime = time.Now().Unix()
  3749. advice.UpdatedTime = time.Now().Unix()
  3750. advice.StopState = 2
  3751. advice.ExecutionState = 2
  3752. advice.UserOrgId = adminUserInfo.Org.Id
  3753. advice.PatientId = patient
  3754. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3755. advice.IsSettle = 2
  3756. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3757. utils.ErrorLog("advice_name")
  3758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3759. return
  3760. }
  3761. adviceName, _ := adviceNameM["advice_name"].(string)
  3762. if len(adviceName) == 0 {
  3763. utils.ErrorLog("len(advice_name) == 0")
  3764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3765. return
  3766. }
  3767. advice.AdviceName = adviceName
  3768. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3769. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3770. advice.DrugSpec = drugSpec
  3771. }
  3772. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3773. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3774. advice.AdviceDesc = adviceDesc
  3775. }
  3776. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3777. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3778. advice.DrugSpecUnit = drugSpecUnit
  3779. }
  3780. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3781. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3782. // advice.SingleDose = singleDose
  3783. //}
  3784. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3785. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3786. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3787. }
  3788. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3789. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3790. advice.SingleDoseUnit = singleDoseUnit
  3791. }
  3792. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3793. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3794. // advice.PrescribingNumber = prescribingNumber
  3795. //}
  3796. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3797. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3798. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3799. }
  3800. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3801. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3802. advice.PrescribingNumberUnit = prescribingNumberUnit
  3803. }
  3804. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3805. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3806. advice.DeliveryWay = deliveryWay
  3807. }
  3808. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3809. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3810. advice.ExecutionFrequency = executionFrequency
  3811. }
  3812. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3813. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3814. advice.FrequencyType = frequency_type
  3815. }
  3816. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3817. day_count := int64(adviceNameM["day_count"].(float64))
  3818. advice.DayCount = day_count
  3819. }
  3820. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3821. week_day, _ := adviceNameM["week_day"].(string)
  3822. advice.WeekDay = week_day
  3823. }
  3824. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3825. way := int64(adviceNameM["way"].(float64))
  3826. advice.Way = way
  3827. }
  3828. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3829. drug_id := int64(adviceNameM["drug_id"].(float64))
  3830. advice.DrugId = drug_id
  3831. }
  3832. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3833. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3834. advice.DrugNameId = drug_name_id
  3835. }
  3836. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3837. template_id, _ := adviceNameM["template_id"].(string)
  3838. advice.TemplateId = template_id
  3839. }
  3840. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  3841. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3842. advice.ExecutionFrequency = executionFrequency
  3843. }
  3844. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3845. children := adviceNameM["child"].([]interface{})
  3846. if len(children) > 0 {
  3847. for _, childrenMap := range children {
  3848. childMap := childrenMap.(map[string]interface{})
  3849. var child models.GroupAdvice
  3850. child.Remark = Remark
  3851. child.AdviceType = adviceType
  3852. child.StartTime = StartTime
  3853. child.AdviceDate = AdviceDate
  3854. child.RecordDate = RecordDate
  3855. child.Status = 1
  3856. child.CreatedTime = time.Now().Unix()
  3857. child.UpdatedTime = time.Now().Unix()
  3858. child.StopState = 2
  3859. child.ExecutionState = 2
  3860. child.UserOrgId = adminUserInfo.Org.Id
  3861. child.PatientId = patient
  3862. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3863. child.IsSettle = 1
  3864. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3865. utils.ErrorLog("child advice_name")
  3866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3867. return
  3868. }
  3869. childAdviceName, _ := childMap["advice_name"].(string)
  3870. if len(childAdviceName) == 0 {
  3871. utils.ErrorLog("len(child advice_name) == 0")
  3872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3873. return
  3874. }
  3875. child.AdviceName = childAdviceName
  3876. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3877. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3878. child.AdviceDesc = childAdviceDesc
  3879. }
  3880. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3881. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3882. child.DrugSpec = childDrugSpec
  3883. }
  3884. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3885. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3886. child.DrugSpecUnit = childDrugSpecUnit
  3887. }
  3888. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3889. child.SingleDose = childMap["single_dose"].(float64)
  3890. }
  3891. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3892. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3893. child.SingleDoseUnit = childSingleDoseUnit
  3894. }
  3895. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3896. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3897. }
  3898. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3899. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3900. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3901. }
  3902. child.DeliveryWay = advice.DeliveryWay
  3903. child.ExecutionFrequency = advice.ExecutionFrequency
  3904. advice.Children = append(advice.Children, &child)
  3905. }
  3906. }
  3907. }
  3908. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  3909. if temp_advice.ID == 0 {
  3910. advices = append(advices, &advice)
  3911. }
  3912. }
  3913. if len(advices) > 0 {
  3914. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  3915. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  3916. redis := service.RedisClient()
  3917. //清空key 值
  3918. redis.Set(key, "", time.Second)
  3919. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3920. redis.Set(keyOne, "", time.Second)
  3921. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3922. defer redis.Close()
  3923. redis.Set(keyThree, "", time.Second)
  3924. if err != nil {
  3925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3926. return
  3927. }
  3928. c.ServeSuccessJSON(map[string]interface{}{
  3929. "msg": "ok",
  3930. "advices": list,
  3931. })
  3932. } else {
  3933. c.ServeSuccessJSON(map[string]interface{}{
  3934. "msg": "ok",
  3935. })
  3936. }
  3937. return
  3938. }
  3939. func (c *DialysisAPIController) UploadDryWeight() {
  3940. patient_id, _ := c.GetInt64("id")
  3941. dry_weight, _ := c.GetFloat("dry_weight")
  3942. doctor_id, _ := c.GetInt64("doctor_id")
  3943. remark := c.GetString("remark")
  3944. adminUserInfo := c.GetMobileAdminUserInfo()
  3945. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  3946. if err == gorm.ErrRecordNotFound {
  3947. dryWeight := &models.SgjPatientDryweight{
  3948. PatientId: patient_id,
  3949. DryWeight: dry_weight,
  3950. Remakes: remark,
  3951. Ctime: time.Now().Unix(),
  3952. Mtime: time.Now().Unix(),
  3953. Creator: doctor_id,
  3954. Status: 1,
  3955. UserOrgId: adminUserInfo.Org.Id,
  3956. AdjustedValue: "/",
  3957. UserId: adminUserInfo.AdminUser.Id,
  3958. }
  3959. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3960. redis := service.RedisClient()
  3961. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  3962. redis.Set(keyOne, "", time.Second)
  3963. loc, _ := time.LoadLocation("Local")
  3964. nowTime := time.Now()
  3965. nowDay := nowTime.Format("2006-01-02")
  3966. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3967. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3968. redis.Set(key, "", time.Second)
  3969. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3970. redis.Set(keyTwo, "", time.Second)
  3971. redis.Close()
  3972. if createErr == nil {
  3973. c.ServeSuccessJSON(map[string]interface{}{
  3974. "msg": "提交成功",
  3975. "weight": dryWeight,
  3976. })
  3977. }
  3978. } else {
  3979. dryWeight := &models.SgjPatientDryweight{
  3980. PatientId: patient_id,
  3981. DryWeight: dry_weight,
  3982. Remakes: remark,
  3983. Ctime: time.Now().Unix(),
  3984. Mtime: time.Now().Unix(),
  3985. Creator: doctor_id,
  3986. Status: 1,
  3987. UserOrgId: adminUserInfo.Org.Id,
  3988. AdjustedValue: "/",
  3989. UserId: adminUserInfo.AdminUser.Id,
  3990. }
  3991. var value float64
  3992. value = dry_weight - weightAdjust.DryWeight
  3993. if value < 0 {
  3994. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3995. } else if value == 0 {
  3996. dryWeight.AdjustedValue = "/"
  3997. } else if value > 0 {
  3998. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  3999. }
  4000. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4001. redis := service.RedisClient()
  4002. loc, _ := time.LoadLocation("Local")
  4003. nowTime := time.Now()
  4004. nowDay := nowTime.Format("2006-01-02")
  4005. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4006. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4007. redis.Set(keyOne, "", time.Second)
  4008. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4009. redis.Set(key, "", time.Second)
  4010. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4011. redis.Set(keyTwo, "", time.Second)
  4012. redis.Close()
  4013. if createErr == nil {
  4014. c.ServeSuccessJSON(map[string]interface{}{
  4015. "msg": "提交成功",
  4016. "weight": dryWeight,
  4017. })
  4018. }
  4019. }
  4020. }
  4021. func (c *DialysisAPIController) GetSolution() {
  4022. patient_id, _ := c.GetInt64("patient_id")
  4023. mode_id, _ := c.GetInt64("mode_id")
  4024. adminUserInfo := c.GetMobileAdminUserInfo()
  4025. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4026. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4027. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4028. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4029. if err != nil {
  4030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4031. return
  4032. }
  4033. c.ServeSuccessJSON(map[string]interface{}{
  4034. "solution": solution,
  4035. "prescription": prescription,
  4036. "system_prescription": system_prescription,
  4037. "dialysisPrescription": dialysisPrescription,
  4038. })
  4039. }
  4040. func (c *DialysisAPIController) GetSchedule() {
  4041. schedual_type, _ := c.GetInt64("schedual_type")
  4042. adminUserInfo := c.GetMobileAdminUserInfo()
  4043. scheduleTime, _ := c.GetInt64("record_date")
  4044. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4045. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4046. c.ServeSuccessJSON(map[string]interface{}{
  4047. "number": deviceNumber,
  4048. "list": list,
  4049. })
  4050. }
  4051. func (c *DialysisAPIController) GetPatientId() {
  4052. id, _ := c.GetInt64("id")
  4053. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4054. patientId, _ := service.GetPatientId(id)
  4055. //获取该患者的所有传染病
  4056. list, _ := service.GetPatientInfectious(id)
  4057. c.ServeSuccessJSON(map[string]interface{}{
  4058. "patient": patientId,
  4059. "infectioulist": list,
  4060. })
  4061. }
  4062. func (this *DialysisAPIController) GetDialysisSchedule() {
  4063. schedualDate := this.GetString("date")
  4064. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4065. if parseDateErr != nil {
  4066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4067. return
  4068. }
  4069. adminInfo := this.GetMobileAdminUserInfo()
  4070. orgID := adminInfo.Org.Id
  4071. redis := service.RedisClient()
  4072. defer redis.Close()
  4073. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  4074. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  4075. if len(scheduals) > 0 {
  4076. //缓存数据
  4077. scheduals_json, err := json.Marshal(scheduals)
  4078. if err == nil {
  4079. redis.Set(key, scheduals_json, time.Second*30)
  4080. }
  4081. }
  4082. this.ServeSuccessJSON(map[string]interface{}{
  4083. "scheduals": scheduals,
  4084. })
  4085. }
  4086. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  4087. change_type, _ := this.GetInt64("type", 0)
  4088. record_date := this.GetString("record_time")
  4089. patient_id, _ := this.GetInt64("patient_id", 0)
  4090. timeLayout := "2006-01-02"
  4091. loc, _ := time.LoadLocation("Local")
  4092. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4093. record_time := theAdviceRecordTime.Unix()
  4094. adminUserInfo := this.GetMobileAdminUserInfo()
  4095. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  4096. if err == nil {
  4097. if len(advices) == 0 {
  4098. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4099. return
  4100. } else {
  4101. this.ServeSuccessJSON(map[string]interface{}{
  4102. "advices": advices,
  4103. "schedule": sch,
  4104. })
  4105. return
  4106. }
  4107. } else {
  4108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4109. return
  4110. }
  4111. }
  4112. func (c *DialysisAPIController) CreateConsumables() {
  4113. record_date := c.GetString("record_time")
  4114. patient_id, _ := c.GetInt64("patient_id", 0)
  4115. active, _ := c.GetInt64("active")
  4116. adminUser := c.GetMobileAdminUserInfo()
  4117. timeLayout := "2006-01-02"
  4118. loc, _ := time.LoadLocation("Local")
  4119. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4120. record_time := theRecordTime.Unix()
  4121. dataBody := make(map[string]interface{}, 0)
  4122. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4123. if err != nil {
  4124. utils.ErrorLog(err.Error())
  4125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4126. return
  4127. }
  4128. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4129. var beforePrepares []*models.DialysisBeforePrepareGoods
  4130. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4131. var dialysisBefor []*models.DialysisBeforePrepare
  4132. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4133. goods, _ := dataBody["goods"].([]interface{})
  4134. if len(goods) > 0 {
  4135. for _, item := range goods {
  4136. items := item.(map[string]interface{})
  4137. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4138. utils.ErrorLog("good_id")
  4139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4140. return
  4141. }
  4142. good_id := int64(items["good_id"].(float64))
  4143. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4144. utils.ErrorLog("good_type_id")
  4145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4146. return
  4147. }
  4148. good_type_id := int64(items["good_type_id"].(float64))
  4149. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4150. utils.ErrorLog("count")
  4151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4152. return
  4153. }
  4154. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4155. commdity_code := items["commdity_code"].(string)
  4156. fmt.Println("commdity", commdity_code)
  4157. prepareGoods := &models.DialysisBeforePrepareGoods{
  4158. GoodTypeId: good_type_id,
  4159. GoodId: good_id,
  4160. Count: count,
  4161. StorehouseId: houseConfig.StorehouseOutInfo,
  4162. }
  4163. beforePrepares = append(beforePrepares, prepareGoods)
  4164. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  4165. GoodTypeId: good_type_id,
  4166. GoodId: good_id,
  4167. Count: count,
  4168. StorehouseId: houseConfig.StorehouseOutInfo,
  4169. }
  4170. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  4171. prepare := &models.DialysisBeforePrepare{
  4172. GoodTypeId: good_type_id,
  4173. GoodId: good_id,
  4174. Count: count,
  4175. PatientId: patient_id,
  4176. RecordDate: record_time,
  4177. UserOrgId: adminUser.Org.Id,
  4178. Status: 1,
  4179. Ctime: time.Now().Unix(),
  4180. Creater: adminUser.AdminUser.Id,
  4181. CommdityCode: commdity_code,
  4182. StorehouseId: houseConfig.StorehouseOutInfo,
  4183. }
  4184. dialysisBefor = append(dialysisBefor, prepare)
  4185. }
  4186. }
  4187. //查询是否有库存
  4188. for _, item := range dialysisBefor {
  4189. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  4190. if err == gorm.ErrRecordNotFound {
  4191. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4192. c.ServeSuccessJSON(map[string]interface{}{
  4193. "message": "1",
  4194. "good_name": goodObj.GoodName,
  4195. "specification_name": goodObj.SpecificationName,
  4196. })
  4197. return
  4198. }
  4199. if err != nil {
  4200. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4201. c.ServeSuccessJSON(map[string]interface{}{
  4202. "message": "1",
  4203. "good_name": goodObj.GoodName,
  4204. "specification_name": goodObj.SpecificationName,
  4205. })
  4206. return
  4207. }
  4208. }
  4209. fmt.Println("active------------------------------------", active)
  4210. fmt.Println("len------------------------------", len(goods))
  4211. //新增
  4212. if active == 1 && len(goods) > 0 {
  4213. for _, item := range dialysisBefor {
  4214. dialyPrepareOne := models.DialysisBeforePrepare{
  4215. GoodTypeId: item.GoodTypeId,
  4216. GoodId: item.GoodId,
  4217. PatientId: item.PatientId,
  4218. RecordDate: item.RecordDate,
  4219. UserOrgId: item.UserOrgId,
  4220. Count: item.Count,
  4221. Ctime: time.Now().Unix(),
  4222. Creater: item.Creater,
  4223. CommdityCode: item.CommdityCode,
  4224. Status: 1,
  4225. StorehouseId: houseConfig.StorehouseOutInfo,
  4226. }
  4227. //先清除再插入
  4228. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4229. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  4230. //查询默认仓库
  4231. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4232. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  4233. var total_count int64
  4234. for _, it := range stockList {
  4235. total_count += it.StockCount
  4236. }
  4237. //基础库插入数据
  4238. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  4239. //更新库存
  4240. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4241. var flush_count int64
  4242. for _, it := range goodList {
  4243. flush_count += it.StockCount
  4244. }
  4245. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4246. }
  4247. if err == nil {
  4248. c.ServeSuccessJSON(map[string]interface{}{
  4249. "msg": "保存成功",
  4250. "message": "2",
  4251. })
  4252. return
  4253. } else {
  4254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4255. return
  4256. }
  4257. }
  4258. if len(beforePrepares) > 0 && active == 2 {
  4259. for _, item := range beforePrepares {
  4260. //1.查看该患者该耗材型号最后一次出库数量
  4261. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4262. //判断当前出库数量和最后一次出库数量的大小
  4263. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  4264. if item.Count <= goodInfo.Count {
  4265. //退库
  4266. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  4267. //查询今日出库数据
  4268. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  4269. for _, it := range list {
  4270. prepare := models.DialysisBeforePrepare{
  4271. UserOrgId: it.OrgId,
  4272. PatientId: patient_id,
  4273. RecordDate: it.RecordTime,
  4274. GoodId: it.GoodId,
  4275. GoodTypeId: it.GoodTypeId,
  4276. Count: it.Count,
  4277. Ctime: time.Now().Unix(),
  4278. Creater: adminUser.AdminUser.Id,
  4279. Status: 1,
  4280. StorehouseId: houseConfig.StorehouseOutInfo,
  4281. }
  4282. //删除准备表数据
  4283. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4284. service.CreateDialysisBeforePrepareOne(&prepare)
  4285. }
  4286. }
  4287. var last_total int64
  4288. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  4289. if item.Count >= goodInfo.Count {
  4290. //查询当前批次当前耗材最后一条出库数据
  4291. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4292. //计算当前出库和最后一次出库数据相差数据
  4293. last_total = item.Count - lastOutInfo.Count
  4294. //查询该批次剩余库存
  4295. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  4296. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  4297. if lastInfo.StockCount >= last_total {
  4298. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  4299. //查询今日出库数据
  4300. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  4301. for _, it := range list {
  4302. prepare := models.DialysisBeforePrepare{
  4303. UserOrgId: it.OrgId,
  4304. PatientId: patient_id,
  4305. RecordDate: it.RecordTime,
  4306. GoodId: it.GoodId,
  4307. GoodTypeId: it.GoodTypeId,
  4308. Count: it.Count,
  4309. Ctime: time.Now().Unix(),
  4310. Creater: adminUser.AdminUser.Id,
  4311. Status: 1,
  4312. StorehouseId: houseConfig.StorehouseOutInfo,
  4313. }
  4314. //删除准备表数据
  4315. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4316. service.CreateDialysisBeforePrepareOne(&prepare)
  4317. //查询默认仓库
  4318. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4319. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  4320. var total_count int64
  4321. for _, it := range stockList {
  4322. total_count += it.StockCount
  4323. }
  4324. //基础库插入数据
  4325. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  4326. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4327. var flush_count int64
  4328. for _, it := range goodList {
  4329. flush_count += it.StockCount
  4330. }
  4331. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4332. }
  4333. }
  4334. //如果库存不够,则出库到下一个批次
  4335. if lastInfo.StockCount < last_total {
  4336. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  4337. //查询今日出库数据
  4338. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  4339. for _, it := range list {
  4340. prepare := models.DialysisBeforePrepare{
  4341. UserOrgId: it.OrgId,
  4342. PatientId: patient_id,
  4343. RecordDate: it.RecordTime,
  4344. GoodId: it.GoodId,
  4345. GoodTypeId: it.GoodTypeId,
  4346. Count: it.Count,
  4347. Ctime: time.Now().Unix(),
  4348. Creater: adminUser.AdminUser.Id,
  4349. Status: 1,
  4350. StorehouseId: houseConfig.StorehouseOutInfo,
  4351. }
  4352. //删除准备表数据
  4353. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4354. service.CreateDialysisBeforePrepareOne(&prepare)
  4355. //查询默认仓库
  4356. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4357. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  4358. var total_count int64
  4359. for _, it := range stockList {
  4360. total_count += it.StockCount
  4361. }
  4362. //基础库插入数据
  4363. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  4364. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4365. var flush_count int64
  4366. for _, it := range goodList {
  4367. flush_count += it.StockCount
  4368. }
  4369. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4370. }
  4371. if err != nil {
  4372. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4373. c.ServeSuccessJSON(map[string]interface{}{
  4374. "message": "1",
  4375. "good_name": goodObj.GoodName,
  4376. "specification_name": goodObj.SpecificationName,
  4377. })
  4378. return
  4379. }
  4380. }
  4381. }
  4382. if err != nil {
  4383. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4384. c.ServeSuccessJSON(map[string]interface{}{
  4385. "message": "1",
  4386. "good_name": goodObj.GoodName,
  4387. "specification_name": goodObj.SpecificationName,
  4388. })
  4389. return
  4390. }
  4391. }
  4392. }
  4393. }
  4394. var errs error
  4395. if errs == nil {
  4396. c.ServeSuccessJSON(map[string]interface{}{
  4397. "msg": "提交成功",
  4398. "message": "2",
  4399. "good_name": "",
  4400. "specification_name": "",
  4401. })
  4402. return
  4403. } else {
  4404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4405. return
  4406. }
  4407. }
  4408. func (c *DialysisAPIController) CreateStockOutInfo() {
  4409. patient_id, _ := c.GetInt64("patient_id", 0)
  4410. record_date := c.GetString("record_time")
  4411. if patient_id <= 0 {
  4412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4413. return
  4414. }
  4415. adminInfo := c.GetMobileAdminUserInfo()
  4416. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  4417. timeLayout := "2006-01-02"
  4418. loc, _ := time.LoadLocation("Local")
  4419. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4420. record_time := theRecordTime.Unix()
  4421. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  4422. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4423. //去重
  4424. consumables = RemoveRepeatedGood(consumables)
  4425. if record.IsOpen == 1 {
  4426. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4427. //查询是否有库存
  4428. for _, item := range consumables {
  4429. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  4430. if item.Count > warehouse.Count {
  4431. goodErrcode := models.XtGoodErrcode{
  4432. UserOrgId: item.UserOrgId,
  4433. Errcode: "自动出库库存不足",
  4434. GoodId: item.GoodId,
  4435. Status: 1,
  4436. Ctime: time.Now().Unix(),
  4437. Mtime: 0,
  4438. Count: 0,
  4439. StockCount: 0,
  4440. Creater: creator,
  4441. BatchNumberId: warehouse.ID,
  4442. WarehouseOutId: 0,
  4443. }
  4444. service.CreateGoodErrcode(goodErrcode)
  4445. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4446. c.ServeSuccessJSON(map[string]interface{}{
  4447. "message": "1",
  4448. "good_name": goodObj.GoodName,
  4449. "specification_name": goodObj.SpecificationName,
  4450. })
  4451. return
  4452. }
  4453. }
  4454. //查询是否有出库单
  4455. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4456. if err == gorm.ErrRecordNotFound {
  4457. //没有记录,则创建出库单
  4458. timeStr := time.Now().Format("2006-01-02")
  4459. timeArr := strings.Split(timeStr, "-")
  4460. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  4461. total = total + 1
  4462. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4463. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4464. number = number + total
  4465. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4466. creater := adminInfo.AdminUser.Id
  4467. warehouseOut := models.WarehouseOut{
  4468. WarehouseOutOrderNumber: warehousing_out_order,
  4469. OperationTime: time.Now().Unix(),
  4470. OrgId: adminInfo.Org.Id,
  4471. Creater: creater,
  4472. Ctime: time.Now().Unix(),
  4473. Status: 1,
  4474. WarehouseOutTime: record_time,
  4475. Dealer: 0,
  4476. Manufacturer: 0,
  4477. Type: 1,
  4478. IsSys: 1,
  4479. StorehouseId: houseConfig.StorehouseOutInfo,
  4480. IsCheck: 1,
  4481. }
  4482. err := service.AddSigleWarehouseOut(&warehouseOut)
  4483. if err != nil {
  4484. goodErrcode := models.XtGoodErrcode{
  4485. UserOrgId: adminInfo.Org.Id,
  4486. Errcode: "创建出库单失败",
  4487. GoodId: 0,
  4488. Status: 1,
  4489. Ctime: time.Now().Unix(),
  4490. Mtime: 0,
  4491. Count: 0,
  4492. StockCount: 0,
  4493. Creater: creator,
  4494. BatchNumberId: 0,
  4495. WarehouseOutId: 0,
  4496. }
  4497. service.CreateGoodErrcode(goodErrcode)
  4498. utils.TraceLog("创建出库单失败 err = %v", err)
  4499. } else {
  4500. for _, item := range consumables {
  4501. //出库
  4502. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  4503. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  4504. //fmt.Println("item----------------------------------count", item.Count)
  4505. if err == nil {
  4506. goodErrcode := models.XtGoodErrcode{
  4507. UserOrgId: adminInfo.Org.Id,
  4508. Errcode: "自动出库接口报错",
  4509. GoodId: 0,
  4510. Status: 1,
  4511. Ctime: time.Now().Unix(),
  4512. Mtime: 0,
  4513. Count: 0,
  4514. StockCount: 0,
  4515. Creater: creator,
  4516. BatchNumberId: 0,
  4517. WarehouseOutId: 0,
  4518. }
  4519. service.CreateGoodErrcode(goodErrcode)
  4520. utils.TraceLog("创建出库单失败 err = %v", err)
  4521. }
  4522. //查询
  4523. //出库数量相加
  4524. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  4525. if errs != nil {
  4526. goodErrcode := models.XtGoodErrcode{
  4527. UserOrgId: item.UserOrgId,
  4528. Errcode: "创建剩余库存字段报错",
  4529. GoodId: item.GoodId,
  4530. Status: 1,
  4531. Ctime: time.Now().Unix(),
  4532. Mtime: 0,
  4533. Count: 0,
  4534. StockCount: 0,
  4535. Creater: creater,
  4536. BatchNumberId: 0,
  4537. WarehouseOutId: 0,
  4538. }
  4539. service.CreateGoodErrcode(goodErrcode)
  4540. }
  4541. }
  4542. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4543. if len(list) == 0 {
  4544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4545. return
  4546. }
  4547. for _, item := range list {
  4548. prepare := models.DialysisBeforePrepare{
  4549. UserOrgId: adminInfo.Org.Id,
  4550. PatientId: patient_id,
  4551. RecordDate: record_time,
  4552. GoodId: item.GoodId,
  4553. GoodTypeId: item.GoodTypeId,
  4554. Count: item.Count,
  4555. Creater: adminInfo.AdminUser.Id,
  4556. Status: 1,
  4557. Ctime: time.Now().Unix(),
  4558. StorehouseId: houseConfig.StorehouseOutInfo,
  4559. }
  4560. //清空准备表数据
  4561. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4562. if err != nil {
  4563. goodErrcode := models.XtGoodErrcode{
  4564. UserOrgId: item.OrgId,
  4565. Errcode: "自动出库清空准备表数据报错",
  4566. GoodId: item.GoodId,
  4567. Status: 1,
  4568. Ctime: time.Now().Unix(),
  4569. Mtime: 0,
  4570. Count: 0,
  4571. StockCount: 0,
  4572. Creater: creater,
  4573. BatchNumberId: 0,
  4574. WarehouseOutId: 0,
  4575. }
  4576. service.CreateGoodErrcode(goodErrcode)
  4577. }
  4578. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  4579. if errs != nil {
  4580. goodErrcode := models.XtGoodErrcode{
  4581. UserOrgId: item.OrgId,
  4582. Errcode: "自动出库创建准备表数据报错",
  4583. GoodId: item.GoodId,
  4584. Status: 1,
  4585. Ctime: time.Now().Unix(),
  4586. Mtime: 0,
  4587. Count: 0,
  4588. StockCount: 0,
  4589. Creater: creater,
  4590. BatchNumberId: 0,
  4591. WarehouseOutId: 0,
  4592. }
  4593. service.CreateGoodErrcode(goodErrcode)
  4594. }
  4595. //查询默认仓库
  4596. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4597. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4598. var total_count int64
  4599. for _, it := range stockList {
  4600. total_count += it.StockCount
  4601. }
  4602. //基础库插入数据
  4603. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4604. if errcodes != nil {
  4605. goodErrcode := models.XtGoodErrcode{
  4606. UserOrgId: item.OrgId,
  4607. Errcode: "自动出库基础库插入数据",
  4608. GoodId: item.GoodId,
  4609. Status: 1,
  4610. Ctime: time.Now().Unix(),
  4611. Mtime: 0,
  4612. Count: 0,
  4613. StockCount: 0,
  4614. Creater: creater,
  4615. BatchNumberId: 0,
  4616. WarehouseOutId: 0,
  4617. }
  4618. service.CreateGoodErrcode(goodErrcode)
  4619. }
  4620. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4621. var flush_count int64
  4622. for _, it := range goodList {
  4623. flush_count += it.StockCount
  4624. }
  4625. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4626. if errsss != nil {
  4627. goodErrcode := models.XtGoodErrcode{
  4628. UserOrgId: item.OrgId,
  4629. Errcode: "自动出库剩余库存更新数据",
  4630. GoodId: item.GoodId,
  4631. Status: 1,
  4632. Ctime: time.Now().Unix(),
  4633. Mtime: 0,
  4634. Count: 0,
  4635. StockCount: 0,
  4636. Creater: creater,
  4637. BatchNumberId: 0,
  4638. WarehouseOutId: 0,
  4639. }
  4640. service.CreateGoodErrcode(goodErrcode)
  4641. }
  4642. }
  4643. }
  4644. //
  4645. } else if err == nil {
  4646. for _, item := range consumables {
  4647. //出库
  4648. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  4649. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  4650. //fmt.Println("item----------------------------------count", item.Count)
  4651. if err != nil {
  4652. goodErrcode := models.XtGoodErrcode{
  4653. UserOrgId: adminInfo.Org.Id,
  4654. Errcode: "自动出库接口报错",
  4655. GoodId: 0,
  4656. Status: 1,
  4657. Ctime: time.Now().Unix(),
  4658. Mtime: 0,
  4659. Count: 0,
  4660. StockCount: 0,
  4661. Creater: creator,
  4662. BatchNumberId: 0,
  4663. WarehouseOutId: 0,
  4664. }
  4665. service.CreateGoodErrcode(goodErrcode)
  4666. }
  4667. //出库数量相加
  4668. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  4669. if errss != nil {
  4670. goodErrcode := models.XtGoodErrcode{
  4671. UserOrgId: item.UserOrgId,
  4672. Errcode: "创建剩余库存字段报错",
  4673. GoodId: item.GoodId,
  4674. Status: 1,
  4675. Ctime: time.Now().Unix(),
  4676. Mtime: time.Now().Unix(),
  4677. Count: 0,
  4678. StockCount: 0,
  4679. Creater: item.Creater,
  4680. BatchNumberId: 0,
  4681. WarehouseOutId: 0,
  4682. }
  4683. service.CreateGoodErrcode(goodErrcode)
  4684. }
  4685. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4686. if len(list) == 0 {
  4687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4688. return
  4689. }
  4690. for _, item := range list {
  4691. prepare := models.DialysisBeforePrepare{
  4692. UserOrgId: adminInfo.Org.Id,
  4693. PatientId: patient_id,
  4694. RecordDate: record_time,
  4695. GoodId: item.GoodId,
  4696. GoodTypeId: item.GoodTypeId,
  4697. Count: item.Count,
  4698. Creater: adminInfo.AdminUser.Id,
  4699. Status: 1,
  4700. Ctime: time.Now().Unix(),
  4701. StorehouseId: houseConfig.StorehouseOutInfo,
  4702. }
  4703. //清空准备表数据
  4704. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4705. if errs != nil {
  4706. goodErrcode := models.XtGoodErrcode{
  4707. UserOrgId: adminInfo.Org.Id,
  4708. Errcode: "自动出库清空准备表数据报错",
  4709. GoodId: 0,
  4710. Status: 1,
  4711. Ctime: time.Now().Unix(),
  4712. Mtime: 0,
  4713. Count: 0,
  4714. StockCount: 0,
  4715. Creater: creator,
  4716. BatchNumberId: 0,
  4717. WarehouseOutId: 0,
  4718. }
  4719. service.CreateGoodErrcode(goodErrcode)
  4720. }
  4721. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  4722. if errcodes != nil {
  4723. goodErrcode := models.XtGoodErrcode{
  4724. UserOrgId: adminInfo.Org.Id,
  4725. Errcode: "自动出库创建准备表数据报错",
  4726. GoodId: 0,
  4727. Status: 1,
  4728. Ctime: time.Now().Unix(),
  4729. Mtime: 0,
  4730. Count: 0,
  4731. StockCount: 0,
  4732. Creater: creator,
  4733. BatchNumberId: 0,
  4734. WarehouseOutId: 0,
  4735. }
  4736. service.CreateGoodErrcode(goodErrcode)
  4737. }
  4738. //查询默认仓库
  4739. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4740. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4741. var total_count int64
  4742. for _, it := range stockList {
  4743. total_count += it.StockCount
  4744. }
  4745. //基础库插入数据
  4746. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4747. if errcodes != nil {
  4748. goodErrcode := models.XtGoodErrcode{
  4749. UserOrgId: adminInfo.Org.Id,
  4750. Errcode: "自动出库基础库插入数据报错",
  4751. GoodId: 0,
  4752. Status: 1,
  4753. Ctime: time.Now().Unix(),
  4754. Mtime: 0,
  4755. Count: 0,
  4756. StockCount: 0,
  4757. Creater: creator,
  4758. BatchNumberId: 0,
  4759. WarehouseOutId: 0,
  4760. }
  4761. service.CreateGoodErrcode(goodErrcode)
  4762. }
  4763. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4764. var flush_count int64
  4765. for _, it := range goodList {
  4766. flush_count += it.StockCount
  4767. }
  4768. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4769. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  4770. if errss != nil {
  4771. goodErrcode := models.XtGoodErrcode{
  4772. UserOrgId: item.OrgId,
  4773. Errcode: "自动出库剩余库存更新数据",
  4774. GoodId: item.GoodId,
  4775. Status: 1,
  4776. Ctime: time.Now().Unix(),
  4777. Mtime: 0,
  4778. Count: 0,
  4779. StockCount: 0,
  4780. Creater: creater,
  4781. BatchNumberId: 0,
  4782. WarehouseOutId: 0,
  4783. }
  4784. service.CreateGoodErrcode(goodErrcode)
  4785. }
  4786. }
  4787. }
  4788. }
  4789. c.ServeSuccessJSON(map[string]interface{}{
  4790. "msg": "提交成功",
  4791. "message": "2",
  4792. "good_name": "",
  4793. "specification_name": "",
  4794. })
  4795. return
  4796. } else {
  4797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  4798. return
  4799. }
  4800. }
  4801. func (c *DialysisAPIController) EditConsumables() {
  4802. patient_id, _ := c.GetInt64("patient_id", 0)
  4803. record_date := c.GetString("record_time")
  4804. if patient_id <= 0 {
  4805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4806. return
  4807. }
  4808. adminInfo := c.GetMobileAdminUserInfo()
  4809. timeLayout := "2006-01-02"
  4810. loc, _ := time.LoadLocation("Local")
  4811. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4812. record_time := theRecordTime.Unix()
  4813. dataBody := make(map[string]interface{}, 0)
  4814. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4815. if err != nil {
  4816. utils.ErrorLog(err.Error())
  4817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4818. return
  4819. }
  4820. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4821. var beforePrepares []*models.DialysisBeforePrepareGoods
  4822. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4823. var cancelbefor []*models.DialysisBeforePrepareGoods
  4824. var outbefor []*models.DialysisBeforePrepareGoods
  4825. //判断是否开启自动出库
  4826. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4827. if record.IsOpen == 1 {
  4828. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4829. goods, _ := dataBody["goods"].([]interface{})
  4830. if len(goods) > 0 {
  4831. for _, item := range goods {
  4832. items := item.(map[string]interface{})
  4833. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4834. utils.ErrorLog("good_id")
  4835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4836. return
  4837. }
  4838. good_id := int64(items["good_id"].(float64))
  4839. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4840. utils.ErrorLog("good_type_id")
  4841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4842. return
  4843. }
  4844. good_type_id := int64(items["good_type_id"].(float64))
  4845. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4846. utils.ErrorLog("count")
  4847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4848. return
  4849. }
  4850. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4851. commdity_code := items["commdity_code"].(string)
  4852. fmt.Println(commdity_code)
  4853. prepareGoods := &models.DialysisBeforePrepareGoods{
  4854. GoodTypeId: good_type_id,
  4855. GoodId: good_id,
  4856. Count: count,
  4857. StorehouseId: houseConfig.StorehouseOutInfo,
  4858. }
  4859. beforePrepares = append(beforePrepares, prepareGoods)
  4860. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  4861. GoodTypeId: good_type_id,
  4862. GoodId: good_id,
  4863. Count: count,
  4864. StorehouseId: houseConfig.StorehouseOutInfo,
  4865. }
  4866. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  4867. }
  4868. for _, item := range beforePrepares {
  4869. //1.查看该患者该耗材型号最后一次出库数量
  4870. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4871. //判断当前出库数量和最后一次出库数量的大小
  4872. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  4873. if item.Count < goodInfo.Count {
  4874. cancelbefor = append(cancelbefor, item)
  4875. }
  4876. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  4877. if item.Count > goodInfo.Count {
  4878. outbefor = append(outbefor, item)
  4879. }
  4880. //处理编辑耗材新增不了的问题
  4881. if goodInfo.Count == item.Count {
  4882. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  4883. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  4884. }
  4885. }
  4886. fmt.Println("退库长度", len(cancelbefor))
  4887. fmt.Println("出库长度", len(outbefor))
  4888. //退库
  4889. for _, item := range cancelbefor {
  4890. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4891. creater := adminInfo.AdminUser.Id
  4892. //退库
  4893. //err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, cancelbefor, adminInfo.AdminUser.Id, item.Count)
  4894. //查询该患者当天已经出库的耗材信息
  4895. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  4896. var delete_count int64 = 0
  4897. delete_count = warehouseOutInfos.Count - item.Count
  4898. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4899. // 在出库记录表里记录退库详情
  4900. warehouseOutInfo := &models.WarehouseOutInfo{
  4901. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4902. WarehouseOutId: warehouseOut.ID,
  4903. Status: 1,
  4904. Ctime: time.Now().Unix(),
  4905. OrgId: adminInfo.Org.Id,
  4906. Type: 1,
  4907. IsSys: 1,
  4908. SysRecordTime: record_time,
  4909. GoodTypeId: item.GoodTypeId,
  4910. GoodId: item.GoodId,
  4911. PatientId: patient_id,
  4912. ConsumableType: 2,
  4913. StorehouseId: houseConfig.StorehouseOutInfo,
  4914. IsCheck: 1,
  4915. }
  4916. warehouseOutInfo.Count = item.Count
  4917. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  4918. warehouseOutInfo.Price = stockInInfo.Price
  4919. warehouseOutInfo.Dealer = stockInInfo.Dealer
  4920. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  4921. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  4922. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  4923. warehouseOutInfo.Number = warehouseOutInfos.Number
  4924. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  4925. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  4926. //查找当天是否存在出库记录
  4927. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  4928. if errcod == gorm.ErrRecordNotFound {
  4929. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4930. //插入详情明细表
  4931. stockFlow := models.VmStockFlow{
  4932. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4933. WarehouseOutId: warehouseOut.ID,
  4934. GoodId: item.GoodId,
  4935. Number: warehouseOutInfos.Number,
  4936. ProductDate: stockInInfo.ProductDate,
  4937. ExpireDate: stockInInfo.ExpiryDate,
  4938. Count: item.Count,
  4939. Price: stockInInfo.Price,
  4940. Status: 1,
  4941. Ctime: time.Now().Unix(),
  4942. UserOrgId: adminInfo.Org.Id,
  4943. Manufacturer: stockInInfo.Manufacturer,
  4944. Dealer: stockInInfo.Dealer,
  4945. LicenseNumber: stockInInfo.LicenseNumber,
  4946. IsEdit: 2,
  4947. Creator: creater,
  4948. SystemTime: record_time,
  4949. ConsumableType: 3,
  4950. WarehousingDetailId: 0,
  4951. IsSys: 1,
  4952. UpdateCreator: creater,
  4953. PatientId: patient_id,
  4954. StorehouseId: houseConfig.StorehouseOutInfo,
  4955. }
  4956. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  4957. if errflow == gorm.ErrRecordNotFound {
  4958. //创建流水表
  4959. err := service.CreateStockFlowOne(stockFlow)
  4960. fmt.Println("err", err)
  4961. } else if errflow == nil {
  4962. //插入详情明细表
  4963. stockFlow := models.VmStockFlow{
  4964. ID: exsit.ID,
  4965. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4966. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4967. WarehouseOutId: warehouseOut.ID,
  4968. GoodId: item.GoodId,
  4969. Number: warehouseOutInfos.Number,
  4970. ProductDate: stockInInfo.ProductDate,
  4971. ExpireDate: stockInInfo.ExpiryDate,
  4972. Count: exsit.Count - delete_count,
  4973. Price: stockInInfo.Price,
  4974. Status: 1,
  4975. Ctime: time.Now().Unix(),
  4976. UserOrgId: adminInfo.Org.Id,
  4977. Manufacturer: stockInInfo.Manufacturer,
  4978. Dealer: stockInInfo.Dealer,
  4979. LicenseNumber: stockInInfo.LicenseNumber,
  4980. IsEdit: 2,
  4981. Creator: creater,
  4982. SystemTime: record_time,
  4983. ConsumableType: 3,
  4984. WarehousingDetailId: 0,
  4985. IsSys: 1,
  4986. UpdateCreator: creater,
  4987. PatientId: patient_id,
  4988. StorehouseId: houseConfig.StorehouseOutInfo,
  4989. }
  4990. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  4991. }
  4992. } else if errcod == nil {
  4993. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  4994. //插入详情明细表
  4995. stockFlow := models.VmStockFlow{
  4996. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4997. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4998. WarehouseOutId: warehouseOut.ID,
  4999. GoodId: item.GoodId,
  5000. Number: warehouseOutInfos.Number,
  5001. ProductDate: stockInInfo.ProductDate,
  5002. ExpireDate: stockInInfo.ExpiryDate,
  5003. Count: item.Count,
  5004. Price: stockInInfo.Price,
  5005. Status: 1,
  5006. Ctime: time.Now().Unix(),
  5007. UserOrgId: adminInfo.Org.Id,
  5008. Manufacturer: stockInInfo.Manufacturer,
  5009. Dealer: stockInInfo.Dealer,
  5010. LicenseNumber: stockInInfo.LicenseNumber,
  5011. IsEdit: 2,
  5012. Creator: creater,
  5013. SystemTime: record_time,
  5014. ConsumableType: 3,
  5015. WarehousingDetailId: 0,
  5016. IsSys: 1,
  5017. UpdateCreator: creater,
  5018. PatientId: patient_id,
  5019. ReturnCount: delete_count,
  5020. StorehouseId: houseConfig.StorehouseOutInfo,
  5021. }
  5022. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  5023. if errflows == gorm.ErrRecordNotFound {
  5024. //创建流水表
  5025. service.CreateStockFlowOne(stockFlow)
  5026. } else if errflows == nil {
  5027. stockFlow := models.VmStockFlow{
  5028. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5029. ID: exsit.ID,
  5030. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5031. WarehouseOutId: warehouseOut.ID,
  5032. GoodId: item.GoodId,
  5033. Number: warehouseOutInfos.Number,
  5034. ProductDate: stockInInfo.ProductDate,
  5035. ExpireDate: stockInInfo.ExpiryDate,
  5036. Count: exsit.Count - delete_count,
  5037. Price: stockInInfo.Price,
  5038. Status: 1,
  5039. Ctime: time.Now().Unix(),
  5040. UserOrgId: adminInfo.Org.Id,
  5041. Manufacturer: stockInInfo.Manufacturer,
  5042. Dealer: stockInInfo.Dealer,
  5043. LicenseNumber: stockInInfo.LicenseNumber,
  5044. IsEdit: 2,
  5045. Creator: creater,
  5046. SystemTime: record_time,
  5047. ConsumableType: 3,
  5048. WarehousingDetailId: 0,
  5049. IsSys: 1,
  5050. UpdateCreator: creater,
  5051. PatientId: patient_id,
  5052. ReturnCount: delete_count,
  5053. StorehouseId: houseConfig.StorehouseOutInfo,
  5054. }
  5055. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  5056. }
  5057. }
  5058. //更改自动出库的表格
  5059. details := models.BloodAutomaticReduceDetail{
  5060. WarehouseOutId: warehouseOutInfo.ID,
  5061. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5062. PatientId: patient_id,
  5063. Ctime: time.Now().Unix(),
  5064. Mtime: time.Now().Unix(),
  5065. Status: 1,
  5066. RecordTime: record_time,
  5067. OrgId: adminInfo.Org.Id,
  5068. GoodId: item.GoodId,
  5069. GoodTypeId: item.GoodTypeId,
  5070. Count: item.Count,
  5071. StorehouseId: houseConfig.StorehouseOutInfo,
  5072. }
  5073. //查询当天耗材是否已经存在数据
  5074. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5075. if errcode == gorm.ErrRecordNotFound {
  5076. service.CreateAutoReduceRecord(&details)
  5077. } else if errcode == nil {
  5078. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5079. service.CreateAutoReduceRecord(&details)
  5080. }
  5081. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  5082. //增加出库库存数量
  5083. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  5084. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
  5085. fmt.Println("errOne", errOne)
  5086. // 删除出库完成后,要增加对应批次的库存数量
  5087. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  5088. //查询默认仓库
  5089. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5090. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5091. var total_count int64
  5092. for _, it := range stockList {
  5093. total_count += it.StockCount
  5094. }
  5095. //基础库插入数据
  5096. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5097. //更新剩余库存
  5098. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5099. var flush_count int64
  5100. for _, it := range goodList {
  5101. flush_count += it.StockCount
  5102. }
  5103. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5104. }
  5105. //出库
  5106. for _, item := range outbefor {
  5107. fmt.Println("出库ID", item.GoodId)
  5108. var last_total int64
  5109. //1.查看该患者该耗材型号最后一次出库数量
  5110. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5111. //计算当前出库和最后一次出库数据相差数据
  5112. last_total = item.Count - goodInfoOne.Count
  5113. //查询该批次剩余库存
  5114. lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
  5115. if lastInfo.StockCount == 0 {
  5116. //查询该耗材的总库存
  5117. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  5118. if wareinfo.StockCount == 0 {
  5119. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5120. c.ServeSuccessJSON(map[string]interface{}{
  5121. "message": "1",
  5122. "good_name": goodObj.GoodName,
  5123. "specification_name": goodObj.SpecificationName,
  5124. })
  5125. return
  5126. }
  5127. }
  5128. //查询该耗材的总库存
  5129. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  5130. // 如果库存差大于剩余库存则提示库存不足
  5131. if last_total > wareinfo.StockCount {
  5132. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5133. c.ServeSuccessJSON(map[string]interface{}{
  5134. "message": "1",
  5135. "good_name": goodObj.GoodName,
  5136. "specification_name": goodObj.SpecificationName,
  5137. })
  5138. return
  5139. } else {
  5140. fmt.Println("出库2o2o2o2o2oo2o2o2o2o2o2o", item.GoodId)
  5141. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5142. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5143. if err == gorm.ErrRecordNotFound {
  5144. //没有记录,则创建出库单
  5145. timeStr := time.Now().Format("2006-01-02")
  5146. timeArr := strings.Split(timeStr, "-")
  5147. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5148. total = total + 1
  5149. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5150. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5151. number = number + total
  5152. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5153. warehouseOut := models.WarehouseOut{
  5154. WarehouseOutOrderNumber: warehousing_out_order,
  5155. OperationTime: time.Now().Unix(),
  5156. OrgId: adminInfo.Org.Id,
  5157. Creater: adminInfo.AdminUser.Id,
  5158. Ctime: time.Now().Unix(),
  5159. Status: 1,
  5160. WarehouseOutTime: record_time,
  5161. Dealer: 0,
  5162. Manufacturer: 0,
  5163. Type: 1,
  5164. IsSys: 1,
  5165. StorehouseId: houseConfig.StorehouseOutInfo,
  5166. IsCheck: 1,
  5167. }
  5168. service.AddSigleWarehouseOut(&warehouseOut)
  5169. }
  5170. //出库
  5171. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  5172. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5173. //1.查看该患者该耗材型号最后一次出库数量
  5174. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5175. fmt.Println("count2323323222323wi", item.Count)
  5176. prepare := models.DialysisBeforePrepare{
  5177. UserOrgId: adminInfo.Org.Id,
  5178. PatientId: patient_id,
  5179. RecordDate: record_time,
  5180. GoodId: item.GoodId,
  5181. GoodTypeId: item.GoodTypeId,
  5182. Count: item.Count - goodInfoTwo.Count,
  5183. Ctime: time.Now().Unix(),
  5184. Mtime: 0,
  5185. Creater: adminInfo.AdminUser.Id,
  5186. Modifier: adminInfo.AdminUser.Id,
  5187. Status: 1,
  5188. CommdityCode: "",
  5189. NewCount: 0,
  5190. ProjectId: 0,
  5191. StorehouseId: houseConfig.StorehouseOutInfo,
  5192. }
  5193. fmt.Println("prepare", prepare.Count)
  5194. fmt.Println("count", item.Count)
  5195. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  5196. //增加出库数量
  5197. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  5198. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5199. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5200. var total_count int64
  5201. for _, it := range stockList {
  5202. total_count += it.StockCount
  5203. }
  5204. //基础库插入数据
  5205. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5206. //剩余库存
  5207. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5208. var flush_count int64
  5209. for _, it := range goodList {
  5210. flush_count += it.StockCount
  5211. }
  5212. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5213. }
  5214. }
  5215. //查询今日出库数据
  5216. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5217. for _, it := range list {
  5218. prepare := models.DialysisBeforePrepare{
  5219. UserOrgId: it.OrgId,
  5220. PatientId: patient_id,
  5221. RecordDate: it.RecordTime,
  5222. GoodId: it.GoodId,
  5223. GoodTypeId: it.GoodTypeId,
  5224. Count: it.Count,
  5225. Ctime: time.Now().Unix(),
  5226. Creater: adminInfo.AdminUser.Id,
  5227. Status: 1,
  5228. StorehouseId: houseConfig.StorehouseOutInfo,
  5229. }
  5230. //删除准备表数据
  5231. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  5232. service.CreateDialysisBeforePrepareOne(&prepare)
  5233. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5234. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5235. var total_count int64
  5236. for _, it := range stockList {
  5237. total_count += it.StockCount
  5238. }
  5239. //基础库插入数据
  5240. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  5241. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  5242. var flush_count int64
  5243. for _, it := range goodList {
  5244. flush_count += it.StockCount
  5245. }
  5246. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  5247. //if err != nil {
  5248. // goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
  5249. // c.ServeSuccessJSON(map[string]interface{}{
  5250. // "message": "2",
  5251. // "good_name": goodObj.GoodName,
  5252. // "specification_name": goodObj.SpecificationName,
  5253. // })
  5254. // return
  5255. //}
  5256. }
  5257. }
  5258. }
  5259. //更新自动出库的地方
  5260. var errs error
  5261. if errs == nil {
  5262. c.ServeSuccessJSON(map[string]interface{}{
  5263. "msg": "修改成功",
  5264. "message": "2",
  5265. "good_name": "",
  5266. "specification_name": "",
  5267. })
  5268. return
  5269. } else {
  5270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5271. return
  5272. }
  5273. }
  5274. }
  5275. func (c *DialysisAPIController) GetDialysisGoods() {
  5276. schedualDate := c.GetString("schedule_date")
  5277. schedule_type, _ := c.GetInt64("schedule_type")
  5278. partition_id, _ := c.GetInt64("partition_id")
  5279. page, _ := c.GetInt("page")
  5280. patient_id, _ := c.GetInt64("patient_id")
  5281. schedualEndDate := int64(0)
  5282. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5283. if parseDateErr != nil && len(schedualDate) != 0 {
  5284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5285. return
  5286. }
  5287. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  5288. if parseDateErr != nil && len(schedualDate) != 0 {
  5289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5290. return
  5291. }
  5292. schedualEndDate = endDate.Unix()
  5293. adminUser := c.GetMobileAdminUserInfo()
  5294. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  5295. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  5296. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  5297. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  5298. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  5299. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  5300. //获取当天该病人的透析处方
  5301. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  5302. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  5303. if err == gorm.ErrRecordNotFound {
  5304. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  5305. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  5306. if patient_id != 0 {
  5307. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5308. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  5309. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  5310. //获取患者总的出库数据
  5311. item.LastAutomaticReduceDetail = goodUser
  5312. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5313. item.Project = project
  5314. }
  5315. }
  5316. c.ServeSuccessJSON(map[string]interface{}{
  5317. "dialysis_goods": dialysisGoods,
  5318. "good_type": goodTypes,
  5319. "total": total,
  5320. "prescribe": prescribe,
  5321. "good_info": good_info,
  5322. "warehouseOutList": warehouseOutList,
  5323. "config": config,
  5324. "outConfig": outConfig,
  5325. "settleConfig": settleConfig,
  5326. })
  5327. return
  5328. } else if err == nil {
  5329. //获取当天排班的每个患者的库存使用情况
  5330. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  5331. //获取患者总的出库数据
  5332. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  5333. if patient_id != 0 {
  5334. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5335. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  5336. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  5337. item.Project = project
  5338. item.LastAutomaticReduceDetail = goodUser
  5339. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5340. }
  5341. }
  5342. if err == nil {
  5343. c.ServeSuccessJSON(map[string]interface{}{
  5344. "dialysis_goods": dialysisGoods,
  5345. "good_type": goodTypes,
  5346. "total": total,
  5347. "prescribe": prescribe,
  5348. "good_info": good_info,
  5349. "project": project,
  5350. "warehouseOutList": warehouseOutList,
  5351. "config": config,
  5352. "outConfig": outConfig,
  5353. "settleConfig": settleConfig,
  5354. })
  5355. return
  5356. } else {
  5357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5358. return
  5359. }
  5360. } else if err != nil {
  5361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5362. return
  5363. }
  5364. }
  5365. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  5366. start_time := c.GetString("start_time")
  5367. end_time := c.GetString("end_time")
  5368. timeLayout := "2006-01-02"
  5369. loc, _ := time.LoadLocation("Local")
  5370. var theStartTime int64
  5371. if len(start_time) > 0 {
  5372. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5373. if err != nil {
  5374. utils.ErrorLog(err.Error())
  5375. }
  5376. theStartTime = theTime.Unix()
  5377. }
  5378. var theEndtTime int64
  5379. if len(end_time) > 0 {
  5380. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5381. if err != nil {
  5382. utils.ErrorLog(err.Error())
  5383. }
  5384. theEndtTime = theTime.Unix()
  5385. }
  5386. adminUser := c.GetMobileAdminUserInfo()
  5387. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  5388. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  5389. if err == nil {
  5390. c.ServeSuccessJSON(map[string]interface{}{
  5391. "stock_out": outInfo,
  5392. "stockCount": stockCount,
  5393. })
  5394. return
  5395. } else {
  5396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5397. return
  5398. }
  5399. }
  5400. func (c *DialysisAPIController) GetStockInGoodInfo() {
  5401. patient_id, _ := c.GetInt64("patient_id", 0)
  5402. record_time := c.GetString("record_time")
  5403. adminUser := c.GetMobileAdminUserInfo()
  5404. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  5405. if parseDateErr != nil && len(record_time) != 0 {
  5406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5407. return
  5408. }
  5409. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  5410. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  5411. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  5412. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  5413. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  5414. //获取今日患者的透析处方参数
  5415. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  5416. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  5417. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  5418. c.ServeSuccessJSON(map[string]interface{}{
  5419. "good_type": goodTypes,
  5420. "good_user": goodUser,
  5421. "good_info": good_info,
  5422. "last_good_user": lastGoodUserDetial,
  5423. "project": project,
  5424. "prescription": prescribe,
  5425. "outInfo": outInfo,
  5426. "configs": configs,
  5427. })
  5428. return
  5429. }
  5430. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  5431. patient_id, _ := c.GetInt64("patient_id", 0)
  5432. record_date := c.GetString("record_time")
  5433. timeLayout := "2006-01-02"
  5434. loc, _ := time.LoadLocation("Local")
  5435. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5436. record_time := theRecordTime.Unix()
  5437. adminInfo := c.GetMobileAdminUserInfo()
  5438. dataBody := make(map[string]interface{}, 0)
  5439. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5440. if err != nil {
  5441. utils.ErrorLog(err.Error())
  5442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5443. return
  5444. }
  5445. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5446. var beforePrepares []*models.DialysisBeforePrepareGoods
  5447. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5448. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5449. goods, _ := dataBody["goods"].([]interface{})
  5450. if len(goods) > 0 {
  5451. for _, item := range goods {
  5452. items := item.(map[string]interface{})
  5453. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5454. utils.ErrorLog("good_id")
  5455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5456. return
  5457. }
  5458. good_id := int64(items["good_id"].(float64))
  5459. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5460. utils.ErrorLog("good_type_id")
  5461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5462. return
  5463. }
  5464. good_type_id := int64(items["good_type_id"].(float64))
  5465. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5466. utils.ErrorLog("count")
  5467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5468. return
  5469. }
  5470. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5471. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  5472. utils.ErrorLog("project_id")
  5473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5474. return
  5475. }
  5476. project_id := int64(items["project_id"].(float64))
  5477. prepare := &models.DialysisBeforePrepareGoods{
  5478. GoodId: good_id,
  5479. GoodTypeId: good_type_id,
  5480. Count: count,
  5481. ProjectId: project_id,
  5482. StorehouseId: houseConfig.StorehouseOutInfo,
  5483. }
  5484. beforePrepares = append(beforePrepares, prepare)
  5485. newPrepare := &models.NewDialysisBeforePrepareGoods{
  5486. GoodId: good_id,
  5487. GoodTypeId: good_type_id,
  5488. Count: count,
  5489. ProjectId: project_id,
  5490. StorehouseId: houseConfig.StorehouseOutInfo,
  5491. }
  5492. newBeforePrepares = append(newBeforePrepares, newPrepare)
  5493. }
  5494. }
  5495. }
  5496. //查询是否有库存
  5497. for _, item := range beforePrepares {
  5498. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5499. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  5500. if item.Count > warehouse.Count {
  5501. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5502. c.ServeSuccessJSON(map[string]interface{}{
  5503. "message": "1",
  5504. "good_name": goodObj.GoodName,
  5505. "specification_name": goodObj.SpecificationName,
  5506. })
  5507. return
  5508. }
  5509. }
  5510. //出库逻辑
  5511. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  5512. if err != nil {
  5513. utils.ErrorLog(err.Error())
  5514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5515. return
  5516. }
  5517. //查询当天出库的数据
  5518. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5519. for _, item := range list {
  5520. prepare := models.DialysisBeforePrepare{
  5521. UserOrgId: item.OrgId,
  5522. PatientId: item.PatientId,
  5523. RecordDate: item.RecordTime,
  5524. GoodId: item.GoodId,
  5525. GoodTypeId: item.GoodTypeId,
  5526. Count: item.Count,
  5527. Creater: adminInfo.AdminUser.Id,
  5528. Status: 1,
  5529. Ctime: time.Now().Unix(),
  5530. ProjectId: item.ProjectId,
  5531. StorehouseId: houseConfig.StorehouseOutInfo,
  5532. }
  5533. //清空准备表的数据
  5534. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5535. //插入准备表数据
  5536. service.CreateDialysisBeforePrepareOne(&prepare)
  5537. //查询默认仓库
  5538. //查询默认仓库
  5539. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5540. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5541. var total_count int64
  5542. for _, it := range stockList {
  5543. total_count += it.StockCount
  5544. }
  5545. //基础库插入数据
  5546. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5547. ////更新剩余库存
  5548. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5549. var flush_count int64
  5550. for _, it := range goodList {
  5551. flush_count += it.StockCount
  5552. }
  5553. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5554. if errs != nil {
  5555. goodErrcode := models.XtGoodErrcode{
  5556. UserOrgId: item.OrgId,
  5557. Errcode: "手动出库更新剩余出库失败",
  5558. GoodId: item.GoodId,
  5559. Status: 1,
  5560. Ctime: time.Now().Unix(),
  5561. Mtime: 0,
  5562. Count: 0,
  5563. StockCount: 0,
  5564. Creater: adminInfo.AdminUser.Id,
  5565. BatchNumberId: 0,
  5566. WarehouseOutId: 0,
  5567. }
  5568. service.CreateGoodErrcode(goodErrcode)
  5569. }
  5570. }
  5571. //更新自动出库的地方
  5572. var errs error
  5573. if errs == nil {
  5574. c.ServeSuccessJSON(map[string]interface{}{
  5575. "msg": "修改成功",
  5576. "message": "2",
  5577. "good_name": "",
  5578. "specification_name": "",
  5579. })
  5580. return
  5581. } else {
  5582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5583. return
  5584. }
  5585. }
  5586. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  5587. newArr = make([]*models.DialysisBeforePrepare, 0)
  5588. for i := 0; i < len(arr); i++ {
  5589. repeat := false
  5590. for j := i + 1; j < len(arr); j++ {
  5591. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  5592. repeat = true
  5593. break
  5594. }
  5595. }
  5596. if !repeat {
  5597. newArr = append(newArr, arr[i])
  5598. }
  5599. }
  5600. return
  5601. }
  5602. func (c *DialysisAPIController) GetAllDrug() {
  5603. patient_id, _ := c.GetInt64("patient_id", 0)
  5604. adminInfo := c.GetMobileAdminUserInfo()
  5605. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5606. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  5607. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  5608. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  5609. c.ServeSuccessJSON(map[string]interface{}{
  5610. "base_drug_config": drugStockConfig,
  5611. "private_drug_config": privateDrugConfig,
  5612. "base_drug_list": drugList,
  5613. "private_drug_list": privateDrugList,
  5614. })
  5615. }
  5616. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  5617. newArr = make([]*models.DialysisBeforePrepare, 0)
  5618. for i := 0; i < len(arr); i++ {
  5619. repeat := false
  5620. for j := i + 1; j < len(arr); j++ {
  5621. if arr[i].GoodId == arr[j].GoodId {
  5622. repeat = true
  5623. break
  5624. }
  5625. }
  5626. if !repeat {
  5627. newArr = append(newArr, arr[i])
  5628. }
  5629. }
  5630. return
  5631. }
  5632. func (c *DialysisAPIController) GetDepartment() {
  5633. adminInfo := c.GetMobileAdminUserInfo()
  5634. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  5635. if err == nil {
  5636. c.ServeSuccessJSON(map[string]interface{}{
  5637. "departments": departments,
  5638. })
  5639. } else {
  5640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5641. return
  5642. }
  5643. }
  5644. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  5645. types, _ := c.GetInt("type", 0)
  5646. start_time := c.GetString("start_time")
  5647. end_time := c.GetString("end_time")
  5648. orgId := c.GetMobileAdminUserInfo().Org.Id
  5649. timeLayout := "2006-01-02"
  5650. loc, _ := time.LoadLocation("Local")
  5651. var startTime int64
  5652. if len(start_time) > 0 {
  5653. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5654. if err != nil {
  5655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5656. return
  5657. }
  5658. startTime = theTime.Unix()
  5659. }
  5660. var endTime int64
  5661. if len(end_time) > 0 {
  5662. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5663. if err != nil {
  5664. utils.ErrorLog(err.Error())
  5665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5666. return
  5667. }
  5668. endTime = theTime.Unix()
  5669. }
  5670. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  5671. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  5672. if err != nil {
  5673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5674. } else {
  5675. c.ServeSuccessJSON(map[string]interface{}{
  5676. "list": list,
  5677. "type": types,
  5678. "stockTotal": stockTotal,
  5679. })
  5680. }
  5681. }
  5682. func (c *DialysisAPIController) BatchDeleteMonitor() {
  5683. ids := c.GetString("ids")
  5684. //patient_id, _ := c.GetInt64("patient_id")
  5685. //monitoring_date, _ := c.GetInt64("monitoring_date")
  5686. idArray := strings.Split(ids, ",")
  5687. err := service.BatchDeleteMonitor(idArray)
  5688. fmt.Print("err", err)
  5689. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5690. //redis := service.RedisClient()
  5691. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  5692. //redis.Set(key, "", time.Second)
  5693. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  5694. //redis.Set(keyOne, "", time.Second)
  5695. //fmt.Println("keyo呢32332322332332232332",keyOne)
  5696. //redis.Close()
  5697. c.ServeSuccessJSON(map[string]interface{}{
  5698. "msg": "批量删除成功",
  5699. })
  5700. return
  5701. }
  5702. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  5703. id, _ := c.GetInt64("id")
  5704. timeLayout := "2006-01-02"
  5705. loc, _ := time.LoadLocation("Local")
  5706. start_time := time.Now().Format("2006-01-02")
  5707. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5708. nowTime := time.Now()
  5709. endTime := nowTime.AddDate(-2, 0, 0)
  5710. endTimes := endTime.Format("2006-01-02")
  5711. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  5712. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  5713. fmt.Println("endtime232332322332322323232332", endTime.Unix())
  5714. c.ServeSuccessJSON(map[string]interface{}{
  5715. "list": list,
  5716. })
  5717. return
  5718. }
  5719. func (c *DialysisAPIController) BathDeleteAdviceList() {
  5720. dataBody := make(map[string]interface{}, 0)
  5721. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5722. ids := c.GetString("ids")
  5723. idArray := strings.Split(ids, ",")
  5724. origin, _ := c.GetInt64("origin")
  5725. if origin == 1 {
  5726. err = service.BatchDeleteAdvice(idArray)
  5727. fmt.Print("err", err)
  5728. c.ServeSuccessJSON(map[string]interface{}{
  5729. "msg": "批量删除成功",
  5730. })
  5731. return
  5732. }
  5733. if origin == 2 {
  5734. service.BatchDeleteHisAdvice(idArray)
  5735. }
  5736. }
  5737. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  5738. good_id, _ := c.GetInt64("good_id")
  5739. count, _ := c.GetInt64("count")
  5740. record_time, _ := c.GetInt64("record_time")
  5741. patient_id, _ := c.GetInt64("patient_id")
  5742. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  5743. c.ServeSuccessJSON(map[string]interface{}{
  5744. "detail": detail,
  5745. })
  5746. return
  5747. }
  5748. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  5749. good_id, _ := c.GetInt64("good_id")
  5750. record_time, _ := c.GetInt64("record_time")
  5751. patient_id, _ := c.GetInt64("patient_id")
  5752. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  5753. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  5754. fmt.Print("err", err)
  5755. c.ServeSuccessJSON(map[string]interface{}{
  5756. "msg": "批量删除成功",
  5757. })
  5758. return
  5759. }
  5760. func (c *DialysisAPIController) BatchAdviceCheck() {
  5761. ids := c.GetString("ids")
  5762. idArray := strings.Split(ids, ",")
  5763. creator, _ := c.GetInt64("creator")
  5764. origin, _ := c.GetInt64("origin")
  5765. if origin == 1 {
  5766. err := service.BatchAdviceCheck(idArray, creator)
  5767. fmt.Println(err)
  5768. list, _ := service.GetAdviceExecutionById(idArray)
  5769. c.ServeSuccessJSON(map[string]interface{}{
  5770. "list": list,
  5771. })
  5772. return
  5773. }
  5774. if origin == 2 {
  5775. service.BatchHisAdviceCheck(idArray, creator)
  5776. list, _ := service.GetHisAdviceExecutionById(idArray)
  5777. c.ServeSuccessJSON(map[string]interface{}{
  5778. "list": list,
  5779. })
  5780. return
  5781. }
  5782. }
  5783. func (c *DialysisAPIController) BatchAdviceExecution() {
  5784. ids := c.GetString("ids")
  5785. idArray := strings.Split(ids, ",")
  5786. executionTime := c.GetString("execution_time")
  5787. creator, _ := c.GetInt64("creator")
  5788. timeLayout := "2006-01-02 15:04:05"
  5789. loc, _ := time.LoadLocation("Local")
  5790. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  5791. orgin, _ := c.GetInt64("origin")
  5792. if orgin == 1 {
  5793. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  5794. list, _ := service.GetAdviceExecutionById(idArray)
  5795. fmt.Println(err)
  5796. c.ServeSuccessJSON(map[string]interface{}{
  5797. "list": list,
  5798. })
  5799. return
  5800. }
  5801. if orgin == 2 {
  5802. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  5803. list, _ := service.GetHisAdviceExecutionById(idArray)
  5804. fmt.Println(err)
  5805. c.ServeSuccessJSON(map[string]interface{}{
  5806. "list": list,
  5807. })
  5808. return
  5809. }
  5810. }
  5811. func (c *DialysisAPIController) UpdateStockGoods() {
  5812. good_id, _ := c.GetInt64("good_id")
  5813. record_time, _ := c.GetInt64("record_time")
  5814. patient_id, _ := c.GetInt64("patient_id")
  5815. count, _ := c.GetInt64("count")
  5816. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  5817. fmt.Print("err", err)
  5818. c.ServeSuccessJSON(map[string]interface{}{
  5819. "msg": "更新成功",
  5820. })
  5821. return
  5822. }
  5823. // 当前数据比上一次出库数据少
  5824. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  5825. //查询该患者当天已经出库的耗材信息
  5826. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  5827. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  5828. for i := len(goods_yc) - 1; i >= 0; i-- {
  5829. goods_yc_temp := goods_yc[i]
  5830. for j := len(goods) - 1; j >= 0; j-- {
  5831. goods_temp := goods[j]
  5832. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  5833. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  5834. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  5835. if goods_yc_temp.Count == goods_temp.Count {
  5836. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5837. goods = append(goods[:j], goods[j+1:]...)
  5838. break
  5839. }
  5840. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  5841. if goods_yc_temp.Count > goods_temp.Count {
  5842. temp_count := goods_yc_temp.Count - goods_temp.Count
  5843. goods_yc[i].Count = temp_count
  5844. goods = append(goods[:j], goods[j+1:]...)
  5845. break
  5846. }
  5847. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  5848. if goods_yc_temp.Count < goods_temp.Count {
  5849. temp_count := goods_temp.Count - goods_yc_temp.Count
  5850. goods[j].Count = temp_count
  5851. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5852. break
  5853. }
  5854. }
  5855. }
  5856. }
  5857. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  5858. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  5859. //退库
  5860. if len(goods_yc) > 0 {
  5861. for _, good_yc := range goods_yc {
  5862. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  5863. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  5864. }
  5865. }
  5866. return nil
  5867. }
  5868. // 耗材出库删除
  5869. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  5870. // 先根据相关信息查询当天该耗材的出库信息
  5871. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  5872. if err != nil {
  5873. return err
  5874. }
  5875. var delete_count int64 = 0
  5876. delete_count = warehouseOutInfos.Count - count
  5877. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5878. // 在出库记录表里记录退库详情
  5879. warehouseOutInfo := &models.WarehouseOutInfo{
  5880. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5881. WarehouseOutId: warehouseOut.ID,
  5882. Status: 1,
  5883. Ctime: time.Now().Unix(),
  5884. OrgId: orgID,
  5885. Type: 1,
  5886. IsSys: 1,
  5887. SysRecordTime: record_time,
  5888. GoodTypeId: good_yc.GoodTypeId,
  5889. GoodId: good_yc.GoodId,
  5890. PatientId: good_yc.PatientId,
  5891. ConsumableType: 2,
  5892. StorehouseId: houseConfig.StorehouseOutInfo,
  5893. IsCheck: 1,
  5894. }
  5895. warehouseOutInfo.Count = count
  5896. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5897. warehouseOutInfo.Price = stockInInfo.Price
  5898. warehouseOutInfo.Dealer = stockInInfo.Dealer
  5899. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  5900. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  5901. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  5902. warehouseOutInfo.Number = warehouseOutInfos.Number
  5903. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  5904. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  5905. //查找当天是否存在出库记录
  5906. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5907. if errcod == gorm.ErrRecordNotFound {
  5908. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5909. //插入详情明细表
  5910. stockFlow := models.VmStockFlow{
  5911. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5912. WarehouseOutId: warehouseOut.ID,
  5913. GoodId: good_yc.GoodId,
  5914. Number: warehouseOutInfos.Number,
  5915. ProductDate: stockInInfo.ProductDate,
  5916. ExpireDate: stockInInfo.ExpiryDate,
  5917. Count: count,
  5918. Price: stockInInfo.Price,
  5919. Status: 1,
  5920. Ctime: time.Now().Unix(),
  5921. UserOrgId: good_yc.OrgId,
  5922. Manufacturer: stockInInfo.Manufacturer,
  5923. Dealer: stockInInfo.Dealer,
  5924. LicenseNumber: stockInInfo.LicenseNumber,
  5925. IsEdit: 2,
  5926. Creator: creater,
  5927. SystemTime: record_time,
  5928. ConsumableType: 3,
  5929. WarehousingDetailId: 0,
  5930. IsSys: 1,
  5931. UpdateCreator: creater,
  5932. PatientId: patient_id,
  5933. StorehouseId: houseConfig.StorehouseOutInfo,
  5934. }
  5935. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  5936. if errflow == gorm.ErrRecordNotFound {
  5937. //创建流水表
  5938. err := service.CreateStockFlowOne(stockFlow)
  5939. fmt.Println("err", err)
  5940. } else if errflow == nil {
  5941. //插入详情明细表
  5942. stockFlow := models.VmStockFlow{
  5943. ID: exsit.ID,
  5944. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5945. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5946. WarehouseOutId: warehouseOut.ID,
  5947. GoodId: good_yc.GoodId,
  5948. Number: warehouseOutInfos.Number,
  5949. ProductDate: stockInInfo.ProductDate,
  5950. ExpireDate: stockInInfo.ExpiryDate,
  5951. Count: exsit.Count - delete_count,
  5952. Price: stockInInfo.Price,
  5953. Status: 1,
  5954. Ctime: time.Now().Unix(),
  5955. UserOrgId: good_yc.OrgId,
  5956. Manufacturer: stockInInfo.Manufacturer,
  5957. Dealer: stockInInfo.Dealer,
  5958. LicenseNumber: stockInInfo.LicenseNumber,
  5959. IsEdit: 2,
  5960. Creator: creater,
  5961. SystemTime: record_time,
  5962. ConsumableType: 3,
  5963. WarehousingDetailId: 0,
  5964. IsSys: 1,
  5965. UpdateCreator: creater,
  5966. PatientId: patient_id,
  5967. StorehouseId: houseConfig.StorehouseOutInfo,
  5968. }
  5969. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  5970. }
  5971. if errOne != nil {
  5972. return errOne
  5973. }
  5974. } else if errcod == nil {
  5975. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5976. //插入详情明细表
  5977. stockFlow := models.VmStockFlow{
  5978. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5979. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5980. WarehouseOutId: warehouseOut.ID,
  5981. GoodId: good_yc.GoodId,
  5982. Number: warehouseOutInfos.Number,
  5983. ProductDate: stockInInfo.ProductDate,
  5984. ExpireDate: stockInInfo.ExpiryDate,
  5985. Count: count,
  5986. Price: stockInInfo.Price,
  5987. Status: 1,
  5988. Ctime: time.Now().Unix(),
  5989. UserOrgId: good_yc.OrgId,
  5990. Manufacturer: stockInInfo.Manufacturer,
  5991. Dealer: stockInInfo.Dealer,
  5992. LicenseNumber: stockInInfo.LicenseNumber,
  5993. IsEdit: 2,
  5994. Creator: creater,
  5995. SystemTime: record_time,
  5996. ConsumableType: 3,
  5997. WarehousingDetailId: 0,
  5998. IsSys: 1,
  5999. UpdateCreator: creater,
  6000. PatientId: patient_id,
  6001. ReturnCount: delete_count,
  6002. StorehouseId: houseConfig.StorehouseOutInfo,
  6003. }
  6004. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  6005. if errflows == gorm.ErrRecordNotFound {
  6006. //创建流水表
  6007. service.CreateStockFlowOne(stockFlow)
  6008. } else if errflows == nil {
  6009. stockFlow := models.VmStockFlow{
  6010. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6011. ID: exsit.ID,
  6012. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6013. WarehouseOutId: warehouseOut.ID,
  6014. GoodId: good_yc.GoodId,
  6015. Number: warehouseOutInfos.Number,
  6016. ProductDate: stockInInfo.ProductDate,
  6017. ExpireDate: stockInInfo.ExpiryDate,
  6018. Count: exsit.Count - delete_count,
  6019. Price: stockInInfo.Price,
  6020. Status: 1,
  6021. Ctime: time.Now().Unix(),
  6022. UserOrgId: good_yc.OrgId,
  6023. Manufacturer: stockInInfo.Manufacturer,
  6024. Dealer: stockInInfo.Dealer,
  6025. LicenseNumber: stockInInfo.LicenseNumber,
  6026. IsEdit: 2,
  6027. Creator: creater,
  6028. SystemTime: record_time,
  6029. ConsumableType: 3,
  6030. WarehousingDetailId: 0,
  6031. IsSys: 1,
  6032. UpdateCreator: creater,
  6033. PatientId: patient_id,
  6034. ReturnCount: delete_count,
  6035. StorehouseId: houseConfig.StorehouseOutInfo,
  6036. }
  6037. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  6038. }
  6039. }
  6040. //更改自动出库的表格
  6041. details := models.BloodAutomaticReduceDetail{
  6042. WarehouseOutId: warehouseOutInfo.ID,
  6043. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6044. PatientId: patient_id,
  6045. Ctime: time.Now().Unix(),
  6046. Mtime: time.Now().Unix(),
  6047. Status: 1,
  6048. RecordTime: record_time,
  6049. OrgId: orgID,
  6050. GoodId: good_yc.GoodId,
  6051. GoodTypeId: good_yc.GoodTypeId,
  6052. Count: count,
  6053. StorehouseId: houseConfig.StorehouseOutInfo,
  6054. }
  6055. //查询当天耗材是否已经存在数据
  6056. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6057. if errcode == gorm.ErrRecordNotFound {
  6058. errTwo := service.CreateAutoReduceRecord(&details)
  6059. if errTwo != nil {
  6060. return errTwo
  6061. }
  6062. } else if errcode == nil {
  6063. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6064. service.CreateAutoReduceRecord(&details)
  6065. }
  6066. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  6067. //增加出库库存数量
  6068. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  6069. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  6070. fmt.Println("errOne", errOne)
  6071. // 删除出库完成后,要增加对应批次的库存数量
  6072. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  6073. if errThree != nil {
  6074. return errThree
  6075. }
  6076. if good_yc.Count == 0 {
  6077. return nil
  6078. } else {
  6079. return errors.New("退库和出库数据不匹配")
  6080. }
  6081. }
  6082. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  6083. //查询该患者当天已经出库的耗材信息
  6084. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  6085. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  6086. for i := len(goods_yc) - 1; i >= 0; i-- {
  6087. goods_yc_temp := goods_yc[i]
  6088. for j := len(goods) - 1; j >= 0; j-- {
  6089. goods_temp := goods[j]
  6090. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  6091. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  6092. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  6093. if goods_yc_temp.Count == goods_temp.Count {
  6094. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6095. goods = append(goods[:j], goods[j+1:]...)
  6096. break
  6097. }
  6098. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  6099. if goods_yc_temp.Count > goods_temp.Count {
  6100. temp_count := goods_yc_temp.Count - goods_temp.Count
  6101. goods_yc[i].Count = temp_count
  6102. goods = append(goods[:j], goods[j+1:]...)
  6103. break
  6104. }
  6105. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  6106. if goods_yc_temp.Count < goods_temp.Count {
  6107. temp_count := goods_temp.Count - goods_yc_temp.Count
  6108. goods[j].Count = temp_count
  6109. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6110. break
  6111. }
  6112. }
  6113. }
  6114. }
  6115. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  6116. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  6117. fmt.Println("剩余需要出库的", len(goods))
  6118. if len(goods) > 0 {
  6119. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  6120. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  6121. if err == gorm.ErrRecordNotFound {
  6122. //没有记录,则创建出库单
  6123. timeStr := time.Now().Format("2006-01-02")
  6124. timeArr := strings.Split(timeStr, "-")
  6125. total, _ := service.FindAllWarehouseOut(orgID)
  6126. total = total + 1
  6127. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6128. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6129. number = number + total
  6130. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6131. warehouseOut := models.WarehouseOut{
  6132. WarehouseOutOrderNumber: warehousing_out_order,
  6133. OperationTime: time.Now().Unix(),
  6134. OrgId: orgID,
  6135. Creater: creater,
  6136. Ctime: time.Now().Unix(),
  6137. Status: 1,
  6138. WarehouseOutTime: record_time,
  6139. Dealer: 0,
  6140. Manufacturer: 0,
  6141. Type: 1,
  6142. IsSys: 1,
  6143. StorehouseId: houseConfig.StorehouseOutInfo,
  6144. IsCheck: 1,
  6145. }
  6146. err := service.AddSigleWarehouseOut(&warehouseOut)
  6147. if err != nil {
  6148. utils.TraceLog("创建出库单失败 err = %v", err)
  6149. return err
  6150. } else {
  6151. out = warehouseOut
  6152. }
  6153. }
  6154. for _, item := range goods {
  6155. var newCount int64 = 0
  6156. for _, it := range goodOne {
  6157. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  6158. newCount = it.Count
  6159. }
  6160. }
  6161. prepare := models.DialysisBeforePrepare{
  6162. GoodTypeId: item.GoodTypeId,
  6163. GoodId: item.GoodId,
  6164. Count: item.Count,
  6165. StorehouseId: houseConfig.StorehouseOutInfo,
  6166. }
  6167. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  6168. //增加出库数量
  6169. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  6170. }
  6171. }
  6172. if len(goods_yc) > 0 {
  6173. for _, good_yc := range goods_yc {
  6174. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  6175. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  6176. }
  6177. }
  6178. return nil
  6179. }
  6180. // 耗材出库删除
  6181. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  6182. // 先根据相关信息查询当天该耗材的出库信息
  6183. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  6184. if err != nil {
  6185. return err
  6186. }
  6187. var delete_count int64 = 0
  6188. for _, ware := range warehouseOutInfos {
  6189. // 判断当前出库的数据和删除出库数量
  6190. if good_yc.Count <= ware.Count {
  6191. delete_count = good_yc.Count
  6192. } else {
  6193. delete_count = ware.Count
  6194. }
  6195. warehouseOutInfo := &models.WarehouseOutInfo{
  6196. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6197. WarehouseOutId: warehouseOut.ID,
  6198. Status: 1,
  6199. Ctime: time.Now().Unix(),
  6200. Remark: "",
  6201. OrgId: orgID,
  6202. Type: 1,
  6203. Manufacturer: 0,
  6204. Dealer: 0,
  6205. IsSys: 0,
  6206. SysRecordTime: record_time,
  6207. GoodTypeId: good_yc.GoodTypeId,
  6208. GoodId: good_yc.GoodId,
  6209. StorehouseId: warehouseOut.StorehouseId,
  6210. IsCheck: 1,
  6211. }
  6212. warehouseOutInfo.Count = delete_count
  6213. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  6214. warehouseOutInfo.Price = stockInInfo.Price
  6215. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6216. if errOne != nil {
  6217. return errOne
  6218. }
  6219. // 删除出库完成后,要改变流水库存(有疑问)
  6220. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  6221. fmt.Println("errOne", errOne)
  6222. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  6223. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  6224. //扣减出库数量
  6225. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  6226. if errThree != nil {
  6227. return errThree
  6228. }
  6229. }
  6230. if good_yc.Count == 0 {
  6231. return nil
  6232. } else {
  6233. return errors.New("退库和出库数据不匹配")
  6234. }
  6235. }
  6236. func (this *DialysisAPIController) GetMobileScheduleList() {
  6237. limit, _ := this.GetInt64("limit")
  6238. page, _ := this.GetInt64("page")
  6239. type_options_visible, _ := this.GetInt64("type_options_visible")
  6240. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  6241. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  6242. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  6243. }
  6244. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  6245. newArr = make([]*models.HisPrescriptionProject, 0)
  6246. for i := 0; i < len(arr); i++ {
  6247. repeat := false
  6248. for j := i + 1; j < len(arr); j++ {
  6249. if arr[i].TeamId == arr[j].TeamId {
  6250. repeat = true
  6251. break
  6252. }
  6253. }
  6254. if !repeat {
  6255. newArr = append(newArr, arr[i])
  6256. }
  6257. }
  6258. return
  6259. }
  6260. func (this *DialysisAPIController) GetRoleList() {
  6261. admin_user_id, _ := this.GetInt64("admin_user_id")
  6262. orgid := this.GetMobileAdminUserInfo().Org.Id
  6263. list, err := service.GetRoleList(orgid, admin_user_id)
  6264. fmt.Println(err)
  6265. this.ServeSuccessJSON(map[string]interface{}{
  6266. "list": list,
  6267. })
  6268. return
  6269. }
  6270. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  6271. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  6272. // 先根据相关信息查询当天该耗材的出库信息
  6273. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  6274. if err != nil {
  6275. return err
  6276. }
  6277. var delete_count int64 = 0
  6278. delete_count = warehouseOutInfos.Count - count
  6279. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  6280. // 删除出库完成后,要增加对应批次的库存数量
  6281. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  6282. if errThree != nil {
  6283. return errThree
  6284. }
  6285. //增加退库数量
  6286. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6287. //扣减出库数量
  6288. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  6289. //查询剩余库存
  6290. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  6291. var sum_count int64
  6292. for _, item := range goodList {
  6293. sum_count += item.StockCount
  6294. }
  6295. // 在出库记录表里记录退库详情
  6296. warehouseOutInfo := &models.WarehouseOutInfo{
  6297. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6298. WarehouseOutId: warehouseOut.ID,
  6299. Status: 1,
  6300. Ctime: time.Now().Unix(),
  6301. OrgId: orgID,
  6302. Type: 1,
  6303. IsSys: 1,
  6304. SysRecordTime: record_time,
  6305. GoodTypeId: good_yc.GoodTypeId,
  6306. GoodId: good_yc.GoodId,
  6307. PatientId: good_yc.PatientId,
  6308. ConsumableType: 2,
  6309. StorehouseId: houseConfig.StorehouseOutInfo,
  6310. IsCheck: 1,
  6311. OverCount: sum_count,
  6312. }
  6313. warehouseOutInfo.Count = count
  6314. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  6315. warehouseOutInfo.Price = stockInInfo.Price
  6316. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6317. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6318. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6319. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6320. warehouseOutInfo.Number = warehouseOutInfos.Number
  6321. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6322. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6323. //查找当天是否存在出库记录
  6324. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6325. if errcod == gorm.ErrRecordNotFound {
  6326. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6327. //插入详情明细表
  6328. if errOne != nil {
  6329. return errOne
  6330. }
  6331. //插入详情明细表
  6332. stockFlow := models.VmStockFlow{
  6333. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6334. WarehouseOutId: warehouseOut.ID,
  6335. GoodId: good_yc.GoodId,
  6336. Number: warehouseOutInfos.Number,
  6337. ProductDate: stockInInfo.ProductDate,
  6338. ExpireDate: stockInInfo.ExpiryDate,
  6339. Count: count,
  6340. Price: stockInInfo.Price,
  6341. Status: 1,
  6342. Ctime: time.Now().Unix(),
  6343. UserOrgId: good_yc.OrgId,
  6344. Manufacturer: stockInInfo.Manufacturer,
  6345. Dealer: stockInInfo.Dealer,
  6346. LicenseNumber: stockInInfo.LicenseNumber,
  6347. IsEdit: 2,
  6348. Creator: creater,
  6349. SystemTime: record_time,
  6350. ConsumableType: 3,
  6351. WarehousingDetailId: 0,
  6352. IsSys: 1,
  6353. UpdateCreator: creater,
  6354. PatientId: patient_id,
  6355. StorehouseId: houseConfig.StorehouseOutInfo,
  6356. OverCount: sum_count,
  6357. ProjectId: good_yc.ProjectId,
  6358. }
  6359. err := service.CreateStockFlowOne(stockFlow)
  6360. fmt.Println("err", err)
  6361. } else if errcod == nil {
  6362. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6363. }
  6364. //创建退库单
  6365. operation_time := time.Now().Unix()
  6366. //创建退库单
  6367. timeStr := time.Now().Format("2006-01-02")
  6368. timeArr := strings.Split(timeStr, "-")
  6369. total, _ := service.FindAllCancelStockTotal(orgID)
  6370. total = total + 1
  6371. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6372. cancelStock := models.CancelStock{
  6373. OrderNumber: orderNumber,
  6374. OperaTime: operation_time,
  6375. OrgId: orgID,
  6376. Creater: warehouseOut.Creater,
  6377. Ctime: time.Now().Unix(),
  6378. Status: 1,
  6379. ReturnTime: record_time,
  6380. Type: 1,
  6381. StorehouseId: stockInInfo.StorehouseId,
  6382. IsCheck: 1,
  6383. }
  6384. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  6385. if msgerrkonde == gorm.ErrRecordNotFound {
  6386. service.AddSigleCancelStock(&cancelStock)
  6387. }
  6388. cancel, _ := service.GetLastCancelStockById(orgID)
  6389. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  6390. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  6391. cancelStockInfo := models.CancelStockInfo{
  6392. GoodId: stockInInfo.GoodId,
  6393. CancelStockId: cancel.ID,
  6394. GoodTypeId: stockInInfo.GoodTypeId,
  6395. Count: delete_count,
  6396. Price: stockInInfo.PackingPrice,
  6397. Total: 0,
  6398. ProductDate: stockInInfo.ProductDate,
  6399. ExpiryDate: stockInInfo.ExpiryDate,
  6400. Ctime: time.Now().Unix(),
  6401. Status: 1,
  6402. OrgId: orgID,
  6403. OrderNumber: cancel.OrderNumber,
  6404. Type: 0,
  6405. Dealer: deaerler.DealerName,
  6406. Manufacturer: manufacturer.ManufacturerName,
  6407. Number: stockInInfo.Number,
  6408. RegisterAccount: "",
  6409. Remark: "",
  6410. WarehouseInfoId: stockInInfo.ID,
  6411. PatientId: patient_id,
  6412. RecordDate: record_time,
  6413. StorehouseId: stockInInfo.StorehouseId,
  6414. IsCheck: 1,
  6415. }
  6416. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6417. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  6418. flow := models.VmStockFlow{
  6419. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  6420. GoodId: good_yc.GoodId,
  6421. Number: warehouseOutInfos.Number,
  6422. LicenseNumber: stockInInfo.LicenseNumber,
  6423. Count: delete_count,
  6424. UserOrgId: orgID,
  6425. PatientId: patient_id,
  6426. SystemTime: record_time,
  6427. ConsumableType: 7,
  6428. IsSys: 0,
  6429. WarehousingOrder: "",
  6430. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  6431. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6432. IsEdit: 0,
  6433. CancelStockId: cancel.ID,
  6434. CancelOrderNumber: cancel.OrderNumber,
  6435. Manufacturer: manufacturer.ID,
  6436. Dealer: 0,
  6437. Creator: warehouseOut.Creater,
  6438. UpdateCreator: 0,
  6439. Status: 1,
  6440. Ctime: time.Now().Unix(),
  6441. Mtime: 0,
  6442. Price: stockInInfo.Price,
  6443. WarehousingDetailId: stockInInfo.ID,
  6444. WarehouseOutDetailId: warehouseOutInfos.ID,
  6445. CancelOutDetailId: cancelInfo.ID,
  6446. ProductDate: stockInInfo.ProductDate,
  6447. ExpireDate: stockInInfo.ExpiryDate,
  6448. StorehouseId: houseConfig.StorehouseOutInfo,
  6449. OverCount: sum_count,
  6450. }
  6451. service.CreateStockFlowOne(flow)
  6452. //更改自动出库的表格
  6453. details := models.BloodAutomaticReduceDetail{
  6454. WarehouseOutId: warehouseOutInfo.ID,
  6455. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6456. PatientId: patient_id,
  6457. Ctime: time.Now().Unix(),
  6458. Mtime: time.Now().Unix(),
  6459. Status: 1,
  6460. RecordTime: record_time,
  6461. OrgId: orgID,
  6462. GoodId: good_yc.GoodId,
  6463. GoodTypeId: good_yc.GoodTypeId,
  6464. Count: count,
  6465. StorehouseId: houseConfig.StorehouseOutInfo,
  6466. }
  6467. //查询当天耗材是否已经存在数据
  6468. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6469. if errcode == gorm.ErrRecordNotFound {
  6470. errTwo := service.CreateAutoReduceRecord(&details)
  6471. if errTwo != nil {
  6472. return errTwo
  6473. }
  6474. } else if errcode == nil {
  6475. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6476. service.CreateAutoReduceRecord(&details)
  6477. }
  6478. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  6479. //增加出库库存数量
  6480. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  6481. if good_yc.Count == 0 {
  6482. return nil
  6483. } else {
  6484. return errors.New("退库和出库数据不匹配")
  6485. }
  6486. }
  6487. func (this *DialysisAPIController) SavePatientSign() {
  6488. adminUserInfo := this.GetMobileAdminUserInfo()
  6489. patient_id, _ := this.GetInt64("patient_id")
  6490. dialysis_date, _ := this.GetInt64("dialysis_date")
  6491. orgid := adminUserInfo.Org.Id
  6492. var esdata models.DialysisOrder
  6493. var err error
  6494. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  6495. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6496. return
  6497. }
  6498. esdata.Hash = esdata.Hash
  6499. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  6500. order := models.DialysisOrder{
  6501. Hash: esdata.Hash,
  6502. Url: esdata.Url,
  6503. }
  6504. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  6505. redis := service.RedisClient()
  6506. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  6507. redis.Set(key, "", time.Second)
  6508. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  6509. //清空key 值
  6510. redis.Set(keyOne, "", time.Second)
  6511. //scheduleDateStartOne := startDate.Format("2006-01-02")
  6512. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6513. //redis.Set(keyTwo, "", time.Second)
  6514. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  6515. redis.Set(keyThree, "", time.Second)
  6516. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  6517. redis.Set(keyFour, "", time.Second)
  6518. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  6519. redis.Set(keyFive, "", time.Second)
  6520. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  6521. redis.Set(keySix, "", time.Second)
  6522. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  6523. redis.Set(keySeven, "", time.Second)
  6524. if err != nil {
  6525. fmt.Println(err)
  6526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6527. return
  6528. }
  6529. this.ServeSuccessJSON(map[string]interface{}{
  6530. "electronic_signature": esdata,
  6531. })
  6532. }
  6533. func (this *DialysisAPIController) GetPatientSign() {
  6534. patient_id, _ := this.GetInt64("patient_id")
  6535. dialysis_date, _ := this.GetInt64("dialysis_date")
  6536. adminUserInfo := this.GetMobileAdminUserInfo()
  6537. orgId := adminUserInfo.Org.Id
  6538. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  6539. if err != nil {
  6540. fmt.Println(err)
  6541. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6542. return
  6543. }
  6544. this.ServeSuccessJSON(map[string]interface{}{
  6545. "dialysisOrder": dialysisOrder,
  6546. })
  6547. }
  6548. func (this *DialysisAPIController) GetScheduleByPatient() {
  6549. patient_id, _ := this.GetInt64("patient_id")
  6550. schedule_date, _ := this.GetInt64("schedule_date")
  6551. orgid := this.GetMobileAdminUserInfo().Org.Id
  6552. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  6553. this.ServeSuccessJSON(map[string]interface{}{
  6554. "schedule": schedule,
  6555. })
  6556. }
  6557. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  6558. org_id := this.GetMobileAdminUserInfo().Org.Id
  6559. patient_id, _ := this.GetInt64("patient_id")
  6560. schedule_date, _ := this.GetInt64("schedule_date")
  6561. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  6562. this.ServeSuccessJSON(map[string]interface{}{
  6563. "order": order,
  6564. })
  6565. }
  6566. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  6567. org_id := this.GetMobileAdminUserInfo().Org.Id
  6568. schedule_date := this.GetString("schedule_date")
  6569. schedule_type, _ := this.GetInt64("schedule_type")
  6570. timeLayout := "2006-01-02"
  6571. loc, _ := time.LoadLocation("Local")
  6572. var startdateunix int64
  6573. if len(schedule_date) > 0 {
  6574. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  6575. if err != nil {
  6576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6577. return
  6578. }
  6579. startdateunix = theTime.Unix()
  6580. }
  6581. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  6582. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  6583. devices, _ := service.GetAllDevicetByListSix(org_id)
  6584. for key, item := range scheduals {
  6585. // 床位信息
  6586. for _, device := range devices {
  6587. if item.BedId == device.ID {
  6588. scheduals[key].DeviceNumber = device
  6589. break
  6590. }
  6591. }
  6592. }
  6593. this.ServeSuccessJSON(map[string]interface{}{
  6594. "list": list,
  6595. "scheduals": scheduals,
  6596. })
  6597. }
  6598. func (this *DialysisAPIController) SavePatientPicture() {
  6599. patient_id, _ := this.GetInt64("patient_id")
  6600. dialysis_date, _ := this.GetInt64("schedule_date")
  6601. avatar := this.GetString("avatar")
  6602. fmt.Println("patient_id", patient_id)
  6603. orgId := this.GetMobileAdminUserInfo().Org.Id
  6604. order := models.DialysisOrder{
  6605. Url: avatar,
  6606. }
  6607. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  6608. redis := service.RedisClient()
  6609. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  6610. redis.Set(key, "", time.Second)
  6611. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  6612. //清空key 值
  6613. redis.Set(keyOne, "", time.Second)
  6614. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  6615. redis.Set(keyThree, "", time.Second)
  6616. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  6617. redis.Set(keyFour, "", time.Second)
  6618. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  6619. redis.Set(keyFive, "", time.Second)
  6620. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  6621. redis.Set(keySix, "", time.Second)
  6622. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  6623. redis.Set(keySeven, "", time.Second)
  6624. if err != nil {
  6625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6626. return
  6627. }
  6628. this.ServeSuccessJSON(map[string]interface{}{
  6629. "order": order,
  6630. })
  6631. }
  6632. func (this *DialysisAPIController) ExectionMobileAdvice() {
  6633. ids := this.GetString("ids")
  6634. idSplit := strings.Split(ids, ",")
  6635. orgId := this.GetMobileAdminUserInfo().Org.Id
  6636. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6637. execution_time := this.GetString("exce_time")
  6638. timeLayout2 := "2006-01-02 15:04:05"
  6639. loc, _ := time.LoadLocation("Local")
  6640. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  6641. if errs != nil {
  6642. utils.ErrorLog(errs.Error())
  6643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6644. return
  6645. }
  6646. //his客户
  6647. if config.IsOpen == 1 {
  6648. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  6649. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  6650. for _, item := range list {
  6651. for _, it := range adviceList {
  6652. if item.DrugId == it.DrugId {
  6653. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6654. }
  6655. }
  6656. }
  6657. for _, item := range list {
  6658. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6659. var sum_out_count int64
  6660. for _, itemThree := range item.ChildDoctorAdvice {
  6661. var prescribing_number int64
  6662. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6663. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6664. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6665. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6666. }
  6667. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6668. prescribing_number = parseIntPrescribingNumber
  6669. }
  6670. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6671. prescribing_number = parseIntPrescribingNumber
  6672. }
  6673. sum_out_count += prescribing_number
  6674. }
  6675. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6676. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6677. //库存不足
  6678. if sum_out_count > drugStockOut.FlushCount {
  6679. this.ServeSuccessJSON(map[string]interface{}{
  6680. "msg": "2",
  6681. "drug": medical,
  6682. "ids": ids,
  6683. })
  6684. return
  6685. }
  6686. }
  6687. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6688. //执行医嘱
  6689. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6690. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  6691. for _, item := range advices {
  6692. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6693. redis := service.RedisClient()
  6694. //清空key 值
  6695. redis.Set(key, "", time.Second)
  6696. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6697. redis.Set(keyTwo, "", time.Second)
  6698. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6699. redis.Set(keyThree, "", time.Second)
  6700. recordDate := theTime.Format("2006-01-02")
  6701. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6702. redis.Set(keyFour, "", time.Second)
  6703. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6704. redis.Set(keyFive, "", time.Second)
  6705. defer redis.Close()
  6706. }
  6707. if errs == nil {
  6708. //药品管理信息
  6709. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  6710. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6711. if drugStockConfig.IsOpen == 1 {
  6712. for _, item := range advices {
  6713. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  6714. config, _ := service.GetDrugOpenConfigOne(orgId)
  6715. if config.IsOpen != 1 {
  6716. //查询该药品是否有库存
  6717. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6718. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  6719. if medical.IsUse == 2 {
  6720. if config.IsOpen != 1 {
  6721. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6722. service.HisDrugsDelivery(orgId, creater, &advice)
  6723. }
  6724. if pharmacyConfig.IsOpen != 1 {
  6725. service.HisDrugsDelivery(orgId, creater, &advice)
  6726. }
  6727. //更新字典里面的库存
  6728. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6729. var sum_count int64
  6730. for _, its := range stockInfo {
  6731. if its.MaxUnit == medical.MaxUnit {
  6732. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6733. }
  6734. sum_count += its.StockMaxNumber + its.StockMinNumber
  6735. }
  6736. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6737. //剩余库存
  6738. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6739. }
  6740. }
  6741. }
  6742. }
  6743. }
  6744. this.ServeSuccessJSON(map[string]interface{}{
  6745. "msg": "1",
  6746. "ids": ids,
  6747. })
  6748. return
  6749. } else {
  6750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6751. }
  6752. }
  6753. fmt.Println("config233322333223", config.IsOpen)
  6754. //血透客户
  6755. if config.IsOpen == 2 || config.IsOpen == 0 {
  6756. //药品管理信息
  6757. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  6758. if drugStockConfig.IsOpen == 1 {
  6759. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  6760. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  6761. for _, item := range list {
  6762. for _, it := range adviceList {
  6763. if item.DrugId == it.DrugId {
  6764. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6765. }
  6766. }
  6767. }
  6768. for _, item := range list {
  6769. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6770. var sum_out_count int64
  6771. for _, itemThree := range item.ChildDoctorAdvice {
  6772. var prescribing_number int64
  6773. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6774. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6775. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6776. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6777. }
  6778. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6779. prescribing_number = parseIntPrescribingNumber
  6780. }
  6781. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6782. prescribing_number = parseIntPrescribingNumber
  6783. }
  6784. sum_out_count += prescribing_number
  6785. }
  6786. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6787. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6788. //库存不足
  6789. if sum_out_count > drugStockOut.FlushCount {
  6790. this.ServeSuccessJSON(map[string]interface{}{
  6791. "msg": "2",
  6792. "drug": medical,
  6793. "ids": ids,
  6794. })
  6795. return
  6796. }
  6797. }
  6798. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6799. fmt.Println("creater2332243244224242424", creater)
  6800. //执行医嘱
  6801. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6802. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  6803. for _, item := range advices {
  6804. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6805. redis := service.RedisClient()
  6806. //清空key 值
  6807. redis.Set(key, "", time.Second)
  6808. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6809. redis.Set(keyTwo, "", time.Second)
  6810. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6811. redis.Set(keyThree, "", time.Second)
  6812. recordDate := theTime.Format("2006-01-02")
  6813. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6814. redis.Set(keyFour, "", time.Second)
  6815. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6816. redis.Set(keyFive, "", time.Second)
  6817. defer redis.Close()
  6818. }
  6819. if errs == nil {
  6820. for _, item := range advices {
  6821. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6822. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6823. //查询是否出库按钮开启
  6824. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  6825. if adviceSetting.IsAdviceOpen == 1 {
  6826. //查询是否出库按钮开启
  6827. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  6828. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  6829. if prescriptionConfig.IsOpen == 1 {
  6830. if medical.IsUse == 2 {
  6831. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6832. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6833. }
  6834. if pharmacyConfig.IsOpen != 1 {
  6835. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6836. }
  6837. //更新字典里面的库存
  6838. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6839. var sum_count int64
  6840. for _, its := range stockInfo {
  6841. if its.MaxUnit == medical.MaxUnit {
  6842. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6843. }
  6844. sum_count += its.StockMaxNumber + its.StockMinNumber
  6845. }
  6846. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6847. //剩余库存
  6848. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6849. }
  6850. }
  6851. } else {
  6852. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  6853. if medical.IsUse == 2 {
  6854. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6855. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6856. }
  6857. if pharmacyConfig.IsOpen != 1 {
  6858. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6859. }
  6860. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6861. var sum_count int64
  6862. for _, its := range stockInfo {
  6863. if its.MaxUnit == medical.MaxUnit {
  6864. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6865. }
  6866. sum_count += its.StockMaxNumber + its.StockMinNumber
  6867. }
  6868. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6869. //剩余库存
  6870. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6871. }
  6872. }
  6873. }
  6874. }
  6875. this.ServeSuccessJSON(map[string]interface{}{
  6876. "msg": "1",
  6877. "ids": ids,
  6878. })
  6879. return
  6880. } else {
  6881. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6882. //执行医嘱
  6883. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6884. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  6885. for _, item := range advices {
  6886. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6887. redis := service.RedisClient()
  6888. //清空key 值
  6889. redis.Set(key, "", time.Second)
  6890. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6891. redis.Set(keyTwo, "", time.Second)
  6892. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6893. redis.Set(keyThree, "", time.Second)
  6894. recordDate := theTime.Format("2006-01-02")
  6895. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6896. redis.Set(keyFour, "", time.Second)
  6897. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6898. redis.Set(keyFive, "", time.Second)
  6899. defer redis.Close()
  6900. }
  6901. this.ServeSuccessJSON(map[string]interface{}{
  6902. "msg": "1",
  6903. "ids": ids,
  6904. })
  6905. return
  6906. }
  6907. }
  6908. }
  6909. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  6910. ids := this.GetString("ids")
  6911. idSplit := strings.Split(ids, ",")
  6912. orgId := this.GetMobileAdminUserInfo().Org.Id
  6913. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6914. if config.IsOpen == 1 {
  6915. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  6916. this.ServeSuccessJSON(map[string]interface{}{
  6917. "msg": "1",
  6918. "ids": ids,
  6919. })
  6920. return
  6921. }
  6922. if config.IsOpen == 0 || config.IsOpen == 2 {
  6923. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  6924. this.ServeSuccessJSON(map[string]interface{}{
  6925. "msg": "1",
  6926. "ids": ids,
  6927. })
  6928. return
  6929. }
  6930. }
  6931. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  6932. ids := this.GetString("ids")
  6933. idSplit := strings.Split(ids, ",")
  6934. orgId := this.GetMobileAdminUserInfo().Org.Id
  6935. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6936. //his
  6937. if config.IsOpen == 1 {
  6938. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  6939. theTime := time.Now()
  6940. advices := models.HisDoctorAdviceThirty{
  6941. CheckTime: theTime.Unix(),
  6942. Checker: checker,
  6943. UpdatedTime: time.Now().Unix(),
  6944. }
  6945. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  6946. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  6947. for _, item := range list {
  6948. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6949. redis := service.RedisClient()
  6950. //清空key 值
  6951. redis.Set(key, "", time.Second)
  6952. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6953. redis.Set(keyTwo, "", time.Second)
  6954. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6955. redis.Set(keyThree, "", time.Second)
  6956. recordDate := theTime.Format("2006-01-02")
  6957. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6958. redis.Set(keyFour, "", time.Second)
  6959. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6960. redis.Set(keyFive, "", time.Second)
  6961. defer redis.Close()
  6962. }
  6963. this.ServeSuccessJSON(map[string]interface{}{
  6964. "msg": "1",
  6965. "ids": ids,
  6966. })
  6967. return
  6968. }
  6969. //血透
  6970. if config.IsOpen == 0 || config.IsOpen == 2 {
  6971. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  6972. theTime := time.Now()
  6973. advices := models.DoctorAdvice{
  6974. CheckTime: theTime.Unix(),
  6975. Checker: checker,
  6976. UpdatedTime: time.Now().Unix(),
  6977. }
  6978. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  6979. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  6980. for _, item := range list {
  6981. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6982. redis := service.RedisClient()
  6983. //清空key 值
  6984. redis.Set(key, "", time.Second)
  6985. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6986. redis.Set(keyTwo, "", time.Second)
  6987. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6988. redis.Set(keyThree, "", time.Second)
  6989. recordDate := theTime.Format("2006-01-02")
  6990. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6991. redis.Set(keyFour, "", time.Second)
  6992. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6993. redis.Set(keyFive, "", time.Second)
  6994. defer redis.Close()
  6995. }
  6996. this.ServeSuccessJSON(map[string]interface{}{
  6997. "msg": "1",
  6998. "ids": ids,
  6999. })
  7000. return
  7001. }
  7002. }
  7003. func (this *DialysisAPIController) CheckSchedule() {
  7004. patientID, _ := this.GetInt64("patient_id")
  7005. recordDateStr := this.GetString("record_date")
  7006. nurseID, _ := this.GetInt64("nurse")
  7007. schedual_type, _ := this.GetInt64("schedual_type")
  7008. bedID, _ := this.GetInt64("bed")
  7009. start_time := this.GetString("start_time")
  7010. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  7011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7012. return
  7013. }
  7014. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  7015. if parseStartDateErr != nil {
  7016. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  7017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7018. return
  7019. }
  7020. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  7021. if parseErr != nil {
  7022. this.ErrorLog("时间解析失败:%v", parseErr)
  7023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7024. return
  7025. }
  7026. adminUserInfo := this.GetMobileAdminUserInfo()
  7027. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  7028. if getPatientErr != nil {
  7029. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  7030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7031. return
  7032. } else if patient == nil {
  7033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7034. return
  7035. }
  7036. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  7037. if getNurseErr != nil {
  7038. this.ErrorLog("获取护士失败:%v", getNurseErr)
  7039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7040. return
  7041. } else if nurse == nil {
  7042. this.ErrorLog("护士不存在")
  7043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7044. return
  7045. }
  7046. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  7047. if getDeviceNumberErr != nil {
  7048. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  7049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7050. return
  7051. } else if deviceNumber == nil {
  7052. this.ErrorLog("床位号不存在")
  7053. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7054. return
  7055. }
  7056. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  7057. if getRecordErr != nil {
  7058. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  7059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7060. return
  7061. } else if dialysisRecord != nil {
  7062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  7063. return
  7064. }
  7065. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  7066. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  7067. timeLayout := "2006-01-02 15:04:05"
  7068. loc, _ := time.LoadLocation("Local")
  7069. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  7070. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  7071. schedulestartTime := theStartTime.Unix()
  7072. scheduleendTime := theEndTime.Unix()
  7073. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  7074. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  7075. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  7076. //查询该床位是否有人用了
  7077. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  7078. if err == nil {
  7079. if schedule.ID == 0 {
  7080. this.ServeSuccessJSON(map[string]interface{}{
  7081. "status": 0,
  7082. "msg": "请求失败",
  7083. })
  7084. } else {
  7085. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  7086. if order.ID > 0 { //该机位被其他人占用了
  7087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  7088. return
  7089. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  7090. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  7091. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  7092. this.ServeSuccessJSON(map[string]interface{}{
  7093. "status": 1,
  7094. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  7095. })
  7096. return
  7097. } else {
  7098. this.ServeSuccessJSON(map[string]interface{}{
  7099. "status": 0,
  7100. "msg": "",
  7101. })
  7102. }
  7103. }
  7104. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  7105. this.ServeSuccessJSON(map[string]interface{}{
  7106. "status": 2,
  7107. "msg": "当前机位已有患者在使用,请重新选择!",
  7108. })
  7109. }
  7110. }
  7111. } else {
  7112. this.ServeSuccessJSON(map[string]interface{}{
  7113. "status": 0,
  7114. "msg": "",
  7115. })
  7116. }
  7117. }