dialysis_api_controller.go 368KB

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