dialysis_api_controller.go 355KB

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