dialysis_api_controller.go 292KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "XT_New/enums"
  12. "XT_New/models"
  13. "XT_New/service"
  14. "XT_New/utils"
  15. "github.com/astaxie/beego"
  16. "math"
  17. "net/http"
  18. "net/url"
  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. scheduals_json_str, _ := redis.Get(key).Result()
  77. redis.Set(key, "", time.Second)
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. if err != nil {
  82. this.ErrorLog("获取排班信息失败:%v", err)
  83. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  84. } else {
  85. if len(scheduals) > 0 {
  86. devices, _ := service.GetAllDevicetByListSix(orgID)
  87. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  88. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  89. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  90. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  91. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  92. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  93. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  94. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  95. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  96. for key, item := range scheduals {
  97. for _, infor := range inforMation {
  98. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  99. scheduals[key].NewDeviceInformation = infor
  100. break
  101. }
  102. }
  103. // 获取患者信息
  104. for _, patient := range patients {
  105. if item.PatientId == patient.ID {
  106. scheduals[key].SchedualPatient = patient
  107. break
  108. }
  109. }
  110. // 床位信息
  111. for _, device := range devices {
  112. if item.BedId == device.ID {
  113. scheduals[key].DeviceNumber = device
  114. break
  115. }
  116. }
  117. // 医嘱信息
  118. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  119. for _, advice := range advices {
  120. if item.PatientId == advice.PatientId {
  121. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  126. for _, hisAdvice := range hisAdvices {
  127. if item.PatientId == hisAdvice.PatientId {
  128. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  129. }
  130. }
  131. // 医嘱信息
  132. for _, prescription := range prescriptions {
  133. if item.PatientId == prescription.PatientId {
  134. scheduals[key].Prescription = prescription
  135. break
  136. }
  137. }
  138. // 透前评估
  139. for _, assessmentBefore := range assessmentBefores {
  140. if item.PatientId == assessmentBefore.PatientId {
  141. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  142. break
  143. }
  144. }
  145. // 透析上下机
  146. for _, dialysisOrder := range dialysisOrders {
  147. if item.PatientId == dialysisOrder.PatientId {
  148. scheduals[key].DialysisOrder = dialysisOrder
  149. break
  150. }
  151. }
  152. // 治疗小节
  153. for _, afterDislysis := range AssessmentAfterDislysis {
  154. if item.PatientId == afterDislysis.PatientId {
  155. scheduals[key].AssessmentAfterDislysis = afterDislysis
  156. break
  157. }
  158. }
  159. // 透后评估
  160. for _, treatmentSummary := range treatmentSummarys {
  161. if item.PatientId == treatmentSummary.PatientId {
  162. scheduals[key].TreatmentSummary = treatmentSummary
  163. break
  164. }
  165. }
  166. for _, check := range dobulecheck {
  167. if item.PatientId == check.PatientId {
  168. scheduals[key].DoubleCheck = check
  169. break
  170. }
  171. }
  172. }
  173. //缓存数据
  174. scheduals_json, err := json.Marshal(&scheduals)
  175. if err == nil {
  176. redis.Set(key, scheduals_json, time.Second*60)
  177. }
  178. }
  179. //获取今日所有的处方开的耗材
  180. _, configs := service.FindXTHisProjectByOrgId(orgID)
  181. project := make([]*models.HisPrescriptionProjectTwo, 0)
  182. if configs.ID > 0 && configs.IsOpen == 1 {
  183. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  184. }
  185. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  186. this.ServeSuccessJSON(map[string]interface{}{
  187. "scheduals": scheduals,
  188. "project": project,
  189. })
  190. }
  191. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  192. var dat []map[string]interface{}
  193. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  194. } else {
  195. }
  196. //获取今日所有的处方开的耗材
  197. _, configs := service.FindXTHisProjectByOrgId(orgID)
  198. project := make([]*models.HisPrescriptionProjectTwo, 0)
  199. if configs.ID > 0 && configs.IsOpen == 1 {
  200. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  201. }
  202. this.ServeSuccessJSON(map[string]interface{}{
  203. "scheduals": dat,
  204. "redis": "true",
  205. "date": schedualDate,
  206. "project": project,
  207. })
  208. }
  209. }
  210. // /m/api/waiting_scheduals [get]
  211. // @param date:string
  212. func (this *DialysisAPIController) WaitingScheduals() {
  213. schedualDate := this.GetString("date")
  214. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  215. if parseDateErr != nil && len(schedualDate) != 0 {
  216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  217. return
  218. }
  219. adminInfo := this.GetMobileAdminUserInfo()
  220. orgID := adminInfo.Org.Id
  221. redis := service.RedisClient()
  222. defer redis.Close()
  223. // cur_date := time.Now().Format("2006-01-02")
  224. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  225. wait_scheduals, _ := redis.Get(key).Result()
  226. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  227. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  228. if err != nil {
  229. this.ErrorLog("获取排班信息失败:%v", err)
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  231. } else {
  232. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  233. for _, s := range scheduals {
  234. returnScheduals = append(returnScheduals, s)
  235. }
  236. if len(returnScheduals) > 0 {
  237. //缓存数据
  238. wait_scheduals_json, err := json.Marshal(scheduals)
  239. if err == nil {
  240. redis.Set(key, wait_scheduals_json, time.Second*30)
  241. }
  242. }
  243. this.ServeSuccessJSON(map[string]interface{}{
  244. "scheduals": scheduals,
  245. })
  246. }
  247. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  248. var dat []map[string]interface{}
  249. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  250. } else {
  251. }
  252. this.ServeSuccessJSON(map[string]interface{}{
  253. "scheduals": dat,
  254. "redis": "true",
  255. "date": schedualDate,
  256. })
  257. }
  258. }
  259. //else{
  260. // fmt.Println("33333333")
  261. //
  262. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  263. // if err != nil {
  264. // this.ErrorLog("获取排班信息失败:%v", err)
  265. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  266. // } else {
  267. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  268. // for _, s := range scheduals {
  269. //
  270. // returnScheduals = append(returnScheduals, s)
  271. // }
  272. //
  273. // this.ServeSuccessJSON(map[string]interface{}{
  274. // "scheduals": returnScheduals,
  275. // })
  276. // }
  277. //
  278. // }
  279. //if err == nil{
  280. //
  281. //
  282. //
  283. //
  284. //
  285. //}else{
  286. //}
  287. // /m/api/dialysis/record [get]
  288. // @param patient_id:int
  289. // @param date:string (yyyy-MM-dd)
  290. func (this *DialysisAPIController) DialysisRecord() {
  291. patientID, _ := this.GetInt64("patient_id")
  292. recordDateStr := this.GetString("date")
  293. if patientID <= 0 {
  294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  295. return
  296. }
  297. if len(recordDateStr) == 0 {
  298. recordDateStr = time.Now().Format("2006-01-02")
  299. }
  300. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  301. if parseDateErr != nil {
  302. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  304. return
  305. }
  306. adminInfo := this.GetMobileAdminUserInfo()
  307. ch := make(chan struct{})
  308. count := 24 // count 表示活动的协程个数
  309. var patient models.Patients
  310. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  311. var predialysisEvaluation *models.PredialysisEvaluation
  312. var lastPredialysisEvaluation *models.PredialysisEvaluation
  313. var doctorAdvices []*models.DoctorAdvice
  314. var dialysisOrder *models.DialysisOrder
  315. var doubleCheck *models.DoubleCheck
  316. var monitorRecords []*models.MonitoringRecord
  317. var lastMonitorRecord *models.MonitoringRecord
  318. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  319. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  320. var treatmentSummary *models.TreatmentSummary
  321. var dialysisPrescribe *models.DialysisPrescription
  322. var dialysisSolution *models.DialysisSolution
  323. var lastDialysisPrescribe *models.DialysisPrescription
  324. var systemDialysisPrescribe *models.SystemPrescription
  325. var is_project_open_config models.XtHisProjectConfig
  326. var projects []*models.HisPrescriptionProject
  327. var stockType []*models.GoodsTypeOne
  328. var prepare []*models.XtDialysisBeforePrepare
  329. var lastAssessment models.XtPatientVascularAccess
  330. var lastDryWeightDislysis *models.SgjPatientDryweight
  331. var gobalConfig models.GobalConfig
  332. var operators []*models.SgjUserAdminRoles
  333. // 先走redis,没有走数据库
  334. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  335. go func() {
  336. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  337. ch <- struct{}{}
  338. }()
  339. go func() {
  340. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  341. ch <- struct{}{}
  342. }()
  343. go func() {
  344. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  345. ch <- struct{}{}
  346. }()
  347. go func() {
  348. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  349. ch <- struct{}{}
  350. }()
  351. go func() {
  352. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  353. ch <- struct{}{}
  354. }()
  355. go func() {
  356. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  357. ch <- struct{}{}
  358. }()
  359. go func() {
  360. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  361. ch <- struct{}{}
  362. }()
  363. go func() {
  364. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  365. ch <- struct{}{}
  366. }()
  367. go func() {
  368. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  369. ch <- struct{}{}
  370. }()
  371. go func() {
  372. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  373. ch <- struct{}{}
  374. }()
  375. go func() {
  376. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  377. ch <- struct{}{}
  378. }()
  379. go func() {
  380. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  381. ch <- struct{}{}
  382. }()
  383. go func() {
  384. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  385. ch <- struct{}{}
  386. }()
  387. go func() {
  388. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  389. ch <- struct{}{}
  390. }()
  391. go func() {
  392. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  393. ch <- struct{}{}
  394. }()
  395. go func() {
  396. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  397. ch <- struct{}{}
  398. }()
  399. go func() {
  400. // 先走redis,没有走数据库
  401. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  402. ch <- struct{}{}
  403. }()
  404. go func() {
  405. // 先走redis,没有走数据库
  406. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. // // 先走redis,没有走数据库
  411. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // //获取最后一次血管通路
  421. // 先走redis,没有走数据库
  422. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  423. ch <- struct{}{}
  424. }()
  425. go func() {
  426. // 先走redis,没有走数据库
  427. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  428. ch <- struct{}{}
  429. }()
  430. go func() {
  431. // 先走redis,没有走数据库
  432. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  433. ch <- struct{}{}
  434. }()
  435. go func() {
  436. // 先走redis,没有走数据库
  437. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  438. ch <- struct{}{}
  439. }()
  440. for range ch {
  441. // 每次从ch中接收数据,表明一个活动的协程结束
  442. count--
  443. // 当所有活动的协程都结束时,关闭管道
  444. if count == 0 {
  445. close(ch)
  446. }
  447. }
  448. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  449. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  450. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  451. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  452. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  453. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  454. var team_projects []*models.HisPrescriptionProject
  455. //var index int64 = 0
  456. for _, item := range temp_team_projects {
  457. //组套里面非检验项目的
  458. if item.HisProject.CostClassify != 3 {
  459. projects = append(projects, item)
  460. }
  461. //组套里面检验项目的
  462. if item.HisProject.CostClassify == 3 {
  463. team_projects = append(team_projects, item)
  464. }
  465. }
  466. team_projects = RemoveRepeatedCheckRecod(team_projects)
  467. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  468. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  469. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  470. var his_advices []*models.HisDoctorAdviceInfo
  471. if is_open_config.IsOpen == 1 {
  472. // 先走redis,没有走数据库
  473. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  474. }
  475. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  476. if is_advice_open.IsAdviceOpen == 1 {
  477. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  478. }
  479. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  480. returnData := map[string]interface{}{
  481. "patient": patient,
  482. "schedual": schedual,
  483. "prescription": dialysisPrescribe,
  484. "solution": dialysisSolution,
  485. "last_prescription": lastDialysisPrescribe,
  486. "receiver_treatment_access": receiverTreatmentAccess,
  487. "predialysis_evaluation": predialysisEvaluation,
  488. "doctor_advices": doctorAdvices,
  489. "double_check": doubleCheck,
  490. "assessment_after_dislysis": assessmentAfterDislysis,
  491. "treatment_summary": treatmentSummary,
  492. "monitor_records": monitorRecords,
  493. "dialysis_order": dialysisOrder,
  494. "operators": operators,
  495. "last_predialysis_evaluation": lastPredialysisEvaluation,
  496. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  497. "last_monitor_record": lastMonitorRecord,
  498. "config": gobalConfig,
  499. "dry_weight": lastDryWeightDislysis,
  500. "system_prescription": systemDialysisPrescribe,
  501. "his_advices": his_advices,
  502. "is_open_config": is_open_config,
  503. "stockType": stockType,
  504. "prepare": prepare,
  505. "lastAssessment": lastAssessment,
  506. "prescribeOne": prescribeOne,
  507. "is_project_open_config": is_project_open_config,
  508. "project": projects,
  509. "team_projects": team_projects,
  510. "is_advice_open": is_advice_open,
  511. "prescription_open": prescriptionConfig.IsOpen,
  512. "lastOrder": lastOrder,
  513. }
  514. this.ServeSuccessJSON(returnData)
  515. }
  516. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  517. adminInfo := c.GetMobileAdminUserInfo()
  518. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  519. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  520. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  521. returnData := map[string]interface{}{
  522. "admin_users": adminUsers,
  523. "devices": devices,
  524. "device_numbers": device_numbers,
  525. }
  526. c.ServeSuccessJSON(returnData)
  527. }
  528. func (c *DialysisAPIController) PostAtreatmentInfo() {
  529. id, _ := c.GetInt64("patient", 0)
  530. recordDateStr := c.GetString("record_date")
  531. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  532. summaryContent := c.GetString("summaryContent")
  533. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  534. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  535. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  536. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  537. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  538. nursingRecord := c.GetString("nursing_record")
  539. fmt.Println("护理记录", nursingRecord)
  540. specialRecord := c.GetString("special_record")
  541. fmt.Println("特殊记录", specialRecord)
  542. adminUserInfo := c.GetMobileAdminUserInfo()
  543. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  544. checkStaffId = adminUserInfo.AdminUser.Id
  545. deboardNurseId = adminUserInfo.AdminUser.Id
  546. treatDoctor = adminUserInfo.AdminUser.Id
  547. if id <= 0 {
  548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  549. return
  550. }
  551. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  552. if patient.ID == 0 {
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  554. return
  555. }
  556. if len(recordDateStr) == 0 {
  557. recordDateStr = time.Now().Format("2006-01-02")
  558. }
  559. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  560. if parseDateErr != nil {
  561. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  563. return
  564. }
  565. summary := models.TreatmentSummary{
  566. UserOrgId: adminUserInfo.Org.Id,
  567. PatientId: id,
  568. AssessmentDate: recordDate.Unix(),
  569. Mission: propagandaAndEducationContent,
  570. DialysisSummary: summaryContent,
  571. SjNurse: changeMedicalNurseId,
  572. ZlNurse: treatNurseId,
  573. HdNurse: checkStaffId,
  574. XjNurse: deboardNurseId,
  575. ZlDoctor: treatDoctor,
  576. CreatedTime: time.Now().Unix(),
  577. Status: 1,
  578. NursingRecord: nursingRecord,
  579. SpecialRecord: specialRecord,
  580. }
  581. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  582. if treatmentSummary.ID == 0 { //新增
  583. summary.Creater = adminUserInfo.AdminUser.Id
  584. service.AddSigleSummaryRecord(&summary)
  585. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  586. redis := service.RedisClient()
  587. //清空key 值
  588. redis.Set(key, "", time.Second)
  589. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  590. redis.Set(keyOne, "", time.Second)
  591. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  592. redis.Set(keyThree, "", time.Second)
  593. defer redis.Close()
  594. c.ServeSuccessJSON(map[string]interface{}{
  595. "summary": summary,
  596. })
  597. } else { //修改
  598. summary.Creater = treatmentSummary.Creater
  599. summary.CreatedTime = treatmentSummary.CreatedTime
  600. summary.Modifier = adminUserInfo.AdminUser.Id
  601. summary.ID = treatmentSummary.ID
  602. service.UpdateSummeRecord(&summary)
  603. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  604. redis := service.RedisClient()
  605. //清空key 值
  606. redis.Set(key, "", time.Second)
  607. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  608. redis.Set(keyOne, "", time.Second)
  609. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  610. redis.Set(keyThree, "", time.Second)
  611. defer redis.Close()
  612. c.ServeSuccessJSON(map[string]interface{}{
  613. "summary": summary,
  614. })
  615. }
  616. }
  617. func (c *DialysisAPIController) PostDoubleCheck() {
  618. id, _ := c.GetInt64("patient", 0)
  619. recordDateStr := c.GetString("record_date")
  620. checkTimeStr := c.GetString("check_time")
  621. firstCheckTimeStr := c.GetString("first_check_time")
  622. creater, _ := c.GetInt64("creater", 0)
  623. modifier, _ := c.GetInt64("modifier", 0)
  624. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  625. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  626. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  627. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  628. dialysis_item_desc := c.GetString("dialysis_item_desc")
  629. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  630. vascular_access_desc := c.GetString("vascular_access_desc")
  631. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  632. collator, _ := c.GetInt64("collator", 0)
  633. employee_number := c.GetString("employee_number")
  634. if id <= 0 {
  635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  636. return
  637. }
  638. adminUserInfo := c.GetMobileAdminUserInfo()
  639. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  640. if patient.ID == 0 {
  641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  642. return
  643. }
  644. if len(recordDateStr) == 0 {
  645. recordDateStr = time.Now().Format("2006-01-02")
  646. }
  647. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  648. if parseDateErr != nil {
  649. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  651. return
  652. }
  653. var checkDate int64
  654. if len(checkTimeStr) == 0 {
  655. checkDate = 0
  656. } else {
  657. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  658. checkDate = checkDateUnix.Unix()
  659. }
  660. var firstCheckDate int64
  661. if len(firstCheckTimeStr) == 0 {
  662. firstCheckDate = 0
  663. } else {
  664. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  665. firstCheckDate = firstCheckDateUnix.Unix()
  666. }
  667. if adminUserInfo.Org.Id == 10340 {
  668. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  669. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if check.ID == 0 {
  671. if employee_number != list.JobNumber {
  672. c.ServeSuccessJSON(map[string]interface{}{
  673. "doubleCheck": check,
  674. "msg": "2",
  675. })
  676. return
  677. }
  678. }
  679. if check.ID > 0 {
  680. if employee_number != list.JobNumber {
  681. c.ServeSuccessJSON(map[string]interface{}{
  682. "doubleCheck": check,
  683. "msg": "2",
  684. })
  685. return
  686. }
  687. }
  688. }
  689. doubleCheck := models.DoubleCheck{
  690. UserOrgId: adminUserInfo.Org.Id,
  691. PatientId: id,
  692. DialysisItemCheck: dialysis_item_check,
  693. DialysisParameterCheck: dialysis_parameter_check,
  694. VascularAccessVerification: vascular_access_verification,
  695. PipelineConnectionCheck: pipeline_connection_check,
  696. DialysisItemDesc: dialysis_item_desc,
  697. DialysisParameterDesc: dialysis_parameter_desc,
  698. VascularAccessDesc: vascular_access_desc,
  699. PipelineConnectionDesc: pipeline_connection_desc,
  700. Collator: collator,
  701. Status: 1,
  702. CreatedTime: time.Now().Unix(),
  703. CheckDate: recordDate.Unix(),
  704. UpdatedTime: time.Now().Unix(),
  705. EmployeeNumber: employee_number,
  706. }
  707. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  708. if check.ID == 0 { //新增
  709. doubleCheck.FirstCheckTime = firstCheckDate
  710. doubleCheck.CheckTime = checkDate
  711. doubleCheck.Creater = creater
  712. doubleCheck.Modifier = modifier
  713. err := service.AddSigleDoubleCheck(&doubleCheck)
  714. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  715. redis := service.RedisClient()
  716. defer redis.Close()
  717. //清空key 值
  718. redis.Set(key, "", time.Second)
  719. if err == nil {
  720. c.ServeSuccessJSON(map[string]interface{}{
  721. "doubleCheck": &doubleCheck,
  722. })
  723. }
  724. } else { //修改
  725. doubleCheck.FirstCheckTime = firstCheckDate
  726. doubleCheck.CheckTime = checkDate
  727. doubleCheck.Creater = creater
  728. doubleCheck.Modifier = modifier
  729. doubleCheck.CreatedTime = check.CreatedTime
  730. doubleCheck.ID = check.ID
  731. doubleCheck.EmployeeNumber = employee_number
  732. err := service.UpdateDoubleCheck(&doubleCheck)
  733. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  734. redis := service.RedisClient()
  735. defer redis.Close()
  736. //清空key 值
  737. redis.Set(key, "", time.Second)
  738. if err == nil {
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "doubleCheck": &doubleCheck,
  741. "msg": "1",
  742. })
  743. }
  744. }
  745. }
  746. func (c *DialysisAPIController) PostAcceptsAssessment() {
  747. id, _ := c.GetInt64("patient", 0)
  748. recordDateStr := c.GetString("record_date")
  749. way, _ := c.GetInt64("way", 0)
  750. consciousness, _ := c.GetInt64("consciousness", 0)
  751. appetite, _ := c.GetInt64("appetite", 0)
  752. condition, _ := c.GetInt64("condition", 0)
  753. posture, _ := c.GetInt64("posture")
  754. sick_condition, _ := c.GetInt64("sick_condition", 0)
  755. danger_level, _ := c.GetInt64("danger_level", 0)
  756. intake, _ := c.GetInt64("intake", 0)
  757. nutrition, _ := c.GetInt64("nutrition", 0)
  758. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  759. psychological_assessment_other := c.GetString("psychological_assessment_other")
  760. score := c.GetString("score")
  761. sick_condition_other := c.GetString("sick_condition_other")
  762. //precaution, _ := c.GetInt64("precaution", 0)
  763. precaution := c.GetString("precaution")
  764. precaution_other := c.GetString("precaution_other")
  765. psychological_other := c.GetString("psychological_other")
  766. admission_number := c.GetString("admission_number")
  767. tumble, _ := c.GetInt64("tumble")
  768. diacrisis := c.GetString("diacrisis")
  769. his_department := c.GetString("his_department")
  770. his_bed := c.GetString("his_bed")
  771. if id <= 0 {
  772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  773. return
  774. }
  775. adminUserInfo := c.GetMobileAdminUserInfo()
  776. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  777. if patient.ID == 0 {
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  779. return
  780. }
  781. //now := time.Now()
  782. //year, month, day := now.Date()
  783. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  784. //todayTimeStamp := today_time.Unix()
  785. if len(recordDateStr) == 0 {
  786. recordDateStr = time.Now().Format("2006-01-02")
  787. }
  788. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  789. if parseDateErr != nil {
  790. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  792. return
  793. }
  794. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  795. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  796. UserOrgId: adminUserInfo.Org.Id,
  797. PatientId: id,
  798. RecordDate: recordDate.Unix(),
  799. Way: way,
  800. Consciousness: consciousness,
  801. Appetite: appetite,
  802. Condition: condition,
  803. SickCondition: sick_condition,
  804. DangerLevel: danger_level,
  805. Intake: intake,
  806. Nutrition: nutrition,
  807. PsychologicalAssessment: psychological_assessment,
  808. PsychologicalAssessmentOther: psychological_assessment_other,
  809. SickConditionOther: sick_condition_other,
  810. Posture: posture,
  811. CreatedTime: time.Now().Unix(),
  812. UpdateTime: time.Now().Unix(),
  813. Status: 1,
  814. Score: score,
  815. Precaution: precaution,
  816. PrecautionOther: precaution_other,
  817. PsychologicalOther: psychological_other,
  818. AdmissionNumber: admission_number,
  819. Tumble: tumble,
  820. Diacrisis: diacrisis,
  821. HisBed: his_bed,
  822. HisDepartment: his_department,
  823. }
  824. if receiveTreatment.ID == 0 { //新增
  825. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  826. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  827. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  828. redis := service.RedisClient()
  829. defer redis.Close()
  830. //清空key 值
  831. redis.Set(key, "", time.Second)
  832. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  833. redis.Set(keyOne, "", time.Second)
  834. if err == nil {
  835. c.ServeSuccessJSON(map[string]interface{}{
  836. "receiveTreatmentAsses": receiveTreatmentAsses,
  837. })
  838. }
  839. } else { //修改
  840. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  841. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  842. // if getPermissionErr != nil {
  843. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  844. // return
  845. // } else if headNursePermission == nil {
  846. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  847. // return
  848. // }
  849. //}
  850. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  851. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  852. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  853. receiveTreatmentAsses.ID = receiveTreatment.ID
  854. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  855. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  856. redis := service.RedisClient()
  857. defer redis.Close()
  858. //清空key 值
  859. redis.Set(key, "", time.Second)
  860. fmt.Println("--------------------------------", recordDateStr)
  861. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  862. redis.Set(keyOne, "", time.Second)
  863. if err == nil {
  864. c.ServeSuccessJSON(map[string]interface{}{
  865. "receiveTreatmentAsses": receiveTreatmentAsses,
  866. })
  867. }
  868. }
  869. }
  870. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  871. id, _ := c.GetInt64("patient", 0)
  872. recordDateStr := c.GetString("record_date")
  873. weightAfter, _ := c.GetFloat("weight_after", 0)
  874. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  875. weightReduce, _ := c.GetFloat("weight_loss", 0)
  876. temperature, _ := c.GetFloat("temperature", 0)
  877. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  878. breathing_rate := c.GetString("breathing_rate")
  879. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  880. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  881. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  882. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  883. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  884. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  885. cruor := c.GetString("cruor")
  886. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  887. internalFistula := c.GetString("internal_fistula")
  888. catheter := c.GetString("catheter")
  889. complications := c.GetString("complication")
  890. remark := c.GetString("remark")
  891. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  892. dialysis_intakes := c.GetString("dialysis_intakes")
  893. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  894. fmt.Println("dialysateVolumewode 23323233223232wode", dialysateVolume)
  895. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  896. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  897. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  898. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  899. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  900. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  901. patientGose, _ := c.GetInt64("patient_gose", 0)
  902. inpatientDepartment := c.GetString("inpatient_department")
  903. observationContent := c.GetString("observation_content")
  904. observationContentOther := c.GetString("observation_content_other")
  905. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  906. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  907. in_advance_reason := c.GetString("in_advance_reason")
  908. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  909. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  910. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  911. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  912. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  913. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  914. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  915. dialyzer, _ := c.GetInt64("dialyzer", 0)
  916. in_advance_reason_other := c.GetString("in_advance_reason_other")
  917. is_eat, _ := c.GetInt64("is_eat", 0)
  918. cvc_a, _ := c.GetFloat("cvc_a", 0)
  919. cvc_v, _ := c.GetFloat("cvc_v", 0)
  920. channels, _ := c.GetInt64("channel", 0)
  921. return_blood, _ := c.GetInt64("return_blood", 0)
  922. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  923. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  924. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  925. blood_flow, _ := c.GetInt64("blood_flow", 0)
  926. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  927. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  928. sealing_fluid_special := c.GetString("sealing_fluid_special")
  929. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  930. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  931. setting_pressure := c.GetString("setting_pressure")
  932. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  933. diastolic_pressure := c.GetString("diastolic_pressure")
  934. other_complication := c.GetString("other_complication")
  935. ktv := c.GetString("ktv")
  936. urr := c.GetString("urr")
  937. hypertenison, _ := c.GetInt64("hypertenison")
  938. hypopiesia, _ := c.GetInt64("hypopiesia")
  939. leave_office_method, _ := c.GetInt64("leave_office_method")
  940. lapse, _ := c.GetInt64("lapse")
  941. consciousness, _ := c.GetInt64("consciousness")
  942. fallrisk, _ := c.GetInt64("fallrisk")
  943. machine_run := c.GetString("machine_run")
  944. after_urea := c.GetString("after_urea")
  945. pip_coagulation := c.GetString("pip_coagulation")
  946. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  947. if id <= 0 {
  948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  949. return
  950. }
  951. adminUserInfo := c.GetMobileAdminUserInfo()
  952. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  953. if patient.ID == 0 {
  954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  955. return
  956. }
  957. if len(recordDateStr) == 0 {
  958. recordDateStr = time.Now().Format("2006-01-02")
  959. }
  960. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  961. if parseDateErr != nil {
  962. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  964. return
  965. }
  966. //now := time.Now()
  967. //year, month, day := now.Date()
  968. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  969. //todayTimeStamp := today_time.Unix()
  970. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  971. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  972. UserOrgId: adminUserInfo.Org.Id,
  973. PatientId: id,
  974. AssessmentDate: recordDate.Unix(),
  975. Temperature: temperature,
  976. PulseFrequency: pulse_frequency,
  977. BreathingRate: breathing_rate,
  978. SystolicBloodPressure: systolic_blood_pressure,
  979. DiastolicBloodPressure: diastolic_blood_pressure,
  980. ActualUltrafiltration: actual_ultrafiltration,
  981. ActualDisplacement: actual_displacement,
  982. ActualTreatmentHour: actualtreatHour,
  983. ActualTreatmentMinute: actualtreatmin,
  984. WeightAfter: weightAfter,
  985. AdditionalWeight: additionalWeight,
  986. WeightLoss: weightReduce,
  987. Cruor: cruor,
  988. SymptomAfterDialysis: symptomsAfterDialysi,
  989. InternalFistula: internalFistula,
  990. Catheter: catheter,
  991. Complication: complications,
  992. DialysisIntakes: dialysateVolume,
  993. CreatedTime: time.Now().Unix(),
  994. UpdatedTime: time.Now().Unix(),
  995. Status: 1,
  996. Remark: remark,
  997. BloodAccessPartId: blood_access_part_id,
  998. BloodAccessPartOperaId: blood_access_part_opera_id,
  999. DialysisIntakesUnit: dialysis_intakes_unit,
  1000. PuncturePointOozingBlood: puncturePointOozingBlood,
  1001. PuncturePointHaematoma: puncturePointHaematoma,
  1002. InternalFistulaTremorAc: internalFistulaTremorAc,
  1003. PatientGose: patientGose,
  1004. InpatientDepartment: inpatientDepartment,
  1005. ObservationContent: observationContent,
  1006. ObservationContentOther: observationContentOther,
  1007. DialysisProcess: dialysis_process,
  1008. InAdvanceMinute: in_advance_minute,
  1009. InAdvanceReason: in_advance_reason,
  1010. HemostasisMinute: hemostasis_minute,
  1011. HemostasisOpera: hemostasis_opera,
  1012. TremorNoise: tremor_noise,
  1013. DisequilibriumSyndrome: disequilibrium_syndrome,
  1014. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1015. ArterialTube: arterial_tube,
  1016. IntravenousTube: intravenous_tube,
  1017. Dialyzer: dialyzer,
  1018. InAdvanceReasonOther: in_advance_reason_other,
  1019. IsEat: is_eat,
  1020. CvcA: cvc_a,
  1021. CvcV: cvc_v,
  1022. Channel: channels,
  1023. ReturnBlood: return_blood,
  1024. RehydrationVolume: rehydration_volume,
  1025. DialysisDuring: dialysis_during,
  1026. StrokeVolume: stroke_volume,
  1027. BloodFlow: blood_flow,
  1028. SealingFluidDispose: sealing_fluid_dispose,
  1029. SealingFluidSpecial: sealing_fluid_special,
  1030. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1031. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1032. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1033. SettingPressure: setting_pressure,
  1034. DiastolicPressure: diastolic_pressure,
  1035. OtherComplication: other_complication,
  1036. Ktv: ktv,
  1037. Urr: urr,
  1038. Hypopiesia: hypopiesia,
  1039. Hypertenison: hypertenison,
  1040. Lapse: lapse,
  1041. LeaveOfficeMethod: leave_office_method,
  1042. Consciousness: consciousness,
  1043. Fallrisk: fallrisk,
  1044. MachineRun: machine_run,
  1045. AfterUrea: after_urea,
  1046. PipCoagulation: pip_coagulation,
  1047. AccumulatedBloodVolume: accumulated_blood_volume,
  1048. }
  1049. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1050. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1051. if assessmentAfter.ID == 0 { //新增
  1052. if appRole.UserType == 2 || appRole.UserType == 1 {
  1053. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1054. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1055. } else {
  1056. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1057. }
  1058. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1059. redis := service.RedisClient()
  1060. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1061. redis.Set(keyTwo, "", time.Second)
  1062. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1063. //清空key 值
  1064. redis.Set(key, "", time.Second)
  1065. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1066. redis.Set(keyOne, "", time.Second)
  1067. defer redis.Close()
  1068. if err == nil {
  1069. c.ServeSuccessJSON(map[string]interface{}{
  1070. "assessmentAfterDislysis": assessmentAfterDislysis,
  1071. })
  1072. }
  1073. } else { //修改
  1074. if appRole.UserType == 2 || appRole.UserType == 1 {
  1075. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1076. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1077. } else {
  1078. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1079. if assessmentAfterDislysis.Creater == 0 {
  1080. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1081. }
  1082. }
  1083. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1084. assessmentAfterDislysis.ID = assessmentAfter.ID
  1085. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1086. redis := service.RedisClient()
  1087. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1088. redis.Set(keyTwo, "", time.Second)
  1089. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1090. //清空key 值
  1091. redis.Set(key, "", time.Second)
  1092. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1093. redis.Set(keyOne, "", time.Second)
  1094. fmt.Println("err233332323232232323", err)
  1095. if err == nil {
  1096. c.ServeSuccessJSON(map[string]interface{}{
  1097. "assessmentAfterDislysis": assessmentAfterDislysis,
  1098. })
  1099. }
  1100. }
  1101. }
  1102. func (c *DialysisAPIController) PostDialysisPrescription() {
  1103. id, _ := c.GetInt64("patient", 0)
  1104. recordDateStr := c.GetString("record_date")
  1105. if id <= 0 {
  1106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1107. return
  1108. }
  1109. adminUserInfo := c.GetMobileAdminUserInfo()
  1110. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1111. if patient.ID == 0 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1113. return
  1114. }
  1115. if len(recordDateStr) == 0 {
  1116. recordDateStr = time.Now().Format("2006-01-02")
  1117. }
  1118. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1119. if parseDateErr != nil {
  1120. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1122. return
  1123. }
  1124. mode_id, _ := c.GetInt64("mode_id", 0)
  1125. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1126. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1127. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1128. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1129. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1130. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1131. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1132. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1133. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1134. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1135. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1136. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1137. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1138. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1139. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1140. kalium, _ := c.GetFloat("kalium", 0)
  1141. sodium, _ := c.GetFloat("sodium", 0)
  1142. calcium, _ := c.GetFloat("calcium", 0)
  1143. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1144. glucose, _ := c.GetFloat("glucose", 0)
  1145. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1146. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1147. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1148. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1149. conductivity, _ := c.GetFloat("conductivity", 0)
  1150. remark := c.GetString("remark")
  1151. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1152. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1153. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1154. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1155. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1156. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1157. special_medicine_other := c.GetString("special_medicine_other")
  1158. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1159. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1160. blood_access, _ := c.GetInt64("blood_access", 0)
  1161. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1162. body_fluid_other := c.GetString("body_fluid_other")
  1163. niprocart, _ := c.GetInt64("niprocart", 0)
  1164. jms, _ := c.GetInt64("jms", 0)
  1165. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1166. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1167. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1168. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1169. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1170. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1171. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1172. injector, _ := c.GetInt64("injector", 0)
  1173. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1174. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1175. safe_package, _ := c.GetInt64("package", 0)
  1176. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1177. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1178. fmt.Println("预冲量", pre_impulse)
  1179. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1180. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1181. blood := c.GetString("blood")
  1182. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1183. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1184. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1185. displace_speed := c.GetString("displace_speed")
  1186. illness, _ := c.GetInt64("illness")
  1187. amylaceum := c.GetString("amylaceum")
  1188. single_time := c.GetString("single_time")
  1189. single_water := c.GetString("single_water")
  1190. replacement_flow := c.GetString("replacement_flow")
  1191. plasma_separator := c.GetString("plasma_separator")
  1192. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1193. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1194. oxygen_flow := c.GetString("oxygen_flow")
  1195. oxygen_time := c.GetString("oxygen_time")
  1196. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1197. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1198. puncture_needle := c.GetString("puncture_needle")
  1199. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1200. epo := c.GetString("epo")
  1201. epo_count, _ := c.GetFloat("epo_count", 0)
  1202. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1203. admin_user_id, _ := c.GetInt64("admin_user_id")
  1204. is_water := c.GetString("is_water")
  1205. var is_war int64
  1206. if is_water == "是" {
  1207. is_war = 1
  1208. }
  1209. if is_water == "否" {
  1210. is_war = 2
  1211. }
  1212. if is_water == "请选择" {
  1213. is_war = 0
  1214. }
  1215. drhy_water := c.GetString("drhy_water")
  1216. dry_water_hour := c.GetString("dry_water_hour")
  1217. water_machine := c.GetString("water_machine")
  1218. add_amount, _ := c.GetFloat("add_amount")
  1219. reduce_amount, _ := c.GetFloat("reduce_amount")
  1220. dialysis_remark := c.GetString("dialysis_remark")
  1221. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1222. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1223. //
  1224. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1225. // if appRole.UserType == 3 {
  1226. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1227. // if getPermissionErr != nil {
  1228. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1229. // return
  1230. // } else if headNursePermission == nil {
  1231. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1232. // return
  1233. // }
  1234. // }
  1235. //}
  1236. if mode_id > 0 {
  1237. var str string
  1238. //查找该机构用的是什么透析器
  1239. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1240. if filedConfig.ID > 0 {
  1241. str = dialyzerPerfusionApparatus
  1242. } else {
  1243. str = dialysis_dialyszers + "/" + dialysis_irrigation
  1244. }
  1245. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1246. }
  1247. //TODO 需要根据角色去判断
  1248. prescription := models.DialysisPrescription{
  1249. UserOrgId: adminUserInfo.Org.Id,
  1250. PatientId: id,
  1251. RecordDate: recordDate.Unix(),
  1252. ModeId: mode_id,
  1253. DialysisDuration: dialysis_duration,
  1254. Dialyzer: dialyzer,
  1255. PerfusionApparatus: perfusion_apparatus,
  1256. BloodFlowVolume: blood_flow_volume,
  1257. DewaterAmount: dewater_amount,
  1258. DisplaceLiqui: displace_liqui,
  1259. ReplacementWay: replacement_way,
  1260. Anticoagulant: anticoagulant,
  1261. AnticoagulantShouji: anticoagulant_shouji,
  1262. AnticoagulantWeichi: anticoagulant_weichi,
  1263. AnticoagulantZongliang: anticoagulant_zongliang,
  1264. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1265. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1266. Kalium: kalium,
  1267. Sodium: sodium,
  1268. Calcium: calcium,
  1269. Bicarbonate: bicarbonate,
  1270. Glucose: glucose,
  1271. // DryWeight: dry_weight,
  1272. DialysateFlow: dialysate_flow,
  1273. DialysateTemperature: dialysate_temperature,
  1274. // PrescriptionDoctor: prescription_doctor,
  1275. ReplacementTotal: replacement_total,
  1276. Conductivity: conductivity,
  1277. Remark: remark,
  1278. Status: 1,
  1279. CreatedTime: time.Now().Unix(),
  1280. UpdatedTime: time.Now().Unix(),
  1281. DialysisDurationMinute: dialysisDurationMinute,
  1282. DialysisDurationHour: dialysisDurationHour,
  1283. TargetUltrafiltration: targetUltrafiltration,
  1284. DialysateFormulation: dialysateFormulation,
  1285. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1286. BodyFluid: body_fluid,
  1287. SpecialMedicine: special_medicine,
  1288. SpecialMedicineOther: special_medicine_other,
  1289. DisplaceLiquiPart: displace_liqui_part,
  1290. DisplaceLiquiValue: displace_liqui_value,
  1291. BloodAccess: blood_access,
  1292. Ultrafiltration: ultrafiltration,
  1293. BodyFluidOther: body_fluid_other,
  1294. Niprocart: niprocart,
  1295. Jms: jms,
  1296. FistulaNeedleSet: fistula_needle_set,
  1297. FistulaNeedleSet16: fistula_needle_set_16,
  1298. Hemoperfusion: hemoperfusion,
  1299. DialyserSterilised: dialyser_sterilised,
  1300. Filtryzer: filtryzer,
  1301. Dialyzers: dialyzers,
  1302. Injector: injector,
  1303. Bloodlines: bloodlines,
  1304. TubingHemodialysis: tubing_hemodialysis,
  1305. Package: safe_package,
  1306. ALiquid: a_liquid,
  1307. TargetKtv: target_ktv,
  1308. PreImpulse: pre_impulse,
  1309. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1310. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1311. Blood: blood,
  1312. DialysisDialyszers: dialysis_dialyszers,
  1313. DialysisIrrigation: dialysis_irrigation,
  1314. AntioxidantCommodityName: antioxidant_commodity_name,
  1315. DisplaceSpeed: displace_speed,
  1316. Illness: illness,
  1317. Amylaceum: amylaceum,
  1318. SingleTime: single_time,
  1319. SingleWater: single_water,
  1320. ReplacementFlow: replacement_flow,
  1321. PlasmaSeparator: plasma_separator,
  1322. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1323. OxygenUptake: oxygen_uptake,
  1324. OxygenFlow: oxygen_flow,
  1325. OxygenTime: oxygen_time,
  1326. HemodialysisPipelines: hemodialysis_pipelines,
  1327. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1328. PunctureNeedle: puncture_needle,
  1329. PunctureNeedleCount: puncture_needle_count,
  1330. Epo: epo,
  1331. EpoCount: epo_count,
  1332. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1333. AdminUserId: admin_user_id,
  1334. IsWater: is_war,
  1335. DrhyWater: drhy_water,
  1336. DryWaterHour: dry_water_hour,
  1337. WaterMachine: water_machine,
  1338. AddAmount: add_amount,
  1339. ReduceAmount: reduce_amount,
  1340. DialysisRemark: dialysis_remark,
  1341. }
  1342. //查询最近透析准备表里是否存在 透析器 灌流器
  1343. //
  1344. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1345. //
  1346. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1347. //
  1348. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1349. //if len(mation)>0{
  1350. // for _, item := range splitStr {
  1351. // for _,it := range mation{
  1352. // if(item == it.SpecificationName){
  1353. //
  1354. // //查询最近一次的透析器
  1355. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1356. //
  1357. // if errcode == gorm.ErrRecordNotFound{
  1358. // //插入数据
  1359. // prepare := models.DialysisBeforePrepare{
  1360. // UserOrgId: adminUserInfo.Org.Id,
  1361. // PatientId: id,
  1362. // RecordDate: recordDate.Unix(),
  1363. // GoodTypeId: it.GoodTypeId,
  1364. // GoodId: it.ID,
  1365. // Count: 1,
  1366. // Ctime: time.Now().Unix(),
  1367. // Creater: adminUserInfo.AdminUser.Id,
  1368. // Status:1,
  1369. //
  1370. // }
  1371. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1372. // fmt.Println("",errcode)
  1373. // }
  1374. // }
  1375. // }
  1376. //
  1377. // }
  1378. //
  1379. // for _, item := range splitIrrigation {
  1380. // for _,it := range mation{
  1381. // if(item == it.SpecificationName){
  1382. // //查询最近一次的透析器
  1383. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1384. // if errcode == gorm.ErrRecordNotFound{
  1385. // //插入数据
  1386. // prepare := models.DialysisBeforePrepare{
  1387. // UserOrgId: adminUserInfo.Org.Id,
  1388. // PatientId: id,
  1389. // RecordDate: recordDate.Unix(),
  1390. // GoodTypeId: it.GoodTypeId,
  1391. // GoodId: it.ID,
  1392. // Count: 1,
  1393. // Ctime: time.Now().Unix(),
  1394. // Creater: adminUserInfo.AdminUser.Id,
  1395. // Status:1,
  1396. //
  1397. // }
  1398. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1399. // fmt.Println(errcode)
  1400. // }
  1401. // }
  1402. // }
  1403. // }
  1404. //}
  1405. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1406. if dialysisPrescription.ID == 0 { //新增
  1407. if appRole.UserType == 2 || appRole.UserType == 1 {
  1408. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1409. }
  1410. prescription.Creater = adminUserInfo.AdminUser.Id
  1411. //针对河间咸得
  1412. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1413. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1414. prescription.DisplaceLiquiPart = 0
  1415. prescription.DisplaceLiquiValue = 0
  1416. }
  1417. }
  1418. err := service.AddSigleRecord(&prescription)
  1419. //获取key,清空redis
  1420. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1421. redis := service.RedisClient()
  1422. //清空key 值
  1423. redis.Set(key, "", time.Second)
  1424. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1425. //清空key 值
  1426. redis.Set(keyOne, "", time.Second)
  1427. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1428. //清空key 值
  1429. redis.Set(keyTwo, "", time.Second)
  1430. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1431. redis.Set(keySix, "", time.Second)
  1432. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1433. redis.Set(keySeven, "", time.Second)
  1434. if err == nil {
  1435. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1436. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1437. //清空key 值
  1438. redis.Set(keyThree, "", time.Second)
  1439. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1440. //清空key 值
  1441. redis.Set(keyFour, "", time.Second)
  1442. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1443. redis.Set(keyFive, "", time.Second)
  1444. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1445. redis.Set(keySix, "", time.Second)
  1446. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1447. redis.Set(keySeven, "", time.Second)
  1448. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1449. //清空key 值
  1450. redis.Set(keyOne, "", time.Second)
  1451. if updateErr != nil {
  1452. utils.ErrorLog("%v", updateErr)
  1453. }
  1454. defer redis.Close()
  1455. c.ServeSuccessJSON(map[string]interface{}{
  1456. "prescription": prescription,
  1457. })
  1458. }
  1459. } else { //修改
  1460. //if mode_id > 0 {
  1461. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1462. //}
  1463. //if template.TemplateId == 1 {
  1464. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1465. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1466. // if getPermissionErr != nil {
  1467. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1468. // return
  1469. // } else if headNursePermission == nil {
  1470. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1471. // return
  1472. // }
  1473. // }
  1474. //}
  1475. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1476. prescription.Modifier = adminUserInfo.AdminUser.Id
  1477. if appRole.UserType == 2 || appRole.UserType == 1 {
  1478. prescription_doctor := adminUserInfo.AdminUser.Id
  1479. prescription.PrescriptionDoctor = prescription_doctor
  1480. } else {
  1481. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1482. }
  1483. if dialysisPrescription.Creater == 0 { //体重称
  1484. prescription.Creater = adminUserInfo.AdminUser.Id
  1485. } else {
  1486. prescription.Creater = dialysisPrescription.Creater
  1487. }
  1488. prescription.ID = dialysisPrescription.ID
  1489. err := service.UpDateDialysisPrescription(&prescription)
  1490. //获取key,清空redis
  1491. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1492. redis := service.RedisClient()
  1493. //清空key 值
  1494. redis.Set(key, "", time.Second)
  1495. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1496. //清空key 值
  1497. redis.Set(keyOne, "", time.Second)
  1498. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1499. redis.Set(keySix, "", time.Second)
  1500. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1501. redis.Set(keySeven, "", time.Second)
  1502. if err == nil {
  1503. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1504. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1505. //清空key 值
  1506. redis.Set(keyOne, "", time.Second)
  1507. defer redis.Close()
  1508. if updateErr != nil {
  1509. utils.ErrorLog("%v", updateErr)
  1510. }
  1511. c.ServeSuccessJSON(map[string]interface{}{
  1512. "prescription": prescription,
  1513. })
  1514. }
  1515. }
  1516. }
  1517. func (c *DialysisAPIController) Finish() {
  1518. id, _ := c.GetInt64("patient", 0)
  1519. recordDateStr := c.GetString("record_date")
  1520. nurseID, _ := c.GetInt64("nurse")
  1521. end_time := c.GetString("end_time")
  1522. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1523. internal_fistula := c.GetString("blood_access_internal_fistula")
  1524. catheter := c.GetString("catheter")
  1525. cruor := c.GetString("cruor")
  1526. mission := c.GetString("mission")
  1527. if id <= 0 || nurseID <= 0 {
  1528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1529. return
  1530. }
  1531. adminUserInfo := c.GetMobileAdminUserInfo()
  1532. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1533. if patient.ID == 0 {
  1534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1535. return
  1536. }
  1537. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1538. if getNurseErr != nil {
  1539. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1541. return
  1542. } else if nurse == nil {
  1543. c.ErrorLog("护士不存在")
  1544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1545. return
  1546. }
  1547. if len(recordDateStr) == 0 {
  1548. recordDateStr = time.Now().Format("2006-01-02")
  1549. }
  1550. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1551. if parseDateErr != nil {
  1552. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1554. return
  1555. }
  1556. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1557. if parseEndDateErr != nil {
  1558. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1560. return
  1561. }
  1562. //now := time.Now()
  1563. //year, month, day := now.Date()
  1564. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1565. //todayTimeStamp := today_time.Unix()
  1566. // 获取当天的第一条透析纪录
  1567. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1568. if getMonitorRecordsErr != nil {
  1569. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1571. return
  1572. }
  1573. // 获取当前的最后一条透析纪录
  1574. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1575. if getMonitorRecordsErr != nil {
  1576. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1578. return
  1579. }
  1580. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1581. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1582. if getAADErr != nil {
  1583. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1585. return
  1586. }
  1587. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1588. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1589. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1590. if assessmentAfterDislysis != nil {
  1591. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1592. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1593. } else {
  1594. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1595. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1596. tempassessmentAfterDislysis.Status = 1
  1597. tempassessmentAfterDislysis.PatientId = id
  1598. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1599. }
  1600. //长沙南雅
  1601. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  1602. //获取最后一条透析处方数据
  1603. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1604. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1605. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  1606. }
  1607. if dialysisOrder.Stage == 1 {
  1608. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1609. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1610. fmt.Println(value)
  1611. a, b := math.Modf(value)
  1612. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1613. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1614. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1615. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1616. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1617. }
  1618. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1619. //var num1 int64
  1620. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1621. //fmt.Println(num1)
  1622. //sub := float64(num1 / 3600)
  1623. //fmt.Println(sub)
  1624. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1625. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1626. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1627. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1628. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1629. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1630. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1631. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1632. if adminUserInfo.Org.Id != 10445 {
  1633. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1634. }
  1635. //北方营口医院
  1636. if adminUserInfo.Org.Id == 10445 {
  1637. //获取最后一条透析处方数据
  1638. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1639. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  1640. } else {
  1641. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1642. }
  1643. //新化博翔
  1644. if adminUserInfo.Org.Id == 10447 {
  1645. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1646. }
  1647. }
  1648. 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 {
  1649. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1650. if evaluation.SystolicBloodPressure == 0 {
  1651. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  1652. pre := models.PredialysisEvaluation{
  1653. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  1654. }
  1655. fmt.Println("prew", pre)
  1656. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1657. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1658. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1659. redis := service.RedisClient()
  1660. redis.Set(key, "", time.Second)
  1661. redis.Set(keyOne, "", time.Second)
  1662. defer redis.Close()
  1663. fmt.Println(getNurseErr)
  1664. }
  1665. if evaluation.DiastolicBloodPressure == 0 {
  1666. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  1667. pres := models.PredialysisEvaluation{
  1668. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  1669. }
  1670. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1671. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1672. redis := service.RedisClient()
  1673. redis.Set(key, "", time.Second)
  1674. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1675. redis.Set(keyOne, "", time.Second)
  1676. defer redis.Close()
  1677. fmt.Println(getNurseErr)
  1678. }
  1679. if evaluation.PulseFrequency == 0 {
  1680. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1681. press := models.PredialysisEvaluation{
  1682. PulseFrequency: evaluation.PulseFrequency,
  1683. }
  1684. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1685. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1686. redis := service.RedisClient()
  1687. redis.Set(key, "", time.Second)
  1688. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1689. redis.Set(keyOne, "", time.Second)
  1690. defer redis.Close()
  1691. fmt.Println(getNurseErr)
  1692. }
  1693. if evaluation.Temperature == 0 {
  1694. evaluation.Temperature = fmonitorRecords.Temperature
  1695. press := models.PredialysisEvaluation{
  1696. Temperature: evaluation.Temperature,
  1697. }
  1698. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1699. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1700. redis := service.RedisClient()
  1701. redis.Set(key, "", time.Second)
  1702. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1703. redis.Set(keyOne, "", time.Second)
  1704. defer redis.Close()
  1705. fmt.Println(getNurseErr)
  1706. }
  1707. }
  1708. if adminUserInfo.Org.Id == 9583 {
  1709. //获取透析处方的最后一条数据
  1710. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  1711. if diaerr != nil {
  1712. c.ErrorLog("获取透析处方失败:%v", diaerr)
  1713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1714. return
  1715. }
  1716. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  1717. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  1718. }
  1719. }
  1720. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  1721. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1722. }
  1723. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  1724. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1725. }
  1726. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  1727. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1728. }
  1729. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  1730. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1731. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1732. }
  1733. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  1734. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1735. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1736. }
  1737. if lastAssessmentAfterDislysis != nil {
  1738. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1739. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1740. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1741. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1742. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1743. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1744. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1745. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1746. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1747. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1748. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1749. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1750. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1751. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1752. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1753. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1754. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1755. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1756. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1757. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1758. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1759. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1760. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1761. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1762. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1763. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1764. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1765. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1766. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1767. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1768. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1769. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1770. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1771. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1772. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1773. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1774. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1775. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1776. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1777. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1778. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1779. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1780. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1781. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1782. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1783. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1784. }
  1785. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1786. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1787. redis := service.RedisClient()
  1788. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1789. redis.Set(keyOne, "", time.Second)
  1790. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  1791. redis.Set(keyTwo, "", time.Second)
  1792. defer redis.Close()
  1793. //清空key 值
  1794. redis.Set(key, "", time.Second)
  1795. if err != nil {
  1796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1797. return
  1798. }
  1799. if dialysisOrder == nil {
  1800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1801. return
  1802. }
  1803. if dialysisOrder.Stage == 2 {
  1804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1805. return
  1806. }
  1807. if dialysisOrder.Stage == 1 {
  1808. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  1809. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1810. redis := service.RedisClient()
  1811. defer redis.Close()
  1812. //清空key 值
  1813. redis.Set(key, "", time.Second)
  1814. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1815. redis.Set(keyOne, "", time.Second)
  1816. //结束时候透析次数加1
  1817. service.UpdateSolutionByPatientId(id)
  1818. //下机完自动消毒,针对长沙南雅
  1819. if dialysisOrder.Stage == 1 {
  1820. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1821. //根据床位号获取设备型号
  1822. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  1823. //查询使用消毒最后一条消毒记录
  1824. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  1825. fmt.Println("err", err)
  1826. if err == gorm.ErrRecordNotFound {
  1827. //查找排班
  1828. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  1829. //查询改设备是否有消毒计划
  1830. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  1831. //根据床位号获取设备id
  1832. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  1833. //查询病人信息
  1834. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  1835. var con = ""
  1836. if patients.IsInfectious == 0 {
  1837. con = ""
  1838. }
  1839. if patients.IsInfectious == 1 {
  1840. con = "无"
  1841. }
  1842. if patients.IsInfectious == 2 {
  1843. con = "有"
  1844. }
  1845. if errcode == nil {
  1846. var end_time int64
  1847. end_time = endDate.Unix() + plan.DisinfecTime*60
  1848. //新增消毒
  1849. information := models.DeviceInformation{
  1850. Date: dialysisOrder.DialysisDate,
  1851. Zone: dialysisOrder.ZoneId,
  1852. Class: dialysisOrder.SchedualType,
  1853. BedNumber: dialysisOrder.BedID,
  1854. PatientId: dialysisOrder.PatientId,
  1855. DialysisMode: scheduleByPatient.ModeId,
  1856. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  1857. Disinfection: 1,
  1858. DialysisConcentration: 1,
  1859. DisinfectionStatus: 1,
  1860. Move: 1,
  1861. UserOrgId: dialysisOrder.UserOrgId,
  1862. DisinfectType: plan.Way,
  1863. DisinfectantType: plan.MachineDisinfectant,
  1864. FluidPath: plan.DisinfectanWay, //液路消毒方式
  1865. Disinfectant: plan.Disinfectant,
  1866. Ctime: time.Now().Unix(),
  1867. Status: 1,
  1868. SignName: nurseID,
  1869. EquimentId: addmacher.ID,
  1870. DisinfectionResidue: 2,
  1871. Bed: addmacher.BedNumber,
  1872. StartTime: dialysisOrder.StartTime,
  1873. EndTime: dialysisOrder.EndTime,
  1874. Contagion: con,
  1875. WeightLoss: 0,
  1876. Hyperfiltratio: 0,
  1877. DialysisHour: "",
  1878. MachineRun: 1,
  1879. DisinfecStartime: endDate.Unix(),
  1880. DisinfecEndtime: end_time,
  1881. }
  1882. err := service.CreateInformationTwo(&information)
  1883. fmt.Println("报错", err)
  1884. }
  1885. }
  1886. }
  1887. }
  1888. dialysisOrder.Stage = 2
  1889. dialysisOrder.FinishNurse = nurseID
  1890. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  1891. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  1892. dialysisOrder.EndTime = endDate.Unix()
  1893. go func() {
  1894. ssoDomain := beego.AppConfig.String("call_domain")
  1895. api := ssoDomain + "/index/downpatient"
  1896. values := make(url.Values)
  1897. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  1898. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1899. values.Set("patient_id", strconv.FormatInt(id, 10))
  1900. http.PostForm(api, values)
  1901. }()
  1902. if err == nil {
  1903. c.ServeSuccessJSON(map[string]interface{}{
  1904. "dialysisOrder": dialysisOrder,
  1905. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1906. })
  1907. } else {
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1909. }
  1910. }
  1911. }
  1912. func (c *DialysisAPIController) GetAllZone() {
  1913. adminUserInfo := c.GetMobileAdminUserInfo()
  1914. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  1915. if err == nil {
  1916. c.ServeSuccessJSON(map[string]interface{}{
  1917. "zone": zone,
  1918. })
  1919. }
  1920. }
  1921. func (c *DialysisAPIController) GetSchedualPatientsList() {
  1922. adminUserInfo := c.GetMobileAdminUserInfo()
  1923. page, _ := c.GetInt64("page", 1)
  1924. limit, _ := c.GetInt64("limit", 10)
  1925. schedulType, _ := c.GetInt64("schedul_type", 0)
  1926. startTime, _ := c.GetInt64("schedul_time", 0)
  1927. partitionType, _ := c.GetInt64("partition_type", 0)
  1928. keywords := c.GetString("keywords")
  1929. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  1930. if err == nil {
  1931. c.ServeSuccessJSON(map[string]interface{}{
  1932. "schedule": dialysisSchedule,
  1933. })
  1934. }
  1935. return
  1936. }
  1937. // /m/api/dialysis/start [post]
  1938. // @param patient_id:int
  1939. // @param record_date:string 排班时间 (yyyy-mm-dd)
  1940. // @param nurse:int 上机护士
  1941. // @param bed:int 床位号
  1942. func (this *DialysisAPIController) StartDialysis() {
  1943. patientID, _ := this.GetInt64("patient_id")
  1944. recordDateStr := this.GetString("record_date")
  1945. nurseID, _ := this.GetInt64("nurse")
  1946. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1947. blood_drawing, _ := this.GetInt64("blood_drawing")
  1948. schedual_type, _ := this.GetInt64("schedual_type")
  1949. bedID, _ := this.GetInt64("bed")
  1950. start_time := this.GetString("start_time")
  1951. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1952. change_nurse, _ := this.GetInt64("change_nurse")
  1953. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1954. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1955. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  1956. puncture_needle := this.GetString("puncture_needle")
  1957. puncture_way := this.GetString("puncture_way")
  1958. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  1959. dialysis_irrigation := this.GetString("dialysis_irrigation")
  1960. blood_access_id, _ := this.GetInt64("blood_access_id")
  1961. zone_id, _ := this.GetInt64("zone_id")
  1962. elecsign := this.GetString("url")
  1963. nuclein_date_str := this.GetString("nuclein_date_str")
  1964. schedule_remark := this.GetString("schedule_remark")
  1965. order_remark := this.GetString("order_remark")
  1966. catheter_operation := this.GetString("catheter_operation")
  1967. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  1968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1969. return
  1970. }
  1971. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1972. if parseStartDateErr != nil {
  1973. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1975. return
  1976. }
  1977. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1978. if parseErr != nil {
  1979. this.ErrorLog("时间解析失败:%v", parseErr)
  1980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1981. return
  1982. }
  1983. adminUserInfo := this.GetMobileAdminUserInfo()
  1984. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  1985. if getPatientErr != nil {
  1986. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1988. return
  1989. } else if patient == nil {
  1990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1991. return
  1992. }
  1993. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1994. if getNurseErr != nil {
  1995. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1996. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1997. return
  1998. } else if nurse == nil {
  1999. this.ErrorLog("护士不存在")
  2000. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2001. return
  2002. }
  2003. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2004. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2005. if getDeviceNumberErr != nil {
  2006. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2007. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2008. return
  2009. } else if deviceNumber == nil {
  2010. this.ErrorLog("床位号不存在")
  2011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2012. return
  2013. }
  2014. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2015. if getRecordErr != nil {
  2016. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2018. return
  2019. } else if dialysisRecord != nil {
  2020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2021. return
  2022. }
  2023. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2024. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2025. timeLayout := "2006-01-02 15:04:05"
  2026. loc, _ := time.LoadLocation("Local")
  2027. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2028. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2029. schedulestartTime := theStartTime.Unix()
  2030. scheduleendTime := theEndTime.Unix()
  2031. var theNucleinDate int64
  2032. timeLayoutOne := "2006-01-02"
  2033. if len(nuclein_date_str) > 0 {
  2034. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2035. if err != nil {
  2036. utils.ErrorLog(err.Error())
  2037. }
  2038. theNucleinDate = theTime.Unix()
  2039. }
  2040. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2041. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2042. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2043. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2044. //查询该床位是否有人用了
  2045. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2046. if err == gorm.ErrRecordNotFound { //空床位
  2047. // 修改了床位逻辑
  2048. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2049. if daySchedule.ID > 0 {
  2050. daySchedule.PartitionId = deviceNumber.ZoneID
  2051. daySchedule.BedId = bedID
  2052. daySchedule.ScheduleType = schedual_type
  2053. daySchedule.UpdatedTime = time.Now().Unix()
  2054. xtSchedule := models.Schedule{
  2055. PartitionId: deviceNumber.ZoneID,
  2056. BedId: bedID,
  2057. ScheduleType: schedual_type,
  2058. UpdatedTime: time.Now().Unix(),
  2059. }
  2060. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2061. if err != nil {
  2062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2063. return
  2064. }
  2065. }
  2066. } else if err == nil {
  2067. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2068. if order.ID > 0 { //该机位被其他人占用了
  2069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2070. return
  2071. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2072. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2073. if daySchedule.ID > 0 {
  2074. //daySchedule.PartitionId = deviceNumber.ZoneID
  2075. //daySchedule.BedId = bedID
  2076. //daySchedule.ScheduleType = schedual_type
  2077. //daySchedule.UpdatedTime = time.Now().Unix()
  2078. //err := service.UpdateSchedule(&daySchedule)
  2079. //xtSchedule := models.Schedule{
  2080. // PartitionId: deviceNumber.ZoneID,
  2081. // BedId: bedID,
  2082. // ScheduleType: schedual_type,
  2083. // UpdatedTime: time.Now().Unix(),
  2084. //}
  2085. //err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2086. service.UpdateScheduleTwo(daySchedule, schedule)
  2087. }
  2088. }
  2089. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2091. return
  2092. }
  2093. //else if order.ID == 0 { //该床位没被占用
  2094. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2095. // if daySchedule.ID > 0 {
  2096. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2097. // //daySchedule.BedId = bedID
  2098. // //daySchedule.ScheduleType = schedual_type
  2099. // //daySchedule.UpdatedTime = time.Now().Unix()
  2100. // //err := service.UpdateSchedule(&daySchedule)
  2101. // xtSchedule := models.Schedule{
  2102. // PartitionId: deviceNumber.ZoneID,
  2103. // BedId: bedID,
  2104. // ScheduleType: schedual_type,
  2105. // UpdatedTime: time.Now().Unix(),
  2106. // }
  2107. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2108. // if err != nil {
  2109. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2110. // return
  2111. // }
  2112. // }
  2113. //}
  2114. //}
  2115. } else if err != nil {
  2116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2117. return
  2118. }
  2119. dialysisRecord = &models.DialysisOrder{
  2120. DialysisDate: recordDate.Unix(),
  2121. UserOrgId: adminUserInfo.Org.Id,
  2122. PatientId: patientID,
  2123. Stage: 1,
  2124. BedID: bedID,
  2125. StartNurse: nurseID,
  2126. Status: 1,
  2127. StartTime: startDate.Unix(),
  2128. CreatedTime: time.Now().Unix(),
  2129. UpdatedTime: time.Now().Unix(),
  2130. PunctureNurse: puncture_nurse,
  2131. Creator: adminUserInfo.AdminUser.Id,
  2132. Modifier: adminUserInfo.AdminUser.Id,
  2133. SchedualType: schedual_type,
  2134. WashpipeNurse: washpipe_nurse,
  2135. ChangeNurse: change_nurse,
  2136. DifficultPunctureNurse: difficult_puncture_nurse,
  2137. NewFistulaNurse: new_fistula_nurse,
  2138. ZoneId: zone_id,
  2139. QualityNurseId: quality_nurse_id,
  2140. PunctureNeedle: puncture_needle,
  2141. PunctureWay: puncture_way,
  2142. DialysisIrrigation: dialysis_irrigation,
  2143. DialysisDialyszers: dialysis_dialyszers,
  2144. BloodAccessId: blood_access_id,
  2145. Url: elecsign,
  2146. NucleinDate: theNucleinDate,
  2147. ScheduleRemark: schedule_remark,
  2148. OrderRemark: order_remark,
  2149. CatheterOperation: catheter_operation,
  2150. }
  2151. //查询该床位是否有人用了
  2152. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2153. if errorscode == gorm.ErrRecordNotFound {
  2154. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2155. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2156. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2157. //统计该患者总次数
  2158. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2159. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2160. }
  2161. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2162. //统计该患者总次数
  2163. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2164. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2165. }
  2166. redis := service.RedisClient()
  2167. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2168. redis.Set(key, "", time.Second)
  2169. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2170. //清空key 值
  2171. redis.Set(keyOne, "", time.Second)
  2172. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2173. //清空key 值
  2174. redis.Set(keyTwo, "", time.Second)
  2175. if createErr != nil {
  2176. this.ErrorLog("上机失败:%v", createErr)
  2177. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2178. return
  2179. }
  2180. }
  2181. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2182. var tempdispose string
  2183. // 只针对中能建
  2184. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2185. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2186. }
  2187. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2188. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2189. }
  2190. var ultrafiltration_rate float64
  2191. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2192. //后期预增脱水量
  2193. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2194. if prescription.ID > 0 {
  2195. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2196. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2197. if (template.TemplateId == 6 || template.TemplateId == 32) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2198. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2199. }
  2200. //针对医师汇
  2201. if adminUserInfo.Org.Id == 10121 {
  2202. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2203. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2204. }
  2205. //针对通道
  2206. if adminUserInfo.Org.Id == 10234 {
  2207. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2208. }
  2209. //针对监利大垸医院
  2210. if template.TemplateId == 41 {
  2211. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2212. }
  2213. //针对肇庆三鹤血液透析中心
  2214. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 {
  2215. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2216. }
  2217. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2218. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2219. }
  2220. // 只针对方济医院
  2221. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2222. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2223. ultrafiltration_rate = value
  2224. }
  2225. }
  2226. }
  2227. record := models.MonitoringRecord{
  2228. UserOrgId: adminUserInfo.Org.Id,
  2229. PatientId: patientID,
  2230. DialysisOrderId: dialysisRecord.ID,
  2231. MonitoringDate: schedulestartTime,
  2232. OperateTime: startDate.Unix(),
  2233. // MonitoringTime: recordTime,
  2234. MonitoringNurse: nurseID,
  2235. Dispose: tempdispose,
  2236. UltrafiltrationRate: ultrafiltration_rate,
  2237. UltrafiltrationVolume: 0,
  2238. Status: 1,
  2239. CreatedTime: time.Now().Unix(),
  2240. UpdatedTime: time.Now().Unix(),
  2241. }
  2242. //只针对广慈医院
  2243. 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 {
  2244. // 查询病人是否有透前评估数据
  2245. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2246. //如果有数据就插入
  2247. if errcode == nil {
  2248. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2249. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2250. record.BreathingRate = befor.BreathingRate
  2251. if adminUserInfo.Org.Id != 10445 {
  2252. record.PulseFrequency = befor.PulseFrequency
  2253. }
  2254. record.Temperature = befor.Temperature
  2255. }
  2256. }
  2257. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2258. if newdialysisRecord.ID > 0 {
  2259. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2260. record.Temperature = 36.5
  2261. record.ArterialPressure = -100
  2262. record.DialysateTemperature = 36.5
  2263. record.Conductivity = 14
  2264. record.BreathingRate = "20"
  2265. record.VenousPressure = 80
  2266. record.TransmembranePressure = 60
  2267. }
  2268. //针对新化博翔
  2269. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2270. record.BloodOxygenSaturation = "99"
  2271. record.Conductivity = 14
  2272. record.DialysateTemperature = 36.5
  2273. record.BreathingRate = "20"
  2274. }
  2275. //针对兰溪人民医院的需求
  2276. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2277. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2278. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2279. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2280. record.Temperature = befor.Temperature
  2281. record.PulseFrequency = befor.PulseFrequency
  2282. record.BreathingRate = befor.BreathingRate
  2283. }
  2284. //新化博翔
  2285. if adminUserInfo.Org.Id == 10447 {
  2286. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2287. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2288. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2289. record.BreathingRate = befor.BreathingRate
  2290. }
  2291. if adminUserInfo.Org.Id == 9829 {
  2292. record.PulseFrequency = 80
  2293. record.Temperature = 36.5
  2294. }
  2295. err := service.CreateMonitor(&record)
  2296. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  2297. redis := service.RedisClient()
  2298. //清空key 值
  2299. redis.Set(key, "", time.Second)
  2300. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  2301. redis.Set(keyOne, "", time.Second)
  2302. defer redis.Close()
  2303. if err != nil {
  2304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2305. return
  2306. }
  2307. }
  2308. go func() {
  2309. ssoDomain := beego.AppConfig.String("call_domain")
  2310. api := ssoDomain + "/index/uppatient"
  2311. values := make(url.Values)
  2312. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  2313. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2314. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  2315. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  2316. http.PostForm(api, values)
  2317. }()
  2318. this.ServeSuccessJSON(map[string]interface{}{
  2319. "dialysis_order": newdialysisRecord,
  2320. "monitor": record,
  2321. })
  2322. return
  2323. }
  2324. func (c *DialysisAPIController) PostSolution() {
  2325. id, _ := c.GetInt64("patient", 0)
  2326. recordDateStr := c.GetString("record_date")
  2327. if id <= 0 {
  2328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2329. return
  2330. }
  2331. adminUserInfo := c.GetMobileAdminUserInfo()
  2332. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2333. if patient.ID == 0 {
  2334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2335. return
  2336. }
  2337. if len(recordDateStr) == 0 {
  2338. recordDateStr = time.Now().Format("2006-01-02")
  2339. }
  2340. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2341. if parseDateErr != nil {
  2342. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2344. return
  2345. }
  2346. mode_id, _ := c.GetInt64("mode_id", 0)
  2347. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  2348. dialyzer, _ := c.GetInt64("dialyzer", 0)
  2349. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  2350. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2351. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  2352. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  2353. replacement_way, _ := c.GetInt64("replacement_way", 0)
  2354. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  2355. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  2356. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  2357. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  2358. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  2359. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  2360. kalium, _ := c.GetFloat("kalium", 0)
  2361. sodium, _ := c.GetFloat("sodium", 0)
  2362. calcium, _ := c.GetFloat("calcium", 0)
  2363. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  2364. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  2365. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  2366. glucose, _ := c.GetFloat("glucose", 0)
  2367. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  2368. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2369. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2370. conductivity, _ := c.GetFloat("conductivity", 0)
  2371. remark := c.GetString("remark")
  2372. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  2373. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  2374. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  2375. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  2376. body_fluid, _ := c.GetInt64("body_fluid", 0)
  2377. special_medicine, _ := c.GetInt64("special_medicine", 0)
  2378. special_medicine_other := c.GetString("special_medicine_other")
  2379. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  2380. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  2381. blood_access, _ := c.GetInt64("blood_access", 0)
  2382. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  2383. body_fluid_other := c.GetString("body_fluid_other")
  2384. replacement_total, _ := c.GetFloat("replacement_total", 0)
  2385. niprocart, _ := c.GetInt64("niprocart", 0)
  2386. jms, _ := c.GetInt64("jms", 0)
  2387. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  2388. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  2389. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  2390. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  2391. filtryzer, _ := c.GetInt64("filtryzer", 0)
  2392. target_ktv, _ := c.GetFloat("target_ktv", 0)
  2393. dialyzers, _ := c.GetInt64("dialyzers", 0)
  2394. injector, _ := c.GetInt64("injector", 0)
  2395. bloodlines, _ := c.GetInt64("bloodlines", 0)
  2396. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  2397. safe_package, _ := c.GetInt64("package", 0)
  2398. a_liquid, _ := c.GetInt64("a_liquid", 0)
  2399. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  2400. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  2401. blood := c.GetString("blood")
  2402. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  2403. dialysis_irrigation := c.GetString("dialysis_irrigation")
  2404. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  2405. displace_speed := c.GetString("displace_speed")
  2406. illness, _ := c.GetInt64("illness")
  2407. amylaceum := c.GetString("amylaceum")
  2408. single_time := c.GetString("single_time")
  2409. single_water := c.GetString("single_water")
  2410. replacement_flow := c.GetString("replacement_flow")
  2411. plasma_separator := c.GetString("plasma_separator")
  2412. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  2413. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  2414. oxygen_flow := c.GetString("oxygen_flow")
  2415. oxygen_time := c.GetString("oxygen_time")
  2416. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  2417. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  2418. puncture_needle := c.GetString("puncture_needle")
  2419. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  2420. epo := c.GetString("epo")
  2421. epo_count, _ := c.GetFloat("epo_count", 0)
  2422. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  2423. pre_impulse := c.GetString("pre_impulse")
  2424. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  2425. admin_user_id, _ := c.GetInt64("admin_user_id")
  2426. is_water := c.GetString("is_water")
  2427. add_amount, _ := c.GetFloat("add_amount")
  2428. reduce_amount, _ := c.GetFloat("reduce_amount")
  2429. var is_war int64
  2430. if is_water == "是" {
  2431. is_war = 1
  2432. }
  2433. if is_water == "否" {
  2434. is_war = 2
  2435. }
  2436. if is_water == "请选择" {
  2437. is_war = 0
  2438. }
  2439. drhy_water := c.GetString("drhy_water")
  2440. dry_water_hour := c.GetString("dry_water_hour")
  2441. water_machine := c.GetString("water_machine")
  2442. dialysis_remark := c.GetString("dialysis_remark")
  2443. if mode_id > 0 {
  2444. var str string
  2445. //查找该机构用的是什么透析器
  2446. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  2447. if filedConfig.ID > 0 {
  2448. str = dialyzerPerfusionApparatus
  2449. } else {
  2450. str = dialysis_dialyszers + "/" + dialysis_irrigation
  2451. }
  2452. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  2453. }
  2454. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2455. //
  2456. //if template.TemplateId == 2 || template.TemplateId == 6 {
  2457. // if appRole.UserType == 3 {
  2458. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2459. // if getPermissionErr != nil {
  2460. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2461. // return
  2462. // } else if headNursePermission == nil {
  2463. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2464. // return
  2465. // }
  2466. // }
  2467. //}
  2468. prescription := models.DialysisPrescription{
  2469. UserOrgId: adminUserInfo.Org.Id,
  2470. PatientId: id,
  2471. RecordDate: recordDate.Unix(),
  2472. ModeId: mode_id,
  2473. DialysisDuration: dialysis_duration,
  2474. Dialyzer: dialyzer,
  2475. PerfusionApparatus: perfusion_apparatus,
  2476. BloodFlowVolume: blood_flow_volume,
  2477. DewaterAmount: dewater_amount,
  2478. DisplaceLiqui: displace_liqui,
  2479. ReplacementWay: replacement_way,
  2480. Anticoagulant: anticoagulant,
  2481. AnticoagulantShouji: anticoagulant_shouji,
  2482. AnticoagulantWeichi: anticoagulant_weichi,
  2483. AnticoagulantZongliang: anticoagulant_zongliang,
  2484. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2485. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2486. Kalium: kalium,
  2487. Sodium: sodium,
  2488. Calcium: calcium,
  2489. Bicarbonate: bicarbonate,
  2490. Glucose: glucose,
  2491. // DryWeight: dry_weight,
  2492. DialysateFlow: dialysate_flow,
  2493. DialysateTemperature: dialysate_temperature,
  2494. Conductivity: conductivity,
  2495. Remark: remark,
  2496. Status: 1,
  2497. CreatedTime: time.Now().Unix(),
  2498. UpdatedTime: time.Now().Unix(),
  2499. DialysisDurationMinute: dialysisDurationMinute,
  2500. DialysisDurationHour: dialysisDurationHour,
  2501. TargetUltrafiltration: targetUltrafiltration,
  2502. DialysateFormulation: dialysateFormulation,
  2503. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2504. BodyFluid: body_fluid,
  2505. SpecialMedicine: special_medicine,
  2506. SpecialMedicineOther: special_medicine_other,
  2507. DisplaceLiquiPart: displace_liqui_part,
  2508. DisplaceLiquiValue: displace_liqui_value,
  2509. BloodAccess: blood_access,
  2510. Ultrafiltration: ultrafiltration,
  2511. BodyFluidOther: body_fluid_other,
  2512. ReplacementTotal: replacement_total,
  2513. Niprocart: niprocart,
  2514. Jms: jms,
  2515. FistulaNeedleSet: fistula_needle_set,
  2516. FistulaNeedleSet16: fistula_needle_set_16,
  2517. Hemoperfusion: hemoperfusion,
  2518. DialyserSterilised: dialyser_sterilised,
  2519. Filtryzer: filtryzer,
  2520. TargetKtv: target_ktv,
  2521. Dialyzers: dialyzers,
  2522. Injector: injector,
  2523. Bloodlines: bloodlines,
  2524. TubingHemodialysis: tubing_hemodialysis,
  2525. Package: safe_package,
  2526. ALiquid: a_liquid,
  2527. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  2528. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  2529. Blood: blood,
  2530. DialysisDialyszers: dialysis_dialyszers,
  2531. DialysisIrrigation: dialysis_irrigation,
  2532. AntioxidantCommodityName: antioxidant_commodity_name,
  2533. DisplaceSpeed: displace_speed,
  2534. Illness: illness,
  2535. Amylaceum: amylaceum,
  2536. SingleWater: single_water,
  2537. SingleTime: single_time,
  2538. ReplacementFlow: replacement_flow,
  2539. PlasmaSeparator: plasma_separator,
  2540. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  2541. OxygenUptake: oxygen_uptake,
  2542. OxygenTime: oxygen_time,
  2543. OxygenFlow: oxygen_flow,
  2544. HemodialysisPipelines: hemodialysis_pipelines,
  2545. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2546. PunctureNeedle: puncture_needle,
  2547. PunctureNeedleCount: puncture_needle_count,
  2548. Epo: epo,
  2549. EpoCount: epo_count,
  2550. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2551. PreImpulse: impulse,
  2552. AdminUserId: admin_user_id,
  2553. IsWater: is_war,
  2554. DrhyWater: drhy_water,
  2555. DryWaterHour: dry_water_hour,
  2556. WaterMachine: water_machine,
  2557. AddAmount: add_amount,
  2558. ReduceAmount: reduce_amount,
  2559. DialysisRemark: dialysis_remark,
  2560. }
  2561. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2562. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2563. //
  2564. if appRole.UserType == 2 || appRole.UserType == 1 {
  2565. prescription_doctor = adminUserInfo.AdminUser.Id
  2566. prescription.PrescriptionDoctor = prescription_doctor
  2567. }
  2568. if dialysisPrescription.ID == 0 { //新增
  2569. prescription.Creater = adminUserInfo.AdminUser.Id
  2570. } else { //修改
  2571. if dialysisPrescription.Creater == 0 {
  2572. prescription.Creater = adminUserInfo.AdminUser.Id
  2573. } else {
  2574. prescription.Creater = dialysisPrescription.Creater
  2575. }
  2576. //if/**/
  2577. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2578. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  2579. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2580. // if getPermissionErr != nil {
  2581. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2582. // return
  2583. // } else if headNursePermission == nil {
  2584. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2585. // return
  2586. // }
  2587. //}
  2588. //prescription.Creater = dialysisPrescription.Creater
  2589. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2590. prescription.Modifier = adminUserInfo.AdminUser.Id
  2591. prescription.ID = dialysisPrescription.ID
  2592. }
  2593. solution := models.DialysisSolution{
  2594. RegistrarsId: adminUserInfo.AdminUser.Id,
  2595. UserOrgId: adminUserInfo.Org.Id,
  2596. Doctor: prescription_doctor,
  2597. PatientId: id,
  2598. ModeId: mode_id,
  2599. DialysisDuration: dialysis_duration,
  2600. PerfusionApparatus: perfusion_apparatus,
  2601. BloodFlowVolume: blood_flow_volume,
  2602. Dewater: dewater_amount,
  2603. DisplaceLiqui: displace_liqui,
  2604. ReplacementWay: replacement_way,
  2605. Anticoagulant: anticoagulant,
  2606. AnticoagulantShouji: anticoagulant_shouji,
  2607. AnticoagulantWeichi: anticoagulant_weichi,
  2608. AnticoagulantZongliang: anticoagulant_zongliang,
  2609. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2610. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2611. Kalium: kalium,
  2612. Sodium: sodium,
  2613. Calcium: calcium,
  2614. Bicarbonate: bicarbonate,
  2615. Glucose: glucose,
  2616. // DryWeight: dry_weight,
  2617. DialysateFlow: dialysate_flow,
  2618. DialysateTemperature: dialysate_temperature,
  2619. Conductivity: conductivity,
  2620. Remark: remark,
  2621. Status: 1,
  2622. CreatedTime: time.Now().Unix(),
  2623. UpdatedTime: time.Now().Unix(),
  2624. DialysisDurationMinute: dialysisDurationMinute,
  2625. DialysisDurationHour: dialysisDurationHour,
  2626. TargetUltrafiltration: targetUltrafiltration,
  2627. DialysateFormulation: dialysateFormulation,
  2628. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2629. BodyFluid: body_fluid,
  2630. SpecialMedicine: special_medicine,
  2631. SpecialMedicineOther: special_medicine_other,
  2632. DisplaceLiquiPart: displace_liqui_part,
  2633. DisplaceLiquiValue: displace_liqui_value,
  2634. BloodAccess: blood_access,
  2635. Ultrafiltration: ultrafiltration,
  2636. BodyFluidOther: body_fluid_other,
  2637. ReplacementTotal: replacement_total,
  2638. TargetKtv: target_ktv,
  2639. DialysisDialyszers: dialysis_dialyszers,
  2640. DialysisIrrigation: dialysis_irrigation,
  2641. HemodialysisPipelines: hemodialysis_pipelines,
  2642. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2643. PunctureNeedle: puncture_needle,
  2644. PunctureNeedleCount: puncture_needle_count,
  2645. Epo: epo,
  2646. EpoCount: epo_count,
  2647. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2648. PreImpulse: impulse,
  2649. SolutionStatus: 1,
  2650. DialysisRemark: dialysis_remark,
  2651. }
  2652. //针对河间咸的
  2653. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  2654. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  2655. solution.DisplaceLiquiPart = 0
  2656. solution.DisplaceLiquiValue = 0
  2657. }
  2658. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2659. prescription.DisplaceLiquiPart = 0
  2660. prescription.DisplaceLiquiValue = 0
  2661. }
  2662. }
  2663. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  2664. //获取最新1条
  2665. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  2666. //更新状态
  2667. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  2668. //获取key,清空redis
  2669. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2670. redis := service.RedisClient()
  2671. defer redis.Close()
  2672. //清空key 值
  2673. redis.Set(key, "", time.Second)
  2674. //清空长期医嘱的key
  2675. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2676. redis.Set(soulution_key, "", time.Second)
  2677. //查询最近透析准备表里是否存在 透析器 灌流器
  2678. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2679. redis.Set(keyOne, "", time.Second)
  2680. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2681. redis.Set(keyTwo, "", time.Second)
  2682. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2683. redis.Set(keyThree, "", time.Second)
  2684. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2685. redis.Set(keyFour, "", time.Second)
  2686. //splitStr := strings.Split(dialysis_dialyszers, ",")
  2687. //
  2688. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  2689. //
  2690. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  2691. //if len(mation)>0{
  2692. // for _, item := range splitStr {
  2693. // for _,it := range mation{
  2694. // if(item == it.SpecificationName){
  2695. //
  2696. // //查询最近一次的透析器
  2697. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2698. //
  2699. // if errcode == gorm.ErrRecordNotFound{
  2700. // //插入数据
  2701. // prepare := models.DialysisBeforePrepare{
  2702. // UserOrgId: adminUserInfo.Org.Id,
  2703. // PatientId: id,
  2704. // RecordDate: recordDate.Unix(),
  2705. // GoodTypeId: it.GoodTypeId,
  2706. // GoodId: it.ID,
  2707. // Count: 1,
  2708. // Ctime: time.Now().Unix(),
  2709. // Creater: adminUserInfo.AdminUser.Id,
  2710. // Status:1,
  2711. //
  2712. // }
  2713. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2714. // fmt.Println("",errcode)
  2715. // }
  2716. // }
  2717. // }
  2718. //
  2719. // }
  2720. //
  2721. // for _, item := range splitIrrigation {
  2722. // for _,it := range mation{
  2723. // if(item == it.SpecificationName){
  2724. // //查询最近一次的透析器
  2725. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2726. // if errcode == gorm.ErrRecordNotFound{
  2727. // //插入数据
  2728. // prepare := models.DialysisBeforePrepare{
  2729. // UserOrgId: adminUserInfo.Org.Id,
  2730. // PatientId: id,
  2731. // RecordDate: recordDate.Unix(),
  2732. // GoodTypeId: it.GoodTypeId,
  2733. // GoodId: it.ID,
  2734. // Count: 1,
  2735. // Ctime: time.Now().Unix(),
  2736. // Creater: adminUserInfo.AdminUser.Id,
  2737. // Status:1,
  2738. //
  2739. // }
  2740. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2741. // fmt.Println(errcode)
  2742. // }
  2743. // }
  2744. // }
  2745. // }
  2746. //}
  2747. c.ServeSuccessJSON(map[string]interface{}{
  2748. "solution": &solution,
  2749. "prescription": &prescription,
  2750. })
  2751. }
  2752. func (c *DialysisAPIController) GetAcceptsAssessment() {
  2753. patient, _ := c.GetInt64("patient", 0)
  2754. adminUserInfo := c.GetMobileAdminUserInfo()
  2755. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  2756. c.ServeSuccessJSON(map[string]interface{}{
  2757. "receiveTreatmentAsses": receiveTreatmentAsses,
  2758. })
  2759. }
  2760. func (this *DialysisAPIController) PostSignInfo() {
  2761. patientID, _ := this.GetInt64("patient_id")
  2762. recordDateStr := this.GetString("date")
  2763. if patientID <= 0 {
  2764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2765. return
  2766. }
  2767. if len(recordDateStr) == 0 {
  2768. recordDateStr = time.Now().Format("2006-01-02")
  2769. }
  2770. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2771. if parseDateErr != nil {
  2772. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2774. return
  2775. }
  2776. adminInfo := this.GetMobileAdminUserInfo()
  2777. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  2778. if err != nil {
  2779. this.ErrorLog("签名失败:%v", err)
  2780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2781. return
  2782. }
  2783. this.ServeSuccessJSON(map[string]interface{}{
  2784. "doctor_id": adminInfo.AdminUser.Id,
  2785. })
  2786. }
  2787. func (this *DialysisAPIController) GetLastMonitorRecord() {
  2788. patientID, _ := this.GetInt64("patient_id")
  2789. adminInfo := this.GetMobileAdminUserInfo()
  2790. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  2791. this.ServeSuccessJSON(map[string]interface{}{
  2792. "monitor": record,
  2793. })
  2794. }
  2795. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  2796. thisTime := time.Now()
  2797. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  2798. timeLayout := "2006-01-02 15:04:05"
  2799. loc, _ := time.LoadLocation("Local")
  2800. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2801. theAssessmentDateTime := theStartTime.Unix()
  2802. patientID, _ := this.GetInt64("patient_id")
  2803. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  2804. adminInfo := this.GetMobileAdminUserInfo()
  2805. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2806. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2807. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  2808. var ultrafiltration_rate float64
  2809. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2810. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2811. fmt.Println(evaluation)
  2812. if prescription.ID > 0 {
  2813. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2814. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2815. if template.TemplateId == 6 && adminInfo.Org.Id != 9538 {
  2816. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2817. record.UltrafiltrationRate = ultrafiltration_rate
  2818. }
  2819. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  2820. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  2821. record.UltrafiltrationRate = ultrafiltration_rate
  2822. }
  2823. if template.TemplateId == 20 || template.TemplateId == 22 {
  2824. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2825. record.UltrafiltrationRate = ultrafiltration_rate
  2826. }
  2827. // 只针对方济医院
  2828. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  2829. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2830. ultrafiltration_rate = value
  2831. record.UltrafiltrationRate = ultrafiltration_rate
  2832. }
  2833. if template.TemplateId == 41 || template.TemplateId == 47 {
  2834. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2835. record.UltrafiltrationRate = ultrafiltration_rate
  2836. }
  2837. if template.TemplateId == 43 {
  2838. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2839. record.UltrafiltrationRate = ultrafiltration_rate
  2840. }
  2841. if template.TemplateId == 46 || template.TemplateId == 54 {
  2842. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2843. record.UltrafiltrationRate = ultrafiltration_rate
  2844. }
  2845. 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 {
  2846. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  2847. record.UltrafiltrationRate = ultrafiltration_rate
  2848. }
  2849. //if template.TemplateId == 47 {
  2850. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2851. // record.UltrafiltrationRate = ultrafiltration_rate
  2852. //}
  2853. }
  2854. }
  2855. // record.UltrafiltrationRate = ultrafiltration_rate
  2856. record.UltrafiltrationVolume = 0
  2857. 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
  2858. if ultrafiltration_rate > 0 {
  2859. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  2860. record.UltrafiltrationVolume = value
  2861. }
  2862. }
  2863. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 { //adminInfo.Org.Id == 9538
  2864. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  2865. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2866. record.UltrafiltrationVolume = ultrafiltration_volume
  2867. }
  2868. }
  2869. //长沙南雅
  2870. 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 {
  2871. if ultrafiltration_rate > 0 {
  2872. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2873. record.UltrafiltrationVolume = ultrafiltration_volume
  2874. }
  2875. }
  2876. if template.TemplateId == 47 || template.TemplateId == 54 {
  2877. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  2878. }
  2879. this.ServeSuccessJSON(map[string]interface{}{
  2880. "monitor": record,
  2881. })
  2882. }
  2883. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  2884. record_id, _ := this.GetInt64("id")
  2885. nurseID, _ := this.GetInt64("nurse")
  2886. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2887. bedID, _ := this.GetInt64("bed")
  2888. start_time := this.GetString("start_time")
  2889. schedual_type, _ := this.GetInt64("schedual_type")
  2890. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2891. change_nurse, _ := this.GetInt64("change_nurse")
  2892. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2893. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2894. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2895. patient_id, _ := this.GetInt64("patient_id")
  2896. record_date, _ := this.GetInt64("record_date")
  2897. puncture_needle := this.GetString("puncture_needle")
  2898. puncture_way := this.GetString("puncture_way")
  2899. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2900. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2901. blood_access_id, _ := this.GetInt64("blood_access_id")
  2902. nuclein_date_str := this.GetString("nuclein_date_str")
  2903. order_remark := this.GetString("order_remark")
  2904. schedule_remark := this.GetString("schedule_remark")
  2905. catheter_operation := this.GetString("catheter_operation")
  2906. if record_id == 0 {
  2907. this.ErrorLog("id:%v", record_id)
  2908. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2909. return
  2910. }
  2911. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2912. if parseStartDateErr != nil {
  2913. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2915. return
  2916. }
  2917. adminUserInfo := this.GetMobileAdminUserInfo()
  2918. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2919. if getNurseErr != nil {
  2920. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2921. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2922. return
  2923. } else if nurse == nil {
  2924. this.ErrorLog("护士不存在")
  2925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2926. return
  2927. }
  2928. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2929. //if getNurseErr != nil {
  2930. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  2931. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2932. // return
  2933. //} else if nurse == nil {
  2934. // this.ErrorLog("护士不存在")
  2935. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2936. // return
  2937. //}
  2938. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2939. if getDeviceNumberErr != nil {
  2940. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2941. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2942. return
  2943. } else if deviceNumber == nil {
  2944. this.ErrorLog("床位号不存在")
  2945. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2946. return
  2947. }
  2948. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  2949. //
  2950. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  2951. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2952. // if getPermissionErr != nil {
  2953. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2954. // return
  2955. // } else if headNursePermission == nil {
  2956. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2957. // return
  2958. // }
  2959. //}
  2960. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2961. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2962. timeLayout := "2006-01-02 15:04:05"
  2963. loc, _ := time.LoadLocation("Local")
  2964. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2965. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2966. schedulestartTime := theStartTime.Unix()
  2967. scheduleendTime := theEndTime.Unix()
  2968. var theNucleinDate int64
  2969. timeLayoutOne := "2006-01-02"
  2970. if len(nuclein_date_str) > 0 {
  2971. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2972. if err != nil {
  2973. utils.ErrorLog(err.Error())
  2974. }
  2975. theNucleinDate = theTime.Unix()
  2976. }
  2977. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2978. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2979. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2980. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  2981. if err == gorm.ErrRecordNotFound { //空床位
  2982. // 修改了床位逻辑
  2983. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2984. if daySchedule.ID > 0 {
  2985. //daySchedule.BedId = bedID
  2986. //daySchedule.PartitionId = deviceNumber.ZoneID
  2987. //daySchedule.ScheduleType = schedual_type
  2988. //daySchedule.UpdatedTime = time.Now().Unix()
  2989. //err := service.UpdateSchedule(&daySchedule)
  2990. xtSchedule := models.Schedule{
  2991. PartitionId: deviceNumber.ZoneID,
  2992. BedId: bedID,
  2993. ScheduleType: schedual_type,
  2994. UpdatedTime: time.Now().Unix(),
  2995. }
  2996. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2997. if err != nil {
  2998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2999. return
  3000. }
  3001. }
  3002. } else if err == nil {
  3003. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3004. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3005. if daySchedule.ID > 0 {
  3006. //daySchedule.BedId = bedID
  3007. //daySchedule.PartitionId = deviceNumber.ZoneID
  3008. //
  3009. //daySchedule.ScheduleType = schedual_type
  3010. //daySchedule.UpdatedTime = time.Now().Unix()
  3011. //err := service.UpdateSchedule(&daySchedule)
  3012. xtSchedule := models.Schedule{
  3013. PartitionId: deviceNumber.ZoneID,
  3014. BedId: bedID,
  3015. ScheduleType: schedual_type,
  3016. UpdatedTime: time.Now().Unix(),
  3017. }
  3018. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3019. if err != nil {
  3020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3021. return
  3022. }
  3023. }
  3024. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3025. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3026. return
  3027. }
  3028. } else if err != nil {
  3029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3030. return
  3031. }
  3032. }
  3033. dialysisRecord := &models.DialysisOrder{
  3034. ID: record_id,
  3035. UserOrgId: adminUserInfo.Org.Id,
  3036. BedID: bedID,
  3037. StartNurse: nurseID,
  3038. StartTime: startDate.Unix(),
  3039. PunctureNurse: puncture_nurse,
  3040. Creator: adminUserInfo.AdminUser.Id,
  3041. Modifier: adminUserInfo.AdminUser.Id,
  3042. WashpipeNurse: washpipe_nurse,
  3043. SchedualType: schedual_type,
  3044. ChangeNurse: change_nurse,
  3045. DifficultPunctureNurse: difficult_puncture_nurse,
  3046. NewFistulaNurse: new_fistula_nurse,
  3047. QualityNurseId: quality_nurse_id,
  3048. PunctureNeedle: puncture_needle,
  3049. PunctureWay: puncture_way,
  3050. DialysisDialyszers: dialysis_dialyszers,
  3051. DialysisIrrigation: dialysis_irrigation,
  3052. BloodAccessId: blood_access_id,
  3053. NucleinDate: theNucleinDate,
  3054. OrderRemark: order_remark,
  3055. ScheduleRemark: schedule_remark,
  3056. CatheterOperation: catheter_operation,
  3057. }
  3058. //修改床位号需要重新消毒
  3059. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 {
  3060. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  3061. }
  3062. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  3063. order, _ := service.GetLastPatientOrder(record_id)
  3064. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  3065. redis := service.RedisClient()
  3066. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  3067. redis.Set(key, "", time.Second)
  3068. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  3069. //清空key 值
  3070. redis.Set(keyOne, "", time.Second)
  3071. scheduleDateStartOne := startDate.Format("2006-01-02")
  3072. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3073. redis.Set(keyTwo, "", time.Second)
  3074. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  3075. redis.Set(keyThree, "", time.Second)
  3076. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  3077. redis.Set(keyFour, "", time.Second)
  3078. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  3079. redis.Set(keyFive, "", time.Second)
  3080. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  3081. redis.Set(keySix, "", time.Second)
  3082. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  3083. redis.Set(keySeven, "", time.Second)
  3084. if updateErr != nil {
  3085. this.ErrorLog("修改上机失败:%v", updateErr)
  3086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3087. return
  3088. }
  3089. if updateErr == nil {
  3090. if tempDialysisRecord.Stage == 2 {
  3091. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  3092. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  3093. fmt.Println(value)
  3094. a, b := math.Modf(value)
  3095. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  3096. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  3097. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  3098. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  3099. redis := service.RedisClient()
  3100. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  3101. redis.Set(key, "", time.Second)
  3102. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  3103. redis.Set(keyOne, "", time.Second)
  3104. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  3105. //清空key 值
  3106. redis.Set(keySix, "", time.Second)
  3107. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  3108. redis.Set(keySeven, "", time.Second)
  3109. redis.Close()
  3110. if updateAssessmentErr != nil {
  3111. utils.ErrorLog("%v", updateAssessmentErr)
  3112. }
  3113. }
  3114. }
  3115. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  3116. this.ServeSuccessJSON(map[string]interface{}{
  3117. "dialysis_order": dialysisRecords,
  3118. })
  3119. }
  3120. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  3121. record_id, _ := c.GetInt64("id")
  3122. nurseID, _ := c.GetInt64("nurse")
  3123. end_time := c.GetString("end_time")
  3124. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  3125. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  3126. catheter := c.GetString("catheter")
  3127. cruor := c.GetString("cruor")
  3128. mission := c.GetString("mission")
  3129. if record_id <= 0 || nurseID <= 0 {
  3130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3131. return
  3132. }
  3133. adminUserInfo := c.GetMobileAdminUserInfo()
  3134. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3135. if getNurseErr != nil {
  3136. c.ErrorLog("获取护士失败:%v", getNurseErr)
  3137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3138. return
  3139. } else if nurse == nil {
  3140. c.ErrorLog("护士不存在")
  3141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3142. return
  3143. }
  3144. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  3145. if parseEndDateErr != nil {
  3146. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  3147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3148. return
  3149. }
  3150. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  3151. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  3152. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3153. // if getPermissionErr != nil {
  3154. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3155. // return
  3156. // } else if headNursePermission == nil {
  3157. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3158. // return
  3159. // }
  3160. //}
  3161. dialysisRecord := &models.DialysisOrder{
  3162. ID: record_id,
  3163. UserOrgId: adminUserInfo.Org.Id,
  3164. EndTime: endDate.Unix(),
  3165. FinishNurse: nurseID,
  3166. FinishModifier: adminUserInfo.AdminUser.Id,
  3167. PuncturePointHaematoma: puncture_point_haematoma,
  3168. BloodAccessInternalFistula: blood_access_internal_fistula,
  3169. Catheter: catheter,
  3170. Cruor: cruor,
  3171. Mission: mission,
  3172. }
  3173. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  3174. redis := service.RedisClient()
  3175. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  3176. //清空key 值
  3177. redis.Set(key, "", time.Second)
  3178. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  3179. //清空key 值
  3180. redis.Set(keyOne, "", time.Second)
  3181. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  3182. redis.Set(keySeven, "", time.Second)
  3183. redis.Close()
  3184. if updateErr != nil {
  3185. c.ErrorLog("修改下机失败:%v", updateErr)
  3186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3187. return
  3188. }
  3189. if updateErr == nil {
  3190. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  3191. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  3192. a, b := math.Modf(value)
  3193. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  3194. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  3195. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  3196. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  3197. redis := service.RedisClient()
  3198. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  3199. redis.Set(keyTen, "", time.Second)
  3200. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  3201. redis.Set(keyTwo, "", time.Second)
  3202. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  3203. redis.Set(key, "", time.Second)
  3204. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  3205. redis.Set(keyThree, "", time.Second)
  3206. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  3207. redis.Set(keySeven, "", time.Second)
  3208. defer redis.Close()
  3209. if updateAssessmentErr != nil {
  3210. utils.ErrorLog("%v", updateAssessmentErr)
  3211. }
  3212. }
  3213. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  3214. c.ServeSuccessJSON(map[string]interface{}{
  3215. "dialysis_order": dialysisRecords,
  3216. })
  3217. }
  3218. func (c *DialysisAPIController) GetLongAdvice() {
  3219. patient_id, _ := c.GetInt64("id")
  3220. adminUserInfo := c.GetMobileAdminUserInfo()
  3221. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  3222. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  3223. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  3224. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  3225. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3226. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3227. c.ServeSuccessJSON(map[string]interface{}{
  3228. "status": "1",
  3229. })
  3230. return
  3231. } else { //开启推送提醒
  3232. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3233. var advice_three []*models.DoctorAdvice
  3234. recordDateStr := time.Now().Format("2006-01-02")
  3235. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3236. nowtime := recordDate.Unix()
  3237. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  3238. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  3239. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  3240. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  3241. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  3242. for _, advice := range advices {
  3243. if advice.FrequencyType == 3 {
  3244. t := time.Now()
  3245. week := int(t.Weekday())
  3246. fmt.Println(t.Weekday())
  3247. fmt.Println(week)
  3248. switch week {
  3249. case 1:
  3250. if strings.Index(advice.WeekDay, "周一") == -1 {
  3251. advice_three = append(advice_three, advice)
  3252. }
  3253. break
  3254. case 2:
  3255. if strings.Index(advice.WeekDay, "周二") == -1 {
  3256. advice_three = append(advice_three, advice)
  3257. }
  3258. break
  3259. case 3:
  3260. if strings.Index(advice.WeekDay, "周三") == -1 {
  3261. advice_three = append(advice_three, advice)
  3262. }
  3263. break
  3264. case 4:
  3265. if strings.Index(advice.WeekDay, "周四") == -1 {
  3266. advice_three = append(advice_three, advice)
  3267. }
  3268. break
  3269. case 5:
  3270. if strings.Index(advice.WeekDay, "周五") == -1 {
  3271. advice_three = append(advice_three, advice)
  3272. }
  3273. break
  3274. case 6:
  3275. if strings.Index(advice.WeekDay, "周六") == -1 {
  3276. advice_three = append(advice_three, advice)
  3277. }
  3278. break
  3279. case 0:
  3280. if strings.Index(advice.WeekDay, "周日") == -1 {
  3281. advice_three = append(advice_three, advice)
  3282. }
  3283. break
  3284. }
  3285. }
  3286. }
  3287. for _, advice := range advices_two {
  3288. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3289. now := p.Unix()
  3290. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3291. dayStr2 := "-" + dayStr
  3292. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3293. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3294. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  3295. for _, ad := range advices {
  3296. advice_three = append(advice_three, ad)
  3297. }
  3298. }
  3299. if err == nil {
  3300. c.ServeSuccessJSON(map[string]interface{}{
  3301. "status": "2",
  3302. "advices": advices,
  3303. "advices_two": RemoveRepeatedElement(advice_three),
  3304. "is_open_remind": config.IsOpenRemind,
  3305. "his_config_open": hisConfig.IsOpen,
  3306. "is_advice_open": is_advice_open.IsAdviceOpen,
  3307. "prescription_open": prescription_open.IsOpen,
  3308. })
  3309. }
  3310. }
  3311. }
  3312. func (c *DialysisAPIController) GetLongAdviceOne() {
  3313. patient_id, _ := c.GetInt64("id")
  3314. startTime := c.GetString("schedule_date")
  3315. timeLayout := "2006-01-02"
  3316. loc, _ := time.LoadLocation("Local")
  3317. var theStartTime int64
  3318. if len(startTime) > 0 {
  3319. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3320. if err != nil {
  3321. utils.ErrorLog(err.Error())
  3322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3323. return
  3324. }
  3325. theStartTime = theTime.Unix()
  3326. }
  3327. adminUserInfo := c.GetMobileAdminUserInfo()
  3328. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  3329. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  3330. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  3331. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  3332. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3333. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3334. c.ServeSuccessJSON(map[string]interface{}{
  3335. "status": "1",
  3336. })
  3337. return
  3338. } else { //开启推送提醒
  3339. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3340. var advice_three []*models.DoctorAdvice
  3341. //fmt.Println("theStartTime23434343433434433443434343434334", theStartTime)
  3342. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  3343. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  3344. for _, advice := range advices {
  3345. if advice.FrequencyType == 3 {
  3346. t := time.Now()
  3347. week := int(t.Weekday())
  3348. fmt.Println(t.Weekday())
  3349. fmt.Println(week)
  3350. switch week {
  3351. case 1:
  3352. if strings.Index(advice.WeekDay, "周一") == -1 {
  3353. advice_three = append(advice_three, advice)
  3354. }
  3355. break
  3356. case 2:
  3357. if strings.Index(advice.WeekDay, "周二") == -1 {
  3358. advice_three = append(advice_three, advice)
  3359. }
  3360. break
  3361. case 3:
  3362. if strings.Index(advice.WeekDay, "周三") == -1 {
  3363. advice_three = append(advice_three, advice)
  3364. }
  3365. break
  3366. case 4:
  3367. if strings.Index(advice.WeekDay, "周四") == -1 {
  3368. advice_three = append(advice_three, advice)
  3369. }
  3370. break
  3371. case 5:
  3372. if strings.Index(advice.WeekDay, "周五") == -1 {
  3373. advice_three = append(advice_three, advice)
  3374. }
  3375. break
  3376. case 6:
  3377. if strings.Index(advice.WeekDay, "周六") == -1 {
  3378. advice_three = append(advice_three, advice)
  3379. }
  3380. break
  3381. case 0:
  3382. if strings.Index(advice.WeekDay, "周日") == -1 {
  3383. advice_three = append(advice_three, advice)
  3384. }
  3385. break
  3386. }
  3387. }
  3388. }
  3389. for _, advice := range advices_two {
  3390. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3391. now := p.Unix()
  3392. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3393. dayStr2 := "-" + dayStr
  3394. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3395. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3396. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  3397. for _, ad := range advices {
  3398. advice_three = append(advice_three, ad)
  3399. }
  3400. }
  3401. if err == nil {
  3402. c.ServeSuccessJSON(map[string]interface{}{
  3403. "status": "2",
  3404. "advices": advices,
  3405. "advices_two": RemoveRepeatedElement(advice_three),
  3406. "is_open_remind": config.IsOpenRemind,
  3407. "his_config_open": hisConfig.IsOpen,
  3408. "is_advice_open": is_advice_open.IsAdviceOpen,
  3409. "prescription_open": prescription_open.IsOpen,
  3410. })
  3411. }
  3412. }
  3413. }
  3414. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3415. newArr = make([]*models.DoctorAdvice, 0)
  3416. for i := 0; i < len(arr); i++ {
  3417. repeat := false
  3418. for j := i + 1; j < len(arr); j++ {
  3419. if arr[i].ID == arr[j].ID {
  3420. repeat = true
  3421. break
  3422. }
  3423. }
  3424. if !repeat {
  3425. newArr = append(newArr, arr[i])
  3426. }
  3427. }
  3428. return
  3429. }
  3430. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  3431. patient, _ := c.GetInt64("id", 0)
  3432. groupNo, _ := c.GetInt64("groupno", 0)
  3433. if patient <= 0 {
  3434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3435. return
  3436. }
  3437. adminUserInfo := c.GetMobileAdminUserInfo()
  3438. dataBody := make(map[string]interface{}, 0)
  3439. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3440. if err != nil {
  3441. utils.ErrorLog(err.Error())
  3442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3443. return
  3444. }
  3445. utils.ErrorLog("%v", dataBody)
  3446. timeLayout := "2006-01-02 15:04"
  3447. loc, _ := time.LoadLocation("Local")
  3448. timeLayout2 := "2006-01-02"
  3449. loc2, _ := time.LoadLocation("Local")
  3450. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3451. utils.ErrorLog("advice_type")
  3452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3453. return
  3454. }
  3455. adviceType := int64(2)
  3456. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3457. utils.ErrorLog("advice_date")
  3458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3459. return
  3460. }
  3461. adviceDate, _ := dataBody["advice_date"].(string)
  3462. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3463. AdviceDate := theTime.Unix()
  3464. RecordDate := theTime.Unix()
  3465. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3466. utils.ErrorLog("start_time")
  3467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3468. return
  3469. }
  3470. startTime, _ := dataBody["start_time"].(string)
  3471. if len(startTime) == 0 {
  3472. utils.ErrorLog("len(start_time) == 0")
  3473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3474. return
  3475. }
  3476. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  3477. if err != nil {
  3478. utils.ErrorLog(err.Error())
  3479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3480. return
  3481. }
  3482. StartTime := theTime.Unix()
  3483. Remark := ""
  3484. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3485. remark, _ := dataBody["remark"].(string)
  3486. Remark = remark
  3487. }
  3488. var advices []*models.GroupAdvice
  3489. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3490. utils.ErrorLog("advices")
  3491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3492. return
  3493. }
  3494. adviceNames := dataBody["advices"].([]interface{})
  3495. for _, adviceNameMap := range adviceNames {
  3496. adviceNameM := adviceNameMap.(map[string]interface{})
  3497. var advice models.GroupAdvice
  3498. advice.Remark = Remark
  3499. advice.AdviceType = adviceType
  3500. advice.StartTime = StartTime
  3501. advice.AdviceDate = AdviceDate
  3502. advice.RecordDate = RecordDate
  3503. advice.Status = 1
  3504. advice.CreatedTime = time.Now().Unix()
  3505. advice.UpdatedTime = time.Now().Unix()
  3506. advice.StopState = 2
  3507. advice.ExecutionState = 2
  3508. advice.UserOrgId = adminUserInfo.Org.Id
  3509. advice.PatientId = patient
  3510. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3511. advice.IsSettle = 2
  3512. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3513. utils.ErrorLog("advice_name")
  3514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3515. return
  3516. }
  3517. adviceName, _ := adviceNameM["advice_name"].(string)
  3518. if len(adviceName) == 0 {
  3519. utils.ErrorLog("len(advice_name) == 0")
  3520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3521. return
  3522. }
  3523. advice.AdviceName = adviceName
  3524. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3525. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3526. advice.DrugSpec = drugSpec
  3527. }
  3528. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3529. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3530. advice.AdviceDesc = adviceDesc
  3531. }
  3532. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3533. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3534. advice.DrugSpecUnit = drugSpecUnit
  3535. }
  3536. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3537. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3538. // advice.SingleDose = singleDose
  3539. //}
  3540. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3541. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3542. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3543. }
  3544. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3545. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3546. advice.SingleDoseUnit = singleDoseUnit
  3547. }
  3548. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3549. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3550. // advice.PrescribingNumber = prescribingNumber
  3551. //}
  3552. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3553. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3554. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3555. }
  3556. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3557. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3558. advice.PrescribingNumberUnit = prescribingNumberUnit
  3559. }
  3560. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3561. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3562. advice.DeliveryWay = deliveryWay
  3563. }
  3564. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3565. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3566. advice.ExecutionFrequency = executionFrequency
  3567. }
  3568. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3569. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3570. advice.FrequencyType = frequency_type
  3571. }
  3572. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3573. day_count := int64(adviceNameM["day_count"].(float64))
  3574. advice.DayCount = day_count
  3575. }
  3576. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3577. week_day, _ := adviceNameM["week_day"].(string)
  3578. advice.WeekDay = week_day
  3579. }
  3580. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3581. way := int64(adviceNameM["way"].(float64))
  3582. advice.Way = way
  3583. }
  3584. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3585. drug_id := int64(adviceNameM["drug_id"].(float64))
  3586. advice.DrugId = drug_id
  3587. }
  3588. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3589. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3590. advice.DrugNameId = drug_name_id
  3591. }
  3592. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3593. template_id, _ := adviceNameM["template_id"].(string)
  3594. advice.TemplateId = template_id
  3595. }
  3596. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  3597. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3598. advice.ExecutionFrequency = executionFrequency
  3599. }
  3600. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3601. children := adviceNameM["child"].([]interface{})
  3602. if len(children) > 0 {
  3603. for _, childrenMap := range children {
  3604. childMap := childrenMap.(map[string]interface{})
  3605. var child models.GroupAdvice
  3606. child.Remark = Remark
  3607. child.AdviceType = adviceType
  3608. child.StartTime = StartTime
  3609. child.AdviceDate = AdviceDate
  3610. child.RecordDate = RecordDate
  3611. child.Status = 1
  3612. child.CreatedTime = time.Now().Unix()
  3613. child.UpdatedTime = time.Now().Unix()
  3614. child.StopState = 2
  3615. child.ExecutionState = 2
  3616. child.UserOrgId = adminUserInfo.Org.Id
  3617. child.PatientId = patient
  3618. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3619. child.IsSettle = 1
  3620. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3621. utils.ErrorLog("child advice_name")
  3622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3623. return
  3624. }
  3625. childAdviceName, _ := childMap["advice_name"].(string)
  3626. if len(childAdviceName) == 0 {
  3627. utils.ErrorLog("len(child advice_name) == 0")
  3628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3629. return
  3630. }
  3631. child.AdviceName = childAdviceName
  3632. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3633. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3634. child.AdviceDesc = childAdviceDesc
  3635. }
  3636. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3637. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3638. child.DrugSpec = childDrugSpec
  3639. }
  3640. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3641. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3642. child.DrugSpecUnit = childDrugSpecUnit
  3643. }
  3644. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3645. child.SingleDose = childMap["single_dose"].(float64)
  3646. }
  3647. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3648. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3649. child.SingleDoseUnit = childSingleDoseUnit
  3650. }
  3651. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3652. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3653. }
  3654. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3655. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3656. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3657. }
  3658. child.DeliveryWay = advice.DeliveryWay
  3659. child.ExecutionFrequency = advice.ExecutionFrequency
  3660. advice.Children = append(advice.Children, &child)
  3661. }
  3662. }
  3663. }
  3664. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  3665. if temp_advice.ID == 0 {
  3666. advices = append(advices, &advice)
  3667. }
  3668. }
  3669. if len(advices) > 0 {
  3670. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  3671. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  3672. redis := service.RedisClient()
  3673. //清空key 值
  3674. redis.Set(key, "", time.Second)
  3675. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3676. redis.Set(keyOne, "", time.Second)
  3677. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3678. defer redis.Close()
  3679. redis.Set(keyThree, "", time.Second)
  3680. if err != nil {
  3681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3682. return
  3683. }
  3684. c.ServeSuccessJSON(map[string]interface{}{
  3685. "msg": "ok",
  3686. "advices": list,
  3687. })
  3688. } else {
  3689. c.ServeSuccessJSON(map[string]interface{}{
  3690. "msg": "ok",
  3691. })
  3692. }
  3693. return
  3694. }
  3695. func (c *DialysisAPIController) UploadDryWeight() {
  3696. patient_id, _ := c.GetInt64("id")
  3697. dry_weight, _ := c.GetFloat("dry_weight")
  3698. doctor_id, _ := c.GetInt64("doctor_id")
  3699. remark := c.GetString("remark")
  3700. adminUserInfo := c.GetMobileAdminUserInfo()
  3701. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  3702. if err == gorm.ErrRecordNotFound {
  3703. dryWeight := &models.SgjPatientDryweight{
  3704. PatientId: patient_id,
  3705. DryWeight: dry_weight,
  3706. Remakes: remark,
  3707. Ctime: time.Now().Unix(),
  3708. Mtime: time.Now().Unix(),
  3709. Creator: doctor_id,
  3710. Status: 1,
  3711. UserOrgId: adminUserInfo.Org.Id,
  3712. AdjustedValue: "/",
  3713. UserId: adminUserInfo.AdminUser.Id,
  3714. }
  3715. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3716. redis := service.RedisClient()
  3717. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  3718. redis.Set(keyOne, "", time.Second)
  3719. loc, _ := time.LoadLocation("Local")
  3720. nowTime := time.Now()
  3721. nowDay := nowTime.Format("2006-01-02")
  3722. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3723. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3724. redis.Set(key, "", time.Second)
  3725. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3726. redis.Set(keyTwo, "", time.Second)
  3727. redis.Close()
  3728. if createErr == nil {
  3729. c.ServeSuccessJSON(map[string]interface{}{
  3730. "msg": "提交成功",
  3731. "weight": dryWeight,
  3732. })
  3733. }
  3734. } else {
  3735. dryWeight := &models.SgjPatientDryweight{
  3736. PatientId: patient_id,
  3737. DryWeight: dry_weight,
  3738. Remakes: remark,
  3739. Ctime: time.Now().Unix(),
  3740. Mtime: time.Now().Unix(),
  3741. Creator: doctor_id,
  3742. Status: 1,
  3743. UserOrgId: adminUserInfo.Org.Id,
  3744. AdjustedValue: "/",
  3745. UserId: adminUserInfo.AdminUser.Id,
  3746. }
  3747. var value float64
  3748. value = dry_weight - weightAdjust.DryWeight
  3749. if value < 0 {
  3750. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3751. } else if value == 0 {
  3752. dryWeight.AdjustedValue = "/"
  3753. } else if value > 0 {
  3754. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  3755. }
  3756. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3757. redis := service.RedisClient()
  3758. loc, _ := time.LoadLocation("Local")
  3759. nowTime := time.Now()
  3760. nowDay := nowTime.Format("2006-01-02")
  3761. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3762. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3763. redis.Set(keyOne, "", time.Second)
  3764. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3765. redis.Set(key, "", time.Second)
  3766. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3767. redis.Set(keyTwo, "", time.Second)
  3768. redis.Close()
  3769. if createErr == nil {
  3770. c.ServeSuccessJSON(map[string]interface{}{
  3771. "msg": "提交成功",
  3772. "weight": dryWeight,
  3773. })
  3774. }
  3775. }
  3776. }
  3777. func (c *DialysisAPIController) GetSolution() {
  3778. patient_id, _ := c.GetInt64("patient_id")
  3779. mode_id, _ := c.GetInt64("mode_id")
  3780. adminUserInfo := c.GetMobileAdminUserInfo()
  3781. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  3782. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  3783. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  3784. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  3785. if err != nil {
  3786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3787. return
  3788. }
  3789. c.ServeSuccessJSON(map[string]interface{}{
  3790. "solution": solution,
  3791. "prescription": prescription,
  3792. "system_prescription": system_prescription,
  3793. "dialysisPrescription": dialysisPrescription,
  3794. })
  3795. }
  3796. func (c *DialysisAPIController) GetSchedule() {
  3797. schedual_type, _ := c.GetInt64("schedual_type")
  3798. adminUserInfo := c.GetMobileAdminUserInfo()
  3799. scheduleTime, _ := c.GetInt64("record_date")
  3800. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  3801. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  3802. c.ServeSuccessJSON(map[string]interface{}{
  3803. "number": deviceNumber,
  3804. "list": list,
  3805. })
  3806. }
  3807. func (c *DialysisAPIController) GetPatientId() {
  3808. id, _ := c.GetInt64("id")
  3809. //orgid := c.GetMobileAdminUserInfo().Org.Id
  3810. patientId, _ := service.GetPatientId(id)
  3811. //获取该患者的所有传染病
  3812. list, _ := service.GetPatientInfectious(id)
  3813. c.ServeSuccessJSON(map[string]interface{}{
  3814. "patient": patientId,
  3815. "infectioulist": list,
  3816. })
  3817. }
  3818. func (this *DialysisAPIController) GetDialysisSchedule() {
  3819. schedualDate := this.GetString("date")
  3820. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3821. if parseDateErr != nil {
  3822. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3823. return
  3824. }
  3825. adminInfo := this.GetMobileAdminUserInfo()
  3826. orgID := adminInfo.Org.Id
  3827. redis := service.RedisClient()
  3828. defer redis.Close()
  3829. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  3830. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  3831. if len(scheduals) > 0 {
  3832. //缓存数据
  3833. scheduals_json, err := json.Marshal(scheduals)
  3834. if err == nil {
  3835. redis.Set(key, scheduals_json, time.Second*30)
  3836. }
  3837. }
  3838. this.ServeSuccessJSON(map[string]interface{}{
  3839. "scheduals": scheduals,
  3840. })
  3841. }
  3842. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  3843. change_type, _ := this.GetInt64("type", 0)
  3844. record_date := this.GetString("record_time")
  3845. patient_id, _ := this.GetInt64("patient_id", 0)
  3846. timeLayout := "2006-01-02"
  3847. loc, _ := time.LoadLocation("Local")
  3848. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3849. record_time := theAdviceRecordTime.Unix()
  3850. adminUserInfo := this.GetMobileAdminUserInfo()
  3851. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  3852. if err == nil {
  3853. if len(advices) == 0 {
  3854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3855. return
  3856. } else {
  3857. this.ServeSuccessJSON(map[string]interface{}{
  3858. "advices": advices,
  3859. "schedule": sch,
  3860. })
  3861. return
  3862. }
  3863. } else {
  3864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3865. return
  3866. }
  3867. }
  3868. func (c *DialysisAPIController) CreateConsumables() {
  3869. record_date := c.GetString("record_time")
  3870. patient_id, _ := c.GetInt64("patient_id", 0)
  3871. active, _ := c.GetInt64("active")
  3872. adminUser := c.GetMobileAdminUserInfo()
  3873. timeLayout := "2006-01-02"
  3874. loc, _ := time.LoadLocation("Local")
  3875. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3876. record_time := theRecordTime.Unix()
  3877. dataBody := make(map[string]interface{}, 0)
  3878. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3879. if err != nil {
  3880. utils.ErrorLog(err.Error())
  3881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3882. return
  3883. }
  3884. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3885. var beforePrepares []*models.DialysisBeforePrepareGoods
  3886. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  3887. var dialysisBefor []*models.DialysisBeforePrepare
  3888. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3889. goods, _ := dataBody["goods"].([]interface{})
  3890. if len(goods) > 0 {
  3891. for _, item := range goods {
  3892. items := item.(map[string]interface{})
  3893. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3894. utils.ErrorLog("good_id")
  3895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3896. return
  3897. }
  3898. good_id := int64(items["good_id"].(float64))
  3899. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3900. utils.ErrorLog("good_type_id")
  3901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3902. return
  3903. }
  3904. good_type_id := int64(items["good_type_id"].(float64))
  3905. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3906. utils.ErrorLog("count")
  3907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3908. return
  3909. }
  3910. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3911. commdity_code := items["commdity_code"].(string)
  3912. fmt.Println("commdity", commdity_code)
  3913. prepareGoods := &models.DialysisBeforePrepareGoods{
  3914. GoodTypeId: good_type_id,
  3915. GoodId: good_id,
  3916. Count: count,
  3917. StorehouseId: houseConfig.StorehouseOutInfo,
  3918. }
  3919. beforePrepares = append(beforePrepares, prepareGoods)
  3920. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  3921. GoodTypeId: good_type_id,
  3922. GoodId: good_id,
  3923. Count: count,
  3924. StorehouseId: houseConfig.StorehouseOutInfo,
  3925. }
  3926. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  3927. prepare := &models.DialysisBeforePrepare{
  3928. GoodTypeId: good_type_id,
  3929. GoodId: good_id,
  3930. Count: count,
  3931. PatientId: patient_id,
  3932. RecordDate: record_time,
  3933. UserOrgId: adminUser.Org.Id,
  3934. Status: 1,
  3935. Ctime: time.Now().Unix(),
  3936. Creater: adminUser.AdminUser.Id,
  3937. CommdityCode: commdity_code,
  3938. StorehouseId: houseConfig.StorehouseOutInfo,
  3939. }
  3940. dialysisBefor = append(dialysisBefor, prepare)
  3941. }
  3942. }
  3943. //查询是否有库存
  3944. for _, item := range dialysisBefor {
  3945. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  3946. if err == gorm.ErrRecordNotFound {
  3947. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3948. c.ServeSuccessJSON(map[string]interface{}{
  3949. "message": "1",
  3950. "good_name": goodObj.GoodName,
  3951. "specification_name": goodObj.SpecificationName,
  3952. })
  3953. return
  3954. }
  3955. if err != nil {
  3956. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3957. c.ServeSuccessJSON(map[string]interface{}{
  3958. "message": "1",
  3959. "good_name": goodObj.GoodName,
  3960. "specification_name": goodObj.SpecificationName,
  3961. })
  3962. return
  3963. }
  3964. }
  3965. fmt.Println("active------------------------------------", active)
  3966. fmt.Println("len------------------------------", len(goods))
  3967. //新增
  3968. if active == 1 && len(goods) > 0 {
  3969. for _, item := range dialysisBefor {
  3970. dialyPrepareOne := models.DialysisBeforePrepare{
  3971. GoodTypeId: item.GoodTypeId,
  3972. GoodId: item.GoodId,
  3973. PatientId: item.PatientId,
  3974. RecordDate: item.RecordDate,
  3975. UserOrgId: item.UserOrgId,
  3976. Count: item.Count,
  3977. Ctime: time.Now().Unix(),
  3978. Creater: item.Creater,
  3979. CommdityCode: item.CommdityCode,
  3980. Status: 1,
  3981. StorehouseId: houseConfig.StorehouseOutInfo,
  3982. }
  3983. //先清除再插入
  3984. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3985. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  3986. //查询默认仓库
  3987. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3988. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3989. var total_count int64
  3990. for _, it := range stockList {
  3991. total_count += it.StockCount
  3992. }
  3993. //基础库插入数据
  3994. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3995. //更新库存
  3996. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  3997. var flush_count int64
  3998. for _, it := range goodList {
  3999. flush_count += it.StockCount
  4000. }
  4001. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4002. }
  4003. if err == nil {
  4004. c.ServeSuccessJSON(map[string]interface{}{
  4005. "msg": "保存成功",
  4006. "message": "2",
  4007. })
  4008. return
  4009. } else {
  4010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4011. return
  4012. }
  4013. }
  4014. if len(beforePrepares) > 0 && active == 2 {
  4015. for _, item := range beforePrepares {
  4016. //1.查看该患者该耗材型号最后一次出库数量
  4017. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4018. //判断当前出库数量和最后一次出库数量的大小
  4019. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  4020. if item.Count <= goodInfo.Count {
  4021. //退库
  4022. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  4023. //查询今日出库数据
  4024. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  4025. for _, it := range list {
  4026. prepare := models.DialysisBeforePrepare{
  4027. UserOrgId: it.OrgId,
  4028. PatientId: patient_id,
  4029. RecordDate: it.RecordTime,
  4030. GoodId: it.GoodId,
  4031. GoodTypeId: it.GoodTypeId,
  4032. Count: it.Count,
  4033. Ctime: time.Now().Unix(),
  4034. Creater: adminUser.AdminUser.Id,
  4035. Status: 1,
  4036. StorehouseId: houseConfig.StorehouseOutInfo,
  4037. }
  4038. //删除准备表数据
  4039. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4040. service.CreateDialysisBeforePrepareOne(&prepare)
  4041. }
  4042. }
  4043. var last_total int64
  4044. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  4045. if item.Count >= goodInfo.Count {
  4046. //查询当前批次当前耗材最后一条出库数据
  4047. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4048. //计算当前出库和最后一次出库数据相差数据
  4049. last_total = item.Count - lastOutInfo.Count
  4050. //查询该批次剩余库存
  4051. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  4052. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  4053. if lastInfo.StockCount >= last_total {
  4054. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  4055. //查询今日出库数据
  4056. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  4057. for _, it := range list {
  4058. prepare := models.DialysisBeforePrepare{
  4059. UserOrgId: it.OrgId,
  4060. PatientId: patient_id,
  4061. RecordDate: it.RecordTime,
  4062. GoodId: it.GoodId,
  4063. GoodTypeId: it.GoodTypeId,
  4064. Count: it.Count,
  4065. Ctime: time.Now().Unix(),
  4066. Creater: adminUser.AdminUser.Id,
  4067. Status: 1,
  4068. StorehouseId: houseConfig.StorehouseOutInfo,
  4069. }
  4070. //删除准备表数据
  4071. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4072. service.CreateDialysisBeforePrepareOne(&prepare)
  4073. //查询默认仓库
  4074. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4075. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  4076. var total_count int64
  4077. for _, it := range stockList {
  4078. total_count += it.StockCount
  4079. }
  4080. //基础库插入数据
  4081. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  4082. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4083. var flush_count int64
  4084. for _, it := range goodList {
  4085. flush_count += it.StockCount
  4086. }
  4087. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4088. }
  4089. }
  4090. //如果库存不够,则出库到下一个批次
  4091. if lastInfo.StockCount < last_total {
  4092. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  4093. //查询今日出库数据
  4094. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  4095. for _, it := range list {
  4096. prepare := models.DialysisBeforePrepare{
  4097. UserOrgId: it.OrgId,
  4098. PatientId: patient_id,
  4099. RecordDate: it.RecordTime,
  4100. GoodId: it.GoodId,
  4101. GoodTypeId: it.GoodTypeId,
  4102. Count: it.Count,
  4103. Ctime: time.Now().Unix(),
  4104. Creater: adminUser.AdminUser.Id,
  4105. Status: 1,
  4106. StorehouseId: houseConfig.StorehouseOutInfo,
  4107. }
  4108. //删除准备表数据
  4109. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4110. service.CreateDialysisBeforePrepareOne(&prepare)
  4111. //查询默认仓库
  4112. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4113. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  4114. var total_count int64
  4115. for _, it := range stockList {
  4116. total_count += it.StockCount
  4117. }
  4118. //基础库插入数据
  4119. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  4120. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4121. var flush_count int64
  4122. for _, it := range goodList {
  4123. flush_count += it.StockCount
  4124. }
  4125. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4126. }
  4127. if err != nil {
  4128. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4129. c.ServeSuccessJSON(map[string]interface{}{
  4130. "message": "1",
  4131. "good_name": goodObj.GoodName,
  4132. "specification_name": goodObj.SpecificationName,
  4133. })
  4134. return
  4135. }
  4136. }
  4137. }
  4138. if err != nil {
  4139. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4140. c.ServeSuccessJSON(map[string]interface{}{
  4141. "message": "1",
  4142. "good_name": goodObj.GoodName,
  4143. "specification_name": goodObj.SpecificationName,
  4144. })
  4145. return
  4146. }
  4147. }
  4148. }
  4149. }
  4150. var errs error
  4151. if errs == nil {
  4152. c.ServeSuccessJSON(map[string]interface{}{
  4153. "msg": "提交成功",
  4154. "message": "2",
  4155. "good_name": "",
  4156. "specification_name": "",
  4157. })
  4158. return
  4159. } else {
  4160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4161. return
  4162. }
  4163. }
  4164. func (c *DialysisAPIController) CreateStockOutInfo() {
  4165. patient_id, _ := c.GetInt64("patient_id", 0)
  4166. record_date := c.GetString("record_time")
  4167. if patient_id <= 0 {
  4168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4169. return
  4170. }
  4171. adminInfo := c.GetMobileAdminUserInfo()
  4172. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  4173. timeLayout := "2006-01-02"
  4174. loc, _ := time.LoadLocation("Local")
  4175. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4176. record_time := theRecordTime.Unix()
  4177. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  4178. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4179. //去重
  4180. consumables = RemoveRepeatedGood(consumables)
  4181. if record.IsOpen == 1 {
  4182. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4183. //查询是否有库存
  4184. for _, item := range consumables {
  4185. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  4186. if item.Count > warehouse.Count {
  4187. goodErrcode := models.XtGoodErrcode{
  4188. UserOrgId: item.UserOrgId,
  4189. Errcode: "自动出库库存不足",
  4190. GoodId: item.GoodId,
  4191. Status: 1,
  4192. Ctime: time.Now().Unix(),
  4193. Mtime: 0,
  4194. Count: 0,
  4195. StockCount: 0,
  4196. Creater: creator,
  4197. BatchNumberId: warehouse.ID,
  4198. WarehouseOutId: 0,
  4199. }
  4200. service.CreateGoodErrcode(goodErrcode)
  4201. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4202. c.ServeSuccessJSON(map[string]interface{}{
  4203. "message": "1",
  4204. "good_name": goodObj.GoodName,
  4205. "specification_name": goodObj.SpecificationName,
  4206. })
  4207. return
  4208. }
  4209. }
  4210. //查询是否有出库单
  4211. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4212. if err == gorm.ErrRecordNotFound {
  4213. //没有记录,则创建出库单
  4214. timeStr := time.Now().Format("2006-01-02")
  4215. timeArr := strings.Split(timeStr, "-")
  4216. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  4217. total = total + 1
  4218. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4219. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4220. number = number + total
  4221. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4222. creater := adminInfo.AdminUser.Id
  4223. warehouseOut := models.WarehouseOut{
  4224. WarehouseOutOrderNumber: warehousing_out_order,
  4225. OperationTime: time.Now().Unix(),
  4226. OrgId: adminInfo.Org.Id,
  4227. Creater: creater,
  4228. Ctime: time.Now().Unix(),
  4229. Status: 1,
  4230. WarehouseOutTime: record_time,
  4231. Dealer: 0,
  4232. Manufacturer: 0,
  4233. Type: 1,
  4234. IsSys: 1,
  4235. StorehouseId: houseConfig.StorehouseOutInfo,
  4236. IsCheck: 1,
  4237. }
  4238. err := service.AddSigleWarehouseOut(&warehouseOut)
  4239. if err != nil {
  4240. goodErrcode := models.XtGoodErrcode{
  4241. UserOrgId: adminInfo.Org.Id,
  4242. Errcode: "创建出库单失败",
  4243. GoodId: 0,
  4244. Status: 1,
  4245. Ctime: time.Now().Unix(),
  4246. Mtime: 0,
  4247. Count: 0,
  4248. StockCount: 0,
  4249. Creater: creator,
  4250. BatchNumberId: 0,
  4251. WarehouseOutId: 0,
  4252. }
  4253. service.CreateGoodErrcode(goodErrcode)
  4254. utils.TraceLog("创建出库单失败 err = %v", err)
  4255. } else {
  4256. for _, item := range consumables {
  4257. //出库
  4258. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  4259. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  4260. //fmt.Println("item----------------------------------count", item.Count)
  4261. if err == nil {
  4262. goodErrcode := models.XtGoodErrcode{
  4263. UserOrgId: adminInfo.Org.Id,
  4264. Errcode: "自动出库接口报错",
  4265. GoodId: 0,
  4266. Status: 1,
  4267. Ctime: time.Now().Unix(),
  4268. Mtime: 0,
  4269. Count: 0,
  4270. StockCount: 0,
  4271. Creater: creator,
  4272. BatchNumberId: 0,
  4273. WarehouseOutId: 0,
  4274. }
  4275. service.CreateGoodErrcode(goodErrcode)
  4276. utils.TraceLog("创建出库单失败 err = %v", err)
  4277. }
  4278. //查询
  4279. //出库数量相加
  4280. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  4281. if errs != nil {
  4282. goodErrcode := models.XtGoodErrcode{
  4283. UserOrgId: item.UserOrgId,
  4284. Errcode: "创建剩余库存字段报错",
  4285. GoodId: item.GoodId,
  4286. Status: 1,
  4287. Ctime: time.Now().Unix(),
  4288. Mtime: 0,
  4289. Count: 0,
  4290. StockCount: 0,
  4291. Creater: creater,
  4292. BatchNumberId: 0,
  4293. WarehouseOutId: 0,
  4294. }
  4295. service.CreateGoodErrcode(goodErrcode)
  4296. }
  4297. }
  4298. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4299. if len(list) == 0 {
  4300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4301. return
  4302. }
  4303. for _, item := range list {
  4304. prepare := models.DialysisBeforePrepare{
  4305. UserOrgId: adminInfo.Org.Id,
  4306. PatientId: patient_id,
  4307. RecordDate: record_time,
  4308. GoodId: item.GoodId,
  4309. GoodTypeId: item.GoodTypeId,
  4310. Count: item.Count,
  4311. Creater: adminInfo.AdminUser.Id,
  4312. Status: 1,
  4313. Ctime: time.Now().Unix(),
  4314. StorehouseId: houseConfig.StorehouseOutInfo,
  4315. }
  4316. //清空准备表数据
  4317. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4318. if err != nil {
  4319. goodErrcode := models.XtGoodErrcode{
  4320. UserOrgId: item.OrgId,
  4321. Errcode: "自动出库清空准备表数据报错",
  4322. GoodId: item.GoodId,
  4323. Status: 1,
  4324. Ctime: time.Now().Unix(),
  4325. Mtime: 0,
  4326. Count: 0,
  4327. StockCount: 0,
  4328. Creater: creater,
  4329. BatchNumberId: 0,
  4330. WarehouseOutId: 0,
  4331. }
  4332. service.CreateGoodErrcode(goodErrcode)
  4333. }
  4334. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  4335. if errs != nil {
  4336. goodErrcode := models.XtGoodErrcode{
  4337. UserOrgId: item.OrgId,
  4338. Errcode: "自动出库创建准备表数据报错",
  4339. GoodId: item.GoodId,
  4340. Status: 1,
  4341. Ctime: time.Now().Unix(),
  4342. Mtime: 0,
  4343. Count: 0,
  4344. StockCount: 0,
  4345. Creater: creater,
  4346. BatchNumberId: 0,
  4347. WarehouseOutId: 0,
  4348. }
  4349. service.CreateGoodErrcode(goodErrcode)
  4350. }
  4351. //查询默认仓库
  4352. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4353. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4354. var total_count int64
  4355. for _, it := range stockList {
  4356. total_count += it.StockCount
  4357. }
  4358. //基础库插入数据
  4359. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4360. if errcodes != nil {
  4361. goodErrcode := models.XtGoodErrcode{
  4362. UserOrgId: item.OrgId,
  4363. Errcode: "自动出库基础库插入数据",
  4364. GoodId: item.GoodId,
  4365. Status: 1,
  4366. Ctime: time.Now().Unix(),
  4367. Mtime: 0,
  4368. Count: 0,
  4369. StockCount: 0,
  4370. Creater: creater,
  4371. BatchNumberId: 0,
  4372. WarehouseOutId: 0,
  4373. }
  4374. service.CreateGoodErrcode(goodErrcode)
  4375. }
  4376. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4377. var flush_count int64
  4378. for _, it := range goodList {
  4379. flush_count += it.StockCount
  4380. }
  4381. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4382. if errsss != nil {
  4383. goodErrcode := models.XtGoodErrcode{
  4384. UserOrgId: item.OrgId,
  4385. Errcode: "自动出库剩余库存更新数据",
  4386. GoodId: item.GoodId,
  4387. Status: 1,
  4388. Ctime: time.Now().Unix(),
  4389. Mtime: 0,
  4390. Count: 0,
  4391. StockCount: 0,
  4392. Creater: creater,
  4393. BatchNumberId: 0,
  4394. WarehouseOutId: 0,
  4395. }
  4396. service.CreateGoodErrcode(goodErrcode)
  4397. }
  4398. }
  4399. }
  4400. //
  4401. } else if err == nil {
  4402. for _, item := range consumables {
  4403. //出库
  4404. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  4405. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  4406. //fmt.Println("item----------------------------------count", item.Count)
  4407. if err != nil {
  4408. goodErrcode := models.XtGoodErrcode{
  4409. UserOrgId: adminInfo.Org.Id,
  4410. Errcode: "自动出库接口报错",
  4411. GoodId: 0,
  4412. Status: 1,
  4413. Ctime: time.Now().Unix(),
  4414. Mtime: 0,
  4415. Count: 0,
  4416. StockCount: 0,
  4417. Creater: creator,
  4418. BatchNumberId: 0,
  4419. WarehouseOutId: 0,
  4420. }
  4421. service.CreateGoodErrcode(goodErrcode)
  4422. }
  4423. //出库数量相加
  4424. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  4425. if errss != nil {
  4426. goodErrcode := models.XtGoodErrcode{
  4427. UserOrgId: item.UserOrgId,
  4428. Errcode: "创建剩余库存字段报错",
  4429. GoodId: item.GoodId,
  4430. Status: 1,
  4431. Ctime: time.Now().Unix(),
  4432. Mtime: time.Now().Unix(),
  4433. Count: 0,
  4434. StockCount: 0,
  4435. Creater: item.Creater,
  4436. BatchNumberId: 0,
  4437. WarehouseOutId: 0,
  4438. }
  4439. service.CreateGoodErrcode(goodErrcode)
  4440. }
  4441. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4442. if len(list) == 0 {
  4443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4444. return
  4445. }
  4446. for _, item := range list {
  4447. prepare := models.DialysisBeforePrepare{
  4448. UserOrgId: adminInfo.Org.Id,
  4449. PatientId: patient_id,
  4450. RecordDate: record_time,
  4451. GoodId: item.GoodId,
  4452. GoodTypeId: item.GoodTypeId,
  4453. Count: item.Count,
  4454. Creater: adminInfo.AdminUser.Id,
  4455. Status: 1,
  4456. Ctime: time.Now().Unix(),
  4457. StorehouseId: houseConfig.StorehouseOutInfo,
  4458. }
  4459. //清空准备表数据
  4460. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4461. if errs != nil {
  4462. goodErrcode := models.XtGoodErrcode{
  4463. UserOrgId: adminInfo.Org.Id,
  4464. Errcode: "自动出库清空准备表数据报错",
  4465. GoodId: 0,
  4466. Status: 1,
  4467. Ctime: time.Now().Unix(),
  4468. Mtime: 0,
  4469. Count: 0,
  4470. StockCount: 0,
  4471. Creater: creator,
  4472. BatchNumberId: 0,
  4473. WarehouseOutId: 0,
  4474. }
  4475. service.CreateGoodErrcode(goodErrcode)
  4476. }
  4477. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  4478. if errcodes != nil {
  4479. goodErrcode := models.XtGoodErrcode{
  4480. UserOrgId: adminInfo.Org.Id,
  4481. Errcode: "自动出库创建准备表数据报错",
  4482. GoodId: 0,
  4483. Status: 1,
  4484. Ctime: time.Now().Unix(),
  4485. Mtime: 0,
  4486. Count: 0,
  4487. StockCount: 0,
  4488. Creater: creator,
  4489. BatchNumberId: 0,
  4490. WarehouseOutId: 0,
  4491. }
  4492. service.CreateGoodErrcode(goodErrcode)
  4493. }
  4494. //查询默认仓库
  4495. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4496. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4497. var total_count int64
  4498. for _, it := range stockList {
  4499. total_count += it.StockCount
  4500. }
  4501. //基础库插入数据
  4502. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4503. if errcodes != nil {
  4504. goodErrcode := models.XtGoodErrcode{
  4505. UserOrgId: adminInfo.Org.Id,
  4506. Errcode: "自动出库基础库插入数据报错",
  4507. GoodId: 0,
  4508. Status: 1,
  4509. Ctime: time.Now().Unix(),
  4510. Mtime: 0,
  4511. Count: 0,
  4512. StockCount: 0,
  4513. Creater: creator,
  4514. BatchNumberId: 0,
  4515. WarehouseOutId: 0,
  4516. }
  4517. service.CreateGoodErrcode(goodErrcode)
  4518. }
  4519. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4520. var flush_count int64
  4521. for _, it := range goodList {
  4522. flush_count += it.StockCount
  4523. }
  4524. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4525. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  4526. if errss != nil {
  4527. goodErrcode := models.XtGoodErrcode{
  4528. UserOrgId: item.OrgId,
  4529. Errcode: "自动出库剩余库存更新数据",
  4530. GoodId: item.GoodId,
  4531. Status: 1,
  4532. Ctime: time.Now().Unix(),
  4533. Mtime: 0,
  4534. Count: 0,
  4535. StockCount: 0,
  4536. Creater: creater,
  4537. BatchNumberId: 0,
  4538. WarehouseOutId: 0,
  4539. }
  4540. service.CreateGoodErrcode(goodErrcode)
  4541. }
  4542. }
  4543. }
  4544. }
  4545. c.ServeSuccessJSON(map[string]interface{}{
  4546. "msg": "提交成功",
  4547. "message": "2",
  4548. "good_name": "",
  4549. "specification_name": "",
  4550. })
  4551. return
  4552. } else {
  4553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  4554. return
  4555. }
  4556. }
  4557. func (c *DialysisAPIController) EditConsumables() {
  4558. patient_id, _ := c.GetInt64("patient_id", 0)
  4559. record_date := c.GetString("record_time")
  4560. if patient_id <= 0 {
  4561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4562. return
  4563. }
  4564. adminInfo := c.GetMobileAdminUserInfo()
  4565. timeLayout := "2006-01-02"
  4566. loc, _ := time.LoadLocation("Local")
  4567. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4568. record_time := theRecordTime.Unix()
  4569. dataBody := make(map[string]interface{}, 0)
  4570. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4571. if err != nil {
  4572. utils.ErrorLog(err.Error())
  4573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4574. return
  4575. }
  4576. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4577. var beforePrepares []*models.DialysisBeforePrepareGoods
  4578. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4579. var cancelbefor []*models.DialysisBeforePrepareGoods
  4580. var outbefor []*models.DialysisBeforePrepareGoods
  4581. //判断是否开启自动出库
  4582. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4583. if record.IsOpen == 1 {
  4584. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4585. goods, _ := dataBody["goods"].([]interface{})
  4586. if len(goods) > 0 {
  4587. for _, item := range goods {
  4588. items := item.(map[string]interface{})
  4589. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4590. utils.ErrorLog("good_id")
  4591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4592. return
  4593. }
  4594. good_id := int64(items["good_id"].(float64))
  4595. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4596. utils.ErrorLog("good_type_id")
  4597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4598. return
  4599. }
  4600. good_type_id := int64(items["good_type_id"].(float64))
  4601. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4602. utils.ErrorLog("count")
  4603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4604. return
  4605. }
  4606. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4607. commdity_code := items["commdity_code"].(string)
  4608. fmt.Println(commdity_code)
  4609. prepareGoods := &models.DialysisBeforePrepareGoods{
  4610. GoodTypeId: good_type_id,
  4611. GoodId: good_id,
  4612. Count: count,
  4613. StorehouseId: houseConfig.StorehouseOutInfo,
  4614. }
  4615. beforePrepares = append(beforePrepares, prepareGoods)
  4616. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  4617. GoodTypeId: good_type_id,
  4618. GoodId: good_id,
  4619. Count: count,
  4620. StorehouseId: houseConfig.StorehouseOutInfo,
  4621. }
  4622. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  4623. }
  4624. for _, item := range beforePrepares {
  4625. //1.查看该患者该耗材型号最后一次出库数量
  4626. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4627. //判断当前出库数量和最后一次出库数量的大小
  4628. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  4629. if item.Count < goodInfo.Count {
  4630. cancelbefor = append(cancelbefor, item)
  4631. }
  4632. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  4633. if item.Count > goodInfo.Count {
  4634. outbefor = append(outbefor, item)
  4635. }
  4636. //处理编辑耗材新增不了的问题
  4637. if goodInfo.Count == item.Count {
  4638. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  4639. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  4640. }
  4641. }
  4642. fmt.Println("退库长度", len(cancelbefor))
  4643. fmt.Println("出库长度", len(outbefor))
  4644. //退库
  4645. for _, item := range cancelbefor {
  4646. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4647. creater := adminInfo.AdminUser.Id
  4648. //退库
  4649. //err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, cancelbefor, adminInfo.AdminUser.Id, item.Count)
  4650. //查询该患者当天已经出库的耗材信息
  4651. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  4652. var delete_count int64 = 0
  4653. delete_count = warehouseOutInfos.Count - item.Count
  4654. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4655. // 在出库记录表里记录退库详情
  4656. warehouseOutInfo := &models.WarehouseOutInfo{
  4657. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4658. WarehouseOutId: warehouseOut.ID,
  4659. Status: 1,
  4660. Ctime: time.Now().Unix(),
  4661. OrgId: adminInfo.Org.Id,
  4662. Type: 1,
  4663. IsSys: 1,
  4664. SysRecordTime: record_time,
  4665. GoodTypeId: item.GoodTypeId,
  4666. GoodId: item.GoodId,
  4667. PatientId: patient_id,
  4668. ConsumableType: 2,
  4669. StorehouseId: houseConfig.StorehouseOutInfo,
  4670. IsCheck: 1,
  4671. }
  4672. warehouseOutInfo.Count = item.Count
  4673. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  4674. warehouseOutInfo.Price = stockInInfo.Price
  4675. warehouseOutInfo.Dealer = stockInInfo.Dealer
  4676. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  4677. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  4678. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  4679. warehouseOutInfo.Number = warehouseOutInfos.Number
  4680. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  4681. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  4682. //查找当天是否存在出库记录
  4683. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  4684. if errcod == gorm.ErrRecordNotFound {
  4685. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4686. //插入详情明细表
  4687. stockFlow := models.VmStockFlow{
  4688. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4689. WarehouseOutId: warehouseOut.ID,
  4690. GoodId: item.GoodId,
  4691. Number: warehouseOutInfos.Number,
  4692. ProductDate: stockInInfo.ProductDate,
  4693. ExpireDate: stockInInfo.ExpiryDate,
  4694. Count: item.Count,
  4695. Price: stockInInfo.Price,
  4696. Status: 1,
  4697. Ctime: time.Now().Unix(),
  4698. UserOrgId: adminInfo.Org.Id,
  4699. Manufacturer: stockInInfo.Manufacturer,
  4700. Dealer: stockInInfo.Dealer,
  4701. LicenseNumber: stockInInfo.LicenseNumber,
  4702. IsEdit: 2,
  4703. Creator: creater,
  4704. SystemTime: record_time,
  4705. ConsumableType: 3,
  4706. WarehousingDetailId: 0,
  4707. IsSys: 1,
  4708. UpdateCreator: creater,
  4709. PatientId: patient_id,
  4710. StorehouseId: houseConfig.StorehouseOutInfo,
  4711. }
  4712. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  4713. if errflow == gorm.ErrRecordNotFound {
  4714. //创建流水表
  4715. err := service.CreateStockFlowOne(stockFlow)
  4716. fmt.Println("err", err)
  4717. } else if errflow == nil {
  4718. //插入详情明细表
  4719. stockFlow := models.VmStockFlow{
  4720. ID: exsit.ID,
  4721. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4722. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4723. WarehouseOutId: warehouseOut.ID,
  4724. GoodId: item.GoodId,
  4725. Number: warehouseOutInfos.Number,
  4726. ProductDate: stockInInfo.ProductDate,
  4727. ExpireDate: stockInInfo.ExpiryDate,
  4728. Count: exsit.Count - delete_count,
  4729. Price: stockInInfo.Price,
  4730. Status: 1,
  4731. Ctime: time.Now().Unix(),
  4732. UserOrgId: adminInfo.Org.Id,
  4733. Manufacturer: stockInInfo.Manufacturer,
  4734. Dealer: stockInInfo.Dealer,
  4735. LicenseNumber: stockInInfo.LicenseNumber,
  4736. IsEdit: 2,
  4737. Creator: creater,
  4738. SystemTime: record_time,
  4739. ConsumableType: 3,
  4740. WarehousingDetailId: 0,
  4741. IsSys: 1,
  4742. UpdateCreator: creater,
  4743. PatientId: patient_id,
  4744. StorehouseId: houseConfig.StorehouseOutInfo,
  4745. }
  4746. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  4747. }
  4748. } else if errcod == nil {
  4749. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  4750. //插入详情明细表
  4751. stockFlow := models.VmStockFlow{
  4752. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4753. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4754. WarehouseOutId: warehouseOut.ID,
  4755. GoodId: item.GoodId,
  4756. Number: warehouseOutInfos.Number,
  4757. ProductDate: stockInInfo.ProductDate,
  4758. ExpireDate: stockInInfo.ExpiryDate,
  4759. Count: item.Count,
  4760. Price: stockInInfo.Price,
  4761. Status: 1,
  4762. Ctime: time.Now().Unix(),
  4763. UserOrgId: adminInfo.Org.Id,
  4764. Manufacturer: stockInInfo.Manufacturer,
  4765. Dealer: stockInInfo.Dealer,
  4766. LicenseNumber: stockInInfo.LicenseNumber,
  4767. IsEdit: 2,
  4768. Creator: creater,
  4769. SystemTime: record_time,
  4770. ConsumableType: 3,
  4771. WarehousingDetailId: 0,
  4772. IsSys: 1,
  4773. UpdateCreator: creater,
  4774. PatientId: patient_id,
  4775. ReturnCount: delete_count,
  4776. StorehouseId: houseConfig.StorehouseOutInfo,
  4777. }
  4778. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  4779. if errflows == gorm.ErrRecordNotFound {
  4780. //创建流水表
  4781. service.CreateStockFlowOne(stockFlow)
  4782. } else if errflows == nil {
  4783. stockFlow := models.VmStockFlow{
  4784. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4785. ID: exsit.ID,
  4786. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4787. WarehouseOutId: warehouseOut.ID,
  4788. GoodId: item.GoodId,
  4789. Number: warehouseOutInfos.Number,
  4790. ProductDate: stockInInfo.ProductDate,
  4791. ExpireDate: stockInInfo.ExpiryDate,
  4792. Count: exsit.Count - delete_count,
  4793. Price: stockInInfo.Price,
  4794. Status: 1,
  4795. Ctime: time.Now().Unix(),
  4796. UserOrgId: adminInfo.Org.Id,
  4797. Manufacturer: stockInInfo.Manufacturer,
  4798. Dealer: stockInInfo.Dealer,
  4799. LicenseNumber: stockInInfo.LicenseNumber,
  4800. IsEdit: 2,
  4801. Creator: creater,
  4802. SystemTime: record_time,
  4803. ConsumableType: 3,
  4804. WarehousingDetailId: 0,
  4805. IsSys: 1,
  4806. UpdateCreator: creater,
  4807. PatientId: patient_id,
  4808. ReturnCount: delete_count,
  4809. StorehouseId: houseConfig.StorehouseOutInfo,
  4810. }
  4811. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  4812. }
  4813. }
  4814. //更改自动出库的表格
  4815. details := models.BloodAutomaticReduceDetail{
  4816. WarehouseOutId: warehouseOutInfo.ID,
  4817. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4818. PatientId: patient_id,
  4819. Ctime: time.Now().Unix(),
  4820. Mtime: time.Now().Unix(),
  4821. Status: 1,
  4822. RecordTime: record_time,
  4823. OrgId: adminInfo.Org.Id,
  4824. GoodId: item.GoodId,
  4825. GoodTypeId: item.GoodTypeId,
  4826. Count: item.Count,
  4827. StorehouseId: houseConfig.StorehouseOutInfo,
  4828. }
  4829. //查询当天耗材是否已经存在数据
  4830. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4831. if errcode == gorm.ErrRecordNotFound {
  4832. service.CreateAutoReduceRecord(&details)
  4833. } else if errcode == nil {
  4834. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4835. service.CreateAutoReduceRecord(&details)
  4836. }
  4837. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  4838. //增加出库库存数量
  4839. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  4840. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
  4841. fmt.Println("errOne", errOne)
  4842. // 删除出库完成后,要增加对应批次的库存数量
  4843. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  4844. //查询默认仓库
  4845. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4846. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4847. var total_count int64
  4848. for _, it := range stockList {
  4849. total_count += it.StockCount
  4850. }
  4851. //基础库插入数据
  4852. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4853. //更新剩余库存
  4854. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4855. var flush_count int64
  4856. for _, it := range goodList {
  4857. flush_count += it.StockCount
  4858. }
  4859. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4860. }
  4861. //出库
  4862. for _, item := range outbefor {
  4863. fmt.Println("出库ID", item.GoodId)
  4864. var last_total int64
  4865. //1.查看该患者该耗材型号最后一次出库数量
  4866. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4867. //计算当前出库和最后一次出库数据相差数据
  4868. last_total = item.Count - goodInfoOne.Count
  4869. //查询该批次剩余库存
  4870. lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
  4871. if lastInfo.StockCount == 0 {
  4872. //查询该耗材的总库存
  4873. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  4874. if wareinfo.StockCount == 0 {
  4875. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4876. c.ServeSuccessJSON(map[string]interface{}{
  4877. "message": "1",
  4878. "good_name": goodObj.GoodName,
  4879. "specification_name": goodObj.SpecificationName,
  4880. })
  4881. return
  4882. }
  4883. }
  4884. //查询该耗材的总库存
  4885. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  4886. // 如果库存差大于剩余库存则提示库存不足
  4887. if last_total > wareinfo.StockCount {
  4888. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4889. c.ServeSuccessJSON(map[string]interface{}{
  4890. "message": "1",
  4891. "good_name": goodObj.GoodName,
  4892. "specification_name": goodObj.SpecificationName,
  4893. })
  4894. return
  4895. } else {
  4896. fmt.Println("出库2o2o2o2o2oo2o2o2o2o2o2o", item.GoodId)
  4897. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4898. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4899. if err == gorm.ErrRecordNotFound {
  4900. //没有记录,则创建出库单
  4901. timeStr := time.Now().Format("2006-01-02")
  4902. timeArr := strings.Split(timeStr, "-")
  4903. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  4904. total = total + 1
  4905. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4906. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4907. number = number + total
  4908. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4909. warehouseOut := models.WarehouseOut{
  4910. WarehouseOutOrderNumber: warehousing_out_order,
  4911. OperationTime: time.Now().Unix(),
  4912. OrgId: adminInfo.Org.Id,
  4913. Creater: adminInfo.AdminUser.Id,
  4914. Ctime: time.Now().Unix(),
  4915. Status: 1,
  4916. WarehouseOutTime: record_time,
  4917. Dealer: 0,
  4918. Manufacturer: 0,
  4919. Type: 1,
  4920. IsSys: 1,
  4921. StorehouseId: houseConfig.StorehouseOutInfo,
  4922. IsCheck: 1,
  4923. }
  4924. service.AddSigleWarehouseOut(&warehouseOut)
  4925. }
  4926. //出库
  4927. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  4928. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4929. //1.查看该患者该耗材型号最后一次出库数量
  4930. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4931. fmt.Println("count2323323222323wi", item.Count)
  4932. prepare := models.DialysisBeforePrepare{
  4933. UserOrgId: adminInfo.Org.Id,
  4934. PatientId: patient_id,
  4935. RecordDate: record_time,
  4936. GoodId: item.GoodId,
  4937. GoodTypeId: item.GoodTypeId,
  4938. Count: item.Count - goodInfoTwo.Count,
  4939. Ctime: time.Now().Unix(),
  4940. Mtime: 0,
  4941. Creater: adminInfo.AdminUser.Id,
  4942. Modifier: adminInfo.AdminUser.Id,
  4943. Status: 1,
  4944. CommdityCode: "",
  4945. NewCount: 0,
  4946. ProjectId: 0,
  4947. StorehouseId: houseConfig.StorehouseOutInfo,
  4948. }
  4949. fmt.Println("prepare", prepare.Count)
  4950. fmt.Println("count", item.Count)
  4951. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  4952. //增加出库数量
  4953. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  4954. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4955. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4956. var total_count int64
  4957. for _, it := range stockList {
  4958. total_count += it.StockCount
  4959. }
  4960. //基础库插入数据
  4961. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4962. //剩余库存
  4963. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4964. var flush_count int64
  4965. for _, it := range goodList {
  4966. flush_count += it.StockCount
  4967. }
  4968. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4969. }
  4970. }
  4971. //查询今日出库数据
  4972. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4973. for _, it := range list {
  4974. prepare := models.DialysisBeforePrepare{
  4975. UserOrgId: it.OrgId,
  4976. PatientId: patient_id,
  4977. RecordDate: it.RecordTime,
  4978. GoodId: it.GoodId,
  4979. GoodTypeId: it.GoodTypeId,
  4980. Count: it.Count,
  4981. Ctime: time.Now().Unix(),
  4982. Creater: adminInfo.AdminUser.Id,
  4983. Status: 1,
  4984. StorehouseId: houseConfig.StorehouseOutInfo,
  4985. }
  4986. //删除准备表数据
  4987. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  4988. service.CreateDialysisBeforePrepareOne(&prepare)
  4989. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4990. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4991. var total_count int64
  4992. for _, it := range stockList {
  4993. total_count += it.StockCount
  4994. }
  4995. //基础库插入数据
  4996. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  4997. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  4998. var flush_count int64
  4999. for _, it := range goodList {
  5000. flush_count += it.StockCount
  5001. }
  5002. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  5003. //if err != nil {
  5004. // goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
  5005. // c.ServeSuccessJSON(map[string]interface{}{
  5006. // "message": "2",
  5007. // "good_name": goodObj.GoodName,
  5008. // "specification_name": goodObj.SpecificationName,
  5009. // })
  5010. // return
  5011. //}
  5012. }
  5013. }
  5014. }
  5015. //更新自动出库的地方
  5016. var errs error
  5017. if errs == nil {
  5018. c.ServeSuccessJSON(map[string]interface{}{
  5019. "msg": "修改成功",
  5020. "message": "2",
  5021. "good_name": "",
  5022. "specification_name": "",
  5023. })
  5024. return
  5025. } else {
  5026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5027. return
  5028. }
  5029. }
  5030. }
  5031. func (c *DialysisAPIController) GetDialysisGoods() {
  5032. schedualDate := c.GetString("schedule_date")
  5033. schedule_type, _ := c.GetInt64("schedule_type")
  5034. partition_id, _ := c.GetInt64("partition_id")
  5035. page, _ := c.GetInt("page")
  5036. patient_id, _ := c.GetInt64("patient_id")
  5037. schedualEndDate := int64(0)
  5038. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5039. if parseDateErr != nil && len(schedualDate) != 0 {
  5040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5041. return
  5042. }
  5043. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  5044. if parseDateErr != nil && len(schedualDate) != 0 {
  5045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5046. return
  5047. }
  5048. schedualEndDate = endDate.Unix()
  5049. adminUser := c.GetMobileAdminUserInfo()
  5050. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  5051. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  5052. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  5053. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  5054. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  5055. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  5056. //获取当天该病人的透析处方
  5057. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  5058. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  5059. if err == gorm.ErrRecordNotFound {
  5060. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  5061. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  5062. if patient_id != 0 {
  5063. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5064. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  5065. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  5066. //获取患者总的出库数据
  5067. item.LastAutomaticReduceDetail = goodUser
  5068. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5069. item.Project = project
  5070. }
  5071. }
  5072. c.ServeSuccessJSON(map[string]interface{}{
  5073. "dialysis_goods": dialysisGoods,
  5074. "good_type": goodTypes,
  5075. "total": total,
  5076. "prescribe": prescribe,
  5077. "good_info": good_info,
  5078. "warehouseOutList": warehouseOutList,
  5079. "config": config,
  5080. "outConfig": outConfig,
  5081. "settleConfig": settleConfig,
  5082. })
  5083. return
  5084. } else if err == nil {
  5085. //获取当天排班的每个患者的库存使用情况
  5086. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  5087. //获取患者总的出库数据
  5088. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  5089. if patient_id != 0 {
  5090. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5091. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  5092. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  5093. item.Project = project
  5094. item.LastAutomaticReduceDetail = goodUser
  5095. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5096. }
  5097. }
  5098. if err == nil {
  5099. c.ServeSuccessJSON(map[string]interface{}{
  5100. "dialysis_goods": dialysisGoods,
  5101. "good_type": goodTypes,
  5102. "total": total,
  5103. "prescribe": prescribe,
  5104. "good_info": good_info,
  5105. "project": project,
  5106. "warehouseOutList": warehouseOutList,
  5107. "config": config,
  5108. "outConfig": outConfig,
  5109. "settleConfig": settleConfig,
  5110. })
  5111. return
  5112. } else {
  5113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5114. return
  5115. }
  5116. } else if err != nil {
  5117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5118. return
  5119. }
  5120. }
  5121. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  5122. start_time := c.GetString("start_time")
  5123. end_time := c.GetString("end_time")
  5124. timeLayout := "2006-01-02"
  5125. loc, _ := time.LoadLocation("Local")
  5126. var theStartTime int64
  5127. if len(start_time) > 0 {
  5128. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5129. if err != nil {
  5130. utils.ErrorLog(err.Error())
  5131. }
  5132. theStartTime = theTime.Unix()
  5133. }
  5134. var theEndtTime int64
  5135. if len(end_time) > 0 {
  5136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5137. if err != nil {
  5138. utils.ErrorLog(err.Error())
  5139. }
  5140. theEndtTime = theTime.Unix()
  5141. }
  5142. adminUser := c.GetMobileAdminUserInfo()
  5143. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  5144. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  5145. if err == nil {
  5146. c.ServeSuccessJSON(map[string]interface{}{
  5147. "stock_out": outInfo,
  5148. "stockCount": stockCount,
  5149. })
  5150. return
  5151. } else {
  5152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5153. return
  5154. }
  5155. }
  5156. func (c *DialysisAPIController) GetStockInGoodInfo() {
  5157. patient_id, _ := c.GetInt64("patient_id", 0)
  5158. record_time := c.GetString("record_time")
  5159. adminUser := c.GetMobileAdminUserInfo()
  5160. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  5161. if parseDateErr != nil && len(record_time) != 0 {
  5162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5163. return
  5164. }
  5165. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  5166. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  5167. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  5168. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  5169. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  5170. //获取今日患者的透析处方参数
  5171. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  5172. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  5173. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  5174. c.ServeSuccessJSON(map[string]interface{}{
  5175. "good_type": goodTypes,
  5176. "good_user": goodUser,
  5177. "good_info": good_info,
  5178. "last_good_user": lastGoodUserDetial,
  5179. "project": project,
  5180. "prescription": prescribe,
  5181. "outInfo": outInfo,
  5182. "configs": configs,
  5183. })
  5184. return
  5185. }
  5186. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  5187. patient_id, _ := c.GetInt64("patient_id", 0)
  5188. record_date := c.GetString("record_time")
  5189. timeLayout := "2006-01-02"
  5190. loc, _ := time.LoadLocation("Local")
  5191. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5192. record_time := theRecordTime.Unix()
  5193. adminInfo := c.GetMobileAdminUserInfo()
  5194. dataBody := make(map[string]interface{}, 0)
  5195. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5196. if err != nil {
  5197. utils.ErrorLog(err.Error())
  5198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5199. return
  5200. }
  5201. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5202. var beforePrepares []*models.DialysisBeforePrepareGoods
  5203. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5204. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5205. goods, _ := dataBody["goods"].([]interface{})
  5206. if len(goods) > 0 {
  5207. for _, item := range goods {
  5208. items := item.(map[string]interface{})
  5209. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5210. utils.ErrorLog("good_id")
  5211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5212. return
  5213. }
  5214. good_id := int64(items["good_id"].(float64))
  5215. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5216. utils.ErrorLog("good_type_id")
  5217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5218. return
  5219. }
  5220. good_type_id := int64(items["good_type_id"].(float64))
  5221. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5222. utils.ErrorLog("count")
  5223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5224. return
  5225. }
  5226. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5227. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  5228. utils.ErrorLog("project_id")
  5229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5230. return
  5231. }
  5232. project_id := int64(items["project_id"].(float64))
  5233. prepare := &models.DialysisBeforePrepareGoods{
  5234. GoodId: good_id,
  5235. GoodTypeId: good_type_id,
  5236. Count: count,
  5237. ProjectId: project_id,
  5238. StorehouseId: houseConfig.StorehouseOutInfo,
  5239. }
  5240. beforePrepares = append(beforePrepares, prepare)
  5241. newPrepare := &models.NewDialysisBeforePrepareGoods{
  5242. GoodId: good_id,
  5243. GoodTypeId: good_type_id,
  5244. Count: count,
  5245. ProjectId: project_id,
  5246. StorehouseId: houseConfig.StorehouseOutInfo,
  5247. }
  5248. newBeforePrepares = append(newBeforePrepares, newPrepare)
  5249. }
  5250. }
  5251. }
  5252. //查询是否有库存
  5253. for _, item := range beforePrepares {
  5254. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5255. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  5256. if item.Count > warehouse.Count {
  5257. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5258. c.ServeSuccessJSON(map[string]interface{}{
  5259. "message": "1",
  5260. "good_name": goodObj.GoodName,
  5261. "specification_name": goodObj.SpecificationName,
  5262. })
  5263. return
  5264. }
  5265. }
  5266. //出库逻辑
  5267. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  5268. if err != nil {
  5269. utils.ErrorLog(err.Error())
  5270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5271. return
  5272. }
  5273. //查询当天出库的数据
  5274. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5275. for _, item := range list {
  5276. prepare := models.DialysisBeforePrepare{
  5277. UserOrgId: item.OrgId,
  5278. PatientId: item.PatientId,
  5279. RecordDate: item.RecordTime,
  5280. GoodId: item.GoodId,
  5281. GoodTypeId: item.GoodTypeId,
  5282. Count: item.Count,
  5283. Creater: adminInfo.AdminUser.Id,
  5284. Status: 1,
  5285. Ctime: time.Now().Unix(),
  5286. ProjectId: item.ProjectId,
  5287. StorehouseId: houseConfig.StorehouseOutInfo,
  5288. }
  5289. //清空准备表的数据
  5290. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5291. //插入准备表数据
  5292. service.CreateDialysisBeforePrepareOne(&prepare)
  5293. //查询默认仓库
  5294. //查询默认仓库
  5295. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5296. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5297. var total_count int64
  5298. for _, it := range stockList {
  5299. total_count += it.StockCount
  5300. }
  5301. //基础库插入数据
  5302. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5303. ////更新剩余库存
  5304. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5305. var flush_count int64
  5306. for _, it := range goodList {
  5307. flush_count += it.StockCount
  5308. }
  5309. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5310. if errs != nil {
  5311. goodErrcode := models.XtGoodErrcode{
  5312. UserOrgId: item.OrgId,
  5313. Errcode: "手动出库更新剩余出库失败",
  5314. GoodId: item.GoodId,
  5315. Status: 1,
  5316. Ctime: time.Now().Unix(),
  5317. Mtime: 0,
  5318. Count: 0,
  5319. StockCount: 0,
  5320. Creater: adminInfo.AdminUser.Id,
  5321. BatchNumberId: 0,
  5322. WarehouseOutId: 0,
  5323. }
  5324. service.CreateGoodErrcode(goodErrcode)
  5325. }
  5326. }
  5327. //更新自动出库的地方
  5328. var errs error
  5329. if errs == nil {
  5330. c.ServeSuccessJSON(map[string]interface{}{
  5331. "msg": "修改成功",
  5332. "message": "2",
  5333. "good_name": "",
  5334. "specification_name": "",
  5335. })
  5336. return
  5337. } else {
  5338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5339. return
  5340. }
  5341. }
  5342. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  5343. newArr = make([]*models.DialysisBeforePrepare, 0)
  5344. for i := 0; i < len(arr); i++ {
  5345. repeat := false
  5346. for j := i + 1; j < len(arr); j++ {
  5347. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  5348. repeat = true
  5349. break
  5350. }
  5351. }
  5352. if !repeat {
  5353. newArr = append(newArr, arr[i])
  5354. }
  5355. }
  5356. return
  5357. }
  5358. func (c *DialysisAPIController) GetAllDrug() {
  5359. patient_id, _ := c.GetInt64("patient_id", 0)
  5360. adminInfo := c.GetMobileAdminUserInfo()
  5361. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5362. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  5363. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  5364. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  5365. c.ServeSuccessJSON(map[string]interface{}{
  5366. "base_drug_config": drugStockConfig,
  5367. "private_drug_config": privateDrugConfig,
  5368. "base_drug_list": drugList,
  5369. "private_drug_list": privateDrugList,
  5370. })
  5371. }
  5372. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  5373. newArr = make([]*models.DialysisBeforePrepare, 0)
  5374. for i := 0; i < len(arr); i++ {
  5375. repeat := false
  5376. for j := i + 1; j < len(arr); j++ {
  5377. if arr[i].GoodId == arr[j].GoodId {
  5378. repeat = true
  5379. break
  5380. }
  5381. }
  5382. if !repeat {
  5383. newArr = append(newArr, arr[i])
  5384. }
  5385. }
  5386. return
  5387. }
  5388. func (c *DialysisAPIController) GetDepartment() {
  5389. adminInfo := c.GetMobileAdminUserInfo()
  5390. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  5391. if err == nil {
  5392. c.ServeSuccessJSON(map[string]interface{}{
  5393. "departments": departments,
  5394. })
  5395. } else {
  5396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5397. return
  5398. }
  5399. }
  5400. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  5401. types, _ := c.GetInt("type", 0)
  5402. start_time := c.GetString("start_time")
  5403. end_time := c.GetString("end_time")
  5404. orgId := c.GetMobileAdminUserInfo().Org.Id
  5405. timeLayout := "2006-01-02"
  5406. loc, _ := time.LoadLocation("Local")
  5407. var startTime int64
  5408. if len(start_time) > 0 {
  5409. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5410. if err != nil {
  5411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5412. return
  5413. }
  5414. startTime = theTime.Unix()
  5415. }
  5416. var endTime int64
  5417. if len(end_time) > 0 {
  5418. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5419. if err != nil {
  5420. utils.ErrorLog(err.Error())
  5421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5422. return
  5423. }
  5424. endTime = theTime.Unix()
  5425. }
  5426. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  5427. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  5428. if err != nil {
  5429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5430. } else {
  5431. c.ServeSuccessJSON(map[string]interface{}{
  5432. "list": list,
  5433. "type": types,
  5434. "stockTotal": stockTotal,
  5435. })
  5436. }
  5437. }
  5438. func (c *DialysisAPIController) BatchDeleteMonitor() {
  5439. ids := c.GetString("ids")
  5440. //patient_id, _ := c.GetInt64("patient_id")
  5441. //monitoring_date, _ := c.GetInt64("monitoring_date")
  5442. idArray := strings.Split(ids, ",")
  5443. err := service.BatchDeleteMonitor(idArray)
  5444. fmt.Print("err", err)
  5445. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5446. //redis := service.RedisClient()
  5447. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  5448. //redis.Set(key, "", time.Second)
  5449. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  5450. //redis.Set(keyOne, "", time.Second)
  5451. //fmt.Println("keyo呢32332322332332232332",keyOne)
  5452. //redis.Close()
  5453. c.ServeSuccessJSON(map[string]interface{}{
  5454. "msg": "批量删除成功",
  5455. })
  5456. return
  5457. }
  5458. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  5459. id, _ := c.GetInt64("id")
  5460. timeLayout := "2006-01-02"
  5461. loc, _ := time.LoadLocation("Local")
  5462. start_time := time.Now().Format("2006-01-02")
  5463. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5464. nowTime := time.Now()
  5465. endTime := nowTime.AddDate(-2, 0, 0)
  5466. endTimes := endTime.Format("2006-01-02")
  5467. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  5468. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  5469. fmt.Println("endtime232332322332322323232332", endTime.Unix())
  5470. c.ServeSuccessJSON(map[string]interface{}{
  5471. "list": list,
  5472. })
  5473. return
  5474. }
  5475. func (c *DialysisAPIController) BathDeleteAdviceList() {
  5476. dataBody := make(map[string]interface{}, 0)
  5477. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5478. ids := c.GetString("ids")
  5479. idArray := strings.Split(ids, ",")
  5480. origin, _ := c.GetInt64("origin")
  5481. if origin == 1 {
  5482. err = service.BatchDeleteAdvice(idArray)
  5483. fmt.Print("err", err)
  5484. c.ServeSuccessJSON(map[string]interface{}{
  5485. "msg": "批量删除成功",
  5486. })
  5487. return
  5488. }
  5489. if origin == 2 {
  5490. service.BatchDeleteHisAdvice(idArray)
  5491. }
  5492. }
  5493. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  5494. good_id, _ := c.GetInt64("good_id")
  5495. count, _ := c.GetInt64("count")
  5496. record_time, _ := c.GetInt64("record_time")
  5497. patient_id, _ := c.GetInt64("patient_id")
  5498. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  5499. c.ServeSuccessJSON(map[string]interface{}{
  5500. "detail": detail,
  5501. })
  5502. return
  5503. }
  5504. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  5505. good_id, _ := c.GetInt64("good_id")
  5506. record_time, _ := c.GetInt64("record_time")
  5507. patient_id, _ := c.GetInt64("patient_id")
  5508. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  5509. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  5510. fmt.Print("err", err)
  5511. c.ServeSuccessJSON(map[string]interface{}{
  5512. "msg": "批量删除成功",
  5513. })
  5514. return
  5515. }
  5516. func (c *DialysisAPIController) BatchAdviceCheck() {
  5517. ids := c.GetString("ids")
  5518. idArray := strings.Split(ids, ",")
  5519. creator, _ := c.GetInt64("creator")
  5520. origin, _ := c.GetInt64("origin")
  5521. if origin == 1 {
  5522. err := service.BatchAdviceCheck(idArray, creator)
  5523. fmt.Println(err)
  5524. list, _ := service.GetAdviceExecutionById(idArray)
  5525. c.ServeSuccessJSON(map[string]interface{}{
  5526. "list": list,
  5527. })
  5528. return
  5529. }
  5530. if origin == 2 {
  5531. service.BatchHisAdviceCheck(idArray, creator)
  5532. list, _ := service.GetHisAdviceExecutionById(idArray)
  5533. c.ServeSuccessJSON(map[string]interface{}{
  5534. "list": list,
  5535. })
  5536. return
  5537. }
  5538. }
  5539. func (c *DialysisAPIController) BatchAdviceExecution() {
  5540. ids := c.GetString("ids")
  5541. idArray := strings.Split(ids, ",")
  5542. executionTime := c.GetString("execution_time")
  5543. creator, _ := c.GetInt64("creator")
  5544. timeLayout := "2006-01-02 15:04:05"
  5545. loc, _ := time.LoadLocation("Local")
  5546. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  5547. orgin, _ := c.GetInt64("origin")
  5548. if orgin == 1 {
  5549. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  5550. list, _ := service.GetAdviceExecutionById(idArray)
  5551. fmt.Println(err)
  5552. c.ServeSuccessJSON(map[string]interface{}{
  5553. "list": list,
  5554. })
  5555. return
  5556. }
  5557. if orgin == 2 {
  5558. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  5559. list, _ := service.GetHisAdviceExecutionById(idArray)
  5560. fmt.Println(err)
  5561. c.ServeSuccessJSON(map[string]interface{}{
  5562. "list": list,
  5563. })
  5564. return
  5565. }
  5566. }
  5567. func (c *DialysisAPIController) UpdateStockGoods() {
  5568. good_id, _ := c.GetInt64("good_id")
  5569. record_time, _ := c.GetInt64("record_time")
  5570. patient_id, _ := c.GetInt64("patient_id")
  5571. count, _ := c.GetInt64("count")
  5572. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  5573. fmt.Print("err", err)
  5574. c.ServeSuccessJSON(map[string]interface{}{
  5575. "msg": "更新成功",
  5576. })
  5577. return
  5578. }
  5579. // 当前数据比上一次出库数据少
  5580. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  5581. //查询该患者当天已经出库的耗材信息
  5582. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  5583. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  5584. for i := len(goods_yc) - 1; i >= 0; i-- {
  5585. goods_yc_temp := goods_yc[i]
  5586. for j := len(goods) - 1; j >= 0; j-- {
  5587. goods_temp := goods[j]
  5588. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  5589. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  5590. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  5591. if goods_yc_temp.Count == goods_temp.Count {
  5592. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5593. goods = append(goods[:j], goods[j+1:]...)
  5594. break
  5595. }
  5596. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  5597. if goods_yc_temp.Count > goods_temp.Count {
  5598. temp_count := goods_yc_temp.Count - goods_temp.Count
  5599. goods_yc[i].Count = temp_count
  5600. goods = append(goods[:j], goods[j+1:]...)
  5601. break
  5602. }
  5603. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  5604. if goods_yc_temp.Count < goods_temp.Count {
  5605. temp_count := goods_temp.Count - goods_yc_temp.Count
  5606. goods[j].Count = temp_count
  5607. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5608. break
  5609. }
  5610. }
  5611. }
  5612. }
  5613. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  5614. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  5615. //退库
  5616. if len(goods_yc) > 0 {
  5617. for _, good_yc := range goods_yc {
  5618. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  5619. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  5620. }
  5621. }
  5622. return nil
  5623. }
  5624. // 耗材出库删除
  5625. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  5626. // 先根据相关信息查询当天该耗材的出库信息
  5627. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  5628. if err != nil {
  5629. return err
  5630. }
  5631. var delete_count int64 = 0
  5632. delete_count = warehouseOutInfos.Count - count
  5633. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5634. // 在出库记录表里记录退库详情
  5635. warehouseOutInfo := &models.WarehouseOutInfo{
  5636. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5637. WarehouseOutId: warehouseOut.ID,
  5638. Status: 1,
  5639. Ctime: time.Now().Unix(),
  5640. OrgId: orgID,
  5641. Type: 1,
  5642. IsSys: 1,
  5643. SysRecordTime: record_time,
  5644. GoodTypeId: good_yc.GoodTypeId,
  5645. GoodId: good_yc.GoodId,
  5646. PatientId: good_yc.PatientId,
  5647. ConsumableType: 2,
  5648. StorehouseId: houseConfig.StorehouseOutInfo,
  5649. IsCheck: 1,
  5650. }
  5651. warehouseOutInfo.Count = count
  5652. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5653. warehouseOutInfo.Price = stockInInfo.Price
  5654. warehouseOutInfo.Dealer = stockInInfo.Dealer
  5655. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  5656. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  5657. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  5658. warehouseOutInfo.Number = warehouseOutInfos.Number
  5659. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  5660. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  5661. //查找当天是否存在出库记录
  5662. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5663. if errcod == gorm.ErrRecordNotFound {
  5664. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5665. //插入详情明细表
  5666. stockFlow := models.VmStockFlow{
  5667. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5668. WarehouseOutId: warehouseOut.ID,
  5669. GoodId: good_yc.GoodId,
  5670. Number: warehouseOutInfos.Number,
  5671. ProductDate: stockInInfo.ProductDate,
  5672. ExpireDate: stockInInfo.ExpiryDate,
  5673. Count: count,
  5674. Price: stockInInfo.Price,
  5675. Status: 1,
  5676. Ctime: time.Now().Unix(),
  5677. UserOrgId: good_yc.OrgId,
  5678. Manufacturer: stockInInfo.Manufacturer,
  5679. Dealer: stockInInfo.Dealer,
  5680. LicenseNumber: stockInInfo.LicenseNumber,
  5681. IsEdit: 2,
  5682. Creator: creater,
  5683. SystemTime: record_time,
  5684. ConsumableType: 3,
  5685. WarehousingDetailId: 0,
  5686. IsSys: 1,
  5687. UpdateCreator: creater,
  5688. PatientId: patient_id,
  5689. StorehouseId: houseConfig.StorehouseOutInfo,
  5690. }
  5691. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  5692. if errflow == gorm.ErrRecordNotFound {
  5693. //创建流水表
  5694. err := service.CreateStockFlowOne(stockFlow)
  5695. fmt.Println("err", err)
  5696. } else if errflow == nil {
  5697. //插入详情明细表
  5698. stockFlow := models.VmStockFlow{
  5699. ID: exsit.ID,
  5700. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5701. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5702. WarehouseOutId: warehouseOut.ID,
  5703. GoodId: good_yc.GoodId,
  5704. Number: warehouseOutInfos.Number,
  5705. ProductDate: stockInInfo.ProductDate,
  5706. ExpireDate: stockInInfo.ExpiryDate,
  5707. Count: exsit.Count - delete_count,
  5708. Price: stockInInfo.Price,
  5709. Status: 1,
  5710. Ctime: time.Now().Unix(),
  5711. UserOrgId: good_yc.OrgId,
  5712. Manufacturer: stockInInfo.Manufacturer,
  5713. Dealer: stockInInfo.Dealer,
  5714. LicenseNumber: stockInInfo.LicenseNumber,
  5715. IsEdit: 2,
  5716. Creator: creater,
  5717. SystemTime: record_time,
  5718. ConsumableType: 3,
  5719. WarehousingDetailId: 0,
  5720. IsSys: 1,
  5721. UpdateCreator: creater,
  5722. PatientId: patient_id,
  5723. StorehouseId: houseConfig.StorehouseOutInfo,
  5724. }
  5725. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  5726. }
  5727. if errOne != nil {
  5728. return errOne
  5729. }
  5730. } else if errcod == nil {
  5731. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5732. //插入详情明细表
  5733. stockFlow := models.VmStockFlow{
  5734. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5735. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5736. WarehouseOutId: warehouseOut.ID,
  5737. GoodId: good_yc.GoodId,
  5738. Number: warehouseOutInfos.Number,
  5739. ProductDate: stockInInfo.ProductDate,
  5740. ExpireDate: stockInInfo.ExpiryDate,
  5741. Count: count,
  5742. Price: stockInInfo.Price,
  5743. Status: 1,
  5744. Ctime: time.Now().Unix(),
  5745. UserOrgId: good_yc.OrgId,
  5746. Manufacturer: stockInInfo.Manufacturer,
  5747. Dealer: stockInInfo.Dealer,
  5748. LicenseNumber: stockInInfo.LicenseNumber,
  5749. IsEdit: 2,
  5750. Creator: creater,
  5751. SystemTime: record_time,
  5752. ConsumableType: 3,
  5753. WarehousingDetailId: 0,
  5754. IsSys: 1,
  5755. UpdateCreator: creater,
  5756. PatientId: patient_id,
  5757. ReturnCount: delete_count,
  5758. StorehouseId: houseConfig.StorehouseOutInfo,
  5759. }
  5760. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  5761. if errflows == gorm.ErrRecordNotFound {
  5762. //创建流水表
  5763. service.CreateStockFlowOne(stockFlow)
  5764. } else if errflows == nil {
  5765. stockFlow := models.VmStockFlow{
  5766. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5767. ID: exsit.ID,
  5768. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5769. WarehouseOutId: warehouseOut.ID,
  5770. GoodId: good_yc.GoodId,
  5771. Number: warehouseOutInfos.Number,
  5772. ProductDate: stockInInfo.ProductDate,
  5773. ExpireDate: stockInInfo.ExpiryDate,
  5774. Count: exsit.Count - delete_count,
  5775. Price: stockInInfo.Price,
  5776. Status: 1,
  5777. Ctime: time.Now().Unix(),
  5778. UserOrgId: good_yc.OrgId,
  5779. Manufacturer: stockInInfo.Manufacturer,
  5780. Dealer: stockInInfo.Dealer,
  5781. LicenseNumber: stockInInfo.LicenseNumber,
  5782. IsEdit: 2,
  5783. Creator: creater,
  5784. SystemTime: record_time,
  5785. ConsumableType: 3,
  5786. WarehousingDetailId: 0,
  5787. IsSys: 1,
  5788. UpdateCreator: creater,
  5789. PatientId: patient_id,
  5790. ReturnCount: delete_count,
  5791. StorehouseId: houseConfig.StorehouseOutInfo,
  5792. }
  5793. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  5794. }
  5795. }
  5796. //更改自动出库的表格
  5797. details := models.BloodAutomaticReduceDetail{
  5798. WarehouseOutId: warehouseOutInfo.ID,
  5799. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5800. PatientId: patient_id,
  5801. Ctime: time.Now().Unix(),
  5802. Mtime: time.Now().Unix(),
  5803. Status: 1,
  5804. RecordTime: record_time,
  5805. OrgId: orgID,
  5806. GoodId: good_yc.GoodId,
  5807. GoodTypeId: good_yc.GoodTypeId,
  5808. Count: count,
  5809. StorehouseId: houseConfig.StorehouseOutInfo,
  5810. }
  5811. //查询当天耗材是否已经存在数据
  5812. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  5813. if errcode == gorm.ErrRecordNotFound {
  5814. errTwo := service.CreateAutoReduceRecord(&details)
  5815. if errTwo != nil {
  5816. return errTwo
  5817. }
  5818. } else if errcode == nil {
  5819. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  5820. service.CreateAutoReduceRecord(&details)
  5821. }
  5822. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  5823. //增加出库库存数量
  5824. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  5825. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  5826. fmt.Println("errOne", errOne)
  5827. // 删除出库完成后,要增加对应批次的库存数量
  5828. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  5829. if errThree != nil {
  5830. return errThree
  5831. }
  5832. if good_yc.Count == 0 {
  5833. return nil
  5834. } else {
  5835. return errors.New("退库和出库数据不匹配")
  5836. }
  5837. }
  5838. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  5839. //查询该患者当天已经出库的耗材信息
  5840. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  5841. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  5842. for i := len(goods_yc) - 1; i >= 0; i-- {
  5843. goods_yc_temp := goods_yc[i]
  5844. for j := len(goods) - 1; j >= 0; j-- {
  5845. goods_temp := goods[j]
  5846. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  5847. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  5848. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  5849. if goods_yc_temp.Count == goods_temp.Count {
  5850. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5851. goods = append(goods[:j], goods[j+1:]...)
  5852. break
  5853. }
  5854. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  5855. if goods_yc_temp.Count > goods_temp.Count {
  5856. temp_count := goods_yc_temp.Count - goods_temp.Count
  5857. goods_yc[i].Count = temp_count
  5858. goods = append(goods[:j], goods[j+1:]...)
  5859. break
  5860. }
  5861. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  5862. if goods_yc_temp.Count < goods_temp.Count {
  5863. temp_count := goods_temp.Count - goods_yc_temp.Count
  5864. goods[j].Count = temp_count
  5865. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5866. break
  5867. }
  5868. }
  5869. }
  5870. }
  5871. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  5872. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  5873. fmt.Println("剩余需要出库的", len(goods))
  5874. if len(goods) > 0 {
  5875. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  5876. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5877. if err == gorm.ErrRecordNotFound {
  5878. //没有记录,则创建出库单
  5879. timeStr := time.Now().Format("2006-01-02")
  5880. timeArr := strings.Split(timeStr, "-")
  5881. total, _ := service.FindAllWarehouseOut(orgID)
  5882. total = total + 1
  5883. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5884. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5885. number = number + total
  5886. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5887. warehouseOut := models.WarehouseOut{
  5888. WarehouseOutOrderNumber: warehousing_out_order,
  5889. OperationTime: time.Now().Unix(),
  5890. OrgId: orgID,
  5891. Creater: creater,
  5892. Ctime: time.Now().Unix(),
  5893. Status: 1,
  5894. WarehouseOutTime: record_time,
  5895. Dealer: 0,
  5896. Manufacturer: 0,
  5897. Type: 1,
  5898. IsSys: 1,
  5899. StorehouseId: houseConfig.StorehouseOutInfo,
  5900. IsCheck: 1,
  5901. }
  5902. err := service.AddSigleWarehouseOut(&warehouseOut)
  5903. if err != nil {
  5904. utils.TraceLog("创建出库单失败 err = %v", err)
  5905. return err
  5906. } else {
  5907. out = warehouseOut
  5908. }
  5909. }
  5910. for _, item := range goods {
  5911. var newCount int64 = 0
  5912. for _, it := range goodOne {
  5913. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  5914. newCount = it.Count
  5915. }
  5916. }
  5917. prepare := models.DialysisBeforePrepare{
  5918. GoodTypeId: item.GoodTypeId,
  5919. GoodId: item.GoodId,
  5920. Count: item.Count,
  5921. StorehouseId: houseConfig.StorehouseOutInfo,
  5922. }
  5923. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  5924. //增加出库数量
  5925. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  5926. }
  5927. }
  5928. if len(goods_yc) > 0 {
  5929. for _, good_yc := range goods_yc {
  5930. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  5931. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  5932. }
  5933. }
  5934. return nil
  5935. }
  5936. // 耗材出库删除
  5937. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  5938. // 先根据相关信息查询当天该耗材的出库信息
  5939. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  5940. if err != nil {
  5941. return err
  5942. }
  5943. var delete_count int64 = 0
  5944. for _, ware := range warehouseOutInfos {
  5945. // 判断当前出库的数据和删除出库数量
  5946. if good_yc.Count <= ware.Count {
  5947. delete_count = good_yc.Count
  5948. } else {
  5949. delete_count = ware.Count
  5950. }
  5951. warehouseOutInfo := &models.WarehouseOutInfo{
  5952. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5953. WarehouseOutId: warehouseOut.ID,
  5954. Status: 1,
  5955. Ctime: time.Now().Unix(),
  5956. Remark: "",
  5957. OrgId: orgID,
  5958. Type: 1,
  5959. Manufacturer: 0,
  5960. Dealer: 0,
  5961. IsSys: 0,
  5962. SysRecordTime: record_time,
  5963. GoodTypeId: good_yc.GoodTypeId,
  5964. GoodId: good_yc.GoodId,
  5965. StorehouseId: warehouseOut.StorehouseId,
  5966. IsCheck: 1,
  5967. }
  5968. warehouseOutInfo.Count = delete_count
  5969. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5970. warehouseOutInfo.Price = stockInInfo.Price
  5971. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5972. if errOne != nil {
  5973. return errOne
  5974. }
  5975. // 删除出库完成后,要改变流水库存(有疑问)
  5976. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  5977. fmt.Println("errOne", errOne)
  5978. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  5979. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  5980. //扣减出库数量
  5981. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  5982. if errThree != nil {
  5983. return errThree
  5984. }
  5985. }
  5986. if good_yc.Count == 0 {
  5987. return nil
  5988. } else {
  5989. return errors.New("退库和出库数据不匹配")
  5990. }
  5991. }
  5992. func (this *DialysisAPIController) GetMobileScheduleList() {
  5993. limit, _ := this.GetInt64("limit")
  5994. page, _ := this.GetInt64("page")
  5995. type_options_visible, _ := this.GetInt64("type_options_visible")
  5996. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  5997. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  5998. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  5999. }
  6000. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  6001. newArr = make([]*models.HisPrescriptionProject, 0)
  6002. for i := 0; i < len(arr); i++ {
  6003. repeat := false
  6004. for j := i + 1; j < len(arr); j++ {
  6005. if arr[i].TeamId == arr[j].TeamId {
  6006. repeat = true
  6007. break
  6008. }
  6009. }
  6010. if !repeat {
  6011. newArr = append(newArr, arr[i])
  6012. }
  6013. }
  6014. return
  6015. }
  6016. func (this *DialysisAPIController) GetRoleList() {
  6017. admin_user_id, _ := this.GetInt64("admin_user_id")
  6018. orgid := this.GetMobileAdminUserInfo().Org.Id
  6019. list, err := service.GetRoleList(orgid, admin_user_id)
  6020. fmt.Println(err)
  6021. this.ServeSuccessJSON(map[string]interface{}{
  6022. "list": list,
  6023. })
  6024. return
  6025. }
  6026. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  6027. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  6028. // 先根据相关信息查询当天该耗材的出库信息
  6029. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  6030. if err != nil {
  6031. return err
  6032. }
  6033. var delete_count int64 = 0
  6034. delete_count = warehouseOutInfos.Count - count
  6035. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  6036. // 删除出库完成后,要增加对应批次的库存数量
  6037. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  6038. if errThree != nil {
  6039. return errThree
  6040. }
  6041. //增加退库数量
  6042. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6043. //扣减出库数量
  6044. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  6045. //查询剩余库存
  6046. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  6047. var sum_count int64
  6048. for _, item := range goodList {
  6049. sum_count += item.StockCount
  6050. }
  6051. // 在出库记录表里记录退库详情
  6052. warehouseOutInfo := &models.WarehouseOutInfo{
  6053. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6054. WarehouseOutId: warehouseOut.ID,
  6055. Status: 1,
  6056. Ctime: time.Now().Unix(),
  6057. OrgId: orgID,
  6058. Type: 1,
  6059. IsSys: 1,
  6060. SysRecordTime: record_time,
  6061. GoodTypeId: good_yc.GoodTypeId,
  6062. GoodId: good_yc.GoodId,
  6063. PatientId: good_yc.PatientId,
  6064. ConsumableType: 2,
  6065. StorehouseId: houseConfig.StorehouseOutInfo,
  6066. IsCheck: 1,
  6067. OverCount: sum_count,
  6068. }
  6069. warehouseOutInfo.Count = count
  6070. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  6071. warehouseOutInfo.Price = stockInInfo.Price
  6072. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6073. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6074. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6075. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6076. warehouseOutInfo.Number = warehouseOutInfos.Number
  6077. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6078. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6079. //查找当天是否存在出库记录
  6080. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6081. if errcod == gorm.ErrRecordNotFound {
  6082. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6083. //插入详情明细表
  6084. if errOne != nil {
  6085. return errOne
  6086. }
  6087. //插入详情明细表
  6088. stockFlow := models.VmStockFlow{
  6089. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6090. WarehouseOutId: warehouseOut.ID,
  6091. GoodId: good_yc.GoodId,
  6092. Number: warehouseOutInfos.Number,
  6093. ProductDate: stockInInfo.ProductDate,
  6094. ExpireDate: stockInInfo.ExpiryDate,
  6095. Count: count,
  6096. Price: stockInInfo.Price,
  6097. Status: 1,
  6098. Ctime: time.Now().Unix(),
  6099. UserOrgId: good_yc.OrgId,
  6100. Manufacturer: stockInInfo.Manufacturer,
  6101. Dealer: stockInInfo.Dealer,
  6102. LicenseNumber: stockInInfo.LicenseNumber,
  6103. IsEdit: 2,
  6104. Creator: creater,
  6105. SystemTime: record_time,
  6106. ConsumableType: 3,
  6107. WarehousingDetailId: 0,
  6108. IsSys: 1,
  6109. UpdateCreator: creater,
  6110. PatientId: patient_id,
  6111. StorehouseId: houseConfig.StorehouseOutInfo,
  6112. OverCount: sum_count,
  6113. ProjectId: good_yc.ProjectId,
  6114. }
  6115. err := service.CreateStockFlowOne(stockFlow)
  6116. fmt.Println("err", err)
  6117. } else if errcod == nil {
  6118. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6119. }
  6120. //创建退库单
  6121. operation_time := time.Now().Unix()
  6122. //创建退库单
  6123. timeStr := time.Now().Format("2006-01-02")
  6124. timeArr := strings.Split(timeStr, "-")
  6125. total, _ := service.FindAllCancelStockTotal(orgID)
  6126. total = total + 1
  6127. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6128. cancelStock := models.CancelStock{
  6129. OrderNumber: orderNumber,
  6130. OperaTime: operation_time,
  6131. OrgId: orgID,
  6132. Creater: warehouseOut.Creater,
  6133. Ctime: time.Now().Unix(),
  6134. Status: 1,
  6135. ReturnTime: record_time,
  6136. Type: 1,
  6137. StorehouseId: stockInInfo.StorehouseId,
  6138. IsCheck: 1,
  6139. }
  6140. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  6141. if msgerrkonde == gorm.ErrRecordNotFound {
  6142. service.AddSigleCancelStock(&cancelStock)
  6143. }
  6144. cancel, _ := service.GetLastCancelStockById(orgID)
  6145. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  6146. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  6147. cancelStockInfo := models.CancelStockInfo{
  6148. GoodId: stockInInfo.GoodId,
  6149. CancelStockId: cancel.ID,
  6150. GoodTypeId: stockInInfo.GoodTypeId,
  6151. Count: delete_count,
  6152. Price: stockInInfo.PackingPrice,
  6153. Total: 0,
  6154. ProductDate: stockInInfo.ProductDate,
  6155. ExpiryDate: stockInInfo.ExpiryDate,
  6156. Ctime: time.Now().Unix(),
  6157. Status: 1,
  6158. OrgId: orgID,
  6159. OrderNumber: cancel.OrderNumber,
  6160. Type: 0,
  6161. Dealer: deaerler.DealerName,
  6162. Manufacturer: manufacturer.ManufacturerName,
  6163. Number: stockInInfo.Number,
  6164. RegisterAccount: "",
  6165. Remark: "",
  6166. WarehouseInfoId: stockInInfo.ID,
  6167. PatientId: patient_id,
  6168. RecordDate: record_time,
  6169. StorehouseId: stockInInfo.StorehouseId,
  6170. IsCheck: 1,
  6171. }
  6172. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6173. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  6174. flow := models.VmStockFlow{
  6175. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  6176. GoodId: good_yc.GoodId,
  6177. Number: warehouseOutInfos.Number,
  6178. LicenseNumber: stockInInfo.LicenseNumber,
  6179. Count: delete_count,
  6180. UserOrgId: orgID,
  6181. PatientId: patient_id,
  6182. SystemTime: record_time,
  6183. ConsumableType: 7,
  6184. IsSys: 0,
  6185. WarehousingOrder: "",
  6186. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  6187. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6188. IsEdit: 0,
  6189. CancelStockId: cancel.ID,
  6190. CancelOrderNumber: cancel.OrderNumber,
  6191. Manufacturer: manufacturer.ID,
  6192. Dealer: 0,
  6193. Creator: warehouseOut.Creater,
  6194. UpdateCreator: 0,
  6195. Status: 1,
  6196. Ctime: time.Now().Unix(),
  6197. Mtime: 0,
  6198. Price: stockInInfo.Price,
  6199. WarehousingDetailId: stockInInfo.ID,
  6200. WarehouseOutDetailId: warehouseOutInfos.ID,
  6201. CancelOutDetailId: cancelInfo.ID,
  6202. ProductDate: stockInInfo.ProductDate,
  6203. ExpireDate: stockInInfo.ExpiryDate,
  6204. StorehouseId: houseConfig.StorehouseOutInfo,
  6205. OverCount: sum_count,
  6206. }
  6207. service.CreateStockFlowOne(flow)
  6208. //更改自动出库的表格
  6209. details := models.BloodAutomaticReduceDetail{
  6210. WarehouseOutId: warehouseOutInfo.ID,
  6211. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6212. PatientId: patient_id,
  6213. Ctime: time.Now().Unix(),
  6214. Mtime: time.Now().Unix(),
  6215. Status: 1,
  6216. RecordTime: record_time,
  6217. OrgId: orgID,
  6218. GoodId: good_yc.GoodId,
  6219. GoodTypeId: good_yc.GoodTypeId,
  6220. Count: count,
  6221. StorehouseId: houseConfig.StorehouseOutInfo,
  6222. }
  6223. //查询当天耗材是否已经存在数据
  6224. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6225. if errcode == gorm.ErrRecordNotFound {
  6226. errTwo := service.CreateAutoReduceRecord(&details)
  6227. if errTwo != nil {
  6228. return errTwo
  6229. }
  6230. } else if errcode == nil {
  6231. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6232. service.CreateAutoReduceRecord(&details)
  6233. }
  6234. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  6235. //增加出库库存数量
  6236. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  6237. if good_yc.Count == 0 {
  6238. return nil
  6239. } else {
  6240. return errors.New("退库和出库数据不匹配")
  6241. }
  6242. }
  6243. func (this *DialysisAPIController) SavePatientSign() {
  6244. adminUserInfo := this.GetMobileAdminUserInfo()
  6245. patient_id, _ := this.GetInt64("patient_id")
  6246. dialysis_date, _ := this.GetInt64("dialysis_date")
  6247. orgid := adminUserInfo.Org.Id
  6248. var esdata models.DialysisOrder
  6249. var err error
  6250. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  6251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6252. return
  6253. }
  6254. esdata.Hash = esdata.Hash
  6255. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  6256. order := models.DialysisOrder{
  6257. Hash: esdata.Hash,
  6258. Url: esdata.Url,
  6259. }
  6260. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  6261. redis := service.RedisClient()
  6262. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  6263. redis.Set(key, "", time.Second)
  6264. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  6265. //清空key 值
  6266. redis.Set(keyOne, "", time.Second)
  6267. //scheduleDateStartOne := startDate.Format("2006-01-02")
  6268. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6269. //redis.Set(keyTwo, "", time.Second)
  6270. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  6271. redis.Set(keyThree, "", time.Second)
  6272. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  6273. redis.Set(keyFour, "", time.Second)
  6274. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  6275. redis.Set(keyFive, "", time.Second)
  6276. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  6277. redis.Set(keySix, "", time.Second)
  6278. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  6279. redis.Set(keySeven, "", time.Second)
  6280. if err != nil {
  6281. fmt.Println(err)
  6282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6283. return
  6284. }
  6285. this.ServeSuccessJSON(map[string]interface{}{
  6286. "electronic_signature": esdata,
  6287. })
  6288. }
  6289. func (this *DialysisAPIController) GetPatientSign() {
  6290. patient_id, _ := this.GetInt64("patient_id")
  6291. dialysis_date, _ := this.GetInt64("dialysis_date")
  6292. adminUserInfo := this.GetMobileAdminUserInfo()
  6293. orgId := adminUserInfo.Org.Id
  6294. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  6295. if err != nil {
  6296. fmt.Println(err)
  6297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6298. return
  6299. }
  6300. this.ServeSuccessJSON(map[string]interface{}{
  6301. "dialysisOrder": dialysisOrder,
  6302. })
  6303. }
  6304. func (this *DialysisAPIController) GetScheduleByPatient() {
  6305. patient_id, _ := this.GetInt64("patient_id")
  6306. schedule_date, _ := this.GetInt64("schedule_date")
  6307. orgid := this.GetMobileAdminUserInfo().Org.Id
  6308. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  6309. this.ServeSuccessJSON(map[string]interface{}{
  6310. "schedule": schedule,
  6311. })
  6312. }
  6313. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  6314. org_id := this.GetMobileAdminUserInfo().Org.Id
  6315. patient_id, _ := this.GetInt64("patient_id")
  6316. schedule_date, _ := this.GetInt64("schedule_date")
  6317. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  6318. this.ServeSuccessJSON(map[string]interface{}{
  6319. "order": order,
  6320. })
  6321. }
  6322. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  6323. org_id := this.GetMobileAdminUserInfo().Org.Id
  6324. schedule_date := this.GetString("schedule_date")
  6325. schedule_type, _ := this.GetInt64("schedule_type")
  6326. timeLayout := "2006-01-02"
  6327. loc, _ := time.LoadLocation("Local")
  6328. var startdateunix int64
  6329. if len(schedule_date) > 0 {
  6330. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  6331. if err != nil {
  6332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6333. return
  6334. }
  6335. startdateunix = theTime.Unix()
  6336. }
  6337. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  6338. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  6339. devices, _ := service.GetAllDevicetByListSix(org_id)
  6340. for key, item := range scheduals {
  6341. // 床位信息
  6342. for _, device := range devices {
  6343. if item.BedId == device.ID {
  6344. scheduals[key].DeviceNumber = device
  6345. break
  6346. }
  6347. }
  6348. }
  6349. this.ServeSuccessJSON(map[string]interface{}{
  6350. "list": list,
  6351. "scheduals": scheduals,
  6352. })
  6353. }
  6354. func (this *DialysisAPIController) SavePatientPicture() {
  6355. patient_id, _ := this.GetInt64("patient_id")
  6356. dialysis_date, _ := this.GetInt64("schedule_date")
  6357. avatar := this.GetString("avatar")
  6358. fmt.Println("patient_id", patient_id)
  6359. orgId := this.GetMobileAdminUserInfo().Org.Id
  6360. order := models.DialysisOrder{
  6361. Url: avatar,
  6362. }
  6363. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  6364. redis := service.RedisClient()
  6365. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  6366. redis.Set(key, "", time.Second)
  6367. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  6368. //清空key 值
  6369. redis.Set(keyOne, "", time.Second)
  6370. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  6371. redis.Set(keyThree, "", time.Second)
  6372. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  6373. redis.Set(keyFour, "", time.Second)
  6374. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  6375. redis.Set(keyFive, "", time.Second)
  6376. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  6377. redis.Set(keySix, "", time.Second)
  6378. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  6379. redis.Set(keySeven, "", time.Second)
  6380. if err != nil {
  6381. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6382. return
  6383. }
  6384. this.ServeSuccessJSON(map[string]interface{}{
  6385. "order": order,
  6386. })
  6387. }
  6388. func (this *DialysisAPIController) ExectionMobileAdvice() {
  6389. ids := this.GetString("ids")
  6390. idSplit := strings.Split(ids, ",")
  6391. orgId := this.GetMobileAdminUserInfo().Org.Id
  6392. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6393. execution_time := this.GetString("exce_time")
  6394. timeLayout2 := "2006-01-02 15:04:05"
  6395. loc, _ := time.LoadLocation("Local")
  6396. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  6397. if errs != nil {
  6398. utils.ErrorLog(errs.Error())
  6399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6400. return
  6401. }
  6402. //his客户
  6403. if config.IsOpen == 1 {
  6404. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  6405. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  6406. for _, item := range list {
  6407. for _, it := range adviceList {
  6408. if item.DrugId == it.DrugId {
  6409. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6410. }
  6411. }
  6412. }
  6413. for _, item := range list {
  6414. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6415. var sum_out_count int64
  6416. for _, itemThree := range item.ChildDoctorAdvice {
  6417. var prescribing_number int64
  6418. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6419. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6420. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6421. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6422. }
  6423. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6424. prescribing_number = parseIntPrescribingNumber
  6425. }
  6426. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6427. prescribing_number = parseIntPrescribingNumber
  6428. }
  6429. sum_out_count += prescribing_number
  6430. }
  6431. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6432. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6433. //库存不足
  6434. if sum_out_count > drugStockOut.FlushCount {
  6435. this.ServeSuccessJSON(map[string]interface{}{
  6436. "msg": "2",
  6437. "drug": medical,
  6438. "ids": ids,
  6439. })
  6440. return
  6441. }
  6442. }
  6443. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6444. //执行医嘱
  6445. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6446. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  6447. for _, item := range advices {
  6448. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6449. redis := service.RedisClient()
  6450. //清空key 值
  6451. redis.Set(key, "", time.Second)
  6452. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6453. redis.Set(keyTwo, "", time.Second)
  6454. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6455. redis.Set(keyThree, "", time.Second)
  6456. recordDate := theTime.Format("2006-01-02")
  6457. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6458. redis.Set(keyFour, "", time.Second)
  6459. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6460. redis.Set(keyFive, "", time.Second)
  6461. defer redis.Close()
  6462. }
  6463. if errs == nil {
  6464. //药品管理信息
  6465. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  6466. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6467. if drugStockConfig.IsOpen == 1 {
  6468. for _, item := range advices {
  6469. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  6470. config, _ := service.GetDrugOpenConfigOne(orgId)
  6471. if config.IsOpen != 1 {
  6472. //查询该药品是否有库存
  6473. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6474. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  6475. if medical.IsUse == 2 {
  6476. if config.IsOpen != 1 {
  6477. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6478. service.HisDrugsDelivery(orgId, creater, &advice)
  6479. }
  6480. if pharmacyConfig.IsOpen != 1 {
  6481. service.HisDrugsDelivery(orgId, creater, &advice)
  6482. }
  6483. //更新字典里面的库存
  6484. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6485. var sum_count int64
  6486. for _, its := range stockInfo {
  6487. if its.MaxUnit == medical.MaxUnit {
  6488. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6489. }
  6490. sum_count += its.StockMaxNumber + its.StockMinNumber
  6491. }
  6492. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6493. //剩余库存
  6494. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6495. }
  6496. }
  6497. }
  6498. }
  6499. }
  6500. this.ServeSuccessJSON(map[string]interface{}{
  6501. "msg": "1",
  6502. "ids": ids,
  6503. })
  6504. return
  6505. } else {
  6506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6507. }
  6508. }
  6509. fmt.Println("config233322333223", config.IsOpen)
  6510. //血透客户
  6511. if config.IsOpen == 2 || config.IsOpen == 0 {
  6512. //药品管理信息
  6513. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  6514. if drugStockConfig.IsOpen == 1 {
  6515. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  6516. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  6517. for _, item := range list {
  6518. for _, it := range adviceList {
  6519. if item.DrugId == it.DrugId {
  6520. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6521. }
  6522. }
  6523. }
  6524. for _, item := range list {
  6525. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6526. var sum_out_count int64
  6527. for _, itemThree := range item.ChildDoctorAdvice {
  6528. var prescribing_number int64
  6529. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6530. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6531. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6532. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6533. }
  6534. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6535. prescribing_number = parseIntPrescribingNumber
  6536. }
  6537. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6538. prescribing_number = parseIntPrescribingNumber
  6539. }
  6540. sum_out_count += prescribing_number
  6541. }
  6542. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6543. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6544. //库存不足
  6545. if sum_out_count > drugStockOut.FlushCount {
  6546. this.ServeSuccessJSON(map[string]interface{}{
  6547. "msg": "2",
  6548. "drug": medical,
  6549. "ids": ids,
  6550. })
  6551. return
  6552. }
  6553. }
  6554. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6555. fmt.Println("creater2332243244224242424", creater)
  6556. //执行医嘱
  6557. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6558. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  6559. for _, item := range advices {
  6560. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6561. redis := service.RedisClient()
  6562. //清空key 值
  6563. redis.Set(key, "", time.Second)
  6564. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6565. redis.Set(keyTwo, "", time.Second)
  6566. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6567. redis.Set(keyThree, "", time.Second)
  6568. recordDate := theTime.Format("2006-01-02")
  6569. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6570. redis.Set(keyFour, "", time.Second)
  6571. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6572. redis.Set(keyFive, "", time.Second)
  6573. defer redis.Close()
  6574. }
  6575. if errs == nil {
  6576. for _, item := range advices {
  6577. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6578. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6579. //查询是否出库按钮开启
  6580. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  6581. if adviceSetting.IsAdviceOpen == 1 {
  6582. //查询是否出库按钮开启
  6583. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  6584. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  6585. if prescriptionConfig.IsOpen == 1 {
  6586. if medical.IsUse == 2 {
  6587. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6588. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6589. }
  6590. if pharmacyConfig.IsOpen != 1 {
  6591. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6592. }
  6593. //更新字典里面的库存
  6594. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6595. var sum_count int64
  6596. for _, its := range stockInfo {
  6597. if its.MaxUnit == medical.MaxUnit {
  6598. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6599. }
  6600. sum_count += its.StockMaxNumber + its.StockMinNumber
  6601. }
  6602. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6603. //剩余库存
  6604. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6605. }
  6606. }
  6607. } else {
  6608. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  6609. if medical.IsUse == 2 {
  6610. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6611. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6612. }
  6613. if pharmacyConfig.IsOpen != 1 {
  6614. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6615. }
  6616. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6617. var sum_count int64
  6618. for _, its := range stockInfo {
  6619. if its.MaxUnit == medical.MaxUnit {
  6620. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6621. }
  6622. sum_count += its.StockMaxNumber + its.StockMinNumber
  6623. }
  6624. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6625. //剩余库存
  6626. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6627. }
  6628. }
  6629. }
  6630. }
  6631. this.ServeSuccessJSON(map[string]interface{}{
  6632. "msg": "1",
  6633. "ids": ids,
  6634. })
  6635. return
  6636. } else {
  6637. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6638. //执行医嘱
  6639. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6640. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  6641. for _, item := range advices {
  6642. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6643. redis := service.RedisClient()
  6644. //清空key 值
  6645. redis.Set(key, "", time.Second)
  6646. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6647. redis.Set(keyTwo, "", time.Second)
  6648. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6649. redis.Set(keyThree, "", time.Second)
  6650. recordDate := theTime.Format("2006-01-02")
  6651. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6652. redis.Set(keyFour, "", time.Second)
  6653. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6654. redis.Set(keyFive, "", time.Second)
  6655. defer redis.Close()
  6656. }
  6657. this.ServeSuccessJSON(map[string]interface{}{
  6658. "msg": "1",
  6659. "ids": ids,
  6660. })
  6661. return
  6662. }
  6663. }
  6664. }
  6665. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  6666. ids := this.GetString("ids")
  6667. idSplit := strings.Split(ids, ",")
  6668. orgId := this.GetMobileAdminUserInfo().Org.Id
  6669. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6670. if config.IsOpen == 1 {
  6671. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  6672. this.ServeSuccessJSON(map[string]interface{}{
  6673. "msg": "1",
  6674. "ids": ids,
  6675. })
  6676. return
  6677. }
  6678. if config.IsOpen == 0 || config.IsOpen == 2 {
  6679. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  6680. this.ServeSuccessJSON(map[string]interface{}{
  6681. "msg": "1",
  6682. "ids": ids,
  6683. })
  6684. return
  6685. }
  6686. }
  6687. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  6688. ids := this.GetString("ids")
  6689. idSplit := strings.Split(ids, ",")
  6690. orgId := this.GetMobileAdminUserInfo().Org.Id
  6691. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6692. //his
  6693. if config.IsOpen == 1 {
  6694. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  6695. theTime := time.Now()
  6696. advices := models.HisDoctorAdviceThirty{
  6697. CheckTime: theTime.Unix(),
  6698. Checker: checker,
  6699. UpdatedTime: time.Now().Unix(),
  6700. }
  6701. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  6702. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  6703. for _, item := range list {
  6704. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6705. redis := service.RedisClient()
  6706. //清空key 值
  6707. redis.Set(key, "", time.Second)
  6708. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6709. redis.Set(keyTwo, "", time.Second)
  6710. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6711. redis.Set(keyThree, "", time.Second)
  6712. recordDate := theTime.Format("2006-01-02")
  6713. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6714. redis.Set(keyFour, "", time.Second)
  6715. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6716. redis.Set(keyFive, "", time.Second)
  6717. defer redis.Close()
  6718. }
  6719. this.ServeSuccessJSON(map[string]interface{}{
  6720. "msg": "1",
  6721. "ids": ids,
  6722. })
  6723. return
  6724. }
  6725. //血透
  6726. if config.IsOpen == 0 || config.IsOpen == 2 {
  6727. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  6728. theTime := time.Now()
  6729. advices := models.DoctorAdvice{
  6730. CheckTime: theTime.Unix(),
  6731. Checker: checker,
  6732. UpdatedTime: time.Now().Unix(),
  6733. }
  6734. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  6735. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  6736. for _, item := range list {
  6737. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6738. redis := service.RedisClient()
  6739. //清空key 值
  6740. redis.Set(key, "", time.Second)
  6741. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6742. redis.Set(keyTwo, "", time.Second)
  6743. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6744. redis.Set(keyThree, "", time.Second)
  6745. recordDate := theTime.Format("2006-01-02")
  6746. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6747. redis.Set(keyFour, "", time.Second)
  6748. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6749. redis.Set(keyFive, "", time.Second)
  6750. defer redis.Close()
  6751. }
  6752. this.ServeSuccessJSON(map[string]interface{}{
  6753. "msg": "1",
  6754. "ids": ids,
  6755. })
  6756. return
  6757. }
  6758. }
  6759. func (this *DialysisAPIController) CheckSchedule() {
  6760. patientID, _ := this.GetInt64("patient_id")
  6761. recordDateStr := this.GetString("record_date")
  6762. nurseID, _ := this.GetInt64("nurse")
  6763. schedual_type, _ := this.GetInt64("schedual_type")
  6764. bedID, _ := this.GetInt64("bed")
  6765. start_time := this.GetString("start_time")
  6766. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  6767. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6768. return
  6769. }
  6770. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  6771. if parseStartDateErr != nil {
  6772. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  6773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6774. return
  6775. }
  6776. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6777. if parseErr != nil {
  6778. this.ErrorLog("时间解析失败:%v", parseErr)
  6779. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6780. return
  6781. }
  6782. adminUserInfo := this.GetMobileAdminUserInfo()
  6783. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  6784. if getPatientErr != nil {
  6785. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  6786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6787. return
  6788. } else if patient == nil {
  6789. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6790. return
  6791. }
  6792. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  6793. if getNurseErr != nil {
  6794. this.ErrorLog("获取护士失败:%v", getNurseErr)
  6795. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6796. return
  6797. } else if nurse == nil {
  6798. this.ErrorLog("护士不存在")
  6799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6800. return
  6801. }
  6802. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  6803. if getDeviceNumberErr != nil {
  6804. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  6805. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6806. return
  6807. } else if deviceNumber == nil {
  6808. this.ErrorLog("床位号不存在")
  6809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6810. return
  6811. }
  6812. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  6813. if getRecordErr != nil {
  6814. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  6815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6816. return
  6817. } else if dialysisRecord != nil {
  6818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  6819. return
  6820. }
  6821. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  6822. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  6823. timeLayout := "2006-01-02 15:04:05"
  6824. loc, _ := time.LoadLocation("Local")
  6825. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  6826. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  6827. schedulestartTime := theStartTime.Unix()
  6828. scheduleendTime := theEndTime.Unix()
  6829. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  6830. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  6831. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  6832. //查询该床位是否有人用了
  6833. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  6834. if err == nil {
  6835. if schedule.ID == 0 {
  6836. this.ServeSuccessJSON(map[string]interface{}{
  6837. "status": 0,
  6838. "msg": "请求失败",
  6839. })
  6840. } else {
  6841. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  6842. if order.ID > 0 { //该机位被其他人占用了
  6843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  6844. return
  6845. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  6846. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  6847. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  6848. this.ServeSuccessJSON(map[string]interface{}{
  6849. "status": 1,
  6850. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  6851. })
  6852. return
  6853. } else {
  6854. this.ServeSuccessJSON(map[string]interface{}{
  6855. "status": 0,
  6856. "msg": "",
  6857. })
  6858. }
  6859. }
  6860. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  6861. this.ServeSuccessJSON(map[string]interface{}{
  6862. "status": 2,
  6863. "msg": "当前机位已有患者在使用,请重新选择!",
  6864. })
  6865. }
  6866. }
  6867. } else {
  6868. this.ServeSuccessJSON(map[string]interface{}{
  6869. "status": 0,
  6870. "msg": "",
  6871. })
  6872. }
  6873. }