dialysis_api_controller.go 376KB

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