dialysis_api_controller.go 462KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015
  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 && item.HisProject.CostClassify != 104 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 || item.HisProject.CostClassify == 104 {
  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. his_bed = lastAcceptTreatment.HisBed
  1124. his_department = lastAcceptTreatment.HisDepartment
  1125. tumble = lastAcceptTreatment.Tumble
  1126. }
  1127. }
  1128. }
  1129. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1130. UserOrgId: adminUserInfo.Org.Id,
  1131. PatientId: id,
  1132. RecordDate: recordDate.Unix(),
  1133. Way: way,
  1134. Consciousness: consciousness,
  1135. Appetite: appetite,
  1136. Condition: condition,
  1137. SickCondition: sick_condition,
  1138. DangerLevel: danger_level,
  1139. Intake: intake,
  1140. Nutrition: nutrition,
  1141. PsychologicalAssessment: psychological_assessment,
  1142. PsychologicalAssessmentOther: psychological_assessment_other,
  1143. SickConditionOther: sick_condition_other,
  1144. Posture: posture,
  1145. CreatedTime: time.Now().Unix(),
  1146. UpdateTime: time.Now().Unix(),
  1147. Status: 1,
  1148. Score: score,
  1149. Precaution: precaution,
  1150. PrecautionOther: precaution_other,
  1151. PsychologicalOther: psychological_other,
  1152. AdmissionNumber: admission_number,
  1153. Tumble: tumble,
  1154. Diacrisis: diacrisis,
  1155. HisBed: his_bed,
  1156. HisDepartment: his_department,
  1157. }
  1158. if receiveTreatment.ID == 0 { //新增
  1159. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1160. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1161. finish := models.XtDialysisFinish{
  1162. IsFinish: 1,
  1163. UserOrgId: adminUserInfo.Org.Id,
  1164. Status: 1,
  1165. Ctime: time.Now().Unix(),
  1166. Mtime: 0,
  1167. Module: 2,
  1168. RecordDate: recordDate.Unix(),
  1169. Sourse: 1,
  1170. PatientId: id,
  1171. }
  1172. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1173. if dialysisFinish.ID == 0 {
  1174. service.CreateDialysisFinish(finish)
  1175. }
  1176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1177. redis := service.RedisClient()
  1178. defer redis.Close()
  1179. //清空key 值
  1180. redis.Set(key, "", time.Second)
  1181. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1182. redis.Set(keyOne, "", time.Second)
  1183. if err == nil {
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "receiveTreatmentAsses": receiveTreatmentAsses,
  1186. })
  1187. }
  1188. } else { //修改
  1189. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1190. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1191. // if getPermissionErr != nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. // return
  1194. // } else if headNursePermission == nil {
  1195. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1196. // return
  1197. // }
  1198. //}
  1199. // 查询信息规挡的设置天数
  1200. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1201. if infor.ID > 0 && infor.WeekDay > 0 {
  1202. var cha_time int64
  1203. timeNowStr := time.Now().Format("2006-01-02")
  1204. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1205. //今日的日期减去设置的日期
  1206. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1207. if cha_time >= recordDate.Unix() {
  1208. //查询审核是否允许
  1209. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1210. //申请状态不允许的情况 拒绝修改
  1211. if infor.ApplicationStatus != 1 {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1213. return
  1214. }
  1215. }
  1216. }
  1217. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1218. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1219. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1220. receiveTreatmentAsses.ID = receiveTreatment.ID
  1221. if adminUserInfo.Org.Id == 10340 {
  1222. if condition == 1 {
  1223. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1224. if receiveTreatmentAsses.AdmissionNumber == "" {
  1225. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1226. }
  1227. }
  1228. }
  1229. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1230. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1231. redis := service.RedisClient()
  1232. defer redis.Close()
  1233. //清空key 值
  1234. redis.Set(key, "", time.Second)
  1235. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1236. redis.Set(keyOne, "", time.Second)
  1237. if err == nil {
  1238. c.ServeSuccessJSON(map[string]interface{}{
  1239. "receiveTreatmentAsses": receiveTreatmentAsses,
  1240. })
  1241. }
  1242. }
  1243. }
  1244. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1245. id, _ := c.GetInt64("patient", 0)
  1246. recordDateStr := c.GetString("record_date")
  1247. weightAfter, _ := c.GetFloat("weight_after", 0)
  1248. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1249. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1250. fmt.Println("weight_loss", weightReduce)
  1251. temperature, _ := c.GetFloat("temperature", 0)
  1252. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1253. breathing_rate := c.GetString("breathing_rate")
  1254. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1255. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1256. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1257. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1258. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1259. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1260. cruor := c.GetString("cruor")
  1261. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1262. internalFistula := c.GetString("internal_fistula")
  1263. catheter := c.GetString("catheter")
  1264. complications := c.GetString("complication")
  1265. remark := c.GetString("remark")
  1266. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1267. dialysis_intakes := c.GetString("dialysis_intakes")
  1268. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1269. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1270. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1271. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1272. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1273. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1274. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1275. patientGose, _ := c.GetInt64("patient_gose", 0)
  1276. inpatientDepartment := c.GetString("inpatient_department")
  1277. observationContent := c.GetString("observation_content")
  1278. observationContentOther := c.GetString("observation_content_other")
  1279. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1280. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1281. in_advance_reason := c.GetString("in_advance_reason")
  1282. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1283. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1284. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1285. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1286. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1287. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1288. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1289. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1290. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1291. is_eat, _ := c.GetInt64("is_eat", 0)
  1292. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1293. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1294. channels, _ := c.GetInt64("channel", 0)
  1295. return_blood, _ := c.GetInt64("return_blood", 0)
  1296. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1297. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1298. dialysis_during, _ := c.GetFloat("dialysis_during")
  1299. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1300. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1301. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1302. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1303. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1304. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1305. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1306. setting_pressure := c.GetString("setting_pressure")
  1307. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1308. diastolic_pressure := c.GetString("diastolic_pressure")
  1309. other_complication := c.GetString("other_complication")
  1310. ktv := c.GetString("ktv")
  1311. urr := c.GetString("urr")
  1312. hypertenison, _ := c.GetInt64("hypertenison")
  1313. hypopiesia, _ := c.GetInt64("hypopiesia")
  1314. leave_office_method, _ := c.GetInt64("leave_office_method")
  1315. lapse, _ := c.GetInt64("lapse")
  1316. consciousness, _ := c.GetInt64("consciousness")
  1317. fallrisk, _ := c.GetInt64("fallrisk")
  1318. machine_run := c.GetString("machine_run")
  1319. after_urea := c.GetString("after_urea")
  1320. pip_coagulation := c.GetString("pip_coagulation")
  1321. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1322. transfusion_volume := c.GetString("transfusion_volume")
  1323. last_after_weight := c.GetString("last_after_weight")
  1324. displace_liqui_value := c.GetString("displace_liqui_value")
  1325. start_time := c.GetString("start_time")
  1326. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1327. if id <= 0 {
  1328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1329. return
  1330. }
  1331. adminUserInfo := c.GetMobileAdminUserInfo()
  1332. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1333. if patient.ID == 0 {
  1334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1335. return
  1336. }
  1337. if len(recordDateStr) == 0 {
  1338. recordDateStr = time.Now().Format("2006-01-02")
  1339. }
  1340. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1341. fmt.Println("parseDateErr", parseDateErr)
  1342. if parseDateErr != nil {
  1343. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1348. //now := time.Now()
  1349. //year, month, day := now.Date()
  1350. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1351. //todayTimeStamp := today_time.Unix()
  1352. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1353. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1354. UserOrgId: adminUserInfo.Org.Id,
  1355. PatientId: id,
  1356. AssessmentDate: recordDate.Unix(),
  1357. Temperature: temperature,
  1358. PulseFrequency: pulse_frequency,
  1359. BreathingRate: breathing_rate,
  1360. SystolicBloodPressure: systolic_blood_pressure,
  1361. DiastolicBloodPressure: diastolic_blood_pressure,
  1362. ActualUltrafiltration: actual_ultrafiltration,
  1363. ActualDisplacement: actual_displacement,
  1364. ActualTreatmentHour: actualtreatHour,
  1365. ActualTreatmentMinute: actualtreatmin,
  1366. WeightAfter: weightAfter,
  1367. AdditionalWeight: additionalWeight,
  1368. WeightLoss: weightReduce,
  1369. Cruor: cruor,
  1370. SymptomAfterDialysis: symptomsAfterDialysi,
  1371. InternalFistula: internalFistula,
  1372. Catheter: catheter,
  1373. Complication: complications,
  1374. DialysisIntakes: dialysateVolume,
  1375. CreatedTime: time.Now().Unix(),
  1376. UpdatedTime: time.Now().Unix(),
  1377. Status: 1,
  1378. Remark: remark,
  1379. BloodAccessPartId: blood_access_part_id,
  1380. BloodAccessPartOperaId: blood_access_part_opera_id,
  1381. DialysisIntakesUnit: dialysis_intakes_unit,
  1382. PuncturePointOozingBlood: puncturePointOozingBlood,
  1383. PuncturePointHaematoma: puncturePointHaematoma,
  1384. InternalFistulaTremorAc: internalFistulaTremorAc,
  1385. PatientGose: patientGose,
  1386. InpatientDepartment: inpatientDepartment,
  1387. ObservationContent: observationContent,
  1388. ObservationContentOther: observationContentOther,
  1389. DialysisProcess: dialysis_process,
  1390. InAdvanceMinute: in_advance_minute,
  1391. InAdvanceReason: in_advance_reason,
  1392. HemostasisMinute: hemostasis_minute,
  1393. HemostasisOpera: hemostasis_opera,
  1394. TremorNoise: tremor_noise,
  1395. DisequilibriumSyndrome: disequilibrium_syndrome,
  1396. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1397. ArterialTube: arterial_tube,
  1398. IntravenousTube: intravenous_tube,
  1399. Dialyzer: dialyzer,
  1400. InAdvanceReasonOther: in_advance_reason_other,
  1401. IsEat: is_eat,
  1402. CvcA: cvc_a,
  1403. CvcV: cvc_v,
  1404. Channel: channels,
  1405. ReturnBlood: return_blood,
  1406. RehydrationVolume: rehydration_volume,
  1407. DialysisDuring: dialysis_during,
  1408. StrokeVolume: stroke_volume,
  1409. BloodFlow: blood_flow,
  1410. SealingFluidDispose: sealing_fluid_dispose,
  1411. SealingFluidSpecial: sealing_fluid_special,
  1412. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1413. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1414. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1415. SettingPressure: setting_pressure,
  1416. DiastolicPressure: diastolic_pressure,
  1417. OtherComplication: other_complication,
  1418. Ktv: ktv,
  1419. Urr: urr,
  1420. Hypopiesia: hypopiesia,
  1421. Hypertenison: hypertenison,
  1422. Lapse: lapse,
  1423. LeaveOfficeMethod: leave_office_method,
  1424. Consciousness: consciousness,
  1425. Fallrisk: fallrisk,
  1426. MachineRun: machine_run,
  1427. AfterUrea: after_urea,
  1428. PipCoagulation: pip_coagulation,
  1429. AccumulatedBloodVolume: accumulated_blood_volume,
  1430. TransfusionVolume: transfusion_volume,
  1431. LastAfterWeight: last_after_weight,
  1432. DisplaceLiquiValue: displace_liqui_value,
  1433. RecordTime: startDate.Unix(),
  1434. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1435. }
  1436. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1437. // 查询信息规挡的设置天数
  1438. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1439. if infor.ID > 0 && infor.WeekDay > 0 {
  1440. var cha_time int64
  1441. timeNowStr := time.Now().Format("2006-01-02")
  1442. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1443. //今日的日期减去设置的日期
  1444. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1445. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1446. if cha_time >= recordDate.Unix() {
  1447. //查询审核是否允许
  1448. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1449. //申请状态不允许的情况 拒绝修改
  1450. if infor.ApplicationStatus != 1 {
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1452. return
  1453. }
  1454. }
  1455. }
  1456. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1457. if assessmentAfter.ID == 0 { //新增
  1458. if appRole.UserType == 2 || appRole.UserType == 1 {
  1459. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1460. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1461. } else {
  1462. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1463. }
  1464. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1465. if assessmentAfterDislysis.UserOrgId != 10340 {
  1466. if assessmentAfterDislysis.WeightAfter == 0 {
  1467. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1468. }
  1469. }
  1470. if adminUserInfo.Org.Id == 10693 {
  1471. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1472. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1473. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1474. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1475. }
  1476. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1477. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1478. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1479. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1480. }
  1481. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1482. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1483. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1484. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1485. }
  1486. if assessmentAfterDislysis.PulseFrequency == 0 {
  1487. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1488. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1489. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1490. }
  1491. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1492. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1493. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1494. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1495. }
  1496. }
  1497. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1498. //记录日志
  1499. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1500. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1501. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1502. PatientId: assessmentAfterDislysis.PatientId,
  1503. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1504. Status: 1,
  1505. ErrLog: string(byterequest),
  1506. AdminUserId: adminUserInfo.AdminUser.Id,
  1507. Ctime: 0,
  1508. Mtime: 0,
  1509. Source: "手机端保存透后评估",
  1510. }
  1511. service.CreateAfterDialysisLog(afterDialysisLog)
  1512. finish := models.XtDialysisFinish{
  1513. IsFinish: 1,
  1514. UserOrgId: adminUserInfo.Org.Id,
  1515. Status: 1,
  1516. Ctime: time.Now().Unix(),
  1517. Mtime: 0,
  1518. Module: 9,
  1519. RecordDate: recordDate.Unix(),
  1520. Sourse: 1,
  1521. PatientId: id,
  1522. }
  1523. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1524. if dialysisFinish.ID == 0 {
  1525. service.CreateDialysisFinish(finish)
  1526. }
  1527. redis := service.RedisClient()
  1528. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1529. redis.Set(keyTwo, "", time.Second)
  1530. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1531. //清空key 值
  1532. redis.Set(key, "", time.Second)
  1533. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1534. redis.Set(keyOne, "", time.Second)
  1535. defer redis.Close()
  1536. if err == nil {
  1537. c.ServeSuccessJSON(map[string]interface{}{
  1538. "assessmentAfterDislysis": assessmentAfterDislysis,
  1539. })
  1540. }
  1541. return
  1542. } else { //修改
  1543. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1544. if infor.ID > 0 && infor.WeekDay > 0 {
  1545. var cha_time int64
  1546. timeNowStr := time.Now().Format("2006-01-02")
  1547. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1548. //今日的日期减去设置的日期
  1549. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1550. if cha_time >= recordDate.Unix() {
  1551. //查询审核是否允许
  1552. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1553. //申请状态不允许的情况 拒绝修改
  1554. if infor.ApplicationStatus != 1 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1556. return
  1557. }
  1558. }
  1559. }
  1560. if appRole.UserType == 2 || appRole.UserType == 1 {
  1561. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1562. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1563. } else {
  1564. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1565. if assessmentAfterDislysis.Creater == 0 {
  1566. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1567. }
  1568. }
  1569. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1570. assessmentAfterDislysis.ID = assessmentAfter.ID
  1571. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1572. if assessmentAfterDislysis.UserOrgId != 10340 {
  1573. if assessmentAfterDislysis.WeightAfter == 0 {
  1574. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1575. }
  1576. }
  1577. if adminUserInfo.Org.Id == 10693 {
  1578. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1579. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1580. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1581. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1582. }
  1583. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1584. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1585. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1586. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1587. }
  1588. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1589. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1590. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1591. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1592. }
  1593. if assessmentAfterDislysis.PulseFrequency == 0 {
  1594. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1595. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1596. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1597. }
  1598. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1599. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1600. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1601. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1602. }
  1603. }
  1604. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1605. //记录日志
  1606. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1607. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1608. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1609. PatientId: assessmentAfterDislysis.PatientId,
  1610. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1611. Status: 1,
  1612. ErrLog: string(byterequest),
  1613. AdminUserId: adminUserInfo.AdminUser.Id,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: 0,
  1616. Source: "手机端修改保存透后评估",
  1617. }
  1618. service.CreateAfterDialysisLog(afterDialysisLog)
  1619. redis := service.RedisClient()
  1620. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1621. redis.Set(keyTwo, "", time.Second)
  1622. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1623. //清空key 值
  1624. redis.Set(key, "", time.Second)
  1625. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1626. redis.Set(keyOne, "", time.Second)
  1627. if err == nil {
  1628. c.ServeSuccessJSON(map[string]interface{}{
  1629. "assessmentAfterDislysis": assessmentAfterDislysis,
  1630. })
  1631. return
  1632. }
  1633. }
  1634. return
  1635. }
  1636. func (c *DialysisAPIController) PostDialysisPrescription() {
  1637. id, _ := c.GetInt64("patient", 0)
  1638. recordDateStr := c.GetString("record_date")
  1639. if id <= 0 {
  1640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. adminUserInfo := c.GetMobileAdminUserInfo()
  1644. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1645. if patient.ID == 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1647. return
  1648. }
  1649. if len(recordDateStr) == 0 {
  1650. recordDateStr = time.Now().Format("2006-01-02")
  1651. }
  1652. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1653. if parseDateErr != nil {
  1654. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. mode_id, _ := c.GetInt64("mode_id", 0)
  1659. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1660. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1661. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1662. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1663. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1664. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1665. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1666. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1667. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1668. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1669. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1670. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1671. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1672. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1673. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1674. kalium, _ := c.GetFloat("kalium", 0)
  1675. sodium, _ := c.GetFloat("sodium", 0)
  1676. calcium, _ := c.GetFloat("calcium", 0)
  1677. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1678. glucose, _ := c.GetFloat("glucose", 0)
  1679. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1680. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1681. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1682. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1683. conductivity, _ := c.GetFloat("conductivity", 0)
  1684. remark := c.GetString("remark")
  1685. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1686. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1687. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1688. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1689. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1690. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1691. special_medicine_other := c.GetString("special_medicine_other")
  1692. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1693. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1694. blood_access, _ := c.GetInt64("blood_access", 0)
  1695. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1696. body_fluid_other := c.GetString("body_fluid_other")
  1697. niprocart, _ := c.GetInt64("niprocart", 0)
  1698. jms, _ := c.GetInt64("jms", 0)
  1699. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1700. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1701. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1702. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1703. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1704. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1705. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1706. injector, _ := c.GetInt64("injector", 0)
  1707. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1708. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1709. safe_package, _ := c.GetInt64("package", 0)
  1710. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1711. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1712. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1713. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1714. blood := c.GetString("blood")
  1715. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1716. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1717. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1718. displace_speed := c.GetString("displace_speed")
  1719. illness, _ := c.GetInt64("illness")
  1720. amylaceum := c.GetString("amylaceum")
  1721. single_time := c.GetString("single_time")
  1722. single_water := c.GetString("single_water")
  1723. replacement_flow := c.GetString("replacement_flow")
  1724. plasma_separator := c.GetString("plasma_separator")
  1725. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1726. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1727. oxygen_flow := c.GetString("oxygen_flow")
  1728. oxygen_time := c.GetString("oxygen_time")
  1729. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1730. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1731. puncture_needle := c.GetString("puncture_needle")
  1732. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1733. epo := c.GetString("epo")
  1734. epo_count, _ := c.GetFloat("epo_count", 0)
  1735. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1736. admin_user_id, _ := c.GetInt64("admin_user_id")
  1737. is_water := c.GetString("is_water")
  1738. var is_war int64
  1739. if is_water == "是" {
  1740. is_war = 1
  1741. }
  1742. if is_water == "否" {
  1743. is_war = 2
  1744. }
  1745. if is_water == "请选择" {
  1746. is_war = 0
  1747. }
  1748. drhy_water := c.GetString("drhy_water")
  1749. dry_water_hour := c.GetString("dry_water_hour")
  1750. water_machine := c.GetString("water_machine")
  1751. add_amount, _ := c.GetFloat("add_amount")
  1752. reduce_amount, _ := c.GetFloat("reduce_amount")
  1753. dialysis_remark := c.GetString("dialysis_remark")
  1754. prescribing_number, _ := c.GetFloat("prescribing_number")
  1755. prescription_sodium := c.GetString("prescription_sodium")
  1756. start_sodium := c.GetString("start_sodium")
  1757. sodium_curve := c.GetString("sodium_curve")
  1758. treatment_remark := c.GetString("treatment_remark")
  1759. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1760. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1761. prescription_water, _ := c.GetFloat("prescription_water")
  1762. dialysis_strainer := c.GetString("dialysis_strainer")
  1763. chaptalization := c.GetString("chaptalization")
  1764. washing_time := c.GetString("washing_time")
  1765. warsh_count := c.GetString("warsh_count")
  1766. blood_access_part_id := c.GetString("blood_access_part_id")
  1767. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1768. dialyzate := c.GetString("dialyzate")
  1769. first_super := c.GetString("first_super")
  1770. var first_sup int64
  1771. if first_super == "是" {
  1772. first_sup = 1
  1773. }
  1774. if first_super == "否" {
  1775. first_sup = 2
  1776. }
  1777. if first_super == "请选择" {
  1778. first_sup = 0
  1779. }
  1780. is_sequential := c.GetString("is_sequential")
  1781. var is_sequent int64
  1782. if is_sequential == "是" {
  1783. is_sequent = 1
  1784. }
  1785. if is_sequential == "否" {
  1786. is_sequent = 2
  1787. }
  1788. if is_sequential == "请选择" {
  1789. is_sequent = 0
  1790. }
  1791. conduct := c.GetString("conduct")
  1792. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1793. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1794. //
  1795. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1796. // if appRole.UserType == 3 {
  1797. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1798. // if getPermissionErr != nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1800. // return
  1801. // } else if headNursePermission == nil {
  1802. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1803. // return
  1804. // }
  1805. // }
  1806. //}
  1807. // 查询信息规挡的设置天数
  1808. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1809. if infor.ID > 0 && infor.WeekDay > 0 {
  1810. var cha_time int64
  1811. timeNowStr := time.Now().Format("2006-01-02")
  1812. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1813. //今日的日期减去设置的日期
  1814. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1815. if cha_time >= recordDate.Unix() {
  1816. //查询审核是否允许
  1817. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1818. //申请状态不允许的情况 拒绝修改
  1819. if infor.ApplicationStatus != 1 {
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1821. return
  1822. }
  1823. }
  1824. }
  1825. if mode_id > 0 {
  1826. var str string
  1827. //查找该机构用的是什么透析器
  1828. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1829. if filedConfig.ID > 0 {
  1830. str = dialyzerPerfusionApparatus
  1831. } else {
  1832. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1833. }
  1834. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1835. }
  1836. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1837. var dialysis_dialyszers_id int64
  1838. var dialysis_strainer_id int64
  1839. var dialysis_irrigation_id int64
  1840. if len(goodList) > 0 {
  1841. for _, item := range goodList {
  1842. if item.SpecificationName == dialysis_dialyszers {
  1843. dialysis_dialyszers_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_irrigation {
  1846. dialysis_irrigation_id = item.ID
  1847. }
  1848. if item.SpecificationName == dialysis_strainer {
  1849. dialysis_strainer_id = item.ID
  1850. }
  1851. }
  1852. }
  1853. //TODO 需要根据角色去判断
  1854. prescription := models.DialysisPrescription{
  1855. UserOrgId: adminUserInfo.Org.Id,
  1856. PatientId: id,
  1857. RecordDate: recordDate.Unix(),
  1858. ModeId: mode_id,
  1859. DialysisDuration: dialysis_duration,
  1860. Dialyzer: dialyzer,
  1861. PerfusionApparatus: perfusion_apparatus,
  1862. BloodFlowVolume: blood_flow_volume,
  1863. DewaterAmount: dewater_amount,
  1864. DisplaceLiqui: displace_liqui,
  1865. ReplacementWay: replacement_way,
  1866. Anticoagulant: anticoagulant,
  1867. AnticoagulantShouji: anticoagulant_shouji,
  1868. AnticoagulantWeichi: anticoagulant_weichi,
  1869. AnticoagulantZongliang: anticoagulant_zongliang,
  1870. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1871. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1872. Kalium: kalium,
  1873. Sodium: sodium,
  1874. Calcium: calcium,
  1875. Bicarbonate: bicarbonate,
  1876. Glucose: glucose,
  1877. // DryWeight: dry_weight,
  1878. DialysateFlow: dialysate_flow,
  1879. DialysateTemperature: dialysate_temperature,
  1880. // PrescriptionDoctor: prescription_doctor,
  1881. ReplacementTotal: replacement_total,
  1882. Conductivity: conductivity,
  1883. Remark: remark,
  1884. Status: 1,
  1885. CreatedTime: time.Now().Unix(),
  1886. UpdatedTime: time.Now().Unix(),
  1887. DialysisDurationMinute: dialysisDurationMinute,
  1888. DialysisDurationHour: dialysisDurationHour,
  1889. TargetUltrafiltration: targetUltrafiltration,
  1890. DialysateFormulation: dialysateFormulation,
  1891. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1892. BodyFluid: body_fluid,
  1893. SpecialMedicine: special_medicine,
  1894. SpecialMedicineOther: special_medicine_other,
  1895. DisplaceLiquiPart: displace_liqui_part,
  1896. DisplaceLiquiValue: displace_liqui_value,
  1897. BloodAccess: blood_access,
  1898. Ultrafiltration: ultrafiltration,
  1899. BodyFluidOther: body_fluid_other,
  1900. Niprocart: niprocart,
  1901. Jms: jms,
  1902. FistulaNeedleSet: fistula_needle_set,
  1903. FistulaNeedleSet16: fistula_needle_set_16,
  1904. Hemoperfusion: hemoperfusion,
  1905. DialyserSterilised: dialyser_sterilised,
  1906. Filtryzer: filtryzer,
  1907. Dialyzers: dialyzers,
  1908. Injector: injector,
  1909. Bloodlines: bloodlines,
  1910. TubingHemodialysis: tubing_hemodialysis,
  1911. Package: safe_package,
  1912. ALiquid: a_liquid,
  1913. TargetKtv: target_ktv,
  1914. PreImpulse: pre_impulse,
  1915. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1916. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1917. Blood: blood,
  1918. DialysisDialyszers: dialysis_dialyszers,
  1919. DialysisIrrigation: dialysis_irrigation,
  1920. AntioxidantCommodityName: antioxidant_commodity_name,
  1921. DisplaceSpeed: displace_speed,
  1922. Illness: illness,
  1923. Amylaceum: amylaceum,
  1924. SingleTime: single_time,
  1925. SingleWater: single_water,
  1926. ReplacementFlow: replacement_flow,
  1927. PlasmaSeparator: plasma_separator,
  1928. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1929. OxygenUptake: oxygen_uptake,
  1930. OxygenFlow: oxygen_flow,
  1931. OxygenTime: oxygen_time,
  1932. HemodialysisPipelines: hemodialysis_pipelines,
  1933. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1934. PunctureNeedle: puncture_needle,
  1935. PunctureNeedleCount: puncture_needle_count,
  1936. Epo: epo,
  1937. EpoCount: epo_count,
  1938. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1939. AdminUserId: admin_user_id,
  1940. IsWater: is_war,
  1941. DrhyWater: drhy_water,
  1942. DryWaterHour: dry_water_hour,
  1943. WaterMachine: water_machine,
  1944. AddAmount: add_amount,
  1945. ReduceAmount: reduce_amount,
  1946. DialysisRemark: dialysis_remark,
  1947. PrescribingNumber: prescribing_number,
  1948. StartSodium: start_sodium,
  1949. SodiumCurve: sodium_curve,
  1950. TreatmentRemark: treatment_remark,
  1951. PrescriptionSodium: prescription_sodium,
  1952. DialysisFluidFlow: dialysis_fluid_flow,
  1953. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1954. PrescriptionWater: prescription_water,
  1955. DialysisStrainer: dialysis_strainer,
  1956. Chaptalization: chaptalization,
  1957. WashingTime: washing_time,
  1958. WarshCount: warsh_count,
  1959. BloodAccessPartId: blood_access_part_id,
  1960. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1961. Dialyzate: dialyzate,
  1962. DialysisDialyszersId: dialysis_dialyszers_id,
  1963. DialysisIrrigationId: dialysis_irrigation_id,
  1964. DialysisStrainerId: dialysis_strainer_id,
  1965. FirstSuper: first_sup,
  1966. IsSequential: is_sequent,
  1967. Conduct: conduct,
  1968. }
  1969. if adminUserInfo.Org.Id == 10721 {
  1970. if prescription.ModeId == 2 {
  1971. if prescription.ReplacementTotal == 0 {
  1972. prescription.ReplacementTotal = 15
  1973. }
  1974. }
  1975. }
  1976. //查询最近透析准备表里是否存在 透析器 灌流器
  1977. //
  1978. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1979. //
  1980. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1981. //
  1982. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1983. //if len(mation)>0{
  1984. // for _, item := range splitStr {
  1985. // for _,it := range mation{
  1986. // if(item == it.SpecificationName){
  1987. //
  1988. // //查询最近一次的透析器
  1989. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1990. //
  1991. // if errcode == gorm.ErrRecordNotFound{
  1992. // //插入数据
  1993. // prepare := models.DialysisBeforePrepare{
  1994. // UserOrgId: adminUserInfo.Org.Id,
  1995. // PatientId: id,
  1996. // RecordDate: recordDate.Unix(),
  1997. // GoodTypeId: it.GoodTypeId,
  1998. // GoodId: it.ID,
  1999. // Count: 1,
  2000. // Ctime: time.Now().Unix(),
  2001. // Creater: adminUserInfo.AdminUser.Id,
  2002. // Status:1,
  2003. //
  2004. // }
  2005. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2006. // fmt.Println("",errcode)
  2007. // }
  2008. // }
  2009. // }
  2010. //
  2011. // }
  2012. //
  2013. // for _, item := range splitIrrigation {
  2014. // for _,it := range mation{
  2015. // if(item == it.SpecificationName){
  2016. // //查询最近一次的透析器
  2017. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2018. // if errcode == gorm.ErrRecordNotFound{
  2019. // //插入数据
  2020. // prepare := models.DialysisBeforePrepare{
  2021. // UserOrgId: adminUserInfo.Org.Id,
  2022. // PatientId: id,
  2023. // RecordDate: recordDate.Unix(),
  2024. // GoodTypeId: it.GoodTypeId,
  2025. // GoodId: it.ID,
  2026. // Count: 1,
  2027. // Ctime: time.Now().Unix(),
  2028. // Creater: adminUserInfo.AdminUser.Id,
  2029. // Status:1,
  2030. //
  2031. // }
  2032. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2033. // fmt.Println(errcode)
  2034. // }
  2035. // }
  2036. // }
  2037. // }
  2038. //}
  2039. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2040. if dialysisPrescription.ID == 0 { //新增
  2041. if appRole.UserType == 2 || appRole.UserType == 1 {
  2042. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2043. }
  2044. prescription.Creater = adminUserInfo.AdminUser.Id
  2045. //针对河间咸得
  2046. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2047. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2048. prescription.DisplaceLiquiPart = 0
  2049. prescription.DisplaceLiquiValue = 0
  2050. }
  2051. }
  2052. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2053. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2054. }
  2055. err := service.AddSigleRecord(&prescription)
  2056. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2057. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  2058. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2059. if len(monitorList) > 0 {
  2060. var ultrafiltration_rate float64
  2061. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2062. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2063. var replacement_rate float64
  2064. if adminUserInfo.Org.Id == 10721 {
  2065. //乘10 除10是为了保留一位小数
  2066. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2067. }
  2068. if adminUserInfo.Org.Id == 9478 {
  2069. //乘10 除10是为了保留一位小数
  2070. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2071. }
  2072. var firstOpeateTime = monitorList[0].OperateTime
  2073. for _, item := range monitorList {
  2074. //超滤率
  2075. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2076. //置换率
  2077. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2078. //超滤量
  2079. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2080. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2081. //置换量
  2082. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2083. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2084. }
  2085. }
  2086. }
  2087. //记录日志
  2088. byterequest, _ := json.Marshal(prescription)
  2089. prescriptionLog := models.XtDialysisPrescriptionLog{
  2090. UserOrgId: prescription.UserOrgId,
  2091. Ctime: time.Now().Unix(),
  2092. Mtime: 0,
  2093. ErrLog: string(byterequest),
  2094. AdminUserId: adminUserInfo.AdminUser.Id,
  2095. RecordDate: prescription.RecordDate,
  2096. PatientId: prescription.PatientId,
  2097. Source: "手机端新增保存处方",
  2098. Status: 1,
  2099. }
  2100. service.CreatePrescriptionLog(prescriptionLog)
  2101. finish := models.XtDialysisFinish{
  2102. IsFinish: 1,
  2103. UserOrgId: adminUserInfo.Org.Id,
  2104. Status: 1,
  2105. Ctime: time.Now().Unix(),
  2106. Mtime: 0,
  2107. Module: 1,
  2108. RecordDate: recordDate.Unix(),
  2109. Sourse: 1,
  2110. PatientId: id,
  2111. }
  2112. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2113. if dialysisFinish.ID == 0 {
  2114. service.CreateDialysisFinish(finish)
  2115. }
  2116. //长沙南雅医院,自动生成抗凝剂的临时处方
  2117. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2118. if prescribing_number == 0 {
  2119. prescribing_number = 1
  2120. }
  2121. if prescribing_number == 0 && id == 14682 {
  2122. prescribing_number = 2
  2123. }
  2124. if prescribing_number == 0 && id == 18560 {
  2125. prescribing_number = 2
  2126. }
  2127. advice := models.DoctorAdvice{
  2128. UserOrgId: adminUserInfo.Org.Id,
  2129. PatientId: id,
  2130. GroupNo: 0,
  2131. AdviceType: 2,
  2132. RecordDate: recordDate.Unix(),
  2133. AdviceDate: recordDate.Unix(),
  2134. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2135. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2136. AdviceDesc: "",
  2137. ReminderDate: 0,
  2138. SingleDose: anticoagulant_zongliang,
  2139. SingleDoseUnit: "iu",
  2140. DrugSpec: 0,
  2141. DrugSpecUnit: "",
  2142. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2143. PrescribingNumberUnit: "支",
  2144. DeliveryWay: "静脉注射",
  2145. ExecutionFrequency: "上机前",
  2146. AdviceDoctor: 0,
  2147. Status: 1,
  2148. CreatedTime: time.Now().Unix(),
  2149. UpdatedTime: time.Now().Unix(),
  2150. IsPrescription: 1,
  2151. ExecutionState: 2,
  2152. StopState: 2,
  2153. IsSettle: 2,
  2154. }
  2155. // 查询排班信息
  2156. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2157. if schedulePatient.ID > 0 {
  2158. if schedulePatient.ScheduleType == 1 {
  2159. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2160. }
  2161. if schedulePatient.ScheduleType == 2 {
  2162. advice.StartTime = recordDate.Unix() + 9*60*60
  2163. }
  2164. }
  2165. // 抗凝剂名称
  2166. switch anticoagulant {
  2167. case 1:
  2168. advice.AdviceName = "无肝素"
  2169. break
  2170. case 2:
  2171. advice.AdviceName = "普通肝素"
  2172. break
  2173. case 3:
  2174. advice.AdviceName = "低分子肝素"
  2175. break
  2176. case 4:
  2177. advice.AdviceName = "阿加曲班"
  2178. break
  2179. case 5:
  2180. advice.AdviceName = "枸橼酸钠"
  2181. break
  2182. case 6:
  2183. advice.AdviceName = "低分子肝素钙"
  2184. break
  2185. case 7:
  2186. advice.AdviceName = "低分子肝素钠"
  2187. break
  2188. case 8:
  2189. advice.AdviceName = "依诺肝素"
  2190. break
  2191. case 9:
  2192. advice.AdviceName = "达肝素"
  2193. break
  2194. case 10:
  2195. advice.AdviceName = "体外抗凝"
  2196. break
  2197. case 11:
  2198. advice.AdviceName = "那曲肝素"
  2199. break
  2200. case 12:
  2201. advice.AdviceName = "无抗凝剂"
  2202. break
  2203. }
  2204. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2205. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2206. advice.AdviceDoctor = appRole.AdminUserId
  2207. }
  2208. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2209. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2210. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2211. advice.AdviceName = "低分子肝素钠注射液"
  2212. // 修改患者临时医嘱里的抗凝剂医嘱
  2213. advice.ID = advicePrescription.ID
  2214. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2215. } else {
  2216. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2217. advice.AdviceName = "低分子肝素钠注射液"
  2218. // 新增患者临时医嘱里的抗凝剂医嘱
  2219. service.CreateDoctorAdvice(&advice)
  2220. }
  2221. }
  2222. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2223. redis := service.RedisClient()
  2224. defer redis.Close()
  2225. //清空key 值
  2226. redis.Set(key, "", time.Second)
  2227. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2228. redis.Set(keyOne, "", time.Second)
  2229. }
  2230. //获取key,清空redis
  2231. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2232. redis := service.RedisClient()
  2233. //清空key 值
  2234. redis.Set(key, "", time.Second)
  2235. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2236. //清空key 值
  2237. redis.Set(keyOne, "", time.Second)
  2238. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2239. //清空key 值
  2240. redis.Set(keyTwo, "", time.Second)
  2241. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2242. redis.Set(keySix, "", time.Second)
  2243. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2244. redis.Set(keySeven, "", time.Second)
  2245. if err == nil {
  2246. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2247. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2248. //清空key 值
  2249. redis.Set(keyThree, "", time.Second)
  2250. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2251. //清空key 值
  2252. redis.Set(keyFour, "", time.Second)
  2253. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2254. redis.Set(keyFive, "", time.Second)
  2255. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2256. redis.Set(keySix, "", time.Second)
  2257. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2258. redis.Set(keySeven, "", time.Second)
  2259. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2260. //清空key 值
  2261. redis.Set(keyOne, "", time.Second)
  2262. if updateErr != nil {
  2263. utils.ErrorLog("%v", updateErr)
  2264. }
  2265. defer redis.Close()
  2266. c.ServeSuccessJSON(map[string]interface{}{
  2267. "prescription": prescription,
  2268. })
  2269. }
  2270. } else { //修改
  2271. //if mode_id > 0 {
  2272. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2273. //}
  2274. //if template.TemplateId == 1 {
  2275. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2276. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2277. // if getPermissionErr != nil {
  2278. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2279. // return
  2280. // } else if headNursePermission == nil {
  2281. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2282. // return
  2283. // }
  2284. // }
  2285. //}
  2286. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2287. prescription.Modifier = adminUserInfo.AdminUser.Id
  2288. if appRole.UserType == 2 || appRole.UserType == 1 {
  2289. prescription_doctor := adminUserInfo.AdminUser.Id
  2290. prescription.PrescriptionDoctor = prescription_doctor
  2291. } else {
  2292. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2293. }
  2294. if dialysisPrescription.Creater == 0 { //体重称
  2295. prescription.Creater = adminUserInfo.AdminUser.Id
  2296. } else {
  2297. prescription.Creater = dialysisPrescription.Creater
  2298. if adminUserInfo.Org.Id == 9882 {
  2299. if appRole.UserType == 2 || appRole.UserType == 1 {
  2300. prescription_doctor := adminUserInfo.AdminUser.Id
  2301. prescription.PrescriptionDoctor = prescription_doctor
  2302. prescription.Creater = prescription_doctor
  2303. }
  2304. }
  2305. }
  2306. prescription.ID = dialysisPrescription.ID
  2307. if adminUserInfo.Org.Id == 10721 {
  2308. if prescription.ModeId == 2 {
  2309. if prescription.ReplacementTotal == 0 {
  2310. prescription.ReplacementTotal = 15
  2311. }
  2312. }
  2313. }
  2314. service.UpDateDialysisPrescription(&prescription)
  2315. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2316. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2317. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2318. if len(monitorList) > 0 {
  2319. var ultrafiltration_rate float64
  2320. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2321. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2322. var replacement_rate float64
  2323. if adminUserInfo.Org.Id == 10721 {
  2324. //乘10 除10是为了保留一位小数
  2325. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2326. }
  2327. if adminUserInfo.Org.Id == 9478 {
  2328. //乘10 除10是为了保留一位小数
  2329. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2330. }
  2331. var firstOpeateTime = monitorList[0].OperateTime
  2332. for _, item := range monitorList {
  2333. //超滤率
  2334. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2335. //置换率
  2336. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2337. //超滤量
  2338. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2339. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2340. //置换量
  2341. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2342. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2343. }
  2344. }
  2345. }
  2346. //记录日志
  2347. byterequest, _ := json.Marshal(prescription)
  2348. prescriptionLog := models.XtDialysisPrescriptionLog{
  2349. UserOrgId: prescription.UserOrgId,
  2350. Ctime: time.Now().Unix(),
  2351. Mtime: 0,
  2352. ErrLog: string(byterequest),
  2353. AdminUserId: adminUserInfo.AdminUser.Id,
  2354. RecordDate: prescription.RecordDate,
  2355. PatientId: prescription.PatientId,
  2356. Source: "手机端修改处方",
  2357. Status: 1,
  2358. }
  2359. service.CreatePrescriptionLog(prescriptionLog)
  2360. finish := models.XtDialysisFinish{
  2361. IsFinish: 1,
  2362. UserOrgId: adminUserInfo.Org.Id,
  2363. Status: 1,
  2364. Ctime: time.Now().Unix(),
  2365. Mtime: 0,
  2366. Module: 1,
  2367. RecordDate: recordDate.Unix(),
  2368. Sourse: 1,
  2369. PatientId: id,
  2370. }
  2371. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2372. if dialysisFinish.ID == 0 {
  2373. service.CreateDialysisFinish(finish)
  2374. }
  2375. //修改处方
  2376. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2377. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2378. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2379. if advicePrescription.ID > 0 {
  2380. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2381. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2382. redis := service.RedisClient()
  2383. defer redis.Close()
  2384. //清空key 值
  2385. redis.Set(key, "", time.Second)
  2386. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2387. redis.Set(keyOne, "", time.Second)
  2388. }
  2389. }
  2390. //获取key,清空redis
  2391. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2392. redis := service.RedisClient()
  2393. //清空key 值
  2394. redis.Set(key, "", time.Second)
  2395. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2396. //清空key 值
  2397. redis.Set(keyOne, "", time.Second)
  2398. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2399. redis.Set(keySix, "", time.Second)
  2400. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2401. redis.Set(keySeven, "", time.Second)
  2402. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2403. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2404. //清空key 值
  2405. redis.Set(keyTwoOne, "", time.Second)
  2406. defer redis.Close()
  2407. if updateErr != nil {
  2408. utils.ErrorLog("%v", updateErr)
  2409. }
  2410. c.ServeSuccessJSON(map[string]interface{}{
  2411. "prescription": prescription,
  2412. })
  2413. }
  2414. }
  2415. func (c *DialysisAPIController) Finish() {
  2416. id, _ := c.GetInt64("patient", 0)
  2417. recordDateStr := c.GetString("record_date")
  2418. nurseID, _ := c.GetInt64("nurse")
  2419. end_time := c.GetString("end_time")
  2420. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2421. internal_fistula := c.GetString("blood_access_internal_fistula")
  2422. catheter := c.GetString("catheter")
  2423. cruor := c.GetString("cruor")
  2424. mission := c.GetString("mission")
  2425. condenser := c.GetString("condenser")
  2426. if id <= 0 || nurseID <= 0 {
  2427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2428. return
  2429. }
  2430. adminUserInfo := c.GetMobileAdminUserInfo()
  2431. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2432. if patient.ID == 0 {
  2433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2434. return
  2435. }
  2436. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2437. if getNurseErr != nil {
  2438. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2440. return
  2441. } else if nurse == nil {
  2442. c.ErrorLog("护士不存在")
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2444. return
  2445. }
  2446. if len(recordDateStr) == 0 {
  2447. recordDateStr = time.Now().Format("2006-01-02")
  2448. }
  2449. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2450. if parseDateErr != nil {
  2451. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2453. return
  2454. }
  2455. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2456. if parseEndDateErr != nil {
  2457. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2459. return
  2460. }
  2461. // 查询信息规挡的设置天数
  2462. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2463. if infor.ID > 0 && infor.WeekDay > 0 {
  2464. var cha_time int64
  2465. timeNowStr := time.Now().Format("2006-01-02")
  2466. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2467. //今日的日期减去设置的日期
  2468. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2469. if cha_time >= recordDate.Unix() {
  2470. //查询审核是否允许
  2471. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2472. //申请状态不允许的情况 拒绝修改
  2473. if infor.ApplicationStatus != 1 {
  2474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2475. return
  2476. }
  2477. }
  2478. }
  2479. //now := time.Now()
  2480. //year, month, day := now.Date()
  2481. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2482. //todayTimeStamp := today_time.Unix()
  2483. // 获取当天的第一条透析纪录
  2484. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2485. if getMonitorRecordsErr != nil {
  2486. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2488. return
  2489. }
  2490. // 获取当前的最后一条透析纪录
  2491. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2492. if getMonitorRecordsErr != nil {
  2493. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2495. return
  2496. }
  2497. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2498. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2499. if getAADErr != nil {
  2500. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2502. return
  2503. }
  2504. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2505. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2506. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2507. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2508. if assessmentAfterDislysis != nil {
  2509. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2510. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2511. } else {
  2512. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2513. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2514. tempassessmentAfterDislysis.Status = 1
  2515. tempassessmentAfterDislysis.PatientId = id
  2516. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2517. }
  2518. //长沙南雅
  2519. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2520. //获取最后一条透析处方数据
  2521. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2522. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2523. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2524. }
  2525. if dialysisOrder.Stage == 1 {
  2526. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2527. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2528. fmt.Println(value)
  2529. a, b := math.Modf(value)
  2530. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2531. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2532. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2533. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2534. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2535. }
  2536. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2537. //var num1 int64
  2538. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2539. //fmt.Println(num1)
  2540. //sub := float64(num1 / 3600)
  2541. //fmt.Println(sub)
  2542. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2543. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2544. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2545. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2546. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2547. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2548. if adminUserInfo.Org.Id != 10375 {
  2549. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2550. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2551. }
  2552. if adminUserInfo.Org.Id != 10445 {
  2553. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2554. }
  2555. //北方营口医院
  2556. if adminUserInfo.Org.Id == 10445 {
  2557. //获取最后一条透析处方数据
  2558. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2559. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2560. } else {
  2561. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2562. }
  2563. //新化博翔
  2564. if adminUserInfo.Org.Id == 10447 {
  2565. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2566. }
  2567. //阳春
  2568. if adminUserInfo.Org.Id == 10485 {
  2569. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2570. }
  2571. if adminUserInfo.Org.Id == 10551 {
  2572. //获取最后一条透析处方数据
  2573. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2574. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2575. }
  2576. if adminUserInfo.Org.Id == 10580 {
  2577. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2578. }
  2579. if adminUserInfo.Org.Id == 10612 {
  2580. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2581. }
  2582. //孝康
  2583. if adminUserInfo.Org.Id == 10693 {
  2584. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2585. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2586. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2587. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2588. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2589. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2590. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2591. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2592. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2593. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2594. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2595. }
  2596. if adminUserInfo.Org.Id == 10721 {
  2597. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2598. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2599. }
  2600. if adminUserInfo.Org.Id == 10697 {
  2601. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2602. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2603. lastWeightAfter.LastAfterWeight = floatAfeter
  2604. }
  2605. if adminUserInfo.Org.Id == 10624 {
  2606. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2607. }
  2608. }
  2609. 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 || adminUserInfo.Org.Id == 10742 {
  2610. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2611. if adminUserInfo.Org.Id != 10702 {
  2612. if evaluation.SystolicBloodPressure == 0 {
  2613. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2614. if adminUserInfo.Org.Id == 10693 {
  2615. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2616. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2617. }
  2618. pre := models.PredialysisEvaluation{
  2619. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2620. }
  2621. fmt.Println("prew", pre)
  2622. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2623. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2624. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2625. redis := service.RedisClient()
  2626. redis.Set(key, "", time.Second)
  2627. redis.Set(keyOne, "", time.Second)
  2628. defer redis.Close()
  2629. fmt.Println(getNurseErr)
  2630. }
  2631. }
  2632. if adminUserInfo.Org.Id != 10702 {
  2633. if evaluation.DiastolicBloodPressure == 0 {
  2634. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2635. if adminUserInfo.Org.Id == 10693 {
  2636. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2637. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2638. }
  2639. pres := models.PredialysisEvaluation{
  2640. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2641. }
  2642. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2643. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2644. redis := service.RedisClient()
  2645. redis.Set(key, "", time.Second)
  2646. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2647. redis.Set(keyOne, "", time.Second)
  2648. defer redis.Close()
  2649. fmt.Println(getNurseErr)
  2650. }
  2651. }
  2652. if adminUserInfo.Org.Id != 10702 {
  2653. if evaluation.PulseFrequency == 0 {
  2654. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2655. if adminUserInfo.Org.Id == 10693 {
  2656. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2657. evaluation.PulseFrequency = pulseFrequency
  2658. }
  2659. press := models.PredialysisEvaluation{
  2660. PulseFrequency: evaluation.PulseFrequency,
  2661. }
  2662. getNurseErr := service.UpdatePredialysisEvaluationThree(&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 evaluation.Temperature == 0 {
  2673. evaluation.Temperature = fmonitorRecords.Temperature
  2674. press := models.PredialysisEvaluation{
  2675. Temperature: evaluation.Temperature,
  2676. }
  2677. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2678. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2679. redis := service.RedisClient()
  2680. redis.Set(key, "", time.Second)
  2681. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2682. redis.Set(keyOne, "", time.Second)
  2683. defer redis.Close()
  2684. fmt.Println(getNurseErr)
  2685. }
  2686. }
  2687. if adminUserInfo.Org.Id == 9583 {
  2688. //获取透析处方的最后一条数据
  2689. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2690. if diaerr != nil {
  2691. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2693. return
  2694. }
  2695. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2696. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2697. }
  2698. }
  2699. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2700. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2701. }
  2702. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2703. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2704. }
  2705. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2706. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2707. }
  2708. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2709. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2710. }
  2711. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2712. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2713. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2714. }
  2715. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2716. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2717. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2718. }
  2719. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2720. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2721. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2722. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2723. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2724. }
  2725. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2726. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2727. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2728. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2729. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2730. }
  2731. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2732. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2733. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2734. }
  2735. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2736. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2737. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2738. }
  2739. if lastAssessmentAfterDislysis != nil {
  2740. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2741. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2742. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2743. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2744. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2745. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2746. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2747. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2748. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2749. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2750. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2751. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2752. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2753. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2754. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2755. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2756. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2757. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2758. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2759. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2760. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2761. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2762. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2763. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2764. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2765. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2766. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2767. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2768. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2769. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2770. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2771. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2772. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2773. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2774. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2775. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2776. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2777. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2778. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2779. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2780. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2781. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2782. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2783. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2784. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2785. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2786. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2787. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2788. if tempassessmentAfterDislysis.PatientId == 18695 {
  2789. tempassessmentAfterDislysis.ActualDisplacement = 0
  2790. }
  2791. if adminUserInfo.Org.Id != 10375 {
  2792. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2793. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2794. }
  2795. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2796. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2797. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2798. }
  2799. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2800. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2801. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2802. }
  2803. }
  2804. finish := models.XtDialysisFinish{
  2805. IsFinish: 1,
  2806. UserOrgId: adminUserInfo.Org.Id,
  2807. Status: 1,
  2808. Ctime: time.Now().Unix(),
  2809. Mtime: 0,
  2810. Module: 9,
  2811. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2812. Sourse: 1,
  2813. PatientId: tempassessmentAfterDislysis.PatientId,
  2814. }
  2815. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2816. if dialysisFinish.ID == 0 {
  2817. service.CreateDialysisFinish(finish)
  2818. }
  2819. //孝康
  2820. if adminUserInfo.Org.Id == 10693 {
  2821. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2822. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2823. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2824. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2825. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2826. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2827. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2828. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2829. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2830. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2831. }
  2832. if adminUserInfo.Org.Id == 10697 {
  2833. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2834. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2835. lastWeightAfter.LastAfterWeight = floatAfeter
  2836. }
  2837. if adminUserInfo.Org.Id == 10721 {
  2838. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2839. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2840. }
  2841. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2842. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2843. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2844. redis := service.RedisClient()
  2845. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2846. redis.Set(keyOne, "", time.Second)
  2847. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2848. redis.Set(keyTwo, "", time.Second)
  2849. defer redis.Close()
  2850. //清空key 值
  2851. redis.Set(key, "", time.Second)
  2852. if err != nil {
  2853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2854. return
  2855. }
  2856. if dialysisOrder == nil {
  2857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2858. return
  2859. }
  2860. if dialysisOrder.Stage == 2 {
  2861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2862. return
  2863. }
  2864. if dialysisOrder.Stage == 1 {
  2865. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2866. finish := models.XtDialysisFinish{
  2867. IsFinish: 1,
  2868. UserOrgId: adminUserInfo.Org.Id,
  2869. Status: 1,
  2870. Ctime: time.Now().Unix(),
  2871. Mtime: 0,
  2872. Module: 8,
  2873. RecordDate: recordDate.Unix(),
  2874. Sourse: 1,
  2875. PatientId: id,
  2876. }
  2877. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2878. if dialysisFinish.ID == 0 {
  2879. service.CreateDialysisFinish(finish)
  2880. }
  2881. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2882. redis := service.RedisClient()
  2883. defer redis.Close()
  2884. //清空key 值
  2885. redis.Set(key, "", time.Second)
  2886. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2887. redis.Set(keyOne, "", time.Second)
  2888. //结束时候透析次数加1
  2889. service.UpdateSolutionByPatientId(id)
  2890. //下机完自动消毒,针对长沙南雅
  2891. if dialysisOrder.Stage == 1 {
  2892. 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 {
  2893. //根据床位号获取设备型号
  2894. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2895. //查询使用消毒最后一条消毒记录
  2896. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2897. fmt.Println("err", err)
  2898. if err == gorm.ErrRecordNotFound {
  2899. //查找排班
  2900. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2901. //查询改设备是否有消毒计划
  2902. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2903. //根据床位号获取设备id
  2904. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2905. //查询病人信息
  2906. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2907. var con = ""
  2908. if patients.IsInfectious == 0 {
  2909. con = ""
  2910. }
  2911. if patients.IsInfectious == 1 {
  2912. con = "无"
  2913. }
  2914. if patients.IsInfectious == 2 {
  2915. con = "有"
  2916. }
  2917. if errcode == nil {
  2918. var end_time int64
  2919. end_time = endDate.Unix() + plan.DisinfecTime*60
  2920. //新增消毒
  2921. information := models.DeviceInformation{
  2922. Date: dialysisOrder.DialysisDate,
  2923. Zone: dialysisOrder.ZoneId,
  2924. Class: dialysisOrder.SchedualType,
  2925. BedNumber: dialysisOrder.BedID,
  2926. PatientId: dialysisOrder.PatientId,
  2927. DialysisMode: scheduleByPatient.ModeId,
  2928. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2929. Disinfection: 1,
  2930. DialysisConcentration: 1,
  2931. DisinfectionStatus: 1,
  2932. Move: 1,
  2933. UserOrgId: dialysisOrder.UserOrgId,
  2934. DisinfectType: plan.Way,
  2935. DisinfectantType: plan.MachineDisinfectant,
  2936. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2937. Disinfectant: plan.Disinfectant,
  2938. Ctime: time.Now().Unix(),
  2939. Status: 1,
  2940. SignName: nurseID,
  2941. EquimentId: addmacher.ID,
  2942. DisinfectionResidue: 2,
  2943. Bed: addmacher.BedNumber,
  2944. StartTime: dialysisOrder.StartTime,
  2945. EndTime: dialysisOrder.EndTime,
  2946. Contagion: con,
  2947. WeightLoss: 0,
  2948. Hyperfiltratio: 0,
  2949. DialysisHour: "",
  2950. MachineRun: 1,
  2951. DisinfecStartime: endDate.Unix(),
  2952. DisinfecEndtime: end_time,
  2953. }
  2954. err := service.CreateInformationTwo(&information)
  2955. fmt.Println("报错", err)
  2956. }
  2957. }
  2958. }
  2959. }
  2960. dialysisOrder.Stage = 2
  2961. dialysisOrder.FinishNurse = nurseID
  2962. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2963. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2964. dialysisOrder.EndTime = endDate.Unix()
  2965. // 长沙南雅需求
  2966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2967. //获取最后1条监测的数据
  2968. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2969. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2970. var accumulatedBloodVolume float64
  2971. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2972. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2973. fmt.Println(err)
  2974. // 查询未执行的医嘱
  2975. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2976. for _, item := range doctorAdvice {
  2977. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2978. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2979. redis := service.RedisClient()
  2980. //清空key 值
  2981. redis.Set(key, "", time.Second)
  2982. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2983. redis.Set(keyTwo, "", time.Second)
  2984. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2985. redis.Set(keyThree, "", time.Second)
  2986. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2987. theTime := toTime.Format("2006-01-02")
  2988. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2989. redis.Set(keyFour, "", time.Second)
  2990. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2991. redis.Set(keyFive, "", time.Second)
  2992. defer redis.Close()
  2993. }
  2994. }
  2995. go func() {
  2996. ssoDomain := beego.AppConfig.String("call_domain")
  2997. api := ssoDomain + "/index/downpatient"
  2998. values := make(url.Values)
  2999. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  3000. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3001. values.Set("patient_id", strconv.FormatInt(id, 10))
  3002. http.PostForm(api, values)
  3003. }()
  3004. if err == nil {
  3005. c.ServeSuccessJSON(map[string]interface{}{
  3006. "dialysisOrder": dialysisOrder,
  3007. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  3008. })
  3009. } else {
  3010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3011. }
  3012. }
  3013. //查找是否开启配置
  3014. //orderSetting, _ := service.GetDialysisOrderSetting(adminUserInfo.Org.Id)
  3015. ////开启下机扣减
  3016. //if orderSetting.IsOpen == 1 {
  3017. //
  3018. // //查询今日患者排班的模式
  3019. // db := service.XTWriteDB()
  3020. // // 开始外部循环的事务
  3021. // tx := db.Begin()
  3022. // // 在函数结束时处理事务回滚
  3023. // defer func() {
  3024. // if r := recover(); r != nil {
  3025. // tx.Rollback()
  3026. // }
  3027. // }()
  3028. //
  3029. // schedule, _ := service.GetDialysisOrderSchedule(id, recordDate.Unix(), adminUserInfo.Org.Id, tx)
  3030. //
  3031. // if schedule.ModeId == 1 {
  3032. // //扣减库存
  3033. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3034. //
  3035. // patient, _ := service.GetSfPatientById(tx, id)
  3036. // var over_count int64
  3037. // if schedule.ModeId == 1 {
  3038. // over_count = patient.HdCount
  3039. // }
  3040. // if schedule.ModeId == 2 {
  3041. // over_count = patient.HdfCount
  3042. // }
  3043. //
  3044. // if schedule.ModeId == 3 {
  3045. // over_count = patient.HdhpCount
  3046. // }
  3047. // if schedule.ModeId == 4 {
  3048. // over_count = patient.HpCount
  3049. // }
  3050. // if schedule.ModeId == 5 {
  3051. // over_count = patient.OtherCount
  3052. // }
  3053. // patientCountFlow := models.SfPatientCountFlow{
  3054. // PatientId: id,
  3055. // ModeId: schedule.ModeId,
  3056. // Count: 1,
  3057. // Status: 1,
  3058. // Ctime: time.Now().Unix(),
  3059. // Mtime: time.Now().Unix(),
  3060. // RecordDate: recordDate.Unix(),
  3061. // UserOrgId: adminUserInfo.Org.Id,
  3062. // Creater: adminUserInfo.AdminUser.Id,
  3063. // IsType: 1,
  3064. // OverCount: over_count,
  3065. // WarehouseOutId: 0,
  3066. // }
  3067. //
  3068. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3069. // }
  3070. //
  3071. // if schedule.ModeId == 2 {
  3072. //
  3073. // //扣减库存
  3074. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3075. //
  3076. // patient, _ := service.GetSfPatientById(tx, id)
  3077. // var over_count int64
  3078. // if schedule.ModeId == 1 {
  3079. // over_count = patient.HdCount
  3080. // }
  3081. // if schedule.ModeId == 2 {
  3082. // over_count = patient.HdfCount
  3083. // }
  3084. //
  3085. // if schedule.ModeId == 3 {
  3086. // over_count = patient.HdhpCount
  3087. // }
  3088. // if schedule.ModeId == 4 {
  3089. // over_count = patient.HpCount
  3090. // }
  3091. // if schedule.ModeId == 5 {
  3092. // over_count = patient.OtherCount
  3093. // }
  3094. // patientCountFlow := models.SfPatientCountFlow{
  3095. // PatientId: id,
  3096. // ModeId: schedule.ModeId,
  3097. // Count: 1,
  3098. // Status: 1,
  3099. // Ctime: time.Now().Unix(),
  3100. // Mtime: time.Now().Unix(),
  3101. // RecordDate: recordDate.Unix(),
  3102. // UserOrgId: adminUserInfo.Org.Id,
  3103. // Creater: adminUserInfo.AdminUser.Id,
  3104. // IsType: 2,
  3105. // OverCount: over_count,
  3106. // WarehouseOutId: 0,
  3107. // }
  3108. //
  3109. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3110. // }
  3111. //
  3112. // if schedule.ModeId == 3 {
  3113. //
  3114. // //扣减库存
  3115. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3116. //
  3117. // patient, _ := service.GetSfPatientById(tx, id)
  3118. // var over_count int64
  3119. // if schedule.ModeId == 1 {
  3120. // over_count = patient.HdCount
  3121. // }
  3122. // if schedule.ModeId == 2 {
  3123. // over_count = patient.HdfCount
  3124. // }
  3125. //
  3126. // if schedule.ModeId == 3 {
  3127. // over_count = patient.HdhpCount
  3128. // }
  3129. // if schedule.ModeId == 4 {
  3130. // over_count = patient.HpCount
  3131. // }
  3132. // if schedule.ModeId == 5 {
  3133. // over_count = patient.OtherCount
  3134. // }
  3135. // patientCountFlow := models.SfPatientCountFlow{
  3136. // PatientId: id,
  3137. // ModeId: schedule.ModeId,
  3138. // Count: 1,
  3139. // Status: 1,
  3140. // Ctime: time.Now().Unix(),
  3141. // Mtime: time.Now().Unix(),
  3142. // RecordDate: recordDate.Unix(),
  3143. // UserOrgId: adminUserInfo.Org.Id,
  3144. // Creater: adminUserInfo.AdminUser.Id,
  3145. // IsType: 3,
  3146. // OverCount: over_count,
  3147. // WarehouseOutId: 0,
  3148. // }
  3149. //
  3150. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3151. // }
  3152. // if schedule.ModeId == 4 {
  3153. //
  3154. // //扣减库存
  3155. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3156. //
  3157. // patient, _ := service.GetSfPatientById(tx, id)
  3158. // var over_count int64
  3159. // if schedule.ModeId == 1 {
  3160. // over_count = patient.HdCount
  3161. // }
  3162. // if schedule.ModeId == 2 {
  3163. // over_count = patient.HdfCount
  3164. // }
  3165. //
  3166. // if schedule.ModeId == 3 {
  3167. // over_count = patient.HdhpCount
  3168. // }
  3169. // if schedule.ModeId == 4 {
  3170. // over_count = patient.HpCount
  3171. // }
  3172. // if schedule.ModeId == 5 {
  3173. // over_count = patient.OtherCount
  3174. // }
  3175. // patientCountFlow := models.SfPatientCountFlow{
  3176. // PatientId: id,
  3177. // ModeId: schedule.ModeId,
  3178. // Count: 1,
  3179. // Status: 1,
  3180. // Ctime: time.Now().Unix(),
  3181. // Mtime: time.Now().Unix(),
  3182. // RecordDate: recordDate.Unix(),
  3183. // UserOrgId: adminUserInfo.Org.Id,
  3184. // Creater: adminUserInfo.AdminUser.Id,
  3185. // IsType: 4,
  3186. // OverCount: over_count,
  3187. // WarehouseOutId: 0,
  3188. // }
  3189. //
  3190. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3191. // }
  3192. // if schedule.ModeId != 1 && schedule.ModeId != 2 && schedule.ModeId != 3 && schedule.ModeId != 4 {
  3193. //
  3194. // //扣减库存
  3195. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3196. //
  3197. // patient, _ := service.GetSfPatientById(tx, id)
  3198. // var over_count int64
  3199. // if schedule.ModeId == 1 {
  3200. // over_count = patient.HdCount
  3201. // }
  3202. // if schedule.ModeId == 2 {
  3203. // over_count = patient.HdfCount
  3204. // }
  3205. //
  3206. // if schedule.ModeId == 3 {
  3207. // over_count = patient.HdhpCount
  3208. // }
  3209. // if schedule.ModeId == 4 {
  3210. // over_count = patient.HpCount
  3211. // }
  3212. // if schedule.ModeId == 5 {
  3213. // over_count = patient.OtherCount
  3214. // }
  3215. // patientCountFlow := models.SfPatientCountFlow{
  3216. // PatientId: id,
  3217. // ModeId: schedule.ModeId,
  3218. // Count: 1,
  3219. // Status: 1,
  3220. // Ctime: time.Now().Unix(),
  3221. // Mtime: time.Now().Unix(),
  3222. // RecordDate: recordDate.Unix(),
  3223. // UserOrgId: adminUserInfo.Org.Id,
  3224. // Creater: adminUserInfo.AdminUser.Id,
  3225. // IsType: 5,
  3226. // OverCount: over_count,
  3227. // WarehouseOutId: 0,
  3228. // }
  3229. //
  3230. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3231. // }
  3232. //
  3233. // tx.Commit()
  3234. // return
  3235. //}
  3236. }
  3237. func (c *DialysisAPIController) GetAllZone() {
  3238. adminUserInfo := c.GetMobileAdminUserInfo()
  3239. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3240. if err == nil {
  3241. c.ServeSuccessJSON(map[string]interface{}{
  3242. "zone": zone,
  3243. })
  3244. }
  3245. }
  3246. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3247. adminUserInfo := c.GetMobileAdminUserInfo()
  3248. page, _ := c.GetInt64("page", 1)
  3249. limit, _ := c.GetInt64("limit", 10)
  3250. schedulType, _ := c.GetInt64("schedul_type", 0)
  3251. startTime, _ := c.GetInt64("schedul_time", 0)
  3252. partitionType, _ := c.GetInt64("partition_type", 0)
  3253. keywords := c.GetString("keywords")
  3254. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3255. if err == nil {
  3256. c.ServeSuccessJSON(map[string]interface{}{
  3257. "schedule": dialysisSchedule,
  3258. })
  3259. }
  3260. return
  3261. }
  3262. // /m/api/dialysis/start [post]
  3263. // @param patient_id:int
  3264. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3265. // @param nurse:int 上机护士
  3266. // @param bed:int 床位号
  3267. func (this *DialysisAPIController) StartDialysis() {
  3268. patientID, _ := this.GetInt64("patient_id")
  3269. recordDateStr := this.GetString("record_date")
  3270. nurseID, _ := this.GetInt64("start_nurse")
  3271. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3272. blood_drawing, _ := this.GetInt64("blood_drawing")
  3273. schedual_type, _ := this.GetInt64("schedual_type")
  3274. bedID, _ := this.GetInt64("bed")
  3275. start_time := this.GetString("start_time")
  3276. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3277. change_nurse, _ := this.GetInt64("change_nurse")
  3278. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3279. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3280. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3281. puncture_needle := this.GetString("puncture_needle")
  3282. puncture_way := this.GetString("puncture_way")
  3283. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3284. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3285. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3286. zone_id, _ := this.GetInt64("zone_id")
  3287. elecsign := this.GetString("url")
  3288. nuclein_date_str := this.GetString("nuclein_date_str")
  3289. schedule_remark := this.GetString("schedule_remark")
  3290. order_remark := this.GetString("order_remark")
  3291. catheter_operation := this.GetString("catheter_operation")
  3292. blood_flow_volume := this.GetString("blood_flow_volume")
  3293. dialysis_strainer := this.GetString("dialysis_strainer")
  3294. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3296. return
  3297. }
  3298. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3299. if parseStartDateErr != nil {
  3300. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3302. return
  3303. }
  3304. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3305. if parseErr != nil {
  3306. this.ErrorLog("时间解析失败:%v", parseErr)
  3307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3308. return
  3309. }
  3310. adminUserInfo := this.GetMobileAdminUserInfo()
  3311. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3312. if getPatientErr != nil {
  3313. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3315. return
  3316. } else if patient == nil {
  3317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3318. return
  3319. }
  3320. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3321. if getNurseErr != nil {
  3322. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3324. return
  3325. } else if nurse == nil {
  3326. this.ErrorLog("护士不存在")
  3327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3328. return
  3329. }
  3330. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3331. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3332. if getDeviceNumberErr != nil {
  3333. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3335. return
  3336. } else if deviceNumber == nil {
  3337. this.ErrorLog("床位号不存在")
  3338. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3339. return
  3340. }
  3341. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3342. if getRecordErr != nil {
  3343. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3345. return
  3346. } else if dialysisRecord != nil {
  3347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3348. return
  3349. }
  3350. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3351. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3352. timeLayout := "2006-01-02 15:04:05"
  3353. loc, _ := time.LoadLocation("Local")
  3354. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3355. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3356. schedulestartTime := theStartTime.Unix()
  3357. scheduleendTime := theEndTime.Unix()
  3358. var theNucleinDate int64
  3359. timeLayoutOne := "2006-01-02"
  3360. if len(nuclein_date_str) > 0 {
  3361. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3362. if err != nil {
  3363. utils.ErrorLog(err.Error())
  3364. }
  3365. theNucleinDate = theTime.Unix()
  3366. }
  3367. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3368. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3369. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3370. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3371. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3372. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3373. if record.ID == 0 {
  3374. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3375. return
  3376. }
  3377. }
  3378. //查询该床位是否有人用了
  3379. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3380. if err == gorm.ErrRecordNotFound { //空床位
  3381. // 修改了床位逻辑
  3382. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3383. if daySchedule.ID > 0 {
  3384. daySchedule.PartitionId = deviceNumber.ZoneID
  3385. daySchedule.BedId = bedID
  3386. daySchedule.ScheduleType = schedual_type
  3387. daySchedule.UpdatedTime = time.Now().Unix()
  3388. xtSchedule := models.Schedule{
  3389. PartitionId: deviceNumber.ZoneID,
  3390. BedId: bedID,
  3391. ScheduleType: schedual_type,
  3392. UpdatedTime: time.Now().Unix(),
  3393. }
  3394. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3395. if err != nil {
  3396. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3397. return
  3398. }
  3399. }
  3400. } else if err == nil {
  3401. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3402. if order.ID > 0 { //该机位被其他人占用了
  3403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3404. return
  3405. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3406. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3407. if daySchedule.ID > 0 {
  3408. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3409. if err != nil {
  3410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3411. return
  3412. }
  3413. }
  3414. }
  3415. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3416. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3417. return
  3418. }
  3419. //else if order.ID == 0 { //该床位没被占用
  3420. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3421. // if daySchedule.ID > 0 {
  3422. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3423. // //daySchedule.BedId = bedID
  3424. // //daySchedule.ScheduleType = schedual_type
  3425. // //daySchedule.UpdatedTime = time.Now().Unix()
  3426. // //err := service.UpdateSchedule(&daySchedule)
  3427. // xtSchedule := models.Schedule{
  3428. // PartitionId: deviceNumber.ZoneID,
  3429. // BedId: bedID,
  3430. // ScheduleType: schedual_type,
  3431. // UpdatedTime: time.Now().Unix(),
  3432. // }
  3433. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3434. // if err != nil {
  3435. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3436. // return
  3437. // }
  3438. // }
  3439. //}
  3440. //}
  3441. } else if err != nil {
  3442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3443. return
  3444. }
  3445. // 查询信息规挡的设置天数
  3446. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3447. if infor.ID > 0 && infor.WeekDay > 0 {
  3448. var cha_time int64
  3449. timeNowStr := time.Now().Format("2006-01-02")
  3450. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3451. //今日的日期减去设置的日期
  3452. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3453. if cha_time >= recordDate.Unix() {
  3454. //查询审核是否允许
  3455. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3456. //申请状态不允许的情况 拒绝修改
  3457. if infor.ApplicationStatus != 1 {
  3458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3459. return
  3460. }
  3461. }
  3462. }
  3463. dialysisRecord = &models.DialysisOrder{
  3464. DialysisDate: recordDate.Unix(),
  3465. UserOrgId: adminUserInfo.Org.Id,
  3466. PatientId: patientID,
  3467. Stage: 1,
  3468. BedID: bedID,
  3469. StartNurse: nurseID,
  3470. Status: 1,
  3471. StartTime: startDate.Unix(),
  3472. CreatedTime: time.Now().Unix(),
  3473. UpdatedTime: time.Now().Unix(),
  3474. PunctureNurse: puncture_nurse,
  3475. Creator: adminUserInfo.AdminUser.Id,
  3476. Modifier: adminUserInfo.AdminUser.Id,
  3477. SchedualType: schedual_type,
  3478. WashpipeNurse: washpipe_nurse,
  3479. ChangeNurse: change_nurse,
  3480. DifficultPunctureNurse: difficult_puncture_nurse,
  3481. NewFistulaNurse: new_fistula_nurse,
  3482. ZoneId: zone_id,
  3483. QualityNurseId: quality_nurse_id,
  3484. PunctureNeedle: puncture_needle,
  3485. PunctureWay: puncture_way,
  3486. DialysisIrrigation: dialysis_irrigation,
  3487. DialysisDialyszers: dialysis_dialyszers,
  3488. BloodAccessId: blood_access_id,
  3489. Url: elecsign,
  3490. NucleinDate: theNucleinDate,
  3491. ScheduleRemark: schedule_remark,
  3492. OrderRemark: order_remark,
  3493. CatheterOperation: catheter_operation,
  3494. BloodFlowVolume: blood_flow_volume,
  3495. BloodDrawing: blood_drawing,
  3496. DialysisStrainer: dialysis_strainer,
  3497. }
  3498. //查询该床位是否有人用了
  3499. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3500. if errorscode == gorm.ErrRecordNotFound {
  3501. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3502. finish := models.XtDialysisFinish{
  3503. IsFinish: 1,
  3504. UserOrgId: adminUserInfo.Org.Id,
  3505. Status: 1,
  3506. Ctime: time.Now().Unix(),
  3507. Mtime: 0,
  3508. Module: 6,
  3509. RecordDate: schedulestartTime,
  3510. Sourse: 1,
  3511. PatientId: patientID,
  3512. }
  3513. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3514. if dialysisFinish.ID == 0 {
  3515. service.CreateDialysisFinish(finish)
  3516. }
  3517. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3518. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3519. //统计该患者总次数
  3520. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3521. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3522. }
  3523. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3524. //统计该患者总次数
  3525. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3526. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3527. }
  3528. redis := service.RedisClient()
  3529. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3530. redis.Set(key, "", time.Second)
  3531. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3532. //清空key 值
  3533. redis.Set(keyOne, "", time.Second)
  3534. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3535. //清空key 值
  3536. redis.Set(keyTwo, "", time.Second)
  3537. if createErr != nil {
  3538. this.ErrorLog("上机失败:%v", createErr)
  3539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3540. return
  3541. }
  3542. }
  3543. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3544. var tempdispose string
  3545. // 只针对中能建
  3546. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3547. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3548. }
  3549. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3550. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3551. }
  3552. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3553. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3554. //}
  3555. var ultrafiltration_rate float64
  3556. var ultrafiltration_rate_one string
  3557. var replacement_rate float64
  3558. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3559. //后期预增脱水量
  3560. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3561. if prescription.ID > 0 {
  3562. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3563. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3564. 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
  3565. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3566. }
  3567. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 || adminUserInfo.Org.Id == 9478 {
  3568. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3569. }
  3570. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3571. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3572. }
  3573. //针对医师汇
  3574. if adminUserInfo.Org.Id == 10121 {
  3575. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3576. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3577. }
  3578. //针对通道
  3579. if adminUserInfo.Org.Id == 10234 {
  3580. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3581. }
  3582. //针对监利大垸医院
  3583. if template.TemplateId == 41 {
  3584. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3585. }
  3586. //针对肇庆三鹤血液透析中心
  3587. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3588. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3589. }
  3590. if adminUserInfo.Org.Id == 10469 {
  3591. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3592. }
  3593. if adminUserInfo.Org.Id == 10667 {
  3594. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3595. }
  3596. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3597. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3598. }
  3599. // 只针对方济医院
  3600. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3601. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3602. ultrafiltration_rate = value
  3603. }
  3604. //针对
  3605. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3606. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3607. ultrafiltration_rate = ultrafiltration_rate / 1000
  3608. }
  3609. if adminUserInfo.Org.Id == 10551 {
  3610. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3611. ultrafiltration_rate = ultrafiltration_rate / 1000
  3612. }
  3613. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3614. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3615. ultrafiltration_rate = ultrafiltration_rate / 1000
  3616. }
  3617. if adminUserInfo.Org.Id == 10580 {
  3618. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3619. ultrafiltration_rate = ultrafiltration_rate / 1000
  3620. }
  3621. if adminUserInfo.Org.Id == 10629 {
  3622. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3623. ultrafiltration_rate = ultrafiltration_rate / 1000
  3624. }
  3625. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3626. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3627. ultrafiltration_rate = ultrafiltration_rate / 1000
  3628. }
  3629. if adminUserInfo.Org.Id == 10751 {
  3630. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3631. ultrafiltration_rate = ultrafiltration_rate / 1000
  3632. }
  3633. if adminUserInfo.Org.Id == 10667 {
  3634. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3635. ultrafiltration_rate = ultrafiltration_rate / 1000
  3636. }
  3637. if adminUserInfo.Org.Id == 10693 {
  3638. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3639. ultrafiltration_rate = ultrafiltration_rate
  3640. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3641. }
  3642. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3643. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3644. ultrafiltration_rate = ultrafiltration_rate
  3645. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3646. }
  3647. if adminUserInfo.Org.Id == 10206 {
  3648. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3649. ultrafiltration_rate = ultrafiltration_rate
  3650. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3651. }
  3652. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3653. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3654. ultrafiltration_rate = ultrafiltration_rate
  3655. }
  3656. if adminUserInfo.Org.Id == 10702 {
  3657. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3658. ultrafiltration_rate = ultrafiltration_rate / 1000
  3659. }
  3660. if adminUserInfo.Org.Id == 10752 {
  3661. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3662. ultrafiltration_rate = ultrafiltration_rate / 1000
  3663. }
  3664. if adminUserInfo.Org.Id == 10723 {
  3665. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3666. ultrafiltration_rate = ultrafiltration_rate / 1000
  3667. }
  3668. if adminUserInfo.Org.Id == 10721 {
  3669. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3670. ultrafiltration_rate = ultrafiltration_rate / 1000
  3671. }
  3672. if adminUserInfo.Org.Id == 10757 {
  3673. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3674. ultrafiltration_rate = ultrafiltration_rate / 1000
  3675. }
  3676. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10757 {
  3677. if prescription.ModeId == 2 {
  3678. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3679. if totalMin == 0 {
  3680. totalMin = 240
  3681. }
  3682. if prescription.ReplacementTotal == 0 {
  3683. prescription.ReplacementTotal = 15
  3684. }
  3685. //乘10 除10是为了保留一位小数
  3686. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3687. }
  3688. }
  3689. if adminUserInfo.Org.Id == 10752 {
  3690. if prescription.ModeId == 2 {
  3691. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3692. if totalMin == 0 {
  3693. totalMin = 240
  3694. }
  3695. if prescription.ReplacementTotal == 0 {
  3696. prescription.ReplacementTotal = 15
  3697. }
  3698. //乘10 除10是为了保留一位小数
  3699. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3700. }
  3701. }
  3702. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10744 {
  3703. if prescription.ModeId == 2 {
  3704. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3705. if totalMin == 0 {
  3706. totalMin = 240
  3707. }
  3708. if prescription.DisplaceLiquiValue == 0 {
  3709. prescription.ReplacementTotal = 32
  3710. }
  3711. //乘10 除10是为了保留一位小数
  3712. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3713. }
  3714. }
  3715. }
  3716. }
  3717. if adminUserInfo.Org.Id == 10172 {
  3718. if prescription.ID == 0 {
  3719. if prescription.ModeId == 2 {
  3720. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3721. if totalMin == 0 {
  3722. totalMin = 240
  3723. }
  3724. if prescription.ReplacementTotal == 0 {
  3725. prescription.ReplacementTotal = 15
  3726. }
  3727. //乘10 除10是为了保留一位小数
  3728. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3729. }
  3730. }
  3731. }
  3732. record := models.MonitoringRecord{
  3733. UserOrgId: adminUserInfo.Org.Id,
  3734. PatientId: patientID,
  3735. DialysisOrderId: dialysisRecord.ID,
  3736. MonitoringDate: schedulestartTime,
  3737. OperateTime: startDate.Unix(),
  3738. // MonitoringTime: recordTime,
  3739. MonitoringNurse: nurseID,
  3740. Dispose: tempdispose,
  3741. UltrafiltrationRate: ultrafiltration_rate,
  3742. UltrafiltrationVolume: 0,
  3743. Status: 1,
  3744. CreatedTime: time.Now().Unix(),
  3745. UpdatedTime: time.Now().Unix(),
  3746. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3747. ReplacementRate: replacement_rate,
  3748. }
  3749. //只针对广慈医院
  3750. 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 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10757 {
  3751. // 查询病人是否有透前评估数据
  3752. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3753. //如果有数据就插入
  3754. if errcode == nil {
  3755. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3756. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3757. record.BreathingRate = befor.BreathingRate
  3758. record.PulseFrequency = befor.PulseFrequency
  3759. record.Temperature = befor.Temperature
  3760. }
  3761. }
  3762. //孝昌
  3763. if adminUserInfo.Org.Id == 10693 {
  3764. // 查询病人是否有透前评估数据
  3765. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3766. //如果有数据就插入
  3767. if errcode == nil {
  3768. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3769. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3770. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3771. record.BreathingRate = befor.BreathingRate
  3772. }
  3773. }
  3774. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3775. if newdialysisRecord.ID > 0 {
  3776. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3777. record.Temperature = 36.5
  3778. record.ArterialPressure = -100
  3779. record.DialysateTemperature = 36.5
  3780. record.Conductivity = 14
  3781. record.BreathingRate = "20"
  3782. record.VenousPressure = 80
  3783. record.TransmembranePressure = 60
  3784. record.Dispose = catheter_operation
  3785. }
  3786. //针对新化博翔
  3787. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3788. record.BloodOxygenSaturation = "99"
  3789. record.Conductivity = 14
  3790. record.DialysateTemperature = 36.5
  3791. record.BreathingRate = "20"
  3792. }
  3793. //针对兰溪人民医院的需求
  3794. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3795. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3796. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3797. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3798. record.Temperature = befor.Temperature
  3799. record.PulseFrequency = befor.PulseFrequency
  3800. record.BreathingRate = befor.BreathingRate
  3801. }
  3802. //针对乐山友谊医院的需求
  3803. if adminUserInfo.Org.Id == 10677 {
  3804. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3805. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3806. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3807. record.Temperature = befor.Temperature
  3808. record.PulseFrequency = befor.PulseFrequency
  3809. record.BreathingRate = befor.BreathingRate
  3810. }
  3811. //新化博翔
  3812. if adminUserInfo.Org.Id == 10447 {
  3813. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3814. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3815. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3816. record.BreathingRate = befor.BreathingRate
  3817. }
  3818. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3819. record.PulseFrequency = 80
  3820. record.Temperature = 36.5
  3821. }
  3822. //诊断灵山圣康
  3823. if adminUserInfo.Org.Id == 10375 {
  3824. record.Conductivity = 13.8
  3825. record.DialysateTemperature = 37
  3826. record.DialysateFlow = 500
  3827. record.BloodFlowVolume = 200
  3828. record.BreathingRate = "18"
  3829. record.SodiumConcentration = 140
  3830. }
  3831. //江成肾病医院
  3832. if adminUserInfo.Org.Id == 10517 {
  3833. record.SodiumConcentration = 138
  3834. record.DialysateTemperature = 36.5
  3835. }
  3836. //濉溪杏康血液透析中心
  3837. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3838. record.BloodFlowVolume = prescription.BloodFlowVolume
  3839. }
  3840. //胶州少海医院
  3841. if adminUserInfo.Org.Id == 10735 {
  3842. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3843. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3844. record.BreathingRate = befor.BreathingRate
  3845. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3846. record.Temperature = befor.Temperature
  3847. record.PulseFrequency = befor.PulseFrequency
  3848. }
  3849. if adminUserInfo.Org.Id != 10683 {
  3850. err = service.CreateMonitor(&record)
  3851. }
  3852. //记录日志
  3853. byterequest, _ := json.Marshal(record)
  3854. monitorRecordLog := models.XtMonitorRecordLog{
  3855. RecordDate: record.MonitoringDate,
  3856. PatientId: record.PatientId,
  3857. Module: 1,
  3858. AdminUserId: adminUserInfo.AdminUser.Id,
  3859. Ctime: time.Now().Unix(),
  3860. Mtime: 0,
  3861. Status: 1,
  3862. UserOrgId: record.UserOrgId,
  3863. ErrLog: string(byterequest),
  3864. Source: "执行上机时新增监测",
  3865. }
  3866. service.CreateMonitorRecordLog(monitorRecordLog)
  3867. finish := models.XtDialysisFinish{
  3868. IsFinish: 1,
  3869. UserOrgId: adminUserInfo.Org.Id,
  3870. Status: 1,
  3871. Ctime: time.Now().Unix(),
  3872. Mtime: 0,
  3873. Module: 7,
  3874. RecordDate: schedulestartTime,
  3875. Sourse: 1,
  3876. PatientId: patientID,
  3877. }
  3878. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3879. if dialysisFinish.ID == 0 {
  3880. service.CreateDialysisFinish(finish)
  3881. }
  3882. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3883. redis := service.RedisClient()
  3884. //清空key 值
  3885. redis.Set(key, "", time.Second)
  3886. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3887. redis.Set(keyOne, "", time.Second)
  3888. defer redis.Close()
  3889. if err != nil {
  3890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3891. return
  3892. }
  3893. }
  3894. go func() {
  3895. ssoDomain := beego.AppConfig.String("call_domain")
  3896. api := ssoDomain + "/index/uppatient"
  3897. values := make(url.Values)
  3898. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3899. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3900. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3901. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3902. http.PostForm(api, values)
  3903. }()
  3904. this.ServeSuccessJSON(map[string]interface{}{
  3905. "dialysis_order": newdialysisRecord,
  3906. "monitor": record,
  3907. })
  3908. return
  3909. }
  3910. func (c *DialysisAPIController) PostSolution() {
  3911. id, _ := c.GetInt64("patient", 0)
  3912. recordDateStr := c.GetString("record_date")
  3913. if id <= 0 {
  3914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3915. return
  3916. }
  3917. adminUserInfo := c.GetMobileAdminUserInfo()
  3918. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3919. if patient.ID == 0 {
  3920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3921. return
  3922. }
  3923. if len(recordDateStr) == 0 {
  3924. recordDateStr = time.Now().Format("2006-01-02")
  3925. }
  3926. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3927. if parseDateErr != nil {
  3928. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3930. return
  3931. }
  3932. mode_id, _ := c.GetInt64("mode_id", 0)
  3933. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3934. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3935. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3936. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3937. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3938. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3939. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3940. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3941. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3942. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3943. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3944. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3945. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3946. kalium, _ := c.GetFloat("kalium", 0)
  3947. sodium, _ := c.GetFloat("sodium", 0)
  3948. calcium, _ := c.GetFloat("calcium", 0)
  3949. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3950. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3951. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3952. glucose, _ := c.GetFloat("glucose", 0)
  3953. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3954. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3955. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3956. conductivity, _ := c.GetFloat("conductivity", 0)
  3957. remark := c.GetString("remark")
  3958. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3959. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3960. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3961. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3962. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3963. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3964. special_medicine_other := c.GetString("special_medicine_other")
  3965. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3966. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3967. blood_access, _ := c.GetInt64("blood_access", 0)
  3968. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3969. body_fluid_other := c.GetString("body_fluid_other")
  3970. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3971. niprocart, _ := c.GetInt64("niprocart", 0)
  3972. jms, _ := c.GetInt64("jms", 0)
  3973. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3974. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3975. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3976. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3977. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3978. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3979. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3980. injector, _ := c.GetInt64("injector", 0)
  3981. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3982. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3983. safe_package, _ := c.GetInt64("package", 0)
  3984. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3985. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3986. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3987. blood := c.GetString("blood")
  3988. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3989. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3990. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3991. displace_speed := c.GetString("displace_speed")
  3992. illness, _ := c.GetInt64("illness")
  3993. amylaceum := c.GetString("amylaceum")
  3994. single_time := c.GetString("single_time")
  3995. single_water := c.GetString("single_water")
  3996. replacement_flow := c.GetString("replacement_flow")
  3997. plasma_separator := c.GetString("plasma_separator")
  3998. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3999. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  4000. oxygen_flow := c.GetString("oxygen_flow")
  4001. oxygen_time := c.GetString("oxygen_time")
  4002. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  4003. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  4004. puncture_needle := c.GetString("puncture_needle")
  4005. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  4006. epo := c.GetString("epo")
  4007. epo_count, _ := c.GetFloat("epo_count", 0)
  4008. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  4009. pre_impulse := c.GetString("pre_impulse")
  4010. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  4011. admin_user_id, _ := c.GetInt64("admin_user_id")
  4012. is_water := c.GetString("is_water")
  4013. add_amount, _ := c.GetFloat("add_amount")
  4014. reduce_amount, _ := c.GetFloat("reduce_amount")
  4015. prescribing_number, _ := c.GetFloat("prescribing_number")
  4016. treatment_remark := c.GetString("treatment_remark")
  4017. prescription_sodium := c.GetString("prescription_sodium")
  4018. start_sodium := c.GetString("start_sodium")
  4019. sodium_curve := c.GetString("sodium_curve")
  4020. var is_war int64
  4021. if is_water == "是" {
  4022. is_war = 1
  4023. }
  4024. if is_water == "否" {
  4025. is_war = 2
  4026. }
  4027. if is_water == "请选择" {
  4028. is_war = 0
  4029. }
  4030. drhy_water := c.GetString("drhy_water")
  4031. dry_water_hour := c.GetString("dry_water_hour")
  4032. water_machine := c.GetString("water_machine")
  4033. dialysis_remark := c.GetString("dialysis_remark")
  4034. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  4035. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  4036. prescription_water, _ := c.GetFloat("prescription_water")
  4037. dialysis_strainer := c.GetString("dialysis_strainer")
  4038. chaptalization := c.GetString("chaptalization")
  4039. washing_time := c.GetString("washing_time")
  4040. warsh_count := c.GetString("warsh_count")
  4041. blood_access_part_id := c.GetString("blood_access_part_id")
  4042. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  4043. dialyzate := c.GetString("dialyzate")
  4044. first_super := c.GetString("first_super")
  4045. is_sequential := c.GetString("is_sequential")
  4046. var fisrt_sup int64
  4047. if first_super == "是" {
  4048. fisrt_sup = 1
  4049. }
  4050. if first_super == "否" {
  4051. fisrt_sup = 2
  4052. }
  4053. if first_super == "请选择" {
  4054. fisrt_sup = 0
  4055. }
  4056. var is_sequen int64
  4057. if is_sequential == "是" {
  4058. is_sequen = 1
  4059. }
  4060. if is_sequential == "否" {
  4061. is_sequen = 2
  4062. }
  4063. if is_sequential == "请选择" {
  4064. is_sequen = 0
  4065. }
  4066. conduct := c.GetString("conduct")
  4067. if mode_id > 0 {
  4068. var str string
  4069. //查找该机构用的是什么透析器
  4070. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  4071. if filedConfig.ID > 0 {
  4072. str = dialyzerPerfusionApparatus
  4073. } else {
  4074. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  4075. }
  4076. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  4077. }
  4078. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4079. //
  4080. //if template.TemplateId == 2 || template.TemplateId == 6 {
  4081. // if appRole.UserType == 3 {
  4082. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4083. // if getPermissionErr != nil {
  4084. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4085. // return
  4086. // } else if headNursePermission == nil {
  4087. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4088. // return
  4089. // }
  4090. // }
  4091. //}
  4092. // 查询信息规挡的设置天数
  4093. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4094. if infor.ID > 0 && infor.WeekDay > 0 {
  4095. var cha_time int64
  4096. timeNowStr := time.Now().Format("2006-01-02")
  4097. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4098. //今日的日期减去设置的日期
  4099. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4100. if cha_time >= recordDate.Unix() {
  4101. //查询审核是否允许
  4102. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  4103. //申请状态不允许的情况 拒绝修改
  4104. if infor.ApplicationStatus != 1 {
  4105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4106. return
  4107. }
  4108. }
  4109. }
  4110. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  4111. var dialysis_dialyszers_id int64
  4112. var dialysis_strainer_id int64
  4113. var dialysis_irrigation_id int64
  4114. if len(goodList) > 0 {
  4115. for _, item := range goodList {
  4116. if item.SpecificationName == dialysis_dialyszers {
  4117. dialysis_dialyszers_id = item.ID
  4118. }
  4119. if item.SpecificationName == dialysis_irrigation {
  4120. dialysis_irrigation_id = item.ID
  4121. }
  4122. if item.SpecificationName == dialysis_strainer {
  4123. dialysis_strainer_id = item.ID
  4124. }
  4125. }
  4126. }
  4127. prescription := models.DialysisPrescription{
  4128. UserOrgId: adminUserInfo.Org.Id,
  4129. PatientId: id,
  4130. RecordDate: recordDate.Unix(),
  4131. ModeId: mode_id,
  4132. DialysisDuration: dialysis_duration,
  4133. Dialyzer: dialyzer,
  4134. PerfusionApparatus: perfusion_apparatus,
  4135. BloodFlowVolume: blood_flow_volume,
  4136. DewaterAmount: dewater_amount,
  4137. DisplaceLiqui: displace_liqui,
  4138. ReplacementWay: replacement_way,
  4139. Anticoagulant: anticoagulant,
  4140. AnticoagulantShouji: anticoagulant_shouji,
  4141. AnticoagulantWeichi: anticoagulant_weichi,
  4142. AnticoagulantZongliang: anticoagulant_zongliang,
  4143. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4144. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4145. Kalium: kalium,
  4146. Sodium: sodium,
  4147. Calcium: calcium,
  4148. Bicarbonate: bicarbonate,
  4149. Glucose: glucose,
  4150. // DryWeight: dry_weight,
  4151. DialysateFlow: dialysate_flow,
  4152. DialysateTemperature: dialysate_temperature,
  4153. Conductivity: conductivity,
  4154. Remark: remark,
  4155. Status: 1,
  4156. CreatedTime: time.Now().Unix(),
  4157. UpdatedTime: time.Now().Unix(),
  4158. DialysisDurationMinute: dialysisDurationMinute,
  4159. DialysisDurationHour: dialysisDurationHour,
  4160. TargetUltrafiltration: targetUltrafiltration,
  4161. DialysateFormulation: dialysateFormulation,
  4162. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4163. BodyFluid: body_fluid,
  4164. SpecialMedicine: special_medicine,
  4165. SpecialMedicineOther: special_medicine_other,
  4166. DisplaceLiquiPart: displace_liqui_part,
  4167. DisplaceLiquiValue: displace_liqui_value,
  4168. BloodAccess: blood_access,
  4169. Ultrafiltration: ultrafiltration,
  4170. BodyFluidOther: body_fluid_other,
  4171. ReplacementTotal: replacement_total,
  4172. Niprocart: niprocart,
  4173. Jms: jms,
  4174. FistulaNeedleSet: fistula_needle_set,
  4175. FistulaNeedleSet16: fistula_needle_set_16,
  4176. Hemoperfusion: hemoperfusion,
  4177. DialyserSterilised: dialyser_sterilised,
  4178. Filtryzer: filtryzer,
  4179. TargetKtv: target_ktv,
  4180. Dialyzers: dialyzers,
  4181. Injector: injector,
  4182. Bloodlines: bloodlines,
  4183. TubingHemodialysis: tubing_hemodialysis,
  4184. Package: safe_package,
  4185. ALiquid: a_liquid,
  4186. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  4187. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  4188. Blood: blood,
  4189. DialysisDialyszers: dialysis_dialyszers,
  4190. DialysisIrrigation: dialysis_irrigation,
  4191. AntioxidantCommodityName: antioxidant_commodity_name,
  4192. DisplaceSpeed: displace_speed,
  4193. Illness: illness,
  4194. Amylaceum: amylaceum,
  4195. SingleWater: single_water,
  4196. SingleTime: single_time,
  4197. ReplacementFlow: replacement_flow,
  4198. PlasmaSeparator: plasma_separator,
  4199. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  4200. OxygenUptake: oxygen_uptake,
  4201. OxygenTime: oxygen_time,
  4202. OxygenFlow: oxygen_flow,
  4203. HemodialysisPipelines: hemodialysis_pipelines,
  4204. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4205. PunctureNeedle: puncture_needle,
  4206. PunctureNeedleCount: puncture_needle_count,
  4207. Epo: epo,
  4208. EpoCount: epo_count,
  4209. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4210. PreImpulse: impulse,
  4211. AdminUserId: admin_user_id,
  4212. IsWater: is_war,
  4213. DrhyWater: drhy_water,
  4214. DryWaterHour: dry_water_hour,
  4215. WaterMachine: water_machine,
  4216. AddAmount: add_amount,
  4217. ReduceAmount: reduce_amount,
  4218. DialysisRemark: dialysis_remark,
  4219. PrescribingNumber: prescribing_number,
  4220. PrescriptionSodium: prescription_sodium,
  4221. StartSodium: start_sodium,
  4222. SodiumCurve: sodium_curve,
  4223. TreatmentRemark: treatment_remark,
  4224. DialysisFluidFlow: dialysis_fluid_flow,
  4225. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4226. PrescriptionWater: prescription_water,
  4227. DialysisStrainer: dialysis_strainer,
  4228. Chaptalization: chaptalization,
  4229. WashingTime: washing_time,
  4230. WarshCount: warsh_count,
  4231. BloodAccessPartId: blood_access_part_id,
  4232. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4233. Dialyzate: dialyzate,
  4234. DialysisDialyszersId: dialysis_dialyszers_id,
  4235. DialysisIrrigationId: dialysis_irrigation_id,
  4236. DialysisStrainerId: dialysis_strainer_id,
  4237. FirstSuper: fisrt_sup,
  4238. IsSequential: is_sequen,
  4239. Conduct: conduct,
  4240. }
  4241. if adminUserInfo.Org.Id == 10721 {
  4242. if prescription.ModeId == 2 {
  4243. if prescription.ReplacementTotal == 0 {
  4244. prescription.ReplacementTotal = 15
  4245. }
  4246. }
  4247. }
  4248. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4249. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4250. //
  4251. if appRole.UserType == 2 || appRole.UserType == 1 {
  4252. prescription_doctor = adminUserInfo.AdminUser.Id
  4253. prescription.PrescriptionDoctor = prescription_doctor
  4254. }
  4255. if dialysisPrescription.ID == 0 { //新增
  4256. prescription.Creater = adminUserInfo.AdminUser.Id
  4257. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4258. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4259. }
  4260. } else { //修改
  4261. if dialysisPrescription.Creater == 0 {
  4262. prescription.Creater = adminUserInfo.AdminUser.Id
  4263. } else {
  4264. prescription.Creater = dialysisPrescription.Creater
  4265. if adminUserInfo.Org.Id == 9882 {
  4266. if appRole.UserType == 2 || appRole.UserType == 1 {
  4267. prescription.Creater = adminUserInfo.AdminUser.Id
  4268. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4269. }
  4270. }
  4271. }
  4272. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4273. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4274. }
  4275. //if/**/
  4276. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4277. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4278. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4279. // if getPermissionErr != nil {
  4280. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4281. // return
  4282. // } else if headNursePermission == nil {
  4283. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4284. // return
  4285. // }
  4286. //}
  4287. //prescription.Creater = dialysisPrescription.Creater
  4288. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4289. prescription.Modifier = adminUserInfo.AdminUser.Id
  4290. prescription.ID = dialysisPrescription.ID
  4291. }
  4292. solution := models.DialysisSolution{
  4293. RegistrarsId: adminUserInfo.AdminUser.Id,
  4294. UserOrgId: adminUserInfo.Org.Id,
  4295. Doctor: prescription_doctor,
  4296. PatientId: id,
  4297. ModeId: mode_id,
  4298. DialysisDuration: dialysis_duration,
  4299. PerfusionApparatus: perfusion_apparatus,
  4300. BloodFlowVolume: blood_flow_volume,
  4301. Dewater: dewater_amount,
  4302. DisplaceLiqui: displace_liqui,
  4303. ReplacementWay: replacement_way,
  4304. Anticoagulant: anticoagulant,
  4305. AnticoagulantShouji: anticoagulant_shouji,
  4306. AnticoagulantWeichi: anticoagulant_weichi,
  4307. AnticoagulantZongliang: anticoagulant_zongliang,
  4308. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4309. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4310. Kalium: kalium,
  4311. Sodium: sodium,
  4312. Calcium: calcium,
  4313. Bicarbonate: bicarbonate,
  4314. Glucose: glucose,
  4315. // DryWeight: dry_weight,
  4316. DialysateFlow: dialysate_flow,
  4317. DialysateTemperature: dialysate_temperature,
  4318. Conductivity: conductivity,
  4319. Remark: remark,
  4320. Status: 1,
  4321. CreatedTime: time.Now().Unix(),
  4322. UpdatedTime: time.Now().Unix(),
  4323. DialysisDurationMinute: dialysisDurationMinute,
  4324. DialysisDurationHour: dialysisDurationHour,
  4325. TargetUltrafiltration: targetUltrafiltration,
  4326. DialysateFormulation: dialysateFormulation,
  4327. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4328. BodyFluid: body_fluid,
  4329. SpecialMedicine: special_medicine,
  4330. SpecialMedicineOther: special_medicine_other,
  4331. DisplaceLiquiPart: displace_liqui_part,
  4332. DisplaceLiquiValue: displace_liqui_value,
  4333. BloodAccess: blood_access,
  4334. Ultrafiltration: ultrafiltration,
  4335. BodyFluidOther: body_fluid_other,
  4336. ReplacementTotal: replacement_total,
  4337. TargetKtv: target_ktv,
  4338. DialysisDialyszers: dialysis_dialyszers,
  4339. DialysisIrrigation: dialysis_irrigation,
  4340. HemodialysisPipelines: hemodialysis_pipelines,
  4341. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4342. PunctureNeedle: puncture_needle,
  4343. PunctureNeedleCount: puncture_needle_count,
  4344. Epo: epo,
  4345. EpoCount: epo_count,
  4346. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4347. PreImpulse: impulse,
  4348. SolutionStatus: 1,
  4349. DialysisRemark: dialysis_remark,
  4350. PrescribingNumber: prescribing_number,
  4351. PrescriptionSodium: prescription_sodium,
  4352. StartSodium: start_sodium,
  4353. SodiumCurve: sodium_curve,
  4354. TreatmentRemark: treatment_remark,
  4355. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4356. DialysisFluidFlow: dialysis_fluid_flow,
  4357. PrescriptionWater: prescription_water,
  4358. DialysisStrainer: dialysis_strainer,
  4359. Chaptalization: chaptalization,
  4360. WashingTime: washing_time,
  4361. WarshCount: warsh_count,
  4362. BloodAccessPartId: blood_access_part_id,
  4363. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4364. Dialyzate: dialyzate,
  4365. DialysisDialyszersId: dialysis_dialyszers_id,
  4366. DialysisIrrigationId: dialysis_irrigation_id,
  4367. DialysisStrainerId: dialysis_strainer_id,
  4368. FirstSuper: fisrt_sup,
  4369. IsSequential: is_sequen,
  4370. Conduct: conduct,
  4371. }
  4372. //针对河间咸的
  4373. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4374. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4375. solution.DisplaceLiquiPart = 0
  4376. solution.DisplaceLiquiValue = 0
  4377. }
  4378. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4379. prescription.DisplaceLiquiPart = 0
  4380. prescription.DisplaceLiquiValue = 0
  4381. }
  4382. }
  4383. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4384. if solution.PrescribingNumber == 0 {
  4385. solution.PrescribingNumber = 1
  4386. }
  4387. if prescription.PrescribingNumber == 0 {
  4388. prescription.PrescribingNumber = 1
  4389. }
  4390. if solution.PrescribingNumber == 0 && id == 14682 {
  4391. solution.PrescribingNumber = 2
  4392. }
  4393. if solution.PrescribingNumber == 0 && id == 18560 {
  4394. solution.PrescribingNumber = 2
  4395. }
  4396. if prescription.PrescribingNumber == 0 && id == 14682 {
  4397. prescription.PrescribingNumber = 2
  4398. }
  4399. if prescription.PrescribingNumber == 0 && id == 18560 {
  4400. prescription.PrescribingNumber = 2
  4401. }
  4402. }
  4403. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4404. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  4405. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4406. if len(monitorList) > 0 {
  4407. var ultrafiltration_rate float64
  4408. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4409. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4410. var replacement_rate float64
  4411. if adminUserInfo.Org.Id == 10721 {
  4412. //乘10 除10是为了保留一位小数
  4413. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4414. }
  4415. if adminUserInfo.Org.Id == 9478 {
  4416. //乘10 除10是为了保留一位小数
  4417. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4418. }
  4419. var firstOpeateTime = monitorList[0].OperateTime
  4420. for _, item := range monitorList {
  4421. //超滤率
  4422. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4423. //置换率
  4424. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4425. //超滤量
  4426. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4427. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4428. //置换量
  4429. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4430. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4431. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4432. }
  4433. }
  4434. }
  4435. //记录日志
  4436. byterequest, _ := json.Marshal(prescription)
  4437. prescriptionLog := models.XtDialysisPrescriptionLog{
  4438. UserOrgId: prescription.UserOrgId,
  4439. Ctime: time.Now().Unix(),
  4440. Mtime: 0,
  4441. ErrLog: string(byterequest),
  4442. AdminUserId: adminUserInfo.AdminUser.Id,
  4443. RecordDate: prescription.RecordDate,
  4444. PatientId: prescription.PatientId,
  4445. Source: "手机端新增长期处方",
  4446. Status: 1,
  4447. }
  4448. service.CreatePrescriptionLog(prescriptionLog)
  4449. finish := models.XtDialysisFinish{
  4450. IsFinish: 1,
  4451. UserOrgId: adminUserInfo.Org.Id,
  4452. Status: 1,
  4453. Ctime: time.Now().Unix(),
  4454. Mtime: 0,
  4455. Module: 1,
  4456. RecordDate: recordDate.Unix(),
  4457. Sourse: 1,
  4458. PatientId: id,
  4459. }
  4460. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4461. if dialysisFinish.ID == 0 {
  4462. service.CreateDialysisFinish(finish)
  4463. }
  4464. //获取最新1条
  4465. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4466. //更新状态
  4467. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4468. //长沙南雅医院,自动生成抗凝剂的临时处方
  4469. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4470. if prescribing_number == 0 {
  4471. prescribing_number = 1
  4472. }
  4473. advice := models.DoctorAdvice{
  4474. UserOrgId: adminUserInfo.Org.Id,
  4475. PatientId: id,
  4476. GroupNo: 0,
  4477. AdviceType: 2,
  4478. RecordDate: recordDate.Unix(),
  4479. AdviceDate: recordDate.Unix(),
  4480. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4481. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4482. AdviceDesc: "",
  4483. ReminderDate: 0,
  4484. SingleDose: prescription.AnticoagulantZongliang,
  4485. SingleDoseUnit: "iu",
  4486. DrugSpec: 0,
  4487. DrugSpecUnit: "",
  4488. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4489. PrescribingNumberUnit: "支",
  4490. DeliveryWay: "静脉注射",
  4491. ExecutionFrequency: "上机前",
  4492. AdviceDoctor: 0,
  4493. Status: 1,
  4494. CreatedTime: time.Now().Unix(),
  4495. UpdatedTime: time.Now().Unix(),
  4496. IsPrescription: 1,
  4497. ExecutionState: 2,
  4498. StopState: 2,
  4499. IsSettle: 2,
  4500. }
  4501. // 查询排班信息
  4502. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4503. if schedulePatient.ID > 0 {
  4504. if schedulePatient.ScheduleType == 1 {
  4505. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4506. }
  4507. if schedulePatient.ScheduleType == 2 {
  4508. advice.StartTime = recordDate.Unix() + 9*60*60
  4509. }
  4510. }
  4511. // 抗凝剂名称
  4512. switch anticoagulant {
  4513. case 1:
  4514. advice.AdviceName = "无肝素"
  4515. break
  4516. case 2:
  4517. advice.AdviceName = "普通肝素"
  4518. break
  4519. case 3:
  4520. advice.AdviceName = "低分子肝素"
  4521. break
  4522. case 4:
  4523. advice.AdviceName = "阿加曲班"
  4524. break
  4525. case 5:
  4526. advice.AdviceName = "枸橼酸钠"
  4527. break
  4528. case 6:
  4529. advice.AdviceName = "低分子肝素钙"
  4530. break
  4531. case 7:
  4532. advice.AdviceName = "低分子肝素钠"
  4533. break
  4534. case 8:
  4535. advice.AdviceName = "依诺肝素"
  4536. break
  4537. case 9:
  4538. advice.AdviceName = "达肝素"
  4539. break
  4540. case 10:
  4541. advice.AdviceName = "体外抗凝"
  4542. break
  4543. case 11:
  4544. advice.AdviceName = "那曲肝素"
  4545. break
  4546. case 12:
  4547. advice.AdviceName = "无抗凝剂"
  4548. break
  4549. }
  4550. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4551. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4552. advice.AdviceDoctor = appRole.AdminUserId
  4553. }
  4554. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4555. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4556. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4557. advice.AdviceName = "低分子肝素钠注射液"
  4558. // 修改患者临时医嘱里的抗凝剂医嘱
  4559. advice.ID = advicePrescription.ID
  4560. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4561. } else {
  4562. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4563. advice.AdviceName = "低分子肝素钠注射液"
  4564. service.CreateDoctorAdvice(&advice)
  4565. }
  4566. }
  4567. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4568. redis := service.RedisClient()
  4569. defer redis.Close()
  4570. //清空key 值
  4571. redis.Set(key, "", time.Second)
  4572. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4573. redis.Set(keyOne, "", time.Second)
  4574. }
  4575. //获取key,清空redis
  4576. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4577. redis := service.RedisClient()
  4578. defer redis.Close()
  4579. //清空key 值
  4580. redis.Set(key, "", time.Second)
  4581. //清空长期医嘱的key
  4582. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4583. redis.Set(soulution_key, "", time.Second)
  4584. //查询最近透析准备表里是否存在 透析器 灌流器
  4585. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4586. redis.Set(keyOne, "", time.Second)
  4587. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4588. redis.Set(keyTwo, "", time.Second)
  4589. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4590. redis.Set(keyThree, "", time.Second)
  4591. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4592. redis.Set(keyFour, "", time.Second)
  4593. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4594. //
  4595. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4596. //
  4597. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4598. //if len(mation)>0{
  4599. // for _, item := range splitStr {
  4600. // for _,it := range mation{
  4601. // if(item == it.SpecificationName){
  4602. //
  4603. // //查询最近一次的透析器
  4604. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4605. //
  4606. // if errcode == gorm.ErrRecordNotFound{
  4607. // //插入数据
  4608. // prepare := models.DialysisBeforePrepare{
  4609. // UserOrgId: adminUserInfo.Org.Id,
  4610. // PatientId: id,
  4611. // RecordDate: recordDate.Unix(),
  4612. // GoodTypeId: it.GoodTypeId,
  4613. // GoodId: it.ID,
  4614. // Count: 1,
  4615. // Ctime: time.Now().Unix(),
  4616. // Creater: adminUserInfo.AdminUser.Id,
  4617. // Status:1,
  4618. //
  4619. // }
  4620. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4621. // fmt.Println("",errcode)
  4622. // }
  4623. // }
  4624. // }
  4625. //
  4626. // }
  4627. //
  4628. // for _, item := range splitIrrigation {
  4629. // for _,it := range mation{
  4630. // if(item == it.SpecificationName){
  4631. // //查询最近一次的透析器
  4632. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4633. // if errcode == gorm.ErrRecordNotFound{
  4634. // //插入数据
  4635. // prepare := models.DialysisBeforePrepare{
  4636. // UserOrgId: adminUserInfo.Org.Id,
  4637. // PatientId: id,
  4638. // RecordDate: recordDate.Unix(),
  4639. // GoodTypeId: it.GoodTypeId,
  4640. // GoodId: it.ID,
  4641. // Count: 1,
  4642. // Ctime: time.Now().Unix(),
  4643. // Creater: adminUserInfo.AdminUser.Id,
  4644. // Status:1,
  4645. //
  4646. // }
  4647. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4648. // fmt.Println(errcode)
  4649. // }
  4650. // }
  4651. // }
  4652. // }
  4653. //}
  4654. c.ServeSuccessJSON(map[string]interface{}{
  4655. "solution": &solution,
  4656. "prescription": &prescription,
  4657. })
  4658. }
  4659. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4660. patient, _ := c.GetInt64("patient", 0)
  4661. adminUserInfo := c.GetMobileAdminUserInfo()
  4662. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4663. c.ServeSuccessJSON(map[string]interface{}{
  4664. "receiveTreatmentAsses": receiveTreatmentAsses,
  4665. })
  4666. }
  4667. func (this *DialysisAPIController) PostSignInfo() {
  4668. patientID, _ := this.GetInt64("patient_id")
  4669. recordDateStr := this.GetString("date")
  4670. if patientID <= 0 {
  4671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4672. return
  4673. }
  4674. if len(recordDateStr) == 0 {
  4675. recordDateStr = time.Now().Format("2006-01-02")
  4676. }
  4677. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4678. if parseDateErr != nil {
  4679. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4681. return
  4682. }
  4683. adminInfo := this.GetMobileAdminUserInfo()
  4684. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4685. if err != nil {
  4686. this.ErrorLog("签名失败:%v", err)
  4687. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4688. return
  4689. }
  4690. this.ServeSuccessJSON(map[string]interface{}{
  4691. "doctor_id": adminInfo.AdminUser.Id,
  4692. })
  4693. }
  4694. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4695. patientID, _ := this.GetInt64("patient_id")
  4696. adminInfo := this.GetMobileAdminUserInfo()
  4697. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4698. this.ServeSuccessJSON(map[string]interface{}{
  4699. "monitor": record,
  4700. })
  4701. }
  4702. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4703. thisTime := time.Now()
  4704. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4705. timeLayout := "2006-01-02 15:04:05"
  4706. loc, _ := time.LoadLocation("Local")
  4707. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4708. theAssessmentDateTime := theStartTime.Unix()
  4709. patientID, _ := this.GetInt64("patient_id")
  4710. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4711. adminInfo := this.GetMobileAdminUserInfo()
  4712. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4713. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4714. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4715. var ultrafiltration_rate float64
  4716. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4717. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4718. fmt.Println(evaluation)
  4719. fmt.Println("prescription.ID", prescription.ID)
  4720. if prescription.ID > 0 {
  4721. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4722. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4723. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4724. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4725. record.UltrafiltrationRate = ultrafiltration_rate
  4726. }
  4727. //重庆塘坝卫生院
  4728. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4729. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4730. fmt.Println("ultrafiltration_rate--------------------", ultrafiltration_rate)
  4731. record.UltrafiltrationRate = ultrafiltration_rate
  4732. }
  4733. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4734. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4735. record.UltrafiltrationRate = ultrafiltration_rate
  4736. }
  4737. if adminInfo.Org.Id == 10510 {
  4738. record.UltrafiltrationRate = 0
  4739. }
  4740. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4741. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4742. record.UltrafiltrationRate = ultrafiltration_rate
  4743. }
  4744. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4745. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4746. record.UltrafiltrationRate = ultrafiltration_rate
  4747. }
  4748. // 只针对方济医院
  4749. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4750. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4751. ultrafiltration_rate = value
  4752. record.UltrafiltrationRate = ultrafiltration_rate
  4753. }
  4754. if template.TemplateId == 41 || template.TemplateId == 47 {
  4755. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4756. record.UltrafiltrationRate = ultrafiltration_rate
  4757. }
  4758. if template.TemplateId == 43 {
  4759. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4760. record.UltrafiltrationRate = ultrafiltration_rate
  4761. }
  4762. if template.TemplateId == 46 || template.TemplateId == 54 {
  4763. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4764. record.UltrafiltrationRate = ultrafiltration_rate
  4765. }
  4766. 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 {
  4767. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4768. record.UltrafiltrationRate = ultrafiltration_rate
  4769. }
  4770. if adminInfo.Org.Id == 10469 {
  4771. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4772. record.UltrafiltrationRate = ultrafiltration_rate
  4773. }
  4774. if adminInfo.Org.Id == 10667 {
  4775. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4776. record.UltrafiltrationRate = ultrafiltration_rate
  4777. }
  4778. if adminInfo.Org.Id == 10471 {
  4779. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4780. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4781. }
  4782. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4783. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4784. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4785. }
  4786. if adminInfo.Org.Id == 10751 {
  4787. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4788. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4789. }
  4790. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4791. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4792. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4793. }
  4794. if adminInfo.Org.Id == 10721 {
  4795. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4796. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4797. }
  4798. if adminInfo.Org.Id == 10757 {
  4799. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4800. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4801. }
  4802. if adminInfo.Org.Id == 10752 {
  4803. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4804. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4805. }
  4806. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4807. record.UltrafiltrationRate = 0
  4808. }
  4809. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4810. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4811. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4812. }
  4813. if adminInfo.Org.Id == 10206 {
  4814. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4815. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4816. }
  4817. //湘潭爱心美白石
  4818. if adminInfo.Org.Id == 9850 {
  4819. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4820. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4821. }
  4822. if adminInfo.Org.Id == 9919 {
  4823. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4824. record.UltrafiltrationRate = math.Floor(ultrafiltration_rate / 1000)
  4825. }
  4826. //if template.TemplateId == 47 {
  4827. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4828. // record.UltrafiltrationRate = ultrafiltration_rate
  4829. //}
  4830. }
  4831. }
  4832. // record.UltrafiltrationRate = ultrafiltration_rate
  4833. record.UltrafiltrationVolume = 0
  4834. 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
  4835. if ultrafiltration_rate > 0 {
  4836. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4837. record.UltrafiltrationVolume = value
  4838. }
  4839. }
  4840. 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
  4841. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4842. if adminInfo.Org.Id != 10735 {
  4843. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4844. record.UltrafiltrationVolume = ultrafiltration_volume
  4845. }
  4846. //胶州少海医院
  4847. if adminInfo.Org.Id == 10735 {
  4848. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4849. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4850. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4851. if lastMonitorRecordList.ID > 0 {
  4852. record.UltrafiltrationRate = ultrafiltration_rate_one
  4853. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4854. record.UltrafiltrationVolume = ultrafiltration_volume
  4855. } else {
  4856. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4857. record.UltrafiltrationVolume = ultrafiltration_volume
  4858. }
  4859. }
  4860. }
  4861. }
  4862. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4863. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4864. record.UltrafiltrationVolume = ultrafiltration_volume
  4865. }
  4866. //长沙南雅
  4867. 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 || adminInfo.Org.Id == 9478 {
  4868. if ultrafiltration_rate > 0 {
  4869. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4870. record.UltrafiltrationVolume = ultrafiltration_volume
  4871. }
  4872. }
  4873. if adminInfo.Org.Id == 10471 {
  4874. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4875. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4876. }
  4877. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4878. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4879. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4880. }
  4881. if adminInfo.Org.Id == 10751 {
  4882. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4883. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4884. }
  4885. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4886. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4887. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4888. }
  4889. //长沙南雅累计血容量自动计算
  4890. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4891. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4892. //}
  4893. if template.TemplateId == 47 || template.TemplateId == 54 {
  4894. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4895. }
  4896. if adminInfo.Org.Id == 10510 {
  4897. record.UltrafiltrationVolume = 0
  4898. }
  4899. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10752 || adminInfo.Org.Id == 10757 {
  4900. if ultrafiltration_rate > 0 {
  4901. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4902. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4903. }
  4904. }
  4905. //古镇乐生
  4906. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4907. if ultrafiltration_rate > 0 {
  4908. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4909. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4910. }
  4911. }
  4912. if adminInfo.Org.Id == 9919 {
  4913. if ultrafiltration_rate > 0 {
  4914. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4915. record.UltrafiltrationVolume = math.Floor(ultrafiltration_volume / 1000)
  4916. }
  4917. }
  4918. if adminInfo.Org.Id == 10206 {
  4919. if ultrafiltration_rate > 0 {
  4920. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4921. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4922. }
  4923. }
  4924. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10290 {
  4925. var replacement_rate float64
  4926. var displacement_quantity float64
  4927. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4928. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4929. record.ReplacementRate = replacement_rate
  4930. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4931. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4932. record.DisplacementQuantity = displacement_quantity
  4933. }
  4934. if adminInfo.Org.Id == 10752 {
  4935. var replacement_rate float64
  4936. var displacement_quantity float64
  4937. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4938. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4939. record.ReplacementRate = replacement_rate
  4940. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4941. record.DisplacementQuantity = displacement_quantity
  4942. }
  4943. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4944. var replacement_rate float64
  4945. var displacement_quantity float64
  4946. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4947. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4948. record.ReplacementRate = replacement_rate
  4949. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4950. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4951. record.DisplacementQuantity = displacement_quantity
  4952. }
  4953. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4954. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4955. record.UltrafiltrationVolume = ultrafiltration_volume
  4956. }
  4957. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10744 {
  4958. var replacement_rate float64
  4959. var displacement_quantity float64
  4960. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4961. if totalMin == 0 {
  4962. totalMin = 240
  4963. }
  4964. if prescription.DisplaceLiquiValue == 0 {
  4965. prescription.ReplacementTotal = 32
  4966. }
  4967. //乘10 除10是为了保留一位小数
  4968. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4969. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4970. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4971. record.DisplacementQuantity = displacement_quantity
  4972. }
  4973. if adminInfo.Org.Id == 9850 {
  4974. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4975. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4976. }
  4977. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4978. this.ServeSuccessJSON(map[string]interface{}{
  4979. "monitor": record,
  4980. "lastMonitorRecordList": lastMonitorRecordList,
  4981. })
  4982. }
  4983. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4984. record_id, _ := this.GetInt64("id")
  4985. nurseID, _ := this.GetInt64("start_nurse")
  4986. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4987. bedID, _ := this.GetInt64("bed")
  4988. start_time := this.GetString("start_time")
  4989. schedual_type, _ := this.GetInt64("schedual_type")
  4990. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4991. change_nurse, _ := this.GetInt64("change_nurse")
  4992. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4993. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4994. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4995. patient_id, _ := this.GetInt64("patient_id")
  4996. record_date, _ := this.GetInt64("record_date")
  4997. puncture_needle := this.GetString("puncture_needle")
  4998. puncture_way := this.GetString("puncture_way")
  4999. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  5000. dialysis_irrigation := this.GetString("dialysis_irrigation")
  5001. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  5002. nuclein_date_str := this.GetString("nuclein_date_str")
  5003. order_remark := this.GetString("order_remark")
  5004. schedule_remark := this.GetString("schedule_remark")
  5005. catheter_operation := this.GetString("catheter_operation")
  5006. blood_flow_volume := this.GetString("blood_flow_volume")
  5007. blood_drawing, _ := this.GetInt64("blood_drawing")
  5008. dialysis_strainer := this.GetString("dialysis_strainer")
  5009. if record_id == 0 {
  5010. this.ErrorLog("id:%v", record_id)
  5011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5012. return
  5013. }
  5014. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5015. if parseStartDateErr != nil {
  5016. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5018. return
  5019. }
  5020. adminUserInfo := this.GetMobileAdminUserInfo()
  5021. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5022. if getNurseErr != nil {
  5023. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5025. return
  5026. } else if nurse == nil {
  5027. this.ErrorLog("护士不存在")
  5028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5029. return
  5030. }
  5031. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5032. //if getNurseErr != nil {
  5033. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  5034. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5035. // return
  5036. //} else if nurse == nil {
  5037. // this.ErrorLog("护士不存在")
  5038. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5039. // return
  5040. //}
  5041. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5042. if getDeviceNumberErr != nil {
  5043. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5045. return
  5046. } else if deviceNumber == nil {
  5047. this.ErrorLog("床位号不存在")
  5048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5049. return
  5050. }
  5051. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5052. //
  5053. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5054. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5055. // if getPermissionErr != nil {
  5056. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5057. // return
  5058. // } else if headNursePermission == nil {
  5059. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5060. // return
  5061. // }
  5062. //}
  5063. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5064. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5065. timeLayout := "2006-01-02 15:04:05"
  5066. loc, _ := time.LoadLocation("Local")
  5067. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5068. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5069. schedulestartTime := theStartTime.Unix()
  5070. scheduleendTime := theEndTime.Unix()
  5071. var theNucleinDate int64
  5072. timeLayoutOne := "2006-01-02"
  5073. if len(nuclein_date_str) > 0 {
  5074. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  5075. if err != nil {
  5076. utils.ErrorLog(err.Error())
  5077. }
  5078. theNucleinDate = theTime.Unix()
  5079. }
  5080. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5081. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5082. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5083. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5084. if err == gorm.ErrRecordNotFound { //空床位
  5085. // 修改了床位逻辑
  5086. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5087. if daySchedule.ID > 0 {
  5088. //daySchedule.BedId = bedID
  5089. //daySchedule.PartitionId = deviceNumber.ZoneID
  5090. //daySchedule.ScheduleType = schedual_type
  5091. //daySchedule.UpdatedTime = time.Now().Unix()
  5092. //err := service.UpdateSchedule(&daySchedule)
  5093. xtSchedule := models.Schedule{
  5094. PartitionId: deviceNumber.ZoneID,
  5095. BedId: bedID,
  5096. ScheduleType: schedual_type,
  5097. UpdatedTime: time.Now().Unix(),
  5098. }
  5099. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5100. if err != nil {
  5101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5102. return
  5103. }
  5104. }
  5105. } else if err == nil {
  5106. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5107. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5108. if daySchedule.ID > 0 {
  5109. //daySchedule.BedId = bedID
  5110. //daySchedule.PartitionId = deviceNumber.ZoneID
  5111. //
  5112. //daySchedule.ScheduleType = schedual_type
  5113. //daySchedule.UpdatedTime = time.Now().Unix()
  5114. //err := service.UpdateSchedule(&daySchedule)
  5115. xtSchedule := models.Schedule{
  5116. PartitionId: deviceNumber.ZoneID,
  5117. BedId: bedID,
  5118. ScheduleType: schedual_type,
  5119. UpdatedTime: time.Now().Unix(),
  5120. }
  5121. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5122. if err != nil {
  5123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5124. return
  5125. }
  5126. }
  5127. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5128. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5129. return
  5130. }
  5131. } else if err != nil {
  5132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5133. return
  5134. }
  5135. }
  5136. dialysisRecord := &models.DialysisOrder{
  5137. ID: record_id,
  5138. UserOrgId: adminUserInfo.Org.Id,
  5139. BedID: bedID,
  5140. StartNurse: nurseID,
  5141. StartTime: startDate.Unix(),
  5142. PunctureNurse: puncture_nurse,
  5143. Creator: adminUserInfo.AdminUser.Id,
  5144. Modifier: adminUserInfo.AdminUser.Id,
  5145. WashpipeNurse: washpipe_nurse,
  5146. SchedualType: schedual_type,
  5147. ChangeNurse: change_nurse,
  5148. DifficultPunctureNurse: difficult_puncture_nurse,
  5149. NewFistulaNurse: new_fistula_nurse,
  5150. QualityNurseId: quality_nurse_id,
  5151. PunctureNeedle: puncture_needle,
  5152. PunctureWay: puncture_way,
  5153. DialysisDialyszers: dialysis_dialyszers,
  5154. DialysisIrrigation: dialysis_irrigation,
  5155. BloodAccessId: blood_access_id,
  5156. NucleinDate: theNucleinDate,
  5157. OrderRemark: order_remark,
  5158. ScheduleRemark: schedule_remark,
  5159. CatheterOperation: catheter_operation,
  5160. BloodFlowVolume: blood_flow_volume,
  5161. BloodDrawing: blood_drawing,
  5162. DialysisStrainer: dialysis_strainer,
  5163. }
  5164. //修改床位号需要重新消毒
  5165. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  5166. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5167. //查询第一条监测
  5168. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5169. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  5170. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5171. redis := service.RedisClient()
  5172. //清空key 值
  5173. redis.Set(key, "", time.Second)
  5174. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5175. redis.Set(keyOne, "", time.Second)
  5176. defer redis.Close()
  5177. }
  5178. // 查询信息规挡的设置天数
  5179. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5180. if infor.ID > 0 && infor.WeekDay > 0 {
  5181. var cha_time int64
  5182. timeNowStr := time.Now().Format("2006-01-02")
  5183. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5184. //今日的日期减去设置的日期
  5185. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5186. if cha_time >= record_date {
  5187. //查询审核是否允许
  5188. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  5189. //申请状态不允许的情况 拒绝修改
  5190. if infor.ApplicationStatus != 1 {
  5191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5192. return
  5193. }
  5194. }
  5195. }
  5196. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5197. //修改床位后重新生成消毒计划
  5198. if adminUserInfo.Org.Id == 10340 {
  5199. //根据床位号获取设备型号
  5200. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5201. //查询使用消毒最后一条消毒记录
  5202. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  5203. fmt.Println("err", err)
  5204. if err == gorm.ErrRecordNotFound {
  5205. //查找排班
  5206. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  5207. //查询改设备是否有消毒计划
  5208. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  5209. //根据床位号获取设备id
  5210. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5211. //查询病人信息
  5212. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  5213. var con = ""
  5214. if patients.IsInfectious == 0 {
  5215. con = ""
  5216. }
  5217. if patients.IsInfectious == 1 {
  5218. con = "无"
  5219. }
  5220. if patients.IsInfectious == 2 {
  5221. con = "有"
  5222. }
  5223. if errcode == nil {
  5224. var end_time int64
  5225. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  5226. //新增消毒
  5227. information := models.DeviceInformation{
  5228. Date: dialysisRecord.DialysisDate,
  5229. Zone: dialysisRecord.ZoneId,
  5230. Class: dialysisRecord.SchedualType,
  5231. BedNumber: dialysisRecord.BedID,
  5232. PatientId: dialysisRecord.PatientId,
  5233. DialysisMode: scheduleByPatient.ModeId,
  5234. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  5235. Disinfection: 1,
  5236. DialysisConcentration: 1,
  5237. DisinfectionStatus: 1,
  5238. Move: 1,
  5239. UserOrgId: dialysisRecord.UserOrgId,
  5240. DisinfectType: plan.Way,
  5241. DisinfectantType: plan.MachineDisinfectant,
  5242. FluidPath: plan.DisinfectanWay, //液路消毒方式
  5243. Disinfectant: plan.Disinfectant,
  5244. Ctime: time.Now().Unix(),
  5245. Status: 1,
  5246. SignName: nurseID,
  5247. EquimentId: addmacher.ID,
  5248. DisinfectionResidue: 2,
  5249. Bed: addmacher.BedNumber,
  5250. StartTime: dialysisRecord.StartTime,
  5251. EndTime: dialysisRecord.EndTime,
  5252. Contagion: con,
  5253. WeightLoss: 0,
  5254. Hyperfiltratio: 0,
  5255. DialysisHour: "",
  5256. MachineRun: 1,
  5257. DisinfecStartime: dialysisRecord.EndTime,
  5258. DisinfecEndtime: end_time,
  5259. }
  5260. err := service.CreateInformationTwo(&information)
  5261. fmt.Println("报错", err)
  5262. }
  5263. }
  5264. }
  5265. order, _ := service.GetLastPatientOrder(record_id)
  5266. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5267. redis := service.RedisClient()
  5268. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5269. redis.Set(key, "", time.Second)
  5270. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5271. //清空key 值
  5272. redis.Set(keyOne, "", time.Second)
  5273. scheduleDateStartOne := startDate.Format("2006-01-02")
  5274. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5275. redis.Set(keyTwo, "", time.Second)
  5276. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5277. redis.Set(keyThree, "", time.Second)
  5278. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5279. redis.Set(keyFour, "", time.Second)
  5280. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5281. redis.Set(keyFive, "", time.Second)
  5282. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5283. redis.Set(keySix, "", time.Second)
  5284. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5285. redis.Set(keySeven, "", time.Second)
  5286. if updateErr != nil {
  5287. this.ErrorLog("修改上机失败:%v", updateErr)
  5288. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5289. return
  5290. }
  5291. if updateErr == nil {
  5292. if tempDialysisRecord.Stage == 2 {
  5293. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5294. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5295. fmt.Println(value)
  5296. a, b := math.Modf(value)
  5297. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5298. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5299. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5300. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5301. redis := service.RedisClient()
  5302. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5303. redis.Set(key, "", time.Second)
  5304. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5305. redis.Set(keyOne, "", time.Second)
  5306. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5307. //清空key 值
  5308. redis.Set(keySix, "", time.Second)
  5309. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5310. redis.Set(keySeven, "", time.Second)
  5311. redis.Close()
  5312. if updateAssessmentErr != nil {
  5313. utils.ErrorLog("%v", updateAssessmentErr)
  5314. }
  5315. }
  5316. }
  5317. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5318. this.ServeSuccessJSON(map[string]interface{}{
  5319. "dialysis_order": dialysisRecords,
  5320. })
  5321. }
  5322. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5323. record_id, _ := c.GetInt64("id")
  5324. nurseID, _ := c.GetInt64("nurse")
  5325. end_time := c.GetString("end_time")
  5326. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5327. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5328. catheter := c.GetString("catheter")
  5329. cruor := c.GetString("cruor")
  5330. mission := c.GetString("mission")
  5331. condenser := c.GetString("condenser")
  5332. if record_id <= 0 || nurseID <= 0 {
  5333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5334. return
  5335. }
  5336. adminUserInfo := c.GetMobileAdminUserInfo()
  5337. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5338. if getNurseErr != nil {
  5339. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5341. return
  5342. } else if nurse == nil {
  5343. c.ErrorLog("护士不存在")
  5344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5345. return
  5346. }
  5347. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5348. if parseEndDateErr != nil {
  5349. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5351. return
  5352. }
  5353. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5354. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5355. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5356. // if getPermissionErr != nil {
  5357. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5358. // return
  5359. // } else if headNursePermission == nil {
  5360. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5361. // return
  5362. // }
  5363. //}
  5364. // 查询信息规挡的设置天数
  5365. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5366. if infor.ID > 0 {
  5367. var cha_time int64
  5368. timeNowStr := time.Now().Format("2006-01-02")
  5369. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5370. //今日的日期减去设置的日期
  5371. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5372. if cha_time >= tempDialysisRecords.DialysisDate {
  5373. //查询审核是否允许
  5374. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5375. //申请状态不允许的情况 拒绝修改
  5376. if infor.ApplicationStatus != 1 {
  5377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5378. return
  5379. }
  5380. }
  5381. }
  5382. dialysisRecord := &models.DialysisOrder{
  5383. ID: record_id,
  5384. UserOrgId: adminUserInfo.Org.Id,
  5385. EndTime: endDate.Unix(),
  5386. FinishNurse: nurseID,
  5387. FinishModifier: adminUserInfo.AdminUser.Id,
  5388. PuncturePointHaematoma: puncture_point_haematoma,
  5389. BloodAccessInternalFistula: blood_access_internal_fistula,
  5390. Catheter: catheter,
  5391. Cruor: cruor,
  5392. Mission: mission,
  5393. Condenser: condenser,
  5394. }
  5395. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5396. redis := service.RedisClient()
  5397. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5398. //清空key 值
  5399. redis.Set(key, "", time.Second)
  5400. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5401. //清空key 值
  5402. redis.Set(keyOne, "", time.Second)
  5403. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5404. redis.Set(keySeven, "", time.Second)
  5405. redis.Close()
  5406. if updateErr != nil {
  5407. c.ErrorLog("修改下机失败:%v", updateErr)
  5408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5409. return
  5410. }
  5411. if updateErr == nil {
  5412. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5413. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5414. a, b := math.Modf(value)
  5415. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5416. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5417. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5418. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5419. redis := service.RedisClient()
  5420. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5421. redis.Set(keyTen, "", time.Second)
  5422. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5423. redis.Set(keyTwo, "", time.Second)
  5424. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5425. redis.Set(key, "", time.Second)
  5426. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5427. redis.Set(keyThree, "", time.Second)
  5428. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5429. redis.Set(keySeven, "", time.Second)
  5430. defer redis.Close()
  5431. if updateAssessmentErr != nil {
  5432. utils.ErrorLog("%v", updateAssessmentErr)
  5433. }
  5434. }
  5435. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5436. c.ServeSuccessJSON(map[string]interface{}{
  5437. "dialysis_order": dialysisRecords,
  5438. })
  5439. }
  5440. func (c *DialysisAPIController) GetLongAdvice() {
  5441. patient_id, _ := c.GetInt64("id")
  5442. adminUserInfo := c.GetMobileAdminUserInfo()
  5443. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5444. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5445. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5446. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5447. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5448. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5449. c.ServeSuccessJSON(map[string]interface{}{
  5450. "status": "1",
  5451. })
  5452. return
  5453. } else { //开启推送提醒
  5454. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5455. var advice_three []*models.DoctorAdvice
  5456. recordDateStr := time.Now().Format("2006-01-02")
  5457. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5458. nowtime := recordDate.Unix()
  5459. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5460. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5461. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5462. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5463. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5464. for _, advice := range advices {
  5465. if advice.FrequencyType == 3 {
  5466. t := time.Now()
  5467. week := int(t.Weekday())
  5468. fmt.Println(t.Weekday())
  5469. fmt.Println(week)
  5470. switch week {
  5471. case 1:
  5472. if strings.Index(advice.WeekDay, "周一") == -1 {
  5473. advice_three = append(advice_three, advice)
  5474. }
  5475. break
  5476. case 2:
  5477. if strings.Index(advice.WeekDay, "周二") == -1 {
  5478. advice_three = append(advice_three, advice)
  5479. }
  5480. break
  5481. case 3:
  5482. if strings.Index(advice.WeekDay, "周三") == -1 {
  5483. advice_three = append(advice_three, advice)
  5484. }
  5485. break
  5486. case 4:
  5487. if strings.Index(advice.WeekDay, "周四") == -1 {
  5488. advice_three = append(advice_three, advice)
  5489. }
  5490. break
  5491. case 5:
  5492. if strings.Index(advice.WeekDay, "周五") == -1 {
  5493. advice_three = append(advice_three, advice)
  5494. }
  5495. break
  5496. case 6:
  5497. if strings.Index(advice.WeekDay, "周六") == -1 {
  5498. advice_three = append(advice_three, advice)
  5499. }
  5500. break
  5501. case 0:
  5502. if strings.Index(advice.WeekDay, "周日") == -1 {
  5503. advice_three = append(advice_three, advice)
  5504. }
  5505. break
  5506. }
  5507. }
  5508. }
  5509. for _, advice := range advices_two {
  5510. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5511. now := p.Unix()
  5512. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5513. dayStr2 := "-" + dayStr
  5514. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5515. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5516. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5517. for _, ad := range advices {
  5518. advice_three = append(advice_three, ad)
  5519. }
  5520. }
  5521. if err == nil {
  5522. c.ServeSuccessJSON(map[string]interface{}{
  5523. "status": "2",
  5524. "advices": advices,
  5525. "advices_two": RemoveRepeatedElement(advice_three),
  5526. "is_open_remind": config.IsOpenRemind,
  5527. "his_config_open": hisConfig.IsOpen,
  5528. "is_advice_open": is_advice_open.IsAdviceOpen,
  5529. "prescription_open": prescription_open.IsOpen,
  5530. })
  5531. }
  5532. }
  5533. }
  5534. func (c *DialysisAPIController) GetLongAdviceOne() {
  5535. patient_id, _ := c.GetInt64("id")
  5536. startTime := c.GetString("schedule_date")
  5537. timeLayout := "2006-01-02"
  5538. loc, _ := time.LoadLocation("Local")
  5539. var theStartTime int64
  5540. if len(startTime) > 0 {
  5541. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5542. if err != nil {
  5543. utils.ErrorLog(err.Error())
  5544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5545. return
  5546. }
  5547. theStartTime = theTime.Unix()
  5548. }
  5549. adminUserInfo := c.GetMobileAdminUserInfo()
  5550. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5551. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5552. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5553. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5554. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5555. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5556. c.ServeSuccessJSON(map[string]interface{}{
  5557. "status": "1",
  5558. })
  5559. return
  5560. } else { //开启推送提醒
  5561. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5562. var advice_three []*models.DoctorAdvice
  5563. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5564. fmt.Println("theStartTime-----------------------", theStartTime)
  5565. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5566. for _, advice := range advices {
  5567. if advice.FrequencyType == 3 {
  5568. t := time.Now()
  5569. week := int(t.Weekday())
  5570. fmt.Println(t.Weekday())
  5571. fmt.Println(week)
  5572. switch week {
  5573. case 1:
  5574. if strings.Index(advice.WeekDay, "周一") == -1 {
  5575. advice_three = append(advice_three, advice)
  5576. }
  5577. break
  5578. case 2:
  5579. if strings.Index(advice.WeekDay, "周二") == -1 {
  5580. advice_three = append(advice_three, advice)
  5581. }
  5582. break
  5583. case 3:
  5584. if strings.Index(advice.WeekDay, "周三") == -1 {
  5585. advice_three = append(advice_three, advice)
  5586. }
  5587. break
  5588. case 4:
  5589. if strings.Index(advice.WeekDay, "周四") == -1 {
  5590. advice_three = append(advice_three, advice)
  5591. }
  5592. break
  5593. case 5:
  5594. if strings.Index(advice.WeekDay, "周五") == -1 {
  5595. advice_three = append(advice_three, advice)
  5596. }
  5597. break
  5598. case 6:
  5599. if strings.Index(advice.WeekDay, "周六") == -1 {
  5600. advice_three = append(advice_three, advice)
  5601. }
  5602. break
  5603. case 0:
  5604. if strings.Index(advice.WeekDay, "周日") == -1 {
  5605. advice_three = append(advice_three, advice)
  5606. }
  5607. break
  5608. }
  5609. }
  5610. }
  5611. for _, advice := range advices_two {
  5612. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5613. now := p.Unix()
  5614. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5615. dayStr2 := "-" + dayStr
  5616. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5617. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5618. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5619. fmt.Println("advices-==---------------", advices)
  5620. for _, ad := range advices {
  5621. advice_three = append(advice_three, ad)
  5622. }
  5623. }
  5624. if err == nil {
  5625. c.ServeSuccessJSON(map[string]interface{}{
  5626. "status": "2",
  5627. "advices": advices,
  5628. "advices_two": RemoveRepeatedElement(advice_three),
  5629. "is_open_remind": config.IsOpenRemind,
  5630. "his_config_open": hisConfig.IsOpen,
  5631. "is_advice_open": is_advice_open.IsAdviceOpen,
  5632. "prescription_open": prescription_open.IsOpen,
  5633. })
  5634. }
  5635. }
  5636. }
  5637. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5638. newArr = make([]*models.DoctorAdvice, 0)
  5639. for i := 0; i < len(arr); i++ {
  5640. repeat := false
  5641. for j := i + 1; j < len(arr); j++ {
  5642. if arr[i].ID == arr[j].ID {
  5643. repeat = true
  5644. break
  5645. }
  5646. }
  5647. if !repeat {
  5648. newArr = append(newArr, arr[i])
  5649. }
  5650. }
  5651. return
  5652. }
  5653. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5654. patient, _ := c.GetInt64("id", 0)
  5655. groupNo, _ := c.GetInt64("groupno", 0)
  5656. if patient <= 0 {
  5657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5658. return
  5659. }
  5660. adminUserInfo := c.GetMobileAdminUserInfo()
  5661. dataBody := make(map[string]interface{}, 0)
  5662. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5663. if err != nil {
  5664. utils.ErrorLog(err.Error())
  5665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5666. return
  5667. }
  5668. utils.ErrorLog("%v", dataBody)
  5669. timeLayout := "2006-01-02 15:04"
  5670. loc, _ := time.LoadLocation("Local")
  5671. timeLayout2 := "2006-01-02"
  5672. loc2, _ := time.LoadLocation("Local")
  5673. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5674. utils.ErrorLog("advice_type")
  5675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5676. return
  5677. }
  5678. adviceType := int64(2)
  5679. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5680. utils.ErrorLog("advice_date")
  5681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5682. return
  5683. }
  5684. adviceDate, _ := dataBody["advice_date"].(string)
  5685. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5686. AdviceDate := theTime.Unix()
  5687. RecordDate := theTime.Unix()
  5688. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5689. utils.ErrorLog("start_time")
  5690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5691. return
  5692. }
  5693. startTime, _ := dataBody["start_time"].(string)
  5694. if len(startTime) == 0 {
  5695. utils.ErrorLog("len(start_time) == 0")
  5696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5697. return
  5698. }
  5699. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5700. if err != nil {
  5701. utils.ErrorLog(err.Error())
  5702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5703. return
  5704. }
  5705. StartTime := theTime.Unix()
  5706. Remark := ""
  5707. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5708. remark, _ := dataBody["remark"].(string)
  5709. Remark = remark
  5710. }
  5711. var advices []*models.GroupAdvice
  5712. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5713. utils.ErrorLog("advices")
  5714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5715. return
  5716. }
  5717. adviceNames := dataBody["advices"].([]interface{})
  5718. for _, adviceNameMap := range adviceNames {
  5719. adviceNameM := adviceNameMap.(map[string]interface{})
  5720. var advice models.GroupAdvice
  5721. advice.Remark = Remark
  5722. advice.AdviceType = adviceType
  5723. advice.StartTime = StartTime
  5724. advice.AdviceDate = AdviceDate
  5725. advice.RecordDate = RecordDate
  5726. advice.Status = 1
  5727. advice.CreatedTime = time.Now().Unix()
  5728. advice.UpdatedTime = time.Now().Unix()
  5729. advice.StopState = 2
  5730. advice.ExecutionState = 2
  5731. advice.UserOrgId = adminUserInfo.Org.Id
  5732. advice.PatientId = patient
  5733. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5734. advice.IsSettle = 2
  5735. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5736. utils.ErrorLog("advice_name")
  5737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5738. return
  5739. }
  5740. adviceName, _ := adviceNameM["advice_name"].(string)
  5741. if len(adviceName) == 0 {
  5742. utils.ErrorLog("len(advice_name) == 0")
  5743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5744. return
  5745. }
  5746. advice.AdviceName = adviceName
  5747. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5748. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5749. advice.DrugSpec = drugSpec
  5750. }
  5751. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5752. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5753. advice.AdviceDesc = adviceDesc
  5754. }
  5755. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5756. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5757. advice.DrugSpecUnit = drugSpecUnit
  5758. }
  5759. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5760. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5761. // advice.SingleDose = singleDose
  5762. //}
  5763. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5764. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5765. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5766. }
  5767. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5768. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5769. advice.SingleDoseUnit = singleDoseUnit
  5770. }
  5771. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5772. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5773. // advice.PrescribingNumber = prescribingNumber
  5774. //}
  5775. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5776. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5777. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5778. }
  5779. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5780. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5781. advice.PrescribingNumberUnit = prescribingNumberUnit
  5782. }
  5783. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5784. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5785. advice.DeliveryWay = deliveryWay
  5786. }
  5787. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5788. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5789. advice.ExecutionFrequency = executionFrequency
  5790. }
  5791. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5792. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5793. advice.FrequencyType = frequency_type
  5794. }
  5795. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5796. day_count := int64(adviceNameM["day_count"].(float64))
  5797. advice.DayCount = day_count
  5798. }
  5799. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5800. week_day, _ := adviceNameM["week_day"].(string)
  5801. advice.WeekDay = week_day
  5802. }
  5803. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5804. way := int64(adviceNameM["way"].(float64))
  5805. advice.Way = way
  5806. }
  5807. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5808. drug_id := int64(adviceNameM["drug_id"].(float64))
  5809. advice.DrugId = drug_id
  5810. }
  5811. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5812. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5813. advice.DrugNameId = drug_name_id
  5814. }
  5815. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5816. remark, _ := adviceNameM["remark"].(string)
  5817. advice.Remark = remark
  5818. }
  5819. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5820. groupno := int64(adviceNameM["groupno"].(float64))
  5821. advice.GroupNo = groupno
  5822. }
  5823. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5824. template_id, _ := adviceNameM["template_id"].(string)
  5825. advice.TemplateId = template_id
  5826. }
  5827. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5828. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5829. advice.ExecutionFrequency = executionFrequency
  5830. }
  5831. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5832. children := adviceNameM["child"].([]interface{})
  5833. if len(children) > 0 {
  5834. for _, childrenMap := range children {
  5835. childMap := childrenMap.(map[string]interface{})
  5836. var child models.GroupAdvice
  5837. child.Remark = Remark
  5838. child.AdviceType = adviceType
  5839. child.StartTime = StartTime
  5840. child.AdviceDate = AdviceDate
  5841. child.RecordDate = RecordDate
  5842. child.Status = 1
  5843. child.CreatedTime = time.Now().Unix()
  5844. child.UpdatedTime = time.Now().Unix()
  5845. child.StopState = 2
  5846. child.ExecutionState = 2
  5847. child.UserOrgId = adminUserInfo.Org.Id
  5848. child.PatientId = patient
  5849. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5850. child.IsSettle = 1
  5851. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5852. utils.ErrorLog("child advice_name")
  5853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5854. return
  5855. }
  5856. childAdviceName, _ := childMap["advice_name"].(string)
  5857. if len(childAdviceName) == 0 {
  5858. utils.ErrorLog("len(child advice_name) == 0")
  5859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5860. return
  5861. }
  5862. child.AdviceName = childAdviceName
  5863. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5864. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5865. child.AdviceDesc = childAdviceDesc
  5866. }
  5867. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5868. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5869. child.DrugSpec = childDrugSpec
  5870. }
  5871. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5872. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5873. child.DrugSpecUnit = childDrugSpecUnit
  5874. }
  5875. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5876. child.SingleDose = childMap["single_dose"].(float64)
  5877. }
  5878. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5879. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5880. child.SingleDoseUnit = childSingleDoseUnit
  5881. }
  5882. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5883. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5884. }
  5885. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5886. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5887. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5888. }
  5889. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5890. groupno := int64(childMap["groupno"].(float64))
  5891. advice.GroupNo = groupno
  5892. }
  5893. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5894. remark, _ := childMap["remark"].(string)
  5895. child.Remark = remark
  5896. }
  5897. child.DeliveryWay = advice.DeliveryWay
  5898. child.ExecutionFrequency = advice.ExecutionFrequency
  5899. advice.Children = append(advice.Children, &child)
  5900. }
  5901. }
  5902. }
  5903. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5904. if temp_advice.ID == 0 {
  5905. advices = append(advices, &advice)
  5906. }
  5907. }
  5908. if len(advices) > 0 {
  5909. finish := models.XtDialysisFinish{
  5910. IsFinish: 1,
  5911. UserOrgId: adminUserInfo.Org.Id,
  5912. Status: 1,
  5913. Ctime: time.Now().Unix(),
  5914. Mtime: 0,
  5915. Module: 4,
  5916. RecordDate: AdviceDate,
  5917. Sourse: 1,
  5918. PatientId: patient,
  5919. }
  5920. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5921. if dialysisFinish.ID == 0 {
  5922. service.CreateDialysisFinish(finish)
  5923. }
  5924. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5925. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5926. for _, item := range advices {
  5927. byterequest, _ := json.Marshal(item)
  5928. adviceLog := models.XtDoctorAdviceLog{
  5929. UserOrgId: adminUserInfo.Org.Id,
  5930. PatientId: patient,
  5931. AdminUserId: adminUserInfo.AdminUser.Id,
  5932. Module: 1,
  5933. ErrLog: string(byterequest),
  5934. Status: 1,
  5935. Ctime: time.Now().Unix(),
  5936. Mtime: 0,
  5937. Source: "手机端医嘱推送",
  5938. RecordDate: item.AdviceDate,
  5939. }
  5940. service.CreateDoctorAdviceLog(adviceLog)
  5941. }
  5942. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5943. redis := service.RedisClient()
  5944. //清空key 值
  5945. redis.Set(key, "", time.Second)
  5946. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5947. redis.Set(keyOne, "", time.Second)
  5948. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5949. defer redis.Close()
  5950. redis.Set(keyThree, "", time.Second)
  5951. if err != nil {
  5952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5953. return
  5954. }
  5955. c.ServeSuccessJSON(map[string]interface{}{
  5956. "msg": "ok",
  5957. "advices": list,
  5958. })
  5959. } else {
  5960. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5961. for _, item := range advices {
  5962. byterequest, _ := json.Marshal(item)
  5963. adviceLog := models.XtDoctorAdviceLog{
  5964. UserOrgId: adminUserInfo.Org.Id,
  5965. PatientId: patient,
  5966. AdminUserId: adminUserInfo.AdminUser.Id,
  5967. Module: 1,
  5968. ErrLog: string(byterequest),
  5969. Status: 1,
  5970. Ctime: time.Now().Unix(),
  5971. Mtime: 0,
  5972. Source: "手机端医嘱推送",
  5973. RecordDate: item.AdviceDate,
  5974. }
  5975. service.CreateDoctorAdviceLog(adviceLog)
  5976. }
  5977. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5978. redis := service.RedisClient()
  5979. //清空key 值
  5980. redis.Set(key, "", time.Second)
  5981. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5982. redis.Set(keyOne, "", time.Second)
  5983. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5984. defer redis.Close()
  5985. redis.Set(keyThree, "", time.Second)
  5986. if err != nil {
  5987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5988. return
  5989. }
  5990. c.ServeSuccessJSON(map[string]interface{}{
  5991. "msg": "ok",
  5992. "advices": list,
  5993. })
  5994. }
  5995. } else {
  5996. c.ServeSuccessJSON(map[string]interface{}{
  5997. "msg": "ok",
  5998. })
  5999. }
  6000. return
  6001. }
  6002. func (c *DialysisAPIController) UploadDryWeight() {
  6003. patient_id, _ := c.GetInt64("id")
  6004. dry_weight, _ := c.GetFloat("dry_weight")
  6005. doctor_id, _ := c.GetInt64("doctor_id")
  6006. remark := c.GetString("remark")
  6007. adminUserInfo := c.GetMobileAdminUserInfo()
  6008. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  6009. if err == gorm.ErrRecordNotFound {
  6010. dryWeight := &models.SgjPatientDryweight{
  6011. PatientId: patient_id,
  6012. DryWeight: dry_weight,
  6013. Remakes: remark,
  6014. Ctime: time.Now().Unix(),
  6015. Mtime: time.Now().Unix(),
  6016. Creator: doctor_id,
  6017. Status: 1,
  6018. UserOrgId: adminUserInfo.Org.Id,
  6019. AdjustedValue: "/",
  6020. UserId: adminUserInfo.AdminUser.Id,
  6021. }
  6022. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6023. redis := service.RedisClient()
  6024. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  6025. redis.Set(keyOne, "", time.Second)
  6026. loc, _ := time.LoadLocation("Local")
  6027. nowTime := time.Now()
  6028. nowDay := nowTime.Format("2006-01-02")
  6029. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6030. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6031. redis.Set(key, "", time.Second)
  6032. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6033. redis.Set(keyTwo, "", time.Second)
  6034. redis.Close()
  6035. if createErr == nil {
  6036. c.ServeSuccessJSON(map[string]interface{}{
  6037. "msg": "提交成功",
  6038. "weight": dryWeight,
  6039. })
  6040. }
  6041. } else {
  6042. dryWeight := &models.SgjPatientDryweight{
  6043. PatientId: patient_id,
  6044. DryWeight: dry_weight,
  6045. Remakes: remark,
  6046. Ctime: time.Now().Unix(),
  6047. Mtime: time.Now().Unix(),
  6048. Creator: doctor_id,
  6049. Status: 1,
  6050. UserOrgId: adminUserInfo.Org.Id,
  6051. AdjustedValue: "/",
  6052. UserId: adminUserInfo.AdminUser.Id,
  6053. }
  6054. var value float64
  6055. value = dry_weight - weightAdjust.DryWeight
  6056. if value < 0 {
  6057. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  6058. } else if value == 0 {
  6059. dryWeight.AdjustedValue = "/"
  6060. } else if value > 0 {
  6061. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  6062. }
  6063. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6064. //康桥
  6065. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  6066. timeNowStr := time.Now().Format("2006-01-02")
  6067. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6068. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6069. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6070. if beforAssesment.ID > 0 {
  6071. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  6072. var dewater_amount float64
  6073. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  6074. if adminUserInfo.Org.Id != 10702 {
  6075. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  6076. }
  6077. if adminUserInfo.Org.Id == 10702 {
  6078. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  6079. }
  6080. //获取key,清空redis
  6081. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  6082. redis := service.RedisClient()
  6083. //清空key 值
  6084. redis.Set(key, "", time.Second)
  6085. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6086. //清空key 值
  6087. redis.Set(keyOne, "", time.Second)
  6088. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  6089. //清空key 值
  6090. redis.Set(keyTwo, "", time.Second)
  6091. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  6092. redis.Set(keySix, "", time.Second)
  6093. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  6094. redis.Set(keySeven, "", time.Second)
  6095. }
  6096. }
  6097. redis := service.RedisClient()
  6098. loc, _ := time.LoadLocation("Local")
  6099. nowTime := time.Now()
  6100. nowDay := nowTime.Format("2006-01-02")
  6101. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6102. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  6103. redis.Set(keyOne, "", time.Second)
  6104. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6105. redis.Set(key, "", time.Second)
  6106. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6107. redis.Set(keyTwo, "", time.Second)
  6108. redis.Close()
  6109. if createErr == nil {
  6110. c.ServeSuccessJSON(map[string]interface{}{
  6111. "msg": "提交成功",
  6112. "weight": dryWeight,
  6113. })
  6114. }
  6115. }
  6116. }
  6117. func (c *DialysisAPIController) GetSolution() {
  6118. patient_id, _ := c.GetInt64("patient_id")
  6119. mode_id, _ := c.GetInt64("mode_id")
  6120. adminUserInfo := c.GetMobileAdminUserInfo()
  6121. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6122. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6123. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  6124. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  6125. if err != nil {
  6126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6127. return
  6128. }
  6129. c.ServeSuccessJSON(map[string]interface{}{
  6130. "solution": solution,
  6131. "prescription": prescription,
  6132. "system_prescription": system_prescription,
  6133. "dialysisPrescription": dialysisPrescription,
  6134. })
  6135. }
  6136. func (c *DialysisAPIController) GetSchedule() {
  6137. schedual_type, _ := c.GetInt64("schedual_type")
  6138. adminUserInfo := c.GetMobileAdminUserInfo()
  6139. scheduleTime, _ := c.GetInt64("record_date")
  6140. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  6141. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  6142. c.ServeSuccessJSON(map[string]interface{}{
  6143. "number": deviceNumber,
  6144. "list": list,
  6145. })
  6146. }
  6147. func (c *DialysisAPIController) GetPatientId() {
  6148. id, _ := c.GetInt64("id")
  6149. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6150. patientId, _ := service.GetPatientId(id)
  6151. //获取该患者的所有传染病
  6152. list, _ := service.GetPatientInfectious(id)
  6153. c.ServeSuccessJSON(map[string]interface{}{
  6154. "patient": patientId,
  6155. "infectioulist": list,
  6156. })
  6157. }
  6158. func (this *DialysisAPIController) GetDialysisSchedule() {
  6159. schedualDate := this.GetString("date")
  6160. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6161. if parseDateErr != nil {
  6162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6163. return
  6164. }
  6165. adminInfo := this.GetMobileAdminUserInfo()
  6166. orgID := adminInfo.Org.Id
  6167. redis := service.RedisClient()
  6168. defer redis.Close()
  6169. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  6170. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  6171. if len(scheduals) > 0 {
  6172. //缓存数据
  6173. scheduals_json, err := json.Marshal(scheduals)
  6174. if err == nil {
  6175. redis.Set(key, scheduals_json, time.Second*30)
  6176. }
  6177. }
  6178. this.ServeSuccessJSON(map[string]interface{}{
  6179. "scheduals": scheduals,
  6180. })
  6181. }
  6182. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  6183. change_type, _ := this.GetInt64("type", 0)
  6184. record_date := this.GetString("record_time")
  6185. patient_id, _ := this.GetInt64("patient_id", 0)
  6186. timeLayout := "2006-01-02"
  6187. loc, _ := time.LoadLocation("Local")
  6188. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6189. record_time := theAdviceRecordTime.Unix()
  6190. adminUserInfo := this.GetMobileAdminUserInfo()
  6191. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  6192. if err == nil {
  6193. if len(advices) == 0 {
  6194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6195. return
  6196. } else {
  6197. this.ServeSuccessJSON(map[string]interface{}{
  6198. "advices": advices,
  6199. "schedule": sch,
  6200. })
  6201. return
  6202. }
  6203. } else {
  6204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6205. return
  6206. }
  6207. }
  6208. func (c *DialysisAPIController) CreateConsumables() {
  6209. record_date := c.GetString("record_time")
  6210. patient_id, _ := c.GetInt64("patient_id", 0)
  6211. active, _ := c.GetInt64("active")
  6212. adminUser := c.GetMobileAdminUserInfo()
  6213. timeLayout := "2006-01-02"
  6214. loc, _ := time.LoadLocation("Local")
  6215. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6216. record_time := theRecordTime.Unix()
  6217. // 查询信息规挡的设置天数
  6218. orgid := c.GetMobileAdminUserInfo().Org.Id
  6219. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  6220. if infor.ID > 0 {
  6221. var cha_time int64
  6222. timeNowStr := time.Now().Format("2006-01-02")
  6223. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6224. //今日的日期减去设置的日期
  6225. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6226. if cha_time >= record_time {
  6227. //查询审核是否允许
  6228. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  6229. //申请状态不允许的情况 拒绝修改
  6230. if infor.ApplicationStatus != 1 {
  6231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6232. return
  6233. }
  6234. }
  6235. }
  6236. dataBody := make(map[string]interface{}, 0)
  6237. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6238. if err != nil {
  6239. utils.ErrorLog(err.Error())
  6240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6241. return
  6242. }
  6243. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6244. var beforePrepares []*models.DialysisBeforePrepareGoods
  6245. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6246. var dialysisBefor []*models.DialysisBeforePrepare
  6247. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6248. goods, _ := dataBody["goods"].([]interface{})
  6249. if len(goods) > 0 {
  6250. for _, item := range goods {
  6251. items := item.(map[string]interface{})
  6252. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6253. utils.ErrorLog("good_id")
  6254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6255. return
  6256. }
  6257. good_id := int64(items["good_id"].(float64))
  6258. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6259. utils.ErrorLog("good_type_id")
  6260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6261. return
  6262. }
  6263. good_type_id := int64(items["good_type_id"].(float64))
  6264. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6265. utils.ErrorLog("count")
  6266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6267. return
  6268. }
  6269. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6270. commdity_code := items["commdity_code"].(string)
  6271. fmt.Println("commdity", commdity_code)
  6272. prepareGoods := &models.DialysisBeforePrepareGoods{
  6273. GoodTypeId: good_type_id,
  6274. GoodId: good_id,
  6275. Count: count,
  6276. StorehouseId: houseConfig.StorehouseOutInfo,
  6277. }
  6278. beforePrepares = append(beforePrepares, prepareGoods)
  6279. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6280. GoodTypeId: good_type_id,
  6281. GoodId: good_id,
  6282. Count: count,
  6283. StorehouseId: houseConfig.StorehouseOutInfo,
  6284. }
  6285. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6286. prepare := &models.DialysisBeforePrepare{
  6287. GoodTypeId: good_type_id,
  6288. GoodId: good_id,
  6289. Count: count,
  6290. PatientId: patient_id,
  6291. RecordDate: record_time,
  6292. UserOrgId: adminUser.Org.Id,
  6293. Status: 1,
  6294. Ctime: time.Now().Unix(),
  6295. Creater: adminUser.AdminUser.Id,
  6296. CommdityCode: commdity_code,
  6297. StorehouseId: houseConfig.StorehouseOutInfo,
  6298. }
  6299. dialysisBefor = append(dialysisBefor, prepare)
  6300. }
  6301. }
  6302. //查询是否有库存
  6303. for _, item := range dialysisBefor {
  6304. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6305. if err == gorm.ErrRecordNotFound {
  6306. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6307. c.ServeSuccessJSON(map[string]interface{}{
  6308. "message": "1",
  6309. "good_name": goodObj.GoodName,
  6310. "specification_name": goodObj.SpecificationName,
  6311. })
  6312. return
  6313. }
  6314. if err != nil {
  6315. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6316. c.ServeSuccessJSON(map[string]interface{}{
  6317. "message": "1",
  6318. "good_name": goodObj.GoodName,
  6319. "specification_name": goodObj.SpecificationName,
  6320. })
  6321. return
  6322. }
  6323. }
  6324. fmt.Println("active-----------------------", active)
  6325. fmt.Println("len(goods)-----------------------", len(goods))
  6326. //新增
  6327. if active == 1 && len(goods) > 0 {
  6328. for _, item := range dialysisBefor {
  6329. dialyPrepareOne := models.DialysisBeforePrepare{
  6330. GoodTypeId: item.GoodTypeId,
  6331. GoodId: item.GoodId,
  6332. PatientId: item.PatientId,
  6333. RecordDate: item.RecordDate,
  6334. UserOrgId: item.UserOrgId,
  6335. Count: item.Count,
  6336. Ctime: time.Now().Unix(),
  6337. Creater: item.Creater,
  6338. CommdityCode: item.CommdityCode,
  6339. Status: 1,
  6340. StorehouseId: houseConfig.StorehouseOutInfo,
  6341. }
  6342. //先清除再插入
  6343. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6344. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6345. //查询默认仓库
  6346. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6347. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6348. var total_count int64
  6349. for _, it := range stockList {
  6350. total_count += it.StockCount
  6351. }
  6352. //基础库插入数据
  6353. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6354. //更新库存
  6355. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6356. var flush_count int64
  6357. for _, it := range goodList {
  6358. flush_count += it.StockCount
  6359. }
  6360. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6361. }
  6362. if err == nil {
  6363. c.ServeSuccessJSON(map[string]interface{}{
  6364. "msg": "保存成功",
  6365. "message": "2",
  6366. })
  6367. return
  6368. } else {
  6369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6370. return
  6371. }
  6372. }
  6373. if len(beforePrepares) > 0 && active == 2 {
  6374. for _, item := range beforePrepares {
  6375. //1.查看该患者该耗材型号最后一次出库数量
  6376. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6377. //判断当前出库数量和最后一次出库数量的大小
  6378. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6379. if item.Count <= goodInfo.Count {
  6380. //退库
  6381. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6382. //查询今日出库数据
  6383. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6384. for _, it := range list {
  6385. prepare := models.DialysisBeforePrepare{
  6386. UserOrgId: it.OrgId,
  6387. PatientId: patient_id,
  6388. RecordDate: it.RecordTime,
  6389. GoodId: it.GoodId,
  6390. GoodTypeId: it.GoodTypeId,
  6391. Count: it.Count,
  6392. Ctime: time.Now().Unix(),
  6393. Creater: adminUser.AdminUser.Id,
  6394. Status: 1,
  6395. StorehouseId: houseConfig.StorehouseOutInfo,
  6396. }
  6397. //删除准备表数据
  6398. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6399. service.CreateDialysisBeforePrepareOne(&prepare)
  6400. }
  6401. }
  6402. var last_total int64
  6403. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6404. if item.Count >= goodInfo.Count {
  6405. //查询当前批次当前耗材最后一条出库数据
  6406. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6407. //计算当前出库和最后一次出库数据相差数据
  6408. last_total = item.Count - lastOutInfo.Count
  6409. //查询该批次剩余库存
  6410. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6411. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6412. if lastInfo.StockCount >= last_total {
  6413. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6414. //查询今日出库数据
  6415. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6416. for _, it := range list {
  6417. prepare := models.DialysisBeforePrepare{
  6418. UserOrgId: it.OrgId,
  6419. PatientId: patient_id,
  6420. RecordDate: it.RecordTime,
  6421. GoodId: it.GoodId,
  6422. GoodTypeId: it.GoodTypeId,
  6423. Count: it.Count,
  6424. Ctime: time.Now().Unix(),
  6425. Creater: adminUser.AdminUser.Id,
  6426. Status: 1,
  6427. StorehouseId: houseConfig.StorehouseOutInfo,
  6428. }
  6429. //删除准备表数据
  6430. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6431. service.CreateDialysisBeforePrepareOne(&prepare)
  6432. //查询默认仓库
  6433. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6434. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6435. var total_count int64
  6436. for _, it := range stockList {
  6437. total_count += it.StockCount
  6438. }
  6439. //基础库插入数据
  6440. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6441. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6442. var flush_count int64
  6443. for _, it := range goodList {
  6444. flush_count += it.StockCount
  6445. }
  6446. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6447. }
  6448. }
  6449. //如果库存不够,则出库到下一个批次
  6450. if lastInfo.StockCount < last_total {
  6451. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6452. //查询今日出库数据
  6453. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6454. for _, it := range list {
  6455. prepare := models.DialysisBeforePrepare{
  6456. UserOrgId: it.OrgId,
  6457. PatientId: patient_id,
  6458. RecordDate: it.RecordTime,
  6459. GoodId: it.GoodId,
  6460. GoodTypeId: it.GoodTypeId,
  6461. Count: it.Count,
  6462. Ctime: time.Now().Unix(),
  6463. Creater: adminUser.AdminUser.Id,
  6464. Status: 1,
  6465. StorehouseId: houseConfig.StorehouseOutInfo,
  6466. }
  6467. //删除准备表数据
  6468. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6469. service.CreateDialysisBeforePrepareOne(&prepare)
  6470. //查询默认仓库
  6471. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6472. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6473. var total_count int64
  6474. for _, it := range stockList {
  6475. total_count += it.StockCount
  6476. }
  6477. //基础库插入数据
  6478. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6479. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6480. var flush_count int64
  6481. for _, it := range goodList {
  6482. flush_count += it.StockCount
  6483. }
  6484. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6485. }
  6486. if err != nil {
  6487. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6488. c.ServeSuccessJSON(map[string]interface{}{
  6489. "message": "1",
  6490. "good_name": goodObj.GoodName,
  6491. "specification_name": goodObj.SpecificationName,
  6492. })
  6493. return
  6494. }
  6495. }
  6496. }
  6497. if err != nil {
  6498. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6499. c.ServeSuccessJSON(map[string]interface{}{
  6500. "message": "1",
  6501. "good_name": goodObj.GoodName,
  6502. "specification_name": goodObj.SpecificationName,
  6503. })
  6504. return
  6505. }
  6506. }
  6507. }
  6508. }
  6509. var errs error
  6510. if errs == nil {
  6511. c.ServeSuccessJSON(map[string]interface{}{
  6512. "msg": "提交成功",
  6513. "message": "2",
  6514. "good_name": "",
  6515. "specification_name": "",
  6516. })
  6517. return
  6518. } else {
  6519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6520. return
  6521. }
  6522. }
  6523. func (c *DialysisAPIController) CreateStockOutInfo() {
  6524. patient_id, _ := c.GetInt64("patient_id", 0)
  6525. record_date := c.GetString("record_time")
  6526. if patient_id <= 0 {
  6527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6528. return
  6529. }
  6530. adminInfo := c.GetMobileAdminUserInfo()
  6531. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6532. timeLayout := "2006-01-02"
  6533. loc, _ := time.LoadLocation("Local")
  6534. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6535. record_time := theRecordTime.Unix()
  6536. // 查询信息规挡的设置天数
  6537. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6538. if infor.ID > 0 && infor.WeekDay > 0 {
  6539. var cha_time int64
  6540. timeNowStr := time.Now().Format("2006-01-02")
  6541. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6542. //今日的日期减去设置的日期
  6543. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6544. if cha_time >= record_time {
  6545. //查询审核是否允许
  6546. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6547. //申请状态不允许的情况 拒绝修改
  6548. if infor.ApplicationStatus != 1 {
  6549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6550. return
  6551. }
  6552. }
  6553. }
  6554. //创建步骤表
  6555. finish := models.XtDialysisFinish{
  6556. IsFinish: 1,
  6557. UserOrgId: adminInfo.Org.Id,
  6558. Status: 1,
  6559. Ctime: time.Now().Unix(),
  6560. Mtime: 0,
  6561. Module: 11,
  6562. RecordDate: record_time,
  6563. Sourse: 1,
  6564. PatientId: patient_id,
  6565. }
  6566. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6567. if dialysisFinish.ID == 0 {
  6568. service.CreateDialysisFinish(finish)
  6569. }
  6570. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6571. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6572. //去重
  6573. consumables = RemoveRepeatedGood(consumables)
  6574. if adminInfo.Org.Id == 9919 {
  6575. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6576. //查询是否有库存
  6577. for _, item := range consumables {
  6578. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6579. if item.Count > warehouse.Count {
  6580. goodErrcode := models.XtGoodErrcode{
  6581. UserOrgId: item.UserOrgId,
  6582. Errcode: "自动出库库存不足",
  6583. GoodId: item.GoodId,
  6584. Status: 1,
  6585. Ctime: time.Now().Unix(),
  6586. Mtime: 0,
  6587. Count: 0,
  6588. StockCount: 0,
  6589. Creater: creator,
  6590. BatchNumberId: warehouse.ID,
  6591. WarehouseOutId: 0,
  6592. }
  6593. service.CreateGoodErrcode(goodErrcode)
  6594. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6595. c.ServeSuccessJSON(map[string]interface{}{
  6596. "message": "1",
  6597. "good_name": goodObj.GoodName,
  6598. "specification_name": goodObj.SpecificationName,
  6599. })
  6600. return
  6601. }
  6602. }
  6603. //查询是否有出库单
  6604. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6605. if err == gorm.ErrRecordNotFound {
  6606. //没有记录,则创建出库单
  6607. timeStr := time.Now().Format("2006-01-02")
  6608. timeArr := strings.Split(timeStr, "-")
  6609. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6610. total = total + 1
  6611. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6612. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6613. number = number + total
  6614. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6615. creater := adminInfo.AdminUser.Id
  6616. warehouseOut := models.WarehouseOut{
  6617. WarehouseOutOrderNumber: warehousing_out_order,
  6618. OperationTime: time.Now().Unix(),
  6619. OrgId: adminInfo.Org.Id,
  6620. Creater: creater,
  6621. Ctime: time.Now().Unix(),
  6622. Status: 1,
  6623. WarehouseOutTime: record_time,
  6624. Dealer: 0,
  6625. Manufacturer: 0,
  6626. Type: 1,
  6627. IsSys: 1,
  6628. StorehouseId: houseConfig.StorehouseOutInfo,
  6629. IsCheck: 1,
  6630. }
  6631. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6632. if err != nil {
  6633. goodErrcode := models.XtGoodErrcode{
  6634. UserOrgId: adminInfo.Org.Id,
  6635. Errcode: "创建出库单失败",
  6636. GoodId: 0,
  6637. Status: 1,
  6638. Ctime: time.Now().Unix(),
  6639. Mtime: 0,
  6640. Count: 0,
  6641. StockCount: 0,
  6642. Creater: creator,
  6643. BatchNumberId: 0,
  6644. WarehouseOutId: 0,
  6645. }
  6646. service.CreateGoodErrcode(goodErrcode)
  6647. utils.TraceLog("创建出库单失败 err = %v", err)
  6648. } else {
  6649. for _, item := range consumables {
  6650. //出库
  6651. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6652. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6653. if err == nil {
  6654. goodErrcode := models.XtGoodErrcode{
  6655. UserOrgId: adminInfo.Org.Id,
  6656. Errcode: "自动出库接口报错",
  6657. GoodId: 0,
  6658. Status: 1,
  6659. Ctime: time.Now().Unix(),
  6660. Mtime: 0,
  6661. Count: 0,
  6662. StockCount: 0,
  6663. Creater: creator,
  6664. BatchNumberId: 0,
  6665. WarehouseOutId: 0,
  6666. }
  6667. service.CreateGoodErrcode(goodErrcode)
  6668. utils.TraceLog("创建出库单失败 err = %v", err)
  6669. }
  6670. //查询
  6671. //出库数量相加
  6672. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6673. if errs != nil {
  6674. goodErrcode := models.XtGoodErrcode{
  6675. UserOrgId: item.UserOrgId,
  6676. Errcode: "创建剩余库存字段报错",
  6677. GoodId: item.GoodId,
  6678. Status: 1,
  6679. Ctime: time.Now().Unix(),
  6680. Mtime: 0,
  6681. Count: 0,
  6682. StockCount: 0,
  6683. Creater: creater,
  6684. BatchNumberId: 0,
  6685. WarehouseOutId: 0,
  6686. }
  6687. service.CreateGoodErrcode(goodErrcode)
  6688. }
  6689. }
  6690. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6691. if len(list) == 0 {
  6692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6693. return
  6694. }
  6695. for _, item := range list {
  6696. prepare := models.DialysisBeforePrepare{
  6697. UserOrgId: adminInfo.Org.Id,
  6698. PatientId: patient_id,
  6699. RecordDate: record_time,
  6700. GoodId: item.GoodId,
  6701. GoodTypeId: item.GoodTypeId,
  6702. Count: item.Count,
  6703. Creater: adminInfo.AdminUser.Id,
  6704. Status: 1,
  6705. Ctime: time.Now().Unix(),
  6706. StorehouseId: houseConfig.StorehouseOutInfo,
  6707. }
  6708. //清空准备表数据
  6709. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6710. if err != nil {
  6711. goodErrcode := models.XtGoodErrcode{
  6712. UserOrgId: item.OrgId,
  6713. Errcode: "自动出库清空准备表数据报错",
  6714. GoodId: item.GoodId,
  6715. Status: 1,
  6716. Ctime: time.Now().Unix(),
  6717. Mtime: 0,
  6718. Count: 0,
  6719. StockCount: 0,
  6720. Creater: creater,
  6721. BatchNumberId: 0,
  6722. WarehouseOutId: 0,
  6723. }
  6724. service.CreateGoodErrcode(goodErrcode)
  6725. }
  6726. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6727. if errs != nil {
  6728. goodErrcode := models.XtGoodErrcode{
  6729. UserOrgId: item.OrgId,
  6730. Errcode: "自动出库创建准备表数据报错",
  6731. GoodId: item.GoodId,
  6732. Status: 1,
  6733. Ctime: time.Now().Unix(),
  6734. Mtime: 0,
  6735. Count: 0,
  6736. StockCount: 0,
  6737. Creater: creater,
  6738. BatchNumberId: 0,
  6739. WarehouseOutId: 0,
  6740. }
  6741. service.CreateGoodErrcode(goodErrcode)
  6742. }
  6743. //查询默认仓库
  6744. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6745. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6746. var total_count int64
  6747. for _, it := range stockList {
  6748. total_count += it.StockCount
  6749. }
  6750. //基础库插入数据
  6751. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6752. if errcodes != nil {
  6753. goodErrcode := models.XtGoodErrcode{
  6754. UserOrgId: item.OrgId,
  6755. Errcode: "自动出库基础库插入数据",
  6756. GoodId: item.GoodId,
  6757. Status: 1,
  6758. Ctime: time.Now().Unix(),
  6759. Mtime: 0,
  6760. Count: 0,
  6761. StockCount: 0,
  6762. Creater: creater,
  6763. BatchNumberId: 0,
  6764. WarehouseOutId: 0,
  6765. }
  6766. service.CreateGoodErrcode(goodErrcode)
  6767. }
  6768. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6769. var flush_count int64
  6770. for _, it := range goodList {
  6771. flush_count += it.StockCount
  6772. }
  6773. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6774. if errsss != nil {
  6775. goodErrcode := models.XtGoodErrcode{
  6776. UserOrgId: item.OrgId,
  6777. Errcode: "自动出库剩余库存更新数据",
  6778. GoodId: item.GoodId,
  6779. Status: 1,
  6780. Ctime: time.Now().Unix(),
  6781. Mtime: 0,
  6782. Count: 0,
  6783. StockCount: 0,
  6784. Creater: creater,
  6785. BatchNumberId: 0,
  6786. WarehouseOutId: 0,
  6787. }
  6788. service.CreateGoodErrcode(goodErrcode)
  6789. }
  6790. }
  6791. }
  6792. //
  6793. } else if err == nil {
  6794. for _, item := range consumables {
  6795. //出库
  6796. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6797. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6798. if err != nil {
  6799. goodErrcode := models.XtGoodErrcode{
  6800. UserOrgId: adminInfo.Org.Id,
  6801. Errcode: "自动出库接口报错",
  6802. GoodId: 0,
  6803. Status: 1,
  6804. Ctime: time.Now().Unix(),
  6805. Mtime: 0,
  6806. Count: 0,
  6807. StockCount: 0,
  6808. Creater: creator,
  6809. BatchNumberId: 0,
  6810. WarehouseOutId: 0,
  6811. }
  6812. service.CreateGoodErrcode(goodErrcode)
  6813. }
  6814. //出库数量相加
  6815. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6816. if errss != nil {
  6817. goodErrcode := models.XtGoodErrcode{
  6818. UserOrgId: item.UserOrgId,
  6819. Errcode: "创建剩余库存字段报错",
  6820. GoodId: item.GoodId,
  6821. Status: 1,
  6822. Ctime: time.Now().Unix(),
  6823. Mtime: time.Now().Unix(),
  6824. Count: 0,
  6825. StockCount: 0,
  6826. Creater: item.Creater,
  6827. BatchNumberId: 0,
  6828. WarehouseOutId: 0,
  6829. }
  6830. service.CreateGoodErrcode(goodErrcode)
  6831. }
  6832. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6833. if len(list) == 0 {
  6834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6835. return
  6836. }
  6837. for _, item := range list {
  6838. prepare := models.DialysisBeforePrepare{
  6839. UserOrgId: adminInfo.Org.Id,
  6840. PatientId: patient_id,
  6841. RecordDate: record_time,
  6842. GoodId: item.GoodId,
  6843. GoodTypeId: item.GoodTypeId,
  6844. Count: item.Count,
  6845. Creater: adminInfo.AdminUser.Id,
  6846. Status: 1,
  6847. Ctime: time.Now().Unix(),
  6848. StorehouseId: houseConfig.StorehouseOutInfo,
  6849. }
  6850. //清空准备表数据
  6851. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6852. if errs != nil {
  6853. goodErrcode := models.XtGoodErrcode{
  6854. UserOrgId: adminInfo.Org.Id,
  6855. Errcode: "自动出库清空准备表数据报错",
  6856. GoodId: 0,
  6857. Status: 1,
  6858. Ctime: time.Now().Unix(),
  6859. Mtime: 0,
  6860. Count: 0,
  6861. StockCount: 0,
  6862. Creater: creator,
  6863. BatchNumberId: 0,
  6864. WarehouseOutId: 0,
  6865. }
  6866. service.CreateGoodErrcode(goodErrcode)
  6867. }
  6868. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6869. if errcodes != nil {
  6870. goodErrcode := models.XtGoodErrcode{
  6871. UserOrgId: adminInfo.Org.Id,
  6872. Errcode: "自动出库创建准备表数据报错",
  6873. GoodId: 0,
  6874. Status: 1,
  6875. Ctime: time.Now().Unix(),
  6876. Mtime: 0,
  6877. Count: 0,
  6878. StockCount: 0,
  6879. Creater: creator,
  6880. BatchNumberId: 0,
  6881. WarehouseOutId: 0,
  6882. }
  6883. service.CreateGoodErrcode(goodErrcode)
  6884. }
  6885. //查询默认仓库
  6886. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6887. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6888. var total_count int64
  6889. for _, it := range stockList {
  6890. total_count += it.StockCount
  6891. }
  6892. //基础库插入数据
  6893. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6894. if errcodes != nil {
  6895. goodErrcode := models.XtGoodErrcode{
  6896. UserOrgId: adminInfo.Org.Id,
  6897. Errcode: "自动出库基础库插入数据报错",
  6898. GoodId: 0,
  6899. Status: 1,
  6900. Ctime: time.Now().Unix(),
  6901. Mtime: 0,
  6902. Count: 0,
  6903. StockCount: 0,
  6904. Creater: creator,
  6905. BatchNumberId: 0,
  6906. WarehouseOutId: 0,
  6907. }
  6908. service.CreateGoodErrcode(goodErrcode)
  6909. }
  6910. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6911. var flush_count int64
  6912. for _, it := range goodList {
  6913. flush_count += it.StockCount
  6914. }
  6915. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6916. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6917. if errss != nil {
  6918. goodErrcode := models.XtGoodErrcode{
  6919. UserOrgId: item.OrgId,
  6920. Errcode: "自动出库剩余库存更新数据",
  6921. GoodId: item.GoodId,
  6922. Status: 1,
  6923. Ctime: time.Now().Unix(),
  6924. Mtime: 0,
  6925. Count: 0,
  6926. StockCount: 0,
  6927. Creater: creater,
  6928. BatchNumberId: 0,
  6929. WarehouseOutId: 0,
  6930. }
  6931. service.CreateGoodErrcode(goodErrcode)
  6932. }
  6933. }
  6934. }
  6935. }
  6936. c.ServeSuccessJSON(map[string]interface{}{
  6937. "msg": "提交成功",
  6938. "message": "2",
  6939. "good_name": "",
  6940. "specification_name": "",
  6941. })
  6942. return
  6943. }
  6944. if record.IsOpen == 1 {
  6945. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6946. //查询是否有库存
  6947. for _, item := range consumables {
  6948. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6949. if item.Count > warehouse.Count {
  6950. goodErrcode := models.XtGoodErrcode{
  6951. UserOrgId: item.UserOrgId,
  6952. Errcode: "自动出库库存不足",
  6953. GoodId: item.GoodId,
  6954. Status: 1,
  6955. Ctime: time.Now().Unix(),
  6956. Mtime: 0,
  6957. Count: 0,
  6958. StockCount: 0,
  6959. Creater: creator,
  6960. BatchNumberId: warehouse.ID,
  6961. WarehouseOutId: 0,
  6962. }
  6963. service.CreateGoodErrcode(goodErrcode)
  6964. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6965. c.ServeSuccessJSON(map[string]interface{}{
  6966. "message": "1",
  6967. "good_name": goodObj.GoodName,
  6968. "specification_name": goodObj.SpecificationName,
  6969. })
  6970. return
  6971. }
  6972. }
  6973. //查询是否有出库单
  6974. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6975. if err == gorm.ErrRecordNotFound {
  6976. //没有记录,则创建出库单
  6977. timeStr := time.Now().Format("2006-01-02")
  6978. timeArr := strings.Split(timeStr, "-")
  6979. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6980. total = total + 1
  6981. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6982. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6983. number = number + total
  6984. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6985. creater := adminInfo.AdminUser.Id
  6986. warehouseOut := models.WarehouseOut{
  6987. WarehouseOutOrderNumber: warehousing_out_order,
  6988. OperationTime: time.Now().Unix(),
  6989. OrgId: adminInfo.Org.Id,
  6990. Creater: creater,
  6991. Ctime: time.Now().Unix(),
  6992. Status: 1,
  6993. WarehouseOutTime: record_time,
  6994. Dealer: 0,
  6995. Manufacturer: 0,
  6996. Type: 1,
  6997. IsSys: 1,
  6998. StorehouseId: houseConfig.StorehouseOutInfo,
  6999. IsCheck: 1,
  7000. }
  7001. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  7002. if err != nil {
  7003. goodErrcode := models.XtGoodErrcode{
  7004. UserOrgId: adminInfo.Org.Id,
  7005. Errcode: "创建出库单失败",
  7006. GoodId: 0,
  7007. Status: 1,
  7008. Ctime: time.Now().Unix(),
  7009. Mtime: 0,
  7010. Count: 0,
  7011. StockCount: 0,
  7012. Creater: creator,
  7013. BatchNumberId: 0,
  7014. WarehouseOutId: 0,
  7015. }
  7016. service.CreateGoodErrcode(goodErrcode)
  7017. utils.TraceLog("创建出库单失败 err = %v", err)
  7018. } else {
  7019. for _, item := range consumables {
  7020. //出库
  7021. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  7022. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  7023. if err == nil {
  7024. goodErrcode := models.XtGoodErrcode{
  7025. UserOrgId: adminInfo.Org.Id,
  7026. Errcode: "自动出库接口报错",
  7027. GoodId: 0,
  7028. Status: 1,
  7029. Ctime: time.Now().Unix(),
  7030. Mtime: 0,
  7031. Count: 0,
  7032. StockCount: 0,
  7033. Creater: creator,
  7034. BatchNumberId: 0,
  7035. WarehouseOutId: 0,
  7036. }
  7037. service.CreateGoodErrcode(goodErrcode)
  7038. utils.TraceLog("创建出库单失败 err = %v", err)
  7039. }
  7040. //查询
  7041. //出库数量相加
  7042. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7043. if errs != nil {
  7044. goodErrcode := models.XtGoodErrcode{
  7045. UserOrgId: item.UserOrgId,
  7046. Errcode: "创建剩余库存字段报错",
  7047. GoodId: item.GoodId,
  7048. Status: 1,
  7049. Ctime: time.Now().Unix(),
  7050. Mtime: 0,
  7051. Count: 0,
  7052. StockCount: 0,
  7053. Creater: creater,
  7054. BatchNumberId: 0,
  7055. WarehouseOutId: 0,
  7056. }
  7057. service.CreateGoodErrcode(goodErrcode)
  7058. }
  7059. }
  7060. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7061. if len(list) == 0 {
  7062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7063. return
  7064. }
  7065. for _, item := range list {
  7066. prepare := models.DialysisBeforePrepare{
  7067. UserOrgId: adminInfo.Org.Id,
  7068. PatientId: patient_id,
  7069. RecordDate: record_time,
  7070. GoodId: item.GoodId,
  7071. GoodTypeId: item.GoodTypeId,
  7072. Count: item.Count,
  7073. Creater: adminInfo.AdminUser.Id,
  7074. Status: 1,
  7075. Ctime: time.Now().Unix(),
  7076. StorehouseId: houseConfig.StorehouseOutInfo,
  7077. }
  7078. //清空准备表数据
  7079. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7080. if err != nil {
  7081. goodErrcode := models.XtGoodErrcode{
  7082. UserOrgId: item.OrgId,
  7083. Errcode: "自动出库清空准备表数据报错",
  7084. GoodId: item.GoodId,
  7085. Status: 1,
  7086. Ctime: time.Now().Unix(),
  7087. Mtime: 0,
  7088. Count: 0,
  7089. StockCount: 0,
  7090. Creater: creater,
  7091. BatchNumberId: 0,
  7092. WarehouseOutId: 0,
  7093. }
  7094. service.CreateGoodErrcode(goodErrcode)
  7095. }
  7096. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  7097. if errs != nil {
  7098. goodErrcode := models.XtGoodErrcode{
  7099. UserOrgId: item.OrgId,
  7100. Errcode: "自动出库创建准备表数据报错",
  7101. GoodId: item.GoodId,
  7102. Status: 1,
  7103. Ctime: time.Now().Unix(),
  7104. Mtime: 0,
  7105. Count: 0,
  7106. StockCount: 0,
  7107. Creater: creater,
  7108. BatchNumberId: 0,
  7109. WarehouseOutId: 0,
  7110. }
  7111. service.CreateGoodErrcode(goodErrcode)
  7112. }
  7113. //查询默认仓库
  7114. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7115. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7116. var total_count int64
  7117. for _, it := range stockList {
  7118. total_count += it.StockCount
  7119. }
  7120. //基础库插入数据
  7121. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7122. if errcodes != nil {
  7123. goodErrcode := models.XtGoodErrcode{
  7124. UserOrgId: item.OrgId,
  7125. Errcode: "自动出库基础库插入数据",
  7126. GoodId: item.GoodId,
  7127. Status: 1,
  7128. Ctime: time.Now().Unix(),
  7129. Mtime: 0,
  7130. Count: 0,
  7131. StockCount: 0,
  7132. Creater: creater,
  7133. BatchNumberId: 0,
  7134. WarehouseOutId: 0,
  7135. }
  7136. service.CreateGoodErrcode(goodErrcode)
  7137. }
  7138. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7139. var flush_count int64
  7140. for _, it := range goodList {
  7141. flush_count += it.StockCount
  7142. }
  7143. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7144. if errsss != nil {
  7145. goodErrcode := models.XtGoodErrcode{
  7146. UserOrgId: item.OrgId,
  7147. Errcode: "自动出库剩余库存更新数据",
  7148. GoodId: item.GoodId,
  7149. Status: 1,
  7150. Ctime: time.Now().Unix(),
  7151. Mtime: 0,
  7152. Count: 0,
  7153. StockCount: 0,
  7154. Creater: creater,
  7155. BatchNumberId: 0,
  7156. WarehouseOutId: 0,
  7157. }
  7158. service.CreateGoodErrcode(goodErrcode)
  7159. }
  7160. }
  7161. }
  7162. //
  7163. } else if err == nil {
  7164. for _, item := range consumables {
  7165. //出库
  7166. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  7167. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  7168. if err != nil {
  7169. goodErrcode := models.XtGoodErrcode{
  7170. UserOrgId: adminInfo.Org.Id,
  7171. Errcode: "自动出库接口报错",
  7172. GoodId: 0,
  7173. Status: 1,
  7174. Ctime: time.Now().Unix(),
  7175. Mtime: 0,
  7176. Count: 0,
  7177. StockCount: 0,
  7178. Creater: creator,
  7179. BatchNumberId: 0,
  7180. WarehouseOutId: 0,
  7181. }
  7182. service.CreateGoodErrcode(goodErrcode)
  7183. }
  7184. //出库数量相加
  7185. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7186. if errss != nil {
  7187. goodErrcode := models.XtGoodErrcode{
  7188. UserOrgId: item.UserOrgId,
  7189. Errcode: "创建剩余库存字段报错",
  7190. GoodId: item.GoodId,
  7191. Status: 1,
  7192. Ctime: time.Now().Unix(),
  7193. Mtime: time.Now().Unix(),
  7194. Count: 0,
  7195. StockCount: 0,
  7196. Creater: item.Creater,
  7197. BatchNumberId: 0,
  7198. WarehouseOutId: 0,
  7199. }
  7200. service.CreateGoodErrcode(goodErrcode)
  7201. }
  7202. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7203. if len(list) == 0 {
  7204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7205. return
  7206. }
  7207. for _, item := range list {
  7208. prepare := models.DialysisBeforePrepare{
  7209. UserOrgId: adminInfo.Org.Id,
  7210. PatientId: patient_id,
  7211. RecordDate: record_time,
  7212. GoodId: item.GoodId,
  7213. GoodTypeId: item.GoodTypeId,
  7214. Count: item.Count,
  7215. Creater: adminInfo.AdminUser.Id,
  7216. Status: 1,
  7217. Ctime: time.Now().Unix(),
  7218. StorehouseId: houseConfig.StorehouseOutInfo,
  7219. }
  7220. //清空准备表数据
  7221. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7222. if errs != nil {
  7223. goodErrcode := models.XtGoodErrcode{
  7224. UserOrgId: adminInfo.Org.Id,
  7225. Errcode: "自动出库清空准备表数据报错",
  7226. GoodId: 0,
  7227. Status: 1,
  7228. Ctime: time.Now().Unix(),
  7229. Mtime: 0,
  7230. Count: 0,
  7231. StockCount: 0,
  7232. Creater: creator,
  7233. BatchNumberId: 0,
  7234. WarehouseOutId: 0,
  7235. }
  7236. service.CreateGoodErrcode(goodErrcode)
  7237. }
  7238. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7239. if errcodes != nil {
  7240. goodErrcode := models.XtGoodErrcode{
  7241. UserOrgId: adminInfo.Org.Id,
  7242. Errcode: "自动出库创建准备表数据报错",
  7243. GoodId: 0,
  7244. Status: 1,
  7245. Ctime: time.Now().Unix(),
  7246. Mtime: 0,
  7247. Count: 0,
  7248. StockCount: 0,
  7249. Creater: creator,
  7250. BatchNumberId: 0,
  7251. WarehouseOutId: 0,
  7252. }
  7253. service.CreateGoodErrcode(goodErrcode)
  7254. }
  7255. //查询默认仓库
  7256. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7257. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7258. var total_count int64
  7259. for _, it := range stockList {
  7260. total_count += it.StockCount
  7261. }
  7262. //基础库插入数据
  7263. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7264. if errcodes != nil {
  7265. goodErrcode := models.XtGoodErrcode{
  7266. UserOrgId: adminInfo.Org.Id,
  7267. Errcode: "自动出库基础库插入数据报错",
  7268. GoodId: 0,
  7269. Status: 1,
  7270. Ctime: time.Now().Unix(),
  7271. Mtime: 0,
  7272. Count: 0,
  7273. StockCount: 0,
  7274. Creater: creator,
  7275. BatchNumberId: 0,
  7276. WarehouseOutId: 0,
  7277. }
  7278. service.CreateGoodErrcode(goodErrcode)
  7279. }
  7280. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7281. var flush_count int64
  7282. for _, it := range goodList {
  7283. flush_count += it.StockCount
  7284. }
  7285. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7286. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7287. if errss != nil {
  7288. goodErrcode := models.XtGoodErrcode{
  7289. UserOrgId: item.OrgId,
  7290. Errcode: "自动出库剩余库存更新数据",
  7291. GoodId: item.GoodId,
  7292. Status: 1,
  7293. Ctime: time.Now().Unix(),
  7294. Mtime: 0,
  7295. Count: 0,
  7296. StockCount: 0,
  7297. Creater: creater,
  7298. BatchNumberId: 0,
  7299. WarehouseOutId: 0,
  7300. }
  7301. service.CreateGoodErrcode(goodErrcode)
  7302. }
  7303. }
  7304. }
  7305. }
  7306. c.ServeSuccessJSON(map[string]interface{}{
  7307. "msg": "提交成功",
  7308. "message": "2",
  7309. "good_name": "",
  7310. "specification_name": "",
  7311. })
  7312. return
  7313. } else {
  7314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7315. return
  7316. }
  7317. }
  7318. func (c *DialysisAPIController) EditConsumables() {
  7319. patient_id, _ := c.GetInt64("patient_id", 0)
  7320. record_date := c.GetString("record_time")
  7321. if patient_id <= 0 {
  7322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7323. return
  7324. }
  7325. adminInfo := c.GetMobileAdminUserInfo()
  7326. timeLayout := "2006-01-02"
  7327. loc, _ := time.LoadLocation("Local")
  7328. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7329. record_time := theRecordTime.Unix()
  7330. // 查询信息规挡的设置天数
  7331. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7332. if infor.ID > 0 && infor.WeekDay > 0 {
  7333. var cha_time int64
  7334. timeNowStr := time.Now().Format("2006-01-02")
  7335. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7336. //今日的日期减去设置的日期
  7337. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7338. if cha_time >= record_time {
  7339. //查询审核是否允许
  7340. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7341. //申请状态不允许的情况 拒绝修改
  7342. if infor.ApplicationStatus != 1 {
  7343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7344. return
  7345. }
  7346. }
  7347. }
  7348. dataBody := make(map[string]interface{}, 0)
  7349. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7350. if err != nil {
  7351. utils.ErrorLog(err.Error())
  7352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7353. return
  7354. }
  7355. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7356. var beforePrepares []*models.DialysisBeforePrepareGoods
  7357. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7358. var cancelbefor []*models.DialysisBeforePrepareGoods
  7359. var outbefor []*models.DialysisBeforePrepareGoods
  7360. //判断是否开启自动出库
  7361. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7362. if record.IsOpen == 1 {
  7363. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7364. goods, _ := dataBody["goods"].([]interface{})
  7365. if len(goods) > 0 {
  7366. for _, item := range goods {
  7367. items := item.(map[string]interface{})
  7368. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7369. utils.ErrorLog("good_id")
  7370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7371. return
  7372. }
  7373. good_id := int64(items["good_id"].(float64))
  7374. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7375. utils.ErrorLog("good_type_id")
  7376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7377. return
  7378. }
  7379. good_type_id := int64(items["good_type_id"].(float64))
  7380. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7381. utils.ErrorLog("count")
  7382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7383. return
  7384. }
  7385. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7386. commdity_code := items["commdity_code"].(string)
  7387. fmt.Println(commdity_code)
  7388. prepareGoods := &models.DialysisBeforePrepareGoods{
  7389. GoodTypeId: good_type_id,
  7390. GoodId: good_id,
  7391. Count: count,
  7392. StorehouseId: houseConfig.StorehouseOutInfo,
  7393. }
  7394. beforePrepares = append(beforePrepares, prepareGoods)
  7395. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7396. GoodTypeId: good_type_id,
  7397. GoodId: good_id,
  7398. Count: count,
  7399. StorehouseId: houseConfig.StorehouseOutInfo,
  7400. }
  7401. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7402. }
  7403. for _, item := range beforePrepares {
  7404. //1.查看该患者该耗材型号最后一次出库数量
  7405. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7406. //判断当前出库数量和最后一次出库数量的大小
  7407. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7408. if item.Count < goodInfo.Count {
  7409. cancelbefor = append(cancelbefor, item)
  7410. }
  7411. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7412. if item.Count > goodInfo.Count {
  7413. outbefor = append(outbefor, item)
  7414. }
  7415. //处理编辑耗材新增不了的问题
  7416. if goodInfo.Count == item.Count {
  7417. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7418. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7419. }
  7420. }
  7421. if len(cancelbefor) > 0 {
  7422. //退库
  7423. for _, item := range cancelbefor {
  7424. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7425. creater := adminInfo.AdminUser.Id
  7426. //查询该患者当天已经出库的耗材信息
  7427. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7428. var delete_count int64 = 0
  7429. delete_count = warehouseOutInfos.Count - item.Count
  7430. //增加库存数量
  7431. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7432. //减少实际出库库存数量
  7433. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7434. // 删除出库完成后,要增加对应批次的库存数量
  7435. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7436. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7437. //更新剩余库存
  7438. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7439. var flush_count int64
  7440. for _, it := range goodListOne {
  7441. flush_count += it.StockCount
  7442. }
  7443. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7444. //查询剩余库存
  7445. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7446. var sum_count int64
  7447. for _, item := range goodList {
  7448. sum_count += item.StockCount
  7449. }
  7450. // 在出库记录表里记录退库详情
  7451. warehouseOutInfo := &models.WarehouseOutInfo{
  7452. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7453. WarehouseOutId: warehouseOut.ID,
  7454. Status: 1,
  7455. Ctime: time.Now().Unix(),
  7456. OrgId: adminInfo.Org.Id,
  7457. Type: 1,
  7458. IsSys: 1,
  7459. SysRecordTime: record_time,
  7460. GoodTypeId: item.GoodTypeId,
  7461. GoodId: item.GoodId,
  7462. PatientId: patient_id,
  7463. ConsumableType: 2,
  7464. StorehouseId: houseConfig.StorehouseOutInfo,
  7465. IsCheck: 1,
  7466. OverCount: sum_count,
  7467. }
  7468. warehouseOutInfo.Count = item.Count
  7469. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7470. warehouseOutInfo.Price = stockInInfo.Price
  7471. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7472. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7473. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7474. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7475. warehouseOutInfo.Number = warehouseOutInfos.Number
  7476. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7477. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7478. //查找当天是否存在出库记录
  7479. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7480. if errcod == gorm.ErrRecordNotFound {
  7481. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7482. //插入详情明细表
  7483. stockFlow := models.VmStockFlow{
  7484. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7485. WarehouseOutId: warehouseOut.ID,
  7486. GoodId: item.GoodId,
  7487. Number: warehouseOutInfos.Number,
  7488. ProductDate: stockInInfo.ProductDate,
  7489. ExpireDate: stockInInfo.ExpiryDate,
  7490. Count: item.Count,
  7491. Price: stockInInfo.Price,
  7492. Status: 1,
  7493. Ctime: record_time,
  7494. UserOrgId: adminInfo.Org.Id,
  7495. Manufacturer: stockInInfo.Manufacturer,
  7496. Dealer: stockInInfo.Dealer,
  7497. LicenseNumber: stockInInfo.LicenseNumber,
  7498. IsEdit: 2,
  7499. Creator: creater,
  7500. SystemTime: record_time,
  7501. ConsumableType: 3,
  7502. WarehousingDetailId: 0,
  7503. IsSys: 1,
  7504. UpdateCreator: creater,
  7505. PatientId: patient_id,
  7506. StorehouseId: houseConfig.StorehouseOutInfo,
  7507. }
  7508. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7509. if errflow == gorm.ErrRecordNotFound {
  7510. //创建流水表
  7511. err := service.CreateStockFlowOne(stockFlow)
  7512. fmt.Println("err", err)
  7513. } else if errflow == nil {
  7514. //插入详情明细表
  7515. stockFlow := models.VmStockFlow{
  7516. ID: exsit.ID,
  7517. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7518. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7519. WarehouseOutId: warehouseOut.ID,
  7520. GoodId: item.GoodId,
  7521. Number: warehouseOutInfos.Number,
  7522. ProductDate: stockInInfo.ProductDate,
  7523. ExpireDate: stockInInfo.ExpiryDate,
  7524. Count: exsit.Count - delete_count,
  7525. Price: stockInInfo.Price,
  7526. Status: 1,
  7527. Ctime: record_time,
  7528. UserOrgId: adminInfo.Org.Id,
  7529. Manufacturer: stockInInfo.Manufacturer,
  7530. Dealer: stockInInfo.Dealer,
  7531. LicenseNumber: stockInInfo.LicenseNumber,
  7532. IsEdit: 2,
  7533. Creator: creater,
  7534. SystemTime: record_time,
  7535. ConsumableType: 3,
  7536. WarehousingDetailId: 0,
  7537. IsSys: 1,
  7538. UpdateCreator: creater,
  7539. PatientId: patient_id,
  7540. StorehouseId: houseConfig.StorehouseOutInfo,
  7541. }
  7542. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7543. }
  7544. } else if errcod == nil {
  7545. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7546. //查询剩余库存
  7547. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7548. var sum_count int64
  7549. for _, item := range goodList {
  7550. sum_count += item.StockCount
  7551. }
  7552. //创建退库单,生成退库数据
  7553. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7554. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7555. operation_time := time.Now().Unix()
  7556. creater := adminInfo.AdminUser.Id
  7557. //创建退库单
  7558. timeStr := time.Now().Format("2006-01-02")
  7559. timeArr := strings.Split(timeStr, "-")
  7560. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7561. total = total + 1
  7562. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7563. cancelStock := models.CancelStock{
  7564. OrderNumber: orderNumber,
  7565. OperaTime: operation_time,
  7566. OrgId: adminInfo.Org.Id,
  7567. Creater: creater,
  7568. Ctime: time.Now().Unix(),
  7569. Status: 1,
  7570. ReturnTime: record_time,
  7571. Type: 1,
  7572. StorehouseId: houseConfig.StorehouseOutInfo,
  7573. IsCheck: 1,
  7574. }
  7575. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7576. if msgerrkonde == gorm.ErrRecordNotFound {
  7577. service.AddSigleCancelStock(&cancelStock)
  7578. }
  7579. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7580. //查询是否有出库
  7581. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7582. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7583. deaerler, _ := service.GetDealerById(info.Dealer)
  7584. if info.ID > 0 {
  7585. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7586. cancelStockInfo := models.CancelStockInfo{
  7587. GoodId: item.GoodId,
  7588. CancelStockId: cancel.ID,
  7589. GoodTypeId: good.GoodTypeId,
  7590. Count: delete_count,
  7591. Price: info.Price,
  7592. Total: 0,
  7593. ProductDate: info.ProductDate,
  7594. ExpiryDate: info.ExpiryDate,
  7595. Ctime: time.Now().Unix(),
  7596. Status: 1,
  7597. OrgId: adminInfo.Org.Id,
  7598. OrderNumber: cancel.OrderNumber,
  7599. Type: 0,
  7600. Dealer: deaerler.DealerName,
  7601. Manufacturer: manufacturer.ManufacturerName,
  7602. Number: info.Number,
  7603. RegisterAccount: "",
  7604. Remark: "",
  7605. WarehouseInfoId: info.WarehouseInfotId,
  7606. PatientId: info.PatientId,
  7607. RecordDate: info.SysRecordTime,
  7608. StorehouseId: houseConfig.StorehouseOutInfo,
  7609. IsCheck: 1,
  7610. }
  7611. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7612. //退库数量增加
  7613. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7614. //查询剩余库存
  7615. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7616. var over_count int64
  7617. for _, it := range goodList {
  7618. over_count += it.StockCount
  7619. }
  7620. flow := models.VmStockFlow{
  7621. WarehousingId: info.WarehouseInfotId,
  7622. GoodId: item.GoodId,
  7623. Number: info.Number,
  7624. LicenseNumber: info.LicenseNumber,
  7625. Count: delete_count,
  7626. UserOrgId: adminInfo.Org.Id,
  7627. PatientId: patient_id,
  7628. SystemTime: info.SysRecordTime,
  7629. ConsumableType: 7,
  7630. IsSys: 0,
  7631. WarehousingOrder: "",
  7632. WarehouseOutId: info.WarehouseOutId,
  7633. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7634. IsEdit: 0,
  7635. CancelStockId: cancel.ID,
  7636. CancelOrderNumber: cancel.OrderNumber,
  7637. Manufacturer: manufacturer.ID,
  7638. Dealer: 0,
  7639. Creator: adminInfo.AdminUser.Id,
  7640. UpdateCreator: 0,
  7641. Status: 1,
  7642. Ctime: record_time,
  7643. Mtime: 0,
  7644. Price: info.Price,
  7645. WarehousingDetailId: info.WarehouseInfotId,
  7646. WarehouseOutDetailId: info.ID,
  7647. CancelOutDetailId: cancelInfo.ID,
  7648. ProductDate: info.ProductDate,
  7649. ExpireDate: info.ExpiryDate,
  7650. StorehouseId: houseConfig.StorehouseOutInfo,
  7651. OverCount: over_count,
  7652. }
  7653. service.CreateStockFlowOne(flow)
  7654. }
  7655. }
  7656. //更改自动出库的表格
  7657. details := models.BloodAutomaticReduceDetail{
  7658. WarehouseOutId: warehouseOutInfo.ID,
  7659. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7660. PatientId: patient_id,
  7661. Ctime: time.Now().Unix(),
  7662. Mtime: time.Now().Unix(),
  7663. Status: 1,
  7664. RecordTime: record_time,
  7665. OrgId: adminInfo.Org.Id,
  7666. GoodId: item.GoodId,
  7667. GoodTypeId: item.GoodTypeId,
  7668. Count: item.Count,
  7669. StorehouseId: houseConfig.StorehouseOutInfo,
  7670. }
  7671. //查询当天耗材是否已经存在数据
  7672. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7673. if errcode == gorm.ErrRecordNotFound {
  7674. service.CreateAutoReduceRecord(&details)
  7675. } else if errcode == nil {
  7676. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7677. service.CreateAutoReduceRecord(&details)
  7678. }
  7679. //查询默认仓库
  7680. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7681. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7682. var total_count int64
  7683. for _, it := range stockList {
  7684. total_count += it.StockCount
  7685. }
  7686. //基础库插入数据
  7687. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7688. }
  7689. }
  7690. if len(outbefor) > 0 {
  7691. //出库
  7692. for _, item := range outbefor {
  7693. var last_total int64
  7694. //1.查看该患者该耗材型号最后一次出库数量
  7695. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7696. //计算当前出库和最后一次出库数据相差数据
  7697. last_total = item.Count - goodInfoOne.Count
  7698. //查询该耗材的总库存
  7699. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7700. // 如果库存差大于剩余库存则提示库存不足
  7701. if last_total > wareinfo.StockCount {
  7702. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7703. c.ServeSuccessJSON(map[string]interface{}{
  7704. "message": "1",
  7705. "good_name": goodObj.GoodName,
  7706. "specification_name": goodObj.SpecificationName,
  7707. })
  7708. return
  7709. } else {
  7710. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7711. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7712. if err == gorm.ErrRecordNotFound {
  7713. //没有记录,则创建出库单
  7714. timeStr := time.Now().Format("2006-01-02")
  7715. timeArr := strings.Split(timeStr, "-")
  7716. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7717. total = total + 1
  7718. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7719. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7720. number = number + total
  7721. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7722. warehouseOut := models.WarehouseOut{
  7723. WarehouseOutOrderNumber: warehousing_out_order,
  7724. OperationTime: time.Now().Unix(),
  7725. OrgId: adminInfo.Org.Id,
  7726. Creater: adminInfo.AdminUser.Id,
  7727. Ctime: time.Now().Unix(),
  7728. Status: 1,
  7729. WarehouseOutTime: record_time,
  7730. Dealer: 0,
  7731. Manufacturer: 0,
  7732. Type: 1,
  7733. IsSys: 1,
  7734. StorehouseId: houseConfig.StorehouseOutInfo,
  7735. IsCheck: 1,
  7736. }
  7737. service.AddSigleWarehouseOutOne(&warehouseOut)
  7738. }
  7739. //出库
  7740. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7741. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7742. //1.查看该患者该耗材型号最后一次出库数量
  7743. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7744. prepare := models.DialysisBeforePrepare{
  7745. UserOrgId: adminInfo.Org.Id,
  7746. PatientId: patient_id,
  7747. RecordDate: record_time,
  7748. GoodId: item.GoodId,
  7749. GoodTypeId: item.GoodTypeId,
  7750. Count: item.Count - goodInfoTwo.Count,
  7751. Ctime: time.Now().Unix(),
  7752. Mtime: 0,
  7753. Creater: adminInfo.AdminUser.Id,
  7754. Modifier: adminInfo.AdminUser.Id,
  7755. Status: 1,
  7756. CommdityCode: "",
  7757. NewCount: 0,
  7758. ProjectId: 0,
  7759. StorehouseId: houseConfig.StorehouseOutInfo,
  7760. }
  7761. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7762. //增加出库数量
  7763. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7764. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7765. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7766. var total_count int64
  7767. for _, it := range stockList {
  7768. total_count += it.StockCount
  7769. }
  7770. //基础库插入数据
  7771. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7772. //剩余库存
  7773. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7774. var flush_count int64
  7775. for _, it := range goodList {
  7776. flush_count += it.StockCount
  7777. }
  7778. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7779. }
  7780. }
  7781. }
  7782. //查询今日出库数据
  7783. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7784. for _, it := range list {
  7785. prepare := models.DialysisBeforePrepare{
  7786. UserOrgId: it.OrgId,
  7787. PatientId: patient_id,
  7788. RecordDate: it.RecordTime,
  7789. GoodId: it.GoodId,
  7790. GoodTypeId: it.GoodTypeId,
  7791. Count: it.Count,
  7792. Ctime: time.Now().Unix(),
  7793. Creater: adminInfo.AdminUser.Id,
  7794. Status: 1,
  7795. StorehouseId: houseConfig.StorehouseOutInfo,
  7796. ProjectId: it.ProjectId,
  7797. }
  7798. //删除准备表数据
  7799. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7800. service.CreateDialysisBeforePrepareOne(&prepare)
  7801. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7802. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7803. var total_count int64
  7804. for _, it := range stockList {
  7805. total_count += it.StockCount
  7806. }
  7807. //基础库插入数据
  7808. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7809. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7810. var flush_count int64
  7811. for _, it := range goodList {
  7812. flush_count += it.StockCount
  7813. }
  7814. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7815. }
  7816. }
  7817. }
  7818. //更新自动出库的地方
  7819. var errs error
  7820. if errs == nil {
  7821. c.ServeSuccessJSON(map[string]interface{}{
  7822. "msg": "修改成功",
  7823. "message": "2",
  7824. "good_name": "",
  7825. "specification_name": "",
  7826. })
  7827. return
  7828. } else {
  7829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7830. return
  7831. }
  7832. }
  7833. }
  7834. func (c *DialysisAPIController) GetDialysisGoods() {
  7835. schedualDate := c.GetString("schedule_date")
  7836. schedule_type, _ := c.GetInt64("schedule_type")
  7837. partition_id, _ := c.GetInt64("partition_id")
  7838. page, _ := c.GetInt("page")
  7839. patient_id, _ := c.GetInt64("patient_id")
  7840. schedualEndDate := int64(0)
  7841. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7842. if parseDateErr != nil && len(schedualDate) != 0 {
  7843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7844. return
  7845. }
  7846. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7847. if parseDateErr != nil && len(schedualDate) != 0 {
  7848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7849. return
  7850. }
  7851. schedualEndDate = endDate.Unix()
  7852. adminUser := c.GetMobileAdminUserInfo()
  7853. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7854. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7855. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7856. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7857. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7858. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7859. //获取当天该病人的透析处方
  7860. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7861. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7862. if err == gorm.ErrRecordNotFound {
  7863. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7864. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7865. if patient_id != 0 {
  7866. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7867. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7868. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7869. //获取患者总的出库数据
  7870. item.LastAutomaticReduceDetail = goodUser
  7871. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7872. item.Project = project
  7873. for _, it := range item.AutomaticReduceDetail {
  7874. var total int64
  7875. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7876. for _, its := range auto {
  7877. total += its.Count
  7878. }
  7879. it.Count = total
  7880. }
  7881. }
  7882. }
  7883. c.ServeSuccessJSON(map[string]interface{}{
  7884. "dialysis_goods": dialysisGoods,
  7885. "good_type": goodTypes,
  7886. "total": total,
  7887. "prescribe": prescribe,
  7888. "good_info": good_info,
  7889. "warehouseOutList": warehouseOutList,
  7890. "config": config,
  7891. "outConfig": outConfig,
  7892. "settleConfig": settleConfig,
  7893. })
  7894. return
  7895. } else if err == nil {
  7896. //获取当天排班的每个患者的库存使用情况
  7897. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7898. //获取患者总的出库数据
  7899. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7900. if patient_id != 0 {
  7901. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7902. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7903. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7904. item.Project = project
  7905. item.LastAutomaticReduceDetail = goodUser
  7906. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7907. for _, it := range item.AutomaticReduceDetail {
  7908. var total int64
  7909. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7910. for _, its := range auto {
  7911. total += its.Count
  7912. }
  7913. it.Count = total
  7914. }
  7915. }
  7916. }
  7917. if err == nil {
  7918. c.ServeSuccessJSON(map[string]interface{}{
  7919. "dialysis_goods": dialysisGoods,
  7920. "good_type": goodTypes,
  7921. "total": total,
  7922. "prescribe": prescribe,
  7923. "good_info": good_info,
  7924. "project": project,
  7925. "warehouseOutList": warehouseOutList,
  7926. "config": config,
  7927. "outConfig": outConfig,
  7928. "settleConfig": settleConfig,
  7929. })
  7930. return
  7931. } else {
  7932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7933. return
  7934. }
  7935. } else if err != nil {
  7936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7937. return
  7938. }
  7939. }
  7940. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7941. start_time := c.GetString("start_time")
  7942. end_time := c.GetString("end_time")
  7943. timeLayout := "2006-01-02"
  7944. loc, _ := time.LoadLocation("Local")
  7945. var theStartTime int64
  7946. if len(start_time) > 0 {
  7947. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7948. if err != nil {
  7949. utils.ErrorLog(err.Error())
  7950. }
  7951. theStartTime = theTime.Unix()
  7952. }
  7953. var theEndtTime int64
  7954. if len(end_time) > 0 {
  7955. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7956. if err != nil {
  7957. utils.ErrorLog(err.Error())
  7958. }
  7959. theEndtTime = theTime.Unix()
  7960. }
  7961. adminUser := c.GetMobileAdminUserInfo()
  7962. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7963. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7964. if err == nil {
  7965. c.ServeSuccessJSON(map[string]interface{}{
  7966. "stock_out": outInfo,
  7967. "stockCount": stockCount,
  7968. })
  7969. return
  7970. } else {
  7971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7972. return
  7973. }
  7974. }
  7975. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7976. patient_id, _ := c.GetInt64("patient_id", 0)
  7977. record_time := c.GetString("record_time")
  7978. adminUser := c.GetMobileAdminUserInfo()
  7979. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7980. if parseDateErr != nil && len(record_time) != 0 {
  7981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7982. return
  7983. }
  7984. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7985. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7986. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7987. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7988. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7989. //获取今日患者的透析处方参数
  7990. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7991. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7992. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7993. c.ServeSuccessJSON(map[string]interface{}{
  7994. "good_type": goodTypes,
  7995. "good_user": goodUser,
  7996. "good_info": good_info,
  7997. "last_good_user": lastGoodUserDetial,
  7998. "project": project,
  7999. "prescription": prescribe,
  8000. "outInfo": outInfo,
  8001. "configs": configs,
  8002. })
  8003. return
  8004. }
  8005. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  8006. patient_id, _ := c.GetInt64("patient_id", 0)
  8007. record_date := c.GetString("record_time")
  8008. timeLayout := "2006-01-02"
  8009. loc, _ := time.LoadLocation("Local")
  8010. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8011. record_time := theRecordTime.Unix()
  8012. adminInfo := c.GetMobileAdminUserInfo()
  8013. dataBody := make(map[string]interface{}, 0)
  8014. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8015. if err != nil {
  8016. utils.ErrorLog(err.Error())
  8017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8018. return
  8019. }
  8020. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8021. var beforePrepares []*models.DialysisBeforePrepareGoods
  8022. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  8023. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  8024. goods, _ := dataBody["goods"].([]interface{})
  8025. if len(goods) > 0 {
  8026. for _, item := range goods {
  8027. items := item.(map[string]interface{})
  8028. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  8029. utils.ErrorLog("good_id")
  8030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8031. return
  8032. }
  8033. good_id := int64(items["good_id"].(float64))
  8034. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  8035. utils.ErrorLog("good_type_id")
  8036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8037. return
  8038. }
  8039. good_type_id := int64(items["good_type_id"].(float64))
  8040. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  8041. utils.ErrorLog("count")
  8042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8043. return
  8044. }
  8045. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  8046. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  8047. utils.ErrorLog("project_id")
  8048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8049. return
  8050. }
  8051. project_id := int64(items["project_id"].(float64))
  8052. new_count := int64(items["new_count"].(float64))
  8053. old_count := int64(items["old_count"].(float64))
  8054. prepare := &models.DialysisBeforePrepareGoods{
  8055. GoodId: good_id,
  8056. GoodTypeId: good_type_id,
  8057. Count: count,
  8058. ProjectId: project_id,
  8059. StorehouseId: houseConfig.StorehouseOutInfo,
  8060. NewCount: new_count,
  8061. OldCount: old_count,
  8062. }
  8063. beforePrepares = append(beforePrepares, prepare)
  8064. newPrepare := &models.NewDialysisBeforePrepareGoods{
  8065. GoodId: good_id,
  8066. GoodTypeId: good_type_id,
  8067. Count: count,
  8068. ProjectId: project_id,
  8069. StorehouseId: houseConfig.StorehouseOutInfo,
  8070. NewCount: new_count,
  8071. OldCount: old_count,
  8072. }
  8073. newBeforePrepares = append(newBeforePrepares, newPrepare)
  8074. }
  8075. }
  8076. }
  8077. //查询是否有库存
  8078. for _, item := range beforePrepares {
  8079. if item.NewCount > 0 {
  8080. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8081. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  8082. if item.Count > warehouse.Count {
  8083. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  8084. c.ServeSuccessJSON(map[string]interface{}{
  8085. "message": "1",
  8086. "good_name": goodObj.GoodName,
  8087. "specification_name": goodObj.SpecificationName,
  8088. })
  8089. return
  8090. }
  8091. }
  8092. }
  8093. // 查询信息规挡的设置天数
  8094. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  8095. if infor.ID > 0 && infor.WeekDay > 0 {
  8096. var cha_time int64
  8097. timeNowStr := time.Now().Format("2006-01-02")
  8098. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  8099. //今日的日期减去设置的日期
  8100. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  8101. if cha_time >= record_time {
  8102. //查询审核是否允许
  8103. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  8104. //申请状态不允许的情况 拒绝修改
  8105. if infor.ApplicationStatus != 1 {
  8106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  8107. return
  8108. }
  8109. }
  8110. }
  8111. //出库逻辑
  8112. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  8113. if err != nil {
  8114. utils.ErrorLog(err.Error())
  8115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8116. return
  8117. }
  8118. finish := models.XtDialysisFinish{
  8119. IsFinish: 1,
  8120. UserOrgId: adminInfo.Org.Id,
  8121. Status: 1,
  8122. Ctime: time.Now().Unix(),
  8123. Mtime: 0,
  8124. Module: 11,
  8125. RecordDate: record_time,
  8126. Sourse: 1,
  8127. PatientId: patient_id,
  8128. }
  8129. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  8130. if dialysisFinish.ID == 0 {
  8131. service.CreateDialysisFinish(finish)
  8132. }
  8133. //查询当天出库的数据
  8134. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  8135. for _, item := range list {
  8136. prepare := models.DialysisBeforePrepare{
  8137. UserOrgId: item.OrgId,
  8138. PatientId: item.PatientId,
  8139. RecordDate: item.RecordTime,
  8140. GoodId: item.GoodId,
  8141. GoodTypeId: item.GoodTypeId,
  8142. Count: item.Count,
  8143. Creater: adminInfo.AdminUser.Id,
  8144. Status: 1,
  8145. Ctime: time.Now().Unix(),
  8146. ProjectId: item.ProjectId,
  8147. StorehouseId: houseConfig.StorehouseOutInfo,
  8148. }
  8149. //清空准备表的数据
  8150. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  8151. //插入准备表数据
  8152. service.CreateDialysisBeforePrepareOne(&prepare)
  8153. //查询默认仓库
  8154. //查询默认仓库
  8155. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8156. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8157. var total_count int64
  8158. for _, it := range stockList {
  8159. total_count += it.StockCount
  8160. }
  8161. //基础库插入数据
  8162. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  8163. ////更新剩余库存
  8164. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  8165. var flush_count int64
  8166. for _, it := range goodList {
  8167. flush_count += it.StockCount
  8168. }
  8169. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  8170. if errs != nil {
  8171. goodErrcode := models.XtGoodErrcode{
  8172. UserOrgId: item.OrgId,
  8173. Errcode: "手动出库更新剩余出库失败",
  8174. GoodId: item.GoodId,
  8175. Status: 1,
  8176. Ctime: time.Now().Unix(),
  8177. Mtime: 0,
  8178. Count: 0,
  8179. StockCount: 0,
  8180. Creater: adminInfo.AdminUser.Id,
  8181. BatchNumberId: 0,
  8182. WarehouseOutId: 0,
  8183. }
  8184. service.CreateGoodErrcode(goodErrcode)
  8185. }
  8186. }
  8187. //更新自动出库的地方
  8188. var errs error
  8189. if errs == nil {
  8190. c.ServeSuccessJSON(map[string]interface{}{
  8191. "msg": "修改成功",
  8192. "message": "2",
  8193. "good_name": "",
  8194. "specification_name": "",
  8195. })
  8196. return
  8197. } else {
  8198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8199. return
  8200. }
  8201. }
  8202. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8203. newArr = make([]*models.DialysisBeforePrepare, 0)
  8204. for i := 0; i < len(arr); i++ {
  8205. repeat := false
  8206. for j := i + 1; j < len(arr); j++ {
  8207. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  8208. repeat = true
  8209. break
  8210. }
  8211. }
  8212. if !repeat {
  8213. newArr = append(newArr, arr[i])
  8214. }
  8215. }
  8216. return
  8217. }
  8218. func (c *DialysisAPIController) GetAllDrug() {
  8219. patient_id, _ := c.GetInt64("patient_id", 0)
  8220. adminInfo := c.GetMobileAdminUserInfo()
  8221. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  8222. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  8223. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  8224. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  8225. c.ServeSuccessJSON(map[string]interface{}{
  8226. "base_drug_config": drugStockConfig,
  8227. "private_drug_config": privateDrugConfig,
  8228. "base_drug_list": drugList,
  8229. "private_drug_list": privateDrugList,
  8230. })
  8231. }
  8232. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8233. newArr = make([]*models.DialysisBeforePrepare, 0)
  8234. for i := 0; i < len(arr); i++ {
  8235. repeat := false
  8236. for j := i + 1; j < len(arr); j++ {
  8237. if arr[i].GoodId == arr[j].GoodId {
  8238. repeat = true
  8239. break
  8240. }
  8241. }
  8242. if !repeat {
  8243. newArr = append(newArr, arr[i])
  8244. }
  8245. }
  8246. return
  8247. }
  8248. func (c *DialysisAPIController) GetDepartment() {
  8249. adminInfo := c.GetMobileAdminUserInfo()
  8250. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  8251. if err == nil {
  8252. c.ServeSuccessJSON(map[string]interface{}{
  8253. "departments": departments,
  8254. })
  8255. } else {
  8256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8257. return
  8258. }
  8259. }
  8260. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  8261. types, _ := c.GetInt("type", 0)
  8262. start_time := c.GetString("start_time")
  8263. end_time := c.GetString("end_time")
  8264. orgId := c.GetMobileAdminUserInfo().Org.Id
  8265. timeLayout := "2006-01-02"
  8266. loc, _ := time.LoadLocation("Local")
  8267. var startTime int64
  8268. if len(start_time) > 0 {
  8269. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8270. if err != nil {
  8271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8272. return
  8273. }
  8274. startTime = theTime.Unix()
  8275. }
  8276. var endTime int64
  8277. if len(end_time) > 0 {
  8278. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8279. if err != nil {
  8280. utils.ErrorLog(err.Error())
  8281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8282. return
  8283. }
  8284. endTime = theTime.Unix()
  8285. }
  8286. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8287. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8288. if err != nil {
  8289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8290. } else {
  8291. c.ServeSuccessJSON(map[string]interface{}{
  8292. "list": list,
  8293. "type": types,
  8294. "stockTotal": stockTotal,
  8295. })
  8296. }
  8297. }
  8298. func (c *DialysisAPIController) GetPrescriptionList() {
  8299. start_time := c.GetString("start_time")
  8300. end_time := c.GetString("end_time")
  8301. schedule_type, _ := c.GetInt64("schedule_type")
  8302. partion_id, _ := c.GetInt64("partion_id")
  8303. orgId := c.GetMobileAdminUserInfo().Org.Id
  8304. timeLayout := "2006-01-02"
  8305. loc, _ := time.LoadLocation("Local")
  8306. var startTime int64
  8307. if len(start_time) > 0 {
  8308. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8309. if err != nil {
  8310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8311. return
  8312. }
  8313. startTime = theTime.Unix()
  8314. }
  8315. var endTime int64
  8316. if len(end_time) > 0 {
  8317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8318. if err != nil {
  8319. utils.ErrorLog(err.Error())
  8320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8321. return
  8322. }
  8323. endTime = theTime.Unix()
  8324. }
  8325. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8326. fmt.Println("schedulelist22222222", schedulelist)
  8327. c.ServeSuccessJSON(map[string]interface{}{
  8328. "list": schedulelist,
  8329. })
  8330. return
  8331. }
  8332. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8333. ids := c.GetString("ids")
  8334. //patient_id, _ := c.GetInt64("patient_id")
  8335. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8336. idArray := strings.Split(ids, ",")
  8337. err := service.BatchDeleteMonitor(idArray)
  8338. fmt.Print("err", err)
  8339. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8340. //redis := service.RedisClient()
  8341. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8342. //redis.Set(key, "", time.Second)
  8343. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8344. //redis.Set(keyOne, "", time.Second)
  8345. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8346. //redis.Close()
  8347. c.ServeSuccessJSON(map[string]interface{}{
  8348. "msg": "批量删除成功",
  8349. })
  8350. return
  8351. }
  8352. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8353. id, _ := c.GetInt64("id")
  8354. timeLayout := "2006-01-02"
  8355. loc, _ := time.LoadLocation("Local")
  8356. //start_time := time.Now().Format("2006-01-02")
  8357. start_time := c.GetString("start_time")
  8358. end_time := c.GetString("end_time")
  8359. var startdateunix int64
  8360. if len(start_time) > 0 {
  8361. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8362. if err != nil {
  8363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8364. return
  8365. }
  8366. startdateunix = theTime.Unix()
  8367. }
  8368. var enddateunix int64
  8369. if len(end_time) > 0 {
  8370. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8371. if err != nil {
  8372. utils.ErrorLog(err.Error())
  8373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8374. return
  8375. }
  8376. enddateunix = theTime.Unix()
  8377. }
  8378. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8379. //nowTime := time.Now()
  8380. //endTime := nowTime.AddDate(-30, 0, 0)
  8381. //endTimes := endTime.Format("2006-01-02")
  8382. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8383. org_id := c.GetMobileAdminUserInfo().Org.Id
  8384. //if org_id == 10579 {
  8385. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8386. // c.ServeSuccessJSON(map[string]interface{}{
  8387. // "list": list,
  8388. // })
  8389. // return
  8390. //} else {
  8391. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8392. // c.ServeSuccessJSON(map[string]interface{}{
  8393. // "list": list,
  8394. // })
  8395. // return
  8396. //}
  8397. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8398. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8399. c.ServeSuccessJSON(map[string]interface{}{
  8400. "list": list,
  8401. })
  8402. return
  8403. } else {
  8404. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8405. c.ServeSuccessJSON(map[string]interface{}{
  8406. "list": list,
  8407. })
  8408. }
  8409. return
  8410. }
  8411. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8412. dataBody := make(map[string]interface{}, 0)
  8413. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8414. ids := c.GetString("ids")
  8415. idArray := strings.Split(ids, ",")
  8416. origin, _ := c.GetInt64("origin")
  8417. if origin == 1 {
  8418. err = service.BatchDeleteAdvice(idArray)
  8419. fmt.Print("err", err)
  8420. c.ServeSuccessJSON(map[string]interface{}{
  8421. "msg": "批量删除成功",
  8422. })
  8423. return
  8424. }
  8425. if origin == 2 {
  8426. service.BatchDeleteHisAdvice(idArray)
  8427. }
  8428. }
  8429. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8430. good_id, _ := c.GetInt64("good_id")
  8431. count, _ := c.GetInt64("count")
  8432. record_time, _ := c.GetInt64("record_time")
  8433. patient_id, _ := c.GetInt64("patient_id")
  8434. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8435. c.ServeSuccessJSON(map[string]interface{}{
  8436. "detail": detail,
  8437. })
  8438. return
  8439. }
  8440. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8441. good_id, _ := c.GetInt64("good_id")
  8442. record_time, _ := c.GetInt64("record_time")
  8443. patient_id, _ := c.GetInt64("patient_id")
  8444. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8445. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8446. fmt.Print("err", err)
  8447. c.ServeSuccessJSON(map[string]interface{}{
  8448. "msg": "批量删除成功",
  8449. })
  8450. return
  8451. }
  8452. func (c *DialysisAPIController) BatchAdviceCheck() {
  8453. ids := c.GetString("ids")
  8454. idArray := strings.Split(ids, ",")
  8455. creator, _ := c.GetInt64("creator")
  8456. origin, _ := c.GetInt64("origin")
  8457. if origin == 1 {
  8458. err := service.BatchAdviceCheck(idArray, creator)
  8459. fmt.Println(err)
  8460. list, _ := service.GetAdviceExecutionById(idArray)
  8461. c.ServeSuccessJSON(map[string]interface{}{
  8462. "list": list,
  8463. })
  8464. return
  8465. }
  8466. if origin == 2 {
  8467. service.BatchHisAdviceCheck(idArray, creator)
  8468. list, _ := service.GetHisAdviceExecutionById(idArray)
  8469. c.ServeSuccessJSON(map[string]interface{}{
  8470. "list": list,
  8471. })
  8472. return
  8473. }
  8474. }
  8475. func (c *DialysisAPIController) BatchAdviceExecution() {
  8476. ids := c.GetString("ids")
  8477. idArray := strings.Split(ids, ",")
  8478. executionTime := c.GetString("execution_time")
  8479. creator, _ := c.GetInt64("creator")
  8480. timeLayout := "2006-01-02 15:04:05"
  8481. loc, _ := time.LoadLocation("Local")
  8482. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8483. orgin, _ := c.GetInt64("origin")
  8484. if orgin == 1 {
  8485. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8486. list, _ := service.GetAdviceExecutionById(idArray)
  8487. fmt.Println(err)
  8488. c.ServeSuccessJSON(map[string]interface{}{
  8489. "list": list,
  8490. })
  8491. return
  8492. }
  8493. if orgin == 2 {
  8494. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8495. list, _ := service.GetHisAdviceExecutionById(idArray)
  8496. fmt.Println(err)
  8497. c.ServeSuccessJSON(map[string]interface{}{
  8498. "list": list,
  8499. })
  8500. return
  8501. }
  8502. }
  8503. func (c *DialysisAPIController) UpdateStockGoods() {
  8504. good_id, _ := c.GetInt64("good_id")
  8505. record_time, _ := c.GetInt64("record_time")
  8506. patient_id, _ := c.GetInt64("patient_id")
  8507. count, _ := c.GetInt64("count")
  8508. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8509. fmt.Print("err", err)
  8510. c.ServeSuccessJSON(map[string]interface{}{
  8511. "msg": "更新成功",
  8512. })
  8513. return
  8514. }
  8515. // 当前数据比上一次出库数据少
  8516. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8517. //查询该患者当天已经出库的耗材信息
  8518. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8519. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8520. for i := len(goods_yc) - 1; i >= 0; i-- {
  8521. goods_yc_temp := goods_yc[i]
  8522. for j := len(goods) - 1; j >= 0; j-- {
  8523. goods_temp := goods[j]
  8524. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8525. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8526. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8527. if goods_yc_temp.Count == goods_temp.Count {
  8528. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8529. goods = append(goods[:j], goods[j+1:]...)
  8530. break
  8531. }
  8532. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8533. if goods_yc_temp.Count > goods_temp.Count {
  8534. temp_count := goods_yc_temp.Count - goods_temp.Count
  8535. goods_yc[i].Count = temp_count
  8536. goods = append(goods[:j], goods[j+1:]...)
  8537. break
  8538. }
  8539. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8540. if goods_yc_temp.Count < goods_temp.Count {
  8541. temp_count := goods_temp.Count - goods_yc_temp.Count
  8542. goods[j].Count = temp_count
  8543. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8544. break
  8545. }
  8546. }
  8547. }
  8548. }
  8549. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8550. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8551. //退库
  8552. if len(goods_yc) > 0 {
  8553. for _, good_yc := range goods_yc {
  8554. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8555. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8556. }
  8557. }
  8558. return nil
  8559. }
  8560. // 耗材出库删除
  8561. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8562. // 先根据相关信息查询当天该耗材的出库信息
  8563. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8564. if err != nil {
  8565. return err
  8566. }
  8567. var delete_count int64 = 0
  8568. delete_count = warehouseOutInfos.Count - count
  8569. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8570. // 在出库记录表里记录退库详情
  8571. warehouseOutInfo := &models.WarehouseOutInfo{
  8572. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8573. WarehouseOutId: warehouseOut.ID,
  8574. Status: 1,
  8575. Ctime: time.Now().Unix(),
  8576. OrgId: orgID,
  8577. Type: 1,
  8578. IsSys: 1,
  8579. SysRecordTime: record_time,
  8580. GoodTypeId: good_yc.GoodTypeId,
  8581. GoodId: good_yc.GoodId,
  8582. PatientId: good_yc.PatientId,
  8583. ConsumableType: 2,
  8584. StorehouseId: houseConfig.StorehouseOutInfo,
  8585. IsCheck: 1,
  8586. }
  8587. warehouseOutInfo.Count = count
  8588. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8589. warehouseOutInfo.Price = stockInInfo.Price
  8590. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8591. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8592. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8593. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8594. warehouseOutInfo.Number = warehouseOutInfos.Number
  8595. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8596. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8597. //查找当天是否存在出库记录
  8598. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8599. if errcod == gorm.ErrRecordNotFound {
  8600. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8601. //插入详情明细表
  8602. stockFlow := models.VmStockFlow{
  8603. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8604. WarehouseOutId: warehouseOut.ID,
  8605. GoodId: good_yc.GoodId,
  8606. Number: warehouseOutInfos.Number,
  8607. ProductDate: stockInInfo.ProductDate,
  8608. ExpireDate: stockInInfo.ExpiryDate,
  8609. Count: count,
  8610. Price: stockInInfo.Price,
  8611. Status: 1,
  8612. Ctime: time.Now().Unix(),
  8613. UserOrgId: good_yc.OrgId,
  8614. Manufacturer: stockInInfo.Manufacturer,
  8615. Dealer: stockInInfo.Dealer,
  8616. LicenseNumber: stockInInfo.LicenseNumber,
  8617. IsEdit: 2,
  8618. Creator: creater,
  8619. SystemTime: record_time,
  8620. ConsumableType: 3,
  8621. WarehousingDetailId: 0,
  8622. IsSys: 1,
  8623. UpdateCreator: creater,
  8624. PatientId: patient_id,
  8625. StorehouseId: houseConfig.StorehouseOutInfo,
  8626. }
  8627. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8628. if errflow == gorm.ErrRecordNotFound {
  8629. //创建流水表
  8630. err := service.CreateStockFlowOne(stockFlow)
  8631. fmt.Println("err", err)
  8632. } else if errflow == nil {
  8633. //插入详情明细表
  8634. stockFlow := models.VmStockFlow{
  8635. ID: exsit.ID,
  8636. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8637. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8638. WarehouseOutId: warehouseOut.ID,
  8639. GoodId: good_yc.GoodId,
  8640. Number: warehouseOutInfos.Number,
  8641. ProductDate: stockInInfo.ProductDate,
  8642. ExpireDate: stockInInfo.ExpiryDate,
  8643. Count: exsit.Count - delete_count,
  8644. Price: stockInInfo.Price,
  8645. Status: 1,
  8646. Ctime: time.Now().Unix(),
  8647. UserOrgId: good_yc.OrgId,
  8648. Manufacturer: stockInInfo.Manufacturer,
  8649. Dealer: stockInInfo.Dealer,
  8650. LicenseNumber: stockInInfo.LicenseNumber,
  8651. IsEdit: 2,
  8652. Creator: creater,
  8653. SystemTime: record_time,
  8654. ConsumableType: 3,
  8655. WarehousingDetailId: 0,
  8656. IsSys: 1,
  8657. UpdateCreator: creater,
  8658. PatientId: patient_id,
  8659. StorehouseId: houseConfig.StorehouseOutInfo,
  8660. }
  8661. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8662. }
  8663. if errOne != nil {
  8664. return errOne
  8665. }
  8666. } else if errcod == nil {
  8667. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8668. //插入详情明细表
  8669. stockFlow := models.VmStockFlow{
  8670. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8671. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8672. WarehouseOutId: warehouseOut.ID,
  8673. GoodId: good_yc.GoodId,
  8674. Number: warehouseOutInfos.Number,
  8675. ProductDate: stockInInfo.ProductDate,
  8676. ExpireDate: stockInInfo.ExpiryDate,
  8677. Count: count,
  8678. Price: stockInInfo.Price,
  8679. Status: 1,
  8680. Ctime: time.Now().Unix(),
  8681. UserOrgId: good_yc.OrgId,
  8682. Manufacturer: stockInInfo.Manufacturer,
  8683. Dealer: stockInInfo.Dealer,
  8684. LicenseNumber: stockInInfo.LicenseNumber,
  8685. IsEdit: 2,
  8686. Creator: creater,
  8687. SystemTime: record_time,
  8688. ConsumableType: 3,
  8689. WarehousingDetailId: 0,
  8690. IsSys: 1,
  8691. UpdateCreator: creater,
  8692. PatientId: patient_id,
  8693. ReturnCount: delete_count,
  8694. StorehouseId: houseConfig.StorehouseOutInfo,
  8695. }
  8696. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8697. if errflows == gorm.ErrRecordNotFound {
  8698. //创建流水表
  8699. service.CreateStockFlowOne(stockFlow)
  8700. } else if errflows == nil {
  8701. stockFlow := models.VmStockFlow{
  8702. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8703. ID: exsit.ID,
  8704. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8705. WarehouseOutId: warehouseOut.ID,
  8706. GoodId: good_yc.GoodId,
  8707. Number: warehouseOutInfos.Number,
  8708. ProductDate: stockInInfo.ProductDate,
  8709. ExpireDate: stockInInfo.ExpiryDate,
  8710. Count: exsit.Count - delete_count,
  8711. Price: stockInInfo.Price,
  8712. Status: 1,
  8713. Ctime: time.Now().Unix(),
  8714. UserOrgId: good_yc.OrgId,
  8715. Manufacturer: stockInInfo.Manufacturer,
  8716. Dealer: stockInInfo.Dealer,
  8717. LicenseNumber: stockInInfo.LicenseNumber,
  8718. IsEdit: 2,
  8719. Creator: creater,
  8720. SystemTime: record_time,
  8721. ConsumableType: 3,
  8722. WarehousingDetailId: 0,
  8723. IsSys: 1,
  8724. UpdateCreator: creater,
  8725. PatientId: patient_id,
  8726. ReturnCount: delete_count,
  8727. StorehouseId: houseConfig.StorehouseOutInfo,
  8728. }
  8729. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8730. }
  8731. }
  8732. //更改自动出库的表格
  8733. details := models.BloodAutomaticReduceDetail{
  8734. WarehouseOutId: warehouseOutInfo.ID,
  8735. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8736. PatientId: patient_id,
  8737. Ctime: time.Now().Unix(),
  8738. Mtime: time.Now().Unix(),
  8739. Status: 1,
  8740. RecordTime: record_time,
  8741. OrgId: orgID,
  8742. GoodId: good_yc.GoodId,
  8743. GoodTypeId: good_yc.GoodTypeId,
  8744. Count: count,
  8745. StorehouseId: houseConfig.StorehouseOutInfo,
  8746. }
  8747. //查询当天耗材是否已经存在数据
  8748. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8749. if errcode == gorm.ErrRecordNotFound {
  8750. errTwo := service.CreateAutoReduceRecord(&details)
  8751. if errTwo != nil {
  8752. return errTwo
  8753. }
  8754. } else if errcode == nil {
  8755. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8756. service.CreateAutoReduceRecord(&details)
  8757. }
  8758. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8759. //增加出库库存数量
  8760. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8761. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8762. fmt.Println("errOne", errOne)
  8763. // 删除出库完成后,要增加对应批次的库存数量
  8764. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8765. if errThree != nil {
  8766. return errThree
  8767. }
  8768. if good_yc.Count == 0 {
  8769. return nil
  8770. } else {
  8771. return errors.New("退库和出库数据不匹配")
  8772. }
  8773. }
  8774. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8775. //查询该患者当天已经出库的耗材信息
  8776. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8777. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8778. for i := len(goods_yc) - 1; i >= 0; i-- {
  8779. goods_yc_temp := goods_yc[i]
  8780. for j := len(goods) - 1; j >= 0; j-- {
  8781. goods_temp := goods[j]
  8782. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8783. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8784. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8785. if goods_yc_temp.Count == goods_temp.Count {
  8786. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8787. goods = append(goods[:j], goods[j+1:]...)
  8788. break
  8789. }
  8790. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8791. if goods_yc_temp.Count > goods_temp.Count {
  8792. temp_count := goods_yc_temp.Count - goods_temp.Count
  8793. goods_yc[i].Count = temp_count
  8794. goods = append(goods[:j], goods[j+1:]...)
  8795. break
  8796. }
  8797. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8798. if goods_yc_temp.Count < goods_temp.Count {
  8799. temp_count := goods_temp.Count - goods_yc_temp.Count
  8800. goods[j].Count = temp_count
  8801. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8802. break
  8803. }
  8804. }
  8805. }
  8806. }
  8807. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8808. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8809. fmt.Println("剩余需要出库的", len(goods))
  8810. if len(goods) > 0 {
  8811. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8812. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8813. if err == gorm.ErrRecordNotFound {
  8814. //没有记录,则创建出库单
  8815. timeStr := time.Now().Format("2006-01-02")
  8816. timeArr := strings.Split(timeStr, "-")
  8817. total, _ := service.FindAllWarehouseOut(orgID)
  8818. total = total + 1
  8819. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8820. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8821. number = number + total
  8822. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8823. warehouseOut := models.WarehouseOut{
  8824. WarehouseOutOrderNumber: warehousing_out_order,
  8825. OperationTime: time.Now().Unix(),
  8826. OrgId: orgID,
  8827. Creater: creater,
  8828. Ctime: time.Now().Unix(),
  8829. Status: 1,
  8830. WarehouseOutTime: record_time,
  8831. Dealer: 0,
  8832. Manufacturer: 0,
  8833. Type: 1,
  8834. IsSys: 1,
  8835. StorehouseId: houseConfig.StorehouseOutInfo,
  8836. IsCheck: 1,
  8837. }
  8838. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  8839. if err != nil {
  8840. utils.TraceLog("创建出库单失败 err = %v", err)
  8841. return err
  8842. } else {
  8843. out = warehouseOut
  8844. }
  8845. }
  8846. for _, item := range goods {
  8847. var newCount int64 = 0
  8848. for _, it := range goodOne {
  8849. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8850. newCount = it.Count
  8851. }
  8852. }
  8853. prepare := models.DialysisBeforePrepare{
  8854. GoodTypeId: item.GoodTypeId,
  8855. GoodId: item.GoodId,
  8856. Count: item.Count,
  8857. StorehouseId: houseConfig.StorehouseOutInfo,
  8858. }
  8859. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8860. //增加出库数量
  8861. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8862. }
  8863. }
  8864. if len(goods_yc) > 0 {
  8865. for _, good_yc := range goods_yc {
  8866. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8867. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8868. }
  8869. }
  8870. return nil
  8871. }
  8872. // 耗材出库删除
  8873. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8874. // 先根据相关信息查询当天该耗材的出库信息
  8875. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8876. if err != nil {
  8877. return err
  8878. }
  8879. var delete_count int64 = 0
  8880. for _, ware := range warehouseOutInfos {
  8881. // 判断当前出库的数据和删除出库数量
  8882. if good_yc.Count <= ware.Count {
  8883. delete_count = good_yc.Count
  8884. } else {
  8885. delete_count = ware.Count
  8886. }
  8887. warehouseOutInfo := &models.WarehouseOutInfo{
  8888. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8889. WarehouseOutId: warehouseOut.ID,
  8890. Status: 1,
  8891. Ctime: time.Now().Unix(),
  8892. Remark: "",
  8893. OrgId: orgID,
  8894. Type: 1,
  8895. Manufacturer: 0,
  8896. Dealer: 0,
  8897. IsSys: 0,
  8898. SysRecordTime: record_time,
  8899. GoodTypeId: good_yc.GoodTypeId,
  8900. GoodId: good_yc.GoodId,
  8901. StorehouseId: warehouseOut.StorehouseId,
  8902. IsCheck: 1,
  8903. }
  8904. warehouseOutInfo.Count = delete_count
  8905. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8906. warehouseOutInfo.Price = stockInInfo.Price
  8907. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8908. if errOne != nil {
  8909. return errOne
  8910. }
  8911. // 删除出库完成后,要改变流水库存(有疑问)
  8912. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8913. fmt.Println("errOne", errOne)
  8914. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8915. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8916. //扣减出库数量
  8917. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8918. if errThree != nil {
  8919. return errThree
  8920. }
  8921. }
  8922. if good_yc.Count == 0 {
  8923. return nil
  8924. } else {
  8925. return errors.New("退库和出库数据不匹配")
  8926. }
  8927. }
  8928. func (this *DialysisAPIController) GetMobileScheduleList() {
  8929. limit, _ := this.GetInt64("limit")
  8930. page, _ := this.GetInt64("page")
  8931. type_options_visible, _ := this.GetInt64("type_options_visible")
  8932. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8933. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8934. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8935. }
  8936. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8937. newArr = make([]*models.HisPrescriptionProject, 0)
  8938. for i := 0; i < len(arr); i++ {
  8939. repeat := false
  8940. for j := i + 1; j < len(arr); j++ {
  8941. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8942. repeat = true
  8943. break
  8944. }
  8945. }
  8946. if !repeat {
  8947. newArr = append(newArr, arr[i])
  8948. }
  8949. }
  8950. return
  8951. }
  8952. func (this *DialysisAPIController) GetRoleList() {
  8953. admin_user_id, _ := this.GetInt64("admin_user_id")
  8954. orgid := this.GetMobileAdminUserInfo().Org.Id
  8955. list, err := service.GetRoleList(orgid, admin_user_id)
  8956. fmt.Println(err)
  8957. this.ServeSuccessJSON(map[string]interface{}{
  8958. "list": list,
  8959. })
  8960. return
  8961. }
  8962. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8963. // 先根据相关信息查询当天该耗材的出库信息
  8964. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8965. if err != nil {
  8966. return err
  8967. }
  8968. var delete_count int64 = 0
  8969. delete_count = warehouseOutInfos.Count - count
  8970. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8971. // 删除出库完成后,要增加对应批次的库存数量
  8972. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8973. if errThree != nil {
  8974. return errThree
  8975. }
  8976. //增加退库数量
  8977. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8978. //扣减出库数量
  8979. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8980. //查询剩余库存
  8981. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8982. var sum_count int64
  8983. for _, item := range goodList {
  8984. sum_count += item.StockCount
  8985. }
  8986. // 在出库记录表里记录退库详情
  8987. warehouseOutInfo := &models.WarehouseOutInfo{
  8988. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8989. WarehouseOutId: warehouseOut.ID,
  8990. Status: 1,
  8991. Ctime: time.Now().Unix(),
  8992. OrgId: orgID,
  8993. Type: 1,
  8994. IsSys: 1,
  8995. SysRecordTime: record_time,
  8996. GoodTypeId: good_yc.GoodTypeId,
  8997. GoodId: good_yc.GoodId,
  8998. PatientId: good_yc.PatientId,
  8999. ConsumableType: 2,
  9000. StorehouseId: houseConfig.StorehouseOutInfo,
  9001. IsCheck: 1,
  9002. OverCount: sum_count,
  9003. }
  9004. warehouseOutInfo.Count = count
  9005. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9006. warehouseOutInfo.Price = stockInInfo.Price
  9007. warehouseOutInfo.Dealer = stockInInfo.Dealer
  9008. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  9009. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  9010. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  9011. warehouseOutInfo.Number = warehouseOutInfos.Number
  9012. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  9013. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  9014. //查找当天是否存在出库记录
  9015. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9016. if errcod == gorm.ErrRecordNotFound {
  9017. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9018. //插入详情明细表
  9019. if errOne != nil {
  9020. return errOne
  9021. }
  9022. //插入详情明细表
  9023. stockFlow := models.VmStockFlow{
  9024. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9025. WarehouseOutId: warehouseOut.ID,
  9026. GoodId: good_yc.GoodId,
  9027. Number: warehouseOutInfos.Number,
  9028. ProductDate: stockInInfo.ProductDate,
  9029. ExpireDate: stockInInfo.ExpiryDate,
  9030. Count: count,
  9031. Price: stockInInfo.Price,
  9032. Status: 1,
  9033. Ctime: record_time,
  9034. UserOrgId: good_yc.OrgId,
  9035. Manufacturer: stockInInfo.Manufacturer,
  9036. Dealer: stockInInfo.Dealer,
  9037. LicenseNumber: stockInInfo.LicenseNumber,
  9038. IsEdit: 2,
  9039. Creator: creater,
  9040. SystemTime: record_time,
  9041. ConsumableType: 3,
  9042. WarehousingDetailId: 0,
  9043. IsSys: 1,
  9044. UpdateCreator: creater,
  9045. PatientId: patient_id,
  9046. StorehouseId: houseConfig.StorehouseOutInfo,
  9047. OverCount: sum_count,
  9048. ProjectId: good_yc.ProjectId,
  9049. }
  9050. err := service.CreateStockFlowOne(stockFlow)
  9051. fmt.Println("err", err)
  9052. } else if errcod == nil {
  9053. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9054. }
  9055. //创建退库单
  9056. operation_time := time.Now().Unix()
  9057. //创建退库单
  9058. timeStr := time.Now().Format("2006-01-02")
  9059. timeArr := strings.Split(timeStr, "-")
  9060. total, _ := service.FindAllCancelStockTotal(orgID)
  9061. total = total + 1
  9062. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9063. cancelStock := models.CancelStock{
  9064. OrderNumber: orderNumber,
  9065. OperaTime: operation_time,
  9066. OrgId: orgID,
  9067. Creater: warehouseOut.Creater,
  9068. Ctime: time.Now().Unix(),
  9069. Status: 1,
  9070. ReturnTime: record_time,
  9071. Type: 1,
  9072. StorehouseId: stockInInfo.StorehouseId,
  9073. IsCheck: 1,
  9074. }
  9075. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  9076. if msgerrkonde == gorm.ErrRecordNotFound {
  9077. service.AddSigleCancelStock(&cancelStock)
  9078. }
  9079. cancel, _ := service.GetLastCancelStockById(orgID)
  9080. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  9081. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  9082. cancelStockInfo := models.CancelStockInfo{
  9083. GoodId: stockInInfo.GoodId,
  9084. CancelStockId: cancel.ID,
  9085. GoodTypeId: stockInInfo.GoodTypeId,
  9086. Count: delete_count,
  9087. Price: stockInInfo.PackingPrice,
  9088. Total: 0,
  9089. ProductDate: stockInInfo.ProductDate,
  9090. ExpiryDate: stockInInfo.ExpiryDate,
  9091. Ctime: record_time,
  9092. Status: 1,
  9093. OrgId: orgID,
  9094. OrderNumber: cancel.OrderNumber,
  9095. Type: 0,
  9096. Dealer: deaerler.DealerName,
  9097. Manufacturer: manufacturer.ManufacturerName,
  9098. Number: stockInInfo.Number,
  9099. RegisterAccount: "",
  9100. Remark: "",
  9101. WarehouseInfoId: stockInInfo.ID,
  9102. PatientId: patient_id,
  9103. RecordDate: record_time,
  9104. StorehouseId: stockInInfo.StorehouseId,
  9105. IsCheck: 1,
  9106. }
  9107. service.CreateCancelStockInfoOne(&cancelStockInfo)
  9108. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  9109. flow := models.VmStockFlow{
  9110. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  9111. GoodId: good_yc.GoodId,
  9112. Number: warehouseOutInfos.Number,
  9113. LicenseNumber: stockInInfo.LicenseNumber,
  9114. Count: delete_count,
  9115. UserOrgId: orgID,
  9116. PatientId: patient_id,
  9117. SystemTime: record_time,
  9118. ConsumableType: 7,
  9119. IsSys: 0,
  9120. WarehousingOrder: "",
  9121. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  9122. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9123. IsEdit: 0,
  9124. CancelStockId: cancel.ID,
  9125. CancelOrderNumber: cancel.OrderNumber,
  9126. Manufacturer: manufacturer.ID,
  9127. Dealer: 0,
  9128. Creator: warehouseOut.Creater,
  9129. UpdateCreator: 0,
  9130. Status: 1,
  9131. Ctime: record_time,
  9132. Mtime: 0,
  9133. Price: stockInInfo.Price,
  9134. WarehousingDetailId: stockInInfo.ID,
  9135. WarehouseOutDetailId: warehouseOutInfos.ID,
  9136. CancelOutDetailId: cancelInfo.ID,
  9137. ProductDate: stockInInfo.ProductDate,
  9138. ExpireDate: stockInInfo.ExpiryDate,
  9139. StorehouseId: houseConfig.StorehouseOutInfo,
  9140. OverCount: sum_count,
  9141. }
  9142. service.CreateStockFlowOne(flow)
  9143. //更改自动出库的表格
  9144. details := models.BloodAutomaticReduceDetail{
  9145. WarehouseOutId: warehouseOutInfo.ID,
  9146. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9147. PatientId: patient_id,
  9148. Ctime: time.Now().Unix(),
  9149. Mtime: time.Now().Unix(),
  9150. Status: 1,
  9151. RecordTime: record_time,
  9152. OrgId: orgID,
  9153. GoodId: good_yc.GoodId,
  9154. GoodTypeId: good_yc.GoodTypeId,
  9155. Count: count,
  9156. StorehouseId: houseConfig.StorehouseOutInfo,
  9157. }
  9158. //查询当天耗材是否已经存在数据
  9159. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9160. if errcode == gorm.ErrRecordNotFound {
  9161. errTwo := service.CreateAutoReduceRecord(&details)
  9162. if errTwo != nil {
  9163. return errTwo
  9164. }
  9165. } else if errcode == nil {
  9166. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9167. service.CreateAutoReduceRecord(&details)
  9168. }
  9169. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9170. //增加出库库存数量
  9171. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  9172. if good_yc.Count == 0 {
  9173. return nil
  9174. } else {
  9175. return errors.New("退库和出库数据不匹配")
  9176. }
  9177. }
  9178. func (this *DialysisAPIController) SavePatientSign() {
  9179. adminUserInfo := this.GetMobileAdminUserInfo()
  9180. patient_id, _ := this.GetInt64("patient_id")
  9181. dialysis_date, _ := this.GetInt64("dialysis_date")
  9182. orgid := adminUserInfo.Org.Id
  9183. var esdata models.DialysisOrder
  9184. var err error
  9185. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  9186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9187. return
  9188. }
  9189. esdata.Hash = esdata.Hash
  9190. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  9191. order := models.DialysisOrder{
  9192. Hash: esdata.Hash,
  9193. Url: esdata.Url,
  9194. }
  9195. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  9196. redis := service.RedisClient()
  9197. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9198. redis.Set(key, "", time.Second)
  9199. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9200. //清空key 值
  9201. redis.Set(keyOne, "", time.Second)
  9202. //scheduleDateStartOne := startDate.Format("2006-01-02")
  9203. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  9204. //redis.Set(keyTwo, "", time.Second)
  9205. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9206. redis.Set(keyThree, "", time.Second)
  9207. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9208. redis.Set(keyFour, "", time.Second)
  9209. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9210. redis.Set(keyFive, "", time.Second)
  9211. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9212. redis.Set(keySix, "", time.Second)
  9213. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  9214. redis.Set(keySeven, "", time.Second)
  9215. if err != nil {
  9216. fmt.Println(err)
  9217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9218. return
  9219. }
  9220. this.ServeSuccessJSON(map[string]interface{}{
  9221. "electronic_signature": esdata,
  9222. })
  9223. }
  9224. func (this *DialysisAPIController) GetPatientSign() {
  9225. patient_id, _ := this.GetInt64("patient_id")
  9226. dialysis_date, _ := this.GetInt64("dialysis_date")
  9227. adminUserInfo := this.GetMobileAdminUserInfo()
  9228. orgId := adminUserInfo.Org.Id
  9229. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  9230. if err != nil {
  9231. fmt.Println(err)
  9232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9233. return
  9234. }
  9235. this.ServeSuccessJSON(map[string]interface{}{
  9236. "dialysisOrder": dialysisOrder,
  9237. })
  9238. }
  9239. func (this *DialysisAPIController) GetScheduleByPatient() {
  9240. patient_id, _ := this.GetInt64("patient_id")
  9241. schedule_date, _ := this.GetInt64("schedule_date")
  9242. orgid := this.GetMobileAdminUserInfo().Org.Id
  9243. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  9244. this.ServeSuccessJSON(map[string]interface{}{
  9245. "schedule": schedule,
  9246. })
  9247. }
  9248. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  9249. org_id := this.GetMobileAdminUserInfo().Org.Id
  9250. patient_id, _ := this.GetInt64("patient_id")
  9251. schedule_date, _ := this.GetInt64("schedule_date")
  9252. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  9253. this.ServeSuccessJSON(map[string]interface{}{
  9254. "order": order,
  9255. })
  9256. }
  9257. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  9258. org_id := this.GetMobileAdminUserInfo().Org.Id
  9259. schedule_date := this.GetString("schedule_date")
  9260. schedule_type, _ := this.GetInt64("schedule_type")
  9261. timeLayout := "2006-01-02"
  9262. loc, _ := time.LoadLocation("Local")
  9263. var startdateunix int64
  9264. if len(schedule_date) > 0 {
  9265. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9266. if err != nil {
  9267. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9268. return
  9269. }
  9270. startdateunix = theTime.Unix()
  9271. }
  9272. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9273. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9274. devices, _ := service.GetAllDevicetByListSix(org_id)
  9275. for key, item := range scheduals {
  9276. // 床位信息
  9277. for _, device := range devices {
  9278. if item.BedId == device.ID {
  9279. scheduals[key].DeviceNumber = device
  9280. break
  9281. }
  9282. }
  9283. }
  9284. this.ServeSuccessJSON(map[string]interface{}{
  9285. "list": list,
  9286. "scheduals": scheduals,
  9287. })
  9288. }
  9289. func (this *DialysisAPIController) SavePatientPicture() {
  9290. patient_id, _ := this.GetInt64("patient_id")
  9291. dialysis_date, _ := this.GetInt64("schedule_date")
  9292. avatar := this.GetString("avatar")
  9293. fmt.Println("patient_id", patient_id)
  9294. orgId := this.GetMobileAdminUserInfo().Org.Id
  9295. order := models.DialysisOrder{
  9296. Url: avatar,
  9297. }
  9298. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9299. redis := service.RedisClient()
  9300. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9301. redis.Set(key, "", time.Second)
  9302. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9303. //清空key 值
  9304. redis.Set(keyOne, "", time.Second)
  9305. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9306. redis.Set(keyThree, "", time.Second)
  9307. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9308. redis.Set(keyFour, "", time.Second)
  9309. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9310. redis.Set(keyFive, "", time.Second)
  9311. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9312. redis.Set(keySix, "", time.Second)
  9313. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9314. redis.Set(keySeven, "", time.Second)
  9315. if err != nil {
  9316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9317. return
  9318. }
  9319. this.ServeSuccessJSON(map[string]interface{}{
  9320. "order": order,
  9321. })
  9322. }
  9323. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9324. ids := this.GetString("ids")
  9325. idSplit := strings.Split(ids, ",")
  9326. orgId := this.GetMobileAdminUserInfo().Org.Id
  9327. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9328. execution_time := this.GetString("exce_time")
  9329. timeLayout2 := "2006-01-02 15:04:05"
  9330. loc, _ := time.LoadLocation("Local")
  9331. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9332. if errs != nil {
  9333. utils.ErrorLog(errs.Error())
  9334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9335. return
  9336. }
  9337. //his客户
  9338. if config.IsOpen == 1 {
  9339. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9340. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9341. for _, item := range list {
  9342. for _, it := range adviceList {
  9343. if item.DrugId == it.DrugId {
  9344. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9345. }
  9346. }
  9347. }
  9348. for _, item := range list {
  9349. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9350. var sum_out_count int64
  9351. for _, itemThree := range item.ChildDoctorAdvice {
  9352. var prescribing_number int64
  9353. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9354. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9355. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9356. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9357. }
  9358. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9359. prescribing_number = parseIntPrescribingNumber
  9360. }
  9361. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9362. prescribing_number = parseIntPrescribingNumber
  9363. }
  9364. sum_out_count += prescribing_number
  9365. }
  9366. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9367. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9368. //库存不足
  9369. if sum_out_count > drugStockOut.FlushCount {
  9370. this.ServeSuccessJSON(map[string]interface{}{
  9371. "msg": "2",
  9372. "drug": medical,
  9373. "ids": ids,
  9374. })
  9375. return
  9376. }
  9377. }
  9378. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9379. //执行医嘱
  9380. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9381. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9382. for _, item := range advices {
  9383. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9384. redis := service.RedisClient()
  9385. //清空key 值
  9386. redis.Set(key, "", time.Second)
  9387. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9388. redis.Set(keyTwo, "", time.Second)
  9389. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9390. redis.Set(keyThree, "", time.Second)
  9391. recordDate := theTime.Format("2006-01-02")
  9392. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9393. redis.Set(keyFour, "", time.Second)
  9394. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9395. redis.Set(keyFive, "", time.Second)
  9396. defer redis.Close()
  9397. }
  9398. if errs == nil {
  9399. //药品管理信息
  9400. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9401. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9402. if drugStockConfig.IsOpen == 1 {
  9403. for _, item := range advices {
  9404. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9405. config, _ := service.GetDrugOpenConfigOne(orgId)
  9406. if config.IsOpen != 1 {
  9407. //查询该药品是否有库存
  9408. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9409. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9410. if medical.IsUse == 2 {
  9411. if config.IsOpen != 1 {
  9412. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9413. service.HisDrugsDelivery(orgId, creater, &advice)
  9414. if orgId == 3877 || orgId == 10265 {
  9415. //查询该药品是否有出库记录
  9416. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9417. if len(flowMap) == 0 {
  9418. errs := service.UpdateHisAdviceById(advice.ID)
  9419. if errs != nil {
  9420. drugError := models.XtDrugError{
  9421. UserOrgId: orgId,
  9422. DrugId: item.DrugId,
  9423. RecordDate: item.AdviceDate,
  9424. PatientId: item.PatientId,
  9425. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9426. Status: 1,
  9427. Ctime: time.Now().Unix(),
  9428. Mtime: 0,
  9429. SumCount: 0,
  9430. Prescribingnumber: advice.PrescribingNumber,
  9431. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9432. }
  9433. service.CreateDrugError(drugError)
  9434. }
  9435. this.ServeSuccessJSON(map[string]interface{}{
  9436. "msg": "2",
  9437. "drug": medical,
  9438. "ids": ids,
  9439. })
  9440. return
  9441. }
  9442. }
  9443. }
  9444. if pharmacyConfig.IsOpen != 1 {
  9445. service.HisDrugsDelivery(orgId, creater, &advice)
  9446. if orgId == 3877 || orgId == 10265 {
  9447. //查询该药品是否有出库记录
  9448. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9449. if len(flowMap) == 0 {
  9450. errs := service.UpdateHisAdviceById(advice.ID)
  9451. if errs != nil {
  9452. drugError := models.XtDrugError{
  9453. UserOrgId: orgId,
  9454. DrugId: item.DrugId,
  9455. RecordDate: item.AdviceDate,
  9456. PatientId: item.PatientId,
  9457. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9458. Status: 1,
  9459. Ctime: time.Now().Unix(),
  9460. Mtime: 0,
  9461. SumCount: 0,
  9462. Prescribingnumber: advice.PrescribingNumber,
  9463. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9464. }
  9465. service.CreateDrugError(drugError)
  9466. }
  9467. this.ServeSuccessJSON(map[string]interface{}{
  9468. "msg": "2",
  9469. "drug": medical,
  9470. "ids": ids,
  9471. })
  9472. return
  9473. }
  9474. }
  9475. }
  9476. //更新字典里面的库存
  9477. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9478. var sum_count int64
  9479. for _, its := range stockInfo {
  9480. if its.MaxUnit == medical.MaxUnit {
  9481. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9482. }
  9483. sum_count += its.StockMaxNumber + its.StockMinNumber
  9484. }
  9485. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9486. //剩余库存
  9487. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9488. }
  9489. }
  9490. }
  9491. }
  9492. }
  9493. this.ServeSuccessJSON(map[string]interface{}{
  9494. "msg": "1",
  9495. "ids": ids,
  9496. })
  9497. return
  9498. } else {
  9499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9500. }
  9501. }
  9502. //血透客户
  9503. if config.IsOpen == 2 || config.IsOpen == 0 {
  9504. //药品管理信息
  9505. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9506. if drugStockConfig.IsOpen == 1 {
  9507. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9508. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9509. for _, item := range list {
  9510. for _, it := range adviceList {
  9511. if item.DrugId == it.DrugId {
  9512. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9513. }
  9514. }
  9515. }
  9516. for _, item := range list {
  9517. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9518. var sum_out_count int64
  9519. for _, itemThree := range item.ChildDoctorAdvice {
  9520. var prescribing_number int64
  9521. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9522. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9523. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9524. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9525. }
  9526. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9527. prescribing_number = parseIntPrescribingNumber
  9528. }
  9529. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9530. prescribing_number = parseIntPrescribingNumber
  9531. }
  9532. sum_out_count += prescribing_number
  9533. }
  9534. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9535. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9536. //库存不足
  9537. if sum_out_count > drugStockOut.FlushCount {
  9538. this.ServeSuccessJSON(map[string]interface{}{
  9539. "msg": "2",
  9540. "drug": medical,
  9541. "ids": ids,
  9542. })
  9543. return
  9544. }
  9545. }
  9546. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9547. //执行医嘱
  9548. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9549. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9550. for _, item := range advices {
  9551. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9552. redis := service.RedisClient()
  9553. //清空key 值
  9554. redis.Set(key, "", time.Second)
  9555. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9556. redis.Set(keyTwo, "", time.Second)
  9557. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9558. redis.Set(keyThree, "", time.Second)
  9559. recordDate := theTime.Format("2006-01-02")
  9560. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9561. redis.Set(keyFour, "", time.Second)
  9562. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9563. redis.Set(keyFive, "", time.Second)
  9564. defer redis.Close()
  9565. }
  9566. if errs == nil {
  9567. for _, item := range advices {
  9568. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9569. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9570. //查询是否出库按钮开启
  9571. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9572. if adviceSetting.IsAdviceOpen == 1 {
  9573. //查询是否出库按钮开启
  9574. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9575. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9576. if prescriptionConfig.IsOpen == 1 {
  9577. if medical.IsUse == 2 {
  9578. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9579. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9580. }
  9581. if pharmacyConfig.IsOpen != 1 {
  9582. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9583. }
  9584. //更新字典里面的库存
  9585. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9586. var sum_count int64
  9587. for _, its := range stockInfo {
  9588. if its.MaxUnit == medical.MaxUnit {
  9589. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9590. }
  9591. sum_count += its.StockMaxNumber + its.StockMinNumber
  9592. }
  9593. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9594. //剩余库存
  9595. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9596. }
  9597. }
  9598. } else {
  9599. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9600. if medical.IsUse == 2 {
  9601. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9602. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9603. }
  9604. if pharmacyConfig.IsOpen != 1 {
  9605. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9606. }
  9607. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9608. var sum_count int64
  9609. for _, its := range stockInfo {
  9610. if its.MaxUnit == medical.MaxUnit {
  9611. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9612. }
  9613. sum_count += its.StockMaxNumber + its.StockMinNumber
  9614. }
  9615. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9616. //剩余库存
  9617. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9618. }
  9619. }
  9620. }
  9621. }
  9622. this.ServeSuccessJSON(map[string]interface{}{
  9623. "msg": "1",
  9624. "ids": ids,
  9625. })
  9626. return
  9627. } else {
  9628. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9629. //执行医嘱
  9630. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9631. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9632. for _, item := range advices {
  9633. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9634. redis := service.RedisClient()
  9635. //清空key 值
  9636. redis.Set(key, "", time.Second)
  9637. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9638. redis.Set(keyTwo, "", time.Second)
  9639. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9640. redis.Set(keyThree, "", time.Second)
  9641. recordDate := theTime.Format("2006-01-02")
  9642. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9643. redis.Set(keyFour, "", time.Second)
  9644. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9645. redis.Set(keyFive, "", time.Second)
  9646. defer redis.Close()
  9647. }
  9648. this.ServeSuccessJSON(map[string]interface{}{
  9649. "msg": "1",
  9650. "ids": ids,
  9651. })
  9652. return
  9653. }
  9654. }
  9655. }
  9656. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9657. ids := this.GetString("ids")
  9658. idSplit := strings.Split(ids, ",")
  9659. orgId := this.GetMobileAdminUserInfo().Org.Id
  9660. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9661. if config.IsOpen == 1 {
  9662. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9663. this.ServeSuccessJSON(map[string]interface{}{
  9664. "msg": "1",
  9665. "ids": ids,
  9666. })
  9667. return
  9668. }
  9669. if config.IsOpen == 0 || config.IsOpen == 2 {
  9670. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9671. this.ServeSuccessJSON(map[string]interface{}{
  9672. "msg": "1",
  9673. "ids": ids,
  9674. })
  9675. return
  9676. }
  9677. }
  9678. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9679. ids := this.GetString("ids")
  9680. idSplit := strings.Split(ids, ",")
  9681. orgId := this.GetMobileAdminUserInfo().Org.Id
  9682. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9683. //his
  9684. if config.IsOpen == 1 {
  9685. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9686. theTime := time.Now()
  9687. advices := models.HisDoctorAdviceThirty{
  9688. CheckTime: theTime.Unix(),
  9689. Checker: checker,
  9690. UpdatedTime: time.Now().Unix(),
  9691. }
  9692. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9693. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9694. for _, item := range list {
  9695. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9696. redis := service.RedisClient()
  9697. //清空key 值
  9698. redis.Set(key, "", time.Second)
  9699. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9700. redis.Set(keyTwo, "", time.Second)
  9701. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9702. redis.Set(keyThree, "", time.Second)
  9703. recordDate := theTime.Format("2006-01-02")
  9704. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9705. redis.Set(keyFour, "", time.Second)
  9706. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9707. redis.Set(keyFive, "", time.Second)
  9708. defer redis.Close()
  9709. }
  9710. this.ServeSuccessJSON(map[string]interface{}{
  9711. "msg": "1",
  9712. "ids": ids,
  9713. })
  9714. return
  9715. }
  9716. //血透
  9717. if config.IsOpen == 0 || config.IsOpen == 2 {
  9718. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9719. theTime := time.Now()
  9720. advices := models.DoctorAdvice{
  9721. CheckTime: theTime.Unix(),
  9722. Checker: checker,
  9723. UpdatedTime: time.Now().Unix(),
  9724. }
  9725. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9726. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9727. for _, item := range list {
  9728. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9729. redis := service.RedisClient()
  9730. //清空key 值
  9731. redis.Set(key, "", time.Second)
  9732. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9733. redis.Set(keyTwo, "", time.Second)
  9734. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9735. redis.Set(keyThree, "", time.Second)
  9736. recordDate := theTime.Format("2006-01-02")
  9737. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9738. redis.Set(keyFour, "", time.Second)
  9739. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9740. redis.Set(keyFive, "", time.Second)
  9741. defer redis.Close()
  9742. }
  9743. this.ServeSuccessJSON(map[string]interface{}{
  9744. "msg": "1",
  9745. "ids": ids,
  9746. })
  9747. return
  9748. }
  9749. }
  9750. func (this *DialysisAPIController) CheckSchedule() {
  9751. patientID, _ := this.GetInt64("patient_id")
  9752. recordDateStr := this.GetString("record_date")
  9753. nurseID, _ := this.GetInt64("start_nurse")
  9754. schedual_type, _ := this.GetInt64("schedual_type")
  9755. bedID, _ := this.GetInt64("bed")
  9756. start_time := this.GetString("start_time")
  9757. fmt.Println("patientID", patientID)
  9758. fmt.Println("recordDateStr", recordDateStr)
  9759. fmt.Println("nurseID", nurseID)
  9760. fmt.Println("schedual_type------", schedual_type)
  9761. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9762. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9763. return
  9764. }
  9765. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9766. if parseStartDateErr != nil {
  9767. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9769. return
  9770. }
  9771. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9772. if parseErr != nil {
  9773. this.ErrorLog("时间解析失败:%v", parseErr)
  9774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9775. return
  9776. }
  9777. adminUserInfo := this.GetMobileAdminUserInfo()
  9778. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9779. if getPatientErr != nil {
  9780. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9781. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9782. return
  9783. } else if patient == nil {
  9784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9785. return
  9786. }
  9787. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9788. if getNurseErr != nil {
  9789. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9791. return
  9792. } else if nurse == nil {
  9793. this.ErrorLog("护士不存在")
  9794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9795. return
  9796. }
  9797. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9798. if getDeviceNumberErr != nil {
  9799. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9801. return
  9802. } else if deviceNumber == nil {
  9803. this.ErrorLog("床位号不存在")
  9804. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9805. return
  9806. }
  9807. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9808. if getRecordErr != nil {
  9809. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9811. return
  9812. } else if dialysisRecord != nil {
  9813. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9814. return
  9815. }
  9816. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9817. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9818. timeLayout := "2006-01-02 15:04:05"
  9819. loc, _ := time.LoadLocation("Local")
  9820. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9821. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9822. schedulestartTime := theStartTime.Unix()
  9823. scheduleendTime := theEndTime.Unix()
  9824. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9825. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9826. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9827. //查询该床位是否有人用了
  9828. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9829. if err == nil {
  9830. if schedule.ID == 0 {
  9831. this.ServeSuccessJSON(map[string]interface{}{
  9832. "status": 0,
  9833. "msg": "请求失败",
  9834. })
  9835. } else {
  9836. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9837. if order.ID > 0 { //该机位被其他人占用了
  9838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9839. return
  9840. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9841. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9842. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9843. this.ServeSuccessJSON(map[string]interface{}{
  9844. "status": 1,
  9845. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9846. })
  9847. return
  9848. } else {
  9849. this.ServeSuccessJSON(map[string]interface{}{
  9850. "status": 0,
  9851. "msg": "",
  9852. })
  9853. }
  9854. }
  9855. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9856. this.ServeSuccessJSON(map[string]interface{}{
  9857. "status": 2,
  9858. "msg": "当前机位已有患者在使用,请重新选择!",
  9859. })
  9860. }
  9861. }
  9862. } else {
  9863. this.ServeSuccessJSON(map[string]interface{}{
  9864. "status": 0,
  9865. "msg": "",
  9866. })
  9867. }
  9868. }
  9869. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9870. orgId := this.GetMobileAdminUserInfo().Org.Id
  9871. schedule_type, _ := this.GetInt64("schedule_type")
  9872. partion_type, _ := this.GetInt64("partion_type")
  9873. start_time := this.GetString("start_time")
  9874. timeLayout := "2006-01-02"
  9875. loc, _ := time.LoadLocation("Local")
  9876. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9877. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9878. _, config := service.FindXTHisRecordByOrgId(orgId)
  9879. appId := this.GetMobileAdminUserInfo().App.Id
  9880. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9881. if err == nil {
  9882. this.ServeSuccessJSON(map[string]interface{}{
  9883. "list": list,
  9884. "config": config,
  9885. "doctorList": doctorList,
  9886. })
  9887. return
  9888. } else {
  9889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9890. return
  9891. }
  9892. }
  9893. func (this *DialysisAPIController) SaveMobileInformation() {
  9894. patient_id, _ := this.GetInt64("patient_id")
  9895. record_date, _ := this.GetInt64("record_date")
  9896. startTime := this.GetString("start_time")
  9897. module, _ := this.GetInt64("module")
  9898. remark := this.GetString("remark")
  9899. timeLayout := "2006-01-02 15:04"
  9900. loc, _ := time.LoadLocation("Local")
  9901. if len(startTime) == 0 {
  9902. utils.ErrorLog("len(start_time) == 0")
  9903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9904. return
  9905. }
  9906. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9907. if err != nil {
  9908. utils.ErrorLog(err.Error())
  9909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9910. return
  9911. }
  9912. StartTime := theTime.Unix()
  9913. fmt.Println("startime-------------", StartTime)
  9914. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9915. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9916. information := models.XtDialysisInformation{
  9917. Module: module,
  9918. PatientId: patient_id,
  9919. RecordDate: record_date,
  9920. ApplicationDate: StartTime,
  9921. Creater: creater,
  9922. ApplicationStatus: 2,
  9923. Checker: 0,
  9924. CheckTime: 0,
  9925. Remark: remark,
  9926. UserOrgId: user_org_id,
  9927. Ctime: time.Now().Unix(),
  9928. Status: 1,
  9929. Mtime: 0,
  9930. }
  9931. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9932. if infor.ID == 0 {
  9933. service.SaveDialysisInformation(information)
  9934. }
  9935. if infor.ID > 0 {
  9936. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9937. }
  9938. this.ServeSuccessJSON(map[string]interface{}{
  9939. "information": information,
  9940. })
  9941. return
  9942. }
  9943. func (this *DialysisAPIController) GetMobileInformation() {
  9944. limit, _ := this.GetInt64("limit")
  9945. page, _ := this.GetInt64("page")
  9946. orgid := this.GetMobileAdminUserInfo().Org.Id
  9947. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9948. appid := this.GetMobileAdminUserInfo().App.Id
  9949. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9950. patients, _ := service.GetAllpatientThirty(orgid)
  9951. this.ServeSuccessJSON(map[string]interface{}{
  9952. "information": information,
  9953. "total": total,
  9954. "doclist": doclist,
  9955. "patients": patients,
  9956. })
  9957. return
  9958. }
  9959. func (this *DialysisAPIController) GetMobileInformationOne() {
  9960. limit, _ := this.GetInt64("limit")
  9961. page, _ := this.GetInt64("page")
  9962. orgid := this.GetMobileAdminUserInfo().Org.Id
  9963. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9964. appid := this.GetMobileAdminUserInfo().App.Id
  9965. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9966. patients, _ := service.GetAllpatientThirty(orgid)
  9967. this.ServeSuccessJSON(map[string]interface{}{
  9968. "information": information,
  9969. "total": total,
  9970. "doclist": doclist,
  9971. "patients": patients,
  9972. })
  9973. return
  9974. }
  9975. func (this *DialysisAPIController) CheckMobileInformation() {
  9976. id, _ := this.GetInt64("id")
  9977. application_status, _ := this.GetInt64("application_status")
  9978. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9979. checktime := time.Now().Unix()
  9980. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9981. if err == nil {
  9982. this.ServeSuccessJSON(map[string]interface{}{
  9983. "msg": "ok",
  9984. })
  9985. return
  9986. }
  9987. }
  9988. func (c *DialysisAPIController) GetControlMonitorList() {
  9989. partition, _ := c.GetInt64("partition")
  9990. monitorDate := c.GetString("date")
  9991. patient_id, _ := c.GetInt64("patient_id")
  9992. pat_type, _ := c.GetInt64("pat_type")
  9993. timeLayout := "2006-01-02"
  9994. loc, _ := time.LoadLocation("Local")
  9995. var theStartTime int64
  9996. if len(monitorDate) > 0 {
  9997. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9998. if err != nil {
  9999. theStartTime = 0
  10000. }
  10001. theStartTime = theTime.Unix()
  10002. }
  10003. adminInfo := c.GetMobileAdminUserInfo()
  10004. orgID := adminInfo.Org.Id
  10005. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  10006. if err != nil {
  10007. c.ErrorLog("获取排班信息失败:%v", err)
  10008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10009. } else {
  10010. if len(monitor) > 0 {
  10011. //获取所有床位
  10012. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  10013. //获取所有分区
  10014. zoneList, _ := service.GetAllZoneByList(orgID)
  10015. //获取透析处方
  10016. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  10017. //获取透前评估
  10018. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  10019. //获取上机
  10020. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  10021. //获取透后
  10022. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  10023. //获取透后监测
  10024. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  10025. //获取所有的患者
  10026. patients, _ := service.GetAllPatientListByListOne(orgID)
  10027. //获取所有透析模式
  10028. treatments, _ := service.GetAllTreatModeByList(orgID)
  10029. //获取所有医嘱
  10030. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  10031. //获取双人核对
  10032. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  10033. //治疗小结
  10034. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  10035. //待消毒
  10036. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  10037. for key, item := range monitor {
  10038. // 获取床位信息
  10039. for _, it := range numberList {
  10040. if item.BedId == it.ID {
  10041. monitor[key].DeviceNumber = it
  10042. break
  10043. }
  10044. }
  10045. //获取分区信息
  10046. for _, it := range zoneList {
  10047. if item.PartitionId == it.ID {
  10048. monitor[key].DeviceZone = it
  10049. }
  10050. }
  10051. for _, prescription := range prescriptions {
  10052. if item.PatientId == prescription.PatientId {
  10053. monitor[key].Prescription = prescription
  10054. break
  10055. }
  10056. }
  10057. for _, it := range checkList {
  10058. if item.PatientId == it.PatientId {
  10059. monitor[key].DoubleCheck = it
  10060. break
  10061. }
  10062. }
  10063. for _, it := range summaryList {
  10064. if item.PatientId == it.PatientId {
  10065. monitor[key].TreatmentSummaryForList = it
  10066. break
  10067. }
  10068. }
  10069. // 透前评估
  10070. for _, assessmentBefore := range assessmentBefores {
  10071. if item.PatientId == assessmentBefore.PatientId {
  10072. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  10073. break
  10074. }
  10075. }
  10076. // 透析上下机
  10077. for _, dialysisOrder := range dialysisOrders {
  10078. if item.PatientId == dialysisOrder.PatientId {
  10079. monitor[key].DialysisOrder = dialysisOrder
  10080. break
  10081. }
  10082. }
  10083. // 治疗小节
  10084. for _, afterDislysis := range AssessmentAfterDislysis {
  10085. if item.PatientId == afterDislysis.PatientId {
  10086. monitor[key].AssessmentAfterDislysis = afterDislysis
  10087. break
  10088. }
  10089. }
  10090. for _, it := range monitorlist {
  10091. if item.PatientId == it.PatientId {
  10092. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  10093. }
  10094. }
  10095. for _, it := range adviceList {
  10096. if item.PatientId == it.PatientId {
  10097. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  10098. }
  10099. }
  10100. for _, patient := range patients {
  10101. if item.PatientId == patient.ID {
  10102. monitor[key].MonitorPatients = patient
  10103. break
  10104. }
  10105. }
  10106. for _, treatment := range treatments {
  10107. if item.ModeId == treatment.ID {
  10108. monitor[key].TreatmentMode = treatment
  10109. break
  10110. }
  10111. }
  10112. for _, infor := range informationList {
  10113. if item.PatientId == infor.PatientId {
  10114. monitor[key].NewDeviceInformation = infor
  10115. break
  10116. }
  10117. }
  10118. }
  10119. }
  10120. }
  10121. patients, err := service.GetAllpatientFourty(orgID)
  10122. var mds []*models.NewMonitorDialysisScheduleList
  10123. if pat_type == 0 {
  10124. for _, item := range monitor {
  10125. mds = append(mds, item)
  10126. }
  10127. }
  10128. //待医嘱核对
  10129. if pat_type == 1 {
  10130. for _, item := range monitor {
  10131. if len(item.AdviceList) > 0 {
  10132. mds = append(mds, item)
  10133. }
  10134. }
  10135. }
  10136. //待开小结
  10137. if pat_type == 2 {
  10138. for _, item := range monitor {
  10139. if item.TreatmentSummaryForList == nil {
  10140. mds = append(mds, item)
  10141. }
  10142. }
  10143. }
  10144. //待下机
  10145. if pat_type == 3 {
  10146. for _, item := range monitor {
  10147. if item.DialysisOrder != nil {
  10148. if item.DialysisOrder.ID > 0 {
  10149. mds = append(mds, item)
  10150. }
  10151. }
  10152. }
  10153. }
  10154. //待消毒
  10155. if pat_type == 4 {
  10156. for _, item := range monitor {
  10157. if item.NewDeviceInformation == nil {
  10158. mds = append(mds, item)
  10159. }
  10160. }
  10161. }
  10162. //待双人核对
  10163. if pat_type == 5 {
  10164. for _, item := range monitor {
  10165. if item.DoubleCheck == nil {
  10166. mds = append(mds, item)
  10167. }
  10168. }
  10169. }
  10170. //医嘱未执行
  10171. if pat_type == 6 {
  10172. for _, item := range monitor {
  10173. if len(item.AdviceList) > 0 {
  10174. mds = append(mds, item)
  10175. }
  10176. }
  10177. }
  10178. //患者未签名
  10179. if pat_type == 7 {
  10180. for _, item := range monitor {
  10181. if item.DialysisOrder != nil {
  10182. if item.DialysisOrder.ID > 0 {
  10183. mds = append(mds, item)
  10184. }
  10185. }
  10186. }
  10187. }
  10188. //目标超滤于实际超滤不同
  10189. if pat_type == 8 {
  10190. for _, item := range monitor {
  10191. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  10192. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  10193. mds = append(mds, item)
  10194. }
  10195. }
  10196. }
  10197. }
  10198. //血压少于5次
  10199. if pat_type == 9 {
  10200. for _, item := range monitor {
  10201. if len(item.MonitoringRecord) < 5 {
  10202. mds = append(mds, item)
  10203. }
  10204. }
  10205. }
  10206. if pat_type == 13 {
  10207. for _, item := range monitor {
  10208. if len(item.MonitoringRecord) < 3 {
  10209. mds = append(mds, item)
  10210. }
  10211. }
  10212. }
  10213. if pat_type == 10 {
  10214. for _, item := range monitor {
  10215. if len(item.MonitoringRecord) == 0 {
  10216. mds = append(mds, item)
  10217. }
  10218. }
  10219. }
  10220. if pat_type == 11 {
  10221. for _, item := range monitor {
  10222. if len(item.MonitoringRecord) > 0 {
  10223. mds = append(mds, item)
  10224. }
  10225. }
  10226. }
  10227. if pat_type == 12 {
  10228. for _, item := range monitor {
  10229. if len(item.MonitoringRecord) > 0 {
  10230. mds = append(mds, item)
  10231. }
  10232. }
  10233. }
  10234. if err == nil {
  10235. c.ServeSuccessJSON(map[string]interface{}{
  10236. "monitor": mds,
  10237. "patients": patients,
  10238. })
  10239. } else {
  10240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10241. }
  10242. }
  10243. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  10244. admin_user_id, _ := c.GetInt64("admin_user_id")
  10245. timeStr := time.Now().Format("2006-01-02")
  10246. timeLayout := "2006-01-02 15:04:05"
  10247. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10248. timenow := timeStringToTime.Unix()
  10249. orgId := c.GetMobileAdminUserInfo().Org.Id
  10250. //查询当前护士的患者
  10251. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  10252. var patientIds []int64
  10253. for _, item := range orderList {
  10254. patientIds = append(patientIds, item.PatientId)
  10255. }
  10256. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  10257. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  10258. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  10259. //药品管理信息
  10260. _, drugStockConfig := service.FindHisConfig(orgId)
  10261. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  10262. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  10263. c.ServeSuccessJSON(map[string]interface{}{
  10264. "adviceList": adviceList,
  10265. "hisAdviceList": hisAdviceList,
  10266. "projectList": projectList,
  10267. "drugStockConfig": drugStockConfig,
  10268. "patientList": patientList,
  10269. "projectConfig": projectConfig,
  10270. })
  10271. }
  10272. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10273. patient_id, _ := c.GetInt64("patient_id")
  10274. org_id := c.GetMobileAdminUserInfo().Org.Id
  10275. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10276. c.ServeSuccessJSON(map[string]interface{}{
  10277. "recrods": recrods,
  10278. })
  10279. }
  10280. func (c *DialysisAPIController) ExMobileChangeSch() {
  10281. id_one, _ := c.GetInt64("id_one")
  10282. id_two, _ := c.GetInt64("id_two")
  10283. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10284. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10285. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10286. //if order2.ID > 0 {
  10287. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10288. // return
  10289. //}
  10290. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10291. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10292. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10293. if count > 0 {
  10294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10295. return
  10296. }
  10297. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10298. if count1 > 0 {
  10299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10300. return
  10301. }
  10302. }
  10303. err := service.UpdateScheduleThree(sch, sch_two)
  10304. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10305. if order.ID > 0 {
  10306. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10307. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10308. redis := service.RedisClient()
  10309. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10310. redis.Set(key, "", time.Second)
  10311. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10312. //清空key 值
  10313. redis.Set(keyOne, "", time.Second)
  10314. }
  10315. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10316. if orderOne.ID > 0 {
  10317. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10318. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10319. redis := service.RedisClient()
  10320. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10321. redis.Set(key, "", time.Second)
  10322. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10323. //清空key 值
  10324. redis.Set(keyOne, "", time.Second)
  10325. }
  10326. if err == nil {
  10327. //去除当天患者排班中重复数据,保留最后一条数据
  10328. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10329. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10330. c.ServeSuccessJSON(map[string]interface{}{
  10331. "msg": "交换成功",
  10332. })
  10333. } else {
  10334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10335. return
  10336. }
  10337. }
  10338. func (c *DialysisAPIController) MobileCoverSch() {
  10339. id_one, _ := c.GetInt64("id_one")
  10340. id_two, _ := c.GetInt64("id_two")
  10341. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10342. //针对凤凰医院
  10343. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10344. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10345. if len(advice) > 0 {
  10346. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10347. }
  10348. }
  10349. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10350. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10351. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10352. if len(hisAdvice) > 0 {
  10353. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10354. }
  10355. if len(project) > 0 {
  10356. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10357. }
  10358. }
  10359. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10360. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10361. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10362. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10363. if count > 0 {
  10364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10365. return
  10366. }
  10367. }
  10368. var new_sch models.Schedule
  10369. new_sch = sch
  10370. new_sch.BedId = sch_two.BedId
  10371. new_sch.ScheduleDate = sch_two.ScheduleDate
  10372. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10373. new_sch.PartitionId = sch_two.PartitionId
  10374. new_sch.ScheduleType = sch_two.ScheduleType
  10375. new_sch.ID = 0
  10376. //删除原来的排班
  10377. err := service.SaveSchTwo(sch, sch_two)
  10378. //生成新的排班
  10379. if err == nil {
  10380. err2 := service.SaveSch(&new_sch)
  10381. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10382. if order.ID > 0 {
  10383. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10384. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10385. redis := service.RedisClient()
  10386. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10387. redis.Set(key, "", time.Second)
  10388. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10389. //清空key 值
  10390. redis.Set(keyOne, "", time.Second)
  10391. }
  10392. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10393. if orderOne.ID > 0 {
  10394. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10395. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10396. redis := service.RedisClient()
  10397. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10398. redis.Set(key, "", time.Second)
  10399. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10400. //清空key 值
  10401. redis.Set(keyOne, "", time.Second)
  10402. }
  10403. if err2 == nil {
  10404. //去除当天患者排班中重复数据,保留最后一条数据
  10405. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10406. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10407. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10408. c.ServeSuccessJSON(map[string]interface{}{
  10409. "msg": "覆盖成功",
  10410. "new_sch": new_sch,
  10411. })
  10412. } else {
  10413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10414. return
  10415. }
  10416. } else {
  10417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10418. return
  10419. }
  10420. }
  10421. func (c *DialysisAPIController) BatchCheckAdvice() {
  10422. patient_id, _ := c.GetInt64("patient_id")
  10423. advice_date, _ := c.GetInt64("advice_date")
  10424. org_id := c.GetMobileAdminUserInfo().Org.Id
  10425. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10426. //查询是his系统还是血透系统
  10427. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10428. //his客户
  10429. if configs.IsOpen == 1 {
  10430. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10431. for _, item := range adviceList {
  10432. service.BatchCheckHisAdvice(item.ID, creater)
  10433. }
  10434. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10435. for _, item := range projectList {
  10436. service.BatchCheckProject(item.ID, creater)
  10437. }
  10438. c.ServeSuccessJSON(map[string]interface{}{
  10439. "adviceList": adviceList,
  10440. "projectList": projectList,
  10441. })
  10442. }
  10443. if configs.IsOpen != 1 {
  10444. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10445. for _, item := range adviceList {
  10446. service.BatchAdviceList(item.ID, creater)
  10447. }
  10448. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10449. for _, item := range projectList {
  10450. service.BatchCheckProject(item.ID, creater)
  10451. }
  10452. c.ServeSuccessJSON(map[string]interface{}{
  10453. "adviceList": adviceList,
  10454. "projectList": projectList,
  10455. })
  10456. }
  10457. return
  10458. }
  10459. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10460. org_id := c.GetMobileAdminUserInfo().Org.Id
  10461. drugList, _ := service.GetAllDrugList(org_id)
  10462. c.ServeSuccessJSON(map[string]interface{}{
  10463. "drugList": drugList,
  10464. })
  10465. }
  10466. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10467. org_id := c.GetMobileAdminUserInfo().Org.Id
  10468. dataBody := make(map[string]interface{}, 0)
  10469. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10470. if err != nil {
  10471. utils.ErrorLog(err.Error())
  10472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10473. return
  10474. }
  10475. timeLayout := "2006-01-02"
  10476. loc, _ := time.LoadLocation("Local")
  10477. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10478. utils.ErrorLog("advice_type")
  10479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10480. return
  10481. }
  10482. adviceType := int64(dataBody["advice_type"].(float64))
  10483. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10484. utils.ErrorLog("start_time")
  10485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10486. return
  10487. }
  10488. startTime2, _ := dataBody["start_time"].(string)
  10489. time_arr := strings.Split(startTime2, " ")
  10490. if len(time_arr) > 0 {
  10491. startTime2 = time_arr[0]
  10492. }
  10493. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10494. utils.ErrorLog("advice_date")
  10495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10496. return
  10497. }
  10498. advice_date, _ := dataBody["advice_date"].(string)
  10499. var advicedateunix int64
  10500. if len(advice_date) > 0 {
  10501. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10502. if err != nil {
  10503. fmt.Println(err)
  10504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10505. return
  10506. }
  10507. advicedateunix = theTime.Unix()
  10508. }
  10509. adviceDate := startTime2
  10510. if len(adviceDate) == 0 {
  10511. utils.ErrorLog("len(adviceDate) == 0")
  10512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10513. return
  10514. }
  10515. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10516. if err != nil {
  10517. utils.ErrorLog(err.Error())
  10518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10519. return
  10520. }
  10521. AdviceDate := advicedateunix
  10522. RecordDate := advicedateunix
  10523. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10524. utils.ErrorLog("start_time")
  10525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10526. return
  10527. }
  10528. startTime, _ := dataBody["start_time"].(string)
  10529. if len(startTime) == 0 {
  10530. utils.ErrorLog("len(start_time) == 0")
  10531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10532. return
  10533. }
  10534. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10535. if err != nil {
  10536. utils.ErrorLog(err.Error())
  10537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10538. return
  10539. }
  10540. StartTime := theTime.Unix()
  10541. advice_name, _ := dataBody["advice_name"].(string)
  10542. advice_desc, _ := dataBody["advice_desc"].(string)
  10543. delivery_way, _ := dataBody["delivery_way"].(string)
  10544. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10545. frequency_type := int64(dataBody["frequency_type"].(float64))
  10546. frequency_week, _ := dataBody["frequency_week"].(string)
  10547. prescribing_number := dataBody["prescribing_number"].(float64)
  10548. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10549. remark := dataBody["remark"].(string)
  10550. single_dose := dataBody["single_dose"].(float64)
  10551. single_dose_unit := dataBody["single_dose_unit"].(string)
  10552. patient_id := int64(dataBody["patient_id"].(float64))
  10553. day_count := int64(dataBody["day_count"].(float64))
  10554. groupNo := int64(dataBody["group_no"].(float64))
  10555. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10556. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10557. if groupNo <= 0 {
  10558. group := service.GetMaxAdviceGroupID(org_id)
  10559. groupNo = group + 1
  10560. }
  10561. var template_id = ""
  10562. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10563. template_id = "M" + adviceLastId
  10564. advice := models.DoctorAdvice{
  10565. UserOrgId: org_id,
  10566. PatientId: patient_id,
  10567. AdviceType: adviceType,
  10568. AdviceDate: AdviceDate,
  10569. StartTime: StartTime,
  10570. AdviceName: advice_name,
  10571. AdviceDesc: advice_desc,
  10572. ReminderDate: 0,
  10573. SingleDose: single_dose,
  10574. SingleDoseUnit: single_dose_unit,
  10575. DrugSpec: 0,
  10576. DrugSpecUnit: "",
  10577. PrescribingNumber: prescribing_number,
  10578. PrescribingNumberUnit: prescribing_number_unit,
  10579. DeliveryWay: delivery_way,
  10580. ExecutionFrequency: execution_frequency,
  10581. AdviceDoctor: advice_doctor,
  10582. Status: 1,
  10583. CreatedTime: time.Now().Unix(),
  10584. UpdatedTime: 0,
  10585. AdviceAffirm: "",
  10586. Remark: remark,
  10587. StopTime: 0,
  10588. StopReason: "",
  10589. StopDoctor: 0,
  10590. StopState: 2,
  10591. ParentId: 0,
  10592. ExecutionTime: 0,
  10593. ExecutionStaff: 0,
  10594. ExecutionState: 0,
  10595. Checker: 0,
  10596. RecordDate: RecordDate,
  10597. DialysisOrderId: 0,
  10598. CheckTime: 0,
  10599. CheckState: 0,
  10600. AdviceId: 0,
  10601. RemindType: 0,
  10602. FrequencyType: frequency_type,
  10603. DayCount: day_count,
  10604. WeekDay: frequency_week,
  10605. ChildDoctorAdvice: nil,
  10606. TemplateId: template_id,
  10607. Modifier: 0,
  10608. IsCheck: 0,
  10609. Way: 0,
  10610. DrugId: 0,
  10611. DrugNameId: 0,
  10612. IsMedicine: 0,
  10613. PushStartTime: 0,
  10614. IsSettle: 0,
  10615. IsPrescription: 0,
  10616. GroupNo: groupNo,
  10617. }
  10618. service.CreateMobileAdivce(advice)
  10619. c.ServeSuccessJSON(map[string]interface{}{
  10620. "msg": "保存成功!",
  10621. })
  10622. }
  10623. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10624. patient_id, _ := c.GetInt64("patient_id")
  10625. org_id := c.GetMobileAdminUserInfo().Org.Id
  10626. app_id := c.GetMobileAdminUserInfo().App.Id
  10627. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10628. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10629. c.ServeSuccessJSON(map[string]interface{}{
  10630. "adviceList": adviceList,
  10631. "adminRoles": adminRoles,
  10632. })
  10633. }
  10634. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10635. org_id := c.GetMobileAdminUserInfo().Org.Id
  10636. dataBody := make(map[string]interface{}, 0)
  10637. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10638. if err != nil {
  10639. utils.ErrorLog(err.Error())
  10640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10641. return
  10642. }
  10643. timeLayout := "2006-01-02"
  10644. loc, _ := time.LoadLocation("Local")
  10645. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10646. utils.ErrorLog("start_time")
  10647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10648. return
  10649. }
  10650. startTime2, _ := dataBody["start_time"].(string)
  10651. time_arr := strings.Split(startTime2, " ")
  10652. if len(time_arr) > 0 {
  10653. startTime2 = time_arr[0]
  10654. }
  10655. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10656. utils.ErrorLog("advice_date")
  10657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10658. return
  10659. }
  10660. advice_date, _ := dataBody["advice_date"].(string)
  10661. var advicedateunix int64
  10662. if len(advice_date) > 0 {
  10663. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10664. if err != nil {
  10665. fmt.Println(err)
  10666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10667. return
  10668. }
  10669. advicedateunix = theTime.Unix()
  10670. }
  10671. adviceDate := startTime2
  10672. if len(adviceDate) == 0 {
  10673. utils.ErrorLog("len(adviceDate) == 0")
  10674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10675. return
  10676. }
  10677. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10678. if err != nil {
  10679. utils.ErrorLog(err.Error())
  10680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10681. return
  10682. }
  10683. AdviceDate := advicedateunix
  10684. RecordDate := advicedateunix
  10685. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10686. utils.ErrorLog("start_time")
  10687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10688. return
  10689. }
  10690. startTime, _ := dataBody["start_time"].(string)
  10691. if len(startTime) == 0 {
  10692. utils.ErrorLog("len(start_time) == 0")
  10693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10694. return
  10695. }
  10696. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10697. if err != nil {
  10698. utils.ErrorLog(err.Error())
  10699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10700. return
  10701. }
  10702. StartTime := theTime.Unix()
  10703. advice_name, _ := dataBody["advice_name"].(string)
  10704. advice_desc, _ := dataBody["advice_desc"].(string)
  10705. delivery_way, _ := dataBody["delivery_way"].(string)
  10706. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10707. prescribing_number := dataBody["prescribing_number"].(float64)
  10708. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10709. remark := dataBody["remark"].(string)
  10710. single_dose := dataBody["single_dose"].(float64)
  10711. single_dose_unit := dataBody["single_dose_unit"].(string)
  10712. patient_id := int64(dataBody["patient_id"].(float64))
  10713. groupNo := int64(dataBody["group_no"].(float64))
  10714. parent_id := int64(dataBody["parent_id"].(float64))
  10715. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10716. advice := models.XtDoctorAdviceOne{
  10717. UserOrgId: org_id,
  10718. PatientId: patient_id,
  10719. AdviceType: 1,
  10720. AdviceDate: AdviceDate,
  10721. StartTime: StartTime,
  10722. AdviceName: advice_name,
  10723. AdviceDesc: advice_desc,
  10724. ReminderDate: 0,
  10725. SingleDose: single_dose,
  10726. SingleDoseUnit: single_dose_unit,
  10727. PrescribingNumber: prescribing_number,
  10728. PrescribingNumberUnit: prescribing_number_unit,
  10729. DeliveryWay: delivery_way,
  10730. ExecutionFrequency: execution_frequency,
  10731. AdviceDoctor: advice_doctor,
  10732. Status: 1,
  10733. CreatedTime: time.Now().Unix(),
  10734. UpdatedTime: time.Now().Unix(),
  10735. AdviceAffirm: "",
  10736. Remark: remark,
  10737. StopTime: 0,
  10738. StopReason: "",
  10739. StopDoctor: 0,
  10740. StopState: 2,
  10741. ParentId: parent_id,
  10742. ExecutionTime: 0,
  10743. ExecutionStaff: 0,
  10744. ExecutionState: 0,
  10745. Checker: 0,
  10746. RecordDate: RecordDate,
  10747. DialysisOrderId: 0,
  10748. CheckTime: 0,
  10749. CheckState: 0,
  10750. DrugSpec: 0,
  10751. DrugSpecUnit: "",
  10752. Groupno: groupNo,
  10753. RemindType: 0,
  10754. FrequencyType: 0,
  10755. DayCount: 0,
  10756. WeekDay: "",
  10757. TemplateId: "",
  10758. Modifier: 0,
  10759. }
  10760. service.CreateMobileAdivceOne(advice)
  10761. c.ServeSuccessJSON(map[string]interface{}{
  10762. "msg": "保存成功!",
  10763. })
  10764. }
  10765. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10766. id, _ := c.GetInt64("id")
  10767. service.DeleteSelfAdviceSubAdvice(id)
  10768. c.ServeSuccessJSON(map[string]interface{}{
  10769. "msg": "保存成功!",
  10770. })
  10771. }
  10772. func (c *DialysisAPIController) GetEditAdviceAction() {
  10773. id, _ := c.GetInt64("id")
  10774. org_id := c.GetMobileAdminUserInfo().Org.Id
  10775. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10776. drugList, _ := service.GetAllDrugList(org_id)
  10777. c.ServeSuccessJSON(map[string]interface{}{
  10778. "advice": advice,
  10779. "drugList": drugList,
  10780. })
  10781. }
  10782. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10783. dataBody := make(map[string]interface{}, 0)
  10784. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10785. if err != nil {
  10786. utils.ErrorLog(err.Error())
  10787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10788. return
  10789. }
  10790. timeLayout := "2006-01-02"
  10791. loc, _ := time.LoadLocation("Local")
  10792. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10793. utils.ErrorLog("start_time")
  10794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10795. return
  10796. }
  10797. startTime2, _ := dataBody["start_time"].(string)
  10798. time_arr := strings.Split(startTime2, " ")
  10799. if len(time_arr) > 0 {
  10800. startTime2 = time_arr[0]
  10801. }
  10802. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10803. utils.ErrorLog("advice_date")
  10804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10805. return
  10806. }
  10807. advice_date, _ := dataBody["advice_date"].(string)
  10808. var advicedateunix int64
  10809. if len(advice_date) > 0 {
  10810. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10811. if err != nil {
  10812. fmt.Println(err)
  10813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10814. return
  10815. }
  10816. advicedateunix = theTime.Unix()
  10817. }
  10818. adviceDate := startTime2
  10819. if len(adviceDate) == 0 {
  10820. utils.ErrorLog("len(adviceDate) == 0")
  10821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10822. return
  10823. }
  10824. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10825. if err != nil {
  10826. utils.ErrorLog(err.Error())
  10827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10828. return
  10829. }
  10830. AdviceDate := advicedateunix
  10831. RecordDate := advicedateunix
  10832. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10833. utils.ErrorLog("start_time")
  10834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10835. return
  10836. }
  10837. startTime, _ := dataBody["start_time"].(string)
  10838. if len(startTime) == 0 {
  10839. utils.ErrorLog("len(start_time) == 0")
  10840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10841. return
  10842. }
  10843. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10844. if err != nil {
  10845. utils.ErrorLog(err.Error())
  10846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10847. return
  10848. }
  10849. StartTime := theTime.Unix()
  10850. advice_name, _ := dataBody["advice_name"].(string)
  10851. advice_desc, _ := dataBody["advice_desc"].(string)
  10852. delivery_way, _ := dataBody["delivery_way"].(string)
  10853. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10854. prescribing_number := dataBody["prescribing_number"].(float64)
  10855. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10856. remark := dataBody["remark"].(string)
  10857. single_dose := dataBody["single_dose"].(float64)
  10858. single_dose_unit := dataBody["single_dose_unit"].(string)
  10859. id := int64(dataBody["id"].(float64))
  10860. frequency_type := int64(dataBody["frequency_type"].(float64))
  10861. frequency_week, _ := dataBody["frequency_week"].(string)
  10862. day_count := int64(dataBody["day_count"].(float64))
  10863. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10864. advice := models.XtDoctorAdviceOne{
  10865. AdviceDate: AdviceDate,
  10866. StartTime: StartTime,
  10867. AdviceName: advice_name,
  10868. AdviceDesc: advice_desc,
  10869. SingleDose: single_dose,
  10870. SingleDoseUnit: single_dose_unit,
  10871. PrescribingNumber: prescribing_number,
  10872. PrescribingNumberUnit: prescribing_number_unit,
  10873. DeliveryWay: delivery_way,
  10874. ExecutionFrequency: execution_frequency,
  10875. AdviceDoctor: advice_doctor,
  10876. Remark: remark,
  10877. RecordDate: RecordDate,
  10878. FrequencyType: frequency_type,
  10879. DayCount: day_count,
  10880. WeekDay: frequency_week,
  10881. }
  10882. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10883. c.ServeSuccessJSON(map[string]interface{}{
  10884. "advice": advice,
  10885. })
  10886. }
  10887. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10888. dataBody := make(map[string]interface{}, 0)
  10889. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10890. if err != nil {
  10891. utils.ErrorLog(err.Error())
  10892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10893. return
  10894. }
  10895. timeLayout := "2006-01-02"
  10896. loc, _ := time.LoadLocation("Local")
  10897. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10898. utils.ErrorLog("start_time")
  10899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10900. return
  10901. }
  10902. startTime2, _ := dataBody["start_time"].(string)
  10903. time_arr := strings.Split(startTime2, " ")
  10904. if len(time_arr) > 0 {
  10905. startTime2 = time_arr[0]
  10906. }
  10907. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10908. utils.ErrorLog("advice_date")
  10909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10910. return
  10911. }
  10912. advice_date, _ := dataBody["advice_date"].(string)
  10913. var advicedateunix int64
  10914. if len(advice_date) > 0 {
  10915. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10916. if err != nil {
  10917. fmt.Println(err)
  10918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10919. return
  10920. }
  10921. advicedateunix = theTime.Unix()
  10922. }
  10923. adviceDate := startTime2
  10924. if len(adviceDate) == 0 {
  10925. utils.ErrorLog("len(adviceDate) == 0")
  10926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10927. return
  10928. }
  10929. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10930. if err != nil {
  10931. utils.ErrorLog(err.Error())
  10932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10933. return
  10934. }
  10935. AdviceDate := advicedateunix
  10936. RecordDate := advicedateunix
  10937. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10938. utils.ErrorLog("start_time")
  10939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10940. return
  10941. }
  10942. startTime, _ := dataBody["start_time"].(string)
  10943. if len(startTime) == 0 {
  10944. utils.ErrorLog("len(start_time) == 0")
  10945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10946. return
  10947. }
  10948. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10949. if err != nil {
  10950. utils.ErrorLog(err.Error())
  10951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10952. return
  10953. }
  10954. StartTime := theTime.Unix()
  10955. advice_name, _ := dataBody["advice_name"].(string)
  10956. advice_desc, _ := dataBody["advice_desc"].(string)
  10957. delivery_way, _ := dataBody["delivery_way"].(string)
  10958. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10959. prescribing_number := dataBody["prescribing_number"].(float64)
  10960. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10961. remark := dataBody["remark"].(string)
  10962. single_dose := dataBody["single_dose"].(float64)
  10963. single_dose_unit := dataBody["single_dose_unit"].(string)
  10964. id := int64(dataBody["id"].(float64))
  10965. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10966. advice := models.XtDoctorAdviceOne{
  10967. AdviceDate: AdviceDate,
  10968. StartTime: StartTime,
  10969. AdviceName: advice_name,
  10970. AdviceDesc: advice_desc,
  10971. SingleDose: single_dose,
  10972. SingleDoseUnit: single_dose_unit,
  10973. PrescribingNumber: prescribing_number,
  10974. PrescribingNumberUnit: prescribing_number_unit,
  10975. DeliveryWay: delivery_way,
  10976. ExecutionFrequency: execution_frequency,
  10977. AdviceDoctor: advice_doctor,
  10978. Remark: remark,
  10979. RecordDate: RecordDate,
  10980. }
  10981. service.UpdateMobileDoctorAdviceById(id, advice)
  10982. c.ServeSuccessJSON(map[string]interface{}{
  10983. "advice": advice,
  10984. })
  10985. }
  10986. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10987. dataBody := make(map[string]interface{}, 0)
  10988. timeLayout := "2006-01-02"
  10989. loc, _ := time.LoadLocation("Local")
  10990. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10991. if err != nil {
  10992. utils.ErrorLog(err.Error())
  10993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10994. return
  10995. }
  10996. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10997. utils.ErrorLog("start_time")
  10998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10999. return
  11000. }
  11001. startTime2, _ := dataBody["start_time"].(string)
  11002. time_arr := strings.Split(startTime2, " ")
  11003. if len(time_arr) > 0 {
  11004. startTime2 = time_arr[0]
  11005. }
  11006. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11007. utils.ErrorLog("advice_date")
  11008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11009. return
  11010. }
  11011. advice_date, _ := dataBody["advice_date"].(string)
  11012. var advicedateunix int64
  11013. if len(advice_date) > 0 {
  11014. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11015. if err != nil {
  11016. fmt.Println(err)
  11017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11018. return
  11019. }
  11020. advicedateunix = theTime.Unix()
  11021. }
  11022. adviceDate := startTime2
  11023. if len(adviceDate) == 0 {
  11024. utils.ErrorLog("len(adviceDate) == 0")
  11025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11026. return
  11027. }
  11028. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11029. if err != nil {
  11030. utils.ErrorLog(err.Error())
  11031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11032. return
  11033. }
  11034. RecordDate := advicedateunix
  11035. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11036. utils.ErrorLog("start_time")
  11037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11038. return
  11039. }
  11040. startTime, _ := dataBody["start_time"].(string)
  11041. if len(startTime) == 0 {
  11042. utils.ErrorLog("len(start_time) == 0")
  11043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11044. return
  11045. }
  11046. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11047. if err != nil {
  11048. utils.ErrorLog(err.Error())
  11049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11050. return
  11051. }
  11052. StartTime := theTime.Unix()
  11053. patient_id := int64(dataBody["patient_id"].(float64))
  11054. group_no := int64(dataBody["group_no"].(float64))
  11055. org_id := c.GetMobileAdminUserInfo().Org.Id
  11056. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11057. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  11058. utils.ErrorLog("advices")
  11059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11060. return
  11061. }
  11062. adviceNames := dataBody["advices"].([]interface{})
  11063. var advices []*models.GroupAdvice
  11064. for _, adviceNameMap := range adviceNames {
  11065. var advice models.GroupAdvice
  11066. adviceNameM := adviceNameMap.(map[string]interface{})
  11067. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  11068. utils.ErrorLog("advice_name")
  11069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11070. return
  11071. }
  11072. adviceName, _ := adviceNameM["advice_name"].(string)
  11073. if len(adviceName) == 0 {
  11074. utils.ErrorLog("len(advice_name) == 0")
  11075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11076. return
  11077. }
  11078. advice.AdviceName = adviceName
  11079. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  11080. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  11081. advice.DrugSpec = drugSpec
  11082. }
  11083. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  11084. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  11085. advice.AdviceDesc = adviceDesc
  11086. }
  11087. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  11088. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  11089. advice.DrugSpecUnit = drugSpecUnit
  11090. }
  11091. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  11092. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  11093. advice.SingleDose = singleDose
  11094. }
  11095. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  11096. singleDose := adviceNameM["single_dose"].(float64)
  11097. advice.SingleDose = singleDose
  11098. }
  11099. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  11100. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  11101. advice.SingleDoseUnit = singleDoseUnit
  11102. }
  11103. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  11104. tmp := adviceNameM["single_dose_unit"].(float64)
  11105. singleDoseUnit := service.TypeConversion(tmp)
  11106. advice.SingleDoseUnit = singleDoseUnit
  11107. }
  11108. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  11109. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  11110. advice.PrescribingNumber = prescribingNumber
  11111. }
  11112. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  11113. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  11114. advice.PrescribingNumber = prescribingNumber
  11115. }
  11116. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  11117. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  11118. advice.PrescribingNumberUnit = prescribingNumberUnit
  11119. }
  11120. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  11121. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  11122. advice.DeliveryWay = deliveryWay
  11123. }
  11124. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  11125. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  11126. advice.ExecutionFrequency = executionFrequency
  11127. }
  11128. remark, _ := adviceNameM["remark"].(string)
  11129. advice.Remark = remark
  11130. advice.AdviceType = 1
  11131. advice.StartTime = StartTime
  11132. advice.RecordDate = RecordDate
  11133. advice.PatientId = patient_id
  11134. advice.UserOrgId = org_id
  11135. advice.AdviceDoctor = advice_doctor
  11136. advice.StopState = 2
  11137. advices = append(advices, &advice)
  11138. }
  11139. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  11140. c.ServeSuccessJSON(map[string]interface{}{
  11141. "advice": newAdvices,
  11142. })
  11143. }
  11144. func (c *DialysisAPIController) StopLongAdvice() {
  11145. stop_time := c.GetString("execution_time")
  11146. id, _ := c.GetInt64("id")
  11147. if len(stop_time) <= 0 {
  11148. utils.ErrorLog("stop_time")
  11149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11150. return
  11151. }
  11152. timeLayout2 := "2006-01-02 15:04:05"
  11153. loc, _ := time.LoadLocation("Local")
  11154. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  11155. if errs != nil {
  11156. utils.ErrorLog(errs.Error())
  11157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11158. return
  11159. }
  11160. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  11161. c.ServeSuccessJSON(map[string]interface{}{
  11162. "advice": advice,
  11163. })
  11164. }