dialysis_api_controller.go 381KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "errors"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "math"
  13. "net/http"
  14. "net/url"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. //redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  501. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  502. returnData := map[string]interface{}{
  503. "patient": patient,
  504. "schedual": schedual,
  505. "prescription": dialysisPrescribe,
  506. "solution": dialysisSolution,
  507. "last_prescription": lastDialysisPrescribe,
  508. "receiver_treatment_access": receiverTreatmentAccess,
  509. "predialysis_evaluation": predialysisEvaluation,
  510. "doctor_advices": doctorAdvices,
  511. "double_check": doubleCheck,
  512. "assessment_after_dislysis": assessmentAfterDislysis,
  513. "treatment_summary": treatmentSummary,
  514. "monitor_records": monitorRecords,
  515. "dialysis_order": dialysisOrder,
  516. "operators": operators,
  517. "last_predialysis_evaluation": lastPredialysisEvaluation,
  518. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  519. "last_monitor_record": lastMonitorRecord,
  520. "config": gobalConfig,
  521. "dry_weight": lastDryWeightDislysis,
  522. "system_prescription": systemDialysisPrescribe,
  523. "his_advices": his_advices,
  524. "is_open_config": is_open_config,
  525. "stockType": stockType,
  526. "prepare": prepare,
  527. "lastAssessment": lastAssessment,
  528. "prescribeOne": prescribeOne,
  529. "is_project_open_config": is_project_open_config,
  530. "project": projects,
  531. "team_projects": team_projects,
  532. "is_advice_open": is_advice_open,
  533. "prescription_open": prescriptionConfig.IsOpen,
  534. "lastOrder": lastOrder,
  535. "remind_lists": remind_lists,
  536. "lastDialysisPrescription": lastDialysisPrescription,
  537. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  538. "dryWeightList": dryWeightList,
  539. }
  540. this.ServeSuccessJSON(returnData)
  541. }
  542. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  543. adminInfo := c.GetMobileAdminUserInfo()
  544. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  545. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  546. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  547. returnData := map[string]interface{}{
  548. "admin_users": adminUsers,
  549. "devices": devices,
  550. "device_numbers": device_numbers,
  551. }
  552. c.ServeSuccessJSON(returnData)
  553. }
  554. func (c *DialysisAPIController) PostAtreatmentInfo() {
  555. id, _ := c.GetInt64("patient", 0)
  556. recordDateStr := c.GetString("record_date")
  557. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  558. summaryContent := c.GetString("summaryContent")
  559. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  560. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  561. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  562. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  563. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  564. nursingRecord := c.GetString("nursing_record")
  565. fmt.Println("护理记录", nursingRecord)
  566. specialRecord := c.GetString("special_record")
  567. fmt.Println("特殊记录", specialRecord)
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  570. checkStaffId = adminUserInfo.AdminUser.Id
  571. deboardNurseId = adminUserInfo.AdminUser.Id
  572. treatDoctor = adminUserInfo.AdminUser.Id
  573. if id <= 0 {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  578. if patient.ID == 0 {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  580. return
  581. }
  582. if len(recordDateStr) == 0 {
  583. recordDateStr = time.Now().Format("2006-01-02")
  584. }
  585. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  586. if parseDateErr != nil {
  587. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. summary := models.TreatmentSummary{
  592. UserOrgId: adminUserInfo.Org.Id,
  593. PatientId: id,
  594. AssessmentDate: recordDate.Unix(),
  595. Mission: propagandaAndEducationContent,
  596. DialysisSummary: summaryContent,
  597. SjNurse: changeMedicalNurseId,
  598. ZlNurse: treatNurseId,
  599. HdNurse: checkStaffId,
  600. XjNurse: deboardNurseId,
  601. ZlDoctor: treatDoctor,
  602. CreatedTime: time.Now().Unix(),
  603. Status: 1,
  604. NursingRecord: nursingRecord,
  605. SpecialRecord: specialRecord,
  606. }
  607. // 查询信息规挡的设置天数
  608. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  609. if infor.ID > 0 && infor.WeekDay > 0 {
  610. var cha_time int64
  611. timeNowStr := time.Now().Format("2006-01-02")
  612. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  613. //今日的日期减去设置的日期
  614. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  615. if cha_time >= recordDate.Unix() {
  616. //查询审核是否允许
  617. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  618. //申请状态不允许的情况 拒绝修改
  619. if infor.ApplicationStatus != 1 {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  621. return
  622. }
  623. }
  624. }
  625. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  626. if treatmentSummary.ID == 0 { //新增
  627. summary.Creater = adminUserInfo.AdminUser.Id
  628. service.AddSigleSummaryRecord(&summary)
  629. finish := models.XtDialysisFinish{
  630. IsFinish: 1,
  631. UserOrgId: adminUserInfo.Org.Id,
  632. Status: 1,
  633. Ctime: time.Now().Unix(),
  634. Mtime: 0,
  635. Module: 10,
  636. RecordDate: recordDate.Unix(),
  637. Sourse: 1,
  638. PatientId: id,
  639. }
  640. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  641. if dialysisFinish.ID == 0 {
  642. service.CreateDialysisFinish(finish)
  643. }
  644. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  645. redis := service.RedisClient()
  646. //清空key 值
  647. redis.Set(key, "", time.Second)
  648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  649. redis.Set(keyOne, "", time.Second)
  650. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  651. redis.Set(keyThree, "", time.Second)
  652. defer redis.Close()
  653. c.ServeSuccessJSON(map[string]interface{}{
  654. "summary": summary,
  655. })
  656. } else { //修改
  657. summary.Creater = treatmentSummary.Creater
  658. summary.CreatedTime = treatmentSummary.CreatedTime
  659. summary.Modifier = adminUserInfo.AdminUser.Id
  660. summary.ID = treatmentSummary.ID
  661. service.UpdateSummeRecord(&summary)
  662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  663. redis := service.RedisClient()
  664. //清空key 值
  665. redis.Set(key, "", time.Second)
  666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  667. redis.Set(keyOne, "", time.Second)
  668. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  669. redis.Set(keyThree, "", time.Second)
  670. defer redis.Close()
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "summary": summary,
  673. })
  674. }
  675. }
  676. func (c *DialysisAPIController) PostDoubleCheck() {
  677. id, _ := c.GetInt64("patient", 0)
  678. recordDateStr := c.GetString("record_date")
  679. checkTimeStr := c.GetString("check_time")
  680. firstCheckTimeStr := c.GetString("first_check_time")
  681. creater, _ := c.GetInt64("creater", 0)
  682. modifier, _ := c.GetInt64("modifier", 0)
  683. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  684. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  685. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  686. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  687. dialysis_item_desc := c.GetString("dialysis_item_desc")
  688. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  689. vascular_access_desc := c.GetString("vascular_access_desc")
  690. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  691. collator, _ := c.GetInt64("collator", 0)
  692. employee_number := c.GetString("employee_number")
  693. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  694. needle_batch_number := c.GetString("needle_batch_number")
  695. if id <= 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. adminUserInfo := c.GetMobileAdminUserInfo()
  700. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  701. if patient.ID == 0 {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  703. return
  704. }
  705. if len(recordDateStr) == 0 {
  706. recordDateStr = time.Now().Format("2006-01-02")
  707. }
  708. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  709. if parseDateErr != nil {
  710. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. var checkDate int64
  715. if len(checkTimeStr) == 0 {
  716. checkDate = 0
  717. } else {
  718. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  719. checkDate = checkDateUnix.Unix()
  720. }
  721. var firstCheckDate int64
  722. if len(firstCheckTimeStr) == 0 {
  723. firstCheckDate = 0
  724. } else {
  725. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  726. firstCheckDate = firstCheckDateUnix.Unix()
  727. }
  728. //if adminUserInfo.Org.Id == 10340 {
  729. //
  730. // list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  731. // _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  732. // if check.ID == 0 {
  733. // if employee_number != list.JobNumber {
  734. // c.ServeSuccessJSON(map[string]interface{}{
  735. // "doubleCheck": check,
  736. // "msg": "2",
  737. // })
  738. // return
  739. // }
  740. // }
  741. // if check.ID > 0 {
  742. // if employee_number != list.JobNumber {
  743. // c.ServeSuccessJSON(map[string]interface{}{
  744. // "doubleCheck": check,
  745. // "msg": "2",
  746. // })
  747. // return
  748. // }
  749. // }
  750. //
  751. //}
  752. doubleCheck := models.DoubleCheck{
  753. UserOrgId: adminUserInfo.Org.Id,
  754. PatientId: id,
  755. DialysisItemCheck: dialysis_item_check,
  756. DialysisParameterCheck: dialysis_parameter_check,
  757. VascularAccessVerification: vascular_access_verification,
  758. PipelineConnectionCheck: pipeline_connection_check,
  759. DialysisItemDesc: dialysis_item_desc,
  760. DialysisParameterDesc: dialysis_parameter_desc,
  761. VascularAccessDesc: vascular_access_desc,
  762. PipelineConnectionDesc: pipeline_connection_desc,
  763. Collator: collator,
  764. Status: 1,
  765. CreatedTime: time.Now().Unix(),
  766. CheckDate: recordDate.Unix(),
  767. UpdatedTime: time.Now().Unix(),
  768. EmployeeNumber: employee_number,
  769. DialyzerBatchNumber: dialyzer_batch_number,
  770. NeedleBatchNumber: needle_batch_number,
  771. }
  772. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  773. if check.ID == 0 { //新增
  774. doubleCheck.FirstCheckTime = firstCheckDate
  775. doubleCheck.CheckTime = checkDate
  776. doubleCheck.Creater = creater
  777. doubleCheck.Modifier = modifier
  778. if adminUserInfo.Org.Id == 10340 {
  779. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  780. doubleCheck.Creater = order.StartNurse
  781. }
  782. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  783. //查询未核对的医嘱
  784. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  785. for _, advice := range doctorList {
  786. if advice.ExecutionStaff == modifier {
  787. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  788. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  789. return
  790. }
  791. }
  792. }
  793. // 查询信息规挡的设置天数
  794. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  795. if infor.ID > 0 && infor.WeekDay > 0 {
  796. var cha_time int64
  797. timeNowStr := time.Now().Format("2006-01-02")
  798. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  799. //今日的日期减去设置的日期
  800. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  801. if cha_time >= recordDate.Unix() {
  802. //查询审核是否允许
  803. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  804. //申请状态不允许的情况 拒绝修改
  805. if infor.ApplicationStatus != 1 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  807. return
  808. }
  809. }
  810. }
  811. err := service.AddSigleDoubleCheck(&doubleCheck)
  812. finish := models.XtDialysisFinish{
  813. IsFinish: 1,
  814. UserOrgId: adminUserInfo.Org.Id,
  815. Status: 1,
  816. Ctime: time.Now().Unix(),
  817. Mtime: 0,
  818. Module: 5,
  819. RecordDate: recordDate.Unix(),
  820. Sourse: 1,
  821. PatientId: id,
  822. }
  823. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  824. if dialysisFinish.ID == 0 {
  825. service.CreateDialysisFinish(finish)
  826. }
  827. //针对长沙南雅
  828. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  829. //查询未核对的医嘱
  830. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  831. if len(doctorList) > 0 && modifier > 0 {
  832. for _, advice := range doctorList {
  833. service.UpdateDoctorAdviceList(advice.ID, modifier)
  834. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  835. redis := service.RedisClient()
  836. //清空key 值
  837. redis.Set(key, "", time.Second)
  838. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  839. redis.Set(keyTwo, "", time.Second)
  840. theTime := time.Now()
  841. recordDate := theTime.Format("2006-01-02")
  842. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  843. redis.Set(keyFour, "", time.Second)
  844. defer redis.Close()
  845. }
  846. }
  847. }
  848. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  849. redis := service.RedisClient()
  850. //清空key 值
  851. redis.Set(key, "", time.Second)
  852. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  853. redis.Set(keyOne, "", time.Second)
  854. defer redis.Close()
  855. if err == nil {
  856. c.ServeSuccessJSON(map[string]interface{}{
  857. "doubleCheck": &doubleCheck,
  858. })
  859. }
  860. } else { //修改
  861. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  862. if infor.ID > 0 {
  863. var cha_time int64
  864. timeNowStr := time.Now().Format("2006-01-02")
  865. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  866. //今日的日期减去设置的日期
  867. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  868. if cha_time >= recordDate.Unix() {
  869. //查询审核是否允许
  870. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  871. //申请状态不允许的情况 拒绝修改
  872. if infor.ApplicationStatus != 1 {
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  874. return
  875. }
  876. }
  877. }
  878. doubleCheck.FirstCheckTime = firstCheckDate
  879. doubleCheck.CheckTime = checkDate
  880. doubleCheck.Creater = creater
  881. doubleCheck.Modifier = modifier
  882. doubleCheck.CreatedTime = check.CreatedTime
  883. doubleCheck.ID = check.ID
  884. doubleCheck.EmployeeNumber = employee_number
  885. doubleCheck.NeedleBatchNumber = needle_batch_number
  886. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  887. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  888. //查询未核对的医嘱
  889. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  890. for _, advice := range doctorList {
  891. if advice.ExecutionStaff == modifier {
  892. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  893. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  894. return
  895. }
  896. }
  897. }
  898. err := service.UpdateDoubleCheck(&doubleCheck)
  899. //针对长沙南雅
  900. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  901. //查询未核对的医嘱
  902. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  903. if len(doctorList) > 0 && modifier > 0 {
  904. for _, advice := range doctorList {
  905. service.UpdateDoctorAdviceList(advice.ID, modifier)
  906. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  907. redis := service.RedisClient()
  908. //清空key 值
  909. redis.Set(key, "", time.Second)
  910. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  911. redis.Set(keyTwo, "", time.Second)
  912. theTime := time.Now()
  913. recordDate := theTime.Format("2006-01-02")
  914. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  915. redis.Set(keyFour, "", time.Second)
  916. defer redis.Close()
  917. }
  918. }
  919. }
  920. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  921. redis := service.RedisClient()
  922. //清空key 值
  923. redis.Set(key, "", time.Second)
  924. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  925. redis.Set(keyOne, "", time.Second)
  926. defer redis.Close()
  927. if err == nil {
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "doubleCheck": &doubleCheck,
  930. "msg": "1",
  931. })
  932. }
  933. }
  934. }
  935. func (c *DialysisAPIController) PostAcceptsAssessment() {
  936. id, _ := c.GetInt64("patient", 0)
  937. recordDateStr := c.GetString("record_date")
  938. way, _ := c.GetInt64("way", 0)
  939. consciousness, _ := c.GetInt64("consciousness", 0)
  940. appetite, _ := c.GetInt64("appetite", 0)
  941. condition, _ := c.GetInt64("condition", 0)
  942. posture, _ := c.GetInt64("posture")
  943. sick_condition, _ := c.GetInt64("sick_condition", 0)
  944. danger_level, _ := c.GetInt64("danger_level", 0)
  945. intake, _ := c.GetInt64("intake", 0)
  946. nutrition, _ := c.GetInt64("nutrition", 0)
  947. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  948. psychological_assessment_other := c.GetString("psychological_assessment_other")
  949. score := c.GetString("score")
  950. sick_condition_other := c.GetString("sick_condition_other")
  951. //precaution, _ := c.GetInt64("precaution", 0)
  952. precaution := c.GetString("precaution")
  953. precaution_other := c.GetString("precaution_other")
  954. psychological_other := c.GetString("psychological_other")
  955. admission_number := c.GetString("admission_number")
  956. tumble, _ := c.GetInt64("tumble")
  957. diacrisis := c.GetString("diacrisis")
  958. his_department := c.GetString("his_department")
  959. his_bed := c.GetString("his_bed")
  960. if id <= 0 {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  962. return
  963. }
  964. adminUserInfo := c.GetMobileAdminUserInfo()
  965. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  966. if patient.ID == 0 {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  968. return
  969. }
  970. //now := time.Now()
  971. //year, month, day := now.Date()
  972. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  973. //todayTimeStamp := today_time.Unix()
  974. if len(recordDateStr) == 0 {
  975. recordDateStr = time.Now().Format("2006-01-02")
  976. }
  977. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  978. if parseDateErr != nil {
  979. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. // 查询信息规挡的设置天数
  984. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  985. if infor.ID > 0 && infor.WeekDay > 0 {
  986. var cha_time int64
  987. timeNowStr := time.Now().Format("2006-01-02")
  988. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  989. //今日的日期减去设置的日期
  990. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  991. if cha_time >= recordDate.Unix() {
  992. //查询审核是否允许
  993. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  994. //申请状态不允许的情况 拒绝修改
  995. if infor.ApplicationStatus != 1 {
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  997. return
  998. }
  999. }
  1000. }
  1001. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1002. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1003. UserOrgId: adminUserInfo.Org.Id,
  1004. PatientId: id,
  1005. RecordDate: recordDate.Unix(),
  1006. Way: way,
  1007. Consciousness: consciousness,
  1008. Appetite: appetite,
  1009. Condition: condition,
  1010. SickCondition: sick_condition,
  1011. DangerLevel: danger_level,
  1012. Intake: intake,
  1013. Nutrition: nutrition,
  1014. PsychologicalAssessment: psychological_assessment,
  1015. PsychologicalAssessmentOther: psychological_assessment_other,
  1016. SickConditionOther: sick_condition_other,
  1017. Posture: posture,
  1018. CreatedTime: time.Now().Unix(),
  1019. UpdateTime: time.Now().Unix(),
  1020. Status: 1,
  1021. Score: score,
  1022. Precaution: precaution,
  1023. PrecautionOther: precaution_other,
  1024. PsychologicalOther: psychological_other,
  1025. AdmissionNumber: admission_number,
  1026. Tumble: tumble,
  1027. Diacrisis: diacrisis,
  1028. HisBed: his_bed,
  1029. HisDepartment: his_department,
  1030. }
  1031. if receiveTreatment.ID == 0 { //新增
  1032. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1033. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1034. finish := models.XtDialysisFinish{
  1035. IsFinish: 1,
  1036. UserOrgId: adminUserInfo.Org.Id,
  1037. Status: 1,
  1038. Ctime: time.Now().Unix(),
  1039. Mtime: 0,
  1040. Module: 2,
  1041. RecordDate: recordDate.Unix(),
  1042. Sourse: 1,
  1043. PatientId: id,
  1044. }
  1045. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1046. if dialysisFinish.ID == 0 {
  1047. service.CreateDialysisFinish(finish)
  1048. }
  1049. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1050. redis := service.RedisClient()
  1051. defer redis.Close()
  1052. //清空key 值
  1053. redis.Set(key, "", time.Second)
  1054. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1055. redis.Set(keyOne, "", time.Second)
  1056. if err == nil {
  1057. c.ServeSuccessJSON(map[string]interface{}{
  1058. "receiveTreatmentAsses": receiveTreatmentAsses,
  1059. })
  1060. }
  1061. } else { //修改
  1062. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1063. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1064. // if getPermissionErr != nil {
  1065. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1066. // return
  1067. // } else if headNursePermission == nil {
  1068. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1069. // return
  1070. // }
  1071. //}
  1072. // 查询信息规挡的设置天数
  1073. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1074. if infor.ID > 0 && infor.WeekDay > 0 {
  1075. var cha_time int64
  1076. timeNowStr := time.Now().Format("2006-01-02")
  1077. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1078. //今日的日期减去设置的日期
  1079. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1080. if cha_time >= recordDate.Unix() {
  1081. //查询审核是否允许
  1082. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1083. //申请状态不允许的情况 拒绝修改
  1084. if infor.ApplicationStatus != 1 {
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1086. return
  1087. }
  1088. }
  1089. }
  1090. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1091. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1092. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1093. receiveTreatmentAsses.ID = receiveTreatment.ID
  1094. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1095. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1096. redis := service.RedisClient()
  1097. defer redis.Close()
  1098. //清空key 值
  1099. redis.Set(key, "", time.Second)
  1100. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1101. redis.Set(keyOne, "", time.Second)
  1102. if err == nil {
  1103. c.ServeSuccessJSON(map[string]interface{}{
  1104. "receiveTreatmentAsses": receiveTreatmentAsses,
  1105. })
  1106. }
  1107. }
  1108. }
  1109. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1110. id, _ := c.GetInt64("patient", 0)
  1111. recordDateStr := c.GetString("record_date")
  1112. weightAfter, _ := c.GetFloat("weight_after", 0)
  1113. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1114. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1115. fmt.Println("weight_loss", weightReduce)
  1116. temperature, _ := c.GetFloat("temperature", 0)
  1117. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1118. breathing_rate := c.GetString("breathing_rate")
  1119. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1120. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1121. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1122. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1123. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1124. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1125. cruor := c.GetString("cruor")
  1126. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1127. internalFistula := c.GetString("internal_fistula")
  1128. catheter := c.GetString("catheter")
  1129. complications := c.GetString("complication")
  1130. remark := c.GetString("remark")
  1131. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1132. dialysis_intakes := c.GetString("dialysis_intakes")
  1133. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1134. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1135. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1136. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1137. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1138. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1139. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1140. patientGose, _ := c.GetInt64("patient_gose", 0)
  1141. inpatientDepartment := c.GetString("inpatient_department")
  1142. observationContent := c.GetString("observation_content")
  1143. observationContentOther := c.GetString("observation_content_other")
  1144. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1145. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1146. in_advance_reason := c.GetString("in_advance_reason")
  1147. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1148. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1149. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1150. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1151. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1152. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1153. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1154. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1155. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1156. is_eat, _ := c.GetInt64("is_eat", 0)
  1157. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1158. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1159. channels, _ := c.GetInt64("channel", 0)
  1160. return_blood, _ := c.GetInt64("return_blood", 0)
  1161. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1162. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1163. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1164. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1165. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1166. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1167. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1168. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1169. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1170. setting_pressure := c.GetString("setting_pressure")
  1171. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1172. diastolic_pressure := c.GetString("diastolic_pressure")
  1173. other_complication := c.GetString("other_complication")
  1174. ktv := c.GetString("ktv")
  1175. urr := c.GetString("urr")
  1176. hypertenison, _ := c.GetInt64("hypertenison")
  1177. hypopiesia, _ := c.GetInt64("hypopiesia")
  1178. leave_office_method, _ := c.GetInt64("leave_office_method")
  1179. lapse, _ := c.GetInt64("lapse")
  1180. consciousness, _ := c.GetInt64("consciousness")
  1181. fallrisk, _ := c.GetInt64("fallrisk")
  1182. machine_run := c.GetString("machine_run")
  1183. after_urea := c.GetString("after_urea")
  1184. pip_coagulation := c.GetString("pip_coagulation")
  1185. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1186. transfusion_volume := c.GetString("transfusion_volume")
  1187. last_after_weight := c.GetString("last_after_weight")
  1188. if id <= 0 {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1190. return
  1191. }
  1192. adminUserInfo := c.GetMobileAdminUserInfo()
  1193. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1194. if patient.ID == 0 {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1196. return
  1197. }
  1198. if len(recordDateStr) == 0 {
  1199. recordDateStr = time.Now().Format("2006-01-02")
  1200. }
  1201. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1202. fmt.Println("parseDateErr", parseDateErr)
  1203. if parseDateErr != nil {
  1204. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. //now := time.Now()
  1209. //year, month, day := now.Date()
  1210. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1211. //todayTimeStamp := today_time.Unix()
  1212. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1213. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1214. UserOrgId: adminUserInfo.Org.Id,
  1215. PatientId: id,
  1216. AssessmentDate: recordDate.Unix(),
  1217. Temperature: temperature,
  1218. PulseFrequency: pulse_frequency,
  1219. BreathingRate: breathing_rate,
  1220. SystolicBloodPressure: systolic_blood_pressure,
  1221. DiastolicBloodPressure: diastolic_blood_pressure,
  1222. ActualUltrafiltration: actual_ultrafiltration,
  1223. ActualDisplacement: actual_displacement,
  1224. ActualTreatmentHour: actualtreatHour,
  1225. ActualTreatmentMinute: actualtreatmin,
  1226. WeightAfter: weightAfter,
  1227. AdditionalWeight: additionalWeight,
  1228. WeightLoss: weightReduce,
  1229. Cruor: cruor,
  1230. SymptomAfterDialysis: symptomsAfterDialysi,
  1231. InternalFistula: internalFistula,
  1232. Catheter: catheter,
  1233. Complication: complications,
  1234. DialysisIntakes: dialysateVolume,
  1235. CreatedTime: time.Now().Unix(),
  1236. UpdatedTime: time.Now().Unix(),
  1237. Status: 1,
  1238. Remark: remark,
  1239. BloodAccessPartId: blood_access_part_id,
  1240. BloodAccessPartOperaId: blood_access_part_opera_id,
  1241. DialysisIntakesUnit: dialysis_intakes_unit,
  1242. PuncturePointOozingBlood: puncturePointOozingBlood,
  1243. PuncturePointHaematoma: puncturePointHaematoma,
  1244. InternalFistulaTremorAc: internalFistulaTremorAc,
  1245. PatientGose: patientGose,
  1246. InpatientDepartment: inpatientDepartment,
  1247. ObservationContent: observationContent,
  1248. ObservationContentOther: observationContentOther,
  1249. DialysisProcess: dialysis_process,
  1250. InAdvanceMinute: in_advance_minute,
  1251. InAdvanceReason: in_advance_reason,
  1252. HemostasisMinute: hemostasis_minute,
  1253. HemostasisOpera: hemostasis_opera,
  1254. TremorNoise: tremor_noise,
  1255. DisequilibriumSyndrome: disequilibrium_syndrome,
  1256. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1257. ArterialTube: arterial_tube,
  1258. IntravenousTube: intravenous_tube,
  1259. Dialyzer: dialyzer,
  1260. InAdvanceReasonOther: in_advance_reason_other,
  1261. IsEat: is_eat,
  1262. CvcA: cvc_a,
  1263. CvcV: cvc_v,
  1264. Channel: channels,
  1265. ReturnBlood: return_blood,
  1266. RehydrationVolume: rehydration_volume,
  1267. DialysisDuring: dialysis_during,
  1268. StrokeVolume: stroke_volume,
  1269. BloodFlow: blood_flow,
  1270. SealingFluidDispose: sealing_fluid_dispose,
  1271. SealingFluidSpecial: sealing_fluid_special,
  1272. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1273. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1274. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1275. SettingPressure: setting_pressure,
  1276. DiastolicPressure: diastolic_pressure,
  1277. OtherComplication: other_complication,
  1278. Ktv: ktv,
  1279. Urr: urr,
  1280. Hypopiesia: hypopiesia,
  1281. Hypertenison: hypertenison,
  1282. Lapse: lapse,
  1283. LeaveOfficeMethod: leave_office_method,
  1284. Consciousness: consciousness,
  1285. Fallrisk: fallrisk,
  1286. MachineRun: machine_run,
  1287. AfterUrea: after_urea,
  1288. PipCoagulation: pip_coagulation,
  1289. AccumulatedBloodVolume: accumulated_blood_volume,
  1290. TransfusionVolume: transfusion_volume,
  1291. LastAfterWeight: last_after_weight,
  1292. }
  1293. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1294. // 查询信息规挡的设置天数
  1295. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1296. if infor.ID > 0 && infor.WeekDay > 0 {
  1297. var cha_time int64
  1298. timeNowStr := time.Now().Format("2006-01-02")
  1299. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1300. //今日的日期减去设置的日期
  1301. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1302. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1303. if cha_time >= recordDate.Unix() {
  1304. //查询审核是否允许
  1305. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1306. //申请状态不允许的情况 拒绝修改
  1307. if infor.ApplicationStatus != 1 {
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1309. return
  1310. }
  1311. }
  1312. }
  1313. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1314. if assessmentAfter.ID == 0 { //新增
  1315. if appRole.UserType == 2 || appRole.UserType == 1 {
  1316. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1317. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1318. } else {
  1319. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1320. }
  1321. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1322. //记录日志
  1323. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1324. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1325. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1326. PatientId: assessmentAfterDislysis.PatientId,
  1327. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1328. Status: 1,
  1329. ErrLog: string(byterequest),
  1330. AdminUserId: adminUserInfo.AdminUser.Id,
  1331. Ctime: 0,
  1332. Mtime: 0,
  1333. Source: "手机端保存透后评估",
  1334. }
  1335. service.CreateAfterDialysisLog(afterDialysisLog)
  1336. finish := models.XtDialysisFinish{
  1337. IsFinish: 1,
  1338. UserOrgId: adminUserInfo.Org.Id,
  1339. Status: 1,
  1340. Ctime: time.Now().Unix(),
  1341. Mtime: 0,
  1342. Module: 9,
  1343. RecordDate: recordDate.Unix(),
  1344. Sourse: 1,
  1345. PatientId: id,
  1346. }
  1347. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1348. if dialysisFinish.ID == 0 {
  1349. service.CreateDialysisFinish(finish)
  1350. }
  1351. redis := service.RedisClient()
  1352. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1353. redis.Set(keyTwo, "", time.Second)
  1354. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1355. //清空key 值
  1356. redis.Set(key, "", time.Second)
  1357. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1358. redis.Set(keyOne, "", time.Second)
  1359. defer redis.Close()
  1360. if err == nil {
  1361. c.ServeSuccessJSON(map[string]interface{}{
  1362. "assessmentAfterDislysis": assessmentAfterDislysis,
  1363. })
  1364. }
  1365. return
  1366. } else { //修改
  1367. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1368. if infor.ID > 0 && infor.WeekDay > 0 {
  1369. var cha_time int64
  1370. timeNowStr := time.Now().Format("2006-01-02")
  1371. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1372. //今日的日期减去设置的日期
  1373. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1374. if cha_time >= recordDate.Unix() {
  1375. //查询审核是否允许
  1376. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1377. //申请状态不允许的情况 拒绝修改
  1378. if infor.ApplicationStatus != 1 {
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1380. return
  1381. }
  1382. }
  1383. }
  1384. if appRole.UserType == 2 || appRole.UserType == 1 {
  1385. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1386. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1387. } else {
  1388. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1389. if assessmentAfterDislysis.Creater == 0 {
  1390. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1391. }
  1392. }
  1393. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1394. assessmentAfterDislysis.ID = assessmentAfter.ID
  1395. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1396. //记录日志
  1397. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1398. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1399. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1400. PatientId: assessmentAfterDislysis.PatientId,
  1401. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1402. Status: 1,
  1403. ErrLog: string(byterequest),
  1404. AdminUserId: adminUserInfo.AdminUser.Id,
  1405. Ctime: time.Now().Unix(),
  1406. Mtime: 0,
  1407. Source: "手机端修改保存透后评估",
  1408. }
  1409. service.CreateAfterDialysisLog(afterDialysisLog)
  1410. redis := service.RedisClient()
  1411. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1412. redis.Set(keyTwo, "", time.Second)
  1413. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1414. //清空key 值
  1415. redis.Set(key, "", time.Second)
  1416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1417. redis.Set(keyOne, "", time.Second)
  1418. if err == nil {
  1419. c.ServeSuccessJSON(map[string]interface{}{
  1420. "assessmentAfterDislysis": assessmentAfterDislysis,
  1421. })
  1422. return
  1423. }
  1424. }
  1425. return
  1426. }
  1427. func (c *DialysisAPIController) PostDialysisPrescription() {
  1428. id, _ := c.GetInt64("patient", 0)
  1429. recordDateStr := c.GetString("record_date")
  1430. if id <= 0 {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. adminUserInfo := c.GetMobileAdminUserInfo()
  1435. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1436. if patient.ID == 0 {
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1438. return
  1439. }
  1440. if len(recordDateStr) == 0 {
  1441. recordDateStr = time.Now().Format("2006-01-02")
  1442. }
  1443. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1444. if parseDateErr != nil {
  1445. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1447. return
  1448. }
  1449. mode_id, _ := c.GetInt64("mode_id", 0)
  1450. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1451. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1452. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1453. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1454. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1455. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1456. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1457. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1458. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1459. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1460. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1461. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1462. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1463. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1464. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1465. kalium, _ := c.GetFloat("kalium", 0)
  1466. sodium, _ := c.GetFloat("sodium", 0)
  1467. calcium, _ := c.GetFloat("calcium", 0)
  1468. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1469. glucose, _ := c.GetFloat("glucose", 0)
  1470. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1471. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1472. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1473. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1474. conductivity, _ := c.GetFloat("conductivity", 0)
  1475. remark := c.GetString("remark")
  1476. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1477. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1478. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1479. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1480. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1481. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1482. special_medicine_other := c.GetString("special_medicine_other")
  1483. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1484. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1485. blood_access, _ := c.GetInt64("blood_access", 0)
  1486. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1487. body_fluid_other := c.GetString("body_fluid_other")
  1488. niprocart, _ := c.GetInt64("niprocart", 0)
  1489. jms, _ := c.GetInt64("jms", 0)
  1490. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1491. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1492. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1493. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1494. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1495. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1496. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1497. injector, _ := c.GetInt64("injector", 0)
  1498. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1499. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1500. safe_package, _ := c.GetInt64("package", 0)
  1501. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1502. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1503. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1504. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1505. blood := c.GetString("blood")
  1506. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1507. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1508. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1509. displace_speed := c.GetString("displace_speed")
  1510. illness, _ := c.GetInt64("illness")
  1511. amylaceum := c.GetString("amylaceum")
  1512. single_time := c.GetString("single_time")
  1513. single_water := c.GetString("single_water")
  1514. replacement_flow := c.GetString("replacement_flow")
  1515. plasma_separator := c.GetString("plasma_separator")
  1516. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1517. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1518. oxygen_flow := c.GetString("oxygen_flow")
  1519. oxygen_time := c.GetString("oxygen_time")
  1520. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1521. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1522. puncture_needle := c.GetString("puncture_needle")
  1523. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1524. epo := c.GetString("epo")
  1525. epo_count, _ := c.GetFloat("epo_count", 0)
  1526. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1527. admin_user_id, _ := c.GetInt64("admin_user_id")
  1528. is_water := c.GetString("is_water")
  1529. var is_war int64
  1530. if is_water == "是" {
  1531. is_war = 1
  1532. }
  1533. if is_water == "否" {
  1534. is_war = 2
  1535. }
  1536. if is_water == "请选择" {
  1537. is_war = 0
  1538. }
  1539. drhy_water := c.GetString("drhy_water")
  1540. dry_water_hour := c.GetString("dry_water_hour")
  1541. water_machine := c.GetString("water_machine")
  1542. add_amount, _ := c.GetFloat("add_amount")
  1543. reduce_amount, _ := c.GetFloat("reduce_amount")
  1544. dialysis_remark := c.GetString("dialysis_remark")
  1545. prescribing_number, _ := c.GetFloat("prescribing_number")
  1546. prescription_sodium := c.GetString("prescription_sodium")
  1547. start_sodium := c.GetString("start_sodium")
  1548. sodium_curve := c.GetString("sodium_curve")
  1549. treatment_remark := c.GetString("treatment_remark")
  1550. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1551. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1552. prescription_water, _ := c.GetFloat("prescription_water")
  1553. dialysis_strainer := c.GetString("dialysis_strainer")
  1554. chaptalization := c.GetString("chaptalization")
  1555. washing_time := c.GetString("washing_time")
  1556. warsh_count := c.GetString("warsh_count")
  1557. blood_access_part_id := c.GetString("blood_access_part_id")
  1558. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1559. dialyzate := c.GetString("dialyzate")
  1560. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1561. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1562. //
  1563. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1564. // if appRole.UserType == 3 {
  1565. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1566. // if getPermissionErr != nil {
  1567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1568. // return
  1569. // } else if headNursePermission == nil {
  1570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1571. // return
  1572. // }
  1573. // }
  1574. //}
  1575. // 查询信息规挡的设置天数
  1576. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1577. if infor.ID > 0 && infor.WeekDay > 0 {
  1578. var cha_time int64
  1579. timeNowStr := time.Now().Format("2006-01-02")
  1580. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1581. //今日的日期减去设置的日期
  1582. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1583. if cha_time >= recordDate.Unix() {
  1584. //查询审核是否允许
  1585. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1586. //申请状态不允许的情况 拒绝修改
  1587. if infor.ApplicationStatus != 1 {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1589. return
  1590. }
  1591. }
  1592. }
  1593. if mode_id > 0 {
  1594. var str string
  1595. //查找该机构用的是什么透析器
  1596. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1597. if filedConfig.ID > 0 {
  1598. str = dialyzerPerfusionApparatus
  1599. } else {
  1600. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1601. }
  1602. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1603. }
  1604. //TODO 需要根据角色去判断
  1605. prescription := models.DialysisPrescription{
  1606. UserOrgId: adminUserInfo.Org.Id,
  1607. PatientId: id,
  1608. RecordDate: recordDate.Unix(),
  1609. ModeId: mode_id,
  1610. DialysisDuration: dialysis_duration,
  1611. Dialyzer: dialyzer,
  1612. PerfusionApparatus: perfusion_apparatus,
  1613. BloodFlowVolume: blood_flow_volume,
  1614. DewaterAmount: dewater_amount,
  1615. DisplaceLiqui: displace_liqui,
  1616. ReplacementWay: replacement_way,
  1617. Anticoagulant: anticoagulant,
  1618. AnticoagulantShouji: anticoagulant_shouji,
  1619. AnticoagulantWeichi: anticoagulant_weichi,
  1620. AnticoagulantZongliang: anticoagulant_zongliang,
  1621. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1622. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1623. Kalium: kalium,
  1624. Sodium: sodium,
  1625. Calcium: calcium,
  1626. Bicarbonate: bicarbonate,
  1627. Glucose: glucose,
  1628. // DryWeight: dry_weight,
  1629. DialysateFlow: dialysate_flow,
  1630. DialysateTemperature: dialysate_temperature,
  1631. // PrescriptionDoctor: prescription_doctor,
  1632. ReplacementTotal: replacement_total,
  1633. Conductivity: conductivity,
  1634. Remark: remark,
  1635. Status: 1,
  1636. CreatedTime: time.Now().Unix(),
  1637. UpdatedTime: time.Now().Unix(),
  1638. DialysisDurationMinute: dialysisDurationMinute,
  1639. DialysisDurationHour: dialysisDurationHour,
  1640. TargetUltrafiltration: targetUltrafiltration,
  1641. DialysateFormulation: dialysateFormulation,
  1642. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1643. BodyFluid: body_fluid,
  1644. SpecialMedicine: special_medicine,
  1645. SpecialMedicineOther: special_medicine_other,
  1646. DisplaceLiquiPart: displace_liqui_part,
  1647. DisplaceLiquiValue: displace_liqui_value,
  1648. BloodAccess: blood_access,
  1649. Ultrafiltration: ultrafiltration,
  1650. BodyFluidOther: body_fluid_other,
  1651. Niprocart: niprocart,
  1652. Jms: jms,
  1653. FistulaNeedleSet: fistula_needle_set,
  1654. FistulaNeedleSet16: fistula_needle_set_16,
  1655. Hemoperfusion: hemoperfusion,
  1656. DialyserSterilised: dialyser_sterilised,
  1657. Filtryzer: filtryzer,
  1658. Dialyzers: dialyzers,
  1659. Injector: injector,
  1660. Bloodlines: bloodlines,
  1661. TubingHemodialysis: tubing_hemodialysis,
  1662. Package: safe_package,
  1663. ALiquid: a_liquid,
  1664. TargetKtv: target_ktv,
  1665. PreImpulse: pre_impulse,
  1666. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1667. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1668. Blood: blood,
  1669. DialysisDialyszers: dialysis_dialyszers,
  1670. DialysisIrrigation: dialysis_irrigation,
  1671. AntioxidantCommodityName: antioxidant_commodity_name,
  1672. DisplaceSpeed: displace_speed,
  1673. Illness: illness,
  1674. Amylaceum: amylaceum,
  1675. SingleTime: single_time,
  1676. SingleWater: single_water,
  1677. ReplacementFlow: replacement_flow,
  1678. PlasmaSeparator: plasma_separator,
  1679. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1680. OxygenUptake: oxygen_uptake,
  1681. OxygenFlow: oxygen_flow,
  1682. OxygenTime: oxygen_time,
  1683. HemodialysisPipelines: hemodialysis_pipelines,
  1684. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1685. PunctureNeedle: puncture_needle,
  1686. PunctureNeedleCount: puncture_needle_count,
  1687. Epo: epo,
  1688. EpoCount: epo_count,
  1689. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1690. AdminUserId: admin_user_id,
  1691. IsWater: is_war,
  1692. DrhyWater: drhy_water,
  1693. DryWaterHour: dry_water_hour,
  1694. WaterMachine: water_machine,
  1695. AddAmount: add_amount,
  1696. ReduceAmount: reduce_amount,
  1697. DialysisRemark: dialysis_remark,
  1698. PrescribingNumber: prescribing_number,
  1699. StartSodium: start_sodium,
  1700. SodiumCurve: sodium_curve,
  1701. TreatmentRemark: treatment_remark,
  1702. PrescriptionSodium: prescription_sodium,
  1703. DialysisFluidFlow: dialysis_fluid_flow,
  1704. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1705. PrescriptionWater: prescription_water,
  1706. DialysisStrainer: dialysis_strainer,
  1707. Chaptalization: chaptalization,
  1708. WashingTime: washing_time,
  1709. WarshCount: warsh_count,
  1710. BloodAccessPartId: blood_access_part_id,
  1711. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1712. Dialyzate: dialyzate,
  1713. }
  1714. //查询最近透析准备表里是否存在 透析器 灌流器
  1715. //
  1716. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1717. //
  1718. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1719. //
  1720. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1721. //if len(mation)>0{
  1722. // for _, item := range splitStr {
  1723. // for _,it := range mation{
  1724. // if(item == it.SpecificationName){
  1725. //
  1726. // //查询最近一次的透析器
  1727. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1728. //
  1729. // if errcode == gorm.ErrRecordNotFound{
  1730. // //插入数据
  1731. // prepare := models.DialysisBeforePrepare{
  1732. // UserOrgId: adminUserInfo.Org.Id,
  1733. // PatientId: id,
  1734. // RecordDate: recordDate.Unix(),
  1735. // GoodTypeId: it.GoodTypeId,
  1736. // GoodId: it.ID,
  1737. // Count: 1,
  1738. // Ctime: time.Now().Unix(),
  1739. // Creater: adminUserInfo.AdminUser.Id,
  1740. // Status:1,
  1741. //
  1742. // }
  1743. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1744. // fmt.Println("",errcode)
  1745. // }
  1746. // }
  1747. // }
  1748. //
  1749. // }
  1750. //
  1751. // for _, item := range splitIrrigation {
  1752. // for _,it := range mation{
  1753. // if(item == it.SpecificationName){
  1754. // //查询最近一次的透析器
  1755. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1756. // if errcode == gorm.ErrRecordNotFound{
  1757. // //插入数据
  1758. // prepare := models.DialysisBeforePrepare{
  1759. // UserOrgId: adminUserInfo.Org.Id,
  1760. // PatientId: id,
  1761. // RecordDate: recordDate.Unix(),
  1762. // GoodTypeId: it.GoodTypeId,
  1763. // GoodId: it.ID,
  1764. // Count: 1,
  1765. // Ctime: time.Now().Unix(),
  1766. // Creater: adminUserInfo.AdminUser.Id,
  1767. // Status:1,
  1768. //
  1769. // }
  1770. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1771. // fmt.Println(errcode)
  1772. // }
  1773. // }
  1774. // }
  1775. // }
  1776. //}
  1777. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1778. if dialysisPrescription.ID == 0 { //新增
  1779. if appRole.UserType == 2 || appRole.UserType == 1 {
  1780. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1781. }
  1782. prescription.Creater = adminUserInfo.AdminUser.Id
  1783. //针对河间咸得
  1784. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1785. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1786. prescription.DisplaceLiquiPart = 0
  1787. prescription.DisplaceLiquiValue = 0
  1788. }
  1789. }
  1790. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1791. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1792. }
  1793. err := service.AddSigleRecord(&prescription)
  1794. //记录日志
  1795. byterequest, _ := json.Marshal(prescription)
  1796. prescriptionLog := models.XtDialysisPrescriptionLog{
  1797. UserOrgId: prescription.UserOrgId,
  1798. Ctime: time.Now().Unix(),
  1799. Mtime: 0,
  1800. ErrLog: string(byterequest),
  1801. AdminUserId: adminUserInfo.AdminUser.Id,
  1802. RecordDate: prescription.RecordDate,
  1803. PatientId: prescription.PatientId,
  1804. Source: "手机端新增保存处方",
  1805. Status: 1,
  1806. }
  1807. service.CreatePrescriptionLog(prescriptionLog)
  1808. finish := models.XtDialysisFinish{
  1809. IsFinish: 1,
  1810. UserOrgId: adminUserInfo.Org.Id,
  1811. Status: 1,
  1812. Ctime: time.Now().Unix(),
  1813. Mtime: 0,
  1814. Module: 1,
  1815. RecordDate: recordDate.Unix(),
  1816. Sourse: 1,
  1817. PatientId: id,
  1818. }
  1819. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1820. if dialysisFinish.ID == 0 {
  1821. service.CreateDialysisFinish(finish)
  1822. }
  1823. //长沙南雅医院,自动生成抗凝剂的临时处方
  1824. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1825. if prescribing_number == 0 {
  1826. prescribing_number = 1
  1827. }
  1828. if prescribing_number == 0 && id == 14682 {
  1829. prescribing_number = 2
  1830. }
  1831. if prescribing_number == 0 && id == 18560 {
  1832. prescribing_number = 2
  1833. }
  1834. advice := models.DoctorAdvice{
  1835. UserOrgId: adminUserInfo.Org.Id,
  1836. PatientId: id,
  1837. GroupNo: 0,
  1838. AdviceType: 2,
  1839. RecordDate: recordDate.Unix(),
  1840. AdviceDate: recordDate.Unix(),
  1841. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1842. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1843. AdviceDesc: "",
  1844. ReminderDate: 0,
  1845. SingleDose: anticoagulant_zongliang,
  1846. SingleDoseUnit: "iu",
  1847. DrugSpec: 0,
  1848. DrugSpecUnit: "",
  1849. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1850. PrescribingNumberUnit: "支",
  1851. DeliveryWay: "静脉注射",
  1852. ExecutionFrequency: "上机前",
  1853. AdviceDoctor: 0,
  1854. Status: 1,
  1855. CreatedTime: time.Now().Unix(),
  1856. UpdatedTime: time.Now().Unix(),
  1857. IsPrescription: 1,
  1858. ExecutionState: 2,
  1859. StopState: 2,
  1860. IsSettle: 2,
  1861. }
  1862. // 查询排班信息
  1863. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1864. if schedulePatient.ID > 0 {
  1865. if schedulePatient.ScheduleType == 1 {
  1866. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1867. }
  1868. if schedulePatient.ScheduleType == 2 {
  1869. advice.StartTime = recordDate.Unix() + 10*60*60
  1870. }
  1871. }
  1872. // 抗凝剂名称
  1873. switch anticoagulant {
  1874. case 1:
  1875. advice.AdviceName = "无肝素"
  1876. break
  1877. case 2:
  1878. advice.AdviceName = "普通肝素"
  1879. break
  1880. case 3:
  1881. advice.AdviceName = "低分子肝素"
  1882. break
  1883. case 4:
  1884. advice.AdviceName = "阿加曲班"
  1885. break
  1886. case 5:
  1887. advice.AdviceName = "枸橼酸钠"
  1888. break
  1889. case 6:
  1890. advice.AdviceName = "低分子肝素钙"
  1891. break
  1892. case 7:
  1893. advice.AdviceName = "低分子肝素钠"
  1894. break
  1895. case 8:
  1896. advice.AdviceName = "依诺肝素"
  1897. break
  1898. case 9:
  1899. advice.AdviceName = "达肝素"
  1900. break
  1901. case 10:
  1902. advice.AdviceName = "体外抗凝"
  1903. break
  1904. case 11:
  1905. advice.AdviceName = "那曲肝素"
  1906. break
  1907. case 12:
  1908. advice.AdviceName = "无抗凝剂"
  1909. break
  1910. }
  1911. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1912. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1913. advice.AdviceDoctor = appRole.AdminUserId
  1914. }
  1915. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1916. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1917. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1918. advice.AdviceName = "低分子肝素钠注射液"
  1919. // 修改患者临时医嘱里的抗凝剂医嘱
  1920. advice.ID = advicePrescription.ID
  1921. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1922. } else {
  1923. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1924. advice.AdviceName = "低分子肝素钠注射液"
  1925. // 新增患者临时医嘱里的抗凝剂医嘱
  1926. service.CreateDoctorAdvice(&advice)
  1927. }
  1928. }
  1929. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1930. redis := service.RedisClient()
  1931. defer redis.Close()
  1932. //清空key 值
  1933. redis.Set(key, "", time.Second)
  1934. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1935. redis.Set(keyOne, "", time.Second)
  1936. }
  1937. //获取key,清空redis
  1938. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1939. redis := service.RedisClient()
  1940. //清空key 值
  1941. redis.Set(key, "", time.Second)
  1942. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1943. //清空key 值
  1944. redis.Set(keyOne, "", time.Second)
  1945. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1946. //清空key 值
  1947. redis.Set(keyTwo, "", time.Second)
  1948. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1949. redis.Set(keySix, "", time.Second)
  1950. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1951. redis.Set(keySeven, "", time.Second)
  1952. if err == nil {
  1953. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1954. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1955. //清空key 值
  1956. redis.Set(keyThree, "", time.Second)
  1957. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1958. //清空key 值
  1959. redis.Set(keyFour, "", time.Second)
  1960. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1961. redis.Set(keyFive, "", time.Second)
  1962. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1963. redis.Set(keySix, "", time.Second)
  1964. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1965. redis.Set(keySeven, "", time.Second)
  1966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1967. //清空key 值
  1968. redis.Set(keyOne, "", time.Second)
  1969. if updateErr != nil {
  1970. utils.ErrorLog("%v", updateErr)
  1971. }
  1972. defer redis.Close()
  1973. c.ServeSuccessJSON(map[string]interface{}{
  1974. "prescription": prescription,
  1975. })
  1976. }
  1977. } else { //修改
  1978. //if mode_id > 0 {
  1979. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1980. //}
  1981. //if template.TemplateId == 1 {
  1982. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1983. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1984. // if getPermissionErr != nil {
  1985. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1986. // return
  1987. // } else if headNursePermission == nil {
  1988. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1989. // return
  1990. // }
  1991. // }
  1992. //}
  1993. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1994. prescription.Modifier = adminUserInfo.AdminUser.Id
  1995. if appRole.UserType == 2 || appRole.UserType == 1 {
  1996. prescription_doctor := adminUserInfo.AdminUser.Id
  1997. prescription.PrescriptionDoctor = prescription_doctor
  1998. } else {
  1999. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2000. }
  2001. if dialysisPrescription.Creater == 0 { //体重称
  2002. prescription.Creater = adminUserInfo.AdminUser.Id
  2003. } else {
  2004. prescription.Creater = dialysisPrescription.Creater
  2005. if adminUserInfo.Org.Id == 9882 {
  2006. if appRole.UserType == 2 || appRole.UserType == 1 {
  2007. prescription_doctor := adminUserInfo.AdminUser.Id
  2008. prescription.PrescriptionDoctor = prescription_doctor
  2009. prescription.Creater = prescription_doctor
  2010. }
  2011. }
  2012. }
  2013. prescription.ID = dialysisPrescription.ID
  2014. service.UpDateDialysisPrescription(&prescription)
  2015. //记录日志
  2016. byterequest, _ := json.Marshal(prescription)
  2017. prescriptionLog := models.XtDialysisPrescriptionLog{
  2018. UserOrgId: prescription.UserOrgId,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. ErrLog: string(byterequest),
  2022. AdminUserId: adminUserInfo.AdminUser.Id,
  2023. RecordDate: prescription.RecordDate,
  2024. PatientId: prescription.PatientId,
  2025. Source: "手机端修改处方",
  2026. Status: 1,
  2027. }
  2028. service.CreatePrescriptionLog(prescriptionLog)
  2029. finish := models.XtDialysisFinish{
  2030. IsFinish: 1,
  2031. UserOrgId: adminUserInfo.Org.Id,
  2032. Status: 1,
  2033. Ctime: time.Now().Unix(),
  2034. Mtime: 0,
  2035. Module: 1,
  2036. RecordDate: recordDate.Unix(),
  2037. Sourse: 1,
  2038. PatientId: id,
  2039. }
  2040. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2041. if dialysisFinish.ID == 0 {
  2042. service.CreateDialysisFinish(finish)
  2043. }
  2044. //修改处方
  2045. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2046. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2047. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2048. if advicePrescription.ID > 0 {
  2049. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2051. redis := service.RedisClient()
  2052. defer redis.Close()
  2053. //清空key 值
  2054. redis.Set(key, "", time.Second)
  2055. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2056. redis.Set(keyOne, "", time.Second)
  2057. }
  2058. }
  2059. //获取key,清空redis
  2060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2061. redis := service.RedisClient()
  2062. //清空key 值
  2063. redis.Set(key, "", time.Second)
  2064. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2065. //清空key 值
  2066. redis.Set(keyOne, "", time.Second)
  2067. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2068. redis.Set(keySix, "", time.Second)
  2069. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2070. redis.Set(keySeven, "", time.Second)
  2071. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2072. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2073. //清空key 值
  2074. redis.Set(keyTwoOne, "", time.Second)
  2075. defer redis.Close()
  2076. if updateErr != nil {
  2077. utils.ErrorLog("%v", updateErr)
  2078. }
  2079. c.ServeSuccessJSON(map[string]interface{}{
  2080. "prescription": prescription,
  2081. })
  2082. }
  2083. }
  2084. func (c *DialysisAPIController) Finish() {
  2085. id, _ := c.GetInt64("patient", 0)
  2086. recordDateStr := c.GetString("record_date")
  2087. nurseID, _ := c.GetInt64("nurse")
  2088. end_time := c.GetString("end_time")
  2089. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2090. internal_fistula := c.GetString("blood_access_internal_fistula")
  2091. catheter := c.GetString("catheter")
  2092. cruor := c.GetString("cruor")
  2093. mission := c.GetString("mission")
  2094. condenser := c.GetString("condenser")
  2095. if id <= 0 || nurseID <= 0 {
  2096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2097. return
  2098. }
  2099. adminUserInfo := c.GetMobileAdminUserInfo()
  2100. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2101. if patient.ID == 0 {
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2103. return
  2104. }
  2105. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2106. if getNurseErr != nil {
  2107. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2109. return
  2110. } else if nurse == nil {
  2111. c.ErrorLog("护士不存在")
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2113. return
  2114. }
  2115. if len(recordDateStr) == 0 {
  2116. recordDateStr = time.Now().Format("2006-01-02")
  2117. }
  2118. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2119. if parseDateErr != nil {
  2120. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2122. return
  2123. }
  2124. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2125. if parseEndDateErr != nil {
  2126. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. // 查询信息规挡的设置天数
  2131. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2132. if infor.ID > 0 && infor.WeekDay > 0 {
  2133. var cha_time int64
  2134. timeNowStr := time.Now().Format("2006-01-02")
  2135. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2136. //今日的日期减去设置的日期
  2137. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2138. if cha_time >= recordDate.Unix() {
  2139. //查询审核是否允许
  2140. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2141. //申请状态不允许的情况 拒绝修改
  2142. if infor.ApplicationStatus != 1 {
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2144. return
  2145. }
  2146. }
  2147. }
  2148. //now := time.Now()
  2149. //year, month, day := now.Date()
  2150. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2151. //todayTimeStamp := today_time.Unix()
  2152. // 获取当天的第一条透析纪录
  2153. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2154. if getMonitorRecordsErr != nil {
  2155. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2157. return
  2158. }
  2159. // 获取当前的最后一条透析纪录
  2160. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2161. if getMonitorRecordsErr != nil {
  2162. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2164. return
  2165. }
  2166. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2167. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2168. if getAADErr != nil {
  2169. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2171. return
  2172. }
  2173. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2174. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2175. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2176. if assessmentAfterDislysis != nil {
  2177. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2178. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2179. } else {
  2180. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2181. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2182. tempassessmentAfterDislysis.Status = 1
  2183. tempassessmentAfterDislysis.PatientId = id
  2184. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2185. }
  2186. //长沙南雅
  2187. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2188. //获取最后一条透析处方数据
  2189. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2190. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2191. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2192. }
  2193. if dialysisOrder.Stage == 1 {
  2194. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2195. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2196. fmt.Println(value)
  2197. a, b := math.Modf(value)
  2198. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2199. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2200. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2201. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2202. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2203. }
  2204. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2205. //var num1 int64
  2206. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2207. //fmt.Println(num1)
  2208. //sub := float64(num1 / 3600)
  2209. //fmt.Println(sub)
  2210. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2211. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2212. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2213. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2214. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2215. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2216. if adminUserInfo.Org.Id != 10375 {
  2217. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2218. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2219. }
  2220. if adminUserInfo.Org.Id != 10445 {
  2221. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2222. }
  2223. //北方营口医院
  2224. if adminUserInfo.Org.Id == 10445 {
  2225. //获取最后一条透析处方数据
  2226. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2227. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2228. } else {
  2229. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2230. }
  2231. //新化博翔
  2232. if adminUserInfo.Org.Id == 10447 {
  2233. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2234. }
  2235. //阳春
  2236. if adminUserInfo.Org.Id == 10485 {
  2237. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2238. }
  2239. if adminUserInfo.Org.Id == 10551 {
  2240. //获取最后一条透析处方数据
  2241. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2242. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2243. }
  2244. if adminUserInfo.Org.Id == 10580 {
  2245. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2246. }
  2247. }
  2248. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 {
  2249. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2250. if evaluation.SystolicBloodPressure == 0 {
  2251. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2252. pre := models.PredialysisEvaluation{
  2253. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2254. }
  2255. fmt.Println("prew", pre)
  2256. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2257. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2258. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2259. redis := service.RedisClient()
  2260. redis.Set(key, "", time.Second)
  2261. redis.Set(keyOne, "", time.Second)
  2262. defer redis.Close()
  2263. fmt.Println(getNurseErr)
  2264. }
  2265. if evaluation.DiastolicBloodPressure == 0 {
  2266. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2267. pres := models.PredialysisEvaluation{
  2268. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2269. }
  2270. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2271. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2272. redis := service.RedisClient()
  2273. redis.Set(key, "", time.Second)
  2274. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2275. redis.Set(keyOne, "", time.Second)
  2276. defer redis.Close()
  2277. fmt.Println(getNurseErr)
  2278. }
  2279. if evaluation.PulseFrequency == 0 {
  2280. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2281. press := models.PredialysisEvaluation{
  2282. PulseFrequency: evaluation.PulseFrequency,
  2283. }
  2284. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2285. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2286. redis := service.RedisClient()
  2287. redis.Set(key, "", time.Second)
  2288. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2289. redis.Set(keyOne, "", time.Second)
  2290. defer redis.Close()
  2291. fmt.Println(getNurseErr)
  2292. }
  2293. if evaluation.Temperature == 0 {
  2294. evaluation.Temperature = fmonitorRecords.Temperature
  2295. press := models.PredialysisEvaluation{
  2296. Temperature: evaluation.Temperature,
  2297. }
  2298. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2299. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2300. redis := service.RedisClient()
  2301. redis.Set(key, "", time.Second)
  2302. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2303. redis.Set(keyOne, "", time.Second)
  2304. defer redis.Close()
  2305. fmt.Println(getNurseErr)
  2306. }
  2307. }
  2308. if adminUserInfo.Org.Id == 9583 {
  2309. //获取透析处方的最后一条数据
  2310. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2311. if diaerr != nil {
  2312. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2314. return
  2315. }
  2316. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2317. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2318. }
  2319. }
  2320. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2321. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2322. }
  2323. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2324. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2325. }
  2326. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2327. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2328. }
  2329. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2330. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2331. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2332. }
  2333. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2334. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2335. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2336. }
  2337. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2338. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2339. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2340. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2341. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2342. }
  2343. if lastAssessmentAfterDislysis != nil {
  2344. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2345. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2346. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2347. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2348. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2349. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2350. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2351. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2352. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2353. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2354. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2355. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2356. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2357. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2358. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2359. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2360. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2361. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2362. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2363. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2364. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2365. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2366. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2367. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2368. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2369. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2370. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2371. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2372. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2373. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2374. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2375. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2376. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2377. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2378. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2379. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2380. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2381. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2382. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2383. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2384. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2385. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2386. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2387. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2388. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2389. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2390. if tempassessmentAfterDislysis.PatientId == 18695 {
  2391. tempassessmentAfterDislysis.ActualDisplacement = 0
  2392. }
  2393. if adminUserInfo.Org.Id != 10375 {
  2394. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2395. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2396. }
  2397. }
  2398. finish := models.XtDialysisFinish{
  2399. IsFinish: 1,
  2400. UserOrgId: adminUserInfo.Org.Id,
  2401. Status: 1,
  2402. Ctime: time.Now().Unix(),
  2403. Mtime: 0,
  2404. Module: 9,
  2405. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2406. Sourse: 1,
  2407. PatientId: tempassessmentAfterDislysis.PatientId,
  2408. }
  2409. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2410. if dialysisFinish.ID == 0 {
  2411. service.CreateDialysisFinish(finish)
  2412. }
  2413. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2414. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2415. redis := service.RedisClient()
  2416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2417. redis.Set(keyOne, "", time.Second)
  2418. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2419. redis.Set(keyTwo, "", time.Second)
  2420. defer redis.Close()
  2421. //清空key 值
  2422. redis.Set(key, "", time.Second)
  2423. if err != nil {
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. }
  2427. if dialysisOrder == nil {
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2429. return
  2430. }
  2431. if dialysisOrder.Stage == 2 {
  2432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2433. return
  2434. }
  2435. if dialysisOrder.Stage == 1 {
  2436. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2437. finish := models.XtDialysisFinish{
  2438. IsFinish: 1,
  2439. UserOrgId: adminUserInfo.Org.Id,
  2440. Status: 1,
  2441. Ctime: time.Now().Unix(),
  2442. Mtime: 0,
  2443. Module: 8,
  2444. RecordDate: recordDate.Unix(),
  2445. Sourse: 1,
  2446. PatientId: id,
  2447. }
  2448. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2449. if dialysisFinish.ID == 0 {
  2450. service.CreateDialysisFinish(finish)
  2451. }
  2452. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2453. redis := service.RedisClient()
  2454. defer redis.Close()
  2455. //清空key 值
  2456. redis.Set(key, "", time.Second)
  2457. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2458. redis.Set(keyOne, "", time.Second)
  2459. //结束时候透析次数加1
  2460. service.UpdateSolutionByPatientId(id)
  2461. //下机完自动消毒,针对长沙南雅
  2462. if dialysisOrder.Stage == 1 {
  2463. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2464. //根据床位号获取设备型号
  2465. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2466. //查询使用消毒最后一条消毒记录
  2467. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2468. fmt.Println("err", err)
  2469. if err == gorm.ErrRecordNotFound {
  2470. //查找排班
  2471. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2472. //查询改设备是否有消毒计划
  2473. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2474. //根据床位号获取设备id
  2475. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2476. //查询病人信息
  2477. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2478. var con = ""
  2479. if patients.IsInfectious == 0 {
  2480. con = ""
  2481. }
  2482. if patients.IsInfectious == 1 {
  2483. con = "无"
  2484. }
  2485. if patients.IsInfectious == 2 {
  2486. con = "有"
  2487. }
  2488. if errcode == nil {
  2489. var end_time int64
  2490. end_time = endDate.Unix() + plan.DisinfecTime*60
  2491. //新增消毒
  2492. information := models.DeviceInformation{
  2493. Date: dialysisOrder.DialysisDate,
  2494. Zone: dialysisOrder.ZoneId,
  2495. Class: dialysisOrder.SchedualType,
  2496. BedNumber: dialysisOrder.BedID,
  2497. PatientId: dialysisOrder.PatientId,
  2498. DialysisMode: scheduleByPatient.ModeId,
  2499. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2500. Disinfection: 1,
  2501. DialysisConcentration: 1,
  2502. DisinfectionStatus: 1,
  2503. Move: 1,
  2504. UserOrgId: dialysisOrder.UserOrgId,
  2505. DisinfectType: plan.Way,
  2506. DisinfectantType: plan.MachineDisinfectant,
  2507. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2508. Disinfectant: plan.Disinfectant,
  2509. Ctime: time.Now().Unix(),
  2510. Status: 1,
  2511. SignName: nurseID,
  2512. EquimentId: addmacher.ID,
  2513. DisinfectionResidue: 2,
  2514. Bed: addmacher.BedNumber,
  2515. StartTime: dialysisOrder.StartTime,
  2516. EndTime: dialysisOrder.EndTime,
  2517. Contagion: con,
  2518. WeightLoss: 0,
  2519. Hyperfiltratio: 0,
  2520. DialysisHour: "",
  2521. MachineRun: 1,
  2522. DisinfecStartime: endDate.Unix(),
  2523. DisinfecEndtime: end_time,
  2524. }
  2525. err := service.CreateInformationTwo(&information)
  2526. fmt.Println("报错", err)
  2527. }
  2528. }
  2529. }
  2530. }
  2531. dialysisOrder.Stage = 2
  2532. dialysisOrder.FinishNurse = nurseID
  2533. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2534. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2535. dialysisOrder.EndTime = endDate.Unix()
  2536. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2537. // 长沙南雅需求
  2538. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2539. //获取最后1条监测的数据
  2540. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2541. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2542. var accumulatedBloodVolume float64
  2543. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2544. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2545. fmt.Println(err)
  2546. // 查询未执行的医嘱
  2547. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2548. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2549. for _, item := range doctorAdvice {
  2550. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2551. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2552. redis := service.RedisClient()
  2553. //清空key 值
  2554. redis.Set(key, "", time.Second)
  2555. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2556. redis.Set(keyTwo, "", time.Second)
  2557. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2558. redis.Set(keyThree, "", time.Second)
  2559. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2560. theTime := toTime.Format("2006-01-02")
  2561. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2562. redis.Set(keyFour, "", time.Second)
  2563. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2564. redis.Set(keyFive, "", time.Second)
  2565. defer redis.Close()
  2566. }
  2567. }
  2568. go func() {
  2569. ssoDomain := beego.AppConfig.String("call_domain")
  2570. api := ssoDomain + "/index/downpatient"
  2571. values := make(url.Values)
  2572. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2573. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2574. values.Set("patient_id", strconv.FormatInt(id, 10))
  2575. http.PostForm(api, values)
  2576. }()
  2577. if err == nil {
  2578. c.ServeSuccessJSON(map[string]interface{}{
  2579. "dialysisOrder": dialysisOrder,
  2580. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2581. })
  2582. } else {
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2584. }
  2585. }
  2586. }
  2587. func (c *DialysisAPIController) GetAllZone() {
  2588. adminUserInfo := c.GetMobileAdminUserInfo()
  2589. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2590. if err == nil {
  2591. c.ServeSuccessJSON(map[string]interface{}{
  2592. "zone": zone,
  2593. })
  2594. }
  2595. }
  2596. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2597. adminUserInfo := c.GetMobileAdminUserInfo()
  2598. page, _ := c.GetInt64("page", 1)
  2599. limit, _ := c.GetInt64("limit", 10)
  2600. schedulType, _ := c.GetInt64("schedul_type", 0)
  2601. startTime, _ := c.GetInt64("schedul_time", 0)
  2602. partitionType, _ := c.GetInt64("partition_type", 0)
  2603. keywords := c.GetString("keywords")
  2604. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2605. if err == nil {
  2606. c.ServeSuccessJSON(map[string]interface{}{
  2607. "schedule": dialysisSchedule,
  2608. })
  2609. }
  2610. return
  2611. }
  2612. // /m/api/dialysis/start [post]
  2613. // @param patient_id:int
  2614. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2615. // @param nurse:int 上机护士
  2616. // @param bed:int 床位号
  2617. func (this *DialysisAPIController) StartDialysis() {
  2618. patientID, _ := this.GetInt64("patient_id")
  2619. recordDateStr := this.GetString("record_date")
  2620. nurseID, _ := this.GetInt64("start_nurse")
  2621. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2622. blood_drawing, _ := this.GetInt64("blood_drawing")
  2623. schedual_type, _ := this.GetInt64("schedual_type")
  2624. bedID, _ := this.GetInt64("bed")
  2625. start_time := this.GetString("start_time")
  2626. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2627. change_nurse, _ := this.GetInt64("change_nurse")
  2628. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2629. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2630. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2631. puncture_needle := this.GetString("puncture_needle")
  2632. puncture_way := this.GetString("puncture_way")
  2633. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2634. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2635. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2636. zone_id, _ := this.GetInt64("zone_id")
  2637. elecsign := this.GetString("url")
  2638. nuclein_date_str := this.GetString("nuclein_date_str")
  2639. schedule_remark := this.GetString("schedule_remark")
  2640. order_remark := this.GetString("order_remark")
  2641. catheter_operation := this.GetString("catheter_operation")
  2642. blood_flow_volume := this.GetString("blood_flow_volume")
  2643. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2644. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2645. return
  2646. }
  2647. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2648. if parseStartDateErr != nil {
  2649. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2651. return
  2652. }
  2653. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2654. if parseErr != nil {
  2655. this.ErrorLog("时间解析失败:%v", parseErr)
  2656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2657. return
  2658. }
  2659. adminUserInfo := this.GetMobileAdminUserInfo()
  2660. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2661. if getPatientErr != nil {
  2662. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2664. return
  2665. } else if patient == nil {
  2666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2667. return
  2668. }
  2669. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2670. if getNurseErr != nil {
  2671. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2673. return
  2674. } else if nurse == nil {
  2675. this.ErrorLog("护士不存在")
  2676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2677. return
  2678. }
  2679. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2680. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2681. if getDeviceNumberErr != nil {
  2682. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2684. return
  2685. } else if deviceNumber == nil {
  2686. this.ErrorLog("床位号不存在")
  2687. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2688. return
  2689. }
  2690. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2691. if getRecordErr != nil {
  2692. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2694. return
  2695. } else if dialysisRecord != nil {
  2696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2697. return
  2698. }
  2699. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2700. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2701. timeLayout := "2006-01-02 15:04:05"
  2702. loc, _ := time.LoadLocation("Local")
  2703. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2704. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2705. schedulestartTime := theStartTime.Unix()
  2706. scheduleendTime := theEndTime.Unix()
  2707. var theNucleinDate int64
  2708. timeLayoutOne := "2006-01-02"
  2709. if len(nuclein_date_str) > 0 {
  2710. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2711. if err != nil {
  2712. utils.ErrorLog(err.Error())
  2713. }
  2714. theNucleinDate = theTime.Unix()
  2715. }
  2716. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2717. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2718. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2719. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2720. //查询该床位是否有人用了
  2721. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2722. if err == gorm.ErrRecordNotFound { //空床位
  2723. // 修改了床位逻辑
  2724. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2725. if daySchedule.ID > 0 {
  2726. daySchedule.PartitionId = deviceNumber.ZoneID
  2727. daySchedule.BedId = bedID
  2728. daySchedule.ScheduleType = schedual_type
  2729. daySchedule.UpdatedTime = time.Now().Unix()
  2730. xtSchedule := models.Schedule{
  2731. PartitionId: deviceNumber.ZoneID,
  2732. BedId: bedID,
  2733. ScheduleType: schedual_type,
  2734. UpdatedTime: time.Now().Unix(),
  2735. }
  2736. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2737. if err != nil {
  2738. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2739. return
  2740. }
  2741. }
  2742. } else if err == nil {
  2743. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2744. if order.ID > 0 { //该机位被其他人占用了
  2745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2746. return
  2747. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2748. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2749. if daySchedule.ID > 0 {
  2750. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2751. if err != nil {
  2752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2753. return
  2754. }
  2755. }
  2756. }
  2757. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2759. return
  2760. }
  2761. //else if order.ID == 0 { //该床位没被占用
  2762. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2763. // if daySchedule.ID > 0 {
  2764. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2765. // //daySchedule.BedId = bedID
  2766. // //daySchedule.ScheduleType = schedual_type
  2767. // //daySchedule.UpdatedTime = time.Now().Unix()
  2768. // //err := service.UpdateSchedule(&daySchedule)
  2769. // xtSchedule := models.Schedule{
  2770. // PartitionId: deviceNumber.ZoneID,
  2771. // BedId: bedID,
  2772. // ScheduleType: schedual_type,
  2773. // UpdatedTime: time.Now().Unix(),
  2774. // }
  2775. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2776. // if err != nil {
  2777. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2778. // return
  2779. // }
  2780. // }
  2781. //}
  2782. //}
  2783. } else if err != nil {
  2784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2785. return
  2786. }
  2787. // 查询信息规挡的设置天数
  2788. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2789. if infor.ID > 0 && infor.WeekDay > 0 {
  2790. var cha_time int64
  2791. timeNowStr := time.Now().Format("2006-01-02")
  2792. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2793. //今日的日期减去设置的日期
  2794. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2795. if cha_time >= recordDate.Unix() {
  2796. //查询审核是否允许
  2797. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2798. //申请状态不允许的情况 拒绝修改
  2799. if infor.ApplicationStatus != 1 {
  2800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2801. return
  2802. }
  2803. }
  2804. }
  2805. dialysisRecord = &models.DialysisOrder{
  2806. DialysisDate: recordDate.Unix(),
  2807. UserOrgId: adminUserInfo.Org.Id,
  2808. PatientId: patientID,
  2809. Stage: 1,
  2810. BedID: bedID,
  2811. StartNurse: nurseID,
  2812. Status: 1,
  2813. StartTime: startDate.Unix(),
  2814. CreatedTime: time.Now().Unix(),
  2815. UpdatedTime: time.Now().Unix(),
  2816. PunctureNurse: puncture_nurse,
  2817. Creator: adminUserInfo.AdminUser.Id,
  2818. Modifier: adminUserInfo.AdminUser.Id,
  2819. SchedualType: schedual_type,
  2820. WashpipeNurse: washpipe_nurse,
  2821. ChangeNurse: change_nurse,
  2822. DifficultPunctureNurse: difficult_puncture_nurse,
  2823. NewFistulaNurse: new_fistula_nurse,
  2824. ZoneId: zone_id,
  2825. QualityNurseId: quality_nurse_id,
  2826. PunctureNeedle: puncture_needle,
  2827. PunctureWay: puncture_way,
  2828. DialysisIrrigation: dialysis_irrigation,
  2829. DialysisDialyszers: dialysis_dialyszers,
  2830. BloodAccessId: blood_access_id,
  2831. Url: elecsign,
  2832. NucleinDate: theNucleinDate,
  2833. ScheduleRemark: schedule_remark,
  2834. OrderRemark: order_remark,
  2835. CatheterOperation: catheter_operation,
  2836. BloodFlowVolume: blood_flow_volume,
  2837. }
  2838. //查询该床位是否有人用了
  2839. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2840. if errorscode == gorm.ErrRecordNotFound {
  2841. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2842. finish := models.XtDialysisFinish{
  2843. IsFinish: 1,
  2844. UserOrgId: adminUserInfo.Org.Id,
  2845. Status: 1,
  2846. Ctime: time.Now().Unix(),
  2847. Mtime: 0,
  2848. Module: 6,
  2849. RecordDate: schedulestartTime,
  2850. Sourse: 1,
  2851. PatientId: patientID,
  2852. }
  2853. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2854. if dialysisFinish.ID == 0 {
  2855. service.CreateDialysisFinish(finish)
  2856. }
  2857. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2858. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2859. //统计该患者总次数
  2860. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2861. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2862. }
  2863. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2864. //统计该患者总次数
  2865. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2866. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2867. }
  2868. redis := service.RedisClient()
  2869. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2870. redis.Set(key, "", time.Second)
  2871. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2872. //清空key 值
  2873. redis.Set(keyOne, "", time.Second)
  2874. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2875. //清空key 值
  2876. redis.Set(keyTwo, "", time.Second)
  2877. if createErr != nil {
  2878. this.ErrorLog("上机失败:%v", createErr)
  2879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2880. return
  2881. }
  2882. }
  2883. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2884. var tempdispose string
  2885. // 只针对中能建
  2886. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2887. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2888. }
  2889. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2890. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2891. }
  2892. var ultrafiltration_rate float64
  2893. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2894. //后期预增脱水量
  2895. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2896. if prescription.ID > 0 {
  2897. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2898. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2899. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2900. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2901. }
  2902. if adminUserInfo.Org.Id == 10597 { //adminUserInfo.Org.Id == 9538
  2903. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2904. }
  2905. //针对医师汇
  2906. if adminUserInfo.Org.Id == 10121 {
  2907. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2908. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2909. }
  2910. //针对通道
  2911. if adminUserInfo.Org.Id == 10234 {
  2912. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2913. }
  2914. //针对监利大垸医院
  2915. if template.TemplateId == 41 {
  2916. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2917. }
  2918. //针对肇庆三鹤血液透析中心
  2919. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2920. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2921. }
  2922. if adminUserInfo.Org.Id == 10469 {
  2923. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2924. }
  2925. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2926. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2927. }
  2928. // 只针对方济医院
  2929. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2930. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2931. ultrafiltration_rate = value
  2932. }
  2933. //针对
  2934. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2935. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2936. ultrafiltration_rate = ultrafiltration_rate / 1000
  2937. }
  2938. if adminUserInfo.Org.Id == 10551 {
  2939. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2940. ultrafiltration_rate = ultrafiltration_rate / 1000
  2941. }
  2942. if adminUserInfo.Org.Id == 10612 {
  2943. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2944. ultrafiltration_rate = ultrafiltration_rate / 1000
  2945. }
  2946. }
  2947. }
  2948. record := models.MonitoringRecord{
  2949. UserOrgId: adminUserInfo.Org.Id,
  2950. PatientId: patientID,
  2951. DialysisOrderId: dialysisRecord.ID,
  2952. MonitoringDate: schedulestartTime,
  2953. OperateTime: startDate.Unix(),
  2954. // MonitoringTime: recordTime,
  2955. MonitoringNurse: nurseID,
  2956. Dispose: tempdispose,
  2957. UltrafiltrationRate: ultrafiltration_rate,
  2958. UltrafiltrationVolume: 0,
  2959. Status: 1,
  2960. CreatedTime: time.Now().Unix(),
  2961. UpdatedTime: time.Now().Unix(),
  2962. }
  2963. //只针对广慈医院
  2964. 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 {
  2965. // 查询病人是否有透前评估数据
  2966. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2967. //如果有数据就插入
  2968. if errcode == nil {
  2969. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2970. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2971. record.BreathingRate = befor.BreathingRate
  2972. record.PulseFrequency = befor.PulseFrequency
  2973. record.Temperature = befor.Temperature
  2974. }
  2975. }
  2976. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2977. if newdialysisRecord.ID > 0 {
  2978. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2979. record.Temperature = 36.5
  2980. record.ArterialPressure = -100
  2981. record.DialysateTemperature = 36.5
  2982. record.Conductivity = 14
  2983. record.BreathingRate = "20"
  2984. record.VenousPressure = 80
  2985. record.TransmembranePressure = 60
  2986. record.Dispose = catheter_operation
  2987. }
  2988. //针对新化博翔
  2989. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2990. record.BloodOxygenSaturation = "99"
  2991. record.Conductivity = 14
  2992. record.DialysateTemperature = 36.5
  2993. record.BreathingRate = "20"
  2994. }
  2995. //针对兰溪人民医院的需求
  2996. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2997. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2998. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2999. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3000. record.Temperature = befor.Temperature
  3001. record.PulseFrequency = befor.PulseFrequency
  3002. record.BreathingRate = befor.BreathingRate
  3003. }
  3004. //新化博翔
  3005. if adminUserInfo.Org.Id == 10447 {
  3006. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3007. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3008. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3009. record.BreathingRate = befor.BreathingRate
  3010. }
  3011. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3012. record.PulseFrequency = 80
  3013. record.Temperature = 36.5
  3014. }
  3015. //诊断灵山圣康
  3016. if adminUserInfo.Org.Id == 10375 {
  3017. record.Conductivity = 13.8
  3018. record.DialysateTemperature = 37
  3019. record.DialysateFlow = 500
  3020. record.BloodFlowVolume = 200
  3021. record.BreathingRate = "18"
  3022. record.SodiumConcentration = 140
  3023. }
  3024. //江成肾病医院
  3025. if adminUserInfo.Org.Id == 10517 {
  3026. record.SodiumConcentration = 138
  3027. record.DialysateTemperature = 36.5
  3028. }
  3029. err := service.CreateMonitor(&record)
  3030. //记录日志
  3031. byterequest, _ := json.Marshal(record)
  3032. monitorRecordLog := models.XtMonitorRecordLog{
  3033. RecordDate: record.MonitoringDate,
  3034. PatientId: record.PatientId,
  3035. Module: 1,
  3036. AdminUserId: adminUserInfo.AdminUser.Id,
  3037. Ctime: time.Now().Unix(),
  3038. Mtime: 0,
  3039. Status: 1,
  3040. UserOrgId: record.UserOrgId,
  3041. ErrLog: string(byterequest),
  3042. Source: "执行上机时新增监测",
  3043. }
  3044. service.CreateMonitorRecordLog(monitorRecordLog)
  3045. finish := models.XtDialysisFinish{
  3046. IsFinish: 1,
  3047. UserOrgId: adminUserInfo.Org.Id,
  3048. Status: 1,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. Module: 7,
  3052. RecordDate: schedulestartTime,
  3053. Sourse: 1,
  3054. PatientId: patientID,
  3055. }
  3056. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3057. if dialysisFinish.ID == 0 {
  3058. service.CreateDialysisFinish(finish)
  3059. }
  3060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3061. redis := service.RedisClient()
  3062. //清空key 值
  3063. redis.Set(key, "", time.Second)
  3064. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3065. redis.Set(keyOne, "", time.Second)
  3066. defer redis.Close()
  3067. if err != nil {
  3068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3069. return
  3070. }
  3071. }
  3072. go func() {
  3073. ssoDomain := beego.AppConfig.String("call_domain")
  3074. api := ssoDomain + "/index/uppatient"
  3075. values := make(url.Values)
  3076. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3077. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3078. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3079. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3080. http.PostForm(api, values)
  3081. }()
  3082. this.ServeSuccessJSON(map[string]interface{}{
  3083. "dialysis_order": newdialysisRecord,
  3084. "monitor": record,
  3085. })
  3086. return
  3087. }
  3088. func (c *DialysisAPIController) PostSolution() {
  3089. id, _ := c.GetInt64("patient", 0)
  3090. recordDateStr := c.GetString("record_date")
  3091. if id <= 0 {
  3092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3093. return
  3094. }
  3095. adminUserInfo := c.GetMobileAdminUserInfo()
  3096. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3097. if patient.ID == 0 {
  3098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3099. return
  3100. }
  3101. if len(recordDateStr) == 0 {
  3102. recordDateStr = time.Now().Format("2006-01-02")
  3103. }
  3104. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3105. if parseDateErr != nil {
  3106. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3108. return
  3109. }
  3110. mode_id, _ := c.GetInt64("mode_id", 0)
  3111. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3112. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3113. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3114. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3115. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3116. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3117. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3118. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3119. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3120. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3121. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3122. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3123. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3124. kalium, _ := c.GetFloat("kalium", 0)
  3125. sodium, _ := c.GetFloat("sodium", 0)
  3126. calcium, _ := c.GetFloat("calcium", 0)
  3127. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3128. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3129. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3130. glucose, _ := c.GetFloat("glucose", 0)
  3131. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3132. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3133. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3134. conductivity, _ := c.GetFloat("conductivity", 0)
  3135. remark := c.GetString("remark")
  3136. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3137. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3138. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3139. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3140. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3141. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3142. special_medicine_other := c.GetString("special_medicine_other")
  3143. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3144. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3145. blood_access, _ := c.GetInt64("blood_access", 0)
  3146. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3147. body_fluid_other := c.GetString("body_fluid_other")
  3148. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3149. niprocart, _ := c.GetInt64("niprocart", 0)
  3150. jms, _ := c.GetInt64("jms", 0)
  3151. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3152. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3153. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3154. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3155. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3156. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3157. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3158. injector, _ := c.GetInt64("injector", 0)
  3159. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3160. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3161. safe_package, _ := c.GetInt64("package", 0)
  3162. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3163. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3164. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3165. blood := c.GetString("blood")
  3166. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3167. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3168. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3169. displace_speed := c.GetString("displace_speed")
  3170. illness, _ := c.GetInt64("illness")
  3171. amylaceum := c.GetString("amylaceum")
  3172. single_time := c.GetString("single_time")
  3173. single_water := c.GetString("single_water")
  3174. replacement_flow := c.GetString("replacement_flow")
  3175. plasma_separator := c.GetString("plasma_separator")
  3176. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3177. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3178. oxygen_flow := c.GetString("oxygen_flow")
  3179. oxygen_time := c.GetString("oxygen_time")
  3180. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3181. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3182. puncture_needle := c.GetString("puncture_needle")
  3183. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3184. epo := c.GetString("epo")
  3185. epo_count, _ := c.GetFloat("epo_count", 0)
  3186. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3187. pre_impulse := c.GetString("pre_impulse")
  3188. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3189. admin_user_id, _ := c.GetInt64("admin_user_id")
  3190. is_water := c.GetString("is_water")
  3191. add_amount, _ := c.GetFloat("add_amount")
  3192. reduce_amount, _ := c.GetFloat("reduce_amount")
  3193. prescribing_number, _ := c.GetFloat("prescribing_number")
  3194. treatment_remark := c.GetString("treatment_remark")
  3195. prescription_sodium := c.GetString("prescription_sodium")
  3196. start_sodium := c.GetString("start_sodium")
  3197. sodium_curve := c.GetString("sodium_curve")
  3198. var is_war int64
  3199. if is_water == "是" {
  3200. is_war = 1
  3201. }
  3202. if is_water == "否" {
  3203. is_war = 2
  3204. }
  3205. if is_water == "请选择" {
  3206. is_war = 0
  3207. }
  3208. drhy_water := c.GetString("drhy_water")
  3209. dry_water_hour := c.GetString("dry_water_hour")
  3210. water_machine := c.GetString("water_machine")
  3211. dialysis_remark := c.GetString("dialysis_remark")
  3212. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3213. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3214. prescription_water, _ := c.GetFloat("prescription_water")
  3215. dialysis_strainer := c.GetString("dialysis_strainer")
  3216. chaptalization := c.GetString("chaptalization")
  3217. washing_time := c.GetString("washing_time")
  3218. warsh_count := c.GetString("warsh_count")
  3219. blood_access_part_id := c.GetString("blood_access_part_id")
  3220. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3221. dialyzate := c.GetString("dialyzate")
  3222. if mode_id > 0 {
  3223. var str string
  3224. //查找该机构用的是什么透析器
  3225. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3226. if filedConfig.ID > 0 {
  3227. str = dialyzerPerfusionApparatus
  3228. } else {
  3229. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3230. }
  3231. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3232. }
  3233. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3234. //
  3235. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3236. // if appRole.UserType == 3 {
  3237. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3238. // if getPermissionErr != nil {
  3239. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3240. // return
  3241. // } else if headNursePermission == nil {
  3242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3243. // return
  3244. // }
  3245. // }
  3246. //}
  3247. // 查询信息规挡的设置天数
  3248. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3249. if infor.ID > 0 && infor.WeekDay > 0 {
  3250. var cha_time int64
  3251. timeNowStr := time.Now().Format("2006-01-02")
  3252. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3253. //今日的日期减去设置的日期
  3254. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3255. if cha_time >= recordDate.Unix() {
  3256. //查询审核是否允许
  3257. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3258. //申请状态不允许的情况 拒绝修改
  3259. if infor.ApplicationStatus != 1 {
  3260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3261. return
  3262. }
  3263. }
  3264. }
  3265. prescription := models.DialysisPrescription{
  3266. UserOrgId: adminUserInfo.Org.Id,
  3267. PatientId: id,
  3268. RecordDate: recordDate.Unix(),
  3269. ModeId: mode_id,
  3270. DialysisDuration: dialysis_duration,
  3271. Dialyzer: dialyzer,
  3272. PerfusionApparatus: perfusion_apparatus,
  3273. BloodFlowVolume: blood_flow_volume,
  3274. DewaterAmount: dewater_amount,
  3275. DisplaceLiqui: displace_liqui,
  3276. ReplacementWay: replacement_way,
  3277. Anticoagulant: anticoagulant,
  3278. AnticoagulantShouji: anticoagulant_shouji,
  3279. AnticoagulantWeichi: anticoagulant_weichi,
  3280. AnticoagulantZongliang: anticoagulant_zongliang,
  3281. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3282. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3283. Kalium: kalium,
  3284. Sodium: sodium,
  3285. Calcium: calcium,
  3286. Bicarbonate: bicarbonate,
  3287. Glucose: glucose,
  3288. // DryWeight: dry_weight,
  3289. DialysateFlow: dialysate_flow,
  3290. DialysateTemperature: dialysate_temperature,
  3291. Conductivity: conductivity,
  3292. Remark: remark,
  3293. Status: 1,
  3294. CreatedTime: time.Now().Unix(),
  3295. UpdatedTime: time.Now().Unix(),
  3296. DialysisDurationMinute: dialysisDurationMinute,
  3297. DialysisDurationHour: dialysisDurationHour,
  3298. TargetUltrafiltration: targetUltrafiltration,
  3299. DialysateFormulation: dialysateFormulation,
  3300. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3301. BodyFluid: body_fluid,
  3302. SpecialMedicine: special_medicine,
  3303. SpecialMedicineOther: special_medicine_other,
  3304. DisplaceLiquiPart: displace_liqui_part,
  3305. DisplaceLiquiValue: displace_liqui_value,
  3306. BloodAccess: blood_access,
  3307. Ultrafiltration: ultrafiltration,
  3308. BodyFluidOther: body_fluid_other,
  3309. ReplacementTotal: replacement_total,
  3310. Niprocart: niprocart,
  3311. Jms: jms,
  3312. FistulaNeedleSet: fistula_needle_set,
  3313. FistulaNeedleSet16: fistula_needle_set_16,
  3314. Hemoperfusion: hemoperfusion,
  3315. DialyserSterilised: dialyser_sterilised,
  3316. Filtryzer: filtryzer,
  3317. TargetKtv: target_ktv,
  3318. Dialyzers: dialyzers,
  3319. Injector: injector,
  3320. Bloodlines: bloodlines,
  3321. TubingHemodialysis: tubing_hemodialysis,
  3322. Package: safe_package,
  3323. ALiquid: a_liquid,
  3324. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3325. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3326. Blood: blood,
  3327. DialysisDialyszers: dialysis_dialyszers,
  3328. DialysisIrrigation: dialysis_irrigation,
  3329. AntioxidantCommodityName: antioxidant_commodity_name,
  3330. DisplaceSpeed: displace_speed,
  3331. Illness: illness,
  3332. Amylaceum: amylaceum,
  3333. SingleWater: single_water,
  3334. SingleTime: single_time,
  3335. ReplacementFlow: replacement_flow,
  3336. PlasmaSeparator: plasma_separator,
  3337. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3338. OxygenUptake: oxygen_uptake,
  3339. OxygenTime: oxygen_time,
  3340. OxygenFlow: oxygen_flow,
  3341. HemodialysisPipelines: hemodialysis_pipelines,
  3342. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3343. PunctureNeedle: puncture_needle,
  3344. PunctureNeedleCount: puncture_needle_count,
  3345. Epo: epo,
  3346. EpoCount: epo_count,
  3347. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3348. PreImpulse: impulse,
  3349. AdminUserId: admin_user_id,
  3350. IsWater: is_war,
  3351. DrhyWater: drhy_water,
  3352. DryWaterHour: dry_water_hour,
  3353. WaterMachine: water_machine,
  3354. AddAmount: add_amount,
  3355. ReduceAmount: reduce_amount,
  3356. DialysisRemark: dialysis_remark,
  3357. PrescribingNumber: prescribing_number,
  3358. PrescriptionSodium: prescription_sodium,
  3359. StartSodium: start_sodium,
  3360. SodiumCurve: sodium_curve,
  3361. TreatmentRemark: treatment_remark,
  3362. DialysisFluidFlow: dialysis_fluid_flow,
  3363. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3364. PrescriptionWater: prescription_water,
  3365. DialysisStrainer: dialysis_strainer,
  3366. Chaptalization: chaptalization,
  3367. WashingTime: washing_time,
  3368. WarshCount: warsh_count,
  3369. BloodAccessPartId: blood_access_part_id,
  3370. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3371. Dialyzate: dialyzate,
  3372. }
  3373. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3374. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3375. //
  3376. if appRole.UserType == 2 || appRole.UserType == 1 {
  3377. prescription_doctor = adminUserInfo.AdminUser.Id
  3378. prescription.PrescriptionDoctor = prescription_doctor
  3379. }
  3380. if dialysisPrescription.ID == 0 { //新增
  3381. prescription.Creater = adminUserInfo.AdminUser.Id
  3382. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3383. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3384. }
  3385. } else { //修改
  3386. if dialysisPrescription.Creater == 0 {
  3387. prescription.Creater = adminUserInfo.AdminUser.Id
  3388. } else {
  3389. prescription.Creater = dialysisPrescription.Creater
  3390. if adminUserInfo.Org.Id == 9882 {
  3391. if appRole.UserType == 2 || appRole.UserType == 1 {
  3392. prescription.Creater = adminUserInfo.AdminUser.Id
  3393. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3394. }
  3395. }
  3396. }
  3397. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3398. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3399. }
  3400. //if/**/
  3401. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3402. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3403. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3404. // if getPermissionErr != nil {
  3405. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3406. // return
  3407. // } else if headNursePermission == nil {
  3408. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3409. // return
  3410. // }
  3411. //}
  3412. //prescription.Creater = dialysisPrescription.Creater
  3413. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3414. prescription.Modifier = adminUserInfo.AdminUser.Id
  3415. prescription.ID = dialysisPrescription.ID
  3416. }
  3417. solution := models.DialysisSolution{
  3418. RegistrarsId: adminUserInfo.AdminUser.Id,
  3419. UserOrgId: adminUserInfo.Org.Id,
  3420. Doctor: prescription_doctor,
  3421. PatientId: id,
  3422. ModeId: mode_id,
  3423. DialysisDuration: dialysis_duration,
  3424. PerfusionApparatus: perfusion_apparatus,
  3425. BloodFlowVolume: blood_flow_volume,
  3426. Dewater: dewater_amount,
  3427. DisplaceLiqui: displace_liqui,
  3428. ReplacementWay: replacement_way,
  3429. Anticoagulant: anticoagulant,
  3430. AnticoagulantShouji: anticoagulant_shouji,
  3431. AnticoagulantWeichi: anticoagulant_weichi,
  3432. AnticoagulantZongliang: anticoagulant_zongliang,
  3433. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3434. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3435. Kalium: kalium,
  3436. Sodium: sodium,
  3437. Calcium: calcium,
  3438. Bicarbonate: bicarbonate,
  3439. Glucose: glucose,
  3440. // DryWeight: dry_weight,
  3441. DialysateFlow: dialysate_flow,
  3442. DialysateTemperature: dialysate_temperature,
  3443. Conductivity: conductivity,
  3444. Remark: remark,
  3445. Status: 1,
  3446. CreatedTime: time.Now().Unix(),
  3447. UpdatedTime: time.Now().Unix(),
  3448. DialysisDurationMinute: dialysisDurationMinute,
  3449. DialysisDurationHour: dialysisDurationHour,
  3450. TargetUltrafiltration: targetUltrafiltration,
  3451. DialysateFormulation: dialysateFormulation,
  3452. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3453. BodyFluid: body_fluid,
  3454. SpecialMedicine: special_medicine,
  3455. SpecialMedicineOther: special_medicine_other,
  3456. DisplaceLiquiPart: displace_liqui_part,
  3457. DisplaceLiquiValue: displace_liqui_value,
  3458. BloodAccess: blood_access,
  3459. Ultrafiltration: ultrafiltration,
  3460. BodyFluidOther: body_fluid_other,
  3461. ReplacementTotal: replacement_total,
  3462. TargetKtv: target_ktv,
  3463. DialysisDialyszers: dialysis_dialyszers,
  3464. DialysisIrrigation: dialysis_irrigation,
  3465. HemodialysisPipelines: hemodialysis_pipelines,
  3466. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3467. PunctureNeedle: puncture_needle,
  3468. PunctureNeedleCount: puncture_needle_count,
  3469. Epo: epo,
  3470. EpoCount: epo_count,
  3471. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3472. PreImpulse: impulse,
  3473. SolutionStatus: 1,
  3474. DialysisRemark: dialysis_remark,
  3475. PrescribingNumber: prescribing_number,
  3476. PrescriptionSodium: prescription_sodium,
  3477. StartSodium: start_sodium,
  3478. SodiumCurve: sodium_curve,
  3479. TreatmentRemark: treatment_remark,
  3480. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3481. DialysisFluidFlow: dialysis_fluid_flow,
  3482. PrescriptionWater: prescription_water,
  3483. DialysisStrainer: dialysis_strainer,
  3484. Chaptalization: chaptalization,
  3485. WashingTime: washing_time,
  3486. WarshCount: warsh_count,
  3487. BloodAccessPartId: blood_access_part_id,
  3488. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3489. Dialyzate: dialyzate,
  3490. }
  3491. //针对河间咸的
  3492. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3493. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3494. solution.DisplaceLiquiPart = 0
  3495. solution.DisplaceLiquiValue = 0
  3496. }
  3497. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3498. prescription.DisplaceLiquiPart = 0
  3499. prescription.DisplaceLiquiValue = 0
  3500. }
  3501. }
  3502. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3503. if solution.PrescribingNumber == 0 {
  3504. solution.PrescribingNumber = 1
  3505. }
  3506. if prescription.PrescribingNumber == 0 {
  3507. prescription.PrescribingNumber = 1
  3508. }
  3509. if solution.PrescribingNumber == 0 && id == 14682 {
  3510. solution.PrescribingNumber = 2
  3511. }
  3512. if solution.PrescribingNumber == 0 && id == 18560 {
  3513. solution.PrescribingNumber = 2
  3514. }
  3515. if prescription.PrescribingNumber == 0 && id == 14682 {
  3516. prescription.PrescribingNumber = 2
  3517. }
  3518. if prescription.PrescribingNumber == 0 && id == 18560 {
  3519. prescription.PrescribingNumber = 2
  3520. }
  3521. }
  3522. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3523. //记录日志
  3524. byterequest, _ := json.Marshal(prescription)
  3525. prescriptionLog := models.XtDialysisPrescriptionLog{
  3526. UserOrgId: prescription.UserOrgId,
  3527. Ctime: time.Now().Unix(),
  3528. Mtime: 0,
  3529. ErrLog: string(byterequest),
  3530. AdminUserId: adminUserInfo.AdminUser.Id,
  3531. RecordDate: prescription.RecordDate,
  3532. PatientId: prescription.PatientId,
  3533. Source: "手机端新增长期处方",
  3534. Status: 1,
  3535. }
  3536. service.CreatePrescriptionLog(prescriptionLog)
  3537. finish := models.XtDialysisFinish{
  3538. IsFinish: 1,
  3539. UserOrgId: adminUserInfo.Org.Id,
  3540. Status: 1,
  3541. Ctime: time.Now().Unix(),
  3542. Mtime: 0,
  3543. Module: 1,
  3544. RecordDate: recordDate.Unix(),
  3545. Sourse: 1,
  3546. PatientId: id,
  3547. }
  3548. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3549. if dialysisFinish.ID == 0 {
  3550. service.CreateDialysisFinish(finish)
  3551. }
  3552. //获取最新1条
  3553. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3554. //更新状态
  3555. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3556. //长沙南雅医院,自动生成抗凝剂的临时处方
  3557. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3558. if prescribing_number == 0 {
  3559. prescribing_number = 1
  3560. }
  3561. advice := models.DoctorAdvice{
  3562. UserOrgId: adminUserInfo.Org.Id,
  3563. PatientId: id,
  3564. GroupNo: 0,
  3565. AdviceType: 2,
  3566. RecordDate: recordDate.Unix(),
  3567. AdviceDate: recordDate.Unix(),
  3568. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3569. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3570. AdviceDesc: "",
  3571. ReminderDate: 0,
  3572. SingleDose: prescription.AnticoagulantZongliang,
  3573. SingleDoseUnit: "iu",
  3574. DrugSpec: 0,
  3575. DrugSpecUnit: "",
  3576. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3577. PrescribingNumberUnit: "支",
  3578. DeliveryWay: "静脉注射",
  3579. ExecutionFrequency: "上机前",
  3580. AdviceDoctor: 0,
  3581. Status: 1,
  3582. CreatedTime: time.Now().Unix(),
  3583. UpdatedTime: time.Now().Unix(),
  3584. IsPrescription: 1,
  3585. ExecutionState: 2,
  3586. StopState: 2,
  3587. IsSettle: 2,
  3588. }
  3589. // 查询排班信息
  3590. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3591. if schedulePatient.ID > 0 {
  3592. if schedulePatient.ScheduleType == 1 {
  3593. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3594. }
  3595. if schedulePatient.ScheduleType == 2 {
  3596. advice.StartTime = recordDate.Unix() + 10*60*60
  3597. }
  3598. }
  3599. // 抗凝剂名称
  3600. switch anticoagulant {
  3601. case 1:
  3602. advice.AdviceName = "无肝素"
  3603. break
  3604. case 2:
  3605. advice.AdviceName = "普通肝素"
  3606. break
  3607. case 3:
  3608. advice.AdviceName = "低分子肝素"
  3609. break
  3610. case 4:
  3611. advice.AdviceName = "阿加曲班"
  3612. break
  3613. case 5:
  3614. advice.AdviceName = "枸橼酸钠"
  3615. break
  3616. case 6:
  3617. advice.AdviceName = "低分子肝素钙"
  3618. break
  3619. case 7:
  3620. advice.AdviceName = "低分子肝素钠"
  3621. break
  3622. case 8:
  3623. advice.AdviceName = "依诺肝素"
  3624. break
  3625. case 9:
  3626. advice.AdviceName = "达肝素"
  3627. break
  3628. case 10:
  3629. advice.AdviceName = "体外抗凝"
  3630. break
  3631. case 11:
  3632. advice.AdviceName = "那曲肝素"
  3633. break
  3634. case 12:
  3635. advice.AdviceName = "无抗凝剂"
  3636. break
  3637. }
  3638. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3639. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3640. advice.AdviceDoctor = appRole.AdminUserId
  3641. }
  3642. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3643. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3644. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3645. advice.AdviceName = "低分子肝素钠注射液"
  3646. // 修改患者临时医嘱里的抗凝剂医嘱
  3647. advice.ID = advicePrescription.ID
  3648. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3649. } else {
  3650. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3651. advice.AdviceName = "低分子肝素钠注射液"
  3652. service.CreateDoctorAdvice(&advice)
  3653. }
  3654. }
  3655. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3656. redis := service.RedisClient()
  3657. defer redis.Close()
  3658. //清空key 值
  3659. redis.Set(key, "", time.Second)
  3660. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3661. redis.Set(keyOne, "", time.Second)
  3662. }
  3663. //获取key,清空redis
  3664. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3665. redis := service.RedisClient()
  3666. defer redis.Close()
  3667. //清空key 值
  3668. redis.Set(key, "", time.Second)
  3669. //清空长期医嘱的key
  3670. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3671. redis.Set(soulution_key, "", time.Second)
  3672. //查询最近透析准备表里是否存在 透析器 灌流器
  3673. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3674. redis.Set(keyOne, "", time.Second)
  3675. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3676. redis.Set(keyTwo, "", time.Second)
  3677. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3678. redis.Set(keyThree, "", time.Second)
  3679. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3680. redis.Set(keyFour, "", time.Second)
  3681. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3682. //
  3683. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3684. //
  3685. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3686. //if len(mation)>0{
  3687. // for _, item := range splitStr {
  3688. // for _,it := range mation{
  3689. // if(item == it.SpecificationName){
  3690. //
  3691. // //查询最近一次的透析器
  3692. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3693. //
  3694. // if errcode == gorm.ErrRecordNotFound{
  3695. // //插入数据
  3696. // prepare := models.DialysisBeforePrepare{
  3697. // UserOrgId: adminUserInfo.Org.Id,
  3698. // PatientId: id,
  3699. // RecordDate: recordDate.Unix(),
  3700. // GoodTypeId: it.GoodTypeId,
  3701. // GoodId: it.ID,
  3702. // Count: 1,
  3703. // Ctime: time.Now().Unix(),
  3704. // Creater: adminUserInfo.AdminUser.Id,
  3705. // Status:1,
  3706. //
  3707. // }
  3708. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3709. // fmt.Println("",errcode)
  3710. // }
  3711. // }
  3712. // }
  3713. //
  3714. // }
  3715. //
  3716. // for _, item := range splitIrrigation {
  3717. // for _,it := range mation{
  3718. // if(item == it.SpecificationName){
  3719. // //查询最近一次的透析器
  3720. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3721. // if errcode == gorm.ErrRecordNotFound{
  3722. // //插入数据
  3723. // prepare := models.DialysisBeforePrepare{
  3724. // UserOrgId: adminUserInfo.Org.Id,
  3725. // PatientId: id,
  3726. // RecordDate: recordDate.Unix(),
  3727. // GoodTypeId: it.GoodTypeId,
  3728. // GoodId: it.ID,
  3729. // Count: 1,
  3730. // Ctime: time.Now().Unix(),
  3731. // Creater: adminUserInfo.AdminUser.Id,
  3732. // Status:1,
  3733. //
  3734. // }
  3735. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3736. // fmt.Println(errcode)
  3737. // }
  3738. // }
  3739. // }
  3740. // }
  3741. //}
  3742. c.ServeSuccessJSON(map[string]interface{}{
  3743. "solution": &solution,
  3744. "prescription": &prescription,
  3745. })
  3746. }
  3747. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3748. patient, _ := c.GetInt64("patient", 0)
  3749. adminUserInfo := c.GetMobileAdminUserInfo()
  3750. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3751. c.ServeSuccessJSON(map[string]interface{}{
  3752. "receiveTreatmentAsses": receiveTreatmentAsses,
  3753. })
  3754. }
  3755. func (this *DialysisAPIController) PostSignInfo() {
  3756. patientID, _ := this.GetInt64("patient_id")
  3757. recordDateStr := this.GetString("date")
  3758. if patientID <= 0 {
  3759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3760. return
  3761. }
  3762. if len(recordDateStr) == 0 {
  3763. recordDateStr = time.Now().Format("2006-01-02")
  3764. }
  3765. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3766. if parseDateErr != nil {
  3767. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3769. return
  3770. }
  3771. adminInfo := this.GetMobileAdminUserInfo()
  3772. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3773. if err != nil {
  3774. this.ErrorLog("签名失败:%v", err)
  3775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3776. return
  3777. }
  3778. this.ServeSuccessJSON(map[string]interface{}{
  3779. "doctor_id": adminInfo.AdminUser.Id,
  3780. })
  3781. }
  3782. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3783. patientID, _ := this.GetInt64("patient_id")
  3784. adminInfo := this.GetMobileAdminUserInfo()
  3785. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3786. this.ServeSuccessJSON(map[string]interface{}{
  3787. "monitor": record,
  3788. })
  3789. }
  3790. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3791. thisTime := time.Now()
  3792. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3793. timeLayout := "2006-01-02 15:04:05"
  3794. loc, _ := time.LoadLocation("Local")
  3795. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3796. theAssessmentDateTime := theStartTime.Unix()
  3797. patientID, _ := this.GetInt64("patient_id")
  3798. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3799. adminInfo := this.GetMobileAdminUserInfo()
  3800. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3801. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3802. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3803. var ultrafiltration_rate float64
  3804. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3805. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3806. fmt.Println(evaluation)
  3807. fmt.Println("prescription.ID", prescription.ID)
  3808. if prescription.ID > 0 {
  3809. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3810. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3811. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3812. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3813. record.UltrafiltrationRate = ultrafiltration_rate
  3814. }
  3815. if adminInfo.Org.Id == 10597 {
  3816. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3817. record.UltrafiltrationRate = ultrafiltration_rate
  3818. }
  3819. if adminInfo.Org.Id == 10510 {
  3820. record.UltrafiltrationRate = 0
  3821. }
  3822. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3823. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3824. record.UltrafiltrationRate = ultrafiltration_rate
  3825. }
  3826. if template.TemplateId == 20 || template.TemplateId == 22 {
  3827. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3828. record.UltrafiltrationRate = ultrafiltration_rate
  3829. }
  3830. // 只针对方济医院
  3831. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3832. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3833. ultrafiltration_rate = value
  3834. record.UltrafiltrationRate = ultrafiltration_rate
  3835. }
  3836. if template.TemplateId == 41 || template.TemplateId == 47 {
  3837. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3838. record.UltrafiltrationRate = ultrafiltration_rate
  3839. }
  3840. if template.TemplateId == 43 {
  3841. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3842. record.UltrafiltrationRate = ultrafiltration_rate
  3843. }
  3844. if template.TemplateId == 46 || template.TemplateId == 54 {
  3845. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3846. record.UltrafiltrationRate = ultrafiltration_rate
  3847. }
  3848. 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 {
  3849. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3850. record.UltrafiltrationRate = ultrafiltration_rate
  3851. }
  3852. if adminInfo.Org.Id == 10469 {
  3853. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3854. record.UltrafiltrationRate = ultrafiltration_rate
  3855. }
  3856. if adminInfo.Org.Id == 10471 {
  3857. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3858. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3859. }
  3860. if adminInfo.Org.Id == 10460 {
  3861. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3862. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3863. }
  3864. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 {
  3865. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3866. fmt.Println("金阿迪发到付阿道夫", ultrafiltration_rate)
  3867. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3868. }
  3869. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 {
  3870. record.UltrafiltrationRate = 0
  3871. }
  3872. //if template.TemplateId == 47 {
  3873. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3874. // record.UltrafiltrationRate = ultrafiltration_rate
  3875. //}
  3876. }
  3877. }
  3878. // record.UltrafiltrationRate = ultrafiltration_rate
  3879. record.UltrafiltrationVolume = 0
  3880. 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
  3881. if ultrafiltration_rate > 0 {
  3882. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3883. record.UltrafiltrationVolume = value
  3884. }
  3885. }
  3886. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  3887. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3888. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3889. record.UltrafiltrationVolume = ultrafiltration_volume
  3890. }
  3891. }
  3892. if adminInfo.Org.Id == 10597 {
  3893. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3894. record.UltrafiltrationVolume = ultrafiltration_volume
  3895. }
  3896. //长沙南雅
  3897. 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 {
  3898. if ultrafiltration_rate > 0 {
  3899. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3900. record.UltrafiltrationVolume = ultrafiltration_volume
  3901. }
  3902. }
  3903. if adminInfo.Org.Id == 10471 {
  3904. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3905. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3906. }
  3907. if adminInfo.Org.Id == 10460 {
  3908. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3909. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3910. }
  3911. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 {
  3912. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3913. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3914. }
  3915. //长沙南雅累计血容量自动计算
  3916. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3917. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3918. //}
  3919. if template.TemplateId == 47 || template.TemplateId == 54 {
  3920. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3921. }
  3922. if adminInfo.Org.Id == 10510 {
  3923. record.UltrafiltrationVolume = 0
  3924. }
  3925. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  3926. this.ServeSuccessJSON(map[string]interface{}{
  3927. "monitor": record,
  3928. "lastMonitorRecordList": lastMonitorRecordList,
  3929. })
  3930. }
  3931. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3932. record_id, _ := this.GetInt64("id")
  3933. nurseID, _ := this.GetInt64("start_nurse")
  3934. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3935. bedID, _ := this.GetInt64("bed")
  3936. start_time := this.GetString("start_time")
  3937. schedual_type, _ := this.GetInt64("schedual_type")
  3938. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3939. change_nurse, _ := this.GetInt64("change_nurse")
  3940. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3941. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3942. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3943. fmt.Println("quality_nurse_id", quality_nurse_id)
  3944. patient_id, _ := this.GetInt64("patient_id")
  3945. record_date, _ := this.GetInt64("record_date")
  3946. puncture_needle := this.GetString("puncture_needle")
  3947. puncture_way := this.GetString("puncture_way")
  3948. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3949. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3950. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3951. nuclein_date_str := this.GetString("nuclein_date_str")
  3952. order_remark := this.GetString("order_remark")
  3953. schedule_remark := this.GetString("schedule_remark")
  3954. catheter_operation := this.GetString("catheter_operation")
  3955. blood_flow_volume := this.GetString("blood_flow_volume")
  3956. if record_id == 0 {
  3957. this.ErrorLog("id:%v", record_id)
  3958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3959. return
  3960. }
  3961. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3962. if parseStartDateErr != nil {
  3963. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3965. return
  3966. }
  3967. adminUserInfo := this.GetMobileAdminUserInfo()
  3968. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3969. if getNurseErr != nil {
  3970. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3972. return
  3973. } else if nurse == nil {
  3974. this.ErrorLog("护士不存在")
  3975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3976. return
  3977. }
  3978. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3979. //if getNurseErr != nil {
  3980. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3981. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3982. // return
  3983. //} else if nurse == nil {
  3984. // this.ErrorLog("护士不存在")
  3985. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3986. // return
  3987. //}
  3988. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3989. if getDeviceNumberErr != nil {
  3990. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3992. return
  3993. } else if deviceNumber == nil {
  3994. this.ErrorLog("床位号不存在")
  3995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3996. return
  3997. }
  3998. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  3999. //
  4000. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4001. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4002. // if getPermissionErr != nil {
  4003. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4004. // return
  4005. // } else if headNursePermission == nil {
  4006. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4007. // return
  4008. // }
  4009. //}
  4010. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4011. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4012. timeLayout := "2006-01-02 15:04:05"
  4013. loc, _ := time.LoadLocation("Local")
  4014. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4015. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4016. schedulestartTime := theStartTime.Unix()
  4017. scheduleendTime := theEndTime.Unix()
  4018. var theNucleinDate int64
  4019. timeLayoutOne := "2006-01-02"
  4020. if len(nuclein_date_str) > 0 {
  4021. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4022. if err != nil {
  4023. utils.ErrorLog(err.Error())
  4024. }
  4025. theNucleinDate = theTime.Unix()
  4026. }
  4027. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4028. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4029. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4030. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4031. if err == gorm.ErrRecordNotFound { //空床位
  4032. // 修改了床位逻辑
  4033. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4034. if daySchedule.ID > 0 {
  4035. //daySchedule.BedId = bedID
  4036. //daySchedule.PartitionId = deviceNumber.ZoneID
  4037. //daySchedule.ScheduleType = schedual_type
  4038. //daySchedule.UpdatedTime = time.Now().Unix()
  4039. //err := service.UpdateSchedule(&daySchedule)
  4040. xtSchedule := models.Schedule{
  4041. PartitionId: deviceNumber.ZoneID,
  4042. BedId: bedID,
  4043. ScheduleType: schedual_type,
  4044. UpdatedTime: time.Now().Unix(),
  4045. }
  4046. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4047. if err != nil {
  4048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4049. return
  4050. }
  4051. }
  4052. } else if err == nil {
  4053. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4054. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4055. if daySchedule.ID > 0 {
  4056. //daySchedule.BedId = bedID
  4057. //daySchedule.PartitionId = deviceNumber.ZoneID
  4058. //
  4059. //daySchedule.ScheduleType = schedual_type
  4060. //daySchedule.UpdatedTime = time.Now().Unix()
  4061. //err := service.UpdateSchedule(&daySchedule)
  4062. xtSchedule := models.Schedule{
  4063. PartitionId: deviceNumber.ZoneID,
  4064. BedId: bedID,
  4065. ScheduleType: schedual_type,
  4066. UpdatedTime: time.Now().Unix(),
  4067. }
  4068. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4069. if err != nil {
  4070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4071. return
  4072. }
  4073. }
  4074. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4076. return
  4077. }
  4078. } else if err != nil {
  4079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4080. return
  4081. }
  4082. }
  4083. dialysisRecord := &models.DialysisOrder{
  4084. ID: record_id,
  4085. UserOrgId: adminUserInfo.Org.Id,
  4086. BedID: bedID,
  4087. StartNurse: nurseID,
  4088. StartTime: startDate.Unix(),
  4089. PunctureNurse: puncture_nurse,
  4090. Creator: adminUserInfo.AdminUser.Id,
  4091. Modifier: adminUserInfo.AdminUser.Id,
  4092. WashpipeNurse: washpipe_nurse,
  4093. SchedualType: schedual_type,
  4094. ChangeNurse: change_nurse,
  4095. DifficultPunctureNurse: difficult_puncture_nurse,
  4096. NewFistulaNurse: new_fistula_nurse,
  4097. QualityNurseId: quality_nurse_id,
  4098. PunctureNeedle: puncture_needle,
  4099. PunctureWay: puncture_way,
  4100. DialysisDialyszers: dialysis_dialyszers,
  4101. DialysisIrrigation: dialysis_irrigation,
  4102. BloodAccessId: blood_access_id,
  4103. NucleinDate: theNucleinDate,
  4104. OrderRemark: order_remark,
  4105. ScheduleRemark: schedule_remark,
  4106. CatheterOperation: catheter_operation,
  4107. BloodFlowVolume: blood_flow_volume,
  4108. }
  4109. //修改床位号需要重新消毒
  4110. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4111. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4112. //查询第一条监测
  4113. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4114. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4115. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4116. redis := service.RedisClient()
  4117. //清空key 值
  4118. redis.Set(key, "", time.Second)
  4119. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4120. redis.Set(keyOne, "", time.Second)
  4121. defer redis.Close()
  4122. }
  4123. // 查询信息规挡的设置天数
  4124. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4125. if infor.ID > 0 && infor.WeekDay > 0 {
  4126. var cha_time int64
  4127. timeNowStr := time.Now().Format("2006-01-02")
  4128. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4129. //今日的日期减去设置的日期
  4130. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4131. if cha_time >= record_date {
  4132. //查询审核是否允许
  4133. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4134. //申请状态不允许的情况 拒绝修改
  4135. if infor.ApplicationStatus != 1 {
  4136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4137. return
  4138. }
  4139. }
  4140. }
  4141. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4142. order, _ := service.GetLastPatientOrder(record_id)
  4143. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4144. redis := service.RedisClient()
  4145. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4146. redis.Set(key, "", time.Second)
  4147. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4148. //清空key 值
  4149. redis.Set(keyOne, "", time.Second)
  4150. scheduleDateStartOne := startDate.Format("2006-01-02")
  4151. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4152. redis.Set(keyTwo, "", time.Second)
  4153. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4154. redis.Set(keyThree, "", time.Second)
  4155. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4156. redis.Set(keyFour, "", time.Second)
  4157. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4158. redis.Set(keyFive, "", time.Second)
  4159. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4160. redis.Set(keySix, "", time.Second)
  4161. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4162. redis.Set(keySeven, "", time.Second)
  4163. if updateErr != nil {
  4164. this.ErrorLog("修改上机失败:%v", updateErr)
  4165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4166. return
  4167. }
  4168. if updateErr == nil {
  4169. if tempDialysisRecord.Stage == 2 {
  4170. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4171. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4172. fmt.Println(value)
  4173. a, b := math.Modf(value)
  4174. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4175. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4176. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4177. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4178. redis := service.RedisClient()
  4179. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4180. redis.Set(key, "", time.Second)
  4181. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4182. redis.Set(keyOne, "", time.Second)
  4183. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4184. //清空key 值
  4185. redis.Set(keySix, "", time.Second)
  4186. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4187. redis.Set(keySeven, "", time.Second)
  4188. redis.Close()
  4189. if updateAssessmentErr != nil {
  4190. utils.ErrorLog("%v", updateAssessmentErr)
  4191. }
  4192. }
  4193. }
  4194. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4195. this.ServeSuccessJSON(map[string]interface{}{
  4196. "dialysis_order": dialysisRecords,
  4197. })
  4198. }
  4199. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4200. record_id, _ := c.GetInt64("id")
  4201. nurseID, _ := c.GetInt64("nurse")
  4202. end_time := c.GetString("end_time")
  4203. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4204. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4205. catheter := c.GetString("catheter")
  4206. cruor := c.GetString("cruor")
  4207. mission := c.GetString("mission")
  4208. condenser := c.GetString("condenser")
  4209. if record_id <= 0 || nurseID <= 0 {
  4210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4211. return
  4212. }
  4213. adminUserInfo := c.GetMobileAdminUserInfo()
  4214. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4215. if getNurseErr != nil {
  4216. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4218. return
  4219. } else if nurse == nil {
  4220. c.ErrorLog("护士不存在")
  4221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4222. return
  4223. }
  4224. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4225. if parseEndDateErr != nil {
  4226. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4228. return
  4229. }
  4230. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4231. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4232. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4233. // if getPermissionErr != nil {
  4234. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4235. // return
  4236. // } else if headNursePermission == nil {
  4237. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4238. // return
  4239. // }
  4240. //}
  4241. // 查询信息规挡的设置天数
  4242. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4243. if infor.ID > 0 {
  4244. var cha_time int64
  4245. timeNowStr := time.Now().Format("2006-01-02")
  4246. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4247. //今日的日期减去设置的日期
  4248. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4249. if cha_time >= tempDialysisRecords.DialysisDate {
  4250. //查询审核是否允许
  4251. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4252. //申请状态不允许的情况 拒绝修改
  4253. if infor.ApplicationStatus != 1 {
  4254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4255. return
  4256. }
  4257. }
  4258. }
  4259. dialysisRecord := &models.DialysisOrder{
  4260. ID: record_id,
  4261. UserOrgId: adminUserInfo.Org.Id,
  4262. EndTime: endDate.Unix(),
  4263. FinishNurse: nurseID,
  4264. FinishModifier: adminUserInfo.AdminUser.Id,
  4265. PuncturePointHaematoma: puncture_point_haematoma,
  4266. BloodAccessInternalFistula: blood_access_internal_fistula,
  4267. Catheter: catheter,
  4268. Cruor: cruor,
  4269. Mission: mission,
  4270. Condenser: condenser,
  4271. }
  4272. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4273. redis := service.RedisClient()
  4274. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4275. //清空key 值
  4276. redis.Set(key, "", time.Second)
  4277. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4278. //清空key 值
  4279. redis.Set(keyOne, "", time.Second)
  4280. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4281. redis.Set(keySeven, "", time.Second)
  4282. redis.Close()
  4283. if updateErr != nil {
  4284. c.ErrorLog("修改下机失败:%v", updateErr)
  4285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4286. return
  4287. }
  4288. if updateErr == nil {
  4289. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4290. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4291. a, b := math.Modf(value)
  4292. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4293. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4294. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4295. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4296. redis := service.RedisClient()
  4297. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4298. redis.Set(keyTen, "", time.Second)
  4299. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4300. redis.Set(keyTwo, "", time.Second)
  4301. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4302. redis.Set(key, "", time.Second)
  4303. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4304. redis.Set(keyThree, "", time.Second)
  4305. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4306. redis.Set(keySeven, "", time.Second)
  4307. defer redis.Close()
  4308. if updateAssessmentErr != nil {
  4309. utils.ErrorLog("%v", updateAssessmentErr)
  4310. }
  4311. }
  4312. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4313. c.ServeSuccessJSON(map[string]interface{}{
  4314. "dialysis_order": dialysisRecords,
  4315. })
  4316. }
  4317. func (c *DialysisAPIController) GetLongAdvice() {
  4318. patient_id, _ := c.GetInt64("id")
  4319. adminUserInfo := c.GetMobileAdminUserInfo()
  4320. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4321. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4322. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4323. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4324. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4325. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4326. c.ServeSuccessJSON(map[string]interface{}{
  4327. "status": "1",
  4328. })
  4329. return
  4330. } else { //开启推送提醒
  4331. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4332. var advice_three []*models.DoctorAdvice
  4333. recordDateStr := time.Now().Format("2006-01-02")
  4334. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4335. nowtime := recordDate.Unix()
  4336. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4337. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4338. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4339. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4340. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4341. for _, advice := range advices {
  4342. if advice.FrequencyType == 3 {
  4343. t := time.Now()
  4344. week := int(t.Weekday())
  4345. fmt.Println(t.Weekday())
  4346. fmt.Println(week)
  4347. switch week {
  4348. case 1:
  4349. if strings.Index(advice.WeekDay, "周一") == -1 {
  4350. advice_three = append(advice_three, advice)
  4351. }
  4352. break
  4353. case 2:
  4354. if strings.Index(advice.WeekDay, "周二") == -1 {
  4355. advice_three = append(advice_three, advice)
  4356. }
  4357. break
  4358. case 3:
  4359. if strings.Index(advice.WeekDay, "周三") == -1 {
  4360. advice_three = append(advice_three, advice)
  4361. }
  4362. break
  4363. case 4:
  4364. if strings.Index(advice.WeekDay, "周四") == -1 {
  4365. advice_three = append(advice_three, advice)
  4366. }
  4367. break
  4368. case 5:
  4369. if strings.Index(advice.WeekDay, "周五") == -1 {
  4370. advice_three = append(advice_three, advice)
  4371. }
  4372. break
  4373. case 6:
  4374. if strings.Index(advice.WeekDay, "周六") == -1 {
  4375. advice_three = append(advice_three, advice)
  4376. }
  4377. break
  4378. case 0:
  4379. if strings.Index(advice.WeekDay, "周日") == -1 {
  4380. advice_three = append(advice_three, advice)
  4381. }
  4382. break
  4383. }
  4384. }
  4385. }
  4386. for _, advice := range advices_two {
  4387. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4388. now := p.Unix()
  4389. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4390. dayStr2 := "-" + dayStr
  4391. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4392. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4393. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4394. for _, ad := range advices {
  4395. advice_three = append(advice_three, ad)
  4396. }
  4397. }
  4398. if err == nil {
  4399. c.ServeSuccessJSON(map[string]interface{}{
  4400. "status": "2",
  4401. "advices": advices,
  4402. "advices_two": RemoveRepeatedElement(advice_three),
  4403. "is_open_remind": config.IsOpenRemind,
  4404. "his_config_open": hisConfig.IsOpen,
  4405. "is_advice_open": is_advice_open.IsAdviceOpen,
  4406. "prescription_open": prescription_open.IsOpen,
  4407. })
  4408. }
  4409. }
  4410. }
  4411. func (c *DialysisAPIController) GetLongAdviceOne() {
  4412. patient_id, _ := c.GetInt64("id")
  4413. startTime := c.GetString("schedule_date")
  4414. timeLayout := "2006-01-02"
  4415. loc, _ := time.LoadLocation("Local")
  4416. var theStartTime int64
  4417. if len(startTime) > 0 {
  4418. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4419. if err != nil {
  4420. utils.ErrorLog(err.Error())
  4421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4422. return
  4423. }
  4424. theStartTime = theTime.Unix()
  4425. }
  4426. adminUserInfo := c.GetMobileAdminUserInfo()
  4427. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4428. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4429. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4430. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4431. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4432. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4433. c.ServeSuccessJSON(map[string]interface{}{
  4434. "status": "1",
  4435. })
  4436. return
  4437. } else { //开启推送提醒
  4438. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4439. var advice_three []*models.DoctorAdvice
  4440. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4441. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4442. for _, advice := range advices {
  4443. if advice.FrequencyType == 3 {
  4444. t := time.Now()
  4445. week := int(t.Weekday())
  4446. fmt.Println(t.Weekday())
  4447. fmt.Println(week)
  4448. switch week {
  4449. case 1:
  4450. if strings.Index(advice.WeekDay, "周一") == -1 {
  4451. advice_three = append(advice_three, advice)
  4452. }
  4453. break
  4454. case 2:
  4455. if strings.Index(advice.WeekDay, "周二") == -1 {
  4456. advice_three = append(advice_three, advice)
  4457. }
  4458. break
  4459. case 3:
  4460. if strings.Index(advice.WeekDay, "周三") == -1 {
  4461. advice_three = append(advice_three, advice)
  4462. }
  4463. break
  4464. case 4:
  4465. if strings.Index(advice.WeekDay, "周四") == -1 {
  4466. advice_three = append(advice_three, advice)
  4467. }
  4468. break
  4469. case 5:
  4470. if strings.Index(advice.WeekDay, "周五") == -1 {
  4471. advice_three = append(advice_three, advice)
  4472. }
  4473. break
  4474. case 6:
  4475. if strings.Index(advice.WeekDay, "周六") == -1 {
  4476. advice_three = append(advice_three, advice)
  4477. }
  4478. break
  4479. case 0:
  4480. if strings.Index(advice.WeekDay, "周日") == -1 {
  4481. advice_three = append(advice_three, advice)
  4482. }
  4483. break
  4484. }
  4485. }
  4486. }
  4487. for _, advice := range advices_two {
  4488. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4489. now := p.Unix()
  4490. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4491. dayStr2 := "-" + dayStr
  4492. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4493. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4494. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4495. for _, ad := range advices {
  4496. advice_three = append(advice_three, ad)
  4497. }
  4498. }
  4499. if err == nil {
  4500. c.ServeSuccessJSON(map[string]interface{}{
  4501. "status": "2",
  4502. "advices": advices,
  4503. "advices_two": RemoveRepeatedElement(advice_three),
  4504. "is_open_remind": config.IsOpenRemind,
  4505. "his_config_open": hisConfig.IsOpen,
  4506. "is_advice_open": is_advice_open.IsAdviceOpen,
  4507. "prescription_open": prescription_open.IsOpen,
  4508. })
  4509. }
  4510. }
  4511. }
  4512. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4513. newArr = make([]*models.DoctorAdvice, 0)
  4514. for i := 0; i < len(arr); i++ {
  4515. repeat := false
  4516. for j := i + 1; j < len(arr); j++ {
  4517. if arr[i].ID == arr[j].ID {
  4518. repeat = true
  4519. break
  4520. }
  4521. }
  4522. if !repeat {
  4523. newArr = append(newArr, arr[i])
  4524. }
  4525. }
  4526. return
  4527. }
  4528. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4529. patient, _ := c.GetInt64("id", 0)
  4530. groupNo, _ := c.GetInt64("groupno", 0)
  4531. if patient <= 0 {
  4532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4533. return
  4534. }
  4535. adminUserInfo := c.GetMobileAdminUserInfo()
  4536. dataBody := make(map[string]interface{}, 0)
  4537. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4538. if err != nil {
  4539. utils.ErrorLog(err.Error())
  4540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4541. return
  4542. }
  4543. utils.ErrorLog("%v", dataBody)
  4544. timeLayout := "2006-01-02 15:04"
  4545. loc, _ := time.LoadLocation("Local")
  4546. timeLayout2 := "2006-01-02"
  4547. loc2, _ := time.LoadLocation("Local")
  4548. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4549. utils.ErrorLog("advice_type")
  4550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4551. return
  4552. }
  4553. adviceType := int64(2)
  4554. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4555. utils.ErrorLog("advice_date")
  4556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4557. return
  4558. }
  4559. adviceDate, _ := dataBody["advice_date"].(string)
  4560. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4561. AdviceDate := theTime.Unix()
  4562. RecordDate := theTime.Unix()
  4563. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4564. utils.ErrorLog("start_time")
  4565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4566. return
  4567. }
  4568. startTime, _ := dataBody["start_time"].(string)
  4569. if len(startTime) == 0 {
  4570. utils.ErrorLog("len(start_time) == 0")
  4571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4572. return
  4573. }
  4574. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4575. if err != nil {
  4576. utils.ErrorLog(err.Error())
  4577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4578. return
  4579. }
  4580. StartTime := theTime.Unix()
  4581. Remark := ""
  4582. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4583. remark, _ := dataBody["remark"].(string)
  4584. Remark = remark
  4585. }
  4586. var advices []*models.GroupAdvice
  4587. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4588. utils.ErrorLog("advices")
  4589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4590. return
  4591. }
  4592. adviceNames := dataBody["advices"].([]interface{})
  4593. for _, adviceNameMap := range adviceNames {
  4594. adviceNameM := adviceNameMap.(map[string]interface{})
  4595. var advice models.GroupAdvice
  4596. advice.Remark = Remark
  4597. advice.AdviceType = adviceType
  4598. advice.StartTime = StartTime
  4599. advice.AdviceDate = AdviceDate
  4600. advice.RecordDate = RecordDate
  4601. advice.Status = 1
  4602. advice.CreatedTime = time.Now().Unix()
  4603. advice.UpdatedTime = time.Now().Unix()
  4604. advice.StopState = 2
  4605. advice.ExecutionState = 2
  4606. advice.UserOrgId = adminUserInfo.Org.Id
  4607. advice.PatientId = patient
  4608. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4609. advice.IsSettle = 2
  4610. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4611. utils.ErrorLog("advice_name")
  4612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4613. return
  4614. }
  4615. adviceName, _ := adviceNameM["advice_name"].(string)
  4616. if len(adviceName) == 0 {
  4617. utils.ErrorLog("len(advice_name) == 0")
  4618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4619. return
  4620. }
  4621. advice.AdviceName = adviceName
  4622. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4623. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4624. advice.DrugSpec = drugSpec
  4625. }
  4626. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4627. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4628. advice.AdviceDesc = adviceDesc
  4629. }
  4630. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4631. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4632. advice.DrugSpecUnit = drugSpecUnit
  4633. }
  4634. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4635. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4636. // advice.SingleDose = singleDose
  4637. //}
  4638. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4639. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4640. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4641. }
  4642. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4643. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4644. advice.SingleDoseUnit = singleDoseUnit
  4645. }
  4646. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4647. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4648. // advice.PrescribingNumber = prescribingNumber
  4649. //}
  4650. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4651. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4652. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4653. }
  4654. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4655. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4656. advice.PrescribingNumberUnit = prescribingNumberUnit
  4657. }
  4658. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4659. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4660. advice.DeliveryWay = deliveryWay
  4661. }
  4662. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4663. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4664. advice.ExecutionFrequency = executionFrequency
  4665. }
  4666. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4667. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4668. advice.FrequencyType = frequency_type
  4669. }
  4670. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4671. day_count := int64(adviceNameM["day_count"].(float64))
  4672. advice.DayCount = day_count
  4673. }
  4674. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4675. week_day, _ := adviceNameM["week_day"].(string)
  4676. advice.WeekDay = week_day
  4677. }
  4678. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4679. way := int64(adviceNameM["way"].(float64))
  4680. advice.Way = way
  4681. }
  4682. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4683. drug_id := int64(adviceNameM["drug_id"].(float64))
  4684. advice.DrugId = drug_id
  4685. }
  4686. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4687. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4688. advice.DrugNameId = drug_name_id
  4689. }
  4690. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4691. remark, _ := adviceNameM["remark"].(string)
  4692. advice.Remark = remark
  4693. }
  4694. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4695. groupno := int64(adviceNameM["groupno"].(float64))
  4696. advice.GroupNo = groupno
  4697. }
  4698. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4699. template_id, _ := adviceNameM["template_id"].(string)
  4700. advice.TemplateId = template_id
  4701. }
  4702. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4703. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4704. advice.ExecutionFrequency = executionFrequency
  4705. }
  4706. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4707. children := adviceNameM["child"].([]interface{})
  4708. if len(children) > 0 {
  4709. for _, childrenMap := range children {
  4710. childMap := childrenMap.(map[string]interface{})
  4711. var child models.GroupAdvice
  4712. child.Remark = Remark
  4713. child.AdviceType = adviceType
  4714. child.StartTime = StartTime
  4715. child.AdviceDate = AdviceDate
  4716. child.RecordDate = RecordDate
  4717. child.Status = 1
  4718. child.CreatedTime = time.Now().Unix()
  4719. child.UpdatedTime = time.Now().Unix()
  4720. child.StopState = 2
  4721. child.ExecutionState = 2
  4722. child.UserOrgId = adminUserInfo.Org.Id
  4723. child.PatientId = patient
  4724. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4725. child.IsSettle = 1
  4726. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4727. utils.ErrorLog("child advice_name")
  4728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4729. return
  4730. }
  4731. childAdviceName, _ := childMap["advice_name"].(string)
  4732. if len(childAdviceName) == 0 {
  4733. utils.ErrorLog("len(child advice_name) == 0")
  4734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4735. return
  4736. }
  4737. child.AdviceName = childAdviceName
  4738. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4739. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4740. child.AdviceDesc = childAdviceDesc
  4741. }
  4742. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4743. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4744. child.DrugSpec = childDrugSpec
  4745. }
  4746. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4747. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4748. child.DrugSpecUnit = childDrugSpecUnit
  4749. }
  4750. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4751. child.SingleDose = childMap["single_dose"].(float64)
  4752. }
  4753. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4754. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4755. child.SingleDoseUnit = childSingleDoseUnit
  4756. }
  4757. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4758. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4759. }
  4760. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4761. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4762. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4763. }
  4764. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4765. groupno := int64(childMap["groupno"].(float64))
  4766. advice.GroupNo = groupno
  4767. }
  4768. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4769. remark, _ := childMap["remark"].(string)
  4770. child.Remark = remark
  4771. }
  4772. child.DeliveryWay = advice.DeliveryWay
  4773. child.ExecutionFrequency = advice.ExecutionFrequency
  4774. advice.Children = append(advice.Children, &child)
  4775. }
  4776. }
  4777. }
  4778. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4779. if temp_advice.ID == 0 {
  4780. advices = append(advices, &advice)
  4781. }
  4782. }
  4783. if len(advices) > 0 {
  4784. finish := models.XtDialysisFinish{
  4785. IsFinish: 1,
  4786. UserOrgId: adminUserInfo.Org.Id,
  4787. Status: 1,
  4788. Ctime: time.Now().Unix(),
  4789. Mtime: 0,
  4790. Module: 4,
  4791. RecordDate: AdviceDate,
  4792. Sourse: 1,
  4793. PatientId: patient,
  4794. }
  4795. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4796. if dialysisFinish.ID == 0 {
  4797. service.CreateDialysisFinish(finish)
  4798. }
  4799. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9671 {
  4800. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4801. for _, item := range advices {
  4802. byterequest, _ := json.Marshal(item)
  4803. adviceLog := models.XtDoctorAdviceLog{
  4804. UserOrgId: adminUserInfo.Org.Id,
  4805. PatientId: patient,
  4806. AdminUserId: adminUserInfo.AdminUser.Id,
  4807. Module: 1,
  4808. ErrLog: string(byterequest),
  4809. Status: 1,
  4810. Ctime: time.Now().Unix(),
  4811. Mtime: 0,
  4812. Source: "手机端医嘱推送",
  4813. RecordDate: item.AdviceDate,
  4814. }
  4815. service.CreateDoctorAdviceLog(adviceLog)
  4816. }
  4817. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4818. redis := service.RedisClient()
  4819. //清空key 值
  4820. redis.Set(key, "", time.Second)
  4821. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4822. redis.Set(keyOne, "", time.Second)
  4823. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4824. defer redis.Close()
  4825. redis.Set(keyThree, "", time.Second)
  4826. if err != nil {
  4827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4828. return
  4829. }
  4830. c.ServeSuccessJSON(map[string]interface{}{
  4831. "msg": "ok",
  4832. "advices": list,
  4833. })
  4834. } else {
  4835. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4836. for _, item := range advices {
  4837. byterequest, _ := json.Marshal(item)
  4838. adviceLog := models.XtDoctorAdviceLog{
  4839. UserOrgId: adminUserInfo.Org.Id,
  4840. PatientId: patient,
  4841. AdminUserId: adminUserInfo.AdminUser.Id,
  4842. Module: 1,
  4843. ErrLog: string(byterequest),
  4844. Status: 1,
  4845. Ctime: time.Now().Unix(),
  4846. Mtime: 0,
  4847. Source: "手机端医嘱推送",
  4848. RecordDate: item.AdviceDate,
  4849. }
  4850. service.CreateDoctorAdviceLog(adviceLog)
  4851. }
  4852. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4853. redis := service.RedisClient()
  4854. //清空key 值
  4855. redis.Set(key, "", time.Second)
  4856. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4857. redis.Set(keyOne, "", time.Second)
  4858. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4859. defer redis.Close()
  4860. redis.Set(keyThree, "", time.Second)
  4861. if err != nil {
  4862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4863. return
  4864. }
  4865. c.ServeSuccessJSON(map[string]interface{}{
  4866. "msg": "ok",
  4867. "advices": list,
  4868. })
  4869. }
  4870. } else {
  4871. c.ServeSuccessJSON(map[string]interface{}{
  4872. "msg": "ok",
  4873. })
  4874. }
  4875. return
  4876. }
  4877. func (c *DialysisAPIController) UploadDryWeight() {
  4878. patient_id, _ := c.GetInt64("id")
  4879. dry_weight, _ := c.GetFloat("dry_weight")
  4880. doctor_id, _ := c.GetInt64("doctor_id")
  4881. remark := c.GetString("remark")
  4882. adminUserInfo := c.GetMobileAdminUserInfo()
  4883. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4884. if err == gorm.ErrRecordNotFound {
  4885. dryWeight := &models.SgjPatientDryweight{
  4886. PatientId: patient_id,
  4887. DryWeight: dry_weight,
  4888. Remakes: remark,
  4889. Ctime: time.Now().Unix(),
  4890. Mtime: time.Now().Unix(),
  4891. Creator: doctor_id,
  4892. Status: 1,
  4893. UserOrgId: adminUserInfo.Org.Id,
  4894. AdjustedValue: "/",
  4895. UserId: adminUserInfo.AdminUser.Id,
  4896. }
  4897. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4898. redis := service.RedisClient()
  4899. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4900. redis.Set(keyOne, "", time.Second)
  4901. loc, _ := time.LoadLocation("Local")
  4902. nowTime := time.Now()
  4903. nowDay := nowTime.Format("2006-01-02")
  4904. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4905. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4906. redis.Set(key, "", time.Second)
  4907. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4908. redis.Set(keyTwo, "", time.Second)
  4909. redis.Close()
  4910. if createErr == nil {
  4911. c.ServeSuccessJSON(map[string]interface{}{
  4912. "msg": "提交成功",
  4913. "weight": dryWeight,
  4914. })
  4915. }
  4916. } else {
  4917. dryWeight := &models.SgjPatientDryweight{
  4918. PatientId: patient_id,
  4919. DryWeight: dry_weight,
  4920. Remakes: remark,
  4921. Ctime: time.Now().Unix(),
  4922. Mtime: time.Now().Unix(),
  4923. Creator: doctor_id,
  4924. Status: 1,
  4925. UserOrgId: adminUserInfo.Org.Id,
  4926. AdjustedValue: "/",
  4927. UserId: adminUserInfo.AdminUser.Id,
  4928. }
  4929. var value float64
  4930. value = dry_weight - weightAdjust.DryWeight
  4931. if value < 0 {
  4932. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4933. } else if value == 0 {
  4934. dryWeight.AdjustedValue = "/"
  4935. } else if value > 0 {
  4936. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4937. }
  4938. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4939. redis := service.RedisClient()
  4940. loc, _ := time.LoadLocation("Local")
  4941. nowTime := time.Now()
  4942. nowDay := nowTime.Format("2006-01-02")
  4943. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4944. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4945. redis.Set(keyOne, "", time.Second)
  4946. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4947. redis.Set(key, "", time.Second)
  4948. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4949. redis.Set(keyTwo, "", time.Second)
  4950. redis.Close()
  4951. if createErr == nil {
  4952. c.ServeSuccessJSON(map[string]interface{}{
  4953. "msg": "提交成功",
  4954. "weight": dryWeight,
  4955. })
  4956. }
  4957. }
  4958. }
  4959. func (c *DialysisAPIController) GetSolution() {
  4960. patient_id, _ := c.GetInt64("patient_id")
  4961. mode_id, _ := c.GetInt64("mode_id")
  4962. adminUserInfo := c.GetMobileAdminUserInfo()
  4963. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4964. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4965. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4966. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4967. if err != nil {
  4968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4969. return
  4970. }
  4971. c.ServeSuccessJSON(map[string]interface{}{
  4972. "solution": solution,
  4973. "prescription": prescription,
  4974. "system_prescription": system_prescription,
  4975. "dialysisPrescription": dialysisPrescription,
  4976. })
  4977. }
  4978. func (c *DialysisAPIController) GetSchedule() {
  4979. schedual_type, _ := c.GetInt64("schedual_type")
  4980. adminUserInfo := c.GetMobileAdminUserInfo()
  4981. scheduleTime, _ := c.GetInt64("record_date")
  4982. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4983. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4984. c.ServeSuccessJSON(map[string]interface{}{
  4985. "number": deviceNumber,
  4986. "list": list,
  4987. })
  4988. }
  4989. func (c *DialysisAPIController) GetPatientId() {
  4990. id, _ := c.GetInt64("id")
  4991. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4992. patientId, _ := service.GetPatientId(id)
  4993. //获取该患者的所有传染病
  4994. list, _ := service.GetPatientInfectious(id)
  4995. c.ServeSuccessJSON(map[string]interface{}{
  4996. "patient": patientId,
  4997. "infectioulist": list,
  4998. })
  4999. }
  5000. func (this *DialysisAPIController) GetDialysisSchedule() {
  5001. schedualDate := this.GetString("date")
  5002. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5003. if parseDateErr != nil {
  5004. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5005. return
  5006. }
  5007. adminInfo := this.GetMobileAdminUserInfo()
  5008. orgID := adminInfo.Org.Id
  5009. redis := service.RedisClient()
  5010. defer redis.Close()
  5011. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5012. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5013. if len(scheduals) > 0 {
  5014. //缓存数据
  5015. scheduals_json, err := json.Marshal(scheduals)
  5016. if err == nil {
  5017. redis.Set(key, scheduals_json, time.Second*30)
  5018. }
  5019. }
  5020. this.ServeSuccessJSON(map[string]interface{}{
  5021. "scheduals": scheduals,
  5022. })
  5023. }
  5024. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5025. change_type, _ := this.GetInt64("type", 0)
  5026. record_date := this.GetString("record_time")
  5027. patient_id, _ := this.GetInt64("patient_id", 0)
  5028. timeLayout := "2006-01-02"
  5029. loc, _ := time.LoadLocation("Local")
  5030. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5031. record_time := theAdviceRecordTime.Unix()
  5032. adminUserInfo := this.GetMobileAdminUserInfo()
  5033. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5034. if err == nil {
  5035. if len(advices) == 0 {
  5036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5037. return
  5038. } else {
  5039. this.ServeSuccessJSON(map[string]interface{}{
  5040. "advices": advices,
  5041. "schedule": sch,
  5042. })
  5043. return
  5044. }
  5045. } else {
  5046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5047. return
  5048. }
  5049. }
  5050. func (c *DialysisAPIController) CreateConsumables() {
  5051. record_date := c.GetString("record_time")
  5052. patient_id, _ := c.GetInt64("patient_id", 0)
  5053. active, _ := c.GetInt64("active")
  5054. adminUser := c.GetMobileAdminUserInfo()
  5055. timeLayout := "2006-01-02"
  5056. loc, _ := time.LoadLocation("Local")
  5057. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5058. record_time := theRecordTime.Unix()
  5059. // 查询信息规挡的设置天数
  5060. orgid := c.GetMobileAdminUserInfo().Org.Id
  5061. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5062. if infor.ID > 0 {
  5063. var cha_time int64
  5064. timeNowStr := time.Now().Format("2006-01-02")
  5065. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5066. //今日的日期减去设置的日期
  5067. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5068. if cha_time >= record_time {
  5069. //查询审核是否允许
  5070. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5071. //申请状态不允许的情况 拒绝修改
  5072. if infor.ApplicationStatus != 1 {
  5073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5074. return
  5075. }
  5076. }
  5077. }
  5078. dataBody := make(map[string]interface{}, 0)
  5079. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5080. if err != nil {
  5081. utils.ErrorLog(err.Error())
  5082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5083. return
  5084. }
  5085. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5086. var beforePrepares []*models.DialysisBeforePrepareGoods
  5087. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5088. var dialysisBefor []*models.DialysisBeforePrepare
  5089. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5090. goods, _ := dataBody["goods"].([]interface{})
  5091. if len(goods) > 0 {
  5092. for _, item := range goods {
  5093. items := item.(map[string]interface{})
  5094. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5095. utils.ErrorLog("good_id")
  5096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5097. return
  5098. }
  5099. good_id := int64(items["good_id"].(float64))
  5100. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5101. utils.ErrorLog("good_type_id")
  5102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5103. return
  5104. }
  5105. good_type_id := int64(items["good_type_id"].(float64))
  5106. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5107. utils.ErrorLog("count")
  5108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5109. return
  5110. }
  5111. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5112. commdity_code := items["commdity_code"].(string)
  5113. fmt.Println("commdity", commdity_code)
  5114. prepareGoods := &models.DialysisBeforePrepareGoods{
  5115. GoodTypeId: good_type_id,
  5116. GoodId: good_id,
  5117. Count: count,
  5118. StorehouseId: houseConfig.StorehouseOutInfo,
  5119. }
  5120. beforePrepares = append(beforePrepares, prepareGoods)
  5121. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5122. GoodTypeId: good_type_id,
  5123. GoodId: good_id,
  5124. Count: count,
  5125. StorehouseId: houseConfig.StorehouseOutInfo,
  5126. }
  5127. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5128. prepare := &models.DialysisBeforePrepare{
  5129. GoodTypeId: good_type_id,
  5130. GoodId: good_id,
  5131. Count: count,
  5132. PatientId: patient_id,
  5133. RecordDate: record_time,
  5134. UserOrgId: adminUser.Org.Id,
  5135. Status: 1,
  5136. Ctime: time.Now().Unix(),
  5137. Creater: adminUser.AdminUser.Id,
  5138. CommdityCode: commdity_code,
  5139. StorehouseId: houseConfig.StorehouseOutInfo,
  5140. }
  5141. dialysisBefor = append(dialysisBefor, prepare)
  5142. }
  5143. }
  5144. //查询是否有库存
  5145. for _, item := range dialysisBefor {
  5146. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5147. if err == gorm.ErrRecordNotFound {
  5148. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5149. c.ServeSuccessJSON(map[string]interface{}{
  5150. "message": "1",
  5151. "good_name": goodObj.GoodName,
  5152. "specification_name": goodObj.SpecificationName,
  5153. })
  5154. return
  5155. }
  5156. if err != nil {
  5157. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5158. c.ServeSuccessJSON(map[string]interface{}{
  5159. "message": "1",
  5160. "good_name": goodObj.GoodName,
  5161. "specification_name": goodObj.SpecificationName,
  5162. })
  5163. return
  5164. }
  5165. }
  5166. //新增
  5167. if active == 1 && len(goods) > 0 {
  5168. for _, item := range dialysisBefor {
  5169. dialyPrepareOne := models.DialysisBeforePrepare{
  5170. GoodTypeId: item.GoodTypeId,
  5171. GoodId: item.GoodId,
  5172. PatientId: item.PatientId,
  5173. RecordDate: item.RecordDate,
  5174. UserOrgId: item.UserOrgId,
  5175. Count: item.Count,
  5176. Ctime: time.Now().Unix(),
  5177. Creater: item.Creater,
  5178. CommdityCode: item.CommdityCode,
  5179. Status: 1,
  5180. StorehouseId: houseConfig.StorehouseOutInfo,
  5181. }
  5182. //先清除再插入
  5183. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5184. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5185. //查询默认仓库
  5186. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5187. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5188. var total_count int64
  5189. for _, it := range stockList {
  5190. total_count += it.StockCount
  5191. }
  5192. //基础库插入数据
  5193. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5194. //更新库存
  5195. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5196. var flush_count int64
  5197. for _, it := range goodList {
  5198. flush_count += it.StockCount
  5199. }
  5200. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5201. }
  5202. if err == nil {
  5203. c.ServeSuccessJSON(map[string]interface{}{
  5204. "msg": "保存成功",
  5205. "message": "2",
  5206. })
  5207. return
  5208. } else {
  5209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5210. return
  5211. }
  5212. }
  5213. if len(beforePrepares) > 0 && active == 2 {
  5214. for _, item := range beforePrepares {
  5215. //1.查看该患者该耗材型号最后一次出库数量
  5216. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5217. //判断当前出库数量和最后一次出库数量的大小
  5218. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5219. if item.Count <= goodInfo.Count {
  5220. //退库
  5221. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5222. //查询今日出库数据
  5223. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5224. for _, it := range list {
  5225. prepare := models.DialysisBeforePrepare{
  5226. UserOrgId: it.OrgId,
  5227. PatientId: patient_id,
  5228. RecordDate: it.RecordTime,
  5229. GoodId: it.GoodId,
  5230. GoodTypeId: it.GoodTypeId,
  5231. Count: it.Count,
  5232. Ctime: time.Now().Unix(),
  5233. Creater: adminUser.AdminUser.Id,
  5234. Status: 1,
  5235. StorehouseId: houseConfig.StorehouseOutInfo,
  5236. }
  5237. //删除准备表数据
  5238. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5239. service.CreateDialysisBeforePrepareOne(&prepare)
  5240. }
  5241. }
  5242. var last_total int64
  5243. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5244. if item.Count >= goodInfo.Count {
  5245. //查询当前批次当前耗材最后一条出库数据
  5246. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5247. //计算当前出库和最后一次出库数据相差数据
  5248. last_total = item.Count - lastOutInfo.Count
  5249. //查询该批次剩余库存
  5250. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5251. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5252. if lastInfo.StockCount >= last_total {
  5253. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5254. //查询今日出库数据
  5255. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5256. for _, it := range list {
  5257. prepare := models.DialysisBeforePrepare{
  5258. UserOrgId: it.OrgId,
  5259. PatientId: patient_id,
  5260. RecordDate: it.RecordTime,
  5261. GoodId: it.GoodId,
  5262. GoodTypeId: it.GoodTypeId,
  5263. Count: it.Count,
  5264. Ctime: time.Now().Unix(),
  5265. Creater: adminUser.AdminUser.Id,
  5266. Status: 1,
  5267. StorehouseId: houseConfig.StorehouseOutInfo,
  5268. }
  5269. //删除准备表数据
  5270. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5271. service.CreateDialysisBeforePrepareOne(&prepare)
  5272. //查询默认仓库
  5273. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5274. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5275. var total_count int64
  5276. for _, it := range stockList {
  5277. total_count += it.StockCount
  5278. }
  5279. //基础库插入数据
  5280. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5281. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5282. var flush_count int64
  5283. for _, it := range goodList {
  5284. flush_count += it.StockCount
  5285. }
  5286. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5287. }
  5288. }
  5289. //如果库存不够,则出库到下一个批次
  5290. if lastInfo.StockCount < last_total {
  5291. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5292. //查询今日出库数据
  5293. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5294. for _, it := range list {
  5295. prepare := models.DialysisBeforePrepare{
  5296. UserOrgId: it.OrgId,
  5297. PatientId: patient_id,
  5298. RecordDate: it.RecordTime,
  5299. GoodId: it.GoodId,
  5300. GoodTypeId: it.GoodTypeId,
  5301. Count: it.Count,
  5302. Ctime: time.Now().Unix(),
  5303. Creater: adminUser.AdminUser.Id,
  5304. Status: 1,
  5305. StorehouseId: houseConfig.StorehouseOutInfo,
  5306. }
  5307. //删除准备表数据
  5308. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5309. service.CreateDialysisBeforePrepareOne(&prepare)
  5310. //查询默认仓库
  5311. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5312. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5313. var total_count int64
  5314. for _, it := range stockList {
  5315. total_count += it.StockCount
  5316. }
  5317. //基础库插入数据
  5318. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5319. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5320. var flush_count int64
  5321. for _, it := range goodList {
  5322. flush_count += it.StockCount
  5323. }
  5324. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5325. }
  5326. if err != nil {
  5327. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5328. c.ServeSuccessJSON(map[string]interface{}{
  5329. "message": "1",
  5330. "good_name": goodObj.GoodName,
  5331. "specification_name": goodObj.SpecificationName,
  5332. })
  5333. return
  5334. }
  5335. }
  5336. }
  5337. if err != nil {
  5338. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5339. c.ServeSuccessJSON(map[string]interface{}{
  5340. "message": "1",
  5341. "good_name": goodObj.GoodName,
  5342. "specification_name": goodObj.SpecificationName,
  5343. })
  5344. return
  5345. }
  5346. }
  5347. }
  5348. }
  5349. var errs error
  5350. if errs == nil {
  5351. c.ServeSuccessJSON(map[string]interface{}{
  5352. "msg": "提交成功",
  5353. "message": "2",
  5354. "good_name": "",
  5355. "specification_name": "",
  5356. })
  5357. return
  5358. } else {
  5359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5360. return
  5361. }
  5362. }
  5363. func (c *DialysisAPIController) CreateStockOutInfo() {
  5364. patient_id, _ := c.GetInt64("patient_id", 0)
  5365. record_date := c.GetString("record_time")
  5366. if patient_id <= 0 {
  5367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5368. return
  5369. }
  5370. adminInfo := c.GetMobileAdminUserInfo()
  5371. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5372. timeLayout := "2006-01-02"
  5373. loc, _ := time.LoadLocation("Local")
  5374. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5375. record_time := theRecordTime.Unix()
  5376. // 查询信息规挡的设置天数
  5377. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5378. if infor.ID > 0 && infor.WeekDay > 0 {
  5379. var cha_time int64
  5380. timeNowStr := time.Now().Format("2006-01-02")
  5381. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5382. //今日的日期减去设置的日期
  5383. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5384. if cha_time >= record_time {
  5385. //查询审核是否允许
  5386. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5387. //申请状态不允许的情况 拒绝修改
  5388. if infor.ApplicationStatus != 1 {
  5389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5390. return
  5391. }
  5392. }
  5393. }
  5394. //创建步骤表
  5395. finish := models.XtDialysisFinish{
  5396. IsFinish: 1,
  5397. UserOrgId: adminInfo.Org.Id,
  5398. Status: 1,
  5399. Ctime: time.Now().Unix(),
  5400. Mtime: 0,
  5401. Module: 11,
  5402. RecordDate: record_time,
  5403. Sourse: 1,
  5404. PatientId: patient_id,
  5405. }
  5406. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5407. if dialysisFinish.ID == 0 {
  5408. service.CreateDialysisFinish(finish)
  5409. }
  5410. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5411. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5412. //去重
  5413. consumables = RemoveRepeatedGood(consumables)
  5414. if adminInfo.Org.Id == 9919 {
  5415. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5416. //查询是否有库存
  5417. for _, item := range consumables {
  5418. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5419. if item.Count > warehouse.Count {
  5420. goodErrcode := models.XtGoodErrcode{
  5421. UserOrgId: item.UserOrgId,
  5422. Errcode: "自动出库库存不足",
  5423. GoodId: item.GoodId,
  5424. Status: 1,
  5425. Ctime: time.Now().Unix(),
  5426. Mtime: 0,
  5427. Count: 0,
  5428. StockCount: 0,
  5429. Creater: creator,
  5430. BatchNumberId: warehouse.ID,
  5431. WarehouseOutId: 0,
  5432. }
  5433. service.CreateGoodErrcode(goodErrcode)
  5434. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5435. c.ServeSuccessJSON(map[string]interface{}{
  5436. "message": "1",
  5437. "good_name": goodObj.GoodName,
  5438. "specification_name": goodObj.SpecificationName,
  5439. })
  5440. return
  5441. }
  5442. }
  5443. //查询是否有出库单
  5444. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5445. if err == gorm.ErrRecordNotFound {
  5446. //没有记录,则创建出库单
  5447. timeStr := time.Now().Format("2006-01-02")
  5448. timeArr := strings.Split(timeStr, "-")
  5449. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5450. total = total + 1
  5451. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5452. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5453. number = number + total
  5454. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5455. creater := adminInfo.AdminUser.Id
  5456. warehouseOut := models.WarehouseOut{
  5457. WarehouseOutOrderNumber: warehousing_out_order,
  5458. OperationTime: time.Now().Unix(),
  5459. OrgId: adminInfo.Org.Id,
  5460. Creater: creater,
  5461. Ctime: time.Now().Unix(),
  5462. Status: 1,
  5463. WarehouseOutTime: record_time,
  5464. Dealer: 0,
  5465. Manufacturer: 0,
  5466. Type: 1,
  5467. IsSys: 1,
  5468. StorehouseId: houseConfig.StorehouseOutInfo,
  5469. IsCheck: 1,
  5470. }
  5471. err := service.AddSigleWarehouseOut(&warehouseOut)
  5472. if err != nil {
  5473. goodErrcode := models.XtGoodErrcode{
  5474. UserOrgId: adminInfo.Org.Id,
  5475. Errcode: "创建出库单失败",
  5476. GoodId: 0,
  5477. Status: 1,
  5478. Ctime: time.Now().Unix(),
  5479. Mtime: 0,
  5480. Count: 0,
  5481. StockCount: 0,
  5482. Creater: creator,
  5483. BatchNumberId: 0,
  5484. WarehouseOutId: 0,
  5485. }
  5486. service.CreateGoodErrcode(goodErrcode)
  5487. utils.TraceLog("创建出库单失败 err = %v", err)
  5488. } else {
  5489. for _, item := range consumables {
  5490. //出库
  5491. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5492. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5493. if err == nil {
  5494. goodErrcode := models.XtGoodErrcode{
  5495. UserOrgId: adminInfo.Org.Id,
  5496. Errcode: "自动出库接口报错",
  5497. GoodId: 0,
  5498. Status: 1,
  5499. Ctime: time.Now().Unix(),
  5500. Mtime: 0,
  5501. Count: 0,
  5502. StockCount: 0,
  5503. Creater: creator,
  5504. BatchNumberId: 0,
  5505. WarehouseOutId: 0,
  5506. }
  5507. service.CreateGoodErrcode(goodErrcode)
  5508. utils.TraceLog("创建出库单失败 err = %v", err)
  5509. }
  5510. //查询
  5511. //出库数量相加
  5512. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5513. if errs != nil {
  5514. goodErrcode := models.XtGoodErrcode{
  5515. UserOrgId: item.UserOrgId,
  5516. Errcode: "创建剩余库存字段报错",
  5517. GoodId: item.GoodId,
  5518. Status: 1,
  5519. Ctime: time.Now().Unix(),
  5520. Mtime: 0,
  5521. Count: 0,
  5522. StockCount: 0,
  5523. Creater: creater,
  5524. BatchNumberId: 0,
  5525. WarehouseOutId: 0,
  5526. }
  5527. service.CreateGoodErrcode(goodErrcode)
  5528. }
  5529. }
  5530. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5531. if len(list) == 0 {
  5532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5533. return
  5534. }
  5535. for _, item := range list {
  5536. prepare := models.DialysisBeforePrepare{
  5537. UserOrgId: adminInfo.Org.Id,
  5538. PatientId: patient_id,
  5539. RecordDate: record_time,
  5540. GoodId: item.GoodId,
  5541. GoodTypeId: item.GoodTypeId,
  5542. Count: item.Count,
  5543. Creater: adminInfo.AdminUser.Id,
  5544. Status: 1,
  5545. Ctime: time.Now().Unix(),
  5546. StorehouseId: houseConfig.StorehouseOutInfo,
  5547. }
  5548. //清空准备表数据
  5549. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5550. if err != nil {
  5551. goodErrcode := models.XtGoodErrcode{
  5552. UserOrgId: item.OrgId,
  5553. Errcode: "自动出库清空准备表数据报错",
  5554. GoodId: item.GoodId,
  5555. Status: 1,
  5556. Ctime: time.Now().Unix(),
  5557. Mtime: 0,
  5558. Count: 0,
  5559. StockCount: 0,
  5560. Creater: creater,
  5561. BatchNumberId: 0,
  5562. WarehouseOutId: 0,
  5563. }
  5564. service.CreateGoodErrcode(goodErrcode)
  5565. }
  5566. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5567. if errs != nil {
  5568. goodErrcode := models.XtGoodErrcode{
  5569. UserOrgId: item.OrgId,
  5570. Errcode: "自动出库创建准备表数据报错",
  5571. GoodId: item.GoodId,
  5572. Status: 1,
  5573. Ctime: time.Now().Unix(),
  5574. Mtime: 0,
  5575. Count: 0,
  5576. StockCount: 0,
  5577. Creater: creater,
  5578. BatchNumberId: 0,
  5579. WarehouseOutId: 0,
  5580. }
  5581. service.CreateGoodErrcode(goodErrcode)
  5582. }
  5583. //查询默认仓库
  5584. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5585. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5586. var total_count int64
  5587. for _, it := range stockList {
  5588. total_count += it.StockCount
  5589. }
  5590. //基础库插入数据
  5591. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5592. if errcodes != nil {
  5593. goodErrcode := models.XtGoodErrcode{
  5594. UserOrgId: item.OrgId,
  5595. Errcode: "自动出库基础库插入数据",
  5596. GoodId: item.GoodId,
  5597. Status: 1,
  5598. Ctime: time.Now().Unix(),
  5599. Mtime: 0,
  5600. Count: 0,
  5601. StockCount: 0,
  5602. Creater: creater,
  5603. BatchNumberId: 0,
  5604. WarehouseOutId: 0,
  5605. }
  5606. service.CreateGoodErrcode(goodErrcode)
  5607. }
  5608. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5609. var flush_count int64
  5610. for _, it := range goodList {
  5611. flush_count += it.StockCount
  5612. }
  5613. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5614. if errsss != nil {
  5615. goodErrcode := models.XtGoodErrcode{
  5616. UserOrgId: item.OrgId,
  5617. Errcode: "自动出库剩余库存更新数据",
  5618. GoodId: item.GoodId,
  5619. Status: 1,
  5620. Ctime: time.Now().Unix(),
  5621. Mtime: 0,
  5622. Count: 0,
  5623. StockCount: 0,
  5624. Creater: creater,
  5625. BatchNumberId: 0,
  5626. WarehouseOutId: 0,
  5627. }
  5628. service.CreateGoodErrcode(goodErrcode)
  5629. }
  5630. }
  5631. }
  5632. //
  5633. } else if err == nil {
  5634. for _, item := range consumables {
  5635. //出库
  5636. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5637. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5638. if err != nil {
  5639. goodErrcode := models.XtGoodErrcode{
  5640. UserOrgId: adminInfo.Org.Id,
  5641. Errcode: "自动出库接口报错",
  5642. GoodId: 0,
  5643. Status: 1,
  5644. Ctime: time.Now().Unix(),
  5645. Mtime: 0,
  5646. Count: 0,
  5647. StockCount: 0,
  5648. Creater: creator,
  5649. BatchNumberId: 0,
  5650. WarehouseOutId: 0,
  5651. }
  5652. service.CreateGoodErrcode(goodErrcode)
  5653. }
  5654. //出库数量相加
  5655. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5656. if errss != nil {
  5657. goodErrcode := models.XtGoodErrcode{
  5658. UserOrgId: item.UserOrgId,
  5659. Errcode: "创建剩余库存字段报错",
  5660. GoodId: item.GoodId,
  5661. Status: 1,
  5662. Ctime: time.Now().Unix(),
  5663. Mtime: time.Now().Unix(),
  5664. Count: 0,
  5665. StockCount: 0,
  5666. Creater: item.Creater,
  5667. BatchNumberId: 0,
  5668. WarehouseOutId: 0,
  5669. }
  5670. service.CreateGoodErrcode(goodErrcode)
  5671. }
  5672. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5673. if len(list) == 0 {
  5674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5675. return
  5676. }
  5677. for _, item := range list {
  5678. prepare := models.DialysisBeforePrepare{
  5679. UserOrgId: adminInfo.Org.Id,
  5680. PatientId: patient_id,
  5681. RecordDate: record_time,
  5682. GoodId: item.GoodId,
  5683. GoodTypeId: item.GoodTypeId,
  5684. Count: item.Count,
  5685. Creater: adminInfo.AdminUser.Id,
  5686. Status: 1,
  5687. Ctime: time.Now().Unix(),
  5688. StorehouseId: houseConfig.StorehouseOutInfo,
  5689. }
  5690. //清空准备表数据
  5691. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5692. if errs != nil {
  5693. goodErrcode := models.XtGoodErrcode{
  5694. UserOrgId: adminInfo.Org.Id,
  5695. Errcode: "自动出库清空准备表数据报错",
  5696. GoodId: 0,
  5697. Status: 1,
  5698. Ctime: time.Now().Unix(),
  5699. Mtime: 0,
  5700. Count: 0,
  5701. StockCount: 0,
  5702. Creater: creator,
  5703. BatchNumberId: 0,
  5704. WarehouseOutId: 0,
  5705. }
  5706. service.CreateGoodErrcode(goodErrcode)
  5707. }
  5708. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5709. if errcodes != nil {
  5710. goodErrcode := models.XtGoodErrcode{
  5711. UserOrgId: adminInfo.Org.Id,
  5712. Errcode: "自动出库创建准备表数据报错",
  5713. GoodId: 0,
  5714. Status: 1,
  5715. Ctime: time.Now().Unix(),
  5716. Mtime: 0,
  5717. Count: 0,
  5718. StockCount: 0,
  5719. Creater: creator,
  5720. BatchNumberId: 0,
  5721. WarehouseOutId: 0,
  5722. }
  5723. service.CreateGoodErrcode(goodErrcode)
  5724. }
  5725. //查询默认仓库
  5726. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5727. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5728. var total_count int64
  5729. for _, it := range stockList {
  5730. total_count += it.StockCount
  5731. }
  5732. //基础库插入数据
  5733. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5734. if errcodes != nil {
  5735. goodErrcode := models.XtGoodErrcode{
  5736. UserOrgId: adminInfo.Org.Id,
  5737. Errcode: "自动出库基础库插入数据报错",
  5738. GoodId: 0,
  5739. Status: 1,
  5740. Ctime: time.Now().Unix(),
  5741. Mtime: 0,
  5742. Count: 0,
  5743. StockCount: 0,
  5744. Creater: creator,
  5745. BatchNumberId: 0,
  5746. WarehouseOutId: 0,
  5747. }
  5748. service.CreateGoodErrcode(goodErrcode)
  5749. }
  5750. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5751. var flush_count int64
  5752. for _, it := range goodList {
  5753. flush_count += it.StockCount
  5754. }
  5755. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5756. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5757. if errss != nil {
  5758. goodErrcode := models.XtGoodErrcode{
  5759. UserOrgId: item.OrgId,
  5760. Errcode: "自动出库剩余库存更新数据",
  5761. GoodId: item.GoodId,
  5762. Status: 1,
  5763. Ctime: time.Now().Unix(),
  5764. Mtime: 0,
  5765. Count: 0,
  5766. StockCount: 0,
  5767. Creater: creater,
  5768. BatchNumberId: 0,
  5769. WarehouseOutId: 0,
  5770. }
  5771. service.CreateGoodErrcode(goodErrcode)
  5772. }
  5773. }
  5774. }
  5775. }
  5776. c.ServeSuccessJSON(map[string]interface{}{
  5777. "msg": "提交成功",
  5778. "message": "2",
  5779. "good_name": "",
  5780. "specification_name": "",
  5781. })
  5782. return
  5783. }
  5784. if record.IsOpen == 1 {
  5785. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5786. //查询是否有库存
  5787. for _, item := range consumables {
  5788. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5789. if item.Count > warehouse.Count {
  5790. goodErrcode := models.XtGoodErrcode{
  5791. UserOrgId: item.UserOrgId,
  5792. Errcode: "自动出库库存不足",
  5793. GoodId: item.GoodId,
  5794. Status: 1,
  5795. Ctime: time.Now().Unix(),
  5796. Mtime: 0,
  5797. Count: 0,
  5798. StockCount: 0,
  5799. Creater: creator,
  5800. BatchNumberId: warehouse.ID,
  5801. WarehouseOutId: 0,
  5802. }
  5803. service.CreateGoodErrcode(goodErrcode)
  5804. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5805. c.ServeSuccessJSON(map[string]interface{}{
  5806. "message": "1",
  5807. "good_name": goodObj.GoodName,
  5808. "specification_name": goodObj.SpecificationName,
  5809. })
  5810. return
  5811. }
  5812. }
  5813. //查询是否有出库单
  5814. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5815. if err == gorm.ErrRecordNotFound {
  5816. //没有记录,则创建出库单
  5817. timeStr := time.Now().Format("2006-01-02")
  5818. timeArr := strings.Split(timeStr, "-")
  5819. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5820. total = total + 1
  5821. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5822. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5823. number = number + total
  5824. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5825. creater := adminInfo.AdminUser.Id
  5826. warehouseOut := models.WarehouseOut{
  5827. WarehouseOutOrderNumber: warehousing_out_order,
  5828. OperationTime: time.Now().Unix(),
  5829. OrgId: adminInfo.Org.Id,
  5830. Creater: creater,
  5831. Ctime: time.Now().Unix(),
  5832. Status: 1,
  5833. WarehouseOutTime: record_time,
  5834. Dealer: 0,
  5835. Manufacturer: 0,
  5836. Type: 1,
  5837. IsSys: 1,
  5838. StorehouseId: houseConfig.StorehouseOutInfo,
  5839. IsCheck: 1,
  5840. }
  5841. err := service.AddSigleWarehouseOut(&warehouseOut)
  5842. if err != nil {
  5843. goodErrcode := models.XtGoodErrcode{
  5844. UserOrgId: adminInfo.Org.Id,
  5845. Errcode: "创建出库单失败",
  5846. GoodId: 0,
  5847. Status: 1,
  5848. Ctime: time.Now().Unix(),
  5849. Mtime: 0,
  5850. Count: 0,
  5851. StockCount: 0,
  5852. Creater: creator,
  5853. BatchNumberId: 0,
  5854. WarehouseOutId: 0,
  5855. }
  5856. service.CreateGoodErrcode(goodErrcode)
  5857. utils.TraceLog("创建出库单失败 err = %v", err)
  5858. } else {
  5859. for _, item := range consumables {
  5860. //出库
  5861. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5862. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5863. if err == nil {
  5864. goodErrcode := models.XtGoodErrcode{
  5865. UserOrgId: adminInfo.Org.Id,
  5866. Errcode: "自动出库接口报错",
  5867. GoodId: 0,
  5868. Status: 1,
  5869. Ctime: time.Now().Unix(),
  5870. Mtime: 0,
  5871. Count: 0,
  5872. StockCount: 0,
  5873. Creater: creator,
  5874. BatchNumberId: 0,
  5875. WarehouseOutId: 0,
  5876. }
  5877. service.CreateGoodErrcode(goodErrcode)
  5878. utils.TraceLog("创建出库单失败 err = %v", err)
  5879. }
  5880. //查询
  5881. //出库数量相加
  5882. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5883. if errs != nil {
  5884. goodErrcode := models.XtGoodErrcode{
  5885. UserOrgId: item.UserOrgId,
  5886. Errcode: "创建剩余库存字段报错",
  5887. GoodId: item.GoodId,
  5888. Status: 1,
  5889. Ctime: time.Now().Unix(),
  5890. Mtime: 0,
  5891. Count: 0,
  5892. StockCount: 0,
  5893. Creater: creater,
  5894. BatchNumberId: 0,
  5895. WarehouseOutId: 0,
  5896. }
  5897. service.CreateGoodErrcode(goodErrcode)
  5898. }
  5899. }
  5900. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5901. if len(list) == 0 {
  5902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5903. return
  5904. }
  5905. for _, item := range list {
  5906. prepare := models.DialysisBeforePrepare{
  5907. UserOrgId: adminInfo.Org.Id,
  5908. PatientId: patient_id,
  5909. RecordDate: record_time,
  5910. GoodId: item.GoodId,
  5911. GoodTypeId: item.GoodTypeId,
  5912. Count: item.Count,
  5913. Creater: adminInfo.AdminUser.Id,
  5914. Status: 1,
  5915. Ctime: time.Now().Unix(),
  5916. StorehouseId: houseConfig.StorehouseOutInfo,
  5917. }
  5918. //清空准备表数据
  5919. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5920. if err != nil {
  5921. goodErrcode := models.XtGoodErrcode{
  5922. UserOrgId: item.OrgId,
  5923. Errcode: "自动出库清空准备表数据报错",
  5924. GoodId: item.GoodId,
  5925. Status: 1,
  5926. Ctime: time.Now().Unix(),
  5927. Mtime: 0,
  5928. Count: 0,
  5929. StockCount: 0,
  5930. Creater: creater,
  5931. BatchNumberId: 0,
  5932. WarehouseOutId: 0,
  5933. }
  5934. service.CreateGoodErrcode(goodErrcode)
  5935. }
  5936. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5937. if errs != nil {
  5938. goodErrcode := models.XtGoodErrcode{
  5939. UserOrgId: item.OrgId,
  5940. Errcode: "自动出库创建准备表数据报错",
  5941. GoodId: item.GoodId,
  5942. Status: 1,
  5943. Ctime: time.Now().Unix(),
  5944. Mtime: 0,
  5945. Count: 0,
  5946. StockCount: 0,
  5947. Creater: creater,
  5948. BatchNumberId: 0,
  5949. WarehouseOutId: 0,
  5950. }
  5951. service.CreateGoodErrcode(goodErrcode)
  5952. }
  5953. //查询默认仓库
  5954. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5955. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5956. var total_count int64
  5957. for _, it := range stockList {
  5958. total_count += it.StockCount
  5959. }
  5960. //基础库插入数据
  5961. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5962. if errcodes != nil {
  5963. goodErrcode := models.XtGoodErrcode{
  5964. UserOrgId: item.OrgId,
  5965. Errcode: "自动出库基础库插入数据",
  5966. GoodId: item.GoodId,
  5967. Status: 1,
  5968. Ctime: time.Now().Unix(),
  5969. Mtime: 0,
  5970. Count: 0,
  5971. StockCount: 0,
  5972. Creater: creater,
  5973. BatchNumberId: 0,
  5974. WarehouseOutId: 0,
  5975. }
  5976. service.CreateGoodErrcode(goodErrcode)
  5977. }
  5978. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5979. var flush_count int64
  5980. for _, it := range goodList {
  5981. flush_count += it.StockCount
  5982. }
  5983. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5984. if errsss != nil {
  5985. goodErrcode := models.XtGoodErrcode{
  5986. UserOrgId: item.OrgId,
  5987. Errcode: "自动出库剩余库存更新数据",
  5988. GoodId: item.GoodId,
  5989. Status: 1,
  5990. Ctime: time.Now().Unix(),
  5991. Mtime: 0,
  5992. Count: 0,
  5993. StockCount: 0,
  5994. Creater: creater,
  5995. BatchNumberId: 0,
  5996. WarehouseOutId: 0,
  5997. }
  5998. service.CreateGoodErrcode(goodErrcode)
  5999. }
  6000. }
  6001. }
  6002. //
  6003. } else if err == nil {
  6004. for _, item := range consumables {
  6005. //出库
  6006. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6007. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6008. if err != nil {
  6009. goodErrcode := models.XtGoodErrcode{
  6010. UserOrgId: adminInfo.Org.Id,
  6011. Errcode: "自动出库接口报错",
  6012. GoodId: 0,
  6013. Status: 1,
  6014. Ctime: time.Now().Unix(),
  6015. Mtime: 0,
  6016. Count: 0,
  6017. StockCount: 0,
  6018. Creater: creator,
  6019. BatchNumberId: 0,
  6020. WarehouseOutId: 0,
  6021. }
  6022. service.CreateGoodErrcode(goodErrcode)
  6023. }
  6024. //出库数量相加
  6025. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6026. if errss != nil {
  6027. goodErrcode := models.XtGoodErrcode{
  6028. UserOrgId: item.UserOrgId,
  6029. Errcode: "创建剩余库存字段报错",
  6030. GoodId: item.GoodId,
  6031. Status: 1,
  6032. Ctime: time.Now().Unix(),
  6033. Mtime: time.Now().Unix(),
  6034. Count: 0,
  6035. StockCount: 0,
  6036. Creater: item.Creater,
  6037. BatchNumberId: 0,
  6038. WarehouseOutId: 0,
  6039. }
  6040. service.CreateGoodErrcode(goodErrcode)
  6041. }
  6042. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6043. if len(list) == 0 {
  6044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6045. return
  6046. }
  6047. for _, item := range list {
  6048. prepare := models.DialysisBeforePrepare{
  6049. UserOrgId: adminInfo.Org.Id,
  6050. PatientId: patient_id,
  6051. RecordDate: record_time,
  6052. GoodId: item.GoodId,
  6053. GoodTypeId: item.GoodTypeId,
  6054. Count: item.Count,
  6055. Creater: adminInfo.AdminUser.Id,
  6056. Status: 1,
  6057. Ctime: time.Now().Unix(),
  6058. StorehouseId: houseConfig.StorehouseOutInfo,
  6059. }
  6060. //清空准备表数据
  6061. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6062. if errs != nil {
  6063. goodErrcode := models.XtGoodErrcode{
  6064. UserOrgId: adminInfo.Org.Id,
  6065. Errcode: "自动出库清空准备表数据报错",
  6066. GoodId: 0,
  6067. Status: 1,
  6068. Ctime: time.Now().Unix(),
  6069. Mtime: 0,
  6070. Count: 0,
  6071. StockCount: 0,
  6072. Creater: creator,
  6073. BatchNumberId: 0,
  6074. WarehouseOutId: 0,
  6075. }
  6076. service.CreateGoodErrcode(goodErrcode)
  6077. }
  6078. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6079. if errcodes != nil {
  6080. goodErrcode := models.XtGoodErrcode{
  6081. UserOrgId: adminInfo.Org.Id,
  6082. Errcode: "自动出库创建准备表数据报错",
  6083. GoodId: 0,
  6084. Status: 1,
  6085. Ctime: time.Now().Unix(),
  6086. Mtime: 0,
  6087. Count: 0,
  6088. StockCount: 0,
  6089. Creater: creator,
  6090. BatchNumberId: 0,
  6091. WarehouseOutId: 0,
  6092. }
  6093. service.CreateGoodErrcode(goodErrcode)
  6094. }
  6095. //查询默认仓库
  6096. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6097. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6098. var total_count int64
  6099. for _, it := range stockList {
  6100. total_count += it.StockCount
  6101. }
  6102. //基础库插入数据
  6103. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6104. if errcodes != nil {
  6105. goodErrcode := models.XtGoodErrcode{
  6106. UserOrgId: adminInfo.Org.Id,
  6107. Errcode: "自动出库基础库插入数据报错",
  6108. GoodId: 0,
  6109. Status: 1,
  6110. Ctime: time.Now().Unix(),
  6111. Mtime: 0,
  6112. Count: 0,
  6113. StockCount: 0,
  6114. Creater: creator,
  6115. BatchNumberId: 0,
  6116. WarehouseOutId: 0,
  6117. }
  6118. service.CreateGoodErrcode(goodErrcode)
  6119. }
  6120. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6121. var flush_count int64
  6122. for _, it := range goodList {
  6123. flush_count += it.StockCount
  6124. }
  6125. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6126. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6127. if errss != nil {
  6128. goodErrcode := models.XtGoodErrcode{
  6129. UserOrgId: item.OrgId,
  6130. Errcode: "自动出库剩余库存更新数据",
  6131. GoodId: item.GoodId,
  6132. Status: 1,
  6133. Ctime: time.Now().Unix(),
  6134. Mtime: 0,
  6135. Count: 0,
  6136. StockCount: 0,
  6137. Creater: creater,
  6138. BatchNumberId: 0,
  6139. WarehouseOutId: 0,
  6140. }
  6141. service.CreateGoodErrcode(goodErrcode)
  6142. }
  6143. }
  6144. }
  6145. }
  6146. c.ServeSuccessJSON(map[string]interface{}{
  6147. "msg": "提交成功",
  6148. "message": "2",
  6149. "good_name": "",
  6150. "specification_name": "",
  6151. })
  6152. return
  6153. } else {
  6154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6155. return
  6156. }
  6157. }
  6158. func (c *DialysisAPIController) EditConsumables() {
  6159. patient_id, _ := c.GetInt64("patient_id", 0)
  6160. record_date := c.GetString("record_time")
  6161. if patient_id <= 0 {
  6162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6163. return
  6164. }
  6165. adminInfo := c.GetMobileAdminUserInfo()
  6166. timeLayout := "2006-01-02"
  6167. loc, _ := time.LoadLocation("Local")
  6168. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6169. record_time := theRecordTime.Unix()
  6170. // 查询信息规挡的设置天数
  6171. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6172. if infor.ID > 0 && infor.WeekDay > 0 {
  6173. var cha_time int64
  6174. timeNowStr := time.Now().Format("2006-01-02")
  6175. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6176. //今日的日期减去设置的日期
  6177. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6178. if cha_time >= record_time {
  6179. //查询审核是否允许
  6180. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6181. //申请状态不允许的情况 拒绝修改
  6182. if infor.ApplicationStatus != 1 {
  6183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6184. return
  6185. }
  6186. }
  6187. }
  6188. dataBody := make(map[string]interface{}, 0)
  6189. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6190. if err != nil {
  6191. utils.ErrorLog(err.Error())
  6192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6193. return
  6194. }
  6195. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6196. var beforePrepares []*models.DialysisBeforePrepareGoods
  6197. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6198. var cancelbefor []*models.DialysisBeforePrepareGoods
  6199. var outbefor []*models.DialysisBeforePrepareGoods
  6200. //判断是否开启自动出库
  6201. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6202. if record.IsOpen == 1 {
  6203. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6204. goods, _ := dataBody["goods"].([]interface{})
  6205. if len(goods) > 0 {
  6206. for _, item := range goods {
  6207. items := item.(map[string]interface{})
  6208. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6209. utils.ErrorLog("good_id")
  6210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6211. return
  6212. }
  6213. good_id := int64(items["good_id"].(float64))
  6214. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6215. utils.ErrorLog("good_type_id")
  6216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6217. return
  6218. }
  6219. good_type_id := int64(items["good_type_id"].(float64))
  6220. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6221. utils.ErrorLog("count")
  6222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6223. return
  6224. }
  6225. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6226. commdity_code := items["commdity_code"].(string)
  6227. fmt.Println(commdity_code)
  6228. prepareGoods := &models.DialysisBeforePrepareGoods{
  6229. GoodTypeId: good_type_id,
  6230. GoodId: good_id,
  6231. Count: count,
  6232. StorehouseId: houseConfig.StorehouseOutInfo,
  6233. }
  6234. beforePrepares = append(beforePrepares, prepareGoods)
  6235. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6236. GoodTypeId: good_type_id,
  6237. GoodId: good_id,
  6238. Count: count,
  6239. StorehouseId: houseConfig.StorehouseOutInfo,
  6240. }
  6241. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6242. }
  6243. for _, item := range beforePrepares {
  6244. //1.查看该患者该耗材型号最后一次出库数量
  6245. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6246. //判断当前出库数量和最后一次出库数量的大小
  6247. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6248. if item.Count < goodInfo.Count {
  6249. cancelbefor = append(cancelbefor, item)
  6250. }
  6251. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6252. if item.Count > goodInfo.Count {
  6253. outbefor = append(outbefor, item)
  6254. }
  6255. //处理编辑耗材新增不了的问题
  6256. if goodInfo.Count == item.Count {
  6257. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6258. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6259. }
  6260. }
  6261. if len(cancelbefor) > 0 {
  6262. //退库
  6263. for _, item := range cancelbefor {
  6264. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6265. creater := adminInfo.AdminUser.Id
  6266. //查询该患者当天已经出库的耗材信息
  6267. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6268. var delete_count int64 = 0
  6269. delete_count = warehouseOutInfos.Count - item.Count
  6270. //增加库存数量
  6271. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6272. //减少实际出库库存数量
  6273. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6274. // 删除出库完成后,要增加对应批次的库存数量
  6275. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6276. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6277. //更新剩余库存
  6278. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6279. var flush_count int64
  6280. for _, it := range goodListOne {
  6281. flush_count += it.StockCount
  6282. }
  6283. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6284. //查询剩余库存
  6285. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6286. var sum_count int64
  6287. for _, item := range goodList {
  6288. sum_count += item.StockCount
  6289. }
  6290. // 在出库记录表里记录退库详情
  6291. warehouseOutInfo := &models.WarehouseOutInfo{
  6292. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6293. WarehouseOutId: warehouseOut.ID,
  6294. Status: 1,
  6295. Ctime: time.Now().Unix(),
  6296. OrgId: adminInfo.Org.Id,
  6297. Type: 1,
  6298. IsSys: 1,
  6299. SysRecordTime: record_time,
  6300. GoodTypeId: item.GoodTypeId,
  6301. GoodId: item.GoodId,
  6302. PatientId: patient_id,
  6303. ConsumableType: 2,
  6304. StorehouseId: houseConfig.StorehouseOutInfo,
  6305. IsCheck: 1,
  6306. OverCount: sum_count,
  6307. }
  6308. warehouseOutInfo.Count = item.Count
  6309. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6310. warehouseOutInfo.Price = stockInInfo.Price
  6311. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6312. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6313. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6314. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6315. warehouseOutInfo.Number = warehouseOutInfos.Number
  6316. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6317. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6318. //查找当天是否存在出库记录
  6319. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6320. if errcod == gorm.ErrRecordNotFound {
  6321. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6322. //插入详情明细表
  6323. stockFlow := models.VmStockFlow{
  6324. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6325. WarehouseOutId: warehouseOut.ID,
  6326. GoodId: item.GoodId,
  6327. Number: warehouseOutInfos.Number,
  6328. ProductDate: stockInInfo.ProductDate,
  6329. ExpireDate: stockInInfo.ExpiryDate,
  6330. Count: item.Count,
  6331. Price: stockInInfo.Price,
  6332. Status: 1,
  6333. Ctime: time.Now().Unix(),
  6334. UserOrgId: adminInfo.Org.Id,
  6335. Manufacturer: stockInInfo.Manufacturer,
  6336. Dealer: stockInInfo.Dealer,
  6337. LicenseNumber: stockInInfo.LicenseNumber,
  6338. IsEdit: 2,
  6339. Creator: creater,
  6340. SystemTime: record_time,
  6341. ConsumableType: 3,
  6342. WarehousingDetailId: 0,
  6343. IsSys: 1,
  6344. UpdateCreator: creater,
  6345. PatientId: patient_id,
  6346. StorehouseId: houseConfig.StorehouseOutInfo,
  6347. }
  6348. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6349. if errflow == gorm.ErrRecordNotFound {
  6350. //创建流水表
  6351. err := service.CreateStockFlowOne(stockFlow)
  6352. fmt.Println("err", err)
  6353. } else if errflow == nil {
  6354. //插入详情明细表
  6355. stockFlow := models.VmStockFlow{
  6356. ID: exsit.ID,
  6357. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6358. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6359. WarehouseOutId: warehouseOut.ID,
  6360. GoodId: item.GoodId,
  6361. Number: warehouseOutInfos.Number,
  6362. ProductDate: stockInInfo.ProductDate,
  6363. ExpireDate: stockInInfo.ExpiryDate,
  6364. Count: exsit.Count - delete_count,
  6365. Price: stockInInfo.Price,
  6366. Status: 1,
  6367. Ctime: time.Now().Unix(),
  6368. UserOrgId: adminInfo.Org.Id,
  6369. Manufacturer: stockInInfo.Manufacturer,
  6370. Dealer: stockInInfo.Dealer,
  6371. LicenseNumber: stockInInfo.LicenseNumber,
  6372. IsEdit: 2,
  6373. Creator: creater,
  6374. SystemTime: record_time,
  6375. ConsumableType: 3,
  6376. WarehousingDetailId: 0,
  6377. IsSys: 1,
  6378. UpdateCreator: creater,
  6379. PatientId: patient_id,
  6380. StorehouseId: houseConfig.StorehouseOutInfo,
  6381. }
  6382. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6383. }
  6384. } else if errcod == nil {
  6385. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6386. //查询剩余库存
  6387. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6388. var sum_count int64
  6389. for _, item := range goodList {
  6390. sum_count += item.StockCount
  6391. }
  6392. //创建退库单,生成退库数据
  6393. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6394. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6395. operation_time := time.Now().Unix()
  6396. creater := adminInfo.AdminUser.Id
  6397. //创建退库单
  6398. timeStr := time.Now().Format("2006-01-02")
  6399. timeArr := strings.Split(timeStr, "-")
  6400. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6401. total = total + 1
  6402. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6403. cancelStock := models.CancelStock{
  6404. OrderNumber: orderNumber,
  6405. OperaTime: operation_time,
  6406. OrgId: adminInfo.Org.Id,
  6407. Creater: creater,
  6408. Ctime: time.Now().Unix(),
  6409. Status: 1,
  6410. ReturnTime: record_time,
  6411. Type: 1,
  6412. StorehouseId: houseConfig.StorehouseOutInfo,
  6413. IsCheck: 1,
  6414. }
  6415. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6416. if msgerrkonde == gorm.ErrRecordNotFound {
  6417. service.AddSigleCancelStock(&cancelStock)
  6418. }
  6419. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6420. //查询是否有出库
  6421. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6422. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6423. deaerler, _ := service.GetDealerById(info.Dealer)
  6424. if info.ID > 0 {
  6425. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6426. cancelStockInfo := models.CancelStockInfo{
  6427. GoodId: item.GoodId,
  6428. CancelStockId: cancel.ID,
  6429. GoodTypeId: good.GoodTypeId,
  6430. Count: delete_count,
  6431. Price: info.Price,
  6432. Total: 0,
  6433. ProductDate: info.ProductDate,
  6434. ExpiryDate: info.ExpiryDate,
  6435. Ctime: time.Now().Unix(),
  6436. Status: 1,
  6437. OrgId: adminInfo.Org.Id,
  6438. OrderNumber: cancel.OrderNumber,
  6439. Type: 0,
  6440. Dealer: deaerler.DealerName,
  6441. Manufacturer: manufacturer.ManufacturerName,
  6442. Number: info.Number,
  6443. RegisterAccount: "",
  6444. Remark: "",
  6445. WarehouseInfoId: info.WarehouseInfotId,
  6446. PatientId: info.PatientId,
  6447. RecordDate: info.SysRecordTime,
  6448. StorehouseId: houseConfig.StorehouseOutInfo,
  6449. IsCheck: 1,
  6450. }
  6451. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6452. //退库数量增加
  6453. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6454. //查询剩余库存
  6455. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6456. var over_count int64
  6457. for _, it := range goodList {
  6458. over_count += it.StockCount
  6459. }
  6460. flow := models.VmStockFlow{
  6461. WarehousingId: info.WarehouseInfotId,
  6462. GoodId: item.GoodId,
  6463. Number: info.Number,
  6464. LicenseNumber: info.LicenseNumber,
  6465. Count: delete_count,
  6466. UserOrgId: adminInfo.Org.Id,
  6467. PatientId: patient_id,
  6468. SystemTime: info.SysRecordTime,
  6469. ConsumableType: 7,
  6470. IsSys: 0,
  6471. WarehousingOrder: "",
  6472. WarehouseOutId: info.WarehouseOutId,
  6473. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6474. IsEdit: 0,
  6475. CancelStockId: cancel.ID,
  6476. CancelOrderNumber: cancel.OrderNumber,
  6477. Manufacturer: manufacturer.ID,
  6478. Dealer: 0,
  6479. Creator: adminInfo.AdminUser.Id,
  6480. UpdateCreator: 0,
  6481. Status: 1,
  6482. Ctime: time.Now().Unix(),
  6483. Mtime: 0,
  6484. Price: info.Price,
  6485. WarehousingDetailId: info.WarehouseInfotId,
  6486. WarehouseOutDetailId: info.ID,
  6487. CancelOutDetailId: cancelInfo.ID,
  6488. ProductDate: info.ProductDate,
  6489. ExpireDate: info.ExpiryDate,
  6490. StorehouseId: houseConfig.StorehouseOutInfo,
  6491. OverCount: over_count,
  6492. }
  6493. service.CreateStockFlowOne(flow)
  6494. }
  6495. }
  6496. //更改自动出库的表格
  6497. details := models.BloodAutomaticReduceDetail{
  6498. WarehouseOutId: warehouseOutInfo.ID,
  6499. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6500. PatientId: patient_id,
  6501. Ctime: time.Now().Unix(),
  6502. Mtime: time.Now().Unix(),
  6503. Status: 1,
  6504. RecordTime: record_time,
  6505. OrgId: adminInfo.Org.Id,
  6506. GoodId: item.GoodId,
  6507. GoodTypeId: item.GoodTypeId,
  6508. Count: item.Count,
  6509. StorehouseId: houseConfig.StorehouseOutInfo,
  6510. }
  6511. //查询当天耗材是否已经存在数据
  6512. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6513. if errcode == gorm.ErrRecordNotFound {
  6514. service.CreateAutoReduceRecord(&details)
  6515. } else if errcode == nil {
  6516. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6517. service.CreateAutoReduceRecord(&details)
  6518. }
  6519. //查询默认仓库
  6520. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6521. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6522. var total_count int64
  6523. for _, it := range stockList {
  6524. total_count += it.StockCount
  6525. }
  6526. //基础库插入数据
  6527. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6528. }
  6529. }
  6530. if len(outbefor) > 0 {
  6531. //出库
  6532. for _, item := range outbefor {
  6533. var last_total int64
  6534. //1.查看该患者该耗材型号最后一次出库数量
  6535. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6536. //计算当前出库和最后一次出库数据相差数据
  6537. last_total = item.Count - goodInfoOne.Count
  6538. //查询该耗材的总库存
  6539. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6540. // 如果库存差大于剩余库存则提示库存不足
  6541. if last_total > wareinfo.StockCount {
  6542. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6543. c.ServeSuccessJSON(map[string]interface{}{
  6544. "message": "1",
  6545. "good_name": goodObj.GoodName,
  6546. "specification_name": goodObj.SpecificationName,
  6547. })
  6548. return
  6549. } else {
  6550. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6551. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6552. if err == gorm.ErrRecordNotFound {
  6553. //没有记录,则创建出库单
  6554. timeStr := time.Now().Format("2006-01-02")
  6555. timeArr := strings.Split(timeStr, "-")
  6556. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6557. total = total + 1
  6558. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6559. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6560. number = number + total
  6561. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6562. warehouseOut := models.WarehouseOut{
  6563. WarehouseOutOrderNumber: warehousing_out_order,
  6564. OperationTime: time.Now().Unix(),
  6565. OrgId: adminInfo.Org.Id,
  6566. Creater: adminInfo.AdminUser.Id,
  6567. Ctime: time.Now().Unix(),
  6568. Status: 1,
  6569. WarehouseOutTime: record_time,
  6570. Dealer: 0,
  6571. Manufacturer: 0,
  6572. Type: 1,
  6573. IsSys: 1,
  6574. StorehouseId: houseConfig.StorehouseOutInfo,
  6575. IsCheck: 1,
  6576. }
  6577. service.AddSigleWarehouseOut(&warehouseOut)
  6578. }
  6579. //出库
  6580. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6581. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6582. //1.查看该患者该耗材型号最后一次出库数量
  6583. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6584. prepare := models.DialysisBeforePrepare{
  6585. UserOrgId: adminInfo.Org.Id,
  6586. PatientId: patient_id,
  6587. RecordDate: record_time,
  6588. GoodId: item.GoodId,
  6589. GoodTypeId: item.GoodTypeId,
  6590. Count: item.Count - goodInfoTwo.Count,
  6591. Ctime: time.Now().Unix(),
  6592. Mtime: 0,
  6593. Creater: adminInfo.AdminUser.Id,
  6594. Modifier: adminInfo.AdminUser.Id,
  6595. Status: 1,
  6596. CommdityCode: "",
  6597. NewCount: 0,
  6598. ProjectId: 0,
  6599. StorehouseId: houseConfig.StorehouseOutInfo,
  6600. }
  6601. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6602. //增加出库数量
  6603. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6604. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6605. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6606. var total_count int64
  6607. for _, it := range stockList {
  6608. total_count += it.StockCount
  6609. }
  6610. //基础库插入数据
  6611. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6612. //剩余库存
  6613. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6614. var flush_count int64
  6615. for _, it := range goodList {
  6616. flush_count += it.StockCount
  6617. }
  6618. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6619. }
  6620. }
  6621. }
  6622. //查询今日出库数据
  6623. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6624. for _, it := range list {
  6625. prepare := models.DialysisBeforePrepare{
  6626. UserOrgId: it.OrgId,
  6627. PatientId: patient_id,
  6628. RecordDate: it.RecordTime,
  6629. GoodId: it.GoodId,
  6630. GoodTypeId: it.GoodTypeId,
  6631. Count: it.Count,
  6632. Ctime: time.Now().Unix(),
  6633. Creater: adminInfo.AdminUser.Id,
  6634. Status: 1,
  6635. StorehouseId: houseConfig.StorehouseOutInfo,
  6636. ProjectId: it.ProjectId,
  6637. }
  6638. //删除准备表数据
  6639. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6640. service.CreateDialysisBeforePrepareOne(&prepare)
  6641. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6642. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6643. var total_count int64
  6644. for _, it := range stockList {
  6645. total_count += it.StockCount
  6646. }
  6647. //基础库插入数据
  6648. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6649. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6650. var flush_count int64
  6651. for _, it := range goodList {
  6652. flush_count += it.StockCount
  6653. }
  6654. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6655. }
  6656. }
  6657. }
  6658. //更新自动出库的地方
  6659. var errs error
  6660. if errs == nil {
  6661. c.ServeSuccessJSON(map[string]interface{}{
  6662. "msg": "修改成功",
  6663. "message": "2",
  6664. "good_name": "",
  6665. "specification_name": "",
  6666. })
  6667. return
  6668. } else {
  6669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6670. return
  6671. }
  6672. }
  6673. }
  6674. func (c *DialysisAPIController) GetDialysisGoods() {
  6675. schedualDate := c.GetString("schedule_date")
  6676. schedule_type, _ := c.GetInt64("schedule_type")
  6677. partition_id, _ := c.GetInt64("partition_id")
  6678. page, _ := c.GetInt("page")
  6679. patient_id, _ := c.GetInt64("patient_id")
  6680. schedualEndDate := int64(0)
  6681. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6682. if parseDateErr != nil && len(schedualDate) != 0 {
  6683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6684. return
  6685. }
  6686. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6687. if parseDateErr != nil && len(schedualDate) != 0 {
  6688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6689. return
  6690. }
  6691. schedualEndDate = endDate.Unix()
  6692. adminUser := c.GetMobileAdminUserInfo()
  6693. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6694. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6695. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6696. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6697. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6698. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6699. //获取当天该病人的透析处方
  6700. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6701. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6702. if err == gorm.ErrRecordNotFound {
  6703. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6704. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6705. if patient_id != 0 {
  6706. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6707. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6708. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6709. //获取患者总的出库数据
  6710. item.LastAutomaticReduceDetail = goodUser
  6711. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6712. item.Project = project
  6713. }
  6714. }
  6715. c.ServeSuccessJSON(map[string]interface{}{
  6716. "dialysis_goods": dialysisGoods,
  6717. "good_type": goodTypes,
  6718. "total": total,
  6719. "prescribe": prescribe,
  6720. "good_info": good_info,
  6721. "warehouseOutList": warehouseOutList,
  6722. "config": config,
  6723. "outConfig": outConfig,
  6724. "settleConfig": settleConfig,
  6725. })
  6726. return
  6727. } else if err == nil {
  6728. //获取当天排班的每个患者的库存使用情况
  6729. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6730. //获取患者总的出库数据
  6731. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6732. if patient_id != 0 {
  6733. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6734. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6735. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6736. item.Project = project
  6737. item.LastAutomaticReduceDetail = goodUser
  6738. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6739. }
  6740. }
  6741. if err == nil {
  6742. c.ServeSuccessJSON(map[string]interface{}{
  6743. "dialysis_goods": dialysisGoods,
  6744. "good_type": goodTypes,
  6745. "total": total,
  6746. "prescribe": prescribe,
  6747. "good_info": good_info,
  6748. "project": project,
  6749. "warehouseOutList": warehouseOutList,
  6750. "config": config,
  6751. "outConfig": outConfig,
  6752. "settleConfig": settleConfig,
  6753. })
  6754. return
  6755. } else {
  6756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6757. return
  6758. }
  6759. } else if err != nil {
  6760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6761. return
  6762. }
  6763. }
  6764. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6765. start_time := c.GetString("start_time")
  6766. end_time := c.GetString("end_time")
  6767. timeLayout := "2006-01-02"
  6768. loc, _ := time.LoadLocation("Local")
  6769. var theStartTime int64
  6770. if len(start_time) > 0 {
  6771. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6772. if err != nil {
  6773. utils.ErrorLog(err.Error())
  6774. }
  6775. theStartTime = theTime.Unix()
  6776. }
  6777. var theEndtTime int64
  6778. if len(end_time) > 0 {
  6779. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6780. if err != nil {
  6781. utils.ErrorLog(err.Error())
  6782. }
  6783. theEndtTime = theTime.Unix()
  6784. }
  6785. adminUser := c.GetMobileAdminUserInfo()
  6786. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6787. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6788. if err == nil {
  6789. c.ServeSuccessJSON(map[string]interface{}{
  6790. "stock_out": outInfo,
  6791. "stockCount": stockCount,
  6792. })
  6793. return
  6794. } else {
  6795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6796. return
  6797. }
  6798. }
  6799. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6800. patient_id, _ := c.GetInt64("patient_id", 0)
  6801. record_time := c.GetString("record_time")
  6802. adminUser := c.GetMobileAdminUserInfo()
  6803. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6804. if parseDateErr != nil && len(record_time) != 0 {
  6805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6806. return
  6807. }
  6808. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6809. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6810. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6811. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6812. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6813. //获取今日患者的透析处方参数
  6814. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6815. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6816. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6817. c.ServeSuccessJSON(map[string]interface{}{
  6818. "good_type": goodTypes,
  6819. "good_user": goodUser,
  6820. "good_info": good_info,
  6821. "last_good_user": lastGoodUserDetial,
  6822. "project": project,
  6823. "prescription": prescribe,
  6824. "outInfo": outInfo,
  6825. "configs": configs,
  6826. })
  6827. return
  6828. }
  6829. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6830. patient_id, _ := c.GetInt64("patient_id", 0)
  6831. record_date := c.GetString("record_time")
  6832. timeLayout := "2006-01-02"
  6833. loc, _ := time.LoadLocation("Local")
  6834. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6835. record_time := theRecordTime.Unix()
  6836. adminInfo := c.GetMobileAdminUserInfo()
  6837. dataBody := make(map[string]interface{}, 0)
  6838. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6839. if err != nil {
  6840. utils.ErrorLog(err.Error())
  6841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6842. return
  6843. }
  6844. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6845. var beforePrepares []*models.DialysisBeforePrepareGoods
  6846. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6847. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6848. goods, _ := dataBody["goods"].([]interface{})
  6849. if len(goods) > 0 {
  6850. for _, item := range goods {
  6851. items := item.(map[string]interface{})
  6852. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6853. utils.ErrorLog("good_id")
  6854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6855. return
  6856. }
  6857. good_id := int64(items["good_id"].(float64))
  6858. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6859. utils.ErrorLog("good_type_id")
  6860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6861. return
  6862. }
  6863. good_type_id := int64(items["good_type_id"].(float64))
  6864. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6865. utils.ErrorLog("count")
  6866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6867. return
  6868. }
  6869. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6870. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6871. utils.ErrorLog("project_id")
  6872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6873. return
  6874. }
  6875. project_id := int64(items["project_id"].(float64))
  6876. new_count := int64(items["new_count"].(float64))
  6877. old_count := int64(items["old_count"].(float64))
  6878. prepare := &models.DialysisBeforePrepareGoods{
  6879. GoodId: good_id,
  6880. GoodTypeId: good_type_id,
  6881. Count: count,
  6882. ProjectId: project_id,
  6883. StorehouseId: houseConfig.StorehouseOutInfo,
  6884. NewCount: new_count,
  6885. OldCount: old_count,
  6886. }
  6887. beforePrepares = append(beforePrepares, prepare)
  6888. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6889. GoodId: good_id,
  6890. GoodTypeId: good_type_id,
  6891. Count: count,
  6892. ProjectId: project_id,
  6893. StorehouseId: houseConfig.StorehouseOutInfo,
  6894. NewCount: new_count,
  6895. OldCount: old_count,
  6896. }
  6897. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6898. }
  6899. }
  6900. }
  6901. //查询是否有库存
  6902. for _, item := range beforePrepares {
  6903. if item.NewCount > 0 {
  6904. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6905. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6906. if item.Count > warehouse.Count {
  6907. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6908. c.ServeSuccessJSON(map[string]interface{}{
  6909. "message": "1",
  6910. "good_name": goodObj.GoodName,
  6911. "specification_name": goodObj.SpecificationName,
  6912. })
  6913. return
  6914. }
  6915. }
  6916. }
  6917. // 查询信息规挡的设置天数
  6918. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6919. if infor.ID > 0 && infor.WeekDay > 0 {
  6920. var cha_time int64
  6921. timeNowStr := time.Now().Format("2006-01-02")
  6922. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6923. //今日的日期减去设置的日期
  6924. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6925. if cha_time >= record_time {
  6926. //查询审核是否允许
  6927. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6928. //申请状态不允许的情况 拒绝修改
  6929. if infor.ApplicationStatus != 1 {
  6930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6931. return
  6932. }
  6933. }
  6934. }
  6935. //出库逻辑
  6936. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6937. if err != nil {
  6938. utils.ErrorLog(err.Error())
  6939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6940. return
  6941. }
  6942. finish := models.XtDialysisFinish{
  6943. IsFinish: 1,
  6944. UserOrgId: adminInfo.Org.Id,
  6945. Status: 1,
  6946. Ctime: time.Now().Unix(),
  6947. Mtime: 0,
  6948. Module: 11,
  6949. RecordDate: record_time,
  6950. Sourse: 1,
  6951. PatientId: patient_id,
  6952. }
  6953. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6954. if dialysisFinish.ID == 0 {
  6955. service.CreateDialysisFinish(finish)
  6956. }
  6957. //查询当天出库的数据
  6958. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6959. for _, item := range list {
  6960. prepare := models.DialysisBeforePrepare{
  6961. UserOrgId: item.OrgId,
  6962. PatientId: item.PatientId,
  6963. RecordDate: item.RecordTime,
  6964. GoodId: item.GoodId,
  6965. GoodTypeId: item.GoodTypeId,
  6966. Count: item.Count,
  6967. Creater: adminInfo.AdminUser.Id,
  6968. Status: 1,
  6969. Ctime: time.Now().Unix(),
  6970. ProjectId: item.ProjectId,
  6971. StorehouseId: houseConfig.StorehouseOutInfo,
  6972. }
  6973. //清空准备表的数据
  6974. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6975. //插入准备表数据
  6976. service.CreateDialysisBeforePrepareOne(&prepare)
  6977. //查询默认仓库
  6978. //查询默认仓库
  6979. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6980. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6981. var total_count int64
  6982. for _, it := range stockList {
  6983. total_count += it.StockCount
  6984. }
  6985. //基础库插入数据
  6986. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6987. ////更新剩余库存
  6988. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6989. var flush_count int64
  6990. for _, it := range goodList {
  6991. flush_count += it.StockCount
  6992. }
  6993. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6994. if errs != nil {
  6995. goodErrcode := models.XtGoodErrcode{
  6996. UserOrgId: item.OrgId,
  6997. Errcode: "手动出库更新剩余出库失败",
  6998. GoodId: item.GoodId,
  6999. Status: 1,
  7000. Ctime: time.Now().Unix(),
  7001. Mtime: 0,
  7002. Count: 0,
  7003. StockCount: 0,
  7004. Creater: adminInfo.AdminUser.Id,
  7005. BatchNumberId: 0,
  7006. WarehouseOutId: 0,
  7007. }
  7008. service.CreateGoodErrcode(goodErrcode)
  7009. }
  7010. }
  7011. //更新自动出库的地方
  7012. var errs error
  7013. if errs == nil {
  7014. c.ServeSuccessJSON(map[string]interface{}{
  7015. "msg": "修改成功",
  7016. "message": "2",
  7017. "good_name": "",
  7018. "specification_name": "",
  7019. })
  7020. return
  7021. } else {
  7022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7023. return
  7024. }
  7025. }
  7026. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7027. newArr = make([]*models.DialysisBeforePrepare, 0)
  7028. for i := 0; i < len(arr); i++ {
  7029. repeat := false
  7030. for j := i + 1; j < len(arr); j++ {
  7031. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7032. repeat = true
  7033. break
  7034. }
  7035. }
  7036. if !repeat {
  7037. newArr = append(newArr, arr[i])
  7038. }
  7039. }
  7040. return
  7041. }
  7042. func (c *DialysisAPIController) GetAllDrug() {
  7043. patient_id, _ := c.GetInt64("patient_id", 0)
  7044. adminInfo := c.GetMobileAdminUserInfo()
  7045. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7046. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7047. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7048. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7049. c.ServeSuccessJSON(map[string]interface{}{
  7050. "base_drug_config": drugStockConfig,
  7051. "private_drug_config": privateDrugConfig,
  7052. "base_drug_list": drugList,
  7053. "private_drug_list": privateDrugList,
  7054. })
  7055. }
  7056. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7057. newArr = make([]*models.DialysisBeforePrepare, 0)
  7058. for i := 0; i < len(arr); i++ {
  7059. repeat := false
  7060. for j := i + 1; j < len(arr); j++ {
  7061. if arr[i].GoodId == arr[j].GoodId {
  7062. repeat = true
  7063. break
  7064. }
  7065. }
  7066. if !repeat {
  7067. newArr = append(newArr, arr[i])
  7068. }
  7069. }
  7070. return
  7071. }
  7072. func (c *DialysisAPIController) GetDepartment() {
  7073. adminInfo := c.GetMobileAdminUserInfo()
  7074. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7075. if err == nil {
  7076. c.ServeSuccessJSON(map[string]interface{}{
  7077. "departments": departments,
  7078. })
  7079. } else {
  7080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7081. return
  7082. }
  7083. }
  7084. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7085. types, _ := c.GetInt("type", 0)
  7086. start_time := c.GetString("start_time")
  7087. end_time := c.GetString("end_time")
  7088. orgId := c.GetMobileAdminUserInfo().Org.Id
  7089. timeLayout := "2006-01-02"
  7090. loc, _ := time.LoadLocation("Local")
  7091. var startTime int64
  7092. if len(start_time) > 0 {
  7093. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7094. if err != nil {
  7095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7096. return
  7097. }
  7098. startTime = theTime.Unix()
  7099. }
  7100. var endTime int64
  7101. if len(end_time) > 0 {
  7102. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7103. if err != nil {
  7104. utils.ErrorLog(err.Error())
  7105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7106. return
  7107. }
  7108. endTime = theTime.Unix()
  7109. }
  7110. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7111. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7112. if err != nil {
  7113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7114. } else {
  7115. c.ServeSuccessJSON(map[string]interface{}{
  7116. "list": list,
  7117. "type": types,
  7118. "stockTotal": stockTotal,
  7119. })
  7120. }
  7121. }
  7122. func (c *DialysisAPIController) GetPrescriptionList() {
  7123. start_time := c.GetString("start_time")
  7124. end_time := c.GetString("end_time")
  7125. schedule_type, _ := c.GetInt64("schedule_type")
  7126. partion_id, _ := c.GetInt64("partion_id")
  7127. orgId := c.GetMobileAdminUserInfo().Org.Id
  7128. timeLayout := "2006-01-02"
  7129. loc, _ := time.LoadLocation("Local")
  7130. var startTime int64
  7131. if len(start_time) > 0 {
  7132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7133. if err != nil {
  7134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7135. return
  7136. }
  7137. startTime = theTime.Unix()
  7138. }
  7139. var endTime int64
  7140. if len(end_time) > 0 {
  7141. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7142. if err != nil {
  7143. utils.ErrorLog(err.Error())
  7144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7145. return
  7146. }
  7147. endTime = theTime.Unix()
  7148. }
  7149. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7150. fmt.Println("schedulelist22222222", schedulelist)
  7151. c.ServeSuccessJSON(map[string]interface{}{
  7152. "list": schedulelist,
  7153. })
  7154. return
  7155. }
  7156. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7157. ids := c.GetString("ids")
  7158. //patient_id, _ := c.GetInt64("patient_id")
  7159. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7160. idArray := strings.Split(ids, ",")
  7161. err := service.BatchDeleteMonitor(idArray)
  7162. fmt.Print("err", err)
  7163. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7164. //redis := service.RedisClient()
  7165. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7166. //redis.Set(key, "", time.Second)
  7167. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7168. //redis.Set(keyOne, "", time.Second)
  7169. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7170. //redis.Close()
  7171. c.ServeSuccessJSON(map[string]interface{}{
  7172. "msg": "批量删除成功",
  7173. })
  7174. return
  7175. }
  7176. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7177. id, _ := c.GetInt64("id")
  7178. timeLayout := "2006-01-02"
  7179. loc, _ := time.LoadLocation("Local")
  7180. //start_time := time.Now().Format("2006-01-02")
  7181. start_time := c.GetString("start_time")
  7182. end_time := c.GetString("end_time")
  7183. var startdateunix int64
  7184. if len(start_time) > 0 {
  7185. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7186. if err != nil {
  7187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7188. return
  7189. }
  7190. startdateunix = theTime.Unix()
  7191. }
  7192. var enddateunix int64
  7193. if len(end_time) > 0 {
  7194. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7195. if err != nil {
  7196. utils.ErrorLog(err.Error())
  7197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7198. return
  7199. }
  7200. enddateunix = theTime.Unix()
  7201. }
  7202. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7203. //nowTime := time.Now()
  7204. //endTime := nowTime.AddDate(-30, 0, 0)
  7205. //endTimes := endTime.Format("2006-01-02")
  7206. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7207. org_id := c.GetMobileAdminUserInfo().Org.Id
  7208. //if org_id == 10579 {
  7209. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7210. // c.ServeSuccessJSON(map[string]interface{}{
  7211. // "list": list,
  7212. // })
  7213. // return
  7214. //} else {
  7215. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7216. // c.ServeSuccessJSON(map[string]interface{}{
  7217. // "list": list,
  7218. // })
  7219. // return
  7220. //}
  7221. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  7222. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7223. c.ServeSuccessJSON(map[string]interface{}{
  7224. "list": list,
  7225. })
  7226. return
  7227. } else {
  7228. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7229. c.ServeSuccessJSON(map[string]interface{}{
  7230. "list": list,
  7231. })
  7232. }
  7233. return
  7234. }
  7235. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7236. dataBody := make(map[string]interface{}, 0)
  7237. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7238. ids := c.GetString("ids")
  7239. idArray := strings.Split(ids, ",")
  7240. origin, _ := c.GetInt64("origin")
  7241. if origin == 1 {
  7242. err = service.BatchDeleteAdvice(idArray)
  7243. fmt.Print("err", err)
  7244. c.ServeSuccessJSON(map[string]interface{}{
  7245. "msg": "批量删除成功",
  7246. })
  7247. return
  7248. }
  7249. if origin == 2 {
  7250. service.BatchDeleteHisAdvice(idArray)
  7251. }
  7252. }
  7253. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7254. good_id, _ := c.GetInt64("good_id")
  7255. count, _ := c.GetInt64("count")
  7256. record_time, _ := c.GetInt64("record_time")
  7257. patient_id, _ := c.GetInt64("patient_id")
  7258. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7259. c.ServeSuccessJSON(map[string]interface{}{
  7260. "detail": detail,
  7261. })
  7262. return
  7263. }
  7264. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7265. good_id, _ := c.GetInt64("good_id")
  7266. record_time, _ := c.GetInt64("record_time")
  7267. patient_id, _ := c.GetInt64("patient_id")
  7268. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7269. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7270. fmt.Print("err", err)
  7271. c.ServeSuccessJSON(map[string]interface{}{
  7272. "msg": "批量删除成功",
  7273. })
  7274. return
  7275. }
  7276. func (c *DialysisAPIController) BatchAdviceCheck() {
  7277. ids := c.GetString("ids")
  7278. idArray := strings.Split(ids, ",")
  7279. creator, _ := c.GetInt64("creator")
  7280. origin, _ := c.GetInt64("origin")
  7281. if origin == 1 {
  7282. err := service.BatchAdviceCheck(idArray, creator)
  7283. fmt.Println(err)
  7284. list, _ := service.GetAdviceExecutionById(idArray)
  7285. c.ServeSuccessJSON(map[string]interface{}{
  7286. "list": list,
  7287. })
  7288. return
  7289. }
  7290. if origin == 2 {
  7291. service.BatchHisAdviceCheck(idArray, creator)
  7292. list, _ := service.GetHisAdviceExecutionById(idArray)
  7293. c.ServeSuccessJSON(map[string]interface{}{
  7294. "list": list,
  7295. })
  7296. return
  7297. }
  7298. }
  7299. func (c *DialysisAPIController) BatchAdviceExecution() {
  7300. ids := c.GetString("ids")
  7301. idArray := strings.Split(ids, ",")
  7302. executionTime := c.GetString("execution_time")
  7303. creator, _ := c.GetInt64("creator")
  7304. timeLayout := "2006-01-02 15:04:05"
  7305. loc, _ := time.LoadLocation("Local")
  7306. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7307. orgin, _ := c.GetInt64("origin")
  7308. if orgin == 1 {
  7309. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7310. list, _ := service.GetAdviceExecutionById(idArray)
  7311. fmt.Println(err)
  7312. c.ServeSuccessJSON(map[string]interface{}{
  7313. "list": list,
  7314. })
  7315. return
  7316. }
  7317. if orgin == 2 {
  7318. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7319. list, _ := service.GetHisAdviceExecutionById(idArray)
  7320. fmt.Println(err)
  7321. c.ServeSuccessJSON(map[string]interface{}{
  7322. "list": list,
  7323. })
  7324. return
  7325. }
  7326. }
  7327. func (c *DialysisAPIController) UpdateStockGoods() {
  7328. good_id, _ := c.GetInt64("good_id")
  7329. record_time, _ := c.GetInt64("record_time")
  7330. patient_id, _ := c.GetInt64("patient_id")
  7331. count, _ := c.GetInt64("count")
  7332. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7333. fmt.Print("err", err)
  7334. c.ServeSuccessJSON(map[string]interface{}{
  7335. "msg": "更新成功",
  7336. })
  7337. return
  7338. }
  7339. // 当前数据比上一次出库数据少
  7340. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7341. //查询该患者当天已经出库的耗材信息
  7342. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7343. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7344. for i := len(goods_yc) - 1; i >= 0; i-- {
  7345. goods_yc_temp := goods_yc[i]
  7346. for j := len(goods) - 1; j >= 0; j-- {
  7347. goods_temp := goods[j]
  7348. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7349. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7350. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7351. if goods_yc_temp.Count == goods_temp.Count {
  7352. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7353. goods = append(goods[:j], goods[j+1:]...)
  7354. break
  7355. }
  7356. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7357. if goods_yc_temp.Count > goods_temp.Count {
  7358. temp_count := goods_yc_temp.Count - goods_temp.Count
  7359. goods_yc[i].Count = temp_count
  7360. goods = append(goods[:j], goods[j+1:]...)
  7361. break
  7362. }
  7363. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7364. if goods_yc_temp.Count < goods_temp.Count {
  7365. temp_count := goods_temp.Count - goods_yc_temp.Count
  7366. goods[j].Count = temp_count
  7367. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7368. break
  7369. }
  7370. }
  7371. }
  7372. }
  7373. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7374. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7375. //退库
  7376. if len(goods_yc) > 0 {
  7377. for _, good_yc := range goods_yc {
  7378. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7379. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7380. }
  7381. }
  7382. return nil
  7383. }
  7384. // 耗材出库删除
  7385. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7386. // 先根据相关信息查询当天该耗材的出库信息
  7387. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7388. if err != nil {
  7389. return err
  7390. }
  7391. var delete_count int64 = 0
  7392. delete_count = warehouseOutInfos.Count - count
  7393. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7394. // 在出库记录表里记录退库详情
  7395. warehouseOutInfo := &models.WarehouseOutInfo{
  7396. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7397. WarehouseOutId: warehouseOut.ID,
  7398. Status: 1,
  7399. Ctime: time.Now().Unix(),
  7400. OrgId: orgID,
  7401. Type: 1,
  7402. IsSys: 1,
  7403. SysRecordTime: record_time,
  7404. GoodTypeId: good_yc.GoodTypeId,
  7405. GoodId: good_yc.GoodId,
  7406. PatientId: good_yc.PatientId,
  7407. ConsumableType: 2,
  7408. StorehouseId: houseConfig.StorehouseOutInfo,
  7409. IsCheck: 1,
  7410. }
  7411. warehouseOutInfo.Count = count
  7412. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7413. warehouseOutInfo.Price = stockInInfo.Price
  7414. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7415. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7416. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7417. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7418. warehouseOutInfo.Number = warehouseOutInfos.Number
  7419. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7420. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7421. //查找当天是否存在出库记录
  7422. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7423. if errcod == gorm.ErrRecordNotFound {
  7424. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7425. //插入详情明细表
  7426. stockFlow := models.VmStockFlow{
  7427. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7428. WarehouseOutId: warehouseOut.ID,
  7429. GoodId: good_yc.GoodId,
  7430. Number: warehouseOutInfos.Number,
  7431. ProductDate: stockInInfo.ProductDate,
  7432. ExpireDate: stockInInfo.ExpiryDate,
  7433. Count: count,
  7434. Price: stockInInfo.Price,
  7435. Status: 1,
  7436. Ctime: time.Now().Unix(),
  7437. UserOrgId: good_yc.OrgId,
  7438. Manufacturer: stockInInfo.Manufacturer,
  7439. Dealer: stockInInfo.Dealer,
  7440. LicenseNumber: stockInInfo.LicenseNumber,
  7441. IsEdit: 2,
  7442. Creator: creater,
  7443. SystemTime: record_time,
  7444. ConsumableType: 3,
  7445. WarehousingDetailId: 0,
  7446. IsSys: 1,
  7447. UpdateCreator: creater,
  7448. PatientId: patient_id,
  7449. StorehouseId: houseConfig.StorehouseOutInfo,
  7450. }
  7451. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7452. if errflow == gorm.ErrRecordNotFound {
  7453. //创建流水表
  7454. err := service.CreateStockFlowOne(stockFlow)
  7455. fmt.Println("err", err)
  7456. } else if errflow == nil {
  7457. //插入详情明细表
  7458. stockFlow := models.VmStockFlow{
  7459. ID: exsit.ID,
  7460. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7461. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7462. WarehouseOutId: warehouseOut.ID,
  7463. GoodId: good_yc.GoodId,
  7464. Number: warehouseOutInfos.Number,
  7465. ProductDate: stockInInfo.ProductDate,
  7466. ExpireDate: stockInInfo.ExpiryDate,
  7467. Count: exsit.Count - delete_count,
  7468. Price: stockInInfo.Price,
  7469. Status: 1,
  7470. Ctime: time.Now().Unix(),
  7471. UserOrgId: good_yc.OrgId,
  7472. Manufacturer: stockInInfo.Manufacturer,
  7473. Dealer: stockInInfo.Dealer,
  7474. LicenseNumber: stockInInfo.LicenseNumber,
  7475. IsEdit: 2,
  7476. Creator: creater,
  7477. SystemTime: record_time,
  7478. ConsumableType: 3,
  7479. WarehousingDetailId: 0,
  7480. IsSys: 1,
  7481. UpdateCreator: creater,
  7482. PatientId: patient_id,
  7483. StorehouseId: houseConfig.StorehouseOutInfo,
  7484. }
  7485. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7486. }
  7487. if errOne != nil {
  7488. return errOne
  7489. }
  7490. } else if errcod == nil {
  7491. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7492. //插入详情明细表
  7493. stockFlow := models.VmStockFlow{
  7494. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7495. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7496. WarehouseOutId: warehouseOut.ID,
  7497. GoodId: good_yc.GoodId,
  7498. Number: warehouseOutInfos.Number,
  7499. ProductDate: stockInInfo.ProductDate,
  7500. ExpireDate: stockInInfo.ExpiryDate,
  7501. Count: count,
  7502. Price: stockInInfo.Price,
  7503. Status: 1,
  7504. Ctime: time.Now().Unix(),
  7505. UserOrgId: good_yc.OrgId,
  7506. Manufacturer: stockInInfo.Manufacturer,
  7507. Dealer: stockInInfo.Dealer,
  7508. LicenseNumber: stockInInfo.LicenseNumber,
  7509. IsEdit: 2,
  7510. Creator: creater,
  7511. SystemTime: record_time,
  7512. ConsumableType: 3,
  7513. WarehousingDetailId: 0,
  7514. IsSys: 1,
  7515. UpdateCreator: creater,
  7516. PatientId: patient_id,
  7517. ReturnCount: delete_count,
  7518. StorehouseId: houseConfig.StorehouseOutInfo,
  7519. }
  7520. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7521. if errflows == gorm.ErrRecordNotFound {
  7522. //创建流水表
  7523. service.CreateStockFlowOne(stockFlow)
  7524. } else if errflows == nil {
  7525. stockFlow := models.VmStockFlow{
  7526. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7527. ID: exsit.ID,
  7528. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7529. WarehouseOutId: warehouseOut.ID,
  7530. GoodId: good_yc.GoodId,
  7531. Number: warehouseOutInfos.Number,
  7532. ProductDate: stockInInfo.ProductDate,
  7533. ExpireDate: stockInInfo.ExpiryDate,
  7534. Count: exsit.Count - delete_count,
  7535. Price: stockInInfo.Price,
  7536. Status: 1,
  7537. Ctime: time.Now().Unix(),
  7538. UserOrgId: good_yc.OrgId,
  7539. Manufacturer: stockInInfo.Manufacturer,
  7540. Dealer: stockInInfo.Dealer,
  7541. LicenseNumber: stockInInfo.LicenseNumber,
  7542. IsEdit: 2,
  7543. Creator: creater,
  7544. SystemTime: record_time,
  7545. ConsumableType: 3,
  7546. WarehousingDetailId: 0,
  7547. IsSys: 1,
  7548. UpdateCreator: creater,
  7549. PatientId: patient_id,
  7550. ReturnCount: delete_count,
  7551. StorehouseId: houseConfig.StorehouseOutInfo,
  7552. }
  7553. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7554. }
  7555. }
  7556. //更改自动出库的表格
  7557. details := models.BloodAutomaticReduceDetail{
  7558. WarehouseOutId: warehouseOutInfo.ID,
  7559. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7560. PatientId: patient_id,
  7561. Ctime: time.Now().Unix(),
  7562. Mtime: time.Now().Unix(),
  7563. Status: 1,
  7564. RecordTime: record_time,
  7565. OrgId: orgID,
  7566. GoodId: good_yc.GoodId,
  7567. GoodTypeId: good_yc.GoodTypeId,
  7568. Count: count,
  7569. StorehouseId: houseConfig.StorehouseOutInfo,
  7570. }
  7571. //查询当天耗材是否已经存在数据
  7572. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7573. if errcode == gorm.ErrRecordNotFound {
  7574. errTwo := service.CreateAutoReduceRecord(&details)
  7575. if errTwo != nil {
  7576. return errTwo
  7577. }
  7578. } else if errcode == nil {
  7579. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7580. service.CreateAutoReduceRecord(&details)
  7581. }
  7582. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7583. //增加出库库存数量
  7584. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7585. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7586. fmt.Println("errOne", errOne)
  7587. // 删除出库完成后,要增加对应批次的库存数量
  7588. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7589. if errThree != nil {
  7590. return errThree
  7591. }
  7592. if good_yc.Count == 0 {
  7593. return nil
  7594. } else {
  7595. return errors.New("退库和出库数据不匹配")
  7596. }
  7597. }
  7598. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7599. //查询该患者当天已经出库的耗材信息
  7600. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7601. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7602. for i := len(goods_yc) - 1; i >= 0; i-- {
  7603. goods_yc_temp := goods_yc[i]
  7604. for j := len(goods) - 1; j >= 0; j-- {
  7605. goods_temp := goods[j]
  7606. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7607. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7608. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7609. if goods_yc_temp.Count == goods_temp.Count {
  7610. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7611. goods = append(goods[:j], goods[j+1:]...)
  7612. break
  7613. }
  7614. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7615. if goods_yc_temp.Count > goods_temp.Count {
  7616. temp_count := goods_yc_temp.Count - goods_temp.Count
  7617. goods_yc[i].Count = temp_count
  7618. goods = append(goods[:j], goods[j+1:]...)
  7619. break
  7620. }
  7621. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7622. if goods_yc_temp.Count < goods_temp.Count {
  7623. temp_count := goods_temp.Count - goods_yc_temp.Count
  7624. goods[j].Count = temp_count
  7625. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7626. break
  7627. }
  7628. }
  7629. }
  7630. }
  7631. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7632. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7633. fmt.Println("剩余需要出库的", len(goods))
  7634. if len(goods) > 0 {
  7635. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7636. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7637. if err == gorm.ErrRecordNotFound {
  7638. //没有记录,则创建出库单
  7639. timeStr := time.Now().Format("2006-01-02")
  7640. timeArr := strings.Split(timeStr, "-")
  7641. total, _ := service.FindAllWarehouseOut(orgID)
  7642. total = total + 1
  7643. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7644. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7645. number = number + total
  7646. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7647. warehouseOut := models.WarehouseOut{
  7648. WarehouseOutOrderNumber: warehousing_out_order,
  7649. OperationTime: time.Now().Unix(),
  7650. OrgId: orgID,
  7651. Creater: creater,
  7652. Ctime: time.Now().Unix(),
  7653. Status: 1,
  7654. WarehouseOutTime: record_time,
  7655. Dealer: 0,
  7656. Manufacturer: 0,
  7657. Type: 1,
  7658. IsSys: 1,
  7659. StorehouseId: houseConfig.StorehouseOutInfo,
  7660. IsCheck: 1,
  7661. }
  7662. err := service.AddSigleWarehouseOut(&warehouseOut)
  7663. if err != nil {
  7664. utils.TraceLog("创建出库单失败 err = %v", err)
  7665. return err
  7666. } else {
  7667. out = warehouseOut
  7668. }
  7669. }
  7670. for _, item := range goods {
  7671. var newCount int64 = 0
  7672. for _, it := range goodOne {
  7673. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7674. newCount = it.Count
  7675. }
  7676. }
  7677. prepare := models.DialysisBeforePrepare{
  7678. GoodTypeId: item.GoodTypeId,
  7679. GoodId: item.GoodId,
  7680. Count: item.Count,
  7681. StorehouseId: houseConfig.StorehouseOutInfo,
  7682. }
  7683. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7684. //增加出库数量
  7685. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7686. }
  7687. }
  7688. if len(goods_yc) > 0 {
  7689. for _, good_yc := range goods_yc {
  7690. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7691. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7692. }
  7693. }
  7694. return nil
  7695. }
  7696. // 耗材出库删除
  7697. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7698. // 先根据相关信息查询当天该耗材的出库信息
  7699. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7700. if err != nil {
  7701. return err
  7702. }
  7703. var delete_count int64 = 0
  7704. for _, ware := range warehouseOutInfos {
  7705. // 判断当前出库的数据和删除出库数量
  7706. if good_yc.Count <= ware.Count {
  7707. delete_count = good_yc.Count
  7708. } else {
  7709. delete_count = ware.Count
  7710. }
  7711. warehouseOutInfo := &models.WarehouseOutInfo{
  7712. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7713. WarehouseOutId: warehouseOut.ID,
  7714. Status: 1,
  7715. Ctime: time.Now().Unix(),
  7716. Remark: "",
  7717. OrgId: orgID,
  7718. Type: 1,
  7719. Manufacturer: 0,
  7720. Dealer: 0,
  7721. IsSys: 0,
  7722. SysRecordTime: record_time,
  7723. GoodTypeId: good_yc.GoodTypeId,
  7724. GoodId: good_yc.GoodId,
  7725. StorehouseId: warehouseOut.StorehouseId,
  7726. IsCheck: 1,
  7727. }
  7728. warehouseOutInfo.Count = delete_count
  7729. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7730. warehouseOutInfo.Price = stockInInfo.Price
  7731. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7732. if errOne != nil {
  7733. return errOne
  7734. }
  7735. // 删除出库完成后,要改变流水库存(有疑问)
  7736. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7737. fmt.Println("errOne", errOne)
  7738. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7739. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7740. //扣减出库数量
  7741. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7742. if errThree != nil {
  7743. return errThree
  7744. }
  7745. }
  7746. if good_yc.Count == 0 {
  7747. return nil
  7748. } else {
  7749. return errors.New("退库和出库数据不匹配")
  7750. }
  7751. }
  7752. func (this *DialysisAPIController) GetMobileScheduleList() {
  7753. limit, _ := this.GetInt64("limit")
  7754. page, _ := this.GetInt64("page")
  7755. type_options_visible, _ := this.GetInt64("type_options_visible")
  7756. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7757. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7758. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7759. }
  7760. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7761. newArr = make([]*models.HisPrescriptionProject, 0)
  7762. for i := 0; i < len(arr); i++ {
  7763. repeat := false
  7764. for j := i + 1; j < len(arr); j++ {
  7765. if arr[i].TeamId == arr[j].TeamId {
  7766. repeat = true
  7767. break
  7768. }
  7769. }
  7770. if !repeat {
  7771. newArr = append(newArr, arr[i])
  7772. }
  7773. }
  7774. return
  7775. }
  7776. func (this *DialysisAPIController) GetRoleList() {
  7777. admin_user_id, _ := this.GetInt64("admin_user_id")
  7778. orgid := this.GetMobileAdminUserInfo().Org.Id
  7779. list, err := service.GetRoleList(orgid, admin_user_id)
  7780. fmt.Println(err)
  7781. this.ServeSuccessJSON(map[string]interface{}{
  7782. "list": list,
  7783. })
  7784. return
  7785. }
  7786. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7787. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7788. // 先根据相关信息查询当天该耗材的出库信息
  7789. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7790. if err != nil {
  7791. return err
  7792. }
  7793. var delete_count int64 = 0
  7794. delete_count = warehouseOutInfos.Count - count
  7795. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7796. // 删除出库完成后,要增加对应批次的库存数量
  7797. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7798. if errThree != nil {
  7799. return errThree
  7800. }
  7801. //增加退库数量
  7802. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7803. //扣减出库数量
  7804. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7805. //查询剩余库存
  7806. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7807. var sum_count int64
  7808. for _, item := range goodList {
  7809. sum_count += item.StockCount
  7810. }
  7811. // 在出库记录表里记录退库详情
  7812. warehouseOutInfo := &models.WarehouseOutInfo{
  7813. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7814. WarehouseOutId: warehouseOut.ID,
  7815. Status: 1,
  7816. Ctime: time.Now().Unix(),
  7817. OrgId: orgID,
  7818. Type: 1,
  7819. IsSys: 1,
  7820. SysRecordTime: record_time,
  7821. GoodTypeId: good_yc.GoodTypeId,
  7822. GoodId: good_yc.GoodId,
  7823. PatientId: good_yc.PatientId,
  7824. ConsumableType: 2,
  7825. StorehouseId: houseConfig.StorehouseOutInfo,
  7826. IsCheck: 1,
  7827. OverCount: sum_count,
  7828. }
  7829. warehouseOutInfo.Count = count
  7830. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7831. warehouseOutInfo.Price = stockInInfo.Price
  7832. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7833. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7834. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7835. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7836. warehouseOutInfo.Number = warehouseOutInfos.Number
  7837. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7838. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7839. //查找当天是否存在出库记录
  7840. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7841. if errcod == gorm.ErrRecordNotFound {
  7842. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7843. //插入详情明细表
  7844. if errOne != nil {
  7845. return errOne
  7846. }
  7847. //插入详情明细表
  7848. stockFlow := models.VmStockFlow{
  7849. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7850. WarehouseOutId: warehouseOut.ID,
  7851. GoodId: good_yc.GoodId,
  7852. Number: warehouseOutInfos.Number,
  7853. ProductDate: stockInInfo.ProductDate,
  7854. ExpireDate: stockInInfo.ExpiryDate,
  7855. Count: count,
  7856. Price: stockInInfo.Price,
  7857. Status: 1,
  7858. Ctime: time.Now().Unix(),
  7859. UserOrgId: good_yc.OrgId,
  7860. Manufacturer: stockInInfo.Manufacturer,
  7861. Dealer: stockInInfo.Dealer,
  7862. LicenseNumber: stockInInfo.LicenseNumber,
  7863. IsEdit: 2,
  7864. Creator: creater,
  7865. SystemTime: record_time,
  7866. ConsumableType: 3,
  7867. WarehousingDetailId: 0,
  7868. IsSys: 1,
  7869. UpdateCreator: creater,
  7870. PatientId: patient_id,
  7871. StorehouseId: houseConfig.StorehouseOutInfo,
  7872. OverCount: sum_count,
  7873. ProjectId: good_yc.ProjectId,
  7874. }
  7875. err := service.CreateStockFlowOne(stockFlow)
  7876. fmt.Println("err", err)
  7877. } else if errcod == nil {
  7878. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7879. }
  7880. //创建退库单
  7881. operation_time := time.Now().Unix()
  7882. //创建退库单
  7883. timeStr := time.Now().Format("2006-01-02")
  7884. timeArr := strings.Split(timeStr, "-")
  7885. total, _ := service.FindAllCancelStockTotal(orgID)
  7886. total = total + 1
  7887. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7888. cancelStock := models.CancelStock{
  7889. OrderNumber: orderNumber,
  7890. OperaTime: operation_time,
  7891. OrgId: orgID,
  7892. Creater: warehouseOut.Creater,
  7893. Ctime: time.Now().Unix(),
  7894. Status: 1,
  7895. ReturnTime: record_time,
  7896. Type: 1,
  7897. StorehouseId: stockInInfo.StorehouseId,
  7898. IsCheck: 1,
  7899. }
  7900. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7901. if msgerrkonde == gorm.ErrRecordNotFound {
  7902. service.AddSigleCancelStock(&cancelStock)
  7903. }
  7904. cancel, _ := service.GetLastCancelStockById(orgID)
  7905. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7906. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7907. cancelStockInfo := models.CancelStockInfo{
  7908. GoodId: stockInInfo.GoodId,
  7909. CancelStockId: cancel.ID,
  7910. GoodTypeId: stockInInfo.GoodTypeId,
  7911. Count: delete_count,
  7912. Price: stockInInfo.PackingPrice,
  7913. Total: 0,
  7914. ProductDate: stockInInfo.ProductDate,
  7915. ExpiryDate: stockInInfo.ExpiryDate,
  7916. Ctime: time.Now().Unix(),
  7917. Status: 1,
  7918. OrgId: orgID,
  7919. OrderNumber: cancel.OrderNumber,
  7920. Type: 0,
  7921. Dealer: deaerler.DealerName,
  7922. Manufacturer: manufacturer.ManufacturerName,
  7923. Number: stockInInfo.Number,
  7924. RegisterAccount: "",
  7925. Remark: "",
  7926. WarehouseInfoId: stockInInfo.ID,
  7927. PatientId: patient_id,
  7928. RecordDate: record_time,
  7929. StorehouseId: stockInInfo.StorehouseId,
  7930. IsCheck: 1,
  7931. }
  7932. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7933. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7934. flow := models.VmStockFlow{
  7935. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7936. GoodId: good_yc.GoodId,
  7937. Number: warehouseOutInfos.Number,
  7938. LicenseNumber: stockInInfo.LicenseNumber,
  7939. Count: delete_count,
  7940. UserOrgId: orgID,
  7941. PatientId: patient_id,
  7942. SystemTime: record_time,
  7943. ConsumableType: 7,
  7944. IsSys: 0,
  7945. WarehousingOrder: "",
  7946. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7947. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7948. IsEdit: 0,
  7949. CancelStockId: cancel.ID,
  7950. CancelOrderNumber: cancel.OrderNumber,
  7951. Manufacturer: manufacturer.ID,
  7952. Dealer: 0,
  7953. Creator: warehouseOut.Creater,
  7954. UpdateCreator: 0,
  7955. Status: 1,
  7956. Ctime: time.Now().Unix(),
  7957. Mtime: 0,
  7958. Price: stockInInfo.Price,
  7959. WarehousingDetailId: stockInInfo.ID,
  7960. WarehouseOutDetailId: warehouseOutInfos.ID,
  7961. CancelOutDetailId: cancelInfo.ID,
  7962. ProductDate: stockInInfo.ProductDate,
  7963. ExpireDate: stockInInfo.ExpiryDate,
  7964. StorehouseId: houseConfig.StorehouseOutInfo,
  7965. OverCount: sum_count,
  7966. }
  7967. service.CreateStockFlowOne(flow)
  7968. //更改自动出库的表格
  7969. details := models.BloodAutomaticReduceDetail{
  7970. WarehouseOutId: warehouseOutInfo.ID,
  7971. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7972. PatientId: patient_id,
  7973. Ctime: time.Now().Unix(),
  7974. Mtime: time.Now().Unix(),
  7975. Status: 1,
  7976. RecordTime: record_time,
  7977. OrgId: orgID,
  7978. GoodId: good_yc.GoodId,
  7979. GoodTypeId: good_yc.GoodTypeId,
  7980. Count: count,
  7981. StorehouseId: houseConfig.StorehouseOutInfo,
  7982. }
  7983. //查询当天耗材是否已经存在数据
  7984. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7985. if errcode == gorm.ErrRecordNotFound {
  7986. errTwo := service.CreateAutoReduceRecord(&details)
  7987. if errTwo != nil {
  7988. return errTwo
  7989. }
  7990. } else if errcode == nil {
  7991. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7992. service.CreateAutoReduceRecord(&details)
  7993. }
  7994. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7995. //增加出库库存数量
  7996. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7997. if good_yc.Count == 0 {
  7998. return nil
  7999. } else {
  8000. return errors.New("退库和出库数据不匹配")
  8001. }
  8002. }
  8003. func (this *DialysisAPIController) SavePatientSign() {
  8004. adminUserInfo := this.GetMobileAdminUserInfo()
  8005. patient_id, _ := this.GetInt64("patient_id")
  8006. dialysis_date, _ := this.GetInt64("dialysis_date")
  8007. orgid := adminUserInfo.Org.Id
  8008. var esdata models.DialysisOrder
  8009. var err error
  8010. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8012. return
  8013. }
  8014. esdata.Hash = esdata.Hash
  8015. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8016. order := models.DialysisOrder{
  8017. Hash: esdata.Hash,
  8018. Url: esdata.Url,
  8019. }
  8020. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8021. redis := service.RedisClient()
  8022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8023. redis.Set(key, "", time.Second)
  8024. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8025. //清空key 值
  8026. redis.Set(keyOne, "", time.Second)
  8027. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8028. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8029. //redis.Set(keyTwo, "", time.Second)
  8030. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8031. redis.Set(keyThree, "", time.Second)
  8032. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8033. redis.Set(keyFour, "", time.Second)
  8034. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8035. redis.Set(keyFive, "", time.Second)
  8036. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8037. redis.Set(keySix, "", time.Second)
  8038. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8039. redis.Set(keySeven, "", time.Second)
  8040. if err != nil {
  8041. fmt.Println(err)
  8042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8043. return
  8044. }
  8045. this.ServeSuccessJSON(map[string]interface{}{
  8046. "electronic_signature": esdata,
  8047. })
  8048. }
  8049. func (this *DialysisAPIController) GetPatientSign() {
  8050. patient_id, _ := this.GetInt64("patient_id")
  8051. dialysis_date, _ := this.GetInt64("dialysis_date")
  8052. adminUserInfo := this.GetMobileAdminUserInfo()
  8053. orgId := adminUserInfo.Org.Id
  8054. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8055. if err != nil {
  8056. fmt.Println(err)
  8057. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8058. return
  8059. }
  8060. this.ServeSuccessJSON(map[string]interface{}{
  8061. "dialysisOrder": dialysisOrder,
  8062. })
  8063. }
  8064. func (this *DialysisAPIController) GetScheduleByPatient() {
  8065. patient_id, _ := this.GetInt64("patient_id")
  8066. schedule_date, _ := this.GetInt64("schedule_date")
  8067. orgid := this.GetMobileAdminUserInfo().Org.Id
  8068. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8069. this.ServeSuccessJSON(map[string]interface{}{
  8070. "schedule": schedule,
  8071. })
  8072. }
  8073. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8074. org_id := this.GetMobileAdminUserInfo().Org.Id
  8075. patient_id, _ := this.GetInt64("patient_id")
  8076. schedule_date, _ := this.GetInt64("schedule_date")
  8077. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8078. this.ServeSuccessJSON(map[string]interface{}{
  8079. "order": order,
  8080. })
  8081. }
  8082. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8083. org_id := this.GetMobileAdminUserInfo().Org.Id
  8084. schedule_date := this.GetString("schedule_date")
  8085. schedule_type, _ := this.GetInt64("schedule_type")
  8086. timeLayout := "2006-01-02"
  8087. loc, _ := time.LoadLocation("Local")
  8088. var startdateunix int64
  8089. if len(schedule_date) > 0 {
  8090. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8091. if err != nil {
  8092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8093. return
  8094. }
  8095. startdateunix = theTime.Unix()
  8096. }
  8097. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8098. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8099. devices, _ := service.GetAllDevicetByListSix(org_id)
  8100. for key, item := range scheduals {
  8101. // 床位信息
  8102. for _, device := range devices {
  8103. if item.BedId == device.ID {
  8104. scheduals[key].DeviceNumber = device
  8105. break
  8106. }
  8107. }
  8108. }
  8109. this.ServeSuccessJSON(map[string]interface{}{
  8110. "list": list,
  8111. "scheduals": scheduals,
  8112. })
  8113. }
  8114. func (this *DialysisAPIController) SavePatientPicture() {
  8115. patient_id, _ := this.GetInt64("patient_id")
  8116. dialysis_date, _ := this.GetInt64("schedule_date")
  8117. avatar := this.GetString("avatar")
  8118. fmt.Println("patient_id", patient_id)
  8119. orgId := this.GetMobileAdminUserInfo().Org.Id
  8120. order := models.DialysisOrder{
  8121. Url: avatar,
  8122. }
  8123. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8124. redis := service.RedisClient()
  8125. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8126. redis.Set(key, "", time.Second)
  8127. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8128. //清空key 值
  8129. redis.Set(keyOne, "", time.Second)
  8130. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8131. redis.Set(keyThree, "", time.Second)
  8132. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8133. redis.Set(keyFour, "", time.Second)
  8134. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8135. redis.Set(keyFive, "", time.Second)
  8136. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8137. redis.Set(keySix, "", time.Second)
  8138. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8139. redis.Set(keySeven, "", time.Second)
  8140. if err != nil {
  8141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8142. return
  8143. }
  8144. this.ServeSuccessJSON(map[string]interface{}{
  8145. "order": order,
  8146. })
  8147. }
  8148. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8149. ids := this.GetString("ids")
  8150. idSplit := strings.Split(ids, ",")
  8151. orgId := this.GetMobileAdminUserInfo().Org.Id
  8152. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8153. execution_time := this.GetString("exce_time")
  8154. timeLayout2 := "2006-01-02 15:04:05"
  8155. loc, _ := time.LoadLocation("Local")
  8156. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8157. if errs != nil {
  8158. utils.ErrorLog(errs.Error())
  8159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8160. return
  8161. }
  8162. //his客户
  8163. if config.IsOpen == 1 {
  8164. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8165. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8166. for _, item := range list {
  8167. for _, it := range adviceList {
  8168. if item.DrugId == it.DrugId {
  8169. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8170. }
  8171. }
  8172. }
  8173. for _, item := range list {
  8174. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8175. var sum_out_count int64
  8176. for _, itemThree := range item.ChildDoctorAdvice {
  8177. var prescribing_number int64
  8178. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8179. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8180. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8181. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8182. }
  8183. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8184. prescribing_number = parseIntPrescribingNumber
  8185. }
  8186. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8187. prescribing_number = parseIntPrescribingNumber
  8188. }
  8189. sum_out_count += prescribing_number
  8190. }
  8191. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8192. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8193. //库存不足
  8194. if sum_out_count > drugStockOut.FlushCount {
  8195. this.ServeSuccessJSON(map[string]interface{}{
  8196. "msg": "2",
  8197. "drug": medical,
  8198. "ids": ids,
  8199. })
  8200. return
  8201. }
  8202. }
  8203. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8204. //执行医嘱
  8205. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8206. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8207. for _, item := range advices {
  8208. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8209. redis := service.RedisClient()
  8210. //清空key 值
  8211. redis.Set(key, "", time.Second)
  8212. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8213. redis.Set(keyTwo, "", time.Second)
  8214. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8215. redis.Set(keyThree, "", time.Second)
  8216. recordDate := theTime.Format("2006-01-02")
  8217. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8218. redis.Set(keyFour, "", time.Second)
  8219. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8220. redis.Set(keyFive, "", time.Second)
  8221. defer redis.Close()
  8222. }
  8223. if errs == nil {
  8224. //药品管理信息
  8225. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8226. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8227. if drugStockConfig.IsOpen == 1 {
  8228. for _, item := range advices {
  8229. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8230. config, _ := service.GetDrugOpenConfigOne(orgId)
  8231. if config.IsOpen != 1 {
  8232. //查询该药品是否有库存
  8233. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8234. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8235. if medical.IsUse == 2 {
  8236. if config.IsOpen != 1 {
  8237. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8238. service.HisDrugsDelivery(orgId, creater, &advice)
  8239. if orgId == 3877 || orgId == 10265 {
  8240. //查询该药品是否有出库记录
  8241. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8242. if len(flowMap) == 0 {
  8243. errs := service.UpdateHisAdviceById(advice.ID)
  8244. if errs != nil {
  8245. drugError := models.XtDrugError{
  8246. UserOrgId: orgId,
  8247. DrugId: item.DrugId,
  8248. RecordDate: item.AdviceDate,
  8249. PatientId: item.PatientId,
  8250. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8251. Status: 1,
  8252. Ctime: time.Now().Unix(),
  8253. Mtime: 0,
  8254. SumCount: 0,
  8255. Prescribingnumber: advice.PrescribingNumber,
  8256. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8257. }
  8258. service.CreateDrugError(drugError)
  8259. }
  8260. this.ServeSuccessJSON(map[string]interface{}{
  8261. "msg": "2",
  8262. "drug": medical,
  8263. "ids": ids,
  8264. })
  8265. return
  8266. }
  8267. }
  8268. }
  8269. if pharmacyConfig.IsOpen != 1 {
  8270. service.HisDrugsDelivery(orgId, creater, &advice)
  8271. if orgId == 3877 || orgId == 10265 {
  8272. //查询该药品是否有出库记录
  8273. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8274. if len(flowMap) == 0 {
  8275. errs := service.UpdateHisAdviceById(advice.ID)
  8276. if errs != nil {
  8277. drugError := models.XtDrugError{
  8278. UserOrgId: orgId,
  8279. DrugId: item.DrugId,
  8280. RecordDate: item.AdviceDate,
  8281. PatientId: item.PatientId,
  8282. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8283. Status: 1,
  8284. Ctime: time.Now().Unix(),
  8285. Mtime: 0,
  8286. SumCount: 0,
  8287. Prescribingnumber: advice.PrescribingNumber,
  8288. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8289. }
  8290. service.CreateDrugError(drugError)
  8291. }
  8292. this.ServeSuccessJSON(map[string]interface{}{
  8293. "msg": "2",
  8294. "drug": medical,
  8295. "ids": ids,
  8296. })
  8297. return
  8298. }
  8299. }
  8300. }
  8301. //更新字典里面的库存
  8302. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8303. var sum_count int64
  8304. for _, its := range stockInfo {
  8305. if its.MaxUnit == medical.MaxUnit {
  8306. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8307. }
  8308. sum_count += its.StockMaxNumber + its.StockMinNumber
  8309. }
  8310. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8311. //剩余库存
  8312. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8313. }
  8314. }
  8315. }
  8316. }
  8317. }
  8318. this.ServeSuccessJSON(map[string]interface{}{
  8319. "msg": "1",
  8320. "ids": ids,
  8321. })
  8322. return
  8323. } else {
  8324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8325. }
  8326. }
  8327. fmt.Println("config233322333223", config.IsOpen)
  8328. //血透客户
  8329. if config.IsOpen == 2 || config.IsOpen == 0 {
  8330. //药品管理信息
  8331. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8332. if drugStockConfig.IsOpen == 1 {
  8333. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8334. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8335. for _, item := range list {
  8336. for _, it := range adviceList {
  8337. if item.DrugId == it.DrugId {
  8338. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8339. }
  8340. }
  8341. }
  8342. for _, item := range list {
  8343. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8344. var sum_out_count int64
  8345. for _, itemThree := range item.ChildDoctorAdvice {
  8346. var prescribing_number int64
  8347. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8348. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8349. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8350. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8351. }
  8352. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8353. prescribing_number = parseIntPrescribingNumber
  8354. }
  8355. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8356. prescribing_number = parseIntPrescribingNumber
  8357. }
  8358. sum_out_count += prescribing_number
  8359. }
  8360. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8361. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8362. //库存不足
  8363. if sum_out_count > drugStockOut.FlushCount {
  8364. this.ServeSuccessJSON(map[string]interface{}{
  8365. "msg": "2",
  8366. "drug": medical,
  8367. "ids": ids,
  8368. })
  8369. return
  8370. }
  8371. }
  8372. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8373. fmt.Println("creater2332243244224242424", creater)
  8374. //执行医嘱
  8375. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8376. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8377. for _, item := range advices {
  8378. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8379. redis := service.RedisClient()
  8380. //清空key 值
  8381. redis.Set(key, "", time.Second)
  8382. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8383. redis.Set(keyTwo, "", time.Second)
  8384. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8385. redis.Set(keyThree, "", time.Second)
  8386. recordDate := theTime.Format("2006-01-02")
  8387. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8388. redis.Set(keyFour, "", time.Second)
  8389. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8390. redis.Set(keyFive, "", time.Second)
  8391. defer redis.Close()
  8392. }
  8393. if errs == nil {
  8394. for _, item := range advices {
  8395. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8396. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8397. //查询是否出库按钮开启
  8398. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8399. if adviceSetting.IsAdviceOpen == 1 {
  8400. //查询是否出库按钮开启
  8401. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8402. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8403. if prescriptionConfig.IsOpen == 1 {
  8404. if medical.IsUse == 2 {
  8405. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8406. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8407. }
  8408. if pharmacyConfig.IsOpen != 1 {
  8409. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8410. }
  8411. //更新字典里面的库存
  8412. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8413. var sum_count int64
  8414. for _, its := range stockInfo {
  8415. if its.MaxUnit == medical.MaxUnit {
  8416. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8417. }
  8418. sum_count += its.StockMaxNumber + its.StockMinNumber
  8419. }
  8420. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8421. //剩余库存
  8422. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8423. }
  8424. }
  8425. } else {
  8426. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8427. if medical.IsUse == 2 {
  8428. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8429. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8430. }
  8431. if pharmacyConfig.IsOpen != 1 {
  8432. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8433. }
  8434. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8435. var sum_count int64
  8436. for _, its := range stockInfo {
  8437. if its.MaxUnit == medical.MaxUnit {
  8438. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8439. }
  8440. sum_count += its.StockMaxNumber + its.StockMinNumber
  8441. }
  8442. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8443. //剩余库存
  8444. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8445. }
  8446. }
  8447. }
  8448. }
  8449. this.ServeSuccessJSON(map[string]interface{}{
  8450. "msg": "1",
  8451. "ids": ids,
  8452. })
  8453. return
  8454. } else {
  8455. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8456. //执行医嘱
  8457. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8458. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8459. for _, item := range advices {
  8460. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8461. redis := service.RedisClient()
  8462. //清空key 值
  8463. redis.Set(key, "", time.Second)
  8464. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8465. redis.Set(keyTwo, "", time.Second)
  8466. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8467. redis.Set(keyThree, "", time.Second)
  8468. recordDate := theTime.Format("2006-01-02")
  8469. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8470. redis.Set(keyFour, "", time.Second)
  8471. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8472. redis.Set(keyFive, "", time.Second)
  8473. defer redis.Close()
  8474. }
  8475. this.ServeSuccessJSON(map[string]interface{}{
  8476. "msg": "1",
  8477. "ids": ids,
  8478. })
  8479. return
  8480. }
  8481. }
  8482. }
  8483. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8484. ids := this.GetString("ids")
  8485. idSplit := strings.Split(ids, ",")
  8486. orgId := this.GetMobileAdminUserInfo().Org.Id
  8487. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8488. if config.IsOpen == 1 {
  8489. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8490. this.ServeSuccessJSON(map[string]interface{}{
  8491. "msg": "1",
  8492. "ids": ids,
  8493. })
  8494. return
  8495. }
  8496. if config.IsOpen == 0 || config.IsOpen == 2 {
  8497. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8498. this.ServeSuccessJSON(map[string]interface{}{
  8499. "msg": "1",
  8500. "ids": ids,
  8501. })
  8502. return
  8503. }
  8504. }
  8505. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8506. ids := this.GetString("ids")
  8507. idSplit := strings.Split(ids, ",")
  8508. orgId := this.GetMobileAdminUserInfo().Org.Id
  8509. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8510. //his
  8511. if config.IsOpen == 1 {
  8512. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8513. theTime := time.Now()
  8514. advices := models.HisDoctorAdviceThirty{
  8515. CheckTime: theTime.Unix(),
  8516. Checker: checker,
  8517. UpdatedTime: time.Now().Unix(),
  8518. }
  8519. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8520. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8521. for _, item := range list {
  8522. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8523. redis := service.RedisClient()
  8524. //清空key 值
  8525. redis.Set(key, "", time.Second)
  8526. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8527. redis.Set(keyTwo, "", time.Second)
  8528. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8529. redis.Set(keyThree, "", time.Second)
  8530. recordDate := theTime.Format("2006-01-02")
  8531. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8532. redis.Set(keyFour, "", time.Second)
  8533. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8534. redis.Set(keyFive, "", time.Second)
  8535. defer redis.Close()
  8536. }
  8537. this.ServeSuccessJSON(map[string]interface{}{
  8538. "msg": "1",
  8539. "ids": ids,
  8540. })
  8541. return
  8542. }
  8543. //血透
  8544. if config.IsOpen == 0 || config.IsOpen == 2 {
  8545. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8546. theTime := time.Now()
  8547. advices := models.DoctorAdvice{
  8548. CheckTime: theTime.Unix(),
  8549. Checker: checker,
  8550. UpdatedTime: time.Now().Unix(),
  8551. }
  8552. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8553. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8554. for _, item := range list {
  8555. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8556. redis := service.RedisClient()
  8557. //清空key 值
  8558. redis.Set(key, "", time.Second)
  8559. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8560. redis.Set(keyTwo, "", time.Second)
  8561. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8562. redis.Set(keyThree, "", time.Second)
  8563. recordDate := theTime.Format("2006-01-02")
  8564. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8565. redis.Set(keyFour, "", time.Second)
  8566. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8567. redis.Set(keyFive, "", time.Second)
  8568. defer redis.Close()
  8569. }
  8570. this.ServeSuccessJSON(map[string]interface{}{
  8571. "msg": "1",
  8572. "ids": ids,
  8573. })
  8574. return
  8575. }
  8576. }
  8577. func (this *DialysisAPIController) CheckSchedule() {
  8578. patientID, _ := this.GetInt64("patient_id")
  8579. recordDateStr := this.GetString("record_date")
  8580. nurseID, _ := this.GetInt64("start_nurse")
  8581. schedual_type, _ := this.GetInt64("schedual_type")
  8582. bedID, _ := this.GetInt64("bed")
  8583. start_time := this.GetString("start_time")
  8584. fmt.Println("patientID", patientID)
  8585. fmt.Println("recordDateStr", recordDateStr)
  8586. fmt.Println("nurseID", nurseID)
  8587. fmt.Println("schedual_type------", schedual_type)
  8588. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8590. return
  8591. }
  8592. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8593. if parseStartDateErr != nil {
  8594. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8596. return
  8597. }
  8598. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8599. if parseErr != nil {
  8600. this.ErrorLog("时间解析失败:%v", parseErr)
  8601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8602. return
  8603. }
  8604. adminUserInfo := this.GetMobileAdminUserInfo()
  8605. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8606. if getPatientErr != nil {
  8607. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8609. return
  8610. } else if patient == nil {
  8611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8612. return
  8613. }
  8614. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8615. if getNurseErr != nil {
  8616. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8618. return
  8619. } else if nurse == nil {
  8620. this.ErrorLog("护士不存在")
  8621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8622. return
  8623. }
  8624. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8625. if getDeviceNumberErr != nil {
  8626. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8627. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8628. return
  8629. } else if deviceNumber == nil {
  8630. this.ErrorLog("床位号不存在")
  8631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8632. return
  8633. }
  8634. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8635. if getRecordErr != nil {
  8636. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8638. return
  8639. } else if dialysisRecord != nil {
  8640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8641. return
  8642. }
  8643. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8644. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8645. timeLayout := "2006-01-02 15:04:05"
  8646. loc, _ := time.LoadLocation("Local")
  8647. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8648. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8649. schedulestartTime := theStartTime.Unix()
  8650. scheduleendTime := theEndTime.Unix()
  8651. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8652. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8653. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8654. //查询该床位是否有人用了
  8655. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8656. if err == nil {
  8657. if schedule.ID == 0 {
  8658. this.ServeSuccessJSON(map[string]interface{}{
  8659. "status": 0,
  8660. "msg": "请求失败",
  8661. })
  8662. } else {
  8663. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8664. if order.ID > 0 { //该机位被其他人占用了
  8665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8666. return
  8667. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8668. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8669. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8670. this.ServeSuccessJSON(map[string]interface{}{
  8671. "status": 1,
  8672. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8673. })
  8674. return
  8675. } else {
  8676. this.ServeSuccessJSON(map[string]interface{}{
  8677. "status": 0,
  8678. "msg": "",
  8679. })
  8680. }
  8681. }
  8682. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8683. this.ServeSuccessJSON(map[string]interface{}{
  8684. "status": 2,
  8685. "msg": "当前机位已有患者在使用,请重新选择!",
  8686. })
  8687. }
  8688. }
  8689. } else {
  8690. this.ServeSuccessJSON(map[string]interface{}{
  8691. "status": 0,
  8692. "msg": "",
  8693. })
  8694. }
  8695. }
  8696. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8697. orgId := this.GetMobileAdminUserInfo().Org.Id
  8698. schedule_type, _ := this.GetInt64("schedule_type")
  8699. partion_type, _ := this.GetInt64("partion_type")
  8700. start_time := this.GetString("start_time")
  8701. timeLayout := "2006-01-02"
  8702. loc, _ := time.LoadLocation("Local")
  8703. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8704. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8705. _, config := service.FindXTHisRecordByOrgId(orgId)
  8706. appId := this.GetMobileAdminUserInfo().App.Id
  8707. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8708. if err == nil {
  8709. this.ServeSuccessJSON(map[string]interface{}{
  8710. "list": list,
  8711. "config": config,
  8712. "doctorList": doctorList,
  8713. })
  8714. return
  8715. } else {
  8716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8717. return
  8718. }
  8719. }
  8720. func (this *DialysisAPIController) SaveMobileInformation() {
  8721. patient_id, _ := this.GetInt64("patient_id")
  8722. record_date, _ := this.GetInt64("record_date")
  8723. startTime := this.GetString("start_time")
  8724. module, _ := this.GetInt64("module")
  8725. remark := this.GetString("remark")
  8726. timeLayout := "2006-01-02 15:04"
  8727. loc, _ := time.LoadLocation("Local")
  8728. if len(startTime) == 0 {
  8729. utils.ErrorLog("len(start_time) == 0")
  8730. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8731. return
  8732. }
  8733. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8734. if err != nil {
  8735. utils.ErrorLog(err.Error())
  8736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8737. return
  8738. }
  8739. StartTime := theTime.Unix()
  8740. fmt.Println("startime-------------", StartTime)
  8741. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8742. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8743. information := models.XtDialysisInformation{
  8744. Module: module,
  8745. PatientId: patient_id,
  8746. RecordDate: record_date,
  8747. ApplicationDate: StartTime,
  8748. Creater: creater,
  8749. ApplicationStatus: 2,
  8750. Checker: 0,
  8751. CheckTime: 0,
  8752. Remark: remark,
  8753. UserOrgId: user_org_id,
  8754. Ctime: time.Now().Unix(),
  8755. Status: 1,
  8756. Mtime: 0,
  8757. }
  8758. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8759. if infor.ID == 0 {
  8760. service.SaveDialysisInformation(information)
  8761. }
  8762. if infor.ID > 0 {
  8763. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8764. }
  8765. this.ServeSuccessJSON(map[string]interface{}{
  8766. "information": information,
  8767. })
  8768. return
  8769. }
  8770. func (this *DialysisAPIController) GetMobileInformation() {
  8771. limit, _ := this.GetInt64("limit")
  8772. page, _ := this.GetInt64("page")
  8773. orgid := this.GetMobileAdminUserInfo().Org.Id
  8774. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8775. appid := this.GetMobileAdminUserInfo().App.Id
  8776. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8777. patients, _ := service.GetAllpatientThirty(orgid)
  8778. this.ServeSuccessJSON(map[string]interface{}{
  8779. "information": information,
  8780. "total": total,
  8781. "doclist": doclist,
  8782. "patients": patients,
  8783. })
  8784. return
  8785. }
  8786. func (this *DialysisAPIController) GetMobileInformationOne() {
  8787. limit, _ := this.GetInt64("limit")
  8788. page, _ := this.GetInt64("page")
  8789. orgid := this.GetMobileAdminUserInfo().Org.Id
  8790. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8791. appid := this.GetMobileAdminUserInfo().App.Id
  8792. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8793. patients, _ := service.GetAllpatientThirty(orgid)
  8794. this.ServeSuccessJSON(map[string]interface{}{
  8795. "information": information,
  8796. "total": total,
  8797. "doclist": doclist,
  8798. "patients": patients,
  8799. })
  8800. return
  8801. }
  8802. func (this *DialysisAPIController) CheckMobileInformation() {
  8803. id, _ := this.GetInt64("id")
  8804. application_status, _ := this.GetInt64("application_status")
  8805. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8806. checktime := time.Now().Unix()
  8807. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8808. if err == nil {
  8809. this.ServeSuccessJSON(map[string]interface{}{
  8810. "msg": "ok",
  8811. })
  8812. return
  8813. }
  8814. }
  8815. func (c *DialysisAPIController) GetControlMonitorList() {
  8816. partition, _ := c.GetInt64("partition")
  8817. monitorDate := c.GetString("date")
  8818. patient_id, _ := c.GetInt64("patient_id")
  8819. pat_type, _ := c.GetInt64("pat_type")
  8820. timeLayout := "2006-01-02"
  8821. loc, _ := time.LoadLocation("Local")
  8822. var theStartTime int64
  8823. if len(monitorDate) > 0 {
  8824. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8825. if err != nil {
  8826. theStartTime = 0
  8827. }
  8828. theStartTime = theTime.Unix()
  8829. }
  8830. adminInfo := c.GetMobileAdminUserInfo()
  8831. orgID := adminInfo.Org.Id
  8832. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8833. if err != nil {
  8834. c.ErrorLog("获取排班信息失败:%v", err)
  8835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8836. } else {
  8837. if len(monitor) > 0 {
  8838. //获取所有床位
  8839. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8840. //获取所有分区
  8841. zoneList, _ := service.GetAllZoneByList(orgID)
  8842. //获取透析处方
  8843. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8844. //获取透前评估
  8845. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8846. //获取上机
  8847. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8848. //获取透后
  8849. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8850. //获取透后监测
  8851. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8852. //获取所有的患者
  8853. patients, _ := service.GetAllPatientListByListOne(orgID)
  8854. //获取所有透析模式
  8855. treatments, _ := service.GetAllTreatModeByList(orgID)
  8856. //获取所有医嘱
  8857. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8858. //获取双人核对
  8859. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8860. //治疗小结
  8861. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8862. //待消毒
  8863. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8864. for key, item := range monitor {
  8865. // 获取床位信息
  8866. for _, it := range numberList {
  8867. if item.BedId == it.ID {
  8868. monitor[key].DeviceNumber = it
  8869. break
  8870. }
  8871. }
  8872. //获取分区信息
  8873. for _, it := range zoneList {
  8874. if item.PartitionId == it.ID {
  8875. monitor[key].DeviceZone = it
  8876. }
  8877. }
  8878. for _, prescription := range prescriptions {
  8879. if item.PatientId == prescription.PatientId {
  8880. monitor[key].Prescription = prescription
  8881. break
  8882. }
  8883. }
  8884. for _, it := range checkList {
  8885. if item.PatientId == it.PatientId {
  8886. monitor[key].DoubleCheck = it
  8887. break
  8888. }
  8889. }
  8890. for _, it := range summaryList {
  8891. if item.PatientId == it.PatientId {
  8892. monitor[key].TreatmentSummaryForList = it
  8893. break
  8894. }
  8895. }
  8896. // 透前评估
  8897. for _, assessmentBefore := range assessmentBefores {
  8898. if item.PatientId == assessmentBefore.PatientId {
  8899. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8900. break
  8901. }
  8902. }
  8903. // 透析上下机
  8904. for _, dialysisOrder := range dialysisOrders {
  8905. if item.PatientId == dialysisOrder.PatientId {
  8906. monitor[key].DialysisOrder = dialysisOrder
  8907. break
  8908. }
  8909. }
  8910. // 治疗小节
  8911. for _, afterDislysis := range AssessmentAfterDislysis {
  8912. if item.PatientId == afterDislysis.PatientId {
  8913. monitor[key].AssessmentAfterDislysis = afterDislysis
  8914. break
  8915. }
  8916. }
  8917. for _, it := range monitorlist {
  8918. if item.PatientId == it.PatientId {
  8919. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8920. }
  8921. }
  8922. for _, it := range adviceList {
  8923. if item.PatientId == it.PatientId {
  8924. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8925. }
  8926. }
  8927. for _, patient := range patients {
  8928. if item.PatientId == patient.ID {
  8929. monitor[key].MonitorPatients = patient
  8930. break
  8931. }
  8932. }
  8933. for _, treatment := range treatments {
  8934. if item.ModeId == treatment.ID {
  8935. monitor[key].TreatmentMode = treatment
  8936. break
  8937. }
  8938. }
  8939. for _, infor := range informationList {
  8940. if item.PatientId == infor.PatientId {
  8941. monitor[key].NewDeviceInformation = infor
  8942. break
  8943. }
  8944. }
  8945. }
  8946. }
  8947. }
  8948. patients, err := service.GetAllpatientFourty(orgID)
  8949. var mds []*models.NewMonitorDialysisScheduleList
  8950. if pat_type == 0 {
  8951. for _, item := range monitor {
  8952. mds = append(mds, item)
  8953. }
  8954. }
  8955. //待医嘱核对
  8956. if pat_type == 1 {
  8957. for _, item := range monitor {
  8958. if len(item.AdviceList) > 0 {
  8959. mds = append(mds, item)
  8960. }
  8961. }
  8962. }
  8963. //待开小结
  8964. if pat_type == 2 {
  8965. for _, item := range monitor {
  8966. if item.TreatmentSummaryForList == nil {
  8967. mds = append(mds, item)
  8968. }
  8969. }
  8970. }
  8971. //待下机
  8972. if pat_type == 3 {
  8973. for _, item := range monitor {
  8974. if item.DialysisOrder != nil {
  8975. if item.DialysisOrder.ID > 0 {
  8976. mds = append(mds, item)
  8977. }
  8978. }
  8979. }
  8980. }
  8981. //待消毒
  8982. if pat_type == 4 {
  8983. for _, item := range monitor {
  8984. if item.NewDeviceInformation == nil {
  8985. mds = append(mds, item)
  8986. }
  8987. }
  8988. }
  8989. //待双人核对
  8990. if pat_type == 5 {
  8991. for _, item := range monitor {
  8992. if item.DoubleCheck == nil {
  8993. mds = append(mds, item)
  8994. }
  8995. }
  8996. }
  8997. //医嘱未执行
  8998. if pat_type == 6 {
  8999. for _, item := range monitor {
  9000. if len(item.AdviceList) > 0 {
  9001. mds = append(mds, item)
  9002. }
  9003. }
  9004. }
  9005. //患者未签名
  9006. if pat_type == 7 {
  9007. for _, item := range monitor {
  9008. if item.DialysisOrder != nil {
  9009. if item.DialysisOrder.ID > 0 {
  9010. mds = append(mds, item)
  9011. }
  9012. }
  9013. }
  9014. }
  9015. //目标超滤于实际超滤不同
  9016. if pat_type == 8 {
  9017. for _, item := range monitor {
  9018. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9019. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9020. mds = append(mds, item)
  9021. }
  9022. }
  9023. }
  9024. }
  9025. //血压少于5次
  9026. if pat_type == 9 {
  9027. for _, item := range monitor {
  9028. if len(item.MonitoringRecord) < 5 {
  9029. mds = append(mds, item)
  9030. }
  9031. }
  9032. }
  9033. if pat_type == 10 {
  9034. for _, item := range monitor {
  9035. if len(item.MonitoringRecord) == 0 {
  9036. mds = append(mds, item)
  9037. }
  9038. }
  9039. }
  9040. if pat_type == 11 {
  9041. for _, item := range monitor {
  9042. if len(item.MonitoringRecord) > 0 {
  9043. mds = append(mds, item)
  9044. }
  9045. }
  9046. }
  9047. if pat_type == 12 {
  9048. for _, item := range monitor {
  9049. if len(item.MonitoringRecord) > 0 {
  9050. mds = append(mds, item)
  9051. }
  9052. }
  9053. }
  9054. if err == nil {
  9055. c.ServeSuccessJSON(map[string]interface{}{
  9056. "monitor": mds,
  9057. "patients": patients,
  9058. })
  9059. } else {
  9060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9061. }
  9062. }
  9063. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9064. admin_user_id, _ := c.GetInt64("admin_user_id")
  9065. timeStr := time.Now().Format("2006-01-02")
  9066. timeLayout := "2006-01-02 15:04:05"
  9067. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9068. timenow := timeStringToTime.Unix()
  9069. orgId := c.GetMobileAdminUserInfo().Org.Id
  9070. //查询当前护士的患者
  9071. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9072. var patientIds []int64
  9073. for _, item := range orderList {
  9074. patientIds = append(patientIds, item.PatientId)
  9075. }
  9076. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9077. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9078. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9079. //药品管理信息
  9080. _, drugStockConfig := service.FindHisConfig(orgId)
  9081. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9082. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9083. c.ServeSuccessJSON(map[string]interface{}{
  9084. "adviceList": adviceList,
  9085. "hisAdviceList": hisAdviceList,
  9086. "projectList": projectList,
  9087. "drugStockConfig": drugStockConfig,
  9088. "patientList": patientList,
  9089. "projectConfig": projectConfig,
  9090. })
  9091. }
  9092. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9093. patient_id, _ := c.GetInt64("patient_id")
  9094. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9095. c.ServeSuccessJSON(map[string]interface{}{
  9096. "recrods": recrods,
  9097. })
  9098. }
  9099. func (c *DialysisAPIController) ExMobileChangeSch() {
  9100. id_one, _ := c.GetInt64("id_one")
  9101. id_two, _ := c.GetInt64("id_two")
  9102. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9103. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9104. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9105. //if order2.ID > 0 {
  9106. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9107. // return
  9108. //}
  9109. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9110. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9111. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9112. if count > 0 {
  9113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9114. return
  9115. }
  9116. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9117. if count1 > 0 {
  9118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9119. return
  9120. }
  9121. }
  9122. err := service.UpdateScheduleThree(sch, sch_two)
  9123. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9124. if order.ID > 0 {
  9125. //查询该患者的排班机位
  9126. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9127. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9128. redis := service.RedisClient()
  9129. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9130. redis.Set(key, "", time.Second)
  9131. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9132. //清空key 值
  9133. redis.Set(keyOne, "", time.Second)
  9134. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9135. //return
  9136. }
  9137. if err == nil {
  9138. //去除当天患者排班中重复数据,保留最后一条数据
  9139. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9140. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9141. c.ServeSuccessJSON(map[string]interface{}{
  9142. "msg": "交换成功",
  9143. })
  9144. } else {
  9145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9146. return
  9147. }
  9148. }
  9149. func (c *DialysisAPIController) MobileCoverSch() {
  9150. id_one, _ := c.GetInt64("id_one")
  9151. id_two, _ := c.GetInt64("id_two")
  9152. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9153. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9154. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9155. if order.ID > 0 {
  9156. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9157. redis := service.RedisClient()
  9158. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9159. redis.Set(key, "", time.Second)
  9160. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9161. //清空key 值
  9162. redis.Set(keyOne, "", time.Second)
  9163. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9164. //return
  9165. }
  9166. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9167. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9168. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9169. if count > 0 {
  9170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9171. return
  9172. }
  9173. }
  9174. var new_sch models.Schedule
  9175. new_sch = sch
  9176. new_sch.BedId = sch_two.BedId
  9177. new_sch.ScheduleDate = sch_two.ScheduleDate
  9178. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9179. new_sch.PartitionId = sch_two.PartitionId
  9180. new_sch.ScheduleType = sch_two.ScheduleType
  9181. new_sch.ID = 0
  9182. //删除原来的排班
  9183. err := service.SaveSchTwo(sch, sch_two)
  9184. //生成新的排班
  9185. if err == nil {
  9186. err2 := service.SaveSch(&new_sch)
  9187. if err2 == nil {
  9188. //去除当天患者排班中重复数据,保留最后一条数据
  9189. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9190. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9191. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9192. c.ServeSuccessJSON(map[string]interface{}{
  9193. "msg": "覆盖成功",
  9194. "new_sch": new_sch,
  9195. })
  9196. } else {
  9197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9198. return
  9199. }
  9200. } else {
  9201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9202. return
  9203. }
  9204. }