dialysis_api_controller.go 449KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616
  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. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. }
  1124. }
  1125. }
  1126. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1127. UserOrgId: adminUserInfo.Org.Id,
  1128. PatientId: id,
  1129. RecordDate: recordDate.Unix(),
  1130. Way: way,
  1131. Consciousness: consciousness,
  1132. Appetite: appetite,
  1133. Condition: condition,
  1134. SickCondition: sick_condition,
  1135. DangerLevel: danger_level,
  1136. Intake: intake,
  1137. Nutrition: nutrition,
  1138. PsychologicalAssessment: psychological_assessment,
  1139. PsychologicalAssessmentOther: psychological_assessment_other,
  1140. SickConditionOther: sick_condition_other,
  1141. Posture: posture,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. Status: 1,
  1145. Score: score,
  1146. Precaution: precaution,
  1147. PrecautionOther: precaution_other,
  1148. PsychologicalOther: psychological_other,
  1149. AdmissionNumber: admission_number,
  1150. Tumble: tumble,
  1151. Diacrisis: diacrisis,
  1152. HisBed: his_bed,
  1153. HisDepartment: his_department,
  1154. }
  1155. if receiveTreatment.ID == 0 { //新增
  1156. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1157. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1158. finish := models.XtDialysisFinish{
  1159. IsFinish: 1,
  1160. UserOrgId: adminUserInfo.Org.Id,
  1161. Status: 1,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Module: 2,
  1165. RecordDate: recordDate.Unix(),
  1166. Sourse: 1,
  1167. PatientId: id,
  1168. }
  1169. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1170. if dialysisFinish.ID == 0 {
  1171. service.CreateDialysisFinish(finish)
  1172. }
  1173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1174. redis := service.RedisClient()
  1175. defer redis.Close()
  1176. //清空key 值
  1177. redis.Set(key, "", time.Second)
  1178. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1179. redis.Set(keyOne, "", time.Second)
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "receiveTreatmentAsses": receiveTreatmentAsses,
  1183. })
  1184. }
  1185. } else { //修改
  1186. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1187. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1188. // if getPermissionErr != nil {
  1189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. // return
  1191. // } else if headNursePermission == nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1193. // return
  1194. // }
  1195. //}
  1196. // 查询信息规挡的设置天数
  1197. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1198. if infor.ID > 0 && infor.WeekDay > 0 {
  1199. var cha_time int64
  1200. timeNowStr := time.Now().Format("2006-01-02")
  1201. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1202. //今日的日期减去设置的日期
  1203. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1204. if cha_time >= recordDate.Unix() {
  1205. //查询审核是否允许
  1206. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1207. //申请状态不允许的情况 拒绝修改
  1208. if infor.ApplicationStatus != 1 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1210. return
  1211. }
  1212. }
  1213. }
  1214. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1215. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1216. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1217. receiveTreatmentAsses.ID = receiveTreatment.ID
  1218. if adminUserInfo.Org.Id == 10340 {
  1219. if condition == 1 {
  1220. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1221. if receiveTreatmentAsses.AdmissionNumber == "" {
  1222. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1223. }
  1224. }
  1225. }
  1226. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1227. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1228. redis := service.RedisClient()
  1229. defer redis.Close()
  1230. //清空key 值
  1231. redis.Set(key, "", time.Second)
  1232. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1233. redis.Set(keyOne, "", time.Second)
  1234. if err == nil {
  1235. c.ServeSuccessJSON(map[string]interface{}{
  1236. "receiveTreatmentAsses": receiveTreatmentAsses,
  1237. })
  1238. }
  1239. }
  1240. }
  1241. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1242. id, _ := c.GetInt64("patient", 0)
  1243. recordDateStr := c.GetString("record_date")
  1244. weightAfter, _ := c.GetFloat("weight_after", 0)
  1245. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1246. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1247. fmt.Println("weight_loss", weightReduce)
  1248. temperature, _ := c.GetFloat("temperature", 0)
  1249. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1250. breathing_rate := c.GetString("breathing_rate")
  1251. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1252. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1253. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1254. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1255. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1256. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1257. cruor := c.GetString("cruor")
  1258. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1259. internalFistula := c.GetString("internal_fistula")
  1260. catheter := c.GetString("catheter")
  1261. complications := c.GetString("complication")
  1262. remark := c.GetString("remark")
  1263. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1264. dialysis_intakes := c.GetString("dialysis_intakes")
  1265. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1266. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1267. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1268. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1269. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1270. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1271. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1272. patientGose, _ := c.GetInt64("patient_gose", 0)
  1273. inpatientDepartment := c.GetString("inpatient_department")
  1274. observationContent := c.GetString("observation_content")
  1275. observationContentOther := c.GetString("observation_content_other")
  1276. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1277. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1278. in_advance_reason := c.GetString("in_advance_reason")
  1279. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1280. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1281. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1282. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1283. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1284. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1285. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1286. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1287. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1288. is_eat, _ := c.GetInt64("is_eat", 0)
  1289. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1290. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1291. channels, _ := c.GetInt64("channel", 0)
  1292. return_blood, _ := c.GetInt64("return_blood", 0)
  1293. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1294. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1295. dialysis_during, _ := c.GetFloat("dialysis_during")
  1296. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1297. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1298. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1299. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1300. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1301. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1302. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1303. setting_pressure := c.GetString("setting_pressure")
  1304. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1305. diastolic_pressure := c.GetString("diastolic_pressure")
  1306. other_complication := c.GetString("other_complication")
  1307. ktv := c.GetString("ktv")
  1308. urr := c.GetString("urr")
  1309. hypertenison, _ := c.GetInt64("hypertenison")
  1310. hypopiesia, _ := c.GetInt64("hypopiesia")
  1311. leave_office_method, _ := c.GetInt64("leave_office_method")
  1312. lapse, _ := c.GetInt64("lapse")
  1313. consciousness, _ := c.GetInt64("consciousness")
  1314. fallrisk, _ := c.GetInt64("fallrisk")
  1315. machine_run := c.GetString("machine_run")
  1316. after_urea := c.GetString("after_urea")
  1317. pip_coagulation := c.GetString("pip_coagulation")
  1318. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1319. transfusion_volume := c.GetString("transfusion_volume")
  1320. last_after_weight := c.GetString("last_after_weight")
  1321. displace_liqui_value := c.GetString("displace_liqui_value")
  1322. start_time := c.GetString("start_time")
  1323. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1324. if id <= 0 {
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. adminUserInfo := c.GetMobileAdminUserInfo()
  1329. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1330. if patient.ID == 0 {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1332. return
  1333. }
  1334. if len(recordDateStr) == 0 {
  1335. recordDateStr = time.Now().Format("2006-01-02")
  1336. }
  1337. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1338. fmt.Println("parseDateErr", parseDateErr)
  1339. if parseDateErr != nil {
  1340. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1342. return
  1343. }
  1344. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1345. //now := time.Now()
  1346. //year, month, day := now.Date()
  1347. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1348. //todayTimeStamp := today_time.Unix()
  1349. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1350. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1351. UserOrgId: adminUserInfo.Org.Id,
  1352. PatientId: id,
  1353. AssessmentDate: recordDate.Unix(),
  1354. Temperature: temperature,
  1355. PulseFrequency: pulse_frequency,
  1356. BreathingRate: breathing_rate,
  1357. SystolicBloodPressure: systolic_blood_pressure,
  1358. DiastolicBloodPressure: diastolic_blood_pressure,
  1359. ActualUltrafiltration: actual_ultrafiltration,
  1360. ActualDisplacement: actual_displacement,
  1361. ActualTreatmentHour: actualtreatHour,
  1362. ActualTreatmentMinute: actualtreatmin,
  1363. WeightAfter: weightAfter,
  1364. AdditionalWeight: additionalWeight,
  1365. WeightLoss: weightReduce,
  1366. Cruor: cruor,
  1367. SymptomAfterDialysis: symptomsAfterDialysi,
  1368. InternalFistula: internalFistula,
  1369. Catheter: catheter,
  1370. Complication: complications,
  1371. DialysisIntakes: dialysateVolume,
  1372. CreatedTime: time.Now().Unix(),
  1373. UpdatedTime: time.Now().Unix(),
  1374. Status: 1,
  1375. Remark: remark,
  1376. BloodAccessPartId: blood_access_part_id,
  1377. BloodAccessPartOperaId: blood_access_part_opera_id,
  1378. DialysisIntakesUnit: dialysis_intakes_unit,
  1379. PuncturePointOozingBlood: puncturePointOozingBlood,
  1380. PuncturePointHaematoma: puncturePointHaematoma,
  1381. InternalFistulaTremorAc: internalFistulaTremorAc,
  1382. PatientGose: patientGose,
  1383. InpatientDepartment: inpatientDepartment,
  1384. ObservationContent: observationContent,
  1385. ObservationContentOther: observationContentOther,
  1386. DialysisProcess: dialysis_process,
  1387. InAdvanceMinute: in_advance_minute,
  1388. InAdvanceReason: in_advance_reason,
  1389. HemostasisMinute: hemostasis_minute,
  1390. HemostasisOpera: hemostasis_opera,
  1391. TremorNoise: tremor_noise,
  1392. DisequilibriumSyndrome: disequilibrium_syndrome,
  1393. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1394. ArterialTube: arterial_tube,
  1395. IntravenousTube: intravenous_tube,
  1396. Dialyzer: dialyzer,
  1397. InAdvanceReasonOther: in_advance_reason_other,
  1398. IsEat: is_eat,
  1399. CvcA: cvc_a,
  1400. CvcV: cvc_v,
  1401. Channel: channels,
  1402. ReturnBlood: return_blood,
  1403. RehydrationVolume: rehydration_volume,
  1404. DialysisDuring: dialysis_during,
  1405. StrokeVolume: stroke_volume,
  1406. BloodFlow: blood_flow,
  1407. SealingFluidDispose: sealing_fluid_dispose,
  1408. SealingFluidSpecial: sealing_fluid_special,
  1409. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1410. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1411. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1412. SettingPressure: setting_pressure,
  1413. DiastolicPressure: diastolic_pressure,
  1414. OtherComplication: other_complication,
  1415. Ktv: ktv,
  1416. Urr: urr,
  1417. Hypopiesia: hypopiesia,
  1418. Hypertenison: hypertenison,
  1419. Lapse: lapse,
  1420. LeaveOfficeMethod: leave_office_method,
  1421. Consciousness: consciousness,
  1422. Fallrisk: fallrisk,
  1423. MachineRun: machine_run,
  1424. AfterUrea: after_urea,
  1425. PipCoagulation: pip_coagulation,
  1426. AccumulatedBloodVolume: accumulated_blood_volume,
  1427. TransfusionVolume: transfusion_volume,
  1428. LastAfterWeight: last_after_weight,
  1429. DisplaceLiquiValue: displace_liqui_value,
  1430. RecordTime: startDate.Unix(),
  1431. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1432. }
  1433. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1434. // 查询信息规挡的设置天数
  1435. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1436. if infor.ID > 0 && infor.WeekDay > 0 {
  1437. var cha_time int64
  1438. timeNowStr := time.Now().Format("2006-01-02")
  1439. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1440. //今日的日期减去设置的日期
  1441. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1442. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1443. if cha_time >= recordDate.Unix() {
  1444. //查询审核是否允许
  1445. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1446. //申请状态不允许的情况 拒绝修改
  1447. if infor.ApplicationStatus != 1 {
  1448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1449. return
  1450. }
  1451. }
  1452. }
  1453. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1454. if assessmentAfter.ID == 0 { //新增
  1455. if appRole.UserType == 2 || appRole.UserType == 1 {
  1456. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1457. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1458. } else {
  1459. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1460. }
  1461. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1462. if assessmentAfterDislysis.UserOrgId != 10340 {
  1463. if assessmentAfterDislysis.WeightAfter == 0 {
  1464. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1465. }
  1466. }
  1467. if adminUserInfo.Org.Id == 10693 {
  1468. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1471. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1472. }
  1473. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1481. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1482. }
  1483. if assessmentAfterDislysis.PulseFrequency == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1486. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1487. }
  1488. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1489. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1490. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1491. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1492. }
  1493. }
  1494. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1495. //记录日志
  1496. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1497. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1498. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1499. PatientId: assessmentAfterDislysis.PatientId,
  1500. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1501. Status: 1,
  1502. ErrLog: string(byterequest),
  1503. AdminUserId: adminUserInfo.AdminUser.Id,
  1504. Ctime: 0,
  1505. Mtime: 0,
  1506. Source: "手机端保存透后评估",
  1507. }
  1508. service.CreateAfterDialysisLog(afterDialysisLog)
  1509. finish := models.XtDialysisFinish{
  1510. IsFinish: 1,
  1511. UserOrgId: adminUserInfo.Org.Id,
  1512. Status: 1,
  1513. Ctime: time.Now().Unix(),
  1514. Mtime: 0,
  1515. Module: 9,
  1516. RecordDate: recordDate.Unix(),
  1517. Sourse: 1,
  1518. PatientId: id,
  1519. }
  1520. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1521. if dialysisFinish.ID == 0 {
  1522. service.CreateDialysisFinish(finish)
  1523. }
  1524. redis := service.RedisClient()
  1525. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1526. redis.Set(keyTwo, "", time.Second)
  1527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1528. //清空key 值
  1529. redis.Set(key, "", time.Second)
  1530. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1531. redis.Set(keyOne, "", time.Second)
  1532. defer redis.Close()
  1533. if err == nil {
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "assessmentAfterDislysis": assessmentAfterDislysis,
  1536. })
  1537. }
  1538. return
  1539. } else { //修改
  1540. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1541. if infor.ID > 0 && infor.WeekDay > 0 {
  1542. var cha_time int64
  1543. timeNowStr := time.Now().Format("2006-01-02")
  1544. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1545. //今日的日期减去设置的日期
  1546. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1547. if cha_time >= recordDate.Unix() {
  1548. //查询审核是否允许
  1549. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1550. //申请状态不允许的情况 拒绝修改
  1551. if infor.ApplicationStatus != 1 {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1553. return
  1554. }
  1555. }
  1556. }
  1557. if appRole.UserType == 2 || appRole.UserType == 1 {
  1558. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1559. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1560. } else {
  1561. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1562. if assessmentAfterDislysis.Creater == 0 {
  1563. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1564. }
  1565. }
  1566. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1567. assessmentAfterDislysis.ID = assessmentAfter.ID
  1568. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1569. if assessmentAfterDislysis.UserOrgId != 10340 {
  1570. if assessmentAfterDislysis.WeightAfter == 0 {
  1571. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1572. }
  1573. }
  1574. if adminUserInfo.Org.Id == 10693 {
  1575. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1578. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1579. }
  1580. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1588. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1589. }
  1590. if assessmentAfterDislysis.PulseFrequency == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1593. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1594. }
  1595. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1596. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1597. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1598. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1599. }
  1600. }
  1601. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1602. //记录日志
  1603. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1604. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1605. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1606. PatientId: assessmentAfterDislysis.PatientId,
  1607. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1608. Status: 1,
  1609. ErrLog: string(byterequest),
  1610. AdminUserId: adminUserInfo.AdminUser.Id,
  1611. Ctime: time.Now().Unix(),
  1612. Mtime: 0,
  1613. Source: "手机端修改保存透后评估",
  1614. }
  1615. service.CreateAfterDialysisLog(afterDialysisLog)
  1616. redis := service.RedisClient()
  1617. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1618. redis.Set(keyTwo, "", time.Second)
  1619. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1620. //清空key 值
  1621. redis.Set(key, "", time.Second)
  1622. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1623. redis.Set(keyOne, "", time.Second)
  1624. if err == nil {
  1625. c.ServeSuccessJSON(map[string]interface{}{
  1626. "assessmentAfterDislysis": assessmentAfterDislysis,
  1627. })
  1628. return
  1629. }
  1630. }
  1631. return
  1632. }
  1633. func (c *DialysisAPIController) PostDialysisPrescription() {
  1634. id, _ := c.GetInt64("patient", 0)
  1635. recordDateStr := c.GetString("record_date")
  1636. if id <= 0 {
  1637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. adminUserInfo := c.GetMobileAdminUserInfo()
  1641. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1642. if patient.ID == 0 {
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1644. return
  1645. }
  1646. if len(recordDateStr) == 0 {
  1647. recordDateStr = time.Now().Format("2006-01-02")
  1648. }
  1649. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1650. if parseDateErr != nil {
  1651. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. mode_id, _ := c.GetInt64("mode_id", 0)
  1656. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1657. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1658. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1659. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1660. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1661. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1662. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1663. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1664. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1665. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1666. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1667. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1668. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1669. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1670. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1671. kalium, _ := c.GetFloat("kalium", 0)
  1672. sodium, _ := c.GetFloat("sodium", 0)
  1673. calcium, _ := c.GetFloat("calcium", 0)
  1674. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1675. glucose, _ := c.GetFloat("glucose", 0)
  1676. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1677. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1678. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1679. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1680. conductivity, _ := c.GetFloat("conductivity", 0)
  1681. remark := c.GetString("remark")
  1682. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1683. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1684. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1685. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1686. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1687. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1688. special_medicine_other := c.GetString("special_medicine_other")
  1689. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1690. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1691. blood_access, _ := c.GetInt64("blood_access", 0)
  1692. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1693. body_fluid_other := c.GetString("body_fluid_other")
  1694. niprocart, _ := c.GetInt64("niprocart", 0)
  1695. jms, _ := c.GetInt64("jms", 0)
  1696. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1697. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1698. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1699. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1700. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1701. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1702. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1703. injector, _ := c.GetInt64("injector", 0)
  1704. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1705. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1706. safe_package, _ := c.GetInt64("package", 0)
  1707. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1708. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1709. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1710. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1711. blood := c.GetString("blood")
  1712. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1713. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1714. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1715. displace_speed := c.GetString("displace_speed")
  1716. illness, _ := c.GetInt64("illness")
  1717. amylaceum := c.GetString("amylaceum")
  1718. single_time := c.GetString("single_time")
  1719. single_water := c.GetString("single_water")
  1720. replacement_flow := c.GetString("replacement_flow")
  1721. plasma_separator := c.GetString("plasma_separator")
  1722. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1723. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1724. oxygen_flow := c.GetString("oxygen_flow")
  1725. oxygen_time := c.GetString("oxygen_time")
  1726. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1727. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1728. puncture_needle := c.GetString("puncture_needle")
  1729. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1730. epo := c.GetString("epo")
  1731. epo_count, _ := c.GetFloat("epo_count", 0)
  1732. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1733. admin_user_id, _ := c.GetInt64("admin_user_id")
  1734. is_water := c.GetString("is_water")
  1735. var is_war int64
  1736. if is_water == "是" {
  1737. is_war = 1
  1738. }
  1739. if is_water == "否" {
  1740. is_war = 2
  1741. }
  1742. if is_water == "请选择" {
  1743. is_war = 0
  1744. }
  1745. drhy_water := c.GetString("drhy_water")
  1746. dry_water_hour := c.GetString("dry_water_hour")
  1747. water_machine := c.GetString("water_machine")
  1748. add_amount, _ := c.GetFloat("add_amount")
  1749. reduce_amount, _ := c.GetFloat("reduce_amount")
  1750. dialysis_remark := c.GetString("dialysis_remark")
  1751. prescribing_number, _ := c.GetFloat("prescribing_number")
  1752. prescription_sodium := c.GetString("prescription_sodium")
  1753. start_sodium := c.GetString("start_sodium")
  1754. sodium_curve := c.GetString("sodium_curve")
  1755. treatment_remark := c.GetString("treatment_remark")
  1756. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1757. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1758. prescription_water, _ := c.GetFloat("prescription_water")
  1759. dialysis_strainer := c.GetString("dialysis_strainer")
  1760. chaptalization := c.GetString("chaptalization")
  1761. washing_time := c.GetString("washing_time")
  1762. warsh_count := c.GetString("warsh_count")
  1763. blood_access_part_id := c.GetString("blood_access_part_id")
  1764. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1765. dialyzate := c.GetString("dialyzate")
  1766. first_super := c.GetString("first_super")
  1767. var first_sup int64
  1768. if first_super == "是" {
  1769. first_sup = 1
  1770. }
  1771. if first_super == "否" {
  1772. first_sup = 2
  1773. }
  1774. if first_super == "请选择" {
  1775. first_sup = 0
  1776. }
  1777. is_sequential := c.GetString("is_sequential")
  1778. var is_sequent int64
  1779. if is_sequential == "是" {
  1780. is_sequent = 1
  1781. }
  1782. if is_sequential == "否" {
  1783. is_sequent = 2
  1784. }
  1785. if is_sequential == "请选择" {
  1786. is_sequent = 0
  1787. }
  1788. conduct := c.GetString("conduct")
  1789. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1790. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1791. //
  1792. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1793. // if appRole.UserType == 3 {
  1794. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1795. // if getPermissionErr != nil {
  1796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1797. // return
  1798. // } else if headNursePermission == nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1800. // return
  1801. // }
  1802. // }
  1803. //}
  1804. // 查询信息规挡的设置天数
  1805. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1806. if infor.ID > 0 && infor.WeekDay > 0 {
  1807. var cha_time int64
  1808. timeNowStr := time.Now().Format("2006-01-02")
  1809. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1810. //今日的日期减去设置的日期
  1811. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1812. if cha_time >= recordDate.Unix() {
  1813. //查询审核是否允许
  1814. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1815. //申请状态不允许的情况 拒绝修改
  1816. if infor.ApplicationStatus != 1 {
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. if mode_id > 0 {
  1823. var str string
  1824. //查找该机构用的是什么透析器
  1825. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1826. if filedConfig.ID > 0 {
  1827. str = dialyzerPerfusionApparatus
  1828. } else {
  1829. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1830. }
  1831. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1832. }
  1833. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1834. var dialysis_dialyszers_id int64
  1835. var dialysis_strainer_id int64
  1836. var dialysis_irrigation_id int64
  1837. if len(goodList) > 0 {
  1838. for _, item := range goodList {
  1839. if item.SpecificationName == dialysis_dialyszers {
  1840. dialysis_dialyszers_id = item.ID
  1841. }
  1842. if item.SpecificationName == dialysis_irrigation {
  1843. dialysis_irrigation_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_strainer {
  1846. dialysis_strainer_id = item.ID
  1847. }
  1848. }
  1849. }
  1850. //TODO 需要根据角色去判断
  1851. prescription := models.DialysisPrescription{
  1852. UserOrgId: adminUserInfo.Org.Id,
  1853. PatientId: id,
  1854. RecordDate: recordDate.Unix(),
  1855. ModeId: mode_id,
  1856. DialysisDuration: dialysis_duration,
  1857. Dialyzer: dialyzer,
  1858. PerfusionApparatus: perfusion_apparatus,
  1859. BloodFlowVolume: blood_flow_volume,
  1860. DewaterAmount: dewater_amount,
  1861. DisplaceLiqui: displace_liqui,
  1862. ReplacementWay: replacement_way,
  1863. Anticoagulant: anticoagulant,
  1864. AnticoagulantShouji: anticoagulant_shouji,
  1865. AnticoagulantWeichi: anticoagulant_weichi,
  1866. AnticoagulantZongliang: anticoagulant_zongliang,
  1867. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1868. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1869. Kalium: kalium,
  1870. Sodium: sodium,
  1871. Calcium: calcium,
  1872. Bicarbonate: bicarbonate,
  1873. Glucose: glucose,
  1874. // DryWeight: dry_weight,
  1875. DialysateFlow: dialysate_flow,
  1876. DialysateTemperature: dialysate_temperature,
  1877. // PrescriptionDoctor: prescription_doctor,
  1878. ReplacementTotal: replacement_total,
  1879. Conductivity: conductivity,
  1880. Remark: remark,
  1881. Status: 1,
  1882. CreatedTime: time.Now().Unix(),
  1883. UpdatedTime: time.Now().Unix(),
  1884. DialysisDurationMinute: dialysisDurationMinute,
  1885. DialysisDurationHour: dialysisDurationHour,
  1886. TargetUltrafiltration: targetUltrafiltration,
  1887. DialysateFormulation: dialysateFormulation,
  1888. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1889. BodyFluid: body_fluid,
  1890. SpecialMedicine: special_medicine,
  1891. SpecialMedicineOther: special_medicine_other,
  1892. DisplaceLiquiPart: displace_liqui_part,
  1893. DisplaceLiquiValue: displace_liqui_value,
  1894. BloodAccess: blood_access,
  1895. Ultrafiltration: ultrafiltration,
  1896. BodyFluidOther: body_fluid_other,
  1897. Niprocart: niprocart,
  1898. Jms: jms,
  1899. FistulaNeedleSet: fistula_needle_set,
  1900. FistulaNeedleSet16: fistula_needle_set_16,
  1901. Hemoperfusion: hemoperfusion,
  1902. DialyserSterilised: dialyser_sterilised,
  1903. Filtryzer: filtryzer,
  1904. Dialyzers: dialyzers,
  1905. Injector: injector,
  1906. Bloodlines: bloodlines,
  1907. TubingHemodialysis: tubing_hemodialysis,
  1908. Package: safe_package,
  1909. ALiquid: a_liquid,
  1910. TargetKtv: target_ktv,
  1911. PreImpulse: pre_impulse,
  1912. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1913. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1914. Blood: blood,
  1915. DialysisDialyszers: dialysis_dialyszers,
  1916. DialysisIrrigation: dialysis_irrigation,
  1917. AntioxidantCommodityName: antioxidant_commodity_name,
  1918. DisplaceSpeed: displace_speed,
  1919. Illness: illness,
  1920. Amylaceum: amylaceum,
  1921. SingleTime: single_time,
  1922. SingleWater: single_water,
  1923. ReplacementFlow: replacement_flow,
  1924. PlasmaSeparator: plasma_separator,
  1925. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1926. OxygenUptake: oxygen_uptake,
  1927. OxygenFlow: oxygen_flow,
  1928. OxygenTime: oxygen_time,
  1929. HemodialysisPipelines: hemodialysis_pipelines,
  1930. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1931. PunctureNeedle: puncture_needle,
  1932. PunctureNeedleCount: puncture_needle_count,
  1933. Epo: epo,
  1934. EpoCount: epo_count,
  1935. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1936. AdminUserId: admin_user_id,
  1937. IsWater: is_war,
  1938. DrhyWater: drhy_water,
  1939. DryWaterHour: dry_water_hour,
  1940. WaterMachine: water_machine,
  1941. AddAmount: add_amount,
  1942. ReduceAmount: reduce_amount,
  1943. DialysisRemark: dialysis_remark,
  1944. PrescribingNumber: prescribing_number,
  1945. StartSodium: start_sodium,
  1946. SodiumCurve: sodium_curve,
  1947. TreatmentRemark: treatment_remark,
  1948. PrescriptionSodium: prescription_sodium,
  1949. DialysisFluidFlow: dialysis_fluid_flow,
  1950. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1951. PrescriptionWater: prescription_water,
  1952. DialysisStrainer: dialysis_strainer,
  1953. Chaptalization: chaptalization,
  1954. WashingTime: washing_time,
  1955. WarshCount: warsh_count,
  1956. BloodAccessPartId: blood_access_part_id,
  1957. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1958. Dialyzate: dialyzate,
  1959. DialysisDialyszersId: dialysis_dialyszers_id,
  1960. DialysisIrrigationId: dialysis_irrigation_id,
  1961. DialysisStrainerId: dialysis_strainer_id,
  1962. FirstSuper: first_sup,
  1963. IsSequential: is_sequent,
  1964. Conduct: conduct,
  1965. }
  1966. if adminUserInfo.Org.Id == 10721 {
  1967. if prescription.ModeId == 2 {
  1968. if prescription.ReplacementTotal == 0 {
  1969. prescription.ReplacementTotal = 15
  1970. }
  1971. }
  1972. }
  1973. //查询最近透析准备表里是否存在 透析器 灌流器
  1974. //
  1975. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1976. //
  1977. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1978. //
  1979. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1980. //if len(mation)>0{
  1981. // for _, item := range splitStr {
  1982. // for _,it := range mation{
  1983. // if(item == it.SpecificationName){
  1984. //
  1985. // //查询最近一次的透析器
  1986. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1987. //
  1988. // if errcode == gorm.ErrRecordNotFound{
  1989. // //插入数据
  1990. // prepare := models.DialysisBeforePrepare{
  1991. // UserOrgId: adminUserInfo.Org.Id,
  1992. // PatientId: id,
  1993. // RecordDate: recordDate.Unix(),
  1994. // GoodTypeId: it.GoodTypeId,
  1995. // GoodId: it.ID,
  1996. // Count: 1,
  1997. // Ctime: time.Now().Unix(),
  1998. // Creater: adminUserInfo.AdminUser.Id,
  1999. // Status:1,
  2000. //
  2001. // }
  2002. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2003. // fmt.Println("",errcode)
  2004. // }
  2005. // }
  2006. // }
  2007. //
  2008. // }
  2009. //
  2010. // for _, item := range splitIrrigation {
  2011. // for _,it := range mation{
  2012. // if(item == it.SpecificationName){
  2013. // //查询最近一次的透析器
  2014. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2015. // if errcode == gorm.ErrRecordNotFound{
  2016. // //插入数据
  2017. // prepare := models.DialysisBeforePrepare{
  2018. // UserOrgId: adminUserInfo.Org.Id,
  2019. // PatientId: id,
  2020. // RecordDate: recordDate.Unix(),
  2021. // GoodTypeId: it.GoodTypeId,
  2022. // GoodId: it.ID,
  2023. // Count: 1,
  2024. // Ctime: time.Now().Unix(),
  2025. // Creater: adminUserInfo.AdminUser.Id,
  2026. // Status:1,
  2027. //
  2028. // }
  2029. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2030. // fmt.Println(errcode)
  2031. // }
  2032. // }
  2033. // }
  2034. // }
  2035. //}
  2036. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2037. if dialysisPrescription.ID == 0 { //新增
  2038. if appRole.UserType == 2 || appRole.UserType == 1 {
  2039. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2040. }
  2041. prescription.Creater = adminUserInfo.AdminUser.Id
  2042. //针对河间咸得
  2043. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2044. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2045. prescription.DisplaceLiquiPart = 0
  2046. prescription.DisplaceLiquiValue = 0
  2047. }
  2048. }
  2049. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2050. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2051. }
  2052. err := service.AddSigleRecord(&prescription)
  2053. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2054. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2055. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2056. if len(monitorList) > 0 {
  2057. var ultrafiltration_rate float64
  2058. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2059. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2060. var replacement_rate float64
  2061. //乘10 除10是为了保留一位小数
  2062. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2063. var firstOpeateTime = monitorList[0].OperateTime
  2064. for _, item := range monitorList {
  2065. //超滤率
  2066. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2067. //置换率
  2068. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2069. //超滤量
  2070. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2071. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2072. //置换量
  2073. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2074. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2075. }
  2076. }
  2077. }
  2078. //记录日志
  2079. byterequest, _ := json.Marshal(prescription)
  2080. prescriptionLog := models.XtDialysisPrescriptionLog{
  2081. UserOrgId: prescription.UserOrgId,
  2082. Ctime: time.Now().Unix(),
  2083. Mtime: 0,
  2084. ErrLog: string(byterequest),
  2085. AdminUserId: adminUserInfo.AdminUser.Id,
  2086. RecordDate: prescription.RecordDate,
  2087. PatientId: prescription.PatientId,
  2088. Source: "手机端新增保存处方",
  2089. Status: 1,
  2090. }
  2091. service.CreatePrescriptionLog(prescriptionLog)
  2092. finish := models.XtDialysisFinish{
  2093. IsFinish: 1,
  2094. UserOrgId: adminUserInfo.Org.Id,
  2095. Status: 1,
  2096. Ctime: time.Now().Unix(),
  2097. Mtime: 0,
  2098. Module: 1,
  2099. RecordDate: recordDate.Unix(),
  2100. Sourse: 1,
  2101. PatientId: id,
  2102. }
  2103. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2104. if dialysisFinish.ID == 0 {
  2105. service.CreateDialysisFinish(finish)
  2106. }
  2107. //长沙南雅医院,自动生成抗凝剂的临时处方
  2108. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2109. if prescribing_number == 0 {
  2110. prescribing_number = 1
  2111. }
  2112. if prescribing_number == 0 && id == 14682 {
  2113. prescribing_number = 2
  2114. }
  2115. if prescribing_number == 0 && id == 18560 {
  2116. prescribing_number = 2
  2117. }
  2118. advice := models.DoctorAdvice{
  2119. UserOrgId: adminUserInfo.Org.Id,
  2120. PatientId: id,
  2121. GroupNo: 0,
  2122. AdviceType: 2,
  2123. RecordDate: recordDate.Unix(),
  2124. AdviceDate: recordDate.Unix(),
  2125. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2126. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2127. AdviceDesc: "",
  2128. ReminderDate: 0,
  2129. SingleDose: anticoagulant_zongliang,
  2130. SingleDoseUnit: "iu",
  2131. DrugSpec: 0,
  2132. DrugSpecUnit: "",
  2133. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2134. PrescribingNumberUnit: "支",
  2135. DeliveryWay: "静脉注射",
  2136. ExecutionFrequency: "上机前",
  2137. AdviceDoctor: 0,
  2138. Status: 1,
  2139. CreatedTime: time.Now().Unix(),
  2140. UpdatedTime: time.Now().Unix(),
  2141. IsPrescription: 1,
  2142. ExecutionState: 2,
  2143. StopState: 2,
  2144. IsSettle: 2,
  2145. }
  2146. // 查询排班信息
  2147. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2148. if schedulePatient.ID > 0 {
  2149. if schedulePatient.ScheduleType == 1 {
  2150. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2151. }
  2152. if schedulePatient.ScheduleType == 2 {
  2153. advice.StartTime = recordDate.Unix() + 9*60*60
  2154. }
  2155. }
  2156. // 抗凝剂名称
  2157. switch anticoagulant {
  2158. case 1:
  2159. advice.AdviceName = "无肝素"
  2160. break
  2161. case 2:
  2162. advice.AdviceName = "普通肝素"
  2163. break
  2164. case 3:
  2165. advice.AdviceName = "低分子肝素"
  2166. break
  2167. case 4:
  2168. advice.AdviceName = "阿加曲班"
  2169. break
  2170. case 5:
  2171. advice.AdviceName = "枸橼酸钠"
  2172. break
  2173. case 6:
  2174. advice.AdviceName = "低分子肝素钙"
  2175. break
  2176. case 7:
  2177. advice.AdviceName = "低分子肝素钠"
  2178. break
  2179. case 8:
  2180. advice.AdviceName = "依诺肝素"
  2181. break
  2182. case 9:
  2183. advice.AdviceName = "达肝素"
  2184. break
  2185. case 10:
  2186. advice.AdviceName = "体外抗凝"
  2187. break
  2188. case 11:
  2189. advice.AdviceName = "那曲肝素"
  2190. break
  2191. case 12:
  2192. advice.AdviceName = "无抗凝剂"
  2193. break
  2194. }
  2195. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2196. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2197. advice.AdviceDoctor = appRole.AdminUserId
  2198. }
  2199. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2200. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2201. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2202. advice.AdviceName = "低分子肝素钠注射液"
  2203. // 修改患者临时医嘱里的抗凝剂医嘱
  2204. advice.ID = advicePrescription.ID
  2205. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2206. } else {
  2207. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2208. advice.AdviceName = "低分子肝素钠注射液"
  2209. // 新增患者临时医嘱里的抗凝剂医嘱
  2210. service.CreateDoctorAdvice(&advice)
  2211. }
  2212. }
  2213. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2214. redis := service.RedisClient()
  2215. defer redis.Close()
  2216. //清空key 值
  2217. redis.Set(key, "", time.Second)
  2218. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2219. redis.Set(keyOne, "", time.Second)
  2220. }
  2221. //获取key,清空redis
  2222. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2223. redis := service.RedisClient()
  2224. //清空key 值
  2225. redis.Set(key, "", time.Second)
  2226. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2227. //清空key 值
  2228. redis.Set(keyOne, "", time.Second)
  2229. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2230. //清空key 值
  2231. redis.Set(keyTwo, "", time.Second)
  2232. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2233. redis.Set(keySix, "", time.Second)
  2234. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2235. redis.Set(keySeven, "", time.Second)
  2236. if err == nil {
  2237. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2238. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2239. //清空key 值
  2240. redis.Set(keyThree, "", time.Second)
  2241. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2242. //清空key 值
  2243. redis.Set(keyFour, "", time.Second)
  2244. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2245. redis.Set(keyFive, "", time.Second)
  2246. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2247. redis.Set(keySix, "", time.Second)
  2248. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2249. redis.Set(keySeven, "", time.Second)
  2250. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2251. //清空key 值
  2252. redis.Set(keyOne, "", time.Second)
  2253. if updateErr != nil {
  2254. utils.ErrorLog("%v", updateErr)
  2255. }
  2256. defer redis.Close()
  2257. c.ServeSuccessJSON(map[string]interface{}{
  2258. "prescription": prescription,
  2259. })
  2260. }
  2261. } else { //修改
  2262. //if mode_id > 0 {
  2263. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2264. //}
  2265. //if template.TemplateId == 1 {
  2266. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2267. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2268. // if getPermissionErr != nil {
  2269. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2270. // return
  2271. // } else if headNursePermission == nil {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2273. // return
  2274. // }
  2275. // }
  2276. //}
  2277. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2278. prescription.Modifier = adminUserInfo.AdminUser.Id
  2279. if appRole.UserType == 2 || appRole.UserType == 1 {
  2280. prescription_doctor := adminUserInfo.AdminUser.Id
  2281. prescription.PrescriptionDoctor = prescription_doctor
  2282. } else {
  2283. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2284. }
  2285. if dialysisPrescription.Creater == 0 { //体重称
  2286. prescription.Creater = adminUserInfo.AdminUser.Id
  2287. } else {
  2288. prescription.Creater = dialysisPrescription.Creater
  2289. if adminUserInfo.Org.Id == 9882 {
  2290. if appRole.UserType == 2 || appRole.UserType == 1 {
  2291. prescription_doctor := adminUserInfo.AdminUser.Id
  2292. prescription.PrescriptionDoctor = prescription_doctor
  2293. prescription.Creater = prescription_doctor
  2294. }
  2295. }
  2296. }
  2297. prescription.ID = dialysisPrescription.ID
  2298. if adminUserInfo.Org.Id == 10721 {
  2299. if prescription.ModeId == 2 {
  2300. if prescription.ReplacementTotal == 0 {
  2301. prescription.ReplacementTotal = 15
  2302. }
  2303. }
  2304. }
  2305. service.UpDateDialysisPrescription(&prescription)
  2306. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2307. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2308. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2309. if len(monitorList) > 0 {
  2310. var ultrafiltration_rate float64
  2311. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2312. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2313. var replacement_rate float64
  2314. //乘10 除10是为了保留一位小数
  2315. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2316. var firstOpeateTime = monitorList[0].OperateTime
  2317. for _, item := range monitorList {
  2318. //超滤率
  2319. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2320. //置换率
  2321. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2322. //超滤量
  2323. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2324. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2325. //置换量
  2326. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2327. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2328. }
  2329. }
  2330. }
  2331. //记录日志
  2332. byterequest, _ := json.Marshal(prescription)
  2333. prescriptionLog := models.XtDialysisPrescriptionLog{
  2334. UserOrgId: prescription.UserOrgId,
  2335. Ctime: time.Now().Unix(),
  2336. Mtime: 0,
  2337. ErrLog: string(byterequest),
  2338. AdminUserId: adminUserInfo.AdminUser.Id,
  2339. RecordDate: prescription.RecordDate,
  2340. PatientId: prescription.PatientId,
  2341. Source: "手机端修改处方",
  2342. Status: 1,
  2343. }
  2344. service.CreatePrescriptionLog(prescriptionLog)
  2345. finish := models.XtDialysisFinish{
  2346. IsFinish: 1,
  2347. UserOrgId: adminUserInfo.Org.Id,
  2348. Status: 1,
  2349. Ctime: time.Now().Unix(),
  2350. Mtime: 0,
  2351. Module: 1,
  2352. RecordDate: recordDate.Unix(),
  2353. Sourse: 1,
  2354. PatientId: id,
  2355. }
  2356. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2357. if dialysisFinish.ID == 0 {
  2358. service.CreateDialysisFinish(finish)
  2359. }
  2360. //修改处方
  2361. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2362. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2363. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2364. if advicePrescription.ID > 0 {
  2365. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2366. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2367. redis := service.RedisClient()
  2368. defer redis.Close()
  2369. //清空key 值
  2370. redis.Set(key, "", time.Second)
  2371. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2372. redis.Set(keyOne, "", time.Second)
  2373. }
  2374. }
  2375. //获取key,清空redis
  2376. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2377. redis := service.RedisClient()
  2378. //清空key 值
  2379. redis.Set(key, "", time.Second)
  2380. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2381. //清空key 值
  2382. redis.Set(keyOne, "", time.Second)
  2383. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2384. redis.Set(keySix, "", time.Second)
  2385. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2386. redis.Set(keySeven, "", time.Second)
  2387. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2388. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2389. //清空key 值
  2390. redis.Set(keyTwoOne, "", time.Second)
  2391. defer redis.Close()
  2392. if updateErr != nil {
  2393. utils.ErrorLog("%v", updateErr)
  2394. }
  2395. c.ServeSuccessJSON(map[string]interface{}{
  2396. "prescription": prescription,
  2397. })
  2398. }
  2399. }
  2400. func (c *DialysisAPIController) Finish() {
  2401. id, _ := c.GetInt64("patient", 0)
  2402. recordDateStr := c.GetString("record_date")
  2403. nurseID, _ := c.GetInt64("nurse")
  2404. end_time := c.GetString("end_time")
  2405. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2406. internal_fistula := c.GetString("blood_access_internal_fistula")
  2407. catheter := c.GetString("catheter")
  2408. cruor := c.GetString("cruor")
  2409. mission := c.GetString("mission")
  2410. condenser := c.GetString("condenser")
  2411. if id <= 0 || nurseID <= 0 {
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. adminUserInfo := c.GetMobileAdminUserInfo()
  2416. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2417. if patient.ID == 0 {
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2419. return
  2420. }
  2421. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2422. if getNurseErr != nil {
  2423. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. } else if nurse == nil {
  2427. c.ErrorLog("护士不存在")
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2429. return
  2430. }
  2431. if len(recordDateStr) == 0 {
  2432. recordDateStr = time.Now().Format("2006-01-02")
  2433. }
  2434. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2435. if parseDateErr != nil {
  2436. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2438. return
  2439. }
  2440. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2441. if parseEndDateErr != nil {
  2442. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2444. return
  2445. }
  2446. // 查询信息规挡的设置天数
  2447. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2448. if infor.ID > 0 && infor.WeekDay > 0 {
  2449. var cha_time int64
  2450. timeNowStr := time.Now().Format("2006-01-02")
  2451. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2452. //今日的日期减去设置的日期
  2453. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2454. if cha_time >= recordDate.Unix() {
  2455. //查询审核是否允许
  2456. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2457. //申请状态不允许的情况 拒绝修改
  2458. if infor.ApplicationStatus != 1 {
  2459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2460. return
  2461. }
  2462. }
  2463. }
  2464. //now := time.Now()
  2465. //year, month, day := now.Date()
  2466. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2467. //todayTimeStamp := today_time.Unix()
  2468. // 获取当天的第一条透析纪录
  2469. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2470. if getMonitorRecordsErr != nil {
  2471. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. }
  2475. // 获取当前的最后一条透析纪录
  2476. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. if getMonitorRecordsErr != nil {
  2478. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2480. return
  2481. }
  2482. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2483. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2484. if getAADErr != nil {
  2485. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2487. return
  2488. }
  2489. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2490. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2491. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2492. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2493. if assessmentAfterDislysis != nil {
  2494. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2495. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2496. } else {
  2497. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2498. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2499. tempassessmentAfterDislysis.Status = 1
  2500. tempassessmentAfterDislysis.PatientId = id
  2501. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2502. }
  2503. //长沙南雅
  2504. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2505. //获取最后一条透析处方数据
  2506. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2507. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2508. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2509. }
  2510. if dialysisOrder.Stage == 1 {
  2511. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2512. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2513. fmt.Println(value)
  2514. a, b := math.Modf(value)
  2515. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2516. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2517. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2518. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2519. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2520. }
  2521. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2522. //var num1 int64
  2523. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2524. //fmt.Println(num1)
  2525. //sub := float64(num1 / 3600)
  2526. //fmt.Println(sub)
  2527. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2528. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2529. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2530. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2531. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2532. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2533. if adminUserInfo.Org.Id != 10375 {
  2534. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2535. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2536. }
  2537. if adminUserInfo.Org.Id != 10445 {
  2538. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2539. }
  2540. //北方营口医院
  2541. if adminUserInfo.Org.Id == 10445 {
  2542. //获取最后一条透析处方数据
  2543. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2544. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2545. } else {
  2546. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2547. }
  2548. //新化博翔
  2549. if adminUserInfo.Org.Id == 10447 {
  2550. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2551. }
  2552. //阳春
  2553. if adminUserInfo.Org.Id == 10485 {
  2554. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2555. }
  2556. if adminUserInfo.Org.Id == 10551 {
  2557. //获取最后一条透析处方数据
  2558. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2559. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2560. }
  2561. if adminUserInfo.Org.Id == 10580 {
  2562. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2563. }
  2564. if adminUserInfo.Org.Id == 10612 {
  2565. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2566. }
  2567. //孝康
  2568. if adminUserInfo.Org.Id == 10693 {
  2569. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2571. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2572. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2573. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2574. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2575. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2576. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2577. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2578. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2579. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2580. }
  2581. if adminUserInfo.Org.Id == 10721 {
  2582. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2583. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2584. }
  2585. if adminUserInfo.Org.Id == 10697 {
  2586. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2587. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2588. lastWeightAfter.LastAfterWeight = floatAfeter
  2589. }
  2590. if adminUserInfo.Org.Id == 10624 {
  2591. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2592. }
  2593. }
  2594. 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 || adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10735 {
  2595. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2596. if adminUserInfo.Org.Id != 10702 {
  2597. if evaluation.SystolicBloodPressure == 0 {
  2598. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2599. if adminUserInfo.Org.Id == 10693 {
  2600. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2601. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2602. }
  2603. pre := models.PredialysisEvaluation{
  2604. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2605. }
  2606. fmt.Println("prew", pre)
  2607. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2608. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2609. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2610. redis := service.RedisClient()
  2611. redis.Set(key, "", time.Second)
  2612. redis.Set(keyOne, "", time.Second)
  2613. defer redis.Close()
  2614. fmt.Println(getNurseErr)
  2615. }
  2616. }
  2617. if adminUserInfo.Org.Id != 10702 {
  2618. if evaluation.DiastolicBloodPressure == 0 {
  2619. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2620. if adminUserInfo.Org.Id == 10693 {
  2621. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2622. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2623. }
  2624. pres := models.PredialysisEvaluation{
  2625. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2626. }
  2627. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2628. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2629. redis := service.RedisClient()
  2630. redis.Set(key, "", time.Second)
  2631. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2632. redis.Set(keyOne, "", time.Second)
  2633. defer redis.Close()
  2634. fmt.Println(getNurseErr)
  2635. }
  2636. }
  2637. if adminUserInfo.Org.Id != 10702 {
  2638. if evaluation.PulseFrequency == 0 {
  2639. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2640. if adminUserInfo.Org.Id == 10693 {
  2641. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2642. evaluation.PulseFrequency = pulseFrequency
  2643. }
  2644. press := models.PredialysisEvaluation{
  2645. PulseFrequency: evaluation.PulseFrequency,
  2646. }
  2647. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2648. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2649. redis := service.RedisClient()
  2650. redis.Set(key, "", time.Second)
  2651. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2652. redis.Set(keyOne, "", time.Second)
  2653. defer redis.Close()
  2654. fmt.Println(getNurseErr)
  2655. }
  2656. }
  2657. if evaluation.Temperature == 0 {
  2658. evaluation.Temperature = fmonitorRecords.Temperature
  2659. press := models.PredialysisEvaluation{
  2660. Temperature: evaluation.Temperature,
  2661. }
  2662. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2663. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2664. redis := service.RedisClient()
  2665. redis.Set(key, "", time.Second)
  2666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2667. redis.Set(keyOne, "", time.Second)
  2668. defer redis.Close()
  2669. fmt.Println(getNurseErr)
  2670. }
  2671. }
  2672. if adminUserInfo.Org.Id == 9583 {
  2673. //获取透析处方的最后一条数据
  2674. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2675. if diaerr != nil {
  2676. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2678. return
  2679. }
  2680. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2681. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2682. }
  2683. }
  2684. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2685. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2686. }
  2687. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2688. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2689. }
  2690. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2691. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2692. }
  2693. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2694. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2695. }
  2696. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2697. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2698. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2699. }
  2700. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2701. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2702. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2703. }
  2704. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2705. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2706. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2707. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2708. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2709. }
  2710. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2711. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2712. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2713. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2714. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2715. }
  2716. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2717. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2718. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2719. }
  2720. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2721. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2722. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2723. }
  2724. if lastAssessmentAfterDislysis != nil {
  2725. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2726. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2727. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2728. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2729. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2730. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2731. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2732. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2733. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2734. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2735. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2736. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2737. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2738. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2739. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2740. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2741. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2742. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2743. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2744. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2745. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2746. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2747. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2748. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2749. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2750. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2751. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2752. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2753. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2754. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2755. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2756. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2757. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2758. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2759. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2760. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2761. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2762. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2763. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2764. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2765. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2766. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2767. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2768. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2769. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2770. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2771. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2772. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2773. if tempassessmentAfterDislysis.PatientId == 18695 {
  2774. tempassessmentAfterDislysis.ActualDisplacement = 0
  2775. }
  2776. if adminUserInfo.Org.Id != 10375 {
  2777. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2778. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2779. }
  2780. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2781. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2782. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2783. }
  2784. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2785. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2786. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2787. }
  2788. }
  2789. finish := models.XtDialysisFinish{
  2790. IsFinish: 1,
  2791. UserOrgId: adminUserInfo.Org.Id,
  2792. Status: 1,
  2793. Ctime: time.Now().Unix(),
  2794. Mtime: 0,
  2795. Module: 9,
  2796. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2797. Sourse: 1,
  2798. PatientId: tempassessmentAfterDislysis.PatientId,
  2799. }
  2800. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2801. if dialysisFinish.ID == 0 {
  2802. service.CreateDialysisFinish(finish)
  2803. }
  2804. //孝康
  2805. if adminUserInfo.Org.Id == 10693 {
  2806. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2807. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2808. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2809. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2810. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2811. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2812. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2813. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2814. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2815. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2816. }
  2817. if adminUserInfo.Org.Id == 10697 {
  2818. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2819. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2820. lastWeightAfter.LastAfterWeight = floatAfeter
  2821. }
  2822. if adminUserInfo.Org.Id == 10721 {
  2823. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2824. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2825. }
  2826. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2827. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2828. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2829. redis := service.RedisClient()
  2830. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2831. redis.Set(keyOne, "", time.Second)
  2832. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2833. redis.Set(keyTwo, "", time.Second)
  2834. defer redis.Close()
  2835. //清空key 值
  2836. redis.Set(key, "", time.Second)
  2837. if err != nil {
  2838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2839. return
  2840. }
  2841. if dialysisOrder == nil {
  2842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2843. return
  2844. }
  2845. if dialysisOrder.Stage == 2 {
  2846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2847. return
  2848. }
  2849. if dialysisOrder.Stage == 1 {
  2850. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2851. finish := models.XtDialysisFinish{
  2852. IsFinish: 1,
  2853. UserOrgId: adminUserInfo.Org.Id,
  2854. Status: 1,
  2855. Ctime: time.Now().Unix(),
  2856. Mtime: 0,
  2857. Module: 8,
  2858. RecordDate: recordDate.Unix(),
  2859. Sourse: 1,
  2860. PatientId: id,
  2861. }
  2862. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2863. if dialysisFinish.ID == 0 {
  2864. service.CreateDialysisFinish(finish)
  2865. }
  2866. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2867. redis := service.RedisClient()
  2868. defer redis.Close()
  2869. //清空key 值
  2870. redis.Set(key, "", time.Second)
  2871. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2872. redis.Set(keyOne, "", time.Second)
  2873. //结束时候透析次数加1
  2874. service.UpdateSolutionByPatientId(id)
  2875. //下机完自动消毒,针对长沙南雅
  2876. if dialysisOrder.Stage == 1 {
  2877. 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 {
  2878. //根据床位号获取设备型号
  2879. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2880. //查询使用消毒最后一条消毒记录
  2881. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2882. fmt.Println("err", err)
  2883. if err == gorm.ErrRecordNotFound {
  2884. //查找排班
  2885. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2886. //查询改设备是否有消毒计划
  2887. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2888. //根据床位号获取设备id
  2889. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2890. //查询病人信息
  2891. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2892. var con = ""
  2893. if patients.IsInfectious == 0 {
  2894. con = ""
  2895. }
  2896. if patients.IsInfectious == 1 {
  2897. con = "无"
  2898. }
  2899. if patients.IsInfectious == 2 {
  2900. con = "有"
  2901. }
  2902. if errcode == nil {
  2903. var end_time int64
  2904. end_time = endDate.Unix() + plan.DisinfecTime*60
  2905. //新增消毒
  2906. information := models.DeviceInformation{
  2907. Date: dialysisOrder.DialysisDate,
  2908. Zone: dialysisOrder.ZoneId,
  2909. Class: dialysisOrder.SchedualType,
  2910. BedNumber: dialysisOrder.BedID,
  2911. PatientId: dialysisOrder.PatientId,
  2912. DialysisMode: scheduleByPatient.ModeId,
  2913. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2914. Disinfection: 1,
  2915. DialysisConcentration: 1,
  2916. DisinfectionStatus: 1,
  2917. Move: 1,
  2918. UserOrgId: dialysisOrder.UserOrgId,
  2919. DisinfectType: plan.Way,
  2920. DisinfectantType: plan.MachineDisinfectant,
  2921. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2922. Disinfectant: plan.Disinfectant,
  2923. Ctime: time.Now().Unix(),
  2924. Status: 1,
  2925. SignName: nurseID,
  2926. EquimentId: addmacher.ID,
  2927. DisinfectionResidue: 2,
  2928. Bed: addmacher.BedNumber,
  2929. StartTime: dialysisOrder.StartTime,
  2930. EndTime: dialysisOrder.EndTime,
  2931. Contagion: con,
  2932. WeightLoss: 0,
  2933. Hyperfiltratio: 0,
  2934. DialysisHour: "",
  2935. MachineRun: 1,
  2936. DisinfecStartime: endDate.Unix(),
  2937. DisinfecEndtime: end_time,
  2938. }
  2939. err := service.CreateInformationTwo(&information)
  2940. fmt.Println("报错", err)
  2941. }
  2942. }
  2943. }
  2944. }
  2945. dialysisOrder.Stage = 2
  2946. dialysisOrder.FinishNurse = nurseID
  2947. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2948. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2949. dialysisOrder.EndTime = endDate.Unix()
  2950. // 长沙南雅需求
  2951. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2952. //获取最后1条监测的数据
  2953. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2954. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2955. var accumulatedBloodVolume float64
  2956. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2957. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2958. fmt.Println(err)
  2959. // 查询未执行的医嘱
  2960. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2961. for _, item := range doctorAdvice {
  2962. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2963. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2964. redis := service.RedisClient()
  2965. //清空key 值
  2966. redis.Set(key, "", time.Second)
  2967. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2968. redis.Set(keyTwo, "", time.Second)
  2969. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2970. redis.Set(keyThree, "", time.Second)
  2971. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2972. theTime := toTime.Format("2006-01-02")
  2973. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2974. redis.Set(keyFour, "", time.Second)
  2975. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2976. redis.Set(keyFive, "", time.Second)
  2977. defer redis.Close()
  2978. }
  2979. }
  2980. go func() {
  2981. ssoDomain := beego.AppConfig.String("call_domain")
  2982. api := ssoDomain + "/index/downpatient"
  2983. values := make(url.Values)
  2984. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2985. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2986. values.Set("patient_id", strconv.FormatInt(id, 10))
  2987. http.PostForm(api, values)
  2988. }()
  2989. if err == nil {
  2990. c.ServeSuccessJSON(map[string]interface{}{
  2991. "dialysisOrder": dialysisOrder,
  2992. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2993. })
  2994. } else {
  2995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2996. }
  2997. }
  2998. }
  2999. func (c *DialysisAPIController) GetAllZone() {
  3000. adminUserInfo := c.GetMobileAdminUserInfo()
  3001. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3002. if err == nil {
  3003. c.ServeSuccessJSON(map[string]interface{}{
  3004. "zone": zone,
  3005. })
  3006. }
  3007. }
  3008. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3009. adminUserInfo := c.GetMobileAdminUserInfo()
  3010. page, _ := c.GetInt64("page", 1)
  3011. limit, _ := c.GetInt64("limit", 10)
  3012. schedulType, _ := c.GetInt64("schedul_type", 0)
  3013. startTime, _ := c.GetInt64("schedul_time", 0)
  3014. partitionType, _ := c.GetInt64("partition_type", 0)
  3015. keywords := c.GetString("keywords")
  3016. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3017. if err == nil {
  3018. c.ServeSuccessJSON(map[string]interface{}{
  3019. "schedule": dialysisSchedule,
  3020. })
  3021. }
  3022. return
  3023. }
  3024. // /m/api/dialysis/start [post]
  3025. // @param patient_id:int
  3026. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3027. // @param nurse:int 上机护士
  3028. // @param bed:int 床位号
  3029. func (this *DialysisAPIController) StartDialysis() {
  3030. patientID, _ := this.GetInt64("patient_id")
  3031. recordDateStr := this.GetString("record_date")
  3032. nurseID, _ := this.GetInt64("start_nurse")
  3033. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3034. blood_drawing, _ := this.GetInt64("blood_drawing")
  3035. schedual_type, _ := this.GetInt64("schedual_type")
  3036. bedID, _ := this.GetInt64("bed")
  3037. start_time := this.GetString("start_time")
  3038. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3039. change_nurse, _ := this.GetInt64("change_nurse")
  3040. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3041. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3042. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3043. puncture_needle := this.GetString("puncture_needle")
  3044. puncture_way := this.GetString("puncture_way")
  3045. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3046. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3047. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3048. zone_id, _ := this.GetInt64("zone_id")
  3049. elecsign := this.GetString("url")
  3050. nuclein_date_str := this.GetString("nuclein_date_str")
  3051. schedule_remark := this.GetString("schedule_remark")
  3052. order_remark := this.GetString("order_remark")
  3053. catheter_operation := this.GetString("catheter_operation")
  3054. blood_flow_volume := this.GetString("blood_flow_volume")
  3055. dialysis_strainer := this.GetString("dialysis_strainer")
  3056. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3057. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3061. if parseStartDateErr != nil {
  3062. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3064. return
  3065. }
  3066. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3067. if parseErr != nil {
  3068. this.ErrorLog("时间解析失败:%v", parseErr)
  3069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3070. return
  3071. }
  3072. adminUserInfo := this.GetMobileAdminUserInfo()
  3073. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3074. if getPatientErr != nil {
  3075. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3077. return
  3078. } else if patient == nil {
  3079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3080. return
  3081. }
  3082. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3083. if getNurseErr != nil {
  3084. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3086. return
  3087. } else if nurse == nil {
  3088. this.ErrorLog("护士不存在")
  3089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3090. return
  3091. }
  3092. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3093. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3094. if getDeviceNumberErr != nil {
  3095. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3097. return
  3098. } else if deviceNumber == nil {
  3099. this.ErrorLog("床位号不存在")
  3100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3101. return
  3102. }
  3103. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3104. if getRecordErr != nil {
  3105. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3107. return
  3108. } else if dialysisRecord != nil {
  3109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3110. return
  3111. }
  3112. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3113. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3114. timeLayout := "2006-01-02 15:04:05"
  3115. loc, _ := time.LoadLocation("Local")
  3116. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3117. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3118. schedulestartTime := theStartTime.Unix()
  3119. scheduleendTime := theEndTime.Unix()
  3120. var theNucleinDate int64
  3121. timeLayoutOne := "2006-01-02"
  3122. if len(nuclein_date_str) > 0 {
  3123. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3124. if err != nil {
  3125. utils.ErrorLog(err.Error())
  3126. }
  3127. theNucleinDate = theTime.Unix()
  3128. }
  3129. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3130. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3131. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3132. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3133. //查询该床位是否有人用了
  3134. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3135. if err == gorm.ErrRecordNotFound { //空床位
  3136. // 修改了床位逻辑
  3137. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3138. if daySchedule.ID > 0 {
  3139. daySchedule.PartitionId = deviceNumber.ZoneID
  3140. daySchedule.BedId = bedID
  3141. daySchedule.ScheduleType = schedual_type
  3142. daySchedule.UpdatedTime = time.Now().Unix()
  3143. xtSchedule := models.Schedule{
  3144. PartitionId: deviceNumber.ZoneID,
  3145. BedId: bedID,
  3146. ScheduleType: schedual_type,
  3147. UpdatedTime: time.Now().Unix(),
  3148. }
  3149. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3150. if err != nil {
  3151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3152. return
  3153. }
  3154. }
  3155. } else if err == nil {
  3156. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3157. if order.ID > 0 { //该机位被其他人占用了
  3158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3159. return
  3160. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3161. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3162. if daySchedule.ID > 0 {
  3163. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3164. if err != nil {
  3165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3166. return
  3167. }
  3168. }
  3169. }
  3170. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3172. return
  3173. }
  3174. //else if order.ID == 0 { //该床位没被占用
  3175. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3176. // if daySchedule.ID > 0 {
  3177. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3178. // //daySchedule.BedId = bedID
  3179. // //daySchedule.ScheduleType = schedual_type
  3180. // //daySchedule.UpdatedTime = time.Now().Unix()
  3181. // //err := service.UpdateSchedule(&daySchedule)
  3182. // xtSchedule := models.Schedule{
  3183. // PartitionId: deviceNumber.ZoneID,
  3184. // BedId: bedID,
  3185. // ScheduleType: schedual_type,
  3186. // UpdatedTime: time.Now().Unix(),
  3187. // }
  3188. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3189. // if err != nil {
  3190. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3191. // return
  3192. // }
  3193. // }
  3194. //}
  3195. //}
  3196. } else if err != nil {
  3197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3198. return
  3199. }
  3200. // 查询信息规挡的设置天数
  3201. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3202. if infor.ID > 0 && infor.WeekDay > 0 {
  3203. var cha_time int64
  3204. timeNowStr := time.Now().Format("2006-01-02")
  3205. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3206. //今日的日期减去设置的日期
  3207. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3208. if cha_time >= recordDate.Unix() {
  3209. //查询审核是否允许
  3210. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3211. //申请状态不允许的情况 拒绝修改
  3212. if infor.ApplicationStatus != 1 {
  3213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3214. return
  3215. }
  3216. }
  3217. }
  3218. dialysisRecord = &models.DialysisOrder{
  3219. DialysisDate: recordDate.Unix(),
  3220. UserOrgId: adminUserInfo.Org.Id,
  3221. PatientId: patientID,
  3222. Stage: 1,
  3223. BedID: bedID,
  3224. StartNurse: nurseID,
  3225. Status: 1,
  3226. StartTime: startDate.Unix(),
  3227. CreatedTime: time.Now().Unix(),
  3228. UpdatedTime: time.Now().Unix(),
  3229. PunctureNurse: puncture_nurse,
  3230. Creator: adminUserInfo.AdminUser.Id,
  3231. Modifier: adminUserInfo.AdminUser.Id,
  3232. SchedualType: schedual_type,
  3233. WashpipeNurse: washpipe_nurse,
  3234. ChangeNurse: change_nurse,
  3235. DifficultPunctureNurse: difficult_puncture_nurse,
  3236. NewFistulaNurse: new_fistula_nurse,
  3237. ZoneId: zone_id,
  3238. QualityNurseId: quality_nurse_id,
  3239. PunctureNeedle: puncture_needle,
  3240. PunctureWay: puncture_way,
  3241. DialysisIrrigation: dialysis_irrigation,
  3242. DialysisDialyszers: dialysis_dialyszers,
  3243. BloodAccessId: blood_access_id,
  3244. Url: elecsign,
  3245. NucleinDate: theNucleinDate,
  3246. ScheduleRemark: schedule_remark,
  3247. OrderRemark: order_remark,
  3248. CatheterOperation: catheter_operation,
  3249. BloodFlowVolume: blood_flow_volume,
  3250. BloodDrawing: blood_drawing,
  3251. DialysisStrainer: dialysis_strainer,
  3252. }
  3253. //查询该床位是否有人用了
  3254. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3255. if errorscode == gorm.ErrRecordNotFound {
  3256. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3257. finish := models.XtDialysisFinish{
  3258. IsFinish: 1,
  3259. UserOrgId: adminUserInfo.Org.Id,
  3260. Status: 1,
  3261. Ctime: time.Now().Unix(),
  3262. Mtime: 0,
  3263. Module: 6,
  3264. RecordDate: schedulestartTime,
  3265. Sourse: 1,
  3266. PatientId: patientID,
  3267. }
  3268. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3269. if dialysisFinish.ID == 0 {
  3270. service.CreateDialysisFinish(finish)
  3271. }
  3272. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3273. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3274. //统计该患者总次数
  3275. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3276. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3277. }
  3278. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3279. //统计该患者总次数
  3280. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3281. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3282. }
  3283. redis := service.RedisClient()
  3284. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3285. redis.Set(key, "", time.Second)
  3286. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3287. //清空key 值
  3288. redis.Set(keyOne, "", time.Second)
  3289. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3290. //清空key 值
  3291. redis.Set(keyTwo, "", time.Second)
  3292. if createErr != nil {
  3293. this.ErrorLog("上机失败:%v", createErr)
  3294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3295. return
  3296. }
  3297. }
  3298. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3299. var tempdispose string
  3300. // 只针对中能建
  3301. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3302. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3303. }
  3304. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3305. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3306. }
  3307. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3308. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3309. //}
  3310. var ultrafiltration_rate float64
  3311. var ultrafiltration_rate_one string
  3312. var replacement_rate float64
  3313. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3314. //后期预增脱水量
  3315. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3316. if prescription.ID > 0 {
  3317. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3318. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3319. 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
  3320. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3321. }
  3322. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3323. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3324. }
  3325. //针对医师汇
  3326. if adminUserInfo.Org.Id == 10121 {
  3327. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3328. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3329. }
  3330. //针对通道
  3331. if adminUserInfo.Org.Id == 10234 {
  3332. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3333. }
  3334. //针对监利大垸医院
  3335. if template.TemplateId == 41 {
  3336. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3337. }
  3338. //针对肇庆三鹤血液透析中心
  3339. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3340. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3341. }
  3342. if adminUserInfo.Org.Id == 10469 {
  3343. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3344. }
  3345. if adminUserInfo.Org.Id == 10667 {
  3346. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3347. }
  3348. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3349. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3350. }
  3351. // 只针对方济医院
  3352. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3353. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3354. ultrafiltration_rate = value
  3355. }
  3356. //针对
  3357. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3358. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3359. ultrafiltration_rate = ultrafiltration_rate / 1000
  3360. }
  3361. if adminUserInfo.Org.Id == 10551 {
  3362. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3363. ultrafiltration_rate = ultrafiltration_rate / 1000
  3364. }
  3365. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3366. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3367. ultrafiltration_rate = ultrafiltration_rate / 1000
  3368. }
  3369. if adminUserInfo.Org.Id == 10580 {
  3370. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3371. ultrafiltration_rate = ultrafiltration_rate / 1000
  3372. }
  3373. if adminUserInfo.Org.Id == 10629 {
  3374. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3375. ultrafiltration_rate = ultrafiltration_rate / 1000
  3376. }
  3377. if adminUserInfo.Org.Id == 10644 {
  3378. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3379. ultrafiltration_rate = ultrafiltration_rate / 1000
  3380. }
  3381. if adminUserInfo.Org.Id == 10667 {
  3382. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3383. ultrafiltration_rate = ultrafiltration_rate / 1000
  3384. }
  3385. if adminUserInfo.Org.Id == 10693 {
  3386. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3387. ultrafiltration_rate = ultrafiltration_rate
  3388. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3389. }
  3390. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3391. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3392. ultrafiltration_rate = ultrafiltration_rate
  3393. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3394. }
  3395. if adminUserInfo.Org.Id == 10206 {
  3396. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3397. ultrafiltration_rate = ultrafiltration_rate
  3398. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3399. }
  3400. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3401. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3402. ultrafiltration_rate = ultrafiltration_rate
  3403. }
  3404. if adminUserInfo.Org.Id == 10702 {
  3405. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3406. ultrafiltration_rate = ultrafiltration_rate / 1000
  3407. }
  3408. if adminUserInfo.Org.Id == 10723 {
  3409. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3410. ultrafiltration_rate = ultrafiltration_rate / 1000
  3411. }
  3412. if adminUserInfo.Org.Id == 10721 {
  3413. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3414. ultrafiltration_rate = ultrafiltration_rate / 1000
  3415. }
  3416. if adminUserInfo.Org.Id == 10721 {
  3417. if prescription.ModeId == 2 {
  3418. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3419. if totalMin == 0 {
  3420. totalMin = 240
  3421. }
  3422. if prescription.ReplacementTotal == 0 {
  3423. prescription.ReplacementTotal = 15
  3424. }
  3425. //乘10 除10是为了保留一位小数
  3426. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3427. }
  3428. }
  3429. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 {
  3430. if prescription.ModeId == 2 {
  3431. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3432. if totalMin == 0 {
  3433. totalMin = 240
  3434. }
  3435. if prescription.DisplaceLiquiValue == 0 {
  3436. prescription.ReplacementTotal = 32
  3437. }
  3438. //乘10 除10是为了保留一位小数
  3439. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3440. }
  3441. }
  3442. }
  3443. }
  3444. if adminUserInfo.Org.Id == 10172 {
  3445. if prescription.ID == 0 {
  3446. if prescription.ModeId == 2 {
  3447. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3448. if totalMin == 0 {
  3449. totalMin = 240
  3450. }
  3451. if prescription.ReplacementTotal == 0 {
  3452. prescription.ReplacementTotal = 15
  3453. }
  3454. //乘10 除10是为了保留一位小数
  3455. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3456. }
  3457. }
  3458. }
  3459. record := models.MonitoringRecord{
  3460. UserOrgId: adminUserInfo.Org.Id,
  3461. PatientId: patientID,
  3462. DialysisOrderId: dialysisRecord.ID,
  3463. MonitoringDate: schedulestartTime,
  3464. OperateTime: startDate.Unix(),
  3465. // MonitoringTime: recordTime,
  3466. MonitoringNurse: nurseID,
  3467. Dispose: tempdispose,
  3468. UltrafiltrationRate: ultrafiltration_rate,
  3469. UltrafiltrationVolume: 0,
  3470. Status: 1,
  3471. CreatedTime: time.Now().Unix(),
  3472. UpdatedTime: time.Now().Unix(),
  3473. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3474. ReplacementRate: replacement_rate,
  3475. }
  3476. //只针对广慈医院
  3477. 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 {
  3478. // 查询病人是否有透前评估数据
  3479. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3480. //如果有数据就插入
  3481. if errcode == nil {
  3482. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3483. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3484. record.BreathingRate = befor.BreathingRate
  3485. record.PulseFrequency = befor.PulseFrequency
  3486. record.Temperature = befor.Temperature
  3487. }
  3488. }
  3489. //孝昌
  3490. if adminUserInfo.Org.Id == 10693 {
  3491. // 查询病人是否有透前评估数据
  3492. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3493. //如果有数据就插入
  3494. if errcode == nil {
  3495. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3496. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3497. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3498. record.BreathingRate = befor.BreathingRate
  3499. }
  3500. }
  3501. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3502. if newdialysisRecord.ID > 0 {
  3503. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3504. record.Temperature = 36.5
  3505. record.ArterialPressure = -100
  3506. record.DialysateTemperature = 36.5
  3507. record.Conductivity = 14
  3508. record.BreathingRate = "20"
  3509. record.VenousPressure = 80
  3510. record.TransmembranePressure = 60
  3511. record.Dispose = catheter_operation
  3512. }
  3513. //针对新化博翔
  3514. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3515. record.BloodOxygenSaturation = "99"
  3516. record.Conductivity = 14
  3517. record.DialysateTemperature = 36.5
  3518. record.BreathingRate = "20"
  3519. }
  3520. //针对兰溪人民医院的需求
  3521. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3522. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3523. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3524. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3525. record.Temperature = befor.Temperature
  3526. record.PulseFrequency = befor.PulseFrequency
  3527. record.BreathingRate = befor.BreathingRate
  3528. }
  3529. //针对乐山友谊医院的需求
  3530. if adminUserInfo.Org.Id == 10677 {
  3531. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3532. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3533. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3534. record.Temperature = befor.Temperature
  3535. record.PulseFrequency = befor.PulseFrequency
  3536. record.BreathingRate = befor.BreathingRate
  3537. }
  3538. //新化博翔
  3539. if adminUserInfo.Org.Id == 10447 {
  3540. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3541. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3542. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3543. record.BreathingRate = befor.BreathingRate
  3544. }
  3545. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3546. record.PulseFrequency = 80
  3547. record.Temperature = 36.5
  3548. }
  3549. //诊断灵山圣康
  3550. if adminUserInfo.Org.Id == 10375 {
  3551. record.Conductivity = 13.8
  3552. record.DialysateTemperature = 37
  3553. record.DialysateFlow = 500
  3554. record.BloodFlowVolume = 200
  3555. record.BreathingRate = "18"
  3556. record.SodiumConcentration = 140
  3557. }
  3558. //江成肾病医院
  3559. if adminUserInfo.Org.Id == 10517 {
  3560. record.SodiumConcentration = 138
  3561. record.DialysateTemperature = 36.5
  3562. }
  3563. //濉溪杏康血液透析中心
  3564. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3565. record.BloodFlowVolume = prescription.BloodFlowVolume
  3566. }
  3567. //胶州少海医院
  3568. if adminUserInfo.Org.Id == 10735 {
  3569. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3570. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3571. record.BreathingRate = befor.BreathingRate
  3572. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3573. record.Temperature = befor.Temperature
  3574. record.PulseFrequency = befor.PulseFrequency
  3575. }
  3576. if adminUserInfo.Org.Id != 10683 {
  3577. err = service.CreateMonitor(&record)
  3578. }
  3579. //记录日志
  3580. byterequest, _ := json.Marshal(record)
  3581. monitorRecordLog := models.XtMonitorRecordLog{
  3582. RecordDate: record.MonitoringDate,
  3583. PatientId: record.PatientId,
  3584. Module: 1,
  3585. AdminUserId: adminUserInfo.AdminUser.Id,
  3586. Ctime: time.Now().Unix(),
  3587. Mtime: 0,
  3588. Status: 1,
  3589. UserOrgId: record.UserOrgId,
  3590. ErrLog: string(byterequest),
  3591. Source: "执行上机时新增监测",
  3592. }
  3593. service.CreateMonitorRecordLog(monitorRecordLog)
  3594. finish := models.XtDialysisFinish{
  3595. IsFinish: 1,
  3596. UserOrgId: adminUserInfo.Org.Id,
  3597. Status: 1,
  3598. Ctime: time.Now().Unix(),
  3599. Mtime: 0,
  3600. Module: 7,
  3601. RecordDate: schedulestartTime,
  3602. Sourse: 1,
  3603. PatientId: patientID,
  3604. }
  3605. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3606. if dialysisFinish.ID == 0 {
  3607. service.CreateDialysisFinish(finish)
  3608. }
  3609. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3610. redis := service.RedisClient()
  3611. //清空key 值
  3612. redis.Set(key, "", time.Second)
  3613. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3614. redis.Set(keyOne, "", time.Second)
  3615. defer redis.Close()
  3616. if err != nil {
  3617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3618. return
  3619. }
  3620. }
  3621. go func() {
  3622. ssoDomain := beego.AppConfig.String("call_domain")
  3623. api := ssoDomain + "/index/uppatient"
  3624. values := make(url.Values)
  3625. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3626. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3627. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3628. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3629. http.PostForm(api, values)
  3630. }()
  3631. this.ServeSuccessJSON(map[string]interface{}{
  3632. "dialysis_order": newdialysisRecord,
  3633. "monitor": record,
  3634. })
  3635. return
  3636. }
  3637. func (c *DialysisAPIController) PostSolution() {
  3638. id, _ := c.GetInt64("patient", 0)
  3639. recordDateStr := c.GetString("record_date")
  3640. if id <= 0 {
  3641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3642. return
  3643. }
  3644. adminUserInfo := c.GetMobileAdminUserInfo()
  3645. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3646. if patient.ID == 0 {
  3647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3648. return
  3649. }
  3650. if len(recordDateStr) == 0 {
  3651. recordDateStr = time.Now().Format("2006-01-02")
  3652. }
  3653. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3654. if parseDateErr != nil {
  3655. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3657. return
  3658. }
  3659. mode_id, _ := c.GetInt64("mode_id", 0)
  3660. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3661. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3662. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3663. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3664. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3665. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3666. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3667. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3668. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3669. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3670. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3671. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3672. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3673. kalium, _ := c.GetFloat("kalium", 0)
  3674. sodium, _ := c.GetFloat("sodium", 0)
  3675. calcium, _ := c.GetFloat("calcium", 0)
  3676. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3677. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3678. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3679. glucose, _ := c.GetFloat("glucose", 0)
  3680. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3681. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3682. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3683. conductivity, _ := c.GetFloat("conductivity", 0)
  3684. remark := c.GetString("remark")
  3685. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3686. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3687. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3688. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3689. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3690. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3691. special_medicine_other := c.GetString("special_medicine_other")
  3692. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3693. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3694. blood_access, _ := c.GetInt64("blood_access", 0)
  3695. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3696. body_fluid_other := c.GetString("body_fluid_other")
  3697. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3698. niprocart, _ := c.GetInt64("niprocart", 0)
  3699. jms, _ := c.GetInt64("jms", 0)
  3700. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3701. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3702. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3703. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3704. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3705. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3706. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3707. injector, _ := c.GetInt64("injector", 0)
  3708. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3709. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3710. safe_package, _ := c.GetInt64("package", 0)
  3711. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3712. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3713. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3714. blood := c.GetString("blood")
  3715. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3716. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3717. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3718. displace_speed := c.GetString("displace_speed")
  3719. illness, _ := c.GetInt64("illness")
  3720. amylaceum := c.GetString("amylaceum")
  3721. single_time := c.GetString("single_time")
  3722. single_water := c.GetString("single_water")
  3723. replacement_flow := c.GetString("replacement_flow")
  3724. plasma_separator := c.GetString("plasma_separator")
  3725. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3726. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3727. oxygen_flow := c.GetString("oxygen_flow")
  3728. oxygen_time := c.GetString("oxygen_time")
  3729. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3730. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3731. puncture_needle := c.GetString("puncture_needle")
  3732. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3733. epo := c.GetString("epo")
  3734. epo_count, _ := c.GetFloat("epo_count", 0)
  3735. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3736. pre_impulse := c.GetString("pre_impulse")
  3737. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3738. admin_user_id, _ := c.GetInt64("admin_user_id")
  3739. is_water := c.GetString("is_water")
  3740. add_amount, _ := c.GetFloat("add_amount")
  3741. reduce_amount, _ := c.GetFloat("reduce_amount")
  3742. prescribing_number, _ := c.GetFloat("prescribing_number")
  3743. treatment_remark := c.GetString("treatment_remark")
  3744. prescription_sodium := c.GetString("prescription_sodium")
  3745. start_sodium := c.GetString("start_sodium")
  3746. sodium_curve := c.GetString("sodium_curve")
  3747. var is_war int64
  3748. if is_water == "是" {
  3749. is_war = 1
  3750. }
  3751. if is_water == "否" {
  3752. is_war = 2
  3753. }
  3754. if is_water == "请选择" {
  3755. is_war = 0
  3756. }
  3757. drhy_water := c.GetString("drhy_water")
  3758. dry_water_hour := c.GetString("dry_water_hour")
  3759. water_machine := c.GetString("water_machine")
  3760. dialysis_remark := c.GetString("dialysis_remark")
  3761. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3762. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3763. prescription_water, _ := c.GetFloat("prescription_water")
  3764. dialysis_strainer := c.GetString("dialysis_strainer")
  3765. chaptalization := c.GetString("chaptalization")
  3766. washing_time := c.GetString("washing_time")
  3767. warsh_count := c.GetString("warsh_count")
  3768. blood_access_part_id := c.GetString("blood_access_part_id")
  3769. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3770. dialyzate := c.GetString("dialyzate")
  3771. first_super := c.GetString("first_super")
  3772. is_sequential := c.GetString("is_sequential")
  3773. var fisrt_sup int64
  3774. if first_super == "是" {
  3775. fisrt_sup = 1
  3776. }
  3777. if first_super == "否" {
  3778. fisrt_sup = 2
  3779. }
  3780. if first_super == "请选择" {
  3781. fisrt_sup = 0
  3782. }
  3783. var is_sequen int64
  3784. if is_sequential == "是" {
  3785. is_sequen = 1
  3786. }
  3787. if is_sequential == "否" {
  3788. is_sequen = 2
  3789. }
  3790. if is_sequential == "请选择" {
  3791. is_sequen = 0
  3792. }
  3793. conduct := c.GetString("conduct")
  3794. if mode_id > 0 {
  3795. var str string
  3796. //查找该机构用的是什么透析器
  3797. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3798. if filedConfig.ID > 0 {
  3799. str = dialyzerPerfusionApparatus
  3800. } else {
  3801. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3802. }
  3803. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3804. }
  3805. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3806. //
  3807. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3808. // if appRole.UserType == 3 {
  3809. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3810. // if getPermissionErr != nil {
  3811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3812. // return
  3813. // } else if headNursePermission == nil {
  3814. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3815. // return
  3816. // }
  3817. // }
  3818. //}
  3819. // 查询信息规挡的设置天数
  3820. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3821. if infor.ID > 0 && infor.WeekDay > 0 {
  3822. var cha_time int64
  3823. timeNowStr := time.Now().Format("2006-01-02")
  3824. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3825. //今日的日期减去设置的日期
  3826. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3827. if cha_time >= recordDate.Unix() {
  3828. //查询审核是否允许
  3829. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3830. //申请状态不允许的情况 拒绝修改
  3831. if infor.ApplicationStatus != 1 {
  3832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3833. return
  3834. }
  3835. }
  3836. }
  3837. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3838. var dialysis_dialyszers_id int64
  3839. var dialysis_strainer_id int64
  3840. var dialysis_irrigation_id int64
  3841. if len(goodList) > 0 {
  3842. for _, item := range goodList {
  3843. if item.SpecificationName == dialysis_dialyszers {
  3844. dialysis_dialyszers_id = item.ID
  3845. }
  3846. if item.SpecificationName == dialysis_irrigation {
  3847. dialysis_irrigation_id = item.ID
  3848. }
  3849. if item.SpecificationName == dialysis_strainer {
  3850. dialysis_strainer_id = item.ID
  3851. }
  3852. }
  3853. }
  3854. prescription := models.DialysisPrescription{
  3855. UserOrgId: adminUserInfo.Org.Id,
  3856. PatientId: id,
  3857. RecordDate: recordDate.Unix(),
  3858. ModeId: mode_id,
  3859. DialysisDuration: dialysis_duration,
  3860. Dialyzer: dialyzer,
  3861. PerfusionApparatus: perfusion_apparatus,
  3862. BloodFlowVolume: blood_flow_volume,
  3863. DewaterAmount: dewater_amount,
  3864. DisplaceLiqui: displace_liqui,
  3865. ReplacementWay: replacement_way,
  3866. Anticoagulant: anticoagulant,
  3867. AnticoagulantShouji: anticoagulant_shouji,
  3868. AnticoagulantWeichi: anticoagulant_weichi,
  3869. AnticoagulantZongliang: anticoagulant_zongliang,
  3870. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3871. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3872. Kalium: kalium,
  3873. Sodium: sodium,
  3874. Calcium: calcium,
  3875. Bicarbonate: bicarbonate,
  3876. Glucose: glucose,
  3877. // DryWeight: dry_weight,
  3878. DialysateFlow: dialysate_flow,
  3879. DialysateTemperature: dialysate_temperature,
  3880. Conductivity: conductivity,
  3881. Remark: remark,
  3882. Status: 1,
  3883. CreatedTime: time.Now().Unix(),
  3884. UpdatedTime: time.Now().Unix(),
  3885. DialysisDurationMinute: dialysisDurationMinute,
  3886. DialysisDurationHour: dialysisDurationHour,
  3887. TargetUltrafiltration: targetUltrafiltration,
  3888. DialysateFormulation: dialysateFormulation,
  3889. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3890. BodyFluid: body_fluid,
  3891. SpecialMedicine: special_medicine,
  3892. SpecialMedicineOther: special_medicine_other,
  3893. DisplaceLiquiPart: displace_liqui_part,
  3894. DisplaceLiquiValue: displace_liqui_value,
  3895. BloodAccess: blood_access,
  3896. Ultrafiltration: ultrafiltration,
  3897. BodyFluidOther: body_fluid_other,
  3898. ReplacementTotal: replacement_total,
  3899. Niprocart: niprocart,
  3900. Jms: jms,
  3901. FistulaNeedleSet: fistula_needle_set,
  3902. FistulaNeedleSet16: fistula_needle_set_16,
  3903. Hemoperfusion: hemoperfusion,
  3904. DialyserSterilised: dialyser_sterilised,
  3905. Filtryzer: filtryzer,
  3906. TargetKtv: target_ktv,
  3907. Dialyzers: dialyzers,
  3908. Injector: injector,
  3909. Bloodlines: bloodlines,
  3910. TubingHemodialysis: tubing_hemodialysis,
  3911. Package: safe_package,
  3912. ALiquid: a_liquid,
  3913. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3914. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3915. Blood: blood,
  3916. DialysisDialyszers: dialysis_dialyszers,
  3917. DialysisIrrigation: dialysis_irrigation,
  3918. AntioxidantCommodityName: antioxidant_commodity_name,
  3919. DisplaceSpeed: displace_speed,
  3920. Illness: illness,
  3921. Amylaceum: amylaceum,
  3922. SingleWater: single_water,
  3923. SingleTime: single_time,
  3924. ReplacementFlow: replacement_flow,
  3925. PlasmaSeparator: plasma_separator,
  3926. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3927. OxygenUptake: oxygen_uptake,
  3928. OxygenTime: oxygen_time,
  3929. OxygenFlow: oxygen_flow,
  3930. HemodialysisPipelines: hemodialysis_pipelines,
  3931. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3932. PunctureNeedle: puncture_needle,
  3933. PunctureNeedleCount: puncture_needle_count,
  3934. Epo: epo,
  3935. EpoCount: epo_count,
  3936. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3937. PreImpulse: impulse,
  3938. AdminUserId: admin_user_id,
  3939. IsWater: is_war,
  3940. DrhyWater: drhy_water,
  3941. DryWaterHour: dry_water_hour,
  3942. WaterMachine: water_machine,
  3943. AddAmount: add_amount,
  3944. ReduceAmount: reduce_amount,
  3945. DialysisRemark: dialysis_remark,
  3946. PrescribingNumber: prescribing_number,
  3947. PrescriptionSodium: prescription_sodium,
  3948. StartSodium: start_sodium,
  3949. SodiumCurve: sodium_curve,
  3950. TreatmentRemark: treatment_remark,
  3951. DialysisFluidFlow: dialysis_fluid_flow,
  3952. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3953. PrescriptionWater: prescription_water,
  3954. DialysisStrainer: dialysis_strainer,
  3955. Chaptalization: chaptalization,
  3956. WashingTime: washing_time,
  3957. WarshCount: warsh_count,
  3958. BloodAccessPartId: blood_access_part_id,
  3959. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3960. Dialyzate: dialyzate,
  3961. DialysisDialyszersId: dialysis_dialyszers_id,
  3962. DialysisIrrigationId: dialysis_irrigation_id,
  3963. DialysisStrainerId: dialysis_strainer_id,
  3964. FirstSuper: fisrt_sup,
  3965. IsSequential: is_sequen,
  3966. Conduct: conduct,
  3967. }
  3968. if adminUserInfo.Org.Id == 10721 {
  3969. if prescription.ModeId == 2 {
  3970. if prescription.ReplacementTotal == 0 {
  3971. prescription.ReplacementTotal = 15
  3972. }
  3973. }
  3974. }
  3975. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3976. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3977. //
  3978. if appRole.UserType == 2 || appRole.UserType == 1 {
  3979. prescription_doctor = adminUserInfo.AdminUser.Id
  3980. prescription.PrescriptionDoctor = prescription_doctor
  3981. }
  3982. if dialysisPrescription.ID == 0 { //新增
  3983. prescription.Creater = adminUserInfo.AdminUser.Id
  3984. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3985. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3986. }
  3987. } else { //修改
  3988. if dialysisPrescription.Creater == 0 {
  3989. prescription.Creater = adminUserInfo.AdminUser.Id
  3990. } else {
  3991. prescription.Creater = dialysisPrescription.Creater
  3992. if adminUserInfo.Org.Id == 9882 {
  3993. if appRole.UserType == 2 || appRole.UserType == 1 {
  3994. prescription.Creater = adminUserInfo.AdminUser.Id
  3995. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3996. }
  3997. }
  3998. }
  3999. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4000. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4001. }
  4002. //if/**/
  4003. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4004. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4005. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4006. // if getPermissionErr != nil {
  4007. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4008. // return
  4009. // } else if headNursePermission == nil {
  4010. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4011. // return
  4012. // }
  4013. //}
  4014. //prescription.Creater = dialysisPrescription.Creater
  4015. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4016. prescription.Modifier = adminUserInfo.AdminUser.Id
  4017. prescription.ID = dialysisPrescription.ID
  4018. }
  4019. solution := models.DialysisSolution{
  4020. RegistrarsId: adminUserInfo.AdminUser.Id,
  4021. UserOrgId: adminUserInfo.Org.Id,
  4022. Doctor: prescription_doctor,
  4023. PatientId: id,
  4024. ModeId: mode_id,
  4025. DialysisDuration: dialysis_duration,
  4026. PerfusionApparatus: perfusion_apparatus,
  4027. BloodFlowVolume: blood_flow_volume,
  4028. Dewater: dewater_amount,
  4029. DisplaceLiqui: displace_liqui,
  4030. ReplacementWay: replacement_way,
  4031. Anticoagulant: anticoagulant,
  4032. AnticoagulantShouji: anticoagulant_shouji,
  4033. AnticoagulantWeichi: anticoagulant_weichi,
  4034. AnticoagulantZongliang: anticoagulant_zongliang,
  4035. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4036. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4037. Kalium: kalium,
  4038. Sodium: sodium,
  4039. Calcium: calcium,
  4040. Bicarbonate: bicarbonate,
  4041. Glucose: glucose,
  4042. // DryWeight: dry_weight,
  4043. DialysateFlow: dialysate_flow,
  4044. DialysateTemperature: dialysate_temperature,
  4045. Conductivity: conductivity,
  4046. Remark: remark,
  4047. Status: 1,
  4048. CreatedTime: time.Now().Unix(),
  4049. UpdatedTime: time.Now().Unix(),
  4050. DialysisDurationMinute: dialysisDurationMinute,
  4051. DialysisDurationHour: dialysisDurationHour,
  4052. TargetUltrafiltration: targetUltrafiltration,
  4053. DialysateFormulation: dialysateFormulation,
  4054. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4055. BodyFluid: body_fluid,
  4056. SpecialMedicine: special_medicine,
  4057. SpecialMedicineOther: special_medicine_other,
  4058. DisplaceLiquiPart: displace_liqui_part,
  4059. DisplaceLiquiValue: displace_liqui_value,
  4060. BloodAccess: blood_access,
  4061. Ultrafiltration: ultrafiltration,
  4062. BodyFluidOther: body_fluid_other,
  4063. ReplacementTotal: replacement_total,
  4064. TargetKtv: target_ktv,
  4065. DialysisDialyszers: dialysis_dialyszers,
  4066. DialysisIrrigation: dialysis_irrigation,
  4067. HemodialysisPipelines: hemodialysis_pipelines,
  4068. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4069. PunctureNeedle: puncture_needle,
  4070. PunctureNeedleCount: puncture_needle_count,
  4071. Epo: epo,
  4072. EpoCount: epo_count,
  4073. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4074. PreImpulse: impulse,
  4075. SolutionStatus: 1,
  4076. DialysisRemark: dialysis_remark,
  4077. PrescribingNumber: prescribing_number,
  4078. PrescriptionSodium: prescription_sodium,
  4079. StartSodium: start_sodium,
  4080. SodiumCurve: sodium_curve,
  4081. TreatmentRemark: treatment_remark,
  4082. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4083. DialysisFluidFlow: dialysis_fluid_flow,
  4084. PrescriptionWater: prescription_water,
  4085. DialysisStrainer: dialysis_strainer,
  4086. Chaptalization: chaptalization,
  4087. WashingTime: washing_time,
  4088. WarshCount: warsh_count,
  4089. BloodAccessPartId: blood_access_part_id,
  4090. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4091. Dialyzate: dialyzate,
  4092. DialysisDialyszersId: dialysis_dialyszers_id,
  4093. DialysisIrrigationId: dialysis_irrigation_id,
  4094. DialysisStrainerId: dialysis_strainer_id,
  4095. FirstSuper: fisrt_sup,
  4096. IsSequential: is_sequen,
  4097. Conduct: conduct,
  4098. }
  4099. //针对河间咸的
  4100. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4101. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4102. solution.DisplaceLiquiPart = 0
  4103. solution.DisplaceLiquiValue = 0
  4104. }
  4105. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4106. prescription.DisplaceLiquiPart = 0
  4107. prescription.DisplaceLiquiValue = 0
  4108. }
  4109. }
  4110. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4111. if solution.PrescribingNumber == 0 {
  4112. solution.PrescribingNumber = 1
  4113. }
  4114. if prescription.PrescribingNumber == 0 {
  4115. prescription.PrescribingNumber = 1
  4116. }
  4117. if solution.PrescribingNumber == 0 && id == 14682 {
  4118. solution.PrescribingNumber = 2
  4119. }
  4120. if solution.PrescribingNumber == 0 && id == 18560 {
  4121. solution.PrescribingNumber = 2
  4122. }
  4123. if prescription.PrescribingNumber == 0 && id == 14682 {
  4124. prescription.PrescribingNumber = 2
  4125. }
  4126. if prescription.PrescribingNumber == 0 && id == 18560 {
  4127. prescription.PrescribingNumber = 2
  4128. }
  4129. }
  4130. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4131. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4132. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4133. if len(monitorList) > 0 {
  4134. var ultrafiltration_rate float64
  4135. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4136. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4137. var replacement_rate float64
  4138. //乘10 除10是为了保留一位小数
  4139. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4140. var firstOpeateTime = monitorList[0].OperateTime
  4141. for _, item := range monitorList {
  4142. //超滤率
  4143. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4144. //置换率
  4145. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4146. //超滤量
  4147. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4148. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4149. //置换量
  4150. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4151. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4152. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4153. }
  4154. }
  4155. }
  4156. //记录日志
  4157. byterequest, _ := json.Marshal(prescription)
  4158. prescriptionLog := models.XtDialysisPrescriptionLog{
  4159. UserOrgId: prescription.UserOrgId,
  4160. Ctime: time.Now().Unix(),
  4161. Mtime: 0,
  4162. ErrLog: string(byterequest),
  4163. AdminUserId: adminUserInfo.AdminUser.Id,
  4164. RecordDate: prescription.RecordDate,
  4165. PatientId: prescription.PatientId,
  4166. Source: "手机端新增长期处方",
  4167. Status: 1,
  4168. }
  4169. service.CreatePrescriptionLog(prescriptionLog)
  4170. finish := models.XtDialysisFinish{
  4171. IsFinish: 1,
  4172. UserOrgId: adminUserInfo.Org.Id,
  4173. Status: 1,
  4174. Ctime: time.Now().Unix(),
  4175. Mtime: 0,
  4176. Module: 1,
  4177. RecordDate: recordDate.Unix(),
  4178. Sourse: 1,
  4179. PatientId: id,
  4180. }
  4181. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4182. if dialysisFinish.ID == 0 {
  4183. service.CreateDialysisFinish(finish)
  4184. }
  4185. //获取最新1条
  4186. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4187. //更新状态
  4188. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4189. //长沙南雅医院,自动生成抗凝剂的临时处方
  4190. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4191. if prescribing_number == 0 {
  4192. prescribing_number = 1
  4193. }
  4194. advice := models.DoctorAdvice{
  4195. UserOrgId: adminUserInfo.Org.Id,
  4196. PatientId: id,
  4197. GroupNo: 0,
  4198. AdviceType: 2,
  4199. RecordDate: recordDate.Unix(),
  4200. AdviceDate: recordDate.Unix(),
  4201. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4202. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4203. AdviceDesc: "",
  4204. ReminderDate: 0,
  4205. SingleDose: prescription.AnticoagulantZongliang,
  4206. SingleDoseUnit: "iu",
  4207. DrugSpec: 0,
  4208. DrugSpecUnit: "",
  4209. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4210. PrescribingNumberUnit: "支",
  4211. DeliveryWay: "静脉注射",
  4212. ExecutionFrequency: "上机前",
  4213. AdviceDoctor: 0,
  4214. Status: 1,
  4215. CreatedTime: time.Now().Unix(),
  4216. UpdatedTime: time.Now().Unix(),
  4217. IsPrescription: 1,
  4218. ExecutionState: 2,
  4219. StopState: 2,
  4220. IsSettle: 2,
  4221. }
  4222. // 查询排班信息
  4223. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4224. if schedulePatient.ID > 0 {
  4225. if schedulePatient.ScheduleType == 1 {
  4226. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4227. }
  4228. if schedulePatient.ScheduleType == 2 {
  4229. advice.StartTime = recordDate.Unix() + 9*60*60
  4230. }
  4231. }
  4232. // 抗凝剂名称
  4233. switch anticoagulant {
  4234. case 1:
  4235. advice.AdviceName = "无肝素"
  4236. break
  4237. case 2:
  4238. advice.AdviceName = "普通肝素"
  4239. break
  4240. case 3:
  4241. advice.AdviceName = "低分子肝素"
  4242. break
  4243. case 4:
  4244. advice.AdviceName = "阿加曲班"
  4245. break
  4246. case 5:
  4247. advice.AdviceName = "枸橼酸钠"
  4248. break
  4249. case 6:
  4250. advice.AdviceName = "低分子肝素钙"
  4251. break
  4252. case 7:
  4253. advice.AdviceName = "低分子肝素钠"
  4254. break
  4255. case 8:
  4256. advice.AdviceName = "依诺肝素"
  4257. break
  4258. case 9:
  4259. advice.AdviceName = "达肝素"
  4260. break
  4261. case 10:
  4262. advice.AdviceName = "体外抗凝"
  4263. break
  4264. case 11:
  4265. advice.AdviceName = "那曲肝素"
  4266. break
  4267. case 12:
  4268. advice.AdviceName = "无抗凝剂"
  4269. break
  4270. }
  4271. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4272. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4273. advice.AdviceDoctor = appRole.AdminUserId
  4274. }
  4275. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4276. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4277. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4278. advice.AdviceName = "低分子肝素钠注射液"
  4279. // 修改患者临时医嘱里的抗凝剂医嘱
  4280. advice.ID = advicePrescription.ID
  4281. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4282. } else {
  4283. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4284. advice.AdviceName = "低分子肝素钠注射液"
  4285. service.CreateDoctorAdvice(&advice)
  4286. }
  4287. }
  4288. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4289. redis := service.RedisClient()
  4290. defer redis.Close()
  4291. //清空key 值
  4292. redis.Set(key, "", time.Second)
  4293. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4294. redis.Set(keyOne, "", time.Second)
  4295. }
  4296. //获取key,清空redis
  4297. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4298. redis := service.RedisClient()
  4299. defer redis.Close()
  4300. //清空key 值
  4301. redis.Set(key, "", time.Second)
  4302. //清空长期医嘱的key
  4303. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4304. redis.Set(soulution_key, "", time.Second)
  4305. //查询最近透析准备表里是否存在 透析器 灌流器
  4306. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4307. redis.Set(keyOne, "", time.Second)
  4308. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4309. redis.Set(keyTwo, "", time.Second)
  4310. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4311. redis.Set(keyThree, "", time.Second)
  4312. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4313. redis.Set(keyFour, "", time.Second)
  4314. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4315. //
  4316. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4317. //
  4318. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4319. //if len(mation)>0{
  4320. // for _, item := range splitStr {
  4321. // for _,it := range mation{
  4322. // if(item == it.SpecificationName){
  4323. //
  4324. // //查询最近一次的透析器
  4325. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4326. //
  4327. // if errcode == gorm.ErrRecordNotFound{
  4328. // //插入数据
  4329. // prepare := models.DialysisBeforePrepare{
  4330. // UserOrgId: adminUserInfo.Org.Id,
  4331. // PatientId: id,
  4332. // RecordDate: recordDate.Unix(),
  4333. // GoodTypeId: it.GoodTypeId,
  4334. // GoodId: it.ID,
  4335. // Count: 1,
  4336. // Ctime: time.Now().Unix(),
  4337. // Creater: adminUserInfo.AdminUser.Id,
  4338. // Status:1,
  4339. //
  4340. // }
  4341. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4342. // fmt.Println("",errcode)
  4343. // }
  4344. // }
  4345. // }
  4346. //
  4347. // }
  4348. //
  4349. // for _, item := range splitIrrigation {
  4350. // for _,it := range mation{
  4351. // if(item == it.SpecificationName){
  4352. // //查询最近一次的透析器
  4353. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4354. // if errcode == gorm.ErrRecordNotFound{
  4355. // //插入数据
  4356. // prepare := models.DialysisBeforePrepare{
  4357. // UserOrgId: adminUserInfo.Org.Id,
  4358. // PatientId: id,
  4359. // RecordDate: recordDate.Unix(),
  4360. // GoodTypeId: it.GoodTypeId,
  4361. // GoodId: it.ID,
  4362. // Count: 1,
  4363. // Ctime: time.Now().Unix(),
  4364. // Creater: adminUserInfo.AdminUser.Id,
  4365. // Status:1,
  4366. //
  4367. // }
  4368. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4369. // fmt.Println(errcode)
  4370. // }
  4371. // }
  4372. // }
  4373. // }
  4374. //}
  4375. c.ServeSuccessJSON(map[string]interface{}{
  4376. "solution": &solution,
  4377. "prescription": &prescription,
  4378. })
  4379. }
  4380. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4381. patient, _ := c.GetInt64("patient", 0)
  4382. adminUserInfo := c.GetMobileAdminUserInfo()
  4383. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4384. c.ServeSuccessJSON(map[string]interface{}{
  4385. "receiveTreatmentAsses": receiveTreatmentAsses,
  4386. })
  4387. }
  4388. func (this *DialysisAPIController) PostSignInfo() {
  4389. patientID, _ := this.GetInt64("patient_id")
  4390. recordDateStr := this.GetString("date")
  4391. if patientID <= 0 {
  4392. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4393. return
  4394. }
  4395. if len(recordDateStr) == 0 {
  4396. recordDateStr = time.Now().Format("2006-01-02")
  4397. }
  4398. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4399. if parseDateErr != nil {
  4400. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4402. return
  4403. }
  4404. adminInfo := this.GetMobileAdminUserInfo()
  4405. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4406. if err != nil {
  4407. this.ErrorLog("签名失败:%v", err)
  4408. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4409. return
  4410. }
  4411. this.ServeSuccessJSON(map[string]interface{}{
  4412. "doctor_id": adminInfo.AdminUser.Id,
  4413. })
  4414. }
  4415. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4416. patientID, _ := this.GetInt64("patient_id")
  4417. adminInfo := this.GetMobileAdminUserInfo()
  4418. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4419. this.ServeSuccessJSON(map[string]interface{}{
  4420. "monitor": record,
  4421. })
  4422. }
  4423. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4424. thisTime := time.Now()
  4425. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4426. timeLayout := "2006-01-02 15:04:05"
  4427. loc, _ := time.LoadLocation("Local")
  4428. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4429. theAssessmentDateTime := theStartTime.Unix()
  4430. patientID, _ := this.GetInt64("patient_id")
  4431. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4432. adminInfo := this.GetMobileAdminUserInfo()
  4433. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4434. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4435. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4436. var ultrafiltration_rate float64
  4437. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4438. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4439. fmt.Println(evaluation)
  4440. fmt.Println("prescription.ID", prescription.ID)
  4441. if prescription.ID > 0 {
  4442. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4443. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4444. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4445. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4446. record.UltrafiltrationRate = ultrafiltration_rate
  4447. }
  4448. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4449. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4450. record.UltrafiltrationRate = ultrafiltration_rate
  4451. }
  4452. if adminInfo.Org.Id == 10510 {
  4453. record.UltrafiltrationRate = 0
  4454. }
  4455. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4456. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4457. record.UltrafiltrationRate = ultrafiltration_rate
  4458. }
  4459. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4460. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4461. record.UltrafiltrationRate = ultrafiltration_rate
  4462. }
  4463. // 只针对方济医院
  4464. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4465. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4466. ultrafiltration_rate = value
  4467. record.UltrafiltrationRate = ultrafiltration_rate
  4468. }
  4469. if template.TemplateId == 41 || template.TemplateId == 47 {
  4470. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4471. record.UltrafiltrationRate = ultrafiltration_rate
  4472. }
  4473. if template.TemplateId == 43 {
  4474. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4475. record.UltrafiltrationRate = ultrafiltration_rate
  4476. }
  4477. if template.TemplateId == 46 || template.TemplateId == 54 {
  4478. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4479. record.UltrafiltrationRate = ultrafiltration_rate
  4480. }
  4481. 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 {
  4482. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4483. record.UltrafiltrationRate = ultrafiltration_rate
  4484. }
  4485. if adminInfo.Org.Id == 10469 {
  4486. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4487. record.UltrafiltrationRate = ultrafiltration_rate
  4488. }
  4489. if adminInfo.Org.Id == 10667 {
  4490. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4491. record.UltrafiltrationRate = ultrafiltration_rate
  4492. }
  4493. if adminInfo.Org.Id == 10471 {
  4494. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4495. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4496. }
  4497. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4498. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4499. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4500. }
  4501. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4502. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4503. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4504. }
  4505. if adminInfo.Org.Id == 10721 {
  4506. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4507. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4508. }
  4509. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4510. record.UltrafiltrationRate = 0
  4511. }
  4512. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4513. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4514. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4515. }
  4516. if adminInfo.Org.Id == 10206 {
  4517. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4518. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4519. }
  4520. //if template.TemplateId == 47 {
  4521. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4522. // record.UltrafiltrationRate = ultrafiltration_rate
  4523. //}
  4524. }
  4525. }
  4526. // record.UltrafiltrationRate = ultrafiltration_rate
  4527. record.UltrafiltrationVolume = 0
  4528. 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
  4529. if ultrafiltration_rate > 0 {
  4530. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4531. record.UltrafiltrationVolume = value
  4532. }
  4533. }
  4534. 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
  4535. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4536. if adminInfo.Org.Id != 10735 {
  4537. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4538. record.UltrafiltrationVolume = ultrafiltration_volume
  4539. }
  4540. //胶州少海医院
  4541. if adminInfo.Org.Id == 10735 {
  4542. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4543. if lastMonitorRecordList.ID > 0 {
  4544. record.UltrafiltrationRate = lastMonitorRecordList.UltrafiltrationRate
  4545. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * lastMonitorRecordList.UltrafiltrationRate)
  4546. record.UltrafiltrationVolume = ultrafiltration_volume
  4547. } else {
  4548. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4549. record.UltrafiltrationVolume = ultrafiltration_volume
  4550. }
  4551. }
  4552. }
  4553. }
  4554. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4555. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4556. record.UltrafiltrationVolume = ultrafiltration_volume
  4557. }
  4558. //长沙南雅
  4559. 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 {
  4560. if ultrafiltration_rate > 0 {
  4561. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4562. record.UltrafiltrationVolume = ultrafiltration_volume
  4563. }
  4564. }
  4565. if adminInfo.Org.Id == 10471 {
  4566. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4567. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4568. }
  4569. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4570. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4571. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4572. }
  4573. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4574. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4575. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4576. }
  4577. //长沙南雅累计血容量自动计算
  4578. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4579. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4580. //}
  4581. if template.TemplateId == 47 || template.TemplateId == 54 {
  4582. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4583. }
  4584. if adminInfo.Org.Id == 10510 {
  4585. record.UltrafiltrationVolume = 0
  4586. }
  4587. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 {
  4588. if ultrafiltration_rate > 0 {
  4589. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4590. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4591. }
  4592. }
  4593. //古镇乐生
  4594. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4595. if ultrafiltration_rate > 0 {
  4596. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4597. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4598. }
  4599. }
  4600. if adminInfo.Org.Id == 10206 {
  4601. if ultrafiltration_rate > 0 {
  4602. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4603. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4604. }
  4605. }
  4606. if adminInfo.Org.Id == 10721 {
  4607. var replacement_rate float64
  4608. var displacement_quantity float64
  4609. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4610. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4611. record.ReplacementRate = replacement_rate
  4612. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4613. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4614. record.DisplacementQuantity = displacement_quantity
  4615. }
  4616. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4617. var replacement_rate float64
  4618. var displacement_quantity float64
  4619. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4620. if totalMin == 0 {
  4621. totalMin = 240
  4622. }
  4623. if prescription.DisplaceLiquiValue == 0 {
  4624. prescription.ReplacementTotal = 32
  4625. }
  4626. //乘10 除10是为了保留一位小数
  4627. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4628. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4629. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4630. record.DisplacementQuantity = displacement_quantity
  4631. }
  4632. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4633. this.ServeSuccessJSON(map[string]interface{}{
  4634. "monitor": record,
  4635. "lastMonitorRecordList": lastMonitorRecordList,
  4636. })
  4637. }
  4638. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4639. record_id, _ := this.GetInt64("id")
  4640. nurseID, _ := this.GetInt64("start_nurse")
  4641. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4642. bedID, _ := this.GetInt64("bed")
  4643. start_time := this.GetString("start_time")
  4644. schedual_type, _ := this.GetInt64("schedual_type")
  4645. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4646. change_nurse, _ := this.GetInt64("change_nurse")
  4647. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4648. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4649. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4650. patient_id, _ := this.GetInt64("patient_id")
  4651. record_date, _ := this.GetInt64("record_date")
  4652. puncture_needle := this.GetString("puncture_needle")
  4653. puncture_way := this.GetString("puncture_way")
  4654. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4655. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4656. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4657. nuclein_date_str := this.GetString("nuclein_date_str")
  4658. order_remark := this.GetString("order_remark")
  4659. schedule_remark := this.GetString("schedule_remark")
  4660. catheter_operation := this.GetString("catheter_operation")
  4661. blood_flow_volume := this.GetString("blood_flow_volume")
  4662. blood_drawing, _ := this.GetInt64("blood_drawing")
  4663. dialysis_strainer := this.GetString("dialysis_strainer")
  4664. if record_id == 0 {
  4665. this.ErrorLog("id:%v", record_id)
  4666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4667. return
  4668. }
  4669. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4670. if parseStartDateErr != nil {
  4671. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4673. return
  4674. }
  4675. adminUserInfo := this.GetMobileAdminUserInfo()
  4676. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4677. if getNurseErr != nil {
  4678. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4680. return
  4681. } else if nurse == nil {
  4682. this.ErrorLog("护士不存在")
  4683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4684. return
  4685. }
  4686. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4687. //if getNurseErr != nil {
  4688. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4689. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4690. // return
  4691. //} else if nurse == nil {
  4692. // this.ErrorLog("护士不存在")
  4693. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4694. // return
  4695. //}
  4696. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4697. if getDeviceNumberErr != nil {
  4698. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4699. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4700. return
  4701. } else if deviceNumber == nil {
  4702. this.ErrorLog("床位号不存在")
  4703. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4704. return
  4705. }
  4706. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4707. //
  4708. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4709. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4710. // if getPermissionErr != nil {
  4711. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4712. // return
  4713. // } else if headNursePermission == nil {
  4714. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4715. // return
  4716. // }
  4717. //}
  4718. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4719. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4720. timeLayout := "2006-01-02 15:04:05"
  4721. loc, _ := time.LoadLocation("Local")
  4722. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4723. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4724. schedulestartTime := theStartTime.Unix()
  4725. scheduleendTime := theEndTime.Unix()
  4726. var theNucleinDate int64
  4727. timeLayoutOne := "2006-01-02"
  4728. if len(nuclein_date_str) > 0 {
  4729. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4730. if err != nil {
  4731. utils.ErrorLog(err.Error())
  4732. }
  4733. theNucleinDate = theTime.Unix()
  4734. }
  4735. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4736. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4737. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4738. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4739. if err == gorm.ErrRecordNotFound { //空床位
  4740. // 修改了床位逻辑
  4741. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4742. if daySchedule.ID > 0 {
  4743. //daySchedule.BedId = bedID
  4744. //daySchedule.PartitionId = deviceNumber.ZoneID
  4745. //daySchedule.ScheduleType = schedual_type
  4746. //daySchedule.UpdatedTime = time.Now().Unix()
  4747. //err := service.UpdateSchedule(&daySchedule)
  4748. xtSchedule := models.Schedule{
  4749. PartitionId: deviceNumber.ZoneID,
  4750. BedId: bedID,
  4751. ScheduleType: schedual_type,
  4752. UpdatedTime: time.Now().Unix(),
  4753. }
  4754. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4755. if err != nil {
  4756. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4757. return
  4758. }
  4759. }
  4760. } else if err == nil {
  4761. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4762. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4763. if daySchedule.ID > 0 {
  4764. //daySchedule.BedId = bedID
  4765. //daySchedule.PartitionId = deviceNumber.ZoneID
  4766. //
  4767. //daySchedule.ScheduleType = schedual_type
  4768. //daySchedule.UpdatedTime = time.Now().Unix()
  4769. //err := service.UpdateSchedule(&daySchedule)
  4770. xtSchedule := models.Schedule{
  4771. PartitionId: deviceNumber.ZoneID,
  4772. BedId: bedID,
  4773. ScheduleType: schedual_type,
  4774. UpdatedTime: time.Now().Unix(),
  4775. }
  4776. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4777. if err != nil {
  4778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4779. return
  4780. }
  4781. }
  4782. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4783. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4784. return
  4785. }
  4786. } else if err != nil {
  4787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4788. return
  4789. }
  4790. }
  4791. dialysisRecord := &models.DialysisOrder{
  4792. ID: record_id,
  4793. UserOrgId: adminUserInfo.Org.Id,
  4794. BedID: bedID,
  4795. StartNurse: nurseID,
  4796. StartTime: startDate.Unix(),
  4797. PunctureNurse: puncture_nurse,
  4798. Creator: adminUserInfo.AdminUser.Id,
  4799. Modifier: adminUserInfo.AdminUser.Id,
  4800. WashpipeNurse: washpipe_nurse,
  4801. SchedualType: schedual_type,
  4802. ChangeNurse: change_nurse,
  4803. DifficultPunctureNurse: difficult_puncture_nurse,
  4804. NewFistulaNurse: new_fistula_nurse,
  4805. QualityNurseId: quality_nurse_id,
  4806. PunctureNeedle: puncture_needle,
  4807. PunctureWay: puncture_way,
  4808. DialysisDialyszers: dialysis_dialyszers,
  4809. DialysisIrrigation: dialysis_irrigation,
  4810. BloodAccessId: blood_access_id,
  4811. NucleinDate: theNucleinDate,
  4812. OrderRemark: order_remark,
  4813. ScheduleRemark: schedule_remark,
  4814. CatheterOperation: catheter_operation,
  4815. BloodFlowVolume: blood_flow_volume,
  4816. BloodDrawing: blood_drawing,
  4817. DialysisStrainer: dialysis_strainer,
  4818. }
  4819. //修改床位号需要重新消毒
  4820. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4821. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4822. //查询第一条监测
  4823. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4824. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4825. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4826. redis := service.RedisClient()
  4827. //清空key 值
  4828. redis.Set(key, "", time.Second)
  4829. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4830. redis.Set(keyOne, "", time.Second)
  4831. defer redis.Close()
  4832. }
  4833. // 查询信息规挡的设置天数
  4834. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4835. if infor.ID > 0 && infor.WeekDay > 0 {
  4836. var cha_time int64
  4837. timeNowStr := time.Now().Format("2006-01-02")
  4838. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4839. //今日的日期减去设置的日期
  4840. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4841. if cha_time >= record_date {
  4842. //查询审核是否允许
  4843. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4844. //申请状态不允许的情况 拒绝修改
  4845. if infor.ApplicationStatus != 1 {
  4846. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4847. return
  4848. }
  4849. }
  4850. }
  4851. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4852. //修改床位后重新生成消毒计划
  4853. if adminUserInfo.Org.Id == 10340 {
  4854. //根据床位号获取设备型号
  4855. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4856. //查询使用消毒最后一条消毒记录
  4857. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4858. fmt.Println("err", err)
  4859. if err == gorm.ErrRecordNotFound {
  4860. //查找排班
  4861. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4862. //查询改设备是否有消毒计划
  4863. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4864. //根据床位号获取设备id
  4865. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4866. //查询病人信息
  4867. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4868. var con = ""
  4869. if patients.IsInfectious == 0 {
  4870. con = ""
  4871. }
  4872. if patients.IsInfectious == 1 {
  4873. con = "无"
  4874. }
  4875. if patients.IsInfectious == 2 {
  4876. con = "有"
  4877. }
  4878. if errcode == nil {
  4879. var end_time int64
  4880. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4881. //新增消毒
  4882. information := models.DeviceInformation{
  4883. Date: dialysisRecord.DialysisDate,
  4884. Zone: dialysisRecord.ZoneId,
  4885. Class: dialysisRecord.SchedualType,
  4886. BedNumber: dialysisRecord.BedID,
  4887. PatientId: dialysisRecord.PatientId,
  4888. DialysisMode: scheduleByPatient.ModeId,
  4889. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4890. Disinfection: 1,
  4891. DialysisConcentration: 1,
  4892. DisinfectionStatus: 1,
  4893. Move: 1,
  4894. UserOrgId: dialysisRecord.UserOrgId,
  4895. DisinfectType: plan.Way,
  4896. DisinfectantType: plan.MachineDisinfectant,
  4897. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4898. Disinfectant: plan.Disinfectant,
  4899. Ctime: time.Now().Unix(),
  4900. Status: 1,
  4901. SignName: nurseID,
  4902. EquimentId: addmacher.ID,
  4903. DisinfectionResidue: 2,
  4904. Bed: addmacher.BedNumber,
  4905. StartTime: dialysisRecord.StartTime,
  4906. EndTime: dialysisRecord.EndTime,
  4907. Contagion: con,
  4908. WeightLoss: 0,
  4909. Hyperfiltratio: 0,
  4910. DialysisHour: "",
  4911. MachineRun: 1,
  4912. DisinfecStartime: dialysisRecord.EndTime,
  4913. DisinfecEndtime: end_time,
  4914. }
  4915. err := service.CreateInformationTwo(&information)
  4916. fmt.Println("报错", err)
  4917. }
  4918. }
  4919. }
  4920. order, _ := service.GetLastPatientOrder(record_id)
  4921. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4922. redis := service.RedisClient()
  4923. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4924. redis.Set(key, "", time.Second)
  4925. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4926. //清空key 值
  4927. redis.Set(keyOne, "", time.Second)
  4928. scheduleDateStartOne := startDate.Format("2006-01-02")
  4929. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4930. redis.Set(keyTwo, "", time.Second)
  4931. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4932. redis.Set(keyThree, "", time.Second)
  4933. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4934. redis.Set(keyFour, "", time.Second)
  4935. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4936. redis.Set(keyFive, "", time.Second)
  4937. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4938. redis.Set(keySix, "", time.Second)
  4939. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4940. redis.Set(keySeven, "", time.Second)
  4941. if updateErr != nil {
  4942. this.ErrorLog("修改上机失败:%v", updateErr)
  4943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4944. return
  4945. }
  4946. if updateErr == nil {
  4947. if tempDialysisRecord.Stage == 2 {
  4948. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4949. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4950. fmt.Println(value)
  4951. a, b := math.Modf(value)
  4952. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4953. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4954. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4955. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4956. redis := service.RedisClient()
  4957. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4958. redis.Set(key, "", time.Second)
  4959. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4960. redis.Set(keyOne, "", time.Second)
  4961. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4962. //清空key 值
  4963. redis.Set(keySix, "", time.Second)
  4964. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4965. redis.Set(keySeven, "", time.Second)
  4966. redis.Close()
  4967. if updateAssessmentErr != nil {
  4968. utils.ErrorLog("%v", updateAssessmentErr)
  4969. }
  4970. }
  4971. }
  4972. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4973. this.ServeSuccessJSON(map[string]interface{}{
  4974. "dialysis_order": dialysisRecords,
  4975. })
  4976. }
  4977. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4978. record_id, _ := c.GetInt64("id")
  4979. nurseID, _ := c.GetInt64("nurse")
  4980. end_time := c.GetString("end_time")
  4981. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4982. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4983. catheter := c.GetString("catheter")
  4984. cruor := c.GetString("cruor")
  4985. mission := c.GetString("mission")
  4986. condenser := c.GetString("condenser")
  4987. if record_id <= 0 || nurseID <= 0 {
  4988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4989. return
  4990. }
  4991. adminUserInfo := c.GetMobileAdminUserInfo()
  4992. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4993. if getNurseErr != nil {
  4994. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4996. return
  4997. } else if nurse == nil {
  4998. c.ErrorLog("护士不存在")
  4999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5000. return
  5001. }
  5002. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5003. if parseEndDateErr != nil {
  5004. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5006. return
  5007. }
  5008. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5009. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5010. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5011. // if getPermissionErr != nil {
  5012. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5013. // return
  5014. // } else if headNursePermission == nil {
  5015. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5016. // return
  5017. // }
  5018. //}
  5019. // 查询信息规挡的设置天数
  5020. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5021. if infor.ID > 0 {
  5022. var cha_time int64
  5023. timeNowStr := time.Now().Format("2006-01-02")
  5024. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5025. //今日的日期减去设置的日期
  5026. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5027. if cha_time >= tempDialysisRecords.DialysisDate {
  5028. //查询审核是否允许
  5029. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5030. //申请状态不允许的情况 拒绝修改
  5031. if infor.ApplicationStatus != 1 {
  5032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5033. return
  5034. }
  5035. }
  5036. }
  5037. dialysisRecord := &models.DialysisOrder{
  5038. ID: record_id,
  5039. UserOrgId: adminUserInfo.Org.Id,
  5040. EndTime: endDate.Unix(),
  5041. FinishNurse: nurseID,
  5042. FinishModifier: adminUserInfo.AdminUser.Id,
  5043. PuncturePointHaematoma: puncture_point_haematoma,
  5044. BloodAccessInternalFistula: blood_access_internal_fistula,
  5045. Catheter: catheter,
  5046. Cruor: cruor,
  5047. Mission: mission,
  5048. Condenser: condenser,
  5049. }
  5050. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5051. redis := service.RedisClient()
  5052. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5053. //清空key 值
  5054. redis.Set(key, "", time.Second)
  5055. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5056. //清空key 值
  5057. redis.Set(keyOne, "", time.Second)
  5058. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5059. redis.Set(keySeven, "", time.Second)
  5060. redis.Close()
  5061. if updateErr != nil {
  5062. c.ErrorLog("修改下机失败:%v", updateErr)
  5063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5064. return
  5065. }
  5066. if updateErr == nil {
  5067. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5068. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5069. a, b := math.Modf(value)
  5070. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5071. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5072. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5073. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5074. redis := service.RedisClient()
  5075. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5076. redis.Set(keyTen, "", time.Second)
  5077. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5078. redis.Set(keyTwo, "", time.Second)
  5079. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5080. redis.Set(key, "", time.Second)
  5081. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5082. redis.Set(keyThree, "", time.Second)
  5083. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5084. redis.Set(keySeven, "", time.Second)
  5085. defer redis.Close()
  5086. if updateAssessmentErr != nil {
  5087. utils.ErrorLog("%v", updateAssessmentErr)
  5088. }
  5089. }
  5090. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5091. c.ServeSuccessJSON(map[string]interface{}{
  5092. "dialysis_order": dialysisRecords,
  5093. })
  5094. }
  5095. func (c *DialysisAPIController) GetLongAdvice() {
  5096. patient_id, _ := c.GetInt64("id")
  5097. adminUserInfo := c.GetMobileAdminUserInfo()
  5098. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5099. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5100. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5101. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5102. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5103. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5104. c.ServeSuccessJSON(map[string]interface{}{
  5105. "status": "1",
  5106. })
  5107. return
  5108. } else { //开启推送提醒
  5109. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5110. var advice_three []*models.DoctorAdvice
  5111. recordDateStr := time.Now().Format("2006-01-02")
  5112. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5113. nowtime := recordDate.Unix()
  5114. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5115. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5116. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5117. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5118. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5119. for _, advice := range advices {
  5120. if advice.FrequencyType == 3 {
  5121. t := time.Now()
  5122. week := int(t.Weekday())
  5123. fmt.Println(t.Weekday())
  5124. fmt.Println(week)
  5125. switch week {
  5126. case 1:
  5127. if strings.Index(advice.WeekDay, "周一") == -1 {
  5128. advice_three = append(advice_three, advice)
  5129. }
  5130. break
  5131. case 2:
  5132. if strings.Index(advice.WeekDay, "周二") == -1 {
  5133. advice_three = append(advice_three, advice)
  5134. }
  5135. break
  5136. case 3:
  5137. if strings.Index(advice.WeekDay, "周三") == -1 {
  5138. advice_three = append(advice_three, advice)
  5139. }
  5140. break
  5141. case 4:
  5142. if strings.Index(advice.WeekDay, "周四") == -1 {
  5143. advice_three = append(advice_three, advice)
  5144. }
  5145. break
  5146. case 5:
  5147. if strings.Index(advice.WeekDay, "周五") == -1 {
  5148. advice_three = append(advice_three, advice)
  5149. }
  5150. break
  5151. case 6:
  5152. if strings.Index(advice.WeekDay, "周六") == -1 {
  5153. advice_three = append(advice_three, advice)
  5154. }
  5155. break
  5156. case 0:
  5157. if strings.Index(advice.WeekDay, "周日") == -1 {
  5158. advice_three = append(advice_three, advice)
  5159. }
  5160. break
  5161. }
  5162. }
  5163. }
  5164. for _, advice := range advices_two {
  5165. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5166. now := p.Unix()
  5167. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5168. dayStr2 := "-" + dayStr
  5169. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5170. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5171. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5172. for _, ad := range advices {
  5173. advice_three = append(advice_three, ad)
  5174. }
  5175. }
  5176. if err == nil {
  5177. c.ServeSuccessJSON(map[string]interface{}{
  5178. "status": "2",
  5179. "advices": advices,
  5180. "advices_two": RemoveRepeatedElement(advice_three),
  5181. "is_open_remind": config.IsOpenRemind,
  5182. "his_config_open": hisConfig.IsOpen,
  5183. "is_advice_open": is_advice_open.IsAdviceOpen,
  5184. "prescription_open": prescription_open.IsOpen,
  5185. })
  5186. }
  5187. }
  5188. }
  5189. func (c *DialysisAPIController) GetLongAdviceOne() {
  5190. patient_id, _ := c.GetInt64("id")
  5191. startTime := c.GetString("schedule_date")
  5192. timeLayout := "2006-01-02"
  5193. loc, _ := time.LoadLocation("Local")
  5194. var theStartTime int64
  5195. if len(startTime) > 0 {
  5196. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5197. if err != nil {
  5198. utils.ErrorLog(err.Error())
  5199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5200. return
  5201. }
  5202. theStartTime = theTime.Unix()
  5203. }
  5204. adminUserInfo := c.GetMobileAdminUserInfo()
  5205. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5206. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5207. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5208. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5209. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5210. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5211. c.ServeSuccessJSON(map[string]interface{}{
  5212. "status": "1",
  5213. })
  5214. return
  5215. } else { //开启推送提醒
  5216. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5217. var advice_three []*models.DoctorAdvice
  5218. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5219. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5220. for _, advice := range advices {
  5221. if advice.FrequencyType == 3 {
  5222. t := time.Now()
  5223. week := int(t.Weekday())
  5224. fmt.Println(t.Weekday())
  5225. fmt.Println(week)
  5226. switch week {
  5227. case 1:
  5228. if strings.Index(advice.WeekDay, "周一") == -1 {
  5229. advice_three = append(advice_three, advice)
  5230. }
  5231. break
  5232. case 2:
  5233. if strings.Index(advice.WeekDay, "周二") == -1 {
  5234. advice_three = append(advice_three, advice)
  5235. }
  5236. break
  5237. case 3:
  5238. if strings.Index(advice.WeekDay, "周三") == -1 {
  5239. advice_three = append(advice_three, advice)
  5240. }
  5241. break
  5242. case 4:
  5243. if strings.Index(advice.WeekDay, "周四") == -1 {
  5244. advice_three = append(advice_three, advice)
  5245. }
  5246. break
  5247. case 5:
  5248. if strings.Index(advice.WeekDay, "周五") == -1 {
  5249. advice_three = append(advice_three, advice)
  5250. }
  5251. break
  5252. case 6:
  5253. if strings.Index(advice.WeekDay, "周六") == -1 {
  5254. advice_three = append(advice_three, advice)
  5255. }
  5256. break
  5257. case 0:
  5258. if strings.Index(advice.WeekDay, "周日") == -1 {
  5259. advice_three = append(advice_three, advice)
  5260. }
  5261. break
  5262. }
  5263. }
  5264. }
  5265. for _, advice := range advices_two {
  5266. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5267. now := p.Unix()
  5268. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5269. dayStr2 := "-" + dayStr
  5270. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5271. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5272. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5273. for _, ad := range advices {
  5274. advice_three = append(advice_three, ad)
  5275. }
  5276. }
  5277. if err == nil {
  5278. c.ServeSuccessJSON(map[string]interface{}{
  5279. "status": "2",
  5280. "advices": advices,
  5281. "advices_two": RemoveRepeatedElement(advice_three),
  5282. "is_open_remind": config.IsOpenRemind,
  5283. "his_config_open": hisConfig.IsOpen,
  5284. "is_advice_open": is_advice_open.IsAdviceOpen,
  5285. "prescription_open": prescription_open.IsOpen,
  5286. })
  5287. }
  5288. }
  5289. }
  5290. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5291. newArr = make([]*models.DoctorAdvice, 0)
  5292. for i := 0; i < len(arr); i++ {
  5293. repeat := false
  5294. for j := i + 1; j < len(arr); j++ {
  5295. if arr[i].ID == arr[j].ID {
  5296. repeat = true
  5297. break
  5298. }
  5299. }
  5300. if !repeat {
  5301. newArr = append(newArr, arr[i])
  5302. }
  5303. }
  5304. return
  5305. }
  5306. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5307. patient, _ := c.GetInt64("id", 0)
  5308. groupNo, _ := c.GetInt64("groupno", 0)
  5309. if patient <= 0 {
  5310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5311. return
  5312. }
  5313. adminUserInfo := c.GetMobileAdminUserInfo()
  5314. dataBody := make(map[string]interface{}, 0)
  5315. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5316. if err != nil {
  5317. utils.ErrorLog(err.Error())
  5318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5319. return
  5320. }
  5321. utils.ErrorLog("%v", dataBody)
  5322. timeLayout := "2006-01-02 15:04"
  5323. loc, _ := time.LoadLocation("Local")
  5324. timeLayout2 := "2006-01-02"
  5325. loc2, _ := time.LoadLocation("Local")
  5326. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5327. utils.ErrorLog("advice_type")
  5328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5329. return
  5330. }
  5331. adviceType := int64(2)
  5332. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5333. utils.ErrorLog("advice_date")
  5334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5335. return
  5336. }
  5337. adviceDate, _ := dataBody["advice_date"].(string)
  5338. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5339. AdviceDate := theTime.Unix()
  5340. RecordDate := theTime.Unix()
  5341. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5342. utils.ErrorLog("start_time")
  5343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5344. return
  5345. }
  5346. startTime, _ := dataBody["start_time"].(string)
  5347. if len(startTime) == 0 {
  5348. utils.ErrorLog("len(start_time) == 0")
  5349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5350. return
  5351. }
  5352. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5353. if err != nil {
  5354. utils.ErrorLog(err.Error())
  5355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5356. return
  5357. }
  5358. StartTime := theTime.Unix()
  5359. Remark := ""
  5360. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5361. remark, _ := dataBody["remark"].(string)
  5362. Remark = remark
  5363. }
  5364. var advices []*models.GroupAdvice
  5365. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5366. utils.ErrorLog("advices")
  5367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5368. return
  5369. }
  5370. adviceNames := dataBody["advices"].([]interface{})
  5371. for _, adviceNameMap := range adviceNames {
  5372. adviceNameM := adviceNameMap.(map[string]interface{})
  5373. var advice models.GroupAdvice
  5374. advice.Remark = Remark
  5375. advice.AdviceType = adviceType
  5376. advice.StartTime = StartTime
  5377. advice.AdviceDate = AdviceDate
  5378. advice.RecordDate = RecordDate
  5379. advice.Status = 1
  5380. advice.CreatedTime = time.Now().Unix()
  5381. advice.UpdatedTime = time.Now().Unix()
  5382. advice.StopState = 2
  5383. advice.ExecutionState = 2
  5384. advice.UserOrgId = adminUserInfo.Org.Id
  5385. advice.PatientId = patient
  5386. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5387. advice.IsSettle = 2
  5388. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5389. utils.ErrorLog("advice_name")
  5390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5391. return
  5392. }
  5393. adviceName, _ := adviceNameM["advice_name"].(string)
  5394. if len(adviceName) == 0 {
  5395. utils.ErrorLog("len(advice_name) == 0")
  5396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5397. return
  5398. }
  5399. advice.AdviceName = adviceName
  5400. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5401. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5402. advice.DrugSpec = drugSpec
  5403. }
  5404. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5405. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5406. advice.AdviceDesc = adviceDesc
  5407. }
  5408. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5409. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5410. advice.DrugSpecUnit = drugSpecUnit
  5411. }
  5412. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5413. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5414. // advice.SingleDose = singleDose
  5415. //}
  5416. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5417. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5418. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5419. }
  5420. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5421. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5422. advice.SingleDoseUnit = singleDoseUnit
  5423. }
  5424. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5425. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5426. // advice.PrescribingNumber = prescribingNumber
  5427. //}
  5428. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5429. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5430. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5431. }
  5432. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5433. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5434. advice.PrescribingNumberUnit = prescribingNumberUnit
  5435. }
  5436. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5437. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5438. advice.DeliveryWay = deliveryWay
  5439. }
  5440. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5441. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5442. advice.ExecutionFrequency = executionFrequency
  5443. }
  5444. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5445. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5446. advice.FrequencyType = frequency_type
  5447. }
  5448. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5449. day_count := int64(adviceNameM["day_count"].(float64))
  5450. advice.DayCount = day_count
  5451. }
  5452. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5453. week_day, _ := adviceNameM["week_day"].(string)
  5454. advice.WeekDay = week_day
  5455. }
  5456. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5457. way := int64(adviceNameM["way"].(float64))
  5458. advice.Way = way
  5459. }
  5460. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5461. drug_id := int64(adviceNameM["drug_id"].(float64))
  5462. advice.DrugId = drug_id
  5463. }
  5464. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5465. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5466. advice.DrugNameId = drug_name_id
  5467. }
  5468. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5469. remark, _ := adviceNameM["remark"].(string)
  5470. advice.Remark = remark
  5471. }
  5472. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5473. groupno := int64(adviceNameM["groupno"].(float64))
  5474. advice.GroupNo = groupno
  5475. }
  5476. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5477. template_id, _ := adviceNameM["template_id"].(string)
  5478. advice.TemplateId = template_id
  5479. }
  5480. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5481. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5482. advice.ExecutionFrequency = executionFrequency
  5483. }
  5484. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5485. children := adviceNameM["child"].([]interface{})
  5486. if len(children) > 0 {
  5487. for _, childrenMap := range children {
  5488. childMap := childrenMap.(map[string]interface{})
  5489. var child models.GroupAdvice
  5490. child.Remark = Remark
  5491. child.AdviceType = adviceType
  5492. child.StartTime = StartTime
  5493. child.AdviceDate = AdviceDate
  5494. child.RecordDate = RecordDate
  5495. child.Status = 1
  5496. child.CreatedTime = time.Now().Unix()
  5497. child.UpdatedTime = time.Now().Unix()
  5498. child.StopState = 2
  5499. child.ExecutionState = 2
  5500. child.UserOrgId = adminUserInfo.Org.Id
  5501. child.PatientId = patient
  5502. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5503. child.IsSettle = 1
  5504. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5505. utils.ErrorLog("child advice_name")
  5506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5507. return
  5508. }
  5509. childAdviceName, _ := childMap["advice_name"].(string)
  5510. if len(childAdviceName) == 0 {
  5511. utils.ErrorLog("len(child advice_name) == 0")
  5512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5513. return
  5514. }
  5515. child.AdviceName = childAdviceName
  5516. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5517. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5518. child.AdviceDesc = childAdviceDesc
  5519. }
  5520. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5521. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5522. child.DrugSpec = childDrugSpec
  5523. }
  5524. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5525. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5526. child.DrugSpecUnit = childDrugSpecUnit
  5527. }
  5528. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5529. child.SingleDose = childMap["single_dose"].(float64)
  5530. }
  5531. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5532. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5533. child.SingleDoseUnit = childSingleDoseUnit
  5534. }
  5535. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5536. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5537. }
  5538. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5539. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5540. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5541. }
  5542. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5543. groupno := int64(childMap["groupno"].(float64))
  5544. advice.GroupNo = groupno
  5545. }
  5546. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5547. remark, _ := childMap["remark"].(string)
  5548. child.Remark = remark
  5549. }
  5550. child.DeliveryWay = advice.DeliveryWay
  5551. child.ExecutionFrequency = advice.ExecutionFrequency
  5552. advice.Children = append(advice.Children, &child)
  5553. }
  5554. }
  5555. }
  5556. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5557. if temp_advice.ID == 0 {
  5558. advices = append(advices, &advice)
  5559. }
  5560. }
  5561. if len(advices) > 0 {
  5562. finish := models.XtDialysisFinish{
  5563. IsFinish: 1,
  5564. UserOrgId: adminUserInfo.Org.Id,
  5565. Status: 1,
  5566. Ctime: time.Now().Unix(),
  5567. Mtime: 0,
  5568. Module: 4,
  5569. RecordDate: AdviceDate,
  5570. Sourse: 1,
  5571. PatientId: patient,
  5572. }
  5573. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5574. if dialysisFinish.ID == 0 {
  5575. service.CreateDialysisFinish(finish)
  5576. }
  5577. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5578. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5579. for _, item := range advices {
  5580. byterequest, _ := json.Marshal(item)
  5581. adviceLog := models.XtDoctorAdviceLog{
  5582. UserOrgId: adminUserInfo.Org.Id,
  5583. PatientId: patient,
  5584. AdminUserId: adminUserInfo.AdminUser.Id,
  5585. Module: 1,
  5586. ErrLog: string(byterequest),
  5587. Status: 1,
  5588. Ctime: time.Now().Unix(),
  5589. Mtime: 0,
  5590. Source: "手机端医嘱推送",
  5591. RecordDate: item.AdviceDate,
  5592. }
  5593. service.CreateDoctorAdviceLog(adviceLog)
  5594. }
  5595. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5596. redis := service.RedisClient()
  5597. //清空key 值
  5598. redis.Set(key, "", time.Second)
  5599. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5600. redis.Set(keyOne, "", time.Second)
  5601. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5602. defer redis.Close()
  5603. redis.Set(keyThree, "", time.Second)
  5604. if err != nil {
  5605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5606. return
  5607. }
  5608. c.ServeSuccessJSON(map[string]interface{}{
  5609. "msg": "ok",
  5610. "advices": list,
  5611. })
  5612. } else {
  5613. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5614. for _, item := range advices {
  5615. byterequest, _ := json.Marshal(item)
  5616. adviceLog := models.XtDoctorAdviceLog{
  5617. UserOrgId: adminUserInfo.Org.Id,
  5618. PatientId: patient,
  5619. AdminUserId: adminUserInfo.AdminUser.Id,
  5620. Module: 1,
  5621. ErrLog: string(byterequest),
  5622. Status: 1,
  5623. Ctime: time.Now().Unix(),
  5624. Mtime: 0,
  5625. Source: "手机端医嘱推送",
  5626. RecordDate: item.AdviceDate,
  5627. }
  5628. service.CreateDoctorAdviceLog(adviceLog)
  5629. }
  5630. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5631. redis := service.RedisClient()
  5632. //清空key 值
  5633. redis.Set(key, "", time.Second)
  5634. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5635. redis.Set(keyOne, "", time.Second)
  5636. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5637. defer redis.Close()
  5638. redis.Set(keyThree, "", time.Second)
  5639. if err != nil {
  5640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5641. return
  5642. }
  5643. c.ServeSuccessJSON(map[string]interface{}{
  5644. "msg": "ok",
  5645. "advices": list,
  5646. })
  5647. }
  5648. } else {
  5649. c.ServeSuccessJSON(map[string]interface{}{
  5650. "msg": "ok",
  5651. })
  5652. }
  5653. return
  5654. }
  5655. func (c *DialysisAPIController) UploadDryWeight() {
  5656. patient_id, _ := c.GetInt64("id")
  5657. dry_weight, _ := c.GetFloat("dry_weight")
  5658. doctor_id, _ := c.GetInt64("doctor_id")
  5659. remark := c.GetString("remark")
  5660. adminUserInfo := c.GetMobileAdminUserInfo()
  5661. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5662. if err == gorm.ErrRecordNotFound {
  5663. dryWeight := &models.SgjPatientDryweight{
  5664. PatientId: patient_id,
  5665. DryWeight: dry_weight,
  5666. Remakes: remark,
  5667. Ctime: time.Now().Unix(),
  5668. Mtime: time.Now().Unix(),
  5669. Creator: doctor_id,
  5670. Status: 1,
  5671. UserOrgId: adminUserInfo.Org.Id,
  5672. AdjustedValue: "/",
  5673. UserId: adminUserInfo.AdminUser.Id,
  5674. }
  5675. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5676. redis := service.RedisClient()
  5677. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5678. redis.Set(keyOne, "", time.Second)
  5679. loc, _ := time.LoadLocation("Local")
  5680. nowTime := time.Now()
  5681. nowDay := nowTime.Format("2006-01-02")
  5682. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5683. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5684. redis.Set(key, "", time.Second)
  5685. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5686. redis.Set(keyTwo, "", time.Second)
  5687. redis.Close()
  5688. if createErr == nil {
  5689. c.ServeSuccessJSON(map[string]interface{}{
  5690. "msg": "提交成功",
  5691. "weight": dryWeight,
  5692. })
  5693. }
  5694. } else {
  5695. dryWeight := &models.SgjPatientDryweight{
  5696. PatientId: patient_id,
  5697. DryWeight: dry_weight,
  5698. Remakes: remark,
  5699. Ctime: time.Now().Unix(),
  5700. Mtime: time.Now().Unix(),
  5701. Creator: doctor_id,
  5702. Status: 1,
  5703. UserOrgId: adminUserInfo.Org.Id,
  5704. AdjustedValue: "/",
  5705. UserId: adminUserInfo.AdminUser.Id,
  5706. }
  5707. var value float64
  5708. value = dry_weight - weightAdjust.DryWeight
  5709. if value < 0 {
  5710. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5711. } else if value == 0 {
  5712. dryWeight.AdjustedValue = "/"
  5713. } else if value > 0 {
  5714. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5715. }
  5716. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5717. //康桥
  5718. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5719. timeNowStr := time.Now().Format("2006-01-02")
  5720. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5721. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5722. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5723. if beforAssesment.ID > 0 {
  5724. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5725. var dewater_amount float64
  5726. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5727. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5728. //获取key,清空redis
  5729. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5730. redis := service.RedisClient()
  5731. //清空key 值
  5732. redis.Set(key, "", time.Second)
  5733. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5734. //清空key 值
  5735. redis.Set(keyOne, "", time.Second)
  5736. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5737. //清空key 值
  5738. redis.Set(keyTwo, "", time.Second)
  5739. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5740. redis.Set(keySix, "", time.Second)
  5741. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5742. redis.Set(keySeven, "", time.Second)
  5743. }
  5744. }
  5745. redis := service.RedisClient()
  5746. loc, _ := time.LoadLocation("Local")
  5747. nowTime := time.Now()
  5748. nowDay := nowTime.Format("2006-01-02")
  5749. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5750. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5751. redis.Set(keyOne, "", time.Second)
  5752. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5753. redis.Set(key, "", time.Second)
  5754. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5755. redis.Set(keyTwo, "", time.Second)
  5756. redis.Close()
  5757. if createErr == nil {
  5758. c.ServeSuccessJSON(map[string]interface{}{
  5759. "msg": "提交成功",
  5760. "weight": dryWeight,
  5761. })
  5762. }
  5763. }
  5764. }
  5765. func (c *DialysisAPIController) GetSolution() {
  5766. patient_id, _ := c.GetInt64("patient_id")
  5767. mode_id, _ := c.GetInt64("mode_id")
  5768. adminUserInfo := c.GetMobileAdminUserInfo()
  5769. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5770. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5771. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5772. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5773. if err != nil {
  5774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5775. return
  5776. }
  5777. c.ServeSuccessJSON(map[string]interface{}{
  5778. "solution": solution,
  5779. "prescription": prescription,
  5780. "system_prescription": system_prescription,
  5781. "dialysisPrescription": dialysisPrescription,
  5782. })
  5783. }
  5784. func (c *DialysisAPIController) GetSchedule() {
  5785. schedual_type, _ := c.GetInt64("schedual_type")
  5786. adminUserInfo := c.GetMobileAdminUserInfo()
  5787. scheduleTime, _ := c.GetInt64("record_date")
  5788. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5789. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5790. c.ServeSuccessJSON(map[string]interface{}{
  5791. "number": deviceNumber,
  5792. "list": list,
  5793. })
  5794. }
  5795. func (c *DialysisAPIController) GetPatientId() {
  5796. id, _ := c.GetInt64("id")
  5797. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5798. patientId, _ := service.GetPatientId(id)
  5799. //获取该患者的所有传染病
  5800. list, _ := service.GetPatientInfectious(id)
  5801. c.ServeSuccessJSON(map[string]interface{}{
  5802. "patient": patientId,
  5803. "infectioulist": list,
  5804. })
  5805. }
  5806. func (this *DialysisAPIController) GetDialysisSchedule() {
  5807. schedualDate := this.GetString("date")
  5808. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5809. if parseDateErr != nil {
  5810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5811. return
  5812. }
  5813. adminInfo := this.GetMobileAdminUserInfo()
  5814. orgID := adminInfo.Org.Id
  5815. redis := service.RedisClient()
  5816. defer redis.Close()
  5817. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5818. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5819. if len(scheduals) > 0 {
  5820. //缓存数据
  5821. scheduals_json, err := json.Marshal(scheduals)
  5822. if err == nil {
  5823. redis.Set(key, scheduals_json, time.Second*30)
  5824. }
  5825. }
  5826. this.ServeSuccessJSON(map[string]interface{}{
  5827. "scheduals": scheduals,
  5828. })
  5829. }
  5830. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5831. change_type, _ := this.GetInt64("type", 0)
  5832. record_date := this.GetString("record_time")
  5833. patient_id, _ := this.GetInt64("patient_id", 0)
  5834. timeLayout := "2006-01-02"
  5835. loc, _ := time.LoadLocation("Local")
  5836. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5837. record_time := theAdviceRecordTime.Unix()
  5838. adminUserInfo := this.GetMobileAdminUserInfo()
  5839. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5840. if err == nil {
  5841. if len(advices) == 0 {
  5842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5843. return
  5844. } else {
  5845. this.ServeSuccessJSON(map[string]interface{}{
  5846. "advices": advices,
  5847. "schedule": sch,
  5848. })
  5849. return
  5850. }
  5851. } else {
  5852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5853. return
  5854. }
  5855. }
  5856. func (c *DialysisAPIController) CreateConsumables() {
  5857. record_date := c.GetString("record_time")
  5858. patient_id, _ := c.GetInt64("patient_id", 0)
  5859. active, _ := c.GetInt64("active")
  5860. adminUser := c.GetMobileAdminUserInfo()
  5861. timeLayout := "2006-01-02"
  5862. loc, _ := time.LoadLocation("Local")
  5863. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5864. record_time := theRecordTime.Unix()
  5865. // 查询信息规挡的设置天数
  5866. orgid := c.GetMobileAdminUserInfo().Org.Id
  5867. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5868. if infor.ID > 0 {
  5869. var cha_time int64
  5870. timeNowStr := time.Now().Format("2006-01-02")
  5871. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5872. //今日的日期减去设置的日期
  5873. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5874. if cha_time >= record_time {
  5875. //查询审核是否允许
  5876. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5877. //申请状态不允许的情况 拒绝修改
  5878. if infor.ApplicationStatus != 1 {
  5879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5880. return
  5881. }
  5882. }
  5883. }
  5884. dataBody := make(map[string]interface{}, 0)
  5885. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5886. if err != nil {
  5887. utils.ErrorLog(err.Error())
  5888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5889. return
  5890. }
  5891. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5892. var beforePrepares []*models.DialysisBeforePrepareGoods
  5893. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5894. var dialysisBefor []*models.DialysisBeforePrepare
  5895. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5896. goods, _ := dataBody["goods"].([]interface{})
  5897. if len(goods) > 0 {
  5898. for _, item := range goods {
  5899. items := item.(map[string]interface{})
  5900. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5901. utils.ErrorLog("good_id")
  5902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5903. return
  5904. }
  5905. good_id := int64(items["good_id"].(float64))
  5906. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5907. utils.ErrorLog("good_type_id")
  5908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5909. return
  5910. }
  5911. good_type_id := int64(items["good_type_id"].(float64))
  5912. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5913. utils.ErrorLog("count")
  5914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5915. return
  5916. }
  5917. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5918. commdity_code := items["commdity_code"].(string)
  5919. fmt.Println("commdity", commdity_code)
  5920. prepareGoods := &models.DialysisBeforePrepareGoods{
  5921. GoodTypeId: good_type_id,
  5922. GoodId: good_id,
  5923. Count: count,
  5924. StorehouseId: houseConfig.StorehouseOutInfo,
  5925. }
  5926. beforePrepares = append(beforePrepares, prepareGoods)
  5927. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5928. GoodTypeId: good_type_id,
  5929. GoodId: good_id,
  5930. Count: count,
  5931. StorehouseId: houseConfig.StorehouseOutInfo,
  5932. }
  5933. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5934. prepare := &models.DialysisBeforePrepare{
  5935. GoodTypeId: good_type_id,
  5936. GoodId: good_id,
  5937. Count: count,
  5938. PatientId: patient_id,
  5939. RecordDate: record_time,
  5940. UserOrgId: adminUser.Org.Id,
  5941. Status: 1,
  5942. Ctime: time.Now().Unix(),
  5943. Creater: adminUser.AdminUser.Id,
  5944. CommdityCode: commdity_code,
  5945. StorehouseId: houseConfig.StorehouseOutInfo,
  5946. }
  5947. dialysisBefor = append(dialysisBefor, prepare)
  5948. }
  5949. }
  5950. //查询是否有库存
  5951. for _, item := range dialysisBefor {
  5952. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5953. if err == gorm.ErrRecordNotFound {
  5954. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5955. c.ServeSuccessJSON(map[string]interface{}{
  5956. "message": "1",
  5957. "good_name": goodObj.GoodName,
  5958. "specification_name": goodObj.SpecificationName,
  5959. })
  5960. return
  5961. }
  5962. if err != nil {
  5963. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5964. c.ServeSuccessJSON(map[string]interface{}{
  5965. "message": "1",
  5966. "good_name": goodObj.GoodName,
  5967. "specification_name": goodObj.SpecificationName,
  5968. })
  5969. return
  5970. }
  5971. }
  5972. fmt.Println("active-----------------------", active)
  5973. fmt.Println("len(goods)-----------------------", len(goods))
  5974. //新增
  5975. if active == 1 && len(goods) > 0 {
  5976. for _, item := range dialysisBefor {
  5977. dialyPrepareOne := models.DialysisBeforePrepare{
  5978. GoodTypeId: item.GoodTypeId,
  5979. GoodId: item.GoodId,
  5980. PatientId: item.PatientId,
  5981. RecordDate: item.RecordDate,
  5982. UserOrgId: item.UserOrgId,
  5983. Count: item.Count,
  5984. Ctime: time.Now().Unix(),
  5985. Creater: item.Creater,
  5986. CommdityCode: item.CommdityCode,
  5987. Status: 1,
  5988. StorehouseId: houseConfig.StorehouseOutInfo,
  5989. }
  5990. //先清除再插入
  5991. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5992. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5993. //查询默认仓库
  5994. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5995. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5996. var total_count int64
  5997. for _, it := range stockList {
  5998. total_count += it.StockCount
  5999. }
  6000. //基础库插入数据
  6001. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6002. //更新库存
  6003. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6004. var flush_count int64
  6005. for _, it := range goodList {
  6006. flush_count += it.StockCount
  6007. }
  6008. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6009. }
  6010. if err == nil {
  6011. c.ServeSuccessJSON(map[string]interface{}{
  6012. "msg": "保存成功",
  6013. "message": "2",
  6014. })
  6015. return
  6016. } else {
  6017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6018. return
  6019. }
  6020. }
  6021. if len(beforePrepares) > 0 && active == 2 {
  6022. for _, item := range beforePrepares {
  6023. //1.查看该患者该耗材型号最后一次出库数量
  6024. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6025. //判断当前出库数量和最后一次出库数量的大小
  6026. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6027. if item.Count <= goodInfo.Count {
  6028. //退库
  6029. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6030. //查询今日出库数据
  6031. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6032. for _, it := range list {
  6033. prepare := models.DialysisBeforePrepare{
  6034. UserOrgId: it.OrgId,
  6035. PatientId: patient_id,
  6036. RecordDate: it.RecordTime,
  6037. GoodId: it.GoodId,
  6038. GoodTypeId: it.GoodTypeId,
  6039. Count: it.Count,
  6040. Ctime: time.Now().Unix(),
  6041. Creater: adminUser.AdminUser.Id,
  6042. Status: 1,
  6043. StorehouseId: houseConfig.StorehouseOutInfo,
  6044. }
  6045. //删除准备表数据
  6046. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6047. service.CreateDialysisBeforePrepareOne(&prepare)
  6048. }
  6049. }
  6050. var last_total int64
  6051. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6052. if item.Count >= goodInfo.Count {
  6053. //查询当前批次当前耗材最后一条出库数据
  6054. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6055. //计算当前出库和最后一次出库数据相差数据
  6056. last_total = item.Count - lastOutInfo.Count
  6057. //查询该批次剩余库存
  6058. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6059. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6060. if lastInfo.StockCount >= last_total {
  6061. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6062. //查询今日出库数据
  6063. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6064. for _, it := range list {
  6065. prepare := models.DialysisBeforePrepare{
  6066. UserOrgId: it.OrgId,
  6067. PatientId: patient_id,
  6068. RecordDate: it.RecordTime,
  6069. GoodId: it.GoodId,
  6070. GoodTypeId: it.GoodTypeId,
  6071. Count: it.Count,
  6072. Ctime: time.Now().Unix(),
  6073. Creater: adminUser.AdminUser.Id,
  6074. Status: 1,
  6075. StorehouseId: houseConfig.StorehouseOutInfo,
  6076. }
  6077. //删除准备表数据
  6078. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6079. service.CreateDialysisBeforePrepareOne(&prepare)
  6080. //查询默认仓库
  6081. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6082. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6083. var total_count int64
  6084. for _, it := range stockList {
  6085. total_count += it.StockCount
  6086. }
  6087. //基础库插入数据
  6088. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6089. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6090. var flush_count int64
  6091. for _, it := range goodList {
  6092. flush_count += it.StockCount
  6093. }
  6094. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6095. }
  6096. }
  6097. //如果库存不够,则出库到下一个批次
  6098. if lastInfo.StockCount < last_total {
  6099. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6100. //查询今日出库数据
  6101. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6102. for _, it := range list {
  6103. prepare := models.DialysisBeforePrepare{
  6104. UserOrgId: it.OrgId,
  6105. PatientId: patient_id,
  6106. RecordDate: it.RecordTime,
  6107. GoodId: it.GoodId,
  6108. GoodTypeId: it.GoodTypeId,
  6109. Count: it.Count,
  6110. Ctime: time.Now().Unix(),
  6111. Creater: adminUser.AdminUser.Id,
  6112. Status: 1,
  6113. StorehouseId: houseConfig.StorehouseOutInfo,
  6114. }
  6115. //删除准备表数据
  6116. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6117. service.CreateDialysisBeforePrepareOne(&prepare)
  6118. //查询默认仓库
  6119. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6120. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6121. var total_count int64
  6122. for _, it := range stockList {
  6123. total_count += it.StockCount
  6124. }
  6125. //基础库插入数据
  6126. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6127. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6128. var flush_count int64
  6129. for _, it := range goodList {
  6130. flush_count += it.StockCount
  6131. }
  6132. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6133. }
  6134. if err != nil {
  6135. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6136. c.ServeSuccessJSON(map[string]interface{}{
  6137. "message": "1",
  6138. "good_name": goodObj.GoodName,
  6139. "specification_name": goodObj.SpecificationName,
  6140. })
  6141. return
  6142. }
  6143. }
  6144. }
  6145. if err != nil {
  6146. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6147. c.ServeSuccessJSON(map[string]interface{}{
  6148. "message": "1",
  6149. "good_name": goodObj.GoodName,
  6150. "specification_name": goodObj.SpecificationName,
  6151. })
  6152. return
  6153. }
  6154. }
  6155. }
  6156. }
  6157. var errs error
  6158. if errs == nil {
  6159. c.ServeSuccessJSON(map[string]interface{}{
  6160. "msg": "提交成功",
  6161. "message": "2",
  6162. "good_name": "",
  6163. "specification_name": "",
  6164. })
  6165. return
  6166. } else {
  6167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6168. return
  6169. }
  6170. }
  6171. func (c *DialysisAPIController) CreateStockOutInfo() {
  6172. patient_id, _ := c.GetInt64("patient_id", 0)
  6173. record_date := c.GetString("record_time")
  6174. if patient_id <= 0 {
  6175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6176. return
  6177. }
  6178. adminInfo := c.GetMobileAdminUserInfo()
  6179. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6180. timeLayout := "2006-01-02"
  6181. loc, _ := time.LoadLocation("Local")
  6182. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6183. record_time := theRecordTime.Unix()
  6184. // 查询信息规挡的设置天数
  6185. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6186. if infor.ID > 0 && infor.WeekDay > 0 {
  6187. var cha_time int64
  6188. timeNowStr := time.Now().Format("2006-01-02")
  6189. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6190. //今日的日期减去设置的日期
  6191. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6192. if cha_time >= record_time {
  6193. //查询审核是否允许
  6194. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6195. //申请状态不允许的情况 拒绝修改
  6196. if infor.ApplicationStatus != 1 {
  6197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6198. return
  6199. }
  6200. }
  6201. }
  6202. //创建步骤表
  6203. finish := models.XtDialysisFinish{
  6204. IsFinish: 1,
  6205. UserOrgId: adminInfo.Org.Id,
  6206. Status: 1,
  6207. Ctime: time.Now().Unix(),
  6208. Mtime: 0,
  6209. Module: 11,
  6210. RecordDate: record_time,
  6211. Sourse: 1,
  6212. PatientId: patient_id,
  6213. }
  6214. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6215. if dialysisFinish.ID == 0 {
  6216. service.CreateDialysisFinish(finish)
  6217. }
  6218. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6219. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6220. //去重
  6221. consumables = RemoveRepeatedGood(consumables)
  6222. if adminInfo.Org.Id == 9919 {
  6223. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6224. //查询是否有库存
  6225. for _, item := range consumables {
  6226. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6227. if item.Count > warehouse.Count {
  6228. goodErrcode := models.XtGoodErrcode{
  6229. UserOrgId: item.UserOrgId,
  6230. Errcode: "自动出库库存不足",
  6231. GoodId: item.GoodId,
  6232. Status: 1,
  6233. Ctime: time.Now().Unix(),
  6234. Mtime: 0,
  6235. Count: 0,
  6236. StockCount: 0,
  6237. Creater: creator,
  6238. BatchNumberId: warehouse.ID,
  6239. WarehouseOutId: 0,
  6240. }
  6241. service.CreateGoodErrcode(goodErrcode)
  6242. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6243. c.ServeSuccessJSON(map[string]interface{}{
  6244. "message": "1",
  6245. "good_name": goodObj.GoodName,
  6246. "specification_name": goodObj.SpecificationName,
  6247. })
  6248. return
  6249. }
  6250. }
  6251. //查询是否有出库单
  6252. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6253. if err == gorm.ErrRecordNotFound {
  6254. //没有记录,则创建出库单
  6255. timeStr := time.Now().Format("2006-01-02")
  6256. timeArr := strings.Split(timeStr, "-")
  6257. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6258. total = total + 1
  6259. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6260. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6261. number = number + total
  6262. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6263. creater := adminInfo.AdminUser.Id
  6264. warehouseOut := models.WarehouseOut{
  6265. WarehouseOutOrderNumber: warehousing_out_order,
  6266. OperationTime: time.Now().Unix(),
  6267. OrgId: adminInfo.Org.Id,
  6268. Creater: creater,
  6269. Ctime: time.Now().Unix(),
  6270. Status: 1,
  6271. WarehouseOutTime: record_time,
  6272. Dealer: 0,
  6273. Manufacturer: 0,
  6274. Type: 1,
  6275. IsSys: 1,
  6276. StorehouseId: houseConfig.StorehouseOutInfo,
  6277. IsCheck: 1,
  6278. }
  6279. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6280. if err != nil {
  6281. goodErrcode := models.XtGoodErrcode{
  6282. UserOrgId: adminInfo.Org.Id,
  6283. Errcode: "创建出库单失败",
  6284. GoodId: 0,
  6285. Status: 1,
  6286. Ctime: time.Now().Unix(),
  6287. Mtime: 0,
  6288. Count: 0,
  6289. StockCount: 0,
  6290. Creater: creator,
  6291. BatchNumberId: 0,
  6292. WarehouseOutId: 0,
  6293. }
  6294. service.CreateGoodErrcode(goodErrcode)
  6295. utils.TraceLog("创建出库单失败 err = %v", err)
  6296. } else {
  6297. for _, item := range consumables {
  6298. //出库
  6299. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6300. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6301. if err == nil {
  6302. goodErrcode := models.XtGoodErrcode{
  6303. UserOrgId: adminInfo.Org.Id,
  6304. Errcode: "自动出库接口报错",
  6305. GoodId: 0,
  6306. Status: 1,
  6307. Ctime: time.Now().Unix(),
  6308. Mtime: 0,
  6309. Count: 0,
  6310. StockCount: 0,
  6311. Creater: creator,
  6312. BatchNumberId: 0,
  6313. WarehouseOutId: 0,
  6314. }
  6315. service.CreateGoodErrcode(goodErrcode)
  6316. utils.TraceLog("创建出库单失败 err = %v", err)
  6317. }
  6318. //查询
  6319. //出库数量相加
  6320. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6321. if errs != nil {
  6322. goodErrcode := models.XtGoodErrcode{
  6323. UserOrgId: item.UserOrgId,
  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. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6339. if len(list) == 0 {
  6340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6341. return
  6342. }
  6343. for _, item := range list {
  6344. prepare := models.DialysisBeforePrepare{
  6345. UserOrgId: adminInfo.Org.Id,
  6346. PatientId: patient_id,
  6347. RecordDate: record_time,
  6348. GoodId: item.GoodId,
  6349. GoodTypeId: item.GoodTypeId,
  6350. Count: item.Count,
  6351. Creater: adminInfo.AdminUser.Id,
  6352. Status: 1,
  6353. Ctime: time.Now().Unix(),
  6354. StorehouseId: houseConfig.StorehouseOutInfo,
  6355. }
  6356. //清空准备表数据
  6357. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6358. if err != nil {
  6359. goodErrcode := models.XtGoodErrcode{
  6360. UserOrgId: item.OrgId,
  6361. Errcode: "自动出库清空准备表数据报错",
  6362. GoodId: item.GoodId,
  6363. Status: 1,
  6364. Ctime: time.Now().Unix(),
  6365. Mtime: 0,
  6366. Count: 0,
  6367. StockCount: 0,
  6368. Creater: creater,
  6369. BatchNumberId: 0,
  6370. WarehouseOutId: 0,
  6371. }
  6372. service.CreateGoodErrcode(goodErrcode)
  6373. }
  6374. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6375. if errs != nil {
  6376. goodErrcode := models.XtGoodErrcode{
  6377. UserOrgId: item.OrgId,
  6378. Errcode: "自动出库创建准备表数据报错",
  6379. GoodId: item.GoodId,
  6380. Status: 1,
  6381. Ctime: time.Now().Unix(),
  6382. Mtime: 0,
  6383. Count: 0,
  6384. StockCount: 0,
  6385. Creater: creater,
  6386. BatchNumberId: 0,
  6387. WarehouseOutId: 0,
  6388. }
  6389. service.CreateGoodErrcode(goodErrcode)
  6390. }
  6391. //查询默认仓库
  6392. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6393. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6394. var total_count int64
  6395. for _, it := range stockList {
  6396. total_count += it.StockCount
  6397. }
  6398. //基础库插入数据
  6399. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6400. if errcodes != nil {
  6401. goodErrcode := models.XtGoodErrcode{
  6402. UserOrgId: item.OrgId,
  6403. Errcode: "自动出库基础库插入数据",
  6404. GoodId: item.GoodId,
  6405. Status: 1,
  6406. Ctime: time.Now().Unix(),
  6407. Mtime: 0,
  6408. Count: 0,
  6409. StockCount: 0,
  6410. Creater: creater,
  6411. BatchNumberId: 0,
  6412. WarehouseOutId: 0,
  6413. }
  6414. service.CreateGoodErrcode(goodErrcode)
  6415. }
  6416. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6417. var flush_count int64
  6418. for _, it := range goodList {
  6419. flush_count += it.StockCount
  6420. }
  6421. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6422. if errsss != nil {
  6423. goodErrcode := models.XtGoodErrcode{
  6424. UserOrgId: item.OrgId,
  6425. Errcode: "自动出库剩余库存更新数据",
  6426. GoodId: item.GoodId,
  6427. Status: 1,
  6428. Ctime: time.Now().Unix(),
  6429. Mtime: 0,
  6430. Count: 0,
  6431. StockCount: 0,
  6432. Creater: creater,
  6433. BatchNumberId: 0,
  6434. WarehouseOutId: 0,
  6435. }
  6436. service.CreateGoodErrcode(goodErrcode)
  6437. }
  6438. }
  6439. }
  6440. //
  6441. } else if err == nil {
  6442. for _, item := range consumables {
  6443. //出库
  6444. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6445. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6446. if err != nil {
  6447. goodErrcode := models.XtGoodErrcode{
  6448. UserOrgId: adminInfo.Org.Id,
  6449. Errcode: "自动出库接口报错",
  6450. GoodId: 0,
  6451. Status: 1,
  6452. Ctime: time.Now().Unix(),
  6453. Mtime: 0,
  6454. Count: 0,
  6455. StockCount: 0,
  6456. Creater: creator,
  6457. BatchNumberId: 0,
  6458. WarehouseOutId: 0,
  6459. }
  6460. service.CreateGoodErrcode(goodErrcode)
  6461. }
  6462. //出库数量相加
  6463. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6464. if errss != nil {
  6465. goodErrcode := models.XtGoodErrcode{
  6466. UserOrgId: item.UserOrgId,
  6467. Errcode: "创建剩余库存字段报错",
  6468. GoodId: item.GoodId,
  6469. Status: 1,
  6470. Ctime: time.Now().Unix(),
  6471. Mtime: time.Now().Unix(),
  6472. Count: 0,
  6473. StockCount: 0,
  6474. Creater: item.Creater,
  6475. BatchNumberId: 0,
  6476. WarehouseOutId: 0,
  6477. }
  6478. service.CreateGoodErrcode(goodErrcode)
  6479. }
  6480. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6481. if len(list) == 0 {
  6482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6483. return
  6484. }
  6485. for _, item := range list {
  6486. prepare := models.DialysisBeforePrepare{
  6487. UserOrgId: adminInfo.Org.Id,
  6488. PatientId: patient_id,
  6489. RecordDate: record_time,
  6490. GoodId: item.GoodId,
  6491. GoodTypeId: item.GoodTypeId,
  6492. Count: item.Count,
  6493. Creater: adminInfo.AdminUser.Id,
  6494. Status: 1,
  6495. Ctime: time.Now().Unix(),
  6496. StorehouseId: houseConfig.StorehouseOutInfo,
  6497. }
  6498. //清空准备表数据
  6499. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6500. if errs != nil {
  6501. goodErrcode := models.XtGoodErrcode{
  6502. UserOrgId: adminInfo.Org.Id,
  6503. Errcode: "自动出库清空准备表数据报错",
  6504. GoodId: 0,
  6505. Status: 1,
  6506. Ctime: time.Now().Unix(),
  6507. Mtime: 0,
  6508. Count: 0,
  6509. StockCount: 0,
  6510. Creater: creator,
  6511. BatchNumberId: 0,
  6512. WarehouseOutId: 0,
  6513. }
  6514. service.CreateGoodErrcode(goodErrcode)
  6515. }
  6516. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6517. if errcodes != nil {
  6518. goodErrcode := models.XtGoodErrcode{
  6519. UserOrgId: adminInfo.Org.Id,
  6520. Errcode: "自动出库创建准备表数据报错",
  6521. GoodId: 0,
  6522. Status: 1,
  6523. Ctime: time.Now().Unix(),
  6524. Mtime: 0,
  6525. Count: 0,
  6526. StockCount: 0,
  6527. Creater: creator,
  6528. BatchNumberId: 0,
  6529. WarehouseOutId: 0,
  6530. }
  6531. service.CreateGoodErrcode(goodErrcode)
  6532. }
  6533. //查询默认仓库
  6534. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6535. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6536. var total_count int64
  6537. for _, it := range stockList {
  6538. total_count += it.StockCount
  6539. }
  6540. //基础库插入数据
  6541. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6542. if errcodes != nil {
  6543. goodErrcode := models.XtGoodErrcode{
  6544. UserOrgId: adminInfo.Org.Id,
  6545. Errcode: "自动出库基础库插入数据报错",
  6546. GoodId: 0,
  6547. Status: 1,
  6548. Ctime: time.Now().Unix(),
  6549. Mtime: 0,
  6550. Count: 0,
  6551. StockCount: 0,
  6552. Creater: creator,
  6553. BatchNumberId: 0,
  6554. WarehouseOutId: 0,
  6555. }
  6556. service.CreateGoodErrcode(goodErrcode)
  6557. }
  6558. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6559. var flush_count int64
  6560. for _, it := range goodList {
  6561. flush_count += it.StockCount
  6562. }
  6563. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6564. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6565. if errss != nil {
  6566. goodErrcode := models.XtGoodErrcode{
  6567. UserOrgId: item.OrgId,
  6568. Errcode: "自动出库剩余库存更新数据",
  6569. GoodId: item.GoodId,
  6570. Status: 1,
  6571. Ctime: time.Now().Unix(),
  6572. Mtime: 0,
  6573. Count: 0,
  6574. StockCount: 0,
  6575. Creater: creater,
  6576. BatchNumberId: 0,
  6577. WarehouseOutId: 0,
  6578. }
  6579. service.CreateGoodErrcode(goodErrcode)
  6580. }
  6581. }
  6582. }
  6583. }
  6584. c.ServeSuccessJSON(map[string]interface{}{
  6585. "msg": "提交成功",
  6586. "message": "2",
  6587. "good_name": "",
  6588. "specification_name": "",
  6589. })
  6590. return
  6591. }
  6592. if record.IsOpen == 1 {
  6593. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6594. //查询是否有库存
  6595. for _, item := range consumables {
  6596. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6597. if item.Count > warehouse.Count {
  6598. goodErrcode := models.XtGoodErrcode{
  6599. UserOrgId: item.UserOrgId,
  6600. Errcode: "自动出库库存不足",
  6601. GoodId: item.GoodId,
  6602. Status: 1,
  6603. Ctime: time.Now().Unix(),
  6604. Mtime: 0,
  6605. Count: 0,
  6606. StockCount: 0,
  6607. Creater: creator,
  6608. BatchNumberId: warehouse.ID,
  6609. WarehouseOutId: 0,
  6610. }
  6611. service.CreateGoodErrcode(goodErrcode)
  6612. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6613. c.ServeSuccessJSON(map[string]interface{}{
  6614. "message": "1",
  6615. "good_name": goodObj.GoodName,
  6616. "specification_name": goodObj.SpecificationName,
  6617. })
  6618. return
  6619. }
  6620. }
  6621. //查询是否有出库单
  6622. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6623. if err == gorm.ErrRecordNotFound {
  6624. //没有记录,则创建出库单
  6625. timeStr := time.Now().Format("2006-01-02")
  6626. timeArr := strings.Split(timeStr, "-")
  6627. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6628. total = total + 1
  6629. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6630. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6631. number = number + total
  6632. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6633. creater := adminInfo.AdminUser.Id
  6634. warehouseOut := models.WarehouseOut{
  6635. WarehouseOutOrderNumber: warehousing_out_order,
  6636. OperationTime: time.Now().Unix(),
  6637. OrgId: adminInfo.Org.Id,
  6638. Creater: creater,
  6639. Ctime: time.Now().Unix(),
  6640. Status: 1,
  6641. WarehouseOutTime: record_time,
  6642. Dealer: 0,
  6643. Manufacturer: 0,
  6644. Type: 1,
  6645. IsSys: 1,
  6646. StorehouseId: houseConfig.StorehouseOutInfo,
  6647. IsCheck: 1,
  6648. }
  6649. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6650. if err != nil {
  6651. goodErrcode := models.XtGoodErrcode{
  6652. UserOrgId: adminInfo.Org.Id,
  6653. Errcode: "创建出库单失败",
  6654. GoodId: 0,
  6655. Status: 1,
  6656. Ctime: time.Now().Unix(),
  6657. Mtime: 0,
  6658. Count: 0,
  6659. StockCount: 0,
  6660. Creater: creator,
  6661. BatchNumberId: 0,
  6662. WarehouseOutId: 0,
  6663. }
  6664. service.CreateGoodErrcode(goodErrcode)
  6665. utils.TraceLog("创建出库单失败 err = %v", err)
  6666. } else {
  6667. for _, item := range consumables {
  6668. //出库
  6669. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6670. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6671. if err == nil {
  6672. goodErrcode := models.XtGoodErrcode{
  6673. UserOrgId: adminInfo.Org.Id,
  6674. Errcode: "自动出库接口报错",
  6675. GoodId: 0,
  6676. Status: 1,
  6677. Ctime: time.Now().Unix(),
  6678. Mtime: 0,
  6679. Count: 0,
  6680. StockCount: 0,
  6681. Creater: creator,
  6682. BatchNumberId: 0,
  6683. WarehouseOutId: 0,
  6684. }
  6685. service.CreateGoodErrcode(goodErrcode)
  6686. utils.TraceLog("创建出库单失败 err = %v", err)
  6687. }
  6688. //查询
  6689. //出库数量相加
  6690. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6691. if errs != nil {
  6692. goodErrcode := models.XtGoodErrcode{
  6693. UserOrgId: item.UserOrgId,
  6694. Errcode: "创建剩余库存字段报错",
  6695. GoodId: item.GoodId,
  6696. Status: 1,
  6697. Ctime: time.Now().Unix(),
  6698. Mtime: 0,
  6699. Count: 0,
  6700. StockCount: 0,
  6701. Creater: creater,
  6702. BatchNumberId: 0,
  6703. WarehouseOutId: 0,
  6704. }
  6705. service.CreateGoodErrcode(goodErrcode)
  6706. }
  6707. }
  6708. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6709. if len(list) == 0 {
  6710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6711. return
  6712. }
  6713. for _, item := range list {
  6714. prepare := models.DialysisBeforePrepare{
  6715. UserOrgId: adminInfo.Org.Id,
  6716. PatientId: patient_id,
  6717. RecordDate: record_time,
  6718. GoodId: item.GoodId,
  6719. GoodTypeId: item.GoodTypeId,
  6720. Count: item.Count,
  6721. Creater: adminInfo.AdminUser.Id,
  6722. Status: 1,
  6723. Ctime: time.Now().Unix(),
  6724. StorehouseId: houseConfig.StorehouseOutInfo,
  6725. }
  6726. //清空准备表数据
  6727. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6728. if err != nil {
  6729. goodErrcode := models.XtGoodErrcode{
  6730. UserOrgId: item.OrgId,
  6731. Errcode: "自动出库清空准备表数据报错",
  6732. GoodId: item.GoodId,
  6733. Status: 1,
  6734. Ctime: time.Now().Unix(),
  6735. Mtime: 0,
  6736. Count: 0,
  6737. StockCount: 0,
  6738. Creater: creater,
  6739. BatchNumberId: 0,
  6740. WarehouseOutId: 0,
  6741. }
  6742. service.CreateGoodErrcode(goodErrcode)
  6743. }
  6744. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6745. if errs != nil {
  6746. goodErrcode := models.XtGoodErrcode{
  6747. UserOrgId: item.OrgId,
  6748. Errcode: "自动出库创建准备表数据报错",
  6749. GoodId: item.GoodId,
  6750. Status: 1,
  6751. Ctime: time.Now().Unix(),
  6752. Mtime: 0,
  6753. Count: 0,
  6754. StockCount: 0,
  6755. Creater: creater,
  6756. BatchNumberId: 0,
  6757. WarehouseOutId: 0,
  6758. }
  6759. service.CreateGoodErrcode(goodErrcode)
  6760. }
  6761. //查询默认仓库
  6762. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6763. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6764. var total_count int64
  6765. for _, it := range stockList {
  6766. total_count += it.StockCount
  6767. }
  6768. //基础库插入数据
  6769. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6770. if errcodes != nil {
  6771. goodErrcode := models.XtGoodErrcode{
  6772. UserOrgId: item.OrgId,
  6773. Errcode: "自动出库基础库插入数据",
  6774. GoodId: item.GoodId,
  6775. Status: 1,
  6776. Ctime: time.Now().Unix(),
  6777. Mtime: 0,
  6778. Count: 0,
  6779. StockCount: 0,
  6780. Creater: creater,
  6781. BatchNumberId: 0,
  6782. WarehouseOutId: 0,
  6783. }
  6784. service.CreateGoodErrcode(goodErrcode)
  6785. }
  6786. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6787. var flush_count int64
  6788. for _, it := range goodList {
  6789. flush_count += it.StockCount
  6790. }
  6791. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6792. if errsss != nil {
  6793. goodErrcode := models.XtGoodErrcode{
  6794. UserOrgId: item.OrgId,
  6795. Errcode: "自动出库剩余库存更新数据",
  6796. GoodId: item.GoodId,
  6797. Status: 1,
  6798. Ctime: time.Now().Unix(),
  6799. Mtime: 0,
  6800. Count: 0,
  6801. StockCount: 0,
  6802. Creater: creater,
  6803. BatchNumberId: 0,
  6804. WarehouseOutId: 0,
  6805. }
  6806. service.CreateGoodErrcode(goodErrcode)
  6807. }
  6808. }
  6809. }
  6810. //
  6811. } else if err == nil {
  6812. for _, item := range consumables {
  6813. //出库
  6814. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6815. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6816. if err != nil {
  6817. goodErrcode := models.XtGoodErrcode{
  6818. UserOrgId: adminInfo.Org.Id,
  6819. Errcode: "自动出库接口报错",
  6820. GoodId: 0,
  6821. Status: 1,
  6822. Ctime: time.Now().Unix(),
  6823. Mtime: 0,
  6824. Count: 0,
  6825. StockCount: 0,
  6826. Creater: creator,
  6827. BatchNumberId: 0,
  6828. WarehouseOutId: 0,
  6829. }
  6830. service.CreateGoodErrcode(goodErrcode)
  6831. }
  6832. //出库数量相加
  6833. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6834. if errss != nil {
  6835. goodErrcode := models.XtGoodErrcode{
  6836. UserOrgId: item.UserOrgId,
  6837. Errcode: "创建剩余库存字段报错",
  6838. GoodId: item.GoodId,
  6839. Status: 1,
  6840. Ctime: time.Now().Unix(),
  6841. Mtime: time.Now().Unix(),
  6842. Count: 0,
  6843. StockCount: 0,
  6844. Creater: item.Creater,
  6845. BatchNumberId: 0,
  6846. WarehouseOutId: 0,
  6847. }
  6848. service.CreateGoodErrcode(goodErrcode)
  6849. }
  6850. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6851. if len(list) == 0 {
  6852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6853. return
  6854. }
  6855. for _, item := range list {
  6856. prepare := models.DialysisBeforePrepare{
  6857. UserOrgId: adminInfo.Org.Id,
  6858. PatientId: patient_id,
  6859. RecordDate: record_time,
  6860. GoodId: item.GoodId,
  6861. GoodTypeId: item.GoodTypeId,
  6862. Count: item.Count,
  6863. Creater: adminInfo.AdminUser.Id,
  6864. Status: 1,
  6865. Ctime: time.Now().Unix(),
  6866. StorehouseId: houseConfig.StorehouseOutInfo,
  6867. }
  6868. //清空准备表数据
  6869. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6870. if errs != nil {
  6871. goodErrcode := models.XtGoodErrcode{
  6872. UserOrgId: adminInfo.Org.Id,
  6873. Errcode: "自动出库清空准备表数据报错",
  6874. GoodId: 0,
  6875. Status: 1,
  6876. Ctime: time.Now().Unix(),
  6877. Mtime: 0,
  6878. Count: 0,
  6879. StockCount: 0,
  6880. Creater: creator,
  6881. BatchNumberId: 0,
  6882. WarehouseOutId: 0,
  6883. }
  6884. service.CreateGoodErrcode(goodErrcode)
  6885. }
  6886. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6887. if errcodes != nil {
  6888. goodErrcode := models.XtGoodErrcode{
  6889. UserOrgId: adminInfo.Org.Id,
  6890. Errcode: "自动出库创建准备表数据报错",
  6891. GoodId: 0,
  6892. Status: 1,
  6893. Ctime: time.Now().Unix(),
  6894. Mtime: 0,
  6895. Count: 0,
  6896. StockCount: 0,
  6897. Creater: creator,
  6898. BatchNumberId: 0,
  6899. WarehouseOutId: 0,
  6900. }
  6901. service.CreateGoodErrcode(goodErrcode)
  6902. }
  6903. //查询默认仓库
  6904. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6905. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6906. var total_count int64
  6907. for _, it := range stockList {
  6908. total_count += it.StockCount
  6909. }
  6910. //基础库插入数据
  6911. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6912. if errcodes != nil {
  6913. goodErrcode := models.XtGoodErrcode{
  6914. UserOrgId: adminInfo.Org.Id,
  6915. Errcode: "自动出库基础库插入数据报错",
  6916. GoodId: 0,
  6917. Status: 1,
  6918. Ctime: time.Now().Unix(),
  6919. Mtime: 0,
  6920. Count: 0,
  6921. StockCount: 0,
  6922. Creater: creator,
  6923. BatchNumberId: 0,
  6924. WarehouseOutId: 0,
  6925. }
  6926. service.CreateGoodErrcode(goodErrcode)
  6927. }
  6928. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6929. var flush_count int64
  6930. for _, it := range goodList {
  6931. flush_count += it.StockCount
  6932. }
  6933. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6934. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6935. if errss != nil {
  6936. goodErrcode := models.XtGoodErrcode{
  6937. UserOrgId: item.OrgId,
  6938. Errcode: "自动出库剩余库存更新数据",
  6939. GoodId: item.GoodId,
  6940. Status: 1,
  6941. Ctime: time.Now().Unix(),
  6942. Mtime: 0,
  6943. Count: 0,
  6944. StockCount: 0,
  6945. Creater: creater,
  6946. BatchNumberId: 0,
  6947. WarehouseOutId: 0,
  6948. }
  6949. service.CreateGoodErrcode(goodErrcode)
  6950. }
  6951. }
  6952. }
  6953. }
  6954. c.ServeSuccessJSON(map[string]interface{}{
  6955. "msg": "提交成功",
  6956. "message": "2",
  6957. "good_name": "",
  6958. "specification_name": "",
  6959. })
  6960. return
  6961. } else {
  6962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6963. return
  6964. }
  6965. }
  6966. func (c *DialysisAPIController) EditConsumables() {
  6967. patient_id, _ := c.GetInt64("patient_id", 0)
  6968. record_date := c.GetString("record_time")
  6969. if patient_id <= 0 {
  6970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6971. return
  6972. }
  6973. adminInfo := c.GetMobileAdminUserInfo()
  6974. timeLayout := "2006-01-02"
  6975. loc, _ := time.LoadLocation("Local")
  6976. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6977. record_time := theRecordTime.Unix()
  6978. // 查询信息规挡的设置天数
  6979. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6980. if infor.ID > 0 && infor.WeekDay > 0 {
  6981. var cha_time int64
  6982. timeNowStr := time.Now().Format("2006-01-02")
  6983. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6984. //今日的日期减去设置的日期
  6985. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6986. if cha_time >= record_time {
  6987. //查询审核是否允许
  6988. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6989. //申请状态不允许的情况 拒绝修改
  6990. if infor.ApplicationStatus != 1 {
  6991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6992. return
  6993. }
  6994. }
  6995. }
  6996. dataBody := make(map[string]interface{}, 0)
  6997. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6998. if err != nil {
  6999. utils.ErrorLog(err.Error())
  7000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7001. return
  7002. }
  7003. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7004. var beforePrepares []*models.DialysisBeforePrepareGoods
  7005. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7006. var cancelbefor []*models.DialysisBeforePrepareGoods
  7007. var outbefor []*models.DialysisBeforePrepareGoods
  7008. //判断是否开启自动出库
  7009. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7010. if record.IsOpen == 1 {
  7011. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7012. goods, _ := dataBody["goods"].([]interface{})
  7013. if len(goods) > 0 {
  7014. for _, item := range goods {
  7015. items := item.(map[string]interface{})
  7016. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7017. utils.ErrorLog("good_id")
  7018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7019. return
  7020. }
  7021. good_id := int64(items["good_id"].(float64))
  7022. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7023. utils.ErrorLog("good_type_id")
  7024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7025. return
  7026. }
  7027. good_type_id := int64(items["good_type_id"].(float64))
  7028. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7029. utils.ErrorLog("count")
  7030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7031. return
  7032. }
  7033. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7034. commdity_code := items["commdity_code"].(string)
  7035. fmt.Println(commdity_code)
  7036. prepareGoods := &models.DialysisBeforePrepareGoods{
  7037. GoodTypeId: good_type_id,
  7038. GoodId: good_id,
  7039. Count: count,
  7040. StorehouseId: houseConfig.StorehouseOutInfo,
  7041. }
  7042. beforePrepares = append(beforePrepares, prepareGoods)
  7043. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7044. GoodTypeId: good_type_id,
  7045. GoodId: good_id,
  7046. Count: count,
  7047. StorehouseId: houseConfig.StorehouseOutInfo,
  7048. }
  7049. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7050. }
  7051. for _, item := range beforePrepares {
  7052. //1.查看该患者该耗材型号最后一次出库数量
  7053. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7054. //判断当前出库数量和最后一次出库数量的大小
  7055. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7056. if item.Count < goodInfo.Count {
  7057. cancelbefor = append(cancelbefor, item)
  7058. }
  7059. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7060. if item.Count > goodInfo.Count {
  7061. outbefor = append(outbefor, item)
  7062. }
  7063. //处理编辑耗材新增不了的问题
  7064. if goodInfo.Count == item.Count {
  7065. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7066. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7067. }
  7068. }
  7069. if len(cancelbefor) > 0 {
  7070. //退库
  7071. for _, item := range cancelbefor {
  7072. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7073. creater := adminInfo.AdminUser.Id
  7074. //查询该患者当天已经出库的耗材信息
  7075. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7076. var delete_count int64 = 0
  7077. delete_count = warehouseOutInfos.Count - item.Count
  7078. //增加库存数量
  7079. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7080. //减少实际出库库存数量
  7081. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7082. // 删除出库完成后,要增加对应批次的库存数量
  7083. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7084. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7085. //更新剩余库存
  7086. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7087. var flush_count int64
  7088. for _, it := range goodListOne {
  7089. flush_count += it.StockCount
  7090. }
  7091. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7092. //查询剩余库存
  7093. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7094. var sum_count int64
  7095. for _, item := range goodList {
  7096. sum_count += item.StockCount
  7097. }
  7098. // 在出库记录表里记录退库详情
  7099. warehouseOutInfo := &models.WarehouseOutInfo{
  7100. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7101. WarehouseOutId: warehouseOut.ID,
  7102. Status: 1,
  7103. Ctime: time.Now().Unix(),
  7104. OrgId: adminInfo.Org.Id,
  7105. Type: 1,
  7106. IsSys: 1,
  7107. SysRecordTime: record_time,
  7108. GoodTypeId: item.GoodTypeId,
  7109. GoodId: item.GoodId,
  7110. PatientId: patient_id,
  7111. ConsumableType: 2,
  7112. StorehouseId: houseConfig.StorehouseOutInfo,
  7113. IsCheck: 1,
  7114. OverCount: sum_count,
  7115. }
  7116. warehouseOutInfo.Count = item.Count
  7117. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7118. warehouseOutInfo.Price = stockInInfo.Price
  7119. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7120. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7121. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7122. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7123. warehouseOutInfo.Number = warehouseOutInfos.Number
  7124. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7125. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7126. //查找当天是否存在出库记录
  7127. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7128. if errcod == gorm.ErrRecordNotFound {
  7129. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7130. //插入详情明细表
  7131. stockFlow := models.VmStockFlow{
  7132. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7133. WarehouseOutId: warehouseOut.ID,
  7134. GoodId: item.GoodId,
  7135. Number: warehouseOutInfos.Number,
  7136. ProductDate: stockInInfo.ProductDate,
  7137. ExpireDate: stockInInfo.ExpiryDate,
  7138. Count: item.Count,
  7139. Price: stockInInfo.Price,
  7140. Status: 1,
  7141. Ctime: record_time,
  7142. UserOrgId: adminInfo.Org.Id,
  7143. Manufacturer: stockInInfo.Manufacturer,
  7144. Dealer: stockInInfo.Dealer,
  7145. LicenseNumber: stockInInfo.LicenseNumber,
  7146. IsEdit: 2,
  7147. Creator: creater,
  7148. SystemTime: record_time,
  7149. ConsumableType: 3,
  7150. WarehousingDetailId: 0,
  7151. IsSys: 1,
  7152. UpdateCreator: creater,
  7153. PatientId: patient_id,
  7154. StorehouseId: houseConfig.StorehouseOutInfo,
  7155. }
  7156. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7157. if errflow == gorm.ErrRecordNotFound {
  7158. //创建流水表
  7159. err := service.CreateStockFlowOne(stockFlow)
  7160. fmt.Println("err", err)
  7161. } else if errflow == nil {
  7162. //插入详情明细表
  7163. stockFlow := models.VmStockFlow{
  7164. ID: exsit.ID,
  7165. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7166. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7167. WarehouseOutId: warehouseOut.ID,
  7168. GoodId: item.GoodId,
  7169. Number: warehouseOutInfos.Number,
  7170. ProductDate: stockInInfo.ProductDate,
  7171. ExpireDate: stockInInfo.ExpiryDate,
  7172. Count: exsit.Count - delete_count,
  7173. Price: stockInInfo.Price,
  7174. Status: 1,
  7175. Ctime: record_time,
  7176. UserOrgId: adminInfo.Org.Id,
  7177. Manufacturer: stockInInfo.Manufacturer,
  7178. Dealer: stockInInfo.Dealer,
  7179. LicenseNumber: stockInInfo.LicenseNumber,
  7180. IsEdit: 2,
  7181. Creator: creater,
  7182. SystemTime: record_time,
  7183. ConsumableType: 3,
  7184. WarehousingDetailId: 0,
  7185. IsSys: 1,
  7186. UpdateCreator: creater,
  7187. PatientId: patient_id,
  7188. StorehouseId: houseConfig.StorehouseOutInfo,
  7189. }
  7190. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7191. }
  7192. } else if errcod == nil {
  7193. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7194. //查询剩余库存
  7195. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7196. var sum_count int64
  7197. for _, item := range goodList {
  7198. sum_count += item.StockCount
  7199. }
  7200. //创建退库单,生成退库数据
  7201. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7202. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7203. operation_time := time.Now().Unix()
  7204. creater := adminInfo.AdminUser.Id
  7205. //创建退库单
  7206. timeStr := time.Now().Format("2006-01-02")
  7207. timeArr := strings.Split(timeStr, "-")
  7208. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7209. total = total + 1
  7210. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7211. cancelStock := models.CancelStock{
  7212. OrderNumber: orderNumber,
  7213. OperaTime: operation_time,
  7214. OrgId: adminInfo.Org.Id,
  7215. Creater: creater,
  7216. Ctime: time.Now().Unix(),
  7217. Status: 1,
  7218. ReturnTime: record_time,
  7219. Type: 1,
  7220. StorehouseId: houseConfig.StorehouseOutInfo,
  7221. IsCheck: 1,
  7222. }
  7223. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7224. if msgerrkonde == gorm.ErrRecordNotFound {
  7225. service.AddSigleCancelStock(&cancelStock)
  7226. }
  7227. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7228. //查询是否有出库
  7229. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7230. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7231. deaerler, _ := service.GetDealerById(info.Dealer)
  7232. if info.ID > 0 {
  7233. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7234. cancelStockInfo := models.CancelStockInfo{
  7235. GoodId: item.GoodId,
  7236. CancelStockId: cancel.ID,
  7237. GoodTypeId: good.GoodTypeId,
  7238. Count: delete_count,
  7239. Price: info.Price,
  7240. Total: 0,
  7241. ProductDate: info.ProductDate,
  7242. ExpiryDate: info.ExpiryDate,
  7243. Ctime: time.Now().Unix(),
  7244. Status: 1,
  7245. OrgId: adminInfo.Org.Id,
  7246. OrderNumber: cancel.OrderNumber,
  7247. Type: 0,
  7248. Dealer: deaerler.DealerName,
  7249. Manufacturer: manufacturer.ManufacturerName,
  7250. Number: info.Number,
  7251. RegisterAccount: "",
  7252. Remark: "",
  7253. WarehouseInfoId: info.WarehouseInfotId,
  7254. PatientId: info.PatientId,
  7255. RecordDate: info.SysRecordTime,
  7256. StorehouseId: houseConfig.StorehouseOutInfo,
  7257. IsCheck: 1,
  7258. }
  7259. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7260. //退库数量增加
  7261. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7262. //查询剩余库存
  7263. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7264. var over_count int64
  7265. for _, it := range goodList {
  7266. over_count += it.StockCount
  7267. }
  7268. flow := models.VmStockFlow{
  7269. WarehousingId: info.WarehouseInfotId,
  7270. GoodId: item.GoodId,
  7271. Number: info.Number,
  7272. LicenseNumber: info.LicenseNumber,
  7273. Count: delete_count,
  7274. UserOrgId: adminInfo.Org.Id,
  7275. PatientId: patient_id,
  7276. SystemTime: info.SysRecordTime,
  7277. ConsumableType: 7,
  7278. IsSys: 0,
  7279. WarehousingOrder: "",
  7280. WarehouseOutId: info.WarehouseOutId,
  7281. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7282. IsEdit: 0,
  7283. CancelStockId: cancel.ID,
  7284. CancelOrderNumber: cancel.OrderNumber,
  7285. Manufacturer: manufacturer.ID,
  7286. Dealer: 0,
  7287. Creator: adminInfo.AdminUser.Id,
  7288. UpdateCreator: 0,
  7289. Status: 1,
  7290. Ctime: record_time,
  7291. Mtime: 0,
  7292. Price: info.Price,
  7293. WarehousingDetailId: info.WarehouseInfotId,
  7294. WarehouseOutDetailId: info.ID,
  7295. CancelOutDetailId: cancelInfo.ID,
  7296. ProductDate: info.ProductDate,
  7297. ExpireDate: info.ExpiryDate,
  7298. StorehouseId: houseConfig.StorehouseOutInfo,
  7299. OverCount: over_count,
  7300. }
  7301. service.CreateStockFlowOne(flow)
  7302. }
  7303. }
  7304. //更改自动出库的表格
  7305. details := models.BloodAutomaticReduceDetail{
  7306. WarehouseOutId: warehouseOutInfo.ID,
  7307. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7308. PatientId: patient_id,
  7309. Ctime: time.Now().Unix(),
  7310. Mtime: time.Now().Unix(),
  7311. Status: 1,
  7312. RecordTime: record_time,
  7313. OrgId: adminInfo.Org.Id,
  7314. GoodId: item.GoodId,
  7315. GoodTypeId: item.GoodTypeId,
  7316. Count: item.Count,
  7317. StorehouseId: houseConfig.StorehouseOutInfo,
  7318. }
  7319. //查询当天耗材是否已经存在数据
  7320. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7321. if errcode == gorm.ErrRecordNotFound {
  7322. service.CreateAutoReduceRecord(&details)
  7323. } else if errcode == nil {
  7324. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7325. service.CreateAutoReduceRecord(&details)
  7326. }
  7327. //查询默认仓库
  7328. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7329. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7330. var total_count int64
  7331. for _, it := range stockList {
  7332. total_count += it.StockCount
  7333. }
  7334. //基础库插入数据
  7335. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7336. }
  7337. }
  7338. if len(outbefor) > 0 {
  7339. //出库
  7340. for _, item := range outbefor {
  7341. var last_total int64
  7342. //1.查看该患者该耗材型号最后一次出库数量
  7343. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7344. //计算当前出库和最后一次出库数据相差数据
  7345. last_total = item.Count - goodInfoOne.Count
  7346. //查询该耗材的总库存
  7347. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7348. // 如果库存差大于剩余库存则提示库存不足
  7349. if last_total > wareinfo.StockCount {
  7350. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7351. c.ServeSuccessJSON(map[string]interface{}{
  7352. "message": "1",
  7353. "good_name": goodObj.GoodName,
  7354. "specification_name": goodObj.SpecificationName,
  7355. })
  7356. return
  7357. } else {
  7358. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7359. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7360. if err == gorm.ErrRecordNotFound {
  7361. //没有记录,则创建出库单
  7362. timeStr := time.Now().Format("2006-01-02")
  7363. timeArr := strings.Split(timeStr, "-")
  7364. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7365. total = total + 1
  7366. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7367. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7368. number = number + total
  7369. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7370. warehouseOut := models.WarehouseOut{
  7371. WarehouseOutOrderNumber: warehousing_out_order,
  7372. OperationTime: time.Now().Unix(),
  7373. OrgId: adminInfo.Org.Id,
  7374. Creater: adminInfo.AdminUser.Id,
  7375. Ctime: time.Now().Unix(),
  7376. Status: 1,
  7377. WarehouseOutTime: record_time,
  7378. Dealer: 0,
  7379. Manufacturer: 0,
  7380. Type: 1,
  7381. IsSys: 1,
  7382. StorehouseId: houseConfig.StorehouseOutInfo,
  7383. IsCheck: 1,
  7384. }
  7385. service.AddSigleWarehouseOutOne(&warehouseOut)
  7386. }
  7387. //出库
  7388. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7389. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7390. //1.查看该患者该耗材型号最后一次出库数量
  7391. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7392. prepare := models.DialysisBeforePrepare{
  7393. UserOrgId: adminInfo.Org.Id,
  7394. PatientId: patient_id,
  7395. RecordDate: record_time,
  7396. GoodId: item.GoodId,
  7397. GoodTypeId: item.GoodTypeId,
  7398. Count: item.Count - goodInfoTwo.Count,
  7399. Ctime: time.Now().Unix(),
  7400. Mtime: 0,
  7401. Creater: adminInfo.AdminUser.Id,
  7402. Modifier: adminInfo.AdminUser.Id,
  7403. Status: 1,
  7404. CommdityCode: "",
  7405. NewCount: 0,
  7406. ProjectId: 0,
  7407. StorehouseId: houseConfig.StorehouseOutInfo,
  7408. }
  7409. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7410. //增加出库数量
  7411. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7412. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7413. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7414. var total_count int64
  7415. for _, it := range stockList {
  7416. total_count += it.StockCount
  7417. }
  7418. //基础库插入数据
  7419. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7420. //剩余库存
  7421. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7422. var flush_count int64
  7423. for _, it := range goodList {
  7424. flush_count += it.StockCount
  7425. }
  7426. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7427. }
  7428. }
  7429. }
  7430. //查询今日出库数据
  7431. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7432. for _, it := range list {
  7433. prepare := models.DialysisBeforePrepare{
  7434. UserOrgId: it.OrgId,
  7435. PatientId: patient_id,
  7436. RecordDate: it.RecordTime,
  7437. GoodId: it.GoodId,
  7438. GoodTypeId: it.GoodTypeId,
  7439. Count: it.Count,
  7440. Ctime: time.Now().Unix(),
  7441. Creater: adminInfo.AdminUser.Id,
  7442. Status: 1,
  7443. StorehouseId: houseConfig.StorehouseOutInfo,
  7444. ProjectId: it.ProjectId,
  7445. }
  7446. //删除准备表数据
  7447. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7448. service.CreateDialysisBeforePrepareOne(&prepare)
  7449. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7450. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7451. var total_count int64
  7452. for _, it := range stockList {
  7453. total_count += it.StockCount
  7454. }
  7455. //基础库插入数据
  7456. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7457. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7458. var flush_count int64
  7459. for _, it := range goodList {
  7460. flush_count += it.StockCount
  7461. }
  7462. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7463. }
  7464. }
  7465. }
  7466. //更新自动出库的地方
  7467. var errs error
  7468. if errs == nil {
  7469. c.ServeSuccessJSON(map[string]interface{}{
  7470. "msg": "修改成功",
  7471. "message": "2",
  7472. "good_name": "",
  7473. "specification_name": "",
  7474. })
  7475. return
  7476. } else {
  7477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7478. return
  7479. }
  7480. }
  7481. }
  7482. func (c *DialysisAPIController) GetDialysisGoods() {
  7483. schedualDate := c.GetString("schedule_date")
  7484. schedule_type, _ := c.GetInt64("schedule_type")
  7485. partition_id, _ := c.GetInt64("partition_id")
  7486. page, _ := c.GetInt("page")
  7487. patient_id, _ := c.GetInt64("patient_id")
  7488. schedualEndDate := int64(0)
  7489. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7490. if parseDateErr != nil && len(schedualDate) != 0 {
  7491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7492. return
  7493. }
  7494. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7495. if parseDateErr != nil && len(schedualDate) != 0 {
  7496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7497. return
  7498. }
  7499. schedualEndDate = endDate.Unix()
  7500. adminUser := c.GetMobileAdminUserInfo()
  7501. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7502. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7503. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7504. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7505. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7506. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7507. //获取当天该病人的透析处方
  7508. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7509. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7510. if err == gorm.ErrRecordNotFound {
  7511. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7512. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7513. if patient_id != 0 {
  7514. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7515. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7516. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7517. //获取患者总的出库数据
  7518. item.LastAutomaticReduceDetail = goodUser
  7519. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7520. item.Project = project
  7521. for _, it := range item.AutomaticReduceDetail {
  7522. var total int64
  7523. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7524. for _, its := range auto {
  7525. total += its.Count
  7526. }
  7527. it.Count = total
  7528. }
  7529. }
  7530. }
  7531. c.ServeSuccessJSON(map[string]interface{}{
  7532. "dialysis_goods": dialysisGoods,
  7533. "good_type": goodTypes,
  7534. "total": total,
  7535. "prescribe": prescribe,
  7536. "good_info": good_info,
  7537. "warehouseOutList": warehouseOutList,
  7538. "config": config,
  7539. "outConfig": outConfig,
  7540. "settleConfig": settleConfig,
  7541. })
  7542. return
  7543. } else if err == nil {
  7544. //获取当天排班的每个患者的库存使用情况
  7545. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7546. //获取患者总的出库数据
  7547. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7548. if patient_id != 0 {
  7549. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7550. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7551. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7552. item.Project = project
  7553. item.LastAutomaticReduceDetail = goodUser
  7554. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7555. for _, it := range item.AutomaticReduceDetail {
  7556. var total int64
  7557. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7558. for _, its := range auto {
  7559. total += its.Count
  7560. }
  7561. it.Count = total
  7562. }
  7563. }
  7564. }
  7565. if err == nil {
  7566. c.ServeSuccessJSON(map[string]interface{}{
  7567. "dialysis_goods": dialysisGoods,
  7568. "good_type": goodTypes,
  7569. "total": total,
  7570. "prescribe": prescribe,
  7571. "good_info": good_info,
  7572. "project": project,
  7573. "warehouseOutList": warehouseOutList,
  7574. "config": config,
  7575. "outConfig": outConfig,
  7576. "settleConfig": settleConfig,
  7577. })
  7578. return
  7579. } else {
  7580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7581. return
  7582. }
  7583. } else if err != nil {
  7584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7585. return
  7586. }
  7587. }
  7588. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7589. start_time := c.GetString("start_time")
  7590. end_time := c.GetString("end_time")
  7591. timeLayout := "2006-01-02"
  7592. loc, _ := time.LoadLocation("Local")
  7593. var theStartTime int64
  7594. if len(start_time) > 0 {
  7595. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7596. if err != nil {
  7597. utils.ErrorLog(err.Error())
  7598. }
  7599. theStartTime = theTime.Unix()
  7600. }
  7601. var theEndtTime int64
  7602. if len(end_time) > 0 {
  7603. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7604. if err != nil {
  7605. utils.ErrorLog(err.Error())
  7606. }
  7607. theEndtTime = theTime.Unix()
  7608. }
  7609. adminUser := c.GetMobileAdminUserInfo()
  7610. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7611. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7612. if err == nil {
  7613. c.ServeSuccessJSON(map[string]interface{}{
  7614. "stock_out": outInfo,
  7615. "stockCount": stockCount,
  7616. })
  7617. return
  7618. } else {
  7619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7620. return
  7621. }
  7622. }
  7623. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7624. patient_id, _ := c.GetInt64("patient_id", 0)
  7625. record_time := c.GetString("record_time")
  7626. adminUser := c.GetMobileAdminUserInfo()
  7627. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7628. if parseDateErr != nil && len(record_time) != 0 {
  7629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7630. return
  7631. }
  7632. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7633. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7634. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7635. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7636. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7637. //获取今日患者的透析处方参数
  7638. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7639. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7640. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7641. c.ServeSuccessJSON(map[string]interface{}{
  7642. "good_type": goodTypes,
  7643. "good_user": goodUser,
  7644. "good_info": good_info,
  7645. "last_good_user": lastGoodUserDetial,
  7646. "project": project,
  7647. "prescription": prescribe,
  7648. "outInfo": outInfo,
  7649. "configs": configs,
  7650. })
  7651. return
  7652. }
  7653. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7654. patient_id, _ := c.GetInt64("patient_id", 0)
  7655. record_date := c.GetString("record_time")
  7656. timeLayout := "2006-01-02"
  7657. loc, _ := time.LoadLocation("Local")
  7658. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7659. record_time := theRecordTime.Unix()
  7660. adminInfo := c.GetMobileAdminUserInfo()
  7661. dataBody := make(map[string]interface{}, 0)
  7662. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7663. if err != nil {
  7664. utils.ErrorLog(err.Error())
  7665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7666. return
  7667. }
  7668. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7669. var beforePrepares []*models.DialysisBeforePrepareGoods
  7670. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7671. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7672. goods, _ := dataBody["goods"].([]interface{})
  7673. if len(goods) > 0 {
  7674. for _, item := range goods {
  7675. items := item.(map[string]interface{})
  7676. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7677. utils.ErrorLog("good_id")
  7678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7679. return
  7680. }
  7681. good_id := int64(items["good_id"].(float64))
  7682. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7683. utils.ErrorLog("good_type_id")
  7684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7685. return
  7686. }
  7687. good_type_id := int64(items["good_type_id"].(float64))
  7688. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7689. utils.ErrorLog("count")
  7690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7691. return
  7692. }
  7693. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7694. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7695. utils.ErrorLog("project_id")
  7696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7697. return
  7698. }
  7699. project_id := int64(items["project_id"].(float64))
  7700. new_count := int64(items["new_count"].(float64))
  7701. old_count := int64(items["old_count"].(float64))
  7702. prepare := &models.DialysisBeforePrepareGoods{
  7703. GoodId: good_id,
  7704. GoodTypeId: good_type_id,
  7705. Count: count,
  7706. ProjectId: project_id,
  7707. StorehouseId: houseConfig.StorehouseOutInfo,
  7708. NewCount: new_count,
  7709. OldCount: old_count,
  7710. }
  7711. beforePrepares = append(beforePrepares, prepare)
  7712. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7713. GoodId: good_id,
  7714. GoodTypeId: good_type_id,
  7715. Count: count,
  7716. ProjectId: project_id,
  7717. StorehouseId: houseConfig.StorehouseOutInfo,
  7718. NewCount: new_count,
  7719. OldCount: old_count,
  7720. }
  7721. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7722. }
  7723. }
  7724. }
  7725. //查询是否有库存
  7726. for _, item := range beforePrepares {
  7727. if item.NewCount > 0 {
  7728. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7729. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7730. if item.Count > warehouse.Count {
  7731. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7732. c.ServeSuccessJSON(map[string]interface{}{
  7733. "message": "1",
  7734. "good_name": goodObj.GoodName,
  7735. "specification_name": goodObj.SpecificationName,
  7736. })
  7737. return
  7738. }
  7739. }
  7740. }
  7741. // 查询信息规挡的设置天数
  7742. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7743. if infor.ID > 0 && infor.WeekDay > 0 {
  7744. var cha_time int64
  7745. timeNowStr := time.Now().Format("2006-01-02")
  7746. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7747. //今日的日期减去设置的日期
  7748. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7749. if cha_time >= record_time {
  7750. //查询审核是否允许
  7751. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7752. //申请状态不允许的情况 拒绝修改
  7753. if infor.ApplicationStatus != 1 {
  7754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7755. return
  7756. }
  7757. }
  7758. }
  7759. //出库逻辑
  7760. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7761. if err != nil {
  7762. utils.ErrorLog(err.Error())
  7763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7764. return
  7765. }
  7766. finish := models.XtDialysisFinish{
  7767. IsFinish: 1,
  7768. UserOrgId: adminInfo.Org.Id,
  7769. Status: 1,
  7770. Ctime: time.Now().Unix(),
  7771. Mtime: 0,
  7772. Module: 11,
  7773. RecordDate: record_time,
  7774. Sourse: 1,
  7775. PatientId: patient_id,
  7776. }
  7777. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7778. if dialysisFinish.ID == 0 {
  7779. service.CreateDialysisFinish(finish)
  7780. }
  7781. //查询当天出库的数据
  7782. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7783. for _, item := range list {
  7784. prepare := models.DialysisBeforePrepare{
  7785. UserOrgId: item.OrgId,
  7786. PatientId: item.PatientId,
  7787. RecordDate: item.RecordTime,
  7788. GoodId: item.GoodId,
  7789. GoodTypeId: item.GoodTypeId,
  7790. Count: item.Count,
  7791. Creater: adminInfo.AdminUser.Id,
  7792. Status: 1,
  7793. Ctime: time.Now().Unix(),
  7794. ProjectId: item.ProjectId,
  7795. StorehouseId: houseConfig.StorehouseOutInfo,
  7796. }
  7797. //清空准备表的数据
  7798. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7799. //插入准备表数据
  7800. service.CreateDialysisBeforePrepareOne(&prepare)
  7801. //查询默认仓库
  7802. //查询默认仓库
  7803. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7804. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7805. var total_count int64
  7806. for _, it := range stockList {
  7807. total_count += it.StockCount
  7808. }
  7809. //基础库插入数据
  7810. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7811. ////更新剩余库存
  7812. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7813. var flush_count int64
  7814. for _, it := range goodList {
  7815. flush_count += it.StockCount
  7816. }
  7817. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7818. if errs != nil {
  7819. goodErrcode := models.XtGoodErrcode{
  7820. UserOrgId: item.OrgId,
  7821. Errcode: "手动出库更新剩余出库失败",
  7822. GoodId: item.GoodId,
  7823. Status: 1,
  7824. Ctime: time.Now().Unix(),
  7825. Mtime: 0,
  7826. Count: 0,
  7827. StockCount: 0,
  7828. Creater: adminInfo.AdminUser.Id,
  7829. BatchNumberId: 0,
  7830. WarehouseOutId: 0,
  7831. }
  7832. service.CreateGoodErrcode(goodErrcode)
  7833. }
  7834. }
  7835. //更新自动出库的地方
  7836. var errs error
  7837. if errs == nil {
  7838. c.ServeSuccessJSON(map[string]interface{}{
  7839. "msg": "修改成功",
  7840. "message": "2",
  7841. "good_name": "",
  7842. "specification_name": "",
  7843. })
  7844. return
  7845. } else {
  7846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7847. return
  7848. }
  7849. }
  7850. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7851. newArr = make([]*models.DialysisBeforePrepare, 0)
  7852. for i := 0; i < len(arr); i++ {
  7853. repeat := false
  7854. for j := i + 1; j < len(arr); j++ {
  7855. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7856. repeat = true
  7857. break
  7858. }
  7859. }
  7860. if !repeat {
  7861. newArr = append(newArr, arr[i])
  7862. }
  7863. }
  7864. return
  7865. }
  7866. func (c *DialysisAPIController) GetAllDrug() {
  7867. patient_id, _ := c.GetInt64("patient_id", 0)
  7868. adminInfo := c.GetMobileAdminUserInfo()
  7869. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7870. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7871. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7872. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7873. c.ServeSuccessJSON(map[string]interface{}{
  7874. "base_drug_config": drugStockConfig,
  7875. "private_drug_config": privateDrugConfig,
  7876. "base_drug_list": drugList,
  7877. "private_drug_list": privateDrugList,
  7878. })
  7879. }
  7880. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7881. newArr = make([]*models.DialysisBeforePrepare, 0)
  7882. for i := 0; i < len(arr); i++ {
  7883. repeat := false
  7884. for j := i + 1; j < len(arr); j++ {
  7885. if arr[i].GoodId == arr[j].GoodId {
  7886. repeat = true
  7887. break
  7888. }
  7889. }
  7890. if !repeat {
  7891. newArr = append(newArr, arr[i])
  7892. }
  7893. }
  7894. return
  7895. }
  7896. func (c *DialysisAPIController) GetDepartment() {
  7897. adminInfo := c.GetMobileAdminUserInfo()
  7898. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7899. if err == nil {
  7900. c.ServeSuccessJSON(map[string]interface{}{
  7901. "departments": departments,
  7902. })
  7903. } else {
  7904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7905. return
  7906. }
  7907. }
  7908. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7909. types, _ := c.GetInt("type", 0)
  7910. start_time := c.GetString("start_time")
  7911. end_time := c.GetString("end_time")
  7912. orgId := c.GetMobileAdminUserInfo().Org.Id
  7913. timeLayout := "2006-01-02"
  7914. loc, _ := time.LoadLocation("Local")
  7915. var startTime int64
  7916. if len(start_time) > 0 {
  7917. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7918. if err != nil {
  7919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7920. return
  7921. }
  7922. startTime = theTime.Unix()
  7923. }
  7924. var endTime int64
  7925. if len(end_time) > 0 {
  7926. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7927. if err != nil {
  7928. utils.ErrorLog(err.Error())
  7929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7930. return
  7931. }
  7932. endTime = theTime.Unix()
  7933. }
  7934. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7935. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7936. if err != nil {
  7937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7938. } else {
  7939. c.ServeSuccessJSON(map[string]interface{}{
  7940. "list": list,
  7941. "type": types,
  7942. "stockTotal": stockTotal,
  7943. })
  7944. }
  7945. }
  7946. func (c *DialysisAPIController) GetPrescriptionList() {
  7947. start_time := c.GetString("start_time")
  7948. end_time := c.GetString("end_time")
  7949. schedule_type, _ := c.GetInt64("schedule_type")
  7950. partion_id, _ := c.GetInt64("partion_id")
  7951. orgId := c.GetMobileAdminUserInfo().Org.Id
  7952. timeLayout := "2006-01-02"
  7953. loc, _ := time.LoadLocation("Local")
  7954. var startTime int64
  7955. if len(start_time) > 0 {
  7956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7957. if err != nil {
  7958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7959. return
  7960. }
  7961. startTime = theTime.Unix()
  7962. }
  7963. var endTime int64
  7964. if len(end_time) > 0 {
  7965. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7966. if err != nil {
  7967. utils.ErrorLog(err.Error())
  7968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7969. return
  7970. }
  7971. endTime = theTime.Unix()
  7972. }
  7973. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7974. fmt.Println("schedulelist22222222", schedulelist)
  7975. c.ServeSuccessJSON(map[string]interface{}{
  7976. "list": schedulelist,
  7977. })
  7978. return
  7979. }
  7980. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7981. ids := c.GetString("ids")
  7982. //patient_id, _ := c.GetInt64("patient_id")
  7983. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7984. idArray := strings.Split(ids, ",")
  7985. err := service.BatchDeleteMonitor(idArray)
  7986. fmt.Print("err", err)
  7987. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7988. //redis := service.RedisClient()
  7989. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7990. //redis.Set(key, "", time.Second)
  7991. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7992. //redis.Set(keyOne, "", time.Second)
  7993. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7994. //redis.Close()
  7995. c.ServeSuccessJSON(map[string]interface{}{
  7996. "msg": "批量删除成功",
  7997. })
  7998. return
  7999. }
  8000. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8001. id, _ := c.GetInt64("id")
  8002. timeLayout := "2006-01-02"
  8003. loc, _ := time.LoadLocation("Local")
  8004. //start_time := time.Now().Format("2006-01-02")
  8005. start_time := c.GetString("start_time")
  8006. end_time := c.GetString("end_time")
  8007. var startdateunix int64
  8008. if len(start_time) > 0 {
  8009. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8010. if err != nil {
  8011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8012. return
  8013. }
  8014. startdateunix = theTime.Unix()
  8015. }
  8016. var enddateunix int64
  8017. if len(end_time) > 0 {
  8018. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8019. if err != nil {
  8020. utils.ErrorLog(err.Error())
  8021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8022. return
  8023. }
  8024. enddateunix = theTime.Unix()
  8025. }
  8026. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8027. //nowTime := time.Now()
  8028. //endTime := nowTime.AddDate(-30, 0, 0)
  8029. //endTimes := endTime.Format("2006-01-02")
  8030. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8031. org_id := c.GetMobileAdminUserInfo().Org.Id
  8032. //if org_id == 10579 {
  8033. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8034. // c.ServeSuccessJSON(map[string]interface{}{
  8035. // "list": list,
  8036. // })
  8037. // return
  8038. //} else {
  8039. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8040. // c.ServeSuccessJSON(map[string]interface{}{
  8041. // "list": list,
  8042. // })
  8043. // return
  8044. //}
  8045. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8046. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8047. c.ServeSuccessJSON(map[string]interface{}{
  8048. "list": list,
  8049. })
  8050. return
  8051. } else {
  8052. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8053. c.ServeSuccessJSON(map[string]interface{}{
  8054. "list": list,
  8055. })
  8056. }
  8057. return
  8058. }
  8059. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8060. dataBody := make(map[string]interface{}, 0)
  8061. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8062. ids := c.GetString("ids")
  8063. idArray := strings.Split(ids, ",")
  8064. origin, _ := c.GetInt64("origin")
  8065. if origin == 1 {
  8066. err = service.BatchDeleteAdvice(idArray)
  8067. fmt.Print("err", err)
  8068. c.ServeSuccessJSON(map[string]interface{}{
  8069. "msg": "批量删除成功",
  8070. })
  8071. return
  8072. }
  8073. if origin == 2 {
  8074. service.BatchDeleteHisAdvice(idArray)
  8075. }
  8076. }
  8077. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8078. good_id, _ := c.GetInt64("good_id")
  8079. count, _ := c.GetInt64("count")
  8080. record_time, _ := c.GetInt64("record_time")
  8081. patient_id, _ := c.GetInt64("patient_id")
  8082. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8083. c.ServeSuccessJSON(map[string]interface{}{
  8084. "detail": detail,
  8085. })
  8086. return
  8087. }
  8088. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8089. good_id, _ := c.GetInt64("good_id")
  8090. record_time, _ := c.GetInt64("record_time")
  8091. patient_id, _ := c.GetInt64("patient_id")
  8092. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8093. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8094. fmt.Print("err", err)
  8095. c.ServeSuccessJSON(map[string]interface{}{
  8096. "msg": "批量删除成功",
  8097. })
  8098. return
  8099. }
  8100. func (c *DialysisAPIController) BatchAdviceCheck() {
  8101. ids := c.GetString("ids")
  8102. idArray := strings.Split(ids, ",")
  8103. creator, _ := c.GetInt64("creator")
  8104. origin, _ := c.GetInt64("origin")
  8105. if origin == 1 {
  8106. err := service.BatchAdviceCheck(idArray, creator)
  8107. fmt.Println(err)
  8108. list, _ := service.GetAdviceExecutionById(idArray)
  8109. c.ServeSuccessJSON(map[string]interface{}{
  8110. "list": list,
  8111. })
  8112. return
  8113. }
  8114. if origin == 2 {
  8115. service.BatchHisAdviceCheck(idArray, creator)
  8116. list, _ := service.GetHisAdviceExecutionById(idArray)
  8117. c.ServeSuccessJSON(map[string]interface{}{
  8118. "list": list,
  8119. })
  8120. return
  8121. }
  8122. }
  8123. func (c *DialysisAPIController) BatchAdviceExecution() {
  8124. ids := c.GetString("ids")
  8125. idArray := strings.Split(ids, ",")
  8126. executionTime := c.GetString("execution_time")
  8127. creator, _ := c.GetInt64("creator")
  8128. timeLayout := "2006-01-02 15:04:05"
  8129. loc, _ := time.LoadLocation("Local")
  8130. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8131. orgin, _ := c.GetInt64("origin")
  8132. if orgin == 1 {
  8133. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8134. list, _ := service.GetAdviceExecutionById(idArray)
  8135. fmt.Println(err)
  8136. c.ServeSuccessJSON(map[string]interface{}{
  8137. "list": list,
  8138. })
  8139. return
  8140. }
  8141. if orgin == 2 {
  8142. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8143. list, _ := service.GetHisAdviceExecutionById(idArray)
  8144. fmt.Println(err)
  8145. c.ServeSuccessJSON(map[string]interface{}{
  8146. "list": list,
  8147. })
  8148. return
  8149. }
  8150. }
  8151. func (c *DialysisAPIController) UpdateStockGoods() {
  8152. good_id, _ := c.GetInt64("good_id")
  8153. record_time, _ := c.GetInt64("record_time")
  8154. patient_id, _ := c.GetInt64("patient_id")
  8155. count, _ := c.GetInt64("count")
  8156. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8157. fmt.Print("err", err)
  8158. c.ServeSuccessJSON(map[string]interface{}{
  8159. "msg": "更新成功",
  8160. })
  8161. return
  8162. }
  8163. // 当前数据比上一次出库数据少
  8164. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8165. //查询该患者当天已经出库的耗材信息
  8166. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8167. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8168. for i := len(goods_yc) - 1; i >= 0; i-- {
  8169. goods_yc_temp := goods_yc[i]
  8170. for j := len(goods) - 1; j >= 0; j-- {
  8171. goods_temp := goods[j]
  8172. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8173. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8174. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8175. if goods_yc_temp.Count == goods_temp.Count {
  8176. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8177. goods = append(goods[:j], goods[j+1:]...)
  8178. break
  8179. }
  8180. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8181. if goods_yc_temp.Count > goods_temp.Count {
  8182. temp_count := goods_yc_temp.Count - goods_temp.Count
  8183. goods_yc[i].Count = temp_count
  8184. goods = append(goods[:j], goods[j+1:]...)
  8185. break
  8186. }
  8187. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8188. if goods_yc_temp.Count < goods_temp.Count {
  8189. temp_count := goods_temp.Count - goods_yc_temp.Count
  8190. goods[j].Count = temp_count
  8191. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8192. break
  8193. }
  8194. }
  8195. }
  8196. }
  8197. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8198. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8199. //退库
  8200. if len(goods_yc) > 0 {
  8201. for _, good_yc := range goods_yc {
  8202. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8203. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8204. }
  8205. }
  8206. return nil
  8207. }
  8208. // 耗材出库删除
  8209. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8210. // 先根据相关信息查询当天该耗材的出库信息
  8211. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8212. if err != nil {
  8213. return err
  8214. }
  8215. var delete_count int64 = 0
  8216. delete_count = warehouseOutInfos.Count - count
  8217. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8218. // 在出库记录表里记录退库详情
  8219. warehouseOutInfo := &models.WarehouseOutInfo{
  8220. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8221. WarehouseOutId: warehouseOut.ID,
  8222. Status: 1,
  8223. Ctime: time.Now().Unix(),
  8224. OrgId: orgID,
  8225. Type: 1,
  8226. IsSys: 1,
  8227. SysRecordTime: record_time,
  8228. GoodTypeId: good_yc.GoodTypeId,
  8229. GoodId: good_yc.GoodId,
  8230. PatientId: good_yc.PatientId,
  8231. ConsumableType: 2,
  8232. StorehouseId: houseConfig.StorehouseOutInfo,
  8233. IsCheck: 1,
  8234. }
  8235. warehouseOutInfo.Count = count
  8236. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8237. warehouseOutInfo.Price = stockInInfo.Price
  8238. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8239. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8240. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8241. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8242. warehouseOutInfo.Number = warehouseOutInfos.Number
  8243. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8244. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8245. //查找当天是否存在出库记录
  8246. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8247. if errcod == gorm.ErrRecordNotFound {
  8248. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8249. //插入详情明细表
  8250. stockFlow := models.VmStockFlow{
  8251. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8252. WarehouseOutId: warehouseOut.ID,
  8253. GoodId: good_yc.GoodId,
  8254. Number: warehouseOutInfos.Number,
  8255. ProductDate: stockInInfo.ProductDate,
  8256. ExpireDate: stockInInfo.ExpiryDate,
  8257. Count: count,
  8258. Price: stockInInfo.Price,
  8259. Status: 1,
  8260. Ctime: time.Now().Unix(),
  8261. UserOrgId: good_yc.OrgId,
  8262. Manufacturer: stockInInfo.Manufacturer,
  8263. Dealer: stockInInfo.Dealer,
  8264. LicenseNumber: stockInInfo.LicenseNumber,
  8265. IsEdit: 2,
  8266. Creator: creater,
  8267. SystemTime: record_time,
  8268. ConsumableType: 3,
  8269. WarehousingDetailId: 0,
  8270. IsSys: 1,
  8271. UpdateCreator: creater,
  8272. PatientId: patient_id,
  8273. StorehouseId: houseConfig.StorehouseOutInfo,
  8274. }
  8275. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8276. if errflow == gorm.ErrRecordNotFound {
  8277. //创建流水表
  8278. err := service.CreateStockFlowOne(stockFlow)
  8279. fmt.Println("err", err)
  8280. } else if errflow == nil {
  8281. //插入详情明细表
  8282. stockFlow := models.VmStockFlow{
  8283. ID: exsit.ID,
  8284. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8285. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8286. WarehouseOutId: warehouseOut.ID,
  8287. GoodId: good_yc.GoodId,
  8288. Number: warehouseOutInfos.Number,
  8289. ProductDate: stockInInfo.ProductDate,
  8290. ExpireDate: stockInInfo.ExpiryDate,
  8291. Count: exsit.Count - delete_count,
  8292. Price: stockInInfo.Price,
  8293. Status: 1,
  8294. Ctime: time.Now().Unix(),
  8295. UserOrgId: good_yc.OrgId,
  8296. Manufacturer: stockInInfo.Manufacturer,
  8297. Dealer: stockInInfo.Dealer,
  8298. LicenseNumber: stockInInfo.LicenseNumber,
  8299. IsEdit: 2,
  8300. Creator: creater,
  8301. SystemTime: record_time,
  8302. ConsumableType: 3,
  8303. WarehousingDetailId: 0,
  8304. IsSys: 1,
  8305. UpdateCreator: creater,
  8306. PatientId: patient_id,
  8307. StorehouseId: houseConfig.StorehouseOutInfo,
  8308. }
  8309. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8310. }
  8311. if errOne != nil {
  8312. return errOne
  8313. }
  8314. } else if errcod == nil {
  8315. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8316. //插入详情明细表
  8317. stockFlow := models.VmStockFlow{
  8318. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8319. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8320. WarehouseOutId: warehouseOut.ID,
  8321. GoodId: good_yc.GoodId,
  8322. Number: warehouseOutInfos.Number,
  8323. ProductDate: stockInInfo.ProductDate,
  8324. ExpireDate: stockInInfo.ExpiryDate,
  8325. Count: count,
  8326. Price: stockInInfo.Price,
  8327. Status: 1,
  8328. Ctime: time.Now().Unix(),
  8329. UserOrgId: good_yc.OrgId,
  8330. Manufacturer: stockInInfo.Manufacturer,
  8331. Dealer: stockInInfo.Dealer,
  8332. LicenseNumber: stockInInfo.LicenseNumber,
  8333. IsEdit: 2,
  8334. Creator: creater,
  8335. SystemTime: record_time,
  8336. ConsumableType: 3,
  8337. WarehousingDetailId: 0,
  8338. IsSys: 1,
  8339. UpdateCreator: creater,
  8340. PatientId: patient_id,
  8341. ReturnCount: delete_count,
  8342. StorehouseId: houseConfig.StorehouseOutInfo,
  8343. }
  8344. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8345. if errflows == gorm.ErrRecordNotFound {
  8346. //创建流水表
  8347. service.CreateStockFlowOne(stockFlow)
  8348. } else if errflows == nil {
  8349. stockFlow := models.VmStockFlow{
  8350. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8351. ID: exsit.ID,
  8352. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8353. WarehouseOutId: warehouseOut.ID,
  8354. GoodId: good_yc.GoodId,
  8355. Number: warehouseOutInfos.Number,
  8356. ProductDate: stockInInfo.ProductDate,
  8357. ExpireDate: stockInInfo.ExpiryDate,
  8358. Count: exsit.Count - delete_count,
  8359. Price: stockInInfo.Price,
  8360. Status: 1,
  8361. Ctime: time.Now().Unix(),
  8362. UserOrgId: good_yc.OrgId,
  8363. Manufacturer: stockInInfo.Manufacturer,
  8364. Dealer: stockInInfo.Dealer,
  8365. LicenseNumber: stockInInfo.LicenseNumber,
  8366. IsEdit: 2,
  8367. Creator: creater,
  8368. SystemTime: record_time,
  8369. ConsumableType: 3,
  8370. WarehousingDetailId: 0,
  8371. IsSys: 1,
  8372. UpdateCreator: creater,
  8373. PatientId: patient_id,
  8374. ReturnCount: delete_count,
  8375. StorehouseId: houseConfig.StorehouseOutInfo,
  8376. }
  8377. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8378. }
  8379. }
  8380. //更改自动出库的表格
  8381. details := models.BloodAutomaticReduceDetail{
  8382. WarehouseOutId: warehouseOutInfo.ID,
  8383. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8384. PatientId: patient_id,
  8385. Ctime: time.Now().Unix(),
  8386. Mtime: time.Now().Unix(),
  8387. Status: 1,
  8388. RecordTime: record_time,
  8389. OrgId: orgID,
  8390. GoodId: good_yc.GoodId,
  8391. GoodTypeId: good_yc.GoodTypeId,
  8392. Count: count,
  8393. StorehouseId: houseConfig.StorehouseOutInfo,
  8394. }
  8395. //查询当天耗材是否已经存在数据
  8396. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8397. if errcode == gorm.ErrRecordNotFound {
  8398. errTwo := service.CreateAutoReduceRecord(&details)
  8399. if errTwo != nil {
  8400. return errTwo
  8401. }
  8402. } else if errcode == nil {
  8403. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8404. service.CreateAutoReduceRecord(&details)
  8405. }
  8406. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8407. //增加出库库存数量
  8408. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8409. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8410. fmt.Println("errOne", errOne)
  8411. // 删除出库完成后,要增加对应批次的库存数量
  8412. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8413. if errThree != nil {
  8414. return errThree
  8415. }
  8416. if good_yc.Count == 0 {
  8417. return nil
  8418. } else {
  8419. return errors.New("退库和出库数据不匹配")
  8420. }
  8421. }
  8422. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8423. //查询该患者当天已经出库的耗材信息
  8424. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8425. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8426. for i := len(goods_yc) - 1; i >= 0; i-- {
  8427. goods_yc_temp := goods_yc[i]
  8428. for j := len(goods) - 1; j >= 0; j-- {
  8429. goods_temp := goods[j]
  8430. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8431. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8432. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8433. if goods_yc_temp.Count == goods_temp.Count {
  8434. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8435. goods = append(goods[:j], goods[j+1:]...)
  8436. break
  8437. }
  8438. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8439. if goods_yc_temp.Count > goods_temp.Count {
  8440. temp_count := goods_yc_temp.Count - goods_temp.Count
  8441. goods_yc[i].Count = temp_count
  8442. goods = append(goods[:j], goods[j+1:]...)
  8443. break
  8444. }
  8445. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8446. if goods_yc_temp.Count < goods_temp.Count {
  8447. temp_count := goods_temp.Count - goods_yc_temp.Count
  8448. goods[j].Count = temp_count
  8449. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8450. break
  8451. }
  8452. }
  8453. }
  8454. }
  8455. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8456. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8457. fmt.Println("剩余需要出库的", len(goods))
  8458. if len(goods) > 0 {
  8459. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8460. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8461. if err == gorm.ErrRecordNotFound {
  8462. //没有记录,则创建出库单
  8463. timeStr := time.Now().Format("2006-01-02")
  8464. timeArr := strings.Split(timeStr, "-")
  8465. total, _ := service.FindAllWarehouseOut(orgID)
  8466. total = total + 1
  8467. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8468. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8469. number = number + total
  8470. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8471. warehouseOut := models.WarehouseOut{
  8472. WarehouseOutOrderNumber: warehousing_out_order,
  8473. OperationTime: time.Now().Unix(),
  8474. OrgId: orgID,
  8475. Creater: creater,
  8476. Ctime: time.Now().Unix(),
  8477. Status: 1,
  8478. WarehouseOutTime: record_time,
  8479. Dealer: 0,
  8480. Manufacturer: 0,
  8481. Type: 1,
  8482. IsSys: 1,
  8483. StorehouseId: houseConfig.StorehouseOutInfo,
  8484. IsCheck: 1,
  8485. }
  8486. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  8487. if err != nil {
  8488. utils.TraceLog("创建出库单失败 err = %v", err)
  8489. return err
  8490. } else {
  8491. out = warehouseOut
  8492. }
  8493. }
  8494. for _, item := range goods {
  8495. var newCount int64 = 0
  8496. for _, it := range goodOne {
  8497. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8498. newCount = it.Count
  8499. }
  8500. }
  8501. prepare := models.DialysisBeforePrepare{
  8502. GoodTypeId: item.GoodTypeId,
  8503. GoodId: item.GoodId,
  8504. Count: item.Count,
  8505. StorehouseId: houseConfig.StorehouseOutInfo,
  8506. }
  8507. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8508. //增加出库数量
  8509. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8510. }
  8511. }
  8512. if len(goods_yc) > 0 {
  8513. for _, good_yc := range goods_yc {
  8514. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8515. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8516. }
  8517. }
  8518. return nil
  8519. }
  8520. // 耗材出库删除
  8521. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8522. // 先根据相关信息查询当天该耗材的出库信息
  8523. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8524. if err != nil {
  8525. return err
  8526. }
  8527. var delete_count int64 = 0
  8528. for _, ware := range warehouseOutInfos {
  8529. // 判断当前出库的数据和删除出库数量
  8530. if good_yc.Count <= ware.Count {
  8531. delete_count = good_yc.Count
  8532. } else {
  8533. delete_count = ware.Count
  8534. }
  8535. warehouseOutInfo := &models.WarehouseOutInfo{
  8536. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8537. WarehouseOutId: warehouseOut.ID,
  8538. Status: 1,
  8539. Ctime: time.Now().Unix(),
  8540. Remark: "",
  8541. OrgId: orgID,
  8542. Type: 1,
  8543. Manufacturer: 0,
  8544. Dealer: 0,
  8545. IsSys: 0,
  8546. SysRecordTime: record_time,
  8547. GoodTypeId: good_yc.GoodTypeId,
  8548. GoodId: good_yc.GoodId,
  8549. StorehouseId: warehouseOut.StorehouseId,
  8550. IsCheck: 1,
  8551. }
  8552. warehouseOutInfo.Count = delete_count
  8553. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8554. warehouseOutInfo.Price = stockInInfo.Price
  8555. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8556. if errOne != nil {
  8557. return errOne
  8558. }
  8559. // 删除出库完成后,要改变流水库存(有疑问)
  8560. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8561. fmt.Println("errOne", errOne)
  8562. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8563. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8564. //扣减出库数量
  8565. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8566. if errThree != nil {
  8567. return errThree
  8568. }
  8569. }
  8570. if good_yc.Count == 0 {
  8571. return nil
  8572. } else {
  8573. return errors.New("退库和出库数据不匹配")
  8574. }
  8575. }
  8576. func (this *DialysisAPIController) GetMobileScheduleList() {
  8577. limit, _ := this.GetInt64("limit")
  8578. page, _ := this.GetInt64("page")
  8579. type_options_visible, _ := this.GetInt64("type_options_visible")
  8580. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8581. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8582. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8583. }
  8584. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8585. newArr = make([]*models.HisPrescriptionProject, 0)
  8586. for i := 0; i < len(arr); i++ {
  8587. repeat := false
  8588. for j := i + 1; j < len(arr); j++ {
  8589. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8590. repeat = true
  8591. break
  8592. }
  8593. }
  8594. if !repeat {
  8595. newArr = append(newArr, arr[i])
  8596. }
  8597. }
  8598. return
  8599. }
  8600. func (this *DialysisAPIController) GetRoleList() {
  8601. admin_user_id, _ := this.GetInt64("admin_user_id")
  8602. orgid := this.GetMobileAdminUserInfo().Org.Id
  8603. list, err := service.GetRoleList(orgid, admin_user_id)
  8604. fmt.Println(err)
  8605. this.ServeSuccessJSON(map[string]interface{}{
  8606. "list": list,
  8607. })
  8608. return
  8609. }
  8610. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8611. // 先根据相关信息查询当天该耗材的出库信息
  8612. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8613. if err != nil {
  8614. return err
  8615. }
  8616. var delete_count int64 = 0
  8617. delete_count = warehouseOutInfos.Count - count
  8618. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8619. // 删除出库完成后,要增加对应批次的库存数量
  8620. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8621. if errThree != nil {
  8622. return errThree
  8623. }
  8624. //增加退库数量
  8625. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8626. //扣减出库数量
  8627. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8628. //查询剩余库存
  8629. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8630. var sum_count int64
  8631. for _, item := range goodList {
  8632. sum_count += item.StockCount
  8633. }
  8634. // 在出库记录表里记录退库详情
  8635. warehouseOutInfo := &models.WarehouseOutInfo{
  8636. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8637. WarehouseOutId: warehouseOut.ID,
  8638. Status: 1,
  8639. Ctime: time.Now().Unix(),
  8640. OrgId: orgID,
  8641. Type: 1,
  8642. IsSys: 1,
  8643. SysRecordTime: record_time,
  8644. GoodTypeId: good_yc.GoodTypeId,
  8645. GoodId: good_yc.GoodId,
  8646. PatientId: good_yc.PatientId,
  8647. ConsumableType: 2,
  8648. StorehouseId: houseConfig.StorehouseOutInfo,
  8649. IsCheck: 1,
  8650. OverCount: sum_count,
  8651. }
  8652. warehouseOutInfo.Count = count
  8653. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8654. warehouseOutInfo.Price = stockInInfo.Price
  8655. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8656. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8657. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8658. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8659. warehouseOutInfo.Number = warehouseOutInfos.Number
  8660. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8661. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8662. //查找当天是否存在出库记录
  8663. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8664. if errcod == gorm.ErrRecordNotFound {
  8665. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8666. //插入详情明细表
  8667. if errOne != nil {
  8668. return errOne
  8669. }
  8670. //插入详情明细表
  8671. stockFlow := models.VmStockFlow{
  8672. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8673. WarehouseOutId: warehouseOut.ID,
  8674. GoodId: good_yc.GoodId,
  8675. Number: warehouseOutInfos.Number,
  8676. ProductDate: stockInInfo.ProductDate,
  8677. ExpireDate: stockInInfo.ExpiryDate,
  8678. Count: count,
  8679. Price: stockInInfo.Price,
  8680. Status: 1,
  8681. Ctime: record_time,
  8682. UserOrgId: good_yc.OrgId,
  8683. Manufacturer: stockInInfo.Manufacturer,
  8684. Dealer: stockInInfo.Dealer,
  8685. LicenseNumber: stockInInfo.LicenseNumber,
  8686. IsEdit: 2,
  8687. Creator: creater,
  8688. SystemTime: record_time,
  8689. ConsumableType: 3,
  8690. WarehousingDetailId: 0,
  8691. IsSys: 1,
  8692. UpdateCreator: creater,
  8693. PatientId: patient_id,
  8694. StorehouseId: houseConfig.StorehouseOutInfo,
  8695. OverCount: sum_count,
  8696. ProjectId: good_yc.ProjectId,
  8697. }
  8698. err := service.CreateStockFlowOne(stockFlow)
  8699. fmt.Println("err", err)
  8700. } else if errcod == nil {
  8701. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8702. }
  8703. //创建退库单
  8704. operation_time := time.Now().Unix()
  8705. //创建退库单
  8706. timeStr := time.Now().Format("2006-01-02")
  8707. timeArr := strings.Split(timeStr, "-")
  8708. total, _ := service.FindAllCancelStockTotal(orgID)
  8709. total = total + 1
  8710. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8711. cancelStock := models.CancelStock{
  8712. OrderNumber: orderNumber,
  8713. OperaTime: operation_time,
  8714. OrgId: orgID,
  8715. Creater: warehouseOut.Creater,
  8716. Ctime: time.Now().Unix(),
  8717. Status: 1,
  8718. ReturnTime: record_time,
  8719. Type: 1,
  8720. StorehouseId: stockInInfo.StorehouseId,
  8721. IsCheck: 1,
  8722. }
  8723. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8724. if msgerrkonde == gorm.ErrRecordNotFound {
  8725. service.AddSigleCancelStock(&cancelStock)
  8726. }
  8727. cancel, _ := service.GetLastCancelStockById(orgID)
  8728. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8729. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8730. cancelStockInfo := models.CancelStockInfo{
  8731. GoodId: stockInInfo.GoodId,
  8732. CancelStockId: cancel.ID,
  8733. GoodTypeId: stockInInfo.GoodTypeId,
  8734. Count: delete_count,
  8735. Price: stockInInfo.PackingPrice,
  8736. Total: 0,
  8737. ProductDate: stockInInfo.ProductDate,
  8738. ExpiryDate: stockInInfo.ExpiryDate,
  8739. Ctime: record_time,
  8740. Status: 1,
  8741. OrgId: orgID,
  8742. OrderNumber: cancel.OrderNumber,
  8743. Type: 0,
  8744. Dealer: deaerler.DealerName,
  8745. Manufacturer: manufacturer.ManufacturerName,
  8746. Number: stockInInfo.Number,
  8747. RegisterAccount: "",
  8748. Remark: "",
  8749. WarehouseInfoId: stockInInfo.ID,
  8750. PatientId: patient_id,
  8751. RecordDate: record_time,
  8752. StorehouseId: stockInInfo.StorehouseId,
  8753. IsCheck: 1,
  8754. }
  8755. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8756. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8757. flow := models.VmStockFlow{
  8758. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8759. GoodId: good_yc.GoodId,
  8760. Number: warehouseOutInfos.Number,
  8761. LicenseNumber: stockInInfo.LicenseNumber,
  8762. Count: delete_count,
  8763. UserOrgId: orgID,
  8764. PatientId: patient_id,
  8765. SystemTime: record_time,
  8766. ConsumableType: 7,
  8767. IsSys: 0,
  8768. WarehousingOrder: "",
  8769. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8770. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8771. IsEdit: 0,
  8772. CancelStockId: cancel.ID,
  8773. CancelOrderNumber: cancel.OrderNumber,
  8774. Manufacturer: manufacturer.ID,
  8775. Dealer: 0,
  8776. Creator: warehouseOut.Creater,
  8777. UpdateCreator: 0,
  8778. Status: 1,
  8779. Ctime: record_time,
  8780. Mtime: 0,
  8781. Price: stockInInfo.Price,
  8782. WarehousingDetailId: stockInInfo.ID,
  8783. WarehouseOutDetailId: warehouseOutInfos.ID,
  8784. CancelOutDetailId: cancelInfo.ID,
  8785. ProductDate: stockInInfo.ProductDate,
  8786. ExpireDate: stockInInfo.ExpiryDate,
  8787. StorehouseId: houseConfig.StorehouseOutInfo,
  8788. OverCount: sum_count,
  8789. }
  8790. service.CreateStockFlowOne(flow)
  8791. //更改自动出库的表格
  8792. details := models.BloodAutomaticReduceDetail{
  8793. WarehouseOutId: warehouseOutInfo.ID,
  8794. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8795. PatientId: patient_id,
  8796. Ctime: time.Now().Unix(),
  8797. Mtime: time.Now().Unix(),
  8798. Status: 1,
  8799. RecordTime: record_time,
  8800. OrgId: orgID,
  8801. GoodId: good_yc.GoodId,
  8802. GoodTypeId: good_yc.GoodTypeId,
  8803. Count: count,
  8804. StorehouseId: houseConfig.StorehouseOutInfo,
  8805. }
  8806. //查询当天耗材是否已经存在数据
  8807. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8808. if errcode == gorm.ErrRecordNotFound {
  8809. errTwo := service.CreateAutoReduceRecord(&details)
  8810. if errTwo != nil {
  8811. return errTwo
  8812. }
  8813. } else if errcode == nil {
  8814. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8815. service.CreateAutoReduceRecord(&details)
  8816. }
  8817. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8818. //增加出库库存数量
  8819. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8820. if good_yc.Count == 0 {
  8821. return nil
  8822. } else {
  8823. return errors.New("退库和出库数据不匹配")
  8824. }
  8825. }
  8826. func (this *DialysisAPIController) SavePatientSign() {
  8827. adminUserInfo := this.GetMobileAdminUserInfo()
  8828. patient_id, _ := this.GetInt64("patient_id")
  8829. dialysis_date, _ := this.GetInt64("dialysis_date")
  8830. orgid := adminUserInfo.Org.Id
  8831. var esdata models.DialysisOrder
  8832. var err error
  8833. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8834. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8835. return
  8836. }
  8837. esdata.Hash = esdata.Hash
  8838. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8839. order := models.DialysisOrder{
  8840. Hash: esdata.Hash,
  8841. Url: esdata.Url,
  8842. }
  8843. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8844. redis := service.RedisClient()
  8845. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8846. redis.Set(key, "", time.Second)
  8847. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8848. //清空key 值
  8849. redis.Set(keyOne, "", time.Second)
  8850. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8851. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8852. //redis.Set(keyTwo, "", time.Second)
  8853. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8854. redis.Set(keyThree, "", time.Second)
  8855. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8856. redis.Set(keyFour, "", time.Second)
  8857. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8858. redis.Set(keyFive, "", time.Second)
  8859. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8860. redis.Set(keySix, "", time.Second)
  8861. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8862. redis.Set(keySeven, "", time.Second)
  8863. if err != nil {
  8864. fmt.Println(err)
  8865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8866. return
  8867. }
  8868. this.ServeSuccessJSON(map[string]interface{}{
  8869. "electronic_signature": esdata,
  8870. })
  8871. }
  8872. func (this *DialysisAPIController) GetPatientSign() {
  8873. patient_id, _ := this.GetInt64("patient_id")
  8874. dialysis_date, _ := this.GetInt64("dialysis_date")
  8875. adminUserInfo := this.GetMobileAdminUserInfo()
  8876. orgId := adminUserInfo.Org.Id
  8877. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8878. if err != nil {
  8879. fmt.Println(err)
  8880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8881. return
  8882. }
  8883. this.ServeSuccessJSON(map[string]interface{}{
  8884. "dialysisOrder": dialysisOrder,
  8885. })
  8886. }
  8887. func (this *DialysisAPIController) GetScheduleByPatient() {
  8888. patient_id, _ := this.GetInt64("patient_id")
  8889. schedule_date, _ := this.GetInt64("schedule_date")
  8890. orgid := this.GetMobileAdminUserInfo().Org.Id
  8891. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8892. this.ServeSuccessJSON(map[string]interface{}{
  8893. "schedule": schedule,
  8894. })
  8895. }
  8896. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8897. org_id := this.GetMobileAdminUserInfo().Org.Id
  8898. patient_id, _ := this.GetInt64("patient_id")
  8899. schedule_date, _ := this.GetInt64("schedule_date")
  8900. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8901. this.ServeSuccessJSON(map[string]interface{}{
  8902. "order": order,
  8903. })
  8904. }
  8905. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8906. org_id := this.GetMobileAdminUserInfo().Org.Id
  8907. schedule_date := this.GetString("schedule_date")
  8908. schedule_type, _ := this.GetInt64("schedule_type")
  8909. timeLayout := "2006-01-02"
  8910. loc, _ := time.LoadLocation("Local")
  8911. var startdateunix int64
  8912. if len(schedule_date) > 0 {
  8913. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8914. if err != nil {
  8915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8916. return
  8917. }
  8918. startdateunix = theTime.Unix()
  8919. }
  8920. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8921. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8922. devices, _ := service.GetAllDevicetByListSix(org_id)
  8923. for key, item := range scheduals {
  8924. // 床位信息
  8925. for _, device := range devices {
  8926. if item.BedId == device.ID {
  8927. scheduals[key].DeviceNumber = device
  8928. break
  8929. }
  8930. }
  8931. }
  8932. this.ServeSuccessJSON(map[string]interface{}{
  8933. "list": list,
  8934. "scheduals": scheduals,
  8935. })
  8936. }
  8937. func (this *DialysisAPIController) SavePatientPicture() {
  8938. patient_id, _ := this.GetInt64("patient_id")
  8939. dialysis_date, _ := this.GetInt64("schedule_date")
  8940. avatar := this.GetString("avatar")
  8941. fmt.Println("patient_id", patient_id)
  8942. orgId := this.GetMobileAdminUserInfo().Org.Id
  8943. order := models.DialysisOrder{
  8944. Url: avatar,
  8945. }
  8946. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8947. redis := service.RedisClient()
  8948. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8949. redis.Set(key, "", time.Second)
  8950. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8951. //清空key 值
  8952. redis.Set(keyOne, "", time.Second)
  8953. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8954. redis.Set(keyThree, "", time.Second)
  8955. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8956. redis.Set(keyFour, "", time.Second)
  8957. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8958. redis.Set(keyFive, "", time.Second)
  8959. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8960. redis.Set(keySix, "", time.Second)
  8961. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8962. redis.Set(keySeven, "", time.Second)
  8963. if err != nil {
  8964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8965. return
  8966. }
  8967. this.ServeSuccessJSON(map[string]interface{}{
  8968. "order": order,
  8969. })
  8970. }
  8971. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8972. ids := this.GetString("ids")
  8973. idSplit := strings.Split(ids, ",")
  8974. orgId := this.GetMobileAdminUserInfo().Org.Id
  8975. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8976. execution_time := this.GetString("exce_time")
  8977. timeLayout2 := "2006-01-02 15:04:05"
  8978. loc, _ := time.LoadLocation("Local")
  8979. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8980. if errs != nil {
  8981. utils.ErrorLog(errs.Error())
  8982. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8983. return
  8984. }
  8985. //his客户
  8986. if config.IsOpen == 1 {
  8987. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8988. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8989. for _, item := range list {
  8990. for _, it := range adviceList {
  8991. if item.DrugId == it.DrugId {
  8992. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8993. }
  8994. }
  8995. }
  8996. for _, item := range list {
  8997. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8998. var sum_out_count int64
  8999. for _, itemThree := range item.ChildDoctorAdvice {
  9000. var prescribing_number int64
  9001. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9002. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9003. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9004. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9005. }
  9006. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9007. prescribing_number = parseIntPrescribingNumber
  9008. }
  9009. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9010. prescribing_number = parseIntPrescribingNumber
  9011. }
  9012. sum_out_count += prescribing_number
  9013. }
  9014. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9015. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9016. //库存不足
  9017. if sum_out_count > drugStockOut.FlushCount {
  9018. this.ServeSuccessJSON(map[string]interface{}{
  9019. "msg": "2",
  9020. "drug": medical,
  9021. "ids": ids,
  9022. })
  9023. return
  9024. }
  9025. }
  9026. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9027. //执行医嘱
  9028. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9029. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9030. for _, item := range advices {
  9031. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9032. redis := service.RedisClient()
  9033. //清空key 值
  9034. redis.Set(key, "", time.Second)
  9035. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9036. redis.Set(keyTwo, "", time.Second)
  9037. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9038. redis.Set(keyThree, "", time.Second)
  9039. recordDate := theTime.Format("2006-01-02")
  9040. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9041. redis.Set(keyFour, "", time.Second)
  9042. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9043. redis.Set(keyFive, "", time.Second)
  9044. defer redis.Close()
  9045. }
  9046. if errs == nil {
  9047. //药品管理信息
  9048. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9049. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9050. if drugStockConfig.IsOpen == 1 {
  9051. for _, item := range advices {
  9052. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9053. config, _ := service.GetDrugOpenConfigOne(orgId)
  9054. if config.IsOpen != 1 {
  9055. //查询该药品是否有库存
  9056. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9057. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9058. if medical.IsUse == 2 {
  9059. if config.IsOpen != 1 {
  9060. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9061. service.HisDrugsDelivery(orgId, creater, &advice)
  9062. if orgId == 3877 || orgId == 10265 {
  9063. //查询该药品是否有出库记录
  9064. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9065. if len(flowMap) == 0 {
  9066. errs := service.UpdateHisAdviceById(advice.ID)
  9067. if errs != nil {
  9068. drugError := models.XtDrugError{
  9069. UserOrgId: orgId,
  9070. DrugId: item.DrugId,
  9071. RecordDate: item.AdviceDate,
  9072. PatientId: item.PatientId,
  9073. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9074. Status: 1,
  9075. Ctime: time.Now().Unix(),
  9076. Mtime: 0,
  9077. SumCount: 0,
  9078. Prescribingnumber: advice.PrescribingNumber,
  9079. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9080. }
  9081. service.CreateDrugError(drugError)
  9082. }
  9083. this.ServeSuccessJSON(map[string]interface{}{
  9084. "msg": "2",
  9085. "drug": medical,
  9086. "ids": ids,
  9087. })
  9088. return
  9089. }
  9090. }
  9091. }
  9092. if pharmacyConfig.IsOpen != 1 {
  9093. service.HisDrugsDelivery(orgId, creater, &advice)
  9094. if orgId == 3877 || orgId == 10265 {
  9095. //查询该药品是否有出库记录
  9096. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9097. if len(flowMap) == 0 {
  9098. errs := service.UpdateHisAdviceById(advice.ID)
  9099. if errs != nil {
  9100. drugError := models.XtDrugError{
  9101. UserOrgId: orgId,
  9102. DrugId: item.DrugId,
  9103. RecordDate: item.AdviceDate,
  9104. PatientId: item.PatientId,
  9105. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9106. Status: 1,
  9107. Ctime: time.Now().Unix(),
  9108. Mtime: 0,
  9109. SumCount: 0,
  9110. Prescribingnumber: advice.PrescribingNumber,
  9111. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9112. }
  9113. service.CreateDrugError(drugError)
  9114. }
  9115. this.ServeSuccessJSON(map[string]interface{}{
  9116. "msg": "2",
  9117. "drug": medical,
  9118. "ids": ids,
  9119. })
  9120. return
  9121. }
  9122. }
  9123. }
  9124. //更新字典里面的库存
  9125. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9126. var sum_count int64
  9127. for _, its := range stockInfo {
  9128. if its.MaxUnit == medical.MaxUnit {
  9129. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9130. }
  9131. sum_count += its.StockMaxNumber + its.StockMinNumber
  9132. }
  9133. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9134. //剩余库存
  9135. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9136. }
  9137. }
  9138. }
  9139. }
  9140. }
  9141. this.ServeSuccessJSON(map[string]interface{}{
  9142. "msg": "1",
  9143. "ids": ids,
  9144. })
  9145. return
  9146. } else {
  9147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9148. }
  9149. }
  9150. //血透客户
  9151. if config.IsOpen == 2 || config.IsOpen == 0 {
  9152. //药品管理信息
  9153. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9154. if drugStockConfig.IsOpen == 1 {
  9155. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9156. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9157. for _, item := range list {
  9158. for _, it := range adviceList {
  9159. if item.DrugId == it.DrugId {
  9160. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9161. }
  9162. }
  9163. }
  9164. for _, item := range list {
  9165. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9166. var sum_out_count int64
  9167. for _, itemThree := range item.ChildDoctorAdvice {
  9168. var prescribing_number int64
  9169. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9170. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9171. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9172. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9173. }
  9174. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9175. prescribing_number = parseIntPrescribingNumber
  9176. }
  9177. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9178. prescribing_number = parseIntPrescribingNumber
  9179. }
  9180. sum_out_count += prescribing_number
  9181. }
  9182. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9183. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9184. //库存不足
  9185. if sum_out_count > drugStockOut.FlushCount {
  9186. this.ServeSuccessJSON(map[string]interface{}{
  9187. "msg": "2",
  9188. "drug": medical,
  9189. "ids": ids,
  9190. })
  9191. return
  9192. }
  9193. }
  9194. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9195. //执行医嘱
  9196. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9197. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9198. for _, item := range advices {
  9199. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9200. redis := service.RedisClient()
  9201. //清空key 值
  9202. redis.Set(key, "", time.Second)
  9203. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9204. redis.Set(keyTwo, "", time.Second)
  9205. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9206. redis.Set(keyThree, "", time.Second)
  9207. recordDate := theTime.Format("2006-01-02")
  9208. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9209. redis.Set(keyFour, "", time.Second)
  9210. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9211. redis.Set(keyFive, "", time.Second)
  9212. defer redis.Close()
  9213. }
  9214. if errs == nil {
  9215. for _, item := range advices {
  9216. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9217. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9218. //查询是否出库按钮开启
  9219. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9220. if adviceSetting.IsAdviceOpen == 1 {
  9221. //查询是否出库按钮开启
  9222. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9223. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9224. if prescriptionConfig.IsOpen == 1 {
  9225. if medical.IsUse == 2 {
  9226. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9227. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9228. }
  9229. if pharmacyConfig.IsOpen != 1 {
  9230. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9231. }
  9232. //更新字典里面的库存
  9233. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9234. var sum_count int64
  9235. for _, its := range stockInfo {
  9236. if its.MaxUnit == medical.MaxUnit {
  9237. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9238. }
  9239. sum_count += its.StockMaxNumber + its.StockMinNumber
  9240. }
  9241. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9242. //剩余库存
  9243. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9244. }
  9245. }
  9246. } else {
  9247. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9248. if medical.IsUse == 2 {
  9249. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9250. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9251. }
  9252. if pharmacyConfig.IsOpen != 1 {
  9253. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9254. }
  9255. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9256. var sum_count int64
  9257. for _, its := range stockInfo {
  9258. if its.MaxUnit == medical.MaxUnit {
  9259. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9260. }
  9261. sum_count += its.StockMaxNumber + its.StockMinNumber
  9262. }
  9263. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9264. //剩余库存
  9265. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9266. }
  9267. }
  9268. }
  9269. }
  9270. this.ServeSuccessJSON(map[string]interface{}{
  9271. "msg": "1",
  9272. "ids": ids,
  9273. })
  9274. return
  9275. } else {
  9276. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9277. //执行医嘱
  9278. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9279. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9280. for _, item := range advices {
  9281. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9282. redis := service.RedisClient()
  9283. //清空key 值
  9284. redis.Set(key, "", time.Second)
  9285. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9286. redis.Set(keyTwo, "", time.Second)
  9287. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9288. redis.Set(keyThree, "", time.Second)
  9289. recordDate := theTime.Format("2006-01-02")
  9290. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9291. redis.Set(keyFour, "", time.Second)
  9292. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9293. redis.Set(keyFive, "", time.Second)
  9294. defer redis.Close()
  9295. }
  9296. this.ServeSuccessJSON(map[string]interface{}{
  9297. "msg": "1",
  9298. "ids": ids,
  9299. })
  9300. return
  9301. }
  9302. }
  9303. }
  9304. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9305. ids := this.GetString("ids")
  9306. idSplit := strings.Split(ids, ",")
  9307. orgId := this.GetMobileAdminUserInfo().Org.Id
  9308. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9309. if config.IsOpen == 1 {
  9310. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9311. this.ServeSuccessJSON(map[string]interface{}{
  9312. "msg": "1",
  9313. "ids": ids,
  9314. })
  9315. return
  9316. }
  9317. if config.IsOpen == 0 || config.IsOpen == 2 {
  9318. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9319. this.ServeSuccessJSON(map[string]interface{}{
  9320. "msg": "1",
  9321. "ids": ids,
  9322. })
  9323. return
  9324. }
  9325. }
  9326. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9327. ids := this.GetString("ids")
  9328. idSplit := strings.Split(ids, ",")
  9329. orgId := this.GetMobileAdminUserInfo().Org.Id
  9330. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9331. //his
  9332. if config.IsOpen == 1 {
  9333. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9334. theTime := time.Now()
  9335. advices := models.HisDoctorAdviceThirty{
  9336. CheckTime: theTime.Unix(),
  9337. Checker: checker,
  9338. UpdatedTime: time.Now().Unix(),
  9339. }
  9340. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9341. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9342. for _, item := range list {
  9343. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9344. redis := service.RedisClient()
  9345. //清空key 值
  9346. redis.Set(key, "", time.Second)
  9347. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9348. redis.Set(keyTwo, "", time.Second)
  9349. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9350. redis.Set(keyThree, "", time.Second)
  9351. recordDate := theTime.Format("2006-01-02")
  9352. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9353. redis.Set(keyFour, "", time.Second)
  9354. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9355. redis.Set(keyFive, "", time.Second)
  9356. defer redis.Close()
  9357. }
  9358. this.ServeSuccessJSON(map[string]interface{}{
  9359. "msg": "1",
  9360. "ids": ids,
  9361. })
  9362. return
  9363. }
  9364. //血透
  9365. if config.IsOpen == 0 || config.IsOpen == 2 {
  9366. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9367. theTime := time.Now()
  9368. advices := models.DoctorAdvice{
  9369. CheckTime: theTime.Unix(),
  9370. Checker: checker,
  9371. UpdatedTime: time.Now().Unix(),
  9372. }
  9373. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9374. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9375. for _, item := range list {
  9376. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9377. redis := service.RedisClient()
  9378. //清空key 值
  9379. redis.Set(key, "", time.Second)
  9380. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9381. redis.Set(keyTwo, "", time.Second)
  9382. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9383. redis.Set(keyThree, "", time.Second)
  9384. recordDate := theTime.Format("2006-01-02")
  9385. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9386. redis.Set(keyFour, "", time.Second)
  9387. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9388. redis.Set(keyFive, "", time.Second)
  9389. defer redis.Close()
  9390. }
  9391. this.ServeSuccessJSON(map[string]interface{}{
  9392. "msg": "1",
  9393. "ids": ids,
  9394. })
  9395. return
  9396. }
  9397. }
  9398. func (this *DialysisAPIController) CheckSchedule() {
  9399. patientID, _ := this.GetInt64("patient_id")
  9400. recordDateStr := this.GetString("record_date")
  9401. nurseID, _ := this.GetInt64("start_nurse")
  9402. schedual_type, _ := this.GetInt64("schedual_type")
  9403. bedID, _ := this.GetInt64("bed")
  9404. start_time := this.GetString("start_time")
  9405. fmt.Println("patientID", patientID)
  9406. fmt.Println("recordDateStr", recordDateStr)
  9407. fmt.Println("nurseID", nurseID)
  9408. fmt.Println("schedual_type------", schedual_type)
  9409. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9411. return
  9412. }
  9413. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9414. if parseStartDateErr != nil {
  9415. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9416. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9417. return
  9418. }
  9419. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9420. if parseErr != nil {
  9421. this.ErrorLog("时间解析失败:%v", parseErr)
  9422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9423. return
  9424. }
  9425. adminUserInfo := this.GetMobileAdminUserInfo()
  9426. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9427. if getPatientErr != nil {
  9428. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9430. return
  9431. } else if patient == nil {
  9432. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9433. return
  9434. }
  9435. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9436. if getNurseErr != nil {
  9437. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9438. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9439. return
  9440. } else if nurse == nil {
  9441. this.ErrorLog("护士不存在")
  9442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9443. return
  9444. }
  9445. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9446. if getDeviceNumberErr != nil {
  9447. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9449. return
  9450. } else if deviceNumber == nil {
  9451. this.ErrorLog("床位号不存在")
  9452. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9453. return
  9454. }
  9455. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9456. if getRecordErr != nil {
  9457. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9459. return
  9460. } else if dialysisRecord != nil {
  9461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9462. return
  9463. }
  9464. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9465. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9466. timeLayout := "2006-01-02 15:04:05"
  9467. loc, _ := time.LoadLocation("Local")
  9468. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9469. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9470. schedulestartTime := theStartTime.Unix()
  9471. scheduleendTime := theEndTime.Unix()
  9472. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9473. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9474. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9475. //查询该床位是否有人用了
  9476. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9477. if err == nil {
  9478. if schedule.ID == 0 {
  9479. this.ServeSuccessJSON(map[string]interface{}{
  9480. "status": 0,
  9481. "msg": "请求失败",
  9482. })
  9483. } else {
  9484. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9485. if order.ID > 0 { //该机位被其他人占用了
  9486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9487. return
  9488. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9489. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9490. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9491. this.ServeSuccessJSON(map[string]interface{}{
  9492. "status": 1,
  9493. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9494. })
  9495. return
  9496. } else {
  9497. this.ServeSuccessJSON(map[string]interface{}{
  9498. "status": 0,
  9499. "msg": "",
  9500. })
  9501. }
  9502. }
  9503. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9504. this.ServeSuccessJSON(map[string]interface{}{
  9505. "status": 2,
  9506. "msg": "当前机位已有患者在使用,请重新选择!",
  9507. })
  9508. }
  9509. }
  9510. } else {
  9511. this.ServeSuccessJSON(map[string]interface{}{
  9512. "status": 0,
  9513. "msg": "",
  9514. })
  9515. }
  9516. }
  9517. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9518. orgId := this.GetMobileAdminUserInfo().Org.Id
  9519. schedule_type, _ := this.GetInt64("schedule_type")
  9520. partion_type, _ := this.GetInt64("partion_type")
  9521. start_time := this.GetString("start_time")
  9522. timeLayout := "2006-01-02"
  9523. loc, _ := time.LoadLocation("Local")
  9524. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9525. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9526. _, config := service.FindXTHisRecordByOrgId(orgId)
  9527. appId := this.GetMobileAdminUserInfo().App.Id
  9528. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9529. if err == nil {
  9530. this.ServeSuccessJSON(map[string]interface{}{
  9531. "list": list,
  9532. "config": config,
  9533. "doctorList": doctorList,
  9534. })
  9535. return
  9536. } else {
  9537. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9538. return
  9539. }
  9540. }
  9541. func (this *DialysisAPIController) SaveMobileInformation() {
  9542. patient_id, _ := this.GetInt64("patient_id")
  9543. record_date, _ := this.GetInt64("record_date")
  9544. startTime := this.GetString("start_time")
  9545. module, _ := this.GetInt64("module")
  9546. remark := this.GetString("remark")
  9547. timeLayout := "2006-01-02 15:04"
  9548. loc, _ := time.LoadLocation("Local")
  9549. if len(startTime) == 0 {
  9550. utils.ErrorLog("len(start_time) == 0")
  9551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9552. return
  9553. }
  9554. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9555. if err != nil {
  9556. utils.ErrorLog(err.Error())
  9557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9558. return
  9559. }
  9560. StartTime := theTime.Unix()
  9561. fmt.Println("startime-------------", StartTime)
  9562. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9563. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9564. information := models.XtDialysisInformation{
  9565. Module: module,
  9566. PatientId: patient_id,
  9567. RecordDate: record_date,
  9568. ApplicationDate: StartTime,
  9569. Creater: creater,
  9570. ApplicationStatus: 2,
  9571. Checker: 0,
  9572. CheckTime: 0,
  9573. Remark: remark,
  9574. UserOrgId: user_org_id,
  9575. Ctime: time.Now().Unix(),
  9576. Status: 1,
  9577. Mtime: 0,
  9578. }
  9579. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9580. if infor.ID == 0 {
  9581. service.SaveDialysisInformation(information)
  9582. }
  9583. if infor.ID > 0 {
  9584. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9585. }
  9586. this.ServeSuccessJSON(map[string]interface{}{
  9587. "information": information,
  9588. })
  9589. return
  9590. }
  9591. func (this *DialysisAPIController) GetMobileInformation() {
  9592. limit, _ := this.GetInt64("limit")
  9593. page, _ := this.GetInt64("page")
  9594. orgid := this.GetMobileAdminUserInfo().Org.Id
  9595. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9596. appid := this.GetMobileAdminUserInfo().App.Id
  9597. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9598. patients, _ := service.GetAllpatientThirty(orgid)
  9599. this.ServeSuccessJSON(map[string]interface{}{
  9600. "information": information,
  9601. "total": total,
  9602. "doclist": doclist,
  9603. "patients": patients,
  9604. })
  9605. return
  9606. }
  9607. func (this *DialysisAPIController) GetMobileInformationOne() {
  9608. limit, _ := this.GetInt64("limit")
  9609. page, _ := this.GetInt64("page")
  9610. orgid := this.GetMobileAdminUserInfo().Org.Id
  9611. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9612. appid := this.GetMobileAdminUserInfo().App.Id
  9613. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9614. patients, _ := service.GetAllpatientThirty(orgid)
  9615. this.ServeSuccessJSON(map[string]interface{}{
  9616. "information": information,
  9617. "total": total,
  9618. "doclist": doclist,
  9619. "patients": patients,
  9620. })
  9621. return
  9622. }
  9623. func (this *DialysisAPIController) CheckMobileInformation() {
  9624. id, _ := this.GetInt64("id")
  9625. application_status, _ := this.GetInt64("application_status")
  9626. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9627. checktime := time.Now().Unix()
  9628. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9629. if err == nil {
  9630. this.ServeSuccessJSON(map[string]interface{}{
  9631. "msg": "ok",
  9632. })
  9633. return
  9634. }
  9635. }
  9636. func (c *DialysisAPIController) GetControlMonitorList() {
  9637. partition, _ := c.GetInt64("partition")
  9638. monitorDate := c.GetString("date")
  9639. patient_id, _ := c.GetInt64("patient_id")
  9640. pat_type, _ := c.GetInt64("pat_type")
  9641. timeLayout := "2006-01-02"
  9642. loc, _ := time.LoadLocation("Local")
  9643. var theStartTime int64
  9644. if len(monitorDate) > 0 {
  9645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9646. if err != nil {
  9647. theStartTime = 0
  9648. }
  9649. theStartTime = theTime.Unix()
  9650. }
  9651. adminInfo := c.GetMobileAdminUserInfo()
  9652. orgID := adminInfo.Org.Id
  9653. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9654. if err != nil {
  9655. c.ErrorLog("获取排班信息失败:%v", err)
  9656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9657. } else {
  9658. if len(monitor) > 0 {
  9659. //获取所有床位
  9660. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9661. //获取所有分区
  9662. zoneList, _ := service.GetAllZoneByList(orgID)
  9663. //获取透析处方
  9664. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9665. //获取透前评估
  9666. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9667. //获取上机
  9668. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9669. //获取透后
  9670. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9671. //获取透后监测
  9672. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9673. //获取所有的患者
  9674. patients, _ := service.GetAllPatientListByListOne(orgID)
  9675. //获取所有透析模式
  9676. treatments, _ := service.GetAllTreatModeByList(orgID)
  9677. //获取所有医嘱
  9678. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9679. //获取双人核对
  9680. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9681. //治疗小结
  9682. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9683. //待消毒
  9684. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9685. for key, item := range monitor {
  9686. // 获取床位信息
  9687. for _, it := range numberList {
  9688. if item.BedId == it.ID {
  9689. monitor[key].DeviceNumber = it
  9690. break
  9691. }
  9692. }
  9693. //获取分区信息
  9694. for _, it := range zoneList {
  9695. if item.PartitionId == it.ID {
  9696. monitor[key].DeviceZone = it
  9697. }
  9698. }
  9699. for _, prescription := range prescriptions {
  9700. if item.PatientId == prescription.PatientId {
  9701. monitor[key].Prescription = prescription
  9702. break
  9703. }
  9704. }
  9705. for _, it := range checkList {
  9706. if item.PatientId == it.PatientId {
  9707. monitor[key].DoubleCheck = it
  9708. break
  9709. }
  9710. }
  9711. for _, it := range summaryList {
  9712. if item.PatientId == it.PatientId {
  9713. monitor[key].TreatmentSummaryForList = it
  9714. break
  9715. }
  9716. }
  9717. // 透前评估
  9718. for _, assessmentBefore := range assessmentBefores {
  9719. if item.PatientId == assessmentBefore.PatientId {
  9720. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9721. break
  9722. }
  9723. }
  9724. // 透析上下机
  9725. for _, dialysisOrder := range dialysisOrders {
  9726. if item.PatientId == dialysisOrder.PatientId {
  9727. monitor[key].DialysisOrder = dialysisOrder
  9728. break
  9729. }
  9730. }
  9731. // 治疗小节
  9732. for _, afterDislysis := range AssessmentAfterDislysis {
  9733. if item.PatientId == afterDislysis.PatientId {
  9734. monitor[key].AssessmentAfterDislysis = afterDislysis
  9735. break
  9736. }
  9737. }
  9738. for _, it := range monitorlist {
  9739. if item.PatientId == it.PatientId {
  9740. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9741. }
  9742. }
  9743. for _, it := range adviceList {
  9744. if item.PatientId == it.PatientId {
  9745. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9746. }
  9747. }
  9748. for _, patient := range patients {
  9749. if item.PatientId == patient.ID {
  9750. monitor[key].MonitorPatients = patient
  9751. break
  9752. }
  9753. }
  9754. for _, treatment := range treatments {
  9755. if item.ModeId == treatment.ID {
  9756. monitor[key].TreatmentMode = treatment
  9757. break
  9758. }
  9759. }
  9760. for _, infor := range informationList {
  9761. if item.PatientId == infor.PatientId {
  9762. monitor[key].NewDeviceInformation = infor
  9763. break
  9764. }
  9765. }
  9766. }
  9767. }
  9768. }
  9769. patients, err := service.GetAllpatientFourty(orgID)
  9770. var mds []*models.NewMonitorDialysisScheduleList
  9771. if pat_type == 0 {
  9772. for _, item := range monitor {
  9773. mds = append(mds, item)
  9774. }
  9775. }
  9776. //待医嘱核对
  9777. if pat_type == 1 {
  9778. for _, item := range monitor {
  9779. if len(item.AdviceList) > 0 {
  9780. mds = append(mds, item)
  9781. }
  9782. }
  9783. }
  9784. //待开小结
  9785. if pat_type == 2 {
  9786. for _, item := range monitor {
  9787. if item.TreatmentSummaryForList == nil {
  9788. mds = append(mds, item)
  9789. }
  9790. }
  9791. }
  9792. //待下机
  9793. if pat_type == 3 {
  9794. for _, item := range monitor {
  9795. if item.DialysisOrder != nil {
  9796. if item.DialysisOrder.ID > 0 {
  9797. mds = append(mds, item)
  9798. }
  9799. }
  9800. }
  9801. }
  9802. //待消毒
  9803. if pat_type == 4 {
  9804. for _, item := range monitor {
  9805. if item.NewDeviceInformation == nil {
  9806. mds = append(mds, item)
  9807. }
  9808. }
  9809. }
  9810. //待双人核对
  9811. if pat_type == 5 {
  9812. for _, item := range monitor {
  9813. if item.DoubleCheck == nil {
  9814. mds = append(mds, item)
  9815. }
  9816. }
  9817. }
  9818. //医嘱未执行
  9819. if pat_type == 6 {
  9820. for _, item := range monitor {
  9821. if len(item.AdviceList) > 0 {
  9822. mds = append(mds, item)
  9823. }
  9824. }
  9825. }
  9826. //患者未签名
  9827. if pat_type == 7 {
  9828. for _, item := range monitor {
  9829. if item.DialysisOrder != nil {
  9830. if item.DialysisOrder.ID > 0 {
  9831. mds = append(mds, item)
  9832. }
  9833. }
  9834. }
  9835. }
  9836. //目标超滤于实际超滤不同
  9837. if pat_type == 8 {
  9838. for _, item := range monitor {
  9839. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9840. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9841. mds = append(mds, item)
  9842. }
  9843. }
  9844. }
  9845. }
  9846. //血压少于5次
  9847. if pat_type == 9 {
  9848. for _, item := range monitor {
  9849. if len(item.MonitoringRecord) < 5 {
  9850. mds = append(mds, item)
  9851. }
  9852. }
  9853. }
  9854. if pat_type == 10 {
  9855. for _, item := range monitor {
  9856. if len(item.MonitoringRecord) == 0 {
  9857. mds = append(mds, item)
  9858. }
  9859. }
  9860. }
  9861. if pat_type == 11 {
  9862. for _, item := range monitor {
  9863. if len(item.MonitoringRecord) > 0 {
  9864. mds = append(mds, item)
  9865. }
  9866. }
  9867. }
  9868. if pat_type == 12 {
  9869. for _, item := range monitor {
  9870. if len(item.MonitoringRecord) > 0 {
  9871. mds = append(mds, item)
  9872. }
  9873. }
  9874. }
  9875. if err == nil {
  9876. c.ServeSuccessJSON(map[string]interface{}{
  9877. "monitor": mds,
  9878. "patients": patients,
  9879. })
  9880. } else {
  9881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9882. }
  9883. }
  9884. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9885. admin_user_id, _ := c.GetInt64("admin_user_id")
  9886. timeStr := time.Now().Format("2006-01-02")
  9887. timeLayout := "2006-01-02 15:04:05"
  9888. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9889. timenow := timeStringToTime.Unix()
  9890. orgId := c.GetMobileAdminUserInfo().Org.Id
  9891. //查询当前护士的患者
  9892. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9893. var patientIds []int64
  9894. for _, item := range orderList {
  9895. patientIds = append(patientIds, item.PatientId)
  9896. }
  9897. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9898. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9899. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9900. //药品管理信息
  9901. _, drugStockConfig := service.FindHisConfig(orgId)
  9902. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9903. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9904. c.ServeSuccessJSON(map[string]interface{}{
  9905. "adviceList": adviceList,
  9906. "hisAdviceList": hisAdviceList,
  9907. "projectList": projectList,
  9908. "drugStockConfig": drugStockConfig,
  9909. "patientList": patientList,
  9910. "projectConfig": projectConfig,
  9911. })
  9912. }
  9913. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9914. patient_id, _ := c.GetInt64("patient_id")
  9915. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9916. c.ServeSuccessJSON(map[string]interface{}{
  9917. "recrods": recrods,
  9918. })
  9919. }
  9920. func (c *DialysisAPIController) ExMobileChangeSch() {
  9921. id_one, _ := c.GetInt64("id_one")
  9922. id_two, _ := c.GetInt64("id_two")
  9923. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9924. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9925. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9926. //if order2.ID > 0 {
  9927. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9928. // return
  9929. //}
  9930. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9931. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9932. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9933. if count > 0 {
  9934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9935. return
  9936. }
  9937. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9938. if count1 > 0 {
  9939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9940. return
  9941. }
  9942. }
  9943. err := service.UpdateScheduleThree(sch, sch_two)
  9944. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9945. if order.ID > 0 {
  9946. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9947. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9948. redis := service.RedisClient()
  9949. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9950. redis.Set(key, "", time.Second)
  9951. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9952. //清空key 值
  9953. redis.Set(keyOne, "", time.Second)
  9954. }
  9955. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9956. if orderOne.ID > 0 {
  9957. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9958. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9959. redis := service.RedisClient()
  9960. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9961. redis.Set(key, "", time.Second)
  9962. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9963. //清空key 值
  9964. redis.Set(keyOne, "", time.Second)
  9965. }
  9966. if err == nil {
  9967. //去除当天患者排班中重复数据,保留最后一条数据
  9968. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9969. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9970. c.ServeSuccessJSON(map[string]interface{}{
  9971. "msg": "交换成功",
  9972. })
  9973. } else {
  9974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9975. return
  9976. }
  9977. }
  9978. func (c *DialysisAPIController) MobileCoverSch() {
  9979. id_one, _ := c.GetInt64("id_one")
  9980. id_two, _ := c.GetInt64("id_two")
  9981. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9982. //针对凤凰医院
  9983. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9984. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9985. if len(advice) > 0 {
  9986. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9987. }
  9988. }
  9989. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9990. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9991. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9992. if len(hisAdvice) > 0 {
  9993. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9994. }
  9995. if len(project) > 0 {
  9996. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9997. }
  9998. }
  9999. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10000. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10001. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10002. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10003. if count > 0 {
  10004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10005. return
  10006. }
  10007. }
  10008. var new_sch models.Schedule
  10009. new_sch = sch
  10010. new_sch.BedId = sch_two.BedId
  10011. new_sch.ScheduleDate = sch_two.ScheduleDate
  10012. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10013. new_sch.PartitionId = sch_two.PartitionId
  10014. new_sch.ScheduleType = sch_two.ScheduleType
  10015. new_sch.ID = 0
  10016. //删除原来的排班
  10017. err := service.SaveSchTwo(sch, sch_two)
  10018. //生成新的排班
  10019. if err == nil {
  10020. err2 := service.SaveSch(&new_sch)
  10021. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10022. if order.ID > 0 {
  10023. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10024. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10025. redis := service.RedisClient()
  10026. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10027. redis.Set(key, "", time.Second)
  10028. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10029. //清空key 值
  10030. redis.Set(keyOne, "", time.Second)
  10031. }
  10032. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10033. if orderOne.ID > 0 {
  10034. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10035. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10036. redis := service.RedisClient()
  10037. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10038. redis.Set(key, "", time.Second)
  10039. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10040. //清空key 值
  10041. redis.Set(keyOne, "", time.Second)
  10042. }
  10043. if err2 == nil {
  10044. //去除当天患者排班中重复数据,保留最后一条数据
  10045. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10046. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10047. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10048. c.ServeSuccessJSON(map[string]interface{}{
  10049. "msg": "覆盖成功",
  10050. "new_sch": new_sch,
  10051. })
  10052. } else {
  10053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10054. return
  10055. }
  10056. } else {
  10057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10058. return
  10059. }
  10060. }
  10061. func (c *DialysisAPIController) BatchCheckAdvice() {
  10062. patient_id, _ := c.GetInt64("patient_id")
  10063. advice_date, _ := c.GetInt64("advice_date")
  10064. org_id := c.GetMobileAdminUserInfo().Org.Id
  10065. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10066. //查询是his系统还是血透系统
  10067. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10068. //his客户
  10069. if configs.IsOpen == 1 {
  10070. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10071. for _, item := range adviceList {
  10072. service.BatchCheckHisAdvice(item.ID, creater)
  10073. }
  10074. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10075. for _, item := range projectList {
  10076. service.BatchCheckProject(item.ID, creater)
  10077. }
  10078. c.ServeSuccessJSON(map[string]interface{}{
  10079. "adviceList": adviceList,
  10080. "projectList": projectList,
  10081. })
  10082. }
  10083. if configs.IsOpen != 1 {
  10084. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10085. for _, item := range adviceList {
  10086. service.BatchAdviceList(item.ID, creater)
  10087. }
  10088. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10089. for _, item := range projectList {
  10090. service.BatchCheckProject(item.ID, creater)
  10091. }
  10092. c.ServeSuccessJSON(map[string]interface{}{
  10093. "adviceList": adviceList,
  10094. "projectList": projectList,
  10095. })
  10096. }
  10097. return
  10098. }
  10099. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10100. org_id := c.GetMobileAdminUserInfo().Org.Id
  10101. drugList, _ := service.GetAllDrugList(org_id)
  10102. c.ServeSuccessJSON(map[string]interface{}{
  10103. "drugList": drugList,
  10104. })
  10105. }
  10106. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10107. org_id := c.GetMobileAdminUserInfo().Org.Id
  10108. dataBody := make(map[string]interface{}, 0)
  10109. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10110. if err != nil {
  10111. utils.ErrorLog(err.Error())
  10112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10113. return
  10114. }
  10115. timeLayout := "2006-01-02"
  10116. loc, _ := time.LoadLocation("Local")
  10117. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10118. utils.ErrorLog("advice_type")
  10119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10120. return
  10121. }
  10122. adviceType := int64(dataBody["advice_type"].(float64))
  10123. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10124. utils.ErrorLog("start_time")
  10125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10126. return
  10127. }
  10128. startTime2, _ := dataBody["start_time"].(string)
  10129. time_arr := strings.Split(startTime2, " ")
  10130. if len(time_arr) > 0 {
  10131. startTime2 = time_arr[0]
  10132. }
  10133. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10134. utils.ErrorLog("advice_date")
  10135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10136. return
  10137. }
  10138. advice_date, _ := dataBody["advice_date"].(string)
  10139. var advicedateunix int64
  10140. if len(advice_date) > 0 {
  10141. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10142. if err != nil {
  10143. fmt.Println(err)
  10144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10145. return
  10146. }
  10147. advicedateunix = theTime.Unix()
  10148. }
  10149. adviceDate := startTime2
  10150. if len(adviceDate) == 0 {
  10151. utils.ErrorLog("len(adviceDate) == 0")
  10152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10153. return
  10154. }
  10155. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10156. if err != nil {
  10157. utils.ErrorLog(err.Error())
  10158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10159. return
  10160. }
  10161. AdviceDate := advicedateunix
  10162. RecordDate := advicedateunix
  10163. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10164. utils.ErrorLog("start_time")
  10165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10166. return
  10167. }
  10168. startTime, _ := dataBody["start_time"].(string)
  10169. if len(startTime) == 0 {
  10170. utils.ErrorLog("len(start_time) == 0")
  10171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10172. return
  10173. }
  10174. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10175. if err != nil {
  10176. utils.ErrorLog(err.Error())
  10177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10178. return
  10179. }
  10180. StartTime := theTime.Unix()
  10181. advice_name, _ := dataBody["advice_name"].(string)
  10182. advice_desc, _ := dataBody["advice_desc"].(string)
  10183. delivery_way, _ := dataBody["delivery_way"].(string)
  10184. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10185. frequency_type := int64(dataBody["frequency_type"].(float64))
  10186. frequency_week, _ := dataBody["frequency_week"].(string)
  10187. prescribing_number := dataBody["prescribing_number"].(float64)
  10188. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10189. remark := dataBody["remark"].(string)
  10190. single_dose := dataBody["single_dose"].(float64)
  10191. single_dose_unit := dataBody["single_dose_unit"].(string)
  10192. patient_id := int64(dataBody["patient_id"].(float64))
  10193. day_count := int64(dataBody["day_count"].(float64))
  10194. groupNo := int64(dataBody["group_no"].(float64))
  10195. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10196. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10197. if groupNo <= 0 {
  10198. group := service.GetMaxAdviceGroupID(org_id)
  10199. groupNo = group + 1
  10200. }
  10201. var template_id = ""
  10202. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10203. template_id = "M" + adviceLastId
  10204. advice := models.DoctorAdvice{
  10205. UserOrgId: org_id,
  10206. PatientId: patient_id,
  10207. AdviceType: adviceType,
  10208. AdviceDate: AdviceDate,
  10209. StartTime: StartTime,
  10210. AdviceName: advice_name,
  10211. AdviceDesc: advice_desc,
  10212. ReminderDate: 0,
  10213. SingleDose: single_dose,
  10214. SingleDoseUnit: single_dose_unit,
  10215. DrugSpec: 0,
  10216. DrugSpecUnit: "",
  10217. PrescribingNumber: prescribing_number,
  10218. PrescribingNumberUnit: prescribing_number_unit,
  10219. DeliveryWay: delivery_way,
  10220. ExecutionFrequency: execution_frequency,
  10221. AdviceDoctor: advice_doctor,
  10222. Status: 1,
  10223. CreatedTime: time.Now().Unix(),
  10224. UpdatedTime: 0,
  10225. AdviceAffirm: "",
  10226. Remark: remark,
  10227. StopTime: 0,
  10228. StopReason: "",
  10229. StopDoctor: 0,
  10230. StopState: 0,
  10231. ParentId: 0,
  10232. ExecutionTime: 0,
  10233. ExecutionStaff: 0,
  10234. ExecutionState: 0,
  10235. Checker: 0,
  10236. RecordDate: RecordDate,
  10237. DialysisOrderId: 0,
  10238. CheckTime: 0,
  10239. CheckState: 0,
  10240. AdviceId: 0,
  10241. RemindType: 0,
  10242. FrequencyType: frequency_type,
  10243. DayCount: day_count,
  10244. WeekDay: frequency_week,
  10245. ChildDoctorAdvice: nil,
  10246. TemplateId: template_id,
  10247. Modifier: 0,
  10248. IsCheck: 0,
  10249. Way: 0,
  10250. DrugId: 0,
  10251. DrugNameId: 0,
  10252. IsMedicine: 0,
  10253. PushStartTime: 0,
  10254. IsSettle: 0,
  10255. IsPrescription: 0,
  10256. GroupNo: groupNo,
  10257. }
  10258. service.CreateMobileAdivce(advice)
  10259. c.ServeSuccessJSON(map[string]interface{}{
  10260. "msg": "保存成功!",
  10261. })
  10262. }
  10263. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10264. patient_id, _ := c.GetInt64("patient_id")
  10265. org_id := c.GetMobileAdminUserInfo().Org.Id
  10266. app_id := c.GetMobileAdminUserInfo().App.Id
  10267. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10268. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10269. c.ServeSuccessJSON(map[string]interface{}{
  10270. "adviceList": adviceList,
  10271. "adminRoles": adminRoles,
  10272. })
  10273. }
  10274. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10275. org_id := c.GetMobileAdminUserInfo().Org.Id
  10276. dataBody := make(map[string]interface{}, 0)
  10277. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10278. if err != nil {
  10279. utils.ErrorLog(err.Error())
  10280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10281. return
  10282. }
  10283. timeLayout := "2006-01-02"
  10284. loc, _ := time.LoadLocation("Local")
  10285. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10286. utils.ErrorLog("start_time")
  10287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10288. return
  10289. }
  10290. startTime2, _ := dataBody["start_time"].(string)
  10291. time_arr := strings.Split(startTime2, " ")
  10292. if len(time_arr) > 0 {
  10293. startTime2 = time_arr[0]
  10294. }
  10295. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10296. utils.ErrorLog("advice_date")
  10297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10298. return
  10299. }
  10300. advice_date, _ := dataBody["advice_date"].(string)
  10301. var advicedateunix int64
  10302. if len(advice_date) > 0 {
  10303. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10304. if err != nil {
  10305. fmt.Println(err)
  10306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10307. return
  10308. }
  10309. advicedateunix = theTime.Unix()
  10310. }
  10311. adviceDate := startTime2
  10312. if len(adviceDate) == 0 {
  10313. utils.ErrorLog("len(adviceDate) == 0")
  10314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10315. return
  10316. }
  10317. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10318. if err != nil {
  10319. utils.ErrorLog(err.Error())
  10320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10321. return
  10322. }
  10323. AdviceDate := advicedateunix
  10324. RecordDate := advicedateunix
  10325. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10326. utils.ErrorLog("start_time")
  10327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10328. return
  10329. }
  10330. startTime, _ := dataBody["start_time"].(string)
  10331. if len(startTime) == 0 {
  10332. utils.ErrorLog("len(start_time) == 0")
  10333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10334. return
  10335. }
  10336. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10337. if err != nil {
  10338. utils.ErrorLog(err.Error())
  10339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10340. return
  10341. }
  10342. StartTime := theTime.Unix()
  10343. advice_name, _ := dataBody["advice_name"].(string)
  10344. advice_desc, _ := dataBody["advice_desc"].(string)
  10345. delivery_way, _ := dataBody["delivery_way"].(string)
  10346. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10347. prescribing_number := dataBody["prescribing_number"].(float64)
  10348. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10349. remark := dataBody["remark"].(string)
  10350. single_dose := dataBody["single_dose"].(float64)
  10351. single_dose_unit := dataBody["single_dose_unit"].(string)
  10352. patient_id := int64(dataBody["patient_id"].(float64))
  10353. groupNo := int64(dataBody["group_no"].(float64))
  10354. parent_id := int64(dataBody["parent_id"].(float64))
  10355. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10356. advice := models.XtDoctorAdviceOne{
  10357. UserOrgId: org_id,
  10358. PatientId: patient_id,
  10359. AdviceType: 1,
  10360. AdviceDate: AdviceDate,
  10361. StartTime: StartTime,
  10362. AdviceName: advice_name,
  10363. AdviceDesc: advice_desc,
  10364. ReminderDate: 0,
  10365. SingleDose: single_dose,
  10366. SingleDoseUnit: single_dose_unit,
  10367. PrescribingNumber: prescribing_number,
  10368. PrescribingNumberUnit: prescribing_number_unit,
  10369. DeliveryWay: delivery_way,
  10370. ExecutionFrequency: execution_frequency,
  10371. AdviceDoctor: advice_doctor,
  10372. Status: 1,
  10373. CreatedTime: time.Now().Unix(),
  10374. UpdatedTime: time.Now().Unix(),
  10375. AdviceAffirm: "",
  10376. Remark: remark,
  10377. StopTime: 0,
  10378. StopReason: "",
  10379. StopDoctor: 0,
  10380. StopState: 0,
  10381. ParentId: parent_id,
  10382. ExecutionTime: 0,
  10383. ExecutionStaff: 0,
  10384. ExecutionState: 0,
  10385. Checker: 0,
  10386. RecordDate: RecordDate,
  10387. DialysisOrderId: 0,
  10388. CheckTime: 0,
  10389. CheckState: 0,
  10390. DrugSpec: 0,
  10391. DrugSpecUnit: "",
  10392. Groupno: groupNo,
  10393. RemindType: 0,
  10394. FrequencyType: 0,
  10395. DayCount: 0,
  10396. WeekDay: "",
  10397. TemplateId: "",
  10398. Modifier: 0,
  10399. }
  10400. service.CreateMobileAdivceOne(advice)
  10401. c.ServeSuccessJSON(map[string]interface{}{
  10402. "msg": "保存成功!",
  10403. })
  10404. }
  10405. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10406. id, _ := c.GetInt64("id")
  10407. service.DeleteSelfAdviceSubAdvice(id)
  10408. c.ServeSuccessJSON(map[string]interface{}{
  10409. "msg": "保存成功!",
  10410. })
  10411. }
  10412. func (c *DialysisAPIController) GetEditAdviceAction() {
  10413. id, _ := c.GetInt64("id")
  10414. org_id := c.GetMobileAdminUserInfo().Org.Id
  10415. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10416. drugList, _ := service.GetAllDrugList(org_id)
  10417. c.ServeSuccessJSON(map[string]interface{}{
  10418. "advice": advice,
  10419. "drugList": drugList,
  10420. })
  10421. }
  10422. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10423. dataBody := make(map[string]interface{}, 0)
  10424. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10425. if err != nil {
  10426. utils.ErrorLog(err.Error())
  10427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10428. return
  10429. }
  10430. timeLayout := "2006-01-02"
  10431. loc, _ := time.LoadLocation("Local")
  10432. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10433. utils.ErrorLog("start_time")
  10434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10435. return
  10436. }
  10437. startTime2, _ := dataBody["start_time"].(string)
  10438. time_arr := strings.Split(startTime2, " ")
  10439. if len(time_arr) > 0 {
  10440. startTime2 = time_arr[0]
  10441. }
  10442. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10443. utils.ErrorLog("advice_date")
  10444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10445. return
  10446. }
  10447. advice_date, _ := dataBody["advice_date"].(string)
  10448. var advicedateunix int64
  10449. if len(advice_date) > 0 {
  10450. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10451. if err != nil {
  10452. fmt.Println(err)
  10453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10454. return
  10455. }
  10456. advicedateunix = theTime.Unix()
  10457. }
  10458. adviceDate := startTime2
  10459. if len(adviceDate) == 0 {
  10460. utils.ErrorLog("len(adviceDate) == 0")
  10461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10462. return
  10463. }
  10464. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10465. if err != nil {
  10466. utils.ErrorLog(err.Error())
  10467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10468. return
  10469. }
  10470. AdviceDate := advicedateunix
  10471. RecordDate := advicedateunix
  10472. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10473. utils.ErrorLog("start_time")
  10474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10475. return
  10476. }
  10477. startTime, _ := dataBody["start_time"].(string)
  10478. if len(startTime) == 0 {
  10479. utils.ErrorLog("len(start_time) == 0")
  10480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10481. return
  10482. }
  10483. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10484. if err != nil {
  10485. utils.ErrorLog(err.Error())
  10486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10487. return
  10488. }
  10489. StartTime := theTime.Unix()
  10490. advice_name, _ := dataBody["advice_name"].(string)
  10491. advice_desc, _ := dataBody["advice_desc"].(string)
  10492. delivery_way, _ := dataBody["delivery_way"].(string)
  10493. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10494. prescribing_number := dataBody["prescribing_number"].(float64)
  10495. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10496. remark := dataBody["remark"].(string)
  10497. single_dose := dataBody["single_dose"].(float64)
  10498. single_dose_unit := dataBody["single_dose_unit"].(string)
  10499. id := int64(dataBody["id"].(float64))
  10500. frequency_type := int64(dataBody["frequency_type"].(float64))
  10501. frequency_week, _ := dataBody["frequency_week"].(string)
  10502. day_count := int64(dataBody["day_count"].(float64))
  10503. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10504. advice := models.XtDoctorAdviceOne{
  10505. AdviceDate: AdviceDate,
  10506. StartTime: StartTime,
  10507. AdviceName: advice_name,
  10508. AdviceDesc: advice_desc,
  10509. SingleDose: single_dose,
  10510. SingleDoseUnit: single_dose_unit,
  10511. PrescribingNumber: prescribing_number,
  10512. PrescribingNumberUnit: prescribing_number_unit,
  10513. DeliveryWay: delivery_way,
  10514. ExecutionFrequency: execution_frequency,
  10515. AdviceDoctor: advice_doctor,
  10516. Remark: remark,
  10517. RecordDate: RecordDate,
  10518. FrequencyType: frequency_type,
  10519. DayCount: day_count,
  10520. WeekDay: frequency_week,
  10521. }
  10522. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10523. c.ServeSuccessJSON(map[string]interface{}{
  10524. "advice": advice,
  10525. })
  10526. }
  10527. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10528. dataBody := make(map[string]interface{}, 0)
  10529. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10530. if err != nil {
  10531. utils.ErrorLog(err.Error())
  10532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10533. return
  10534. }
  10535. timeLayout := "2006-01-02"
  10536. loc, _ := time.LoadLocation("Local")
  10537. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10538. utils.ErrorLog("start_time")
  10539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10540. return
  10541. }
  10542. startTime2, _ := dataBody["start_time"].(string)
  10543. time_arr := strings.Split(startTime2, " ")
  10544. if len(time_arr) > 0 {
  10545. startTime2 = time_arr[0]
  10546. }
  10547. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10548. utils.ErrorLog("advice_date")
  10549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10550. return
  10551. }
  10552. advice_date, _ := dataBody["advice_date"].(string)
  10553. var advicedateunix int64
  10554. if len(advice_date) > 0 {
  10555. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10556. if err != nil {
  10557. fmt.Println(err)
  10558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10559. return
  10560. }
  10561. advicedateunix = theTime.Unix()
  10562. }
  10563. adviceDate := startTime2
  10564. if len(adviceDate) == 0 {
  10565. utils.ErrorLog("len(adviceDate) == 0")
  10566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10567. return
  10568. }
  10569. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10570. if err != nil {
  10571. utils.ErrorLog(err.Error())
  10572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10573. return
  10574. }
  10575. AdviceDate := advicedateunix
  10576. RecordDate := advicedateunix
  10577. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10578. utils.ErrorLog("start_time")
  10579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10580. return
  10581. }
  10582. startTime, _ := dataBody["start_time"].(string)
  10583. if len(startTime) == 0 {
  10584. utils.ErrorLog("len(start_time) == 0")
  10585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10586. return
  10587. }
  10588. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10589. if err != nil {
  10590. utils.ErrorLog(err.Error())
  10591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10592. return
  10593. }
  10594. StartTime := theTime.Unix()
  10595. advice_name, _ := dataBody["advice_name"].(string)
  10596. advice_desc, _ := dataBody["advice_desc"].(string)
  10597. delivery_way, _ := dataBody["delivery_way"].(string)
  10598. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10599. prescribing_number := dataBody["prescribing_number"].(float64)
  10600. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10601. remark := dataBody["remark"].(string)
  10602. single_dose := dataBody["single_dose"].(float64)
  10603. single_dose_unit := dataBody["single_dose_unit"].(string)
  10604. id := int64(dataBody["id"].(float64))
  10605. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10606. advice := models.XtDoctorAdviceOne{
  10607. AdviceDate: AdviceDate,
  10608. StartTime: StartTime,
  10609. AdviceName: advice_name,
  10610. AdviceDesc: advice_desc,
  10611. SingleDose: single_dose,
  10612. SingleDoseUnit: single_dose_unit,
  10613. PrescribingNumber: prescribing_number,
  10614. PrescribingNumberUnit: prescribing_number_unit,
  10615. DeliveryWay: delivery_way,
  10616. ExecutionFrequency: execution_frequency,
  10617. AdviceDoctor: advice_doctor,
  10618. Remark: remark,
  10619. RecordDate: RecordDate,
  10620. }
  10621. service.UpdateMobileDoctorAdviceById(id, advice)
  10622. c.ServeSuccessJSON(map[string]interface{}{
  10623. "advice": advice,
  10624. })
  10625. }
  10626. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10627. dataBody := make(map[string]interface{}, 0)
  10628. timeLayout := "2006-01-02"
  10629. loc, _ := time.LoadLocation("Local")
  10630. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10631. if err != nil {
  10632. utils.ErrorLog(err.Error())
  10633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10634. return
  10635. }
  10636. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10637. utils.ErrorLog("start_time")
  10638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10639. return
  10640. }
  10641. startTime2, _ := dataBody["start_time"].(string)
  10642. time_arr := strings.Split(startTime2, " ")
  10643. if len(time_arr) > 0 {
  10644. startTime2 = time_arr[0]
  10645. }
  10646. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10647. utils.ErrorLog("advice_date")
  10648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10649. return
  10650. }
  10651. advice_date, _ := dataBody["advice_date"].(string)
  10652. var advicedateunix int64
  10653. if len(advice_date) > 0 {
  10654. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10655. if err != nil {
  10656. fmt.Println(err)
  10657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10658. return
  10659. }
  10660. advicedateunix = theTime.Unix()
  10661. }
  10662. adviceDate := startTime2
  10663. if len(adviceDate) == 0 {
  10664. utils.ErrorLog("len(adviceDate) == 0")
  10665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10666. return
  10667. }
  10668. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10669. if err != nil {
  10670. utils.ErrorLog(err.Error())
  10671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10672. return
  10673. }
  10674. RecordDate := advicedateunix
  10675. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10676. utils.ErrorLog("start_time")
  10677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10678. return
  10679. }
  10680. startTime, _ := dataBody["start_time"].(string)
  10681. if len(startTime) == 0 {
  10682. utils.ErrorLog("len(start_time) == 0")
  10683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10684. return
  10685. }
  10686. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10687. if err != nil {
  10688. utils.ErrorLog(err.Error())
  10689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10690. return
  10691. }
  10692. StartTime := theTime.Unix()
  10693. patient_id := int64(dataBody["patient_id"].(float64))
  10694. group_no := int64(dataBody["group_no"].(float64))
  10695. org_id := c.GetMobileAdminUserInfo().Org.Id
  10696. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10697. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10698. utils.ErrorLog("advices")
  10699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10700. return
  10701. }
  10702. adviceNames := dataBody["advices"].([]interface{})
  10703. var advices []*models.GroupAdvice
  10704. for _, adviceNameMap := range adviceNames {
  10705. var advice models.GroupAdvice
  10706. adviceNameM := adviceNameMap.(map[string]interface{})
  10707. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10708. utils.ErrorLog("advice_name")
  10709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10710. return
  10711. }
  10712. adviceName, _ := adviceNameM["advice_name"].(string)
  10713. if len(adviceName) == 0 {
  10714. utils.ErrorLog("len(advice_name) == 0")
  10715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10716. return
  10717. }
  10718. advice.AdviceName = adviceName
  10719. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10720. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10721. advice.DrugSpec = drugSpec
  10722. }
  10723. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10724. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10725. advice.AdviceDesc = adviceDesc
  10726. }
  10727. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10728. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10729. advice.DrugSpecUnit = drugSpecUnit
  10730. }
  10731. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10732. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10733. advice.SingleDose = singleDose
  10734. }
  10735. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10736. singleDose := adviceNameM["single_dose"].(float64)
  10737. advice.SingleDose = singleDose
  10738. }
  10739. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10740. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10741. advice.SingleDoseUnit = singleDoseUnit
  10742. }
  10743. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10744. tmp := adviceNameM["single_dose_unit"].(float64)
  10745. singleDoseUnit := service.TypeConversion(tmp)
  10746. advice.SingleDoseUnit = singleDoseUnit
  10747. }
  10748. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10749. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10750. advice.PrescribingNumber = prescribingNumber
  10751. }
  10752. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10753. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10754. advice.PrescribingNumber = prescribingNumber
  10755. }
  10756. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10757. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10758. advice.PrescribingNumberUnit = prescribingNumberUnit
  10759. }
  10760. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10761. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10762. advice.DeliveryWay = deliveryWay
  10763. }
  10764. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10765. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10766. advice.ExecutionFrequency = executionFrequency
  10767. }
  10768. remark, _ := adviceNameM["remark"].(string)
  10769. advice.Remark = remark
  10770. advice.AdviceType = 1
  10771. advice.StartTime = StartTime
  10772. advice.RecordDate = RecordDate
  10773. advice.PatientId = patient_id
  10774. advice.UserOrgId = org_id
  10775. advice.AdviceDoctor = advice_doctor
  10776. advices = append(advices, &advice)
  10777. }
  10778. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10779. c.ServeSuccessJSON(map[string]interface{}{
  10780. "advice": newAdvices,
  10781. })
  10782. }
  10783. func (c *DialysisAPIController) StopLongAdvice() {
  10784. stop_time := c.GetString("execution_time")
  10785. id, _ := c.GetInt64("id")
  10786. if len(stop_time) <= 0 {
  10787. utils.ErrorLog("stop_time")
  10788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10789. return
  10790. }
  10791. timeLayout2 := "2006-01-02 15:04:05"
  10792. loc, _ := time.LoadLocation("Local")
  10793. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10794. if errs != nil {
  10795. utils.ErrorLog(errs.Error())
  10796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10797. return
  10798. }
  10799. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10800. c.ServeSuccessJSON(map[string]interface{}{
  10801. "advice": advice,
  10802. })
  10803. }