dialysis_api_controller.go 374KB

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