dialysis_api_controller.go 426KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. fmt.Print("projectOne------------------------", projectsOne)
  468. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  469. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  470. var team_projects []*models.HisPrescriptionProject
  471. //var index int64 = 0
  472. for _, item := range temp_team_projects {
  473. //组套里面非检验项目的
  474. if item.HisProject.CostClassify != 3 {
  475. projects = append(projects, item)
  476. }
  477. //组套里面检验项目的
  478. if item.HisProject.CostClassify == 3 {
  479. team_projects = append(team_projects, item)
  480. }
  481. }
  482. //针对茂名舒和
  483. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  484. if len(projects) > 0 {
  485. for _, item := range projects {
  486. if item.Type == 2 {
  487. if item.HisProject.IsShow == 1 {
  488. projectsOne = append(projectsOne, item)
  489. }
  490. }
  491. if item.Type == 3 {
  492. if item.GoodInfo.IsShow == 1 {
  493. projectsOne = append(projectsOne, item)
  494. }
  495. }
  496. }
  497. }
  498. } else {
  499. for _, item := range projects {
  500. projectsOne = append(projectsOne, item)
  501. }
  502. }
  503. team_projects = RemoveRepeatedCheckRecod(team_projects)
  504. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  505. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  506. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  507. var his_advices []*models.HisDoctorAdviceInfo
  508. var his_advices_one []*models.HisDoctorAdviceInfo
  509. if is_open_config.IsOpen == 1 {
  510. // 先走redis,没有走数据库
  511. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  512. }
  513. //针对茂名舒和
  514. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  515. if len(his_advices) > 0 {
  516. for _, item := range his_advices {
  517. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  518. if drug.IsShow == 1 {
  519. his_advices_one = append(his_advices_one, item)
  520. }
  521. }
  522. }
  523. } else {
  524. if len(his_advices) > 0 {
  525. for _, item := range his_advices {
  526. his_advices_one = append(his_advices_one, item)
  527. }
  528. }
  529. }
  530. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  531. if is_advice_open.IsAdviceOpen == 1 {
  532. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  533. }
  534. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  535. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  536. var remind_lists []models.XtCheckRemind
  537. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  538. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  539. }
  540. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  541. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  542. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  543. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  544. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  545. returnData := map[string]interface{}{
  546. "patient": patient,
  547. "schedual": schedual,
  548. "prescription": dialysisPrescribe,
  549. "solution": dialysisSolution,
  550. "last_prescription": lastDialysisPrescribe,
  551. "receiver_treatment_access": receiverTreatmentAccess,
  552. "predialysis_evaluation": predialysisEvaluation,
  553. "doctor_advices": doctorAdvices,
  554. "double_check": doubleCheck,
  555. "assessment_after_dislysis": assessmentAfterDislysis,
  556. "treatment_summary": treatmentSummary,
  557. "monitor_records": monitorRecords,
  558. "dialysis_order": dialysisOrder,
  559. "operators": operators,
  560. "last_predialysis_evaluation": lastPredialysisEvaluation,
  561. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  562. "last_monitor_record": lastMonitorRecord,
  563. "config": gobalConfig,
  564. "dry_weight": lastDryWeightDislysis,
  565. "system_prescription": systemDialysisPrescribe,
  566. "his_advices": his_advices_one,
  567. "is_open_config": is_open_config,
  568. "stockType": stockType,
  569. "prepare": prepare,
  570. "lastAssessment": lastAssessment,
  571. "prescribeOne": prescribeOne,
  572. "is_project_open_config": is_project_open_config,
  573. "project": projectsOne,
  574. "team_projects": team_projects,
  575. "is_advice_open": is_advice_open,
  576. "prescription_open": prescriptionConfig.IsOpen,
  577. "lastOrder": lastOrder,
  578. "remind_lists": remind_lists,
  579. "lastDialysisPrescription": lastDialysisPrescription,
  580. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  581. "dryWeightList": dryWeightList,
  582. "firstMonitor": firstMonitor,
  583. "lastMonitor": lastMonitor,
  584. }
  585. this.ServeSuccessJSON(returnData)
  586. }
  587. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  588. adminInfo := c.GetMobileAdminUserInfo()
  589. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  590. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  591. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  592. returnData := map[string]interface{}{
  593. "admin_users": adminUsers,
  594. "devices": devices,
  595. "device_numbers": device_numbers,
  596. }
  597. c.ServeSuccessJSON(returnData)
  598. }
  599. func (c *DialysisAPIController) PostAtreatmentInfo() {
  600. id, _ := c.GetInt64("patient", 0)
  601. recordDateStr := c.GetString("record_date")
  602. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  603. summaryContent := c.GetString("summaryContent")
  604. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  605. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  606. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  607. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  608. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  609. nursingRecord := c.GetString("nursing_record")
  610. fmt.Println("护理记录", nursingRecord)
  611. specialRecord := c.GetString("special_record")
  612. fmt.Println("特殊记录", specialRecord)
  613. adminUserInfo := c.GetMobileAdminUserInfo()
  614. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  615. checkStaffId = adminUserInfo.AdminUser.Id
  616. deboardNurseId = adminUserInfo.AdminUser.Id
  617. treatDoctor = adminUserInfo.AdminUser.Id
  618. if id <= 0 {
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  620. return
  621. }
  622. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  623. if patient.ID == 0 {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  625. return
  626. }
  627. if len(recordDateStr) == 0 {
  628. recordDateStr = time.Now().Format("2006-01-02")
  629. }
  630. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  631. if parseDateErr != nil {
  632. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  634. return
  635. }
  636. summary := models.TreatmentSummary{
  637. UserOrgId: adminUserInfo.Org.Id,
  638. PatientId: id,
  639. AssessmentDate: recordDate.Unix(),
  640. Mission: propagandaAndEducationContent,
  641. DialysisSummary: summaryContent,
  642. SjNurse: changeMedicalNurseId,
  643. ZlNurse: treatNurseId,
  644. HdNurse: checkStaffId,
  645. XjNurse: deboardNurseId,
  646. ZlDoctor: treatDoctor,
  647. CreatedTime: time.Now().Unix(),
  648. Status: 1,
  649. NursingRecord: nursingRecord,
  650. SpecialRecord: specialRecord,
  651. }
  652. // 查询信息规挡的设置天数
  653. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  654. if infor.ID > 0 && infor.WeekDay > 0 {
  655. var cha_time int64
  656. timeNowStr := time.Now().Format("2006-01-02")
  657. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  658. //今日的日期减去设置的日期
  659. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  660. if cha_time >= recordDate.Unix() {
  661. //查询审核是否允许
  662. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  663. //申请状态不允许的情况 拒绝修改
  664. if infor.ApplicationStatus != 1 {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  666. return
  667. }
  668. }
  669. }
  670. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  671. if treatmentSummary.ID == 0 { //新增
  672. summary.Creater = adminUserInfo.AdminUser.Id
  673. service.AddSigleSummaryRecord(&summary)
  674. finish := models.XtDialysisFinish{
  675. IsFinish: 1,
  676. UserOrgId: adminUserInfo.Org.Id,
  677. Status: 1,
  678. Ctime: time.Now().Unix(),
  679. Mtime: 0,
  680. Module: 10,
  681. RecordDate: recordDate.Unix(),
  682. Sourse: 1,
  683. PatientId: id,
  684. }
  685. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  686. if dialysisFinish.ID == 0 {
  687. service.CreateDialysisFinish(finish)
  688. }
  689. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  690. redis := service.RedisClient()
  691. //清空key 值
  692. redis.Set(key, "", time.Second)
  693. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  694. redis.Set(keyOne, "", time.Second)
  695. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  696. redis.Set(keyThree, "", time.Second)
  697. defer redis.Close()
  698. c.ServeSuccessJSON(map[string]interface{}{
  699. "summary": summary,
  700. })
  701. } else { //修改
  702. summary.Creater = treatmentSummary.Creater
  703. summary.CreatedTime = treatmentSummary.CreatedTime
  704. summary.Modifier = adminUserInfo.AdminUser.Id
  705. summary.ID = treatmentSummary.ID
  706. service.UpdateSummeRecord(&summary)
  707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  708. redis := service.RedisClient()
  709. //清空key 值
  710. redis.Set(key, "", time.Second)
  711. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  712. redis.Set(keyOne, "", time.Second)
  713. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  714. redis.Set(keyThree, "", time.Second)
  715. defer redis.Close()
  716. c.ServeSuccessJSON(map[string]interface{}{
  717. "summary": summary,
  718. })
  719. }
  720. }
  721. func (c *DialysisAPIController) PostDoubleCheck() {
  722. id, _ := c.GetInt64("patient", 0)
  723. recordDateStr := c.GetString("record_date")
  724. checkTimeStr := c.GetString("check_time")
  725. firstCheckTimeStr := c.GetString("first_check_time")
  726. creater, _ := c.GetInt64("creater", 0)
  727. modifier, _ := c.GetInt64("modifier", 0)
  728. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  729. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  730. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  731. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  732. dialysis_item_desc := c.GetString("dialysis_item_desc")
  733. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  734. vascular_access_desc := c.GetString("vascular_access_desc")
  735. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  736. collator, _ := c.GetInt64("collator", 0)
  737. employee_number := c.GetString("employee_number")
  738. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  739. needle_batch_number := c.GetString("needle_batch_number")
  740. if id <= 0 {
  741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  742. return
  743. }
  744. adminUserInfo := c.GetMobileAdminUserInfo()
  745. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  746. if patient.ID == 0 {
  747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  748. return
  749. }
  750. if len(recordDateStr) == 0 {
  751. recordDateStr = time.Now().Format("2006-01-02")
  752. }
  753. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  754. if parseDateErr != nil {
  755. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  757. return
  758. }
  759. var checkDate int64
  760. if len(checkTimeStr) == 0 {
  761. checkDate = 0
  762. } else {
  763. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  764. checkDate = checkDateUnix.Unix()
  765. }
  766. var firstCheckDate int64
  767. if len(firstCheckTimeStr) == 0 {
  768. firstCheckDate = 0
  769. } else {
  770. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  771. firstCheckDate = firstCheckDateUnix.Unix()
  772. }
  773. if adminUserInfo.Org.Id == 10644 {
  774. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  775. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  776. if check.ID == 0 {
  777. if employee_number != list.JobNumber {
  778. c.ServeSuccessJSON(map[string]interface{}{
  779. "doubleCheck": check,
  780. "msg": "2",
  781. })
  782. return
  783. }
  784. }
  785. if check.ID > 0 {
  786. if employee_number != list.JobNumber {
  787. c.ServeSuccessJSON(map[string]interface{}{
  788. "doubleCheck": check,
  789. "msg": "2",
  790. })
  791. return
  792. }
  793. }
  794. }
  795. doubleCheck := models.DoubleCheck{
  796. UserOrgId: adminUserInfo.Org.Id,
  797. PatientId: id,
  798. DialysisItemCheck: dialysis_item_check,
  799. DialysisParameterCheck: dialysis_parameter_check,
  800. VascularAccessVerification: vascular_access_verification,
  801. PipelineConnectionCheck: pipeline_connection_check,
  802. DialysisItemDesc: dialysis_item_desc,
  803. DialysisParameterDesc: dialysis_parameter_desc,
  804. VascularAccessDesc: vascular_access_desc,
  805. PipelineConnectionDesc: pipeline_connection_desc,
  806. Collator: collator,
  807. Status: 1,
  808. CreatedTime: time.Now().Unix(),
  809. CheckDate: recordDate.Unix(),
  810. UpdatedTime: time.Now().Unix(),
  811. EmployeeNumber: employee_number,
  812. DialyzerBatchNumber: dialyzer_batch_number,
  813. NeedleBatchNumber: needle_batch_number,
  814. }
  815. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  816. if check.ID == 0 { //新增
  817. doubleCheck.FirstCheckTime = firstCheckDate
  818. doubleCheck.CheckTime = checkDate
  819. doubleCheck.Creater = creater
  820. doubleCheck.Modifier = modifier
  821. if adminUserInfo.Org.Id == 10340 {
  822. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  823. doubleCheck.Creater = order.StartNurse
  824. }
  825. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  826. //查询未核对的医嘱
  827. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  828. for _, advice := range doctorList {
  829. if advice.ExecutionStaff == modifier {
  830. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  831. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  832. return
  833. }
  834. }
  835. }
  836. // 查询信息规挡的设置天数
  837. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  838. if infor.ID > 0 && infor.WeekDay > 0 {
  839. var cha_time int64
  840. timeNowStr := time.Now().Format("2006-01-02")
  841. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  842. //今日的日期减去设置的日期
  843. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  844. if cha_time >= recordDate.Unix() {
  845. //查询审核是否允许
  846. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  847. //申请状态不允许的情况 拒绝修改
  848. if infor.ApplicationStatus != 1 {
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  850. return
  851. }
  852. }
  853. }
  854. err := service.AddSigleDoubleCheck(&doubleCheck)
  855. finish := models.XtDialysisFinish{
  856. IsFinish: 1,
  857. UserOrgId: adminUserInfo.Org.Id,
  858. Status: 1,
  859. Ctime: time.Now().Unix(),
  860. Mtime: 0,
  861. Module: 5,
  862. RecordDate: recordDate.Unix(),
  863. Sourse: 1,
  864. PatientId: id,
  865. }
  866. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  867. if dialysisFinish.ID == 0 {
  868. service.CreateDialysisFinish(finish)
  869. }
  870. //针对长沙南雅
  871. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  872. //查询未核对的医嘱
  873. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  874. if len(doctorList) > 0 && modifier > 0 {
  875. for _, advice := range doctorList {
  876. service.UpdateDoctorAdviceList(advice.ID, modifier)
  877. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  878. redis := service.RedisClient()
  879. //清空key 值
  880. redis.Set(key, "", time.Second)
  881. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  882. redis.Set(keyTwo, "", time.Second)
  883. theTime := time.Now()
  884. recordDate := theTime.Format("2006-01-02")
  885. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  886. redis.Set(keyFour, "", time.Second)
  887. defer redis.Close()
  888. }
  889. }
  890. }
  891. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  892. redis := service.RedisClient()
  893. //清空key 值
  894. redis.Set(key, "", time.Second)
  895. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  896. redis.Set(keyOne, "", time.Second)
  897. defer redis.Close()
  898. if err == nil {
  899. c.ServeSuccessJSON(map[string]interface{}{
  900. "doubleCheck": &doubleCheck,
  901. })
  902. }
  903. } else { //修改
  904. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  905. if infor.ID > 0 {
  906. var cha_time int64
  907. timeNowStr := time.Now().Format("2006-01-02")
  908. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  909. //今日的日期减去设置的日期
  910. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  911. if cha_time >= recordDate.Unix() {
  912. //查询审核是否允许
  913. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  914. //申请状态不允许的情况 拒绝修改
  915. if infor.ApplicationStatus != 1 {
  916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  917. return
  918. }
  919. }
  920. }
  921. doubleCheck.FirstCheckTime = firstCheckDate
  922. doubleCheck.CheckTime = checkDate
  923. doubleCheck.Creater = creater
  924. doubleCheck.Modifier = modifier
  925. doubleCheck.CreatedTime = check.CreatedTime
  926. doubleCheck.ID = check.ID
  927. doubleCheck.EmployeeNumber = employee_number
  928. doubleCheck.NeedleBatchNumber = needle_batch_number
  929. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  930. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  931. //查询未核对的医嘱
  932. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  933. for _, advice := range doctorList {
  934. if advice.ExecutionStaff == modifier {
  935. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  936. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  937. return
  938. }
  939. }
  940. }
  941. err := service.UpdateDoubleCheck(&doubleCheck)
  942. //针对长沙南雅
  943. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  944. //查询未核对的医嘱
  945. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  946. if len(doctorList) > 0 && modifier > 0 {
  947. for _, advice := range doctorList {
  948. service.UpdateDoctorAdviceList(advice.ID, modifier)
  949. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  950. redis := service.RedisClient()
  951. //清空key 值
  952. redis.Set(key, "", time.Second)
  953. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  954. redis.Set(keyTwo, "", time.Second)
  955. theTime := time.Now()
  956. recordDate := theTime.Format("2006-01-02")
  957. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  958. redis.Set(keyFour, "", time.Second)
  959. defer redis.Close()
  960. }
  961. }
  962. }
  963. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  964. redis := service.RedisClient()
  965. //清空key 值
  966. redis.Set(key, "", time.Second)
  967. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  968. redis.Set(keyOne, "", time.Second)
  969. defer redis.Close()
  970. if err == nil {
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "doubleCheck": &doubleCheck,
  973. "msg": "1",
  974. })
  975. }
  976. }
  977. }
  978. func (c *DialysisAPIController) PostAcceptsAssessment() {
  979. id, _ := c.GetInt64("patient", 0)
  980. recordDateStr := c.GetString("record_date")
  981. way, _ := c.GetInt64("way", 0)
  982. consciousness, _ := c.GetInt64("consciousness", 0)
  983. appetite, _ := c.GetInt64("appetite", 0)
  984. condition, _ := c.GetInt64("condition", 0)
  985. posture, _ := c.GetInt64("posture")
  986. sick_condition, _ := c.GetInt64("sick_condition", 0)
  987. danger_level, _ := c.GetInt64("danger_level", 0)
  988. intake, _ := c.GetInt64("intake", 0)
  989. nutrition, _ := c.GetInt64("nutrition", 0)
  990. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  991. psychological_assessment_other := c.GetString("psychological_assessment_other")
  992. score := c.GetString("score")
  993. sick_condition_other := c.GetString("sick_condition_other")
  994. //precaution, _ := c.GetInt64("precaution", 0)
  995. precaution := c.GetString("precaution")
  996. precaution_other := c.GetString("precaution_other")
  997. psychological_other := c.GetString("psychological_other")
  998. admission_number := c.GetString("admission_number")
  999. tumble, _ := c.GetInt64("tumble")
  1000. diacrisis := c.GetString("diacrisis")
  1001. his_department := c.GetString("his_department")
  1002. his_bed := c.GetString("his_bed")
  1003. if id <= 0 {
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1005. return
  1006. }
  1007. adminUserInfo := c.GetMobileAdminUserInfo()
  1008. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1009. if patient.ID == 0 {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1011. return
  1012. }
  1013. //now := time.Now()
  1014. //year, month, day := now.Date()
  1015. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1016. //todayTimeStamp := today_time.Unix()
  1017. if len(recordDateStr) == 0 {
  1018. recordDateStr = time.Now().Format("2006-01-02")
  1019. }
  1020. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1021. if parseDateErr != nil {
  1022. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. // 查询信息规挡的设置天数
  1027. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1028. if infor.ID > 0 && infor.WeekDay > 0 {
  1029. var cha_time int64
  1030. timeNowStr := time.Now().Format("2006-01-02")
  1031. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1032. //今日的日期减去设置的日期
  1033. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1034. if cha_time >= recordDate.Unix() {
  1035. //查询审核是否允许
  1036. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1037. //申请状态不允许的情况 拒绝修改
  1038. if infor.ApplicationStatus != 1 {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1040. return
  1041. }
  1042. }
  1043. }
  1044. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1045. if adminUserInfo.Org.Id == 10340 {
  1046. if condition == 1 {
  1047. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1048. if admission_number == "" {
  1049. admission_number = lastAcceptTreatment.AdmissionNumber
  1050. }
  1051. }
  1052. }
  1053. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1054. UserOrgId: adminUserInfo.Org.Id,
  1055. PatientId: id,
  1056. RecordDate: recordDate.Unix(),
  1057. Way: way,
  1058. Consciousness: consciousness,
  1059. Appetite: appetite,
  1060. Condition: condition,
  1061. SickCondition: sick_condition,
  1062. DangerLevel: danger_level,
  1063. Intake: intake,
  1064. Nutrition: nutrition,
  1065. PsychologicalAssessment: psychological_assessment,
  1066. PsychologicalAssessmentOther: psychological_assessment_other,
  1067. SickConditionOther: sick_condition_other,
  1068. Posture: posture,
  1069. CreatedTime: time.Now().Unix(),
  1070. UpdateTime: time.Now().Unix(),
  1071. Status: 1,
  1072. Score: score,
  1073. Precaution: precaution,
  1074. PrecautionOther: precaution_other,
  1075. PsychologicalOther: psychological_other,
  1076. AdmissionNumber: admission_number,
  1077. Tumble: tumble,
  1078. Diacrisis: diacrisis,
  1079. HisBed: his_bed,
  1080. HisDepartment: his_department,
  1081. }
  1082. if receiveTreatment.ID == 0 { //新增
  1083. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1084. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1085. finish := models.XtDialysisFinish{
  1086. IsFinish: 1,
  1087. UserOrgId: adminUserInfo.Org.Id,
  1088. Status: 1,
  1089. Ctime: time.Now().Unix(),
  1090. Mtime: 0,
  1091. Module: 2,
  1092. RecordDate: recordDate.Unix(),
  1093. Sourse: 1,
  1094. PatientId: id,
  1095. }
  1096. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1097. if dialysisFinish.ID == 0 {
  1098. service.CreateDialysisFinish(finish)
  1099. }
  1100. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1101. redis := service.RedisClient()
  1102. defer redis.Close()
  1103. //清空key 值
  1104. redis.Set(key, "", time.Second)
  1105. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1106. redis.Set(keyOne, "", time.Second)
  1107. if err == nil {
  1108. c.ServeSuccessJSON(map[string]interface{}{
  1109. "receiveTreatmentAsses": receiveTreatmentAsses,
  1110. })
  1111. }
  1112. } else { //修改
  1113. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1114. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1115. // if getPermissionErr != nil {
  1116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1117. // return
  1118. // } else if headNursePermission == nil {
  1119. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1120. // return
  1121. // }
  1122. //}
  1123. // 查询信息规挡的设置天数
  1124. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1125. if infor.ID > 0 && infor.WeekDay > 0 {
  1126. var cha_time int64
  1127. timeNowStr := time.Now().Format("2006-01-02")
  1128. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1129. //今日的日期减去设置的日期
  1130. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1131. if cha_time >= recordDate.Unix() {
  1132. //查询审核是否允许
  1133. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1134. //申请状态不允许的情况 拒绝修改
  1135. if infor.ApplicationStatus != 1 {
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1137. return
  1138. }
  1139. }
  1140. }
  1141. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1142. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1143. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1144. receiveTreatmentAsses.ID = receiveTreatment.ID
  1145. if adminUserInfo.Org.Id == 10340 {
  1146. if condition == 1 {
  1147. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1148. if receiveTreatmentAsses.AdmissionNumber == "" {
  1149. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1150. }
  1151. }
  1152. }
  1153. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1154. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1155. redis := service.RedisClient()
  1156. defer redis.Close()
  1157. //清空key 值
  1158. redis.Set(key, "", time.Second)
  1159. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1160. redis.Set(keyOne, "", time.Second)
  1161. if err == nil {
  1162. c.ServeSuccessJSON(map[string]interface{}{
  1163. "receiveTreatmentAsses": receiveTreatmentAsses,
  1164. })
  1165. }
  1166. }
  1167. }
  1168. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1169. id, _ := c.GetInt64("patient", 0)
  1170. recordDateStr := c.GetString("record_date")
  1171. weightAfter, _ := c.GetFloat("weight_after", 0)
  1172. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1173. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1174. fmt.Println("weight_loss", weightReduce)
  1175. temperature, _ := c.GetFloat("temperature", 0)
  1176. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1177. breathing_rate := c.GetString("breathing_rate")
  1178. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1179. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1180. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1181. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1182. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1183. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1184. cruor := c.GetString("cruor")
  1185. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1186. internalFistula := c.GetString("internal_fistula")
  1187. catheter := c.GetString("catheter")
  1188. complications := c.GetString("complication")
  1189. remark := c.GetString("remark")
  1190. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1191. dialysis_intakes := c.GetString("dialysis_intakes")
  1192. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1193. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1194. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1195. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1196. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1197. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1198. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1199. patientGose, _ := c.GetInt64("patient_gose", 0)
  1200. inpatientDepartment := c.GetString("inpatient_department")
  1201. observationContent := c.GetString("observation_content")
  1202. observationContentOther := c.GetString("observation_content_other")
  1203. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1204. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1205. in_advance_reason := c.GetString("in_advance_reason")
  1206. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1207. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1208. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1209. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1210. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1211. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1212. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1213. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1214. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1215. is_eat, _ := c.GetInt64("is_eat", 0)
  1216. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1217. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1218. channels, _ := c.GetInt64("channel", 0)
  1219. return_blood, _ := c.GetInt64("return_blood", 0)
  1220. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1221. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1222. dialysis_during, _ := c.GetFloat("dialysis_during")
  1223. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1224. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1225. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1226. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1227. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1228. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1229. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1230. setting_pressure := c.GetString("setting_pressure")
  1231. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1232. diastolic_pressure := c.GetString("diastolic_pressure")
  1233. other_complication := c.GetString("other_complication")
  1234. ktv := c.GetString("ktv")
  1235. urr := c.GetString("urr")
  1236. hypertenison, _ := c.GetInt64("hypertenison")
  1237. hypopiesia, _ := c.GetInt64("hypopiesia")
  1238. leave_office_method, _ := c.GetInt64("leave_office_method")
  1239. lapse, _ := c.GetInt64("lapse")
  1240. consciousness, _ := c.GetInt64("consciousness")
  1241. fallrisk, _ := c.GetInt64("fallrisk")
  1242. machine_run := c.GetString("machine_run")
  1243. after_urea := c.GetString("after_urea")
  1244. pip_coagulation := c.GetString("pip_coagulation")
  1245. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1246. transfusion_volume := c.GetString("transfusion_volume")
  1247. last_after_weight := c.GetString("last_after_weight")
  1248. displace_liqui_value := c.GetString("displace_liqui_value")
  1249. if id <= 0 {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1251. return
  1252. }
  1253. adminUserInfo := c.GetMobileAdminUserInfo()
  1254. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1255. if patient.ID == 0 {
  1256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1257. return
  1258. }
  1259. if len(recordDateStr) == 0 {
  1260. recordDateStr = time.Now().Format("2006-01-02")
  1261. }
  1262. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1263. fmt.Println("parseDateErr", parseDateErr)
  1264. if parseDateErr != nil {
  1265. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1267. return
  1268. }
  1269. //now := time.Now()
  1270. //year, month, day := now.Date()
  1271. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1272. //todayTimeStamp := today_time.Unix()
  1273. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1274. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1275. UserOrgId: adminUserInfo.Org.Id,
  1276. PatientId: id,
  1277. AssessmentDate: recordDate.Unix(),
  1278. Temperature: temperature,
  1279. PulseFrequency: pulse_frequency,
  1280. BreathingRate: breathing_rate,
  1281. SystolicBloodPressure: systolic_blood_pressure,
  1282. DiastolicBloodPressure: diastolic_blood_pressure,
  1283. ActualUltrafiltration: actual_ultrafiltration,
  1284. ActualDisplacement: actual_displacement,
  1285. ActualTreatmentHour: actualtreatHour,
  1286. ActualTreatmentMinute: actualtreatmin,
  1287. WeightAfter: weightAfter,
  1288. AdditionalWeight: additionalWeight,
  1289. WeightLoss: weightReduce,
  1290. Cruor: cruor,
  1291. SymptomAfterDialysis: symptomsAfterDialysi,
  1292. InternalFistula: internalFistula,
  1293. Catheter: catheter,
  1294. Complication: complications,
  1295. DialysisIntakes: dialysateVolume,
  1296. CreatedTime: time.Now().Unix(),
  1297. UpdatedTime: time.Now().Unix(),
  1298. Status: 1,
  1299. Remark: remark,
  1300. BloodAccessPartId: blood_access_part_id,
  1301. BloodAccessPartOperaId: blood_access_part_opera_id,
  1302. DialysisIntakesUnit: dialysis_intakes_unit,
  1303. PuncturePointOozingBlood: puncturePointOozingBlood,
  1304. PuncturePointHaematoma: puncturePointHaematoma,
  1305. InternalFistulaTremorAc: internalFistulaTremorAc,
  1306. PatientGose: patientGose,
  1307. InpatientDepartment: inpatientDepartment,
  1308. ObservationContent: observationContent,
  1309. ObservationContentOther: observationContentOther,
  1310. DialysisProcess: dialysis_process,
  1311. InAdvanceMinute: in_advance_minute,
  1312. InAdvanceReason: in_advance_reason,
  1313. HemostasisMinute: hemostasis_minute,
  1314. HemostasisOpera: hemostasis_opera,
  1315. TremorNoise: tremor_noise,
  1316. DisequilibriumSyndrome: disequilibrium_syndrome,
  1317. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1318. ArterialTube: arterial_tube,
  1319. IntravenousTube: intravenous_tube,
  1320. Dialyzer: dialyzer,
  1321. InAdvanceReasonOther: in_advance_reason_other,
  1322. IsEat: is_eat,
  1323. CvcA: cvc_a,
  1324. CvcV: cvc_v,
  1325. Channel: channels,
  1326. ReturnBlood: return_blood,
  1327. RehydrationVolume: rehydration_volume,
  1328. DialysisDuring: dialysis_during,
  1329. StrokeVolume: stroke_volume,
  1330. BloodFlow: blood_flow,
  1331. SealingFluidDispose: sealing_fluid_dispose,
  1332. SealingFluidSpecial: sealing_fluid_special,
  1333. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1334. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1335. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1336. SettingPressure: setting_pressure,
  1337. DiastolicPressure: diastolic_pressure,
  1338. OtherComplication: other_complication,
  1339. Ktv: ktv,
  1340. Urr: urr,
  1341. Hypopiesia: hypopiesia,
  1342. Hypertenison: hypertenison,
  1343. Lapse: lapse,
  1344. LeaveOfficeMethod: leave_office_method,
  1345. Consciousness: consciousness,
  1346. Fallrisk: fallrisk,
  1347. MachineRun: machine_run,
  1348. AfterUrea: after_urea,
  1349. PipCoagulation: pip_coagulation,
  1350. AccumulatedBloodVolume: accumulated_blood_volume,
  1351. TransfusionVolume: transfusion_volume,
  1352. LastAfterWeight: last_after_weight,
  1353. DisplaceLiquiValue: displace_liqui_value,
  1354. }
  1355. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1356. // 查询信息规挡的设置天数
  1357. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1358. if infor.ID > 0 && infor.WeekDay > 0 {
  1359. var cha_time int64
  1360. timeNowStr := time.Now().Format("2006-01-02")
  1361. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1362. //今日的日期减去设置的日期
  1363. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1364. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1365. if cha_time >= recordDate.Unix() {
  1366. //查询审核是否允许
  1367. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1368. //申请状态不允许的情况 拒绝修改
  1369. if infor.ApplicationStatus != 1 {
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1371. return
  1372. }
  1373. }
  1374. }
  1375. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1376. if assessmentAfter.ID == 0 { //新增
  1377. if appRole.UserType == 2 || appRole.UserType == 1 {
  1378. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1379. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1380. } else {
  1381. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1382. }
  1383. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1384. if assessmentAfterDislysis.UserOrgId != 10340 {
  1385. if assessmentAfterDislysis.WeightAfter == 0 {
  1386. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1387. }
  1388. }
  1389. if adminUserInfo.Org.Id == 10693 {
  1390. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1391. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1392. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1393. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1394. }
  1395. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1396. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1397. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1398. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1399. }
  1400. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1401. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1402. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1403. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1404. }
  1405. if assessmentAfterDislysis.PulseFrequency == 0 {
  1406. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1407. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1408. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1409. }
  1410. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1411. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1412. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1413. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1414. }
  1415. }
  1416. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1417. //记录日志
  1418. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1419. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1420. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1421. PatientId: assessmentAfterDislysis.PatientId,
  1422. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1423. Status: 1,
  1424. ErrLog: string(byterequest),
  1425. AdminUserId: adminUserInfo.AdminUser.Id,
  1426. Ctime: 0,
  1427. Mtime: 0,
  1428. Source: "手机端保存透后评估",
  1429. }
  1430. service.CreateAfterDialysisLog(afterDialysisLog)
  1431. finish := models.XtDialysisFinish{
  1432. IsFinish: 1,
  1433. UserOrgId: adminUserInfo.Org.Id,
  1434. Status: 1,
  1435. Ctime: time.Now().Unix(),
  1436. Mtime: 0,
  1437. Module: 9,
  1438. RecordDate: recordDate.Unix(),
  1439. Sourse: 1,
  1440. PatientId: id,
  1441. }
  1442. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1443. if dialysisFinish.ID == 0 {
  1444. service.CreateDialysisFinish(finish)
  1445. }
  1446. redis := service.RedisClient()
  1447. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1448. redis.Set(keyTwo, "", time.Second)
  1449. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1450. //清空key 值
  1451. redis.Set(key, "", time.Second)
  1452. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1453. redis.Set(keyOne, "", time.Second)
  1454. defer redis.Close()
  1455. if err == nil {
  1456. c.ServeSuccessJSON(map[string]interface{}{
  1457. "assessmentAfterDislysis": assessmentAfterDislysis,
  1458. })
  1459. }
  1460. return
  1461. } else { //修改
  1462. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1463. if infor.ID > 0 && infor.WeekDay > 0 {
  1464. var cha_time int64
  1465. timeNowStr := time.Now().Format("2006-01-02")
  1466. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1467. //今日的日期减去设置的日期
  1468. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1469. if cha_time >= recordDate.Unix() {
  1470. //查询审核是否允许
  1471. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1472. //申请状态不允许的情况 拒绝修改
  1473. if infor.ApplicationStatus != 1 {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1475. return
  1476. }
  1477. }
  1478. }
  1479. if appRole.UserType == 2 || appRole.UserType == 1 {
  1480. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1481. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1482. } else {
  1483. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1484. if assessmentAfterDislysis.Creater == 0 {
  1485. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1486. }
  1487. }
  1488. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1489. assessmentAfterDislysis.ID = assessmentAfter.ID
  1490. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1491. if assessmentAfterDislysis.UserOrgId != 10340 {
  1492. if assessmentAfterDislysis.WeightAfter == 0 {
  1493. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1494. }
  1495. }
  1496. if adminUserInfo.Org.Id == 10693 {
  1497. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1498. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1499. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1500. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1501. }
  1502. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1503. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1504. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1505. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1506. }
  1507. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1508. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1509. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1510. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1511. }
  1512. if assessmentAfterDislysis.PulseFrequency == 0 {
  1513. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1514. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1515. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1516. }
  1517. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1518. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1519. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1520. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1521. }
  1522. }
  1523. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1524. //记录日志
  1525. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1526. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1527. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1528. PatientId: assessmentAfterDislysis.PatientId,
  1529. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1530. Status: 1,
  1531. ErrLog: string(byterequest),
  1532. AdminUserId: adminUserInfo.AdminUser.Id,
  1533. Ctime: time.Now().Unix(),
  1534. Mtime: 0,
  1535. Source: "手机端修改保存透后评估",
  1536. }
  1537. service.CreateAfterDialysisLog(afterDialysisLog)
  1538. redis := service.RedisClient()
  1539. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1540. redis.Set(keyTwo, "", time.Second)
  1541. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1542. //清空key 值
  1543. redis.Set(key, "", time.Second)
  1544. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1545. redis.Set(keyOne, "", time.Second)
  1546. if err == nil {
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "assessmentAfterDislysis": assessmentAfterDislysis,
  1549. })
  1550. return
  1551. }
  1552. }
  1553. return
  1554. }
  1555. func (c *DialysisAPIController) PostDialysisPrescription() {
  1556. id, _ := c.GetInt64("patient", 0)
  1557. recordDateStr := c.GetString("record_date")
  1558. if id <= 0 {
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1560. return
  1561. }
  1562. adminUserInfo := c.GetMobileAdminUserInfo()
  1563. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1564. if patient.ID == 0 {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1566. return
  1567. }
  1568. if len(recordDateStr) == 0 {
  1569. recordDateStr = time.Now().Format("2006-01-02")
  1570. }
  1571. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1572. if parseDateErr != nil {
  1573. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. mode_id, _ := c.GetInt64("mode_id", 0)
  1578. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1579. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1580. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1581. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1582. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1583. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1584. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1585. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1586. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1587. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1588. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1589. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1590. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1591. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1592. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1593. kalium, _ := c.GetFloat("kalium", 0)
  1594. sodium, _ := c.GetFloat("sodium", 0)
  1595. calcium, _ := c.GetFloat("calcium", 0)
  1596. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1597. glucose, _ := c.GetFloat("glucose", 0)
  1598. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1599. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1600. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1601. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1602. conductivity, _ := c.GetFloat("conductivity", 0)
  1603. remark := c.GetString("remark")
  1604. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1605. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1606. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1607. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1608. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1609. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1610. special_medicine_other := c.GetString("special_medicine_other")
  1611. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1612. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1613. blood_access, _ := c.GetInt64("blood_access", 0)
  1614. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1615. body_fluid_other := c.GetString("body_fluid_other")
  1616. niprocart, _ := c.GetInt64("niprocart", 0)
  1617. jms, _ := c.GetInt64("jms", 0)
  1618. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1619. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1620. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1621. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1622. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1623. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1624. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1625. injector, _ := c.GetInt64("injector", 0)
  1626. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1627. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1628. safe_package, _ := c.GetInt64("package", 0)
  1629. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1630. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1631. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1632. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1633. blood := c.GetString("blood")
  1634. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1635. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1636. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1637. displace_speed := c.GetString("displace_speed")
  1638. illness, _ := c.GetInt64("illness")
  1639. amylaceum := c.GetString("amylaceum")
  1640. single_time := c.GetString("single_time")
  1641. single_water := c.GetString("single_water")
  1642. replacement_flow := c.GetString("replacement_flow")
  1643. plasma_separator := c.GetString("plasma_separator")
  1644. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1645. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1646. oxygen_flow := c.GetString("oxygen_flow")
  1647. oxygen_time := c.GetString("oxygen_time")
  1648. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1649. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1650. puncture_needle := c.GetString("puncture_needle")
  1651. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1652. epo := c.GetString("epo")
  1653. epo_count, _ := c.GetFloat("epo_count", 0)
  1654. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1655. admin_user_id, _ := c.GetInt64("admin_user_id")
  1656. is_water := c.GetString("is_water")
  1657. var is_war int64
  1658. if is_water == "是" {
  1659. is_war = 1
  1660. }
  1661. if is_water == "否" {
  1662. is_war = 2
  1663. }
  1664. if is_water == "请选择" {
  1665. is_war = 0
  1666. }
  1667. drhy_water := c.GetString("drhy_water")
  1668. dry_water_hour := c.GetString("dry_water_hour")
  1669. water_machine := c.GetString("water_machine")
  1670. add_amount, _ := c.GetFloat("add_amount")
  1671. reduce_amount, _ := c.GetFloat("reduce_amount")
  1672. dialysis_remark := c.GetString("dialysis_remark")
  1673. prescribing_number, _ := c.GetFloat("prescribing_number")
  1674. prescription_sodium := c.GetString("prescription_sodium")
  1675. start_sodium := c.GetString("start_sodium")
  1676. sodium_curve := c.GetString("sodium_curve")
  1677. treatment_remark := c.GetString("treatment_remark")
  1678. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1679. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1680. prescription_water, _ := c.GetFloat("prescription_water")
  1681. dialysis_strainer := c.GetString("dialysis_strainer")
  1682. chaptalization := c.GetString("chaptalization")
  1683. washing_time := c.GetString("washing_time")
  1684. warsh_count := c.GetString("warsh_count")
  1685. blood_access_part_id := c.GetString("blood_access_part_id")
  1686. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1687. dialyzate := c.GetString("dialyzate")
  1688. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1689. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1690. //
  1691. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1692. // if appRole.UserType == 3 {
  1693. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1694. // if getPermissionErr != nil {
  1695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1696. // return
  1697. // } else if headNursePermission == nil {
  1698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1699. // return
  1700. // }
  1701. // }
  1702. //}
  1703. // 查询信息规挡的设置天数
  1704. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1705. if infor.ID > 0 && infor.WeekDay > 0 {
  1706. var cha_time int64
  1707. timeNowStr := time.Now().Format("2006-01-02")
  1708. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1709. //今日的日期减去设置的日期
  1710. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1711. if cha_time >= recordDate.Unix() {
  1712. //查询审核是否允许
  1713. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1714. //申请状态不允许的情况 拒绝修改
  1715. if infor.ApplicationStatus != 1 {
  1716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1717. return
  1718. }
  1719. }
  1720. }
  1721. if mode_id > 0 {
  1722. var str string
  1723. //查找该机构用的是什么透析器
  1724. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1725. if filedConfig.ID > 0 {
  1726. str = dialyzerPerfusionApparatus
  1727. } else {
  1728. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1729. }
  1730. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1731. }
  1732. //TODO 需要根据角色去判断
  1733. prescription := models.DialysisPrescription{
  1734. UserOrgId: adminUserInfo.Org.Id,
  1735. PatientId: id,
  1736. RecordDate: recordDate.Unix(),
  1737. ModeId: mode_id,
  1738. DialysisDuration: dialysis_duration,
  1739. Dialyzer: dialyzer,
  1740. PerfusionApparatus: perfusion_apparatus,
  1741. BloodFlowVolume: blood_flow_volume,
  1742. DewaterAmount: dewater_amount,
  1743. DisplaceLiqui: displace_liqui,
  1744. ReplacementWay: replacement_way,
  1745. Anticoagulant: anticoagulant,
  1746. AnticoagulantShouji: anticoagulant_shouji,
  1747. AnticoagulantWeichi: anticoagulant_weichi,
  1748. AnticoagulantZongliang: anticoagulant_zongliang,
  1749. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1750. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1751. Kalium: kalium,
  1752. Sodium: sodium,
  1753. Calcium: calcium,
  1754. Bicarbonate: bicarbonate,
  1755. Glucose: glucose,
  1756. // DryWeight: dry_weight,
  1757. DialysateFlow: dialysate_flow,
  1758. DialysateTemperature: dialysate_temperature,
  1759. // PrescriptionDoctor: prescription_doctor,
  1760. ReplacementTotal: replacement_total,
  1761. Conductivity: conductivity,
  1762. Remark: remark,
  1763. Status: 1,
  1764. CreatedTime: time.Now().Unix(),
  1765. UpdatedTime: time.Now().Unix(),
  1766. DialysisDurationMinute: dialysisDurationMinute,
  1767. DialysisDurationHour: dialysisDurationHour,
  1768. TargetUltrafiltration: targetUltrafiltration,
  1769. DialysateFormulation: dialysateFormulation,
  1770. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1771. BodyFluid: body_fluid,
  1772. SpecialMedicine: special_medicine,
  1773. SpecialMedicineOther: special_medicine_other,
  1774. DisplaceLiquiPart: displace_liqui_part,
  1775. DisplaceLiquiValue: displace_liqui_value,
  1776. BloodAccess: blood_access,
  1777. Ultrafiltration: ultrafiltration,
  1778. BodyFluidOther: body_fluid_other,
  1779. Niprocart: niprocart,
  1780. Jms: jms,
  1781. FistulaNeedleSet: fistula_needle_set,
  1782. FistulaNeedleSet16: fistula_needle_set_16,
  1783. Hemoperfusion: hemoperfusion,
  1784. DialyserSterilised: dialyser_sterilised,
  1785. Filtryzer: filtryzer,
  1786. Dialyzers: dialyzers,
  1787. Injector: injector,
  1788. Bloodlines: bloodlines,
  1789. TubingHemodialysis: tubing_hemodialysis,
  1790. Package: safe_package,
  1791. ALiquid: a_liquid,
  1792. TargetKtv: target_ktv,
  1793. PreImpulse: pre_impulse,
  1794. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1795. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1796. Blood: blood,
  1797. DialysisDialyszers: dialysis_dialyszers,
  1798. DialysisIrrigation: dialysis_irrigation,
  1799. AntioxidantCommodityName: antioxidant_commodity_name,
  1800. DisplaceSpeed: displace_speed,
  1801. Illness: illness,
  1802. Amylaceum: amylaceum,
  1803. SingleTime: single_time,
  1804. SingleWater: single_water,
  1805. ReplacementFlow: replacement_flow,
  1806. PlasmaSeparator: plasma_separator,
  1807. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1808. OxygenUptake: oxygen_uptake,
  1809. OxygenFlow: oxygen_flow,
  1810. OxygenTime: oxygen_time,
  1811. HemodialysisPipelines: hemodialysis_pipelines,
  1812. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1813. PunctureNeedle: puncture_needle,
  1814. PunctureNeedleCount: puncture_needle_count,
  1815. Epo: epo,
  1816. EpoCount: epo_count,
  1817. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1818. AdminUserId: admin_user_id,
  1819. IsWater: is_war,
  1820. DrhyWater: drhy_water,
  1821. DryWaterHour: dry_water_hour,
  1822. WaterMachine: water_machine,
  1823. AddAmount: add_amount,
  1824. ReduceAmount: reduce_amount,
  1825. DialysisRemark: dialysis_remark,
  1826. PrescribingNumber: prescribing_number,
  1827. StartSodium: start_sodium,
  1828. SodiumCurve: sodium_curve,
  1829. TreatmentRemark: treatment_remark,
  1830. PrescriptionSodium: prescription_sodium,
  1831. DialysisFluidFlow: dialysis_fluid_flow,
  1832. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1833. PrescriptionWater: prescription_water,
  1834. DialysisStrainer: dialysis_strainer,
  1835. Chaptalization: chaptalization,
  1836. WashingTime: washing_time,
  1837. WarshCount: warsh_count,
  1838. BloodAccessPartId: blood_access_part_id,
  1839. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1840. Dialyzate: dialyzate,
  1841. }
  1842. //查询最近透析准备表里是否存在 透析器 灌流器
  1843. //
  1844. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1845. //
  1846. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1847. //
  1848. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1849. //if len(mation)>0{
  1850. // for _, item := range splitStr {
  1851. // for _,it := range mation{
  1852. // if(item == it.SpecificationName){
  1853. //
  1854. // //查询最近一次的透析器
  1855. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1856. //
  1857. // if errcode == gorm.ErrRecordNotFound{
  1858. // //插入数据
  1859. // prepare := models.DialysisBeforePrepare{
  1860. // UserOrgId: adminUserInfo.Org.Id,
  1861. // PatientId: id,
  1862. // RecordDate: recordDate.Unix(),
  1863. // GoodTypeId: it.GoodTypeId,
  1864. // GoodId: it.ID,
  1865. // Count: 1,
  1866. // Ctime: time.Now().Unix(),
  1867. // Creater: adminUserInfo.AdminUser.Id,
  1868. // Status:1,
  1869. //
  1870. // }
  1871. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1872. // fmt.Println("",errcode)
  1873. // }
  1874. // }
  1875. // }
  1876. //
  1877. // }
  1878. //
  1879. // for _, item := range splitIrrigation {
  1880. // for _,it := range mation{
  1881. // if(item == it.SpecificationName){
  1882. // //查询最近一次的透析器
  1883. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1884. // if errcode == gorm.ErrRecordNotFound{
  1885. // //插入数据
  1886. // prepare := models.DialysisBeforePrepare{
  1887. // UserOrgId: adminUserInfo.Org.Id,
  1888. // PatientId: id,
  1889. // RecordDate: recordDate.Unix(),
  1890. // GoodTypeId: it.GoodTypeId,
  1891. // GoodId: it.ID,
  1892. // Count: 1,
  1893. // Ctime: time.Now().Unix(),
  1894. // Creater: adminUserInfo.AdminUser.Id,
  1895. // Status:1,
  1896. //
  1897. // }
  1898. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1899. // fmt.Println(errcode)
  1900. // }
  1901. // }
  1902. // }
  1903. // }
  1904. //}
  1905. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1906. if dialysisPrescription.ID == 0 { //新增
  1907. if appRole.UserType == 2 || appRole.UserType == 1 {
  1908. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1909. }
  1910. prescription.Creater = adminUserInfo.AdminUser.Id
  1911. //针对河间咸得
  1912. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1913. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1914. prescription.DisplaceLiquiPart = 0
  1915. prescription.DisplaceLiquiValue = 0
  1916. }
  1917. }
  1918. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1919. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1920. }
  1921. err := service.AddSigleRecord(&prescription)
  1922. //记录日志
  1923. byterequest, _ := json.Marshal(prescription)
  1924. prescriptionLog := models.XtDialysisPrescriptionLog{
  1925. UserOrgId: prescription.UserOrgId,
  1926. Ctime: time.Now().Unix(),
  1927. Mtime: 0,
  1928. ErrLog: string(byterequest),
  1929. AdminUserId: adminUserInfo.AdminUser.Id,
  1930. RecordDate: prescription.RecordDate,
  1931. PatientId: prescription.PatientId,
  1932. Source: "手机端新增保存处方",
  1933. Status: 1,
  1934. }
  1935. service.CreatePrescriptionLog(prescriptionLog)
  1936. finish := models.XtDialysisFinish{
  1937. IsFinish: 1,
  1938. UserOrgId: adminUserInfo.Org.Id,
  1939. Status: 1,
  1940. Ctime: time.Now().Unix(),
  1941. Mtime: 0,
  1942. Module: 1,
  1943. RecordDate: recordDate.Unix(),
  1944. Sourse: 1,
  1945. PatientId: id,
  1946. }
  1947. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1948. if dialysisFinish.ID == 0 {
  1949. service.CreateDialysisFinish(finish)
  1950. }
  1951. //长沙南雅医院,自动生成抗凝剂的临时处方
  1952. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1953. if prescribing_number == 0 {
  1954. prescribing_number = 1
  1955. }
  1956. if prescribing_number == 0 && id == 14682 {
  1957. prescribing_number = 2
  1958. }
  1959. if prescribing_number == 0 && id == 18560 {
  1960. prescribing_number = 2
  1961. }
  1962. advice := models.DoctorAdvice{
  1963. UserOrgId: adminUserInfo.Org.Id,
  1964. PatientId: id,
  1965. GroupNo: 0,
  1966. AdviceType: 2,
  1967. RecordDate: recordDate.Unix(),
  1968. AdviceDate: recordDate.Unix(),
  1969. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1970. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1971. AdviceDesc: "",
  1972. ReminderDate: 0,
  1973. SingleDose: anticoagulant_zongliang,
  1974. SingleDoseUnit: "iu",
  1975. DrugSpec: 0,
  1976. DrugSpecUnit: "",
  1977. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1978. PrescribingNumberUnit: "支",
  1979. DeliveryWay: "静脉注射",
  1980. ExecutionFrequency: "上机前",
  1981. AdviceDoctor: 0,
  1982. Status: 1,
  1983. CreatedTime: time.Now().Unix(),
  1984. UpdatedTime: time.Now().Unix(),
  1985. IsPrescription: 1,
  1986. ExecutionState: 2,
  1987. StopState: 2,
  1988. IsSettle: 2,
  1989. }
  1990. // 查询排班信息
  1991. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1992. if schedulePatient.ID > 0 {
  1993. if schedulePatient.ScheduleType == 1 {
  1994. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1995. }
  1996. if schedulePatient.ScheduleType == 2 {
  1997. advice.StartTime = recordDate.Unix() + 9*60*60
  1998. }
  1999. }
  2000. // 抗凝剂名称
  2001. switch anticoagulant {
  2002. case 1:
  2003. advice.AdviceName = "无肝素"
  2004. break
  2005. case 2:
  2006. advice.AdviceName = "普通肝素"
  2007. break
  2008. case 3:
  2009. advice.AdviceName = "低分子肝素"
  2010. break
  2011. case 4:
  2012. advice.AdviceName = "阿加曲班"
  2013. break
  2014. case 5:
  2015. advice.AdviceName = "枸橼酸钠"
  2016. break
  2017. case 6:
  2018. advice.AdviceName = "低分子肝素钙"
  2019. break
  2020. case 7:
  2021. advice.AdviceName = "低分子肝素钠"
  2022. break
  2023. case 8:
  2024. advice.AdviceName = "依诺肝素"
  2025. break
  2026. case 9:
  2027. advice.AdviceName = "达肝素"
  2028. break
  2029. case 10:
  2030. advice.AdviceName = "体外抗凝"
  2031. break
  2032. case 11:
  2033. advice.AdviceName = "那曲肝素"
  2034. break
  2035. case 12:
  2036. advice.AdviceName = "无抗凝剂"
  2037. break
  2038. }
  2039. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2040. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2041. advice.AdviceDoctor = appRole.AdminUserId
  2042. }
  2043. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2044. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2045. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2046. advice.AdviceName = "低分子肝素钠注射液"
  2047. // 修改患者临时医嘱里的抗凝剂医嘱
  2048. advice.ID = advicePrescription.ID
  2049. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. } else {
  2051. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2052. advice.AdviceName = "低分子肝素钠注射液"
  2053. // 新增患者临时医嘱里的抗凝剂医嘱
  2054. service.CreateDoctorAdvice(&advice)
  2055. }
  2056. }
  2057. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2058. redis := service.RedisClient()
  2059. defer redis.Close()
  2060. //清空key 值
  2061. redis.Set(key, "", time.Second)
  2062. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2063. redis.Set(keyOne, "", time.Second)
  2064. }
  2065. //获取key,清空redis
  2066. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2067. redis := service.RedisClient()
  2068. //清空key 值
  2069. redis.Set(key, "", time.Second)
  2070. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2071. //清空key 值
  2072. redis.Set(keyOne, "", time.Second)
  2073. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2074. //清空key 值
  2075. redis.Set(keyTwo, "", time.Second)
  2076. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2077. redis.Set(keySix, "", time.Second)
  2078. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2079. redis.Set(keySeven, "", time.Second)
  2080. if err == nil {
  2081. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2082. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2083. //清空key 值
  2084. redis.Set(keyThree, "", time.Second)
  2085. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2086. //清空key 值
  2087. redis.Set(keyFour, "", time.Second)
  2088. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2089. redis.Set(keyFive, "", time.Second)
  2090. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2091. redis.Set(keySix, "", time.Second)
  2092. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2093. redis.Set(keySeven, "", time.Second)
  2094. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2095. //清空key 值
  2096. redis.Set(keyOne, "", time.Second)
  2097. if updateErr != nil {
  2098. utils.ErrorLog("%v", updateErr)
  2099. }
  2100. defer redis.Close()
  2101. c.ServeSuccessJSON(map[string]interface{}{
  2102. "prescription": prescription,
  2103. })
  2104. }
  2105. } else { //修改
  2106. //if mode_id > 0 {
  2107. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2108. //}
  2109. //if template.TemplateId == 1 {
  2110. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2112. // if getPermissionErr != nil {
  2113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2114. // return
  2115. // } else if headNursePermission == nil {
  2116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2117. // return
  2118. // }
  2119. // }
  2120. //}
  2121. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2122. prescription.Modifier = adminUserInfo.AdminUser.Id
  2123. if appRole.UserType == 2 || appRole.UserType == 1 {
  2124. prescription_doctor := adminUserInfo.AdminUser.Id
  2125. prescription.PrescriptionDoctor = prescription_doctor
  2126. } else {
  2127. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2128. }
  2129. if dialysisPrescription.Creater == 0 { //体重称
  2130. prescription.Creater = adminUserInfo.AdminUser.Id
  2131. } else {
  2132. prescription.Creater = dialysisPrescription.Creater
  2133. if adminUserInfo.Org.Id == 9882 {
  2134. if appRole.UserType == 2 || appRole.UserType == 1 {
  2135. prescription_doctor := adminUserInfo.AdminUser.Id
  2136. prescription.PrescriptionDoctor = prescription_doctor
  2137. prescription.Creater = prescription_doctor
  2138. }
  2139. }
  2140. }
  2141. prescription.ID = dialysisPrescription.ID
  2142. service.UpDateDialysisPrescription(&prescription)
  2143. //记录日志
  2144. byterequest, _ := json.Marshal(prescription)
  2145. prescriptionLog := models.XtDialysisPrescriptionLog{
  2146. UserOrgId: prescription.UserOrgId,
  2147. Ctime: time.Now().Unix(),
  2148. Mtime: 0,
  2149. ErrLog: string(byterequest),
  2150. AdminUserId: adminUserInfo.AdminUser.Id,
  2151. RecordDate: prescription.RecordDate,
  2152. PatientId: prescription.PatientId,
  2153. Source: "手机端修改处方",
  2154. Status: 1,
  2155. }
  2156. service.CreatePrescriptionLog(prescriptionLog)
  2157. finish := models.XtDialysisFinish{
  2158. IsFinish: 1,
  2159. UserOrgId: adminUserInfo.Org.Id,
  2160. Status: 1,
  2161. Ctime: time.Now().Unix(),
  2162. Mtime: 0,
  2163. Module: 1,
  2164. RecordDate: recordDate.Unix(),
  2165. Sourse: 1,
  2166. PatientId: id,
  2167. }
  2168. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2169. if dialysisFinish.ID == 0 {
  2170. service.CreateDialysisFinish(finish)
  2171. }
  2172. //修改处方
  2173. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2174. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2175. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2176. if advicePrescription.ID > 0 {
  2177. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2178. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2179. redis := service.RedisClient()
  2180. defer redis.Close()
  2181. //清空key 值
  2182. redis.Set(key, "", time.Second)
  2183. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2184. redis.Set(keyOne, "", time.Second)
  2185. }
  2186. }
  2187. //获取key,清空redis
  2188. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2189. redis := service.RedisClient()
  2190. //清空key 值
  2191. redis.Set(key, "", time.Second)
  2192. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2193. //清空key 值
  2194. redis.Set(keyOne, "", time.Second)
  2195. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2196. redis.Set(keySix, "", time.Second)
  2197. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2198. redis.Set(keySeven, "", time.Second)
  2199. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2200. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2201. //清空key 值
  2202. redis.Set(keyTwoOne, "", time.Second)
  2203. defer redis.Close()
  2204. if updateErr != nil {
  2205. utils.ErrorLog("%v", updateErr)
  2206. }
  2207. c.ServeSuccessJSON(map[string]interface{}{
  2208. "prescription": prescription,
  2209. })
  2210. }
  2211. }
  2212. func (c *DialysisAPIController) Finish() {
  2213. id, _ := c.GetInt64("patient", 0)
  2214. recordDateStr := c.GetString("record_date")
  2215. nurseID, _ := c.GetInt64("nurse")
  2216. end_time := c.GetString("end_time")
  2217. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2218. internal_fistula := c.GetString("blood_access_internal_fistula")
  2219. catheter := c.GetString("catheter")
  2220. cruor := c.GetString("cruor")
  2221. mission := c.GetString("mission")
  2222. condenser := c.GetString("condenser")
  2223. if id <= 0 || nurseID <= 0 {
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2225. return
  2226. }
  2227. adminUserInfo := c.GetMobileAdminUserInfo()
  2228. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2229. if patient.ID == 0 {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2231. return
  2232. }
  2233. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2234. if getNurseErr != nil {
  2235. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2237. return
  2238. } else if nurse == nil {
  2239. c.ErrorLog("护士不存在")
  2240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2241. return
  2242. }
  2243. if len(recordDateStr) == 0 {
  2244. recordDateStr = time.Now().Format("2006-01-02")
  2245. }
  2246. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2247. if parseDateErr != nil {
  2248. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2250. return
  2251. }
  2252. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2253. if parseEndDateErr != nil {
  2254. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. // 查询信息规挡的设置天数
  2259. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2260. if infor.ID > 0 && infor.WeekDay > 0 {
  2261. var cha_time int64
  2262. timeNowStr := time.Now().Format("2006-01-02")
  2263. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2264. //今日的日期减去设置的日期
  2265. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2266. if cha_time >= recordDate.Unix() {
  2267. //查询审核是否允许
  2268. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2269. //申请状态不允许的情况 拒绝修改
  2270. if infor.ApplicationStatus != 1 {
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2272. return
  2273. }
  2274. }
  2275. }
  2276. //now := time.Now()
  2277. //year, month, day := now.Date()
  2278. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2279. //todayTimeStamp := today_time.Unix()
  2280. // 获取当天的第一条透析纪录
  2281. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2282. if getMonitorRecordsErr != nil {
  2283. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2285. return
  2286. }
  2287. // 获取当前的最后一条透析纪录
  2288. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2289. if getMonitorRecordsErr != nil {
  2290. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2292. return
  2293. }
  2294. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2295. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2296. if getAADErr != nil {
  2297. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2299. return
  2300. }
  2301. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2302. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2303. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2304. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2305. if assessmentAfterDislysis != nil {
  2306. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2307. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2308. } else {
  2309. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2310. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2311. tempassessmentAfterDislysis.Status = 1
  2312. tempassessmentAfterDislysis.PatientId = id
  2313. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2314. }
  2315. //长沙南雅
  2316. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2317. //获取最后一条透析处方数据
  2318. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2319. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2320. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2321. }
  2322. if dialysisOrder.Stage == 1 {
  2323. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2324. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2325. fmt.Println(value)
  2326. a, b := math.Modf(value)
  2327. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2328. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2329. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2330. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2331. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2332. }
  2333. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2334. //var num1 int64
  2335. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2336. //fmt.Println(num1)
  2337. //sub := float64(num1 / 3600)
  2338. //fmt.Println(sub)
  2339. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2340. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2341. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2342. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2343. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2344. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2345. if adminUserInfo.Org.Id != 10375 {
  2346. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2347. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2348. }
  2349. if adminUserInfo.Org.Id != 10445 {
  2350. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2351. }
  2352. //北方营口医院
  2353. if adminUserInfo.Org.Id == 10445 {
  2354. //获取最后一条透析处方数据
  2355. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2356. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2357. } else {
  2358. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2359. }
  2360. //新化博翔
  2361. if adminUserInfo.Org.Id == 10447 {
  2362. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2363. }
  2364. //阳春
  2365. if adminUserInfo.Org.Id == 10485 {
  2366. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2367. }
  2368. if adminUserInfo.Org.Id == 10551 {
  2369. //获取最后一条透析处方数据
  2370. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2371. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2372. }
  2373. if adminUserInfo.Org.Id == 10580 {
  2374. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2375. }
  2376. if adminUserInfo.Org.Id == 10612 {
  2377. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2378. }
  2379. //孝康
  2380. if adminUserInfo.Org.Id == 10693 {
  2381. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2382. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2383. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2384. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2385. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2386. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2387. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2388. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2389. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2390. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2391. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2392. }
  2393. if adminUserInfo.Org.Id == 10697 {
  2394. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2395. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2396. lastWeightAfter.LastAfterWeight = floatAfeter
  2397. }
  2398. }
  2399. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 {
  2400. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2401. if evaluation.SystolicBloodPressure == 0 {
  2402. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2403. if adminUserInfo.Org.Id == 10693 {
  2404. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2405. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2406. }
  2407. pre := models.PredialysisEvaluation{
  2408. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2409. }
  2410. fmt.Println("prew", pre)
  2411. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2412. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2413. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2414. redis := service.RedisClient()
  2415. redis.Set(key, "", time.Second)
  2416. redis.Set(keyOne, "", time.Second)
  2417. defer redis.Close()
  2418. fmt.Println(getNurseErr)
  2419. }
  2420. if evaluation.DiastolicBloodPressure == 0 {
  2421. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2422. if adminUserInfo.Org.Id == 10693 {
  2423. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2424. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2425. }
  2426. pres := models.PredialysisEvaluation{
  2427. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2428. }
  2429. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2430. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2431. redis := service.RedisClient()
  2432. redis.Set(key, "", time.Second)
  2433. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2434. redis.Set(keyOne, "", time.Second)
  2435. defer redis.Close()
  2436. fmt.Println(getNurseErr)
  2437. }
  2438. if evaluation.PulseFrequency == 0 {
  2439. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2440. if adminUserInfo.Org.Id == 10693 {
  2441. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2442. evaluation.PulseFrequency = pulseFrequency
  2443. }
  2444. press := models.PredialysisEvaluation{
  2445. PulseFrequency: evaluation.PulseFrequency,
  2446. }
  2447. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2449. redis := service.RedisClient()
  2450. redis.Set(key, "", time.Second)
  2451. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2452. redis.Set(keyOne, "", time.Second)
  2453. defer redis.Close()
  2454. fmt.Println(getNurseErr)
  2455. }
  2456. if evaluation.Temperature == 0 {
  2457. evaluation.Temperature = fmonitorRecords.Temperature
  2458. press := models.PredialysisEvaluation{
  2459. Temperature: evaluation.Temperature,
  2460. }
  2461. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2462. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2463. redis := service.RedisClient()
  2464. redis.Set(key, "", time.Second)
  2465. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2466. redis.Set(keyOne, "", time.Second)
  2467. defer redis.Close()
  2468. fmt.Println(getNurseErr)
  2469. }
  2470. }
  2471. if adminUserInfo.Org.Id == 9583 {
  2472. //获取透析处方的最后一条数据
  2473. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2474. if diaerr != nil {
  2475. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2477. return
  2478. }
  2479. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2480. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2481. }
  2482. }
  2483. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2484. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2485. }
  2486. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2487. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2488. }
  2489. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2490. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2491. }
  2492. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2493. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2494. }
  2495. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2496. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2497. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2498. }
  2499. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2500. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2501. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2502. }
  2503. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2504. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2505. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2506. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2507. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2508. }
  2509. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2510. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2511. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2512. }
  2513. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2514. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2515. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2516. }
  2517. if lastAssessmentAfterDislysis != nil {
  2518. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2519. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2520. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2521. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2522. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2523. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2524. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2525. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2526. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2527. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2528. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2529. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2530. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2531. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2532. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2533. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2534. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2535. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2536. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2537. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2538. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2539. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2540. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2541. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2542. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2543. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2544. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2545. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2546. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2547. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2548. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2549. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2550. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2551. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2552. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2553. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2554. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2555. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2556. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2557. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2558. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2559. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2560. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2561. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2562. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2563. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2564. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2565. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2566. if tempassessmentAfterDislysis.PatientId == 18695 {
  2567. tempassessmentAfterDislysis.ActualDisplacement = 0
  2568. }
  2569. if adminUserInfo.Org.Id != 10375 {
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2571. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2572. }
  2573. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2574. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2575. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2576. }
  2577. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2578. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2579. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2580. }
  2581. }
  2582. finish := models.XtDialysisFinish{
  2583. IsFinish: 1,
  2584. UserOrgId: adminUserInfo.Org.Id,
  2585. Status: 1,
  2586. Ctime: time.Now().Unix(),
  2587. Mtime: 0,
  2588. Module: 9,
  2589. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2590. Sourse: 1,
  2591. PatientId: tempassessmentAfterDislysis.PatientId,
  2592. }
  2593. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2594. if dialysisFinish.ID == 0 {
  2595. service.CreateDialysisFinish(finish)
  2596. }
  2597. //孝康
  2598. if adminUserInfo.Org.Id == 10693 {
  2599. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2600. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2601. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2602. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2603. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2604. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2605. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2606. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2607. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2608. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2609. }
  2610. if adminUserInfo.Org.Id == 10697 {
  2611. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2612. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2613. lastWeightAfter.LastAfterWeight = floatAfeter
  2614. }
  2615. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2616. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2617. redis := service.RedisClient()
  2618. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2619. redis.Set(keyOne, "", time.Second)
  2620. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2621. redis.Set(keyTwo, "", time.Second)
  2622. defer redis.Close()
  2623. //清空key 值
  2624. redis.Set(key, "", time.Second)
  2625. if err != nil {
  2626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2627. return
  2628. }
  2629. if dialysisOrder == nil {
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2631. return
  2632. }
  2633. if dialysisOrder.Stage == 2 {
  2634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2635. return
  2636. }
  2637. if dialysisOrder.Stage == 1 {
  2638. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2639. finish := models.XtDialysisFinish{
  2640. IsFinish: 1,
  2641. UserOrgId: adminUserInfo.Org.Id,
  2642. Status: 1,
  2643. Ctime: time.Now().Unix(),
  2644. Mtime: 0,
  2645. Module: 8,
  2646. RecordDate: recordDate.Unix(),
  2647. Sourse: 1,
  2648. PatientId: id,
  2649. }
  2650. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2651. if dialysisFinish.ID == 0 {
  2652. service.CreateDialysisFinish(finish)
  2653. }
  2654. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2655. redis := service.RedisClient()
  2656. defer redis.Close()
  2657. //清空key 值
  2658. redis.Set(key, "", time.Second)
  2659. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2660. redis.Set(keyOne, "", time.Second)
  2661. //结束时候透析次数加1
  2662. service.UpdateSolutionByPatientId(id)
  2663. //下机完自动消毒,针对长沙南雅
  2664. if dialysisOrder.Stage == 1 {
  2665. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2666. //根据床位号获取设备型号
  2667. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2668. //查询使用消毒最后一条消毒记录
  2669. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2670. fmt.Println("err", err)
  2671. if err == gorm.ErrRecordNotFound {
  2672. //查找排班
  2673. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2674. //查询改设备是否有消毒计划
  2675. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2676. //根据床位号获取设备id
  2677. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2678. //查询病人信息
  2679. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2680. var con = ""
  2681. if patients.IsInfectious == 0 {
  2682. con = ""
  2683. }
  2684. if patients.IsInfectious == 1 {
  2685. con = "无"
  2686. }
  2687. if patients.IsInfectious == 2 {
  2688. con = "有"
  2689. }
  2690. if errcode == nil {
  2691. var end_time int64
  2692. end_time = endDate.Unix() + plan.DisinfecTime*60
  2693. //新增消毒
  2694. information := models.DeviceInformation{
  2695. Date: dialysisOrder.DialysisDate,
  2696. Zone: dialysisOrder.ZoneId,
  2697. Class: dialysisOrder.SchedualType,
  2698. BedNumber: dialysisOrder.BedID,
  2699. PatientId: dialysisOrder.PatientId,
  2700. DialysisMode: scheduleByPatient.ModeId,
  2701. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2702. Disinfection: 1,
  2703. DialysisConcentration: 1,
  2704. DisinfectionStatus: 1,
  2705. Move: 1,
  2706. UserOrgId: dialysisOrder.UserOrgId,
  2707. DisinfectType: plan.Way,
  2708. DisinfectantType: plan.MachineDisinfectant,
  2709. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2710. Disinfectant: plan.Disinfectant,
  2711. Ctime: time.Now().Unix(),
  2712. Status: 1,
  2713. SignName: nurseID,
  2714. EquimentId: addmacher.ID,
  2715. DisinfectionResidue: 2,
  2716. Bed: addmacher.BedNumber,
  2717. StartTime: dialysisOrder.StartTime,
  2718. EndTime: dialysisOrder.EndTime,
  2719. Contagion: con,
  2720. WeightLoss: 0,
  2721. Hyperfiltratio: 0,
  2722. DialysisHour: "",
  2723. MachineRun: 1,
  2724. DisinfecStartime: endDate.Unix(),
  2725. DisinfecEndtime: end_time,
  2726. }
  2727. err := service.CreateInformationTwo(&information)
  2728. fmt.Println("报错", err)
  2729. }
  2730. }
  2731. }
  2732. }
  2733. dialysisOrder.Stage = 2
  2734. dialysisOrder.FinishNurse = nurseID
  2735. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2736. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2737. dialysisOrder.EndTime = endDate.Unix()
  2738. // 长沙南雅需求
  2739. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2740. //获取最后1条监测的数据
  2741. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2742. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2743. var accumulatedBloodVolume float64
  2744. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2745. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2746. fmt.Println(err)
  2747. // 查询未执行的医嘱
  2748. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2749. for _, item := range doctorAdvice {
  2750. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2751. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2752. redis := service.RedisClient()
  2753. //清空key 值
  2754. redis.Set(key, "", time.Second)
  2755. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2756. redis.Set(keyTwo, "", time.Second)
  2757. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2758. redis.Set(keyThree, "", time.Second)
  2759. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2760. theTime := toTime.Format("2006-01-02")
  2761. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2762. redis.Set(keyFour, "", time.Second)
  2763. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2764. redis.Set(keyFive, "", time.Second)
  2765. defer redis.Close()
  2766. }
  2767. }
  2768. go func() {
  2769. ssoDomain := beego.AppConfig.String("call_domain")
  2770. api := ssoDomain + "/index/downpatient"
  2771. values := make(url.Values)
  2772. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2773. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2774. values.Set("patient_id", strconv.FormatInt(id, 10))
  2775. http.PostForm(api, values)
  2776. }()
  2777. if err == nil {
  2778. c.ServeSuccessJSON(map[string]interface{}{
  2779. "dialysisOrder": dialysisOrder,
  2780. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2781. })
  2782. } else {
  2783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2784. }
  2785. }
  2786. }
  2787. func (c *DialysisAPIController) GetAllZone() {
  2788. adminUserInfo := c.GetMobileAdminUserInfo()
  2789. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2790. if err == nil {
  2791. c.ServeSuccessJSON(map[string]interface{}{
  2792. "zone": zone,
  2793. })
  2794. }
  2795. }
  2796. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2797. adminUserInfo := c.GetMobileAdminUserInfo()
  2798. page, _ := c.GetInt64("page", 1)
  2799. limit, _ := c.GetInt64("limit", 10)
  2800. schedulType, _ := c.GetInt64("schedul_type", 0)
  2801. startTime, _ := c.GetInt64("schedul_time", 0)
  2802. partitionType, _ := c.GetInt64("partition_type", 0)
  2803. keywords := c.GetString("keywords")
  2804. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2805. if err == nil {
  2806. c.ServeSuccessJSON(map[string]interface{}{
  2807. "schedule": dialysisSchedule,
  2808. })
  2809. }
  2810. return
  2811. }
  2812. // /m/api/dialysis/start [post]
  2813. // @param patient_id:int
  2814. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2815. // @param nurse:int 上机护士
  2816. // @param bed:int 床位号
  2817. func (this *DialysisAPIController) StartDialysis() {
  2818. patientID, _ := this.GetInt64("patient_id")
  2819. recordDateStr := this.GetString("record_date")
  2820. nurseID, _ := this.GetInt64("start_nurse")
  2821. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2822. blood_drawing, _ := this.GetInt64("blood_drawing")
  2823. schedual_type, _ := this.GetInt64("schedual_type")
  2824. bedID, _ := this.GetInt64("bed")
  2825. start_time := this.GetString("start_time")
  2826. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2827. change_nurse, _ := this.GetInt64("change_nurse")
  2828. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2829. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2830. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2831. puncture_needle := this.GetString("puncture_needle")
  2832. puncture_way := this.GetString("puncture_way")
  2833. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2834. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2835. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2836. zone_id, _ := this.GetInt64("zone_id")
  2837. elecsign := this.GetString("url")
  2838. nuclein_date_str := this.GetString("nuclein_date_str")
  2839. schedule_remark := this.GetString("schedule_remark")
  2840. order_remark := this.GetString("order_remark")
  2841. catheter_operation := this.GetString("catheter_operation")
  2842. blood_flow_volume := this.GetString("blood_flow_volume")
  2843. dialysis_strainer := this.GetString("dialysis_strainer")
  2844. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2846. return
  2847. }
  2848. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2849. if parseStartDateErr != nil {
  2850. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2852. return
  2853. }
  2854. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2855. if parseErr != nil {
  2856. this.ErrorLog("时间解析失败:%v", parseErr)
  2857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2858. return
  2859. }
  2860. adminUserInfo := this.GetMobileAdminUserInfo()
  2861. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2862. if getPatientErr != nil {
  2863. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2865. return
  2866. } else if patient == nil {
  2867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2868. return
  2869. }
  2870. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2871. if getNurseErr != nil {
  2872. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2874. return
  2875. } else if nurse == nil {
  2876. this.ErrorLog("护士不存在")
  2877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2878. return
  2879. }
  2880. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2881. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2882. if getDeviceNumberErr != nil {
  2883. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2885. return
  2886. } else if deviceNumber == nil {
  2887. this.ErrorLog("床位号不存在")
  2888. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2889. return
  2890. }
  2891. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2892. if getRecordErr != nil {
  2893. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2895. return
  2896. } else if dialysisRecord != nil {
  2897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2898. return
  2899. }
  2900. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2901. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2902. timeLayout := "2006-01-02 15:04:05"
  2903. loc, _ := time.LoadLocation("Local")
  2904. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2905. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2906. schedulestartTime := theStartTime.Unix()
  2907. scheduleendTime := theEndTime.Unix()
  2908. var theNucleinDate int64
  2909. timeLayoutOne := "2006-01-02"
  2910. if len(nuclein_date_str) > 0 {
  2911. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2912. if err != nil {
  2913. utils.ErrorLog(err.Error())
  2914. }
  2915. theNucleinDate = theTime.Unix()
  2916. }
  2917. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2918. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2919. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2920. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2921. //查询该床位是否有人用了
  2922. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2923. if err == gorm.ErrRecordNotFound { //空床位
  2924. // 修改了床位逻辑
  2925. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2926. if daySchedule.ID > 0 {
  2927. daySchedule.PartitionId = deviceNumber.ZoneID
  2928. daySchedule.BedId = bedID
  2929. daySchedule.ScheduleType = schedual_type
  2930. daySchedule.UpdatedTime = time.Now().Unix()
  2931. xtSchedule := models.Schedule{
  2932. PartitionId: deviceNumber.ZoneID,
  2933. BedId: bedID,
  2934. ScheduleType: schedual_type,
  2935. UpdatedTime: time.Now().Unix(),
  2936. }
  2937. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2938. if err != nil {
  2939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2940. return
  2941. }
  2942. }
  2943. } else if err == nil {
  2944. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2945. if order.ID > 0 { //该机位被其他人占用了
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2947. return
  2948. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2949. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2950. if daySchedule.ID > 0 {
  2951. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2952. if err != nil {
  2953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2954. return
  2955. }
  2956. }
  2957. }
  2958. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2960. return
  2961. }
  2962. //else if order.ID == 0 { //该床位没被占用
  2963. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2964. // if daySchedule.ID > 0 {
  2965. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2966. // //daySchedule.BedId = bedID
  2967. // //daySchedule.ScheduleType = schedual_type
  2968. // //daySchedule.UpdatedTime = time.Now().Unix()
  2969. // //err := service.UpdateSchedule(&daySchedule)
  2970. // xtSchedule := models.Schedule{
  2971. // PartitionId: deviceNumber.ZoneID,
  2972. // BedId: bedID,
  2973. // ScheduleType: schedual_type,
  2974. // UpdatedTime: time.Now().Unix(),
  2975. // }
  2976. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2977. // if err != nil {
  2978. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2979. // return
  2980. // }
  2981. // }
  2982. //}
  2983. //}
  2984. } else if err != nil {
  2985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2986. return
  2987. }
  2988. // 查询信息规挡的设置天数
  2989. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2990. if infor.ID > 0 && infor.WeekDay > 0 {
  2991. var cha_time int64
  2992. timeNowStr := time.Now().Format("2006-01-02")
  2993. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2994. //今日的日期减去设置的日期
  2995. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2996. if cha_time >= recordDate.Unix() {
  2997. //查询审核是否允许
  2998. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2999. //申请状态不允许的情况 拒绝修改
  3000. if infor.ApplicationStatus != 1 {
  3001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3002. return
  3003. }
  3004. }
  3005. }
  3006. dialysisRecord = &models.DialysisOrder{
  3007. DialysisDate: recordDate.Unix(),
  3008. UserOrgId: adminUserInfo.Org.Id,
  3009. PatientId: patientID,
  3010. Stage: 1,
  3011. BedID: bedID,
  3012. StartNurse: nurseID,
  3013. Status: 1,
  3014. StartTime: startDate.Unix(),
  3015. CreatedTime: time.Now().Unix(),
  3016. UpdatedTime: time.Now().Unix(),
  3017. PunctureNurse: puncture_nurse,
  3018. Creator: adminUserInfo.AdminUser.Id,
  3019. Modifier: adminUserInfo.AdminUser.Id,
  3020. SchedualType: schedual_type,
  3021. WashpipeNurse: washpipe_nurse,
  3022. ChangeNurse: change_nurse,
  3023. DifficultPunctureNurse: difficult_puncture_nurse,
  3024. NewFistulaNurse: new_fistula_nurse,
  3025. ZoneId: zone_id,
  3026. QualityNurseId: quality_nurse_id,
  3027. PunctureNeedle: puncture_needle,
  3028. PunctureWay: puncture_way,
  3029. DialysisIrrigation: dialysis_irrigation,
  3030. DialysisDialyszers: dialysis_dialyszers,
  3031. BloodAccessId: blood_access_id,
  3032. Url: elecsign,
  3033. NucleinDate: theNucleinDate,
  3034. ScheduleRemark: schedule_remark,
  3035. OrderRemark: order_remark,
  3036. CatheterOperation: catheter_operation,
  3037. BloodFlowVolume: blood_flow_volume,
  3038. BloodDrawing: blood_drawing,
  3039. DialysisStrainer: dialysis_strainer,
  3040. }
  3041. //查询该床位是否有人用了
  3042. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3043. if errorscode == gorm.ErrRecordNotFound {
  3044. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3045. finish := models.XtDialysisFinish{
  3046. IsFinish: 1,
  3047. UserOrgId: adminUserInfo.Org.Id,
  3048. Status: 1,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. Module: 6,
  3052. RecordDate: schedulestartTime,
  3053. Sourse: 1,
  3054. PatientId: patientID,
  3055. }
  3056. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3057. if dialysisFinish.ID == 0 {
  3058. service.CreateDialysisFinish(finish)
  3059. }
  3060. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3061. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3062. //统计该患者总次数
  3063. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3064. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3065. }
  3066. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3067. //统计该患者总次数
  3068. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3069. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3070. }
  3071. redis := service.RedisClient()
  3072. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3073. redis.Set(key, "", time.Second)
  3074. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3075. //清空key 值
  3076. redis.Set(keyOne, "", time.Second)
  3077. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3078. //清空key 值
  3079. redis.Set(keyTwo, "", time.Second)
  3080. if createErr != nil {
  3081. this.ErrorLog("上机失败:%v", createErr)
  3082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3083. return
  3084. }
  3085. }
  3086. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3087. var tempdispose string
  3088. // 只针对中能建
  3089. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3090. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3091. }
  3092. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3093. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3094. }
  3095. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3096. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3097. //}
  3098. var ultrafiltration_rate float64
  3099. var ultrafiltration_rate_one string
  3100. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3101. //后期预增脱水量
  3102. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3103. if prescription.ID > 0 {
  3104. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3105. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3106. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3107. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3108. }
  3109. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3110. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3111. }
  3112. //针对医师汇
  3113. if adminUserInfo.Org.Id == 10121 {
  3114. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3115. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3116. }
  3117. //针对通道
  3118. if adminUserInfo.Org.Id == 10234 {
  3119. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3120. }
  3121. //针对监利大垸医院
  3122. if template.TemplateId == 41 {
  3123. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3124. }
  3125. //针对肇庆三鹤血液透析中心
  3126. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3127. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3128. }
  3129. if adminUserInfo.Org.Id == 10469 {
  3130. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3131. }
  3132. if adminUserInfo.Org.Id == 10667 {
  3133. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3134. }
  3135. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3137. }
  3138. // 只针对方济医院
  3139. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3140. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3141. ultrafiltration_rate = value
  3142. }
  3143. //针对
  3144. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3145. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3146. ultrafiltration_rate = ultrafiltration_rate / 1000
  3147. }
  3148. if adminUserInfo.Org.Id == 10551 {
  3149. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3150. ultrafiltration_rate = ultrafiltration_rate / 1000
  3151. }
  3152. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3153. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3154. ultrafiltration_rate = ultrafiltration_rate / 1000
  3155. }
  3156. if adminUserInfo.Org.Id == 10580 {
  3157. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3158. ultrafiltration_rate = ultrafiltration_rate / 1000
  3159. }
  3160. if adminUserInfo.Org.Id == 10629 {
  3161. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3162. ultrafiltration_rate = ultrafiltration_rate / 1000
  3163. }
  3164. if adminUserInfo.Org.Id == 10644 {
  3165. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3166. ultrafiltration_rate = ultrafiltration_rate / 1000
  3167. }
  3168. if adminUserInfo.Org.Id == 10667 {
  3169. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3170. ultrafiltration_rate = ultrafiltration_rate / 1000
  3171. }
  3172. if adminUserInfo.Org.Id == 10693 {
  3173. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3174. ultrafiltration_rate = ultrafiltration_rate
  3175. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3176. }
  3177. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3178. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3179. ultrafiltration_rate = ultrafiltration_rate
  3180. }
  3181. if adminUserInfo.Org.Id == 10702 {
  3182. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3183. ultrafiltration_rate = ultrafiltration_rate / 1000
  3184. }
  3185. }
  3186. }
  3187. record := models.MonitoringRecord{
  3188. UserOrgId: adminUserInfo.Org.Id,
  3189. PatientId: patientID,
  3190. DialysisOrderId: dialysisRecord.ID,
  3191. MonitoringDate: schedulestartTime,
  3192. OperateTime: startDate.Unix(),
  3193. // MonitoringTime: recordTime,
  3194. MonitoringNurse: nurseID,
  3195. Dispose: tempdispose,
  3196. UltrafiltrationRate: ultrafiltration_rate,
  3197. UltrafiltrationVolume: 0,
  3198. Status: 1,
  3199. CreatedTime: time.Now().Unix(),
  3200. UpdatedTime: time.Now().Unix(),
  3201. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3202. }
  3203. //只针对广慈医院
  3204. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 {
  3205. // 查询病人是否有透前评估数据
  3206. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3207. //如果有数据就插入
  3208. if errcode == nil {
  3209. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3210. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3211. record.BreathingRate = befor.BreathingRate
  3212. record.PulseFrequency = befor.PulseFrequency
  3213. record.Temperature = befor.Temperature
  3214. }
  3215. }
  3216. //孝昌
  3217. if adminUserInfo.Org.Id == 10693 {
  3218. // 查询病人是否有透前评估数据
  3219. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3220. //如果有数据就插入
  3221. if errcode == nil {
  3222. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3223. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3224. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3225. record.BreathingRate = befor.BreathingRate
  3226. }
  3227. }
  3228. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3229. if newdialysisRecord.ID > 0 {
  3230. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3231. record.Temperature = 36.5
  3232. record.ArterialPressure = -100
  3233. record.DialysateTemperature = 36.5
  3234. record.Conductivity = 14
  3235. record.BreathingRate = "20"
  3236. record.VenousPressure = 80
  3237. record.TransmembranePressure = 60
  3238. record.Dispose = catheter_operation
  3239. }
  3240. //针对新化博翔
  3241. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3242. record.BloodOxygenSaturation = "99"
  3243. record.Conductivity = 14
  3244. record.DialysateTemperature = 36.5
  3245. record.BreathingRate = "20"
  3246. }
  3247. //针对兰溪人民医院的需求
  3248. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3249. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3250. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3251. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3252. record.Temperature = befor.Temperature
  3253. record.PulseFrequency = befor.PulseFrequency
  3254. record.BreathingRate = befor.BreathingRate
  3255. }
  3256. //针对乐山友谊医院的需求
  3257. if adminUserInfo.Org.Id == 10677 {
  3258. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3259. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3260. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3261. record.Temperature = befor.Temperature
  3262. record.PulseFrequency = befor.PulseFrequency
  3263. record.BreathingRate = befor.BreathingRate
  3264. }
  3265. //新化博翔
  3266. if adminUserInfo.Org.Id == 10447 {
  3267. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3268. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3269. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3270. record.BreathingRate = befor.BreathingRate
  3271. }
  3272. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3273. record.PulseFrequency = 80
  3274. record.Temperature = 36.5
  3275. }
  3276. //诊断灵山圣康
  3277. if adminUserInfo.Org.Id == 10375 {
  3278. record.Conductivity = 13.8
  3279. record.DialysateTemperature = 37
  3280. record.DialysateFlow = 500
  3281. record.BloodFlowVolume = 200
  3282. record.BreathingRate = "18"
  3283. record.SodiumConcentration = 140
  3284. }
  3285. //江成肾病医院
  3286. if adminUserInfo.Org.Id == 10517 {
  3287. record.SodiumConcentration = 138
  3288. record.DialysateTemperature = 36.5
  3289. }
  3290. if adminUserInfo.Org.Id != 10683 {
  3291. err = service.CreateMonitor(&record)
  3292. }
  3293. //记录日志
  3294. byterequest, _ := json.Marshal(record)
  3295. monitorRecordLog := models.XtMonitorRecordLog{
  3296. RecordDate: record.MonitoringDate,
  3297. PatientId: record.PatientId,
  3298. Module: 1,
  3299. AdminUserId: adminUserInfo.AdminUser.Id,
  3300. Ctime: time.Now().Unix(),
  3301. Mtime: 0,
  3302. Status: 1,
  3303. UserOrgId: record.UserOrgId,
  3304. ErrLog: string(byterequest),
  3305. Source: "执行上机时新增监测",
  3306. }
  3307. service.CreateMonitorRecordLog(monitorRecordLog)
  3308. finish := models.XtDialysisFinish{
  3309. IsFinish: 1,
  3310. UserOrgId: adminUserInfo.Org.Id,
  3311. Status: 1,
  3312. Ctime: time.Now().Unix(),
  3313. Mtime: 0,
  3314. Module: 7,
  3315. RecordDate: schedulestartTime,
  3316. Sourse: 1,
  3317. PatientId: patientID,
  3318. }
  3319. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3320. if dialysisFinish.ID == 0 {
  3321. service.CreateDialysisFinish(finish)
  3322. }
  3323. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3324. redis := service.RedisClient()
  3325. //清空key 值
  3326. redis.Set(key, "", time.Second)
  3327. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3328. redis.Set(keyOne, "", time.Second)
  3329. defer redis.Close()
  3330. if err != nil {
  3331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3332. return
  3333. }
  3334. }
  3335. go func() {
  3336. ssoDomain := beego.AppConfig.String("call_domain")
  3337. api := ssoDomain + "/index/uppatient"
  3338. values := make(url.Values)
  3339. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3340. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3341. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3342. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3343. http.PostForm(api, values)
  3344. }()
  3345. this.ServeSuccessJSON(map[string]interface{}{
  3346. "dialysis_order": newdialysisRecord,
  3347. "monitor": record,
  3348. })
  3349. return
  3350. }
  3351. func (c *DialysisAPIController) PostSolution() {
  3352. id, _ := c.GetInt64("patient", 0)
  3353. recordDateStr := c.GetString("record_date")
  3354. if id <= 0 {
  3355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3356. return
  3357. }
  3358. adminUserInfo := c.GetMobileAdminUserInfo()
  3359. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3360. if patient.ID == 0 {
  3361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3362. return
  3363. }
  3364. if len(recordDateStr) == 0 {
  3365. recordDateStr = time.Now().Format("2006-01-02")
  3366. }
  3367. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3368. if parseDateErr != nil {
  3369. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3371. return
  3372. }
  3373. mode_id, _ := c.GetInt64("mode_id", 0)
  3374. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3375. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3376. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3377. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3378. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3379. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3380. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3381. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3382. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3383. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3384. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3385. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3386. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3387. kalium, _ := c.GetFloat("kalium", 0)
  3388. sodium, _ := c.GetFloat("sodium", 0)
  3389. calcium, _ := c.GetFloat("calcium", 0)
  3390. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3391. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3392. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3393. glucose, _ := c.GetFloat("glucose", 0)
  3394. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3395. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3396. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3397. conductivity, _ := c.GetFloat("conductivity", 0)
  3398. remark := c.GetString("remark")
  3399. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3400. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3401. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3402. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3403. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3404. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3405. special_medicine_other := c.GetString("special_medicine_other")
  3406. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3407. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3408. blood_access, _ := c.GetInt64("blood_access", 0)
  3409. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3410. body_fluid_other := c.GetString("body_fluid_other")
  3411. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3412. niprocart, _ := c.GetInt64("niprocart", 0)
  3413. jms, _ := c.GetInt64("jms", 0)
  3414. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3415. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3416. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3417. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3418. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3419. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3420. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3421. injector, _ := c.GetInt64("injector", 0)
  3422. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3423. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3424. safe_package, _ := c.GetInt64("package", 0)
  3425. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3426. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3427. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3428. blood := c.GetString("blood")
  3429. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3430. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3431. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3432. displace_speed := c.GetString("displace_speed")
  3433. illness, _ := c.GetInt64("illness")
  3434. amylaceum := c.GetString("amylaceum")
  3435. single_time := c.GetString("single_time")
  3436. single_water := c.GetString("single_water")
  3437. replacement_flow := c.GetString("replacement_flow")
  3438. plasma_separator := c.GetString("plasma_separator")
  3439. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3440. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3441. oxygen_flow := c.GetString("oxygen_flow")
  3442. oxygen_time := c.GetString("oxygen_time")
  3443. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3444. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3445. puncture_needle := c.GetString("puncture_needle")
  3446. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3447. epo := c.GetString("epo")
  3448. epo_count, _ := c.GetFloat("epo_count", 0)
  3449. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3450. pre_impulse := c.GetString("pre_impulse")
  3451. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3452. admin_user_id, _ := c.GetInt64("admin_user_id")
  3453. is_water := c.GetString("is_water")
  3454. add_amount, _ := c.GetFloat("add_amount")
  3455. reduce_amount, _ := c.GetFloat("reduce_amount")
  3456. prescribing_number, _ := c.GetFloat("prescribing_number")
  3457. treatment_remark := c.GetString("treatment_remark")
  3458. prescription_sodium := c.GetString("prescription_sodium")
  3459. start_sodium := c.GetString("start_sodium")
  3460. sodium_curve := c.GetString("sodium_curve")
  3461. var is_war int64
  3462. if is_water == "是" {
  3463. is_war = 1
  3464. }
  3465. if is_water == "否" {
  3466. is_war = 2
  3467. }
  3468. if is_water == "请选择" {
  3469. is_war = 0
  3470. }
  3471. drhy_water := c.GetString("drhy_water")
  3472. dry_water_hour := c.GetString("dry_water_hour")
  3473. water_machine := c.GetString("water_machine")
  3474. dialysis_remark := c.GetString("dialysis_remark")
  3475. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3476. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3477. prescription_water, _ := c.GetFloat("prescription_water")
  3478. dialysis_strainer := c.GetString("dialysis_strainer")
  3479. chaptalization := c.GetString("chaptalization")
  3480. washing_time := c.GetString("washing_time")
  3481. warsh_count := c.GetString("warsh_count")
  3482. blood_access_part_id := c.GetString("blood_access_part_id")
  3483. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3484. dialyzate := c.GetString("dialyzate")
  3485. if mode_id > 0 {
  3486. var str string
  3487. //查找该机构用的是什么透析器
  3488. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3489. if filedConfig.ID > 0 {
  3490. str = dialyzerPerfusionApparatus
  3491. } else {
  3492. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3493. }
  3494. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3495. }
  3496. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3497. //
  3498. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3499. // if appRole.UserType == 3 {
  3500. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3501. // if getPermissionErr != nil {
  3502. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3503. // return
  3504. // } else if headNursePermission == nil {
  3505. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3506. // return
  3507. // }
  3508. // }
  3509. //}
  3510. // 查询信息规挡的设置天数
  3511. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3512. if infor.ID > 0 && infor.WeekDay > 0 {
  3513. var cha_time int64
  3514. timeNowStr := time.Now().Format("2006-01-02")
  3515. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3516. //今日的日期减去设置的日期
  3517. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3518. if cha_time >= recordDate.Unix() {
  3519. //查询审核是否允许
  3520. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3521. //申请状态不允许的情况 拒绝修改
  3522. if infor.ApplicationStatus != 1 {
  3523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3524. return
  3525. }
  3526. }
  3527. }
  3528. prescription := models.DialysisPrescription{
  3529. UserOrgId: adminUserInfo.Org.Id,
  3530. PatientId: id,
  3531. RecordDate: recordDate.Unix(),
  3532. ModeId: mode_id,
  3533. DialysisDuration: dialysis_duration,
  3534. Dialyzer: dialyzer,
  3535. PerfusionApparatus: perfusion_apparatus,
  3536. BloodFlowVolume: blood_flow_volume,
  3537. DewaterAmount: dewater_amount,
  3538. DisplaceLiqui: displace_liqui,
  3539. ReplacementWay: replacement_way,
  3540. Anticoagulant: anticoagulant,
  3541. AnticoagulantShouji: anticoagulant_shouji,
  3542. AnticoagulantWeichi: anticoagulant_weichi,
  3543. AnticoagulantZongliang: anticoagulant_zongliang,
  3544. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3545. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3546. Kalium: kalium,
  3547. Sodium: sodium,
  3548. Calcium: calcium,
  3549. Bicarbonate: bicarbonate,
  3550. Glucose: glucose,
  3551. // DryWeight: dry_weight,
  3552. DialysateFlow: dialysate_flow,
  3553. DialysateTemperature: dialysate_temperature,
  3554. Conductivity: conductivity,
  3555. Remark: remark,
  3556. Status: 1,
  3557. CreatedTime: time.Now().Unix(),
  3558. UpdatedTime: time.Now().Unix(),
  3559. DialysisDurationMinute: dialysisDurationMinute,
  3560. DialysisDurationHour: dialysisDurationHour,
  3561. TargetUltrafiltration: targetUltrafiltration,
  3562. DialysateFormulation: dialysateFormulation,
  3563. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3564. BodyFluid: body_fluid,
  3565. SpecialMedicine: special_medicine,
  3566. SpecialMedicineOther: special_medicine_other,
  3567. DisplaceLiquiPart: displace_liqui_part,
  3568. DisplaceLiquiValue: displace_liqui_value,
  3569. BloodAccess: blood_access,
  3570. Ultrafiltration: ultrafiltration,
  3571. BodyFluidOther: body_fluid_other,
  3572. ReplacementTotal: replacement_total,
  3573. Niprocart: niprocart,
  3574. Jms: jms,
  3575. FistulaNeedleSet: fistula_needle_set,
  3576. FistulaNeedleSet16: fistula_needle_set_16,
  3577. Hemoperfusion: hemoperfusion,
  3578. DialyserSterilised: dialyser_sterilised,
  3579. Filtryzer: filtryzer,
  3580. TargetKtv: target_ktv,
  3581. Dialyzers: dialyzers,
  3582. Injector: injector,
  3583. Bloodlines: bloodlines,
  3584. TubingHemodialysis: tubing_hemodialysis,
  3585. Package: safe_package,
  3586. ALiquid: a_liquid,
  3587. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3588. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3589. Blood: blood,
  3590. DialysisDialyszers: dialysis_dialyszers,
  3591. DialysisIrrigation: dialysis_irrigation,
  3592. AntioxidantCommodityName: antioxidant_commodity_name,
  3593. DisplaceSpeed: displace_speed,
  3594. Illness: illness,
  3595. Amylaceum: amylaceum,
  3596. SingleWater: single_water,
  3597. SingleTime: single_time,
  3598. ReplacementFlow: replacement_flow,
  3599. PlasmaSeparator: plasma_separator,
  3600. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3601. OxygenUptake: oxygen_uptake,
  3602. OxygenTime: oxygen_time,
  3603. OxygenFlow: oxygen_flow,
  3604. HemodialysisPipelines: hemodialysis_pipelines,
  3605. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3606. PunctureNeedle: puncture_needle,
  3607. PunctureNeedleCount: puncture_needle_count,
  3608. Epo: epo,
  3609. EpoCount: epo_count,
  3610. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3611. PreImpulse: impulse,
  3612. AdminUserId: admin_user_id,
  3613. IsWater: is_war,
  3614. DrhyWater: drhy_water,
  3615. DryWaterHour: dry_water_hour,
  3616. WaterMachine: water_machine,
  3617. AddAmount: add_amount,
  3618. ReduceAmount: reduce_amount,
  3619. DialysisRemark: dialysis_remark,
  3620. PrescribingNumber: prescribing_number,
  3621. PrescriptionSodium: prescription_sodium,
  3622. StartSodium: start_sodium,
  3623. SodiumCurve: sodium_curve,
  3624. TreatmentRemark: treatment_remark,
  3625. DialysisFluidFlow: dialysis_fluid_flow,
  3626. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3627. PrescriptionWater: prescription_water,
  3628. DialysisStrainer: dialysis_strainer,
  3629. Chaptalization: chaptalization,
  3630. WashingTime: washing_time,
  3631. WarshCount: warsh_count,
  3632. BloodAccessPartId: blood_access_part_id,
  3633. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3634. Dialyzate: dialyzate,
  3635. }
  3636. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3637. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3638. //
  3639. if appRole.UserType == 2 || appRole.UserType == 1 {
  3640. prescription_doctor = adminUserInfo.AdminUser.Id
  3641. prescription.PrescriptionDoctor = prescription_doctor
  3642. }
  3643. if dialysisPrescription.ID == 0 { //新增
  3644. prescription.Creater = adminUserInfo.AdminUser.Id
  3645. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3646. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3647. }
  3648. } else { //修改
  3649. if dialysisPrescription.Creater == 0 {
  3650. prescription.Creater = adminUserInfo.AdminUser.Id
  3651. } else {
  3652. prescription.Creater = dialysisPrescription.Creater
  3653. if adminUserInfo.Org.Id == 9882 {
  3654. if appRole.UserType == 2 || appRole.UserType == 1 {
  3655. prescription.Creater = adminUserInfo.AdminUser.Id
  3656. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3657. }
  3658. }
  3659. }
  3660. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3661. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3662. }
  3663. //if/**/
  3664. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3665. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3666. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3667. // if getPermissionErr != nil {
  3668. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3669. // return
  3670. // } else if headNursePermission == nil {
  3671. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3672. // return
  3673. // }
  3674. //}
  3675. //prescription.Creater = dialysisPrescription.Creater
  3676. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3677. prescription.Modifier = adminUserInfo.AdminUser.Id
  3678. prescription.ID = dialysisPrescription.ID
  3679. }
  3680. solution := models.DialysisSolution{
  3681. RegistrarsId: adminUserInfo.AdminUser.Id,
  3682. UserOrgId: adminUserInfo.Org.Id,
  3683. Doctor: prescription_doctor,
  3684. PatientId: id,
  3685. ModeId: mode_id,
  3686. DialysisDuration: dialysis_duration,
  3687. PerfusionApparatus: perfusion_apparatus,
  3688. BloodFlowVolume: blood_flow_volume,
  3689. Dewater: dewater_amount,
  3690. DisplaceLiqui: displace_liqui,
  3691. ReplacementWay: replacement_way,
  3692. Anticoagulant: anticoagulant,
  3693. AnticoagulantShouji: anticoagulant_shouji,
  3694. AnticoagulantWeichi: anticoagulant_weichi,
  3695. AnticoagulantZongliang: anticoagulant_zongliang,
  3696. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3697. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3698. Kalium: kalium,
  3699. Sodium: sodium,
  3700. Calcium: calcium,
  3701. Bicarbonate: bicarbonate,
  3702. Glucose: glucose,
  3703. // DryWeight: dry_weight,
  3704. DialysateFlow: dialysate_flow,
  3705. DialysateTemperature: dialysate_temperature,
  3706. Conductivity: conductivity,
  3707. Remark: remark,
  3708. Status: 1,
  3709. CreatedTime: time.Now().Unix(),
  3710. UpdatedTime: time.Now().Unix(),
  3711. DialysisDurationMinute: dialysisDurationMinute,
  3712. DialysisDurationHour: dialysisDurationHour,
  3713. TargetUltrafiltration: targetUltrafiltration,
  3714. DialysateFormulation: dialysateFormulation,
  3715. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3716. BodyFluid: body_fluid,
  3717. SpecialMedicine: special_medicine,
  3718. SpecialMedicineOther: special_medicine_other,
  3719. DisplaceLiquiPart: displace_liqui_part,
  3720. DisplaceLiquiValue: displace_liqui_value,
  3721. BloodAccess: blood_access,
  3722. Ultrafiltration: ultrafiltration,
  3723. BodyFluidOther: body_fluid_other,
  3724. ReplacementTotal: replacement_total,
  3725. TargetKtv: target_ktv,
  3726. DialysisDialyszers: dialysis_dialyszers,
  3727. DialysisIrrigation: dialysis_irrigation,
  3728. HemodialysisPipelines: hemodialysis_pipelines,
  3729. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3730. PunctureNeedle: puncture_needle,
  3731. PunctureNeedleCount: puncture_needle_count,
  3732. Epo: epo,
  3733. EpoCount: epo_count,
  3734. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3735. PreImpulse: impulse,
  3736. SolutionStatus: 1,
  3737. DialysisRemark: dialysis_remark,
  3738. PrescribingNumber: prescribing_number,
  3739. PrescriptionSodium: prescription_sodium,
  3740. StartSodium: start_sodium,
  3741. SodiumCurve: sodium_curve,
  3742. TreatmentRemark: treatment_remark,
  3743. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3744. DialysisFluidFlow: dialysis_fluid_flow,
  3745. PrescriptionWater: prescription_water,
  3746. DialysisStrainer: dialysis_strainer,
  3747. Chaptalization: chaptalization,
  3748. WashingTime: washing_time,
  3749. WarshCount: warsh_count,
  3750. BloodAccessPartId: blood_access_part_id,
  3751. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3752. Dialyzate: dialyzate,
  3753. }
  3754. //针对河间咸的
  3755. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3756. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3757. solution.DisplaceLiquiPart = 0
  3758. solution.DisplaceLiquiValue = 0
  3759. }
  3760. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3761. prescription.DisplaceLiquiPart = 0
  3762. prescription.DisplaceLiquiValue = 0
  3763. }
  3764. }
  3765. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3766. if solution.PrescribingNumber == 0 {
  3767. solution.PrescribingNumber = 1
  3768. }
  3769. if prescription.PrescribingNumber == 0 {
  3770. prescription.PrescribingNumber = 1
  3771. }
  3772. if solution.PrescribingNumber == 0 && id == 14682 {
  3773. solution.PrescribingNumber = 2
  3774. }
  3775. if solution.PrescribingNumber == 0 && id == 18560 {
  3776. solution.PrescribingNumber = 2
  3777. }
  3778. if prescription.PrescribingNumber == 0 && id == 14682 {
  3779. prescription.PrescribingNumber = 2
  3780. }
  3781. if prescription.PrescribingNumber == 0 && id == 18560 {
  3782. prescription.PrescribingNumber = 2
  3783. }
  3784. }
  3785. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3786. //记录日志
  3787. byterequest, _ := json.Marshal(prescription)
  3788. prescriptionLog := models.XtDialysisPrescriptionLog{
  3789. UserOrgId: prescription.UserOrgId,
  3790. Ctime: time.Now().Unix(),
  3791. Mtime: 0,
  3792. ErrLog: string(byterequest),
  3793. AdminUserId: adminUserInfo.AdminUser.Id,
  3794. RecordDate: prescription.RecordDate,
  3795. PatientId: prescription.PatientId,
  3796. Source: "手机端新增长期处方",
  3797. Status: 1,
  3798. }
  3799. service.CreatePrescriptionLog(prescriptionLog)
  3800. finish := models.XtDialysisFinish{
  3801. IsFinish: 1,
  3802. UserOrgId: adminUserInfo.Org.Id,
  3803. Status: 1,
  3804. Ctime: time.Now().Unix(),
  3805. Mtime: 0,
  3806. Module: 1,
  3807. RecordDate: recordDate.Unix(),
  3808. Sourse: 1,
  3809. PatientId: id,
  3810. }
  3811. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3812. if dialysisFinish.ID == 0 {
  3813. service.CreateDialysisFinish(finish)
  3814. }
  3815. //获取最新1条
  3816. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3817. //更新状态
  3818. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3819. //长沙南雅医院,自动生成抗凝剂的临时处方
  3820. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3821. if prescribing_number == 0 {
  3822. prescribing_number = 1
  3823. }
  3824. advice := models.DoctorAdvice{
  3825. UserOrgId: adminUserInfo.Org.Id,
  3826. PatientId: id,
  3827. GroupNo: 0,
  3828. AdviceType: 2,
  3829. RecordDate: recordDate.Unix(),
  3830. AdviceDate: recordDate.Unix(),
  3831. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3832. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3833. AdviceDesc: "",
  3834. ReminderDate: 0,
  3835. SingleDose: prescription.AnticoagulantZongliang,
  3836. SingleDoseUnit: "iu",
  3837. DrugSpec: 0,
  3838. DrugSpecUnit: "",
  3839. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3840. PrescribingNumberUnit: "支",
  3841. DeliveryWay: "静脉注射",
  3842. ExecutionFrequency: "上机前",
  3843. AdviceDoctor: 0,
  3844. Status: 1,
  3845. CreatedTime: time.Now().Unix(),
  3846. UpdatedTime: time.Now().Unix(),
  3847. IsPrescription: 1,
  3848. ExecutionState: 2,
  3849. StopState: 2,
  3850. IsSettle: 2,
  3851. }
  3852. // 查询排班信息
  3853. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3854. if schedulePatient.ID > 0 {
  3855. if schedulePatient.ScheduleType == 1 {
  3856. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3857. }
  3858. if schedulePatient.ScheduleType == 2 {
  3859. advice.StartTime = recordDate.Unix() + 9*60*60
  3860. }
  3861. }
  3862. // 抗凝剂名称
  3863. switch anticoagulant {
  3864. case 1:
  3865. advice.AdviceName = "无肝素"
  3866. break
  3867. case 2:
  3868. advice.AdviceName = "普通肝素"
  3869. break
  3870. case 3:
  3871. advice.AdviceName = "低分子肝素"
  3872. break
  3873. case 4:
  3874. advice.AdviceName = "阿加曲班"
  3875. break
  3876. case 5:
  3877. advice.AdviceName = "枸橼酸钠"
  3878. break
  3879. case 6:
  3880. advice.AdviceName = "低分子肝素钙"
  3881. break
  3882. case 7:
  3883. advice.AdviceName = "低分子肝素钠"
  3884. break
  3885. case 8:
  3886. advice.AdviceName = "依诺肝素"
  3887. break
  3888. case 9:
  3889. advice.AdviceName = "达肝素"
  3890. break
  3891. case 10:
  3892. advice.AdviceName = "体外抗凝"
  3893. break
  3894. case 11:
  3895. advice.AdviceName = "那曲肝素"
  3896. break
  3897. case 12:
  3898. advice.AdviceName = "无抗凝剂"
  3899. break
  3900. }
  3901. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3902. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3903. advice.AdviceDoctor = appRole.AdminUserId
  3904. }
  3905. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3906. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3907. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3908. advice.AdviceName = "低分子肝素钠注射液"
  3909. // 修改患者临时医嘱里的抗凝剂医嘱
  3910. advice.ID = advicePrescription.ID
  3911. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3912. } else {
  3913. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3914. advice.AdviceName = "低分子肝素钠注射液"
  3915. service.CreateDoctorAdvice(&advice)
  3916. }
  3917. }
  3918. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3919. redis := service.RedisClient()
  3920. defer redis.Close()
  3921. //清空key 值
  3922. redis.Set(key, "", time.Second)
  3923. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3924. redis.Set(keyOne, "", time.Second)
  3925. }
  3926. //获取key,清空redis
  3927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3928. redis := service.RedisClient()
  3929. defer redis.Close()
  3930. //清空key 值
  3931. redis.Set(key, "", time.Second)
  3932. //清空长期医嘱的key
  3933. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3934. redis.Set(soulution_key, "", time.Second)
  3935. //查询最近透析准备表里是否存在 透析器 灌流器
  3936. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3937. redis.Set(keyOne, "", time.Second)
  3938. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3939. redis.Set(keyTwo, "", time.Second)
  3940. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3941. redis.Set(keyThree, "", time.Second)
  3942. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3943. redis.Set(keyFour, "", time.Second)
  3944. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3945. //
  3946. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3947. //
  3948. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3949. //if len(mation)>0{
  3950. // for _, item := range splitStr {
  3951. // for _,it := range mation{
  3952. // if(item == it.SpecificationName){
  3953. //
  3954. // //查询最近一次的透析器
  3955. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3956. //
  3957. // if errcode == gorm.ErrRecordNotFound{
  3958. // //插入数据
  3959. // prepare := models.DialysisBeforePrepare{
  3960. // UserOrgId: adminUserInfo.Org.Id,
  3961. // PatientId: id,
  3962. // RecordDate: recordDate.Unix(),
  3963. // GoodTypeId: it.GoodTypeId,
  3964. // GoodId: it.ID,
  3965. // Count: 1,
  3966. // Ctime: time.Now().Unix(),
  3967. // Creater: adminUserInfo.AdminUser.Id,
  3968. // Status:1,
  3969. //
  3970. // }
  3971. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3972. // fmt.Println("",errcode)
  3973. // }
  3974. // }
  3975. // }
  3976. //
  3977. // }
  3978. //
  3979. // for _, item := range splitIrrigation {
  3980. // for _,it := range mation{
  3981. // if(item == it.SpecificationName){
  3982. // //查询最近一次的透析器
  3983. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3984. // if errcode == gorm.ErrRecordNotFound{
  3985. // //插入数据
  3986. // prepare := models.DialysisBeforePrepare{
  3987. // UserOrgId: adminUserInfo.Org.Id,
  3988. // PatientId: id,
  3989. // RecordDate: recordDate.Unix(),
  3990. // GoodTypeId: it.GoodTypeId,
  3991. // GoodId: it.ID,
  3992. // Count: 1,
  3993. // Ctime: time.Now().Unix(),
  3994. // Creater: adminUserInfo.AdminUser.Id,
  3995. // Status:1,
  3996. //
  3997. // }
  3998. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3999. // fmt.Println(errcode)
  4000. // }
  4001. // }
  4002. // }
  4003. // }
  4004. //}
  4005. c.ServeSuccessJSON(map[string]interface{}{
  4006. "solution": &solution,
  4007. "prescription": &prescription,
  4008. })
  4009. }
  4010. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4011. patient, _ := c.GetInt64("patient", 0)
  4012. adminUserInfo := c.GetMobileAdminUserInfo()
  4013. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4014. c.ServeSuccessJSON(map[string]interface{}{
  4015. "receiveTreatmentAsses": receiveTreatmentAsses,
  4016. })
  4017. }
  4018. func (this *DialysisAPIController) PostSignInfo() {
  4019. patientID, _ := this.GetInt64("patient_id")
  4020. recordDateStr := this.GetString("date")
  4021. if patientID <= 0 {
  4022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4023. return
  4024. }
  4025. if len(recordDateStr) == 0 {
  4026. recordDateStr = time.Now().Format("2006-01-02")
  4027. }
  4028. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4029. if parseDateErr != nil {
  4030. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4031. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4032. return
  4033. }
  4034. adminInfo := this.GetMobileAdminUserInfo()
  4035. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4036. if err != nil {
  4037. this.ErrorLog("签名失败:%v", err)
  4038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4039. return
  4040. }
  4041. this.ServeSuccessJSON(map[string]interface{}{
  4042. "doctor_id": adminInfo.AdminUser.Id,
  4043. })
  4044. }
  4045. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4046. patientID, _ := this.GetInt64("patient_id")
  4047. adminInfo := this.GetMobileAdminUserInfo()
  4048. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4049. this.ServeSuccessJSON(map[string]interface{}{
  4050. "monitor": record,
  4051. })
  4052. }
  4053. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4054. thisTime := time.Now()
  4055. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4056. timeLayout := "2006-01-02 15:04:05"
  4057. loc, _ := time.LoadLocation("Local")
  4058. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4059. theAssessmentDateTime := theStartTime.Unix()
  4060. patientID, _ := this.GetInt64("patient_id")
  4061. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4062. adminInfo := this.GetMobileAdminUserInfo()
  4063. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4064. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4065. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4066. var ultrafiltration_rate float64
  4067. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4068. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4069. fmt.Println(evaluation)
  4070. fmt.Println("prescription.ID", prescription.ID)
  4071. if prescription.ID > 0 {
  4072. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4073. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4074. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4075. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4076. record.UltrafiltrationRate = ultrafiltration_rate
  4077. }
  4078. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4079. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4080. record.UltrafiltrationRate = ultrafiltration_rate
  4081. }
  4082. if adminInfo.Org.Id == 10510 {
  4083. record.UltrafiltrationRate = 0
  4084. }
  4085. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4086. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4087. record.UltrafiltrationRate = ultrafiltration_rate
  4088. }
  4089. if template.TemplateId == 20 || template.TemplateId == 22 {
  4090. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4091. record.UltrafiltrationRate = ultrafiltration_rate
  4092. }
  4093. // 只针对方济医院
  4094. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4095. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4096. ultrafiltration_rate = value
  4097. record.UltrafiltrationRate = ultrafiltration_rate
  4098. }
  4099. if template.TemplateId == 41 || template.TemplateId == 47 {
  4100. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4101. record.UltrafiltrationRate = ultrafiltration_rate
  4102. }
  4103. if template.TemplateId == 43 {
  4104. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4105. record.UltrafiltrationRate = ultrafiltration_rate
  4106. }
  4107. if template.TemplateId == 46 || template.TemplateId == 54 {
  4108. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4109. record.UltrafiltrationRate = ultrafiltration_rate
  4110. }
  4111. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  4112. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4113. record.UltrafiltrationRate = ultrafiltration_rate
  4114. }
  4115. if adminInfo.Org.Id == 10469 {
  4116. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4117. record.UltrafiltrationRate = ultrafiltration_rate
  4118. }
  4119. if adminInfo.Org.Id == 10667 {
  4120. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4121. record.UltrafiltrationRate = ultrafiltration_rate
  4122. }
  4123. if adminInfo.Org.Id == 10471 {
  4124. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4125. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4126. }
  4127. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4128. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4129. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4130. }
  4131. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4132. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4133. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4134. }
  4135. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4136. record.UltrafiltrationRate = 0
  4137. }
  4138. //if template.TemplateId == 47 {
  4139. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4140. // record.UltrafiltrationRate = ultrafiltration_rate
  4141. //}
  4142. }
  4143. }
  4144. // record.UltrafiltrationRate = ultrafiltration_rate
  4145. record.UltrafiltrationVolume = 0
  4146. 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
  4147. if ultrafiltration_rate > 0 {
  4148. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4149. record.UltrafiltrationVolume = value
  4150. }
  4151. }
  4152. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  4153. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4154. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4155. record.UltrafiltrationVolume = ultrafiltration_volume
  4156. }
  4157. }
  4158. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4159. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4160. record.UltrafiltrationVolume = ultrafiltration_volume
  4161. }
  4162. //长沙南雅
  4163. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  4164. if ultrafiltration_rate > 0 {
  4165. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4166. record.UltrafiltrationVolume = ultrafiltration_volume
  4167. }
  4168. }
  4169. if adminInfo.Org.Id == 10471 {
  4170. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4171. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4172. }
  4173. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4174. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4175. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4176. }
  4177. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4178. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4179. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4180. }
  4181. //长沙南雅累计血容量自动计算
  4182. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4183. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4184. //}
  4185. if template.TemplateId == 47 || template.TemplateId == 54 {
  4186. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4187. }
  4188. if adminInfo.Org.Id == 10510 {
  4189. record.UltrafiltrationVolume = 0
  4190. }
  4191. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4192. this.ServeSuccessJSON(map[string]interface{}{
  4193. "monitor": record,
  4194. "lastMonitorRecordList": lastMonitorRecordList,
  4195. })
  4196. }
  4197. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4198. record_id, _ := this.GetInt64("id")
  4199. nurseID, _ := this.GetInt64("start_nurse")
  4200. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4201. bedID, _ := this.GetInt64("bed")
  4202. start_time := this.GetString("start_time")
  4203. schedual_type, _ := this.GetInt64("schedual_type")
  4204. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4205. change_nurse, _ := this.GetInt64("change_nurse")
  4206. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4207. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4208. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4209. patient_id, _ := this.GetInt64("patient_id")
  4210. record_date, _ := this.GetInt64("record_date")
  4211. puncture_needle := this.GetString("puncture_needle")
  4212. puncture_way := this.GetString("puncture_way")
  4213. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4214. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4215. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4216. nuclein_date_str := this.GetString("nuclein_date_str")
  4217. order_remark := this.GetString("order_remark")
  4218. schedule_remark := this.GetString("schedule_remark")
  4219. catheter_operation := this.GetString("catheter_operation")
  4220. blood_flow_volume := this.GetString("blood_flow_volume")
  4221. blood_drawing, _ := this.GetInt64("blood_drawing")
  4222. dialysis_strainer := this.GetString("dialysis_strainer")
  4223. if record_id == 0 {
  4224. this.ErrorLog("id:%v", record_id)
  4225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4226. return
  4227. }
  4228. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4229. if parseStartDateErr != nil {
  4230. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4232. return
  4233. }
  4234. adminUserInfo := this.GetMobileAdminUserInfo()
  4235. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4236. if getNurseErr != nil {
  4237. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4239. return
  4240. } else if nurse == nil {
  4241. this.ErrorLog("护士不存在")
  4242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4243. return
  4244. }
  4245. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4246. //if getNurseErr != nil {
  4247. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4248. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4249. // return
  4250. //} else if nurse == nil {
  4251. // this.ErrorLog("护士不存在")
  4252. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4253. // return
  4254. //}
  4255. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4256. if getDeviceNumberErr != nil {
  4257. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4258. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4259. return
  4260. } else if deviceNumber == nil {
  4261. this.ErrorLog("床位号不存在")
  4262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4263. return
  4264. }
  4265. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4266. //
  4267. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4268. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4269. // if getPermissionErr != nil {
  4270. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4271. // return
  4272. // } else if headNursePermission == nil {
  4273. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4274. // return
  4275. // }
  4276. //}
  4277. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4278. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4279. timeLayout := "2006-01-02 15:04:05"
  4280. loc, _ := time.LoadLocation("Local")
  4281. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4282. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4283. schedulestartTime := theStartTime.Unix()
  4284. scheduleendTime := theEndTime.Unix()
  4285. var theNucleinDate int64
  4286. timeLayoutOne := "2006-01-02"
  4287. if len(nuclein_date_str) > 0 {
  4288. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4289. if err != nil {
  4290. utils.ErrorLog(err.Error())
  4291. }
  4292. theNucleinDate = theTime.Unix()
  4293. }
  4294. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4295. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4296. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4297. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4298. if err == gorm.ErrRecordNotFound { //空床位
  4299. // 修改了床位逻辑
  4300. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4301. if daySchedule.ID > 0 {
  4302. //daySchedule.BedId = bedID
  4303. //daySchedule.PartitionId = deviceNumber.ZoneID
  4304. //daySchedule.ScheduleType = schedual_type
  4305. //daySchedule.UpdatedTime = time.Now().Unix()
  4306. //err := service.UpdateSchedule(&daySchedule)
  4307. xtSchedule := models.Schedule{
  4308. PartitionId: deviceNumber.ZoneID,
  4309. BedId: bedID,
  4310. ScheduleType: schedual_type,
  4311. UpdatedTime: time.Now().Unix(),
  4312. }
  4313. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4314. if err != nil {
  4315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4316. return
  4317. }
  4318. }
  4319. } else if err == nil {
  4320. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4321. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4322. if daySchedule.ID > 0 {
  4323. //daySchedule.BedId = bedID
  4324. //daySchedule.PartitionId = deviceNumber.ZoneID
  4325. //
  4326. //daySchedule.ScheduleType = schedual_type
  4327. //daySchedule.UpdatedTime = time.Now().Unix()
  4328. //err := service.UpdateSchedule(&daySchedule)
  4329. xtSchedule := models.Schedule{
  4330. PartitionId: deviceNumber.ZoneID,
  4331. BedId: bedID,
  4332. ScheduleType: schedual_type,
  4333. UpdatedTime: time.Now().Unix(),
  4334. }
  4335. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4336. if err != nil {
  4337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4338. return
  4339. }
  4340. }
  4341. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4343. return
  4344. }
  4345. } else if err != nil {
  4346. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4347. return
  4348. }
  4349. }
  4350. dialysisRecord := &models.DialysisOrder{
  4351. ID: record_id,
  4352. UserOrgId: adminUserInfo.Org.Id,
  4353. BedID: bedID,
  4354. StartNurse: nurseID,
  4355. StartTime: startDate.Unix(),
  4356. PunctureNurse: puncture_nurse,
  4357. Creator: adminUserInfo.AdminUser.Id,
  4358. Modifier: adminUserInfo.AdminUser.Id,
  4359. WashpipeNurse: washpipe_nurse,
  4360. SchedualType: schedual_type,
  4361. ChangeNurse: change_nurse,
  4362. DifficultPunctureNurse: difficult_puncture_nurse,
  4363. NewFistulaNurse: new_fistula_nurse,
  4364. QualityNurseId: quality_nurse_id,
  4365. PunctureNeedle: puncture_needle,
  4366. PunctureWay: puncture_way,
  4367. DialysisDialyszers: dialysis_dialyszers,
  4368. DialysisIrrigation: dialysis_irrigation,
  4369. BloodAccessId: blood_access_id,
  4370. NucleinDate: theNucleinDate,
  4371. OrderRemark: order_remark,
  4372. ScheduleRemark: schedule_remark,
  4373. CatheterOperation: catheter_operation,
  4374. BloodFlowVolume: blood_flow_volume,
  4375. BloodDrawing: blood_drawing,
  4376. DialysisStrainer: dialysis_strainer,
  4377. }
  4378. //修改床位号需要重新消毒
  4379. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4380. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4381. //查询第一条监测
  4382. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4383. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4384. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4385. redis := service.RedisClient()
  4386. //清空key 值
  4387. redis.Set(key, "", time.Second)
  4388. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4389. redis.Set(keyOne, "", time.Second)
  4390. defer redis.Close()
  4391. }
  4392. // 查询信息规挡的设置天数
  4393. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4394. if infor.ID > 0 && infor.WeekDay > 0 {
  4395. var cha_time int64
  4396. timeNowStr := time.Now().Format("2006-01-02")
  4397. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4398. //今日的日期减去设置的日期
  4399. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4400. if cha_time >= record_date {
  4401. //查询审核是否允许
  4402. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4403. //申请状态不允许的情况 拒绝修改
  4404. if infor.ApplicationStatus != 1 {
  4405. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4406. return
  4407. }
  4408. }
  4409. }
  4410. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4411. //修改床位后重新生成消毒计划
  4412. if adminUserInfo.Org.Id == 10340 {
  4413. //根据床位号获取设备型号
  4414. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4415. //查询使用消毒最后一条消毒记录
  4416. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4417. fmt.Println("err", err)
  4418. if err == gorm.ErrRecordNotFound {
  4419. //查找排班
  4420. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4421. //查询改设备是否有消毒计划
  4422. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4423. //根据床位号获取设备id
  4424. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4425. //查询病人信息
  4426. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4427. var con = ""
  4428. if patients.IsInfectious == 0 {
  4429. con = ""
  4430. }
  4431. if patients.IsInfectious == 1 {
  4432. con = "无"
  4433. }
  4434. if patients.IsInfectious == 2 {
  4435. con = "有"
  4436. }
  4437. if errcode == nil {
  4438. var end_time int64
  4439. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4440. //新增消毒
  4441. information := models.DeviceInformation{
  4442. Date: dialysisRecord.DialysisDate,
  4443. Zone: dialysisRecord.ZoneId,
  4444. Class: dialysisRecord.SchedualType,
  4445. BedNumber: dialysisRecord.BedID,
  4446. PatientId: dialysisRecord.PatientId,
  4447. DialysisMode: scheduleByPatient.ModeId,
  4448. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4449. Disinfection: 1,
  4450. DialysisConcentration: 1,
  4451. DisinfectionStatus: 1,
  4452. Move: 1,
  4453. UserOrgId: dialysisRecord.UserOrgId,
  4454. DisinfectType: plan.Way,
  4455. DisinfectantType: plan.MachineDisinfectant,
  4456. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4457. Disinfectant: plan.Disinfectant,
  4458. Ctime: time.Now().Unix(),
  4459. Status: 1,
  4460. SignName: nurseID,
  4461. EquimentId: addmacher.ID,
  4462. DisinfectionResidue: 2,
  4463. Bed: addmacher.BedNumber,
  4464. StartTime: dialysisRecord.StartTime,
  4465. EndTime: dialysisRecord.EndTime,
  4466. Contagion: con,
  4467. WeightLoss: 0,
  4468. Hyperfiltratio: 0,
  4469. DialysisHour: "",
  4470. MachineRun: 1,
  4471. DisinfecStartime: dialysisRecord.EndTime,
  4472. DisinfecEndtime: end_time,
  4473. }
  4474. err := service.CreateInformationTwo(&information)
  4475. fmt.Println("报错", err)
  4476. }
  4477. }
  4478. }
  4479. order, _ := service.GetLastPatientOrder(record_id)
  4480. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4481. redis := service.RedisClient()
  4482. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4483. redis.Set(key, "", time.Second)
  4484. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4485. //清空key 值
  4486. redis.Set(keyOne, "", time.Second)
  4487. scheduleDateStartOne := startDate.Format("2006-01-02")
  4488. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4489. redis.Set(keyTwo, "", time.Second)
  4490. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4491. redis.Set(keyThree, "", time.Second)
  4492. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4493. redis.Set(keyFour, "", time.Second)
  4494. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4495. redis.Set(keyFive, "", time.Second)
  4496. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4497. redis.Set(keySix, "", time.Second)
  4498. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4499. redis.Set(keySeven, "", time.Second)
  4500. if updateErr != nil {
  4501. this.ErrorLog("修改上机失败:%v", updateErr)
  4502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4503. return
  4504. }
  4505. if updateErr == nil {
  4506. if tempDialysisRecord.Stage == 2 {
  4507. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4508. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4509. fmt.Println(value)
  4510. a, b := math.Modf(value)
  4511. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4512. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4513. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4514. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4515. redis := service.RedisClient()
  4516. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4517. redis.Set(key, "", time.Second)
  4518. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4519. redis.Set(keyOne, "", time.Second)
  4520. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4521. //清空key 值
  4522. redis.Set(keySix, "", time.Second)
  4523. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4524. redis.Set(keySeven, "", time.Second)
  4525. redis.Close()
  4526. if updateAssessmentErr != nil {
  4527. utils.ErrorLog("%v", updateAssessmentErr)
  4528. }
  4529. }
  4530. }
  4531. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4532. this.ServeSuccessJSON(map[string]interface{}{
  4533. "dialysis_order": dialysisRecords,
  4534. })
  4535. }
  4536. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4537. record_id, _ := c.GetInt64("id")
  4538. nurseID, _ := c.GetInt64("nurse")
  4539. end_time := c.GetString("end_time")
  4540. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4541. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4542. catheter := c.GetString("catheter")
  4543. cruor := c.GetString("cruor")
  4544. mission := c.GetString("mission")
  4545. condenser := c.GetString("condenser")
  4546. if record_id <= 0 || nurseID <= 0 {
  4547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4548. return
  4549. }
  4550. adminUserInfo := c.GetMobileAdminUserInfo()
  4551. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4552. if getNurseErr != nil {
  4553. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4555. return
  4556. } else if nurse == nil {
  4557. c.ErrorLog("护士不存在")
  4558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4559. return
  4560. }
  4561. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4562. if parseEndDateErr != nil {
  4563. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4565. return
  4566. }
  4567. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4568. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4569. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4570. // if getPermissionErr != nil {
  4571. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4572. // return
  4573. // } else if headNursePermission == nil {
  4574. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4575. // return
  4576. // }
  4577. //}
  4578. // 查询信息规挡的设置天数
  4579. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4580. if infor.ID > 0 {
  4581. var cha_time int64
  4582. timeNowStr := time.Now().Format("2006-01-02")
  4583. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4584. //今日的日期减去设置的日期
  4585. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4586. if cha_time >= tempDialysisRecords.DialysisDate {
  4587. //查询审核是否允许
  4588. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4589. //申请状态不允许的情况 拒绝修改
  4590. if infor.ApplicationStatus != 1 {
  4591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4592. return
  4593. }
  4594. }
  4595. }
  4596. dialysisRecord := &models.DialysisOrder{
  4597. ID: record_id,
  4598. UserOrgId: adminUserInfo.Org.Id,
  4599. EndTime: endDate.Unix(),
  4600. FinishNurse: nurseID,
  4601. FinishModifier: adminUserInfo.AdminUser.Id,
  4602. PuncturePointHaematoma: puncture_point_haematoma,
  4603. BloodAccessInternalFistula: blood_access_internal_fistula,
  4604. Catheter: catheter,
  4605. Cruor: cruor,
  4606. Mission: mission,
  4607. Condenser: condenser,
  4608. }
  4609. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4610. redis := service.RedisClient()
  4611. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4612. //清空key 值
  4613. redis.Set(key, "", time.Second)
  4614. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4615. //清空key 值
  4616. redis.Set(keyOne, "", time.Second)
  4617. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4618. redis.Set(keySeven, "", time.Second)
  4619. redis.Close()
  4620. if updateErr != nil {
  4621. c.ErrorLog("修改下机失败:%v", updateErr)
  4622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4623. return
  4624. }
  4625. if updateErr == nil {
  4626. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4627. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4628. a, b := math.Modf(value)
  4629. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4630. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4631. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4632. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4633. redis := service.RedisClient()
  4634. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4635. redis.Set(keyTen, "", time.Second)
  4636. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4637. redis.Set(keyTwo, "", time.Second)
  4638. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4639. redis.Set(key, "", time.Second)
  4640. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4641. redis.Set(keyThree, "", time.Second)
  4642. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4643. redis.Set(keySeven, "", time.Second)
  4644. defer redis.Close()
  4645. if updateAssessmentErr != nil {
  4646. utils.ErrorLog("%v", updateAssessmentErr)
  4647. }
  4648. }
  4649. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4650. c.ServeSuccessJSON(map[string]interface{}{
  4651. "dialysis_order": dialysisRecords,
  4652. })
  4653. }
  4654. func (c *DialysisAPIController) GetLongAdvice() {
  4655. patient_id, _ := c.GetInt64("id")
  4656. adminUserInfo := c.GetMobileAdminUserInfo()
  4657. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4658. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4659. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4660. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4661. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4662. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4663. c.ServeSuccessJSON(map[string]interface{}{
  4664. "status": "1",
  4665. })
  4666. return
  4667. } else { //开启推送提醒
  4668. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4669. var advice_three []*models.DoctorAdvice
  4670. recordDateStr := time.Now().Format("2006-01-02")
  4671. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4672. nowtime := recordDate.Unix()
  4673. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4674. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4675. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4676. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4677. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4678. for _, advice := range advices {
  4679. if advice.FrequencyType == 3 {
  4680. t := time.Now()
  4681. week := int(t.Weekday())
  4682. fmt.Println(t.Weekday())
  4683. fmt.Println(week)
  4684. switch week {
  4685. case 1:
  4686. if strings.Index(advice.WeekDay, "周一") == -1 {
  4687. advice_three = append(advice_three, advice)
  4688. }
  4689. break
  4690. case 2:
  4691. if strings.Index(advice.WeekDay, "周二") == -1 {
  4692. advice_three = append(advice_three, advice)
  4693. }
  4694. break
  4695. case 3:
  4696. if strings.Index(advice.WeekDay, "周三") == -1 {
  4697. advice_three = append(advice_three, advice)
  4698. }
  4699. break
  4700. case 4:
  4701. if strings.Index(advice.WeekDay, "周四") == -1 {
  4702. advice_three = append(advice_three, advice)
  4703. }
  4704. break
  4705. case 5:
  4706. if strings.Index(advice.WeekDay, "周五") == -1 {
  4707. advice_three = append(advice_three, advice)
  4708. }
  4709. break
  4710. case 6:
  4711. if strings.Index(advice.WeekDay, "周六") == -1 {
  4712. advice_three = append(advice_three, advice)
  4713. }
  4714. break
  4715. case 0:
  4716. if strings.Index(advice.WeekDay, "周日") == -1 {
  4717. advice_three = append(advice_three, advice)
  4718. }
  4719. break
  4720. }
  4721. }
  4722. }
  4723. for _, advice := range advices_two {
  4724. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4725. now := p.Unix()
  4726. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4727. dayStr2 := "-" + dayStr
  4728. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4729. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4730. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4731. for _, ad := range advices {
  4732. advice_three = append(advice_three, ad)
  4733. }
  4734. }
  4735. if err == nil {
  4736. c.ServeSuccessJSON(map[string]interface{}{
  4737. "status": "2",
  4738. "advices": advices,
  4739. "advices_two": RemoveRepeatedElement(advice_three),
  4740. "is_open_remind": config.IsOpenRemind,
  4741. "his_config_open": hisConfig.IsOpen,
  4742. "is_advice_open": is_advice_open.IsAdviceOpen,
  4743. "prescription_open": prescription_open.IsOpen,
  4744. })
  4745. }
  4746. }
  4747. }
  4748. func (c *DialysisAPIController) GetLongAdviceOne() {
  4749. patient_id, _ := c.GetInt64("id")
  4750. startTime := c.GetString("schedule_date")
  4751. timeLayout := "2006-01-02"
  4752. loc, _ := time.LoadLocation("Local")
  4753. var theStartTime int64
  4754. if len(startTime) > 0 {
  4755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4756. if err != nil {
  4757. utils.ErrorLog(err.Error())
  4758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4759. return
  4760. }
  4761. theStartTime = theTime.Unix()
  4762. }
  4763. adminUserInfo := c.GetMobileAdminUserInfo()
  4764. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4765. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4766. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4767. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4768. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4769. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4770. c.ServeSuccessJSON(map[string]interface{}{
  4771. "status": "1",
  4772. })
  4773. return
  4774. } else { //开启推送提醒
  4775. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4776. var advice_three []*models.DoctorAdvice
  4777. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4778. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4779. for _, advice := range advices {
  4780. if advice.FrequencyType == 3 {
  4781. t := time.Now()
  4782. week := int(t.Weekday())
  4783. fmt.Println(t.Weekday())
  4784. fmt.Println(week)
  4785. switch week {
  4786. case 1:
  4787. if strings.Index(advice.WeekDay, "周一") == -1 {
  4788. advice_three = append(advice_three, advice)
  4789. }
  4790. break
  4791. case 2:
  4792. if strings.Index(advice.WeekDay, "周二") == -1 {
  4793. advice_three = append(advice_three, advice)
  4794. }
  4795. break
  4796. case 3:
  4797. if strings.Index(advice.WeekDay, "周三") == -1 {
  4798. advice_three = append(advice_three, advice)
  4799. }
  4800. break
  4801. case 4:
  4802. if strings.Index(advice.WeekDay, "周四") == -1 {
  4803. advice_three = append(advice_three, advice)
  4804. }
  4805. break
  4806. case 5:
  4807. if strings.Index(advice.WeekDay, "周五") == -1 {
  4808. advice_three = append(advice_three, advice)
  4809. }
  4810. break
  4811. case 6:
  4812. if strings.Index(advice.WeekDay, "周六") == -1 {
  4813. advice_three = append(advice_three, advice)
  4814. }
  4815. break
  4816. case 0:
  4817. if strings.Index(advice.WeekDay, "周日") == -1 {
  4818. advice_three = append(advice_three, advice)
  4819. }
  4820. break
  4821. }
  4822. }
  4823. }
  4824. for _, advice := range advices_two {
  4825. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4826. now := p.Unix()
  4827. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4828. dayStr2 := "-" + dayStr
  4829. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4830. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4831. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4832. for _, ad := range advices {
  4833. advice_three = append(advice_three, ad)
  4834. }
  4835. }
  4836. if err == nil {
  4837. c.ServeSuccessJSON(map[string]interface{}{
  4838. "status": "2",
  4839. "advices": advices,
  4840. "advices_two": RemoveRepeatedElement(advice_three),
  4841. "is_open_remind": config.IsOpenRemind,
  4842. "his_config_open": hisConfig.IsOpen,
  4843. "is_advice_open": is_advice_open.IsAdviceOpen,
  4844. "prescription_open": prescription_open.IsOpen,
  4845. })
  4846. }
  4847. }
  4848. }
  4849. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4850. newArr = make([]*models.DoctorAdvice, 0)
  4851. for i := 0; i < len(arr); i++ {
  4852. repeat := false
  4853. for j := i + 1; j < len(arr); j++ {
  4854. if arr[i].ID == arr[j].ID {
  4855. repeat = true
  4856. break
  4857. }
  4858. }
  4859. if !repeat {
  4860. newArr = append(newArr, arr[i])
  4861. }
  4862. }
  4863. return
  4864. }
  4865. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4866. patient, _ := c.GetInt64("id", 0)
  4867. groupNo, _ := c.GetInt64("groupno", 0)
  4868. if patient <= 0 {
  4869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4870. return
  4871. }
  4872. adminUserInfo := c.GetMobileAdminUserInfo()
  4873. dataBody := make(map[string]interface{}, 0)
  4874. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4875. if err != nil {
  4876. utils.ErrorLog(err.Error())
  4877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4878. return
  4879. }
  4880. utils.ErrorLog("%v", dataBody)
  4881. timeLayout := "2006-01-02 15:04"
  4882. loc, _ := time.LoadLocation("Local")
  4883. timeLayout2 := "2006-01-02"
  4884. loc2, _ := time.LoadLocation("Local")
  4885. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4886. utils.ErrorLog("advice_type")
  4887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4888. return
  4889. }
  4890. adviceType := int64(2)
  4891. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4892. utils.ErrorLog("advice_date")
  4893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4894. return
  4895. }
  4896. adviceDate, _ := dataBody["advice_date"].(string)
  4897. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4898. AdviceDate := theTime.Unix()
  4899. RecordDate := theTime.Unix()
  4900. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4901. utils.ErrorLog("start_time")
  4902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4903. return
  4904. }
  4905. startTime, _ := dataBody["start_time"].(string)
  4906. if len(startTime) == 0 {
  4907. utils.ErrorLog("len(start_time) == 0")
  4908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4909. return
  4910. }
  4911. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4912. if err != nil {
  4913. utils.ErrorLog(err.Error())
  4914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4915. return
  4916. }
  4917. StartTime := theTime.Unix()
  4918. Remark := ""
  4919. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4920. remark, _ := dataBody["remark"].(string)
  4921. Remark = remark
  4922. }
  4923. var advices []*models.GroupAdvice
  4924. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4925. utils.ErrorLog("advices")
  4926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4927. return
  4928. }
  4929. adviceNames := dataBody["advices"].([]interface{})
  4930. for _, adviceNameMap := range adviceNames {
  4931. adviceNameM := adviceNameMap.(map[string]interface{})
  4932. var advice models.GroupAdvice
  4933. advice.Remark = Remark
  4934. advice.AdviceType = adviceType
  4935. advice.StartTime = StartTime
  4936. advice.AdviceDate = AdviceDate
  4937. advice.RecordDate = RecordDate
  4938. advice.Status = 1
  4939. advice.CreatedTime = time.Now().Unix()
  4940. advice.UpdatedTime = time.Now().Unix()
  4941. advice.StopState = 2
  4942. advice.ExecutionState = 2
  4943. advice.UserOrgId = adminUserInfo.Org.Id
  4944. advice.PatientId = patient
  4945. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4946. advice.IsSettle = 2
  4947. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4948. utils.ErrorLog("advice_name")
  4949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4950. return
  4951. }
  4952. adviceName, _ := adviceNameM["advice_name"].(string)
  4953. if len(adviceName) == 0 {
  4954. utils.ErrorLog("len(advice_name) == 0")
  4955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4956. return
  4957. }
  4958. advice.AdviceName = adviceName
  4959. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4960. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4961. advice.DrugSpec = drugSpec
  4962. }
  4963. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4964. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4965. advice.AdviceDesc = adviceDesc
  4966. }
  4967. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4968. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4969. advice.DrugSpecUnit = drugSpecUnit
  4970. }
  4971. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4972. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4973. // advice.SingleDose = singleDose
  4974. //}
  4975. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4976. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4977. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4978. }
  4979. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4980. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4981. advice.SingleDoseUnit = singleDoseUnit
  4982. }
  4983. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4984. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4985. // advice.PrescribingNumber = prescribingNumber
  4986. //}
  4987. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4988. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4989. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4990. }
  4991. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4992. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4993. advice.PrescribingNumberUnit = prescribingNumberUnit
  4994. }
  4995. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4996. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4997. advice.DeliveryWay = deliveryWay
  4998. }
  4999. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5000. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5001. advice.ExecutionFrequency = executionFrequency
  5002. }
  5003. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5004. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5005. advice.FrequencyType = frequency_type
  5006. }
  5007. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5008. day_count := int64(adviceNameM["day_count"].(float64))
  5009. advice.DayCount = day_count
  5010. }
  5011. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5012. week_day, _ := adviceNameM["week_day"].(string)
  5013. advice.WeekDay = week_day
  5014. }
  5015. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5016. way := int64(adviceNameM["way"].(float64))
  5017. advice.Way = way
  5018. }
  5019. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5020. drug_id := int64(adviceNameM["drug_id"].(float64))
  5021. advice.DrugId = drug_id
  5022. }
  5023. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5024. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5025. advice.DrugNameId = drug_name_id
  5026. }
  5027. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5028. remark, _ := adviceNameM["remark"].(string)
  5029. advice.Remark = remark
  5030. }
  5031. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5032. groupno := int64(adviceNameM["groupno"].(float64))
  5033. advice.GroupNo = groupno
  5034. }
  5035. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5036. template_id, _ := adviceNameM["template_id"].(string)
  5037. advice.TemplateId = template_id
  5038. }
  5039. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5040. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5041. advice.ExecutionFrequency = executionFrequency
  5042. }
  5043. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5044. children := adviceNameM["child"].([]interface{})
  5045. if len(children) > 0 {
  5046. for _, childrenMap := range children {
  5047. childMap := childrenMap.(map[string]interface{})
  5048. var child models.GroupAdvice
  5049. child.Remark = Remark
  5050. child.AdviceType = adviceType
  5051. child.StartTime = StartTime
  5052. child.AdviceDate = AdviceDate
  5053. child.RecordDate = RecordDate
  5054. child.Status = 1
  5055. child.CreatedTime = time.Now().Unix()
  5056. child.UpdatedTime = time.Now().Unix()
  5057. child.StopState = 2
  5058. child.ExecutionState = 2
  5059. child.UserOrgId = adminUserInfo.Org.Id
  5060. child.PatientId = patient
  5061. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5062. child.IsSettle = 1
  5063. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5064. utils.ErrorLog("child advice_name")
  5065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5066. return
  5067. }
  5068. childAdviceName, _ := childMap["advice_name"].(string)
  5069. if len(childAdviceName) == 0 {
  5070. utils.ErrorLog("len(child advice_name) == 0")
  5071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5072. return
  5073. }
  5074. child.AdviceName = childAdviceName
  5075. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5076. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5077. child.AdviceDesc = childAdviceDesc
  5078. }
  5079. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5080. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5081. child.DrugSpec = childDrugSpec
  5082. }
  5083. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5084. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5085. child.DrugSpecUnit = childDrugSpecUnit
  5086. }
  5087. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5088. child.SingleDose = childMap["single_dose"].(float64)
  5089. }
  5090. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5091. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5092. child.SingleDoseUnit = childSingleDoseUnit
  5093. }
  5094. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5095. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5096. }
  5097. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5098. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5099. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5100. }
  5101. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5102. groupno := int64(childMap["groupno"].(float64))
  5103. advice.GroupNo = groupno
  5104. }
  5105. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5106. remark, _ := childMap["remark"].(string)
  5107. child.Remark = remark
  5108. }
  5109. child.DeliveryWay = advice.DeliveryWay
  5110. child.ExecutionFrequency = advice.ExecutionFrequency
  5111. advice.Children = append(advice.Children, &child)
  5112. }
  5113. }
  5114. }
  5115. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5116. if temp_advice.ID == 0 {
  5117. advices = append(advices, &advice)
  5118. }
  5119. }
  5120. if len(advices) > 0 {
  5121. finish := models.XtDialysisFinish{
  5122. IsFinish: 1,
  5123. UserOrgId: adminUserInfo.Org.Id,
  5124. Status: 1,
  5125. Ctime: time.Now().Unix(),
  5126. Mtime: 0,
  5127. Module: 4,
  5128. RecordDate: AdviceDate,
  5129. Sourse: 1,
  5130. PatientId: patient,
  5131. }
  5132. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5133. if dialysisFinish.ID == 0 {
  5134. service.CreateDialysisFinish(finish)
  5135. }
  5136. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5137. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5138. for _, item := range advices {
  5139. byterequest, _ := json.Marshal(item)
  5140. adviceLog := models.XtDoctorAdviceLog{
  5141. UserOrgId: adminUserInfo.Org.Id,
  5142. PatientId: patient,
  5143. AdminUserId: adminUserInfo.AdminUser.Id,
  5144. Module: 1,
  5145. ErrLog: string(byterequest),
  5146. Status: 1,
  5147. Ctime: time.Now().Unix(),
  5148. Mtime: 0,
  5149. Source: "手机端医嘱推送",
  5150. RecordDate: item.AdviceDate,
  5151. }
  5152. service.CreateDoctorAdviceLog(adviceLog)
  5153. }
  5154. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5155. redis := service.RedisClient()
  5156. //清空key 值
  5157. redis.Set(key, "", time.Second)
  5158. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5159. redis.Set(keyOne, "", time.Second)
  5160. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5161. defer redis.Close()
  5162. redis.Set(keyThree, "", time.Second)
  5163. if err != nil {
  5164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5165. return
  5166. }
  5167. c.ServeSuccessJSON(map[string]interface{}{
  5168. "msg": "ok",
  5169. "advices": list,
  5170. })
  5171. } else {
  5172. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5173. for _, item := range advices {
  5174. byterequest, _ := json.Marshal(item)
  5175. adviceLog := models.XtDoctorAdviceLog{
  5176. UserOrgId: adminUserInfo.Org.Id,
  5177. PatientId: patient,
  5178. AdminUserId: adminUserInfo.AdminUser.Id,
  5179. Module: 1,
  5180. ErrLog: string(byterequest),
  5181. Status: 1,
  5182. Ctime: time.Now().Unix(),
  5183. Mtime: 0,
  5184. Source: "手机端医嘱推送",
  5185. RecordDate: item.AdviceDate,
  5186. }
  5187. service.CreateDoctorAdviceLog(adviceLog)
  5188. }
  5189. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5190. redis := service.RedisClient()
  5191. //清空key 值
  5192. redis.Set(key, "", time.Second)
  5193. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5194. redis.Set(keyOne, "", time.Second)
  5195. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5196. defer redis.Close()
  5197. redis.Set(keyThree, "", time.Second)
  5198. if err != nil {
  5199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5200. return
  5201. }
  5202. c.ServeSuccessJSON(map[string]interface{}{
  5203. "msg": "ok",
  5204. "advices": list,
  5205. })
  5206. }
  5207. } else {
  5208. c.ServeSuccessJSON(map[string]interface{}{
  5209. "msg": "ok",
  5210. })
  5211. }
  5212. return
  5213. }
  5214. func (c *DialysisAPIController) UploadDryWeight() {
  5215. patient_id, _ := c.GetInt64("id")
  5216. dry_weight, _ := c.GetFloat("dry_weight")
  5217. doctor_id, _ := c.GetInt64("doctor_id")
  5218. remark := c.GetString("remark")
  5219. adminUserInfo := c.GetMobileAdminUserInfo()
  5220. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5221. if err == gorm.ErrRecordNotFound {
  5222. dryWeight := &models.SgjPatientDryweight{
  5223. PatientId: patient_id,
  5224. DryWeight: dry_weight,
  5225. Remakes: remark,
  5226. Ctime: time.Now().Unix(),
  5227. Mtime: time.Now().Unix(),
  5228. Creator: doctor_id,
  5229. Status: 1,
  5230. UserOrgId: adminUserInfo.Org.Id,
  5231. AdjustedValue: "/",
  5232. UserId: adminUserInfo.AdminUser.Id,
  5233. }
  5234. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5235. redis := service.RedisClient()
  5236. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5237. redis.Set(keyOne, "", time.Second)
  5238. loc, _ := time.LoadLocation("Local")
  5239. nowTime := time.Now()
  5240. nowDay := nowTime.Format("2006-01-02")
  5241. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5242. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5243. redis.Set(key, "", time.Second)
  5244. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5245. redis.Set(keyTwo, "", time.Second)
  5246. redis.Close()
  5247. if createErr == nil {
  5248. c.ServeSuccessJSON(map[string]interface{}{
  5249. "msg": "提交成功",
  5250. "weight": dryWeight,
  5251. })
  5252. }
  5253. } else {
  5254. dryWeight := &models.SgjPatientDryweight{
  5255. PatientId: patient_id,
  5256. DryWeight: dry_weight,
  5257. Remakes: remark,
  5258. Ctime: time.Now().Unix(),
  5259. Mtime: time.Now().Unix(),
  5260. Creator: doctor_id,
  5261. Status: 1,
  5262. UserOrgId: adminUserInfo.Org.Id,
  5263. AdjustedValue: "/",
  5264. UserId: adminUserInfo.AdminUser.Id,
  5265. }
  5266. var value float64
  5267. value = dry_weight - weightAdjust.DryWeight
  5268. if value < 0 {
  5269. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5270. } else if value == 0 {
  5271. dryWeight.AdjustedValue = "/"
  5272. } else if value > 0 {
  5273. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5274. }
  5275. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5276. redis := service.RedisClient()
  5277. loc, _ := time.LoadLocation("Local")
  5278. nowTime := time.Now()
  5279. nowDay := nowTime.Format("2006-01-02")
  5280. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5281. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5282. redis.Set(keyOne, "", time.Second)
  5283. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5284. redis.Set(key, "", time.Second)
  5285. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5286. redis.Set(keyTwo, "", time.Second)
  5287. redis.Close()
  5288. if createErr == nil {
  5289. c.ServeSuccessJSON(map[string]interface{}{
  5290. "msg": "提交成功",
  5291. "weight": dryWeight,
  5292. })
  5293. }
  5294. }
  5295. }
  5296. func (c *DialysisAPIController) GetSolution() {
  5297. patient_id, _ := c.GetInt64("patient_id")
  5298. mode_id, _ := c.GetInt64("mode_id")
  5299. adminUserInfo := c.GetMobileAdminUserInfo()
  5300. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5301. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5302. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5303. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5304. if err != nil {
  5305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5306. return
  5307. }
  5308. c.ServeSuccessJSON(map[string]interface{}{
  5309. "solution": solution,
  5310. "prescription": prescription,
  5311. "system_prescription": system_prescription,
  5312. "dialysisPrescription": dialysisPrescription,
  5313. })
  5314. }
  5315. func (c *DialysisAPIController) GetSchedule() {
  5316. schedual_type, _ := c.GetInt64("schedual_type")
  5317. adminUserInfo := c.GetMobileAdminUserInfo()
  5318. scheduleTime, _ := c.GetInt64("record_date")
  5319. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5320. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5321. c.ServeSuccessJSON(map[string]interface{}{
  5322. "number": deviceNumber,
  5323. "list": list,
  5324. })
  5325. }
  5326. func (c *DialysisAPIController) GetPatientId() {
  5327. id, _ := c.GetInt64("id")
  5328. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5329. patientId, _ := service.GetPatientId(id)
  5330. //获取该患者的所有传染病
  5331. list, _ := service.GetPatientInfectious(id)
  5332. c.ServeSuccessJSON(map[string]interface{}{
  5333. "patient": patientId,
  5334. "infectioulist": list,
  5335. })
  5336. }
  5337. func (this *DialysisAPIController) GetDialysisSchedule() {
  5338. schedualDate := this.GetString("date")
  5339. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5340. if parseDateErr != nil {
  5341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5342. return
  5343. }
  5344. adminInfo := this.GetMobileAdminUserInfo()
  5345. orgID := adminInfo.Org.Id
  5346. redis := service.RedisClient()
  5347. defer redis.Close()
  5348. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5349. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5350. if len(scheduals) > 0 {
  5351. //缓存数据
  5352. scheduals_json, err := json.Marshal(scheduals)
  5353. if err == nil {
  5354. redis.Set(key, scheduals_json, time.Second*30)
  5355. }
  5356. }
  5357. this.ServeSuccessJSON(map[string]interface{}{
  5358. "scheduals": scheduals,
  5359. })
  5360. }
  5361. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5362. change_type, _ := this.GetInt64("type", 0)
  5363. record_date := this.GetString("record_time")
  5364. patient_id, _ := this.GetInt64("patient_id", 0)
  5365. timeLayout := "2006-01-02"
  5366. loc, _ := time.LoadLocation("Local")
  5367. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5368. record_time := theAdviceRecordTime.Unix()
  5369. adminUserInfo := this.GetMobileAdminUserInfo()
  5370. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5371. if err == nil {
  5372. if len(advices) == 0 {
  5373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5374. return
  5375. } else {
  5376. this.ServeSuccessJSON(map[string]interface{}{
  5377. "advices": advices,
  5378. "schedule": sch,
  5379. })
  5380. return
  5381. }
  5382. } else {
  5383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5384. return
  5385. }
  5386. }
  5387. func (c *DialysisAPIController) CreateConsumables() {
  5388. record_date := c.GetString("record_time")
  5389. patient_id, _ := c.GetInt64("patient_id", 0)
  5390. active, _ := c.GetInt64("active")
  5391. adminUser := c.GetMobileAdminUserInfo()
  5392. timeLayout := "2006-01-02"
  5393. loc, _ := time.LoadLocation("Local")
  5394. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5395. record_time := theRecordTime.Unix()
  5396. // 查询信息规挡的设置天数
  5397. orgid := c.GetMobileAdminUserInfo().Org.Id
  5398. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5399. if infor.ID > 0 {
  5400. var cha_time int64
  5401. timeNowStr := time.Now().Format("2006-01-02")
  5402. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5403. //今日的日期减去设置的日期
  5404. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5405. if cha_time >= record_time {
  5406. //查询审核是否允许
  5407. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5408. //申请状态不允许的情况 拒绝修改
  5409. if infor.ApplicationStatus != 1 {
  5410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5411. return
  5412. }
  5413. }
  5414. }
  5415. dataBody := make(map[string]interface{}, 0)
  5416. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5417. if err != nil {
  5418. utils.ErrorLog(err.Error())
  5419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5420. return
  5421. }
  5422. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5423. var beforePrepares []*models.DialysisBeforePrepareGoods
  5424. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5425. var dialysisBefor []*models.DialysisBeforePrepare
  5426. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5427. goods, _ := dataBody["goods"].([]interface{})
  5428. if len(goods) > 0 {
  5429. for _, item := range goods {
  5430. items := item.(map[string]interface{})
  5431. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5432. utils.ErrorLog("good_id")
  5433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5434. return
  5435. }
  5436. good_id := int64(items["good_id"].(float64))
  5437. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5438. utils.ErrorLog("good_type_id")
  5439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5440. return
  5441. }
  5442. good_type_id := int64(items["good_type_id"].(float64))
  5443. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5444. utils.ErrorLog("count")
  5445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5446. return
  5447. }
  5448. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5449. commdity_code := items["commdity_code"].(string)
  5450. fmt.Println("commdity", commdity_code)
  5451. prepareGoods := &models.DialysisBeforePrepareGoods{
  5452. GoodTypeId: good_type_id,
  5453. GoodId: good_id,
  5454. Count: count,
  5455. StorehouseId: houseConfig.StorehouseOutInfo,
  5456. }
  5457. beforePrepares = append(beforePrepares, prepareGoods)
  5458. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5459. GoodTypeId: good_type_id,
  5460. GoodId: good_id,
  5461. Count: count,
  5462. StorehouseId: houseConfig.StorehouseOutInfo,
  5463. }
  5464. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5465. prepare := &models.DialysisBeforePrepare{
  5466. GoodTypeId: good_type_id,
  5467. GoodId: good_id,
  5468. Count: count,
  5469. PatientId: patient_id,
  5470. RecordDate: record_time,
  5471. UserOrgId: adminUser.Org.Id,
  5472. Status: 1,
  5473. Ctime: time.Now().Unix(),
  5474. Creater: adminUser.AdminUser.Id,
  5475. CommdityCode: commdity_code,
  5476. StorehouseId: houseConfig.StorehouseOutInfo,
  5477. }
  5478. dialysisBefor = append(dialysisBefor, prepare)
  5479. }
  5480. }
  5481. //查询是否有库存
  5482. for _, item := range dialysisBefor {
  5483. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5484. if err == gorm.ErrRecordNotFound {
  5485. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5486. c.ServeSuccessJSON(map[string]interface{}{
  5487. "message": "1",
  5488. "good_name": goodObj.GoodName,
  5489. "specification_name": goodObj.SpecificationName,
  5490. })
  5491. return
  5492. }
  5493. if err != nil {
  5494. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5495. c.ServeSuccessJSON(map[string]interface{}{
  5496. "message": "1",
  5497. "good_name": goodObj.GoodName,
  5498. "specification_name": goodObj.SpecificationName,
  5499. })
  5500. return
  5501. }
  5502. }
  5503. //新增
  5504. if active == 1 && len(goods) > 0 {
  5505. for _, item := range dialysisBefor {
  5506. dialyPrepareOne := models.DialysisBeforePrepare{
  5507. GoodTypeId: item.GoodTypeId,
  5508. GoodId: item.GoodId,
  5509. PatientId: item.PatientId,
  5510. RecordDate: item.RecordDate,
  5511. UserOrgId: item.UserOrgId,
  5512. Count: item.Count,
  5513. Ctime: time.Now().Unix(),
  5514. Creater: item.Creater,
  5515. CommdityCode: item.CommdityCode,
  5516. Status: 1,
  5517. StorehouseId: houseConfig.StorehouseOutInfo,
  5518. }
  5519. //先清除再插入
  5520. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5521. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5522. //查询默认仓库
  5523. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5524. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5525. var total_count int64
  5526. for _, it := range stockList {
  5527. total_count += it.StockCount
  5528. }
  5529. //基础库插入数据
  5530. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5531. //更新库存
  5532. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5533. var flush_count int64
  5534. for _, it := range goodList {
  5535. flush_count += it.StockCount
  5536. }
  5537. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5538. }
  5539. if err == nil {
  5540. c.ServeSuccessJSON(map[string]interface{}{
  5541. "msg": "保存成功",
  5542. "message": "2",
  5543. })
  5544. return
  5545. } else {
  5546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5547. return
  5548. }
  5549. }
  5550. if len(beforePrepares) > 0 && active == 2 {
  5551. for _, item := range beforePrepares {
  5552. //1.查看该患者该耗材型号最后一次出库数量
  5553. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5554. //判断当前出库数量和最后一次出库数量的大小
  5555. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5556. if item.Count <= goodInfo.Count {
  5557. //退库
  5558. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5559. //查询今日出库数据
  5560. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5561. for _, it := range list {
  5562. prepare := models.DialysisBeforePrepare{
  5563. UserOrgId: it.OrgId,
  5564. PatientId: patient_id,
  5565. RecordDate: it.RecordTime,
  5566. GoodId: it.GoodId,
  5567. GoodTypeId: it.GoodTypeId,
  5568. Count: it.Count,
  5569. Ctime: time.Now().Unix(),
  5570. Creater: adminUser.AdminUser.Id,
  5571. Status: 1,
  5572. StorehouseId: houseConfig.StorehouseOutInfo,
  5573. }
  5574. //删除准备表数据
  5575. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5576. service.CreateDialysisBeforePrepareOne(&prepare)
  5577. }
  5578. }
  5579. var last_total int64
  5580. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5581. if item.Count >= goodInfo.Count {
  5582. //查询当前批次当前耗材最后一条出库数据
  5583. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5584. //计算当前出库和最后一次出库数据相差数据
  5585. last_total = item.Count - lastOutInfo.Count
  5586. //查询该批次剩余库存
  5587. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5588. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5589. if lastInfo.StockCount >= last_total {
  5590. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5591. //查询今日出库数据
  5592. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5593. for _, it := range list {
  5594. prepare := models.DialysisBeforePrepare{
  5595. UserOrgId: it.OrgId,
  5596. PatientId: patient_id,
  5597. RecordDate: it.RecordTime,
  5598. GoodId: it.GoodId,
  5599. GoodTypeId: it.GoodTypeId,
  5600. Count: it.Count,
  5601. Ctime: time.Now().Unix(),
  5602. Creater: adminUser.AdminUser.Id,
  5603. Status: 1,
  5604. StorehouseId: houseConfig.StorehouseOutInfo,
  5605. }
  5606. //删除准备表数据
  5607. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5608. service.CreateDialysisBeforePrepareOne(&prepare)
  5609. //查询默认仓库
  5610. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5611. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5612. var total_count int64
  5613. for _, it := range stockList {
  5614. total_count += it.StockCount
  5615. }
  5616. //基础库插入数据
  5617. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5618. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5619. var flush_count int64
  5620. for _, it := range goodList {
  5621. flush_count += it.StockCount
  5622. }
  5623. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5624. }
  5625. }
  5626. //如果库存不够,则出库到下一个批次
  5627. if lastInfo.StockCount < last_total {
  5628. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5629. //查询今日出库数据
  5630. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5631. for _, it := range list {
  5632. prepare := models.DialysisBeforePrepare{
  5633. UserOrgId: it.OrgId,
  5634. PatientId: patient_id,
  5635. RecordDate: it.RecordTime,
  5636. GoodId: it.GoodId,
  5637. GoodTypeId: it.GoodTypeId,
  5638. Count: it.Count,
  5639. Ctime: time.Now().Unix(),
  5640. Creater: adminUser.AdminUser.Id,
  5641. Status: 1,
  5642. StorehouseId: houseConfig.StorehouseOutInfo,
  5643. }
  5644. //删除准备表数据
  5645. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5646. service.CreateDialysisBeforePrepareOne(&prepare)
  5647. //查询默认仓库
  5648. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5649. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5650. var total_count int64
  5651. for _, it := range stockList {
  5652. total_count += it.StockCount
  5653. }
  5654. //基础库插入数据
  5655. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5656. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5657. var flush_count int64
  5658. for _, it := range goodList {
  5659. flush_count += it.StockCount
  5660. }
  5661. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5662. }
  5663. if err != nil {
  5664. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5665. c.ServeSuccessJSON(map[string]interface{}{
  5666. "message": "1",
  5667. "good_name": goodObj.GoodName,
  5668. "specification_name": goodObj.SpecificationName,
  5669. })
  5670. return
  5671. }
  5672. }
  5673. }
  5674. if err != nil {
  5675. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5676. c.ServeSuccessJSON(map[string]interface{}{
  5677. "message": "1",
  5678. "good_name": goodObj.GoodName,
  5679. "specification_name": goodObj.SpecificationName,
  5680. })
  5681. return
  5682. }
  5683. }
  5684. }
  5685. }
  5686. var errs error
  5687. if errs == nil {
  5688. c.ServeSuccessJSON(map[string]interface{}{
  5689. "msg": "提交成功",
  5690. "message": "2",
  5691. "good_name": "",
  5692. "specification_name": "",
  5693. })
  5694. return
  5695. } else {
  5696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5697. return
  5698. }
  5699. }
  5700. func (c *DialysisAPIController) CreateStockOutInfo() {
  5701. patient_id, _ := c.GetInt64("patient_id", 0)
  5702. record_date := c.GetString("record_time")
  5703. if patient_id <= 0 {
  5704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5705. return
  5706. }
  5707. adminInfo := c.GetMobileAdminUserInfo()
  5708. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5709. timeLayout := "2006-01-02"
  5710. loc, _ := time.LoadLocation("Local")
  5711. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5712. record_time := theRecordTime.Unix()
  5713. // 查询信息规挡的设置天数
  5714. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5715. if infor.ID > 0 && infor.WeekDay > 0 {
  5716. var cha_time int64
  5717. timeNowStr := time.Now().Format("2006-01-02")
  5718. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5719. //今日的日期减去设置的日期
  5720. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5721. if cha_time >= record_time {
  5722. //查询审核是否允许
  5723. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5724. //申请状态不允许的情况 拒绝修改
  5725. if infor.ApplicationStatus != 1 {
  5726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5727. return
  5728. }
  5729. }
  5730. }
  5731. //创建步骤表
  5732. finish := models.XtDialysisFinish{
  5733. IsFinish: 1,
  5734. UserOrgId: adminInfo.Org.Id,
  5735. Status: 1,
  5736. Ctime: time.Now().Unix(),
  5737. Mtime: 0,
  5738. Module: 11,
  5739. RecordDate: record_time,
  5740. Sourse: 1,
  5741. PatientId: patient_id,
  5742. }
  5743. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5744. if dialysisFinish.ID == 0 {
  5745. service.CreateDialysisFinish(finish)
  5746. }
  5747. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5748. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5749. //去重
  5750. consumables = RemoveRepeatedGood(consumables)
  5751. if adminInfo.Org.Id == 9919 {
  5752. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5753. //查询是否有库存
  5754. for _, item := range consumables {
  5755. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5756. if item.Count > warehouse.Count {
  5757. goodErrcode := models.XtGoodErrcode{
  5758. UserOrgId: item.UserOrgId,
  5759. Errcode: "自动出库库存不足",
  5760. GoodId: item.GoodId,
  5761. Status: 1,
  5762. Ctime: time.Now().Unix(),
  5763. Mtime: 0,
  5764. Count: 0,
  5765. StockCount: 0,
  5766. Creater: creator,
  5767. BatchNumberId: warehouse.ID,
  5768. WarehouseOutId: 0,
  5769. }
  5770. service.CreateGoodErrcode(goodErrcode)
  5771. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5772. c.ServeSuccessJSON(map[string]interface{}{
  5773. "message": "1",
  5774. "good_name": goodObj.GoodName,
  5775. "specification_name": goodObj.SpecificationName,
  5776. })
  5777. return
  5778. }
  5779. }
  5780. //查询是否有出库单
  5781. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5782. if err == gorm.ErrRecordNotFound {
  5783. //没有记录,则创建出库单
  5784. timeStr := time.Now().Format("2006-01-02")
  5785. timeArr := strings.Split(timeStr, "-")
  5786. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5787. total = total + 1
  5788. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5789. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5790. number = number + total
  5791. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5792. creater := adminInfo.AdminUser.Id
  5793. warehouseOut := models.WarehouseOut{
  5794. WarehouseOutOrderNumber: warehousing_out_order,
  5795. OperationTime: time.Now().Unix(),
  5796. OrgId: adminInfo.Org.Id,
  5797. Creater: creater,
  5798. Ctime: time.Now().Unix(),
  5799. Status: 1,
  5800. WarehouseOutTime: record_time,
  5801. Dealer: 0,
  5802. Manufacturer: 0,
  5803. Type: 1,
  5804. IsSys: 1,
  5805. StorehouseId: houseConfig.StorehouseOutInfo,
  5806. IsCheck: 1,
  5807. }
  5808. err := service.AddSigleWarehouseOut(&warehouseOut)
  5809. if err != nil {
  5810. goodErrcode := models.XtGoodErrcode{
  5811. UserOrgId: adminInfo.Org.Id,
  5812. Errcode: "创建出库单失败",
  5813. GoodId: 0,
  5814. Status: 1,
  5815. Ctime: time.Now().Unix(),
  5816. Mtime: 0,
  5817. Count: 0,
  5818. StockCount: 0,
  5819. Creater: creator,
  5820. BatchNumberId: 0,
  5821. WarehouseOutId: 0,
  5822. }
  5823. service.CreateGoodErrcode(goodErrcode)
  5824. utils.TraceLog("创建出库单失败 err = %v", err)
  5825. } else {
  5826. for _, item := range consumables {
  5827. //出库
  5828. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5829. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5830. if err == nil {
  5831. goodErrcode := models.XtGoodErrcode{
  5832. UserOrgId: adminInfo.Org.Id,
  5833. Errcode: "自动出库接口报错",
  5834. GoodId: 0,
  5835. Status: 1,
  5836. Ctime: time.Now().Unix(),
  5837. Mtime: 0,
  5838. Count: 0,
  5839. StockCount: 0,
  5840. Creater: creator,
  5841. BatchNumberId: 0,
  5842. WarehouseOutId: 0,
  5843. }
  5844. service.CreateGoodErrcode(goodErrcode)
  5845. utils.TraceLog("创建出库单失败 err = %v", err)
  5846. }
  5847. //查询
  5848. //出库数量相加
  5849. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5850. if errs != nil {
  5851. goodErrcode := models.XtGoodErrcode{
  5852. UserOrgId: item.UserOrgId,
  5853. Errcode: "创建剩余库存字段报错",
  5854. GoodId: item.GoodId,
  5855. Status: 1,
  5856. Ctime: time.Now().Unix(),
  5857. Mtime: 0,
  5858. Count: 0,
  5859. StockCount: 0,
  5860. Creater: creater,
  5861. BatchNumberId: 0,
  5862. WarehouseOutId: 0,
  5863. }
  5864. service.CreateGoodErrcode(goodErrcode)
  5865. }
  5866. }
  5867. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5868. if len(list) == 0 {
  5869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5870. return
  5871. }
  5872. for _, item := range list {
  5873. prepare := models.DialysisBeforePrepare{
  5874. UserOrgId: adminInfo.Org.Id,
  5875. PatientId: patient_id,
  5876. RecordDate: record_time,
  5877. GoodId: item.GoodId,
  5878. GoodTypeId: item.GoodTypeId,
  5879. Count: item.Count,
  5880. Creater: adminInfo.AdminUser.Id,
  5881. Status: 1,
  5882. Ctime: time.Now().Unix(),
  5883. StorehouseId: houseConfig.StorehouseOutInfo,
  5884. }
  5885. //清空准备表数据
  5886. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5887. if err != nil {
  5888. goodErrcode := models.XtGoodErrcode{
  5889. UserOrgId: item.OrgId,
  5890. Errcode: "自动出库清空准备表数据报错",
  5891. GoodId: item.GoodId,
  5892. Status: 1,
  5893. Ctime: time.Now().Unix(),
  5894. Mtime: 0,
  5895. Count: 0,
  5896. StockCount: 0,
  5897. Creater: creater,
  5898. BatchNumberId: 0,
  5899. WarehouseOutId: 0,
  5900. }
  5901. service.CreateGoodErrcode(goodErrcode)
  5902. }
  5903. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5904. if errs != nil {
  5905. goodErrcode := models.XtGoodErrcode{
  5906. UserOrgId: item.OrgId,
  5907. Errcode: "自动出库创建准备表数据报错",
  5908. GoodId: item.GoodId,
  5909. Status: 1,
  5910. Ctime: time.Now().Unix(),
  5911. Mtime: 0,
  5912. Count: 0,
  5913. StockCount: 0,
  5914. Creater: creater,
  5915. BatchNumberId: 0,
  5916. WarehouseOutId: 0,
  5917. }
  5918. service.CreateGoodErrcode(goodErrcode)
  5919. }
  5920. //查询默认仓库
  5921. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5922. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5923. var total_count int64
  5924. for _, it := range stockList {
  5925. total_count += it.StockCount
  5926. }
  5927. //基础库插入数据
  5928. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5929. if errcodes != nil {
  5930. goodErrcode := models.XtGoodErrcode{
  5931. UserOrgId: item.OrgId,
  5932. Errcode: "自动出库基础库插入数据",
  5933. GoodId: item.GoodId,
  5934. Status: 1,
  5935. Ctime: time.Now().Unix(),
  5936. Mtime: 0,
  5937. Count: 0,
  5938. StockCount: 0,
  5939. Creater: creater,
  5940. BatchNumberId: 0,
  5941. WarehouseOutId: 0,
  5942. }
  5943. service.CreateGoodErrcode(goodErrcode)
  5944. }
  5945. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5946. var flush_count int64
  5947. for _, it := range goodList {
  5948. flush_count += it.StockCount
  5949. }
  5950. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5951. if errsss != nil {
  5952. goodErrcode := models.XtGoodErrcode{
  5953. UserOrgId: item.OrgId,
  5954. Errcode: "自动出库剩余库存更新数据",
  5955. GoodId: item.GoodId,
  5956. Status: 1,
  5957. Ctime: time.Now().Unix(),
  5958. Mtime: 0,
  5959. Count: 0,
  5960. StockCount: 0,
  5961. Creater: creater,
  5962. BatchNumberId: 0,
  5963. WarehouseOutId: 0,
  5964. }
  5965. service.CreateGoodErrcode(goodErrcode)
  5966. }
  5967. }
  5968. }
  5969. //
  5970. } else if err == nil {
  5971. for _, item := range consumables {
  5972. //出库
  5973. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5974. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5975. if err != nil {
  5976. goodErrcode := models.XtGoodErrcode{
  5977. UserOrgId: adminInfo.Org.Id,
  5978. Errcode: "自动出库接口报错",
  5979. GoodId: 0,
  5980. Status: 1,
  5981. Ctime: time.Now().Unix(),
  5982. Mtime: 0,
  5983. Count: 0,
  5984. StockCount: 0,
  5985. Creater: creator,
  5986. BatchNumberId: 0,
  5987. WarehouseOutId: 0,
  5988. }
  5989. service.CreateGoodErrcode(goodErrcode)
  5990. }
  5991. //出库数量相加
  5992. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5993. if errss != nil {
  5994. goodErrcode := models.XtGoodErrcode{
  5995. UserOrgId: item.UserOrgId,
  5996. Errcode: "创建剩余库存字段报错",
  5997. GoodId: item.GoodId,
  5998. Status: 1,
  5999. Ctime: time.Now().Unix(),
  6000. Mtime: time.Now().Unix(),
  6001. Count: 0,
  6002. StockCount: 0,
  6003. Creater: item.Creater,
  6004. BatchNumberId: 0,
  6005. WarehouseOutId: 0,
  6006. }
  6007. service.CreateGoodErrcode(goodErrcode)
  6008. }
  6009. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6010. if len(list) == 0 {
  6011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6012. return
  6013. }
  6014. for _, item := range list {
  6015. prepare := models.DialysisBeforePrepare{
  6016. UserOrgId: adminInfo.Org.Id,
  6017. PatientId: patient_id,
  6018. RecordDate: record_time,
  6019. GoodId: item.GoodId,
  6020. GoodTypeId: item.GoodTypeId,
  6021. Count: item.Count,
  6022. Creater: adminInfo.AdminUser.Id,
  6023. Status: 1,
  6024. Ctime: time.Now().Unix(),
  6025. StorehouseId: houseConfig.StorehouseOutInfo,
  6026. }
  6027. //清空准备表数据
  6028. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6029. if errs != nil {
  6030. goodErrcode := models.XtGoodErrcode{
  6031. UserOrgId: adminInfo.Org.Id,
  6032. Errcode: "自动出库清空准备表数据报错",
  6033. GoodId: 0,
  6034. Status: 1,
  6035. Ctime: time.Now().Unix(),
  6036. Mtime: 0,
  6037. Count: 0,
  6038. StockCount: 0,
  6039. Creater: creator,
  6040. BatchNumberId: 0,
  6041. WarehouseOutId: 0,
  6042. }
  6043. service.CreateGoodErrcode(goodErrcode)
  6044. }
  6045. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6046. if errcodes != nil {
  6047. goodErrcode := models.XtGoodErrcode{
  6048. UserOrgId: adminInfo.Org.Id,
  6049. Errcode: "自动出库创建准备表数据报错",
  6050. GoodId: 0,
  6051. Status: 1,
  6052. Ctime: time.Now().Unix(),
  6053. Mtime: 0,
  6054. Count: 0,
  6055. StockCount: 0,
  6056. Creater: creator,
  6057. BatchNumberId: 0,
  6058. WarehouseOutId: 0,
  6059. }
  6060. service.CreateGoodErrcode(goodErrcode)
  6061. }
  6062. //查询默认仓库
  6063. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6064. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6065. var total_count int64
  6066. for _, it := range stockList {
  6067. total_count += it.StockCount
  6068. }
  6069. //基础库插入数据
  6070. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6071. if errcodes != nil {
  6072. goodErrcode := models.XtGoodErrcode{
  6073. UserOrgId: adminInfo.Org.Id,
  6074. Errcode: "自动出库基础库插入数据报错",
  6075. GoodId: 0,
  6076. Status: 1,
  6077. Ctime: time.Now().Unix(),
  6078. Mtime: 0,
  6079. Count: 0,
  6080. StockCount: 0,
  6081. Creater: creator,
  6082. BatchNumberId: 0,
  6083. WarehouseOutId: 0,
  6084. }
  6085. service.CreateGoodErrcode(goodErrcode)
  6086. }
  6087. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6088. var flush_count int64
  6089. for _, it := range goodList {
  6090. flush_count += it.StockCount
  6091. }
  6092. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6093. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6094. if errss != nil {
  6095. goodErrcode := models.XtGoodErrcode{
  6096. UserOrgId: item.OrgId,
  6097. Errcode: "自动出库剩余库存更新数据",
  6098. GoodId: item.GoodId,
  6099. Status: 1,
  6100. Ctime: time.Now().Unix(),
  6101. Mtime: 0,
  6102. Count: 0,
  6103. StockCount: 0,
  6104. Creater: creater,
  6105. BatchNumberId: 0,
  6106. WarehouseOutId: 0,
  6107. }
  6108. service.CreateGoodErrcode(goodErrcode)
  6109. }
  6110. }
  6111. }
  6112. }
  6113. c.ServeSuccessJSON(map[string]interface{}{
  6114. "msg": "提交成功",
  6115. "message": "2",
  6116. "good_name": "",
  6117. "specification_name": "",
  6118. })
  6119. return
  6120. }
  6121. if record.IsOpen == 1 {
  6122. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6123. //查询是否有库存
  6124. for _, item := range consumables {
  6125. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6126. if item.Count > warehouse.Count {
  6127. goodErrcode := models.XtGoodErrcode{
  6128. UserOrgId: item.UserOrgId,
  6129. Errcode: "自动出库库存不足",
  6130. GoodId: item.GoodId,
  6131. Status: 1,
  6132. Ctime: time.Now().Unix(),
  6133. Mtime: 0,
  6134. Count: 0,
  6135. StockCount: 0,
  6136. Creater: creator,
  6137. BatchNumberId: warehouse.ID,
  6138. WarehouseOutId: 0,
  6139. }
  6140. service.CreateGoodErrcode(goodErrcode)
  6141. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6142. c.ServeSuccessJSON(map[string]interface{}{
  6143. "message": "1",
  6144. "good_name": goodObj.GoodName,
  6145. "specification_name": goodObj.SpecificationName,
  6146. })
  6147. return
  6148. }
  6149. }
  6150. //查询是否有出库单
  6151. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6152. if err == gorm.ErrRecordNotFound {
  6153. //没有记录,则创建出库单
  6154. timeStr := time.Now().Format("2006-01-02")
  6155. timeArr := strings.Split(timeStr, "-")
  6156. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6157. total = total + 1
  6158. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6159. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6160. number = number + total
  6161. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6162. creater := adminInfo.AdminUser.Id
  6163. warehouseOut := models.WarehouseOut{
  6164. WarehouseOutOrderNumber: warehousing_out_order,
  6165. OperationTime: time.Now().Unix(),
  6166. OrgId: adminInfo.Org.Id,
  6167. Creater: creater,
  6168. Ctime: time.Now().Unix(),
  6169. Status: 1,
  6170. WarehouseOutTime: record_time,
  6171. Dealer: 0,
  6172. Manufacturer: 0,
  6173. Type: 1,
  6174. IsSys: 1,
  6175. StorehouseId: houseConfig.StorehouseOutInfo,
  6176. IsCheck: 1,
  6177. }
  6178. err := service.AddSigleWarehouseOut(&warehouseOut)
  6179. if err != nil {
  6180. goodErrcode := models.XtGoodErrcode{
  6181. UserOrgId: adminInfo.Org.Id,
  6182. Errcode: "创建出库单失败",
  6183. GoodId: 0,
  6184. Status: 1,
  6185. Ctime: time.Now().Unix(),
  6186. Mtime: 0,
  6187. Count: 0,
  6188. StockCount: 0,
  6189. Creater: creator,
  6190. BatchNumberId: 0,
  6191. WarehouseOutId: 0,
  6192. }
  6193. service.CreateGoodErrcode(goodErrcode)
  6194. utils.TraceLog("创建出库单失败 err = %v", err)
  6195. } else {
  6196. for _, item := range consumables {
  6197. //出库
  6198. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6199. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6200. if err == nil {
  6201. goodErrcode := models.XtGoodErrcode{
  6202. UserOrgId: adminInfo.Org.Id,
  6203. Errcode: "自动出库接口报错",
  6204. GoodId: 0,
  6205. Status: 1,
  6206. Ctime: time.Now().Unix(),
  6207. Mtime: 0,
  6208. Count: 0,
  6209. StockCount: 0,
  6210. Creater: creator,
  6211. BatchNumberId: 0,
  6212. WarehouseOutId: 0,
  6213. }
  6214. service.CreateGoodErrcode(goodErrcode)
  6215. utils.TraceLog("创建出库单失败 err = %v", err)
  6216. }
  6217. //查询
  6218. //出库数量相加
  6219. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6220. if errs != nil {
  6221. goodErrcode := models.XtGoodErrcode{
  6222. UserOrgId: item.UserOrgId,
  6223. Errcode: "创建剩余库存字段报错",
  6224. GoodId: item.GoodId,
  6225. Status: 1,
  6226. Ctime: time.Now().Unix(),
  6227. Mtime: 0,
  6228. Count: 0,
  6229. StockCount: 0,
  6230. Creater: creater,
  6231. BatchNumberId: 0,
  6232. WarehouseOutId: 0,
  6233. }
  6234. service.CreateGoodErrcode(goodErrcode)
  6235. }
  6236. }
  6237. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6238. if len(list) == 0 {
  6239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6240. return
  6241. }
  6242. for _, item := range list {
  6243. prepare := models.DialysisBeforePrepare{
  6244. UserOrgId: adminInfo.Org.Id,
  6245. PatientId: patient_id,
  6246. RecordDate: record_time,
  6247. GoodId: item.GoodId,
  6248. GoodTypeId: item.GoodTypeId,
  6249. Count: item.Count,
  6250. Creater: adminInfo.AdminUser.Id,
  6251. Status: 1,
  6252. Ctime: time.Now().Unix(),
  6253. StorehouseId: houseConfig.StorehouseOutInfo,
  6254. }
  6255. //清空准备表数据
  6256. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6257. if err != nil {
  6258. goodErrcode := models.XtGoodErrcode{
  6259. UserOrgId: item.OrgId,
  6260. Errcode: "自动出库清空准备表数据报错",
  6261. GoodId: item.GoodId,
  6262. Status: 1,
  6263. Ctime: time.Now().Unix(),
  6264. Mtime: 0,
  6265. Count: 0,
  6266. StockCount: 0,
  6267. Creater: creater,
  6268. BatchNumberId: 0,
  6269. WarehouseOutId: 0,
  6270. }
  6271. service.CreateGoodErrcode(goodErrcode)
  6272. }
  6273. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6274. if errs != nil {
  6275. goodErrcode := models.XtGoodErrcode{
  6276. UserOrgId: item.OrgId,
  6277. Errcode: "自动出库创建准备表数据报错",
  6278. GoodId: item.GoodId,
  6279. Status: 1,
  6280. Ctime: time.Now().Unix(),
  6281. Mtime: 0,
  6282. Count: 0,
  6283. StockCount: 0,
  6284. Creater: creater,
  6285. BatchNumberId: 0,
  6286. WarehouseOutId: 0,
  6287. }
  6288. service.CreateGoodErrcode(goodErrcode)
  6289. }
  6290. //查询默认仓库
  6291. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6292. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6293. var total_count int64
  6294. for _, it := range stockList {
  6295. total_count += it.StockCount
  6296. }
  6297. //基础库插入数据
  6298. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6299. if errcodes != nil {
  6300. goodErrcode := models.XtGoodErrcode{
  6301. UserOrgId: item.OrgId,
  6302. Errcode: "自动出库基础库插入数据",
  6303. GoodId: item.GoodId,
  6304. Status: 1,
  6305. Ctime: time.Now().Unix(),
  6306. Mtime: 0,
  6307. Count: 0,
  6308. StockCount: 0,
  6309. Creater: creater,
  6310. BatchNumberId: 0,
  6311. WarehouseOutId: 0,
  6312. }
  6313. service.CreateGoodErrcode(goodErrcode)
  6314. }
  6315. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6316. var flush_count int64
  6317. for _, it := range goodList {
  6318. flush_count += it.StockCount
  6319. }
  6320. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6321. if errsss != nil {
  6322. goodErrcode := models.XtGoodErrcode{
  6323. UserOrgId: item.OrgId,
  6324. Errcode: "自动出库剩余库存更新数据",
  6325. GoodId: item.GoodId,
  6326. Status: 1,
  6327. Ctime: time.Now().Unix(),
  6328. Mtime: 0,
  6329. Count: 0,
  6330. StockCount: 0,
  6331. Creater: creater,
  6332. BatchNumberId: 0,
  6333. WarehouseOutId: 0,
  6334. }
  6335. service.CreateGoodErrcode(goodErrcode)
  6336. }
  6337. }
  6338. }
  6339. //
  6340. } else if err == nil {
  6341. for _, item := range consumables {
  6342. //出库
  6343. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6344. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6345. if err != nil {
  6346. goodErrcode := models.XtGoodErrcode{
  6347. UserOrgId: adminInfo.Org.Id,
  6348. Errcode: "自动出库接口报错",
  6349. GoodId: 0,
  6350. Status: 1,
  6351. Ctime: time.Now().Unix(),
  6352. Mtime: 0,
  6353. Count: 0,
  6354. StockCount: 0,
  6355. Creater: creator,
  6356. BatchNumberId: 0,
  6357. WarehouseOutId: 0,
  6358. }
  6359. service.CreateGoodErrcode(goodErrcode)
  6360. }
  6361. //出库数量相加
  6362. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6363. if errss != nil {
  6364. goodErrcode := models.XtGoodErrcode{
  6365. UserOrgId: item.UserOrgId,
  6366. Errcode: "创建剩余库存字段报错",
  6367. GoodId: item.GoodId,
  6368. Status: 1,
  6369. Ctime: time.Now().Unix(),
  6370. Mtime: time.Now().Unix(),
  6371. Count: 0,
  6372. StockCount: 0,
  6373. Creater: item.Creater,
  6374. BatchNumberId: 0,
  6375. WarehouseOutId: 0,
  6376. }
  6377. service.CreateGoodErrcode(goodErrcode)
  6378. }
  6379. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6380. if len(list) == 0 {
  6381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6382. return
  6383. }
  6384. for _, item := range list {
  6385. prepare := models.DialysisBeforePrepare{
  6386. UserOrgId: adminInfo.Org.Id,
  6387. PatientId: patient_id,
  6388. RecordDate: record_time,
  6389. GoodId: item.GoodId,
  6390. GoodTypeId: item.GoodTypeId,
  6391. Count: item.Count,
  6392. Creater: adminInfo.AdminUser.Id,
  6393. Status: 1,
  6394. Ctime: time.Now().Unix(),
  6395. StorehouseId: houseConfig.StorehouseOutInfo,
  6396. }
  6397. //清空准备表数据
  6398. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6399. if errs != nil {
  6400. goodErrcode := models.XtGoodErrcode{
  6401. UserOrgId: adminInfo.Org.Id,
  6402. Errcode: "自动出库清空准备表数据报错",
  6403. GoodId: 0,
  6404. Status: 1,
  6405. Ctime: time.Now().Unix(),
  6406. Mtime: 0,
  6407. Count: 0,
  6408. StockCount: 0,
  6409. Creater: creator,
  6410. BatchNumberId: 0,
  6411. WarehouseOutId: 0,
  6412. }
  6413. service.CreateGoodErrcode(goodErrcode)
  6414. }
  6415. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6416. if errcodes != nil {
  6417. goodErrcode := models.XtGoodErrcode{
  6418. UserOrgId: adminInfo.Org.Id,
  6419. Errcode: "自动出库创建准备表数据报错",
  6420. GoodId: 0,
  6421. Status: 1,
  6422. Ctime: time.Now().Unix(),
  6423. Mtime: 0,
  6424. Count: 0,
  6425. StockCount: 0,
  6426. Creater: creator,
  6427. BatchNumberId: 0,
  6428. WarehouseOutId: 0,
  6429. }
  6430. service.CreateGoodErrcode(goodErrcode)
  6431. }
  6432. //查询默认仓库
  6433. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6434. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6435. var total_count int64
  6436. for _, it := range stockList {
  6437. total_count += it.StockCount
  6438. }
  6439. //基础库插入数据
  6440. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6441. if errcodes != nil {
  6442. goodErrcode := models.XtGoodErrcode{
  6443. UserOrgId: adminInfo.Org.Id,
  6444. Errcode: "自动出库基础库插入数据报错",
  6445. GoodId: 0,
  6446. Status: 1,
  6447. Ctime: time.Now().Unix(),
  6448. Mtime: 0,
  6449. Count: 0,
  6450. StockCount: 0,
  6451. Creater: creator,
  6452. BatchNumberId: 0,
  6453. WarehouseOutId: 0,
  6454. }
  6455. service.CreateGoodErrcode(goodErrcode)
  6456. }
  6457. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6458. var flush_count int64
  6459. for _, it := range goodList {
  6460. flush_count += it.StockCount
  6461. }
  6462. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6463. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6464. if errss != nil {
  6465. goodErrcode := models.XtGoodErrcode{
  6466. UserOrgId: item.OrgId,
  6467. Errcode: "自动出库剩余库存更新数据",
  6468. GoodId: item.GoodId,
  6469. Status: 1,
  6470. Ctime: time.Now().Unix(),
  6471. Mtime: 0,
  6472. Count: 0,
  6473. StockCount: 0,
  6474. Creater: creater,
  6475. BatchNumberId: 0,
  6476. WarehouseOutId: 0,
  6477. }
  6478. service.CreateGoodErrcode(goodErrcode)
  6479. }
  6480. }
  6481. }
  6482. }
  6483. c.ServeSuccessJSON(map[string]interface{}{
  6484. "msg": "提交成功",
  6485. "message": "2",
  6486. "good_name": "",
  6487. "specification_name": "",
  6488. })
  6489. return
  6490. } else {
  6491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6492. return
  6493. }
  6494. }
  6495. func (c *DialysisAPIController) EditConsumables() {
  6496. patient_id, _ := c.GetInt64("patient_id", 0)
  6497. record_date := c.GetString("record_time")
  6498. if patient_id <= 0 {
  6499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6500. return
  6501. }
  6502. adminInfo := c.GetMobileAdminUserInfo()
  6503. timeLayout := "2006-01-02"
  6504. loc, _ := time.LoadLocation("Local")
  6505. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6506. record_time := theRecordTime.Unix()
  6507. // 查询信息规挡的设置天数
  6508. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6509. if infor.ID > 0 && infor.WeekDay > 0 {
  6510. var cha_time int64
  6511. timeNowStr := time.Now().Format("2006-01-02")
  6512. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6513. //今日的日期减去设置的日期
  6514. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6515. if cha_time >= record_time {
  6516. //查询审核是否允许
  6517. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6518. //申请状态不允许的情况 拒绝修改
  6519. if infor.ApplicationStatus != 1 {
  6520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6521. return
  6522. }
  6523. }
  6524. }
  6525. dataBody := make(map[string]interface{}, 0)
  6526. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6527. if err != nil {
  6528. utils.ErrorLog(err.Error())
  6529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6530. return
  6531. }
  6532. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6533. var beforePrepares []*models.DialysisBeforePrepareGoods
  6534. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6535. var cancelbefor []*models.DialysisBeforePrepareGoods
  6536. var outbefor []*models.DialysisBeforePrepareGoods
  6537. //判断是否开启自动出库
  6538. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6539. if record.IsOpen == 1 {
  6540. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6541. goods, _ := dataBody["goods"].([]interface{})
  6542. if len(goods) > 0 {
  6543. for _, item := range goods {
  6544. items := item.(map[string]interface{})
  6545. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6546. utils.ErrorLog("good_id")
  6547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6548. return
  6549. }
  6550. good_id := int64(items["good_id"].(float64))
  6551. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6552. utils.ErrorLog("good_type_id")
  6553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6554. return
  6555. }
  6556. good_type_id := int64(items["good_type_id"].(float64))
  6557. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6558. utils.ErrorLog("count")
  6559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6560. return
  6561. }
  6562. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6563. commdity_code := items["commdity_code"].(string)
  6564. fmt.Println(commdity_code)
  6565. prepareGoods := &models.DialysisBeforePrepareGoods{
  6566. GoodTypeId: good_type_id,
  6567. GoodId: good_id,
  6568. Count: count,
  6569. StorehouseId: houseConfig.StorehouseOutInfo,
  6570. }
  6571. beforePrepares = append(beforePrepares, prepareGoods)
  6572. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6573. GoodTypeId: good_type_id,
  6574. GoodId: good_id,
  6575. Count: count,
  6576. StorehouseId: houseConfig.StorehouseOutInfo,
  6577. }
  6578. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6579. }
  6580. for _, item := range beforePrepares {
  6581. //1.查看该患者该耗材型号最后一次出库数量
  6582. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6583. //判断当前出库数量和最后一次出库数量的大小
  6584. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6585. if item.Count < goodInfo.Count {
  6586. cancelbefor = append(cancelbefor, item)
  6587. }
  6588. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6589. if item.Count > goodInfo.Count {
  6590. outbefor = append(outbefor, item)
  6591. }
  6592. //处理编辑耗材新增不了的问题
  6593. if goodInfo.Count == item.Count {
  6594. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6595. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6596. }
  6597. }
  6598. if len(cancelbefor) > 0 {
  6599. //退库
  6600. for _, item := range cancelbefor {
  6601. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6602. creater := adminInfo.AdminUser.Id
  6603. //查询该患者当天已经出库的耗材信息
  6604. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6605. var delete_count int64 = 0
  6606. delete_count = warehouseOutInfos.Count - item.Count
  6607. //增加库存数量
  6608. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6609. //减少实际出库库存数量
  6610. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6611. // 删除出库完成后,要增加对应批次的库存数量
  6612. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6613. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6614. //更新剩余库存
  6615. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6616. var flush_count int64
  6617. for _, it := range goodListOne {
  6618. flush_count += it.StockCount
  6619. }
  6620. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6621. //查询剩余库存
  6622. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6623. var sum_count int64
  6624. for _, item := range goodList {
  6625. sum_count += item.StockCount
  6626. }
  6627. // 在出库记录表里记录退库详情
  6628. warehouseOutInfo := &models.WarehouseOutInfo{
  6629. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6630. WarehouseOutId: warehouseOut.ID,
  6631. Status: 1,
  6632. Ctime: time.Now().Unix(),
  6633. OrgId: adminInfo.Org.Id,
  6634. Type: 1,
  6635. IsSys: 1,
  6636. SysRecordTime: record_time,
  6637. GoodTypeId: item.GoodTypeId,
  6638. GoodId: item.GoodId,
  6639. PatientId: patient_id,
  6640. ConsumableType: 2,
  6641. StorehouseId: houseConfig.StorehouseOutInfo,
  6642. IsCheck: 1,
  6643. OverCount: sum_count,
  6644. }
  6645. warehouseOutInfo.Count = item.Count
  6646. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6647. warehouseOutInfo.Price = stockInInfo.Price
  6648. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6649. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6650. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6651. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6652. warehouseOutInfo.Number = warehouseOutInfos.Number
  6653. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6654. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6655. //查找当天是否存在出库记录
  6656. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6657. if errcod == gorm.ErrRecordNotFound {
  6658. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6659. //插入详情明细表
  6660. stockFlow := models.VmStockFlow{
  6661. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6662. WarehouseOutId: warehouseOut.ID,
  6663. GoodId: item.GoodId,
  6664. Number: warehouseOutInfos.Number,
  6665. ProductDate: stockInInfo.ProductDate,
  6666. ExpireDate: stockInInfo.ExpiryDate,
  6667. Count: item.Count,
  6668. Price: stockInInfo.Price,
  6669. Status: 1,
  6670. Ctime: record_time,
  6671. UserOrgId: adminInfo.Org.Id,
  6672. Manufacturer: stockInInfo.Manufacturer,
  6673. Dealer: stockInInfo.Dealer,
  6674. LicenseNumber: stockInInfo.LicenseNumber,
  6675. IsEdit: 2,
  6676. Creator: creater,
  6677. SystemTime: record_time,
  6678. ConsumableType: 3,
  6679. WarehousingDetailId: 0,
  6680. IsSys: 1,
  6681. UpdateCreator: creater,
  6682. PatientId: patient_id,
  6683. StorehouseId: houseConfig.StorehouseOutInfo,
  6684. }
  6685. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6686. if errflow == gorm.ErrRecordNotFound {
  6687. //创建流水表
  6688. err := service.CreateStockFlowOne(stockFlow)
  6689. fmt.Println("err", err)
  6690. } else if errflow == nil {
  6691. //插入详情明细表
  6692. stockFlow := models.VmStockFlow{
  6693. ID: exsit.ID,
  6694. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6695. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6696. WarehouseOutId: warehouseOut.ID,
  6697. GoodId: item.GoodId,
  6698. Number: warehouseOutInfos.Number,
  6699. ProductDate: stockInInfo.ProductDate,
  6700. ExpireDate: stockInInfo.ExpiryDate,
  6701. Count: exsit.Count - delete_count,
  6702. Price: stockInInfo.Price,
  6703. Status: 1,
  6704. Ctime: record_time,
  6705. UserOrgId: adminInfo.Org.Id,
  6706. Manufacturer: stockInInfo.Manufacturer,
  6707. Dealer: stockInInfo.Dealer,
  6708. LicenseNumber: stockInInfo.LicenseNumber,
  6709. IsEdit: 2,
  6710. Creator: creater,
  6711. SystemTime: record_time,
  6712. ConsumableType: 3,
  6713. WarehousingDetailId: 0,
  6714. IsSys: 1,
  6715. UpdateCreator: creater,
  6716. PatientId: patient_id,
  6717. StorehouseId: houseConfig.StorehouseOutInfo,
  6718. }
  6719. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6720. }
  6721. } else if errcod == nil {
  6722. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6723. //查询剩余库存
  6724. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6725. var sum_count int64
  6726. for _, item := range goodList {
  6727. sum_count += item.StockCount
  6728. }
  6729. //创建退库单,生成退库数据
  6730. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6731. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6732. operation_time := time.Now().Unix()
  6733. creater := adminInfo.AdminUser.Id
  6734. //创建退库单
  6735. timeStr := time.Now().Format("2006-01-02")
  6736. timeArr := strings.Split(timeStr, "-")
  6737. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6738. total = total + 1
  6739. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6740. cancelStock := models.CancelStock{
  6741. OrderNumber: orderNumber,
  6742. OperaTime: operation_time,
  6743. OrgId: adminInfo.Org.Id,
  6744. Creater: creater,
  6745. Ctime: time.Now().Unix(),
  6746. Status: 1,
  6747. ReturnTime: record_time,
  6748. Type: 1,
  6749. StorehouseId: houseConfig.StorehouseOutInfo,
  6750. IsCheck: 1,
  6751. }
  6752. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6753. if msgerrkonde == gorm.ErrRecordNotFound {
  6754. service.AddSigleCancelStock(&cancelStock)
  6755. }
  6756. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6757. //查询是否有出库
  6758. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6759. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6760. deaerler, _ := service.GetDealerById(info.Dealer)
  6761. if info.ID > 0 {
  6762. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6763. cancelStockInfo := models.CancelStockInfo{
  6764. GoodId: item.GoodId,
  6765. CancelStockId: cancel.ID,
  6766. GoodTypeId: good.GoodTypeId,
  6767. Count: delete_count,
  6768. Price: info.Price,
  6769. Total: 0,
  6770. ProductDate: info.ProductDate,
  6771. ExpiryDate: info.ExpiryDate,
  6772. Ctime: time.Now().Unix(),
  6773. Status: 1,
  6774. OrgId: adminInfo.Org.Id,
  6775. OrderNumber: cancel.OrderNumber,
  6776. Type: 0,
  6777. Dealer: deaerler.DealerName,
  6778. Manufacturer: manufacturer.ManufacturerName,
  6779. Number: info.Number,
  6780. RegisterAccount: "",
  6781. Remark: "",
  6782. WarehouseInfoId: info.WarehouseInfotId,
  6783. PatientId: info.PatientId,
  6784. RecordDate: info.SysRecordTime,
  6785. StorehouseId: houseConfig.StorehouseOutInfo,
  6786. IsCheck: 1,
  6787. }
  6788. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6789. //退库数量增加
  6790. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6791. //查询剩余库存
  6792. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6793. var over_count int64
  6794. for _, it := range goodList {
  6795. over_count += it.StockCount
  6796. }
  6797. flow := models.VmStockFlow{
  6798. WarehousingId: info.WarehouseInfotId,
  6799. GoodId: item.GoodId,
  6800. Number: info.Number,
  6801. LicenseNumber: info.LicenseNumber,
  6802. Count: delete_count,
  6803. UserOrgId: adminInfo.Org.Id,
  6804. PatientId: patient_id,
  6805. SystemTime: info.SysRecordTime,
  6806. ConsumableType: 7,
  6807. IsSys: 0,
  6808. WarehousingOrder: "",
  6809. WarehouseOutId: info.WarehouseOutId,
  6810. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6811. IsEdit: 0,
  6812. CancelStockId: cancel.ID,
  6813. CancelOrderNumber: cancel.OrderNumber,
  6814. Manufacturer: manufacturer.ID,
  6815. Dealer: 0,
  6816. Creator: adminInfo.AdminUser.Id,
  6817. UpdateCreator: 0,
  6818. Status: 1,
  6819. Ctime: record_time,
  6820. Mtime: 0,
  6821. Price: info.Price,
  6822. WarehousingDetailId: info.WarehouseInfotId,
  6823. WarehouseOutDetailId: info.ID,
  6824. CancelOutDetailId: cancelInfo.ID,
  6825. ProductDate: info.ProductDate,
  6826. ExpireDate: info.ExpiryDate,
  6827. StorehouseId: houseConfig.StorehouseOutInfo,
  6828. OverCount: over_count,
  6829. }
  6830. service.CreateStockFlowOne(flow)
  6831. }
  6832. }
  6833. //更改自动出库的表格
  6834. details := models.BloodAutomaticReduceDetail{
  6835. WarehouseOutId: warehouseOutInfo.ID,
  6836. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6837. PatientId: patient_id,
  6838. Ctime: time.Now().Unix(),
  6839. Mtime: time.Now().Unix(),
  6840. Status: 1,
  6841. RecordTime: record_time,
  6842. OrgId: adminInfo.Org.Id,
  6843. GoodId: item.GoodId,
  6844. GoodTypeId: item.GoodTypeId,
  6845. Count: item.Count,
  6846. StorehouseId: houseConfig.StorehouseOutInfo,
  6847. }
  6848. //查询当天耗材是否已经存在数据
  6849. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6850. if errcode == gorm.ErrRecordNotFound {
  6851. service.CreateAutoReduceRecord(&details)
  6852. } else if errcode == nil {
  6853. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6854. service.CreateAutoReduceRecord(&details)
  6855. }
  6856. //查询默认仓库
  6857. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6858. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6859. var total_count int64
  6860. for _, it := range stockList {
  6861. total_count += it.StockCount
  6862. }
  6863. //基础库插入数据
  6864. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6865. }
  6866. }
  6867. if len(outbefor) > 0 {
  6868. //出库
  6869. for _, item := range outbefor {
  6870. var last_total int64
  6871. //1.查看该患者该耗材型号最后一次出库数量
  6872. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6873. //计算当前出库和最后一次出库数据相差数据
  6874. last_total = item.Count - goodInfoOne.Count
  6875. //查询该耗材的总库存
  6876. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6877. // 如果库存差大于剩余库存则提示库存不足
  6878. if last_total > wareinfo.StockCount {
  6879. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6880. c.ServeSuccessJSON(map[string]interface{}{
  6881. "message": "1",
  6882. "good_name": goodObj.GoodName,
  6883. "specification_name": goodObj.SpecificationName,
  6884. })
  6885. return
  6886. } else {
  6887. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6888. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6889. if err == gorm.ErrRecordNotFound {
  6890. //没有记录,则创建出库单
  6891. timeStr := time.Now().Format("2006-01-02")
  6892. timeArr := strings.Split(timeStr, "-")
  6893. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6894. total = total + 1
  6895. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6896. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6897. number = number + total
  6898. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6899. warehouseOut := models.WarehouseOut{
  6900. WarehouseOutOrderNumber: warehousing_out_order,
  6901. OperationTime: time.Now().Unix(),
  6902. OrgId: adminInfo.Org.Id,
  6903. Creater: adminInfo.AdminUser.Id,
  6904. Ctime: time.Now().Unix(),
  6905. Status: 1,
  6906. WarehouseOutTime: record_time,
  6907. Dealer: 0,
  6908. Manufacturer: 0,
  6909. Type: 1,
  6910. IsSys: 1,
  6911. StorehouseId: houseConfig.StorehouseOutInfo,
  6912. IsCheck: 1,
  6913. }
  6914. service.AddSigleWarehouseOut(&warehouseOut)
  6915. }
  6916. //出库
  6917. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6918. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6919. //1.查看该患者该耗材型号最后一次出库数量
  6920. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6921. prepare := models.DialysisBeforePrepare{
  6922. UserOrgId: adminInfo.Org.Id,
  6923. PatientId: patient_id,
  6924. RecordDate: record_time,
  6925. GoodId: item.GoodId,
  6926. GoodTypeId: item.GoodTypeId,
  6927. Count: item.Count - goodInfoTwo.Count,
  6928. Ctime: time.Now().Unix(),
  6929. Mtime: 0,
  6930. Creater: adminInfo.AdminUser.Id,
  6931. Modifier: adminInfo.AdminUser.Id,
  6932. Status: 1,
  6933. CommdityCode: "",
  6934. NewCount: 0,
  6935. ProjectId: 0,
  6936. StorehouseId: houseConfig.StorehouseOutInfo,
  6937. }
  6938. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6939. //增加出库数量
  6940. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6941. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6942. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6943. var total_count int64
  6944. for _, it := range stockList {
  6945. total_count += it.StockCount
  6946. }
  6947. //基础库插入数据
  6948. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6949. //剩余库存
  6950. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6951. var flush_count int64
  6952. for _, it := range goodList {
  6953. flush_count += it.StockCount
  6954. }
  6955. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6956. }
  6957. }
  6958. }
  6959. //查询今日出库数据
  6960. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6961. for _, it := range list {
  6962. prepare := models.DialysisBeforePrepare{
  6963. UserOrgId: it.OrgId,
  6964. PatientId: patient_id,
  6965. RecordDate: it.RecordTime,
  6966. GoodId: it.GoodId,
  6967. GoodTypeId: it.GoodTypeId,
  6968. Count: it.Count,
  6969. Ctime: time.Now().Unix(),
  6970. Creater: adminInfo.AdminUser.Id,
  6971. Status: 1,
  6972. StorehouseId: houseConfig.StorehouseOutInfo,
  6973. ProjectId: it.ProjectId,
  6974. }
  6975. //删除准备表数据
  6976. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6977. service.CreateDialysisBeforePrepareOne(&prepare)
  6978. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6979. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6980. var total_count int64
  6981. for _, it := range stockList {
  6982. total_count += it.StockCount
  6983. }
  6984. //基础库插入数据
  6985. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6986. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6987. var flush_count int64
  6988. for _, it := range goodList {
  6989. flush_count += it.StockCount
  6990. }
  6991. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6992. }
  6993. }
  6994. }
  6995. //更新自动出库的地方
  6996. var errs error
  6997. if errs == nil {
  6998. c.ServeSuccessJSON(map[string]interface{}{
  6999. "msg": "修改成功",
  7000. "message": "2",
  7001. "good_name": "",
  7002. "specification_name": "",
  7003. })
  7004. return
  7005. } else {
  7006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7007. return
  7008. }
  7009. }
  7010. }
  7011. func (c *DialysisAPIController) GetDialysisGoods() {
  7012. schedualDate := c.GetString("schedule_date")
  7013. schedule_type, _ := c.GetInt64("schedule_type")
  7014. partition_id, _ := c.GetInt64("partition_id")
  7015. page, _ := c.GetInt("page")
  7016. patient_id, _ := c.GetInt64("patient_id")
  7017. schedualEndDate := int64(0)
  7018. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7019. if parseDateErr != nil && len(schedualDate) != 0 {
  7020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7021. return
  7022. }
  7023. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7024. if parseDateErr != nil && len(schedualDate) != 0 {
  7025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7026. return
  7027. }
  7028. schedualEndDate = endDate.Unix()
  7029. adminUser := c.GetMobileAdminUserInfo()
  7030. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7031. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7032. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7033. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7034. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7035. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7036. //获取当天该病人的透析处方
  7037. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7038. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7039. if err == gorm.ErrRecordNotFound {
  7040. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7041. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7042. if patient_id != 0 {
  7043. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7044. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7045. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7046. //获取患者总的出库数据
  7047. item.LastAutomaticReduceDetail = goodUser
  7048. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7049. item.Project = project
  7050. for _, it := range item.AutomaticReduceDetail {
  7051. var total int64
  7052. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7053. for _, its := range auto {
  7054. total += its.Count
  7055. }
  7056. it.Count = total
  7057. }
  7058. }
  7059. }
  7060. c.ServeSuccessJSON(map[string]interface{}{
  7061. "dialysis_goods": dialysisGoods,
  7062. "good_type": goodTypes,
  7063. "total": total,
  7064. "prescribe": prescribe,
  7065. "good_info": good_info,
  7066. "warehouseOutList": warehouseOutList,
  7067. "config": config,
  7068. "outConfig": outConfig,
  7069. "settleConfig": settleConfig,
  7070. })
  7071. return
  7072. } else if err == nil {
  7073. //获取当天排班的每个患者的库存使用情况
  7074. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7075. //获取患者总的出库数据
  7076. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7077. if patient_id != 0 {
  7078. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7079. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7080. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7081. item.Project = project
  7082. item.LastAutomaticReduceDetail = goodUser
  7083. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7084. for _, it := range item.AutomaticReduceDetail {
  7085. var total int64
  7086. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7087. for _, its := range auto {
  7088. total += its.Count
  7089. }
  7090. it.Count = total
  7091. }
  7092. }
  7093. }
  7094. if err == nil {
  7095. c.ServeSuccessJSON(map[string]interface{}{
  7096. "dialysis_goods": dialysisGoods,
  7097. "good_type": goodTypes,
  7098. "total": total,
  7099. "prescribe": prescribe,
  7100. "good_info": good_info,
  7101. "project": project,
  7102. "warehouseOutList": warehouseOutList,
  7103. "config": config,
  7104. "outConfig": outConfig,
  7105. "settleConfig": settleConfig,
  7106. })
  7107. return
  7108. } else {
  7109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7110. return
  7111. }
  7112. } else if err != nil {
  7113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7114. return
  7115. }
  7116. }
  7117. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7118. start_time := c.GetString("start_time")
  7119. end_time := c.GetString("end_time")
  7120. timeLayout := "2006-01-02"
  7121. loc, _ := time.LoadLocation("Local")
  7122. var theStartTime int64
  7123. if len(start_time) > 0 {
  7124. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7125. if err != nil {
  7126. utils.ErrorLog(err.Error())
  7127. }
  7128. theStartTime = theTime.Unix()
  7129. }
  7130. var theEndtTime int64
  7131. if len(end_time) > 0 {
  7132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7133. if err != nil {
  7134. utils.ErrorLog(err.Error())
  7135. }
  7136. theEndtTime = theTime.Unix()
  7137. }
  7138. adminUser := c.GetMobileAdminUserInfo()
  7139. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7140. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7141. if err == nil {
  7142. c.ServeSuccessJSON(map[string]interface{}{
  7143. "stock_out": outInfo,
  7144. "stockCount": stockCount,
  7145. })
  7146. return
  7147. } else {
  7148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7149. return
  7150. }
  7151. }
  7152. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7153. patient_id, _ := c.GetInt64("patient_id", 0)
  7154. record_time := c.GetString("record_time")
  7155. adminUser := c.GetMobileAdminUserInfo()
  7156. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7157. if parseDateErr != nil && len(record_time) != 0 {
  7158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7159. return
  7160. }
  7161. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7162. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7163. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7164. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7165. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7166. //获取今日患者的透析处方参数
  7167. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7168. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7169. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7170. c.ServeSuccessJSON(map[string]interface{}{
  7171. "good_type": goodTypes,
  7172. "good_user": goodUser,
  7173. "good_info": good_info,
  7174. "last_good_user": lastGoodUserDetial,
  7175. "project": project,
  7176. "prescription": prescribe,
  7177. "outInfo": outInfo,
  7178. "configs": configs,
  7179. })
  7180. return
  7181. }
  7182. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7183. patient_id, _ := c.GetInt64("patient_id", 0)
  7184. record_date := c.GetString("record_time")
  7185. timeLayout := "2006-01-02"
  7186. loc, _ := time.LoadLocation("Local")
  7187. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7188. record_time := theRecordTime.Unix()
  7189. adminInfo := c.GetMobileAdminUserInfo()
  7190. dataBody := make(map[string]interface{}, 0)
  7191. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7192. if err != nil {
  7193. utils.ErrorLog(err.Error())
  7194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7195. return
  7196. }
  7197. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7198. var beforePrepares []*models.DialysisBeforePrepareGoods
  7199. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7200. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7201. goods, _ := dataBody["goods"].([]interface{})
  7202. if len(goods) > 0 {
  7203. for _, item := range goods {
  7204. items := item.(map[string]interface{})
  7205. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7206. utils.ErrorLog("good_id")
  7207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7208. return
  7209. }
  7210. good_id := int64(items["good_id"].(float64))
  7211. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7212. utils.ErrorLog("good_type_id")
  7213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7214. return
  7215. }
  7216. good_type_id := int64(items["good_type_id"].(float64))
  7217. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7218. utils.ErrorLog("count")
  7219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7220. return
  7221. }
  7222. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7223. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7224. utils.ErrorLog("project_id")
  7225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7226. return
  7227. }
  7228. project_id := int64(items["project_id"].(float64))
  7229. new_count := int64(items["new_count"].(float64))
  7230. old_count := int64(items["old_count"].(float64))
  7231. prepare := &models.DialysisBeforePrepareGoods{
  7232. GoodId: good_id,
  7233. GoodTypeId: good_type_id,
  7234. Count: count,
  7235. ProjectId: project_id,
  7236. StorehouseId: houseConfig.StorehouseOutInfo,
  7237. NewCount: new_count,
  7238. OldCount: old_count,
  7239. }
  7240. beforePrepares = append(beforePrepares, prepare)
  7241. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7242. GoodId: good_id,
  7243. GoodTypeId: good_type_id,
  7244. Count: count,
  7245. ProjectId: project_id,
  7246. StorehouseId: houseConfig.StorehouseOutInfo,
  7247. NewCount: new_count,
  7248. OldCount: old_count,
  7249. }
  7250. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7251. }
  7252. }
  7253. }
  7254. //查询是否有库存
  7255. for _, item := range beforePrepares {
  7256. if item.NewCount > 0 {
  7257. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7258. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7259. if item.Count > warehouse.Count {
  7260. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7261. c.ServeSuccessJSON(map[string]interface{}{
  7262. "message": "1",
  7263. "good_name": goodObj.GoodName,
  7264. "specification_name": goodObj.SpecificationName,
  7265. })
  7266. return
  7267. }
  7268. }
  7269. }
  7270. // 查询信息规挡的设置天数
  7271. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7272. if infor.ID > 0 && infor.WeekDay > 0 {
  7273. var cha_time int64
  7274. timeNowStr := time.Now().Format("2006-01-02")
  7275. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7276. //今日的日期减去设置的日期
  7277. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7278. if cha_time >= record_time {
  7279. //查询审核是否允许
  7280. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7281. //申请状态不允许的情况 拒绝修改
  7282. if infor.ApplicationStatus != 1 {
  7283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7284. return
  7285. }
  7286. }
  7287. }
  7288. //出库逻辑
  7289. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7290. if err != nil {
  7291. utils.ErrorLog(err.Error())
  7292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7293. return
  7294. }
  7295. finish := models.XtDialysisFinish{
  7296. IsFinish: 1,
  7297. UserOrgId: adminInfo.Org.Id,
  7298. Status: 1,
  7299. Ctime: time.Now().Unix(),
  7300. Mtime: 0,
  7301. Module: 11,
  7302. RecordDate: record_time,
  7303. Sourse: 1,
  7304. PatientId: patient_id,
  7305. }
  7306. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7307. if dialysisFinish.ID == 0 {
  7308. service.CreateDialysisFinish(finish)
  7309. }
  7310. //查询当天出库的数据
  7311. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7312. for _, item := range list {
  7313. prepare := models.DialysisBeforePrepare{
  7314. UserOrgId: item.OrgId,
  7315. PatientId: item.PatientId,
  7316. RecordDate: item.RecordTime,
  7317. GoodId: item.GoodId,
  7318. GoodTypeId: item.GoodTypeId,
  7319. Count: item.Count,
  7320. Creater: adminInfo.AdminUser.Id,
  7321. Status: 1,
  7322. Ctime: time.Now().Unix(),
  7323. ProjectId: item.ProjectId,
  7324. StorehouseId: houseConfig.StorehouseOutInfo,
  7325. }
  7326. //清空准备表的数据
  7327. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7328. //插入准备表数据
  7329. service.CreateDialysisBeforePrepareOne(&prepare)
  7330. //查询默认仓库
  7331. //查询默认仓库
  7332. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7333. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7334. var total_count int64
  7335. for _, it := range stockList {
  7336. total_count += it.StockCount
  7337. }
  7338. //基础库插入数据
  7339. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7340. ////更新剩余库存
  7341. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7342. var flush_count int64
  7343. for _, it := range goodList {
  7344. flush_count += it.StockCount
  7345. }
  7346. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7347. if errs != nil {
  7348. goodErrcode := models.XtGoodErrcode{
  7349. UserOrgId: item.OrgId,
  7350. Errcode: "手动出库更新剩余出库失败",
  7351. GoodId: item.GoodId,
  7352. Status: 1,
  7353. Ctime: time.Now().Unix(),
  7354. Mtime: 0,
  7355. Count: 0,
  7356. StockCount: 0,
  7357. Creater: adminInfo.AdminUser.Id,
  7358. BatchNumberId: 0,
  7359. WarehouseOutId: 0,
  7360. }
  7361. service.CreateGoodErrcode(goodErrcode)
  7362. }
  7363. }
  7364. //更新自动出库的地方
  7365. var errs error
  7366. if errs == nil {
  7367. c.ServeSuccessJSON(map[string]interface{}{
  7368. "msg": "修改成功",
  7369. "message": "2",
  7370. "good_name": "",
  7371. "specification_name": "",
  7372. })
  7373. return
  7374. } else {
  7375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7376. return
  7377. }
  7378. }
  7379. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7380. newArr = make([]*models.DialysisBeforePrepare, 0)
  7381. for i := 0; i < len(arr); i++ {
  7382. repeat := false
  7383. for j := i + 1; j < len(arr); j++ {
  7384. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7385. repeat = true
  7386. break
  7387. }
  7388. }
  7389. if !repeat {
  7390. newArr = append(newArr, arr[i])
  7391. }
  7392. }
  7393. return
  7394. }
  7395. func (c *DialysisAPIController) GetAllDrug() {
  7396. patient_id, _ := c.GetInt64("patient_id", 0)
  7397. adminInfo := c.GetMobileAdminUserInfo()
  7398. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7399. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7400. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7401. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7402. c.ServeSuccessJSON(map[string]interface{}{
  7403. "base_drug_config": drugStockConfig,
  7404. "private_drug_config": privateDrugConfig,
  7405. "base_drug_list": drugList,
  7406. "private_drug_list": privateDrugList,
  7407. })
  7408. }
  7409. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7410. newArr = make([]*models.DialysisBeforePrepare, 0)
  7411. for i := 0; i < len(arr); i++ {
  7412. repeat := false
  7413. for j := i + 1; j < len(arr); j++ {
  7414. if arr[i].GoodId == arr[j].GoodId {
  7415. repeat = true
  7416. break
  7417. }
  7418. }
  7419. if !repeat {
  7420. newArr = append(newArr, arr[i])
  7421. }
  7422. }
  7423. return
  7424. }
  7425. func (c *DialysisAPIController) GetDepartment() {
  7426. adminInfo := c.GetMobileAdminUserInfo()
  7427. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7428. if err == nil {
  7429. c.ServeSuccessJSON(map[string]interface{}{
  7430. "departments": departments,
  7431. })
  7432. } else {
  7433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7434. return
  7435. }
  7436. }
  7437. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7438. types, _ := c.GetInt("type", 0)
  7439. start_time := c.GetString("start_time")
  7440. end_time := c.GetString("end_time")
  7441. orgId := c.GetMobileAdminUserInfo().Org.Id
  7442. timeLayout := "2006-01-02"
  7443. loc, _ := time.LoadLocation("Local")
  7444. var startTime int64
  7445. if len(start_time) > 0 {
  7446. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7447. if err != nil {
  7448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7449. return
  7450. }
  7451. startTime = theTime.Unix()
  7452. }
  7453. var endTime int64
  7454. if len(end_time) > 0 {
  7455. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7456. if err != nil {
  7457. utils.ErrorLog(err.Error())
  7458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7459. return
  7460. }
  7461. endTime = theTime.Unix()
  7462. }
  7463. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7464. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7465. if err != nil {
  7466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7467. } else {
  7468. c.ServeSuccessJSON(map[string]interface{}{
  7469. "list": list,
  7470. "type": types,
  7471. "stockTotal": stockTotal,
  7472. })
  7473. }
  7474. }
  7475. func (c *DialysisAPIController) GetPrescriptionList() {
  7476. start_time := c.GetString("start_time")
  7477. end_time := c.GetString("end_time")
  7478. schedule_type, _ := c.GetInt64("schedule_type")
  7479. partion_id, _ := c.GetInt64("partion_id")
  7480. orgId := c.GetMobileAdminUserInfo().Org.Id
  7481. timeLayout := "2006-01-02"
  7482. loc, _ := time.LoadLocation("Local")
  7483. var startTime int64
  7484. if len(start_time) > 0 {
  7485. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7486. if err != nil {
  7487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7488. return
  7489. }
  7490. startTime = theTime.Unix()
  7491. }
  7492. var endTime int64
  7493. if len(end_time) > 0 {
  7494. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7495. if err != nil {
  7496. utils.ErrorLog(err.Error())
  7497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7498. return
  7499. }
  7500. endTime = theTime.Unix()
  7501. }
  7502. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7503. fmt.Println("schedulelist22222222", schedulelist)
  7504. c.ServeSuccessJSON(map[string]interface{}{
  7505. "list": schedulelist,
  7506. })
  7507. return
  7508. }
  7509. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7510. ids := c.GetString("ids")
  7511. //patient_id, _ := c.GetInt64("patient_id")
  7512. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7513. idArray := strings.Split(ids, ",")
  7514. err := service.BatchDeleteMonitor(idArray)
  7515. fmt.Print("err", err)
  7516. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7517. //redis := service.RedisClient()
  7518. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7519. //redis.Set(key, "", time.Second)
  7520. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7521. //redis.Set(keyOne, "", time.Second)
  7522. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7523. //redis.Close()
  7524. c.ServeSuccessJSON(map[string]interface{}{
  7525. "msg": "批量删除成功",
  7526. })
  7527. return
  7528. }
  7529. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7530. id, _ := c.GetInt64("id")
  7531. timeLayout := "2006-01-02"
  7532. loc, _ := time.LoadLocation("Local")
  7533. //start_time := time.Now().Format("2006-01-02")
  7534. start_time := c.GetString("start_time")
  7535. end_time := c.GetString("end_time")
  7536. var startdateunix int64
  7537. if len(start_time) > 0 {
  7538. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7539. if err != nil {
  7540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7541. return
  7542. }
  7543. startdateunix = theTime.Unix()
  7544. }
  7545. var enddateunix int64
  7546. if len(end_time) > 0 {
  7547. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7548. if err != nil {
  7549. utils.ErrorLog(err.Error())
  7550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7551. return
  7552. }
  7553. enddateunix = theTime.Unix()
  7554. }
  7555. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7556. //nowTime := time.Now()
  7557. //endTime := nowTime.AddDate(-30, 0, 0)
  7558. //endTimes := endTime.Format("2006-01-02")
  7559. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7560. org_id := c.GetMobileAdminUserInfo().Org.Id
  7561. //if org_id == 10579 {
  7562. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7563. // c.ServeSuccessJSON(map[string]interface{}{
  7564. // "list": list,
  7565. // })
  7566. // return
  7567. //} else {
  7568. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7569. // c.ServeSuccessJSON(map[string]interface{}{
  7570. // "list": list,
  7571. // })
  7572. // return
  7573. //}
  7574. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7575. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7576. c.ServeSuccessJSON(map[string]interface{}{
  7577. "list": list,
  7578. })
  7579. return
  7580. } else {
  7581. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7582. c.ServeSuccessJSON(map[string]interface{}{
  7583. "list": list,
  7584. })
  7585. }
  7586. return
  7587. }
  7588. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7589. dataBody := make(map[string]interface{}, 0)
  7590. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7591. ids := c.GetString("ids")
  7592. idArray := strings.Split(ids, ",")
  7593. origin, _ := c.GetInt64("origin")
  7594. if origin == 1 {
  7595. err = service.BatchDeleteAdvice(idArray)
  7596. fmt.Print("err", err)
  7597. c.ServeSuccessJSON(map[string]interface{}{
  7598. "msg": "批量删除成功",
  7599. })
  7600. return
  7601. }
  7602. if origin == 2 {
  7603. service.BatchDeleteHisAdvice(idArray)
  7604. }
  7605. }
  7606. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7607. good_id, _ := c.GetInt64("good_id")
  7608. count, _ := c.GetInt64("count")
  7609. record_time, _ := c.GetInt64("record_time")
  7610. patient_id, _ := c.GetInt64("patient_id")
  7611. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7612. c.ServeSuccessJSON(map[string]interface{}{
  7613. "detail": detail,
  7614. })
  7615. return
  7616. }
  7617. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7618. good_id, _ := c.GetInt64("good_id")
  7619. record_time, _ := c.GetInt64("record_time")
  7620. patient_id, _ := c.GetInt64("patient_id")
  7621. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7622. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7623. fmt.Print("err", err)
  7624. c.ServeSuccessJSON(map[string]interface{}{
  7625. "msg": "批量删除成功",
  7626. })
  7627. return
  7628. }
  7629. func (c *DialysisAPIController) BatchAdviceCheck() {
  7630. ids := c.GetString("ids")
  7631. idArray := strings.Split(ids, ",")
  7632. creator, _ := c.GetInt64("creator")
  7633. origin, _ := c.GetInt64("origin")
  7634. if origin == 1 {
  7635. err := service.BatchAdviceCheck(idArray, creator)
  7636. fmt.Println(err)
  7637. list, _ := service.GetAdviceExecutionById(idArray)
  7638. c.ServeSuccessJSON(map[string]interface{}{
  7639. "list": list,
  7640. })
  7641. return
  7642. }
  7643. if origin == 2 {
  7644. service.BatchHisAdviceCheck(idArray, creator)
  7645. list, _ := service.GetHisAdviceExecutionById(idArray)
  7646. c.ServeSuccessJSON(map[string]interface{}{
  7647. "list": list,
  7648. })
  7649. return
  7650. }
  7651. }
  7652. func (c *DialysisAPIController) BatchAdviceExecution() {
  7653. ids := c.GetString("ids")
  7654. idArray := strings.Split(ids, ",")
  7655. executionTime := c.GetString("execution_time")
  7656. creator, _ := c.GetInt64("creator")
  7657. timeLayout := "2006-01-02 15:04:05"
  7658. loc, _ := time.LoadLocation("Local")
  7659. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7660. orgin, _ := c.GetInt64("origin")
  7661. if orgin == 1 {
  7662. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7663. list, _ := service.GetAdviceExecutionById(idArray)
  7664. fmt.Println(err)
  7665. c.ServeSuccessJSON(map[string]interface{}{
  7666. "list": list,
  7667. })
  7668. return
  7669. }
  7670. if orgin == 2 {
  7671. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7672. list, _ := service.GetHisAdviceExecutionById(idArray)
  7673. fmt.Println(err)
  7674. c.ServeSuccessJSON(map[string]interface{}{
  7675. "list": list,
  7676. })
  7677. return
  7678. }
  7679. }
  7680. func (c *DialysisAPIController) UpdateStockGoods() {
  7681. good_id, _ := c.GetInt64("good_id")
  7682. record_time, _ := c.GetInt64("record_time")
  7683. patient_id, _ := c.GetInt64("patient_id")
  7684. count, _ := c.GetInt64("count")
  7685. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7686. fmt.Print("err", err)
  7687. c.ServeSuccessJSON(map[string]interface{}{
  7688. "msg": "更新成功",
  7689. })
  7690. return
  7691. }
  7692. // 当前数据比上一次出库数据少
  7693. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7694. //查询该患者当天已经出库的耗材信息
  7695. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7696. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7697. for i := len(goods_yc) - 1; i >= 0; i-- {
  7698. goods_yc_temp := goods_yc[i]
  7699. for j := len(goods) - 1; j >= 0; j-- {
  7700. goods_temp := goods[j]
  7701. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7702. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7703. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7704. if goods_yc_temp.Count == goods_temp.Count {
  7705. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7706. goods = append(goods[:j], goods[j+1:]...)
  7707. break
  7708. }
  7709. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7710. if goods_yc_temp.Count > goods_temp.Count {
  7711. temp_count := goods_yc_temp.Count - goods_temp.Count
  7712. goods_yc[i].Count = temp_count
  7713. goods = append(goods[:j], goods[j+1:]...)
  7714. break
  7715. }
  7716. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7717. if goods_yc_temp.Count < goods_temp.Count {
  7718. temp_count := goods_temp.Count - goods_yc_temp.Count
  7719. goods[j].Count = temp_count
  7720. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7721. break
  7722. }
  7723. }
  7724. }
  7725. }
  7726. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7727. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7728. //退库
  7729. if len(goods_yc) > 0 {
  7730. for _, good_yc := range goods_yc {
  7731. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7732. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7733. }
  7734. }
  7735. return nil
  7736. }
  7737. // 耗材出库删除
  7738. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7739. // 先根据相关信息查询当天该耗材的出库信息
  7740. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7741. if err != nil {
  7742. return err
  7743. }
  7744. var delete_count int64 = 0
  7745. delete_count = warehouseOutInfos.Count - count
  7746. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7747. // 在出库记录表里记录退库详情
  7748. warehouseOutInfo := &models.WarehouseOutInfo{
  7749. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7750. WarehouseOutId: warehouseOut.ID,
  7751. Status: 1,
  7752. Ctime: time.Now().Unix(),
  7753. OrgId: orgID,
  7754. Type: 1,
  7755. IsSys: 1,
  7756. SysRecordTime: record_time,
  7757. GoodTypeId: good_yc.GoodTypeId,
  7758. GoodId: good_yc.GoodId,
  7759. PatientId: good_yc.PatientId,
  7760. ConsumableType: 2,
  7761. StorehouseId: houseConfig.StorehouseOutInfo,
  7762. IsCheck: 1,
  7763. }
  7764. warehouseOutInfo.Count = count
  7765. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7766. warehouseOutInfo.Price = stockInInfo.Price
  7767. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7768. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7769. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7770. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7771. warehouseOutInfo.Number = warehouseOutInfos.Number
  7772. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7773. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7774. //查找当天是否存在出库记录
  7775. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7776. if errcod == gorm.ErrRecordNotFound {
  7777. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7778. //插入详情明细表
  7779. stockFlow := models.VmStockFlow{
  7780. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7781. WarehouseOutId: warehouseOut.ID,
  7782. GoodId: good_yc.GoodId,
  7783. Number: warehouseOutInfos.Number,
  7784. ProductDate: stockInInfo.ProductDate,
  7785. ExpireDate: stockInInfo.ExpiryDate,
  7786. Count: count,
  7787. Price: stockInInfo.Price,
  7788. Status: 1,
  7789. Ctime: time.Now().Unix(),
  7790. UserOrgId: good_yc.OrgId,
  7791. Manufacturer: stockInInfo.Manufacturer,
  7792. Dealer: stockInInfo.Dealer,
  7793. LicenseNumber: stockInInfo.LicenseNumber,
  7794. IsEdit: 2,
  7795. Creator: creater,
  7796. SystemTime: record_time,
  7797. ConsumableType: 3,
  7798. WarehousingDetailId: 0,
  7799. IsSys: 1,
  7800. UpdateCreator: creater,
  7801. PatientId: patient_id,
  7802. StorehouseId: houseConfig.StorehouseOutInfo,
  7803. }
  7804. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7805. if errflow == gorm.ErrRecordNotFound {
  7806. //创建流水表
  7807. err := service.CreateStockFlowOne(stockFlow)
  7808. fmt.Println("err", err)
  7809. } else if errflow == nil {
  7810. //插入详情明细表
  7811. stockFlow := models.VmStockFlow{
  7812. ID: exsit.ID,
  7813. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7814. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7815. WarehouseOutId: warehouseOut.ID,
  7816. GoodId: good_yc.GoodId,
  7817. Number: warehouseOutInfos.Number,
  7818. ProductDate: stockInInfo.ProductDate,
  7819. ExpireDate: stockInInfo.ExpiryDate,
  7820. Count: exsit.Count - delete_count,
  7821. Price: stockInInfo.Price,
  7822. Status: 1,
  7823. Ctime: time.Now().Unix(),
  7824. UserOrgId: good_yc.OrgId,
  7825. Manufacturer: stockInInfo.Manufacturer,
  7826. Dealer: stockInInfo.Dealer,
  7827. LicenseNumber: stockInInfo.LicenseNumber,
  7828. IsEdit: 2,
  7829. Creator: creater,
  7830. SystemTime: record_time,
  7831. ConsumableType: 3,
  7832. WarehousingDetailId: 0,
  7833. IsSys: 1,
  7834. UpdateCreator: creater,
  7835. PatientId: patient_id,
  7836. StorehouseId: houseConfig.StorehouseOutInfo,
  7837. }
  7838. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7839. }
  7840. if errOne != nil {
  7841. return errOne
  7842. }
  7843. } else if errcod == nil {
  7844. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7845. //插入详情明细表
  7846. stockFlow := models.VmStockFlow{
  7847. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7848. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7849. WarehouseOutId: warehouseOut.ID,
  7850. GoodId: good_yc.GoodId,
  7851. Number: warehouseOutInfos.Number,
  7852. ProductDate: stockInInfo.ProductDate,
  7853. ExpireDate: stockInInfo.ExpiryDate,
  7854. Count: count,
  7855. Price: stockInInfo.Price,
  7856. Status: 1,
  7857. Ctime: time.Now().Unix(),
  7858. UserOrgId: good_yc.OrgId,
  7859. Manufacturer: stockInInfo.Manufacturer,
  7860. Dealer: stockInInfo.Dealer,
  7861. LicenseNumber: stockInInfo.LicenseNumber,
  7862. IsEdit: 2,
  7863. Creator: creater,
  7864. SystemTime: record_time,
  7865. ConsumableType: 3,
  7866. WarehousingDetailId: 0,
  7867. IsSys: 1,
  7868. UpdateCreator: creater,
  7869. PatientId: patient_id,
  7870. ReturnCount: delete_count,
  7871. StorehouseId: houseConfig.StorehouseOutInfo,
  7872. }
  7873. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7874. if errflows == gorm.ErrRecordNotFound {
  7875. //创建流水表
  7876. service.CreateStockFlowOne(stockFlow)
  7877. } else if errflows == nil {
  7878. stockFlow := models.VmStockFlow{
  7879. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7880. ID: exsit.ID,
  7881. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7882. WarehouseOutId: warehouseOut.ID,
  7883. GoodId: good_yc.GoodId,
  7884. Number: warehouseOutInfos.Number,
  7885. ProductDate: stockInInfo.ProductDate,
  7886. ExpireDate: stockInInfo.ExpiryDate,
  7887. Count: exsit.Count - delete_count,
  7888. Price: stockInInfo.Price,
  7889. Status: 1,
  7890. Ctime: time.Now().Unix(),
  7891. UserOrgId: good_yc.OrgId,
  7892. Manufacturer: stockInInfo.Manufacturer,
  7893. Dealer: stockInInfo.Dealer,
  7894. LicenseNumber: stockInInfo.LicenseNumber,
  7895. IsEdit: 2,
  7896. Creator: creater,
  7897. SystemTime: record_time,
  7898. ConsumableType: 3,
  7899. WarehousingDetailId: 0,
  7900. IsSys: 1,
  7901. UpdateCreator: creater,
  7902. PatientId: patient_id,
  7903. ReturnCount: delete_count,
  7904. StorehouseId: houseConfig.StorehouseOutInfo,
  7905. }
  7906. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7907. }
  7908. }
  7909. //更改自动出库的表格
  7910. details := models.BloodAutomaticReduceDetail{
  7911. WarehouseOutId: warehouseOutInfo.ID,
  7912. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7913. PatientId: patient_id,
  7914. Ctime: time.Now().Unix(),
  7915. Mtime: time.Now().Unix(),
  7916. Status: 1,
  7917. RecordTime: record_time,
  7918. OrgId: orgID,
  7919. GoodId: good_yc.GoodId,
  7920. GoodTypeId: good_yc.GoodTypeId,
  7921. Count: count,
  7922. StorehouseId: houseConfig.StorehouseOutInfo,
  7923. }
  7924. //查询当天耗材是否已经存在数据
  7925. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7926. if errcode == gorm.ErrRecordNotFound {
  7927. errTwo := service.CreateAutoReduceRecord(&details)
  7928. if errTwo != nil {
  7929. return errTwo
  7930. }
  7931. } else if errcode == nil {
  7932. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7933. service.CreateAutoReduceRecord(&details)
  7934. }
  7935. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7936. //增加出库库存数量
  7937. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7938. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7939. fmt.Println("errOne", errOne)
  7940. // 删除出库完成后,要增加对应批次的库存数量
  7941. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7942. if errThree != nil {
  7943. return errThree
  7944. }
  7945. if good_yc.Count == 0 {
  7946. return nil
  7947. } else {
  7948. return errors.New("退库和出库数据不匹配")
  7949. }
  7950. }
  7951. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7952. //查询该患者当天已经出库的耗材信息
  7953. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7954. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7955. for i := len(goods_yc) - 1; i >= 0; i-- {
  7956. goods_yc_temp := goods_yc[i]
  7957. for j := len(goods) - 1; j >= 0; j-- {
  7958. goods_temp := goods[j]
  7959. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7960. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7961. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7962. if goods_yc_temp.Count == goods_temp.Count {
  7963. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7964. goods = append(goods[:j], goods[j+1:]...)
  7965. break
  7966. }
  7967. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7968. if goods_yc_temp.Count > goods_temp.Count {
  7969. temp_count := goods_yc_temp.Count - goods_temp.Count
  7970. goods_yc[i].Count = temp_count
  7971. goods = append(goods[:j], goods[j+1:]...)
  7972. break
  7973. }
  7974. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7975. if goods_yc_temp.Count < goods_temp.Count {
  7976. temp_count := goods_temp.Count - goods_yc_temp.Count
  7977. goods[j].Count = temp_count
  7978. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7979. break
  7980. }
  7981. }
  7982. }
  7983. }
  7984. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7985. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7986. fmt.Println("剩余需要出库的", len(goods))
  7987. if len(goods) > 0 {
  7988. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7989. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7990. if err == gorm.ErrRecordNotFound {
  7991. //没有记录,则创建出库单
  7992. timeStr := time.Now().Format("2006-01-02")
  7993. timeArr := strings.Split(timeStr, "-")
  7994. total, _ := service.FindAllWarehouseOut(orgID)
  7995. total = total + 1
  7996. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7997. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7998. number = number + total
  7999. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8000. warehouseOut := models.WarehouseOut{
  8001. WarehouseOutOrderNumber: warehousing_out_order,
  8002. OperationTime: time.Now().Unix(),
  8003. OrgId: orgID,
  8004. Creater: creater,
  8005. Ctime: time.Now().Unix(),
  8006. Status: 1,
  8007. WarehouseOutTime: record_time,
  8008. Dealer: 0,
  8009. Manufacturer: 0,
  8010. Type: 1,
  8011. IsSys: 1,
  8012. StorehouseId: houseConfig.StorehouseOutInfo,
  8013. IsCheck: 1,
  8014. }
  8015. err := service.AddSigleWarehouseOut(&warehouseOut)
  8016. if err != nil {
  8017. utils.TraceLog("创建出库单失败 err = %v", err)
  8018. return err
  8019. } else {
  8020. out = warehouseOut
  8021. }
  8022. }
  8023. for _, item := range goods {
  8024. var newCount int64 = 0
  8025. for _, it := range goodOne {
  8026. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8027. newCount = it.Count
  8028. }
  8029. }
  8030. prepare := models.DialysisBeforePrepare{
  8031. GoodTypeId: item.GoodTypeId,
  8032. GoodId: item.GoodId,
  8033. Count: item.Count,
  8034. StorehouseId: houseConfig.StorehouseOutInfo,
  8035. }
  8036. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8037. //增加出库数量
  8038. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8039. }
  8040. }
  8041. if len(goods_yc) > 0 {
  8042. for _, good_yc := range goods_yc {
  8043. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8044. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8045. }
  8046. }
  8047. return nil
  8048. }
  8049. // 耗材出库删除
  8050. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8051. // 先根据相关信息查询当天该耗材的出库信息
  8052. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8053. if err != nil {
  8054. return err
  8055. }
  8056. var delete_count int64 = 0
  8057. for _, ware := range warehouseOutInfos {
  8058. // 判断当前出库的数据和删除出库数量
  8059. if good_yc.Count <= ware.Count {
  8060. delete_count = good_yc.Count
  8061. } else {
  8062. delete_count = ware.Count
  8063. }
  8064. warehouseOutInfo := &models.WarehouseOutInfo{
  8065. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8066. WarehouseOutId: warehouseOut.ID,
  8067. Status: 1,
  8068. Ctime: time.Now().Unix(),
  8069. Remark: "",
  8070. OrgId: orgID,
  8071. Type: 1,
  8072. Manufacturer: 0,
  8073. Dealer: 0,
  8074. IsSys: 0,
  8075. SysRecordTime: record_time,
  8076. GoodTypeId: good_yc.GoodTypeId,
  8077. GoodId: good_yc.GoodId,
  8078. StorehouseId: warehouseOut.StorehouseId,
  8079. IsCheck: 1,
  8080. }
  8081. warehouseOutInfo.Count = delete_count
  8082. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8083. warehouseOutInfo.Price = stockInInfo.Price
  8084. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8085. if errOne != nil {
  8086. return errOne
  8087. }
  8088. // 删除出库完成后,要改变流水库存(有疑问)
  8089. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8090. fmt.Println("errOne", errOne)
  8091. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8092. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8093. //扣减出库数量
  8094. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8095. if errThree != nil {
  8096. return errThree
  8097. }
  8098. }
  8099. if good_yc.Count == 0 {
  8100. return nil
  8101. } else {
  8102. return errors.New("退库和出库数据不匹配")
  8103. }
  8104. }
  8105. func (this *DialysisAPIController) GetMobileScheduleList() {
  8106. limit, _ := this.GetInt64("limit")
  8107. page, _ := this.GetInt64("page")
  8108. type_options_visible, _ := this.GetInt64("type_options_visible")
  8109. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8110. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8111. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8112. }
  8113. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8114. newArr = make([]*models.HisPrescriptionProject, 0)
  8115. for i := 0; i < len(arr); i++ {
  8116. repeat := false
  8117. for j := i + 1; j < len(arr); j++ {
  8118. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8119. repeat = true
  8120. break
  8121. }
  8122. }
  8123. if !repeat {
  8124. newArr = append(newArr, arr[i])
  8125. }
  8126. }
  8127. return
  8128. }
  8129. func (this *DialysisAPIController) GetRoleList() {
  8130. admin_user_id, _ := this.GetInt64("admin_user_id")
  8131. orgid := this.GetMobileAdminUserInfo().Org.Id
  8132. list, err := service.GetRoleList(orgid, admin_user_id)
  8133. fmt.Println(err)
  8134. this.ServeSuccessJSON(map[string]interface{}{
  8135. "list": list,
  8136. })
  8137. return
  8138. }
  8139. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8140. // 先根据相关信息查询当天该耗材的出库信息
  8141. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8142. if err != nil {
  8143. return err
  8144. }
  8145. var delete_count int64 = 0
  8146. delete_count = warehouseOutInfos.Count - count
  8147. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8148. // 删除出库完成后,要增加对应批次的库存数量
  8149. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8150. if errThree != nil {
  8151. return errThree
  8152. }
  8153. //增加退库数量
  8154. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8155. //扣减出库数量
  8156. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8157. //查询剩余库存
  8158. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8159. var sum_count int64
  8160. for _, item := range goodList {
  8161. sum_count += item.StockCount
  8162. }
  8163. // 在出库记录表里记录退库详情
  8164. warehouseOutInfo := &models.WarehouseOutInfo{
  8165. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8166. WarehouseOutId: warehouseOut.ID,
  8167. Status: 1,
  8168. Ctime: time.Now().Unix(),
  8169. OrgId: orgID,
  8170. Type: 1,
  8171. IsSys: 1,
  8172. SysRecordTime: record_time,
  8173. GoodTypeId: good_yc.GoodTypeId,
  8174. GoodId: good_yc.GoodId,
  8175. PatientId: good_yc.PatientId,
  8176. ConsumableType: 2,
  8177. StorehouseId: houseConfig.StorehouseOutInfo,
  8178. IsCheck: 1,
  8179. OverCount: sum_count,
  8180. }
  8181. warehouseOutInfo.Count = count
  8182. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8183. warehouseOutInfo.Price = stockInInfo.Price
  8184. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8185. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8186. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8187. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8188. warehouseOutInfo.Number = warehouseOutInfos.Number
  8189. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8190. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8191. //查找当天是否存在出库记录
  8192. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8193. if errcod == gorm.ErrRecordNotFound {
  8194. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8195. //插入详情明细表
  8196. if errOne != nil {
  8197. return errOne
  8198. }
  8199. //插入详情明细表
  8200. stockFlow := models.VmStockFlow{
  8201. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8202. WarehouseOutId: warehouseOut.ID,
  8203. GoodId: good_yc.GoodId,
  8204. Number: warehouseOutInfos.Number,
  8205. ProductDate: stockInInfo.ProductDate,
  8206. ExpireDate: stockInInfo.ExpiryDate,
  8207. Count: count,
  8208. Price: stockInInfo.Price,
  8209. Status: 1,
  8210. Ctime: record_time,
  8211. UserOrgId: good_yc.OrgId,
  8212. Manufacturer: stockInInfo.Manufacturer,
  8213. Dealer: stockInInfo.Dealer,
  8214. LicenseNumber: stockInInfo.LicenseNumber,
  8215. IsEdit: 2,
  8216. Creator: creater,
  8217. SystemTime: record_time,
  8218. ConsumableType: 3,
  8219. WarehousingDetailId: 0,
  8220. IsSys: 1,
  8221. UpdateCreator: creater,
  8222. PatientId: patient_id,
  8223. StorehouseId: houseConfig.StorehouseOutInfo,
  8224. OverCount: sum_count,
  8225. ProjectId: good_yc.ProjectId,
  8226. }
  8227. err := service.CreateStockFlowOne(stockFlow)
  8228. fmt.Println("err", err)
  8229. } else if errcod == nil {
  8230. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8231. }
  8232. //创建退库单
  8233. operation_time := time.Now().Unix()
  8234. //创建退库单
  8235. timeStr := time.Now().Format("2006-01-02")
  8236. timeArr := strings.Split(timeStr, "-")
  8237. total, _ := service.FindAllCancelStockTotal(orgID)
  8238. total = total + 1
  8239. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8240. cancelStock := models.CancelStock{
  8241. OrderNumber: orderNumber,
  8242. OperaTime: operation_time,
  8243. OrgId: orgID,
  8244. Creater: warehouseOut.Creater,
  8245. Ctime: time.Now().Unix(),
  8246. Status: 1,
  8247. ReturnTime: record_time,
  8248. Type: 1,
  8249. StorehouseId: stockInInfo.StorehouseId,
  8250. IsCheck: 1,
  8251. }
  8252. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8253. if msgerrkonde == gorm.ErrRecordNotFound {
  8254. service.AddSigleCancelStock(&cancelStock)
  8255. }
  8256. cancel, _ := service.GetLastCancelStockById(orgID)
  8257. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8258. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8259. cancelStockInfo := models.CancelStockInfo{
  8260. GoodId: stockInInfo.GoodId,
  8261. CancelStockId: cancel.ID,
  8262. GoodTypeId: stockInInfo.GoodTypeId,
  8263. Count: delete_count,
  8264. Price: stockInInfo.PackingPrice,
  8265. Total: 0,
  8266. ProductDate: stockInInfo.ProductDate,
  8267. ExpiryDate: stockInInfo.ExpiryDate,
  8268. Ctime: record_time,
  8269. Status: 1,
  8270. OrgId: orgID,
  8271. OrderNumber: cancel.OrderNumber,
  8272. Type: 0,
  8273. Dealer: deaerler.DealerName,
  8274. Manufacturer: manufacturer.ManufacturerName,
  8275. Number: stockInInfo.Number,
  8276. RegisterAccount: "",
  8277. Remark: "",
  8278. WarehouseInfoId: stockInInfo.ID,
  8279. PatientId: patient_id,
  8280. RecordDate: record_time,
  8281. StorehouseId: stockInInfo.StorehouseId,
  8282. IsCheck: 1,
  8283. }
  8284. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8285. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8286. flow := models.VmStockFlow{
  8287. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8288. GoodId: good_yc.GoodId,
  8289. Number: warehouseOutInfos.Number,
  8290. LicenseNumber: stockInInfo.LicenseNumber,
  8291. Count: delete_count,
  8292. UserOrgId: orgID,
  8293. PatientId: patient_id,
  8294. SystemTime: record_time,
  8295. ConsumableType: 7,
  8296. IsSys: 0,
  8297. WarehousingOrder: "",
  8298. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8299. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8300. IsEdit: 0,
  8301. CancelStockId: cancel.ID,
  8302. CancelOrderNumber: cancel.OrderNumber,
  8303. Manufacturer: manufacturer.ID,
  8304. Dealer: 0,
  8305. Creator: warehouseOut.Creater,
  8306. UpdateCreator: 0,
  8307. Status: 1,
  8308. Ctime: record_time,
  8309. Mtime: 0,
  8310. Price: stockInInfo.Price,
  8311. WarehousingDetailId: stockInInfo.ID,
  8312. WarehouseOutDetailId: warehouseOutInfos.ID,
  8313. CancelOutDetailId: cancelInfo.ID,
  8314. ProductDate: stockInInfo.ProductDate,
  8315. ExpireDate: stockInInfo.ExpiryDate,
  8316. StorehouseId: houseConfig.StorehouseOutInfo,
  8317. OverCount: sum_count,
  8318. }
  8319. service.CreateStockFlowOne(flow)
  8320. //更改自动出库的表格
  8321. details := models.BloodAutomaticReduceDetail{
  8322. WarehouseOutId: warehouseOutInfo.ID,
  8323. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8324. PatientId: patient_id,
  8325. Ctime: time.Now().Unix(),
  8326. Mtime: time.Now().Unix(),
  8327. Status: 1,
  8328. RecordTime: record_time,
  8329. OrgId: orgID,
  8330. GoodId: good_yc.GoodId,
  8331. GoodTypeId: good_yc.GoodTypeId,
  8332. Count: count,
  8333. StorehouseId: houseConfig.StorehouseOutInfo,
  8334. }
  8335. //查询当天耗材是否已经存在数据
  8336. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8337. if errcode == gorm.ErrRecordNotFound {
  8338. errTwo := service.CreateAutoReduceRecord(&details)
  8339. if errTwo != nil {
  8340. return errTwo
  8341. }
  8342. } else if errcode == nil {
  8343. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8344. service.CreateAutoReduceRecord(&details)
  8345. }
  8346. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8347. //增加出库库存数量
  8348. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8349. if good_yc.Count == 0 {
  8350. return nil
  8351. } else {
  8352. return errors.New("退库和出库数据不匹配")
  8353. }
  8354. }
  8355. func (this *DialysisAPIController) SavePatientSign() {
  8356. adminUserInfo := this.GetMobileAdminUserInfo()
  8357. patient_id, _ := this.GetInt64("patient_id")
  8358. dialysis_date, _ := this.GetInt64("dialysis_date")
  8359. orgid := adminUserInfo.Org.Id
  8360. var esdata models.DialysisOrder
  8361. var err error
  8362. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8364. return
  8365. }
  8366. esdata.Hash = esdata.Hash
  8367. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8368. order := models.DialysisOrder{
  8369. Hash: esdata.Hash,
  8370. Url: esdata.Url,
  8371. }
  8372. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8373. redis := service.RedisClient()
  8374. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8375. redis.Set(key, "", time.Second)
  8376. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8377. //清空key 值
  8378. redis.Set(keyOne, "", time.Second)
  8379. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8380. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8381. //redis.Set(keyTwo, "", time.Second)
  8382. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8383. redis.Set(keyThree, "", time.Second)
  8384. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8385. redis.Set(keyFour, "", time.Second)
  8386. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8387. redis.Set(keyFive, "", time.Second)
  8388. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8389. redis.Set(keySix, "", time.Second)
  8390. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8391. redis.Set(keySeven, "", time.Second)
  8392. if err != nil {
  8393. fmt.Println(err)
  8394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8395. return
  8396. }
  8397. this.ServeSuccessJSON(map[string]interface{}{
  8398. "electronic_signature": esdata,
  8399. })
  8400. }
  8401. func (this *DialysisAPIController) GetPatientSign() {
  8402. patient_id, _ := this.GetInt64("patient_id")
  8403. dialysis_date, _ := this.GetInt64("dialysis_date")
  8404. adminUserInfo := this.GetMobileAdminUserInfo()
  8405. orgId := adminUserInfo.Org.Id
  8406. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8407. if err != nil {
  8408. fmt.Println(err)
  8409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8410. return
  8411. }
  8412. this.ServeSuccessJSON(map[string]interface{}{
  8413. "dialysisOrder": dialysisOrder,
  8414. })
  8415. }
  8416. func (this *DialysisAPIController) GetScheduleByPatient() {
  8417. patient_id, _ := this.GetInt64("patient_id")
  8418. schedule_date, _ := this.GetInt64("schedule_date")
  8419. orgid := this.GetMobileAdminUserInfo().Org.Id
  8420. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8421. this.ServeSuccessJSON(map[string]interface{}{
  8422. "schedule": schedule,
  8423. })
  8424. }
  8425. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8426. org_id := this.GetMobileAdminUserInfo().Org.Id
  8427. patient_id, _ := this.GetInt64("patient_id")
  8428. schedule_date, _ := this.GetInt64("schedule_date")
  8429. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8430. this.ServeSuccessJSON(map[string]interface{}{
  8431. "order": order,
  8432. })
  8433. }
  8434. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8435. org_id := this.GetMobileAdminUserInfo().Org.Id
  8436. schedule_date := this.GetString("schedule_date")
  8437. schedule_type, _ := this.GetInt64("schedule_type")
  8438. timeLayout := "2006-01-02"
  8439. loc, _ := time.LoadLocation("Local")
  8440. var startdateunix int64
  8441. if len(schedule_date) > 0 {
  8442. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8443. if err != nil {
  8444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8445. return
  8446. }
  8447. startdateunix = theTime.Unix()
  8448. }
  8449. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8450. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8451. devices, _ := service.GetAllDevicetByListSix(org_id)
  8452. for key, item := range scheduals {
  8453. // 床位信息
  8454. for _, device := range devices {
  8455. if item.BedId == device.ID {
  8456. scheduals[key].DeviceNumber = device
  8457. break
  8458. }
  8459. }
  8460. }
  8461. this.ServeSuccessJSON(map[string]interface{}{
  8462. "list": list,
  8463. "scheduals": scheduals,
  8464. })
  8465. }
  8466. func (this *DialysisAPIController) SavePatientPicture() {
  8467. patient_id, _ := this.GetInt64("patient_id")
  8468. dialysis_date, _ := this.GetInt64("schedule_date")
  8469. avatar := this.GetString("avatar")
  8470. fmt.Println("patient_id", patient_id)
  8471. orgId := this.GetMobileAdminUserInfo().Org.Id
  8472. order := models.DialysisOrder{
  8473. Url: avatar,
  8474. }
  8475. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8476. redis := service.RedisClient()
  8477. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8478. redis.Set(key, "", time.Second)
  8479. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8480. //清空key 值
  8481. redis.Set(keyOne, "", time.Second)
  8482. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8483. redis.Set(keyThree, "", time.Second)
  8484. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8485. redis.Set(keyFour, "", time.Second)
  8486. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8487. redis.Set(keyFive, "", time.Second)
  8488. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8489. redis.Set(keySix, "", time.Second)
  8490. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8491. redis.Set(keySeven, "", time.Second)
  8492. if err != nil {
  8493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8494. return
  8495. }
  8496. this.ServeSuccessJSON(map[string]interface{}{
  8497. "order": order,
  8498. })
  8499. }
  8500. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8501. ids := this.GetString("ids")
  8502. idSplit := strings.Split(ids, ",")
  8503. orgId := this.GetMobileAdminUserInfo().Org.Id
  8504. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8505. execution_time := this.GetString("exce_time")
  8506. timeLayout2 := "2006-01-02 15:04:05"
  8507. loc, _ := time.LoadLocation("Local")
  8508. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8509. if errs != nil {
  8510. utils.ErrorLog(errs.Error())
  8511. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8512. return
  8513. }
  8514. //his客户
  8515. if config.IsOpen == 1 {
  8516. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8517. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8518. for _, item := range list {
  8519. for _, it := range adviceList {
  8520. if item.DrugId == it.DrugId {
  8521. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8522. }
  8523. }
  8524. }
  8525. for _, item := range list {
  8526. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8527. var sum_out_count int64
  8528. for _, itemThree := range item.ChildDoctorAdvice {
  8529. var prescribing_number int64
  8530. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8531. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8532. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8533. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8534. }
  8535. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8536. prescribing_number = parseIntPrescribingNumber
  8537. }
  8538. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8539. prescribing_number = parseIntPrescribingNumber
  8540. }
  8541. sum_out_count += prescribing_number
  8542. }
  8543. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8544. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8545. //库存不足
  8546. if sum_out_count > drugStockOut.FlushCount {
  8547. this.ServeSuccessJSON(map[string]interface{}{
  8548. "msg": "2",
  8549. "drug": medical,
  8550. "ids": ids,
  8551. })
  8552. return
  8553. }
  8554. }
  8555. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8556. //执行医嘱
  8557. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8558. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8559. for _, item := range advices {
  8560. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8561. redis := service.RedisClient()
  8562. //清空key 值
  8563. redis.Set(key, "", time.Second)
  8564. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8565. redis.Set(keyTwo, "", time.Second)
  8566. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8567. redis.Set(keyThree, "", time.Second)
  8568. recordDate := theTime.Format("2006-01-02")
  8569. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8570. redis.Set(keyFour, "", time.Second)
  8571. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8572. redis.Set(keyFive, "", time.Second)
  8573. defer redis.Close()
  8574. }
  8575. if errs == nil {
  8576. //药品管理信息
  8577. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8578. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8579. if drugStockConfig.IsOpen == 1 {
  8580. for _, item := range advices {
  8581. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8582. config, _ := service.GetDrugOpenConfigOne(orgId)
  8583. if config.IsOpen != 1 {
  8584. //查询该药品是否有库存
  8585. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8586. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8587. if medical.IsUse == 2 {
  8588. if config.IsOpen != 1 {
  8589. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8590. service.HisDrugsDelivery(orgId, creater, &advice)
  8591. if orgId == 3877 || orgId == 10265 {
  8592. //查询该药品是否有出库记录
  8593. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8594. if len(flowMap) == 0 {
  8595. errs := service.UpdateHisAdviceById(advice.ID)
  8596. if errs != nil {
  8597. drugError := models.XtDrugError{
  8598. UserOrgId: orgId,
  8599. DrugId: item.DrugId,
  8600. RecordDate: item.AdviceDate,
  8601. PatientId: item.PatientId,
  8602. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8603. Status: 1,
  8604. Ctime: time.Now().Unix(),
  8605. Mtime: 0,
  8606. SumCount: 0,
  8607. Prescribingnumber: advice.PrescribingNumber,
  8608. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8609. }
  8610. service.CreateDrugError(drugError)
  8611. }
  8612. this.ServeSuccessJSON(map[string]interface{}{
  8613. "msg": "2",
  8614. "drug": medical,
  8615. "ids": ids,
  8616. })
  8617. return
  8618. }
  8619. }
  8620. }
  8621. if pharmacyConfig.IsOpen != 1 {
  8622. service.HisDrugsDelivery(orgId, creater, &advice)
  8623. if orgId == 3877 || orgId == 10265 {
  8624. //查询该药品是否有出库记录
  8625. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8626. if len(flowMap) == 0 {
  8627. errs := service.UpdateHisAdviceById(advice.ID)
  8628. if errs != nil {
  8629. drugError := models.XtDrugError{
  8630. UserOrgId: orgId,
  8631. DrugId: item.DrugId,
  8632. RecordDate: item.AdviceDate,
  8633. PatientId: item.PatientId,
  8634. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8635. Status: 1,
  8636. Ctime: time.Now().Unix(),
  8637. Mtime: 0,
  8638. SumCount: 0,
  8639. Prescribingnumber: advice.PrescribingNumber,
  8640. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8641. }
  8642. service.CreateDrugError(drugError)
  8643. }
  8644. this.ServeSuccessJSON(map[string]interface{}{
  8645. "msg": "2",
  8646. "drug": medical,
  8647. "ids": ids,
  8648. })
  8649. return
  8650. }
  8651. }
  8652. }
  8653. //更新字典里面的库存
  8654. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8655. var sum_count int64
  8656. for _, its := range stockInfo {
  8657. if its.MaxUnit == medical.MaxUnit {
  8658. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8659. }
  8660. sum_count += its.StockMaxNumber + its.StockMinNumber
  8661. }
  8662. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8663. //剩余库存
  8664. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8665. }
  8666. }
  8667. }
  8668. }
  8669. }
  8670. this.ServeSuccessJSON(map[string]interface{}{
  8671. "msg": "1",
  8672. "ids": ids,
  8673. })
  8674. return
  8675. } else {
  8676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8677. }
  8678. }
  8679. //血透客户
  8680. if config.IsOpen == 2 || config.IsOpen == 0 {
  8681. //药品管理信息
  8682. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8683. if drugStockConfig.IsOpen == 1 {
  8684. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8685. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8686. for _, item := range list {
  8687. for _, it := range adviceList {
  8688. if item.DrugId == it.DrugId {
  8689. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8690. }
  8691. }
  8692. }
  8693. for _, item := range list {
  8694. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8695. var sum_out_count int64
  8696. for _, itemThree := range item.ChildDoctorAdvice {
  8697. var prescribing_number int64
  8698. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8699. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8700. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8701. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8702. }
  8703. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8704. prescribing_number = parseIntPrescribingNumber
  8705. }
  8706. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8707. prescribing_number = parseIntPrescribingNumber
  8708. }
  8709. sum_out_count += prescribing_number
  8710. }
  8711. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8712. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8713. //库存不足
  8714. if sum_out_count > drugStockOut.FlushCount {
  8715. this.ServeSuccessJSON(map[string]interface{}{
  8716. "msg": "2",
  8717. "drug": medical,
  8718. "ids": ids,
  8719. })
  8720. return
  8721. }
  8722. }
  8723. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8724. //执行医嘱
  8725. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8726. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8727. for _, item := range advices {
  8728. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8729. redis := service.RedisClient()
  8730. //清空key 值
  8731. redis.Set(key, "", time.Second)
  8732. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8733. redis.Set(keyTwo, "", time.Second)
  8734. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8735. redis.Set(keyThree, "", time.Second)
  8736. recordDate := theTime.Format("2006-01-02")
  8737. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8738. redis.Set(keyFour, "", time.Second)
  8739. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8740. redis.Set(keyFive, "", time.Second)
  8741. defer redis.Close()
  8742. }
  8743. if errs == nil {
  8744. for _, item := range advices {
  8745. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8746. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8747. //查询是否出库按钮开启
  8748. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8749. if adviceSetting.IsAdviceOpen == 1 {
  8750. //查询是否出库按钮开启
  8751. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8752. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8753. if prescriptionConfig.IsOpen == 1 {
  8754. if medical.IsUse == 2 {
  8755. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8756. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8757. }
  8758. if pharmacyConfig.IsOpen != 1 {
  8759. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8760. }
  8761. //更新字典里面的库存
  8762. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8763. var sum_count int64
  8764. for _, its := range stockInfo {
  8765. if its.MaxUnit == medical.MaxUnit {
  8766. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8767. }
  8768. sum_count += its.StockMaxNumber + its.StockMinNumber
  8769. }
  8770. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8771. //剩余库存
  8772. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8773. }
  8774. }
  8775. } else {
  8776. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8777. if medical.IsUse == 2 {
  8778. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8779. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8780. }
  8781. if pharmacyConfig.IsOpen != 1 {
  8782. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8783. }
  8784. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8785. var sum_count int64
  8786. for _, its := range stockInfo {
  8787. if its.MaxUnit == medical.MaxUnit {
  8788. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8789. }
  8790. sum_count += its.StockMaxNumber + its.StockMinNumber
  8791. }
  8792. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8793. //剩余库存
  8794. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8795. }
  8796. }
  8797. }
  8798. }
  8799. this.ServeSuccessJSON(map[string]interface{}{
  8800. "msg": "1",
  8801. "ids": ids,
  8802. })
  8803. return
  8804. } else {
  8805. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8806. //执行医嘱
  8807. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8808. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8809. for _, item := range advices {
  8810. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8811. redis := service.RedisClient()
  8812. //清空key 值
  8813. redis.Set(key, "", time.Second)
  8814. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8815. redis.Set(keyTwo, "", time.Second)
  8816. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8817. redis.Set(keyThree, "", time.Second)
  8818. recordDate := theTime.Format("2006-01-02")
  8819. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8820. redis.Set(keyFour, "", time.Second)
  8821. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8822. redis.Set(keyFive, "", time.Second)
  8823. defer redis.Close()
  8824. }
  8825. this.ServeSuccessJSON(map[string]interface{}{
  8826. "msg": "1",
  8827. "ids": ids,
  8828. })
  8829. return
  8830. }
  8831. }
  8832. }
  8833. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8834. ids := this.GetString("ids")
  8835. idSplit := strings.Split(ids, ",")
  8836. orgId := this.GetMobileAdminUserInfo().Org.Id
  8837. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8838. if config.IsOpen == 1 {
  8839. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8840. this.ServeSuccessJSON(map[string]interface{}{
  8841. "msg": "1",
  8842. "ids": ids,
  8843. })
  8844. return
  8845. }
  8846. if config.IsOpen == 0 || config.IsOpen == 2 {
  8847. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8848. this.ServeSuccessJSON(map[string]interface{}{
  8849. "msg": "1",
  8850. "ids": ids,
  8851. })
  8852. return
  8853. }
  8854. }
  8855. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8856. ids := this.GetString("ids")
  8857. idSplit := strings.Split(ids, ",")
  8858. orgId := this.GetMobileAdminUserInfo().Org.Id
  8859. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8860. //his
  8861. if config.IsOpen == 1 {
  8862. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8863. theTime := time.Now()
  8864. advices := models.HisDoctorAdviceThirty{
  8865. CheckTime: theTime.Unix(),
  8866. Checker: checker,
  8867. UpdatedTime: time.Now().Unix(),
  8868. }
  8869. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8870. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8871. for _, item := range list {
  8872. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8873. redis := service.RedisClient()
  8874. //清空key 值
  8875. redis.Set(key, "", time.Second)
  8876. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8877. redis.Set(keyTwo, "", time.Second)
  8878. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8879. redis.Set(keyThree, "", time.Second)
  8880. recordDate := theTime.Format("2006-01-02")
  8881. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8882. redis.Set(keyFour, "", time.Second)
  8883. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8884. redis.Set(keyFive, "", time.Second)
  8885. defer redis.Close()
  8886. }
  8887. this.ServeSuccessJSON(map[string]interface{}{
  8888. "msg": "1",
  8889. "ids": ids,
  8890. })
  8891. return
  8892. }
  8893. //血透
  8894. if config.IsOpen == 0 || config.IsOpen == 2 {
  8895. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8896. theTime := time.Now()
  8897. advices := models.DoctorAdvice{
  8898. CheckTime: theTime.Unix(),
  8899. Checker: checker,
  8900. UpdatedTime: time.Now().Unix(),
  8901. }
  8902. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8903. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8904. for _, item := range list {
  8905. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8906. redis := service.RedisClient()
  8907. //清空key 值
  8908. redis.Set(key, "", time.Second)
  8909. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8910. redis.Set(keyTwo, "", time.Second)
  8911. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8912. redis.Set(keyThree, "", time.Second)
  8913. recordDate := theTime.Format("2006-01-02")
  8914. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8915. redis.Set(keyFour, "", time.Second)
  8916. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8917. redis.Set(keyFive, "", time.Second)
  8918. defer redis.Close()
  8919. }
  8920. this.ServeSuccessJSON(map[string]interface{}{
  8921. "msg": "1",
  8922. "ids": ids,
  8923. })
  8924. return
  8925. }
  8926. }
  8927. func (this *DialysisAPIController) CheckSchedule() {
  8928. patientID, _ := this.GetInt64("patient_id")
  8929. recordDateStr := this.GetString("record_date")
  8930. nurseID, _ := this.GetInt64("start_nurse")
  8931. schedual_type, _ := this.GetInt64("schedual_type")
  8932. bedID, _ := this.GetInt64("bed")
  8933. start_time := this.GetString("start_time")
  8934. fmt.Println("patientID", patientID)
  8935. fmt.Println("recordDateStr", recordDateStr)
  8936. fmt.Println("nurseID", nurseID)
  8937. fmt.Println("schedual_type------", schedual_type)
  8938. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8940. return
  8941. }
  8942. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8943. if parseStartDateErr != nil {
  8944. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8945. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8946. return
  8947. }
  8948. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8949. if parseErr != nil {
  8950. this.ErrorLog("时间解析失败:%v", parseErr)
  8951. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8952. return
  8953. }
  8954. adminUserInfo := this.GetMobileAdminUserInfo()
  8955. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8956. if getPatientErr != nil {
  8957. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8959. return
  8960. } else if patient == nil {
  8961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8962. return
  8963. }
  8964. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8965. if getNurseErr != nil {
  8966. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8968. return
  8969. } else if nurse == nil {
  8970. this.ErrorLog("护士不存在")
  8971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8972. return
  8973. }
  8974. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8975. if getDeviceNumberErr != nil {
  8976. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8977. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8978. return
  8979. } else if deviceNumber == nil {
  8980. this.ErrorLog("床位号不存在")
  8981. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8982. return
  8983. }
  8984. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8985. if getRecordErr != nil {
  8986. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8988. return
  8989. } else if dialysisRecord != nil {
  8990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8991. return
  8992. }
  8993. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8994. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8995. timeLayout := "2006-01-02 15:04:05"
  8996. loc, _ := time.LoadLocation("Local")
  8997. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8998. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8999. schedulestartTime := theStartTime.Unix()
  9000. scheduleendTime := theEndTime.Unix()
  9001. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9002. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9003. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9004. //查询该床位是否有人用了
  9005. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9006. if err == nil {
  9007. if schedule.ID == 0 {
  9008. this.ServeSuccessJSON(map[string]interface{}{
  9009. "status": 0,
  9010. "msg": "请求失败",
  9011. })
  9012. } else {
  9013. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9014. if order.ID > 0 { //该机位被其他人占用了
  9015. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9016. return
  9017. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9018. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9019. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9020. this.ServeSuccessJSON(map[string]interface{}{
  9021. "status": 1,
  9022. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9023. })
  9024. return
  9025. } else {
  9026. this.ServeSuccessJSON(map[string]interface{}{
  9027. "status": 0,
  9028. "msg": "",
  9029. })
  9030. }
  9031. }
  9032. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9033. this.ServeSuccessJSON(map[string]interface{}{
  9034. "status": 2,
  9035. "msg": "当前机位已有患者在使用,请重新选择!",
  9036. })
  9037. }
  9038. }
  9039. } else {
  9040. this.ServeSuccessJSON(map[string]interface{}{
  9041. "status": 0,
  9042. "msg": "",
  9043. })
  9044. }
  9045. }
  9046. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9047. orgId := this.GetMobileAdminUserInfo().Org.Id
  9048. schedule_type, _ := this.GetInt64("schedule_type")
  9049. partion_type, _ := this.GetInt64("partion_type")
  9050. start_time := this.GetString("start_time")
  9051. timeLayout := "2006-01-02"
  9052. loc, _ := time.LoadLocation("Local")
  9053. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9054. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9055. _, config := service.FindXTHisRecordByOrgId(orgId)
  9056. appId := this.GetMobileAdminUserInfo().App.Id
  9057. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9058. if err == nil {
  9059. this.ServeSuccessJSON(map[string]interface{}{
  9060. "list": list,
  9061. "config": config,
  9062. "doctorList": doctorList,
  9063. })
  9064. return
  9065. } else {
  9066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9067. return
  9068. }
  9069. }
  9070. func (this *DialysisAPIController) SaveMobileInformation() {
  9071. patient_id, _ := this.GetInt64("patient_id")
  9072. record_date, _ := this.GetInt64("record_date")
  9073. startTime := this.GetString("start_time")
  9074. module, _ := this.GetInt64("module")
  9075. remark := this.GetString("remark")
  9076. timeLayout := "2006-01-02 15:04"
  9077. loc, _ := time.LoadLocation("Local")
  9078. if len(startTime) == 0 {
  9079. utils.ErrorLog("len(start_time) == 0")
  9080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9081. return
  9082. }
  9083. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9084. if err != nil {
  9085. utils.ErrorLog(err.Error())
  9086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9087. return
  9088. }
  9089. StartTime := theTime.Unix()
  9090. fmt.Println("startime-------------", StartTime)
  9091. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9092. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9093. information := models.XtDialysisInformation{
  9094. Module: module,
  9095. PatientId: patient_id,
  9096. RecordDate: record_date,
  9097. ApplicationDate: StartTime,
  9098. Creater: creater,
  9099. ApplicationStatus: 2,
  9100. Checker: 0,
  9101. CheckTime: 0,
  9102. Remark: remark,
  9103. UserOrgId: user_org_id,
  9104. Ctime: time.Now().Unix(),
  9105. Status: 1,
  9106. Mtime: 0,
  9107. }
  9108. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9109. if infor.ID == 0 {
  9110. service.SaveDialysisInformation(information)
  9111. }
  9112. if infor.ID > 0 {
  9113. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9114. }
  9115. this.ServeSuccessJSON(map[string]interface{}{
  9116. "information": information,
  9117. })
  9118. return
  9119. }
  9120. func (this *DialysisAPIController) GetMobileInformation() {
  9121. limit, _ := this.GetInt64("limit")
  9122. page, _ := this.GetInt64("page")
  9123. orgid := this.GetMobileAdminUserInfo().Org.Id
  9124. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9125. appid := this.GetMobileAdminUserInfo().App.Id
  9126. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9127. patients, _ := service.GetAllpatientThirty(orgid)
  9128. this.ServeSuccessJSON(map[string]interface{}{
  9129. "information": information,
  9130. "total": total,
  9131. "doclist": doclist,
  9132. "patients": patients,
  9133. })
  9134. return
  9135. }
  9136. func (this *DialysisAPIController) GetMobileInformationOne() {
  9137. limit, _ := this.GetInt64("limit")
  9138. page, _ := this.GetInt64("page")
  9139. orgid := this.GetMobileAdminUserInfo().Org.Id
  9140. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9141. appid := this.GetMobileAdminUserInfo().App.Id
  9142. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9143. patients, _ := service.GetAllpatientThirty(orgid)
  9144. this.ServeSuccessJSON(map[string]interface{}{
  9145. "information": information,
  9146. "total": total,
  9147. "doclist": doclist,
  9148. "patients": patients,
  9149. })
  9150. return
  9151. }
  9152. func (this *DialysisAPIController) CheckMobileInformation() {
  9153. id, _ := this.GetInt64("id")
  9154. application_status, _ := this.GetInt64("application_status")
  9155. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9156. checktime := time.Now().Unix()
  9157. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9158. if err == nil {
  9159. this.ServeSuccessJSON(map[string]interface{}{
  9160. "msg": "ok",
  9161. })
  9162. return
  9163. }
  9164. }
  9165. func (c *DialysisAPIController) GetControlMonitorList() {
  9166. partition, _ := c.GetInt64("partition")
  9167. monitorDate := c.GetString("date")
  9168. patient_id, _ := c.GetInt64("patient_id")
  9169. pat_type, _ := c.GetInt64("pat_type")
  9170. timeLayout := "2006-01-02"
  9171. loc, _ := time.LoadLocation("Local")
  9172. var theStartTime int64
  9173. if len(monitorDate) > 0 {
  9174. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9175. if err != nil {
  9176. theStartTime = 0
  9177. }
  9178. theStartTime = theTime.Unix()
  9179. }
  9180. adminInfo := c.GetMobileAdminUserInfo()
  9181. orgID := adminInfo.Org.Id
  9182. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9183. if err != nil {
  9184. c.ErrorLog("获取排班信息失败:%v", err)
  9185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9186. } else {
  9187. if len(monitor) > 0 {
  9188. //获取所有床位
  9189. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9190. //获取所有分区
  9191. zoneList, _ := service.GetAllZoneByList(orgID)
  9192. //获取透析处方
  9193. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9194. //获取透前评估
  9195. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9196. //获取上机
  9197. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9198. //获取透后
  9199. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9200. //获取透后监测
  9201. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9202. //获取所有的患者
  9203. patients, _ := service.GetAllPatientListByListOne(orgID)
  9204. //获取所有透析模式
  9205. treatments, _ := service.GetAllTreatModeByList(orgID)
  9206. //获取所有医嘱
  9207. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9208. //获取双人核对
  9209. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9210. //治疗小结
  9211. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9212. //待消毒
  9213. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9214. for key, item := range monitor {
  9215. // 获取床位信息
  9216. for _, it := range numberList {
  9217. if item.BedId == it.ID {
  9218. monitor[key].DeviceNumber = it
  9219. break
  9220. }
  9221. }
  9222. //获取分区信息
  9223. for _, it := range zoneList {
  9224. if item.PartitionId == it.ID {
  9225. monitor[key].DeviceZone = it
  9226. }
  9227. }
  9228. for _, prescription := range prescriptions {
  9229. if item.PatientId == prescription.PatientId {
  9230. monitor[key].Prescription = prescription
  9231. break
  9232. }
  9233. }
  9234. for _, it := range checkList {
  9235. if item.PatientId == it.PatientId {
  9236. monitor[key].DoubleCheck = it
  9237. break
  9238. }
  9239. }
  9240. for _, it := range summaryList {
  9241. if item.PatientId == it.PatientId {
  9242. monitor[key].TreatmentSummaryForList = it
  9243. break
  9244. }
  9245. }
  9246. // 透前评估
  9247. for _, assessmentBefore := range assessmentBefores {
  9248. if item.PatientId == assessmentBefore.PatientId {
  9249. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9250. break
  9251. }
  9252. }
  9253. // 透析上下机
  9254. for _, dialysisOrder := range dialysisOrders {
  9255. if item.PatientId == dialysisOrder.PatientId {
  9256. monitor[key].DialysisOrder = dialysisOrder
  9257. break
  9258. }
  9259. }
  9260. // 治疗小节
  9261. for _, afterDislysis := range AssessmentAfterDislysis {
  9262. if item.PatientId == afterDislysis.PatientId {
  9263. monitor[key].AssessmentAfterDislysis = afterDislysis
  9264. break
  9265. }
  9266. }
  9267. for _, it := range monitorlist {
  9268. if item.PatientId == it.PatientId {
  9269. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9270. }
  9271. }
  9272. for _, it := range adviceList {
  9273. if item.PatientId == it.PatientId {
  9274. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9275. }
  9276. }
  9277. for _, patient := range patients {
  9278. if item.PatientId == patient.ID {
  9279. monitor[key].MonitorPatients = patient
  9280. break
  9281. }
  9282. }
  9283. for _, treatment := range treatments {
  9284. if item.ModeId == treatment.ID {
  9285. monitor[key].TreatmentMode = treatment
  9286. break
  9287. }
  9288. }
  9289. for _, infor := range informationList {
  9290. if item.PatientId == infor.PatientId {
  9291. monitor[key].NewDeviceInformation = infor
  9292. break
  9293. }
  9294. }
  9295. }
  9296. }
  9297. }
  9298. patients, err := service.GetAllpatientFourty(orgID)
  9299. var mds []*models.NewMonitorDialysisScheduleList
  9300. if pat_type == 0 {
  9301. for _, item := range monitor {
  9302. mds = append(mds, item)
  9303. }
  9304. }
  9305. //待医嘱核对
  9306. if pat_type == 1 {
  9307. for _, item := range monitor {
  9308. if len(item.AdviceList) > 0 {
  9309. mds = append(mds, item)
  9310. }
  9311. }
  9312. }
  9313. //待开小结
  9314. if pat_type == 2 {
  9315. for _, item := range monitor {
  9316. if item.TreatmentSummaryForList == nil {
  9317. mds = append(mds, item)
  9318. }
  9319. }
  9320. }
  9321. //待下机
  9322. if pat_type == 3 {
  9323. for _, item := range monitor {
  9324. if item.DialysisOrder != nil {
  9325. if item.DialysisOrder.ID > 0 {
  9326. mds = append(mds, item)
  9327. }
  9328. }
  9329. }
  9330. }
  9331. //待消毒
  9332. if pat_type == 4 {
  9333. for _, item := range monitor {
  9334. if item.NewDeviceInformation == nil {
  9335. mds = append(mds, item)
  9336. }
  9337. }
  9338. }
  9339. //待双人核对
  9340. if pat_type == 5 {
  9341. for _, item := range monitor {
  9342. if item.DoubleCheck == nil {
  9343. mds = append(mds, item)
  9344. }
  9345. }
  9346. }
  9347. //医嘱未执行
  9348. if pat_type == 6 {
  9349. for _, item := range monitor {
  9350. if len(item.AdviceList) > 0 {
  9351. mds = append(mds, item)
  9352. }
  9353. }
  9354. }
  9355. //患者未签名
  9356. if pat_type == 7 {
  9357. for _, item := range monitor {
  9358. if item.DialysisOrder != nil {
  9359. if item.DialysisOrder.ID > 0 {
  9360. mds = append(mds, item)
  9361. }
  9362. }
  9363. }
  9364. }
  9365. //目标超滤于实际超滤不同
  9366. if pat_type == 8 {
  9367. for _, item := range monitor {
  9368. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9369. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9370. mds = append(mds, item)
  9371. }
  9372. }
  9373. }
  9374. }
  9375. //血压少于5次
  9376. if pat_type == 9 {
  9377. for _, item := range monitor {
  9378. if len(item.MonitoringRecord) < 5 {
  9379. mds = append(mds, item)
  9380. }
  9381. }
  9382. }
  9383. if pat_type == 10 {
  9384. for _, item := range monitor {
  9385. if len(item.MonitoringRecord) == 0 {
  9386. mds = append(mds, item)
  9387. }
  9388. }
  9389. }
  9390. if pat_type == 11 {
  9391. for _, item := range monitor {
  9392. if len(item.MonitoringRecord) > 0 {
  9393. mds = append(mds, item)
  9394. }
  9395. }
  9396. }
  9397. if pat_type == 12 {
  9398. for _, item := range monitor {
  9399. if len(item.MonitoringRecord) > 0 {
  9400. mds = append(mds, item)
  9401. }
  9402. }
  9403. }
  9404. if err == nil {
  9405. c.ServeSuccessJSON(map[string]interface{}{
  9406. "monitor": mds,
  9407. "patients": patients,
  9408. })
  9409. } else {
  9410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9411. }
  9412. }
  9413. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9414. admin_user_id, _ := c.GetInt64("admin_user_id")
  9415. timeStr := time.Now().Format("2006-01-02")
  9416. timeLayout := "2006-01-02 15:04:05"
  9417. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9418. timenow := timeStringToTime.Unix()
  9419. orgId := c.GetMobileAdminUserInfo().Org.Id
  9420. //查询当前护士的患者
  9421. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9422. var patientIds []int64
  9423. for _, item := range orderList {
  9424. patientIds = append(patientIds, item.PatientId)
  9425. }
  9426. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9427. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9428. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9429. //药品管理信息
  9430. _, drugStockConfig := service.FindHisConfig(orgId)
  9431. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9432. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9433. c.ServeSuccessJSON(map[string]interface{}{
  9434. "adviceList": adviceList,
  9435. "hisAdviceList": hisAdviceList,
  9436. "projectList": projectList,
  9437. "drugStockConfig": drugStockConfig,
  9438. "patientList": patientList,
  9439. "projectConfig": projectConfig,
  9440. })
  9441. }
  9442. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9443. patient_id, _ := c.GetInt64("patient_id")
  9444. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9445. c.ServeSuccessJSON(map[string]interface{}{
  9446. "recrods": recrods,
  9447. })
  9448. }
  9449. func (c *DialysisAPIController) ExMobileChangeSch() {
  9450. id_one, _ := c.GetInt64("id_one")
  9451. id_two, _ := c.GetInt64("id_two")
  9452. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9453. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9454. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9455. //if order2.ID > 0 {
  9456. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9457. // return
  9458. //}
  9459. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9460. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9461. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9462. if count > 0 {
  9463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9464. return
  9465. }
  9466. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9467. if count1 > 0 {
  9468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9469. return
  9470. }
  9471. }
  9472. err := service.UpdateScheduleThree(sch, sch_two)
  9473. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9474. if order.ID > 0 {
  9475. //查询该患者的排班机位
  9476. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9477. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9478. redis := service.RedisClient()
  9479. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9480. redis.Set(key, "", time.Second)
  9481. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9482. //清空key 值
  9483. redis.Set(keyOne, "", time.Second)
  9484. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9485. //return
  9486. }
  9487. if err == nil {
  9488. //去除当天患者排班中重复数据,保留最后一条数据
  9489. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9490. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9491. c.ServeSuccessJSON(map[string]interface{}{
  9492. "msg": "交换成功",
  9493. })
  9494. } else {
  9495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9496. return
  9497. }
  9498. }
  9499. func (c *DialysisAPIController) MobileCoverSch() {
  9500. id_one, _ := c.GetInt64("id_one")
  9501. id_two, _ := c.GetInt64("id_two")
  9502. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9503. //针对凤凰医院
  9504. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9505. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9506. if len(advice) > 0 {
  9507. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9508. }
  9509. }
  9510. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9511. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9512. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9513. if len(hisAdvice) > 0 {
  9514. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9515. }
  9516. if len(project) > 0 {
  9517. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9518. }
  9519. }
  9520. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9521. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9522. if order.ID > 0 {
  9523. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9524. redis := service.RedisClient()
  9525. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9526. redis.Set(key, "", time.Second)
  9527. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9528. //清空key 值
  9529. redis.Set(keyOne, "", time.Second)
  9530. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9531. //return
  9532. }
  9533. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9534. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9535. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9536. if count > 0 {
  9537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9538. return
  9539. }
  9540. }
  9541. var new_sch models.Schedule
  9542. new_sch = sch
  9543. new_sch.BedId = sch_two.BedId
  9544. new_sch.ScheduleDate = sch_two.ScheduleDate
  9545. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9546. new_sch.PartitionId = sch_two.PartitionId
  9547. new_sch.ScheduleType = sch_two.ScheduleType
  9548. new_sch.ID = 0
  9549. //删除原来的排班
  9550. err := service.SaveSchTwo(sch, sch_two)
  9551. //生成新的排班
  9552. if err == nil {
  9553. err2 := service.SaveSch(&new_sch)
  9554. if err2 == nil {
  9555. //去除当天患者排班中重复数据,保留最后一条数据
  9556. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9557. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9558. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9559. c.ServeSuccessJSON(map[string]interface{}{
  9560. "msg": "覆盖成功",
  9561. "new_sch": new_sch,
  9562. })
  9563. } else {
  9564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9565. return
  9566. }
  9567. } else {
  9568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9569. return
  9570. }
  9571. }
  9572. func (c *DialysisAPIController) BatchCheckAdvice() {
  9573. patient_id, _ := c.GetInt64("patient_id")
  9574. advice_date, _ := c.GetInt64("advice_date")
  9575. org_id := c.GetMobileAdminUserInfo().Org.Id
  9576. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9577. //查询是his系统还是血透系统
  9578. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9579. //his客户
  9580. if configs.IsOpen == 1 {
  9581. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9582. for _, item := range adviceList {
  9583. service.BatchCheckHisAdvice(item.ID, creater)
  9584. }
  9585. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9586. for _, item := range projectList {
  9587. service.BatchCheckProject(item.ID, creater)
  9588. }
  9589. c.ServeSuccessJSON(map[string]interface{}{
  9590. "adviceList": adviceList,
  9591. "projectList": projectList,
  9592. })
  9593. }
  9594. if configs.IsOpen != 1 {
  9595. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9596. for _, item := range adviceList {
  9597. service.BatchAdviceList(item.ID, creater)
  9598. }
  9599. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9600. for _, item := range projectList {
  9601. service.BatchCheckProject(item.ID, creater)
  9602. }
  9603. c.ServeSuccessJSON(map[string]interface{}{
  9604. "adviceList": adviceList,
  9605. "projectList": projectList,
  9606. })
  9607. }
  9608. return
  9609. }
  9610. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9611. org_id := c.GetMobileAdminUserInfo().Org.Id
  9612. drugList, _ := service.GetAllDrugList(org_id)
  9613. c.ServeSuccessJSON(map[string]interface{}{
  9614. "drugList": drugList,
  9615. })
  9616. }
  9617. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9618. org_id := c.GetMobileAdminUserInfo().Org.Id
  9619. dataBody := make(map[string]interface{}, 0)
  9620. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9621. if err != nil {
  9622. utils.ErrorLog(err.Error())
  9623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9624. return
  9625. }
  9626. timeLayout := "2006-01-02"
  9627. loc, _ := time.LoadLocation("Local")
  9628. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9629. utils.ErrorLog("advice_type")
  9630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9631. return
  9632. }
  9633. adviceType := int64(dataBody["advice_type"].(float64))
  9634. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9635. utils.ErrorLog("start_time")
  9636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9637. return
  9638. }
  9639. startTime2, _ := dataBody["start_time"].(string)
  9640. time_arr := strings.Split(startTime2, " ")
  9641. if len(time_arr) > 0 {
  9642. startTime2 = time_arr[0]
  9643. }
  9644. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9645. utils.ErrorLog("advice_date")
  9646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9647. return
  9648. }
  9649. advice_date, _ := dataBody["advice_date"].(string)
  9650. var advicedateunix int64
  9651. if len(advice_date) > 0 {
  9652. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9653. if err != nil {
  9654. fmt.Println(err)
  9655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9656. return
  9657. }
  9658. advicedateunix = theTime.Unix()
  9659. }
  9660. adviceDate := startTime2
  9661. if len(adviceDate) == 0 {
  9662. utils.ErrorLog("len(adviceDate) == 0")
  9663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9664. return
  9665. }
  9666. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9667. if err != nil {
  9668. utils.ErrorLog(err.Error())
  9669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9670. return
  9671. }
  9672. AdviceDate := advicedateunix
  9673. RecordDate := advicedateunix
  9674. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9675. utils.ErrorLog("start_time")
  9676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9677. return
  9678. }
  9679. startTime, _ := dataBody["start_time"].(string)
  9680. if len(startTime) == 0 {
  9681. utils.ErrorLog("len(start_time) == 0")
  9682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9683. return
  9684. }
  9685. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9686. if err != nil {
  9687. utils.ErrorLog(err.Error())
  9688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9689. return
  9690. }
  9691. StartTime := theTime.Unix()
  9692. advice_name, _ := dataBody["advice_name"].(string)
  9693. advice_desc, _ := dataBody["advice_desc"].(string)
  9694. delivery_way, _ := dataBody["delivery_way"].(string)
  9695. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9696. frequency_type := int64(dataBody["frequency_type"].(float64))
  9697. frequency_week, _ := dataBody["frequency_week"].(string)
  9698. prescribing_number := dataBody["prescribing_number"].(float64)
  9699. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9700. remark := dataBody["remark"].(string)
  9701. single_dose := dataBody["single_dose"].(float64)
  9702. single_dose_unit := dataBody["single_dose_unit"].(string)
  9703. patient_id := int64(dataBody["patient_id"].(float64))
  9704. day_count := int64(dataBody["day_count"].(float64))
  9705. groupNo := int64(dataBody["group_no"].(float64))
  9706. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9707. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9708. if groupNo <= 0 {
  9709. group := service.GetMaxAdviceGroupID(org_id)
  9710. groupNo = group + 1
  9711. }
  9712. var template_id = ""
  9713. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9714. template_id = "M" + adviceLastId
  9715. advice := models.DoctorAdvice{
  9716. UserOrgId: org_id,
  9717. PatientId: patient_id,
  9718. AdviceType: adviceType,
  9719. AdviceDate: AdviceDate,
  9720. StartTime: StartTime,
  9721. AdviceName: advice_name,
  9722. AdviceDesc: advice_desc,
  9723. ReminderDate: 0,
  9724. SingleDose: single_dose,
  9725. SingleDoseUnit: single_dose_unit,
  9726. DrugSpec: 0,
  9727. DrugSpecUnit: "",
  9728. PrescribingNumber: prescribing_number,
  9729. PrescribingNumberUnit: prescribing_number_unit,
  9730. DeliveryWay: delivery_way,
  9731. ExecutionFrequency: execution_frequency,
  9732. AdviceDoctor: advice_doctor,
  9733. Status: 1,
  9734. CreatedTime: time.Now().Unix(),
  9735. UpdatedTime: 0,
  9736. AdviceAffirm: "",
  9737. Remark: remark,
  9738. StopTime: 0,
  9739. StopReason: "",
  9740. StopDoctor: 0,
  9741. StopState: 0,
  9742. ParentId: 0,
  9743. ExecutionTime: 0,
  9744. ExecutionStaff: 0,
  9745. ExecutionState: 0,
  9746. Checker: 0,
  9747. RecordDate: RecordDate,
  9748. DialysisOrderId: 0,
  9749. CheckTime: 0,
  9750. CheckState: 0,
  9751. AdviceId: 0,
  9752. RemindType: 0,
  9753. FrequencyType: frequency_type,
  9754. DayCount: day_count,
  9755. WeekDay: frequency_week,
  9756. ChildDoctorAdvice: nil,
  9757. TemplateId: template_id,
  9758. Modifier: 0,
  9759. IsCheck: 0,
  9760. Way: 0,
  9761. DrugId: 0,
  9762. DrugNameId: 0,
  9763. IsMedicine: 0,
  9764. PushStartTime: 0,
  9765. IsSettle: 0,
  9766. IsPrescription: 0,
  9767. GroupNo: groupNo,
  9768. }
  9769. service.CreateMobileAdivce(advice)
  9770. c.ServeSuccessJSON(map[string]interface{}{
  9771. "msg": "保存成功!",
  9772. })
  9773. }
  9774. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9775. patient_id, _ := c.GetInt64("patient_id")
  9776. org_id := c.GetMobileAdminUserInfo().Org.Id
  9777. app_id := c.GetMobileAdminUserInfo().App.Id
  9778. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9779. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9780. c.ServeSuccessJSON(map[string]interface{}{
  9781. "adviceList": adviceList,
  9782. "adminRoles": adminRoles,
  9783. })
  9784. }
  9785. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9786. org_id := c.GetMobileAdminUserInfo().Org.Id
  9787. dataBody := make(map[string]interface{}, 0)
  9788. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9789. if err != nil {
  9790. utils.ErrorLog(err.Error())
  9791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9792. return
  9793. }
  9794. timeLayout := "2006-01-02"
  9795. loc, _ := time.LoadLocation("Local")
  9796. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9797. utils.ErrorLog("start_time")
  9798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9799. return
  9800. }
  9801. startTime2, _ := dataBody["start_time"].(string)
  9802. time_arr := strings.Split(startTime2, " ")
  9803. if len(time_arr) > 0 {
  9804. startTime2 = time_arr[0]
  9805. }
  9806. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9807. utils.ErrorLog("advice_date")
  9808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9809. return
  9810. }
  9811. advice_date, _ := dataBody["advice_date"].(string)
  9812. var advicedateunix int64
  9813. if len(advice_date) > 0 {
  9814. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9815. if err != nil {
  9816. fmt.Println(err)
  9817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9818. return
  9819. }
  9820. advicedateunix = theTime.Unix()
  9821. }
  9822. adviceDate := startTime2
  9823. if len(adviceDate) == 0 {
  9824. utils.ErrorLog("len(adviceDate) == 0")
  9825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9826. return
  9827. }
  9828. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9829. if err != nil {
  9830. utils.ErrorLog(err.Error())
  9831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9832. return
  9833. }
  9834. AdviceDate := advicedateunix
  9835. RecordDate := advicedateunix
  9836. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9837. utils.ErrorLog("start_time")
  9838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9839. return
  9840. }
  9841. startTime, _ := dataBody["start_time"].(string)
  9842. if len(startTime) == 0 {
  9843. utils.ErrorLog("len(start_time) == 0")
  9844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9845. return
  9846. }
  9847. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9848. if err != nil {
  9849. utils.ErrorLog(err.Error())
  9850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9851. return
  9852. }
  9853. StartTime := theTime.Unix()
  9854. advice_name, _ := dataBody["advice_name"].(string)
  9855. advice_desc, _ := dataBody["advice_desc"].(string)
  9856. delivery_way, _ := dataBody["delivery_way"].(string)
  9857. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9858. prescribing_number := dataBody["prescribing_number"].(float64)
  9859. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9860. remark := dataBody["remark"].(string)
  9861. single_dose := dataBody["single_dose"].(float64)
  9862. single_dose_unit := dataBody["single_dose_unit"].(string)
  9863. patient_id := int64(dataBody["patient_id"].(float64))
  9864. groupNo := int64(dataBody["group_no"].(float64))
  9865. parent_id := int64(dataBody["parent_id"].(float64))
  9866. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9867. advice := models.XtDoctorAdviceOne{
  9868. UserOrgId: org_id,
  9869. PatientId: patient_id,
  9870. AdviceType: 1,
  9871. AdviceDate: AdviceDate,
  9872. StartTime: StartTime,
  9873. AdviceName: advice_name,
  9874. AdviceDesc: advice_desc,
  9875. ReminderDate: 0,
  9876. SingleDose: single_dose,
  9877. SingleDoseUnit: single_dose_unit,
  9878. PrescribingNumber: prescribing_number,
  9879. PrescribingNumberUnit: prescribing_number_unit,
  9880. DeliveryWay: delivery_way,
  9881. ExecutionFrequency: execution_frequency,
  9882. AdviceDoctor: advice_doctor,
  9883. Status: 1,
  9884. CreatedTime: time.Now().Unix(),
  9885. UpdatedTime: time.Now().Unix(),
  9886. AdviceAffirm: "",
  9887. Remark: remark,
  9888. StopTime: 0,
  9889. StopReason: "",
  9890. StopDoctor: 0,
  9891. StopState: 0,
  9892. ParentId: parent_id,
  9893. ExecutionTime: 0,
  9894. ExecutionStaff: 0,
  9895. ExecutionState: 0,
  9896. Checker: 0,
  9897. RecordDate: RecordDate,
  9898. DialysisOrderId: 0,
  9899. CheckTime: 0,
  9900. CheckState: 0,
  9901. DrugSpec: 0,
  9902. DrugSpecUnit: "",
  9903. Groupno: groupNo,
  9904. RemindType: 0,
  9905. FrequencyType: 0,
  9906. DayCount: 0,
  9907. WeekDay: "",
  9908. TemplateId: "",
  9909. Modifier: 0,
  9910. }
  9911. service.CreateMobileAdivceOne(advice)
  9912. c.ServeSuccessJSON(map[string]interface{}{
  9913. "msg": "保存成功!",
  9914. })
  9915. }
  9916. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  9917. id, _ := c.GetInt64("id")
  9918. service.DeleteSelfAdviceSubAdvice(id)
  9919. c.ServeSuccessJSON(map[string]interface{}{
  9920. "msg": "保存成功!",
  9921. })
  9922. }
  9923. func (c *DialysisAPIController) GetEditAdviceAction() {
  9924. id, _ := c.GetInt64("id")
  9925. org_id := c.GetMobileAdminUserInfo().Org.Id
  9926. advice, _ := service.GetEditAdviceActionList(id, org_id)
  9927. drugList, _ := service.GetAllDrugList(org_id)
  9928. c.ServeSuccessJSON(map[string]interface{}{
  9929. "advice": advice,
  9930. "drugList": drugList,
  9931. })
  9932. }
  9933. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  9934. dataBody := make(map[string]interface{}, 0)
  9935. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9936. if err != nil {
  9937. utils.ErrorLog(err.Error())
  9938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9939. return
  9940. }
  9941. timeLayout := "2006-01-02"
  9942. loc, _ := time.LoadLocation("Local")
  9943. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9944. utils.ErrorLog("start_time")
  9945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9946. return
  9947. }
  9948. startTime2, _ := dataBody["start_time"].(string)
  9949. time_arr := strings.Split(startTime2, " ")
  9950. if len(time_arr) > 0 {
  9951. startTime2 = time_arr[0]
  9952. }
  9953. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9954. utils.ErrorLog("advice_date")
  9955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9956. return
  9957. }
  9958. advice_date, _ := dataBody["advice_date"].(string)
  9959. var advicedateunix int64
  9960. if len(advice_date) > 0 {
  9961. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9962. if err != nil {
  9963. fmt.Println(err)
  9964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9965. return
  9966. }
  9967. advicedateunix = theTime.Unix()
  9968. }
  9969. adviceDate := startTime2
  9970. if len(adviceDate) == 0 {
  9971. utils.ErrorLog("len(adviceDate) == 0")
  9972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9973. return
  9974. }
  9975. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9976. if err != nil {
  9977. utils.ErrorLog(err.Error())
  9978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9979. return
  9980. }
  9981. AdviceDate := advicedateunix
  9982. RecordDate := advicedateunix
  9983. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9984. utils.ErrorLog("start_time")
  9985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9986. return
  9987. }
  9988. startTime, _ := dataBody["start_time"].(string)
  9989. if len(startTime) == 0 {
  9990. utils.ErrorLog("len(start_time) == 0")
  9991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9992. return
  9993. }
  9994. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9995. if err != nil {
  9996. utils.ErrorLog(err.Error())
  9997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9998. return
  9999. }
  10000. StartTime := theTime.Unix()
  10001. advice_name, _ := dataBody["advice_name"].(string)
  10002. advice_desc, _ := dataBody["advice_desc"].(string)
  10003. delivery_way, _ := dataBody["delivery_way"].(string)
  10004. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10005. prescribing_number := dataBody["prescribing_number"].(float64)
  10006. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10007. remark := dataBody["remark"].(string)
  10008. single_dose := dataBody["single_dose"].(float64)
  10009. single_dose_unit := dataBody["single_dose_unit"].(string)
  10010. id := int64(dataBody["id"].(float64))
  10011. frequency_type := int64(dataBody["frequency_type"].(float64))
  10012. frequency_week, _ := dataBody["frequency_week"].(string)
  10013. day_count := int64(dataBody["day_count"].(float64))
  10014. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10015. advice := models.XtDoctorAdviceOne{
  10016. AdviceDate: AdviceDate,
  10017. StartTime: StartTime,
  10018. AdviceName: advice_name,
  10019. AdviceDesc: advice_desc,
  10020. SingleDose: single_dose,
  10021. SingleDoseUnit: single_dose_unit,
  10022. PrescribingNumber: prescribing_number,
  10023. PrescribingNumberUnit: prescribing_number_unit,
  10024. DeliveryWay: delivery_way,
  10025. ExecutionFrequency: execution_frequency,
  10026. AdviceDoctor: advice_doctor,
  10027. Remark: remark,
  10028. RecordDate: RecordDate,
  10029. FrequencyType: frequency_type,
  10030. DayCount: day_count,
  10031. WeekDay: frequency_week,
  10032. }
  10033. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10034. c.ServeSuccessJSON(map[string]interface{}{
  10035. "advice": advice,
  10036. })
  10037. }
  10038. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10039. dataBody := make(map[string]interface{}, 0)
  10040. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10041. if err != nil {
  10042. utils.ErrorLog(err.Error())
  10043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10044. return
  10045. }
  10046. timeLayout := "2006-01-02"
  10047. loc, _ := time.LoadLocation("Local")
  10048. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10049. utils.ErrorLog("start_time")
  10050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10051. return
  10052. }
  10053. startTime2, _ := dataBody["start_time"].(string)
  10054. time_arr := strings.Split(startTime2, " ")
  10055. if len(time_arr) > 0 {
  10056. startTime2 = time_arr[0]
  10057. }
  10058. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10059. utils.ErrorLog("advice_date")
  10060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10061. return
  10062. }
  10063. advice_date, _ := dataBody["advice_date"].(string)
  10064. var advicedateunix int64
  10065. if len(advice_date) > 0 {
  10066. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10067. if err != nil {
  10068. fmt.Println(err)
  10069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10070. return
  10071. }
  10072. advicedateunix = theTime.Unix()
  10073. }
  10074. adviceDate := startTime2
  10075. if len(adviceDate) == 0 {
  10076. utils.ErrorLog("len(adviceDate) == 0")
  10077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10078. return
  10079. }
  10080. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10081. if err != nil {
  10082. utils.ErrorLog(err.Error())
  10083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10084. return
  10085. }
  10086. AdviceDate := advicedateunix
  10087. RecordDate := advicedateunix
  10088. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10089. utils.ErrorLog("start_time")
  10090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10091. return
  10092. }
  10093. startTime, _ := dataBody["start_time"].(string)
  10094. if len(startTime) == 0 {
  10095. utils.ErrorLog("len(start_time) == 0")
  10096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10097. return
  10098. }
  10099. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10100. if err != nil {
  10101. utils.ErrorLog(err.Error())
  10102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10103. return
  10104. }
  10105. StartTime := theTime.Unix()
  10106. advice_name, _ := dataBody["advice_name"].(string)
  10107. advice_desc, _ := dataBody["advice_desc"].(string)
  10108. delivery_way, _ := dataBody["delivery_way"].(string)
  10109. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10110. prescribing_number := dataBody["prescribing_number"].(float64)
  10111. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10112. remark := dataBody["remark"].(string)
  10113. single_dose := dataBody["single_dose"].(float64)
  10114. single_dose_unit := dataBody["single_dose_unit"].(string)
  10115. id := int64(dataBody["id"].(float64))
  10116. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10117. advice := models.XtDoctorAdviceOne{
  10118. AdviceDate: AdviceDate,
  10119. StartTime: StartTime,
  10120. AdviceName: advice_name,
  10121. AdviceDesc: advice_desc,
  10122. SingleDose: single_dose,
  10123. SingleDoseUnit: single_dose_unit,
  10124. PrescribingNumber: prescribing_number,
  10125. PrescribingNumberUnit: prescribing_number_unit,
  10126. DeliveryWay: delivery_way,
  10127. ExecutionFrequency: execution_frequency,
  10128. AdviceDoctor: advice_doctor,
  10129. Remark: remark,
  10130. RecordDate: RecordDate,
  10131. }
  10132. service.UpdateMobileDoctorAdviceById(id, advice)
  10133. c.ServeSuccessJSON(map[string]interface{}{
  10134. "advice": advice,
  10135. })
  10136. }
  10137. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10138. dataBody := make(map[string]interface{}, 0)
  10139. timeLayout := "2006-01-02"
  10140. loc, _ := time.LoadLocation("Local")
  10141. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10142. if err != nil {
  10143. utils.ErrorLog(err.Error())
  10144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10145. return
  10146. }
  10147. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10148. utils.ErrorLog("start_time")
  10149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10150. return
  10151. }
  10152. startTime2, _ := dataBody["start_time"].(string)
  10153. time_arr := strings.Split(startTime2, " ")
  10154. if len(time_arr) > 0 {
  10155. startTime2 = time_arr[0]
  10156. }
  10157. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10158. utils.ErrorLog("advice_date")
  10159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10160. return
  10161. }
  10162. advice_date, _ := dataBody["advice_date"].(string)
  10163. var advicedateunix int64
  10164. if len(advice_date) > 0 {
  10165. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10166. if err != nil {
  10167. fmt.Println(err)
  10168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10169. return
  10170. }
  10171. advicedateunix = theTime.Unix()
  10172. }
  10173. adviceDate := startTime2
  10174. if len(adviceDate) == 0 {
  10175. utils.ErrorLog("len(adviceDate) == 0")
  10176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10177. return
  10178. }
  10179. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10180. if err != nil {
  10181. utils.ErrorLog(err.Error())
  10182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10183. return
  10184. }
  10185. RecordDate := advicedateunix
  10186. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10187. utils.ErrorLog("start_time")
  10188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10189. return
  10190. }
  10191. startTime, _ := dataBody["start_time"].(string)
  10192. if len(startTime) == 0 {
  10193. utils.ErrorLog("len(start_time) == 0")
  10194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10195. return
  10196. }
  10197. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10198. if err != nil {
  10199. utils.ErrorLog(err.Error())
  10200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10201. return
  10202. }
  10203. StartTime := theTime.Unix()
  10204. patient_id := int64(dataBody["patient_id"].(float64))
  10205. group_no := int64(dataBody["group_no"].(float64))
  10206. org_id := c.GetMobileAdminUserInfo().Org.Id
  10207. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10208. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10209. utils.ErrorLog("advices")
  10210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10211. return
  10212. }
  10213. adviceNames := dataBody["advices"].([]interface{})
  10214. var advices []*models.GroupAdvice
  10215. for _, adviceNameMap := range adviceNames {
  10216. var advice models.GroupAdvice
  10217. adviceNameM := adviceNameMap.(map[string]interface{})
  10218. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10219. utils.ErrorLog("advice_name")
  10220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10221. return
  10222. }
  10223. adviceName, _ := adviceNameM["advice_name"].(string)
  10224. if len(adviceName) == 0 {
  10225. utils.ErrorLog("len(advice_name) == 0")
  10226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10227. return
  10228. }
  10229. advice.AdviceName = adviceName
  10230. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10231. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10232. advice.DrugSpec = drugSpec
  10233. }
  10234. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10235. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10236. advice.AdviceDesc = adviceDesc
  10237. }
  10238. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10239. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10240. advice.DrugSpecUnit = drugSpecUnit
  10241. }
  10242. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10243. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10244. advice.SingleDose = singleDose
  10245. }
  10246. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10247. singleDose := adviceNameM["single_dose"].(float64)
  10248. advice.SingleDose = singleDose
  10249. }
  10250. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10251. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10252. advice.SingleDoseUnit = singleDoseUnit
  10253. }
  10254. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10255. tmp := adviceNameM["single_dose_unit"].(float64)
  10256. singleDoseUnit := service.TypeConversion(tmp)
  10257. advice.SingleDoseUnit = singleDoseUnit
  10258. }
  10259. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10260. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10261. advice.PrescribingNumber = prescribingNumber
  10262. }
  10263. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10264. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10265. advice.PrescribingNumber = prescribingNumber
  10266. }
  10267. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10268. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10269. advice.PrescribingNumberUnit = prescribingNumberUnit
  10270. }
  10271. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10272. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10273. advice.DeliveryWay = deliveryWay
  10274. }
  10275. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10276. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10277. advice.ExecutionFrequency = executionFrequency
  10278. }
  10279. remark, _ := adviceNameM["remark"].(string)
  10280. advice.Remark = remark
  10281. advice.AdviceType = 1
  10282. advice.StartTime = StartTime
  10283. advice.RecordDate = RecordDate
  10284. advice.PatientId = patient_id
  10285. advice.UserOrgId = org_id
  10286. advice.AdviceDoctor = advice_doctor
  10287. advices = append(advices, &advice)
  10288. }
  10289. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10290. c.ServeSuccessJSON(map[string]interface{}{
  10291. "advice": newAdvices,
  10292. })
  10293. }