dialysis_api_controller.go 381KB

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