dialysis_api_controller.go 376KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "errors"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "math"
  13. "net/http"
  14. "net/url"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. //redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  501. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  502. returnData := map[string]interface{}{
  503. "patient": patient,
  504. "schedual": schedual,
  505. "prescription": dialysisPrescribe,
  506. "solution": dialysisSolution,
  507. "last_prescription": lastDialysisPrescribe,
  508. "receiver_treatment_access": receiverTreatmentAccess,
  509. "predialysis_evaluation": predialysisEvaluation,
  510. "doctor_advices": doctorAdvices,
  511. "double_check": doubleCheck,
  512. "assessment_after_dislysis": assessmentAfterDislysis,
  513. "treatment_summary": treatmentSummary,
  514. "monitor_records": monitorRecords,
  515. "dialysis_order": dialysisOrder,
  516. "operators": operators,
  517. "last_predialysis_evaluation": lastPredialysisEvaluation,
  518. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  519. "last_monitor_record": lastMonitorRecord,
  520. "config": gobalConfig,
  521. "dry_weight": lastDryWeightDislysis,
  522. "system_prescription": systemDialysisPrescribe,
  523. "his_advices": his_advices,
  524. "is_open_config": is_open_config,
  525. "stockType": stockType,
  526. "prepare": prepare,
  527. "lastAssessment": lastAssessment,
  528. "prescribeOne": prescribeOne,
  529. "is_project_open_config": is_project_open_config,
  530. "project": projects,
  531. "team_projects": team_projects,
  532. "is_advice_open": is_advice_open,
  533. "prescription_open": prescriptionConfig.IsOpen,
  534. "lastOrder": lastOrder,
  535. "remind_lists": remind_lists,
  536. "lastDialysisPrescription": lastDialysisPrescription,
  537. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  538. "dryWeightList": dryWeightList,
  539. }
  540. this.ServeSuccessJSON(returnData)
  541. }
  542. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  543. adminInfo := c.GetMobileAdminUserInfo()
  544. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  545. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  546. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  547. returnData := map[string]interface{}{
  548. "admin_users": adminUsers,
  549. "devices": devices,
  550. "device_numbers": device_numbers,
  551. }
  552. c.ServeSuccessJSON(returnData)
  553. }
  554. func (c *DialysisAPIController) PostAtreatmentInfo() {
  555. id, _ := c.GetInt64("patient", 0)
  556. recordDateStr := c.GetString("record_date")
  557. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  558. summaryContent := c.GetString("summaryContent")
  559. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  560. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  561. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  562. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  563. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  564. nursingRecord := c.GetString("nursing_record")
  565. fmt.Println("护理记录", nursingRecord)
  566. specialRecord := c.GetString("special_record")
  567. fmt.Println("特殊记录", specialRecord)
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  570. checkStaffId = adminUserInfo.AdminUser.Id
  571. deboardNurseId = adminUserInfo.AdminUser.Id
  572. treatDoctor = adminUserInfo.AdminUser.Id
  573. if id <= 0 {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  578. if patient.ID == 0 {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  580. return
  581. }
  582. if len(recordDateStr) == 0 {
  583. recordDateStr = time.Now().Format("2006-01-02")
  584. }
  585. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  586. if parseDateErr != nil {
  587. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. summary := models.TreatmentSummary{
  592. UserOrgId: adminUserInfo.Org.Id,
  593. PatientId: id,
  594. AssessmentDate: recordDate.Unix(),
  595. Mission: propagandaAndEducationContent,
  596. DialysisSummary: summaryContent,
  597. SjNurse: changeMedicalNurseId,
  598. ZlNurse: treatNurseId,
  599. HdNurse: checkStaffId,
  600. XjNurse: deboardNurseId,
  601. ZlDoctor: treatDoctor,
  602. CreatedTime: time.Now().Unix(),
  603. Status: 1,
  604. NursingRecord: nursingRecord,
  605. SpecialRecord: specialRecord,
  606. }
  607. // 查询信息规挡的设置天数
  608. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  609. if infor.ID > 0 && infor.WeekDay > 0 {
  610. var cha_time int64
  611. timeNowStr := time.Now().Format("2006-01-02")
  612. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  613. //今日的日期减去设置的日期
  614. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  615. if cha_time >= recordDate.Unix() {
  616. //查询审核是否允许
  617. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  618. //申请状态不允许的情况 拒绝修改
  619. if infor.ApplicationStatus != 1 {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  621. return
  622. }
  623. }
  624. }
  625. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  626. if treatmentSummary.ID == 0 { //新增
  627. summary.Creater = adminUserInfo.AdminUser.Id
  628. service.AddSigleSummaryRecord(&summary)
  629. finish := models.XtDialysisFinish{
  630. IsFinish: 1,
  631. UserOrgId: adminUserInfo.Org.Id,
  632. Status: 1,
  633. Ctime: time.Now().Unix(),
  634. Mtime: 0,
  635. Module: 10,
  636. RecordDate: recordDate.Unix(),
  637. Sourse: 1,
  638. PatientId: id,
  639. }
  640. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  641. if dialysisFinish.ID == 0 {
  642. service.CreateDialysisFinish(finish)
  643. }
  644. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  645. redis := service.RedisClient()
  646. //清空key 值
  647. redis.Set(key, "", time.Second)
  648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  649. redis.Set(keyOne, "", time.Second)
  650. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  651. redis.Set(keyThree, "", time.Second)
  652. defer redis.Close()
  653. c.ServeSuccessJSON(map[string]interface{}{
  654. "summary": summary,
  655. })
  656. } else { //修改
  657. summary.Creater = treatmentSummary.Creater
  658. summary.CreatedTime = treatmentSummary.CreatedTime
  659. summary.Modifier = adminUserInfo.AdminUser.Id
  660. summary.ID = treatmentSummary.ID
  661. service.UpdateSummeRecord(&summary)
  662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  663. redis := service.RedisClient()
  664. //清空key 值
  665. redis.Set(key, "", time.Second)
  666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  667. redis.Set(keyOne, "", time.Second)
  668. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  669. redis.Set(keyThree, "", time.Second)
  670. defer redis.Close()
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "summary": summary,
  673. })
  674. }
  675. }
  676. func (c *DialysisAPIController) PostDoubleCheck() {
  677. id, _ := c.GetInt64("patient", 0)
  678. recordDateStr := c.GetString("record_date")
  679. checkTimeStr := c.GetString("check_time")
  680. firstCheckTimeStr := c.GetString("first_check_time")
  681. creater, _ := c.GetInt64("creater", 0)
  682. modifier, _ := c.GetInt64("modifier", 0)
  683. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  684. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  685. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  686. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  687. dialysis_item_desc := c.GetString("dialysis_item_desc")
  688. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  689. vascular_access_desc := c.GetString("vascular_access_desc")
  690. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  691. collator, _ := c.GetInt64("collator", 0)
  692. employee_number := c.GetString("employee_number")
  693. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  694. needle_batch_number := c.GetString("needle_batch_number")
  695. if id <= 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. adminUserInfo := c.GetMobileAdminUserInfo()
  700. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  701. if patient.ID == 0 {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  703. return
  704. }
  705. if len(recordDateStr) == 0 {
  706. recordDateStr = time.Now().Format("2006-01-02")
  707. }
  708. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  709. if parseDateErr != nil {
  710. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. var checkDate int64
  715. if len(checkTimeStr) == 0 {
  716. checkDate = 0
  717. } else {
  718. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  719. checkDate = checkDateUnix.Unix()
  720. }
  721. var firstCheckDate int64
  722. if len(firstCheckTimeStr) == 0 {
  723. firstCheckDate = 0
  724. } else {
  725. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  726. firstCheckDate = firstCheckDateUnix.Unix()
  727. }
  728. //if adminUserInfo.Org.Id == 10340 {
  729. //
  730. // list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  731. // _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  732. // if check.ID == 0 {
  733. // if employee_number != list.JobNumber {
  734. // c.ServeSuccessJSON(map[string]interface{}{
  735. // "doubleCheck": check,
  736. // "msg": "2",
  737. // })
  738. // return
  739. // }
  740. // }
  741. // if check.ID > 0 {
  742. // if employee_number != list.JobNumber {
  743. // c.ServeSuccessJSON(map[string]interface{}{
  744. // "doubleCheck": check,
  745. // "msg": "2",
  746. // })
  747. // return
  748. // }
  749. // }
  750. //
  751. //}
  752. doubleCheck := models.DoubleCheck{
  753. UserOrgId: adminUserInfo.Org.Id,
  754. PatientId: id,
  755. DialysisItemCheck: dialysis_item_check,
  756. DialysisParameterCheck: dialysis_parameter_check,
  757. VascularAccessVerification: vascular_access_verification,
  758. PipelineConnectionCheck: pipeline_connection_check,
  759. DialysisItemDesc: dialysis_item_desc,
  760. DialysisParameterDesc: dialysis_parameter_desc,
  761. VascularAccessDesc: vascular_access_desc,
  762. PipelineConnectionDesc: pipeline_connection_desc,
  763. Collator: collator,
  764. Status: 1,
  765. CreatedTime: time.Now().Unix(),
  766. CheckDate: recordDate.Unix(),
  767. UpdatedTime: time.Now().Unix(),
  768. EmployeeNumber: employee_number,
  769. DialyzerBatchNumber: dialyzer_batch_number,
  770. NeedleBatchNumber: needle_batch_number,
  771. }
  772. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  773. if check.ID == 0 { //新增
  774. doubleCheck.FirstCheckTime = firstCheckDate
  775. doubleCheck.CheckTime = checkDate
  776. doubleCheck.Creater = creater
  777. doubleCheck.Modifier = modifier
  778. if adminUserInfo.Org.Id == 10340 {
  779. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  780. doubleCheck.Creater = order.StartNurse
  781. }
  782. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  783. //查询未核对的医嘱
  784. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  785. for _, advice := range doctorList {
  786. if advice.ExecutionStaff == modifier {
  787. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  788. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  789. return
  790. }
  791. }
  792. }
  793. // 查询信息规挡的设置天数
  794. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  795. if infor.ID > 0 && infor.WeekDay > 0 {
  796. var cha_time int64
  797. timeNowStr := time.Now().Format("2006-01-02")
  798. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  799. //今日的日期减去设置的日期
  800. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  801. if cha_time >= recordDate.Unix() {
  802. //查询审核是否允许
  803. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  804. //申请状态不允许的情况 拒绝修改
  805. if infor.ApplicationStatus != 1 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  807. return
  808. }
  809. }
  810. }
  811. err := service.AddSigleDoubleCheck(&doubleCheck)
  812. finish := models.XtDialysisFinish{
  813. IsFinish: 1,
  814. UserOrgId: adminUserInfo.Org.Id,
  815. Status: 1,
  816. Ctime: time.Now().Unix(),
  817. Mtime: 0,
  818. Module: 5,
  819. RecordDate: recordDate.Unix(),
  820. Sourse: 1,
  821. PatientId: id,
  822. }
  823. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  824. if dialysisFinish.ID == 0 {
  825. service.CreateDialysisFinish(finish)
  826. }
  827. //针对长沙南雅
  828. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  829. //查询未核对的医嘱
  830. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  831. if len(doctorList) > 0 && modifier > 0 {
  832. for _, advice := range doctorList {
  833. service.UpdateDoctorAdviceList(advice.ID, modifier)
  834. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  835. redis := service.RedisClient()
  836. //清空key 值
  837. redis.Set(key, "", time.Second)
  838. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  839. redis.Set(keyTwo, "", time.Second)
  840. theTime := time.Now()
  841. recordDate := theTime.Format("2006-01-02")
  842. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  843. redis.Set(keyFour, "", time.Second)
  844. defer redis.Close()
  845. }
  846. }
  847. }
  848. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  849. redis := service.RedisClient()
  850. //清空key 值
  851. redis.Set(key, "", time.Second)
  852. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  853. redis.Set(keyOne, "", time.Second)
  854. defer redis.Close()
  855. if err == nil {
  856. c.ServeSuccessJSON(map[string]interface{}{
  857. "doubleCheck": &doubleCheck,
  858. })
  859. }
  860. } else { //修改
  861. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  862. if infor.ID > 0 {
  863. var cha_time int64
  864. timeNowStr := time.Now().Format("2006-01-02")
  865. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  866. //今日的日期减去设置的日期
  867. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  868. if cha_time >= recordDate.Unix() {
  869. //查询审核是否允许
  870. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  871. //申请状态不允许的情况 拒绝修改
  872. if infor.ApplicationStatus != 1 {
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  874. return
  875. }
  876. }
  877. }
  878. doubleCheck.FirstCheckTime = firstCheckDate
  879. doubleCheck.CheckTime = checkDate
  880. doubleCheck.Creater = creater
  881. doubleCheck.Modifier = modifier
  882. doubleCheck.CreatedTime = check.CreatedTime
  883. doubleCheck.ID = check.ID
  884. doubleCheck.EmployeeNumber = employee_number
  885. doubleCheck.NeedleBatchNumber = needle_batch_number
  886. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  887. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  888. //查询未核对的医嘱
  889. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  890. for _, advice := range doctorList {
  891. if advice.ExecutionStaff == modifier {
  892. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  893. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  894. return
  895. }
  896. }
  897. }
  898. err := service.UpdateDoubleCheck(&doubleCheck)
  899. //针对长沙南雅
  900. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  901. //查询未核对的医嘱
  902. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  903. if len(doctorList) > 0 && modifier > 0 {
  904. for _, advice := range doctorList {
  905. service.UpdateDoctorAdviceList(advice.ID, modifier)
  906. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  907. redis := service.RedisClient()
  908. //清空key 值
  909. redis.Set(key, "", time.Second)
  910. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  911. redis.Set(keyTwo, "", time.Second)
  912. theTime := time.Now()
  913. recordDate := theTime.Format("2006-01-02")
  914. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  915. redis.Set(keyFour, "", time.Second)
  916. defer redis.Close()
  917. }
  918. }
  919. }
  920. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  921. redis := service.RedisClient()
  922. //清空key 值
  923. redis.Set(key, "", time.Second)
  924. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  925. redis.Set(keyOne, "", time.Second)
  926. defer redis.Close()
  927. if err == nil {
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "doubleCheck": &doubleCheck,
  930. "msg": "1",
  931. })
  932. }
  933. }
  934. }
  935. func (c *DialysisAPIController) PostAcceptsAssessment() {
  936. id, _ := c.GetInt64("patient", 0)
  937. recordDateStr := c.GetString("record_date")
  938. way, _ := c.GetInt64("way", 0)
  939. consciousness, _ := c.GetInt64("consciousness", 0)
  940. appetite, _ := c.GetInt64("appetite", 0)
  941. condition, _ := c.GetInt64("condition", 0)
  942. posture, _ := c.GetInt64("posture")
  943. sick_condition, _ := c.GetInt64("sick_condition", 0)
  944. danger_level, _ := c.GetInt64("danger_level", 0)
  945. intake, _ := c.GetInt64("intake", 0)
  946. nutrition, _ := c.GetInt64("nutrition", 0)
  947. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  948. psychological_assessment_other := c.GetString("psychological_assessment_other")
  949. score := c.GetString("score")
  950. sick_condition_other := c.GetString("sick_condition_other")
  951. //precaution, _ := c.GetInt64("precaution", 0)
  952. precaution := c.GetString("precaution")
  953. precaution_other := c.GetString("precaution_other")
  954. psychological_other := c.GetString("psychological_other")
  955. admission_number := c.GetString("admission_number")
  956. tumble, _ := c.GetInt64("tumble")
  957. diacrisis := c.GetString("diacrisis")
  958. his_department := c.GetString("his_department")
  959. his_bed := c.GetString("his_bed")
  960. if id <= 0 {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  962. return
  963. }
  964. adminUserInfo := c.GetMobileAdminUserInfo()
  965. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  966. if patient.ID == 0 {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  968. return
  969. }
  970. //now := time.Now()
  971. //year, month, day := now.Date()
  972. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  973. //todayTimeStamp := today_time.Unix()
  974. if len(recordDateStr) == 0 {
  975. recordDateStr = time.Now().Format("2006-01-02")
  976. }
  977. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  978. if parseDateErr != nil {
  979. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. // 查询信息规挡的设置天数
  984. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  985. if infor.ID > 0 && infor.WeekDay > 0 {
  986. var cha_time int64
  987. timeNowStr := time.Now().Format("2006-01-02")
  988. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  989. //今日的日期减去设置的日期
  990. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  991. if cha_time >= recordDate.Unix() {
  992. //查询审核是否允许
  993. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  994. //申请状态不允许的情况 拒绝修改
  995. if infor.ApplicationStatus != 1 {
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  997. return
  998. }
  999. }
  1000. }
  1001. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1002. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1003. UserOrgId: adminUserInfo.Org.Id,
  1004. PatientId: id,
  1005. RecordDate: recordDate.Unix(),
  1006. Way: way,
  1007. Consciousness: consciousness,
  1008. Appetite: appetite,
  1009. Condition: condition,
  1010. SickCondition: sick_condition,
  1011. DangerLevel: danger_level,
  1012. Intake: intake,
  1013. Nutrition: nutrition,
  1014. PsychologicalAssessment: psychological_assessment,
  1015. PsychologicalAssessmentOther: psychological_assessment_other,
  1016. SickConditionOther: sick_condition_other,
  1017. Posture: posture,
  1018. CreatedTime: time.Now().Unix(),
  1019. UpdateTime: time.Now().Unix(),
  1020. Status: 1,
  1021. Score: score,
  1022. Precaution: precaution,
  1023. PrecautionOther: precaution_other,
  1024. PsychologicalOther: psychological_other,
  1025. AdmissionNumber: admission_number,
  1026. Tumble: tumble,
  1027. Diacrisis: diacrisis,
  1028. HisBed: his_bed,
  1029. HisDepartment: his_department,
  1030. }
  1031. if receiveTreatment.ID == 0 { //新增
  1032. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1033. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1034. finish := models.XtDialysisFinish{
  1035. IsFinish: 1,
  1036. UserOrgId: adminUserInfo.Org.Id,
  1037. Status: 1,
  1038. Ctime: time.Now().Unix(),
  1039. Mtime: 0,
  1040. Module: 2,
  1041. RecordDate: recordDate.Unix(),
  1042. Sourse: 1,
  1043. PatientId: id,
  1044. }
  1045. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1046. if dialysisFinish.ID == 0 {
  1047. service.CreateDialysisFinish(finish)
  1048. }
  1049. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1050. redis := service.RedisClient()
  1051. defer redis.Close()
  1052. //清空key 值
  1053. redis.Set(key, "", time.Second)
  1054. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1055. redis.Set(keyOne, "", time.Second)
  1056. if err == nil {
  1057. c.ServeSuccessJSON(map[string]interface{}{
  1058. "receiveTreatmentAsses": receiveTreatmentAsses,
  1059. })
  1060. }
  1061. } else { //修改
  1062. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1063. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1064. // if getPermissionErr != nil {
  1065. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1066. // return
  1067. // } else if headNursePermission == nil {
  1068. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1069. // return
  1070. // }
  1071. //}
  1072. // 查询信息规挡的设置天数
  1073. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1074. if infor.ID > 0 && infor.WeekDay > 0 {
  1075. var cha_time int64
  1076. timeNowStr := time.Now().Format("2006-01-02")
  1077. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1078. //今日的日期减去设置的日期
  1079. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1080. if cha_time >= recordDate.Unix() {
  1081. //查询审核是否允许
  1082. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1083. //申请状态不允许的情况 拒绝修改
  1084. if infor.ApplicationStatus != 1 {
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1086. return
  1087. }
  1088. }
  1089. }
  1090. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1091. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1092. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1093. receiveTreatmentAsses.ID = receiveTreatment.ID
  1094. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1095. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1096. redis := service.RedisClient()
  1097. defer redis.Close()
  1098. //清空key 值
  1099. redis.Set(key, "", time.Second)
  1100. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1101. redis.Set(keyOne, "", time.Second)
  1102. if err == nil {
  1103. c.ServeSuccessJSON(map[string]interface{}{
  1104. "receiveTreatmentAsses": receiveTreatmentAsses,
  1105. })
  1106. }
  1107. }
  1108. }
  1109. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1110. id, _ := c.GetInt64("patient", 0)
  1111. recordDateStr := c.GetString("record_date")
  1112. weightAfter, _ := c.GetFloat("weight_after", 0)
  1113. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1114. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1115. fmt.Println("weight_loss", weightReduce)
  1116. temperature, _ := c.GetFloat("temperature", 0)
  1117. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1118. breathing_rate := c.GetString("breathing_rate")
  1119. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1120. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1121. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1122. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1123. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1124. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1125. cruor := c.GetString("cruor")
  1126. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1127. internalFistula := c.GetString("internal_fistula")
  1128. catheter := c.GetString("catheter")
  1129. complications := c.GetString("complication")
  1130. remark := c.GetString("remark")
  1131. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1132. dialysis_intakes := c.GetString("dialysis_intakes")
  1133. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1134. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1135. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1136. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1137. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1138. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1139. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1140. patientGose, _ := c.GetInt64("patient_gose", 0)
  1141. inpatientDepartment := c.GetString("inpatient_department")
  1142. observationContent := c.GetString("observation_content")
  1143. observationContentOther := c.GetString("observation_content_other")
  1144. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1145. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1146. in_advance_reason := c.GetString("in_advance_reason")
  1147. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1148. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1149. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1150. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1151. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1152. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1153. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1154. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1155. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1156. is_eat, _ := c.GetInt64("is_eat", 0)
  1157. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1158. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1159. channels, _ := c.GetInt64("channel", 0)
  1160. return_blood, _ := c.GetInt64("return_blood", 0)
  1161. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1162. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1163. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1164. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1165. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1166. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1167. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1168. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1169. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1170. setting_pressure := c.GetString("setting_pressure")
  1171. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1172. diastolic_pressure := c.GetString("diastolic_pressure")
  1173. other_complication := c.GetString("other_complication")
  1174. ktv := c.GetString("ktv")
  1175. urr := c.GetString("urr")
  1176. hypertenison, _ := c.GetInt64("hypertenison")
  1177. hypopiesia, _ := c.GetInt64("hypopiesia")
  1178. leave_office_method, _ := c.GetInt64("leave_office_method")
  1179. lapse, _ := c.GetInt64("lapse")
  1180. consciousness, _ := c.GetInt64("consciousness")
  1181. fallrisk, _ := c.GetInt64("fallrisk")
  1182. machine_run := c.GetString("machine_run")
  1183. after_urea := c.GetString("after_urea")
  1184. pip_coagulation := c.GetString("pip_coagulation")
  1185. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1186. transfusion_volume := c.GetString("transfusion_volume")
  1187. last_after_weight := c.GetString("last_after_weight")
  1188. if id <= 0 {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1190. return
  1191. }
  1192. adminUserInfo := c.GetMobileAdminUserInfo()
  1193. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1194. if patient.ID == 0 {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1196. return
  1197. }
  1198. if len(recordDateStr) == 0 {
  1199. recordDateStr = time.Now().Format("2006-01-02")
  1200. }
  1201. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1202. fmt.Println("parseDateErr", parseDateErr)
  1203. if parseDateErr != nil {
  1204. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. //now := time.Now()
  1209. //year, month, day := now.Date()
  1210. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1211. //todayTimeStamp := today_time.Unix()
  1212. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1213. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1214. UserOrgId: adminUserInfo.Org.Id,
  1215. PatientId: id,
  1216. AssessmentDate: recordDate.Unix(),
  1217. Temperature: temperature,
  1218. PulseFrequency: pulse_frequency,
  1219. BreathingRate: breathing_rate,
  1220. SystolicBloodPressure: systolic_blood_pressure,
  1221. DiastolicBloodPressure: diastolic_blood_pressure,
  1222. ActualUltrafiltration: actual_ultrafiltration,
  1223. ActualDisplacement: actual_displacement,
  1224. ActualTreatmentHour: actualtreatHour,
  1225. ActualTreatmentMinute: actualtreatmin,
  1226. WeightAfter: weightAfter,
  1227. AdditionalWeight: additionalWeight,
  1228. WeightLoss: weightReduce,
  1229. Cruor: cruor,
  1230. SymptomAfterDialysis: symptomsAfterDialysi,
  1231. InternalFistula: internalFistula,
  1232. Catheter: catheter,
  1233. Complication: complications,
  1234. DialysisIntakes: dialysateVolume,
  1235. CreatedTime: time.Now().Unix(),
  1236. UpdatedTime: time.Now().Unix(),
  1237. Status: 1,
  1238. Remark: remark,
  1239. BloodAccessPartId: blood_access_part_id,
  1240. BloodAccessPartOperaId: blood_access_part_opera_id,
  1241. DialysisIntakesUnit: dialysis_intakes_unit,
  1242. PuncturePointOozingBlood: puncturePointOozingBlood,
  1243. PuncturePointHaematoma: puncturePointHaematoma,
  1244. InternalFistulaTremorAc: internalFistulaTremorAc,
  1245. PatientGose: patientGose,
  1246. InpatientDepartment: inpatientDepartment,
  1247. ObservationContent: observationContent,
  1248. ObservationContentOther: observationContentOther,
  1249. DialysisProcess: dialysis_process,
  1250. InAdvanceMinute: in_advance_minute,
  1251. InAdvanceReason: in_advance_reason,
  1252. HemostasisMinute: hemostasis_minute,
  1253. HemostasisOpera: hemostasis_opera,
  1254. TremorNoise: tremor_noise,
  1255. DisequilibriumSyndrome: disequilibrium_syndrome,
  1256. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1257. ArterialTube: arterial_tube,
  1258. IntravenousTube: intravenous_tube,
  1259. Dialyzer: dialyzer,
  1260. InAdvanceReasonOther: in_advance_reason_other,
  1261. IsEat: is_eat,
  1262. CvcA: cvc_a,
  1263. CvcV: cvc_v,
  1264. Channel: channels,
  1265. ReturnBlood: return_blood,
  1266. RehydrationVolume: rehydration_volume,
  1267. DialysisDuring: dialysis_during,
  1268. StrokeVolume: stroke_volume,
  1269. BloodFlow: blood_flow,
  1270. SealingFluidDispose: sealing_fluid_dispose,
  1271. SealingFluidSpecial: sealing_fluid_special,
  1272. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1273. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1274. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1275. SettingPressure: setting_pressure,
  1276. DiastolicPressure: diastolic_pressure,
  1277. OtherComplication: other_complication,
  1278. Ktv: ktv,
  1279. Urr: urr,
  1280. Hypopiesia: hypopiesia,
  1281. Hypertenison: hypertenison,
  1282. Lapse: lapse,
  1283. LeaveOfficeMethod: leave_office_method,
  1284. Consciousness: consciousness,
  1285. Fallrisk: fallrisk,
  1286. MachineRun: machine_run,
  1287. AfterUrea: after_urea,
  1288. PipCoagulation: pip_coagulation,
  1289. AccumulatedBloodVolume: accumulated_blood_volume,
  1290. TransfusionVolume: transfusion_volume,
  1291. LastAfterWeight: last_after_weight,
  1292. }
  1293. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1294. // 查询信息规挡的设置天数
  1295. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1296. if infor.ID > 0 && infor.WeekDay > 0 {
  1297. var cha_time int64
  1298. timeNowStr := time.Now().Format("2006-01-02")
  1299. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1300. //今日的日期减去设置的日期
  1301. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1302. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1303. if cha_time >= recordDate.Unix() {
  1304. //查询审核是否允许
  1305. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1306. //申请状态不允许的情况 拒绝修改
  1307. if infor.ApplicationStatus != 1 {
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1309. return
  1310. }
  1311. }
  1312. }
  1313. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1314. if assessmentAfter.ID == 0 { //新增
  1315. if appRole.UserType == 2 || appRole.UserType == 1 {
  1316. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1317. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1318. } else {
  1319. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1320. }
  1321. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1322. //记录日志
  1323. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1324. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1325. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1326. PatientId: assessmentAfterDislysis.PatientId,
  1327. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1328. Status: 1,
  1329. ErrLog: string(byterequest),
  1330. AdminUserId: adminUserInfo.AdminUser.Id,
  1331. Ctime: 0,
  1332. Mtime: 0,
  1333. Source: "手机端保存透后评估",
  1334. }
  1335. service.CreateAfterDialysisLog(afterDialysisLog)
  1336. finish := models.XtDialysisFinish{
  1337. IsFinish: 1,
  1338. UserOrgId: adminUserInfo.Org.Id,
  1339. Status: 1,
  1340. Ctime: time.Now().Unix(),
  1341. Mtime: 0,
  1342. Module: 9,
  1343. RecordDate: recordDate.Unix(),
  1344. Sourse: 1,
  1345. PatientId: id,
  1346. }
  1347. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1348. if dialysisFinish.ID == 0 {
  1349. service.CreateDialysisFinish(finish)
  1350. }
  1351. redis := service.RedisClient()
  1352. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1353. redis.Set(keyTwo, "", time.Second)
  1354. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1355. //清空key 值
  1356. redis.Set(key, "", time.Second)
  1357. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1358. redis.Set(keyOne, "", time.Second)
  1359. defer redis.Close()
  1360. if err == nil {
  1361. c.ServeSuccessJSON(map[string]interface{}{
  1362. "assessmentAfterDislysis": assessmentAfterDislysis,
  1363. })
  1364. }
  1365. return
  1366. } else { //修改
  1367. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1368. if infor.ID > 0 && infor.WeekDay > 0 {
  1369. var cha_time int64
  1370. timeNowStr := time.Now().Format("2006-01-02")
  1371. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1372. //今日的日期减去设置的日期
  1373. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1374. if cha_time >= recordDate.Unix() {
  1375. //查询审核是否允许
  1376. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1377. //申请状态不允许的情况 拒绝修改
  1378. if infor.ApplicationStatus != 1 {
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1380. return
  1381. }
  1382. }
  1383. }
  1384. if appRole.UserType == 2 || appRole.UserType == 1 {
  1385. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1386. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1387. } else {
  1388. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1389. if assessmentAfterDislysis.Creater == 0 {
  1390. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1391. }
  1392. }
  1393. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1394. assessmentAfterDislysis.ID = assessmentAfter.ID
  1395. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1396. //记录日志
  1397. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1398. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1399. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1400. PatientId: assessmentAfterDislysis.PatientId,
  1401. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1402. Status: 1,
  1403. ErrLog: string(byterequest),
  1404. AdminUserId: adminUserInfo.AdminUser.Id,
  1405. Ctime: time.Now().Unix(),
  1406. Mtime: 0,
  1407. Source: "手机端修改保存透后评估",
  1408. }
  1409. service.CreateAfterDialysisLog(afterDialysisLog)
  1410. redis := service.RedisClient()
  1411. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1412. redis.Set(keyTwo, "", time.Second)
  1413. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1414. //清空key 值
  1415. redis.Set(key, "", time.Second)
  1416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1417. redis.Set(keyOne, "", time.Second)
  1418. if err == nil {
  1419. c.ServeSuccessJSON(map[string]interface{}{
  1420. "assessmentAfterDislysis": assessmentAfterDislysis,
  1421. })
  1422. return
  1423. }
  1424. }
  1425. return
  1426. }
  1427. func (c *DialysisAPIController) PostDialysisPrescription() {
  1428. id, _ := c.GetInt64("patient", 0)
  1429. recordDateStr := c.GetString("record_date")
  1430. if id <= 0 {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. adminUserInfo := c.GetMobileAdminUserInfo()
  1435. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1436. if patient.ID == 0 {
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1438. return
  1439. }
  1440. if len(recordDateStr) == 0 {
  1441. recordDateStr = time.Now().Format("2006-01-02")
  1442. }
  1443. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1444. if parseDateErr != nil {
  1445. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1447. return
  1448. }
  1449. mode_id, _ := c.GetInt64("mode_id", 0)
  1450. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1451. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1452. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1453. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1454. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1455. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1456. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1457. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1458. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1459. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1460. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1461. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1462. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1463. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1464. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1465. kalium, _ := c.GetFloat("kalium", 0)
  1466. sodium, _ := c.GetFloat("sodium", 0)
  1467. calcium, _ := c.GetFloat("calcium", 0)
  1468. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1469. glucose, _ := c.GetFloat("glucose", 0)
  1470. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1471. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1472. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1473. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1474. conductivity, _ := c.GetFloat("conductivity", 0)
  1475. remark := c.GetString("remark")
  1476. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1477. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1478. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1479. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1480. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1481. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1482. special_medicine_other := c.GetString("special_medicine_other")
  1483. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1484. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1485. blood_access, _ := c.GetInt64("blood_access", 0)
  1486. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1487. body_fluid_other := c.GetString("body_fluid_other")
  1488. niprocart, _ := c.GetInt64("niprocart", 0)
  1489. jms, _ := c.GetInt64("jms", 0)
  1490. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1491. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1492. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1493. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1494. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1495. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1496. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1497. injector, _ := c.GetInt64("injector", 0)
  1498. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1499. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1500. safe_package, _ := c.GetInt64("package", 0)
  1501. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1502. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1503. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1504. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1505. blood := c.GetString("blood")
  1506. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1507. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1508. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1509. displace_speed := c.GetString("displace_speed")
  1510. illness, _ := c.GetInt64("illness")
  1511. amylaceum := c.GetString("amylaceum")
  1512. single_time := c.GetString("single_time")
  1513. single_water := c.GetString("single_water")
  1514. replacement_flow := c.GetString("replacement_flow")
  1515. plasma_separator := c.GetString("plasma_separator")
  1516. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1517. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1518. oxygen_flow := c.GetString("oxygen_flow")
  1519. oxygen_time := c.GetString("oxygen_time")
  1520. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1521. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1522. puncture_needle := c.GetString("puncture_needle")
  1523. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1524. epo := c.GetString("epo")
  1525. epo_count, _ := c.GetFloat("epo_count", 0)
  1526. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1527. admin_user_id, _ := c.GetInt64("admin_user_id")
  1528. is_water := c.GetString("is_water")
  1529. var is_war int64
  1530. if is_water == "是" {
  1531. is_war = 1
  1532. }
  1533. if is_water == "否" {
  1534. is_war = 2
  1535. }
  1536. if is_water == "请选择" {
  1537. is_war = 0
  1538. }
  1539. drhy_water := c.GetString("drhy_water")
  1540. dry_water_hour := c.GetString("dry_water_hour")
  1541. water_machine := c.GetString("water_machine")
  1542. add_amount, _ := c.GetFloat("add_amount")
  1543. reduce_amount, _ := c.GetFloat("reduce_amount")
  1544. dialysis_remark := c.GetString("dialysis_remark")
  1545. prescribing_number, _ := c.GetFloat("prescribing_number")
  1546. prescription_sodium := c.GetString("prescription_sodium")
  1547. start_sodium := c.GetString("start_sodium")
  1548. sodium_curve := c.GetString("sodium_curve")
  1549. treatment_remark := c.GetString("treatment_remark")
  1550. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1551. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1552. prescription_water, _ := c.GetFloat("prescription_water")
  1553. dialysis_strainer := c.GetString("dialysis_strainer")
  1554. chaptalization := c.GetString("chaptalization")
  1555. washing_time := c.GetString("washing_time")
  1556. warsh_count := c.GetString("warsh_count")
  1557. blood_access_part_id := c.GetString("blood_access_part_id")
  1558. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1559. dialyzate := c.GetString("dialyzate")
  1560. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1561. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1562. //
  1563. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1564. // if appRole.UserType == 3 {
  1565. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1566. // if getPermissionErr != nil {
  1567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1568. // return
  1569. // } else if headNursePermission == nil {
  1570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1571. // return
  1572. // }
  1573. // }
  1574. //}
  1575. // 查询信息规挡的设置天数
  1576. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1577. if infor.ID > 0 && infor.WeekDay > 0 {
  1578. var cha_time int64
  1579. timeNowStr := time.Now().Format("2006-01-02")
  1580. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1581. //今日的日期减去设置的日期
  1582. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1583. if cha_time >= recordDate.Unix() {
  1584. //查询审核是否允许
  1585. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1586. //申请状态不允许的情况 拒绝修改
  1587. if infor.ApplicationStatus != 1 {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1589. return
  1590. }
  1591. }
  1592. }
  1593. if mode_id > 0 {
  1594. var str string
  1595. //查找该机构用的是什么透析器
  1596. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1597. if filedConfig.ID > 0 {
  1598. str = dialyzerPerfusionApparatus
  1599. } else {
  1600. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1601. }
  1602. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1603. }
  1604. //TODO 需要根据角色去判断
  1605. prescription := models.DialysisPrescription{
  1606. UserOrgId: adminUserInfo.Org.Id,
  1607. PatientId: id,
  1608. RecordDate: recordDate.Unix(),
  1609. ModeId: mode_id,
  1610. DialysisDuration: dialysis_duration,
  1611. Dialyzer: dialyzer,
  1612. PerfusionApparatus: perfusion_apparatus,
  1613. BloodFlowVolume: blood_flow_volume,
  1614. DewaterAmount: dewater_amount,
  1615. DisplaceLiqui: displace_liqui,
  1616. ReplacementWay: replacement_way,
  1617. Anticoagulant: anticoagulant,
  1618. AnticoagulantShouji: anticoagulant_shouji,
  1619. AnticoagulantWeichi: anticoagulant_weichi,
  1620. AnticoagulantZongliang: anticoagulant_zongliang,
  1621. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1622. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1623. Kalium: kalium,
  1624. Sodium: sodium,
  1625. Calcium: calcium,
  1626. Bicarbonate: bicarbonate,
  1627. Glucose: glucose,
  1628. // DryWeight: dry_weight,
  1629. DialysateFlow: dialysate_flow,
  1630. DialysateTemperature: dialysate_temperature,
  1631. // PrescriptionDoctor: prescription_doctor,
  1632. ReplacementTotal: replacement_total,
  1633. Conductivity: conductivity,
  1634. Remark: remark,
  1635. Status: 1,
  1636. CreatedTime: time.Now().Unix(),
  1637. UpdatedTime: time.Now().Unix(),
  1638. DialysisDurationMinute: dialysisDurationMinute,
  1639. DialysisDurationHour: dialysisDurationHour,
  1640. TargetUltrafiltration: targetUltrafiltration,
  1641. DialysateFormulation: dialysateFormulation,
  1642. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1643. BodyFluid: body_fluid,
  1644. SpecialMedicine: special_medicine,
  1645. SpecialMedicineOther: special_medicine_other,
  1646. DisplaceLiquiPart: displace_liqui_part,
  1647. DisplaceLiquiValue: displace_liqui_value,
  1648. BloodAccess: blood_access,
  1649. Ultrafiltration: ultrafiltration,
  1650. BodyFluidOther: body_fluid_other,
  1651. Niprocart: niprocart,
  1652. Jms: jms,
  1653. FistulaNeedleSet: fistula_needle_set,
  1654. FistulaNeedleSet16: fistula_needle_set_16,
  1655. Hemoperfusion: hemoperfusion,
  1656. DialyserSterilised: dialyser_sterilised,
  1657. Filtryzer: filtryzer,
  1658. Dialyzers: dialyzers,
  1659. Injector: injector,
  1660. Bloodlines: bloodlines,
  1661. TubingHemodialysis: tubing_hemodialysis,
  1662. Package: safe_package,
  1663. ALiquid: a_liquid,
  1664. TargetKtv: target_ktv,
  1665. PreImpulse: pre_impulse,
  1666. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1667. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1668. Blood: blood,
  1669. DialysisDialyszers: dialysis_dialyszers,
  1670. DialysisIrrigation: dialysis_irrigation,
  1671. AntioxidantCommodityName: antioxidant_commodity_name,
  1672. DisplaceSpeed: displace_speed,
  1673. Illness: illness,
  1674. Amylaceum: amylaceum,
  1675. SingleTime: single_time,
  1676. SingleWater: single_water,
  1677. ReplacementFlow: replacement_flow,
  1678. PlasmaSeparator: plasma_separator,
  1679. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1680. OxygenUptake: oxygen_uptake,
  1681. OxygenFlow: oxygen_flow,
  1682. OxygenTime: oxygen_time,
  1683. HemodialysisPipelines: hemodialysis_pipelines,
  1684. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1685. PunctureNeedle: puncture_needle,
  1686. PunctureNeedleCount: puncture_needle_count,
  1687. Epo: epo,
  1688. EpoCount: epo_count,
  1689. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1690. AdminUserId: admin_user_id,
  1691. IsWater: is_war,
  1692. DrhyWater: drhy_water,
  1693. DryWaterHour: dry_water_hour,
  1694. WaterMachine: water_machine,
  1695. AddAmount: add_amount,
  1696. ReduceAmount: reduce_amount,
  1697. DialysisRemark: dialysis_remark,
  1698. PrescribingNumber: prescribing_number,
  1699. StartSodium: start_sodium,
  1700. SodiumCurve: sodium_curve,
  1701. TreatmentRemark: treatment_remark,
  1702. PrescriptionSodium: prescription_sodium,
  1703. DialysisFluidFlow: dialysis_fluid_flow,
  1704. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1705. PrescriptionWater: prescription_water,
  1706. DialysisStrainer: dialysis_strainer,
  1707. Chaptalization: chaptalization,
  1708. WashingTime: washing_time,
  1709. WarshCount: warsh_count,
  1710. BloodAccessPartId: blood_access_part_id,
  1711. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1712. Dialyzate: dialyzate,
  1713. }
  1714. //查询最近透析准备表里是否存在 透析器 灌流器
  1715. //
  1716. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1717. //
  1718. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1719. //
  1720. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1721. //if len(mation)>0{
  1722. // for _, item := range splitStr {
  1723. // for _,it := range mation{
  1724. // if(item == it.SpecificationName){
  1725. //
  1726. // //查询最近一次的透析器
  1727. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1728. //
  1729. // if errcode == gorm.ErrRecordNotFound{
  1730. // //插入数据
  1731. // prepare := models.DialysisBeforePrepare{
  1732. // UserOrgId: adminUserInfo.Org.Id,
  1733. // PatientId: id,
  1734. // RecordDate: recordDate.Unix(),
  1735. // GoodTypeId: it.GoodTypeId,
  1736. // GoodId: it.ID,
  1737. // Count: 1,
  1738. // Ctime: time.Now().Unix(),
  1739. // Creater: adminUserInfo.AdminUser.Id,
  1740. // Status:1,
  1741. //
  1742. // }
  1743. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1744. // fmt.Println("",errcode)
  1745. // }
  1746. // }
  1747. // }
  1748. //
  1749. // }
  1750. //
  1751. // for _, item := range splitIrrigation {
  1752. // for _,it := range mation{
  1753. // if(item == it.SpecificationName){
  1754. // //查询最近一次的透析器
  1755. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1756. // if errcode == gorm.ErrRecordNotFound{
  1757. // //插入数据
  1758. // prepare := models.DialysisBeforePrepare{
  1759. // UserOrgId: adminUserInfo.Org.Id,
  1760. // PatientId: id,
  1761. // RecordDate: recordDate.Unix(),
  1762. // GoodTypeId: it.GoodTypeId,
  1763. // GoodId: it.ID,
  1764. // Count: 1,
  1765. // Ctime: time.Now().Unix(),
  1766. // Creater: adminUserInfo.AdminUser.Id,
  1767. // Status:1,
  1768. //
  1769. // }
  1770. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1771. // fmt.Println(errcode)
  1772. // }
  1773. // }
  1774. // }
  1775. // }
  1776. //}
  1777. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1778. if dialysisPrescription.ID == 0 { //新增
  1779. if appRole.UserType == 2 || appRole.UserType == 1 {
  1780. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1781. }
  1782. prescription.Creater = adminUserInfo.AdminUser.Id
  1783. //针对河间咸得
  1784. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1785. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1786. prescription.DisplaceLiquiPart = 0
  1787. prescription.DisplaceLiquiValue = 0
  1788. }
  1789. }
  1790. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1791. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1792. }
  1793. err := service.AddSigleRecord(&prescription)
  1794. //记录日志
  1795. byterequest, _ := json.Marshal(prescription)
  1796. prescriptionLog := models.XtDialysisPrescriptionLog{
  1797. UserOrgId: prescription.UserOrgId,
  1798. Ctime: time.Now().Unix(),
  1799. Mtime: 0,
  1800. ErrLog: string(byterequest),
  1801. AdminUserId: adminUserInfo.AdminUser.Id,
  1802. RecordDate: prescription.RecordDate,
  1803. PatientId: prescription.PatientId,
  1804. Source: "手机端新增保存处方",
  1805. Status: 1,
  1806. }
  1807. service.CreatePrescriptionLog(prescriptionLog)
  1808. finish := models.XtDialysisFinish{
  1809. IsFinish: 1,
  1810. UserOrgId: adminUserInfo.Org.Id,
  1811. Status: 1,
  1812. Ctime: time.Now().Unix(),
  1813. Mtime: 0,
  1814. Module: 1,
  1815. RecordDate: recordDate.Unix(),
  1816. Sourse: 1,
  1817. PatientId: id,
  1818. }
  1819. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1820. if dialysisFinish.ID == 0 {
  1821. service.CreateDialysisFinish(finish)
  1822. }
  1823. //长沙南雅医院,自动生成抗凝剂的临时处方
  1824. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1825. if prescribing_number == 0 {
  1826. prescribing_number = 1
  1827. }
  1828. if prescribing_number == 0 && id == 14682 {
  1829. prescribing_number = 2
  1830. }
  1831. if prescribing_number == 0 && id == 18560 {
  1832. prescribing_number = 2
  1833. }
  1834. advice := models.DoctorAdvice{
  1835. UserOrgId: adminUserInfo.Org.Id,
  1836. PatientId: id,
  1837. GroupNo: 0,
  1838. AdviceType: 2,
  1839. RecordDate: recordDate.Unix(),
  1840. AdviceDate: recordDate.Unix(),
  1841. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1842. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1843. AdviceDesc: "",
  1844. ReminderDate: 0,
  1845. SingleDose: anticoagulant_zongliang,
  1846. SingleDoseUnit: "iu",
  1847. DrugSpec: 0,
  1848. DrugSpecUnit: "",
  1849. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1850. PrescribingNumberUnit: "支",
  1851. DeliveryWay: "静脉注射",
  1852. ExecutionFrequency: "上机前",
  1853. AdviceDoctor: 0,
  1854. Status: 1,
  1855. CreatedTime: time.Now().Unix(),
  1856. UpdatedTime: time.Now().Unix(),
  1857. IsPrescription: 1,
  1858. ExecutionState: 2,
  1859. StopState: 2,
  1860. IsSettle: 2,
  1861. }
  1862. // 查询排班信息
  1863. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1864. if schedulePatient.ID > 0 {
  1865. if schedulePatient.ScheduleType == 1 {
  1866. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1867. }
  1868. if schedulePatient.ScheduleType == 2 {
  1869. advice.StartTime = recordDate.Unix() + 10*60*60
  1870. }
  1871. }
  1872. // 抗凝剂名称
  1873. switch anticoagulant {
  1874. case 1:
  1875. advice.AdviceName = "无肝素"
  1876. break
  1877. case 2:
  1878. advice.AdviceName = "普通肝素"
  1879. break
  1880. case 3:
  1881. advice.AdviceName = "低分子肝素"
  1882. break
  1883. case 4:
  1884. advice.AdviceName = "阿加曲班"
  1885. break
  1886. case 5:
  1887. advice.AdviceName = "枸橼酸钠"
  1888. break
  1889. case 6:
  1890. advice.AdviceName = "低分子肝素钙"
  1891. break
  1892. case 7:
  1893. advice.AdviceName = "低分子肝素钠"
  1894. break
  1895. case 8:
  1896. advice.AdviceName = "依诺肝素"
  1897. break
  1898. case 9:
  1899. advice.AdviceName = "达肝素"
  1900. break
  1901. case 10:
  1902. advice.AdviceName = "体外抗凝"
  1903. break
  1904. case 11:
  1905. advice.AdviceName = "那曲肝素"
  1906. break
  1907. case 12:
  1908. advice.AdviceName = "无抗凝剂"
  1909. break
  1910. }
  1911. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1912. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1913. advice.AdviceDoctor = appRole.AdminUserId
  1914. }
  1915. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1916. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1917. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1918. advice.AdviceName = "低分子肝素钠注射液"
  1919. // 修改患者临时医嘱里的抗凝剂医嘱
  1920. advice.ID = advicePrescription.ID
  1921. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1922. } else {
  1923. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1924. advice.AdviceName = "低分子肝素钠注射液"
  1925. // 新增患者临时医嘱里的抗凝剂医嘱
  1926. service.CreateDoctorAdvice(&advice)
  1927. }
  1928. }
  1929. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1930. redis := service.RedisClient()
  1931. defer redis.Close()
  1932. //清空key 值
  1933. redis.Set(key, "", time.Second)
  1934. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1935. redis.Set(keyOne, "", time.Second)
  1936. }
  1937. //获取key,清空redis
  1938. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1939. redis := service.RedisClient()
  1940. //清空key 值
  1941. redis.Set(key, "", time.Second)
  1942. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1943. //清空key 值
  1944. redis.Set(keyOne, "", time.Second)
  1945. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1946. //清空key 值
  1947. redis.Set(keyTwo, "", time.Second)
  1948. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1949. redis.Set(keySix, "", time.Second)
  1950. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1951. redis.Set(keySeven, "", time.Second)
  1952. if err == nil {
  1953. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1954. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1955. //清空key 值
  1956. redis.Set(keyThree, "", time.Second)
  1957. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1958. //清空key 值
  1959. redis.Set(keyFour, "", time.Second)
  1960. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1961. redis.Set(keyFive, "", time.Second)
  1962. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1963. redis.Set(keySix, "", time.Second)
  1964. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1965. redis.Set(keySeven, "", time.Second)
  1966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1967. //清空key 值
  1968. redis.Set(keyOne, "", time.Second)
  1969. if updateErr != nil {
  1970. utils.ErrorLog("%v", updateErr)
  1971. }
  1972. defer redis.Close()
  1973. c.ServeSuccessJSON(map[string]interface{}{
  1974. "prescription": prescription,
  1975. })
  1976. }
  1977. } else { //修改
  1978. //if mode_id > 0 {
  1979. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1980. //}
  1981. //if template.TemplateId == 1 {
  1982. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1983. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1984. // if getPermissionErr != nil {
  1985. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1986. // return
  1987. // } else if headNursePermission == nil {
  1988. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1989. // return
  1990. // }
  1991. // }
  1992. //}
  1993. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1994. prescription.Modifier = adminUserInfo.AdminUser.Id
  1995. if appRole.UserType == 2 || appRole.UserType == 1 {
  1996. prescription_doctor := adminUserInfo.AdminUser.Id
  1997. prescription.PrescriptionDoctor = prescription_doctor
  1998. } else {
  1999. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2000. }
  2001. if dialysisPrescription.Creater == 0 { //体重称
  2002. prescription.Creater = adminUserInfo.AdminUser.Id
  2003. } else {
  2004. prescription.Creater = dialysisPrescription.Creater
  2005. if adminUserInfo.Org.Id == 9882 {
  2006. if appRole.UserType == 2 || appRole.UserType == 1 {
  2007. prescription_doctor := adminUserInfo.AdminUser.Id
  2008. prescription.PrescriptionDoctor = prescription_doctor
  2009. prescription.Creater = prescription_doctor
  2010. }
  2011. }
  2012. }
  2013. prescription.ID = dialysisPrescription.ID
  2014. err := service.UpDateDialysisPrescription(&prescription)
  2015. //记录日志
  2016. byterequest, _ := json.Marshal(prescription)
  2017. prescriptionLog := models.XtDialysisPrescriptionLog{
  2018. UserOrgId: prescription.UserOrgId,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. ErrLog: string(byterequest),
  2022. AdminUserId: adminUserInfo.AdminUser.Id,
  2023. RecordDate: prescription.RecordDate,
  2024. PatientId: prescription.PatientId,
  2025. Source: "手机端修改处方",
  2026. Status: 1,
  2027. }
  2028. service.CreatePrescriptionLog(prescriptionLog)
  2029. finish := models.XtDialysisFinish{
  2030. IsFinish: 1,
  2031. UserOrgId: adminUserInfo.Org.Id,
  2032. Status: 1,
  2033. Ctime: time.Now().Unix(),
  2034. Mtime: 0,
  2035. Module: 1,
  2036. RecordDate: recordDate.Unix(),
  2037. Sourse: 1,
  2038. PatientId: id,
  2039. }
  2040. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2041. if dialysisFinish.ID == 0 {
  2042. service.CreateDialysisFinish(finish)
  2043. }
  2044. //修改处方
  2045. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2046. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2047. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2048. if advicePrescription.ID > 0 {
  2049. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2051. redis := service.RedisClient()
  2052. defer redis.Close()
  2053. //清空key 值
  2054. redis.Set(key, "", time.Second)
  2055. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2056. redis.Set(keyOne, "", time.Second)
  2057. }
  2058. }
  2059. //获取key,清空redis
  2060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2061. redis := service.RedisClient()
  2062. //清空key 值
  2063. redis.Set(key, "", time.Second)
  2064. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2065. //清空key 值
  2066. redis.Set(keyOne, "", time.Second)
  2067. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2068. redis.Set(keySix, "", time.Second)
  2069. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2070. redis.Set(keySeven, "", time.Second)
  2071. if err == nil {
  2072. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2073. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2074. //清空key 值
  2075. redis.Set(keyOne, "", time.Second)
  2076. defer redis.Close()
  2077. if updateErr != nil {
  2078. utils.ErrorLog("%v", updateErr)
  2079. }
  2080. c.ServeSuccessJSON(map[string]interface{}{
  2081. "prescription": prescription,
  2082. })
  2083. }
  2084. }
  2085. }
  2086. func (c *DialysisAPIController) Finish() {
  2087. id, _ := c.GetInt64("patient", 0)
  2088. recordDateStr := c.GetString("record_date")
  2089. nurseID, _ := c.GetInt64("nurse")
  2090. end_time := c.GetString("end_time")
  2091. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2092. internal_fistula := c.GetString("blood_access_internal_fistula")
  2093. catheter := c.GetString("catheter")
  2094. cruor := c.GetString("cruor")
  2095. mission := c.GetString("mission")
  2096. condenser := c.GetString("condenser")
  2097. if id <= 0 || nurseID <= 0 {
  2098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2099. return
  2100. }
  2101. adminUserInfo := c.GetMobileAdminUserInfo()
  2102. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2103. if patient.ID == 0 {
  2104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2105. return
  2106. }
  2107. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2108. if getNurseErr != nil {
  2109. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2111. return
  2112. } else if nurse == nil {
  2113. c.ErrorLog("护士不存在")
  2114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2115. return
  2116. }
  2117. if len(recordDateStr) == 0 {
  2118. recordDateStr = time.Now().Format("2006-01-02")
  2119. }
  2120. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2121. if parseDateErr != nil {
  2122. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2124. return
  2125. }
  2126. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2127. if parseEndDateErr != nil {
  2128. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2130. return
  2131. }
  2132. // 查询信息规挡的设置天数
  2133. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2134. if infor.ID > 0 && infor.WeekDay > 0 {
  2135. var cha_time int64
  2136. timeNowStr := time.Now().Format("2006-01-02")
  2137. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2138. //今日的日期减去设置的日期
  2139. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2140. if cha_time >= recordDate.Unix() {
  2141. //查询审核是否允许
  2142. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2143. //申请状态不允许的情况 拒绝修改
  2144. if infor.ApplicationStatus != 1 {
  2145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2146. return
  2147. }
  2148. }
  2149. }
  2150. //now := time.Now()
  2151. //year, month, day := now.Date()
  2152. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2153. //todayTimeStamp := today_time.Unix()
  2154. // 获取当天的第一条透析纪录
  2155. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2156. if getMonitorRecordsErr != nil {
  2157. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2159. return
  2160. }
  2161. // 获取当前的最后一条透析纪录
  2162. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2163. if getMonitorRecordsErr != nil {
  2164. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2166. return
  2167. }
  2168. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2169. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2170. if getAADErr != nil {
  2171. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2173. return
  2174. }
  2175. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2176. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2177. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2178. if assessmentAfterDislysis != nil {
  2179. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2180. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2181. } else {
  2182. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2183. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2184. tempassessmentAfterDislysis.Status = 1
  2185. tempassessmentAfterDislysis.PatientId = id
  2186. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2187. }
  2188. //长沙南雅
  2189. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2190. //获取最后一条透析处方数据
  2191. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2192. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2193. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2194. }
  2195. if dialysisOrder.Stage == 1 {
  2196. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2197. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2198. fmt.Println(value)
  2199. a, b := math.Modf(value)
  2200. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2201. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2202. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2203. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2204. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2205. }
  2206. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2207. //var num1 int64
  2208. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2209. //fmt.Println(num1)
  2210. //sub := float64(num1 / 3600)
  2211. //fmt.Println(sub)
  2212. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2213. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2214. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2215. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2216. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2217. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2218. if adminUserInfo.Org.Id != 10375 {
  2219. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2220. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2221. }
  2222. if adminUserInfo.Org.Id != 10445 {
  2223. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2224. }
  2225. //北方营口医院
  2226. if adminUserInfo.Org.Id == 10445 {
  2227. //获取最后一条透析处方数据
  2228. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2229. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2230. } else {
  2231. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2232. }
  2233. //新化博翔
  2234. if adminUserInfo.Org.Id == 10447 {
  2235. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2236. }
  2237. //阳春
  2238. if adminUserInfo.Org.Id == 10485 {
  2239. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2240. }
  2241. if adminUserInfo.Org.Id == 10551 {
  2242. //获取最后一条透析处方数据
  2243. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2244. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2245. }
  2246. if adminUserInfo.Org.Id == 10580 {
  2247. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2248. }
  2249. }
  2250. 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 {
  2251. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2252. if evaluation.SystolicBloodPressure == 0 {
  2253. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2254. pre := models.PredialysisEvaluation{
  2255. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2256. }
  2257. fmt.Println("prew", pre)
  2258. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2259. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2260. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2261. redis := service.RedisClient()
  2262. redis.Set(key, "", time.Second)
  2263. redis.Set(keyOne, "", time.Second)
  2264. defer redis.Close()
  2265. fmt.Println(getNurseErr)
  2266. }
  2267. if evaluation.DiastolicBloodPressure == 0 {
  2268. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2269. pres := models.PredialysisEvaluation{
  2270. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2271. }
  2272. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2273. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2274. redis := service.RedisClient()
  2275. redis.Set(key, "", time.Second)
  2276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2277. redis.Set(keyOne, "", time.Second)
  2278. defer redis.Close()
  2279. fmt.Println(getNurseErr)
  2280. }
  2281. if evaluation.PulseFrequency == 0 {
  2282. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2283. press := models.PredialysisEvaluation{
  2284. PulseFrequency: evaluation.PulseFrequency,
  2285. }
  2286. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2287. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2288. redis := service.RedisClient()
  2289. redis.Set(key, "", time.Second)
  2290. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2291. redis.Set(keyOne, "", time.Second)
  2292. defer redis.Close()
  2293. fmt.Println(getNurseErr)
  2294. }
  2295. if evaluation.Temperature == 0 {
  2296. evaluation.Temperature = fmonitorRecords.Temperature
  2297. press := models.PredialysisEvaluation{
  2298. Temperature: evaluation.Temperature,
  2299. }
  2300. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2301. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2302. redis := service.RedisClient()
  2303. redis.Set(key, "", time.Second)
  2304. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2305. redis.Set(keyOne, "", time.Second)
  2306. defer redis.Close()
  2307. fmt.Println(getNurseErr)
  2308. }
  2309. }
  2310. if adminUserInfo.Org.Id == 9583 {
  2311. //获取透析处方的最后一条数据
  2312. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2313. if diaerr != nil {
  2314. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2316. return
  2317. }
  2318. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2319. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2320. }
  2321. }
  2322. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2323. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2324. }
  2325. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2326. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2327. }
  2328. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2329. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2330. }
  2331. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2332. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2333. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2334. }
  2335. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2336. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2337. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2338. }
  2339. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2340. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2341. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2342. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2343. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2344. }
  2345. if lastAssessmentAfterDislysis != nil {
  2346. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2347. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2348. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2349. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2350. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2351. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2352. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2353. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2354. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2355. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2356. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2357. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2358. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2359. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2360. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2361. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2362. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2363. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2364. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2365. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2366. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2367. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2368. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2369. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2370. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2371. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2372. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2373. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2374. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2375. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2376. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2377. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2378. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2379. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2380. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2381. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2382. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2383. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2384. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2385. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2386. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2387. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2388. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2389. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2390. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2391. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2392. if tempassessmentAfterDislysis.PatientId == 18695 {
  2393. tempassessmentAfterDislysis.ActualDisplacement = 0
  2394. }
  2395. if adminUserInfo.Org.Id != 10375 {
  2396. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2397. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2398. }
  2399. }
  2400. finish := models.XtDialysisFinish{
  2401. IsFinish: 1,
  2402. UserOrgId: adminUserInfo.Org.Id,
  2403. Status: 1,
  2404. Ctime: time.Now().Unix(),
  2405. Mtime: 0,
  2406. Module: 9,
  2407. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2408. Sourse: 1,
  2409. PatientId: tempassessmentAfterDislysis.PatientId,
  2410. }
  2411. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2412. if dialysisFinish.ID == 0 {
  2413. service.CreateDialysisFinish(finish)
  2414. }
  2415. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2416. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2417. redis := service.RedisClient()
  2418. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2419. redis.Set(keyOne, "", time.Second)
  2420. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2421. redis.Set(keyTwo, "", time.Second)
  2422. defer redis.Close()
  2423. //清空key 值
  2424. redis.Set(key, "", time.Second)
  2425. if err != nil {
  2426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2427. return
  2428. }
  2429. if dialysisOrder == nil {
  2430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2431. return
  2432. }
  2433. if dialysisOrder.Stage == 2 {
  2434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2435. return
  2436. }
  2437. if dialysisOrder.Stage == 1 {
  2438. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2439. finish := models.XtDialysisFinish{
  2440. IsFinish: 1,
  2441. UserOrgId: adminUserInfo.Org.Id,
  2442. Status: 1,
  2443. Ctime: time.Now().Unix(),
  2444. Mtime: 0,
  2445. Module: 8,
  2446. RecordDate: recordDate.Unix(),
  2447. Sourse: 1,
  2448. PatientId: id,
  2449. }
  2450. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2451. if dialysisFinish.ID == 0 {
  2452. service.CreateDialysisFinish(finish)
  2453. }
  2454. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2455. redis := service.RedisClient()
  2456. defer redis.Close()
  2457. //清空key 值
  2458. redis.Set(key, "", time.Second)
  2459. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2460. redis.Set(keyOne, "", time.Second)
  2461. //结束时候透析次数加1
  2462. service.UpdateSolutionByPatientId(id)
  2463. //下机完自动消毒,针对长沙南雅
  2464. if dialysisOrder.Stage == 1 {
  2465. 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 {
  2466. //根据床位号获取设备型号
  2467. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2468. //查询使用消毒最后一条消毒记录
  2469. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2470. fmt.Println("err", err)
  2471. if err == gorm.ErrRecordNotFound {
  2472. //查找排班
  2473. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2474. //查询改设备是否有消毒计划
  2475. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2476. //根据床位号获取设备id
  2477. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2478. //查询病人信息
  2479. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2480. var con = ""
  2481. if patients.IsInfectious == 0 {
  2482. con = ""
  2483. }
  2484. if patients.IsInfectious == 1 {
  2485. con = "无"
  2486. }
  2487. if patients.IsInfectious == 2 {
  2488. con = "有"
  2489. }
  2490. if errcode == nil {
  2491. var end_time int64
  2492. end_time = endDate.Unix() + plan.DisinfecTime*60
  2493. //新增消毒
  2494. information := models.DeviceInformation{
  2495. Date: dialysisOrder.DialysisDate,
  2496. Zone: dialysisOrder.ZoneId,
  2497. Class: dialysisOrder.SchedualType,
  2498. BedNumber: dialysisOrder.BedID,
  2499. PatientId: dialysisOrder.PatientId,
  2500. DialysisMode: scheduleByPatient.ModeId,
  2501. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2502. Disinfection: 1,
  2503. DialysisConcentration: 1,
  2504. DisinfectionStatus: 1,
  2505. Move: 1,
  2506. UserOrgId: dialysisOrder.UserOrgId,
  2507. DisinfectType: plan.Way,
  2508. DisinfectantType: plan.MachineDisinfectant,
  2509. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2510. Disinfectant: plan.Disinfectant,
  2511. Ctime: time.Now().Unix(),
  2512. Status: 1,
  2513. SignName: nurseID,
  2514. EquimentId: addmacher.ID,
  2515. DisinfectionResidue: 2,
  2516. Bed: addmacher.BedNumber,
  2517. StartTime: dialysisOrder.StartTime,
  2518. EndTime: dialysisOrder.EndTime,
  2519. Contagion: con,
  2520. WeightLoss: 0,
  2521. Hyperfiltratio: 0,
  2522. DialysisHour: "",
  2523. MachineRun: 1,
  2524. DisinfecStartime: endDate.Unix(),
  2525. DisinfecEndtime: end_time,
  2526. }
  2527. err := service.CreateInformationTwo(&information)
  2528. fmt.Println("报错", err)
  2529. }
  2530. }
  2531. }
  2532. }
  2533. dialysisOrder.Stage = 2
  2534. dialysisOrder.FinishNurse = nurseID
  2535. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2536. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2537. dialysisOrder.EndTime = endDate.Unix()
  2538. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2539. // 长沙南雅需求
  2540. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2541. //获取最后1条监测的数据
  2542. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2543. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2544. var accumulatedBloodVolume float64
  2545. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2546. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2547. fmt.Println(err)
  2548. // 查询未执行的医嘱
  2549. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2550. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2551. for _, item := range doctorAdvice {
  2552. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2553. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2554. redis := service.RedisClient()
  2555. //清空key 值
  2556. redis.Set(key, "", time.Second)
  2557. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2558. redis.Set(keyTwo, "", time.Second)
  2559. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2560. redis.Set(keyThree, "", time.Second)
  2561. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2562. theTime := toTime.Format("2006-01-02")
  2563. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2564. redis.Set(keyFour, "", time.Second)
  2565. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2566. redis.Set(keyFive, "", time.Second)
  2567. defer redis.Close()
  2568. }
  2569. }
  2570. go func() {
  2571. ssoDomain := beego.AppConfig.String("call_domain")
  2572. api := ssoDomain + "/index/downpatient"
  2573. values := make(url.Values)
  2574. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2575. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2576. values.Set("patient_id", strconv.FormatInt(id, 10))
  2577. http.PostForm(api, values)
  2578. }()
  2579. if err == nil {
  2580. c.ServeSuccessJSON(map[string]interface{}{
  2581. "dialysisOrder": dialysisOrder,
  2582. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2583. })
  2584. } else {
  2585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2586. }
  2587. }
  2588. }
  2589. func (c *DialysisAPIController) GetAllZone() {
  2590. adminUserInfo := c.GetMobileAdminUserInfo()
  2591. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2592. if err == nil {
  2593. c.ServeSuccessJSON(map[string]interface{}{
  2594. "zone": zone,
  2595. })
  2596. }
  2597. }
  2598. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2599. adminUserInfo := c.GetMobileAdminUserInfo()
  2600. page, _ := c.GetInt64("page", 1)
  2601. limit, _ := c.GetInt64("limit", 10)
  2602. schedulType, _ := c.GetInt64("schedul_type", 0)
  2603. startTime, _ := c.GetInt64("schedul_time", 0)
  2604. partitionType, _ := c.GetInt64("partition_type", 0)
  2605. keywords := c.GetString("keywords")
  2606. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2607. if err == nil {
  2608. c.ServeSuccessJSON(map[string]interface{}{
  2609. "schedule": dialysisSchedule,
  2610. })
  2611. }
  2612. return
  2613. }
  2614. // /m/api/dialysis/start [post]
  2615. // @param patient_id:int
  2616. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2617. // @param nurse:int 上机护士
  2618. // @param bed:int 床位号
  2619. func (this *DialysisAPIController) StartDialysis() {
  2620. patientID, _ := this.GetInt64("patient_id")
  2621. recordDateStr := this.GetString("record_date")
  2622. nurseID, _ := this.GetInt64("start_nurse")
  2623. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2624. blood_drawing, _ := this.GetInt64("blood_drawing")
  2625. schedual_type, _ := this.GetInt64("schedual_type")
  2626. bedID, _ := this.GetInt64("bed")
  2627. start_time := this.GetString("start_time")
  2628. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2629. change_nurse, _ := this.GetInt64("change_nurse")
  2630. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2631. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2632. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2633. puncture_needle := this.GetString("puncture_needle")
  2634. puncture_way := this.GetString("puncture_way")
  2635. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2636. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2637. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2638. zone_id, _ := this.GetInt64("zone_id")
  2639. elecsign := this.GetString("url")
  2640. nuclein_date_str := this.GetString("nuclein_date_str")
  2641. schedule_remark := this.GetString("schedule_remark")
  2642. order_remark := this.GetString("order_remark")
  2643. catheter_operation := this.GetString("catheter_operation")
  2644. blood_flow_volume := this.GetString("blood_flow_volume")
  2645. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2646. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2647. return
  2648. }
  2649. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2650. if parseStartDateErr != nil {
  2651. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2652. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2653. return
  2654. }
  2655. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2656. if parseErr != nil {
  2657. this.ErrorLog("时间解析失败:%v", parseErr)
  2658. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2659. return
  2660. }
  2661. adminUserInfo := this.GetMobileAdminUserInfo()
  2662. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2663. if getPatientErr != nil {
  2664. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2666. return
  2667. } else if patient == nil {
  2668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2669. return
  2670. }
  2671. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2672. if getNurseErr != nil {
  2673. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2675. return
  2676. } else if nurse == nil {
  2677. this.ErrorLog("护士不存在")
  2678. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2682. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2683. if getDeviceNumberErr != nil {
  2684. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2685. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2686. return
  2687. } else if deviceNumber == nil {
  2688. this.ErrorLog("床位号不存在")
  2689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2690. return
  2691. }
  2692. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2693. if getRecordErr != nil {
  2694. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2696. return
  2697. } else if dialysisRecord != nil {
  2698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2699. return
  2700. }
  2701. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2702. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2703. timeLayout := "2006-01-02 15:04:05"
  2704. loc, _ := time.LoadLocation("Local")
  2705. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2706. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2707. schedulestartTime := theStartTime.Unix()
  2708. scheduleendTime := theEndTime.Unix()
  2709. var theNucleinDate int64
  2710. timeLayoutOne := "2006-01-02"
  2711. if len(nuclein_date_str) > 0 {
  2712. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2713. if err != nil {
  2714. utils.ErrorLog(err.Error())
  2715. }
  2716. theNucleinDate = theTime.Unix()
  2717. }
  2718. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2719. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2720. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2721. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2722. //查询该床位是否有人用了
  2723. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2724. if err == gorm.ErrRecordNotFound { //空床位
  2725. // 修改了床位逻辑
  2726. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2727. if daySchedule.ID > 0 {
  2728. daySchedule.PartitionId = deviceNumber.ZoneID
  2729. daySchedule.BedId = bedID
  2730. daySchedule.ScheduleType = schedual_type
  2731. daySchedule.UpdatedTime = time.Now().Unix()
  2732. xtSchedule := models.Schedule{
  2733. PartitionId: deviceNumber.ZoneID,
  2734. BedId: bedID,
  2735. ScheduleType: schedual_type,
  2736. UpdatedTime: time.Now().Unix(),
  2737. }
  2738. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2739. if err != nil {
  2740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2741. return
  2742. }
  2743. }
  2744. } else if err == nil {
  2745. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2746. if order.ID > 0 { //该机位被其他人占用了
  2747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2748. return
  2749. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2750. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2751. if daySchedule.ID > 0 {
  2752. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2753. if err != nil {
  2754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2755. return
  2756. }
  2757. }
  2758. }
  2759. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2760. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2761. return
  2762. }
  2763. //else if order.ID == 0 { //该床位没被占用
  2764. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2765. // if daySchedule.ID > 0 {
  2766. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2767. // //daySchedule.BedId = bedID
  2768. // //daySchedule.ScheduleType = schedual_type
  2769. // //daySchedule.UpdatedTime = time.Now().Unix()
  2770. // //err := service.UpdateSchedule(&daySchedule)
  2771. // xtSchedule := models.Schedule{
  2772. // PartitionId: deviceNumber.ZoneID,
  2773. // BedId: bedID,
  2774. // ScheduleType: schedual_type,
  2775. // UpdatedTime: time.Now().Unix(),
  2776. // }
  2777. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2778. // if err != nil {
  2779. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2780. // return
  2781. // }
  2782. // }
  2783. //}
  2784. //}
  2785. } else if err != nil {
  2786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2787. return
  2788. }
  2789. // 查询信息规挡的设置天数
  2790. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2791. if infor.ID > 0 && infor.WeekDay > 0 {
  2792. var cha_time int64
  2793. timeNowStr := time.Now().Format("2006-01-02")
  2794. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2795. //今日的日期减去设置的日期
  2796. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2797. if cha_time >= recordDate.Unix() {
  2798. //查询审核是否允许
  2799. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2800. //申请状态不允许的情况 拒绝修改
  2801. if infor.ApplicationStatus != 1 {
  2802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2803. return
  2804. }
  2805. }
  2806. }
  2807. dialysisRecord = &models.DialysisOrder{
  2808. DialysisDate: recordDate.Unix(),
  2809. UserOrgId: adminUserInfo.Org.Id,
  2810. PatientId: patientID,
  2811. Stage: 1,
  2812. BedID: bedID,
  2813. StartNurse: nurseID,
  2814. Status: 1,
  2815. StartTime: startDate.Unix(),
  2816. CreatedTime: time.Now().Unix(),
  2817. UpdatedTime: time.Now().Unix(),
  2818. PunctureNurse: puncture_nurse,
  2819. Creator: adminUserInfo.AdminUser.Id,
  2820. Modifier: adminUserInfo.AdminUser.Id,
  2821. SchedualType: schedual_type,
  2822. WashpipeNurse: washpipe_nurse,
  2823. ChangeNurse: change_nurse,
  2824. DifficultPunctureNurse: difficult_puncture_nurse,
  2825. NewFistulaNurse: new_fistula_nurse,
  2826. ZoneId: zone_id,
  2827. QualityNurseId: quality_nurse_id,
  2828. PunctureNeedle: puncture_needle,
  2829. PunctureWay: puncture_way,
  2830. DialysisIrrigation: dialysis_irrigation,
  2831. DialysisDialyszers: dialysis_dialyszers,
  2832. BloodAccessId: blood_access_id,
  2833. Url: elecsign,
  2834. NucleinDate: theNucleinDate,
  2835. ScheduleRemark: schedule_remark,
  2836. OrderRemark: order_remark,
  2837. CatheterOperation: catheter_operation,
  2838. BloodFlowVolume: blood_flow_volume,
  2839. }
  2840. //查询该床位是否有人用了
  2841. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2842. if errorscode == gorm.ErrRecordNotFound {
  2843. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2844. finish := models.XtDialysisFinish{
  2845. IsFinish: 1,
  2846. UserOrgId: adminUserInfo.Org.Id,
  2847. Status: 1,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: 0,
  2850. Module: 6,
  2851. RecordDate: schedulestartTime,
  2852. Sourse: 1,
  2853. PatientId: patientID,
  2854. }
  2855. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2856. if dialysisFinish.ID == 0 {
  2857. service.CreateDialysisFinish(finish)
  2858. }
  2859. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2860. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2861. //统计该患者总次数
  2862. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2863. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2864. }
  2865. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2866. //统计该患者总次数
  2867. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2868. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2869. }
  2870. redis := service.RedisClient()
  2871. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2872. redis.Set(key, "", time.Second)
  2873. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2874. //清空key 值
  2875. redis.Set(keyOne, "", time.Second)
  2876. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2877. //清空key 值
  2878. redis.Set(keyTwo, "", time.Second)
  2879. if createErr != nil {
  2880. this.ErrorLog("上机失败:%v", createErr)
  2881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2882. return
  2883. }
  2884. }
  2885. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2886. var tempdispose string
  2887. // 只针对中能建
  2888. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2889. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2890. }
  2891. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2892. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2893. }
  2894. var ultrafiltration_rate float64
  2895. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2896. //后期预增脱水量
  2897. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2898. if prescription.ID > 0 {
  2899. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2900. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2901. 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
  2902. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2903. }
  2904. if adminUserInfo.Org.Id == 10597 { //adminUserInfo.Org.Id == 9538
  2905. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2906. }
  2907. //针对医师汇
  2908. if adminUserInfo.Org.Id == 10121 {
  2909. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2910. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2911. }
  2912. //针对通道
  2913. if adminUserInfo.Org.Id == 10234 {
  2914. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2915. }
  2916. //针对监利大垸医院
  2917. if template.TemplateId == 41 {
  2918. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2919. }
  2920. //针对肇庆三鹤血液透析中心
  2921. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2922. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2923. }
  2924. if adminUserInfo.Org.Id == 10469 {
  2925. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2926. }
  2927. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2928. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2929. }
  2930. // 只针对方济医院
  2931. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2932. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2933. ultrafiltration_rate = value
  2934. }
  2935. //针对
  2936. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2937. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2938. ultrafiltration_rate = ultrafiltration_rate / 1000
  2939. }
  2940. if adminUserInfo.Org.Id == 10551 {
  2941. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2942. ultrafiltration_rate = ultrafiltration_rate / 1000
  2943. }
  2944. }
  2945. }
  2946. record := models.MonitoringRecord{
  2947. UserOrgId: adminUserInfo.Org.Id,
  2948. PatientId: patientID,
  2949. DialysisOrderId: dialysisRecord.ID,
  2950. MonitoringDate: schedulestartTime,
  2951. OperateTime: startDate.Unix(),
  2952. // MonitoringTime: recordTime,
  2953. MonitoringNurse: nurseID,
  2954. Dispose: tempdispose,
  2955. UltrafiltrationRate: ultrafiltration_rate,
  2956. UltrafiltrationVolume: 0,
  2957. Status: 1,
  2958. CreatedTime: time.Now().Unix(),
  2959. UpdatedTime: time.Now().Unix(),
  2960. }
  2961. //只针对广慈医院
  2962. 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 {
  2963. // 查询病人是否有透前评估数据
  2964. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2965. //如果有数据就插入
  2966. if errcode == nil {
  2967. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2968. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2969. record.BreathingRate = befor.BreathingRate
  2970. record.PulseFrequency = befor.PulseFrequency
  2971. record.Temperature = befor.Temperature
  2972. }
  2973. }
  2974. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2975. if newdialysisRecord.ID > 0 {
  2976. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2977. record.Temperature = 36.5
  2978. record.ArterialPressure = -100
  2979. record.DialysateTemperature = 36.5
  2980. record.Conductivity = 14
  2981. record.BreathingRate = "20"
  2982. record.VenousPressure = 80
  2983. record.TransmembranePressure = 60
  2984. record.Dispose = catheter_operation
  2985. }
  2986. //针对新化博翔
  2987. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2988. record.BloodOxygenSaturation = "99"
  2989. record.Conductivity = 14
  2990. record.DialysateTemperature = 36.5
  2991. record.BreathingRate = "20"
  2992. }
  2993. //针对兰溪人民医院的需求
  2994. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2995. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2996. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2997. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2998. record.Temperature = befor.Temperature
  2999. record.PulseFrequency = befor.PulseFrequency
  3000. record.BreathingRate = befor.BreathingRate
  3001. }
  3002. //新化博翔
  3003. if adminUserInfo.Org.Id == 10447 {
  3004. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3005. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3006. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3007. record.BreathingRate = befor.BreathingRate
  3008. }
  3009. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3010. record.PulseFrequency = 80
  3011. record.Temperature = 36.5
  3012. }
  3013. //诊断灵山圣康
  3014. if adminUserInfo.Org.Id == 10375 {
  3015. record.Conductivity = 13.8
  3016. record.DialysateTemperature = 37
  3017. record.DialysateFlow = 500
  3018. record.BloodFlowVolume = 200
  3019. record.BreathingRate = "18"
  3020. record.SodiumConcentration = 140
  3021. }
  3022. //江成肾病医院
  3023. if adminUserInfo.Org.Id == 10517 {
  3024. record.SodiumConcentration = 138
  3025. record.DialysateTemperature = 36.5
  3026. }
  3027. err := service.CreateMonitor(&record)
  3028. //记录日志
  3029. byterequest, _ := json.Marshal(record)
  3030. monitorRecordLog := models.XtMonitorRecordLog{
  3031. RecordDate: record.MonitoringDate,
  3032. PatientId: record.PatientId,
  3033. Module: 1,
  3034. AdminUserId: adminUserInfo.AdminUser.Id,
  3035. Ctime: time.Now().Unix(),
  3036. Mtime: 0,
  3037. Status: 1,
  3038. UserOrgId: record.UserOrgId,
  3039. ErrLog: string(byterequest),
  3040. Source: "执行上机时新增监测",
  3041. }
  3042. service.CreateMonitorRecordLog(monitorRecordLog)
  3043. finish := models.XtDialysisFinish{
  3044. IsFinish: 1,
  3045. UserOrgId: adminUserInfo.Org.Id,
  3046. Status: 1,
  3047. Ctime: time.Now().Unix(),
  3048. Mtime: 0,
  3049. Module: 7,
  3050. RecordDate: schedulestartTime,
  3051. Sourse: 1,
  3052. PatientId: patientID,
  3053. }
  3054. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3055. if dialysisFinish.ID == 0 {
  3056. service.CreateDialysisFinish(finish)
  3057. }
  3058. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3059. redis := service.RedisClient()
  3060. //清空key 值
  3061. redis.Set(key, "", time.Second)
  3062. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3063. redis.Set(keyOne, "", time.Second)
  3064. defer redis.Close()
  3065. if err != nil {
  3066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3067. return
  3068. }
  3069. }
  3070. go func() {
  3071. ssoDomain := beego.AppConfig.String("call_domain")
  3072. api := ssoDomain + "/index/uppatient"
  3073. values := make(url.Values)
  3074. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3075. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3076. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3077. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3078. http.PostForm(api, values)
  3079. }()
  3080. this.ServeSuccessJSON(map[string]interface{}{
  3081. "dialysis_order": newdialysisRecord,
  3082. "monitor": record,
  3083. })
  3084. return
  3085. }
  3086. func (c *DialysisAPIController) PostSolution() {
  3087. id, _ := c.GetInt64("patient", 0)
  3088. recordDateStr := c.GetString("record_date")
  3089. if id <= 0 {
  3090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3091. return
  3092. }
  3093. adminUserInfo := c.GetMobileAdminUserInfo()
  3094. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3095. if patient.ID == 0 {
  3096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3097. return
  3098. }
  3099. if len(recordDateStr) == 0 {
  3100. recordDateStr = time.Now().Format("2006-01-02")
  3101. }
  3102. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3103. if parseDateErr != nil {
  3104. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3106. return
  3107. }
  3108. mode_id, _ := c.GetInt64("mode_id", 0)
  3109. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3110. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3111. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3112. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3113. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3114. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3115. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3116. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3117. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3118. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3119. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3120. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3121. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3122. kalium, _ := c.GetFloat("kalium", 0)
  3123. sodium, _ := c.GetFloat("sodium", 0)
  3124. calcium, _ := c.GetFloat("calcium", 0)
  3125. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3126. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3127. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3128. glucose, _ := c.GetFloat("glucose", 0)
  3129. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3130. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3131. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3132. conductivity, _ := c.GetFloat("conductivity", 0)
  3133. remark := c.GetString("remark")
  3134. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3135. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3136. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3137. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3138. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3139. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3140. special_medicine_other := c.GetString("special_medicine_other")
  3141. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3142. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3143. blood_access, _ := c.GetInt64("blood_access", 0)
  3144. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3145. body_fluid_other := c.GetString("body_fluid_other")
  3146. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3147. niprocart, _ := c.GetInt64("niprocart", 0)
  3148. jms, _ := c.GetInt64("jms", 0)
  3149. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3150. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3151. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3152. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3153. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3154. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3155. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3156. injector, _ := c.GetInt64("injector", 0)
  3157. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3158. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3159. safe_package, _ := c.GetInt64("package", 0)
  3160. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3161. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3162. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3163. blood := c.GetString("blood")
  3164. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3165. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3166. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3167. displace_speed := c.GetString("displace_speed")
  3168. illness, _ := c.GetInt64("illness")
  3169. amylaceum := c.GetString("amylaceum")
  3170. single_time := c.GetString("single_time")
  3171. single_water := c.GetString("single_water")
  3172. replacement_flow := c.GetString("replacement_flow")
  3173. plasma_separator := c.GetString("plasma_separator")
  3174. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3175. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3176. oxygen_flow := c.GetString("oxygen_flow")
  3177. oxygen_time := c.GetString("oxygen_time")
  3178. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3179. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3180. puncture_needle := c.GetString("puncture_needle")
  3181. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3182. epo := c.GetString("epo")
  3183. epo_count, _ := c.GetFloat("epo_count", 0)
  3184. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3185. pre_impulse := c.GetString("pre_impulse")
  3186. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3187. admin_user_id, _ := c.GetInt64("admin_user_id")
  3188. is_water := c.GetString("is_water")
  3189. add_amount, _ := c.GetFloat("add_amount")
  3190. reduce_amount, _ := c.GetFloat("reduce_amount")
  3191. prescribing_number, _ := c.GetFloat("prescribing_number")
  3192. treatment_remark := c.GetString("treatment_remark")
  3193. prescription_sodium := c.GetString("prescription_sodium")
  3194. start_sodium := c.GetString("start_sodium")
  3195. sodium_curve := c.GetString("sodium_curve")
  3196. var is_war int64
  3197. if is_water == "是" {
  3198. is_war = 1
  3199. }
  3200. if is_water == "否" {
  3201. is_war = 2
  3202. }
  3203. if is_water == "请选择" {
  3204. is_war = 0
  3205. }
  3206. drhy_water := c.GetString("drhy_water")
  3207. dry_water_hour := c.GetString("dry_water_hour")
  3208. water_machine := c.GetString("water_machine")
  3209. dialysis_remark := c.GetString("dialysis_remark")
  3210. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3211. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3212. prescription_water, _ := c.GetFloat("prescription_water")
  3213. dialysis_strainer := c.GetString("dialysis_strainer")
  3214. chaptalization := c.GetString("chaptalization")
  3215. washing_time := c.GetString("washing_time")
  3216. warsh_count := c.GetString("warsh_count")
  3217. blood_access_part_id := c.GetString("blood_access_part_id")
  3218. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3219. dialyzate := c.GetString("dialyzate")
  3220. if mode_id > 0 {
  3221. var str string
  3222. //查找该机构用的是什么透析器
  3223. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3224. if filedConfig.ID > 0 {
  3225. str = dialyzerPerfusionApparatus
  3226. } else {
  3227. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3228. }
  3229. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3230. }
  3231. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3232. //
  3233. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3234. // if appRole.UserType == 3 {
  3235. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3236. // if getPermissionErr != nil {
  3237. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3238. // return
  3239. // } else if headNursePermission == nil {
  3240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3241. // return
  3242. // }
  3243. // }
  3244. //}
  3245. // 查询信息规挡的设置天数
  3246. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3247. if infor.ID > 0 && infor.WeekDay > 0 {
  3248. var cha_time int64
  3249. timeNowStr := time.Now().Format("2006-01-02")
  3250. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3251. //今日的日期减去设置的日期
  3252. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3253. if cha_time >= recordDate.Unix() {
  3254. //查询审核是否允许
  3255. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3256. //申请状态不允许的情况 拒绝修改
  3257. if infor.ApplicationStatus != 1 {
  3258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3259. return
  3260. }
  3261. }
  3262. }
  3263. prescription := models.DialysisPrescription{
  3264. UserOrgId: adminUserInfo.Org.Id,
  3265. PatientId: id,
  3266. RecordDate: recordDate.Unix(),
  3267. ModeId: mode_id,
  3268. DialysisDuration: dialysis_duration,
  3269. Dialyzer: dialyzer,
  3270. PerfusionApparatus: perfusion_apparatus,
  3271. BloodFlowVolume: blood_flow_volume,
  3272. DewaterAmount: dewater_amount,
  3273. DisplaceLiqui: displace_liqui,
  3274. ReplacementWay: replacement_way,
  3275. Anticoagulant: anticoagulant,
  3276. AnticoagulantShouji: anticoagulant_shouji,
  3277. AnticoagulantWeichi: anticoagulant_weichi,
  3278. AnticoagulantZongliang: anticoagulant_zongliang,
  3279. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3280. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3281. Kalium: kalium,
  3282. Sodium: sodium,
  3283. Calcium: calcium,
  3284. Bicarbonate: bicarbonate,
  3285. Glucose: glucose,
  3286. // DryWeight: dry_weight,
  3287. DialysateFlow: dialysate_flow,
  3288. DialysateTemperature: dialysate_temperature,
  3289. Conductivity: conductivity,
  3290. Remark: remark,
  3291. Status: 1,
  3292. CreatedTime: time.Now().Unix(),
  3293. UpdatedTime: time.Now().Unix(),
  3294. DialysisDurationMinute: dialysisDurationMinute,
  3295. DialysisDurationHour: dialysisDurationHour,
  3296. TargetUltrafiltration: targetUltrafiltration,
  3297. DialysateFormulation: dialysateFormulation,
  3298. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3299. BodyFluid: body_fluid,
  3300. SpecialMedicine: special_medicine,
  3301. SpecialMedicineOther: special_medicine_other,
  3302. DisplaceLiquiPart: displace_liqui_part,
  3303. DisplaceLiquiValue: displace_liqui_value,
  3304. BloodAccess: blood_access,
  3305. Ultrafiltration: ultrafiltration,
  3306. BodyFluidOther: body_fluid_other,
  3307. ReplacementTotal: replacement_total,
  3308. Niprocart: niprocart,
  3309. Jms: jms,
  3310. FistulaNeedleSet: fistula_needle_set,
  3311. FistulaNeedleSet16: fistula_needle_set_16,
  3312. Hemoperfusion: hemoperfusion,
  3313. DialyserSterilised: dialyser_sterilised,
  3314. Filtryzer: filtryzer,
  3315. TargetKtv: target_ktv,
  3316. Dialyzers: dialyzers,
  3317. Injector: injector,
  3318. Bloodlines: bloodlines,
  3319. TubingHemodialysis: tubing_hemodialysis,
  3320. Package: safe_package,
  3321. ALiquid: a_liquid,
  3322. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3323. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3324. Blood: blood,
  3325. DialysisDialyszers: dialysis_dialyszers,
  3326. DialysisIrrigation: dialysis_irrigation,
  3327. AntioxidantCommodityName: antioxidant_commodity_name,
  3328. DisplaceSpeed: displace_speed,
  3329. Illness: illness,
  3330. Amylaceum: amylaceum,
  3331. SingleWater: single_water,
  3332. SingleTime: single_time,
  3333. ReplacementFlow: replacement_flow,
  3334. PlasmaSeparator: plasma_separator,
  3335. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3336. OxygenUptake: oxygen_uptake,
  3337. OxygenTime: oxygen_time,
  3338. OxygenFlow: oxygen_flow,
  3339. HemodialysisPipelines: hemodialysis_pipelines,
  3340. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3341. PunctureNeedle: puncture_needle,
  3342. PunctureNeedleCount: puncture_needle_count,
  3343. Epo: epo,
  3344. EpoCount: epo_count,
  3345. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3346. PreImpulse: impulse,
  3347. AdminUserId: admin_user_id,
  3348. IsWater: is_war,
  3349. DrhyWater: drhy_water,
  3350. DryWaterHour: dry_water_hour,
  3351. WaterMachine: water_machine,
  3352. AddAmount: add_amount,
  3353. ReduceAmount: reduce_amount,
  3354. DialysisRemark: dialysis_remark,
  3355. PrescribingNumber: prescribing_number,
  3356. PrescriptionSodium: prescription_sodium,
  3357. StartSodium: start_sodium,
  3358. SodiumCurve: sodium_curve,
  3359. TreatmentRemark: treatment_remark,
  3360. DialysisFluidFlow: dialysis_fluid_flow,
  3361. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3362. PrescriptionWater: prescription_water,
  3363. DialysisStrainer: dialysis_strainer,
  3364. Chaptalization: chaptalization,
  3365. WashingTime: washing_time,
  3366. WarshCount: warsh_count,
  3367. BloodAccessPartId: blood_access_part_id,
  3368. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3369. Dialyzate: dialyzate,
  3370. }
  3371. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3372. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3373. //
  3374. if appRole.UserType == 2 || appRole.UserType == 1 {
  3375. prescription_doctor = adminUserInfo.AdminUser.Id
  3376. prescription.PrescriptionDoctor = prescription_doctor
  3377. }
  3378. if dialysisPrescription.ID == 0 { //新增
  3379. prescription.Creater = adminUserInfo.AdminUser.Id
  3380. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3381. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3382. }
  3383. } else { //修改
  3384. if dialysisPrescription.Creater == 0 {
  3385. prescription.Creater = adminUserInfo.AdminUser.Id
  3386. } else {
  3387. prescription.Creater = dialysisPrescription.Creater
  3388. if adminUserInfo.Org.Id == 9882 {
  3389. if appRole.UserType == 2 || appRole.UserType == 1 {
  3390. prescription.Creater = adminUserInfo.AdminUser.Id
  3391. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3392. }
  3393. }
  3394. }
  3395. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3396. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3397. }
  3398. //if/**/
  3399. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3400. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3401. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3402. // if getPermissionErr != nil {
  3403. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3404. // return
  3405. // } else if headNursePermission == nil {
  3406. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3407. // return
  3408. // }
  3409. //}
  3410. //prescription.Creater = dialysisPrescription.Creater
  3411. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3412. prescription.Modifier = adminUserInfo.AdminUser.Id
  3413. prescription.ID = dialysisPrescription.ID
  3414. }
  3415. solution := models.DialysisSolution{
  3416. RegistrarsId: adminUserInfo.AdminUser.Id,
  3417. UserOrgId: adminUserInfo.Org.Id,
  3418. Doctor: prescription_doctor,
  3419. PatientId: id,
  3420. ModeId: mode_id,
  3421. DialysisDuration: dialysis_duration,
  3422. PerfusionApparatus: perfusion_apparatus,
  3423. BloodFlowVolume: blood_flow_volume,
  3424. Dewater: dewater_amount,
  3425. DisplaceLiqui: displace_liqui,
  3426. ReplacementWay: replacement_way,
  3427. Anticoagulant: anticoagulant,
  3428. AnticoagulantShouji: anticoagulant_shouji,
  3429. AnticoagulantWeichi: anticoagulant_weichi,
  3430. AnticoagulantZongliang: anticoagulant_zongliang,
  3431. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3432. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3433. Kalium: kalium,
  3434. Sodium: sodium,
  3435. Calcium: calcium,
  3436. Bicarbonate: bicarbonate,
  3437. Glucose: glucose,
  3438. // DryWeight: dry_weight,
  3439. DialysateFlow: dialysate_flow,
  3440. DialysateTemperature: dialysate_temperature,
  3441. Conductivity: conductivity,
  3442. Remark: remark,
  3443. Status: 1,
  3444. CreatedTime: time.Now().Unix(),
  3445. UpdatedTime: time.Now().Unix(),
  3446. DialysisDurationMinute: dialysisDurationMinute,
  3447. DialysisDurationHour: dialysisDurationHour,
  3448. TargetUltrafiltration: targetUltrafiltration,
  3449. DialysateFormulation: dialysateFormulation,
  3450. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3451. BodyFluid: body_fluid,
  3452. SpecialMedicine: special_medicine,
  3453. SpecialMedicineOther: special_medicine_other,
  3454. DisplaceLiquiPart: displace_liqui_part,
  3455. DisplaceLiquiValue: displace_liqui_value,
  3456. BloodAccess: blood_access,
  3457. Ultrafiltration: ultrafiltration,
  3458. BodyFluidOther: body_fluid_other,
  3459. ReplacementTotal: replacement_total,
  3460. TargetKtv: target_ktv,
  3461. DialysisDialyszers: dialysis_dialyszers,
  3462. DialysisIrrigation: dialysis_irrigation,
  3463. HemodialysisPipelines: hemodialysis_pipelines,
  3464. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3465. PunctureNeedle: puncture_needle,
  3466. PunctureNeedleCount: puncture_needle_count,
  3467. Epo: epo,
  3468. EpoCount: epo_count,
  3469. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3470. PreImpulse: impulse,
  3471. SolutionStatus: 1,
  3472. DialysisRemark: dialysis_remark,
  3473. PrescribingNumber: prescribing_number,
  3474. PrescriptionSodium: prescription_sodium,
  3475. StartSodium: start_sodium,
  3476. SodiumCurve: sodium_curve,
  3477. TreatmentRemark: treatment_remark,
  3478. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3479. DialysisFluidFlow: dialysis_fluid_flow,
  3480. PrescriptionWater: prescription_water,
  3481. DialysisStrainer: dialysis_strainer,
  3482. Chaptalization: chaptalization,
  3483. WashingTime: washing_time,
  3484. WarshCount: warsh_count,
  3485. BloodAccessPartId: blood_access_part_id,
  3486. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3487. Dialyzate: dialyzate,
  3488. }
  3489. //针对河间咸的
  3490. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3491. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3492. solution.DisplaceLiquiPart = 0
  3493. solution.DisplaceLiquiValue = 0
  3494. }
  3495. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3496. prescription.DisplaceLiquiPart = 0
  3497. prescription.DisplaceLiquiValue = 0
  3498. }
  3499. }
  3500. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3501. if solution.PrescribingNumber == 0 {
  3502. solution.PrescribingNumber = 1
  3503. }
  3504. if prescription.PrescribingNumber == 0 {
  3505. prescription.PrescribingNumber = 1
  3506. }
  3507. if solution.PrescribingNumber == 0 && id == 14682 {
  3508. solution.PrescribingNumber = 2
  3509. }
  3510. if solution.PrescribingNumber == 0 && id == 18560 {
  3511. solution.PrescribingNumber = 2
  3512. }
  3513. if prescription.PrescribingNumber == 0 && id == 14682 {
  3514. prescription.PrescribingNumber = 2
  3515. }
  3516. if prescription.PrescribingNumber == 0 && id == 18560 {
  3517. prescription.PrescribingNumber = 2
  3518. }
  3519. }
  3520. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3521. //记录日志
  3522. byterequest, _ := json.Marshal(prescription)
  3523. prescriptionLog := models.XtDialysisPrescriptionLog{
  3524. UserOrgId: prescription.UserOrgId,
  3525. Ctime: time.Now().Unix(),
  3526. Mtime: 0,
  3527. ErrLog: string(byterequest),
  3528. AdminUserId: adminUserInfo.AdminUser.Id,
  3529. RecordDate: prescription.RecordDate,
  3530. PatientId: prescription.PatientId,
  3531. Source: "手机端新增处方",
  3532. Status: 1,
  3533. }
  3534. service.CreatePrescriptionLog(prescriptionLog)
  3535. finish := models.XtDialysisFinish{
  3536. IsFinish: 1,
  3537. UserOrgId: adminUserInfo.Org.Id,
  3538. Status: 1,
  3539. Ctime: time.Now().Unix(),
  3540. Mtime: 0,
  3541. Module: 1,
  3542. RecordDate: recordDate.Unix(),
  3543. Sourse: 1,
  3544. PatientId: id,
  3545. }
  3546. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3547. if dialysisFinish.ID == 0 {
  3548. service.CreateDialysisFinish(finish)
  3549. }
  3550. //获取最新1条
  3551. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3552. //更新状态
  3553. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3554. //长沙南雅医院,自动生成抗凝剂的临时处方
  3555. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3556. if prescribing_number == 0 {
  3557. prescribing_number = 1
  3558. }
  3559. advice := models.DoctorAdvice{
  3560. UserOrgId: adminUserInfo.Org.Id,
  3561. PatientId: id,
  3562. GroupNo: 0,
  3563. AdviceType: 2,
  3564. RecordDate: recordDate.Unix(),
  3565. AdviceDate: recordDate.Unix(),
  3566. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3567. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3568. AdviceDesc: "",
  3569. ReminderDate: 0,
  3570. SingleDose: prescription.AnticoagulantZongliang,
  3571. SingleDoseUnit: "iu",
  3572. DrugSpec: 0,
  3573. DrugSpecUnit: "",
  3574. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3575. PrescribingNumberUnit: "支",
  3576. DeliveryWay: "静脉注射",
  3577. ExecutionFrequency: "上机前",
  3578. AdviceDoctor: 0,
  3579. Status: 1,
  3580. CreatedTime: time.Now().Unix(),
  3581. UpdatedTime: time.Now().Unix(),
  3582. IsPrescription: 1,
  3583. ExecutionState: 2,
  3584. StopState: 2,
  3585. IsSettle: 2,
  3586. }
  3587. // 查询排班信息
  3588. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3589. if schedulePatient.ID > 0 {
  3590. if schedulePatient.ScheduleType == 1 {
  3591. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3592. }
  3593. if schedulePatient.ScheduleType == 2 {
  3594. advice.StartTime = recordDate.Unix() + 10*60*60
  3595. }
  3596. }
  3597. // 抗凝剂名称
  3598. switch anticoagulant {
  3599. case 1:
  3600. advice.AdviceName = "无肝素"
  3601. break
  3602. case 2:
  3603. advice.AdviceName = "普通肝素"
  3604. break
  3605. case 3:
  3606. advice.AdviceName = "低分子肝素"
  3607. break
  3608. case 4:
  3609. advice.AdviceName = "阿加曲班"
  3610. break
  3611. case 5:
  3612. advice.AdviceName = "枸橼酸钠"
  3613. break
  3614. case 6:
  3615. advice.AdviceName = "低分子肝素钙"
  3616. break
  3617. case 7:
  3618. advice.AdviceName = "低分子肝素钠"
  3619. break
  3620. case 8:
  3621. advice.AdviceName = "依诺肝素"
  3622. break
  3623. case 9:
  3624. advice.AdviceName = "达肝素"
  3625. break
  3626. case 10:
  3627. advice.AdviceName = "体外抗凝"
  3628. break
  3629. case 11:
  3630. advice.AdviceName = "那曲肝素"
  3631. break
  3632. case 12:
  3633. advice.AdviceName = "无抗凝剂"
  3634. break
  3635. }
  3636. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3637. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3638. advice.AdviceDoctor = appRole.AdminUserId
  3639. }
  3640. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3641. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3642. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3643. advice.AdviceName = "低分子肝素钠注射液"
  3644. // 修改患者临时医嘱里的抗凝剂医嘱
  3645. advice.ID = advicePrescription.ID
  3646. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3647. } else {
  3648. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3649. advice.AdviceName = "低分子肝素钠注射液"
  3650. service.CreateDoctorAdvice(&advice)
  3651. }
  3652. }
  3653. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3654. redis := service.RedisClient()
  3655. defer redis.Close()
  3656. //清空key 值
  3657. redis.Set(key, "", time.Second)
  3658. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3659. redis.Set(keyOne, "", time.Second)
  3660. }
  3661. //获取key,清空redis
  3662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3663. redis := service.RedisClient()
  3664. defer redis.Close()
  3665. //清空key 值
  3666. redis.Set(key, "", time.Second)
  3667. //清空长期医嘱的key
  3668. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3669. redis.Set(soulution_key, "", time.Second)
  3670. //查询最近透析准备表里是否存在 透析器 灌流器
  3671. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3672. redis.Set(keyOne, "", time.Second)
  3673. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3674. redis.Set(keyTwo, "", time.Second)
  3675. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3676. redis.Set(keyThree, "", time.Second)
  3677. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3678. redis.Set(keyFour, "", time.Second)
  3679. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3680. //
  3681. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3682. //
  3683. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3684. //if len(mation)>0{
  3685. // for _, item := range splitStr {
  3686. // for _,it := range mation{
  3687. // if(item == it.SpecificationName){
  3688. //
  3689. // //查询最近一次的透析器
  3690. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3691. //
  3692. // if errcode == gorm.ErrRecordNotFound{
  3693. // //插入数据
  3694. // prepare := models.DialysisBeforePrepare{
  3695. // UserOrgId: adminUserInfo.Org.Id,
  3696. // PatientId: id,
  3697. // RecordDate: recordDate.Unix(),
  3698. // GoodTypeId: it.GoodTypeId,
  3699. // GoodId: it.ID,
  3700. // Count: 1,
  3701. // Ctime: time.Now().Unix(),
  3702. // Creater: adminUserInfo.AdminUser.Id,
  3703. // Status:1,
  3704. //
  3705. // }
  3706. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3707. // fmt.Println("",errcode)
  3708. // }
  3709. // }
  3710. // }
  3711. //
  3712. // }
  3713. //
  3714. // for _, item := range splitIrrigation {
  3715. // for _,it := range mation{
  3716. // if(item == it.SpecificationName){
  3717. // //查询最近一次的透析器
  3718. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3719. // if errcode == gorm.ErrRecordNotFound{
  3720. // //插入数据
  3721. // prepare := models.DialysisBeforePrepare{
  3722. // UserOrgId: adminUserInfo.Org.Id,
  3723. // PatientId: id,
  3724. // RecordDate: recordDate.Unix(),
  3725. // GoodTypeId: it.GoodTypeId,
  3726. // GoodId: it.ID,
  3727. // Count: 1,
  3728. // Ctime: time.Now().Unix(),
  3729. // Creater: adminUserInfo.AdminUser.Id,
  3730. // Status:1,
  3731. //
  3732. // }
  3733. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3734. // fmt.Println(errcode)
  3735. // }
  3736. // }
  3737. // }
  3738. // }
  3739. //}
  3740. c.ServeSuccessJSON(map[string]interface{}{
  3741. "solution": &solution,
  3742. "prescription": &prescription,
  3743. })
  3744. }
  3745. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3746. patient, _ := c.GetInt64("patient", 0)
  3747. adminUserInfo := c.GetMobileAdminUserInfo()
  3748. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3749. c.ServeSuccessJSON(map[string]interface{}{
  3750. "receiveTreatmentAsses": receiveTreatmentAsses,
  3751. })
  3752. }
  3753. func (this *DialysisAPIController) PostSignInfo() {
  3754. patientID, _ := this.GetInt64("patient_id")
  3755. recordDateStr := this.GetString("date")
  3756. if patientID <= 0 {
  3757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3758. return
  3759. }
  3760. if len(recordDateStr) == 0 {
  3761. recordDateStr = time.Now().Format("2006-01-02")
  3762. }
  3763. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3764. if parseDateErr != nil {
  3765. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3766. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3767. return
  3768. }
  3769. adminInfo := this.GetMobileAdminUserInfo()
  3770. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3771. if err != nil {
  3772. this.ErrorLog("签名失败:%v", err)
  3773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3774. return
  3775. }
  3776. this.ServeSuccessJSON(map[string]interface{}{
  3777. "doctor_id": adminInfo.AdminUser.Id,
  3778. })
  3779. }
  3780. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3781. patientID, _ := this.GetInt64("patient_id")
  3782. adminInfo := this.GetMobileAdminUserInfo()
  3783. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3784. this.ServeSuccessJSON(map[string]interface{}{
  3785. "monitor": record,
  3786. })
  3787. }
  3788. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3789. thisTime := time.Now()
  3790. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3791. timeLayout := "2006-01-02 15:04:05"
  3792. loc, _ := time.LoadLocation("Local")
  3793. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3794. theAssessmentDateTime := theStartTime.Unix()
  3795. patientID, _ := this.GetInt64("patient_id")
  3796. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3797. adminInfo := this.GetMobileAdminUserInfo()
  3798. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3799. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3800. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3801. var ultrafiltration_rate float64
  3802. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3803. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3804. fmt.Println(evaluation)
  3805. fmt.Println("prescription.ID", prescription.ID)
  3806. if prescription.ID > 0 {
  3807. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3808. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3809. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3810. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3811. record.UltrafiltrationRate = ultrafiltration_rate
  3812. }
  3813. if adminInfo.Org.Id == 10597 {
  3814. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3815. record.UltrafiltrationRate = ultrafiltration_rate
  3816. }
  3817. if adminInfo.Org.Id == 10510 {
  3818. record.UltrafiltrationRate = 0
  3819. }
  3820. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3821. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3822. record.UltrafiltrationRate = ultrafiltration_rate
  3823. }
  3824. if template.TemplateId == 20 || template.TemplateId == 22 {
  3825. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3826. record.UltrafiltrationRate = ultrafiltration_rate
  3827. }
  3828. // 只针对方济医院
  3829. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3830. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3831. ultrafiltration_rate = value
  3832. record.UltrafiltrationRate = ultrafiltration_rate
  3833. }
  3834. if template.TemplateId == 41 || template.TemplateId == 47 {
  3835. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3836. record.UltrafiltrationRate = ultrafiltration_rate
  3837. }
  3838. if template.TemplateId == 43 {
  3839. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3840. record.UltrafiltrationRate = ultrafiltration_rate
  3841. }
  3842. if template.TemplateId == 46 || template.TemplateId == 54 {
  3843. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3844. record.UltrafiltrationRate = ultrafiltration_rate
  3845. }
  3846. 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 {
  3847. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3848. record.UltrafiltrationRate = ultrafiltration_rate
  3849. }
  3850. if adminInfo.Org.Id == 10469 {
  3851. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3852. record.UltrafiltrationRate = ultrafiltration_rate
  3853. }
  3854. if adminInfo.Org.Id == 10471 {
  3855. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3856. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3857. }
  3858. if adminInfo.Org.Id == 10460 {
  3859. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3860. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3861. }
  3862. if adminInfo.Org.Id == 10551 {
  3863. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3864. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3865. }
  3866. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 {
  3867. record.UltrafiltrationRate = 0
  3868. }
  3869. //if template.TemplateId == 47 {
  3870. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3871. // record.UltrafiltrationRate = ultrafiltration_rate
  3872. //}
  3873. }
  3874. }
  3875. // record.UltrafiltrationRate = ultrafiltration_rate
  3876. record.UltrafiltrationVolume = 0
  3877. 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
  3878. if ultrafiltration_rate > 0 {
  3879. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3880. record.UltrafiltrationVolume = value
  3881. }
  3882. }
  3883. 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
  3884. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3885. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3886. record.UltrafiltrationVolume = ultrafiltration_volume
  3887. }
  3888. }
  3889. if adminInfo.Org.Id == 10597 {
  3890. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3891. record.UltrafiltrationVolume = ultrafiltration_volume
  3892. }
  3893. //长沙南雅
  3894. 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 {
  3895. if ultrafiltration_rate > 0 {
  3896. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3897. record.UltrafiltrationVolume = ultrafiltration_volume
  3898. }
  3899. }
  3900. if adminInfo.Org.Id == 10471 {
  3901. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3902. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3903. }
  3904. if adminInfo.Org.Id == 10460 {
  3905. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3906. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3907. }
  3908. if adminInfo.Org.Id == 10551 {
  3909. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3910. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3911. }
  3912. //长沙南雅累计血容量自动计算
  3913. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3914. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3915. //}
  3916. if template.TemplateId == 47 || template.TemplateId == 54 {
  3917. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3918. }
  3919. if adminInfo.Org.Id == 10510 {
  3920. record.UltrafiltrationVolume = 0
  3921. }
  3922. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  3923. this.ServeSuccessJSON(map[string]interface{}{
  3924. "monitor": record,
  3925. "lastMonitorRecordList": lastMonitorRecordList,
  3926. })
  3927. }
  3928. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3929. record_id, _ := this.GetInt64("id")
  3930. nurseID, _ := this.GetInt64("start_nurse")
  3931. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3932. bedID, _ := this.GetInt64("bed")
  3933. start_time := this.GetString("start_time")
  3934. schedual_type, _ := this.GetInt64("schedual_type")
  3935. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3936. change_nurse, _ := this.GetInt64("change_nurse")
  3937. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3938. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3939. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3940. fmt.Println("quality_nurse_id", quality_nurse_id)
  3941. patient_id, _ := this.GetInt64("patient_id")
  3942. record_date, _ := this.GetInt64("record_date")
  3943. puncture_needle := this.GetString("puncture_needle")
  3944. puncture_way := this.GetString("puncture_way")
  3945. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3946. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3947. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3948. nuclein_date_str := this.GetString("nuclein_date_str")
  3949. order_remark := this.GetString("order_remark")
  3950. schedule_remark := this.GetString("schedule_remark")
  3951. catheter_operation := this.GetString("catheter_operation")
  3952. blood_flow_volume := this.GetString("blood_flow_volume")
  3953. if record_id == 0 {
  3954. this.ErrorLog("id:%v", record_id)
  3955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3956. return
  3957. }
  3958. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3959. if parseStartDateErr != nil {
  3960. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3962. return
  3963. }
  3964. adminUserInfo := this.GetMobileAdminUserInfo()
  3965. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3966. if getNurseErr != nil {
  3967. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3969. return
  3970. } else if nurse == nil {
  3971. this.ErrorLog("护士不存在")
  3972. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3973. return
  3974. }
  3975. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3976. //if getNurseErr != nil {
  3977. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3978. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3979. // return
  3980. //} else if nurse == nil {
  3981. // this.ErrorLog("护士不存在")
  3982. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3983. // return
  3984. //}
  3985. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3986. if getDeviceNumberErr != nil {
  3987. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3988. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3989. return
  3990. } else if deviceNumber == nil {
  3991. this.ErrorLog("床位号不存在")
  3992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3993. return
  3994. }
  3995. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  3996. //
  3997. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  3998. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3999. // if getPermissionErr != nil {
  4000. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4001. // return
  4002. // } else if headNursePermission == nil {
  4003. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4004. // return
  4005. // }
  4006. //}
  4007. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4008. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4009. timeLayout := "2006-01-02 15:04:05"
  4010. loc, _ := time.LoadLocation("Local")
  4011. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4012. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4013. schedulestartTime := theStartTime.Unix()
  4014. scheduleendTime := theEndTime.Unix()
  4015. var theNucleinDate int64
  4016. timeLayoutOne := "2006-01-02"
  4017. if len(nuclein_date_str) > 0 {
  4018. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4019. if err != nil {
  4020. utils.ErrorLog(err.Error())
  4021. }
  4022. theNucleinDate = theTime.Unix()
  4023. }
  4024. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4025. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4026. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4027. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4028. if err == gorm.ErrRecordNotFound { //空床位
  4029. // 修改了床位逻辑
  4030. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4031. if daySchedule.ID > 0 {
  4032. //daySchedule.BedId = bedID
  4033. //daySchedule.PartitionId = deviceNumber.ZoneID
  4034. //daySchedule.ScheduleType = schedual_type
  4035. //daySchedule.UpdatedTime = time.Now().Unix()
  4036. //err := service.UpdateSchedule(&daySchedule)
  4037. xtSchedule := models.Schedule{
  4038. PartitionId: deviceNumber.ZoneID,
  4039. BedId: bedID,
  4040. ScheduleType: schedual_type,
  4041. UpdatedTime: time.Now().Unix(),
  4042. }
  4043. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4044. if err != nil {
  4045. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4046. return
  4047. }
  4048. }
  4049. } else if err == nil {
  4050. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4051. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4052. if daySchedule.ID > 0 {
  4053. //daySchedule.BedId = bedID
  4054. //daySchedule.PartitionId = deviceNumber.ZoneID
  4055. //
  4056. //daySchedule.ScheduleType = schedual_type
  4057. //daySchedule.UpdatedTime = time.Now().Unix()
  4058. //err := service.UpdateSchedule(&daySchedule)
  4059. xtSchedule := models.Schedule{
  4060. PartitionId: deviceNumber.ZoneID,
  4061. BedId: bedID,
  4062. ScheduleType: schedual_type,
  4063. UpdatedTime: time.Now().Unix(),
  4064. }
  4065. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4066. if err != nil {
  4067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4068. return
  4069. }
  4070. }
  4071. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4073. return
  4074. }
  4075. } else if err != nil {
  4076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4077. return
  4078. }
  4079. }
  4080. dialysisRecord := &models.DialysisOrder{
  4081. ID: record_id,
  4082. UserOrgId: adminUserInfo.Org.Id,
  4083. BedID: bedID,
  4084. StartNurse: nurseID,
  4085. StartTime: startDate.Unix(),
  4086. PunctureNurse: puncture_nurse,
  4087. Creator: adminUserInfo.AdminUser.Id,
  4088. Modifier: adminUserInfo.AdminUser.Id,
  4089. WashpipeNurse: washpipe_nurse,
  4090. SchedualType: schedual_type,
  4091. ChangeNurse: change_nurse,
  4092. DifficultPunctureNurse: difficult_puncture_nurse,
  4093. NewFistulaNurse: new_fistula_nurse,
  4094. QualityNurseId: quality_nurse_id,
  4095. PunctureNeedle: puncture_needle,
  4096. PunctureWay: puncture_way,
  4097. DialysisDialyszers: dialysis_dialyszers,
  4098. DialysisIrrigation: dialysis_irrigation,
  4099. BloodAccessId: blood_access_id,
  4100. NucleinDate: theNucleinDate,
  4101. OrderRemark: order_remark,
  4102. ScheduleRemark: schedule_remark,
  4103. CatheterOperation: catheter_operation,
  4104. BloodFlowVolume: blood_flow_volume,
  4105. }
  4106. //修改床位号需要重新消毒
  4107. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4108. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4109. //查询第一条监测
  4110. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4111. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4112. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4113. redis := service.RedisClient()
  4114. //清空key 值
  4115. redis.Set(key, "", time.Second)
  4116. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4117. redis.Set(keyOne, "", time.Second)
  4118. defer redis.Close()
  4119. }
  4120. // 查询信息规挡的设置天数
  4121. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4122. if infor.ID > 0 && infor.WeekDay > 0 {
  4123. var cha_time int64
  4124. timeNowStr := time.Now().Format("2006-01-02")
  4125. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4126. //今日的日期减去设置的日期
  4127. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4128. if cha_time >= record_date {
  4129. //查询审核是否允许
  4130. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4131. //申请状态不允许的情况 拒绝修改
  4132. if infor.ApplicationStatus != 1 {
  4133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4134. return
  4135. }
  4136. }
  4137. }
  4138. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4139. order, _ := service.GetLastPatientOrder(record_id)
  4140. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4141. redis := service.RedisClient()
  4142. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4143. redis.Set(key, "", time.Second)
  4144. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4145. //清空key 值
  4146. redis.Set(keyOne, "", time.Second)
  4147. scheduleDateStartOne := startDate.Format("2006-01-02")
  4148. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4149. redis.Set(keyTwo, "", time.Second)
  4150. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4151. redis.Set(keyThree, "", time.Second)
  4152. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4153. redis.Set(keyFour, "", time.Second)
  4154. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4155. redis.Set(keyFive, "", time.Second)
  4156. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4157. redis.Set(keySix, "", time.Second)
  4158. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4159. redis.Set(keySeven, "", time.Second)
  4160. if updateErr != nil {
  4161. this.ErrorLog("修改上机失败:%v", updateErr)
  4162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4163. return
  4164. }
  4165. if updateErr == nil {
  4166. if tempDialysisRecord.Stage == 2 {
  4167. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4168. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4169. fmt.Println(value)
  4170. a, b := math.Modf(value)
  4171. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4172. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4173. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4174. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4175. redis := service.RedisClient()
  4176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4177. redis.Set(key, "", time.Second)
  4178. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4179. redis.Set(keyOne, "", time.Second)
  4180. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4181. //清空key 值
  4182. redis.Set(keySix, "", time.Second)
  4183. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4184. redis.Set(keySeven, "", time.Second)
  4185. redis.Close()
  4186. if updateAssessmentErr != nil {
  4187. utils.ErrorLog("%v", updateAssessmentErr)
  4188. }
  4189. }
  4190. }
  4191. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4192. this.ServeSuccessJSON(map[string]interface{}{
  4193. "dialysis_order": dialysisRecords,
  4194. })
  4195. }
  4196. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4197. record_id, _ := c.GetInt64("id")
  4198. nurseID, _ := c.GetInt64("nurse")
  4199. end_time := c.GetString("end_time")
  4200. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4201. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4202. catheter := c.GetString("catheter")
  4203. cruor := c.GetString("cruor")
  4204. mission := c.GetString("mission")
  4205. condenser := c.GetString("condenser")
  4206. if record_id <= 0 || nurseID <= 0 {
  4207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4208. return
  4209. }
  4210. adminUserInfo := c.GetMobileAdminUserInfo()
  4211. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4212. if getNurseErr != nil {
  4213. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4215. return
  4216. } else if nurse == nil {
  4217. c.ErrorLog("护士不存在")
  4218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4219. return
  4220. }
  4221. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4222. if parseEndDateErr != nil {
  4223. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4225. return
  4226. }
  4227. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4228. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4229. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4230. // if getPermissionErr != nil {
  4231. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4232. // return
  4233. // } else if headNursePermission == nil {
  4234. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4235. // return
  4236. // }
  4237. //}
  4238. // 查询信息规挡的设置天数
  4239. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4240. if infor.ID > 0 {
  4241. var cha_time int64
  4242. timeNowStr := time.Now().Format("2006-01-02")
  4243. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4244. //今日的日期减去设置的日期
  4245. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4246. if cha_time >= tempDialysisRecords.DialysisDate {
  4247. //查询审核是否允许
  4248. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4249. //申请状态不允许的情况 拒绝修改
  4250. if infor.ApplicationStatus != 1 {
  4251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4252. return
  4253. }
  4254. }
  4255. }
  4256. dialysisRecord := &models.DialysisOrder{
  4257. ID: record_id,
  4258. UserOrgId: adminUserInfo.Org.Id,
  4259. EndTime: endDate.Unix(),
  4260. FinishNurse: nurseID,
  4261. FinishModifier: adminUserInfo.AdminUser.Id,
  4262. PuncturePointHaematoma: puncture_point_haematoma,
  4263. BloodAccessInternalFistula: blood_access_internal_fistula,
  4264. Catheter: catheter,
  4265. Cruor: cruor,
  4266. Mission: mission,
  4267. Condenser: condenser,
  4268. }
  4269. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4270. redis := service.RedisClient()
  4271. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4272. //清空key 值
  4273. redis.Set(key, "", time.Second)
  4274. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4275. //清空key 值
  4276. redis.Set(keyOne, "", time.Second)
  4277. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4278. redis.Set(keySeven, "", time.Second)
  4279. redis.Close()
  4280. if updateErr != nil {
  4281. c.ErrorLog("修改下机失败:%v", updateErr)
  4282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4283. return
  4284. }
  4285. if updateErr == nil {
  4286. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4287. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4288. a, b := math.Modf(value)
  4289. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4290. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4291. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4292. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4293. redis := service.RedisClient()
  4294. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4295. redis.Set(keyTen, "", time.Second)
  4296. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4297. redis.Set(keyTwo, "", time.Second)
  4298. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4299. redis.Set(key, "", time.Second)
  4300. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4301. redis.Set(keyThree, "", time.Second)
  4302. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4303. redis.Set(keySeven, "", time.Second)
  4304. defer redis.Close()
  4305. if updateAssessmentErr != nil {
  4306. utils.ErrorLog("%v", updateAssessmentErr)
  4307. }
  4308. }
  4309. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4310. c.ServeSuccessJSON(map[string]interface{}{
  4311. "dialysis_order": dialysisRecords,
  4312. })
  4313. }
  4314. func (c *DialysisAPIController) GetLongAdvice() {
  4315. patient_id, _ := c.GetInt64("id")
  4316. adminUserInfo := c.GetMobileAdminUserInfo()
  4317. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4318. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4319. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4320. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4321. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4322. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4323. c.ServeSuccessJSON(map[string]interface{}{
  4324. "status": "1",
  4325. })
  4326. return
  4327. } else { //开启推送提醒
  4328. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4329. var advice_three []*models.DoctorAdvice
  4330. recordDateStr := time.Now().Format("2006-01-02")
  4331. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4332. nowtime := recordDate.Unix()
  4333. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4334. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4335. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4336. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4337. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4338. for _, advice := range advices {
  4339. if advice.FrequencyType == 3 {
  4340. t := time.Now()
  4341. week := int(t.Weekday())
  4342. fmt.Println(t.Weekday())
  4343. fmt.Println(week)
  4344. switch week {
  4345. case 1:
  4346. if strings.Index(advice.WeekDay, "周一") == -1 {
  4347. advice_three = append(advice_three, advice)
  4348. }
  4349. break
  4350. case 2:
  4351. if strings.Index(advice.WeekDay, "周二") == -1 {
  4352. advice_three = append(advice_three, advice)
  4353. }
  4354. break
  4355. case 3:
  4356. if strings.Index(advice.WeekDay, "周三") == -1 {
  4357. advice_three = append(advice_three, advice)
  4358. }
  4359. break
  4360. case 4:
  4361. if strings.Index(advice.WeekDay, "周四") == -1 {
  4362. advice_three = append(advice_three, advice)
  4363. }
  4364. break
  4365. case 5:
  4366. if strings.Index(advice.WeekDay, "周五") == -1 {
  4367. advice_three = append(advice_three, advice)
  4368. }
  4369. break
  4370. case 6:
  4371. if strings.Index(advice.WeekDay, "周六") == -1 {
  4372. advice_three = append(advice_three, advice)
  4373. }
  4374. break
  4375. case 0:
  4376. if strings.Index(advice.WeekDay, "周日") == -1 {
  4377. advice_three = append(advice_three, advice)
  4378. }
  4379. break
  4380. }
  4381. }
  4382. }
  4383. for _, advice := range advices_two {
  4384. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4385. now := p.Unix()
  4386. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4387. dayStr2 := "-" + dayStr
  4388. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4389. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4390. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4391. for _, ad := range advices {
  4392. advice_three = append(advice_three, ad)
  4393. }
  4394. }
  4395. if err == nil {
  4396. c.ServeSuccessJSON(map[string]interface{}{
  4397. "status": "2",
  4398. "advices": advices,
  4399. "advices_two": RemoveRepeatedElement(advice_three),
  4400. "is_open_remind": config.IsOpenRemind,
  4401. "his_config_open": hisConfig.IsOpen,
  4402. "is_advice_open": is_advice_open.IsAdviceOpen,
  4403. "prescription_open": prescription_open.IsOpen,
  4404. })
  4405. }
  4406. }
  4407. }
  4408. func (c *DialysisAPIController) GetLongAdviceOne() {
  4409. patient_id, _ := c.GetInt64("id")
  4410. startTime := c.GetString("schedule_date")
  4411. timeLayout := "2006-01-02"
  4412. loc, _ := time.LoadLocation("Local")
  4413. var theStartTime int64
  4414. if len(startTime) > 0 {
  4415. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4416. if err != nil {
  4417. utils.ErrorLog(err.Error())
  4418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4419. return
  4420. }
  4421. theStartTime = theTime.Unix()
  4422. }
  4423. adminUserInfo := c.GetMobileAdminUserInfo()
  4424. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4425. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4426. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4427. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4428. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4429. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4430. c.ServeSuccessJSON(map[string]interface{}{
  4431. "status": "1",
  4432. })
  4433. return
  4434. } else { //开启推送提醒
  4435. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4436. var advice_three []*models.DoctorAdvice
  4437. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4438. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4439. for _, advice := range advices {
  4440. if advice.FrequencyType == 3 {
  4441. t := time.Now()
  4442. week := int(t.Weekday())
  4443. fmt.Println(t.Weekday())
  4444. fmt.Println(week)
  4445. switch week {
  4446. case 1:
  4447. if strings.Index(advice.WeekDay, "周一") == -1 {
  4448. advice_three = append(advice_three, advice)
  4449. }
  4450. break
  4451. case 2:
  4452. if strings.Index(advice.WeekDay, "周二") == -1 {
  4453. advice_three = append(advice_three, advice)
  4454. }
  4455. break
  4456. case 3:
  4457. if strings.Index(advice.WeekDay, "周三") == -1 {
  4458. advice_three = append(advice_three, advice)
  4459. }
  4460. break
  4461. case 4:
  4462. if strings.Index(advice.WeekDay, "周四") == -1 {
  4463. advice_three = append(advice_three, advice)
  4464. }
  4465. break
  4466. case 5:
  4467. if strings.Index(advice.WeekDay, "周五") == -1 {
  4468. advice_three = append(advice_three, advice)
  4469. }
  4470. break
  4471. case 6:
  4472. if strings.Index(advice.WeekDay, "周六") == -1 {
  4473. advice_three = append(advice_three, advice)
  4474. }
  4475. break
  4476. case 0:
  4477. if strings.Index(advice.WeekDay, "周日") == -1 {
  4478. advice_three = append(advice_three, advice)
  4479. }
  4480. break
  4481. }
  4482. }
  4483. }
  4484. for _, advice := range advices_two {
  4485. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4486. now := p.Unix()
  4487. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4488. dayStr2 := "-" + dayStr
  4489. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4490. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4491. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4492. for _, ad := range advices {
  4493. advice_three = append(advice_three, ad)
  4494. }
  4495. }
  4496. if err == nil {
  4497. c.ServeSuccessJSON(map[string]interface{}{
  4498. "status": "2",
  4499. "advices": advices,
  4500. "advices_two": RemoveRepeatedElement(advice_three),
  4501. "is_open_remind": config.IsOpenRemind,
  4502. "his_config_open": hisConfig.IsOpen,
  4503. "is_advice_open": is_advice_open.IsAdviceOpen,
  4504. "prescription_open": prescription_open.IsOpen,
  4505. })
  4506. }
  4507. }
  4508. }
  4509. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4510. newArr = make([]*models.DoctorAdvice, 0)
  4511. for i := 0; i < len(arr); i++ {
  4512. repeat := false
  4513. for j := i + 1; j < len(arr); j++ {
  4514. if arr[i].ID == arr[j].ID {
  4515. repeat = true
  4516. break
  4517. }
  4518. }
  4519. if !repeat {
  4520. newArr = append(newArr, arr[i])
  4521. }
  4522. }
  4523. return
  4524. }
  4525. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4526. patient, _ := c.GetInt64("id", 0)
  4527. groupNo, _ := c.GetInt64("groupno", 0)
  4528. if patient <= 0 {
  4529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4530. return
  4531. }
  4532. adminUserInfo := c.GetMobileAdminUserInfo()
  4533. dataBody := make(map[string]interface{}, 0)
  4534. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4535. if err != nil {
  4536. utils.ErrorLog(err.Error())
  4537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4538. return
  4539. }
  4540. utils.ErrorLog("%v", dataBody)
  4541. timeLayout := "2006-01-02 15:04"
  4542. loc, _ := time.LoadLocation("Local")
  4543. timeLayout2 := "2006-01-02"
  4544. loc2, _ := time.LoadLocation("Local")
  4545. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4546. utils.ErrorLog("advice_type")
  4547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4548. return
  4549. }
  4550. adviceType := int64(2)
  4551. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4552. utils.ErrorLog("advice_date")
  4553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4554. return
  4555. }
  4556. adviceDate, _ := dataBody["advice_date"].(string)
  4557. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4558. AdviceDate := theTime.Unix()
  4559. RecordDate := theTime.Unix()
  4560. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4561. utils.ErrorLog("start_time")
  4562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4563. return
  4564. }
  4565. startTime, _ := dataBody["start_time"].(string)
  4566. if len(startTime) == 0 {
  4567. utils.ErrorLog("len(start_time) == 0")
  4568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4569. return
  4570. }
  4571. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4572. if err != nil {
  4573. utils.ErrorLog(err.Error())
  4574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4575. return
  4576. }
  4577. StartTime := theTime.Unix()
  4578. Remark := ""
  4579. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4580. remark, _ := dataBody["remark"].(string)
  4581. Remark = remark
  4582. }
  4583. var advices []*models.GroupAdvice
  4584. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4585. utils.ErrorLog("advices")
  4586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4587. return
  4588. }
  4589. adviceNames := dataBody["advices"].([]interface{})
  4590. for _, adviceNameMap := range adviceNames {
  4591. adviceNameM := adviceNameMap.(map[string]interface{})
  4592. var advice models.GroupAdvice
  4593. advice.Remark = Remark
  4594. advice.AdviceType = adviceType
  4595. advice.StartTime = StartTime
  4596. advice.AdviceDate = AdviceDate
  4597. advice.RecordDate = RecordDate
  4598. advice.Status = 1
  4599. advice.CreatedTime = time.Now().Unix()
  4600. advice.UpdatedTime = time.Now().Unix()
  4601. advice.StopState = 2
  4602. advice.ExecutionState = 2
  4603. advice.UserOrgId = adminUserInfo.Org.Id
  4604. advice.PatientId = patient
  4605. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4606. advice.IsSettle = 2
  4607. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4608. utils.ErrorLog("advice_name")
  4609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4610. return
  4611. }
  4612. adviceName, _ := adviceNameM["advice_name"].(string)
  4613. if len(adviceName) == 0 {
  4614. utils.ErrorLog("len(advice_name) == 0")
  4615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4616. return
  4617. }
  4618. advice.AdviceName = adviceName
  4619. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4620. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4621. advice.DrugSpec = drugSpec
  4622. }
  4623. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4624. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4625. advice.AdviceDesc = adviceDesc
  4626. }
  4627. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4628. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4629. advice.DrugSpecUnit = drugSpecUnit
  4630. }
  4631. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4632. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4633. // advice.SingleDose = singleDose
  4634. //}
  4635. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4636. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4637. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4638. }
  4639. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4640. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4641. advice.SingleDoseUnit = singleDoseUnit
  4642. }
  4643. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4644. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4645. // advice.PrescribingNumber = prescribingNumber
  4646. //}
  4647. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4648. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4649. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4650. }
  4651. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4652. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4653. advice.PrescribingNumberUnit = prescribingNumberUnit
  4654. }
  4655. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4656. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4657. advice.DeliveryWay = deliveryWay
  4658. }
  4659. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4660. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4661. advice.ExecutionFrequency = executionFrequency
  4662. }
  4663. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4664. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4665. advice.FrequencyType = frequency_type
  4666. }
  4667. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4668. day_count := int64(adviceNameM["day_count"].(float64))
  4669. advice.DayCount = day_count
  4670. }
  4671. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4672. week_day, _ := adviceNameM["week_day"].(string)
  4673. advice.WeekDay = week_day
  4674. }
  4675. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4676. way := int64(adviceNameM["way"].(float64))
  4677. advice.Way = way
  4678. }
  4679. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4680. drug_id := int64(adviceNameM["drug_id"].(float64))
  4681. advice.DrugId = drug_id
  4682. }
  4683. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4684. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4685. advice.DrugNameId = drug_name_id
  4686. }
  4687. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4688. remark, _ := adviceNameM["remark"].(string)
  4689. advice.Remark = remark
  4690. }
  4691. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4692. groupno := int64(adviceNameM["groupno"].(float64))
  4693. advice.GroupNo = groupno
  4694. }
  4695. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4696. template_id, _ := adviceNameM["template_id"].(string)
  4697. advice.TemplateId = template_id
  4698. }
  4699. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4700. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4701. advice.ExecutionFrequency = executionFrequency
  4702. }
  4703. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4704. children := adviceNameM["child"].([]interface{})
  4705. if len(children) > 0 {
  4706. for _, childrenMap := range children {
  4707. childMap := childrenMap.(map[string]interface{})
  4708. var child models.GroupAdvice
  4709. child.Remark = Remark
  4710. child.AdviceType = adviceType
  4711. child.StartTime = StartTime
  4712. child.AdviceDate = AdviceDate
  4713. child.RecordDate = RecordDate
  4714. child.Status = 1
  4715. child.CreatedTime = time.Now().Unix()
  4716. child.UpdatedTime = time.Now().Unix()
  4717. child.StopState = 2
  4718. child.ExecutionState = 2
  4719. child.UserOrgId = adminUserInfo.Org.Id
  4720. child.PatientId = patient
  4721. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4722. child.IsSettle = 1
  4723. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4724. utils.ErrorLog("child advice_name")
  4725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4726. return
  4727. }
  4728. childAdviceName, _ := childMap["advice_name"].(string)
  4729. if len(childAdviceName) == 0 {
  4730. utils.ErrorLog("len(child advice_name) == 0")
  4731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4732. return
  4733. }
  4734. child.AdviceName = childAdviceName
  4735. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4736. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4737. child.AdviceDesc = childAdviceDesc
  4738. }
  4739. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4740. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4741. child.DrugSpec = childDrugSpec
  4742. }
  4743. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4744. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4745. child.DrugSpecUnit = childDrugSpecUnit
  4746. }
  4747. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4748. child.SingleDose = childMap["single_dose"].(float64)
  4749. }
  4750. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4751. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4752. child.SingleDoseUnit = childSingleDoseUnit
  4753. }
  4754. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4755. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4756. }
  4757. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4758. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4759. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4760. }
  4761. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4762. groupno := int64(childMap["groupno"].(float64))
  4763. advice.GroupNo = groupno
  4764. }
  4765. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4766. remark, _ := childMap["remark"].(string)
  4767. child.Remark = remark
  4768. }
  4769. child.DeliveryWay = advice.DeliveryWay
  4770. child.ExecutionFrequency = advice.ExecutionFrequency
  4771. advice.Children = append(advice.Children, &child)
  4772. }
  4773. }
  4774. }
  4775. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4776. if temp_advice.ID == 0 {
  4777. advices = append(advices, &advice)
  4778. }
  4779. }
  4780. if len(advices) > 0 {
  4781. finish := models.XtDialysisFinish{
  4782. IsFinish: 1,
  4783. UserOrgId: adminUserInfo.Org.Id,
  4784. Status: 1,
  4785. Ctime: time.Now().Unix(),
  4786. Mtime: 0,
  4787. Module: 4,
  4788. RecordDate: AdviceDate,
  4789. Sourse: 1,
  4790. PatientId: patient,
  4791. }
  4792. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4793. if dialysisFinish.ID == 0 {
  4794. service.CreateDialysisFinish(finish)
  4795. }
  4796. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9671 {
  4797. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4798. for _, item := range advices {
  4799. byterequest, _ := json.Marshal(item)
  4800. adviceLog := models.XtDoctorAdviceLog{
  4801. UserOrgId: adminUserInfo.Org.Id,
  4802. PatientId: patient,
  4803. AdminUserId: adminUserInfo.AdminUser.Id,
  4804. Module: 1,
  4805. ErrLog: string(byterequest),
  4806. Status: 1,
  4807. Ctime: time.Now().Unix(),
  4808. Mtime: 0,
  4809. Source: "手机端医嘱推送",
  4810. RecordDate: item.AdviceDate,
  4811. }
  4812. service.CreateDoctorAdviceLog(adviceLog)
  4813. }
  4814. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4815. redis := service.RedisClient()
  4816. //清空key 值
  4817. redis.Set(key, "", time.Second)
  4818. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4819. redis.Set(keyOne, "", time.Second)
  4820. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4821. defer redis.Close()
  4822. redis.Set(keyThree, "", time.Second)
  4823. if err != nil {
  4824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4825. return
  4826. }
  4827. c.ServeSuccessJSON(map[string]interface{}{
  4828. "msg": "ok",
  4829. "advices": list,
  4830. })
  4831. } else {
  4832. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4833. for _, item := range advices {
  4834. byterequest, _ := json.Marshal(item)
  4835. adviceLog := models.XtDoctorAdviceLog{
  4836. UserOrgId: adminUserInfo.Org.Id,
  4837. PatientId: patient,
  4838. AdminUserId: adminUserInfo.AdminUser.Id,
  4839. Module: 1,
  4840. ErrLog: string(byterequest),
  4841. Status: 1,
  4842. Ctime: time.Now().Unix(),
  4843. Mtime: 0,
  4844. Source: "手机端医嘱推送",
  4845. RecordDate: item.AdviceDate,
  4846. }
  4847. service.CreateDoctorAdviceLog(adviceLog)
  4848. }
  4849. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4850. redis := service.RedisClient()
  4851. //清空key 值
  4852. redis.Set(key, "", time.Second)
  4853. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4854. redis.Set(keyOne, "", time.Second)
  4855. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4856. defer redis.Close()
  4857. redis.Set(keyThree, "", time.Second)
  4858. if err != nil {
  4859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4860. return
  4861. }
  4862. c.ServeSuccessJSON(map[string]interface{}{
  4863. "msg": "ok",
  4864. "advices": list,
  4865. })
  4866. }
  4867. } else {
  4868. c.ServeSuccessJSON(map[string]interface{}{
  4869. "msg": "ok",
  4870. })
  4871. }
  4872. return
  4873. }
  4874. func (c *DialysisAPIController) UploadDryWeight() {
  4875. patient_id, _ := c.GetInt64("id")
  4876. dry_weight, _ := c.GetFloat("dry_weight")
  4877. doctor_id, _ := c.GetInt64("doctor_id")
  4878. remark := c.GetString("remark")
  4879. adminUserInfo := c.GetMobileAdminUserInfo()
  4880. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4881. if err == gorm.ErrRecordNotFound {
  4882. dryWeight := &models.SgjPatientDryweight{
  4883. PatientId: patient_id,
  4884. DryWeight: dry_weight,
  4885. Remakes: remark,
  4886. Ctime: time.Now().Unix(),
  4887. Mtime: time.Now().Unix(),
  4888. Creator: doctor_id,
  4889. Status: 1,
  4890. UserOrgId: adminUserInfo.Org.Id,
  4891. AdjustedValue: "/",
  4892. UserId: adminUserInfo.AdminUser.Id,
  4893. }
  4894. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4895. redis := service.RedisClient()
  4896. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4897. redis.Set(keyOne, "", time.Second)
  4898. loc, _ := time.LoadLocation("Local")
  4899. nowTime := time.Now()
  4900. nowDay := nowTime.Format("2006-01-02")
  4901. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4902. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4903. redis.Set(key, "", time.Second)
  4904. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4905. redis.Set(keyTwo, "", time.Second)
  4906. redis.Close()
  4907. if createErr == nil {
  4908. c.ServeSuccessJSON(map[string]interface{}{
  4909. "msg": "提交成功",
  4910. "weight": dryWeight,
  4911. })
  4912. }
  4913. } else {
  4914. dryWeight := &models.SgjPatientDryweight{
  4915. PatientId: patient_id,
  4916. DryWeight: dry_weight,
  4917. Remakes: remark,
  4918. Ctime: time.Now().Unix(),
  4919. Mtime: time.Now().Unix(),
  4920. Creator: doctor_id,
  4921. Status: 1,
  4922. UserOrgId: adminUserInfo.Org.Id,
  4923. AdjustedValue: "/",
  4924. UserId: adminUserInfo.AdminUser.Id,
  4925. }
  4926. var value float64
  4927. value = dry_weight - weightAdjust.DryWeight
  4928. if value < 0 {
  4929. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4930. } else if value == 0 {
  4931. dryWeight.AdjustedValue = "/"
  4932. } else if value > 0 {
  4933. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4934. }
  4935. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4936. redis := service.RedisClient()
  4937. loc, _ := time.LoadLocation("Local")
  4938. nowTime := time.Now()
  4939. nowDay := nowTime.Format("2006-01-02")
  4940. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4941. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4942. redis.Set(keyOne, "", time.Second)
  4943. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4944. redis.Set(key, "", time.Second)
  4945. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4946. redis.Set(keyTwo, "", time.Second)
  4947. redis.Close()
  4948. if createErr == nil {
  4949. c.ServeSuccessJSON(map[string]interface{}{
  4950. "msg": "提交成功",
  4951. "weight": dryWeight,
  4952. })
  4953. }
  4954. }
  4955. }
  4956. func (c *DialysisAPIController) GetSolution() {
  4957. patient_id, _ := c.GetInt64("patient_id")
  4958. mode_id, _ := c.GetInt64("mode_id")
  4959. adminUserInfo := c.GetMobileAdminUserInfo()
  4960. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4961. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4962. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4963. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4964. if err != nil {
  4965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4966. return
  4967. }
  4968. c.ServeSuccessJSON(map[string]interface{}{
  4969. "solution": solution,
  4970. "prescription": prescription,
  4971. "system_prescription": system_prescription,
  4972. "dialysisPrescription": dialysisPrescription,
  4973. })
  4974. }
  4975. func (c *DialysisAPIController) GetSchedule() {
  4976. schedual_type, _ := c.GetInt64("schedual_type")
  4977. adminUserInfo := c.GetMobileAdminUserInfo()
  4978. scheduleTime, _ := c.GetInt64("record_date")
  4979. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4980. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4981. c.ServeSuccessJSON(map[string]interface{}{
  4982. "number": deviceNumber,
  4983. "list": list,
  4984. })
  4985. }
  4986. func (c *DialysisAPIController) GetPatientId() {
  4987. id, _ := c.GetInt64("id")
  4988. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4989. patientId, _ := service.GetPatientId(id)
  4990. //获取该患者的所有传染病
  4991. list, _ := service.GetPatientInfectious(id)
  4992. c.ServeSuccessJSON(map[string]interface{}{
  4993. "patient": patientId,
  4994. "infectioulist": list,
  4995. })
  4996. }
  4997. func (this *DialysisAPIController) GetDialysisSchedule() {
  4998. schedualDate := this.GetString("date")
  4999. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5000. if parseDateErr != nil {
  5001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5002. return
  5003. }
  5004. adminInfo := this.GetMobileAdminUserInfo()
  5005. orgID := adminInfo.Org.Id
  5006. redis := service.RedisClient()
  5007. defer redis.Close()
  5008. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5009. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5010. if len(scheduals) > 0 {
  5011. //缓存数据
  5012. scheduals_json, err := json.Marshal(scheduals)
  5013. if err == nil {
  5014. redis.Set(key, scheduals_json, time.Second*30)
  5015. }
  5016. }
  5017. this.ServeSuccessJSON(map[string]interface{}{
  5018. "scheduals": scheduals,
  5019. })
  5020. }
  5021. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5022. change_type, _ := this.GetInt64("type", 0)
  5023. record_date := this.GetString("record_time")
  5024. patient_id, _ := this.GetInt64("patient_id", 0)
  5025. timeLayout := "2006-01-02"
  5026. loc, _ := time.LoadLocation("Local")
  5027. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5028. record_time := theAdviceRecordTime.Unix()
  5029. adminUserInfo := this.GetMobileAdminUserInfo()
  5030. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5031. if err == nil {
  5032. if len(advices) == 0 {
  5033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5034. return
  5035. } else {
  5036. this.ServeSuccessJSON(map[string]interface{}{
  5037. "advices": advices,
  5038. "schedule": sch,
  5039. })
  5040. return
  5041. }
  5042. } else {
  5043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5044. return
  5045. }
  5046. }
  5047. func (c *DialysisAPIController) CreateConsumables() {
  5048. record_date := c.GetString("record_time")
  5049. patient_id, _ := c.GetInt64("patient_id", 0)
  5050. active, _ := c.GetInt64("active")
  5051. adminUser := c.GetMobileAdminUserInfo()
  5052. timeLayout := "2006-01-02"
  5053. loc, _ := time.LoadLocation("Local")
  5054. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5055. record_time := theRecordTime.Unix()
  5056. // 查询信息规挡的设置天数
  5057. orgid := c.GetMobileAdminUserInfo().Org.Id
  5058. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5059. if infor.ID > 0 {
  5060. var cha_time int64
  5061. timeNowStr := time.Now().Format("2006-01-02")
  5062. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5063. //今日的日期减去设置的日期
  5064. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5065. if cha_time >= record_time {
  5066. //查询审核是否允许
  5067. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5068. //申请状态不允许的情况 拒绝修改
  5069. if infor.ApplicationStatus != 1 {
  5070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5071. return
  5072. }
  5073. }
  5074. }
  5075. dataBody := make(map[string]interface{}, 0)
  5076. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5077. if err != nil {
  5078. utils.ErrorLog(err.Error())
  5079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5080. return
  5081. }
  5082. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5083. var beforePrepares []*models.DialysisBeforePrepareGoods
  5084. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5085. var dialysisBefor []*models.DialysisBeforePrepare
  5086. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5087. goods, _ := dataBody["goods"].([]interface{})
  5088. if len(goods) > 0 {
  5089. for _, item := range goods {
  5090. items := item.(map[string]interface{})
  5091. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5092. utils.ErrorLog("good_id")
  5093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5094. return
  5095. }
  5096. good_id := int64(items["good_id"].(float64))
  5097. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5098. utils.ErrorLog("good_type_id")
  5099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5100. return
  5101. }
  5102. good_type_id := int64(items["good_type_id"].(float64))
  5103. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5104. utils.ErrorLog("count")
  5105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5106. return
  5107. }
  5108. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5109. commdity_code := items["commdity_code"].(string)
  5110. fmt.Println("commdity", commdity_code)
  5111. prepareGoods := &models.DialysisBeforePrepareGoods{
  5112. GoodTypeId: good_type_id,
  5113. GoodId: good_id,
  5114. Count: count,
  5115. StorehouseId: houseConfig.StorehouseOutInfo,
  5116. }
  5117. beforePrepares = append(beforePrepares, prepareGoods)
  5118. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5119. GoodTypeId: good_type_id,
  5120. GoodId: good_id,
  5121. Count: count,
  5122. StorehouseId: houseConfig.StorehouseOutInfo,
  5123. }
  5124. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5125. prepare := &models.DialysisBeforePrepare{
  5126. GoodTypeId: good_type_id,
  5127. GoodId: good_id,
  5128. Count: count,
  5129. PatientId: patient_id,
  5130. RecordDate: record_time,
  5131. UserOrgId: adminUser.Org.Id,
  5132. Status: 1,
  5133. Ctime: time.Now().Unix(),
  5134. Creater: adminUser.AdminUser.Id,
  5135. CommdityCode: commdity_code,
  5136. StorehouseId: houseConfig.StorehouseOutInfo,
  5137. }
  5138. dialysisBefor = append(dialysisBefor, prepare)
  5139. }
  5140. }
  5141. //查询是否有库存
  5142. for _, item := range dialysisBefor {
  5143. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5144. if err == gorm.ErrRecordNotFound {
  5145. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5146. c.ServeSuccessJSON(map[string]interface{}{
  5147. "message": "1",
  5148. "good_name": goodObj.GoodName,
  5149. "specification_name": goodObj.SpecificationName,
  5150. })
  5151. return
  5152. }
  5153. if err != nil {
  5154. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5155. c.ServeSuccessJSON(map[string]interface{}{
  5156. "message": "1",
  5157. "good_name": goodObj.GoodName,
  5158. "specification_name": goodObj.SpecificationName,
  5159. })
  5160. return
  5161. }
  5162. }
  5163. //新增
  5164. if active == 1 && len(goods) > 0 {
  5165. for _, item := range dialysisBefor {
  5166. dialyPrepareOne := models.DialysisBeforePrepare{
  5167. GoodTypeId: item.GoodTypeId,
  5168. GoodId: item.GoodId,
  5169. PatientId: item.PatientId,
  5170. RecordDate: item.RecordDate,
  5171. UserOrgId: item.UserOrgId,
  5172. Count: item.Count,
  5173. Ctime: time.Now().Unix(),
  5174. Creater: item.Creater,
  5175. CommdityCode: item.CommdityCode,
  5176. Status: 1,
  5177. StorehouseId: houseConfig.StorehouseOutInfo,
  5178. }
  5179. //先清除再插入
  5180. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5181. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5182. //查询默认仓库
  5183. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5184. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5185. var total_count int64
  5186. for _, it := range stockList {
  5187. total_count += it.StockCount
  5188. }
  5189. //基础库插入数据
  5190. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5191. //更新库存
  5192. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5193. var flush_count int64
  5194. for _, it := range goodList {
  5195. flush_count += it.StockCount
  5196. }
  5197. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5198. }
  5199. if err == nil {
  5200. c.ServeSuccessJSON(map[string]interface{}{
  5201. "msg": "保存成功",
  5202. "message": "2",
  5203. })
  5204. return
  5205. } else {
  5206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5207. return
  5208. }
  5209. }
  5210. if len(beforePrepares) > 0 && active == 2 {
  5211. for _, item := range beforePrepares {
  5212. //1.查看该患者该耗材型号最后一次出库数量
  5213. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5214. //判断当前出库数量和最后一次出库数量的大小
  5215. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5216. if item.Count <= goodInfo.Count {
  5217. //退库
  5218. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5219. //查询今日出库数据
  5220. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5221. for _, it := range list {
  5222. prepare := models.DialysisBeforePrepare{
  5223. UserOrgId: it.OrgId,
  5224. PatientId: patient_id,
  5225. RecordDate: it.RecordTime,
  5226. GoodId: it.GoodId,
  5227. GoodTypeId: it.GoodTypeId,
  5228. Count: it.Count,
  5229. Ctime: time.Now().Unix(),
  5230. Creater: adminUser.AdminUser.Id,
  5231. Status: 1,
  5232. StorehouseId: houseConfig.StorehouseOutInfo,
  5233. }
  5234. //删除准备表数据
  5235. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5236. service.CreateDialysisBeforePrepareOne(&prepare)
  5237. }
  5238. }
  5239. var last_total int64
  5240. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5241. if item.Count >= goodInfo.Count {
  5242. //查询当前批次当前耗材最后一条出库数据
  5243. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5244. //计算当前出库和最后一次出库数据相差数据
  5245. last_total = item.Count - lastOutInfo.Count
  5246. //查询该批次剩余库存
  5247. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5248. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5249. if lastInfo.StockCount >= last_total {
  5250. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5251. //查询今日出库数据
  5252. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5253. for _, it := range list {
  5254. prepare := models.DialysisBeforePrepare{
  5255. UserOrgId: it.OrgId,
  5256. PatientId: patient_id,
  5257. RecordDate: it.RecordTime,
  5258. GoodId: it.GoodId,
  5259. GoodTypeId: it.GoodTypeId,
  5260. Count: it.Count,
  5261. Ctime: time.Now().Unix(),
  5262. Creater: adminUser.AdminUser.Id,
  5263. Status: 1,
  5264. StorehouseId: houseConfig.StorehouseOutInfo,
  5265. }
  5266. //删除准备表数据
  5267. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5268. service.CreateDialysisBeforePrepareOne(&prepare)
  5269. //查询默认仓库
  5270. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5271. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5272. var total_count int64
  5273. for _, it := range stockList {
  5274. total_count += it.StockCount
  5275. }
  5276. //基础库插入数据
  5277. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5278. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5279. var flush_count int64
  5280. for _, it := range goodList {
  5281. flush_count += it.StockCount
  5282. }
  5283. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5284. }
  5285. }
  5286. //如果库存不够,则出库到下一个批次
  5287. if lastInfo.StockCount < last_total {
  5288. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5289. //查询今日出库数据
  5290. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5291. for _, it := range list {
  5292. prepare := models.DialysisBeforePrepare{
  5293. UserOrgId: it.OrgId,
  5294. PatientId: patient_id,
  5295. RecordDate: it.RecordTime,
  5296. GoodId: it.GoodId,
  5297. GoodTypeId: it.GoodTypeId,
  5298. Count: it.Count,
  5299. Ctime: time.Now().Unix(),
  5300. Creater: adminUser.AdminUser.Id,
  5301. Status: 1,
  5302. StorehouseId: houseConfig.StorehouseOutInfo,
  5303. }
  5304. //删除准备表数据
  5305. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5306. service.CreateDialysisBeforePrepareOne(&prepare)
  5307. //查询默认仓库
  5308. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5309. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5310. var total_count int64
  5311. for _, it := range stockList {
  5312. total_count += it.StockCount
  5313. }
  5314. //基础库插入数据
  5315. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5316. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5317. var flush_count int64
  5318. for _, it := range goodList {
  5319. flush_count += it.StockCount
  5320. }
  5321. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5322. }
  5323. if err != nil {
  5324. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5325. c.ServeSuccessJSON(map[string]interface{}{
  5326. "message": "1",
  5327. "good_name": goodObj.GoodName,
  5328. "specification_name": goodObj.SpecificationName,
  5329. })
  5330. return
  5331. }
  5332. }
  5333. }
  5334. if err != nil {
  5335. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5336. c.ServeSuccessJSON(map[string]interface{}{
  5337. "message": "1",
  5338. "good_name": goodObj.GoodName,
  5339. "specification_name": goodObj.SpecificationName,
  5340. })
  5341. return
  5342. }
  5343. }
  5344. }
  5345. }
  5346. var errs error
  5347. if errs == nil {
  5348. c.ServeSuccessJSON(map[string]interface{}{
  5349. "msg": "提交成功",
  5350. "message": "2",
  5351. "good_name": "",
  5352. "specification_name": "",
  5353. })
  5354. return
  5355. } else {
  5356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5357. return
  5358. }
  5359. }
  5360. func (c *DialysisAPIController) CreateStockOutInfo() {
  5361. patient_id, _ := c.GetInt64("patient_id", 0)
  5362. record_date := c.GetString("record_time")
  5363. if patient_id <= 0 {
  5364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5365. return
  5366. }
  5367. adminInfo := c.GetMobileAdminUserInfo()
  5368. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5369. timeLayout := "2006-01-02"
  5370. loc, _ := time.LoadLocation("Local")
  5371. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5372. record_time := theRecordTime.Unix()
  5373. // 查询信息规挡的设置天数
  5374. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5375. if infor.ID > 0 && infor.WeekDay > 0 {
  5376. var cha_time int64
  5377. timeNowStr := time.Now().Format("2006-01-02")
  5378. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5379. //今日的日期减去设置的日期
  5380. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5381. if cha_time >= record_time {
  5382. //查询审核是否允许
  5383. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5384. //申请状态不允许的情况 拒绝修改
  5385. if infor.ApplicationStatus != 1 {
  5386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5387. return
  5388. }
  5389. }
  5390. }
  5391. //创建步骤表
  5392. finish := models.XtDialysisFinish{
  5393. IsFinish: 1,
  5394. UserOrgId: adminInfo.Org.Id,
  5395. Status: 1,
  5396. Ctime: time.Now().Unix(),
  5397. Mtime: 0,
  5398. Module: 11,
  5399. RecordDate: record_time,
  5400. Sourse: 1,
  5401. PatientId: patient_id,
  5402. }
  5403. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5404. if dialysisFinish.ID == 0 {
  5405. service.CreateDialysisFinish(finish)
  5406. }
  5407. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5408. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5409. //去重
  5410. consumables = RemoveRepeatedGood(consumables)
  5411. if adminInfo.Org.Id == 9919 {
  5412. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5413. //查询是否有库存
  5414. for _, item := range consumables {
  5415. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5416. if item.Count > warehouse.Count {
  5417. goodErrcode := models.XtGoodErrcode{
  5418. UserOrgId: item.UserOrgId,
  5419. Errcode: "自动出库库存不足",
  5420. GoodId: item.GoodId,
  5421. Status: 1,
  5422. Ctime: time.Now().Unix(),
  5423. Mtime: 0,
  5424. Count: 0,
  5425. StockCount: 0,
  5426. Creater: creator,
  5427. BatchNumberId: warehouse.ID,
  5428. WarehouseOutId: 0,
  5429. }
  5430. service.CreateGoodErrcode(goodErrcode)
  5431. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5432. c.ServeSuccessJSON(map[string]interface{}{
  5433. "message": "1",
  5434. "good_name": goodObj.GoodName,
  5435. "specification_name": goodObj.SpecificationName,
  5436. })
  5437. return
  5438. }
  5439. }
  5440. //查询是否有出库单
  5441. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5442. if err == gorm.ErrRecordNotFound {
  5443. //没有记录,则创建出库单
  5444. timeStr := time.Now().Format("2006-01-02")
  5445. timeArr := strings.Split(timeStr, "-")
  5446. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5447. total = total + 1
  5448. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5449. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5450. number = number + total
  5451. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5452. creater := adminInfo.AdminUser.Id
  5453. warehouseOut := models.WarehouseOut{
  5454. WarehouseOutOrderNumber: warehousing_out_order,
  5455. OperationTime: time.Now().Unix(),
  5456. OrgId: adminInfo.Org.Id,
  5457. Creater: creater,
  5458. Ctime: time.Now().Unix(),
  5459. Status: 1,
  5460. WarehouseOutTime: record_time,
  5461. Dealer: 0,
  5462. Manufacturer: 0,
  5463. Type: 1,
  5464. IsSys: 1,
  5465. StorehouseId: houseConfig.StorehouseOutInfo,
  5466. IsCheck: 1,
  5467. }
  5468. err := service.AddSigleWarehouseOut(&warehouseOut)
  5469. if err != nil {
  5470. goodErrcode := models.XtGoodErrcode{
  5471. UserOrgId: adminInfo.Org.Id,
  5472. Errcode: "创建出库单失败",
  5473. GoodId: 0,
  5474. Status: 1,
  5475. Ctime: time.Now().Unix(),
  5476. Mtime: 0,
  5477. Count: 0,
  5478. StockCount: 0,
  5479. Creater: creator,
  5480. BatchNumberId: 0,
  5481. WarehouseOutId: 0,
  5482. }
  5483. service.CreateGoodErrcode(goodErrcode)
  5484. utils.TraceLog("创建出库单失败 err = %v", err)
  5485. } else {
  5486. for _, item := range consumables {
  5487. //出库
  5488. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5489. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5490. if err == nil {
  5491. goodErrcode := models.XtGoodErrcode{
  5492. UserOrgId: adminInfo.Org.Id,
  5493. Errcode: "自动出库接口报错",
  5494. GoodId: 0,
  5495. Status: 1,
  5496. Ctime: time.Now().Unix(),
  5497. Mtime: 0,
  5498. Count: 0,
  5499. StockCount: 0,
  5500. Creater: creator,
  5501. BatchNumberId: 0,
  5502. WarehouseOutId: 0,
  5503. }
  5504. service.CreateGoodErrcode(goodErrcode)
  5505. utils.TraceLog("创建出库单失败 err = %v", err)
  5506. }
  5507. //查询
  5508. //出库数量相加
  5509. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5510. if errs != nil {
  5511. goodErrcode := models.XtGoodErrcode{
  5512. UserOrgId: item.UserOrgId,
  5513. Errcode: "创建剩余库存字段报错",
  5514. GoodId: item.GoodId,
  5515. Status: 1,
  5516. Ctime: time.Now().Unix(),
  5517. Mtime: 0,
  5518. Count: 0,
  5519. StockCount: 0,
  5520. Creater: creater,
  5521. BatchNumberId: 0,
  5522. WarehouseOutId: 0,
  5523. }
  5524. service.CreateGoodErrcode(goodErrcode)
  5525. }
  5526. }
  5527. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5528. if len(list) == 0 {
  5529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5530. return
  5531. }
  5532. for _, item := range list {
  5533. prepare := models.DialysisBeforePrepare{
  5534. UserOrgId: adminInfo.Org.Id,
  5535. PatientId: patient_id,
  5536. RecordDate: record_time,
  5537. GoodId: item.GoodId,
  5538. GoodTypeId: item.GoodTypeId,
  5539. Count: item.Count,
  5540. Creater: adminInfo.AdminUser.Id,
  5541. Status: 1,
  5542. Ctime: time.Now().Unix(),
  5543. StorehouseId: houseConfig.StorehouseOutInfo,
  5544. }
  5545. //清空准备表数据
  5546. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5547. if err != nil {
  5548. goodErrcode := models.XtGoodErrcode{
  5549. UserOrgId: item.OrgId,
  5550. Errcode: "自动出库清空准备表数据报错",
  5551. GoodId: item.GoodId,
  5552. Status: 1,
  5553. Ctime: time.Now().Unix(),
  5554. Mtime: 0,
  5555. Count: 0,
  5556. StockCount: 0,
  5557. Creater: creater,
  5558. BatchNumberId: 0,
  5559. WarehouseOutId: 0,
  5560. }
  5561. service.CreateGoodErrcode(goodErrcode)
  5562. }
  5563. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5564. if errs != nil {
  5565. goodErrcode := models.XtGoodErrcode{
  5566. UserOrgId: item.OrgId,
  5567. Errcode: "自动出库创建准备表数据报错",
  5568. GoodId: item.GoodId,
  5569. Status: 1,
  5570. Ctime: time.Now().Unix(),
  5571. Mtime: 0,
  5572. Count: 0,
  5573. StockCount: 0,
  5574. Creater: creater,
  5575. BatchNumberId: 0,
  5576. WarehouseOutId: 0,
  5577. }
  5578. service.CreateGoodErrcode(goodErrcode)
  5579. }
  5580. //查询默认仓库
  5581. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5582. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5583. var total_count int64
  5584. for _, it := range stockList {
  5585. total_count += it.StockCount
  5586. }
  5587. //基础库插入数据
  5588. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5589. if errcodes != nil {
  5590. goodErrcode := models.XtGoodErrcode{
  5591. UserOrgId: item.OrgId,
  5592. Errcode: "自动出库基础库插入数据",
  5593. GoodId: item.GoodId,
  5594. Status: 1,
  5595. Ctime: time.Now().Unix(),
  5596. Mtime: 0,
  5597. Count: 0,
  5598. StockCount: 0,
  5599. Creater: creater,
  5600. BatchNumberId: 0,
  5601. WarehouseOutId: 0,
  5602. }
  5603. service.CreateGoodErrcode(goodErrcode)
  5604. }
  5605. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5606. var flush_count int64
  5607. for _, it := range goodList {
  5608. flush_count += it.StockCount
  5609. }
  5610. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5611. if errsss != nil {
  5612. goodErrcode := models.XtGoodErrcode{
  5613. UserOrgId: item.OrgId,
  5614. Errcode: "自动出库剩余库存更新数据",
  5615. GoodId: item.GoodId,
  5616. Status: 1,
  5617. Ctime: time.Now().Unix(),
  5618. Mtime: 0,
  5619. Count: 0,
  5620. StockCount: 0,
  5621. Creater: creater,
  5622. BatchNumberId: 0,
  5623. WarehouseOutId: 0,
  5624. }
  5625. service.CreateGoodErrcode(goodErrcode)
  5626. }
  5627. }
  5628. }
  5629. //
  5630. } else if err == nil {
  5631. for _, item := range consumables {
  5632. //出库
  5633. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5634. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5635. if err != nil {
  5636. goodErrcode := models.XtGoodErrcode{
  5637. UserOrgId: adminInfo.Org.Id,
  5638. Errcode: "自动出库接口报错",
  5639. GoodId: 0,
  5640. Status: 1,
  5641. Ctime: time.Now().Unix(),
  5642. Mtime: 0,
  5643. Count: 0,
  5644. StockCount: 0,
  5645. Creater: creator,
  5646. BatchNumberId: 0,
  5647. WarehouseOutId: 0,
  5648. }
  5649. service.CreateGoodErrcode(goodErrcode)
  5650. }
  5651. //出库数量相加
  5652. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5653. if errss != nil {
  5654. goodErrcode := models.XtGoodErrcode{
  5655. UserOrgId: item.UserOrgId,
  5656. Errcode: "创建剩余库存字段报错",
  5657. GoodId: item.GoodId,
  5658. Status: 1,
  5659. Ctime: time.Now().Unix(),
  5660. Mtime: time.Now().Unix(),
  5661. Count: 0,
  5662. StockCount: 0,
  5663. Creater: item.Creater,
  5664. BatchNumberId: 0,
  5665. WarehouseOutId: 0,
  5666. }
  5667. service.CreateGoodErrcode(goodErrcode)
  5668. }
  5669. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5670. if len(list) == 0 {
  5671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5672. return
  5673. }
  5674. for _, item := range list {
  5675. prepare := models.DialysisBeforePrepare{
  5676. UserOrgId: adminInfo.Org.Id,
  5677. PatientId: patient_id,
  5678. RecordDate: record_time,
  5679. GoodId: item.GoodId,
  5680. GoodTypeId: item.GoodTypeId,
  5681. Count: item.Count,
  5682. Creater: adminInfo.AdminUser.Id,
  5683. Status: 1,
  5684. Ctime: time.Now().Unix(),
  5685. StorehouseId: houseConfig.StorehouseOutInfo,
  5686. }
  5687. //清空准备表数据
  5688. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5689. if errs != nil {
  5690. goodErrcode := models.XtGoodErrcode{
  5691. UserOrgId: adminInfo.Org.Id,
  5692. Errcode: "自动出库清空准备表数据报错",
  5693. GoodId: 0,
  5694. Status: 1,
  5695. Ctime: time.Now().Unix(),
  5696. Mtime: 0,
  5697. Count: 0,
  5698. StockCount: 0,
  5699. Creater: creator,
  5700. BatchNumberId: 0,
  5701. WarehouseOutId: 0,
  5702. }
  5703. service.CreateGoodErrcode(goodErrcode)
  5704. }
  5705. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5706. if errcodes != nil {
  5707. goodErrcode := models.XtGoodErrcode{
  5708. UserOrgId: adminInfo.Org.Id,
  5709. Errcode: "自动出库创建准备表数据报错",
  5710. GoodId: 0,
  5711. Status: 1,
  5712. Ctime: time.Now().Unix(),
  5713. Mtime: 0,
  5714. Count: 0,
  5715. StockCount: 0,
  5716. Creater: creator,
  5717. BatchNumberId: 0,
  5718. WarehouseOutId: 0,
  5719. }
  5720. service.CreateGoodErrcode(goodErrcode)
  5721. }
  5722. //查询默认仓库
  5723. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5724. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5725. var total_count int64
  5726. for _, it := range stockList {
  5727. total_count += it.StockCount
  5728. }
  5729. //基础库插入数据
  5730. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5731. if errcodes != nil {
  5732. goodErrcode := models.XtGoodErrcode{
  5733. UserOrgId: adminInfo.Org.Id,
  5734. Errcode: "自动出库基础库插入数据报错",
  5735. GoodId: 0,
  5736. Status: 1,
  5737. Ctime: time.Now().Unix(),
  5738. Mtime: 0,
  5739. Count: 0,
  5740. StockCount: 0,
  5741. Creater: creator,
  5742. BatchNumberId: 0,
  5743. WarehouseOutId: 0,
  5744. }
  5745. service.CreateGoodErrcode(goodErrcode)
  5746. }
  5747. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5748. var flush_count int64
  5749. for _, it := range goodList {
  5750. flush_count += it.StockCount
  5751. }
  5752. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5753. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5754. if errss != nil {
  5755. goodErrcode := models.XtGoodErrcode{
  5756. UserOrgId: item.OrgId,
  5757. Errcode: "自动出库剩余库存更新数据",
  5758. GoodId: item.GoodId,
  5759. Status: 1,
  5760. Ctime: time.Now().Unix(),
  5761. Mtime: 0,
  5762. Count: 0,
  5763. StockCount: 0,
  5764. Creater: creater,
  5765. BatchNumberId: 0,
  5766. WarehouseOutId: 0,
  5767. }
  5768. service.CreateGoodErrcode(goodErrcode)
  5769. }
  5770. }
  5771. }
  5772. }
  5773. c.ServeSuccessJSON(map[string]interface{}{
  5774. "msg": "提交成功",
  5775. "message": "2",
  5776. "good_name": "",
  5777. "specification_name": "",
  5778. })
  5779. return
  5780. }
  5781. if record.IsOpen == 1 {
  5782. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5783. //查询是否有库存
  5784. for _, item := range consumables {
  5785. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5786. if item.Count > warehouse.Count {
  5787. goodErrcode := models.XtGoodErrcode{
  5788. UserOrgId: item.UserOrgId,
  5789. Errcode: "自动出库库存不足",
  5790. GoodId: item.GoodId,
  5791. Status: 1,
  5792. Ctime: time.Now().Unix(),
  5793. Mtime: 0,
  5794. Count: 0,
  5795. StockCount: 0,
  5796. Creater: creator,
  5797. BatchNumberId: warehouse.ID,
  5798. WarehouseOutId: 0,
  5799. }
  5800. service.CreateGoodErrcode(goodErrcode)
  5801. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5802. c.ServeSuccessJSON(map[string]interface{}{
  5803. "message": "1",
  5804. "good_name": goodObj.GoodName,
  5805. "specification_name": goodObj.SpecificationName,
  5806. })
  5807. return
  5808. }
  5809. }
  5810. //查询是否有出库单
  5811. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5812. if err == gorm.ErrRecordNotFound {
  5813. //没有记录,则创建出库单
  5814. timeStr := time.Now().Format("2006-01-02")
  5815. timeArr := strings.Split(timeStr, "-")
  5816. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5817. total = total + 1
  5818. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5819. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5820. number = number + total
  5821. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5822. creater := adminInfo.AdminUser.Id
  5823. warehouseOut := models.WarehouseOut{
  5824. WarehouseOutOrderNumber: warehousing_out_order,
  5825. OperationTime: time.Now().Unix(),
  5826. OrgId: adminInfo.Org.Id,
  5827. Creater: creater,
  5828. Ctime: time.Now().Unix(),
  5829. Status: 1,
  5830. WarehouseOutTime: record_time,
  5831. Dealer: 0,
  5832. Manufacturer: 0,
  5833. Type: 1,
  5834. IsSys: 1,
  5835. StorehouseId: houseConfig.StorehouseOutInfo,
  5836. IsCheck: 1,
  5837. }
  5838. err := service.AddSigleWarehouseOut(&warehouseOut)
  5839. if err != nil {
  5840. goodErrcode := models.XtGoodErrcode{
  5841. UserOrgId: adminInfo.Org.Id,
  5842. Errcode: "创建出库单失败",
  5843. GoodId: 0,
  5844. Status: 1,
  5845. Ctime: time.Now().Unix(),
  5846. Mtime: 0,
  5847. Count: 0,
  5848. StockCount: 0,
  5849. Creater: creator,
  5850. BatchNumberId: 0,
  5851. WarehouseOutId: 0,
  5852. }
  5853. service.CreateGoodErrcode(goodErrcode)
  5854. utils.TraceLog("创建出库单失败 err = %v", err)
  5855. } else {
  5856. for _, item := range consumables {
  5857. //出库
  5858. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5859. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5860. if err == nil {
  5861. goodErrcode := models.XtGoodErrcode{
  5862. UserOrgId: adminInfo.Org.Id,
  5863. Errcode: "自动出库接口报错",
  5864. GoodId: 0,
  5865. Status: 1,
  5866. Ctime: time.Now().Unix(),
  5867. Mtime: 0,
  5868. Count: 0,
  5869. StockCount: 0,
  5870. Creater: creator,
  5871. BatchNumberId: 0,
  5872. WarehouseOutId: 0,
  5873. }
  5874. service.CreateGoodErrcode(goodErrcode)
  5875. utils.TraceLog("创建出库单失败 err = %v", err)
  5876. }
  5877. //查询
  5878. //出库数量相加
  5879. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5880. if errs != nil {
  5881. goodErrcode := models.XtGoodErrcode{
  5882. UserOrgId: item.UserOrgId,
  5883. Errcode: "创建剩余库存字段报错",
  5884. GoodId: item.GoodId,
  5885. Status: 1,
  5886. Ctime: time.Now().Unix(),
  5887. Mtime: 0,
  5888. Count: 0,
  5889. StockCount: 0,
  5890. Creater: creater,
  5891. BatchNumberId: 0,
  5892. WarehouseOutId: 0,
  5893. }
  5894. service.CreateGoodErrcode(goodErrcode)
  5895. }
  5896. }
  5897. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5898. if len(list) == 0 {
  5899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5900. return
  5901. }
  5902. for _, item := range list {
  5903. prepare := models.DialysisBeforePrepare{
  5904. UserOrgId: adminInfo.Org.Id,
  5905. PatientId: patient_id,
  5906. RecordDate: record_time,
  5907. GoodId: item.GoodId,
  5908. GoodTypeId: item.GoodTypeId,
  5909. Count: item.Count,
  5910. Creater: adminInfo.AdminUser.Id,
  5911. Status: 1,
  5912. Ctime: time.Now().Unix(),
  5913. StorehouseId: houseConfig.StorehouseOutInfo,
  5914. }
  5915. //清空准备表数据
  5916. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5917. if err != nil {
  5918. goodErrcode := models.XtGoodErrcode{
  5919. UserOrgId: item.OrgId,
  5920. Errcode: "自动出库清空准备表数据报错",
  5921. GoodId: item.GoodId,
  5922. Status: 1,
  5923. Ctime: time.Now().Unix(),
  5924. Mtime: 0,
  5925. Count: 0,
  5926. StockCount: 0,
  5927. Creater: creater,
  5928. BatchNumberId: 0,
  5929. WarehouseOutId: 0,
  5930. }
  5931. service.CreateGoodErrcode(goodErrcode)
  5932. }
  5933. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5934. if errs != nil {
  5935. goodErrcode := models.XtGoodErrcode{
  5936. UserOrgId: item.OrgId,
  5937. Errcode: "自动出库创建准备表数据报错",
  5938. GoodId: item.GoodId,
  5939. Status: 1,
  5940. Ctime: time.Now().Unix(),
  5941. Mtime: 0,
  5942. Count: 0,
  5943. StockCount: 0,
  5944. Creater: creater,
  5945. BatchNumberId: 0,
  5946. WarehouseOutId: 0,
  5947. }
  5948. service.CreateGoodErrcode(goodErrcode)
  5949. }
  5950. //查询默认仓库
  5951. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5952. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5953. var total_count int64
  5954. for _, it := range stockList {
  5955. total_count += it.StockCount
  5956. }
  5957. //基础库插入数据
  5958. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5959. if errcodes != nil {
  5960. goodErrcode := models.XtGoodErrcode{
  5961. UserOrgId: item.OrgId,
  5962. Errcode: "自动出库基础库插入数据",
  5963. GoodId: item.GoodId,
  5964. Status: 1,
  5965. Ctime: time.Now().Unix(),
  5966. Mtime: 0,
  5967. Count: 0,
  5968. StockCount: 0,
  5969. Creater: creater,
  5970. BatchNumberId: 0,
  5971. WarehouseOutId: 0,
  5972. }
  5973. service.CreateGoodErrcode(goodErrcode)
  5974. }
  5975. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5976. var flush_count int64
  5977. for _, it := range goodList {
  5978. flush_count += it.StockCount
  5979. }
  5980. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5981. if errsss != nil {
  5982. goodErrcode := models.XtGoodErrcode{
  5983. UserOrgId: item.OrgId,
  5984. Errcode: "自动出库剩余库存更新数据",
  5985. GoodId: item.GoodId,
  5986. Status: 1,
  5987. Ctime: time.Now().Unix(),
  5988. Mtime: 0,
  5989. Count: 0,
  5990. StockCount: 0,
  5991. Creater: creater,
  5992. BatchNumberId: 0,
  5993. WarehouseOutId: 0,
  5994. }
  5995. service.CreateGoodErrcode(goodErrcode)
  5996. }
  5997. }
  5998. }
  5999. //
  6000. } else if err == nil {
  6001. for _, item := range consumables {
  6002. //出库
  6003. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6004. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6005. if err != nil {
  6006. goodErrcode := models.XtGoodErrcode{
  6007. UserOrgId: adminInfo.Org.Id,
  6008. Errcode: "自动出库接口报错",
  6009. GoodId: 0,
  6010. Status: 1,
  6011. Ctime: time.Now().Unix(),
  6012. Mtime: 0,
  6013. Count: 0,
  6014. StockCount: 0,
  6015. Creater: creator,
  6016. BatchNumberId: 0,
  6017. WarehouseOutId: 0,
  6018. }
  6019. service.CreateGoodErrcode(goodErrcode)
  6020. }
  6021. //出库数量相加
  6022. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6023. if errss != nil {
  6024. goodErrcode := models.XtGoodErrcode{
  6025. UserOrgId: item.UserOrgId,
  6026. Errcode: "创建剩余库存字段报错",
  6027. GoodId: item.GoodId,
  6028. Status: 1,
  6029. Ctime: time.Now().Unix(),
  6030. Mtime: time.Now().Unix(),
  6031. Count: 0,
  6032. StockCount: 0,
  6033. Creater: item.Creater,
  6034. BatchNumberId: 0,
  6035. WarehouseOutId: 0,
  6036. }
  6037. service.CreateGoodErrcode(goodErrcode)
  6038. }
  6039. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6040. if len(list) == 0 {
  6041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6042. return
  6043. }
  6044. for _, item := range list {
  6045. prepare := models.DialysisBeforePrepare{
  6046. UserOrgId: adminInfo.Org.Id,
  6047. PatientId: patient_id,
  6048. RecordDate: record_time,
  6049. GoodId: item.GoodId,
  6050. GoodTypeId: item.GoodTypeId,
  6051. Count: item.Count,
  6052. Creater: adminInfo.AdminUser.Id,
  6053. Status: 1,
  6054. Ctime: time.Now().Unix(),
  6055. StorehouseId: houseConfig.StorehouseOutInfo,
  6056. }
  6057. //清空准备表数据
  6058. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6059. if errs != nil {
  6060. goodErrcode := models.XtGoodErrcode{
  6061. UserOrgId: adminInfo.Org.Id,
  6062. Errcode: "自动出库清空准备表数据报错",
  6063. GoodId: 0,
  6064. Status: 1,
  6065. Ctime: time.Now().Unix(),
  6066. Mtime: 0,
  6067. Count: 0,
  6068. StockCount: 0,
  6069. Creater: creator,
  6070. BatchNumberId: 0,
  6071. WarehouseOutId: 0,
  6072. }
  6073. service.CreateGoodErrcode(goodErrcode)
  6074. }
  6075. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6076. if errcodes != nil {
  6077. goodErrcode := models.XtGoodErrcode{
  6078. UserOrgId: adminInfo.Org.Id,
  6079. Errcode: "自动出库创建准备表数据报错",
  6080. GoodId: 0,
  6081. Status: 1,
  6082. Ctime: time.Now().Unix(),
  6083. Mtime: 0,
  6084. Count: 0,
  6085. StockCount: 0,
  6086. Creater: creator,
  6087. BatchNumberId: 0,
  6088. WarehouseOutId: 0,
  6089. }
  6090. service.CreateGoodErrcode(goodErrcode)
  6091. }
  6092. //查询默认仓库
  6093. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6094. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6095. var total_count int64
  6096. for _, it := range stockList {
  6097. total_count += it.StockCount
  6098. }
  6099. //基础库插入数据
  6100. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6101. if errcodes != nil {
  6102. goodErrcode := models.XtGoodErrcode{
  6103. UserOrgId: adminInfo.Org.Id,
  6104. Errcode: "自动出库基础库插入数据报错",
  6105. GoodId: 0,
  6106. Status: 1,
  6107. Ctime: time.Now().Unix(),
  6108. Mtime: 0,
  6109. Count: 0,
  6110. StockCount: 0,
  6111. Creater: creator,
  6112. BatchNumberId: 0,
  6113. WarehouseOutId: 0,
  6114. }
  6115. service.CreateGoodErrcode(goodErrcode)
  6116. }
  6117. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6118. var flush_count int64
  6119. for _, it := range goodList {
  6120. flush_count += it.StockCount
  6121. }
  6122. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6123. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6124. if errss != nil {
  6125. goodErrcode := models.XtGoodErrcode{
  6126. UserOrgId: item.OrgId,
  6127. Errcode: "自动出库剩余库存更新数据",
  6128. GoodId: item.GoodId,
  6129. Status: 1,
  6130. Ctime: time.Now().Unix(),
  6131. Mtime: 0,
  6132. Count: 0,
  6133. StockCount: 0,
  6134. Creater: creater,
  6135. BatchNumberId: 0,
  6136. WarehouseOutId: 0,
  6137. }
  6138. service.CreateGoodErrcode(goodErrcode)
  6139. }
  6140. }
  6141. }
  6142. }
  6143. c.ServeSuccessJSON(map[string]interface{}{
  6144. "msg": "提交成功",
  6145. "message": "2",
  6146. "good_name": "",
  6147. "specification_name": "",
  6148. })
  6149. return
  6150. } else {
  6151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6152. return
  6153. }
  6154. }
  6155. func (c *DialysisAPIController) EditConsumables() {
  6156. patient_id, _ := c.GetInt64("patient_id", 0)
  6157. record_date := c.GetString("record_time")
  6158. if patient_id <= 0 {
  6159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6160. return
  6161. }
  6162. adminInfo := c.GetMobileAdminUserInfo()
  6163. timeLayout := "2006-01-02"
  6164. loc, _ := time.LoadLocation("Local")
  6165. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6166. record_time := theRecordTime.Unix()
  6167. // 查询信息规挡的设置天数
  6168. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6169. if infor.ID > 0 && infor.WeekDay > 0 {
  6170. var cha_time int64
  6171. timeNowStr := time.Now().Format("2006-01-02")
  6172. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6173. //今日的日期减去设置的日期
  6174. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6175. if cha_time >= record_time {
  6176. //查询审核是否允许
  6177. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6178. //申请状态不允许的情况 拒绝修改
  6179. if infor.ApplicationStatus != 1 {
  6180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6181. return
  6182. }
  6183. }
  6184. }
  6185. dataBody := make(map[string]interface{}, 0)
  6186. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6187. if err != nil {
  6188. utils.ErrorLog(err.Error())
  6189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6190. return
  6191. }
  6192. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6193. var beforePrepares []*models.DialysisBeforePrepareGoods
  6194. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6195. var cancelbefor []*models.DialysisBeforePrepareGoods
  6196. var outbefor []*models.DialysisBeforePrepareGoods
  6197. //判断是否开启自动出库
  6198. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6199. if record.IsOpen == 1 {
  6200. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6201. goods, _ := dataBody["goods"].([]interface{})
  6202. if len(goods) > 0 {
  6203. for _, item := range goods {
  6204. items := item.(map[string]interface{})
  6205. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6206. utils.ErrorLog("good_id")
  6207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6208. return
  6209. }
  6210. good_id := int64(items["good_id"].(float64))
  6211. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6212. utils.ErrorLog("good_type_id")
  6213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6214. return
  6215. }
  6216. good_type_id := int64(items["good_type_id"].(float64))
  6217. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6218. utils.ErrorLog("count")
  6219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6220. return
  6221. }
  6222. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6223. commdity_code := items["commdity_code"].(string)
  6224. fmt.Println(commdity_code)
  6225. prepareGoods := &models.DialysisBeforePrepareGoods{
  6226. GoodTypeId: good_type_id,
  6227. GoodId: good_id,
  6228. Count: count,
  6229. StorehouseId: houseConfig.StorehouseOutInfo,
  6230. }
  6231. beforePrepares = append(beforePrepares, prepareGoods)
  6232. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6233. GoodTypeId: good_type_id,
  6234. GoodId: good_id,
  6235. Count: count,
  6236. StorehouseId: houseConfig.StorehouseOutInfo,
  6237. }
  6238. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6239. }
  6240. for _, item := range beforePrepares {
  6241. //1.查看该患者该耗材型号最后一次出库数量
  6242. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6243. //判断当前出库数量和最后一次出库数量的大小
  6244. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6245. if item.Count < goodInfo.Count {
  6246. cancelbefor = append(cancelbefor, item)
  6247. }
  6248. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6249. if item.Count > goodInfo.Count {
  6250. outbefor = append(outbefor, item)
  6251. }
  6252. //处理编辑耗材新增不了的问题
  6253. if goodInfo.Count == item.Count {
  6254. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6255. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6256. }
  6257. }
  6258. if len(cancelbefor) > 0 {
  6259. //退库
  6260. for _, item := range cancelbefor {
  6261. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6262. creater := adminInfo.AdminUser.Id
  6263. //查询该患者当天已经出库的耗材信息
  6264. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6265. var delete_count int64 = 0
  6266. delete_count = warehouseOutInfos.Count - item.Count
  6267. //增加库存数量
  6268. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6269. //减少实际出库库存数量
  6270. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6271. // 删除出库完成后,要增加对应批次的库存数量
  6272. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6273. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6274. //更新剩余库存
  6275. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6276. var flush_count int64
  6277. for _, it := range goodListOne {
  6278. flush_count += it.StockCount
  6279. }
  6280. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6281. //查询剩余库存
  6282. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6283. var sum_count int64
  6284. for _, item := range goodList {
  6285. sum_count += item.StockCount
  6286. }
  6287. // 在出库记录表里记录退库详情
  6288. warehouseOutInfo := &models.WarehouseOutInfo{
  6289. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6290. WarehouseOutId: warehouseOut.ID,
  6291. Status: 1,
  6292. Ctime: time.Now().Unix(),
  6293. OrgId: adminInfo.Org.Id,
  6294. Type: 1,
  6295. IsSys: 1,
  6296. SysRecordTime: record_time,
  6297. GoodTypeId: item.GoodTypeId,
  6298. GoodId: item.GoodId,
  6299. PatientId: patient_id,
  6300. ConsumableType: 2,
  6301. StorehouseId: houseConfig.StorehouseOutInfo,
  6302. IsCheck: 1,
  6303. OverCount: sum_count,
  6304. }
  6305. warehouseOutInfo.Count = item.Count
  6306. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6307. warehouseOutInfo.Price = stockInInfo.Price
  6308. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6309. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6310. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6311. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6312. warehouseOutInfo.Number = warehouseOutInfos.Number
  6313. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6314. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6315. //查找当天是否存在出库记录
  6316. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6317. if errcod == gorm.ErrRecordNotFound {
  6318. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6319. //插入详情明细表
  6320. stockFlow := models.VmStockFlow{
  6321. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6322. WarehouseOutId: warehouseOut.ID,
  6323. GoodId: item.GoodId,
  6324. Number: warehouseOutInfos.Number,
  6325. ProductDate: stockInInfo.ProductDate,
  6326. ExpireDate: stockInInfo.ExpiryDate,
  6327. Count: item.Count,
  6328. Price: stockInInfo.Price,
  6329. Status: 1,
  6330. Ctime: time.Now().Unix(),
  6331. UserOrgId: adminInfo.Org.Id,
  6332. Manufacturer: stockInInfo.Manufacturer,
  6333. Dealer: stockInInfo.Dealer,
  6334. LicenseNumber: stockInInfo.LicenseNumber,
  6335. IsEdit: 2,
  6336. Creator: creater,
  6337. SystemTime: record_time,
  6338. ConsumableType: 3,
  6339. WarehousingDetailId: 0,
  6340. IsSys: 1,
  6341. UpdateCreator: creater,
  6342. PatientId: patient_id,
  6343. StorehouseId: houseConfig.StorehouseOutInfo,
  6344. }
  6345. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6346. if errflow == gorm.ErrRecordNotFound {
  6347. //创建流水表
  6348. err := service.CreateStockFlowOne(stockFlow)
  6349. fmt.Println("err", err)
  6350. } else if errflow == nil {
  6351. //插入详情明细表
  6352. stockFlow := models.VmStockFlow{
  6353. ID: exsit.ID,
  6354. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6355. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6356. WarehouseOutId: warehouseOut.ID,
  6357. GoodId: item.GoodId,
  6358. Number: warehouseOutInfos.Number,
  6359. ProductDate: stockInInfo.ProductDate,
  6360. ExpireDate: stockInInfo.ExpiryDate,
  6361. Count: exsit.Count - delete_count,
  6362. Price: stockInInfo.Price,
  6363. Status: 1,
  6364. Ctime: time.Now().Unix(),
  6365. UserOrgId: adminInfo.Org.Id,
  6366. Manufacturer: stockInInfo.Manufacturer,
  6367. Dealer: stockInInfo.Dealer,
  6368. LicenseNumber: stockInInfo.LicenseNumber,
  6369. IsEdit: 2,
  6370. Creator: creater,
  6371. SystemTime: record_time,
  6372. ConsumableType: 3,
  6373. WarehousingDetailId: 0,
  6374. IsSys: 1,
  6375. UpdateCreator: creater,
  6376. PatientId: patient_id,
  6377. StorehouseId: houseConfig.StorehouseOutInfo,
  6378. }
  6379. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6380. }
  6381. } else if errcod == nil {
  6382. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6383. //查询剩余库存
  6384. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6385. var sum_count int64
  6386. for _, item := range goodList {
  6387. sum_count += item.StockCount
  6388. }
  6389. //创建退库单,生成退库数据
  6390. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6391. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6392. operation_time := time.Now().Unix()
  6393. creater := adminInfo.AdminUser.Id
  6394. //创建退库单
  6395. timeStr := time.Now().Format("2006-01-02")
  6396. timeArr := strings.Split(timeStr, "-")
  6397. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6398. total = total + 1
  6399. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6400. cancelStock := models.CancelStock{
  6401. OrderNumber: orderNumber,
  6402. OperaTime: operation_time,
  6403. OrgId: adminInfo.Org.Id,
  6404. Creater: creater,
  6405. Ctime: time.Now().Unix(),
  6406. Status: 1,
  6407. ReturnTime: record_time,
  6408. Type: 1,
  6409. StorehouseId: houseConfig.StorehouseOutInfo,
  6410. IsCheck: 1,
  6411. }
  6412. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6413. if msgerrkonde == gorm.ErrRecordNotFound {
  6414. service.AddSigleCancelStock(&cancelStock)
  6415. }
  6416. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6417. //查询是否有出库
  6418. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6419. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6420. deaerler, _ := service.GetDealerById(info.Dealer)
  6421. if info.ID > 0 {
  6422. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6423. cancelStockInfo := models.CancelStockInfo{
  6424. GoodId: item.GoodId,
  6425. CancelStockId: cancel.ID,
  6426. GoodTypeId: good.GoodTypeId,
  6427. Count: delete_count,
  6428. Price: info.Price,
  6429. Total: 0,
  6430. ProductDate: info.ProductDate,
  6431. ExpiryDate: info.ExpiryDate,
  6432. Ctime: time.Now().Unix(),
  6433. Status: 1,
  6434. OrgId: adminInfo.Org.Id,
  6435. OrderNumber: cancel.OrderNumber,
  6436. Type: 0,
  6437. Dealer: deaerler.DealerName,
  6438. Manufacturer: manufacturer.ManufacturerName,
  6439. Number: info.Number,
  6440. RegisterAccount: "",
  6441. Remark: "",
  6442. WarehouseInfoId: info.WarehouseInfotId,
  6443. PatientId: info.PatientId,
  6444. RecordDate: info.SysRecordTime,
  6445. StorehouseId: houseConfig.StorehouseOutInfo,
  6446. IsCheck: 1,
  6447. }
  6448. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6449. //退库数量增加
  6450. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6451. //查询剩余库存
  6452. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6453. var over_count int64
  6454. for _, it := range goodList {
  6455. over_count += it.StockCount
  6456. }
  6457. flow := models.VmStockFlow{
  6458. WarehousingId: info.WarehouseInfotId,
  6459. GoodId: item.GoodId,
  6460. Number: info.Number,
  6461. LicenseNumber: info.LicenseNumber,
  6462. Count: delete_count,
  6463. UserOrgId: adminInfo.Org.Id,
  6464. PatientId: patient_id,
  6465. SystemTime: info.SysRecordTime,
  6466. ConsumableType: 7,
  6467. IsSys: 0,
  6468. WarehousingOrder: "",
  6469. WarehouseOutId: info.WarehouseOutId,
  6470. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6471. IsEdit: 0,
  6472. CancelStockId: cancel.ID,
  6473. CancelOrderNumber: cancel.OrderNumber,
  6474. Manufacturer: manufacturer.ID,
  6475. Dealer: 0,
  6476. Creator: adminInfo.AdminUser.Id,
  6477. UpdateCreator: 0,
  6478. Status: 1,
  6479. Ctime: time.Now().Unix(),
  6480. Mtime: 0,
  6481. Price: info.Price,
  6482. WarehousingDetailId: info.WarehouseInfotId,
  6483. WarehouseOutDetailId: info.ID,
  6484. CancelOutDetailId: cancelInfo.ID,
  6485. ProductDate: info.ProductDate,
  6486. ExpireDate: info.ExpiryDate,
  6487. StorehouseId: houseConfig.StorehouseOutInfo,
  6488. OverCount: over_count,
  6489. }
  6490. service.CreateStockFlowOne(flow)
  6491. }
  6492. }
  6493. //更改自动出库的表格
  6494. details := models.BloodAutomaticReduceDetail{
  6495. WarehouseOutId: warehouseOutInfo.ID,
  6496. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6497. PatientId: patient_id,
  6498. Ctime: time.Now().Unix(),
  6499. Mtime: time.Now().Unix(),
  6500. Status: 1,
  6501. RecordTime: record_time,
  6502. OrgId: adminInfo.Org.Id,
  6503. GoodId: item.GoodId,
  6504. GoodTypeId: item.GoodTypeId,
  6505. Count: item.Count,
  6506. StorehouseId: houseConfig.StorehouseOutInfo,
  6507. }
  6508. //查询当天耗材是否已经存在数据
  6509. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6510. if errcode == gorm.ErrRecordNotFound {
  6511. service.CreateAutoReduceRecord(&details)
  6512. } else if errcode == nil {
  6513. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6514. service.CreateAutoReduceRecord(&details)
  6515. }
  6516. //查询默认仓库
  6517. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6518. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6519. var total_count int64
  6520. for _, it := range stockList {
  6521. total_count += it.StockCount
  6522. }
  6523. //基础库插入数据
  6524. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6525. }
  6526. }
  6527. if len(outbefor) > 0 {
  6528. //出库
  6529. for _, item := range outbefor {
  6530. var last_total int64
  6531. //1.查看该患者该耗材型号最后一次出库数量
  6532. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6533. //计算当前出库和最后一次出库数据相差数据
  6534. last_total = item.Count - goodInfoOne.Count
  6535. //查询该耗材的总库存
  6536. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6537. // 如果库存差大于剩余库存则提示库存不足
  6538. if last_total > wareinfo.StockCount {
  6539. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6540. c.ServeSuccessJSON(map[string]interface{}{
  6541. "message": "1",
  6542. "good_name": goodObj.GoodName,
  6543. "specification_name": goodObj.SpecificationName,
  6544. })
  6545. return
  6546. } else {
  6547. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6548. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6549. if err == gorm.ErrRecordNotFound {
  6550. //没有记录,则创建出库单
  6551. timeStr := time.Now().Format("2006-01-02")
  6552. timeArr := strings.Split(timeStr, "-")
  6553. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6554. total = total + 1
  6555. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6556. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6557. number = number + total
  6558. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6559. warehouseOut := models.WarehouseOut{
  6560. WarehouseOutOrderNumber: warehousing_out_order,
  6561. OperationTime: time.Now().Unix(),
  6562. OrgId: adminInfo.Org.Id,
  6563. Creater: adminInfo.AdminUser.Id,
  6564. Ctime: time.Now().Unix(),
  6565. Status: 1,
  6566. WarehouseOutTime: record_time,
  6567. Dealer: 0,
  6568. Manufacturer: 0,
  6569. Type: 1,
  6570. IsSys: 1,
  6571. StorehouseId: houseConfig.StorehouseOutInfo,
  6572. IsCheck: 1,
  6573. }
  6574. service.AddSigleWarehouseOut(&warehouseOut)
  6575. }
  6576. //出库
  6577. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6578. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6579. //1.查看该患者该耗材型号最后一次出库数量
  6580. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6581. prepare := models.DialysisBeforePrepare{
  6582. UserOrgId: adminInfo.Org.Id,
  6583. PatientId: patient_id,
  6584. RecordDate: record_time,
  6585. GoodId: item.GoodId,
  6586. GoodTypeId: item.GoodTypeId,
  6587. Count: item.Count - goodInfoTwo.Count,
  6588. Ctime: time.Now().Unix(),
  6589. Mtime: 0,
  6590. Creater: adminInfo.AdminUser.Id,
  6591. Modifier: adminInfo.AdminUser.Id,
  6592. Status: 1,
  6593. CommdityCode: "",
  6594. NewCount: 0,
  6595. ProjectId: 0,
  6596. StorehouseId: houseConfig.StorehouseOutInfo,
  6597. }
  6598. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6599. //增加出库数量
  6600. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6601. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6602. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6603. var total_count int64
  6604. for _, it := range stockList {
  6605. total_count += it.StockCount
  6606. }
  6607. //基础库插入数据
  6608. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6609. //剩余库存
  6610. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6611. var flush_count int64
  6612. for _, it := range goodList {
  6613. flush_count += it.StockCount
  6614. }
  6615. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6616. }
  6617. }
  6618. }
  6619. //查询今日出库数据
  6620. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6621. for _, it := range list {
  6622. prepare := models.DialysisBeforePrepare{
  6623. UserOrgId: it.OrgId,
  6624. PatientId: patient_id,
  6625. RecordDate: it.RecordTime,
  6626. GoodId: it.GoodId,
  6627. GoodTypeId: it.GoodTypeId,
  6628. Count: it.Count,
  6629. Ctime: time.Now().Unix(),
  6630. Creater: adminInfo.AdminUser.Id,
  6631. Status: 1,
  6632. StorehouseId: houseConfig.StorehouseOutInfo,
  6633. ProjectId: it.ProjectId,
  6634. }
  6635. //删除准备表数据
  6636. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6637. service.CreateDialysisBeforePrepareOne(&prepare)
  6638. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6639. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6640. var total_count int64
  6641. for _, it := range stockList {
  6642. total_count += it.StockCount
  6643. }
  6644. //基础库插入数据
  6645. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6646. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6647. var flush_count int64
  6648. for _, it := range goodList {
  6649. flush_count += it.StockCount
  6650. }
  6651. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6652. }
  6653. }
  6654. }
  6655. //更新自动出库的地方
  6656. var errs error
  6657. if errs == nil {
  6658. c.ServeSuccessJSON(map[string]interface{}{
  6659. "msg": "修改成功",
  6660. "message": "2",
  6661. "good_name": "",
  6662. "specification_name": "",
  6663. })
  6664. return
  6665. } else {
  6666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6667. return
  6668. }
  6669. }
  6670. }
  6671. func (c *DialysisAPIController) GetDialysisGoods() {
  6672. schedualDate := c.GetString("schedule_date")
  6673. schedule_type, _ := c.GetInt64("schedule_type")
  6674. partition_id, _ := c.GetInt64("partition_id")
  6675. page, _ := c.GetInt("page")
  6676. patient_id, _ := c.GetInt64("patient_id")
  6677. schedualEndDate := int64(0)
  6678. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6679. if parseDateErr != nil && len(schedualDate) != 0 {
  6680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6681. return
  6682. }
  6683. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6684. if parseDateErr != nil && len(schedualDate) != 0 {
  6685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6686. return
  6687. }
  6688. schedualEndDate = endDate.Unix()
  6689. adminUser := c.GetMobileAdminUserInfo()
  6690. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6691. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6692. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6693. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6694. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6695. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6696. //获取当天该病人的透析处方
  6697. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6698. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6699. if err == gorm.ErrRecordNotFound {
  6700. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6701. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6702. if patient_id != 0 {
  6703. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6704. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6705. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6706. //获取患者总的出库数据
  6707. item.LastAutomaticReduceDetail = goodUser
  6708. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6709. item.Project = project
  6710. }
  6711. }
  6712. c.ServeSuccessJSON(map[string]interface{}{
  6713. "dialysis_goods": dialysisGoods,
  6714. "good_type": goodTypes,
  6715. "total": total,
  6716. "prescribe": prescribe,
  6717. "good_info": good_info,
  6718. "warehouseOutList": warehouseOutList,
  6719. "config": config,
  6720. "outConfig": outConfig,
  6721. "settleConfig": settleConfig,
  6722. })
  6723. return
  6724. } else if err == nil {
  6725. //获取当天排班的每个患者的库存使用情况
  6726. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6727. //获取患者总的出库数据
  6728. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6729. if patient_id != 0 {
  6730. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6731. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6732. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6733. item.Project = project
  6734. item.LastAutomaticReduceDetail = goodUser
  6735. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6736. }
  6737. }
  6738. if err == nil {
  6739. c.ServeSuccessJSON(map[string]interface{}{
  6740. "dialysis_goods": dialysisGoods,
  6741. "good_type": goodTypes,
  6742. "total": total,
  6743. "prescribe": prescribe,
  6744. "good_info": good_info,
  6745. "project": project,
  6746. "warehouseOutList": warehouseOutList,
  6747. "config": config,
  6748. "outConfig": outConfig,
  6749. "settleConfig": settleConfig,
  6750. })
  6751. return
  6752. } else {
  6753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6754. return
  6755. }
  6756. } else if err != nil {
  6757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6758. return
  6759. }
  6760. }
  6761. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6762. start_time := c.GetString("start_time")
  6763. end_time := c.GetString("end_time")
  6764. timeLayout := "2006-01-02"
  6765. loc, _ := time.LoadLocation("Local")
  6766. var theStartTime int64
  6767. if len(start_time) > 0 {
  6768. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6769. if err != nil {
  6770. utils.ErrorLog(err.Error())
  6771. }
  6772. theStartTime = theTime.Unix()
  6773. }
  6774. var theEndtTime int64
  6775. if len(end_time) > 0 {
  6776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6777. if err != nil {
  6778. utils.ErrorLog(err.Error())
  6779. }
  6780. theEndtTime = theTime.Unix()
  6781. }
  6782. adminUser := c.GetMobileAdminUserInfo()
  6783. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6784. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6785. if err == nil {
  6786. c.ServeSuccessJSON(map[string]interface{}{
  6787. "stock_out": outInfo,
  6788. "stockCount": stockCount,
  6789. })
  6790. return
  6791. } else {
  6792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6793. return
  6794. }
  6795. }
  6796. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6797. patient_id, _ := c.GetInt64("patient_id", 0)
  6798. record_time := c.GetString("record_time")
  6799. adminUser := c.GetMobileAdminUserInfo()
  6800. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6801. if parseDateErr != nil && len(record_time) != 0 {
  6802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6803. return
  6804. }
  6805. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6806. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6807. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6808. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6809. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6810. //获取今日患者的透析处方参数
  6811. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6812. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6813. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6814. c.ServeSuccessJSON(map[string]interface{}{
  6815. "good_type": goodTypes,
  6816. "good_user": goodUser,
  6817. "good_info": good_info,
  6818. "last_good_user": lastGoodUserDetial,
  6819. "project": project,
  6820. "prescription": prescribe,
  6821. "outInfo": outInfo,
  6822. "configs": configs,
  6823. })
  6824. return
  6825. }
  6826. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6827. patient_id, _ := c.GetInt64("patient_id", 0)
  6828. record_date := c.GetString("record_time")
  6829. timeLayout := "2006-01-02"
  6830. loc, _ := time.LoadLocation("Local")
  6831. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6832. record_time := theRecordTime.Unix()
  6833. adminInfo := c.GetMobileAdminUserInfo()
  6834. dataBody := make(map[string]interface{}, 0)
  6835. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6836. if err != nil {
  6837. utils.ErrorLog(err.Error())
  6838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6839. return
  6840. }
  6841. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6842. var beforePrepares []*models.DialysisBeforePrepareGoods
  6843. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6844. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6845. goods, _ := dataBody["goods"].([]interface{})
  6846. if len(goods) > 0 {
  6847. for _, item := range goods {
  6848. items := item.(map[string]interface{})
  6849. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6850. utils.ErrorLog("good_id")
  6851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6852. return
  6853. }
  6854. good_id := int64(items["good_id"].(float64))
  6855. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6856. utils.ErrorLog("good_type_id")
  6857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6858. return
  6859. }
  6860. good_type_id := int64(items["good_type_id"].(float64))
  6861. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6862. utils.ErrorLog("count")
  6863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6864. return
  6865. }
  6866. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6867. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6868. utils.ErrorLog("project_id")
  6869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6870. return
  6871. }
  6872. project_id := int64(items["project_id"].(float64))
  6873. new_count := int64(items["new_count"].(float64))
  6874. old_count := int64(items["old_count"].(float64))
  6875. prepare := &models.DialysisBeforePrepareGoods{
  6876. GoodId: good_id,
  6877. GoodTypeId: good_type_id,
  6878. Count: count,
  6879. ProjectId: project_id,
  6880. StorehouseId: houseConfig.StorehouseOutInfo,
  6881. NewCount: new_count,
  6882. OldCount: old_count,
  6883. }
  6884. beforePrepares = append(beforePrepares, prepare)
  6885. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6886. GoodId: good_id,
  6887. GoodTypeId: good_type_id,
  6888. Count: count,
  6889. ProjectId: project_id,
  6890. StorehouseId: houseConfig.StorehouseOutInfo,
  6891. NewCount: new_count,
  6892. OldCount: old_count,
  6893. }
  6894. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6895. }
  6896. }
  6897. }
  6898. //查询是否有库存
  6899. for _, item := range beforePrepares {
  6900. if item.NewCount > 0 {
  6901. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6902. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6903. if item.Count > warehouse.Count {
  6904. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6905. c.ServeSuccessJSON(map[string]interface{}{
  6906. "message": "1",
  6907. "good_name": goodObj.GoodName,
  6908. "specification_name": goodObj.SpecificationName,
  6909. })
  6910. return
  6911. }
  6912. }
  6913. }
  6914. // 查询信息规挡的设置天数
  6915. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6916. if infor.ID > 0 && infor.WeekDay > 0 {
  6917. var cha_time int64
  6918. timeNowStr := time.Now().Format("2006-01-02")
  6919. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6920. //今日的日期减去设置的日期
  6921. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6922. if cha_time >= record_time {
  6923. //查询审核是否允许
  6924. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6925. //申请状态不允许的情况 拒绝修改
  6926. if infor.ApplicationStatus != 1 {
  6927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6928. return
  6929. }
  6930. }
  6931. }
  6932. //出库逻辑
  6933. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6934. if err != nil {
  6935. utils.ErrorLog(err.Error())
  6936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6937. return
  6938. }
  6939. finish := models.XtDialysisFinish{
  6940. IsFinish: 1,
  6941. UserOrgId: adminInfo.Org.Id,
  6942. Status: 1,
  6943. Ctime: time.Now().Unix(),
  6944. Mtime: 0,
  6945. Module: 11,
  6946. RecordDate: record_time,
  6947. Sourse: 1,
  6948. PatientId: patient_id,
  6949. }
  6950. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6951. if dialysisFinish.ID == 0 {
  6952. service.CreateDialysisFinish(finish)
  6953. }
  6954. //查询当天出库的数据
  6955. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6956. for _, item := range list {
  6957. prepare := models.DialysisBeforePrepare{
  6958. UserOrgId: item.OrgId,
  6959. PatientId: item.PatientId,
  6960. RecordDate: item.RecordTime,
  6961. GoodId: item.GoodId,
  6962. GoodTypeId: item.GoodTypeId,
  6963. Count: item.Count,
  6964. Creater: adminInfo.AdminUser.Id,
  6965. Status: 1,
  6966. Ctime: time.Now().Unix(),
  6967. ProjectId: item.ProjectId,
  6968. StorehouseId: houseConfig.StorehouseOutInfo,
  6969. }
  6970. //清空准备表的数据
  6971. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6972. //插入准备表数据
  6973. service.CreateDialysisBeforePrepareOne(&prepare)
  6974. //查询默认仓库
  6975. //查询默认仓库
  6976. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6977. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6978. var total_count int64
  6979. for _, it := range stockList {
  6980. total_count += it.StockCount
  6981. }
  6982. //基础库插入数据
  6983. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6984. ////更新剩余库存
  6985. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6986. var flush_count int64
  6987. for _, it := range goodList {
  6988. flush_count += it.StockCount
  6989. }
  6990. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6991. if errs != nil {
  6992. goodErrcode := models.XtGoodErrcode{
  6993. UserOrgId: item.OrgId,
  6994. Errcode: "手动出库更新剩余出库失败",
  6995. GoodId: item.GoodId,
  6996. Status: 1,
  6997. Ctime: time.Now().Unix(),
  6998. Mtime: 0,
  6999. Count: 0,
  7000. StockCount: 0,
  7001. Creater: adminInfo.AdminUser.Id,
  7002. BatchNumberId: 0,
  7003. WarehouseOutId: 0,
  7004. }
  7005. service.CreateGoodErrcode(goodErrcode)
  7006. }
  7007. }
  7008. //更新自动出库的地方
  7009. var errs error
  7010. if errs == nil {
  7011. c.ServeSuccessJSON(map[string]interface{}{
  7012. "msg": "修改成功",
  7013. "message": "2",
  7014. "good_name": "",
  7015. "specification_name": "",
  7016. })
  7017. return
  7018. } else {
  7019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7020. return
  7021. }
  7022. }
  7023. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7024. newArr = make([]*models.DialysisBeforePrepare, 0)
  7025. for i := 0; i < len(arr); i++ {
  7026. repeat := false
  7027. for j := i + 1; j < len(arr); j++ {
  7028. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7029. repeat = true
  7030. break
  7031. }
  7032. }
  7033. if !repeat {
  7034. newArr = append(newArr, arr[i])
  7035. }
  7036. }
  7037. return
  7038. }
  7039. func (c *DialysisAPIController) GetAllDrug() {
  7040. patient_id, _ := c.GetInt64("patient_id", 0)
  7041. adminInfo := c.GetMobileAdminUserInfo()
  7042. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7043. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7044. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7045. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7046. c.ServeSuccessJSON(map[string]interface{}{
  7047. "base_drug_config": drugStockConfig,
  7048. "private_drug_config": privateDrugConfig,
  7049. "base_drug_list": drugList,
  7050. "private_drug_list": privateDrugList,
  7051. })
  7052. }
  7053. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7054. newArr = make([]*models.DialysisBeforePrepare, 0)
  7055. for i := 0; i < len(arr); i++ {
  7056. repeat := false
  7057. for j := i + 1; j < len(arr); j++ {
  7058. if arr[i].GoodId == arr[j].GoodId {
  7059. repeat = true
  7060. break
  7061. }
  7062. }
  7063. if !repeat {
  7064. newArr = append(newArr, arr[i])
  7065. }
  7066. }
  7067. return
  7068. }
  7069. func (c *DialysisAPIController) GetDepartment() {
  7070. adminInfo := c.GetMobileAdminUserInfo()
  7071. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7072. if err == nil {
  7073. c.ServeSuccessJSON(map[string]interface{}{
  7074. "departments": departments,
  7075. })
  7076. } else {
  7077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7078. return
  7079. }
  7080. }
  7081. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7082. types, _ := c.GetInt("type", 0)
  7083. start_time := c.GetString("start_time")
  7084. end_time := c.GetString("end_time")
  7085. orgId := c.GetMobileAdminUserInfo().Org.Id
  7086. timeLayout := "2006-01-02"
  7087. loc, _ := time.LoadLocation("Local")
  7088. var startTime int64
  7089. if len(start_time) > 0 {
  7090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7091. if err != nil {
  7092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7093. return
  7094. }
  7095. startTime = theTime.Unix()
  7096. }
  7097. var endTime int64
  7098. if len(end_time) > 0 {
  7099. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7100. if err != nil {
  7101. utils.ErrorLog(err.Error())
  7102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7103. return
  7104. }
  7105. endTime = theTime.Unix()
  7106. }
  7107. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7108. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7109. if err != nil {
  7110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7111. } else {
  7112. c.ServeSuccessJSON(map[string]interface{}{
  7113. "list": list,
  7114. "type": types,
  7115. "stockTotal": stockTotal,
  7116. })
  7117. }
  7118. }
  7119. func (c *DialysisAPIController) GetPrescriptionList() {
  7120. start_time := c.GetString("start_time")
  7121. end_time := c.GetString("end_time")
  7122. schedule_type, _ := c.GetInt64("schedule_type")
  7123. partion_id, _ := c.GetInt64("partion_id")
  7124. orgId := c.GetMobileAdminUserInfo().Org.Id
  7125. timeLayout := "2006-01-02"
  7126. loc, _ := time.LoadLocation("Local")
  7127. var startTime int64
  7128. if len(start_time) > 0 {
  7129. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7130. if err != nil {
  7131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7132. return
  7133. }
  7134. startTime = theTime.Unix()
  7135. }
  7136. var endTime int64
  7137. if len(end_time) > 0 {
  7138. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7139. if err != nil {
  7140. utils.ErrorLog(err.Error())
  7141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7142. return
  7143. }
  7144. endTime = theTime.Unix()
  7145. }
  7146. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7147. fmt.Println("schedulelist22222222", schedulelist)
  7148. c.ServeSuccessJSON(map[string]interface{}{
  7149. "list": schedulelist,
  7150. })
  7151. return
  7152. }
  7153. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7154. ids := c.GetString("ids")
  7155. //patient_id, _ := c.GetInt64("patient_id")
  7156. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7157. idArray := strings.Split(ids, ",")
  7158. err := service.BatchDeleteMonitor(idArray)
  7159. fmt.Print("err", err)
  7160. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7161. //redis := service.RedisClient()
  7162. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7163. //redis.Set(key, "", time.Second)
  7164. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7165. //redis.Set(keyOne, "", time.Second)
  7166. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7167. //redis.Close()
  7168. c.ServeSuccessJSON(map[string]interface{}{
  7169. "msg": "批量删除成功",
  7170. })
  7171. return
  7172. }
  7173. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7174. id, _ := c.GetInt64("id")
  7175. timeLayout := "2006-01-02"
  7176. loc, _ := time.LoadLocation("Local")
  7177. //start_time := time.Now().Format("2006-01-02")
  7178. start_time := c.GetString("start_time")
  7179. end_time := c.GetString("end_time")
  7180. var startdateunix int64
  7181. if len(start_time) > 0 {
  7182. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7183. if err != nil {
  7184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7185. return
  7186. }
  7187. startdateunix = theTime.Unix()
  7188. }
  7189. var enddateunix int64
  7190. if len(end_time) > 0 {
  7191. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7192. if err != nil {
  7193. utils.ErrorLog(err.Error())
  7194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7195. return
  7196. }
  7197. enddateunix = theTime.Unix()
  7198. }
  7199. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7200. //nowTime := time.Now()
  7201. //endTime := nowTime.AddDate(-30, 0, 0)
  7202. //endTimes := endTime.Format("2006-01-02")
  7203. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7204. org_id := c.GetMobileAdminUserInfo().Org.Id
  7205. //if org_id == 10579 {
  7206. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7207. // c.ServeSuccessJSON(map[string]interface{}{
  7208. // "list": list,
  7209. // })
  7210. // return
  7211. //} else {
  7212. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7213. // c.ServeSuccessJSON(map[string]interface{}{
  7214. // "list": list,
  7215. // })
  7216. // return
  7217. //}
  7218. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  7219. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7220. c.ServeSuccessJSON(map[string]interface{}{
  7221. "list": list,
  7222. })
  7223. return
  7224. } else {
  7225. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7226. c.ServeSuccessJSON(map[string]interface{}{
  7227. "list": list,
  7228. })
  7229. }
  7230. return
  7231. }
  7232. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7233. dataBody := make(map[string]interface{}, 0)
  7234. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7235. ids := c.GetString("ids")
  7236. idArray := strings.Split(ids, ",")
  7237. origin, _ := c.GetInt64("origin")
  7238. if origin == 1 {
  7239. err = service.BatchDeleteAdvice(idArray)
  7240. fmt.Print("err", err)
  7241. c.ServeSuccessJSON(map[string]interface{}{
  7242. "msg": "批量删除成功",
  7243. })
  7244. return
  7245. }
  7246. if origin == 2 {
  7247. service.BatchDeleteHisAdvice(idArray)
  7248. }
  7249. }
  7250. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7251. good_id, _ := c.GetInt64("good_id")
  7252. count, _ := c.GetInt64("count")
  7253. record_time, _ := c.GetInt64("record_time")
  7254. patient_id, _ := c.GetInt64("patient_id")
  7255. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7256. c.ServeSuccessJSON(map[string]interface{}{
  7257. "detail": detail,
  7258. })
  7259. return
  7260. }
  7261. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7262. good_id, _ := c.GetInt64("good_id")
  7263. record_time, _ := c.GetInt64("record_time")
  7264. patient_id, _ := c.GetInt64("patient_id")
  7265. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7266. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7267. fmt.Print("err", err)
  7268. c.ServeSuccessJSON(map[string]interface{}{
  7269. "msg": "批量删除成功",
  7270. })
  7271. return
  7272. }
  7273. func (c *DialysisAPIController) BatchAdviceCheck() {
  7274. ids := c.GetString("ids")
  7275. idArray := strings.Split(ids, ",")
  7276. creator, _ := c.GetInt64("creator")
  7277. origin, _ := c.GetInt64("origin")
  7278. if origin == 1 {
  7279. err := service.BatchAdviceCheck(idArray, creator)
  7280. fmt.Println(err)
  7281. list, _ := service.GetAdviceExecutionById(idArray)
  7282. c.ServeSuccessJSON(map[string]interface{}{
  7283. "list": list,
  7284. })
  7285. return
  7286. }
  7287. if origin == 2 {
  7288. service.BatchHisAdviceCheck(idArray, creator)
  7289. list, _ := service.GetHisAdviceExecutionById(idArray)
  7290. c.ServeSuccessJSON(map[string]interface{}{
  7291. "list": list,
  7292. })
  7293. return
  7294. }
  7295. }
  7296. func (c *DialysisAPIController) BatchAdviceExecution() {
  7297. ids := c.GetString("ids")
  7298. idArray := strings.Split(ids, ",")
  7299. executionTime := c.GetString("execution_time")
  7300. creator, _ := c.GetInt64("creator")
  7301. timeLayout := "2006-01-02 15:04:05"
  7302. loc, _ := time.LoadLocation("Local")
  7303. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7304. orgin, _ := c.GetInt64("origin")
  7305. if orgin == 1 {
  7306. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7307. list, _ := service.GetAdviceExecutionById(idArray)
  7308. fmt.Println(err)
  7309. c.ServeSuccessJSON(map[string]interface{}{
  7310. "list": list,
  7311. })
  7312. return
  7313. }
  7314. if orgin == 2 {
  7315. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7316. list, _ := service.GetHisAdviceExecutionById(idArray)
  7317. fmt.Println(err)
  7318. c.ServeSuccessJSON(map[string]interface{}{
  7319. "list": list,
  7320. })
  7321. return
  7322. }
  7323. }
  7324. func (c *DialysisAPIController) UpdateStockGoods() {
  7325. good_id, _ := c.GetInt64("good_id")
  7326. record_time, _ := c.GetInt64("record_time")
  7327. patient_id, _ := c.GetInt64("patient_id")
  7328. count, _ := c.GetInt64("count")
  7329. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7330. fmt.Print("err", err)
  7331. c.ServeSuccessJSON(map[string]interface{}{
  7332. "msg": "更新成功",
  7333. })
  7334. return
  7335. }
  7336. // 当前数据比上一次出库数据少
  7337. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7338. //查询该患者当天已经出库的耗材信息
  7339. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7340. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7341. for i := len(goods_yc) - 1; i >= 0; i-- {
  7342. goods_yc_temp := goods_yc[i]
  7343. for j := len(goods) - 1; j >= 0; j-- {
  7344. goods_temp := goods[j]
  7345. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7346. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7347. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7348. if goods_yc_temp.Count == goods_temp.Count {
  7349. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7350. goods = append(goods[:j], goods[j+1:]...)
  7351. break
  7352. }
  7353. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7354. if goods_yc_temp.Count > goods_temp.Count {
  7355. temp_count := goods_yc_temp.Count - goods_temp.Count
  7356. goods_yc[i].Count = temp_count
  7357. goods = append(goods[:j], goods[j+1:]...)
  7358. break
  7359. }
  7360. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7361. if goods_yc_temp.Count < goods_temp.Count {
  7362. temp_count := goods_temp.Count - goods_yc_temp.Count
  7363. goods[j].Count = temp_count
  7364. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7365. break
  7366. }
  7367. }
  7368. }
  7369. }
  7370. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7371. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7372. //退库
  7373. if len(goods_yc) > 0 {
  7374. for _, good_yc := range goods_yc {
  7375. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7376. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7377. }
  7378. }
  7379. return nil
  7380. }
  7381. // 耗材出库删除
  7382. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7383. // 先根据相关信息查询当天该耗材的出库信息
  7384. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7385. if err != nil {
  7386. return err
  7387. }
  7388. var delete_count int64 = 0
  7389. delete_count = warehouseOutInfos.Count - count
  7390. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7391. // 在出库记录表里记录退库详情
  7392. warehouseOutInfo := &models.WarehouseOutInfo{
  7393. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7394. WarehouseOutId: warehouseOut.ID,
  7395. Status: 1,
  7396. Ctime: time.Now().Unix(),
  7397. OrgId: orgID,
  7398. Type: 1,
  7399. IsSys: 1,
  7400. SysRecordTime: record_time,
  7401. GoodTypeId: good_yc.GoodTypeId,
  7402. GoodId: good_yc.GoodId,
  7403. PatientId: good_yc.PatientId,
  7404. ConsumableType: 2,
  7405. StorehouseId: houseConfig.StorehouseOutInfo,
  7406. IsCheck: 1,
  7407. }
  7408. warehouseOutInfo.Count = count
  7409. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7410. warehouseOutInfo.Price = stockInInfo.Price
  7411. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7412. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7413. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7414. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7415. warehouseOutInfo.Number = warehouseOutInfos.Number
  7416. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7417. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7418. //查找当天是否存在出库记录
  7419. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7420. if errcod == gorm.ErrRecordNotFound {
  7421. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7422. //插入详情明细表
  7423. stockFlow := models.VmStockFlow{
  7424. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7425. WarehouseOutId: warehouseOut.ID,
  7426. GoodId: good_yc.GoodId,
  7427. Number: warehouseOutInfos.Number,
  7428. ProductDate: stockInInfo.ProductDate,
  7429. ExpireDate: stockInInfo.ExpiryDate,
  7430. Count: count,
  7431. Price: stockInInfo.Price,
  7432. Status: 1,
  7433. Ctime: time.Now().Unix(),
  7434. UserOrgId: good_yc.OrgId,
  7435. Manufacturer: stockInInfo.Manufacturer,
  7436. Dealer: stockInInfo.Dealer,
  7437. LicenseNumber: stockInInfo.LicenseNumber,
  7438. IsEdit: 2,
  7439. Creator: creater,
  7440. SystemTime: record_time,
  7441. ConsumableType: 3,
  7442. WarehousingDetailId: 0,
  7443. IsSys: 1,
  7444. UpdateCreator: creater,
  7445. PatientId: patient_id,
  7446. StorehouseId: houseConfig.StorehouseOutInfo,
  7447. }
  7448. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7449. if errflow == gorm.ErrRecordNotFound {
  7450. //创建流水表
  7451. err := service.CreateStockFlowOne(stockFlow)
  7452. fmt.Println("err", err)
  7453. } else if errflow == nil {
  7454. //插入详情明细表
  7455. stockFlow := models.VmStockFlow{
  7456. ID: exsit.ID,
  7457. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7458. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7459. WarehouseOutId: warehouseOut.ID,
  7460. GoodId: good_yc.GoodId,
  7461. Number: warehouseOutInfos.Number,
  7462. ProductDate: stockInInfo.ProductDate,
  7463. ExpireDate: stockInInfo.ExpiryDate,
  7464. Count: exsit.Count - delete_count,
  7465. Price: stockInInfo.Price,
  7466. Status: 1,
  7467. Ctime: time.Now().Unix(),
  7468. UserOrgId: good_yc.OrgId,
  7469. Manufacturer: stockInInfo.Manufacturer,
  7470. Dealer: stockInInfo.Dealer,
  7471. LicenseNumber: stockInInfo.LicenseNumber,
  7472. IsEdit: 2,
  7473. Creator: creater,
  7474. SystemTime: record_time,
  7475. ConsumableType: 3,
  7476. WarehousingDetailId: 0,
  7477. IsSys: 1,
  7478. UpdateCreator: creater,
  7479. PatientId: patient_id,
  7480. StorehouseId: houseConfig.StorehouseOutInfo,
  7481. }
  7482. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7483. }
  7484. if errOne != nil {
  7485. return errOne
  7486. }
  7487. } else if errcod == nil {
  7488. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7489. //插入详情明细表
  7490. stockFlow := models.VmStockFlow{
  7491. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7492. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7493. WarehouseOutId: warehouseOut.ID,
  7494. GoodId: good_yc.GoodId,
  7495. Number: warehouseOutInfos.Number,
  7496. ProductDate: stockInInfo.ProductDate,
  7497. ExpireDate: stockInInfo.ExpiryDate,
  7498. Count: count,
  7499. Price: stockInInfo.Price,
  7500. Status: 1,
  7501. Ctime: time.Now().Unix(),
  7502. UserOrgId: good_yc.OrgId,
  7503. Manufacturer: stockInInfo.Manufacturer,
  7504. Dealer: stockInInfo.Dealer,
  7505. LicenseNumber: stockInInfo.LicenseNumber,
  7506. IsEdit: 2,
  7507. Creator: creater,
  7508. SystemTime: record_time,
  7509. ConsumableType: 3,
  7510. WarehousingDetailId: 0,
  7511. IsSys: 1,
  7512. UpdateCreator: creater,
  7513. PatientId: patient_id,
  7514. ReturnCount: delete_count,
  7515. StorehouseId: houseConfig.StorehouseOutInfo,
  7516. }
  7517. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7518. if errflows == gorm.ErrRecordNotFound {
  7519. //创建流水表
  7520. service.CreateStockFlowOne(stockFlow)
  7521. } else if errflows == nil {
  7522. stockFlow := models.VmStockFlow{
  7523. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7524. ID: exsit.ID,
  7525. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7526. WarehouseOutId: warehouseOut.ID,
  7527. GoodId: good_yc.GoodId,
  7528. Number: warehouseOutInfos.Number,
  7529. ProductDate: stockInInfo.ProductDate,
  7530. ExpireDate: stockInInfo.ExpiryDate,
  7531. Count: exsit.Count - delete_count,
  7532. Price: stockInInfo.Price,
  7533. Status: 1,
  7534. Ctime: time.Now().Unix(),
  7535. UserOrgId: good_yc.OrgId,
  7536. Manufacturer: stockInInfo.Manufacturer,
  7537. Dealer: stockInInfo.Dealer,
  7538. LicenseNumber: stockInInfo.LicenseNumber,
  7539. IsEdit: 2,
  7540. Creator: creater,
  7541. SystemTime: record_time,
  7542. ConsumableType: 3,
  7543. WarehousingDetailId: 0,
  7544. IsSys: 1,
  7545. UpdateCreator: creater,
  7546. PatientId: patient_id,
  7547. ReturnCount: delete_count,
  7548. StorehouseId: houseConfig.StorehouseOutInfo,
  7549. }
  7550. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7551. }
  7552. }
  7553. //更改自动出库的表格
  7554. details := models.BloodAutomaticReduceDetail{
  7555. WarehouseOutId: warehouseOutInfo.ID,
  7556. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7557. PatientId: patient_id,
  7558. Ctime: time.Now().Unix(),
  7559. Mtime: time.Now().Unix(),
  7560. Status: 1,
  7561. RecordTime: record_time,
  7562. OrgId: orgID,
  7563. GoodId: good_yc.GoodId,
  7564. GoodTypeId: good_yc.GoodTypeId,
  7565. Count: count,
  7566. StorehouseId: houseConfig.StorehouseOutInfo,
  7567. }
  7568. //查询当天耗材是否已经存在数据
  7569. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7570. if errcode == gorm.ErrRecordNotFound {
  7571. errTwo := service.CreateAutoReduceRecord(&details)
  7572. if errTwo != nil {
  7573. return errTwo
  7574. }
  7575. } else if errcode == nil {
  7576. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7577. service.CreateAutoReduceRecord(&details)
  7578. }
  7579. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7580. //增加出库库存数量
  7581. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7582. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7583. fmt.Println("errOne", errOne)
  7584. // 删除出库完成后,要增加对应批次的库存数量
  7585. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7586. if errThree != nil {
  7587. return errThree
  7588. }
  7589. if good_yc.Count == 0 {
  7590. return nil
  7591. } else {
  7592. return errors.New("退库和出库数据不匹配")
  7593. }
  7594. }
  7595. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7596. //查询该患者当天已经出库的耗材信息
  7597. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7598. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7599. for i := len(goods_yc) - 1; i >= 0; i-- {
  7600. goods_yc_temp := goods_yc[i]
  7601. for j := len(goods) - 1; j >= 0; j-- {
  7602. goods_temp := goods[j]
  7603. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7604. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7605. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7606. if goods_yc_temp.Count == goods_temp.Count {
  7607. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7608. goods = append(goods[:j], goods[j+1:]...)
  7609. break
  7610. }
  7611. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7612. if goods_yc_temp.Count > goods_temp.Count {
  7613. temp_count := goods_yc_temp.Count - goods_temp.Count
  7614. goods_yc[i].Count = temp_count
  7615. goods = append(goods[:j], goods[j+1:]...)
  7616. break
  7617. }
  7618. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7619. if goods_yc_temp.Count < goods_temp.Count {
  7620. temp_count := goods_temp.Count - goods_yc_temp.Count
  7621. goods[j].Count = temp_count
  7622. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7623. break
  7624. }
  7625. }
  7626. }
  7627. }
  7628. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7629. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7630. fmt.Println("剩余需要出库的", len(goods))
  7631. if len(goods) > 0 {
  7632. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7633. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7634. if err == gorm.ErrRecordNotFound {
  7635. //没有记录,则创建出库单
  7636. timeStr := time.Now().Format("2006-01-02")
  7637. timeArr := strings.Split(timeStr, "-")
  7638. total, _ := service.FindAllWarehouseOut(orgID)
  7639. total = total + 1
  7640. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7641. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7642. number = number + total
  7643. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7644. warehouseOut := models.WarehouseOut{
  7645. WarehouseOutOrderNumber: warehousing_out_order,
  7646. OperationTime: time.Now().Unix(),
  7647. OrgId: orgID,
  7648. Creater: creater,
  7649. Ctime: time.Now().Unix(),
  7650. Status: 1,
  7651. WarehouseOutTime: record_time,
  7652. Dealer: 0,
  7653. Manufacturer: 0,
  7654. Type: 1,
  7655. IsSys: 1,
  7656. StorehouseId: houseConfig.StorehouseOutInfo,
  7657. IsCheck: 1,
  7658. }
  7659. err := service.AddSigleWarehouseOut(&warehouseOut)
  7660. if err != nil {
  7661. utils.TraceLog("创建出库单失败 err = %v", err)
  7662. return err
  7663. } else {
  7664. out = warehouseOut
  7665. }
  7666. }
  7667. for _, item := range goods {
  7668. var newCount int64 = 0
  7669. for _, it := range goodOne {
  7670. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7671. newCount = it.Count
  7672. }
  7673. }
  7674. prepare := models.DialysisBeforePrepare{
  7675. GoodTypeId: item.GoodTypeId,
  7676. GoodId: item.GoodId,
  7677. Count: item.Count,
  7678. StorehouseId: houseConfig.StorehouseOutInfo,
  7679. }
  7680. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7681. //增加出库数量
  7682. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7683. }
  7684. }
  7685. if len(goods_yc) > 0 {
  7686. for _, good_yc := range goods_yc {
  7687. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7688. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7689. }
  7690. }
  7691. return nil
  7692. }
  7693. // 耗材出库删除
  7694. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7695. // 先根据相关信息查询当天该耗材的出库信息
  7696. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7697. if err != nil {
  7698. return err
  7699. }
  7700. var delete_count int64 = 0
  7701. for _, ware := range warehouseOutInfos {
  7702. // 判断当前出库的数据和删除出库数量
  7703. if good_yc.Count <= ware.Count {
  7704. delete_count = good_yc.Count
  7705. } else {
  7706. delete_count = ware.Count
  7707. }
  7708. warehouseOutInfo := &models.WarehouseOutInfo{
  7709. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7710. WarehouseOutId: warehouseOut.ID,
  7711. Status: 1,
  7712. Ctime: time.Now().Unix(),
  7713. Remark: "",
  7714. OrgId: orgID,
  7715. Type: 1,
  7716. Manufacturer: 0,
  7717. Dealer: 0,
  7718. IsSys: 0,
  7719. SysRecordTime: record_time,
  7720. GoodTypeId: good_yc.GoodTypeId,
  7721. GoodId: good_yc.GoodId,
  7722. StorehouseId: warehouseOut.StorehouseId,
  7723. IsCheck: 1,
  7724. }
  7725. warehouseOutInfo.Count = delete_count
  7726. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7727. warehouseOutInfo.Price = stockInInfo.Price
  7728. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7729. if errOne != nil {
  7730. return errOne
  7731. }
  7732. // 删除出库完成后,要改变流水库存(有疑问)
  7733. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7734. fmt.Println("errOne", errOne)
  7735. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7736. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7737. //扣减出库数量
  7738. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7739. if errThree != nil {
  7740. return errThree
  7741. }
  7742. }
  7743. if good_yc.Count == 0 {
  7744. return nil
  7745. } else {
  7746. return errors.New("退库和出库数据不匹配")
  7747. }
  7748. }
  7749. func (this *DialysisAPIController) GetMobileScheduleList() {
  7750. limit, _ := this.GetInt64("limit")
  7751. page, _ := this.GetInt64("page")
  7752. type_options_visible, _ := this.GetInt64("type_options_visible")
  7753. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7754. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7755. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7756. }
  7757. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7758. newArr = make([]*models.HisPrescriptionProject, 0)
  7759. for i := 0; i < len(arr); i++ {
  7760. repeat := false
  7761. for j := i + 1; j < len(arr); j++ {
  7762. if arr[i].TeamId == arr[j].TeamId {
  7763. repeat = true
  7764. break
  7765. }
  7766. }
  7767. if !repeat {
  7768. newArr = append(newArr, arr[i])
  7769. }
  7770. }
  7771. return
  7772. }
  7773. func (this *DialysisAPIController) GetRoleList() {
  7774. admin_user_id, _ := this.GetInt64("admin_user_id")
  7775. orgid := this.GetMobileAdminUserInfo().Org.Id
  7776. list, err := service.GetRoleList(orgid, admin_user_id)
  7777. fmt.Println(err)
  7778. this.ServeSuccessJSON(map[string]interface{}{
  7779. "list": list,
  7780. })
  7781. return
  7782. }
  7783. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7784. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7785. // 先根据相关信息查询当天该耗材的出库信息
  7786. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7787. if err != nil {
  7788. return err
  7789. }
  7790. var delete_count int64 = 0
  7791. delete_count = warehouseOutInfos.Count - count
  7792. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7793. // 删除出库完成后,要增加对应批次的库存数量
  7794. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7795. if errThree != nil {
  7796. return errThree
  7797. }
  7798. //增加退库数量
  7799. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7800. //扣减出库数量
  7801. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7802. //查询剩余库存
  7803. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7804. var sum_count int64
  7805. for _, item := range goodList {
  7806. sum_count += item.StockCount
  7807. }
  7808. // 在出库记录表里记录退库详情
  7809. warehouseOutInfo := &models.WarehouseOutInfo{
  7810. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7811. WarehouseOutId: warehouseOut.ID,
  7812. Status: 1,
  7813. Ctime: time.Now().Unix(),
  7814. OrgId: orgID,
  7815. Type: 1,
  7816. IsSys: 1,
  7817. SysRecordTime: record_time,
  7818. GoodTypeId: good_yc.GoodTypeId,
  7819. GoodId: good_yc.GoodId,
  7820. PatientId: good_yc.PatientId,
  7821. ConsumableType: 2,
  7822. StorehouseId: houseConfig.StorehouseOutInfo,
  7823. IsCheck: 1,
  7824. OverCount: sum_count,
  7825. }
  7826. warehouseOutInfo.Count = count
  7827. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7828. warehouseOutInfo.Price = stockInInfo.Price
  7829. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7830. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7831. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7832. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7833. warehouseOutInfo.Number = warehouseOutInfos.Number
  7834. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7835. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7836. //查找当天是否存在出库记录
  7837. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7838. if errcod == gorm.ErrRecordNotFound {
  7839. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7840. //插入详情明细表
  7841. if errOne != nil {
  7842. return errOne
  7843. }
  7844. //插入详情明细表
  7845. stockFlow := models.VmStockFlow{
  7846. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7847. WarehouseOutId: warehouseOut.ID,
  7848. GoodId: good_yc.GoodId,
  7849. Number: warehouseOutInfos.Number,
  7850. ProductDate: stockInInfo.ProductDate,
  7851. ExpireDate: stockInInfo.ExpiryDate,
  7852. Count: count,
  7853. Price: stockInInfo.Price,
  7854. Status: 1,
  7855. Ctime: time.Now().Unix(),
  7856. UserOrgId: good_yc.OrgId,
  7857. Manufacturer: stockInInfo.Manufacturer,
  7858. Dealer: stockInInfo.Dealer,
  7859. LicenseNumber: stockInInfo.LicenseNumber,
  7860. IsEdit: 2,
  7861. Creator: creater,
  7862. SystemTime: record_time,
  7863. ConsumableType: 3,
  7864. WarehousingDetailId: 0,
  7865. IsSys: 1,
  7866. UpdateCreator: creater,
  7867. PatientId: patient_id,
  7868. StorehouseId: houseConfig.StorehouseOutInfo,
  7869. OverCount: sum_count,
  7870. ProjectId: good_yc.ProjectId,
  7871. }
  7872. err := service.CreateStockFlowOne(stockFlow)
  7873. fmt.Println("err", err)
  7874. } else if errcod == nil {
  7875. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7876. }
  7877. //创建退库单
  7878. operation_time := time.Now().Unix()
  7879. //创建退库单
  7880. timeStr := time.Now().Format("2006-01-02")
  7881. timeArr := strings.Split(timeStr, "-")
  7882. total, _ := service.FindAllCancelStockTotal(orgID)
  7883. total = total + 1
  7884. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7885. cancelStock := models.CancelStock{
  7886. OrderNumber: orderNumber,
  7887. OperaTime: operation_time,
  7888. OrgId: orgID,
  7889. Creater: warehouseOut.Creater,
  7890. Ctime: time.Now().Unix(),
  7891. Status: 1,
  7892. ReturnTime: record_time,
  7893. Type: 1,
  7894. StorehouseId: stockInInfo.StorehouseId,
  7895. IsCheck: 1,
  7896. }
  7897. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7898. if msgerrkonde == gorm.ErrRecordNotFound {
  7899. service.AddSigleCancelStock(&cancelStock)
  7900. }
  7901. cancel, _ := service.GetLastCancelStockById(orgID)
  7902. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7903. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7904. cancelStockInfo := models.CancelStockInfo{
  7905. GoodId: stockInInfo.GoodId,
  7906. CancelStockId: cancel.ID,
  7907. GoodTypeId: stockInInfo.GoodTypeId,
  7908. Count: delete_count,
  7909. Price: stockInInfo.PackingPrice,
  7910. Total: 0,
  7911. ProductDate: stockInInfo.ProductDate,
  7912. ExpiryDate: stockInInfo.ExpiryDate,
  7913. Ctime: time.Now().Unix(),
  7914. Status: 1,
  7915. OrgId: orgID,
  7916. OrderNumber: cancel.OrderNumber,
  7917. Type: 0,
  7918. Dealer: deaerler.DealerName,
  7919. Manufacturer: manufacturer.ManufacturerName,
  7920. Number: stockInInfo.Number,
  7921. RegisterAccount: "",
  7922. Remark: "",
  7923. WarehouseInfoId: stockInInfo.ID,
  7924. PatientId: patient_id,
  7925. RecordDate: record_time,
  7926. StorehouseId: stockInInfo.StorehouseId,
  7927. IsCheck: 1,
  7928. }
  7929. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7930. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7931. flow := models.VmStockFlow{
  7932. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7933. GoodId: good_yc.GoodId,
  7934. Number: warehouseOutInfos.Number,
  7935. LicenseNumber: stockInInfo.LicenseNumber,
  7936. Count: delete_count,
  7937. UserOrgId: orgID,
  7938. PatientId: patient_id,
  7939. SystemTime: record_time,
  7940. ConsumableType: 7,
  7941. IsSys: 0,
  7942. WarehousingOrder: "",
  7943. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7944. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7945. IsEdit: 0,
  7946. CancelStockId: cancel.ID,
  7947. CancelOrderNumber: cancel.OrderNumber,
  7948. Manufacturer: manufacturer.ID,
  7949. Dealer: 0,
  7950. Creator: warehouseOut.Creater,
  7951. UpdateCreator: 0,
  7952. Status: 1,
  7953. Ctime: time.Now().Unix(),
  7954. Mtime: 0,
  7955. Price: stockInInfo.Price,
  7956. WarehousingDetailId: stockInInfo.ID,
  7957. WarehouseOutDetailId: warehouseOutInfos.ID,
  7958. CancelOutDetailId: cancelInfo.ID,
  7959. ProductDate: stockInInfo.ProductDate,
  7960. ExpireDate: stockInInfo.ExpiryDate,
  7961. StorehouseId: houseConfig.StorehouseOutInfo,
  7962. OverCount: sum_count,
  7963. }
  7964. service.CreateStockFlowOne(flow)
  7965. //更改自动出库的表格
  7966. details := models.BloodAutomaticReduceDetail{
  7967. WarehouseOutId: warehouseOutInfo.ID,
  7968. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7969. PatientId: patient_id,
  7970. Ctime: time.Now().Unix(),
  7971. Mtime: time.Now().Unix(),
  7972. Status: 1,
  7973. RecordTime: record_time,
  7974. OrgId: orgID,
  7975. GoodId: good_yc.GoodId,
  7976. GoodTypeId: good_yc.GoodTypeId,
  7977. Count: count,
  7978. StorehouseId: houseConfig.StorehouseOutInfo,
  7979. }
  7980. //查询当天耗材是否已经存在数据
  7981. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7982. if errcode == gorm.ErrRecordNotFound {
  7983. errTwo := service.CreateAutoReduceRecord(&details)
  7984. if errTwo != nil {
  7985. return errTwo
  7986. }
  7987. } else if errcode == nil {
  7988. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7989. service.CreateAutoReduceRecord(&details)
  7990. }
  7991. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7992. //增加出库库存数量
  7993. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7994. if good_yc.Count == 0 {
  7995. return nil
  7996. } else {
  7997. return errors.New("退库和出库数据不匹配")
  7998. }
  7999. }
  8000. func (this *DialysisAPIController) SavePatientSign() {
  8001. adminUserInfo := this.GetMobileAdminUserInfo()
  8002. patient_id, _ := this.GetInt64("patient_id")
  8003. dialysis_date, _ := this.GetInt64("dialysis_date")
  8004. orgid := adminUserInfo.Org.Id
  8005. var esdata models.DialysisOrder
  8006. var err error
  8007. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8009. return
  8010. }
  8011. esdata.Hash = esdata.Hash
  8012. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8013. order := models.DialysisOrder{
  8014. Hash: esdata.Hash,
  8015. Url: esdata.Url,
  8016. }
  8017. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8018. redis := service.RedisClient()
  8019. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8020. redis.Set(key, "", time.Second)
  8021. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8022. //清空key 值
  8023. redis.Set(keyOne, "", time.Second)
  8024. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8025. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8026. //redis.Set(keyTwo, "", time.Second)
  8027. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8028. redis.Set(keyThree, "", time.Second)
  8029. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8030. redis.Set(keyFour, "", time.Second)
  8031. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8032. redis.Set(keyFive, "", time.Second)
  8033. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8034. redis.Set(keySix, "", time.Second)
  8035. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8036. redis.Set(keySeven, "", time.Second)
  8037. if err != nil {
  8038. fmt.Println(err)
  8039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8040. return
  8041. }
  8042. this.ServeSuccessJSON(map[string]interface{}{
  8043. "electronic_signature": esdata,
  8044. })
  8045. }
  8046. func (this *DialysisAPIController) GetPatientSign() {
  8047. patient_id, _ := this.GetInt64("patient_id")
  8048. dialysis_date, _ := this.GetInt64("dialysis_date")
  8049. adminUserInfo := this.GetMobileAdminUserInfo()
  8050. orgId := adminUserInfo.Org.Id
  8051. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8052. if err != nil {
  8053. fmt.Println(err)
  8054. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8055. return
  8056. }
  8057. this.ServeSuccessJSON(map[string]interface{}{
  8058. "dialysisOrder": dialysisOrder,
  8059. })
  8060. }
  8061. func (this *DialysisAPIController) GetScheduleByPatient() {
  8062. patient_id, _ := this.GetInt64("patient_id")
  8063. schedule_date, _ := this.GetInt64("schedule_date")
  8064. orgid := this.GetMobileAdminUserInfo().Org.Id
  8065. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8066. this.ServeSuccessJSON(map[string]interface{}{
  8067. "schedule": schedule,
  8068. })
  8069. }
  8070. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8071. org_id := this.GetMobileAdminUserInfo().Org.Id
  8072. patient_id, _ := this.GetInt64("patient_id")
  8073. schedule_date, _ := this.GetInt64("schedule_date")
  8074. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8075. this.ServeSuccessJSON(map[string]interface{}{
  8076. "order": order,
  8077. })
  8078. }
  8079. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8080. org_id := this.GetMobileAdminUserInfo().Org.Id
  8081. schedule_date := this.GetString("schedule_date")
  8082. schedule_type, _ := this.GetInt64("schedule_type")
  8083. timeLayout := "2006-01-02"
  8084. loc, _ := time.LoadLocation("Local")
  8085. var startdateunix int64
  8086. if len(schedule_date) > 0 {
  8087. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8088. if err != nil {
  8089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8090. return
  8091. }
  8092. startdateunix = theTime.Unix()
  8093. }
  8094. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8095. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8096. devices, _ := service.GetAllDevicetByListSix(org_id)
  8097. for key, item := range scheduals {
  8098. // 床位信息
  8099. for _, device := range devices {
  8100. if item.BedId == device.ID {
  8101. scheduals[key].DeviceNumber = device
  8102. break
  8103. }
  8104. }
  8105. }
  8106. this.ServeSuccessJSON(map[string]interface{}{
  8107. "list": list,
  8108. "scheduals": scheduals,
  8109. })
  8110. }
  8111. func (this *DialysisAPIController) SavePatientPicture() {
  8112. patient_id, _ := this.GetInt64("patient_id")
  8113. dialysis_date, _ := this.GetInt64("schedule_date")
  8114. avatar := this.GetString("avatar")
  8115. fmt.Println("patient_id", patient_id)
  8116. orgId := this.GetMobileAdminUserInfo().Org.Id
  8117. order := models.DialysisOrder{
  8118. Url: avatar,
  8119. }
  8120. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8121. redis := service.RedisClient()
  8122. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8123. redis.Set(key, "", time.Second)
  8124. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8125. //清空key 值
  8126. redis.Set(keyOne, "", time.Second)
  8127. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8128. redis.Set(keyThree, "", time.Second)
  8129. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8130. redis.Set(keyFour, "", time.Second)
  8131. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8132. redis.Set(keyFive, "", time.Second)
  8133. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8134. redis.Set(keySix, "", time.Second)
  8135. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8136. redis.Set(keySeven, "", time.Second)
  8137. if err != nil {
  8138. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8139. return
  8140. }
  8141. this.ServeSuccessJSON(map[string]interface{}{
  8142. "order": order,
  8143. })
  8144. }
  8145. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8146. ids := this.GetString("ids")
  8147. idSplit := strings.Split(ids, ",")
  8148. orgId := this.GetMobileAdminUserInfo().Org.Id
  8149. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8150. execution_time := this.GetString("exce_time")
  8151. timeLayout2 := "2006-01-02 15:04:05"
  8152. loc, _ := time.LoadLocation("Local")
  8153. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8154. if errs != nil {
  8155. utils.ErrorLog(errs.Error())
  8156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8157. return
  8158. }
  8159. //his客户
  8160. if config.IsOpen == 1 {
  8161. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8162. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8163. for _, item := range list {
  8164. for _, it := range adviceList {
  8165. if item.DrugId == it.DrugId {
  8166. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8167. }
  8168. }
  8169. }
  8170. for _, item := range list {
  8171. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8172. var sum_out_count int64
  8173. for _, itemThree := range item.ChildDoctorAdvice {
  8174. var prescribing_number int64
  8175. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8176. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8177. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8178. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8179. }
  8180. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8181. prescribing_number = parseIntPrescribingNumber
  8182. }
  8183. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8184. prescribing_number = parseIntPrescribingNumber
  8185. }
  8186. sum_out_count += prescribing_number
  8187. }
  8188. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8189. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8190. //库存不足
  8191. if sum_out_count > drugStockOut.FlushCount {
  8192. this.ServeSuccessJSON(map[string]interface{}{
  8193. "msg": "2",
  8194. "drug": medical,
  8195. "ids": ids,
  8196. })
  8197. return
  8198. }
  8199. }
  8200. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8201. //执行医嘱
  8202. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8203. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8204. for _, item := range advices {
  8205. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8206. redis := service.RedisClient()
  8207. //清空key 值
  8208. redis.Set(key, "", time.Second)
  8209. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8210. redis.Set(keyTwo, "", time.Second)
  8211. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8212. redis.Set(keyThree, "", time.Second)
  8213. recordDate := theTime.Format("2006-01-02")
  8214. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8215. redis.Set(keyFour, "", time.Second)
  8216. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8217. redis.Set(keyFive, "", time.Second)
  8218. defer redis.Close()
  8219. }
  8220. if errs == nil {
  8221. //药品管理信息
  8222. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8223. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8224. if drugStockConfig.IsOpen == 1 {
  8225. for _, item := range advices {
  8226. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8227. config, _ := service.GetDrugOpenConfigOne(orgId)
  8228. if config.IsOpen != 1 {
  8229. //查询该药品是否有库存
  8230. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8231. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8232. if medical.IsUse == 2 {
  8233. if config.IsOpen != 1 {
  8234. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8235. service.HisDrugsDelivery(orgId, creater, &advice)
  8236. if orgId == 3877 || orgId == 10265 {
  8237. //查询该药品是否有出库记录
  8238. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8239. if len(flowMap) == 0 {
  8240. errs := service.UpdateHisAdviceById(advice.ID)
  8241. if errs != nil {
  8242. drugError := models.XtDrugError{
  8243. UserOrgId: orgId,
  8244. DrugId: item.DrugId,
  8245. RecordDate: item.AdviceDate,
  8246. PatientId: item.PatientId,
  8247. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8248. Status: 1,
  8249. Ctime: time.Now().Unix(),
  8250. Mtime: 0,
  8251. SumCount: 0,
  8252. Prescribingnumber: advice.PrescribingNumber,
  8253. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8254. }
  8255. service.CreateDrugError(drugError)
  8256. }
  8257. this.ServeSuccessJSON(map[string]interface{}{
  8258. "msg": "2",
  8259. "drug": medical,
  8260. "ids": ids,
  8261. })
  8262. return
  8263. }
  8264. }
  8265. }
  8266. if pharmacyConfig.IsOpen != 1 {
  8267. service.HisDrugsDelivery(orgId, creater, &advice)
  8268. if orgId == 3877 || orgId == 10265 {
  8269. //查询该药品是否有出库记录
  8270. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8271. if len(flowMap) == 0 {
  8272. errs := service.UpdateHisAdviceById(advice.ID)
  8273. if errs != nil {
  8274. drugError := models.XtDrugError{
  8275. UserOrgId: orgId,
  8276. DrugId: item.DrugId,
  8277. RecordDate: item.AdviceDate,
  8278. PatientId: item.PatientId,
  8279. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8280. Status: 1,
  8281. Ctime: time.Now().Unix(),
  8282. Mtime: 0,
  8283. SumCount: 0,
  8284. Prescribingnumber: advice.PrescribingNumber,
  8285. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8286. }
  8287. service.CreateDrugError(drugError)
  8288. }
  8289. this.ServeSuccessJSON(map[string]interface{}{
  8290. "msg": "2",
  8291. "drug": medical,
  8292. "ids": ids,
  8293. })
  8294. return
  8295. }
  8296. }
  8297. }
  8298. //更新字典里面的库存
  8299. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8300. var sum_count int64
  8301. for _, its := range stockInfo {
  8302. if its.MaxUnit == medical.MaxUnit {
  8303. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8304. }
  8305. sum_count += its.StockMaxNumber + its.StockMinNumber
  8306. }
  8307. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8308. //剩余库存
  8309. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8310. }
  8311. }
  8312. }
  8313. }
  8314. }
  8315. this.ServeSuccessJSON(map[string]interface{}{
  8316. "msg": "1",
  8317. "ids": ids,
  8318. })
  8319. return
  8320. } else {
  8321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8322. }
  8323. }
  8324. fmt.Println("config233322333223", config.IsOpen)
  8325. //血透客户
  8326. if config.IsOpen == 2 || config.IsOpen == 0 {
  8327. //药品管理信息
  8328. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8329. if drugStockConfig.IsOpen == 1 {
  8330. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8331. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8332. for _, item := range list {
  8333. for _, it := range adviceList {
  8334. if item.DrugId == it.DrugId {
  8335. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8336. }
  8337. }
  8338. }
  8339. for _, item := range list {
  8340. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8341. var sum_out_count int64
  8342. for _, itemThree := range item.ChildDoctorAdvice {
  8343. var prescribing_number int64
  8344. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8345. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8346. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8347. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8348. }
  8349. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8350. prescribing_number = parseIntPrescribingNumber
  8351. }
  8352. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8353. prescribing_number = parseIntPrescribingNumber
  8354. }
  8355. sum_out_count += prescribing_number
  8356. }
  8357. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8358. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8359. //库存不足
  8360. if sum_out_count > drugStockOut.FlushCount {
  8361. this.ServeSuccessJSON(map[string]interface{}{
  8362. "msg": "2",
  8363. "drug": medical,
  8364. "ids": ids,
  8365. })
  8366. return
  8367. }
  8368. }
  8369. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8370. fmt.Println("creater2332243244224242424", creater)
  8371. //执行医嘱
  8372. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8373. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8374. for _, item := range advices {
  8375. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8376. redis := service.RedisClient()
  8377. //清空key 值
  8378. redis.Set(key, "", time.Second)
  8379. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8380. redis.Set(keyTwo, "", time.Second)
  8381. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8382. redis.Set(keyThree, "", time.Second)
  8383. recordDate := theTime.Format("2006-01-02")
  8384. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8385. redis.Set(keyFour, "", time.Second)
  8386. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8387. redis.Set(keyFive, "", time.Second)
  8388. defer redis.Close()
  8389. }
  8390. if errs == nil {
  8391. for _, item := range advices {
  8392. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8393. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8394. //查询是否出库按钮开启
  8395. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8396. if adviceSetting.IsAdviceOpen == 1 {
  8397. //查询是否出库按钮开启
  8398. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8399. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8400. if prescriptionConfig.IsOpen == 1 {
  8401. if medical.IsUse == 2 {
  8402. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8403. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8404. }
  8405. if pharmacyConfig.IsOpen != 1 {
  8406. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8407. }
  8408. //更新字典里面的库存
  8409. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8410. var sum_count int64
  8411. for _, its := range stockInfo {
  8412. if its.MaxUnit == medical.MaxUnit {
  8413. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8414. }
  8415. sum_count += its.StockMaxNumber + its.StockMinNumber
  8416. }
  8417. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8418. //剩余库存
  8419. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8420. }
  8421. }
  8422. } else {
  8423. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8424. if medical.IsUse == 2 {
  8425. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8426. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8427. }
  8428. if pharmacyConfig.IsOpen != 1 {
  8429. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8430. }
  8431. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8432. var sum_count int64
  8433. for _, its := range stockInfo {
  8434. if its.MaxUnit == medical.MaxUnit {
  8435. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8436. }
  8437. sum_count += its.StockMaxNumber + its.StockMinNumber
  8438. }
  8439. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8440. //剩余库存
  8441. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8442. }
  8443. }
  8444. }
  8445. }
  8446. this.ServeSuccessJSON(map[string]interface{}{
  8447. "msg": "1",
  8448. "ids": ids,
  8449. })
  8450. return
  8451. } else {
  8452. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8453. //执行医嘱
  8454. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8455. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8456. for _, item := range advices {
  8457. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8458. redis := service.RedisClient()
  8459. //清空key 值
  8460. redis.Set(key, "", time.Second)
  8461. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8462. redis.Set(keyTwo, "", time.Second)
  8463. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8464. redis.Set(keyThree, "", time.Second)
  8465. recordDate := theTime.Format("2006-01-02")
  8466. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8467. redis.Set(keyFour, "", time.Second)
  8468. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8469. redis.Set(keyFive, "", time.Second)
  8470. defer redis.Close()
  8471. }
  8472. this.ServeSuccessJSON(map[string]interface{}{
  8473. "msg": "1",
  8474. "ids": ids,
  8475. })
  8476. return
  8477. }
  8478. }
  8479. }
  8480. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8481. ids := this.GetString("ids")
  8482. idSplit := strings.Split(ids, ",")
  8483. orgId := this.GetMobileAdminUserInfo().Org.Id
  8484. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8485. if config.IsOpen == 1 {
  8486. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8487. this.ServeSuccessJSON(map[string]interface{}{
  8488. "msg": "1",
  8489. "ids": ids,
  8490. })
  8491. return
  8492. }
  8493. if config.IsOpen == 0 || config.IsOpen == 2 {
  8494. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8495. this.ServeSuccessJSON(map[string]interface{}{
  8496. "msg": "1",
  8497. "ids": ids,
  8498. })
  8499. return
  8500. }
  8501. }
  8502. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8503. ids := this.GetString("ids")
  8504. idSplit := strings.Split(ids, ",")
  8505. orgId := this.GetMobileAdminUserInfo().Org.Id
  8506. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8507. //his
  8508. if config.IsOpen == 1 {
  8509. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8510. theTime := time.Now()
  8511. advices := models.HisDoctorAdviceThirty{
  8512. CheckTime: theTime.Unix(),
  8513. Checker: checker,
  8514. UpdatedTime: time.Now().Unix(),
  8515. }
  8516. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8517. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8518. for _, item := range list {
  8519. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8520. redis := service.RedisClient()
  8521. //清空key 值
  8522. redis.Set(key, "", time.Second)
  8523. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8524. redis.Set(keyTwo, "", time.Second)
  8525. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8526. redis.Set(keyThree, "", time.Second)
  8527. recordDate := theTime.Format("2006-01-02")
  8528. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8529. redis.Set(keyFour, "", time.Second)
  8530. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8531. redis.Set(keyFive, "", time.Second)
  8532. defer redis.Close()
  8533. }
  8534. this.ServeSuccessJSON(map[string]interface{}{
  8535. "msg": "1",
  8536. "ids": ids,
  8537. })
  8538. return
  8539. }
  8540. //血透
  8541. if config.IsOpen == 0 || config.IsOpen == 2 {
  8542. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8543. theTime := time.Now()
  8544. advices := models.DoctorAdvice{
  8545. CheckTime: theTime.Unix(),
  8546. Checker: checker,
  8547. UpdatedTime: time.Now().Unix(),
  8548. }
  8549. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8550. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8551. for _, item := range list {
  8552. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8553. redis := service.RedisClient()
  8554. //清空key 值
  8555. redis.Set(key, "", time.Second)
  8556. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8557. redis.Set(keyTwo, "", time.Second)
  8558. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8559. redis.Set(keyThree, "", time.Second)
  8560. recordDate := theTime.Format("2006-01-02")
  8561. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8562. redis.Set(keyFour, "", time.Second)
  8563. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8564. redis.Set(keyFive, "", time.Second)
  8565. defer redis.Close()
  8566. }
  8567. this.ServeSuccessJSON(map[string]interface{}{
  8568. "msg": "1",
  8569. "ids": ids,
  8570. })
  8571. return
  8572. }
  8573. }
  8574. func (this *DialysisAPIController) CheckSchedule() {
  8575. patientID, _ := this.GetInt64("patient_id")
  8576. recordDateStr := this.GetString("record_date")
  8577. nurseID, _ := this.GetInt64("start_nurse")
  8578. schedual_type, _ := this.GetInt64("schedual_type")
  8579. bedID, _ := this.GetInt64("bed")
  8580. start_time := this.GetString("start_time")
  8581. fmt.Println("patientID", patientID)
  8582. fmt.Println("recordDateStr", recordDateStr)
  8583. fmt.Println("nurseID", nurseID)
  8584. fmt.Println("schedual_type------", schedual_type)
  8585. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8587. return
  8588. }
  8589. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8590. if parseStartDateErr != nil {
  8591. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8593. return
  8594. }
  8595. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8596. if parseErr != nil {
  8597. this.ErrorLog("时间解析失败:%v", parseErr)
  8598. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8599. return
  8600. }
  8601. adminUserInfo := this.GetMobileAdminUserInfo()
  8602. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8603. if getPatientErr != nil {
  8604. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8606. return
  8607. } else if patient == nil {
  8608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8609. return
  8610. }
  8611. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8612. if getNurseErr != nil {
  8613. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8615. return
  8616. } else if nurse == nil {
  8617. this.ErrorLog("护士不存在")
  8618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8619. return
  8620. }
  8621. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8622. if getDeviceNumberErr != nil {
  8623. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8625. return
  8626. } else if deviceNumber == nil {
  8627. this.ErrorLog("床位号不存在")
  8628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8629. return
  8630. }
  8631. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8632. if getRecordErr != nil {
  8633. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8635. return
  8636. } else if dialysisRecord != nil {
  8637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8638. return
  8639. }
  8640. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8641. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8642. timeLayout := "2006-01-02 15:04:05"
  8643. loc, _ := time.LoadLocation("Local")
  8644. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8645. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8646. schedulestartTime := theStartTime.Unix()
  8647. scheduleendTime := theEndTime.Unix()
  8648. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8649. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8650. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8651. //查询该床位是否有人用了
  8652. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8653. if err == nil {
  8654. if schedule.ID == 0 {
  8655. this.ServeSuccessJSON(map[string]interface{}{
  8656. "status": 0,
  8657. "msg": "请求失败",
  8658. })
  8659. } else {
  8660. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8661. if order.ID > 0 { //该机位被其他人占用了
  8662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8663. return
  8664. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8665. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8666. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8667. this.ServeSuccessJSON(map[string]interface{}{
  8668. "status": 1,
  8669. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8670. })
  8671. return
  8672. } else {
  8673. this.ServeSuccessJSON(map[string]interface{}{
  8674. "status": 0,
  8675. "msg": "",
  8676. })
  8677. }
  8678. }
  8679. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8680. this.ServeSuccessJSON(map[string]interface{}{
  8681. "status": 2,
  8682. "msg": "当前机位已有患者在使用,请重新选择!",
  8683. })
  8684. }
  8685. }
  8686. } else {
  8687. this.ServeSuccessJSON(map[string]interface{}{
  8688. "status": 0,
  8689. "msg": "",
  8690. })
  8691. }
  8692. }
  8693. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8694. orgId := this.GetMobileAdminUserInfo().Org.Id
  8695. schedule_type, _ := this.GetInt64("schedule_type")
  8696. partion_type, _ := this.GetInt64("partion_type")
  8697. start_time := this.GetString("start_time")
  8698. timeLayout := "2006-01-02"
  8699. loc, _ := time.LoadLocation("Local")
  8700. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8701. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8702. _, config := service.FindXTHisRecordByOrgId(orgId)
  8703. appId := this.GetMobileAdminUserInfo().App.Id
  8704. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8705. if err == nil {
  8706. this.ServeSuccessJSON(map[string]interface{}{
  8707. "list": list,
  8708. "config": config,
  8709. "doctorList": doctorList,
  8710. })
  8711. return
  8712. } else {
  8713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8714. return
  8715. }
  8716. }
  8717. func (this *DialysisAPIController) SaveMobileInformation() {
  8718. patient_id, _ := this.GetInt64("patient_id")
  8719. record_date, _ := this.GetInt64("record_date")
  8720. startTime := this.GetString("start_time")
  8721. module, _ := this.GetInt64("module")
  8722. remark := this.GetString("remark")
  8723. timeLayout := "2006-01-02 15:04"
  8724. loc, _ := time.LoadLocation("Local")
  8725. if len(startTime) == 0 {
  8726. utils.ErrorLog("len(start_time) == 0")
  8727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8728. return
  8729. }
  8730. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8731. if err != nil {
  8732. utils.ErrorLog(err.Error())
  8733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8734. return
  8735. }
  8736. StartTime := theTime.Unix()
  8737. fmt.Println("startime-------------", StartTime)
  8738. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8739. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8740. information := models.XtDialysisInformation{
  8741. Module: module,
  8742. PatientId: patient_id,
  8743. RecordDate: record_date,
  8744. ApplicationDate: StartTime,
  8745. Creater: creater,
  8746. ApplicationStatus: 2,
  8747. Checker: 0,
  8748. CheckTime: 0,
  8749. Remark: remark,
  8750. UserOrgId: user_org_id,
  8751. Ctime: time.Now().Unix(),
  8752. Status: 1,
  8753. Mtime: 0,
  8754. }
  8755. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8756. if infor.ID == 0 {
  8757. service.SaveDialysisInformation(information)
  8758. }
  8759. if infor.ID > 0 {
  8760. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8761. }
  8762. this.ServeSuccessJSON(map[string]interface{}{
  8763. "information": information,
  8764. })
  8765. return
  8766. }
  8767. func (this *DialysisAPIController) GetMobileInformation() {
  8768. limit, _ := this.GetInt64("limit")
  8769. page, _ := this.GetInt64("page")
  8770. orgid := this.GetMobileAdminUserInfo().Org.Id
  8771. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8772. appid := this.GetMobileAdminUserInfo().App.Id
  8773. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8774. patients, _ := service.GetAllpatientThirty(orgid)
  8775. this.ServeSuccessJSON(map[string]interface{}{
  8776. "information": information,
  8777. "total": total,
  8778. "doclist": doclist,
  8779. "patients": patients,
  8780. })
  8781. return
  8782. }
  8783. func (this *DialysisAPIController) GetMobileInformationOne() {
  8784. limit, _ := this.GetInt64("limit")
  8785. page, _ := this.GetInt64("page")
  8786. orgid := this.GetMobileAdminUserInfo().Org.Id
  8787. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8788. appid := this.GetMobileAdminUserInfo().App.Id
  8789. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8790. patients, _ := service.GetAllpatientThirty(orgid)
  8791. this.ServeSuccessJSON(map[string]interface{}{
  8792. "information": information,
  8793. "total": total,
  8794. "doclist": doclist,
  8795. "patients": patients,
  8796. })
  8797. return
  8798. }
  8799. func (this *DialysisAPIController) CheckMobileInformation() {
  8800. id, _ := this.GetInt64("id")
  8801. application_status, _ := this.GetInt64("application_status")
  8802. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8803. checktime := time.Now().Unix()
  8804. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8805. if err == nil {
  8806. this.ServeSuccessJSON(map[string]interface{}{
  8807. "msg": "ok",
  8808. })
  8809. return
  8810. }
  8811. }
  8812. func (c *DialysisAPIController) GetControlMonitorList() {
  8813. partition, _ := c.GetInt64("partition")
  8814. monitorDate := c.GetString("date")
  8815. patient_id, _ := c.GetInt64("patient_id")
  8816. pat_type, _ := c.GetInt64("pat_type")
  8817. timeLayout := "2006-01-02"
  8818. loc, _ := time.LoadLocation("Local")
  8819. var theStartTime int64
  8820. if len(monitorDate) > 0 {
  8821. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8822. if err != nil {
  8823. theStartTime = 0
  8824. }
  8825. theStartTime = theTime.Unix()
  8826. }
  8827. adminInfo := c.GetMobileAdminUserInfo()
  8828. orgID := adminInfo.Org.Id
  8829. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8830. if err != nil {
  8831. c.ErrorLog("获取排班信息失败:%v", err)
  8832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8833. } else {
  8834. if len(monitor) > 0 {
  8835. //获取所有床位
  8836. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8837. //获取所有分区
  8838. zoneList, _ := service.GetAllZoneByList(orgID)
  8839. //获取透析处方
  8840. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8841. //获取透前评估
  8842. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8843. //获取上机
  8844. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8845. //获取透后
  8846. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8847. //获取透后监测
  8848. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8849. //获取所有的患者
  8850. patients, _ := service.GetAllPatientListByListOne(orgID)
  8851. //获取所有透析模式
  8852. treatments, _ := service.GetAllTreatModeByList(orgID)
  8853. //获取所有医嘱
  8854. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8855. //获取双人核对
  8856. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8857. //治疗小结
  8858. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8859. //待消毒
  8860. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8861. for key, item := range monitor {
  8862. // 获取床位信息
  8863. for _, it := range numberList {
  8864. if item.BedId == it.ID {
  8865. monitor[key].DeviceNumber = it
  8866. break
  8867. }
  8868. }
  8869. //获取分区信息
  8870. for _, it := range zoneList {
  8871. if item.PartitionId == it.ID {
  8872. monitor[key].DeviceZone = it
  8873. }
  8874. }
  8875. for _, prescription := range prescriptions {
  8876. if item.PatientId == prescription.PatientId {
  8877. monitor[key].Prescription = prescription
  8878. break
  8879. }
  8880. }
  8881. for _, it := range checkList {
  8882. if item.PatientId == it.PatientId {
  8883. monitor[key].DoubleCheck = it
  8884. break
  8885. }
  8886. }
  8887. for _, it := range summaryList {
  8888. if item.PatientId == it.PatientId {
  8889. monitor[key].TreatmentSummaryForList = it
  8890. break
  8891. }
  8892. }
  8893. // 透前评估
  8894. for _, assessmentBefore := range assessmentBefores {
  8895. if item.PatientId == assessmentBefore.PatientId {
  8896. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8897. break
  8898. }
  8899. }
  8900. // 透析上下机
  8901. for _, dialysisOrder := range dialysisOrders {
  8902. if item.PatientId == dialysisOrder.PatientId {
  8903. monitor[key].DialysisOrder = dialysisOrder
  8904. break
  8905. }
  8906. }
  8907. // 治疗小节
  8908. for _, afterDislysis := range AssessmentAfterDislysis {
  8909. if item.PatientId == afterDislysis.PatientId {
  8910. monitor[key].AssessmentAfterDislysis = afterDislysis
  8911. break
  8912. }
  8913. }
  8914. for _, it := range monitorlist {
  8915. if item.PatientId == it.PatientId {
  8916. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8917. }
  8918. }
  8919. for _, it := range adviceList {
  8920. if item.PatientId == it.PatientId {
  8921. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8922. }
  8923. }
  8924. for _, patient := range patients {
  8925. if item.PatientId == patient.ID {
  8926. monitor[key].MonitorPatients = patient
  8927. break
  8928. }
  8929. }
  8930. for _, treatment := range treatments {
  8931. if item.ModeId == treatment.ID {
  8932. monitor[key].TreatmentMode = treatment
  8933. break
  8934. }
  8935. }
  8936. for _, infor := range informationList {
  8937. if item.PatientId == infor.PatientId {
  8938. monitor[key].NewDeviceInformation = infor
  8939. break
  8940. }
  8941. }
  8942. }
  8943. }
  8944. }
  8945. patients, err := service.GetAllpatientFourty(orgID)
  8946. var mds []*models.NewMonitorDialysisScheduleList
  8947. if pat_type == 0 {
  8948. for _, item := range monitor {
  8949. mds = append(mds, item)
  8950. }
  8951. }
  8952. //待医嘱核对
  8953. if pat_type == 1 {
  8954. for _, item := range monitor {
  8955. if len(item.AdviceList) > 0 {
  8956. mds = append(mds, item)
  8957. }
  8958. }
  8959. }
  8960. //待开小结
  8961. if pat_type == 2 {
  8962. for _, item := range monitor {
  8963. if item.TreatmentSummaryForList == nil {
  8964. mds = append(mds, item)
  8965. }
  8966. }
  8967. }
  8968. //待下机
  8969. if pat_type == 3 {
  8970. for _, item := range monitor {
  8971. if item.DialysisOrder != nil {
  8972. if item.DialysisOrder.ID > 0 {
  8973. mds = append(mds, item)
  8974. }
  8975. }
  8976. }
  8977. }
  8978. //待消毒
  8979. if pat_type == 4 {
  8980. for _, item := range monitor {
  8981. if item.NewDeviceInformation == nil {
  8982. mds = append(mds, item)
  8983. }
  8984. }
  8985. }
  8986. //待双人核对
  8987. if pat_type == 5 {
  8988. for _, item := range monitor {
  8989. if item.DoubleCheck == nil {
  8990. mds = append(mds, item)
  8991. }
  8992. }
  8993. }
  8994. //医嘱未执行
  8995. if pat_type == 6 {
  8996. for _, item := range monitor {
  8997. if len(item.AdviceList) > 0 {
  8998. mds = append(mds, item)
  8999. }
  9000. }
  9001. }
  9002. //患者未签名
  9003. if pat_type == 7 {
  9004. for _, item := range monitor {
  9005. if item.DialysisOrder != nil {
  9006. if item.DialysisOrder.ID > 0 {
  9007. mds = append(mds, item)
  9008. }
  9009. }
  9010. }
  9011. }
  9012. //目标超滤于实际超滤不同
  9013. if pat_type == 8 {
  9014. for _, item := range monitor {
  9015. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9016. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9017. mds = append(mds, item)
  9018. }
  9019. }
  9020. }
  9021. }
  9022. //血压少于5次
  9023. if pat_type == 9 {
  9024. for _, item := range monitor {
  9025. if len(item.MonitoringRecord) < 5 {
  9026. mds = append(mds, item)
  9027. }
  9028. }
  9029. }
  9030. if pat_type == 10 {
  9031. for _, item := range monitor {
  9032. if len(item.MonitoringRecord) == 0 {
  9033. mds = append(mds, item)
  9034. }
  9035. }
  9036. }
  9037. if pat_type == 11 {
  9038. for _, item := range monitor {
  9039. if len(item.MonitoringRecord) > 0 {
  9040. mds = append(mds, item)
  9041. }
  9042. }
  9043. }
  9044. if pat_type == 12 {
  9045. for _, item := range monitor {
  9046. if len(item.MonitoringRecord) > 0 {
  9047. mds = append(mds, item)
  9048. }
  9049. }
  9050. }
  9051. if err == nil {
  9052. c.ServeSuccessJSON(map[string]interface{}{
  9053. "monitor": mds,
  9054. "patients": patients,
  9055. })
  9056. } else {
  9057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9058. }
  9059. }
  9060. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9061. admin_user_id, _ := c.GetInt64("admin_user_id")
  9062. timeStr := time.Now().Format("2006-01-02")
  9063. timeLayout := "2006-01-02 15:04:05"
  9064. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9065. timenow := timeStringToTime.Unix()
  9066. orgId := c.GetMobileAdminUserInfo().Org.Id
  9067. //查询当前护士的患者
  9068. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9069. var patientIds []int64
  9070. for _, item := range orderList {
  9071. patientIds = append(patientIds, item.PatientId)
  9072. }
  9073. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9074. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9075. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9076. //药品管理信息
  9077. _, drugStockConfig := service.FindHisConfig(orgId)
  9078. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9079. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9080. c.ServeSuccessJSON(map[string]interface{}{
  9081. "adviceList": adviceList,
  9082. "hisAdviceList": hisAdviceList,
  9083. "projectList": projectList,
  9084. "drugStockConfig": drugStockConfig,
  9085. "patientList": patientList,
  9086. "projectConfig": projectConfig,
  9087. })
  9088. }
  9089. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9090. patient_id, _ := c.GetInt64("patient_id")
  9091. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9092. c.ServeSuccessJSON(map[string]interface{}{
  9093. "recrods": recrods,
  9094. })
  9095. }