dialysis_api_controller.go 449KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619
  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. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4544. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4545. if lastMonitorRecordList.ID > 0 {
  4546. record.UltrafiltrationRate = ultrafiltration_rate_one
  4547. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4548. record.UltrafiltrationVolume = ultrafiltration_volume
  4549. } else {
  4550. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4551. record.UltrafiltrationVolume = ultrafiltration_volume
  4552. }
  4553. }
  4554. }
  4555. }
  4556. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4557. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4558. record.UltrafiltrationVolume = ultrafiltration_volume
  4559. }
  4560. //长沙南雅
  4561. 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 {
  4562. if ultrafiltration_rate > 0 {
  4563. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4564. record.UltrafiltrationVolume = ultrafiltration_volume
  4565. }
  4566. }
  4567. if adminInfo.Org.Id == 10471 {
  4568. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4569. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4570. }
  4571. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4572. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4573. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4574. }
  4575. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4576. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4577. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4578. }
  4579. //长沙南雅累计血容量自动计算
  4580. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4581. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4582. //}
  4583. if template.TemplateId == 47 || template.TemplateId == 54 {
  4584. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4585. }
  4586. if adminInfo.Org.Id == 10510 {
  4587. record.UltrafiltrationVolume = 0
  4588. }
  4589. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 {
  4590. if ultrafiltration_rate > 0 {
  4591. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4592. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4593. }
  4594. }
  4595. //古镇乐生
  4596. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4597. if ultrafiltration_rate > 0 {
  4598. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4599. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4600. }
  4601. }
  4602. if adminInfo.Org.Id == 10206 {
  4603. if ultrafiltration_rate > 0 {
  4604. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4605. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4606. }
  4607. }
  4608. if adminInfo.Org.Id == 10721 {
  4609. var replacement_rate float64
  4610. var displacement_quantity float64
  4611. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4612. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4613. record.ReplacementRate = replacement_rate
  4614. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4615. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4616. record.DisplacementQuantity = displacement_quantity
  4617. }
  4618. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4619. var replacement_rate float64
  4620. var displacement_quantity float64
  4621. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4622. if totalMin == 0 {
  4623. totalMin = 240
  4624. }
  4625. if prescription.DisplaceLiquiValue == 0 {
  4626. prescription.ReplacementTotal = 32
  4627. }
  4628. //乘10 除10是为了保留一位小数
  4629. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4630. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4631. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4632. record.DisplacementQuantity = displacement_quantity
  4633. }
  4634. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4635. this.ServeSuccessJSON(map[string]interface{}{
  4636. "monitor": record,
  4637. "lastMonitorRecordList": lastMonitorRecordList,
  4638. })
  4639. }
  4640. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4641. record_id, _ := this.GetInt64("id")
  4642. nurseID, _ := this.GetInt64("start_nurse")
  4643. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4644. bedID, _ := this.GetInt64("bed")
  4645. start_time := this.GetString("start_time")
  4646. schedual_type, _ := this.GetInt64("schedual_type")
  4647. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4648. change_nurse, _ := this.GetInt64("change_nurse")
  4649. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4650. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4651. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4652. patient_id, _ := this.GetInt64("patient_id")
  4653. record_date, _ := this.GetInt64("record_date")
  4654. puncture_needle := this.GetString("puncture_needle")
  4655. puncture_way := this.GetString("puncture_way")
  4656. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4657. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4658. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4659. nuclein_date_str := this.GetString("nuclein_date_str")
  4660. order_remark := this.GetString("order_remark")
  4661. schedule_remark := this.GetString("schedule_remark")
  4662. catheter_operation := this.GetString("catheter_operation")
  4663. blood_flow_volume := this.GetString("blood_flow_volume")
  4664. blood_drawing, _ := this.GetInt64("blood_drawing")
  4665. dialysis_strainer := this.GetString("dialysis_strainer")
  4666. if record_id == 0 {
  4667. this.ErrorLog("id:%v", record_id)
  4668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4669. return
  4670. }
  4671. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4672. if parseStartDateErr != nil {
  4673. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4675. return
  4676. }
  4677. adminUserInfo := this.GetMobileAdminUserInfo()
  4678. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4679. if getNurseErr != nil {
  4680. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4681. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4682. return
  4683. } else if nurse == nil {
  4684. this.ErrorLog("护士不存在")
  4685. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4686. return
  4687. }
  4688. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4689. //if getNurseErr != nil {
  4690. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4691. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4692. // return
  4693. //} else if nurse == nil {
  4694. // this.ErrorLog("护士不存在")
  4695. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4696. // return
  4697. //}
  4698. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4699. if getDeviceNumberErr != nil {
  4700. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4702. return
  4703. } else if deviceNumber == nil {
  4704. this.ErrorLog("床位号不存在")
  4705. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4706. return
  4707. }
  4708. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4709. //
  4710. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4711. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4712. // if getPermissionErr != nil {
  4713. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4714. // return
  4715. // } else if headNursePermission == nil {
  4716. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4717. // return
  4718. // }
  4719. //}
  4720. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4721. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4722. timeLayout := "2006-01-02 15:04:05"
  4723. loc, _ := time.LoadLocation("Local")
  4724. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4725. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4726. schedulestartTime := theStartTime.Unix()
  4727. scheduleendTime := theEndTime.Unix()
  4728. var theNucleinDate int64
  4729. timeLayoutOne := "2006-01-02"
  4730. if len(nuclein_date_str) > 0 {
  4731. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4732. if err != nil {
  4733. utils.ErrorLog(err.Error())
  4734. }
  4735. theNucleinDate = theTime.Unix()
  4736. }
  4737. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4738. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4739. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4740. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4741. if err == gorm.ErrRecordNotFound { //空床位
  4742. // 修改了床位逻辑
  4743. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4744. if daySchedule.ID > 0 {
  4745. //daySchedule.BedId = bedID
  4746. //daySchedule.PartitionId = deviceNumber.ZoneID
  4747. //daySchedule.ScheduleType = schedual_type
  4748. //daySchedule.UpdatedTime = time.Now().Unix()
  4749. //err := service.UpdateSchedule(&daySchedule)
  4750. xtSchedule := models.Schedule{
  4751. PartitionId: deviceNumber.ZoneID,
  4752. BedId: bedID,
  4753. ScheduleType: schedual_type,
  4754. UpdatedTime: time.Now().Unix(),
  4755. }
  4756. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4757. if err != nil {
  4758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4759. return
  4760. }
  4761. }
  4762. } else if err == nil {
  4763. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4764. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4765. if daySchedule.ID > 0 {
  4766. //daySchedule.BedId = bedID
  4767. //daySchedule.PartitionId = deviceNumber.ZoneID
  4768. //
  4769. //daySchedule.ScheduleType = schedual_type
  4770. //daySchedule.UpdatedTime = time.Now().Unix()
  4771. //err := service.UpdateSchedule(&daySchedule)
  4772. xtSchedule := models.Schedule{
  4773. PartitionId: deviceNumber.ZoneID,
  4774. BedId: bedID,
  4775. ScheduleType: schedual_type,
  4776. UpdatedTime: time.Now().Unix(),
  4777. }
  4778. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4779. if err != nil {
  4780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4781. return
  4782. }
  4783. }
  4784. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4785. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4786. return
  4787. }
  4788. } else if err != nil {
  4789. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4790. return
  4791. }
  4792. }
  4793. dialysisRecord := &models.DialysisOrder{
  4794. ID: record_id,
  4795. UserOrgId: adminUserInfo.Org.Id,
  4796. BedID: bedID,
  4797. StartNurse: nurseID,
  4798. StartTime: startDate.Unix(),
  4799. PunctureNurse: puncture_nurse,
  4800. Creator: adminUserInfo.AdminUser.Id,
  4801. Modifier: adminUserInfo.AdminUser.Id,
  4802. WashpipeNurse: washpipe_nurse,
  4803. SchedualType: schedual_type,
  4804. ChangeNurse: change_nurse,
  4805. DifficultPunctureNurse: difficult_puncture_nurse,
  4806. NewFistulaNurse: new_fistula_nurse,
  4807. QualityNurseId: quality_nurse_id,
  4808. PunctureNeedle: puncture_needle,
  4809. PunctureWay: puncture_way,
  4810. DialysisDialyszers: dialysis_dialyszers,
  4811. DialysisIrrigation: dialysis_irrigation,
  4812. BloodAccessId: blood_access_id,
  4813. NucleinDate: theNucleinDate,
  4814. OrderRemark: order_remark,
  4815. ScheduleRemark: schedule_remark,
  4816. CatheterOperation: catheter_operation,
  4817. BloodFlowVolume: blood_flow_volume,
  4818. BloodDrawing: blood_drawing,
  4819. DialysisStrainer: dialysis_strainer,
  4820. }
  4821. //修改床位号需要重新消毒
  4822. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4823. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4824. //查询第一条监测
  4825. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4826. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4827. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4828. redis := service.RedisClient()
  4829. //清空key 值
  4830. redis.Set(key, "", time.Second)
  4831. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4832. redis.Set(keyOne, "", time.Second)
  4833. defer redis.Close()
  4834. }
  4835. // 查询信息规挡的设置天数
  4836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4837. if infor.ID > 0 && infor.WeekDay > 0 {
  4838. var cha_time int64
  4839. timeNowStr := time.Now().Format("2006-01-02")
  4840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4841. //今日的日期减去设置的日期
  4842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4843. if cha_time >= record_date {
  4844. //查询审核是否允许
  4845. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4846. //申请状态不允许的情况 拒绝修改
  4847. if infor.ApplicationStatus != 1 {
  4848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4849. return
  4850. }
  4851. }
  4852. }
  4853. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4854. //修改床位后重新生成消毒计划
  4855. if adminUserInfo.Org.Id == 10340 {
  4856. //根据床位号获取设备型号
  4857. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4858. //查询使用消毒最后一条消毒记录
  4859. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4860. fmt.Println("err", err)
  4861. if err == gorm.ErrRecordNotFound {
  4862. //查找排班
  4863. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4864. //查询改设备是否有消毒计划
  4865. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4866. //根据床位号获取设备id
  4867. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4868. //查询病人信息
  4869. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4870. var con = ""
  4871. if patients.IsInfectious == 0 {
  4872. con = ""
  4873. }
  4874. if patients.IsInfectious == 1 {
  4875. con = "无"
  4876. }
  4877. if patients.IsInfectious == 2 {
  4878. con = "有"
  4879. }
  4880. if errcode == nil {
  4881. var end_time int64
  4882. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4883. //新增消毒
  4884. information := models.DeviceInformation{
  4885. Date: dialysisRecord.DialysisDate,
  4886. Zone: dialysisRecord.ZoneId,
  4887. Class: dialysisRecord.SchedualType,
  4888. BedNumber: dialysisRecord.BedID,
  4889. PatientId: dialysisRecord.PatientId,
  4890. DialysisMode: scheduleByPatient.ModeId,
  4891. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4892. Disinfection: 1,
  4893. DialysisConcentration: 1,
  4894. DisinfectionStatus: 1,
  4895. Move: 1,
  4896. UserOrgId: dialysisRecord.UserOrgId,
  4897. DisinfectType: plan.Way,
  4898. DisinfectantType: plan.MachineDisinfectant,
  4899. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4900. Disinfectant: plan.Disinfectant,
  4901. Ctime: time.Now().Unix(),
  4902. Status: 1,
  4903. SignName: nurseID,
  4904. EquimentId: addmacher.ID,
  4905. DisinfectionResidue: 2,
  4906. Bed: addmacher.BedNumber,
  4907. StartTime: dialysisRecord.StartTime,
  4908. EndTime: dialysisRecord.EndTime,
  4909. Contagion: con,
  4910. WeightLoss: 0,
  4911. Hyperfiltratio: 0,
  4912. DialysisHour: "",
  4913. MachineRun: 1,
  4914. DisinfecStartime: dialysisRecord.EndTime,
  4915. DisinfecEndtime: end_time,
  4916. }
  4917. err := service.CreateInformationTwo(&information)
  4918. fmt.Println("报错", err)
  4919. }
  4920. }
  4921. }
  4922. order, _ := service.GetLastPatientOrder(record_id)
  4923. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4924. redis := service.RedisClient()
  4925. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4926. redis.Set(key, "", time.Second)
  4927. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4928. //清空key 值
  4929. redis.Set(keyOne, "", time.Second)
  4930. scheduleDateStartOne := startDate.Format("2006-01-02")
  4931. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4932. redis.Set(keyTwo, "", time.Second)
  4933. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4934. redis.Set(keyThree, "", time.Second)
  4935. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4936. redis.Set(keyFour, "", time.Second)
  4937. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4938. redis.Set(keyFive, "", time.Second)
  4939. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4940. redis.Set(keySix, "", time.Second)
  4941. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4942. redis.Set(keySeven, "", time.Second)
  4943. if updateErr != nil {
  4944. this.ErrorLog("修改上机失败:%v", updateErr)
  4945. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4946. return
  4947. }
  4948. if updateErr == nil {
  4949. if tempDialysisRecord.Stage == 2 {
  4950. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4951. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4952. fmt.Println(value)
  4953. a, b := math.Modf(value)
  4954. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4955. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4956. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4957. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4958. redis := service.RedisClient()
  4959. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4960. redis.Set(key, "", time.Second)
  4961. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4962. redis.Set(keyOne, "", time.Second)
  4963. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4964. //清空key 值
  4965. redis.Set(keySix, "", time.Second)
  4966. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4967. redis.Set(keySeven, "", time.Second)
  4968. redis.Close()
  4969. if updateAssessmentErr != nil {
  4970. utils.ErrorLog("%v", updateAssessmentErr)
  4971. }
  4972. }
  4973. }
  4974. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4975. this.ServeSuccessJSON(map[string]interface{}{
  4976. "dialysis_order": dialysisRecords,
  4977. })
  4978. }
  4979. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4980. record_id, _ := c.GetInt64("id")
  4981. nurseID, _ := c.GetInt64("nurse")
  4982. end_time := c.GetString("end_time")
  4983. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4984. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4985. catheter := c.GetString("catheter")
  4986. cruor := c.GetString("cruor")
  4987. mission := c.GetString("mission")
  4988. condenser := c.GetString("condenser")
  4989. if record_id <= 0 || nurseID <= 0 {
  4990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4991. return
  4992. }
  4993. adminUserInfo := c.GetMobileAdminUserInfo()
  4994. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4995. if getNurseErr != nil {
  4996. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4998. return
  4999. } else if nurse == nil {
  5000. c.ErrorLog("护士不存在")
  5001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5002. return
  5003. }
  5004. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5005. if parseEndDateErr != nil {
  5006. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5008. return
  5009. }
  5010. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5011. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5012. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5013. // if getPermissionErr != nil {
  5014. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5015. // return
  5016. // } else if headNursePermission == nil {
  5017. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5018. // return
  5019. // }
  5020. //}
  5021. // 查询信息规挡的设置天数
  5022. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5023. if infor.ID > 0 {
  5024. var cha_time int64
  5025. timeNowStr := time.Now().Format("2006-01-02")
  5026. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5027. //今日的日期减去设置的日期
  5028. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5029. if cha_time >= tempDialysisRecords.DialysisDate {
  5030. //查询审核是否允许
  5031. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5032. //申请状态不允许的情况 拒绝修改
  5033. if infor.ApplicationStatus != 1 {
  5034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5035. return
  5036. }
  5037. }
  5038. }
  5039. dialysisRecord := &models.DialysisOrder{
  5040. ID: record_id,
  5041. UserOrgId: adminUserInfo.Org.Id,
  5042. EndTime: endDate.Unix(),
  5043. FinishNurse: nurseID,
  5044. FinishModifier: adminUserInfo.AdminUser.Id,
  5045. PuncturePointHaematoma: puncture_point_haematoma,
  5046. BloodAccessInternalFistula: blood_access_internal_fistula,
  5047. Catheter: catheter,
  5048. Cruor: cruor,
  5049. Mission: mission,
  5050. Condenser: condenser,
  5051. }
  5052. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5053. redis := service.RedisClient()
  5054. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5055. //清空key 值
  5056. redis.Set(key, "", time.Second)
  5057. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5058. //清空key 值
  5059. redis.Set(keyOne, "", time.Second)
  5060. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5061. redis.Set(keySeven, "", time.Second)
  5062. redis.Close()
  5063. if updateErr != nil {
  5064. c.ErrorLog("修改下机失败:%v", updateErr)
  5065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5066. return
  5067. }
  5068. if updateErr == nil {
  5069. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5070. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5071. a, b := math.Modf(value)
  5072. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5073. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5074. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5075. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5076. redis := service.RedisClient()
  5077. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5078. redis.Set(keyTen, "", time.Second)
  5079. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5080. redis.Set(keyTwo, "", time.Second)
  5081. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5082. redis.Set(key, "", time.Second)
  5083. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5084. redis.Set(keyThree, "", time.Second)
  5085. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5086. redis.Set(keySeven, "", time.Second)
  5087. defer redis.Close()
  5088. if updateAssessmentErr != nil {
  5089. utils.ErrorLog("%v", updateAssessmentErr)
  5090. }
  5091. }
  5092. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5093. c.ServeSuccessJSON(map[string]interface{}{
  5094. "dialysis_order": dialysisRecords,
  5095. })
  5096. }
  5097. func (c *DialysisAPIController) GetLongAdvice() {
  5098. patient_id, _ := c.GetInt64("id")
  5099. adminUserInfo := c.GetMobileAdminUserInfo()
  5100. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5101. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5102. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5103. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5104. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5105. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5106. c.ServeSuccessJSON(map[string]interface{}{
  5107. "status": "1",
  5108. })
  5109. return
  5110. } else { //开启推送提醒
  5111. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5112. var advice_three []*models.DoctorAdvice
  5113. recordDateStr := time.Now().Format("2006-01-02")
  5114. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5115. nowtime := recordDate.Unix()
  5116. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5117. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5118. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5119. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5120. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5121. for _, advice := range advices {
  5122. if advice.FrequencyType == 3 {
  5123. t := time.Now()
  5124. week := int(t.Weekday())
  5125. fmt.Println(t.Weekday())
  5126. fmt.Println(week)
  5127. switch week {
  5128. case 1:
  5129. if strings.Index(advice.WeekDay, "周一") == -1 {
  5130. advice_three = append(advice_three, advice)
  5131. }
  5132. break
  5133. case 2:
  5134. if strings.Index(advice.WeekDay, "周二") == -1 {
  5135. advice_three = append(advice_three, advice)
  5136. }
  5137. break
  5138. case 3:
  5139. if strings.Index(advice.WeekDay, "周三") == -1 {
  5140. advice_three = append(advice_three, advice)
  5141. }
  5142. break
  5143. case 4:
  5144. if strings.Index(advice.WeekDay, "周四") == -1 {
  5145. advice_three = append(advice_three, advice)
  5146. }
  5147. break
  5148. case 5:
  5149. if strings.Index(advice.WeekDay, "周五") == -1 {
  5150. advice_three = append(advice_three, advice)
  5151. }
  5152. break
  5153. case 6:
  5154. if strings.Index(advice.WeekDay, "周六") == -1 {
  5155. advice_three = append(advice_three, advice)
  5156. }
  5157. break
  5158. case 0:
  5159. if strings.Index(advice.WeekDay, "周日") == -1 {
  5160. advice_three = append(advice_three, advice)
  5161. }
  5162. break
  5163. }
  5164. }
  5165. }
  5166. for _, advice := range advices_two {
  5167. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5168. now := p.Unix()
  5169. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5170. dayStr2 := "-" + dayStr
  5171. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5172. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5173. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5174. for _, ad := range advices {
  5175. advice_three = append(advice_three, ad)
  5176. }
  5177. }
  5178. if err == nil {
  5179. c.ServeSuccessJSON(map[string]interface{}{
  5180. "status": "2",
  5181. "advices": advices,
  5182. "advices_two": RemoveRepeatedElement(advice_three),
  5183. "is_open_remind": config.IsOpenRemind,
  5184. "his_config_open": hisConfig.IsOpen,
  5185. "is_advice_open": is_advice_open.IsAdviceOpen,
  5186. "prescription_open": prescription_open.IsOpen,
  5187. })
  5188. }
  5189. }
  5190. }
  5191. func (c *DialysisAPIController) GetLongAdviceOne() {
  5192. patient_id, _ := c.GetInt64("id")
  5193. startTime := c.GetString("schedule_date")
  5194. timeLayout := "2006-01-02"
  5195. loc, _ := time.LoadLocation("Local")
  5196. var theStartTime int64
  5197. if len(startTime) > 0 {
  5198. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5199. if err != nil {
  5200. utils.ErrorLog(err.Error())
  5201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5202. return
  5203. }
  5204. theStartTime = theTime.Unix()
  5205. }
  5206. adminUserInfo := c.GetMobileAdminUserInfo()
  5207. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5208. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5209. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5210. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5211. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5212. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5213. c.ServeSuccessJSON(map[string]interface{}{
  5214. "status": "1",
  5215. })
  5216. return
  5217. } else { //开启推送提醒
  5218. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5219. var advice_three []*models.DoctorAdvice
  5220. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5221. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5222. for _, advice := range advices {
  5223. if advice.FrequencyType == 3 {
  5224. t := time.Now()
  5225. week := int(t.Weekday())
  5226. fmt.Println(t.Weekday())
  5227. fmt.Println(week)
  5228. switch week {
  5229. case 1:
  5230. if strings.Index(advice.WeekDay, "周一") == -1 {
  5231. advice_three = append(advice_three, advice)
  5232. }
  5233. break
  5234. case 2:
  5235. if strings.Index(advice.WeekDay, "周二") == -1 {
  5236. advice_three = append(advice_three, advice)
  5237. }
  5238. break
  5239. case 3:
  5240. if strings.Index(advice.WeekDay, "周三") == -1 {
  5241. advice_three = append(advice_three, advice)
  5242. }
  5243. break
  5244. case 4:
  5245. if strings.Index(advice.WeekDay, "周四") == -1 {
  5246. advice_three = append(advice_three, advice)
  5247. }
  5248. break
  5249. case 5:
  5250. if strings.Index(advice.WeekDay, "周五") == -1 {
  5251. advice_three = append(advice_three, advice)
  5252. }
  5253. break
  5254. case 6:
  5255. if strings.Index(advice.WeekDay, "周六") == -1 {
  5256. advice_three = append(advice_three, advice)
  5257. }
  5258. break
  5259. case 0:
  5260. if strings.Index(advice.WeekDay, "周日") == -1 {
  5261. advice_three = append(advice_three, advice)
  5262. }
  5263. break
  5264. }
  5265. }
  5266. }
  5267. for _, advice := range advices_two {
  5268. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5269. now := p.Unix()
  5270. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5271. dayStr2 := "-" + dayStr
  5272. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5273. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5274. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5275. for _, ad := range advices {
  5276. advice_three = append(advice_three, ad)
  5277. }
  5278. }
  5279. if err == nil {
  5280. c.ServeSuccessJSON(map[string]interface{}{
  5281. "status": "2",
  5282. "advices": advices,
  5283. "advices_two": RemoveRepeatedElement(advice_three),
  5284. "is_open_remind": config.IsOpenRemind,
  5285. "his_config_open": hisConfig.IsOpen,
  5286. "is_advice_open": is_advice_open.IsAdviceOpen,
  5287. "prescription_open": prescription_open.IsOpen,
  5288. })
  5289. }
  5290. }
  5291. }
  5292. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5293. newArr = make([]*models.DoctorAdvice, 0)
  5294. for i := 0; i < len(arr); i++ {
  5295. repeat := false
  5296. for j := i + 1; j < len(arr); j++ {
  5297. if arr[i].ID == arr[j].ID {
  5298. repeat = true
  5299. break
  5300. }
  5301. }
  5302. if !repeat {
  5303. newArr = append(newArr, arr[i])
  5304. }
  5305. }
  5306. return
  5307. }
  5308. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5309. patient, _ := c.GetInt64("id", 0)
  5310. groupNo, _ := c.GetInt64("groupno", 0)
  5311. if patient <= 0 {
  5312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5313. return
  5314. }
  5315. adminUserInfo := c.GetMobileAdminUserInfo()
  5316. dataBody := make(map[string]interface{}, 0)
  5317. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5318. if err != nil {
  5319. utils.ErrorLog(err.Error())
  5320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5321. return
  5322. }
  5323. utils.ErrorLog("%v", dataBody)
  5324. timeLayout := "2006-01-02 15:04"
  5325. loc, _ := time.LoadLocation("Local")
  5326. timeLayout2 := "2006-01-02"
  5327. loc2, _ := time.LoadLocation("Local")
  5328. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5329. utils.ErrorLog("advice_type")
  5330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5331. return
  5332. }
  5333. adviceType := int64(2)
  5334. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5335. utils.ErrorLog("advice_date")
  5336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5337. return
  5338. }
  5339. adviceDate, _ := dataBody["advice_date"].(string)
  5340. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5341. AdviceDate := theTime.Unix()
  5342. RecordDate := theTime.Unix()
  5343. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5344. utils.ErrorLog("start_time")
  5345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5346. return
  5347. }
  5348. startTime, _ := dataBody["start_time"].(string)
  5349. if len(startTime) == 0 {
  5350. utils.ErrorLog("len(start_time) == 0")
  5351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5352. return
  5353. }
  5354. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5355. if err != nil {
  5356. utils.ErrorLog(err.Error())
  5357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5358. return
  5359. }
  5360. StartTime := theTime.Unix()
  5361. Remark := ""
  5362. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5363. remark, _ := dataBody["remark"].(string)
  5364. Remark = remark
  5365. }
  5366. var advices []*models.GroupAdvice
  5367. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5368. utils.ErrorLog("advices")
  5369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5370. return
  5371. }
  5372. adviceNames := dataBody["advices"].([]interface{})
  5373. for _, adviceNameMap := range adviceNames {
  5374. adviceNameM := adviceNameMap.(map[string]interface{})
  5375. var advice models.GroupAdvice
  5376. advice.Remark = Remark
  5377. advice.AdviceType = adviceType
  5378. advice.StartTime = StartTime
  5379. advice.AdviceDate = AdviceDate
  5380. advice.RecordDate = RecordDate
  5381. advice.Status = 1
  5382. advice.CreatedTime = time.Now().Unix()
  5383. advice.UpdatedTime = time.Now().Unix()
  5384. advice.StopState = 2
  5385. advice.ExecutionState = 2
  5386. advice.UserOrgId = adminUserInfo.Org.Id
  5387. advice.PatientId = patient
  5388. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5389. advice.IsSettle = 2
  5390. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5391. utils.ErrorLog("advice_name")
  5392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5393. return
  5394. }
  5395. adviceName, _ := adviceNameM["advice_name"].(string)
  5396. if len(adviceName) == 0 {
  5397. utils.ErrorLog("len(advice_name) == 0")
  5398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5399. return
  5400. }
  5401. advice.AdviceName = adviceName
  5402. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5403. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5404. advice.DrugSpec = drugSpec
  5405. }
  5406. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5407. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5408. advice.AdviceDesc = adviceDesc
  5409. }
  5410. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5411. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5412. advice.DrugSpecUnit = drugSpecUnit
  5413. }
  5414. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5415. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5416. // advice.SingleDose = singleDose
  5417. //}
  5418. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5419. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5420. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5421. }
  5422. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5423. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5424. advice.SingleDoseUnit = singleDoseUnit
  5425. }
  5426. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5427. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5428. // advice.PrescribingNumber = prescribingNumber
  5429. //}
  5430. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5431. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5432. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5433. }
  5434. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5435. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5436. advice.PrescribingNumberUnit = prescribingNumberUnit
  5437. }
  5438. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5439. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5440. advice.DeliveryWay = deliveryWay
  5441. }
  5442. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5443. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5444. advice.ExecutionFrequency = executionFrequency
  5445. }
  5446. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5447. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5448. advice.FrequencyType = frequency_type
  5449. }
  5450. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5451. day_count := int64(adviceNameM["day_count"].(float64))
  5452. advice.DayCount = day_count
  5453. }
  5454. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5455. week_day, _ := adviceNameM["week_day"].(string)
  5456. advice.WeekDay = week_day
  5457. }
  5458. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5459. way := int64(adviceNameM["way"].(float64))
  5460. advice.Way = way
  5461. }
  5462. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5463. drug_id := int64(adviceNameM["drug_id"].(float64))
  5464. advice.DrugId = drug_id
  5465. }
  5466. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5467. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5468. advice.DrugNameId = drug_name_id
  5469. }
  5470. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5471. remark, _ := adviceNameM["remark"].(string)
  5472. advice.Remark = remark
  5473. }
  5474. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5475. groupno := int64(adviceNameM["groupno"].(float64))
  5476. advice.GroupNo = groupno
  5477. }
  5478. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5479. template_id, _ := adviceNameM["template_id"].(string)
  5480. advice.TemplateId = template_id
  5481. }
  5482. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5483. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5484. advice.ExecutionFrequency = executionFrequency
  5485. }
  5486. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5487. children := adviceNameM["child"].([]interface{})
  5488. if len(children) > 0 {
  5489. for _, childrenMap := range children {
  5490. childMap := childrenMap.(map[string]interface{})
  5491. var child models.GroupAdvice
  5492. child.Remark = Remark
  5493. child.AdviceType = adviceType
  5494. child.StartTime = StartTime
  5495. child.AdviceDate = AdviceDate
  5496. child.RecordDate = RecordDate
  5497. child.Status = 1
  5498. child.CreatedTime = time.Now().Unix()
  5499. child.UpdatedTime = time.Now().Unix()
  5500. child.StopState = 2
  5501. child.ExecutionState = 2
  5502. child.UserOrgId = adminUserInfo.Org.Id
  5503. child.PatientId = patient
  5504. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5505. child.IsSettle = 1
  5506. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5507. utils.ErrorLog("child advice_name")
  5508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5509. return
  5510. }
  5511. childAdviceName, _ := childMap["advice_name"].(string)
  5512. if len(childAdviceName) == 0 {
  5513. utils.ErrorLog("len(child advice_name) == 0")
  5514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5515. return
  5516. }
  5517. child.AdviceName = childAdviceName
  5518. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5519. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5520. child.AdviceDesc = childAdviceDesc
  5521. }
  5522. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5523. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5524. child.DrugSpec = childDrugSpec
  5525. }
  5526. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5527. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5528. child.DrugSpecUnit = childDrugSpecUnit
  5529. }
  5530. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5531. child.SingleDose = childMap["single_dose"].(float64)
  5532. }
  5533. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5534. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5535. child.SingleDoseUnit = childSingleDoseUnit
  5536. }
  5537. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5538. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5539. }
  5540. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5541. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5542. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5543. }
  5544. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5545. groupno := int64(childMap["groupno"].(float64))
  5546. advice.GroupNo = groupno
  5547. }
  5548. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5549. remark, _ := childMap["remark"].(string)
  5550. child.Remark = remark
  5551. }
  5552. child.DeliveryWay = advice.DeliveryWay
  5553. child.ExecutionFrequency = advice.ExecutionFrequency
  5554. advice.Children = append(advice.Children, &child)
  5555. }
  5556. }
  5557. }
  5558. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5559. if temp_advice.ID == 0 {
  5560. advices = append(advices, &advice)
  5561. }
  5562. }
  5563. if len(advices) > 0 {
  5564. finish := models.XtDialysisFinish{
  5565. IsFinish: 1,
  5566. UserOrgId: adminUserInfo.Org.Id,
  5567. Status: 1,
  5568. Ctime: time.Now().Unix(),
  5569. Mtime: 0,
  5570. Module: 4,
  5571. RecordDate: AdviceDate,
  5572. Sourse: 1,
  5573. PatientId: patient,
  5574. }
  5575. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5576. if dialysisFinish.ID == 0 {
  5577. service.CreateDialysisFinish(finish)
  5578. }
  5579. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5580. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5581. for _, item := range advices {
  5582. byterequest, _ := json.Marshal(item)
  5583. adviceLog := models.XtDoctorAdviceLog{
  5584. UserOrgId: adminUserInfo.Org.Id,
  5585. PatientId: patient,
  5586. AdminUserId: adminUserInfo.AdminUser.Id,
  5587. Module: 1,
  5588. ErrLog: string(byterequest),
  5589. Status: 1,
  5590. Ctime: time.Now().Unix(),
  5591. Mtime: 0,
  5592. Source: "手机端医嘱推送",
  5593. RecordDate: item.AdviceDate,
  5594. }
  5595. service.CreateDoctorAdviceLog(adviceLog)
  5596. }
  5597. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5598. redis := service.RedisClient()
  5599. //清空key 值
  5600. redis.Set(key, "", time.Second)
  5601. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5602. redis.Set(keyOne, "", time.Second)
  5603. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5604. defer redis.Close()
  5605. redis.Set(keyThree, "", time.Second)
  5606. if err != nil {
  5607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5608. return
  5609. }
  5610. c.ServeSuccessJSON(map[string]interface{}{
  5611. "msg": "ok",
  5612. "advices": list,
  5613. })
  5614. } else {
  5615. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5616. for _, item := range advices {
  5617. byterequest, _ := json.Marshal(item)
  5618. adviceLog := models.XtDoctorAdviceLog{
  5619. UserOrgId: adminUserInfo.Org.Id,
  5620. PatientId: patient,
  5621. AdminUserId: adminUserInfo.AdminUser.Id,
  5622. Module: 1,
  5623. ErrLog: string(byterequest),
  5624. Status: 1,
  5625. Ctime: time.Now().Unix(),
  5626. Mtime: 0,
  5627. Source: "手机端医嘱推送",
  5628. RecordDate: item.AdviceDate,
  5629. }
  5630. service.CreateDoctorAdviceLog(adviceLog)
  5631. }
  5632. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5633. redis := service.RedisClient()
  5634. //清空key 值
  5635. redis.Set(key, "", time.Second)
  5636. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5637. redis.Set(keyOne, "", time.Second)
  5638. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5639. defer redis.Close()
  5640. redis.Set(keyThree, "", time.Second)
  5641. if err != nil {
  5642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5643. return
  5644. }
  5645. c.ServeSuccessJSON(map[string]interface{}{
  5646. "msg": "ok",
  5647. "advices": list,
  5648. })
  5649. }
  5650. } else {
  5651. c.ServeSuccessJSON(map[string]interface{}{
  5652. "msg": "ok",
  5653. })
  5654. }
  5655. return
  5656. }
  5657. func (c *DialysisAPIController) UploadDryWeight() {
  5658. patient_id, _ := c.GetInt64("id")
  5659. dry_weight, _ := c.GetFloat("dry_weight")
  5660. doctor_id, _ := c.GetInt64("doctor_id")
  5661. remark := c.GetString("remark")
  5662. adminUserInfo := c.GetMobileAdminUserInfo()
  5663. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5664. if err == gorm.ErrRecordNotFound {
  5665. dryWeight := &models.SgjPatientDryweight{
  5666. PatientId: patient_id,
  5667. DryWeight: dry_weight,
  5668. Remakes: remark,
  5669. Ctime: time.Now().Unix(),
  5670. Mtime: time.Now().Unix(),
  5671. Creator: doctor_id,
  5672. Status: 1,
  5673. UserOrgId: adminUserInfo.Org.Id,
  5674. AdjustedValue: "/",
  5675. UserId: adminUserInfo.AdminUser.Id,
  5676. }
  5677. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5678. redis := service.RedisClient()
  5679. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5680. redis.Set(keyOne, "", time.Second)
  5681. loc, _ := time.LoadLocation("Local")
  5682. nowTime := time.Now()
  5683. nowDay := nowTime.Format("2006-01-02")
  5684. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5685. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5686. redis.Set(key, "", time.Second)
  5687. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5688. redis.Set(keyTwo, "", time.Second)
  5689. redis.Close()
  5690. if createErr == nil {
  5691. c.ServeSuccessJSON(map[string]interface{}{
  5692. "msg": "提交成功",
  5693. "weight": dryWeight,
  5694. })
  5695. }
  5696. } else {
  5697. dryWeight := &models.SgjPatientDryweight{
  5698. PatientId: patient_id,
  5699. DryWeight: dry_weight,
  5700. Remakes: remark,
  5701. Ctime: time.Now().Unix(),
  5702. Mtime: time.Now().Unix(),
  5703. Creator: doctor_id,
  5704. Status: 1,
  5705. UserOrgId: adminUserInfo.Org.Id,
  5706. AdjustedValue: "/",
  5707. UserId: adminUserInfo.AdminUser.Id,
  5708. }
  5709. var value float64
  5710. value = dry_weight - weightAdjust.DryWeight
  5711. if value < 0 {
  5712. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5713. } else if value == 0 {
  5714. dryWeight.AdjustedValue = "/"
  5715. } else if value > 0 {
  5716. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5717. }
  5718. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5719. //康桥
  5720. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5721. timeNowStr := time.Now().Format("2006-01-02")
  5722. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5723. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5724. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5725. if beforAssesment.ID > 0 {
  5726. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5727. var dewater_amount float64
  5728. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5729. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5730. //获取key,清空redis
  5731. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5732. redis := service.RedisClient()
  5733. //清空key 值
  5734. redis.Set(key, "", time.Second)
  5735. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5736. //清空key 值
  5737. redis.Set(keyOne, "", time.Second)
  5738. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5739. //清空key 值
  5740. redis.Set(keyTwo, "", time.Second)
  5741. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5742. redis.Set(keySix, "", time.Second)
  5743. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5744. redis.Set(keySeven, "", time.Second)
  5745. }
  5746. }
  5747. redis := service.RedisClient()
  5748. loc, _ := time.LoadLocation("Local")
  5749. nowTime := time.Now()
  5750. nowDay := nowTime.Format("2006-01-02")
  5751. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5752. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5753. redis.Set(keyOne, "", time.Second)
  5754. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5755. redis.Set(key, "", time.Second)
  5756. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5757. redis.Set(keyTwo, "", time.Second)
  5758. redis.Close()
  5759. if createErr == nil {
  5760. c.ServeSuccessJSON(map[string]interface{}{
  5761. "msg": "提交成功",
  5762. "weight": dryWeight,
  5763. })
  5764. }
  5765. }
  5766. }
  5767. func (c *DialysisAPIController) GetSolution() {
  5768. patient_id, _ := c.GetInt64("patient_id")
  5769. mode_id, _ := c.GetInt64("mode_id")
  5770. adminUserInfo := c.GetMobileAdminUserInfo()
  5771. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5772. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5773. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5774. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5775. if err != nil {
  5776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5777. return
  5778. }
  5779. c.ServeSuccessJSON(map[string]interface{}{
  5780. "solution": solution,
  5781. "prescription": prescription,
  5782. "system_prescription": system_prescription,
  5783. "dialysisPrescription": dialysisPrescription,
  5784. })
  5785. }
  5786. func (c *DialysisAPIController) GetSchedule() {
  5787. schedual_type, _ := c.GetInt64("schedual_type")
  5788. adminUserInfo := c.GetMobileAdminUserInfo()
  5789. scheduleTime, _ := c.GetInt64("record_date")
  5790. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5791. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5792. c.ServeSuccessJSON(map[string]interface{}{
  5793. "number": deviceNumber,
  5794. "list": list,
  5795. })
  5796. }
  5797. func (c *DialysisAPIController) GetPatientId() {
  5798. id, _ := c.GetInt64("id")
  5799. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5800. patientId, _ := service.GetPatientId(id)
  5801. //获取该患者的所有传染病
  5802. list, _ := service.GetPatientInfectious(id)
  5803. c.ServeSuccessJSON(map[string]interface{}{
  5804. "patient": patientId,
  5805. "infectioulist": list,
  5806. })
  5807. }
  5808. func (this *DialysisAPIController) GetDialysisSchedule() {
  5809. schedualDate := this.GetString("date")
  5810. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5811. if parseDateErr != nil {
  5812. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5813. return
  5814. }
  5815. adminInfo := this.GetMobileAdminUserInfo()
  5816. orgID := adminInfo.Org.Id
  5817. redis := service.RedisClient()
  5818. defer redis.Close()
  5819. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5820. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5821. if len(scheduals) > 0 {
  5822. //缓存数据
  5823. scheduals_json, err := json.Marshal(scheduals)
  5824. if err == nil {
  5825. redis.Set(key, scheduals_json, time.Second*30)
  5826. }
  5827. }
  5828. this.ServeSuccessJSON(map[string]interface{}{
  5829. "scheduals": scheduals,
  5830. })
  5831. }
  5832. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5833. change_type, _ := this.GetInt64("type", 0)
  5834. record_date := this.GetString("record_time")
  5835. patient_id, _ := this.GetInt64("patient_id", 0)
  5836. timeLayout := "2006-01-02"
  5837. loc, _ := time.LoadLocation("Local")
  5838. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5839. record_time := theAdviceRecordTime.Unix()
  5840. adminUserInfo := this.GetMobileAdminUserInfo()
  5841. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5842. if err == nil {
  5843. if len(advices) == 0 {
  5844. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5845. return
  5846. } else {
  5847. this.ServeSuccessJSON(map[string]interface{}{
  5848. "advices": advices,
  5849. "schedule": sch,
  5850. })
  5851. return
  5852. }
  5853. } else {
  5854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5855. return
  5856. }
  5857. }
  5858. func (c *DialysisAPIController) CreateConsumables() {
  5859. record_date := c.GetString("record_time")
  5860. patient_id, _ := c.GetInt64("patient_id", 0)
  5861. active, _ := c.GetInt64("active")
  5862. adminUser := c.GetMobileAdminUserInfo()
  5863. timeLayout := "2006-01-02"
  5864. loc, _ := time.LoadLocation("Local")
  5865. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5866. record_time := theRecordTime.Unix()
  5867. // 查询信息规挡的设置天数
  5868. orgid := c.GetMobileAdminUserInfo().Org.Id
  5869. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5870. if infor.ID > 0 {
  5871. var cha_time int64
  5872. timeNowStr := time.Now().Format("2006-01-02")
  5873. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5874. //今日的日期减去设置的日期
  5875. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5876. if cha_time >= record_time {
  5877. //查询审核是否允许
  5878. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5879. //申请状态不允许的情况 拒绝修改
  5880. if infor.ApplicationStatus != 1 {
  5881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5882. return
  5883. }
  5884. }
  5885. }
  5886. dataBody := make(map[string]interface{}, 0)
  5887. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5888. if err != nil {
  5889. utils.ErrorLog(err.Error())
  5890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5891. return
  5892. }
  5893. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5894. var beforePrepares []*models.DialysisBeforePrepareGoods
  5895. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5896. var dialysisBefor []*models.DialysisBeforePrepare
  5897. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5898. goods, _ := dataBody["goods"].([]interface{})
  5899. if len(goods) > 0 {
  5900. for _, item := range goods {
  5901. items := item.(map[string]interface{})
  5902. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5903. utils.ErrorLog("good_id")
  5904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5905. return
  5906. }
  5907. good_id := int64(items["good_id"].(float64))
  5908. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5909. utils.ErrorLog("good_type_id")
  5910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5911. return
  5912. }
  5913. good_type_id := int64(items["good_type_id"].(float64))
  5914. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5915. utils.ErrorLog("count")
  5916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5917. return
  5918. }
  5919. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5920. commdity_code := items["commdity_code"].(string)
  5921. fmt.Println("commdity", commdity_code)
  5922. prepareGoods := &models.DialysisBeforePrepareGoods{
  5923. GoodTypeId: good_type_id,
  5924. GoodId: good_id,
  5925. Count: count,
  5926. StorehouseId: houseConfig.StorehouseOutInfo,
  5927. }
  5928. beforePrepares = append(beforePrepares, prepareGoods)
  5929. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5930. GoodTypeId: good_type_id,
  5931. GoodId: good_id,
  5932. Count: count,
  5933. StorehouseId: houseConfig.StorehouseOutInfo,
  5934. }
  5935. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5936. prepare := &models.DialysisBeforePrepare{
  5937. GoodTypeId: good_type_id,
  5938. GoodId: good_id,
  5939. Count: count,
  5940. PatientId: patient_id,
  5941. RecordDate: record_time,
  5942. UserOrgId: adminUser.Org.Id,
  5943. Status: 1,
  5944. Ctime: time.Now().Unix(),
  5945. Creater: adminUser.AdminUser.Id,
  5946. CommdityCode: commdity_code,
  5947. StorehouseId: houseConfig.StorehouseOutInfo,
  5948. }
  5949. dialysisBefor = append(dialysisBefor, prepare)
  5950. }
  5951. }
  5952. //查询是否有库存
  5953. for _, item := range dialysisBefor {
  5954. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5955. if err == gorm.ErrRecordNotFound {
  5956. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5957. c.ServeSuccessJSON(map[string]interface{}{
  5958. "message": "1",
  5959. "good_name": goodObj.GoodName,
  5960. "specification_name": goodObj.SpecificationName,
  5961. })
  5962. return
  5963. }
  5964. if err != nil {
  5965. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5966. c.ServeSuccessJSON(map[string]interface{}{
  5967. "message": "1",
  5968. "good_name": goodObj.GoodName,
  5969. "specification_name": goodObj.SpecificationName,
  5970. })
  5971. return
  5972. }
  5973. }
  5974. fmt.Println("active-----------------------", active)
  5975. fmt.Println("len(goods)-----------------------", len(goods))
  5976. //新增
  5977. if active == 1 && len(goods) > 0 {
  5978. for _, item := range dialysisBefor {
  5979. dialyPrepareOne := models.DialysisBeforePrepare{
  5980. GoodTypeId: item.GoodTypeId,
  5981. GoodId: item.GoodId,
  5982. PatientId: item.PatientId,
  5983. RecordDate: item.RecordDate,
  5984. UserOrgId: item.UserOrgId,
  5985. Count: item.Count,
  5986. Ctime: time.Now().Unix(),
  5987. Creater: item.Creater,
  5988. CommdityCode: item.CommdityCode,
  5989. Status: 1,
  5990. StorehouseId: houseConfig.StorehouseOutInfo,
  5991. }
  5992. //先清除再插入
  5993. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5994. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5995. //查询默认仓库
  5996. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5997. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5998. var total_count int64
  5999. for _, it := range stockList {
  6000. total_count += it.StockCount
  6001. }
  6002. //基础库插入数据
  6003. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6004. //更新库存
  6005. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6006. var flush_count int64
  6007. for _, it := range goodList {
  6008. flush_count += it.StockCount
  6009. }
  6010. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6011. }
  6012. if err == nil {
  6013. c.ServeSuccessJSON(map[string]interface{}{
  6014. "msg": "保存成功",
  6015. "message": "2",
  6016. })
  6017. return
  6018. } else {
  6019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6020. return
  6021. }
  6022. }
  6023. if len(beforePrepares) > 0 && active == 2 {
  6024. for _, item := range beforePrepares {
  6025. //1.查看该患者该耗材型号最后一次出库数量
  6026. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6027. //判断当前出库数量和最后一次出库数量的大小
  6028. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6029. if item.Count <= goodInfo.Count {
  6030. //退库
  6031. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6032. //查询今日出库数据
  6033. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6034. for _, it := range list {
  6035. prepare := models.DialysisBeforePrepare{
  6036. UserOrgId: it.OrgId,
  6037. PatientId: patient_id,
  6038. RecordDate: it.RecordTime,
  6039. GoodId: it.GoodId,
  6040. GoodTypeId: it.GoodTypeId,
  6041. Count: it.Count,
  6042. Ctime: time.Now().Unix(),
  6043. Creater: adminUser.AdminUser.Id,
  6044. Status: 1,
  6045. StorehouseId: houseConfig.StorehouseOutInfo,
  6046. }
  6047. //删除准备表数据
  6048. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6049. service.CreateDialysisBeforePrepareOne(&prepare)
  6050. }
  6051. }
  6052. var last_total int64
  6053. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6054. if item.Count >= goodInfo.Count {
  6055. //查询当前批次当前耗材最后一条出库数据
  6056. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6057. //计算当前出库和最后一次出库数据相差数据
  6058. last_total = item.Count - lastOutInfo.Count
  6059. //查询该批次剩余库存
  6060. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6061. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6062. if lastInfo.StockCount >= last_total {
  6063. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6064. //查询今日出库数据
  6065. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6066. for _, it := range list {
  6067. prepare := models.DialysisBeforePrepare{
  6068. UserOrgId: it.OrgId,
  6069. PatientId: patient_id,
  6070. RecordDate: it.RecordTime,
  6071. GoodId: it.GoodId,
  6072. GoodTypeId: it.GoodTypeId,
  6073. Count: it.Count,
  6074. Ctime: time.Now().Unix(),
  6075. Creater: adminUser.AdminUser.Id,
  6076. Status: 1,
  6077. StorehouseId: houseConfig.StorehouseOutInfo,
  6078. }
  6079. //删除准备表数据
  6080. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6081. service.CreateDialysisBeforePrepareOne(&prepare)
  6082. //查询默认仓库
  6083. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6084. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6085. var total_count int64
  6086. for _, it := range stockList {
  6087. total_count += it.StockCount
  6088. }
  6089. //基础库插入数据
  6090. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6091. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6092. var flush_count int64
  6093. for _, it := range goodList {
  6094. flush_count += it.StockCount
  6095. }
  6096. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6097. }
  6098. }
  6099. //如果库存不够,则出库到下一个批次
  6100. if lastInfo.StockCount < last_total {
  6101. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6102. //查询今日出库数据
  6103. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6104. for _, it := range list {
  6105. prepare := models.DialysisBeforePrepare{
  6106. UserOrgId: it.OrgId,
  6107. PatientId: patient_id,
  6108. RecordDate: it.RecordTime,
  6109. GoodId: it.GoodId,
  6110. GoodTypeId: it.GoodTypeId,
  6111. Count: it.Count,
  6112. Ctime: time.Now().Unix(),
  6113. Creater: adminUser.AdminUser.Id,
  6114. Status: 1,
  6115. StorehouseId: houseConfig.StorehouseOutInfo,
  6116. }
  6117. //删除准备表数据
  6118. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6119. service.CreateDialysisBeforePrepareOne(&prepare)
  6120. //查询默认仓库
  6121. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6122. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6123. var total_count int64
  6124. for _, it := range stockList {
  6125. total_count += it.StockCount
  6126. }
  6127. //基础库插入数据
  6128. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6129. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6130. var flush_count int64
  6131. for _, it := range goodList {
  6132. flush_count += it.StockCount
  6133. }
  6134. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6135. }
  6136. if err != nil {
  6137. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6138. c.ServeSuccessJSON(map[string]interface{}{
  6139. "message": "1",
  6140. "good_name": goodObj.GoodName,
  6141. "specification_name": goodObj.SpecificationName,
  6142. })
  6143. return
  6144. }
  6145. }
  6146. }
  6147. if err != nil {
  6148. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6149. c.ServeSuccessJSON(map[string]interface{}{
  6150. "message": "1",
  6151. "good_name": goodObj.GoodName,
  6152. "specification_name": goodObj.SpecificationName,
  6153. })
  6154. return
  6155. }
  6156. }
  6157. }
  6158. }
  6159. var errs error
  6160. if errs == nil {
  6161. c.ServeSuccessJSON(map[string]interface{}{
  6162. "msg": "提交成功",
  6163. "message": "2",
  6164. "good_name": "",
  6165. "specification_name": "",
  6166. })
  6167. return
  6168. } else {
  6169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6170. return
  6171. }
  6172. }
  6173. func (c *DialysisAPIController) CreateStockOutInfo() {
  6174. patient_id, _ := c.GetInt64("patient_id", 0)
  6175. record_date := c.GetString("record_time")
  6176. if patient_id <= 0 {
  6177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6178. return
  6179. }
  6180. adminInfo := c.GetMobileAdminUserInfo()
  6181. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6182. timeLayout := "2006-01-02"
  6183. loc, _ := time.LoadLocation("Local")
  6184. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6185. record_time := theRecordTime.Unix()
  6186. // 查询信息规挡的设置天数
  6187. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6188. if infor.ID > 0 && infor.WeekDay > 0 {
  6189. var cha_time int64
  6190. timeNowStr := time.Now().Format("2006-01-02")
  6191. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6192. //今日的日期减去设置的日期
  6193. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6194. if cha_time >= record_time {
  6195. //查询审核是否允许
  6196. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6197. //申请状态不允许的情况 拒绝修改
  6198. if infor.ApplicationStatus != 1 {
  6199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6200. return
  6201. }
  6202. }
  6203. }
  6204. //创建步骤表
  6205. finish := models.XtDialysisFinish{
  6206. IsFinish: 1,
  6207. UserOrgId: adminInfo.Org.Id,
  6208. Status: 1,
  6209. Ctime: time.Now().Unix(),
  6210. Mtime: 0,
  6211. Module: 11,
  6212. RecordDate: record_time,
  6213. Sourse: 1,
  6214. PatientId: patient_id,
  6215. }
  6216. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6217. if dialysisFinish.ID == 0 {
  6218. service.CreateDialysisFinish(finish)
  6219. }
  6220. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6221. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6222. //去重
  6223. consumables = RemoveRepeatedGood(consumables)
  6224. if adminInfo.Org.Id == 9919 {
  6225. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6226. //查询是否有库存
  6227. for _, item := range consumables {
  6228. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6229. if item.Count > warehouse.Count {
  6230. goodErrcode := models.XtGoodErrcode{
  6231. UserOrgId: item.UserOrgId,
  6232. Errcode: "自动出库库存不足",
  6233. GoodId: item.GoodId,
  6234. Status: 1,
  6235. Ctime: time.Now().Unix(),
  6236. Mtime: 0,
  6237. Count: 0,
  6238. StockCount: 0,
  6239. Creater: creator,
  6240. BatchNumberId: warehouse.ID,
  6241. WarehouseOutId: 0,
  6242. }
  6243. service.CreateGoodErrcode(goodErrcode)
  6244. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6245. c.ServeSuccessJSON(map[string]interface{}{
  6246. "message": "1",
  6247. "good_name": goodObj.GoodName,
  6248. "specification_name": goodObj.SpecificationName,
  6249. })
  6250. return
  6251. }
  6252. }
  6253. //查询是否有出库单
  6254. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6255. if err == gorm.ErrRecordNotFound {
  6256. //没有记录,则创建出库单
  6257. timeStr := time.Now().Format("2006-01-02")
  6258. timeArr := strings.Split(timeStr, "-")
  6259. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6260. total = total + 1
  6261. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6262. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6263. number = number + total
  6264. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6265. creater := adminInfo.AdminUser.Id
  6266. warehouseOut := models.WarehouseOut{
  6267. WarehouseOutOrderNumber: warehousing_out_order,
  6268. OperationTime: time.Now().Unix(),
  6269. OrgId: adminInfo.Org.Id,
  6270. Creater: creater,
  6271. Ctime: time.Now().Unix(),
  6272. Status: 1,
  6273. WarehouseOutTime: record_time,
  6274. Dealer: 0,
  6275. Manufacturer: 0,
  6276. Type: 1,
  6277. IsSys: 1,
  6278. StorehouseId: houseConfig.StorehouseOutInfo,
  6279. IsCheck: 1,
  6280. }
  6281. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6282. if err != nil {
  6283. goodErrcode := models.XtGoodErrcode{
  6284. UserOrgId: adminInfo.Org.Id,
  6285. Errcode: "创建出库单失败",
  6286. GoodId: 0,
  6287. Status: 1,
  6288. Ctime: time.Now().Unix(),
  6289. Mtime: 0,
  6290. Count: 0,
  6291. StockCount: 0,
  6292. Creater: creator,
  6293. BatchNumberId: 0,
  6294. WarehouseOutId: 0,
  6295. }
  6296. service.CreateGoodErrcode(goodErrcode)
  6297. utils.TraceLog("创建出库单失败 err = %v", err)
  6298. } else {
  6299. for _, item := range consumables {
  6300. //出库
  6301. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6302. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6303. if err == nil {
  6304. goodErrcode := models.XtGoodErrcode{
  6305. UserOrgId: adminInfo.Org.Id,
  6306. Errcode: "自动出库接口报错",
  6307. GoodId: 0,
  6308. Status: 1,
  6309. Ctime: time.Now().Unix(),
  6310. Mtime: 0,
  6311. Count: 0,
  6312. StockCount: 0,
  6313. Creater: creator,
  6314. BatchNumberId: 0,
  6315. WarehouseOutId: 0,
  6316. }
  6317. service.CreateGoodErrcode(goodErrcode)
  6318. utils.TraceLog("创建出库单失败 err = %v", err)
  6319. }
  6320. //查询
  6321. //出库数量相加
  6322. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6323. if errs != nil {
  6324. goodErrcode := models.XtGoodErrcode{
  6325. UserOrgId: item.UserOrgId,
  6326. Errcode: "创建剩余库存字段报错",
  6327. GoodId: item.GoodId,
  6328. Status: 1,
  6329. Ctime: time.Now().Unix(),
  6330. Mtime: 0,
  6331. Count: 0,
  6332. StockCount: 0,
  6333. Creater: creater,
  6334. BatchNumberId: 0,
  6335. WarehouseOutId: 0,
  6336. }
  6337. service.CreateGoodErrcode(goodErrcode)
  6338. }
  6339. }
  6340. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6341. if len(list) == 0 {
  6342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6343. return
  6344. }
  6345. for _, item := range list {
  6346. prepare := models.DialysisBeforePrepare{
  6347. UserOrgId: adminInfo.Org.Id,
  6348. PatientId: patient_id,
  6349. RecordDate: record_time,
  6350. GoodId: item.GoodId,
  6351. GoodTypeId: item.GoodTypeId,
  6352. Count: item.Count,
  6353. Creater: adminInfo.AdminUser.Id,
  6354. Status: 1,
  6355. Ctime: time.Now().Unix(),
  6356. StorehouseId: houseConfig.StorehouseOutInfo,
  6357. }
  6358. //清空准备表数据
  6359. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6360. if err != nil {
  6361. goodErrcode := models.XtGoodErrcode{
  6362. UserOrgId: item.OrgId,
  6363. Errcode: "自动出库清空准备表数据报错",
  6364. GoodId: item.GoodId,
  6365. Status: 1,
  6366. Ctime: time.Now().Unix(),
  6367. Mtime: 0,
  6368. Count: 0,
  6369. StockCount: 0,
  6370. Creater: creater,
  6371. BatchNumberId: 0,
  6372. WarehouseOutId: 0,
  6373. }
  6374. service.CreateGoodErrcode(goodErrcode)
  6375. }
  6376. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6377. if errs != nil {
  6378. goodErrcode := models.XtGoodErrcode{
  6379. UserOrgId: item.OrgId,
  6380. Errcode: "自动出库创建准备表数据报错",
  6381. GoodId: item.GoodId,
  6382. Status: 1,
  6383. Ctime: time.Now().Unix(),
  6384. Mtime: 0,
  6385. Count: 0,
  6386. StockCount: 0,
  6387. Creater: creater,
  6388. BatchNumberId: 0,
  6389. WarehouseOutId: 0,
  6390. }
  6391. service.CreateGoodErrcode(goodErrcode)
  6392. }
  6393. //查询默认仓库
  6394. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6395. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6396. var total_count int64
  6397. for _, it := range stockList {
  6398. total_count += it.StockCount
  6399. }
  6400. //基础库插入数据
  6401. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6402. if errcodes != nil {
  6403. goodErrcode := models.XtGoodErrcode{
  6404. UserOrgId: item.OrgId,
  6405. Errcode: "自动出库基础库插入数据",
  6406. GoodId: item.GoodId,
  6407. Status: 1,
  6408. Ctime: time.Now().Unix(),
  6409. Mtime: 0,
  6410. Count: 0,
  6411. StockCount: 0,
  6412. Creater: creater,
  6413. BatchNumberId: 0,
  6414. WarehouseOutId: 0,
  6415. }
  6416. service.CreateGoodErrcode(goodErrcode)
  6417. }
  6418. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6419. var flush_count int64
  6420. for _, it := range goodList {
  6421. flush_count += it.StockCount
  6422. }
  6423. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6424. if errsss != nil {
  6425. goodErrcode := models.XtGoodErrcode{
  6426. UserOrgId: item.OrgId,
  6427. Errcode: "自动出库剩余库存更新数据",
  6428. GoodId: item.GoodId,
  6429. Status: 1,
  6430. Ctime: time.Now().Unix(),
  6431. Mtime: 0,
  6432. Count: 0,
  6433. StockCount: 0,
  6434. Creater: creater,
  6435. BatchNumberId: 0,
  6436. WarehouseOutId: 0,
  6437. }
  6438. service.CreateGoodErrcode(goodErrcode)
  6439. }
  6440. }
  6441. }
  6442. //
  6443. } else if err == nil {
  6444. for _, item := range consumables {
  6445. //出库
  6446. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6447. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6448. if err != nil {
  6449. goodErrcode := models.XtGoodErrcode{
  6450. UserOrgId: adminInfo.Org.Id,
  6451. Errcode: "自动出库接口报错",
  6452. GoodId: 0,
  6453. Status: 1,
  6454. Ctime: time.Now().Unix(),
  6455. Mtime: 0,
  6456. Count: 0,
  6457. StockCount: 0,
  6458. Creater: creator,
  6459. BatchNumberId: 0,
  6460. WarehouseOutId: 0,
  6461. }
  6462. service.CreateGoodErrcode(goodErrcode)
  6463. }
  6464. //出库数量相加
  6465. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6466. if errss != nil {
  6467. goodErrcode := models.XtGoodErrcode{
  6468. UserOrgId: item.UserOrgId,
  6469. Errcode: "创建剩余库存字段报错",
  6470. GoodId: item.GoodId,
  6471. Status: 1,
  6472. Ctime: time.Now().Unix(),
  6473. Mtime: time.Now().Unix(),
  6474. Count: 0,
  6475. StockCount: 0,
  6476. Creater: item.Creater,
  6477. BatchNumberId: 0,
  6478. WarehouseOutId: 0,
  6479. }
  6480. service.CreateGoodErrcode(goodErrcode)
  6481. }
  6482. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6483. if len(list) == 0 {
  6484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6485. return
  6486. }
  6487. for _, item := range list {
  6488. prepare := models.DialysisBeforePrepare{
  6489. UserOrgId: adminInfo.Org.Id,
  6490. PatientId: patient_id,
  6491. RecordDate: record_time,
  6492. GoodId: item.GoodId,
  6493. GoodTypeId: item.GoodTypeId,
  6494. Count: item.Count,
  6495. Creater: adminInfo.AdminUser.Id,
  6496. Status: 1,
  6497. Ctime: time.Now().Unix(),
  6498. StorehouseId: houseConfig.StorehouseOutInfo,
  6499. }
  6500. //清空准备表数据
  6501. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6502. if errs != nil {
  6503. goodErrcode := models.XtGoodErrcode{
  6504. UserOrgId: adminInfo.Org.Id,
  6505. Errcode: "自动出库清空准备表数据报错",
  6506. GoodId: 0,
  6507. Status: 1,
  6508. Ctime: time.Now().Unix(),
  6509. Mtime: 0,
  6510. Count: 0,
  6511. StockCount: 0,
  6512. Creater: creator,
  6513. BatchNumberId: 0,
  6514. WarehouseOutId: 0,
  6515. }
  6516. service.CreateGoodErrcode(goodErrcode)
  6517. }
  6518. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6519. if errcodes != nil {
  6520. goodErrcode := models.XtGoodErrcode{
  6521. UserOrgId: adminInfo.Org.Id,
  6522. Errcode: "自动出库创建准备表数据报错",
  6523. GoodId: 0,
  6524. Status: 1,
  6525. Ctime: time.Now().Unix(),
  6526. Mtime: 0,
  6527. Count: 0,
  6528. StockCount: 0,
  6529. Creater: creator,
  6530. BatchNumberId: 0,
  6531. WarehouseOutId: 0,
  6532. }
  6533. service.CreateGoodErrcode(goodErrcode)
  6534. }
  6535. //查询默认仓库
  6536. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6537. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6538. var total_count int64
  6539. for _, it := range stockList {
  6540. total_count += it.StockCount
  6541. }
  6542. //基础库插入数据
  6543. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6544. if errcodes != nil {
  6545. goodErrcode := models.XtGoodErrcode{
  6546. UserOrgId: adminInfo.Org.Id,
  6547. Errcode: "自动出库基础库插入数据报错",
  6548. GoodId: 0,
  6549. Status: 1,
  6550. Ctime: time.Now().Unix(),
  6551. Mtime: 0,
  6552. Count: 0,
  6553. StockCount: 0,
  6554. Creater: creator,
  6555. BatchNumberId: 0,
  6556. WarehouseOutId: 0,
  6557. }
  6558. service.CreateGoodErrcode(goodErrcode)
  6559. }
  6560. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6561. var flush_count int64
  6562. for _, it := range goodList {
  6563. flush_count += it.StockCount
  6564. }
  6565. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6566. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6567. if errss != nil {
  6568. goodErrcode := models.XtGoodErrcode{
  6569. UserOrgId: item.OrgId,
  6570. Errcode: "自动出库剩余库存更新数据",
  6571. GoodId: item.GoodId,
  6572. Status: 1,
  6573. Ctime: time.Now().Unix(),
  6574. Mtime: 0,
  6575. Count: 0,
  6576. StockCount: 0,
  6577. Creater: creater,
  6578. BatchNumberId: 0,
  6579. WarehouseOutId: 0,
  6580. }
  6581. service.CreateGoodErrcode(goodErrcode)
  6582. }
  6583. }
  6584. }
  6585. }
  6586. c.ServeSuccessJSON(map[string]interface{}{
  6587. "msg": "提交成功",
  6588. "message": "2",
  6589. "good_name": "",
  6590. "specification_name": "",
  6591. })
  6592. return
  6593. }
  6594. if record.IsOpen == 1 {
  6595. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6596. //查询是否有库存
  6597. for _, item := range consumables {
  6598. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6599. if item.Count > warehouse.Count {
  6600. goodErrcode := models.XtGoodErrcode{
  6601. UserOrgId: item.UserOrgId,
  6602. Errcode: "自动出库库存不足",
  6603. GoodId: item.GoodId,
  6604. Status: 1,
  6605. Ctime: time.Now().Unix(),
  6606. Mtime: 0,
  6607. Count: 0,
  6608. StockCount: 0,
  6609. Creater: creator,
  6610. BatchNumberId: warehouse.ID,
  6611. WarehouseOutId: 0,
  6612. }
  6613. service.CreateGoodErrcode(goodErrcode)
  6614. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6615. c.ServeSuccessJSON(map[string]interface{}{
  6616. "message": "1",
  6617. "good_name": goodObj.GoodName,
  6618. "specification_name": goodObj.SpecificationName,
  6619. })
  6620. return
  6621. }
  6622. }
  6623. //查询是否有出库单
  6624. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6625. if err == gorm.ErrRecordNotFound {
  6626. //没有记录,则创建出库单
  6627. timeStr := time.Now().Format("2006-01-02")
  6628. timeArr := strings.Split(timeStr, "-")
  6629. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6630. total = total + 1
  6631. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6632. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6633. number = number + total
  6634. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6635. creater := adminInfo.AdminUser.Id
  6636. warehouseOut := models.WarehouseOut{
  6637. WarehouseOutOrderNumber: warehousing_out_order,
  6638. OperationTime: time.Now().Unix(),
  6639. OrgId: adminInfo.Org.Id,
  6640. Creater: creater,
  6641. Ctime: time.Now().Unix(),
  6642. Status: 1,
  6643. WarehouseOutTime: record_time,
  6644. Dealer: 0,
  6645. Manufacturer: 0,
  6646. Type: 1,
  6647. IsSys: 1,
  6648. StorehouseId: houseConfig.StorehouseOutInfo,
  6649. IsCheck: 1,
  6650. }
  6651. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6652. if err != nil {
  6653. goodErrcode := models.XtGoodErrcode{
  6654. UserOrgId: adminInfo.Org.Id,
  6655. Errcode: "创建出库单失败",
  6656. GoodId: 0,
  6657. Status: 1,
  6658. Ctime: time.Now().Unix(),
  6659. Mtime: 0,
  6660. Count: 0,
  6661. StockCount: 0,
  6662. Creater: creator,
  6663. BatchNumberId: 0,
  6664. WarehouseOutId: 0,
  6665. }
  6666. service.CreateGoodErrcode(goodErrcode)
  6667. utils.TraceLog("创建出库单失败 err = %v", err)
  6668. } else {
  6669. for _, item := range consumables {
  6670. //出库
  6671. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6672. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6673. if err == nil {
  6674. goodErrcode := models.XtGoodErrcode{
  6675. UserOrgId: adminInfo.Org.Id,
  6676. Errcode: "自动出库接口报错",
  6677. GoodId: 0,
  6678. Status: 1,
  6679. Ctime: time.Now().Unix(),
  6680. Mtime: 0,
  6681. Count: 0,
  6682. StockCount: 0,
  6683. Creater: creator,
  6684. BatchNumberId: 0,
  6685. WarehouseOutId: 0,
  6686. }
  6687. service.CreateGoodErrcode(goodErrcode)
  6688. utils.TraceLog("创建出库单失败 err = %v", err)
  6689. }
  6690. //查询
  6691. //出库数量相加
  6692. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6693. if errs != nil {
  6694. goodErrcode := models.XtGoodErrcode{
  6695. UserOrgId: item.UserOrgId,
  6696. Errcode: "创建剩余库存字段报错",
  6697. GoodId: item.GoodId,
  6698. Status: 1,
  6699. Ctime: time.Now().Unix(),
  6700. Mtime: 0,
  6701. Count: 0,
  6702. StockCount: 0,
  6703. Creater: creater,
  6704. BatchNumberId: 0,
  6705. WarehouseOutId: 0,
  6706. }
  6707. service.CreateGoodErrcode(goodErrcode)
  6708. }
  6709. }
  6710. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6711. if len(list) == 0 {
  6712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6713. return
  6714. }
  6715. for _, item := range list {
  6716. prepare := models.DialysisBeforePrepare{
  6717. UserOrgId: adminInfo.Org.Id,
  6718. PatientId: patient_id,
  6719. RecordDate: record_time,
  6720. GoodId: item.GoodId,
  6721. GoodTypeId: item.GoodTypeId,
  6722. Count: item.Count,
  6723. Creater: adminInfo.AdminUser.Id,
  6724. Status: 1,
  6725. Ctime: time.Now().Unix(),
  6726. StorehouseId: houseConfig.StorehouseOutInfo,
  6727. }
  6728. //清空准备表数据
  6729. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6730. if err != nil {
  6731. goodErrcode := models.XtGoodErrcode{
  6732. UserOrgId: item.OrgId,
  6733. Errcode: "自动出库清空准备表数据报错",
  6734. GoodId: item.GoodId,
  6735. Status: 1,
  6736. Ctime: time.Now().Unix(),
  6737. Mtime: 0,
  6738. Count: 0,
  6739. StockCount: 0,
  6740. Creater: creater,
  6741. BatchNumberId: 0,
  6742. WarehouseOutId: 0,
  6743. }
  6744. service.CreateGoodErrcode(goodErrcode)
  6745. }
  6746. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6747. if errs != nil {
  6748. goodErrcode := models.XtGoodErrcode{
  6749. UserOrgId: item.OrgId,
  6750. Errcode: "自动出库创建准备表数据报错",
  6751. GoodId: item.GoodId,
  6752. Status: 1,
  6753. Ctime: time.Now().Unix(),
  6754. Mtime: 0,
  6755. Count: 0,
  6756. StockCount: 0,
  6757. Creater: creater,
  6758. BatchNumberId: 0,
  6759. WarehouseOutId: 0,
  6760. }
  6761. service.CreateGoodErrcode(goodErrcode)
  6762. }
  6763. //查询默认仓库
  6764. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6765. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6766. var total_count int64
  6767. for _, it := range stockList {
  6768. total_count += it.StockCount
  6769. }
  6770. //基础库插入数据
  6771. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6772. if errcodes != nil {
  6773. goodErrcode := models.XtGoodErrcode{
  6774. UserOrgId: item.OrgId,
  6775. Errcode: "自动出库基础库插入数据",
  6776. GoodId: item.GoodId,
  6777. Status: 1,
  6778. Ctime: time.Now().Unix(),
  6779. Mtime: 0,
  6780. Count: 0,
  6781. StockCount: 0,
  6782. Creater: creater,
  6783. BatchNumberId: 0,
  6784. WarehouseOutId: 0,
  6785. }
  6786. service.CreateGoodErrcode(goodErrcode)
  6787. }
  6788. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6789. var flush_count int64
  6790. for _, it := range goodList {
  6791. flush_count += it.StockCount
  6792. }
  6793. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6794. if errsss != nil {
  6795. goodErrcode := models.XtGoodErrcode{
  6796. UserOrgId: item.OrgId,
  6797. Errcode: "自动出库剩余库存更新数据",
  6798. GoodId: item.GoodId,
  6799. Status: 1,
  6800. Ctime: time.Now().Unix(),
  6801. Mtime: 0,
  6802. Count: 0,
  6803. StockCount: 0,
  6804. Creater: creater,
  6805. BatchNumberId: 0,
  6806. WarehouseOutId: 0,
  6807. }
  6808. service.CreateGoodErrcode(goodErrcode)
  6809. }
  6810. }
  6811. }
  6812. //
  6813. } else if err == nil {
  6814. for _, item := range consumables {
  6815. //出库
  6816. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6817. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6818. if err != nil {
  6819. goodErrcode := models.XtGoodErrcode{
  6820. UserOrgId: adminInfo.Org.Id,
  6821. Errcode: "自动出库接口报错",
  6822. GoodId: 0,
  6823. Status: 1,
  6824. Ctime: time.Now().Unix(),
  6825. Mtime: 0,
  6826. Count: 0,
  6827. StockCount: 0,
  6828. Creater: creator,
  6829. BatchNumberId: 0,
  6830. WarehouseOutId: 0,
  6831. }
  6832. service.CreateGoodErrcode(goodErrcode)
  6833. }
  6834. //出库数量相加
  6835. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6836. if errss != nil {
  6837. goodErrcode := models.XtGoodErrcode{
  6838. UserOrgId: item.UserOrgId,
  6839. Errcode: "创建剩余库存字段报错",
  6840. GoodId: item.GoodId,
  6841. Status: 1,
  6842. Ctime: time.Now().Unix(),
  6843. Mtime: time.Now().Unix(),
  6844. Count: 0,
  6845. StockCount: 0,
  6846. Creater: item.Creater,
  6847. BatchNumberId: 0,
  6848. WarehouseOutId: 0,
  6849. }
  6850. service.CreateGoodErrcode(goodErrcode)
  6851. }
  6852. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6853. if len(list) == 0 {
  6854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6855. return
  6856. }
  6857. for _, item := range list {
  6858. prepare := models.DialysisBeforePrepare{
  6859. UserOrgId: adminInfo.Org.Id,
  6860. PatientId: patient_id,
  6861. RecordDate: record_time,
  6862. GoodId: item.GoodId,
  6863. GoodTypeId: item.GoodTypeId,
  6864. Count: item.Count,
  6865. Creater: adminInfo.AdminUser.Id,
  6866. Status: 1,
  6867. Ctime: time.Now().Unix(),
  6868. StorehouseId: houseConfig.StorehouseOutInfo,
  6869. }
  6870. //清空准备表数据
  6871. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6872. if errs != nil {
  6873. goodErrcode := models.XtGoodErrcode{
  6874. UserOrgId: adminInfo.Org.Id,
  6875. Errcode: "自动出库清空准备表数据报错",
  6876. GoodId: 0,
  6877. Status: 1,
  6878. Ctime: time.Now().Unix(),
  6879. Mtime: 0,
  6880. Count: 0,
  6881. StockCount: 0,
  6882. Creater: creator,
  6883. BatchNumberId: 0,
  6884. WarehouseOutId: 0,
  6885. }
  6886. service.CreateGoodErrcode(goodErrcode)
  6887. }
  6888. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6889. if errcodes != nil {
  6890. goodErrcode := models.XtGoodErrcode{
  6891. UserOrgId: adminInfo.Org.Id,
  6892. Errcode: "自动出库创建准备表数据报错",
  6893. GoodId: 0,
  6894. Status: 1,
  6895. Ctime: time.Now().Unix(),
  6896. Mtime: 0,
  6897. Count: 0,
  6898. StockCount: 0,
  6899. Creater: creator,
  6900. BatchNumberId: 0,
  6901. WarehouseOutId: 0,
  6902. }
  6903. service.CreateGoodErrcode(goodErrcode)
  6904. }
  6905. //查询默认仓库
  6906. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6907. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6908. var total_count int64
  6909. for _, it := range stockList {
  6910. total_count += it.StockCount
  6911. }
  6912. //基础库插入数据
  6913. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6914. if errcodes != nil {
  6915. goodErrcode := models.XtGoodErrcode{
  6916. UserOrgId: adminInfo.Org.Id,
  6917. Errcode: "自动出库基础库插入数据报错",
  6918. GoodId: 0,
  6919. Status: 1,
  6920. Ctime: time.Now().Unix(),
  6921. Mtime: 0,
  6922. Count: 0,
  6923. StockCount: 0,
  6924. Creater: creator,
  6925. BatchNumberId: 0,
  6926. WarehouseOutId: 0,
  6927. }
  6928. service.CreateGoodErrcode(goodErrcode)
  6929. }
  6930. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6931. var flush_count int64
  6932. for _, it := range goodList {
  6933. flush_count += it.StockCount
  6934. }
  6935. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6936. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6937. if errss != nil {
  6938. goodErrcode := models.XtGoodErrcode{
  6939. UserOrgId: item.OrgId,
  6940. Errcode: "自动出库剩余库存更新数据",
  6941. GoodId: item.GoodId,
  6942. Status: 1,
  6943. Ctime: time.Now().Unix(),
  6944. Mtime: 0,
  6945. Count: 0,
  6946. StockCount: 0,
  6947. Creater: creater,
  6948. BatchNumberId: 0,
  6949. WarehouseOutId: 0,
  6950. }
  6951. service.CreateGoodErrcode(goodErrcode)
  6952. }
  6953. }
  6954. }
  6955. }
  6956. c.ServeSuccessJSON(map[string]interface{}{
  6957. "msg": "提交成功",
  6958. "message": "2",
  6959. "good_name": "",
  6960. "specification_name": "",
  6961. })
  6962. return
  6963. } else {
  6964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6965. return
  6966. }
  6967. }
  6968. func (c *DialysisAPIController) EditConsumables() {
  6969. patient_id, _ := c.GetInt64("patient_id", 0)
  6970. record_date := c.GetString("record_time")
  6971. if patient_id <= 0 {
  6972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6973. return
  6974. }
  6975. adminInfo := c.GetMobileAdminUserInfo()
  6976. timeLayout := "2006-01-02"
  6977. loc, _ := time.LoadLocation("Local")
  6978. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6979. record_time := theRecordTime.Unix()
  6980. // 查询信息规挡的设置天数
  6981. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6982. if infor.ID > 0 && infor.WeekDay > 0 {
  6983. var cha_time int64
  6984. timeNowStr := time.Now().Format("2006-01-02")
  6985. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6986. //今日的日期减去设置的日期
  6987. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6988. if cha_time >= record_time {
  6989. //查询审核是否允许
  6990. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6991. //申请状态不允许的情况 拒绝修改
  6992. if infor.ApplicationStatus != 1 {
  6993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6994. return
  6995. }
  6996. }
  6997. }
  6998. dataBody := make(map[string]interface{}, 0)
  6999. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7000. if err != nil {
  7001. utils.ErrorLog(err.Error())
  7002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7003. return
  7004. }
  7005. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7006. var beforePrepares []*models.DialysisBeforePrepareGoods
  7007. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7008. var cancelbefor []*models.DialysisBeforePrepareGoods
  7009. var outbefor []*models.DialysisBeforePrepareGoods
  7010. //判断是否开启自动出库
  7011. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7012. if record.IsOpen == 1 {
  7013. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7014. goods, _ := dataBody["goods"].([]interface{})
  7015. if len(goods) > 0 {
  7016. for _, item := range goods {
  7017. items := item.(map[string]interface{})
  7018. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7019. utils.ErrorLog("good_id")
  7020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7021. return
  7022. }
  7023. good_id := int64(items["good_id"].(float64))
  7024. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7025. utils.ErrorLog("good_type_id")
  7026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7027. return
  7028. }
  7029. good_type_id := int64(items["good_type_id"].(float64))
  7030. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7031. utils.ErrorLog("count")
  7032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7033. return
  7034. }
  7035. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7036. commdity_code := items["commdity_code"].(string)
  7037. fmt.Println(commdity_code)
  7038. prepareGoods := &models.DialysisBeforePrepareGoods{
  7039. GoodTypeId: good_type_id,
  7040. GoodId: good_id,
  7041. Count: count,
  7042. StorehouseId: houseConfig.StorehouseOutInfo,
  7043. }
  7044. beforePrepares = append(beforePrepares, prepareGoods)
  7045. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7046. GoodTypeId: good_type_id,
  7047. GoodId: good_id,
  7048. Count: count,
  7049. StorehouseId: houseConfig.StorehouseOutInfo,
  7050. }
  7051. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7052. }
  7053. for _, item := range beforePrepares {
  7054. //1.查看该患者该耗材型号最后一次出库数量
  7055. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7056. //判断当前出库数量和最后一次出库数量的大小
  7057. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7058. if item.Count < goodInfo.Count {
  7059. cancelbefor = append(cancelbefor, item)
  7060. }
  7061. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7062. if item.Count > goodInfo.Count {
  7063. outbefor = append(outbefor, item)
  7064. }
  7065. //处理编辑耗材新增不了的问题
  7066. if goodInfo.Count == item.Count {
  7067. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7068. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7069. }
  7070. }
  7071. if len(cancelbefor) > 0 {
  7072. //退库
  7073. for _, item := range cancelbefor {
  7074. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7075. creater := adminInfo.AdminUser.Id
  7076. //查询该患者当天已经出库的耗材信息
  7077. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7078. var delete_count int64 = 0
  7079. delete_count = warehouseOutInfos.Count - item.Count
  7080. //增加库存数量
  7081. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7082. //减少实际出库库存数量
  7083. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7084. // 删除出库完成后,要增加对应批次的库存数量
  7085. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7086. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7087. //更新剩余库存
  7088. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7089. var flush_count int64
  7090. for _, it := range goodListOne {
  7091. flush_count += it.StockCount
  7092. }
  7093. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7094. //查询剩余库存
  7095. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7096. var sum_count int64
  7097. for _, item := range goodList {
  7098. sum_count += item.StockCount
  7099. }
  7100. // 在出库记录表里记录退库详情
  7101. warehouseOutInfo := &models.WarehouseOutInfo{
  7102. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7103. WarehouseOutId: warehouseOut.ID,
  7104. Status: 1,
  7105. Ctime: time.Now().Unix(),
  7106. OrgId: adminInfo.Org.Id,
  7107. Type: 1,
  7108. IsSys: 1,
  7109. SysRecordTime: record_time,
  7110. GoodTypeId: item.GoodTypeId,
  7111. GoodId: item.GoodId,
  7112. PatientId: patient_id,
  7113. ConsumableType: 2,
  7114. StorehouseId: houseConfig.StorehouseOutInfo,
  7115. IsCheck: 1,
  7116. OverCount: sum_count,
  7117. }
  7118. warehouseOutInfo.Count = item.Count
  7119. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7120. warehouseOutInfo.Price = stockInInfo.Price
  7121. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7122. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7123. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7124. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7125. warehouseOutInfo.Number = warehouseOutInfos.Number
  7126. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7127. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7128. //查找当天是否存在出库记录
  7129. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7130. if errcod == gorm.ErrRecordNotFound {
  7131. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7132. //插入详情明细表
  7133. stockFlow := models.VmStockFlow{
  7134. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7135. WarehouseOutId: warehouseOut.ID,
  7136. GoodId: item.GoodId,
  7137. Number: warehouseOutInfos.Number,
  7138. ProductDate: stockInInfo.ProductDate,
  7139. ExpireDate: stockInInfo.ExpiryDate,
  7140. Count: item.Count,
  7141. Price: stockInInfo.Price,
  7142. Status: 1,
  7143. Ctime: record_time,
  7144. UserOrgId: adminInfo.Org.Id,
  7145. Manufacturer: stockInInfo.Manufacturer,
  7146. Dealer: stockInInfo.Dealer,
  7147. LicenseNumber: stockInInfo.LicenseNumber,
  7148. IsEdit: 2,
  7149. Creator: creater,
  7150. SystemTime: record_time,
  7151. ConsumableType: 3,
  7152. WarehousingDetailId: 0,
  7153. IsSys: 1,
  7154. UpdateCreator: creater,
  7155. PatientId: patient_id,
  7156. StorehouseId: houseConfig.StorehouseOutInfo,
  7157. }
  7158. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7159. if errflow == gorm.ErrRecordNotFound {
  7160. //创建流水表
  7161. err := service.CreateStockFlowOne(stockFlow)
  7162. fmt.Println("err", err)
  7163. } else if errflow == nil {
  7164. //插入详情明细表
  7165. stockFlow := models.VmStockFlow{
  7166. ID: exsit.ID,
  7167. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7168. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7169. WarehouseOutId: warehouseOut.ID,
  7170. GoodId: item.GoodId,
  7171. Number: warehouseOutInfos.Number,
  7172. ProductDate: stockInInfo.ProductDate,
  7173. ExpireDate: stockInInfo.ExpiryDate,
  7174. Count: exsit.Count - delete_count,
  7175. Price: stockInInfo.Price,
  7176. Status: 1,
  7177. Ctime: record_time,
  7178. UserOrgId: adminInfo.Org.Id,
  7179. Manufacturer: stockInInfo.Manufacturer,
  7180. Dealer: stockInInfo.Dealer,
  7181. LicenseNumber: stockInInfo.LicenseNumber,
  7182. IsEdit: 2,
  7183. Creator: creater,
  7184. SystemTime: record_time,
  7185. ConsumableType: 3,
  7186. WarehousingDetailId: 0,
  7187. IsSys: 1,
  7188. UpdateCreator: creater,
  7189. PatientId: patient_id,
  7190. StorehouseId: houseConfig.StorehouseOutInfo,
  7191. }
  7192. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7193. }
  7194. } else if errcod == nil {
  7195. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7196. //查询剩余库存
  7197. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7198. var sum_count int64
  7199. for _, item := range goodList {
  7200. sum_count += item.StockCount
  7201. }
  7202. //创建退库单,生成退库数据
  7203. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7204. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7205. operation_time := time.Now().Unix()
  7206. creater := adminInfo.AdminUser.Id
  7207. //创建退库单
  7208. timeStr := time.Now().Format("2006-01-02")
  7209. timeArr := strings.Split(timeStr, "-")
  7210. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7211. total = total + 1
  7212. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7213. cancelStock := models.CancelStock{
  7214. OrderNumber: orderNumber,
  7215. OperaTime: operation_time,
  7216. OrgId: adminInfo.Org.Id,
  7217. Creater: creater,
  7218. Ctime: time.Now().Unix(),
  7219. Status: 1,
  7220. ReturnTime: record_time,
  7221. Type: 1,
  7222. StorehouseId: houseConfig.StorehouseOutInfo,
  7223. IsCheck: 1,
  7224. }
  7225. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7226. if msgerrkonde == gorm.ErrRecordNotFound {
  7227. service.AddSigleCancelStock(&cancelStock)
  7228. }
  7229. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7230. //查询是否有出库
  7231. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7232. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7233. deaerler, _ := service.GetDealerById(info.Dealer)
  7234. if info.ID > 0 {
  7235. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7236. cancelStockInfo := models.CancelStockInfo{
  7237. GoodId: item.GoodId,
  7238. CancelStockId: cancel.ID,
  7239. GoodTypeId: good.GoodTypeId,
  7240. Count: delete_count,
  7241. Price: info.Price,
  7242. Total: 0,
  7243. ProductDate: info.ProductDate,
  7244. ExpiryDate: info.ExpiryDate,
  7245. Ctime: time.Now().Unix(),
  7246. Status: 1,
  7247. OrgId: adminInfo.Org.Id,
  7248. OrderNumber: cancel.OrderNumber,
  7249. Type: 0,
  7250. Dealer: deaerler.DealerName,
  7251. Manufacturer: manufacturer.ManufacturerName,
  7252. Number: info.Number,
  7253. RegisterAccount: "",
  7254. Remark: "",
  7255. WarehouseInfoId: info.WarehouseInfotId,
  7256. PatientId: info.PatientId,
  7257. RecordDate: info.SysRecordTime,
  7258. StorehouseId: houseConfig.StorehouseOutInfo,
  7259. IsCheck: 1,
  7260. }
  7261. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7262. //退库数量增加
  7263. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7264. //查询剩余库存
  7265. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7266. var over_count int64
  7267. for _, it := range goodList {
  7268. over_count += it.StockCount
  7269. }
  7270. flow := models.VmStockFlow{
  7271. WarehousingId: info.WarehouseInfotId,
  7272. GoodId: item.GoodId,
  7273. Number: info.Number,
  7274. LicenseNumber: info.LicenseNumber,
  7275. Count: delete_count,
  7276. UserOrgId: adminInfo.Org.Id,
  7277. PatientId: patient_id,
  7278. SystemTime: info.SysRecordTime,
  7279. ConsumableType: 7,
  7280. IsSys: 0,
  7281. WarehousingOrder: "",
  7282. WarehouseOutId: info.WarehouseOutId,
  7283. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7284. IsEdit: 0,
  7285. CancelStockId: cancel.ID,
  7286. CancelOrderNumber: cancel.OrderNumber,
  7287. Manufacturer: manufacturer.ID,
  7288. Dealer: 0,
  7289. Creator: adminInfo.AdminUser.Id,
  7290. UpdateCreator: 0,
  7291. Status: 1,
  7292. Ctime: record_time,
  7293. Mtime: 0,
  7294. Price: info.Price,
  7295. WarehousingDetailId: info.WarehouseInfotId,
  7296. WarehouseOutDetailId: info.ID,
  7297. CancelOutDetailId: cancelInfo.ID,
  7298. ProductDate: info.ProductDate,
  7299. ExpireDate: info.ExpiryDate,
  7300. StorehouseId: houseConfig.StorehouseOutInfo,
  7301. OverCount: over_count,
  7302. }
  7303. service.CreateStockFlowOne(flow)
  7304. }
  7305. }
  7306. //更改自动出库的表格
  7307. details := models.BloodAutomaticReduceDetail{
  7308. WarehouseOutId: warehouseOutInfo.ID,
  7309. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7310. PatientId: patient_id,
  7311. Ctime: time.Now().Unix(),
  7312. Mtime: time.Now().Unix(),
  7313. Status: 1,
  7314. RecordTime: record_time,
  7315. OrgId: adminInfo.Org.Id,
  7316. GoodId: item.GoodId,
  7317. GoodTypeId: item.GoodTypeId,
  7318. Count: item.Count,
  7319. StorehouseId: houseConfig.StorehouseOutInfo,
  7320. }
  7321. //查询当天耗材是否已经存在数据
  7322. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7323. if errcode == gorm.ErrRecordNotFound {
  7324. service.CreateAutoReduceRecord(&details)
  7325. } else if errcode == nil {
  7326. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7327. service.CreateAutoReduceRecord(&details)
  7328. }
  7329. //查询默认仓库
  7330. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7331. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7332. var total_count int64
  7333. for _, it := range stockList {
  7334. total_count += it.StockCount
  7335. }
  7336. //基础库插入数据
  7337. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7338. }
  7339. }
  7340. if len(outbefor) > 0 {
  7341. //出库
  7342. for _, item := range outbefor {
  7343. var last_total int64
  7344. //1.查看该患者该耗材型号最后一次出库数量
  7345. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7346. //计算当前出库和最后一次出库数据相差数据
  7347. last_total = item.Count - goodInfoOne.Count
  7348. //查询该耗材的总库存
  7349. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7350. // 如果库存差大于剩余库存则提示库存不足
  7351. if last_total > wareinfo.StockCount {
  7352. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7353. c.ServeSuccessJSON(map[string]interface{}{
  7354. "message": "1",
  7355. "good_name": goodObj.GoodName,
  7356. "specification_name": goodObj.SpecificationName,
  7357. })
  7358. return
  7359. } else {
  7360. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7361. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7362. if err == gorm.ErrRecordNotFound {
  7363. //没有记录,则创建出库单
  7364. timeStr := time.Now().Format("2006-01-02")
  7365. timeArr := strings.Split(timeStr, "-")
  7366. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7367. total = total + 1
  7368. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7369. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7370. number = number + total
  7371. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7372. warehouseOut := models.WarehouseOut{
  7373. WarehouseOutOrderNumber: warehousing_out_order,
  7374. OperationTime: time.Now().Unix(),
  7375. OrgId: adminInfo.Org.Id,
  7376. Creater: adminInfo.AdminUser.Id,
  7377. Ctime: time.Now().Unix(),
  7378. Status: 1,
  7379. WarehouseOutTime: record_time,
  7380. Dealer: 0,
  7381. Manufacturer: 0,
  7382. Type: 1,
  7383. IsSys: 1,
  7384. StorehouseId: houseConfig.StorehouseOutInfo,
  7385. IsCheck: 1,
  7386. }
  7387. service.AddSigleWarehouseOutOne(&warehouseOut)
  7388. }
  7389. //出库
  7390. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7391. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7392. //1.查看该患者该耗材型号最后一次出库数量
  7393. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7394. prepare := models.DialysisBeforePrepare{
  7395. UserOrgId: adminInfo.Org.Id,
  7396. PatientId: patient_id,
  7397. RecordDate: record_time,
  7398. GoodId: item.GoodId,
  7399. GoodTypeId: item.GoodTypeId,
  7400. Count: item.Count - goodInfoTwo.Count,
  7401. Ctime: time.Now().Unix(),
  7402. Mtime: 0,
  7403. Creater: adminInfo.AdminUser.Id,
  7404. Modifier: adminInfo.AdminUser.Id,
  7405. Status: 1,
  7406. CommdityCode: "",
  7407. NewCount: 0,
  7408. ProjectId: 0,
  7409. StorehouseId: houseConfig.StorehouseOutInfo,
  7410. }
  7411. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7412. //增加出库数量
  7413. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7414. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7415. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7416. var total_count int64
  7417. for _, it := range stockList {
  7418. total_count += it.StockCount
  7419. }
  7420. //基础库插入数据
  7421. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7422. //剩余库存
  7423. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7424. var flush_count int64
  7425. for _, it := range goodList {
  7426. flush_count += it.StockCount
  7427. }
  7428. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7429. }
  7430. }
  7431. }
  7432. //查询今日出库数据
  7433. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7434. for _, it := range list {
  7435. prepare := models.DialysisBeforePrepare{
  7436. UserOrgId: it.OrgId,
  7437. PatientId: patient_id,
  7438. RecordDate: it.RecordTime,
  7439. GoodId: it.GoodId,
  7440. GoodTypeId: it.GoodTypeId,
  7441. Count: it.Count,
  7442. Ctime: time.Now().Unix(),
  7443. Creater: adminInfo.AdminUser.Id,
  7444. Status: 1,
  7445. StorehouseId: houseConfig.StorehouseOutInfo,
  7446. ProjectId: it.ProjectId,
  7447. }
  7448. //删除准备表数据
  7449. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7450. service.CreateDialysisBeforePrepareOne(&prepare)
  7451. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7452. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7453. var total_count int64
  7454. for _, it := range stockList {
  7455. total_count += it.StockCount
  7456. }
  7457. //基础库插入数据
  7458. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7459. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7460. var flush_count int64
  7461. for _, it := range goodList {
  7462. flush_count += it.StockCount
  7463. }
  7464. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7465. }
  7466. }
  7467. }
  7468. //更新自动出库的地方
  7469. var errs error
  7470. if errs == nil {
  7471. c.ServeSuccessJSON(map[string]interface{}{
  7472. "msg": "修改成功",
  7473. "message": "2",
  7474. "good_name": "",
  7475. "specification_name": "",
  7476. })
  7477. return
  7478. } else {
  7479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7480. return
  7481. }
  7482. }
  7483. }
  7484. func (c *DialysisAPIController) GetDialysisGoods() {
  7485. schedualDate := c.GetString("schedule_date")
  7486. schedule_type, _ := c.GetInt64("schedule_type")
  7487. partition_id, _ := c.GetInt64("partition_id")
  7488. page, _ := c.GetInt("page")
  7489. patient_id, _ := c.GetInt64("patient_id")
  7490. schedualEndDate := int64(0)
  7491. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7492. if parseDateErr != nil && len(schedualDate) != 0 {
  7493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7494. return
  7495. }
  7496. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7497. if parseDateErr != nil && len(schedualDate) != 0 {
  7498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7499. return
  7500. }
  7501. schedualEndDate = endDate.Unix()
  7502. adminUser := c.GetMobileAdminUserInfo()
  7503. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7504. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7505. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7506. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7507. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7508. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7509. //获取当天该病人的透析处方
  7510. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7511. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7512. if err == gorm.ErrRecordNotFound {
  7513. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7514. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7515. if patient_id != 0 {
  7516. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7517. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7518. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7519. //获取患者总的出库数据
  7520. item.LastAutomaticReduceDetail = goodUser
  7521. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7522. item.Project = project
  7523. for _, it := range item.AutomaticReduceDetail {
  7524. var total int64
  7525. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7526. for _, its := range auto {
  7527. total += its.Count
  7528. }
  7529. it.Count = total
  7530. }
  7531. }
  7532. }
  7533. c.ServeSuccessJSON(map[string]interface{}{
  7534. "dialysis_goods": dialysisGoods,
  7535. "good_type": goodTypes,
  7536. "total": total,
  7537. "prescribe": prescribe,
  7538. "good_info": good_info,
  7539. "warehouseOutList": warehouseOutList,
  7540. "config": config,
  7541. "outConfig": outConfig,
  7542. "settleConfig": settleConfig,
  7543. })
  7544. return
  7545. } else if err == nil {
  7546. //获取当天排班的每个患者的库存使用情况
  7547. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7548. //获取患者总的出库数据
  7549. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7550. if patient_id != 0 {
  7551. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7552. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7553. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7554. item.Project = project
  7555. item.LastAutomaticReduceDetail = goodUser
  7556. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7557. for _, it := range item.AutomaticReduceDetail {
  7558. var total int64
  7559. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7560. for _, its := range auto {
  7561. total += its.Count
  7562. }
  7563. it.Count = total
  7564. }
  7565. }
  7566. }
  7567. if err == nil {
  7568. c.ServeSuccessJSON(map[string]interface{}{
  7569. "dialysis_goods": dialysisGoods,
  7570. "good_type": goodTypes,
  7571. "total": total,
  7572. "prescribe": prescribe,
  7573. "good_info": good_info,
  7574. "project": project,
  7575. "warehouseOutList": warehouseOutList,
  7576. "config": config,
  7577. "outConfig": outConfig,
  7578. "settleConfig": settleConfig,
  7579. })
  7580. return
  7581. } else {
  7582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7583. return
  7584. }
  7585. } else if err != nil {
  7586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7587. return
  7588. }
  7589. }
  7590. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7591. start_time := c.GetString("start_time")
  7592. end_time := c.GetString("end_time")
  7593. timeLayout := "2006-01-02"
  7594. loc, _ := time.LoadLocation("Local")
  7595. var theStartTime int64
  7596. if len(start_time) > 0 {
  7597. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7598. if err != nil {
  7599. utils.ErrorLog(err.Error())
  7600. }
  7601. theStartTime = theTime.Unix()
  7602. }
  7603. var theEndtTime int64
  7604. if len(end_time) > 0 {
  7605. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7606. if err != nil {
  7607. utils.ErrorLog(err.Error())
  7608. }
  7609. theEndtTime = theTime.Unix()
  7610. }
  7611. adminUser := c.GetMobileAdminUserInfo()
  7612. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7613. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7614. if err == nil {
  7615. c.ServeSuccessJSON(map[string]interface{}{
  7616. "stock_out": outInfo,
  7617. "stockCount": stockCount,
  7618. })
  7619. return
  7620. } else {
  7621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7622. return
  7623. }
  7624. }
  7625. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7626. patient_id, _ := c.GetInt64("patient_id", 0)
  7627. record_time := c.GetString("record_time")
  7628. adminUser := c.GetMobileAdminUserInfo()
  7629. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7630. if parseDateErr != nil && len(record_time) != 0 {
  7631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7632. return
  7633. }
  7634. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7635. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7636. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7637. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7638. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7639. //获取今日患者的透析处方参数
  7640. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7641. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7642. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7643. c.ServeSuccessJSON(map[string]interface{}{
  7644. "good_type": goodTypes,
  7645. "good_user": goodUser,
  7646. "good_info": good_info,
  7647. "last_good_user": lastGoodUserDetial,
  7648. "project": project,
  7649. "prescription": prescribe,
  7650. "outInfo": outInfo,
  7651. "configs": configs,
  7652. })
  7653. return
  7654. }
  7655. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7656. patient_id, _ := c.GetInt64("patient_id", 0)
  7657. record_date := c.GetString("record_time")
  7658. timeLayout := "2006-01-02"
  7659. loc, _ := time.LoadLocation("Local")
  7660. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7661. record_time := theRecordTime.Unix()
  7662. adminInfo := c.GetMobileAdminUserInfo()
  7663. dataBody := make(map[string]interface{}, 0)
  7664. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7665. if err != nil {
  7666. utils.ErrorLog(err.Error())
  7667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7668. return
  7669. }
  7670. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7671. var beforePrepares []*models.DialysisBeforePrepareGoods
  7672. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7673. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7674. goods, _ := dataBody["goods"].([]interface{})
  7675. if len(goods) > 0 {
  7676. for _, item := range goods {
  7677. items := item.(map[string]interface{})
  7678. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7679. utils.ErrorLog("good_id")
  7680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7681. return
  7682. }
  7683. good_id := int64(items["good_id"].(float64))
  7684. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7685. utils.ErrorLog("good_type_id")
  7686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7687. return
  7688. }
  7689. good_type_id := int64(items["good_type_id"].(float64))
  7690. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7691. utils.ErrorLog("count")
  7692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7693. return
  7694. }
  7695. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7696. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7697. utils.ErrorLog("project_id")
  7698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7699. return
  7700. }
  7701. project_id := int64(items["project_id"].(float64))
  7702. new_count := int64(items["new_count"].(float64))
  7703. old_count := int64(items["old_count"].(float64))
  7704. prepare := &models.DialysisBeforePrepareGoods{
  7705. GoodId: good_id,
  7706. GoodTypeId: good_type_id,
  7707. Count: count,
  7708. ProjectId: project_id,
  7709. StorehouseId: houseConfig.StorehouseOutInfo,
  7710. NewCount: new_count,
  7711. OldCount: old_count,
  7712. }
  7713. beforePrepares = append(beforePrepares, prepare)
  7714. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7715. GoodId: good_id,
  7716. GoodTypeId: good_type_id,
  7717. Count: count,
  7718. ProjectId: project_id,
  7719. StorehouseId: houseConfig.StorehouseOutInfo,
  7720. NewCount: new_count,
  7721. OldCount: old_count,
  7722. }
  7723. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7724. }
  7725. }
  7726. }
  7727. //查询是否有库存
  7728. for _, item := range beforePrepares {
  7729. if item.NewCount > 0 {
  7730. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7731. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7732. if item.Count > warehouse.Count {
  7733. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7734. c.ServeSuccessJSON(map[string]interface{}{
  7735. "message": "1",
  7736. "good_name": goodObj.GoodName,
  7737. "specification_name": goodObj.SpecificationName,
  7738. })
  7739. return
  7740. }
  7741. }
  7742. }
  7743. // 查询信息规挡的设置天数
  7744. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7745. if infor.ID > 0 && infor.WeekDay > 0 {
  7746. var cha_time int64
  7747. timeNowStr := time.Now().Format("2006-01-02")
  7748. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7749. //今日的日期减去设置的日期
  7750. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7751. if cha_time >= record_time {
  7752. //查询审核是否允许
  7753. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7754. //申请状态不允许的情况 拒绝修改
  7755. if infor.ApplicationStatus != 1 {
  7756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7757. return
  7758. }
  7759. }
  7760. }
  7761. //出库逻辑
  7762. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7763. if err != nil {
  7764. utils.ErrorLog(err.Error())
  7765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7766. return
  7767. }
  7768. finish := models.XtDialysisFinish{
  7769. IsFinish: 1,
  7770. UserOrgId: adminInfo.Org.Id,
  7771. Status: 1,
  7772. Ctime: time.Now().Unix(),
  7773. Mtime: 0,
  7774. Module: 11,
  7775. RecordDate: record_time,
  7776. Sourse: 1,
  7777. PatientId: patient_id,
  7778. }
  7779. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7780. if dialysisFinish.ID == 0 {
  7781. service.CreateDialysisFinish(finish)
  7782. }
  7783. //查询当天出库的数据
  7784. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7785. for _, item := range list {
  7786. prepare := models.DialysisBeforePrepare{
  7787. UserOrgId: item.OrgId,
  7788. PatientId: item.PatientId,
  7789. RecordDate: item.RecordTime,
  7790. GoodId: item.GoodId,
  7791. GoodTypeId: item.GoodTypeId,
  7792. Count: item.Count,
  7793. Creater: adminInfo.AdminUser.Id,
  7794. Status: 1,
  7795. Ctime: time.Now().Unix(),
  7796. ProjectId: item.ProjectId,
  7797. StorehouseId: houseConfig.StorehouseOutInfo,
  7798. }
  7799. //清空准备表的数据
  7800. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7801. //插入准备表数据
  7802. service.CreateDialysisBeforePrepareOne(&prepare)
  7803. //查询默认仓库
  7804. //查询默认仓库
  7805. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7806. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7807. var total_count int64
  7808. for _, it := range stockList {
  7809. total_count += it.StockCount
  7810. }
  7811. //基础库插入数据
  7812. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7813. ////更新剩余库存
  7814. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7815. var flush_count int64
  7816. for _, it := range goodList {
  7817. flush_count += it.StockCount
  7818. }
  7819. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7820. if errs != nil {
  7821. goodErrcode := models.XtGoodErrcode{
  7822. UserOrgId: item.OrgId,
  7823. Errcode: "手动出库更新剩余出库失败",
  7824. GoodId: item.GoodId,
  7825. Status: 1,
  7826. Ctime: time.Now().Unix(),
  7827. Mtime: 0,
  7828. Count: 0,
  7829. StockCount: 0,
  7830. Creater: adminInfo.AdminUser.Id,
  7831. BatchNumberId: 0,
  7832. WarehouseOutId: 0,
  7833. }
  7834. service.CreateGoodErrcode(goodErrcode)
  7835. }
  7836. }
  7837. //更新自动出库的地方
  7838. var errs error
  7839. if errs == nil {
  7840. c.ServeSuccessJSON(map[string]interface{}{
  7841. "msg": "修改成功",
  7842. "message": "2",
  7843. "good_name": "",
  7844. "specification_name": "",
  7845. })
  7846. return
  7847. } else {
  7848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7849. return
  7850. }
  7851. }
  7852. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7853. newArr = make([]*models.DialysisBeforePrepare, 0)
  7854. for i := 0; i < len(arr); i++ {
  7855. repeat := false
  7856. for j := i + 1; j < len(arr); j++ {
  7857. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7858. repeat = true
  7859. break
  7860. }
  7861. }
  7862. if !repeat {
  7863. newArr = append(newArr, arr[i])
  7864. }
  7865. }
  7866. return
  7867. }
  7868. func (c *DialysisAPIController) GetAllDrug() {
  7869. patient_id, _ := c.GetInt64("patient_id", 0)
  7870. adminInfo := c.GetMobileAdminUserInfo()
  7871. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7872. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7873. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7874. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7875. c.ServeSuccessJSON(map[string]interface{}{
  7876. "base_drug_config": drugStockConfig,
  7877. "private_drug_config": privateDrugConfig,
  7878. "base_drug_list": drugList,
  7879. "private_drug_list": privateDrugList,
  7880. })
  7881. }
  7882. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7883. newArr = make([]*models.DialysisBeforePrepare, 0)
  7884. for i := 0; i < len(arr); i++ {
  7885. repeat := false
  7886. for j := i + 1; j < len(arr); j++ {
  7887. if arr[i].GoodId == arr[j].GoodId {
  7888. repeat = true
  7889. break
  7890. }
  7891. }
  7892. if !repeat {
  7893. newArr = append(newArr, arr[i])
  7894. }
  7895. }
  7896. return
  7897. }
  7898. func (c *DialysisAPIController) GetDepartment() {
  7899. adminInfo := c.GetMobileAdminUserInfo()
  7900. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7901. if err == nil {
  7902. c.ServeSuccessJSON(map[string]interface{}{
  7903. "departments": departments,
  7904. })
  7905. } else {
  7906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7907. return
  7908. }
  7909. }
  7910. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7911. types, _ := c.GetInt("type", 0)
  7912. start_time := c.GetString("start_time")
  7913. end_time := c.GetString("end_time")
  7914. orgId := c.GetMobileAdminUserInfo().Org.Id
  7915. timeLayout := "2006-01-02"
  7916. loc, _ := time.LoadLocation("Local")
  7917. var startTime int64
  7918. if len(start_time) > 0 {
  7919. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7920. if err != nil {
  7921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7922. return
  7923. }
  7924. startTime = theTime.Unix()
  7925. }
  7926. var endTime int64
  7927. if len(end_time) > 0 {
  7928. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7929. if err != nil {
  7930. utils.ErrorLog(err.Error())
  7931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7932. return
  7933. }
  7934. endTime = theTime.Unix()
  7935. }
  7936. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7937. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7938. if err != nil {
  7939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7940. } else {
  7941. c.ServeSuccessJSON(map[string]interface{}{
  7942. "list": list,
  7943. "type": types,
  7944. "stockTotal": stockTotal,
  7945. })
  7946. }
  7947. }
  7948. func (c *DialysisAPIController) GetPrescriptionList() {
  7949. start_time := c.GetString("start_time")
  7950. end_time := c.GetString("end_time")
  7951. schedule_type, _ := c.GetInt64("schedule_type")
  7952. partion_id, _ := c.GetInt64("partion_id")
  7953. orgId := c.GetMobileAdminUserInfo().Org.Id
  7954. timeLayout := "2006-01-02"
  7955. loc, _ := time.LoadLocation("Local")
  7956. var startTime int64
  7957. if len(start_time) > 0 {
  7958. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7959. if err != nil {
  7960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7961. return
  7962. }
  7963. startTime = theTime.Unix()
  7964. }
  7965. var endTime int64
  7966. if len(end_time) > 0 {
  7967. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7968. if err != nil {
  7969. utils.ErrorLog(err.Error())
  7970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7971. return
  7972. }
  7973. endTime = theTime.Unix()
  7974. }
  7975. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7976. fmt.Println("schedulelist22222222", schedulelist)
  7977. c.ServeSuccessJSON(map[string]interface{}{
  7978. "list": schedulelist,
  7979. })
  7980. return
  7981. }
  7982. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7983. ids := c.GetString("ids")
  7984. //patient_id, _ := c.GetInt64("patient_id")
  7985. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7986. idArray := strings.Split(ids, ",")
  7987. err := service.BatchDeleteMonitor(idArray)
  7988. fmt.Print("err", err)
  7989. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7990. //redis := service.RedisClient()
  7991. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7992. //redis.Set(key, "", time.Second)
  7993. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7994. //redis.Set(keyOne, "", time.Second)
  7995. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7996. //redis.Close()
  7997. c.ServeSuccessJSON(map[string]interface{}{
  7998. "msg": "批量删除成功",
  7999. })
  8000. return
  8001. }
  8002. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8003. id, _ := c.GetInt64("id")
  8004. timeLayout := "2006-01-02"
  8005. loc, _ := time.LoadLocation("Local")
  8006. //start_time := time.Now().Format("2006-01-02")
  8007. start_time := c.GetString("start_time")
  8008. end_time := c.GetString("end_time")
  8009. var startdateunix int64
  8010. if len(start_time) > 0 {
  8011. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8012. if err != nil {
  8013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8014. return
  8015. }
  8016. startdateunix = theTime.Unix()
  8017. }
  8018. var enddateunix int64
  8019. if len(end_time) > 0 {
  8020. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8021. if err != nil {
  8022. utils.ErrorLog(err.Error())
  8023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8024. return
  8025. }
  8026. enddateunix = theTime.Unix()
  8027. }
  8028. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8029. //nowTime := time.Now()
  8030. //endTime := nowTime.AddDate(-30, 0, 0)
  8031. //endTimes := endTime.Format("2006-01-02")
  8032. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8033. org_id := c.GetMobileAdminUserInfo().Org.Id
  8034. //if org_id == 10579 {
  8035. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8036. // c.ServeSuccessJSON(map[string]interface{}{
  8037. // "list": list,
  8038. // })
  8039. // return
  8040. //} else {
  8041. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8042. // c.ServeSuccessJSON(map[string]interface{}{
  8043. // "list": list,
  8044. // })
  8045. // return
  8046. //}
  8047. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8048. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8049. c.ServeSuccessJSON(map[string]interface{}{
  8050. "list": list,
  8051. })
  8052. return
  8053. } else {
  8054. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8055. c.ServeSuccessJSON(map[string]interface{}{
  8056. "list": list,
  8057. })
  8058. }
  8059. return
  8060. }
  8061. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8062. dataBody := make(map[string]interface{}, 0)
  8063. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8064. ids := c.GetString("ids")
  8065. idArray := strings.Split(ids, ",")
  8066. origin, _ := c.GetInt64("origin")
  8067. if origin == 1 {
  8068. err = service.BatchDeleteAdvice(idArray)
  8069. fmt.Print("err", err)
  8070. c.ServeSuccessJSON(map[string]interface{}{
  8071. "msg": "批量删除成功",
  8072. })
  8073. return
  8074. }
  8075. if origin == 2 {
  8076. service.BatchDeleteHisAdvice(idArray)
  8077. }
  8078. }
  8079. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8080. good_id, _ := c.GetInt64("good_id")
  8081. count, _ := c.GetInt64("count")
  8082. record_time, _ := c.GetInt64("record_time")
  8083. patient_id, _ := c.GetInt64("patient_id")
  8084. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8085. c.ServeSuccessJSON(map[string]interface{}{
  8086. "detail": detail,
  8087. })
  8088. return
  8089. }
  8090. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8091. good_id, _ := c.GetInt64("good_id")
  8092. record_time, _ := c.GetInt64("record_time")
  8093. patient_id, _ := c.GetInt64("patient_id")
  8094. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8095. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8096. fmt.Print("err", err)
  8097. c.ServeSuccessJSON(map[string]interface{}{
  8098. "msg": "批量删除成功",
  8099. })
  8100. return
  8101. }
  8102. func (c *DialysisAPIController) BatchAdviceCheck() {
  8103. ids := c.GetString("ids")
  8104. idArray := strings.Split(ids, ",")
  8105. creator, _ := c.GetInt64("creator")
  8106. origin, _ := c.GetInt64("origin")
  8107. if origin == 1 {
  8108. err := service.BatchAdviceCheck(idArray, creator)
  8109. fmt.Println(err)
  8110. list, _ := service.GetAdviceExecutionById(idArray)
  8111. c.ServeSuccessJSON(map[string]interface{}{
  8112. "list": list,
  8113. })
  8114. return
  8115. }
  8116. if origin == 2 {
  8117. service.BatchHisAdviceCheck(idArray, creator)
  8118. list, _ := service.GetHisAdviceExecutionById(idArray)
  8119. c.ServeSuccessJSON(map[string]interface{}{
  8120. "list": list,
  8121. })
  8122. return
  8123. }
  8124. }
  8125. func (c *DialysisAPIController) BatchAdviceExecution() {
  8126. ids := c.GetString("ids")
  8127. idArray := strings.Split(ids, ",")
  8128. executionTime := c.GetString("execution_time")
  8129. creator, _ := c.GetInt64("creator")
  8130. timeLayout := "2006-01-02 15:04:05"
  8131. loc, _ := time.LoadLocation("Local")
  8132. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8133. orgin, _ := c.GetInt64("origin")
  8134. if orgin == 1 {
  8135. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8136. list, _ := service.GetAdviceExecutionById(idArray)
  8137. fmt.Println(err)
  8138. c.ServeSuccessJSON(map[string]interface{}{
  8139. "list": list,
  8140. })
  8141. return
  8142. }
  8143. if orgin == 2 {
  8144. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8145. list, _ := service.GetHisAdviceExecutionById(idArray)
  8146. fmt.Println(err)
  8147. c.ServeSuccessJSON(map[string]interface{}{
  8148. "list": list,
  8149. })
  8150. return
  8151. }
  8152. }
  8153. func (c *DialysisAPIController) UpdateStockGoods() {
  8154. good_id, _ := c.GetInt64("good_id")
  8155. record_time, _ := c.GetInt64("record_time")
  8156. patient_id, _ := c.GetInt64("patient_id")
  8157. count, _ := c.GetInt64("count")
  8158. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8159. fmt.Print("err", err)
  8160. c.ServeSuccessJSON(map[string]interface{}{
  8161. "msg": "更新成功",
  8162. })
  8163. return
  8164. }
  8165. // 当前数据比上一次出库数据少
  8166. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8167. //查询该患者当天已经出库的耗材信息
  8168. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8169. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8170. for i := len(goods_yc) - 1; i >= 0; i-- {
  8171. goods_yc_temp := goods_yc[i]
  8172. for j := len(goods) - 1; j >= 0; j-- {
  8173. goods_temp := goods[j]
  8174. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8175. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8176. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8177. if goods_yc_temp.Count == goods_temp.Count {
  8178. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8179. goods = append(goods[:j], goods[j+1:]...)
  8180. break
  8181. }
  8182. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8183. if goods_yc_temp.Count > goods_temp.Count {
  8184. temp_count := goods_yc_temp.Count - goods_temp.Count
  8185. goods_yc[i].Count = temp_count
  8186. goods = append(goods[:j], goods[j+1:]...)
  8187. break
  8188. }
  8189. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8190. if goods_yc_temp.Count < goods_temp.Count {
  8191. temp_count := goods_temp.Count - goods_yc_temp.Count
  8192. goods[j].Count = temp_count
  8193. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8194. break
  8195. }
  8196. }
  8197. }
  8198. }
  8199. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8200. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8201. //退库
  8202. if len(goods_yc) > 0 {
  8203. for _, good_yc := range goods_yc {
  8204. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8205. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8206. }
  8207. }
  8208. return nil
  8209. }
  8210. // 耗材出库删除
  8211. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8212. // 先根据相关信息查询当天该耗材的出库信息
  8213. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8214. if err != nil {
  8215. return err
  8216. }
  8217. var delete_count int64 = 0
  8218. delete_count = warehouseOutInfos.Count - count
  8219. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8220. // 在出库记录表里记录退库详情
  8221. warehouseOutInfo := &models.WarehouseOutInfo{
  8222. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8223. WarehouseOutId: warehouseOut.ID,
  8224. Status: 1,
  8225. Ctime: time.Now().Unix(),
  8226. OrgId: orgID,
  8227. Type: 1,
  8228. IsSys: 1,
  8229. SysRecordTime: record_time,
  8230. GoodTypeId: good_yc.GoodTypeId,
  8231. GoodId: good_yc.GoodId,
  8232. PatientId: good_yc.PatientId,
  8233. ConsumableType: 2,
  8234. StorehouseId: houseConfig.StorehouseOutInfo,
  8235. IsCheck: 1,
  8236. }
  8237. warehouseOutInfo.Count = count
  8238. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8239. warehouseOutInfo.Price = stockInInfo.Price
  8240. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8241. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8242. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8243. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8244. warehouseOutInfo.Number = warehouseOutInfos.Number
  8245. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8246. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8247. //查找当天是否存在出库记录
  8248. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8249. if errcod == gorm.ErrRecordNotFound {
  8250. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8251. //插入详情明细表
  8252. stockFlow := models.VmStockFlow{
  8253. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8254. WarehouseOutId: warehouseOut.ID,
  8255. GoodId: good_yc.GoodId,
  8256. Number: warehouseOutInfos.Number,
  8257. ProductDate: stockInInfo.ProductDate,
  8258. ExpireDate: stockInInfo.ExpiryDate,
  8259. Count: count,
  8260. Price: stockInInfo.Price,
  8261. Status: 1,
  8262. Ctime: time.Now().Unix(),
  8263. UserOrgId: good_yc.OrgId,
  8264. Manufacturer: stockInInfo.Manufacturer,
  8265. Dealer: stockInInfo.Dealer,
  8266. LicenseNumber: stockInInfo.LicenseNumber,
  8267. IsEdit: 2,
  8268. Creator: creater,
  8269. SystemTime: record_time,
  8270. ConsumableType: 3,
  8271. WarehousingDetailId: 0,
  8272. IsSys: 1,
  8273. UpdateCreator: creater,
  8274. PatientId: patient_id,
  8275. StorehouseId: houseConfig.StorehouseOutInfo,
  8276. }
  8277. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8278. if errflow == gorm.ErrRecordNotFound {
  8279. //创建流水表
  8280. err := service.CreateStockFlowOne(stockFlow)
  8281. fmt.Println("err", err)
  8282. } else if errflow == nil {
  8283. //插入详情明细表
  8284. stockFlow := models.VmStockFlow{
  8285. ID: exsit.ID,
  8286. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8287. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8288. WarehouseOutId: warehouseOut.ID,
  8289. GoodId: good_yc.GoodId,
  8290. Number: warehouseOutInfos.Number,
  8291. ProductDate: stockInInfo.ProductDate,
  8292. ExpireDate: stockInInfo.ExpiryDate,
  8293. Count: exsit.Count - delete_count,
  8294. Price: stockInInfo.Price,
  8295. Status: 1,
  8296. Ctime: time.Now().Unix(),
  8297. UserOrgId: good_yc.OrgId,
  8298. Manufacturer: stockInInfo.Manufacturer,
  8299. Dealer: stockInInfo.Dealer,
  8300. LicenseNumber: stockInInfo.LicenseNumber,
  8301. IsEdit: 2,
  8302. Creator: creater,
  8303. SystemTime: record_time,
  8304. ConsumableType: 3,
  8305. WarehousingDetailId: 0,
  8306. IsSys: 1,
  8307. UpdateCreator: creater,
  8308. PatientId: patient_id,
  8309. StorehouseId: houseConfig.StorehouseOutInfo,
  8310. }
  8311. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8312. }
  8313. if errOne != nil {
  8314. return errOne
  8315. }
  8316. } else if errcod == nil {
  8317. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8318. //插入详情明细表
  8319. stockFlow := models.VmStockFlow{
  8320. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8321. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8322. WarehouseOutId: warehouseOut.ID,
  8323. GoodId: good_yc.GoodId,
  8324. Number: warehouseOutInfos.Number,
  8325. ProductDate: stockInInfo.ProductDate,
  8326. ExpireDate: stockInInfo.ExpiryDate,
  8327. Count: count,
  8328. Price: stockInInfo.Price,
  8329. Status: 1,
  8330. Ctime: time.Now().Unix(),
  8331. UserOrgId: good_yc.OrgId,
  8332. Manufacturer: stockInInfo.Manufacturer,
  8333. Dealer: stockInInfo.Dealer,
  8334. LicenseNumber: stockInInfo.LicenseNumber,
  8335. IsEdit: 2,
  8336. Creator: creater,
  8337. SystemTime: record_time,
  8338. ConsumableType: 3,
  8339. WarehousingDetailId: 0,
  8340. IsSys: 1,
  8341. UpdateCreator: creater,
  8342. PatientId: patient_id,
  8343. ReturnCount: delete_count,
  8344. StorehouseId: houseConfig.StorehouseOutInfo,
  8345. }
  8346. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8347. if errflows == gorm.ErrRecordNotFound {
  8348. //创建流水表
  8349. service.CreateStockFlowOne(stockFlow)
  8350. } else if errflows == nil {
  8351. stockFlow := models.VmStockFlow{
  8352. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8353. ID: exsit.ID,
  8354. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8355. WarehouseOutId: warehouseOut.ID,
  8356. GoodId: good_yc.GoodId,
  8357. Number: warehouseOutInfos.Number,
  8358. ProductDate: stockInInfo.ProductDate,
  8359. ExpireDate: stockInInfo.ExpiryDate,
  8360. Count: exsit.Count - delete_count,
  8361. Price: stockInInfo.Price,
  8362. Status: 1,
  8363. Ctime: time.Now().Unix(),
  8364. UserOrgId: good_yc.OrgId,
  8365. Manufacturer: stockInInfo.Manufacturer,
  8366. Dealer: stockInInfo.Dealer,
  8367. LicenseNumber: stockInInfo.LicenseNumber,
  8368. IsEdit: 2,
  8369. Creator: creater,
  8370. SystemTime: record_time,
  8371. ConsumableType: 3,
  8372. WarehousingDetailId: 0,
  8373. IsSys: 1,
  8374. UpdateCreator: creater,
  8375. PatientId: patient_id,
  8376. ReturnCount: delete_count,
  8377. StorehouseId: houseConfig.StorehouseOutInfo,
  8378. }
  8379. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8380. }
  8381. }
  8382. //更改自动出库的表格
  8383. details := models.BloodAutomaticReduceDetail{
  8384. WarehouseOutId: warehouseOutInfo.ID,
  8385. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8386. PatientId: patient_id,
  8387. Ctime: time.Now().Unix(),
  8388. Mtime: time.Now().Unix(),
  8389. Status: 1,
  8390. RecordTime: record_time,
  8391. OrgId: orgID,
  8392. GoodId: good_yc.GoodId,
  8393. GoodTypeId: good_yc.GoodTypeId,
  8394. Count: count,
  8395. StorehouseId: houseConfig.StorehouseOutInfo,
  8396. }
  8397. //查询当天耗材是否已经存在数据
  8398. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8399. if errcode == gorm.ErrRecordNotFound {
  8400. errTwo := service.CreateAutoReduceRecord(&details)
  8401. if errTwo != nil {
  8402. return errTwo
  8403. }
  8404. } else if errcode == nil {
  8405. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8406. service.CreateAutoReduceRecord(&details)
  8407. }
  8408. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8409. //增加出库库存数量
  8410. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8411. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8412. fmt.Println("errOne", errOne)
  8413. // 删除出库完成后,要增加对应批次的库存数量
  8414. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8415. if errThree != nil {
  8416. return errThree
  8417. }
  8418. if good_yc.Count == 0 {
  8419. return nil
  8420. } else {
  8421. return errors.New("退库和出库数据不匹配")
  8422. }
  8423. }
  8424. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8425. //查询该患者当天已经出库的耗材信息
  8426. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8427. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8428. for i := len(goods_yc) - 1; i >= 0; i-- {
  8429. goods_yc_temp := goods_yc[i]
  8430. for j := len(goods) - 1; j >= 0; j-- {
  8431. goods_temp := goods[j]
  8432. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8433. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8434. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8435. if goods_yc_temp.Count == goods_temp.Count {
  8436. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8437. goods = append(goods[:j], goods[j+1:]...)
  8438. break
  8439. }
  8440. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8441. if goods_yc_temp.Count > goods_temp.Count {
  8442. temp_count := goods_yc_temp.Count - goods_temp.Count
  8443. goods_yc[i].Count = temp_count
  8444. goods = append(goods[:j], goods[j+1:]...)
  8445. break
  8446. }
  8447. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8448. if goods_yc_temp.Count < goods_temp.Count {
  8449. temp_count := goods_temp.Count - goods_yc_temp.Count
  8450. goods[j].Count = temp_count
  8451. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8452. break
  8453. }
  8454. }
  8455. }
  8456. }
  8457. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8458. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8459. fmt.Println("剩余需要出库的", len(goods))
  8460. if len(goods) > 0 {
  8461. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8462. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8463. if err == gorm.ErrRecordNotFound {
  8464. //没有记录,则创建出库单
  8465. timeStr := time.Now().Format("2006-01-02")
  8466. timeArr := strings.Split(timeStr, "-")
  8467. total, _ := service.FindAllWarehouseOut(orgID)
  8468. total = total + 1
  8469. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8470. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8471. number = number + total
  8472. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8473. warehouseOut := models.WarehouseOut{
  8474. WarehouseOutOrderNumber: warehousing_out_order,
  8475. OperationTime: time.Now().Unix(),
  8476. OrgId: orgID,
  8477. Creater: creater,
  8478. Ctime: time.Now().Unix(),
  8479. Status: 1,
  8480. WarehouseOutTime: record_time,
  8481. Dealer: 0,
  8482. Manufacturer: 0,
  8483. Type: 1,
  8484. IsSys: 1,
  8485. StorehouseId: houseConfig.StorehouseOutInfo,
  8486. IsCheck: 1,
  8487. }
  8488. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  8489. if err != nil {
  8490. utils.TraceLog("创建出库单失败 err = %v", err)
  8491. return err
  8492. } else {
  8493. out = warehouseOut
  8494. }
  8495. }
  8496. for _, item := range goods {
  8497. var newCount int64 = 0
  8498. for _, it := range goodOne {
  8499. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8500. newCount = it.Count
  8501. }
  8502. }
  8503. prepare := models.DialysisBeforePrepare{
  8504. GoodTypeId: item.GoodTypeId,
  8505. GoodId: item.GoodId,
  8506. Count: item.Count,
  8507. StorehouseId: houseConfig.StorehouseOutInfo,
  8508. }
  8509. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8510. //增加出库数量
  8511. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8512. }
  8513. }
  8514. if len(goods_yc) > 0 {
  8515. for _, good_yc := range goods_yc {
  8516. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8517. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8518. }
  8519. }
  8520. return nil
  8521. }
  8522. // 耗材出库删除
  8523. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8524. // 先根据相关信息查询当天该耗材的出库信息
  8525. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8526. if err != nil {
  8527. return err
  8528. }
  8529. var delete_count int64 = 0
  8530. for _, ware := range warehouseOutInfos {
  8531. // 判断当前出库的数据和删除出库数量
  8532. if good_yc.Count <= ware.Count {
  8533. delete_count = good_yc.Count
  8534. } else {
  8535. delete_count = ware.Count
  8536. }
  8537. warehouseOutInfo := &models.WarehouseOutInfo{
  8538. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8539. WarehouseOutId: warehouseOut.ID,
  8540. Status: 1,
  8541. Ctime: time.Now().Unix(),
  8542. Remark: "",
  8543. OrgId: orgID,
  8544. Type: 1,
  8545. Manufacturer: 0,
  8546. Dealer: 0,
  8547. IsSys: 0,
  8548. SysRecordTime: record_time,
  8549. GoodTypeId: good_yc.GoodTypeId,
  8550. GoodId: good_yc.GoodId,
  8551. StorehouseId: warehouseOut.StorehouseId,
  8552. IsCheck: 1,
  8553. }
  8554. warehouseOutInfo.Count = delete_count
  8555. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8556. warehouseOutInfo.Price = stockInInfo.Price
  8557. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8558. if errOne != nil {
  8559. return errOne
  8560. }
  8561. // 删除出库完成后,要改变流水库存(有疑问)
  8562. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8563. fmt.Println("errOne", errOne)
  8564. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8565. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8566. //扣减出库数量
  8567. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8568. if errThree != nil {
  8569. return errThree
  8570. }
  8571. }
  8572. if good_yc.Count == 0 {
  8573. return nil
  8574. } else {
  8575. return errors.New("退库和出库数据不匹配")
  8576. }
  8577. }
  8578. func (this *DialysisAPIController) GetMobileScheduleList() {
  8579. limit, _ := this.GetInt64("limit")
  8580. page, _ := this.GetInt64("page")
  8581. type_options_visible, _ := this.GetInt64("type_options_visible")
  8582. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8583. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8584. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8585. }
  8586. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8587. newArr = make([]*models.HisPrescriptionProject, 0)
  8588. for i := 0; i < len(arr); i++ {
  8589. repeat := false
  8590. for j := i + 1; j < len(arr); j++ {
  8591. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8592. repeat = true
  8593. break
  8594. }
  8595. }
  8596. if !repeat {
  8597. newArr = append(newArr, arr[i])
  8598. }
  8599. }
  8600. return
  8601. }
  8602. func (this *DialysisAPIController) GetRoleList() {
  8603. admin_user_id, _ := this.GetInt64("admin_user_id")
  8604. orgid := this.GetMobileAdminUserInfo().Org.Id
  8605. list, err := service.GetRoleList(orgid, admin_user_id)
  8606. fmt.Println(err)
  8607. this.ServeSuccessJSON(map[string]interface{}{
  8608. "list": list,
  8609. })
  8610. return
  8611. }
  8612. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8613. // 先根据相关信息查询当天该耗材的出库信息
  8614. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8615. if err != nil {
  8616. return err
  8617. }
  8618. var delete_count int64 = 0
  8619. delete_count = warehouseOutInfos.Count - count
  8620. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8621. // 删除出库完成后,要增加对应批次的库存数量
  8622. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8623. if errThree != nil {
  8624. return errThree
  8625. }
  8626. //增加退库数量
  8627. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8628. //扣减出库数量
  8629. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8630. //查询剩余库存
  8631. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8632. var sum_count int64
  8633. for _, item := range goodList {
  8634. sum_count += item.StockCount
  8635. }
  8636. // 在出库记录表里记录退库详情
  8637. warehouseOutInfo := &models.WarehouseOutInfo{
  8638. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8639. WarehouseOutId: warehouseOut.ID,
  8640. Status: 1,
  8641. Ctime: time.Now().Unix(),
  8642. OrgId: orgID,
  8643. Type: 1,
  8644. IsSys: 1,
  8645. SysRecordTime: record_time,
  8646. GoodTypeId: good_yc.GoodTypeId,
  8647. GoodId: good_yc.GoodId,
  8648. PatientId: good_yc.PatientId,
  8649. ConsumableType: 2,
  8650. StorehouseId: houseConfig.StorehouseOutInfo,
  8651. IsCheck: 1,
  8652. OverCount: sum_count,
  8653. }
  8654. warehouseOutInfo.Count = count
  8655. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8656. warehouseOutInfo.Price = stockInInfo.Price
  8657. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8658. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8659. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8660. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8661. warehouseOutInfo.Number = warehouseOutInfos.Number
  8662. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8663. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8664. //查找当天是否存在出库记录
  8665. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8666. if errcod == gorm.ErrRecordNotFound {
  8667. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8668. //插入详情明细表
  8669. if errOne != nil {
  8670. return errOne
  8671. }
  8672. //插入详情明细表
  8673. stockFlow := models.VmStockFlow{
  8674. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8675. WarehouseOutId: warehouseOut.ID,
  8676. GoodId: good_yc.GoodId,
  8677. Number: warehouseOutInfos.Number,
  8678. ProductDate: stockInInfo.ProductDate,
  8679. ExpireDate: stockInInfo.ExpiryDate,
  8680. Count: count,
  8681. Price: stockInInfo.Price,
  8682. Status: 1,
  8683. Ctime: record_time,
  8684. UserOrgId: good_yc.OrgId,
  8685. Manufacturer: stockInInfo.Manufacturer,
  8686. Dealer: stockInInfo.Dealer,
  8687. LicenseNumber: stockInInfo.LicenseNumber,
  8688. IsEdit: 2,
  8689. Creator: creater,
  8690. SystemTime: record_time,
  8691. ConsumableType: 3,
  8692. WarehousingDetailId: 0,
  8693. IsSys: 1,
  8694. UpdateCreator: creater,
  8695. PatientId: patient_id,
  8696. StorehouseId: houseConfig.StorehouseOutInfo,
  8697. OverCount: sum_count,
  8698. ProjectId: good_yc.ProjectId,
  8699. }
  8700. err := service.CreateStockFlowOne(stockFlow)
  8701. fmt.Println("err", err)
  8702. } else if errcod == nil {
  8703. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8704. }
  8705. //创建退库单
  8706. operation_time := time.Now().Unix()
  8707. //创建退库单
  8708. timeStr := time.Now().Format("2006-01-02")
  8709. timeArr := strings.Split(timeStr, "-")
  8710. total, _ := service.FindAllCancelStockTotal(orgID)
  8711. total = total + 1
  8712. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8713. cancelStock := models.CancelStock{
  8714. OrderNumber: orderNumber,
  8715. OperaTime: operation_time,
  8716. OrgId: orgID,
  8717. Creater: warehouseOut.Creater,
  8718. Ctime: time.Now().Unix(),
  8719. Status: 1,
  8720. ReturnTime: record_time,
  8721. Type: 1,
  8722. StorehouseId: stockInInfo.StorehouseId,
  8723. IsCheck: 1,
  8724. }
  8725. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8726. if msgerrkonde == gorm.ErrRecordNotFound {
  8727. service.AddSigleCancelStock(&cancelStock)
  8728. }
  8729. cancel, _ := service.GetLastCancelStockById(orgID)
  8730. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8731. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8732. cancelStockInfo := models.CancelStockInfo{
  8733. GoodId: stockInInfo.GoodId,
  8734. CancelStockId: cancel.ID,
  8735. GoodTypeId: stockInInfo.GoodTypeId,
  8736. Count: delete_count,
  8737. Price: stockInInfo.PackingPrice,
  8738. Total: 0,
  8739. ProductDate: stockInInfo.ProductDate,
  8740. ExpiryDate: stockInInfo.ExpiryDate,
  8741. Ctime: record_time,
  8742. Status: 1,
  8743. OrgId: orgID,
  8744. OrderNumber: cancel.OrderNumber,
  8745. Type: 0,
  8746. Dealer: deaerler.DealerName,
  8747. Manufacturer: manufacturer.ManufacturerName,
  8748. Number: stockInInfo.Number,
  8749. RegisterAccount: "",
  8750. Remark: "",
  8751. WarehouseInfoId: stockInInfo.ID,
  8752. PatientId: patient_id,
  8753. RecordDate: record_time,
  8754. StorehouseId: stockInInfo.StorehouseId,
  8755. IsCheck: 1,
  8756. }
  8757. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8758. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8759. flow := models.VmStockFlow{
  8760. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8761. GoodId: good_yc.GoodId,
  8762. Number: warehouseOutInfos.Number,
  8763. LicenseNumber: stockInInfo.LicenseNumber,
  8764. Count: delete_count,
  8765. UserOrgId: orgID,
  8766. PatientId: patient_id,
  8767. SystemTime: record_time,
  8768. ConsumableType: 7,
  8769. IsSys: 0,
  8770. WarehousingOrder: "",
  8771. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8772. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8773. IsEdit: 0,
  8774. CancelStockId: cancel.ID,
  8775. CancelOrderNumber: cancel.OrderNumber,
  8776. Manufacturer: manufacturer.ID,
  8777. Dealer: 0,
  8778. Creator: warehouseOut.Creater,
  8779. UpdateCreator: 0,
  8780. Status: 1,
  8781. Ctime: record_time,
  8782. Mtime: 0,
  8783. Price: stockInInfo.Price,
  8784. WarehousingDetailId: stockInInfo.ID,
  8785. WarehouseOutDetailId: warehouseOutInfos.ID,
  8786. CancelOutDetailId: cancelInfo.ID,
  8787. ProductDate: stockInInfo.ProductDate,
  8788. ExpireDate: stockInInfo.ExpiryDate,
  8789. StorehouseId: houseConfig.StorehouseOutInfo,
  8790. OverCount: sum_count,
  8791. }
  8792. service.CreateStockFlowOne(flow)
  8793. //更改自动出库的表格
  8794. details := models.BloodAutomaticReduceDetail{
  8795. WarehouseOutId: warehouseOutInfo.ID,
  8796. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8797. PatientId: patient_id,
  8798. Ctime: time.Now().Unix(),
  8799. Mtime: time.Now().Unix(),
  8800. Status: 1,
  8801. RecordTime: record_time,
  8802. OrgId: orgID,
  8803. GoodId: good_yc.GoodId,
  8804. GoodTypeId: good_yc.GoodTypeId,
  8805. Count: count,
  8806. StorehouseId: houseConfig.StorehouseOutInfo,
  8807. }
  8808. //查询当天耗材是否已经存在数据
  8809. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8810. if errcode == gorm.ErrRecordNotFound {
  8811. errTwo := service.CreateAutoReduceRecord(&details)
  8812. if errTwo != nil {
  8813. return errTwo
  8814. }
  8815. } else if errcode == nil {
  8816. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8817. service.CreateAutoReduceRecord(&details)
  8818. }
  8819. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8820. //增加出库库存数量
  8821. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8822. if good_yc.Count == 0 {
  8823. return nil
  8824. } else {
  8825. return errors.New("退库和出库数据不匹配")
  8826. }
  8827. }
  8828. func (this *DialysisAPIController) SavePatientSign() {
  8829. adminUserInfo := this.GetMobileAdminUserInfo()
  8830. patient_id, _ := this.GetInt64("patient_id")
  8831. dialysis_date, _ := this.GetInt64("dialysis_date")
  8832. orgid := adminUserInfo.Org.Id
  8833. var esdata models.DialysisOrder
  8834. var err error
  8835. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8837. return
  8838. }
  8839. esdata.Hash = esdata.Hash
  8840. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8841. order := models.DialysisOrder{
  8842. Hash: esdata.Hash,
  8843. Url: esdata.Url,
  8844. }
  8845. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8846. redis := service.RedisClient()
  8847. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8848. redis.Set(key, "", time.Second)
  8849. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8850. //清空key 值
  8851. redis.Set(keyOne, "", time.Second)
  8852. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8853. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8854. //redis.Set(keyTwo, "", time.Second)
  8855. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8856. redis.Set(keyThree, "", time.Second)
  8857. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8858. redis.Set(keyFour, "", time.Second)
  8859. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8860. redis.Set(keyFive, "", time.Second)
  8861. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8862. redis.Set(keySix, "", time.Second)
  8863. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8864. redis.Set(keySeven, "", time.Second)
  8865. if err != nil {
  8866. fmt.Println(err)
  8867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8868. return
  8869. }
  8870. this.ServeSuccessJSON(map[string]interface{}{
  8871. "electronic_signature": esdata,
  8872. })
  8873. }
  8874. func (this *DialysisAPIController) GetPatientSign() {
  8875. patient_id, _ := this.GetInt64("patient_id")
  8876. dialysis_date, _ := this.GetInt64("dialysis_date")
  8877. adminUserInfo := this.GetMobileAdminUserInfo()
  8878. orgId := adminUserInfo.Org.Id
  8879. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8880. if err != nil {
  8881. fmt.Println(err)
  8882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8883. return
  8884. }
  8885. this.ServeSuccessJSON(map[string]interface{}{
  8886. "dialysisOrder": dialysisOrder,
  8887. })
  8888. }
  8889. func (this *DialysisAPIController) GetScheduleByPatient() {
  8890. patient_id, _ := this.GetInt64("patient_id")
  8891. schedule_date, _ := this.GetInt64("schedule_date")
  8892. orgid := this.GetMobileAdminUserInfo().Org.Id
  8893. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8894. this.ServeSuccessJSON(map[string]interface{}{
  8895. "schedule": schedule,
  8896. })
  8897. }
  8898. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8899. org_id := this.GetMobileAdminUserInfo().Org.Id
  8900. patient_id, _ := this.GetInt64("patient_id")
  8901. schedule_date, _ := this.GetInt64("schedule_date")
  8902. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8903. this.ServeSuccessJSON(map[string]interface{}{
  8904. "order": order,
  8905. })
  8906. }
  8907. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8908. org_id := this.GetMobileAdminUserInfo().Org.Id
  8909. schedule_date := this.GetString("schedule_date")
  8910. schedule_type, _ := this.GetInt64("schedule_type")
  8911. timeLayout := "2006-01-02"
  8912. loc, _ := time.LoadLocation("Local")
  8913. var startdateunix int64
  8914. if len(schedule_date) > 0 {
  8915. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8916. if err != nil {
  8917. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8918. return
  8919. }
  8920. startdateunix = theTime.Unix()
  8921. }
  8922. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8923. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8924. devices, _ := service.GetAllDevicetByListSix(org_id)
  8925. for key, item := range scheduals {
  8926. // 床位信息
  8927. for _, device := range devices {
  8928. if item.BedId == device.ID {
  8929. scheduals[key].DeviceNumber = device
  8930. break
  8931. }
  8932. }
  8933. }
  8934. this.ServeSuccessJSON(map[string]interface{}{
  8935. "list": list,
  8936. "scheduals": scheduals,
  8937. })
  8938. }
  8939. func (this *DialysisAPIController) SavePatientPicture() {
  8940. patient_id, _ := this.GetInt64("patient_id")
  8941. dialysis_date, _ := this.GetInt64("schedule_date")
  8942. avatar := this.GetString("avatar")
  8943. fmt.Println("patient_id", patient_id)
  8944. orgId := this.GetMobileAdminUserInfo().Org.Id
  8945. order := models.DialysisOrder{
  8946. Url: avatar,
  8947. }
  8948. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8949. redis := service.RedisClient()
  8950. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8951. redis.Set(key, "", time.Second)
  8952. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8953. //清空key 值
  8954. redis.Set(keyOne, "", time.Second)
  8955. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8956. redis.Set(keyThree, "", time.Second)
  8957. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8958. redis.Set(keyFour, "", time.Second)
  8959. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8960. redis.Set(keyFive, "", time.Second)
  8961. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8962. redis.Set(keySix, "", time.Second)
  8963. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8964. redis.Set(keySeven, "", time.Second)
  8965. if err != nil {
  8966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8967. return
  8968. }
  8969. this.ServeSuccessJSON(map[string]interface{}{
  8970. "order": order,
  8971. })
  8972. }
  8973. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8974. ids := this.GetString("ids")
  8975. idSplit := strings.Split(ids, ",")
  8976. orgId := this.GetMobileAdminUserInfo().Org.Id
  8977. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8978. execution_time := this.GetString("exce_time")
  8979. timeLayout2 := "2006-01-02 15:04:05"
  8980. loc, _ := time.LoadLocation("Local")
  8981. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8982. if errs != nil {
  8983. utils.ErrorLog(errs.Error())
  8984. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8985. return
  8986. }
  8987. //his客户
  8988. if config.IsOpen == 1 {
  8989. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8990. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8991. for _, item := range list {
  8992. for _, it := range adviceList {
  8993. if item.DrugId == it.DrugId {
  8994. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8995. }
  8996. }
  8997. }
  8998. for _, item := range list {
  8999. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9000. var sum_out_count int64
  9001. for _, itemThree := range item.ChildDoctorAdvice {
  9002. var prescribing_number int64
  9003. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9004. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9005. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9006. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9007. }
  9008. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9009. prescribing_number = parseIntPrescribingNumber
  9010. }
  9011. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9012. prescribing_number = parseIntPrescribingNumber
  9013. }
  9014. sum_out_count += prescribing_number
  9015. }
  9016. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9017. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9018. //库存不足
  9019. if sum_out_count > drugStockOut.FlushCount {
  9020. this.ServeSuccessJSON(map[string]interface{}{
  9021. "msg": "2",
  9022. "drug": medical,
  9023. "ids": ids,
  9024. })
  9025. return
  9026. }
  9027. }
  9028. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9029. //执行医嘱
  9030. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9031. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9032. for _, item := range advices {
  9033. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9034. redis := service.RedisClient()
  9035. //清空key 值
  9036. redis.Set(key, "", time.Second)
  9037. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9038. redis.Set(keyTwo, "", time.Second)
  9039. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9040. redis.Set(keyThree, "", time.Second)
  9041. recordDate := theTime.Format("2006-01-02")
  9042. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9043. redis.Set(keyFour, "", time.Second)
  9044. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9045. redis.Set(keyFive, "", time.Second)
  9046. defer redis.Close()
  9047. }
  9048. if errs == nil {
  9049. //药品管理信息
  9050. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9051. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9052. if drugStockConfig.IsOpen == 1 {
  9053. for _, item := range advices {
  9054. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9055. config, _ := service.GetDrugOpenConfigOne(orgId)
  9056. if config.IsOpen != 1 {
  9057. //查询该药品是否有库存
  9058. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9059. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9060. if medical.IsUse == 2 {
  9061. if config.IsOpen != 1 {
  9062. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9063. service.HisDrugsDelivery(orgId, creater, &advice)
  9064. if orgId == 3877 || orgId == 10265 {
  9065. //查询该药品是否有出库记录
  9066. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9067. if len(flowMap) == 0 {
  9068. errs := service.UpdateHisAdviceById(advice.ID)
  9069. if errs != nil {
  9070. drugError := models.XtDrugError{
  9071. UserOrgId: orgId,
  9072. DrugId: item.DrugId,
  9073. RecordDate: item.AdviceDate,
  9074. PatientId: item.PatientId,
  9075. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9076. Status: 1,
  9077. Ctime: time.Now().Unix(),
  9078. Mtime: 0,
  9079. SumCount: 0,
  9080. Prescribingnumber: advice.PrescribingNumber,
  9081. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9082. }
  9083. service.CreateDrugError(drugError)
  9084. }
  9085. this.ServeSuccessJSON(map[string]interface{}{
  9086. "msg": "2",
  9087. "drug": medical,
  9088. "ids": ids,
  9089. })
  9090. return
  9091. }
  9092. }
  9093. }
  9094. if pharmacyConfig.IsOpen != 1 {
  9095. service.HisDrugsDelivery(orgId, creater, &advice)
  9096. if orgId == 3877 || orgId == 10265 {
  9097. //查询该药品是否有出库记录
  9098. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9099. if len(flowMap) == 0 {
  9100. errs := service.UpdateHisAdviceById(advice.ID)
  9101. if errs != nil {
  9102. drugError := models.XtDrugError{
  9103. UserOrgId: orgId,
  9104. DrugId: item.DrugId,
  9105. RecordDate: item.AdviceDate,
  9106. PatientId: item.PatientId,
  9107. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9108. Status: 1,
  9109. Ctime: time.Now().Unix(),
  9110. Mtime: 0,
  9111. SumCount: 0,
  9112. Prescribingnumber: advice.PrescribingNumber,
  9113. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9114. }
  9115. service.CreateDrugError(drugError)
  9116. }
  9117. this.ServeSuccessJSON(map[string]interface{}{
  9118. "msg": "2",
  9119. "drug": medical,
  9120. "ids": ids,
  9121. })
  9122. return
  9123. }
  9124. }
  9125. }
  9126. //更新字典里面的库存
  9127. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9128. var sum_count int64
  9129. for _, its := range stockInfo {
  9130. if its.MaxUnit == medical.MaxUnit {
  9131. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9132. }
  9133. sum_count += its.StockMaxNumber + its.StockMinNumber
  9134. }
  9135. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9136. //剩余库存
  9137. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9138. }
  9139. }
  9140. }
  9141. }
  9142. }
  9143. this.ServeSuccessJSON(map[string]interface{}{
  9144. "msg": "1",
  9145. "ids": ids,
  9146. })
  9147. return
  9148. } else {
  9149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9150. }
  9151. }
  9152. //血透客户
  9153. if config.IsOpen == 2 || config.IsOpen == 0 {
  9154. //药品管理信息
  9155. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9156. if drugStockConfig.IsOpen == 1 {
  9157. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9158. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9159. for _, item := range list {
  9160. for _, it := range adviceList {
  9161. if item.DrugId == it.DrugId {
  9162. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9163. }
  9164. }
  9165. }
  9166. for _, item := range list {
  9167. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9168. var sum_out_count int64
  9169. for _, itemThree := range item.ChildDoctorAdvice {
  9170. var prescribing_number int64
  9171. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9172. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9173. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9174. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9175. }
  9176. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9177. prescribing_number = parseIntPrescribingNumber
  9178. }
  9179. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9180. prescribing_number = parseIntPrescribingNumber
  9181. }
  9182. sum_out_count += prescribing_number
  9183. }
  9184. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9185. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9186. //库存不足
  9187. if sum_out_count > drugStockOut.FlushCount {
  9188. this.ServeSuccessJSON(map[string]interface{}{
  9189. "msg": "2",
  9190. "drug": medical,
  9191. "ids": ids,
  9192. })
  9193. return
  9194. }
  9195. }
  9196. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9197. //执行医嘱
  9198. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9199. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9200. for _, item := range advices {
  9201. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9202. redis := service.RedisClient()
  9203. //清空key 值
  9204. redis.Set(key, "", time.Second)
  9205. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9206. redis.Set(keyTwo, "", time.Second)
  9207. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9208. redis.Set(keyThree, "", time.Second)
  9209. recordDate := theTime.Format("2006-01-02")
  9210. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9211. redis.Set(keyFour, "", time.Second)
  9212. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9213. redis.Set(keyFive, "", time.Second)
  9214. defer redis.Close()
  9215. }
  9216. if errs == nil {
  9217. for _, item := range advices {
  9218. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9219. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9220. //查询是否出库按钮开启
  9221. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9222. if adviceSetting.IsAdviceOpen == 1 {
  9223. //查询是否出库按钮开启
  9224. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9225. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9226. if prescriptionConfig.IsOpen == 1 {
  9227. if medical.IsUse == 2 {
  9228. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9229. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9230. }
  9231. if pharmacyConfig.IsOpen != 1 {
  9232. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9233. }
  9234. //更新字典里面的库存
  9235. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9236. var sum_count int64
  9237. for _, its := range stockInfo {
  9238. if its.MaxUnit == medical.MaxUnit {
  9239. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9240. }
  9241. sum_count += its.StockMaxNumber + its.StockMinNumber
  9242. }
  9243. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9244. //剩余库存
  9245. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9246. }
  9247. }
  9248. } else {
  9249. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9250. if medical.IsUse == 2 {
  9251. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9252. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9253. }
  9254. if pharmacyConfig.IsOpen != 1 {
  9255. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9256. }
  9257. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9258. var sum_count int64
  9259. for _, its := range stockInfo {
  9260. if its.MaxUnit == medical.MaxUnit {
  9261. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9262. }
  9263. sum_count += its.StockMaxNumber + its.StockMinNumber
  9264. }
  9265. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9266. //剩余库存
  9267. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9268. }
  9269. }
  9270. }
  9271. }
  9272. this.ServeSuccessJSON(map[string]interface{}{
  9273. "msg": "1",
  9274. "ids": ids,
  9275. })
  9276. return
  9277. } else {
  9278. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9279. //执行医嘱
  9280. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9281. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9282. for _, item := range advices {
  9283. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9284. redis := service.RedisClient()
  9285. //清空key 值
  9286. redis.Set(key, "", time.Second)
  9287. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9288. redis.Set(keyTwo, "", time.Second)
  9289. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9290. redis.Set(keyThree, "", time.Second)
  9291. recordDate := theTime.Format("2006-01-02")
  9292. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9293. redis.Set(keyFour, "", time.Second)
  9294. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9295. redis.Set(keyFive, "", time.Second)
  9296. defer redis.Close()
  9297. }
  9298. this.ServeSuccessJSON(map[string]interface{}{
  9299. "msg": "1",
  9300. "ids": ids,
  9301. })
  9302. return
  9303. }
  9304. }
  9305. }
  9306. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9307. ids := this.GetString("ids")
  9308. idSplit := strings.Split(ids, ",")
  9309. orgId := this.GetMobileAdminUserInfo().Org.Id
  9310. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9311. if config.IsOpen == 1 {
  9312. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9313. this.ServeSuccessJSON(map[string]interface{}{
  9314. "msg": "1",
  9315. "ids": ids,
  9316. })
  9317. return
  9318. }
  9319. if config.IsOpen == 0 || config.IsOpen == 2 {
  9320. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9321. this.ServeSuccessJSON(map[string]interface{}{
  9322. "msg": "1",
  9323. "ids": ids,
  9324. })
  9325. return
  9326. }
  9327. }
  9328. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9329. ids := this.GetString("ids")
  9330. idSplit := strings.Split(ids, ",")
  9331. orgId := this.GetMobileAdminUserInfo().Org.Id
  9332. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9333. //his
  9334. if config.IsOpen == 1 {
  9335. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9336. theTime := time.Now()
  9337. advices := models.HisDoctorAdviceThirty{
  9338. CheckTime: theTime.Unix(),
  9339. Checker: checker,
  9340. UpdatedTime: time.Now().Unix(),
  9341. }
  9342. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9343. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9344. for _, item := range list {
  9345. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9346. redis := service.RedisClient()
  9347. //清空key 值
  9348. redis.Set(key, "", time.Second)
  9349. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9350. redis.Set(keyTwo, "", time.Second)
  9351. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9352. redis.Set(keyThree, "", time.Second)
  9353. recordDate := theTime.Format("2006-01-02")
  9354. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9355. redis.Set(keyFour, "", time.Second)
  9356. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9357. redis.Set(keyFive, "", time.Second)
  9358. defer redis.Close()
  9359. }
  9360. this.ServeSuccessJSON(map[string]interface{}{
  9361. "msg": "1",
  9362. "ids": ids,
  9363. })
  9364. return
  9365. }
  9366. //血透
  9367. if config.IsOpen == 0 || config.IsOpen == 2 {
  9368. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9369. theTime := time.Now()
  9370. advices := models.DoctorAdvice{
  9371. CheckTime: theTime.Unix(),
  9372. Checker: checker,
  9373. UpdatedTime: time.Now().Unix(),
  9374. }
  9375. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9376. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9377. for _, item := range list {
  9378. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9379. redis := service.RedisClient()
  9380. //清空key 值
  9381. redis.Set(key, "", time.Second)
  9382. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9383. redis.Set(keyTwo, "", time.Second)
  9384. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9385. redis.Set(keyThree, "", time.Second)
  9386. recordDate := theTime.Format("2006-01-02")
  9387. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9388. redis.Set(keyFour, "", time.Second)
  9389. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9390. redis.Set(keyFive, "", time.Second)
  9391. defer redis.Close()
  9392. }
  9393. this.ServeSuccessJSON(map[string]interface{}{
  9394. "msg": "1",
  9395. "ids": ids,
  9396. })
  9397. return
  9398. }
  9399. }
  9400. func (this *DialysisAPIController) CheckSchedule() {
  9401. patientID, _ := this.GetInt64("patient_id")
  9402. recordDateStr := this.GetString("record_date")
  9403. nurseID, _ := this.GetInt64("start_nurse")
  9404. schedual_type, _ := this.GetInt64("schedual_type")
  9405. bedID, _ := this.GetInt64("bed")
  9406. start_time := this.GetString("start_time")
  9407. fmt.Println("patientID", patientID)
  9408. fmt.Println("recordDateStr", recordDateStr)
  9409. fmt.Println("nurseID", nurseID)
  9410. fmt.Println("schedual_type------", schedual_type)
  9411. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9413. return
  9414. }
  9415. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9416. if parseStartDateErr != nil {
  9417. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9419. return
  9420. }
  9421. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9422. if parseErr != nil {
  9423. this.ErrorLog("时间解析失败:%v", parseErr)
  9424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9425. return
  9426. }
  9427. adminUserInfo := this.GetMobileAdminUserInfo()
  9428. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9429. if getPatientErr != nil {
  9430. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9432. return
  9433. } else if patient == nil {
  9434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9435. return
  9436. }
  9437. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9438. if getNurseErr != nil {
  9439. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9440. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9441. return
  9442. } else if nurse == nil {
  9443. this.ErrorLog("护士不存在")
  9444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9445. return
  9446. }
  9447. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9448. if getDeviceNumberErr != nil {
  9449. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9450. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9451. return
  9452. } else if deviceNumber == nil {
  9453. this.ErrorLog("床位号不存在")
  9454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9455. return
  9456. }
  9457. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9458. if getRecordErr != nil {
  9459. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9460. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9461. return
  9462. } else if dialysisRecord != nil {
  9463. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9464. return
  9465. }
  9466. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9467. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9468. timeLayout := "2006-01-02 15:04:05"
  9469. loc, _ := time.LoadLocation("Local")
  9470. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9471. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9472. schedulestartTime := theStartTime.Unix()
  9473. scheduleendTime := theEndTime.Unix()
  9474. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9475. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9476. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9477. //查询该床位是否有人用了
  9478. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9479. if err == nil {
  9480. if schedule.ID == 0 {
  9481. this.ServeSuccessJSON(map[string]interface{}{
  9482. "status": 0,
  9483. "msg": "请求失败",
  9484. })
  9485. } else {
  9486. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9487. if order.ID > 0 { //该机位被其他人占用了
  9488. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9489. return
  9490. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9491. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9492. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9493. this.ServeSuccessJSON(map[string]interface{}{
  9494. "status": 1,
  9495. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9496. })
  9497. return
  9498. } else {
  9499. this.ServeSuccessJSON(map[string]interface{}{
  9500. "status": 0,
  9501. "msg": "",
  9502. })
  9503. }
  9504. }
  9505. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9506. this.ServeSuccessJSON(map[string]interface{}{
  9507. "status": 2,
  9508. "msg": "当前机位已有患者在使用,请重新选择!",
  9509. })
  9510. }
  9511. }
  9512. } else {
  9513. this.ServeSuccessJSON(map[string]interface{}{
  9514. "status": 0,
  9515. "msg": "",
  9516. })
  9517. }
  9518. }
  9519. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9520. orgId := this.GetMobileAdminUserInfo().Org.Id
  9521. schedule_type, _ := this.GetInt64("schedule_type")
  9522. partion_type, _ := this.GetInt64("partion_type")
  9523. start_time := this.GetString("start_time")
  9524. timeLayout := "2006-01-02"
  9525. loc, _ := time.LoadLocation("Local")
  9526. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9527. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9528. _, config := service.FindXTHisRecordByOrgId(orgId)
  9529. appId := this.GetMobileAdminUserInfo().App.Id
  9530. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9531. if err == nil {
  9532. this.ServeSuccessJSON(map[string]interface{}{
  9533. "list": list,
  9534. "config": config,
  9535. "doctorList": doctorList,
  9536. })
  9537. return
  9538. } else {
  9539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9540. return
  9541. }
  9542. }
  9543. func (this *DialysisAPIController) SaveMobileInformation() {
  9544. patient_id, _ := this.GetInt64("patient_id")
  9545. record_date, _ := this.GetInt64("record_date")
  9546. startTime := this.GetString("start_time")
  9547. module, _ := this.GetInt64("module")
  9548. remark := this.GetString("remark")
  9549. timeLayout := "2006-01-02 15:04"
  9550. loc, _ := time.LoadLocation("Local")
  9551. if len(startTime) == 0 {
  9552. utils.ErrorLog("len(start_time) == 0")
  9553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9554. return
  9555. }
  9556. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9557. if err != nil {
  9558. utils.ErrorLog(err.Error())
  9559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9560. return
  9561. }
  9562. StartTime := theTime.Unix()
  9563. fmt.Println("startime-------------", StartTime)
  9564. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9565. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9566. information := models.XtDialysisInformation{
  9567. Module: module,
  9568. PatientId: patient_id,
  9569. RecordDate: record_date,
  9570. ApplicationDate: StartTime,
  9571. Creater: creater,
  9572. ApplicationStatus: 2,
  9573. Checker: 0,
  9574. CheckTime: 0,
  9575. Remark: remark,
  9576. UserOrgId: user_org_id,
  9577. Ctime: time.Now().Unix(),
  9578. Status: 1,
  9579. Mtime: 0,
  9580. }
  9581. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9582. if infor.ID == 0 {
  9583. service.SaveDialysisInformation(information)
  9584. }
  9585. if infor.ID > 0 {
  9586. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9587. }
  9588. this.ServeSuccessJSON(map[string]interface{}{
  9589. "information": information,
  9590. })
  9591. return
  9592. }
  9593. func (this *DialysisAPIController) GetMobileInformation() {
  9594. limit, _ := this.GetInt64("limit")
  9595. page, _ := this.GetInt64("page")
  9596. orgid := this.GetMobileAdminUserInfo().Org.Id
  9597. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9598. appid := this.GetMobileAdminUserInfo().App.Id
  9599. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9600. patients, _ := service.GetAllpatientThirty(orgid)
  9601. this.ServeSuccessJSON(map[string]interface{}{
  9602. "information": information,
  9603. "total": total,
  9604. "doclist": doclist,
  9605. "patients": patients,
  9606. })
  9607. return
  9608. }
  9609. func (this *DialysisAPIController) GetMobileInformationOne() {
  9610. limit, _ := this.GetInt64("limit")
  9611. page, _ := this.GetInt64("page")
  9612. orgid := this.GetMobileAdminUserInfo().Org.Id
  9613. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9614. appid := this.GetMobileAdminUserInfo().App.Id
  9615. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9616. patients, _ := service.GetAllpatientThirty(orgid)
  9617. this.ServeSuccessJSON(map[string]interface{}{
  9618. "information": information,
  9619. "total": total,
  9620. "doclist": doclist,
  9621. "patients": patients,
  9622. })
  9623. return
  9624. }
  9625. func (this *DialysisAPIController) CheckMobileInformation() {
  9626. id, _ := this.GetInt64("id")
  9627. application_status, _ := this.GetInt64("application_status")
  9628. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9629. checktime := time.Now().Unix()
  9630. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9631. if err == nil {
  9632. this.ServeSuccessJSON(map[string]interface{}{
  9633. "msg": "ok",
  9634. })
  9635. return
  9636. }
  9637. }
  9638. func (c *DialysisAPIController) GetControlMonitorList() {
  9639. partition, _ := c.GetInt64("partition")
  9640. monitorDate := c.GetString("date")
  9641. patient_id, _ := c.GetInt64("patient_id")
  9642. pat_type, _ := c.GetInt64("pat_type")
  9643. timeLayout := "2006-01-02"
  9644. loc, _ := time.LoadLocation("Local")
  9645. var theStartTime int64
  9646. if len(monitorDate) > 0 {
  9647. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9648. if err != nil {
  9649. theStartTime = 0
  9650. }
  9651. theStartTime = theTime.Unix()
  9652. }
  9653. adminInfo := c.GetMobileAdminUserInfo()
  9654. orgID := adminInfo.Org.Id
  9655. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9656. if err != nil {
  9657. c.ErrorLog("获取排班信息失败:%v", err)
  9658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9659. } else {
  9660. if len(monitor) > 0 {
  9661. //获取所有床位
  9662. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9663. //获取所有分区
  9664. zoneList, _ := service.GetAllZoneByList(orgID)
  9665. //获取透析处方
  9666. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9667. //获取透前评估
  9668. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9669. //获取上机
  9670. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9671. //获取透后
  9672. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9673. //获取透后监测
  9674. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9675. //获取所有的患者
  9676. patients, _ := service.GetAllPatientListByListOne(orgID)
  9677. //获取所有透析模式
  9678. treatments, _ := service.GetAllTreatModeByList(orgID)
  9679. //获取所有医嘱
  9680. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9681. //获取双人核对
  9682. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9683. //治疗小结
  9684. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9685. //待消毒
  9686. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9687. for key, item := range monitor {
  9688. // 获取床位信息
  9689. for _, it := range numberList {
  9690. if item.BedId == it.ID {
  9691. monitor[key].DeviceNumber = it
  9692. break
  9693. }
  9694. }
  9695. //获取分区信息
  9696. for _, it := range zoneList {
  9697. if item.PartitionId == it.ID {
  9698. monitor[key].DeviceZone = it
  9699. }
  9700. }
  9701. for _, prescription := range prescriptions {
  9702. if item.PatientId == prescription.PatientId {
  9703. monitor[key].Prescription = prescription
  9704. break
  9705. }
  9706. }
  9707. for _, it := range checkList {
  9708. if item.PatientId == it.PatientId {
  9709. monitor[key].DoubleCheck = it
  9710. break
  9711. }
  9712. }
  9713. for _, it := range summaryList {
  9714. if item.PatientId == it.PatientId {
  9715. monitor[key].TreatmentSummaryForList = it
  9716. break
  9717. }
  9718. }
  9719. // 透前评估
  9720. for _, assessmentBefore := range assessmentBefores {
  9721. if item.PatientId == assessmentBefore.PatientId {
  9722. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9723. break
  9724. }
  9725. }
  9726. // 透析上下机
  9727. for _, dialysisOrder := range dialysisOrders {
  9728. if item.PatientId == dialysisOrder.PatientId {
  9729. monitor[key].DialysisOrder = dialysisOrder
  9730. break
  9731. }
  9732. }
  9733. // 治疗小节
  9734. for _, afterDislysis := range AssessmentAfterDislysis {
  9735. if item.PatientId == afterDislysis.PatientId {
  9736. monitor[key].AssessmentAfterDislysis = afterDislysis
  9737. break
  9738. }
  9739. }
  9740. for _, it := range monitorlist {
  9741. if item.PatientId == it.PatientId {
  9742. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9743. }
  9744. }
  9745. for _, it := range adviceList {
  9746. if item.PatientId == it.PatientId {
  9747. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9748. }
  9749. }
  9750. for _, patient := range patients {
  9751. if item.PatientId == patient.ID {
  9752. monitor[key].MonitorPatients = patient
  9753. break
  9754. }
  9755. }
  9756. for _, treatment := range treatments {
  9757. if item.ModeId == treatment.ID {
  9758. monitor[key].TreatmentMode = treatment
  9759. break
  9760. }
  9761. }
  9762. for _, infor := range informationList {
  9763. if item.PatientId == infor.PatientId {
  9764. monitor[key].NewDeviceInformation = infor
  9765. break
  9766. }
  9767. }
  9768. }
  9769. }
  9770. }
  9771. patients, err := service.GetAllpatientFourty(orgID)
  9772. var mds []*models.NewMonitorDialysisScheduleList
  9773. if pat_type == 0 {
  9774. for _, item := range monitor {
  9775. mds = append(mds, item)
  9776. }
  9777. }
  9778. //待医嘱核对
  9779. if pat_type == 1 {
  9780. for _, item := range monitor {
  9781. if len(item.AdviceList) > 0 {
  9782. mds = append(mds, item)
  9783. }
  9784. }
  9785. }
  9786. //待开小结
  9787. if pat_type == 2 {
  9788. for _, item := range monitor {
  9789. if item.TreatmentSummaryForList == nil {
  9790. mds = append(mds, item)
  9791. }
  9792. }
  9793. }
  9794. //待下机
  9795. if pat_type == 3 {
  9796. for _, item := range monitor {
  9797. if item.DialysisOrder != nil {
  9798. if item.DialysisOrder.ID > 0 {
  9799. mds = append(mds, item)
  9800. }
  9801. }
  9802. }
  9803. }
  9804. //待消毒
  9805. if pat_type == 4 {
  9806. for _, item := range monitor {
  9807. if item.NewDeviceInformation == nil {
  9808. mds = append(mds, item)
  9809. }
  9810. }
  9811. }
  9812. //待双人核对
  9813. if pat_type == 5 {
  9814. for _, item := range monitor {
  9815. if item.DoubleCheck == nil {
  9816. mds = append(mds, item)
  9817. }
  9818. }
  9819. }
  9820. //医嘱未执行
  9821. if pat_type == 6 {
  9822. for _, item := range monitor {
  9823. if len(item.AdviceList) > 0 {
  9824. mds = append(mds, item)
  9825. }
  9826. }
  9827. }
  9828. //患者未签名
  9829. if pat_type == 7 {
  9830. for _, item := range monitor {
  9831. if item.DialysisOrder != nil {
  9832. if item.DialysisOrder.ID > 0 {
  9833. mds = append(mds, item)
  9834. }
  9835. }
  9836. }
  9837. }
  9838. //目标超滤于实际超滤不同
  9839. if pat_type == 8 {
  9840. for _, item := range monitor {
  9841. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9842. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9843. mds = append(mds, item)
  9844. }
  9845. }
  9846. }
  9847. }
  9848. //血压少于5次
  9849. if pat_type == 9 {
  9850. for _, item := range monitor {
  9851. if len(item.MonitoringRecord) < 5 {
  9852. mds = append(mds, item)
  9853. }
  9854. }
  9855. }
  9856. if pat_type == 10 {
  9857. for _, item := range monitor {
  9858. if len(item.MonitoringRecord) == 0 {
  9859. mds = append(mds, item)
  9860. }
  9861. }
  9862. }
  9863. if pat_type == 11 {
  9864. for _, item := range monitor {
  9865. if len(item.MonitoringRecord) > 0 {
  9866. mds = append(mds, item)
  9867. }
  9868. }
  9869. }
  9870. if pat_type == 12 {
  9871. for _, item := range monitor {
  9872. if len(item.MonitoringRecord) > 0 {
  9873. mds = append(mds, item)
  9874. }
  9875. }
  9876. }
  9877. if err == nil {
  9878. c.ServeSuccessJSON(map[string]interface{}{
  9879. "monitor": mds,
  9880. "patients": patients,
  9881. })
  9882. } else {
  9883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9884. }
  9885. }
  9886. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9887. admin_user_id, _ := c.GetInt64("admin_user_id")
  9888. timeStr := time.Now().Format("2006-01-02")
  9889. timeLayout := "2006-01-02 15:04:05"
  9890. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9891. timenow := timeStringToTime.Unix()
  9892. orgId := c.GetMobileAdminUserInfo().Org.Id
  9893. //查询当前护士的患者
  9894. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9895. var patientIds []int64
  9896. for _, item := range orderList {
  9897. patientIds = append(patientIds, item.PatientId)
  9898. }
  9899. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9900. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9901. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9902. //药品管理信息
  9903. _, drugStockConfig := service.FindHisConfig(orgId)
  9904. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9905. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9906. c.ServeSuccessJSON(map[string]interface{}{
  9907. "adviceList": adviceList,
  9908. "hisAdviceList": hisAdviceList,
  9909. "projectList": projectList,
  9910. "drugStockConfig": drugStockConfig,
  9911. "patientList": patientList,
  9912. "projectConfig": projectConfig,
  9913. })
  9914. }
  9915. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9916. patient_id, _ := c.GetInt64("patient_id")
  9917. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9918. c.ServeSuccessJSON(map[string]interface{}{
  9919. "recrods": recrods,
  9920. })
  9921. }
  9922. func (c *DialysisAPIController) ExMobileChangeSch() {
  9923. id_one, _ := c.GetInt64("id_one")
  9924. id_two, _ := c.GetInt64("id_two")
  9925. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9926. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9927. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9928. //if order2.ID > 0 {
  9929. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9930. // return
  9931. //}
  9932. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9933. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9934. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9935. if count > 0 {
  9936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9937. return
  9938. }
  9939. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9940. if count1 > 0 {
  9941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9942. return
  9943. }
  9944. }
  9945. err := service.UpdateScheduleThree(sch, sch_two)
  9946. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9947. if order.ID > 0 {
  9948. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9949. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9950. redis := service.RedisClient()
  9951. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9952. redis.Set(key, "", time.Second)
  9953. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9954. //清空key 值
  9955. redis.Set(keyOne, "", time.Second)
  9956. }
  9957. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9958. if orderOne.ID > 0 {
  9959. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9960. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9961. redis := service.RedisClient()
  9962. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9963. redis.Set(key, "", time.Second)
  9964. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9965. //清空key 值
  9966. redis.Set(keyOne, "", time.Second)
  9967. }
  9968. if err == nil {
  9969. //去除当天患者排班中重复数据,保留最后一条数据
  9970. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9971. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9972. c.ServeSuccessJSON(map[string]interface{}{
  9973. "msg": "交换成功",
  9974. })
  9975. } else {
  9976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9977. return
  9978. }
  9979. }
  9980. func (c *DialysisAPIController) MobileCoverSch() {
  9981. id_one, _ := c.GetInt64("id_one")
  9982. id_two, _ := c.GetInt64("id_two")
  9983. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9984. //针对凤凰医院
  9985. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9986. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9987. if len(advice) > 0 {
  9988. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9989. }
  9990. }
  9991. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9992. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9993. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9994. if len(hisAdvice) > 0 {
  9995. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9996. }
  9997. if len(project) > 0 {
  9998. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9999. }
  10000. }
  10001. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10002. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10003. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10004. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10005. if count > 0 {
  10006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10007. return
  10008. }
  10009. }
  10010. var new_sch models.Schedule
  10011. new_sch = sch
  10012. new_sch.BedId = sch_two.BedId
  10013. new_sch.ScheduleDate = sch_two.ScheduleDate
  10014. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10015. new_sch.PartitionId = sch_two.PartitionId
  10016. new_sch.ScheduleType = sch_two.ScheduleType
  10017. new_sch.ID = 0
  10018. //删除原来的排班
  10019. err := service.SaveSchTwo(sch, sch_two)
  10020. //生成新的排班
  10021. if err == nil {
  10022. err2 := service.SaveSch(&new_sch)
  10023. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10024. if order.ID > 0 {
  10025. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10026. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10027. redis := service.RedisClient()
  10028. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10029. redis.Set(key, "", time.Second)
  10030. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10031. //清空key 值
  10032. redis.Set(keyOne, "", time.Second)
  10033. }
  10034. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10035. if orderOne.ID > 0 {
  10036. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10037. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10038. redis := service.RedisClient()
  10039. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10040. redis.Set(key, "", time.Second)
  10041. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10042. //清空key 值
  10043. redis.Set(keyOne, "", time.Second)
  10044. }
  10045. if err2 == nil {
  10046. //去除当天患者排班中重复数据,保留最后一条数据
  10047. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10048. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10049. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10050. c.ServeSuccessJSON(map[string]interface{}{
  10051. "msg": "覆盖成功",
  10052. "new_sch": new_sch,
  10053. })
  10054. } else {
  10055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10056. return
  10057. }
  10058. } else {
  10059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10060. return
  10061. }
  10062. }
  10063. func (c *DialysisAPIController) BatchCheckAdvice() {
  10064. patient_id, _ := c.GetInt64("patient_id")
  10065. advice_date, _ := c.GetInt64("advice_date")
  10066. org_id := c.GetMobileAdminUserInfo().Org.Id
  10067. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10068. //查询是his系统还是血透系统
  10069. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10070. //his客户
  10071. if configs.IsOpen == 1 {
  10072. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10073. for _, item := range adviceList {
  10074. service.BatchCheckHisAdvice(item.ID, creater)
  10075. }
  10076. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10077. for _, item := range projectList {
  10078. service.BatchCheckProject(item.ID, creater)
  10079. }
  10080. c.ServeSuccessJSON(map[string]interface{}{
  10081. "adviceList": adviceList,
  10082. "projectList": projectList,
  10083. })
  10084. }
  10085. if configs.IsOpen != 1 {
  10086. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10087. for _, item := range adviceList {
  10088. service.BatchAdviceList(item.ID, creater)
  10089. }
  10090. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10091. for _, item := range projectList {
  10092. service.BatchCheckProject(item.ID, creater)
  10093. }
  10094. c.ServeSuccessJSON(map[string]interface{}{
  10095. "adviceList": adviceList,
  10096. "projectList": projectList,
  10097. })
  10098. }
  10099. return
  10100. }
  10101. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10102. org_id := c.GetMobileAdminUserInfo().Org.Id
  10103. drugList, _ := service.GetAllDrugList(org_id)
  10104. c.ServeSuccessJSON(map[string]interface{}{
  10105. "drugList": drugList,
  10106. })
  10107. }
  10108. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10109. org_id := c.GetMobileAdminUserInfo().Org.Id
  10110. dataBody := make(map[string]interface{}, 0)
  10111. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10112. if err != nil {
  10113. utils.ErrorLog(err.Error())
  10114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10115. return
  10116. }
  10117. timeLayout := "2006-01-02"
  10118. loc, _ := time.LoadLocation("Local")
  10119. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10120. utils.ErrorLog("advice_type")
  10121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10122. return
  10123. }
  10124. adviceType := int64(dataBody["advice_type"].(float64))
  10125. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10126. utils.ErrorLog("start_time")
  10127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10128. return
  10129. }
  10130. startTime2, _ := dataBody["start_time"].(string)
  10131. time_arr := strings.Split(startTime2, " ")
  10132. if len(time_arr) > 0 {
  10133. startTime2 = time_arr[0]
  10134. }
  10135. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10136. utils.ErrorLog("advice_date")
  10137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10138. return
  10139. }
  10140. advice_date, _ := dataBody["advice_date"].(string)
  10141. var advicedateunix int64
  10142. if len(advice_date) > 0 {
  10143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10144. if err != nil {
  10145. fmt.Println(err)
  10146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10147. return
  10148. }
  10149. advicedateunix = theTime.Unix()
  10150. }
  10151. adviceDate := startTime2
  10152. if len(adviceDate) == 0 {
  10153. utils.ErrorLog("len(adviceDate) == 0")
  10154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10155. return
  10156. }
  10157. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10158. if err != nil {
  10159. utils.ErrorLog(err.Error())
  10160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10161. return
  10162. }
  10163. AdviceDate := advicedateunix
  10164. RecordDate := advicedateunix
  10165. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10166. utils.ErrorLog("start_time")
  10167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10168. return
  10169. }
  10170. startTime, _ := dataBody["start_time"].(string)
  10171. if len(startTime) == 0 {
  10172. utils.ErrorLog("len(start_time) == 0")
  10173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10174. return
  10175. }
  10176. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10177. if err != nil {
  10178. utils.ErrorLog(err.Error())
  10179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10180. return
  10181. }
  10182. StartTime := theTime.Unix()
  10183. advice_name, _ := dataBody["advice_name"].(string)
  10184. advice_desc, _ := dataBody["advice_desc"].(string)
  10185. delivery_way, _ := dataBody["delivery_way"].(string)
  10186. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10187. frequency_type := int64(dataBody["frequency_type"].(float64))
  10188. frequency_week, _ := dataBody["frequency_week"].(string)
  10189. prescribing_number := dataBody["prescribing_number"].(float64)
  10190. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10191. remark := dataBody["remark"].(string)
  10192. single_dose := dataBody["single_dose"].(float64)
  10193. single_dose_unit := dataBody["single_dose_unit"].(string)
  10194. patient_id := int64(dataBody["patient_id"].(float64))
  10195. day_count := int64(dataBody["day_count"].(float64))
  10196. groupNo := int64(dataBody["group_no"].(float64))
  10197. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10198. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10199. if groupNo <= 0 {
  10200. group := service.GetMaxAdviceGroupID(org_id)
  10201. groupNo = group + 1
  10202. }
  10203. var template_id = ""
  10204. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10205. template_id = "M" + adviceLastId
  10206. advice := models.DoctorAdvice{
  10207. UserOrgId: org_id,
  10208. PatientId: patient_id,
  10209. AdviceType: adviceType,
  10210. AdviceDate: AdviceDate,
  10211. StartTime: StartTime,
  10212. AdviceName: advice_name,
  10213. AdviceDesc: advice_desc,
  10214. ReminderDate: 0,
  10215. SingleDose: single_dose,
  10216. SingleDoseUnit: single_dose_unit,
  10217. DrugSpec: 0,
  10218. DrugSpecUnit: "",
  10219. PrescribingNumber: prescribing_number,
  10220. PrescribingNumberUnit: prescribing_number_unit,
  10221. DeliveryWay: delivery_way,
  10222. ExecutionFrequency: execution_frequency,
  10223. AdviceDoctor: advice_doctor,
  10224. Status: 1,
  10225. CreatedTime: time.Now().Unix(),
  10226. UpdatedTime: 0,
  10227. AdviceAffirm: "",
  10228. Remark: remark,
  10229. StopTime: 0,
  10230. StopReason: "",
  10231. StopDoctor: 0,
  10232. StopState: 0,
  10233. ParentId: 0,
  10234. ExecutionTime: 0,
  10235. ExecutionStaff: 0,
  10236. ExecutionState: 0,
  10237. Checker: 0,
  10238. RecordDate: RecordDate,
  10239. DialysisOrderId: 0,
  10240. CheckTime: 0,
  10241. CheckState: 0,
  10242. AdviceId: 0,
  10243. RemindType: 0,
  10244. FrequencyType: frequency_type,
  10245. DayCount: day_count,
  10246. WeekDay: frequency_week,
  10247. ChildDoctorAdvice: nil,
  10248. TemplateId: template_id,
  10249. Modifier: 0,
  10250. IsCheck: 0,
  10251. Way: 0,
  10252. DrugId: 0,
  10253. DrugNameId: 0,
  10254. IsMedicine: 0,
  10255. PushStartTime: 0,
  10256. IsSettle: 0,
  10257. IsPrescription: 0,
  10258. GroupNo: groupNo,
  10259. }
  10260. service.CreateMobileAdivce(advice)
  10261. c.ServeSuccessJSON(map[string]interface{}{
  10262. "msg": "保存成功!",
  10263. })
  10264. }
  10265. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10266. patient_id, _ := c.GetInt64("patient_id")
  10267. org_id := c.GetMobileAdminUserInfo().Org.Id
  10268. app_id := c.GetMobileAdminUserInfo().App.Id
  10269. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10270. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10271. c.ServeSuccessJSON(map[string]interface{}{
  10272. "adviceList": adviceList,
  10273. "adminRoles": adminRoles,
  10274. })
  10275. }
  10276. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10277. org_id := c.GetMobileAdminUserInfo().Org.Id
  10278. dataBody := make(map[string]interface{}, 0)
  10279. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10280. if err != nil {
  10281. utils.ErrorLog(err.Error())
  10282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10283. return
  10284. }
  10285. timeLayout := "2006-01-02"
  10286. loc, _ := time.LoadLocation("Local")
  10287. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10288. utils.ErrorLog("start_time")
  10289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10290. return
  10291. }
  10292. startTime2, _ := dataBody["start_time"].(string)
  10293. time_arr := strings.Split(startTime2, " ")
  10294. if len(time_arr) > 0 {
  10295. startTime2 = time_arr[0]
  10296. }
  10297. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10298. utils.ErrorLog("advice_date")
  10299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10300. return
  10301. }
  10302. advice_date, _ := dataBody["advice_date"].(string)
  10303. var advicedateunix int64
  10304. if len(advice_date) > 0 {
  10305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10306. if err != nil {
  10307. fmt.Println(err)
  10308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10309. return
  10310. }
  10311. advicedateunix = theTime.Unix()
  10312. }
  10313. adviceDate := startTime2
  10314. if len(adviceDate) == 0 {
  10315. utils.ErrorLog("len(adviceDate) == 0")
  10316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10317. return
  10318. }
  10319. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10320. if err != nil {
  10321. utils.ErrorLog(err.Error())
  10322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10323. return
  10324. }
  10325. AdviceDate := advicedateunix
  10326. RecordDate := advicedateunix
  10327. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10328. utils.ErrorLog("start_time")
  10329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10330. return
  10331. }
  10332. startTime, _ := dataBody["start_time"].(string)
  10333. if len(startTime) == 0 {
  10334. utils.ErrorLog("len(start_time) == 0")
  10335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10336. return
  10337. }
  10338. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10339. if err != nil {
  10340. utils.ErrorLog(err.Error())
  10341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10342. return
  10343. }
  10344. StartTime := theTime.Unix()
  10345. advice_name, _ := dataBody["advice_name"].(string)
  10346. advice_desc, _ := dataBody["advice_desc"].(string)
  10347. delivery_way, _ := dataBody["delivery_way"].(string)
  10348. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10349. prescribing_number := dataBody["prescribing_number"].(float64)
  10350. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10351. remark := dataBody["remark"].(string)
  10352. single_dose := dataBody["single_dose"].(float64)
  10353. single_dose_unit := dataBody["single_dose_unit"].(string)
  10354. patient_id := int64(dataBody["patient_id"].(float64))
  10355. groupNo := int64(dataBody["group_no"].(float64))
  10356. parent_id := int64(dataBody["parent_id"].(float64))
  10357. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10358. advice := models.XtDoctorAdviceOne{
  10359. UserOrgId: org_id,
  10360. PatientId: patient_id,
  10361. AdviceType: 1,
  10362. AdviceDate: AdviceDate,
  10363. StartTime: StartTime,
  10364. AdviceName: advice_name,
  10365. AdviceDesc: advice_desc,
  10366. ReminderDate: 0,
  10367. SingleDose: single_dose,
  10368. SingleDoseUnit: single_dose_unit,
  10369. PrescribingNumber: prescribing_number,
  10370. PrescribingNumberUnit: prescribing_number_unit,
  10371. DeliveryWay: delivery_way,
  10372. ExecutionFrequency: execution_frequency,
  10373. AdviceDoctor: advice_doctor,
  10374. Status: 1,
  10375. CreatedTime: time.Now().Unix(),
  10376. UpdatedTime: time.Now().Unix(),
  10377. AdviceAffirm: "",
  10378. Remark: remark,
  10379. StopTime: 0,
  10380. StopReason: "",
  10381. StopDoctor: 0,
  10382. StopState: 0,
  10383. ParentId: parent_id,
  10384. ExecutionTime: 0,
  10385. ExecutionStaff: 0,
  10386. ExecutionState: 0,
  10387. Checker: 0,
  10388. RecordDate: RecordDate,
  10389. DialysisOrderId: 0,
  10390. CheckTime: 0,
  10391. CheckState: 0,
  10392. DrugSpec: 0,
  10393. DrugSpecUnit: "",
  10394. Groupno: groupNo,
  10395. RemindType: 0,
  10396. FrequencyType: 0,
  10397. DayCount: 0,
  10398. WeekDay: "",
  10399. TemplateId: "",
  10400. Modifier: 0,
  10401. }
  10402. service.CreateMobileAdivceOne(advice)
  10403. c.ServeSuccessJSON(map[string]interface{}{
  10404. "msg": "保存成功!",
  10405. })
  10406. }
  10407. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10408. id, _ := c.GetInt64("id")
  10409. service.DeleteSelfAdviceSubAdvice(id)
  10410. c.ServeSuccessJSON(map[string]interface{}{
  10411. "msg": "保存成功!",
  10412. })
  10413. }
  10414. func (c *DialysisAPIController) GetEditAdviceAction() {
  10415. id, _ := c.GetInt64("id")
  10416. org_id := c.GetMobileAdminUserInfo().Org.Id
  10417. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10418. drugList, _ := service.GetAllDrugList(org_id)
  10419. c.ServeSuccessJSON(map[string]interface{}{
  10420. "advice": advice,
  10421. "drugList": drugList,
  10422. })
  10423. }
  10424. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10425. dataBody := make(map[string]interface{}, 0)
  10426. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10427. if err != nil {
  10428. utils.ErrorLog(err.Error())
  10429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10430. return
  10431. }
  10432. timeLayout := "2006-01-02"
  10433. loc, _ := time.LoadLocation("Local")
  10434. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10435. utils.ErrorLog("start_time")
  10436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10437. return
  10438. }
  10439. startTime2, _ := dataBody["start_time"].(string)
  10440. time_arr := strings.Split(startTime2, " ")
  10441. if len(time_arr) > 0 {
  10442. startTime2 = time_arr[0]
  10443. }
  10444. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10445. utils.ErrorLog("advice_date")
  10446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10447. return
  10448. }
  10449. advice_date, _ := dataBody["advice_date"].(string)
  10450. var advicedateunix int64
  10451. if len(advice_date) > 0 {
  10452. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10453. if err != nil {
  10454. fmt.Println(err)
  10455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10456. return
  10457. }
  10458. advicedateunix = theTime.Unix()
  10459. }
  10460. adviceDate := startTime2
  10461. if len(adviceDate) == 0 {
  10462. utils.ErrorLog("len(adviceDate) == 0")
  10463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10464. return
  10465. }
  10466. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10467. if err != nil {
  10468. utils.ErrorLog(err.Error())
  10469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10470. return
  10471. }
  10472. AdviceDate := advicedateunix
  10473. RecordDate := advicedateunix
  10474. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10475. utils.ErrorLog("start_time")
  10476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10477. return
  10478. }
  10479. startTime, _ := dataBody["start_time"].(string)
  10480. if len(startTime) == 0 {
  10481. utils.ErrorLog("len(start_time) == 0")
  10482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10483. return
  10484. }
  10485. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10486. if err != nil {
  10487. utils.ErrorLog(err.Error())
  10488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10489. return
  10490. }
  10491. StartTime := theTime.Unix()
  10492. advice_name, _ := dataBody["advice_name"].(string)
  10493. advice_desc, _ := dataBody["advice_desc"].(string)
  10494. delivery_way, _ := dataBody["delivery_way"].(string)
  10495. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10496. prescribing_number := dataBody["prescribing_number"].(float64)
  10497. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10498. remark := dataBody["remark"].(string)
  10499. single_dose := dataBody["single_dose"].(float64)
  10500. single_dose_unit := dataBody["single_dose_unit"].(string)
  10501. id := int64(dataBody["id"].(float64))
  10502. frequency_type := int64(dataBody["frequency_type"].(float64))
  10503. frequency_week, _ := dataBody["frequency_week"].(string)
  10504. day_count := int64(dataBody["day_count"].(float64))
  10505. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10506. advice := models.XtDoctorAdviceOne{
  10507. AdviceDate: AdviceDate,
  10508. StartTime: StartTime,
  10509. AdviceName: advice_name,
  10510. AdviceDesc: advice_desc,
  10511. SingleDose: single_dose,
  10512. SingleDoseUnit: single_dose_unit,
  10513. PrescribingNumber: prescribing_number,
  10514. PrescribingNumberUnit: prescribing_number_unit,
  10515. DeliveryWay: delivery_way,
  10516. ExecutionFrequency: execution_frequency,
  10517. AdviceDoctor: advice_doctor,
  10518. Remark: remark,
  10519. RecordDate: RecordDate,
  10520. FrequencyType: frequency_type,
  10521. DayCount: day_count,
  10522. WeekDay: frequency_week,
  10523. }
  10524. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10525. c.ServeSuccessJSON(map[string]interface{}{
  10526. "advice": advice,
  10527. })
  10528. }
  10529. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10530. dataBody := make(map[string]interface{}, 0)
  10531. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10532. if err != nil {
  10533. utils.ErrorLog(err.Error())
  10534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10535. return
  10536. }
  10537. timeLayout := "2006-01-02"
  10538. loc, _ := time.LoadLocation("Local")
  10539. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10540. utils.ErrorLog("start_time")
  10541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10542. return
  10543. }
  10544. startTime2, _ := dataBody["start_time"].(string)
  10545. time_arr := strings.Split(startTime2, " ")
  10546. if len(time_arr) > 0 {
  10547. startTime2 = time_arr[0]
  10548. }
  10549. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10550. utils.ErrorLog("advice_date")
  10551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10552. return
  10553. }
  10554. advice_date, _ := dataBody["advice_date"].(string)
  10555. var advicedateunix int64
  10556. if len(advice_date) > 0 {
  10557. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10558. if err != nil {
  10559. fmt.Println(err)
  10560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10561. return
  10562. }
  10563. advicedateunix = theTime.Unix()
  10564. }
  10565. adviceDate := startTime2
  10566. if len(adviceDate) == 0 {
  10567. utils.ErrorLog("len(adviceDate) == 0")
  10568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10569. return
  10570. }
  10571. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10572. if err != nil {
  10573. utils.ErrorLog(err.Error())
  10574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10575. return
  10576. }
  10577. AdviceDate := advicedateunix
  10578. RecordDate := advicedateunix
  10579. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10580. utils.ErrorLog("start_time")
  10581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10582. return
  10583. }
  10584. startTime, _ := dataBody["start_time"].(string)
  10585. if len(startTime) == 0 {
  10586. utils.ErrorLog("len(start_time) == 0")
  10587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10588. return
  10589. }
  10590. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10591. if err != nil {
  10592. utils.ErrorLog(err.Error())
  10593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10594. return
  10595. }
  10596. StartTime := theTime.Unix()
  10597. advice_name, _ := dataBody["advice_name"].(string)
  10598. advice_desc, _ := dataBody["advice_desc"].(string)
  10599. delivery_way, _ := dataBody["delivery_way"].(string)
  10600. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10601. prescribing_number := dataBody["prescribing_number"].(float64)
  10602. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10603. remark := dataBody["remark"].(string)
  10604. single_dose := dataBody["single_dose"].(float64)
  10605. single_dose_unit := dataBody["single_dose_unit"].(string)
  10606. id := int64(dataBody["id"].(float64))
  10607. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10608. advice := models.XtDoctorAdviceOne{
  10609. AdviceDate: AdviceDate,
  10610. StartTime: StartTime,
  10611. AdviceName: advice_name,
  10612. AdviceDesc: advice_desc,
  10613. SingleDose: single_dose,
  10614. SingleDoseUnit: single_dose_unit,
  10615. PrescribingNumber: prescribing_number,
  10616. PrescribingNumberUnit: prescribing_number_unit,
  10617. DeliveryWay: delivery_way,
  10618. ExecutionFrequency: execution_frequency,
  10619. AdviceDoctor: advice_doctor,
  10620. Remark: remark,
  10621. RecordDate: RecordDate,
  10622. }
  10623. service.UpdateMobileDoctorAdviceById(id, advice)
  10624. c.ServeSuccessJSON(map[string]interface{}{
  10625. "advice": advice,
  10626. })
  10627. }
  10628. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10629. dataBody := make(map[string]interface{}, 0)
  10630. timeLayout := "2006-01-02"
  10631. loc, _ := time.LoadLocation("Local")
  10632. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10633. if err != nil {
  10634. utils.ErrorLog(err.Error())
  10635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10636. return
  10637. }
  10638. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10639. utils.ErrorLog("start_time")
  10640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10641. return
  10642. }
  10643. startTime2, _ := dataBody["start_time"].(string)
  10644. time_arr := strings.Split(startTime2, " ")
  10645. if len(time_arr) > 0 {
  10646. startTime2 = time_arr[0]
  10647. }
  10648. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10649. utils.ErrorLog("advice_date")
  10650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10651. return
  10652. }
  10653. advice_date, _ := dataBody["advice_date"].(string)
  10654. var advicedateunix int64
  10655. if len(advice_date) > 0 {
  10656. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10657. if err != nil {
  10658. fmt.Println(err)
  10659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10660. return
  10661. }
  10662. advicedateunix = theTime.Unix()
  10663. }
  10664. adviceDate := startTime2
  10665. if len(adviceDate) == 0 {
  10666. utils.ErrorLog("len(adviceDate) == 0")
  10667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10668. return
  10669. }
  10670. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10671. if err != nil {
  10672. utils.ErrorLog(err.Error())
  10673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10674. return
  10675. }
  10676. RecordDate := advicedateunix
  10677. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10678. utils.ErrorLog("start_time")
  10679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10680. return
  10681. }
  10682. startTime, _ := dataBody["start_time"].(string)
  10683. if len(startTime) == 0 {
  10684. utils.ErrorLog("len(start_time) == 0")
  10685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10686. return
  10687. }
  10688. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10689. if err != nil {
  10690. utils.ErrorLog(err.Error())
  10691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10692. return
  10693. }
  10694. StartTime := theTime.Unix()
  10695. patient_id := int64(dataBody["patient_id"].(float64))
  10696. group_no := int64(dataBody["group_no"].(float64))
  10697. org_id := c.GetMobileAdminUserInfo().Org.Id
  10698. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10699. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10700. utils.ErrorLog("advices")
  10701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10702. return
  10703. }
  10704. adviceNames := dataBody["advices"].([]interface{})
  10705. var advices []*models.GroupAdvice
  10706. for _, adviceNameMap := range adviceNames {
  10707. var advice models.GroupAdvice
  10708. adviceNameM := adviceNameMap.(map[string]interface{})
  10709. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10710. utils.ErrorLog("advice_name")
  10711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10712. return
  10713. }
  10714. adviceName, _ := adviceNameM["advice_name"].(string)
  10715. if len(adviceName) == 0 {
  10716. utils.ErrorLog("len(advice_name) == 0")
  10717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10718. return
  10719. }
  10720. advice.AdviceName = adviceName
  10721. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10722. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10723. advice.DrugSpec = drugSpec
  10724. }
  10725. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10726. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10727. advice.AdviceDesc = adviceDesc
  10728. }
  10729. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10730. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10731. advice.DrugSpecUnit = drugSpecUnit
  10732. }
  10733. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10734. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10735. advice.SingleDose = singleDose
  10736. }
  10737. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10738. singleDose := adviceNameM["single_dose"].(float64)
  10739. advice.SingleDose = singleDose
  10740. }
  10741. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10742. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10743. advice.SingleDoseUnit = singleDoseUnit
  10744. }
  10745. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10746. tmp := adviceNameM["single_dose_unit"].(float64)
  10747. singleDoseUnit := service.TypeConversion(tmp)
  10748. advice.SingleDoseUnit = singleDoseUnit
  10749. }
  10750. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10751. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10752. advice.PrescribingNumber = prescribingNumber
  10753. }
  10754. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10755. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10756. advice.PrescribingNumber = prescribingNumber
  10757. }
  10758. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10759. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10760. advice.PrescribingNumberUnit = prescribingNumberUnit
  10761. }
  10762. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10763. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10764. advice.DeliveryWay = deliveryWay
  10765. }
  10766. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10767. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10768. advice.ExecutionFrequency = executionFrequency
  10769. }
  10770. remark, _ := adviceNameM["remark"].(string)
  10771. advice.Remark = remark
  10772. advice.AdviceType = 1
  10773. advice.StartTime = StartTime
  10774. advice.RecordDate = RecordDate
  10775. advice.PatientId = patient_id
  10776. advice.UserOrgId = org_id
  10777. advice.AdviceDoctor = advice_doctor
  10778. advices = append(advices, &advice)
  10779. }
  10780. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10781. c.ServeSuccessJSON(map[string]interface{}{
  10782. "advice": newAdvices,
  10783. })
  10784. }
  10785. func (c *DialysisAPIController) StopLongAdvice() {
  10786. stop_time := c.GetString("execution_time")
  10787. id, _ := c.GetInt64("id")
  10788. if len(stop_time) <= 0 {
  10789. utils.ErrorLog("stop_time")
  10790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10791. return
  10792. }
  10793. timeLayout2 := "2006-01-02 15:04:05"
  10794. loc, _ := time.LoadLocation("Local")
  10795. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10796. if errs != nil {
  10797. utils.ErrorLog(errs.Error())
  10798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10799. return
  10800. }
  10801. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10802. c.ServeSuccessJSON(map[string]interface{}{
  10803. "advice": advice,
  10804. })
  10805. }