dialysis_api_controller.go 273KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/dialysis/advice_remind/one", &DialysisApiController{}, "Get:GetLongAdviceOne")
  41. beego.Router("/api/dialysis/advice_remind/two", &DialysisApiController{}, "Get:GetLongAdviceTwo")
  42. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  43. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  44. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  45. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  46. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  47. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  48. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  49. beego.Router("/api/dialysisgoods/get", &DialysisApiController{}, "Get:GetDialysisGoods")
  50. beego.Router("/api/goodstatistics/get", &DialysisApiController{}, "Get:GetDialysisGoodsStatistics")
  51. beego.Router("/api/queue/get", &DialysisApiController{}, "Get:GetQueueCall")
  52. beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
  53. beego.Router("/api/get/getrolelist", &DialysisApiController{}, "Get:GetRoleList")
  54. beego.Router("/api/getinitprintdata", &DialysisApiController{}, "Get:GetInitPrintData")
  55. beego.Router("/api/schedule/getorderdoctoradvice", &DialysisApiController{}, "Get:GetOrderDoctorAdvice")
  56. beego.Router("/api/getinitprintdateone", &DialysisApiController{}, "Get:GetInitPrintDataOne")
  57. //新接口
  58. beego.Router("/api/patient/getpatientdialysissolutiongrouplist", &DialysisApiController{}, "Get:GetPatientDialysisSolutionGroupList")
  59. beego.Router("/api/patient/getdialysisadvicetemplatelist", &DialysisApiController{}, "Get:GetDialysisAdviceTemplateList")
  60. beego.Router("/api/patient/savedialysissetting", &DialysisApiController{}, "Get:SaveDialysisSetting")
  61. beego.Router("/api/patient/getdialysissetting", &DialysisApiController{}, "Get:GetDialysisSetting")
  62. beego.Router("/api/patient/getdialysisparameter", &DialysisApiController{}, "Get:GetDialysisParameterList")
  63. beego.Router("/api/patient/getdialysisgoodtotalcount", &DialysisApiController{}, "Get:GetDialysisGoodTotalCount")
  64. beego.Router("/api/patient/getdialysisadvicescheduelist", &DialysisApiController{}, "Get:GetDialysisAdviceSchedulist")
  65. beego.Router("/api/patient/getdialysisparametergoodlist", &DialysisApiController{}, "Get:GetDialysisParameterGoodList")
  66. beego.Router("/api/patient/savehisdialysis", &DialysisApiController{}, "Get:SaveHisDialysis")
  67. beego.Router("/api/patient/gethisdialysisgoodcount", &DialysisApiController{}, "Get:GetHisDialysisGoodCount")
  68. beego.Router("/api/schedule/getpatientshedule", &DialysisApiController{}, "Get:GetPatientSchedule")
  69. beego.Router("/api/patient/getscheduleprintlist", &DialysisApiController{}, "Get:GetSchedulePrintList")
  70. beego.Router("/api/patient/getsolutionlistbyorgid", &DialysisApiController{}, "Get:GetSolutionListByOrgId")
  71. beego.Router("/api/schedule/excutiondoctoradvice", &DialysisApiController{}, "Get:ExcutionDoctorAdvice")
  72. beego.Router("/api/schedule/checknewdoctoradvice", &DialysisApiController{}, "Get:CheckNewDoctorAdvice")
  73. beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
  74. beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
  75. beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
  76. beego.Router("/api/schedule/getmobileschedulelist", &DialysisApiController{}, "Get:GetMobileScheduleList")
  77. beego.Router("/api/patient/saveinformation", &DialysisApiController{}, "Get:SaveInformation")
  78. beego.Router("/api/patient/savedialysisInformationsetting", &DialysisApiController{}, "Get:SaveDialysisInformationSetting")
  79. beego.Router("/api/patient/getdialyisinformationsetting", &DialysisApiController{}, "Get:GetDialysisInformationSetting")
  80. beego.Router("/api/patient/checkdialysisinformation", &DialysisApiController{}, "Get:CheckDialysisInformation")
  81. beego.Router("/api/dialysis/patientsflow", &DialysisApiController{}, "Get:GetDialysisPatientsFlow")
  82. beego.Router("/api/patient/getlongdialysisadvicetoday", &DialysisApiController{}, "Get:GetLongDialysisAdviceToday")
  83. beego.Router("/api/patient/getpatientlist", &DialysisApiController{}, "Get:GetPatientList")
  84. beego.Router("/api/patient/getprescriptionloglist", &DialysisApiController{}, "Get:GetPrescriptionLogList")
  85. beego.Router("/api/patient/getbeforloglist", &DialysisApiController{}, "Get:GetBeforLogList")
  86. beego.Router("/api/patient/getdocloglist", &DialysisApiController{}, "Get:GetDocLogList")
  87. beego.Router("/api/patient/getmonitorloglist", &DialysisApiController{}, "Get:GetMonitorLogList")
  88. beego.Router("/api/patient/getafterloglist", &DialysisApiController{}, "Get:GetAfterLogList")
  89. }
  90. func (c *DialysisApiController) GetQueueCall() {
  91. adminUserInfo := c.GetAdminUserInfo()
  92. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  93. if queueConfig.ID <= 0 {
  94. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  95. queueConfig.Qhsj = 10
  96. queueConfig.Jzdcbbcs = 3
  97. queueConfig.Jzbbsy = 1
  98. queueConfig.Jzjhyc = 0
  99. queueConfig.Sjdcbbcs = 3
  100. queueConfig.Sjbbsy = 0
  101. queueConfig.Sjjhyc = 0
  102. queueConfig.Txxqyxs = 0
  103. queueConfig.Txglsyxs = 0
  104. }
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "queue_config": queueConfig,
  107. })
  108. }
  109. func (c *DialysisApiController) UpdateQueueCall() {
  110. adminUserInfo := c.GetAdminUserInfo()
  111. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  112. if queueConfig.ID <= 0 {
  113. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  114. queueConfig.Qhsj = 10
  115. queueConfig.Jzdcbbcs = 3
  116. queueConfig.Jzbbsy = 1
  117. queueConfig.Jzjhyc = 0
  118. queueConfig.Sjdcbbcs = 3
  119. queueConfig.Sjbbsy = 0
  120. queueConfig.Sjjhyc = 0
  121. queueConfig.Txxqyxs = 0
  122. queueConfig.Txglsyxs = 0
  123. queueConfig.CreateTime = time.Now().Unix()
  124. queueConfig.UpdateTime = time.Now().Unix()
  125. }
  126. qhsj, _ := c.GetInt64("qhsj", 0)
  127. if qhsj > 0 {
  128. queueConfig.Qhsj = qhsj
  129. }
  130. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  131. if jzdcbbcs > 0 {
  132. queueConfig.Jzdcbbcs = jzdcbbcs
  133. }
  134. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  135. if jzbbsy > 0 {
  136. queueConfig.Jzbbsy = jzbbsy
  137. }
  138. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  139. queueConfig.Jzjhyc = jzjhyc
  140. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  141. if sjdcbbcs > 0 {
  142. queueConfig.Sjdcbbcs = sjdcbbcs
  143. }
  144. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  145. if sjbbsy > 0 {
  146. queueConfig.Sjbbsy = sjbbsy
  147. }
  148. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  149. queueConfig.Sjjhyc = sjjhyc
  150. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  151. queueConfig.Txxqyxs = txxqyxs
  152. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  153. queueConfig.Txglsyxs = txglsyxs
  154. queueConfig.UpdateTime = time.Now().Unix()
  155. service.UpDateQueueCallInfo(queueConfig)
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "queue_config": queueConfig,
  158. })
  159. }
  160. func (c *DialysisApiController) PostPrescription() {
  161. patient, _ := c.GetInt64("patient_id", 0)
  162. recordDateStr := c.GetString("record_date")
  163. if patient <= 0 {
  164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  165. return
  166. }
  167. adminUserInfo := c.GetAdminUserInfo()
  168. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  169. if patientInfo.ID == 0 {
  170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  171. return
  172. }
  173. if len(recordDateStr) == 0 {
  174. recordDateStr = time.Now().Format("2006-01-02")
  175. }
  176. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  177. if parseDateErr != nil {
  178. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. return
  181. }
  182. mode_id, _ := c.GetInt64("mode_id", 0)
  183. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  184. dialyzer, _ := c.GetInt64("dialyzer", 0)
  185. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  186. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  187. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  188. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  189. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  190. replacement_way, _ := c.GetInt64("replacement_way", 0)
  191. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  192. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  193. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  194. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  195. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  196. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  197. kalium, _ := c.GetFloat("kalium", 0)
  198. sodium, _ := c.GetFloat("sodium", 0)
  199. replacement_total, _ := c.GetFloat("replacement_total", 0)
  200. calcium, _ := c.GetFloat("calcium", 0)
  201. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  202. glucose, _ := c.GetFloat("glucose", 0)
  203. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  204. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  205. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  206. conductivity, _ := c.GetFloat("conductivity", 0)
  207. remark := c.GetString("remark")
  208. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  209. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  210. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  211. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  212. body_fluid, _ := c.GetInt64("body_fluid", 0)
  213. special_medicine, _ := c.GetInt64("special_medicine", 0)
  214. special_medicine_other := c.GetString("special_medicine_other")
  215. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  216. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  217. blood_access, _ := c.GetInt64("blood_access", 0)
  218. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  219. body_fluid_other := c.GetString("body_fluid_other")
  220. target_ktv, _ := c.GetFloat("target_ktv", 0)
  221. niprocart, _ := c.GetInt64("niprocart", 0)
  222. jms, _ := c.GetInt64("jms", 0)
  223. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  224. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  225. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  226. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  227. filtryzer, _ := c.GetInt64("filtryzer", 0)
  228. dialyzers, _ := c.GetInt64("dialyzers", 0)
  229. injector, _ := c.GetInt64("injector", 0)
  230. bloodlines, _ := c.GetInt64("bloodlines", 0)
  231. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  232. safe_package, _ := c.GetInt64("package", 0)
  233. a_liquid, _ := c.GetInt64("a_liquid", 0)
  234. preImpules, _ := c.GetFloat("pre_impulse", 0)
  235. fmt.Println("", preImpules)
  236. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  237. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  238. //heparin_sodium := c.GetString("heparin_sodium")
  239. //fmt.Println("肝素钠",heparin_sodium)
  240. //nucleoprotamine := c.GetString("nucleoprotamine")
  241. //fmt.Println("鱼精蛋白",nucleoprotamine)
  242. //push_the_protamine := c.GetString("push_the_protamine")
  243. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  244. // var prescription_doctor int64
  245. blood := c.GetString("blood")
  246. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  247. dialysis_irrigation := c.GetString("dialysis_irrigation")
  248. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  249. displace_speed := c.GetString("displace_speed")
  250. illness, _ := c.GetInt64("illness")
  251. amylaceum := c.GetString("amylaceum")
  252. single_time := c.GetString("single_time")
  253. single_water := c.GetString("single_water")
  254. replacement_flow := c.GetString("replacement_flow")
  255. plasma_separator := c.GetString("plasma_separator")
  256. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  257. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  258. oxygen_flow := c.GetString("oxygen_flow")
  259. oxygen_time := c.GetString("oxygen_time")
  260. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  261. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  262. puncture_needle := c.GetString("puncture_needle")
  263. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  264. epo := c.GetString("epo")
  265. epo_count, _ := c.GetFloat("epo_count", 0)
  266. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  267. admin_user_id, _ := c.GetInt64("admin_user_id")
  268. is_water, _ := c.GetInt64("is_water")
  269. drhy_water := c.GetString("drhy_water")
  270. dry_water_hour := c.GetString("dry_water_hour")
  271. water_machine := c.GetString("water_machine")
  272. add_amount, _ := c.GetFloat("add_amount")
  273. reduce_amount, _ := c.GetFloat("reduce_amount")
  274. dialysis_remark := c.GetString("dialysis_remark")
  275. prescribing_number, _ := c.GetFloat("prescribing_number")
  276. treatment_remark := c.GetString("treatment_remark")
  277. prescription_sodium := c.GetString("prescription_sodium")
  278. start_sodium := c.GetString("start_sodium")
  279. sodium_curve := c.GetString("sodium_curve")
  280. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  281. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  282. prescription_water, _ := c.GetFloat("prescription_water")
  283. dialysis_strainer := c.GetString("dialysis_strainer")
  284. chaptalization := c.GetString("chaptalization")
  285. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  286. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  287. //if template.TemplateId == 2 || template.TemplateId == 6 {
  288. // if appRole.UserType == 3 {
  289. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  290. // if getPermissionErr != nil {
  291. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  292. // return
  293. // } else if headNursePermission == nil {
  294. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  295. // return
  296. // }
  297. // }
  298. //}
  299. prescription := models.DialysisPrescription{
  300. UserOrgId: adminUserInfo.CurrentOrgId,
  301. PatientId: patient,
  302. RecordDate: recordDate.Unix(),
  303. ModeId: mode_id,
  304. DialysisDuration: dialysis_duration,
  305. Dialyzer: dialyzer,
  306. ReplacementTotal: replacement_total,
  307. PerfusionApparatus: perfusion_apparatus,
  308. BloodFlowVolume: blood_flow_volume,
  309. DewaterAmount: dewater_amount,
  310. DisplaceLiqui: displace_liqui,
  311. ReplacementWay: replacement_way,
  312. Anticoagulant: anticoagulant,
  313. AnticoagulantShouji: anticoagulant_shouji,
  314. AnticoagulantWeichi: anticoagulant_weichi,
  315. AnticoagulantZongliang: anticoagulant_zongliang,
  316. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  317. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  318. Kalium: kalium,
  319. Sodium: sodium,
  320. Calcium: calcium,
  321. Bicarbonate: bicarbonate,
  322. Glucose: glucose,
  323. // DryWeight: dry_weight,
  324. DialysateFlow: dialysate_flow,
  325. DialysateTemperature: dialysate_temperature,
  326. Conductivity: conductivity,
  327. Remark: remark,
  328. Status: 1,
  329. CreatedTime: time.Now().Unix(),
  330. UpdatedTime: time.Now().Unix(),
  331. DialysisDurationMinute: dialysisDurationMinute,
  332. DialysisDurationHour: dialysisDurationHour,
  333. TargetUltrafiltration: targetUltrafiltration,
  334. DialysateFormulation: dialysateFormulation,
  335. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  336. BodyFluid: body_fluid,
  337. SpecialMedicine: special_medicine,
  338. SpecialMedicineOther: special_medicine_other,
  339. DisplaceLiquiPart: displace_liqui_part,
  340. DisplaceLiquiValue: displace_liqui_value,
  341. BloodAccess: blood_access,
  342. Ultrafiltration: ultrafiltration,
  343. BodyFluidOther: body_fluid_other,
  344. TargetKtv: target_ktv,
  345. Niprocart: niprocart,
  346. Jms: jms,
  347. FistulaNeedleSet: fistula_needle_set,
  348. FistulaNeedleSet16: fistula_needle_set_16,
  349. Hemoperfusion: hemoperfusion,
  350. DialyserSterilised: dialyser_sterilised,
  351. Filtryzer: filtryzer,
  352. Dialyzers: dialyzers,
  353. Injector: injector,
  354. Bloodlines: bloodlines,
  355. TubingHemodialysis: tubing_hemodialysis,
  356. Package: safe_package,
  357. ALiquid: a_liquid,
  358. PreImpulse: preImpules,
  359. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  360. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  361. Blood: blood,
  362. DialysisDialyszers: dialysis_dialyszers,
  363. DialysisIrrigation: dialysis_irrigation,
  364. AntioxidantCommodityName: antioxidant_commodity_name,
  365. DisplaceSpeed: displace_speed,
  366. Illness: illness,
  367. Amylaceum: amylaceum,
  368. SingleTime: single_time,
  369. SingleWater: single_water,
  370. ReplacementFlow: replacement_flow,
  371. PlasmaSeparator: plasma_separator,
  372. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  373. OxygenFlow: oxygen_flow,
  374. OxygenUptake: oxygen_uptake,
  375. OxygenTime: oxygen_time,
  376. HemodialysisPipelines: hemodialysis_pipelines,
  377. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  378. PunctureNeedle: puncture_needle,
  379. PunctureNeedleCount: puncture_needle_count,
  380. Epo: epo,
  381. EpoCount: epo_count,
  382. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  383. AdminUserId: admin_user_id,
  384. IsWater: is_water,
  385. DrhyWater: drhy_water,
  386. DryWaterHour: dry_water_hour,
  387. WaterMachine: water_machine,
  388. AddAmount: add_amount,
  389. ReduceAmount: reduce_amount,
  390. DialysisRemark: dialysis_remark,
  391. PrescribingNumber: prescribing_number,
  392. TreatmentRemark: treatment_remark,
  393. PrescriptionSodium: prescription_sodium,
  394. StartSodium: start_sodium,
  395. SodiumCurve: sodium_curve,
  396. DialysisFluidFlow: dialysis_fluid_flow,
  397. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  398. PrescriptionWater: prescription_water,
  399. DialysisStrainer: dialysis_strainer,
  400. Chaptalization: chaptalization,
  401. }
  402. //长沙南雅医院,自动生成抗凝剂的临时处方
  403. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  404. if prescribing_number == 0 {
  405. prescribing_number = 1
  406. }
  407. advice := models.DoctorAdvice{
  408. UserOrgId: adminUserInfo.CurrentOrgId,
  409. PatientId: patient,
  410. GroupNo: 0,
  411. AdviceType: 2,
  412. RecordDate: recordDate.Unix(),
  413. AdviceDate: recordDate.Unix(),
  414. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  415. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  416. AdviceDesc: "",
  417. ReminderDate: 0,
  418. SingleDose: anticoagulant_zongliang,
  419. SingleDoseUnit: "iu",
  420. DrugSpec: 0,
  421. DrugSpecUnit: "",
  422. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  423. PrescribingNumberUnit: "支",
  424. DeliveryWay: "静脉注射",
  425. ExecutionFrequency: "上机前",
  426. AdviceDoctor: 0,
  427. Status: 1,
  428. CreatedTime: time.Now().Unix(),
  429. UpdatedTime: time.Now().Unix(),
  430. IsPrescription: 1,
  431. ExecutionState: 2,
  432. StopState: 2,
  433. IsSettle: 2,
  434. }
  435. // 查询排班信息
  436. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  437. if schedulePatient.ID > 0 {
  438. if schedulePatient.ScheduleType == 1 {
  439. advice.StartTime = recordDate.Unix() + 6.5*60*60
  440. }
  441. if schedulePatient.ScheduleType == 2 {
  442. advice.StartTime = recordDate.Unix() + 11*60*60
  443. }
  444. }
  445. // 抗凝剂名称
  446. switch anticoagulant {
  447. case 1:
  448. advice.AdviceName = "无肝素"
  449. break
  450. case 2:
  451. advice.AdviceName = "普通肝素"
  452. break
  453. case 3:
  454. advice.AdviceName = "低分子肝素"
  455. break
  456. case 4:
  457. advice.AdviceName = "阿加曲班"
  458. break
  459. case 5:
  460. advice.AdviceName = "枸橼酸钠"
  461. break
  462. case 6:
  463. advice.AdviceName = "低分子肝素钙"
  464. break
  465. case 7:
  466. advice.AdviceName = "低分子肝素钠"
  467. break
  468. case 8:
  469. advice.AdviceName = "依诺肝素"
  470. break
  471. case 9:
  472. advice.AdviceName = "达肝素"
  473. break
  474. case 10:
  475. advice.AdviceName = "体外抗凝"
  476. break
  477. case 11:
  478. advice.AdviceName = "那曲肝素"
  479. break
  480. case 12:
  481. advice.AdviceName = "无抗凝剂"
  482. break
  483. }
  484. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  485. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  486. advice.AdviceDoctor = appRole.AdminUserId
  487. }
  488. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  489. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  490. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  491. advice.AdviceName = "低分子肝素钠注射液"
  492. // 修改患者临时医嘱里的抗凝剂医嘱
  493. advice.ID = advicePrescription.ID
  494. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  495. //service.UpdateDoctorAdvice(&advice)
  496. } else {
  497. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  498. advice.AdviceName = "低分子肝素钠注射液"
  499. // 新增患者临时医嘱里的抗凝剂医嘱
  500. service.CreateDoctorAdvice(&advice)
  501. }
  502. }
  503. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  504. redis := service.RedisClient()
  505. //清空key 值
  506. redis.Set(key, "", time.Second)
  507. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  508. redis.Set(keyOne, "", time.Second)
  509. }
  510. if appRole.UserType == 2 || appRole.UserType == 1 {
  511. prescription.PrescriptionDoctor = appRole.AdminUserId
  512. }
  513. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  514. if dialysisPrescription.ID == 0 { //新增
  515. if mode_id > 0 {
  516. var str string
  517. //查找该机构用的是什么透析器
  518. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  519. if filedConfig.ID > 0 {
  520. str = dialyzerPerfusionApparatus
  521. } else {
  522. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  523. }
  524. if adminUserInfo.CurrentOrgId == 10346 {
  525. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  526. } else {
  527. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  528. }
  529. }
  530. prescription.Creater = adminUserInfo.AdminUser.Id
  531. //针对河间咸得
  532. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  533. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  534. prescription.DisplaceLiquiPart = 0
  535. prescription.DisplaceLiquiValue = 0
  536. }
  537. }
  538. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  539. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  540. }
  541. // 查询信息规挡的设置天数
  542. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  543. if infor.ID > 0 && infor.WeekDay > 0 {
  544. var cha_time int64
  545. timeNowStr := time.Now().Format("2006-01-02")
  546. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  547. //今日的日期减去设置的日期
  548. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  549. if cha_time >= recordDate.Unix() {
  550. //查询审核是否允许
  551. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 1)
  552. //申请状态不允许的情况 拒绝修改
  553. if infor.ApplicationStatus != 1 {
  554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  555. return
  556. }
  557. }
  558. }
  559. err := service.AddSigleRecord(&prescription)
  560. //记录日志
  561. byterequest, _ := json.Marshal(prescription)
  562. dialysisPrescriptionLog := models.XtDialysisPrescriptionLog{
  563. UserOrgId: adminUserInfo.CurrentOrgId,
  564. Ctime: time.Now().Unix(),
  565. Mtime: 0,
  566. ErrLog: string(byterequest),
  567. AdminUserId: adminUserInfo.AdminUser.Id,
  568. RecordDate: prescription.RecordDate,
  569. PatientId: prescription.PatientId,
  570. Source: "电脑端新建处方",
  571. Status: 1,
  572. }
  573. service.CreatePrescriptionLog(dialysisPrescriptionLog)
  574. //创建步骤表
  575. finish := models.XtDialysisFinish{
  576. IsFinish: 1,
  577. UserOrgId: adminUserInfo.CurrentOrgId,
  578. Status: 1,
  579. Ctime: time.Now().Unix(),
  580. Mtime: 0,
  581. Module: 1,
  582. RecordDate: recordDate.Unix(),
  583. Sourse: 1,
  584. PatientId: patient,
  585. }
  586. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  587. if dialysisFinish.ID == 0 {
  588. service.CreateDialysisFinish(finish)
  589. }
  590. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  591. redis := service.RedisClient()
  592. //清空key 值
  593. redis.Set(key, "", time.Second)
  594. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  595. redis.Set(keyTwo, "", time.Second)
  596. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  597. redis.Set(keyThree, "", time.Second)
  598. defer redis.Close()
  599. if err == nil {
  600. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  601. if updateErr != nil {
  602. utils.ErrorLog("%v", updateErr)
  603. }
  604. c.ServeSuccessJSON(map[string]interface{}{
  605. "prescription": &prescription,
  606. })
  607. } else {
  608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  609. }
  610. } else { //修改
  611. if mode_id > 0 {
  612. var str string
  613. //查找该机构用的是什么透析器
  614. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  615. if filedConfig.ID > 0 {
  616. str = dialyzerPerfusionApparatus
  617. } else {
  618. str = dialysis_dialyszers + "/" + dialysis_irrigation
  619. }
  620. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  621. }
  622. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  623. //if template.TemplateId == 1 {
  624. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  625. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  626. // if getPermissionErr != nil {
  627. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  628. // return
  629. // } else if headNursePermission == nil {
  630. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  631. // return
  632. // }
  633. // }
  634. //}
  635. if appRole.UserType == 2 || appRole.UserType == 1 {
  636. prescription_doctor := adminUserInfo.AdminUser.Id
  637. prescription.PrescriptionDoctor = prescription_doctor
  638. }
  639. if dialysisPrescription.Creater == 0 { //体重称
  640. prescription.Creater = adminUserInfo.AdminUser.Id
  641. } else {
  642. prescription.Creater = dialysisPrescription.Creater
  643. if adminUserInfo.CurrentOrgId == 9882 {
  644. if appRole.UserType == 2 || appRole.UserType == 1 {
  645. prescription_doctor := adminUserInfo.AdminUser.Id
  646. prescription.PrescriptionDoctor = prescription_doctor
  647. prescription.Creater = prescription_doctor
  648. }
  649. }
  650. }
  651. prescription.CreatedTime = dialysisPrescription.CreatedTime
  652. prescription.UpdatedTime = time.Now().Unix()
  653. prescription.Modifier = adminUserInfo.AdminUser.Id
  654. prescription.ID = dialysisPrescription.ID
  655. // 查询信息规挡的设置天数
  656. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  657. if infor.ID > 0 && infor.WeekDay > 0 {
  658. var cha_time int64
  659. timeNowStr := time.Now().Format("2006-01-02")
  660. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  661. //今日的日期减去设置的日期
  662. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  663. if cha_time >= recordDate.Unix() {
  664. //查询审核是否允许
  665. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 1)
  666. //申请状态不允许的情况 拒绝修改
  667. if infor.ApplicationStatus != 1 {
  668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  669. return
  670. }
  671. }
  672. }
  673. updateErr := service.UpDateDialysisPrescription(&prescription)
  674. //记录日志
  675. byterequest, _ := json.Marshal(prescription)
  676. dialysisPrescriptionLog := models.XtDialysisPrescriptionLog{
  677. UserOrgId: adminUserInfo.CurrentOrgId,
  678. Ctime: time.Now().Unix(),
  679. Mtime: 0,
  680. ErrLog: string(byterequest),
  681. AdminUserId: adminUserInfo.AdminUser.Id,
  682. RecordDate: prescription.RecordDate,
  683. PatientId: prescription.PatientId,
  684. Source: "电脑端修改处方",
  685. Status: 1,
  686. }
  687. service.CreatePrescriptionLog(dialysisPrescriptionLog)
  688. //创建步骤表
  689. finish := models.XtDialysisFinish{
  690. IsFinish: 1,
  691. UserOrgId: adminUserInfo.CurrentOrgId,
  692. Status: 1,
  693. Ctime: time.Now().Unix(),
  694. Mtime: 0,
  695. Module: 1,
  696. RecordDate: recordDate.Unix(),
  697. Sourse: 1,
  698. PatientId: patient,
  699. }
  700. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  701. if dialysisFinish.ID == 0 {
  702. service.CreateDialysisFinish(finish)
  703. }
  704. //修改处方
  705. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  706. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  707. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  708. if advicePrescription.ID > 0 {
  709. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  710. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  711. redis := service.RedisClient()
  712. defer redis.Close()
  713. //清空key 值
  714. redis.Set(key, "", time.Second)
  715. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  716. redis.Set(keyOne, "", time.Second)
  717. }
  718. }
  719. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  720. redis := service.RedisClient()
  721. defer redis.Close()
  722. //清空key 值
  723. redis.Set(key, "", time.Second)
  724. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  725. redis.Set(keyOne, "", time.Second)
  726. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  727. redis.Set(keyThree, "", time.Second)
  728. if updateErr == nil {
  729. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  730. if updateErr != nil {
  731. utils.ErrorLog("%v", updateErr)
  732. }
  733. c.ServeSuccessJSON(map[string]interface{}{
  734. "prescription": &prescription,
  735. })
  736. } else {
  737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  738. }
  739. }
  740. }
  741. func (c *DialysisApiController) PostSoulution() {
  742. patient, _ := c.GetInt64("patient", 0)
  743. recordDateStr := c.GetString("record_date")
  744. if patient <= 0 {
  745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  746. return
  747. }
  748. adminUserInfo := c.GetAdminUserInfo()
  749. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  750. if patientInfo.ID == 0 {
  751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  752. return
  753. }
  754. if len(recordDateStr) == 0 {
  755. recordDateStr = time.Now().Format("2006-01-02")
  756. }
  757. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  758. if parseDateErr != nil {
  759. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  761. return
  762. }
  763. mode_id, _ := c.GetInt64("mode_id", 0)
  764. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  765. dialyzer, _ := c.GetInt64("dialyzer", 0)
  766. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  767. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  768. replacement_total, _ := c.GetFloat("replacement_total", 0)
  769. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  770. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  771. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  772. replacement_way, _ := c.GetInt64("replacement_way", 0)
  773. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  774. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  775. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  776. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  777. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  778. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  779. kalium, _ := c.GetFloat("kalium", 0)
  780. sodium, _ := c.GetFloat("sodium", 0)
  781. calcium, _ := c.GetFloat("calcium", 0)
  782. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  783. glucose, _ := c.GetFloat("glucose", 0)
  784. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  785. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  786. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  787. conductivity, _ := c.GetFloat("conductivity", 0)
  788. remark := c.GetString("remark")
  789. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  790. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  791. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  792. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  793. body_fluid, _ := c.GetInt64("body_fluid", 0)
  794. special_medicine, _ := c.GetInt64("special_medicine", 0)
  795. special_medicine_other := c.GetString("special_medicine_other")
  796. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  797. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  798. blood_access, _ := c.GetInt64("blood_access", 0)
  799. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  800. body_fluid_other := c.GetString("body_fluid_other")
  801. target_ktv, _ := c.GetFloat("target_ktv", 0)
  802. niprocart, _ := c.GetInt64("niprocart", 0)
  803. jms, _ := c.GetInt64("jms", 0)
  804. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  805. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  806. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  807. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  808. filtryzer, _ := c.GetInt64("filtryzer", 0)
  809. dialyzers, _ := c.GetInt64("dialyzers", 0)
  810. injector, _ := c.GetInt64("injector", 0)
  811. bloodlines, _ := c.GetInt64("bloodlines", 0)
  812. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  813. safe_package, _ := c.GetInt64("package", 0)
  814. a_liquid, _ := c.GetInt64("a_liquid", 0)
  815. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  816. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  817. blood := c.GetString("blood")
  818. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  819. dialysis_irrigation := c.GetString("dialysis_irrigation")
  820. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  821. displace_speed := c.GetString("displace_speed")
  822. illness, _ := c.GetInt64("illness")
  823. amylaceum := c.GetString("amylaceum")
  824. single_time := c.GetString("single_time")
  825. single_water := c.GetString("single_water")
  826. replacement_flow := c.GetString("replacement_flow")
  827. plasma_separator := c.GetString("plasma_separator")
  828. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  829. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  830. oxygen_flow := c.GetString("oxygen_flow")
  831. oxygen_time := c.GetString("oxygen_time")
  832. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  833. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  834. puncture_needle := c.GetString("puncture_needle")
  835. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  836. epo := c.GetString("epo")
  837. epo_count, _ := c.GetFloat("epo_count", 0)
  838. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  839. impulse := c.GetString("impulse")
  840. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  841. admin_user_id, _ := c.GetInt64("admin_user_id")
  842. fmt.Println("", preImpules)
  843. is_water, _ := c.GetInt64("is_water")
  844. dry_water_hour := c.GetString("dry_water_hour")
  845. drhy_water := c.GetString("drhy_water")
  846. water_machine := c.GetString("water_machine")
  847. add_amount, _ := c.GetFloat("add_amount")
  848. reduce_amount, _ := c.GetFloat("reduce_amount")
  849. dialysis_remark := c.GetString("dialysis_remark")
  850. prescribing_number, _ := c.GetFloat("prescribing_number")
  851. treatment_remark := c.GetString("treatment_remark")
  852. prescription_sodium := c.GetString("prescription_sodium")
  853. start_sodium := c.GetString("start_sodium")
  854. sodium_curve := c.GetString("sodium_curve")
  855. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  856. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  857. prescription_water, _ := c.GetFloat("prescription_water")
  858. dialysis_strainer := c.GetString("dialysis_strainer")
  859. chaptalization := c.GetString("chaptalization")
  860. var prescription_doctor int64
  861. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  862. if appRole.UserType == 2 || appRole.UserType == 1 {
  863. prescription_doctor = appRole.AdminUserId
  864. }
  865. if mode_id > 0 {
  866. var str string
  867. //查找该机构用的是什么透析器
  868. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  869. if filedConfig.ID > 0 {
  870. str = dialyzerPerfusionApparatus
  871. } else {
  872. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  873. }
  874. if adminUserInfo.CurrentOrgId == 10346 {
  875. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  876. } else {
  877. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  878. }
  879. }
  880. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  881. //
  882. //if template.TemplateId == 2 || template.TemplateId == 6 {
  883. // if appRole.UserType == 3 {
  884. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  885. // if getPermissionErr != nil {
  886. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  887. // return
  888. // } else if headNursePermission == nil {
  889. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  890. // return
  891. // }
  892. // }
  893. //}
  894. // 查询信息规挡的设置天数
  895. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  896. if infor.ID > 0 && infor.WeekDay > 0 {
  897. var cha_time int64
  898. timeNowStr := time.Now().Format("2006-01-02")
  899. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  900. //今日的日期减去设置的日期
  901. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  902. if cha_time >= recordDate.Unix() {
  903. //查询审核是否允许
  904. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 1)
  905. //申请状态不允许的情况 拒绝修改
  906. if infor.ApplicationStatus != 1 {
  907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  908. return
  909. }
  910. }
  911. }
  912. prescription := models.DialysisPrescription{
  913. UserOrgId: adminUserInfo.CurrentOrgId,
  914. PatientId: patient,
  915. RecordDate: recordDate.Unix(),
  916. ModeId: mode_id,
  917. DialysisDuration: dialysis_duration,
  918. Dialyzer: dialyzer,
  919. PerfusionApparatus: perfusion_apparatus,
  920. BloodFlowVolume: blood_flow_volume,
  921. DewaterAmount: dewater_amount,
  922. DisplaceLiqui: displace_liqui,
  923. ReplacementWay: replacement_way,
  924. Anticoagulant: anticoagulant,
  925. AnticoagulantShouji: anticoagulant_shouji,
  926. AnticoagulantWeichi: anticoagulant_weichi,
  927. AnticoagulantZongliang: anticoagulant_zongliang,
  928. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  929. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  930. Kalium: kalium,
  931. Sodium: sodium,
  932. Calcium: calcium,
  933. Bicarbonate: bicarbonate,
  934. Glucose: glucose,
  935. // DryWeight: dry_weight,
  936. DialysateFlow: dialysate_flow,
  937. DialysateTemperature: dialysate_temperature,
  938. Conductivity: conductivity,
  939. Remark: remark,
  940. PrescriptionDoctor: prescription_doctor,
  941. Status: 1,
  942. CreatedTime: time.Now().Unix(),
  943. UpdatedTime: time.Now().Unix(),
  944. DialysisDurationMinute: dialysisDurationMinute,
  945. DialysisDurationHour: dialysisDurationHour,
  946. TargetUltrafiltration: targetUltrafiltration,
  947. DialysateFormulation: dialysateFormulation,
  948. ReplacementTotal: replacement_total,
  949. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  950. BodyFluid: body_fluid,
  951. SpecialMedicine: special_medicine,
  952. SpecialMedicineOther: special_medicine_other,
  953. DisplaceLiquiPart: displace_liqui_part,
  954. DisplaceLiquiValue: displace_liqui_value,
  955. BloodAccess: blood_access,
  956. Ultrafiltration: ultrafiltration,
  957. BodyFluidOther: body_fluid_other,
  958. TargetKtv: target_ktv,
  959. Niprocart: niprocart,
  960. Jms: jms,
  961. FistulaNeedleSet: fistula_needle_set,
  962. FistulaNeedleSet16: fistula_needle_set_16,
  963. Hemoperfusion: hemoperfusion,
  964. DialyserSterilised: dialyser_sterilised,
  965. Filtryzer: filtryzer,
  966. Dialyzers: dialyzers,
  967. Injector: injector,
  968. Bloodlines: bloodlines,
  969. TubingHemodialysis: tubing_hemodialysis,
  970. Package: safe_package,
  971. ALiquid: a_liquid,
  972. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  973. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  974. Blood: blood,
  975. DialysisIrrigation: dialysis_irrigation,
  976. DialysisDialyszers: dialysis_dialyszers,
  977. AntioxidantCommodityName: antioxidant_commodity_name,
  978. DisplaceSpeed: displace_speed,
  979. Illness: illness,
  980. Amylaceum: amylaceum,
  981. SingleTime: single_time,
  982. SingleWater: single_water,
  983. ReplacementFlow: replacement_flow,
  984. PlasmaSeparator: plasma_separator,
  985. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  986. OxygenTime: oxygen_time,
  987. OxygenUptake: oxygen_uptake,
  988. OxygenFlow: oxygen_flow,
  989. HemodialysisPipelines: hemodialysis_pipelines,
  990. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  991. PunctureNeedle: puncture_needle,
  992. PunctureNeedleCount: puncture_needle_count,
  993. Epo: epo,
  994. EpoCount: epo_count,
  995. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  996. PreImpulse: preImpules,
  997. AdminUserId: admin_user_id,
  998. IsWater: is_water,
  999. DryWaterHour: dry_water_hour,
  1000. DrhyWater: drhy_water,
  1001. WaterMachine: water_machine,
  1002. AddAmount: add_amount,
  1003. ReduceAmount: reduce_amount,
  1004. DialysisRemark: dialysis_remark,
  1005. PrescribingNumber: prescribing_number,
  1006. StartSodium: start_sodium,
  1007. PrescriptionSodium: prescription_sodium,
  1008. SodiumCurve: sodium_curve,
  1009. TreatmentRemark: treatment_remark,
  1010. DialysisFluidFlow: dialysis_fluid_flow,
  1011. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1012. PrescriptionWater: prescription_water,
  1013. DialysisStrainer: dialysis_strainer,
  1014. Chaptalization: chaptalization,
  1015. }
  1016. //查询最近透析准备表里是否存在 透析器 灌流器
  1017. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1018. //
  1019. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1020. //
  1021. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  1022. //if len(mation)>0{
  1023. // for _, item := range splitStr {
  1024. // for _,it := range mation{
  1025. // if(item == it.SpecificationName){
  1026. //
  1027. // //查询最近一次的透析器
  1028. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  1029. //
  1030. // if errcode == gorm.ErrRecordNotFound{
  1031. // //插入数据
  1032. // prepare := models.DialysisBeforePrepare{
  1033. // UserOrgId: adminUserInfo.CurrentOrgId,
  1034. // PatientId: patient,
  1035. // RecordDate: recordDate.Unix(),
  1036. // GoodTypeId: it.GoodTypeId,
  1037. // GoodId: it.ID,
  1038. // Count: 1,
  1039. // Ctime: time.Now().Unix(),
  1040. // Creater: adminUserInfo.AdminUser.Id,
  1041. // Status:1,
  1042. //
  1043. // }
  1044. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1045. // fmt.Println("",errcode)
  1046. // }
  1047. // }
  1048. // }
  1049. //
  1050. // }
  1051. //
  1052. // for _, item := range splitIrrigation {
  1053. // for _,it := range mation{
  1054. // if(item == it.SpecificationName){
  1055. // //查询最近一次的透析器
  1056. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  1057. // if errcode == gorm.ErrRecordNotFound{
  1058. // //插入数据
  1059. // prepare := models.DialysisBeforePrepare{
  1060. // UserOrgId: adminUserInfo.CurrentOrgId,
  1061. // PatientId: patient,
  1062. // RecordDate: recordDate.Unix(),
  1063. // GoodTypeId: it.GoodTypeId,
  1064. // GoodId: it.ID,
  1065. // Count: 1,
  1066. // Ctime: time.Now().Unix(),
  1067. // Creater: adminUserInfo.AdminUser.Id,
  1068. // Status:1,
  1069. //
  1070. // }
  1071. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1072. // fmt.Println(errcode)
  1073. // }
  1074. // }
  1075. // }
  1076. // }
  1077. //}
  1078. //创建步骤表
  1079. finish := models.XtDialysisFinish{
  1080. IsFinish: 1,
  1081. UserOrgId: adminUserInfo.CurrentOrgId,
  1082. Status: 1,
  1083. Ctime: time.Now().Unix(),
  1084. Mtime: 0,
  1085. Module: 1,
  1086. RecordDate: recordDate.Unix(),
  1087. Sourse: 1,
  1088. PatientId: patient,
  1089. }
  1090. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  1091. if dialysisFinish.ID == 0 {
  1092. service.CreateDialysisFinish(finish)
  1093. }
  1094. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1095. if dialysisPrescription.ID == 0 { //新增
  1096. if appRole.UserType == 2 || appRole.UserType == 1 {
  1097. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1098. }
  1099. prescription.Creater = adminUserInfo.AdminUser.Id
  1100. } else { //修改
  1101. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1102. //if template.TemplateId == 1 {
  1103. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1104. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1105. // if getPermissionErr != nil {
  1106. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1107. // return
  1108. // } else if headNursePermission == nil {
  1109. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1110. // return
  1111. // }
  1112. // }
  1113. //}
  1114. if appRole.UserType == 2 || appRole.UserType == 1 {
  1115. prescription_doctor := adminUserInfo.AdminUser.Id
  1116. prescription.PrescriptionDoctor = prescription_doctor
  1117. } else {
  1118. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1119. }
  1120. if dialysisPrescription.Creater == 0 {
  1121. prescription.Creater = adminUserInfo.AdminUser.Id
  1122. } else {
  1123. prescription.Creater = dialysisPrescription.Creater
  1124. if appRole.UserType == 2 || appRole.UserType == 1 {
  1125. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1126. prescription.Creater = adminUserInfo.AdminUser.Id
  1127. }
  1128. }
  1129. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1130. prescription.UpdatedTime = time.Now().Unix()
  1131. prescription.Modifier = adminUserInfo.AdminUser.Id
  1132. prescription.ID = dialysisPrescription.ID
  1133. }
  1134. solution := models.DialysisSolution{
  1135. RegistrarsId: adminUserInfo.AdminUser.Id,
  1136. UserOrgId: adminUserInfo.CurrentOrgId,
  1137. Doctor: prescription_doctor,
  1138. PatientId: patient,
  1139. ModeId: mode_id,
  1140. DialysisDuration: dialysis_duration,
  1141. PerfusionApparatus: perfusion_apparatus,
  1142. BloodFlowVolume: blood_flow_volume,
  1143. Dewater: dewater_amount,
  1144. DisplaceLiqui: displace_liqui,
  1145. ReplacementWay: replacement_way,
  1146. Anticoagulant: anticoagulant,
  1147. AnticoagulantShouji: anticoagulant_shouji,
  1148. AnticoagulantWeichi: anticoagulant_weichi,
  1149. AnticoagulantZongliang: anticoagulant_zongliang,
  1150. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1151. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1152. Kalium: kalium,
  1153. Sodium: sodium,
  1154. Calcium: calcium,
  1155. Bicarbonate: bicarbonate,
  1156. Glucose: glucose,
  1157. // DryWeight: dry_weight,
  1158. DialysateFlow: dialysate_flow,
  1159. DialysateTemperature: dialysate_temperature,
  1160. Conductivity: conductivity,
  1161. Remark: remark,
  1162. Status: 1,
  1163. CreatedTime: time.Now().Unix(),
  1164. UpdatedTime: time.Now().Unix(),
  1165. DialysisDurationMinute: dialysisDurationMinute,
  1166. DialysisDurationHour: dialysisDurationHour,
  1167. TargetUltrafiltration: targetUltrafiltration,
  1168. DialysateFormulation: dialysateFormulation,
  1169. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1170. BodyFluid: body_fluid,
  1171. SpecialMedicine: special_medicine,
  1172. SpecialMedicineOther: special_medicine_other,
  1173. DisplaceLiquiPart: displace_liqui_part,
  1174. DisplaceLiquiValue: displace_liqui_value,
  1175. BloodAccess: blood_access,
  1176. Ultrafiltration: ultrafiltration,
  1177. BodyFluidOther: body_fluid_other,
  1178. ReplacementTotal: replacement_total,
  1179. TargetKtv: target_ktv,
  1180. DialysisIrrigation: dialysis_irrigation,
  1181. DialysisDialyszers: dialysis_dialyszers,
  1182. HemodialysisPipelines: hemodialysis_pipelines,
  1183. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1184. PunctureNeedle: puncture_needle,
  1185. PunctureNeedleCount: puncture_needle_count,
  1186. Epo: epo,
  1187. EpoCount: epo_count,
  1188. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1189. OxygenUptake: oxygen_uptake,
  1190. OxygenFlow: oxygen_flow,
  1191. OxygenTime: oxygen_time,
  1192. PreImpulse: preImpules,
  1193. SolutionStatus: 1,
  1194. DialysisRemark: dialysis_remark,
  1195. PrescribingNumber: prescribing_number,
  1196. StartSodium: start_sodium,
  1197. PrescriptionSodium: prescription_sodium,
  1198. SodiumCurve: sodium_curve,
  1199. TreatmentRemark: treatment_remark,
  1200. DialysisFluidFlow: dialysis_fluid_flow,
  1201. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1202. PrescriptionWater: prescribing_number,
  1203. DialysisStrainer: dialysis_strainer,
  1204. Chaptalization: chaptalization,
  1205. }
  1206. //针对河间咸得
  1207. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1208. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1209. prescription.DisplaceLiquiPart = 0
  1210. prescription.DisplaceLiquiValue = 0
  1211. }
  1212. }
  1213. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1214. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  1215. solution.DisplaceLiquiPart = 0
  1216. solution.DisplaceLiquiValue = 0
  1217. }
  1218. }
  1219. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  1220. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1221. }
  1222. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1223. //记录日志
  1224. byterequest, _ := json.Marshal(prescription)
  1225. dialysisPrescriptionLog := models.XtDialysisPrescriptionLog{
  1226. UserOrgId: adminUserInfo.CurrentOrgId,
  1227. Ctime: time.Now().Unix(),
  1228. Mtime: 0,
  1229. ErrLog: string(byterequest),
  1230. AdminUserId: adminUserInfo.AdminUser.Id,
  1231. RecordDate: prescription.RecordDate,
  1232. PatientId: prescription.PatientId,
  1233. Source: "电脑端新增长期处方",
  1234. Status: 1,
  1235. }
  1236. service.CreatePrescriptionLog(dialysisPrescriptionLog)
  1237. //创建步骤表
  1238. finishOne := models.XtDialysisFinish{
  1239. IsFinish: 1,
  1240. UserOrgId: adminUserInfo.CurrentOrgId,
  1241. Status: 1,
  1242. Ctime: time.Now().Unix(),
  1243. Mtime: 0,
  1244. Module: 1,
  1245. RecordDate: recordDate.Unix(),
  1246. Sourse: 1,
  1247. PatientId: patient,
  1248. }
  1249. dialysisFinishOne, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  1250. if dialysisFinishOne.ID == 0 {
  1251. service.CreateDialysisFinish(finishOne)
  1252. }
  1253. //获取最新1条
  1254. dialysisSolution, _ := service.GetLastPatientDialysisSolution(patient, adminUserInfo.CurrentOrgId)
  1255. //更新状态
  1256. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  1257. //长沙南雅医院,自动生成抗凝剂的临时处方
  1258. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  1259. if prescribing_number == 0 {
  1260. prescribing_number = 1
  1261. }
  1262. advice := models.DoctorAdvice{
  1263. UserOrgId: adminUserInfo.CurrentOrgId,
  1264. PatientId: patient,
  1265. GroupNo: 0,
  1266. AdviceType: 2,
  1267. RecordDate: recordDate.Unix(),
  1268. AdviceDate: recordDate.Unix(),
  1269. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1270. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1271. AdviceDesc: "",
  1272. ReminderDate: 0,
  1273. SingleDose: anticoagulant_zongliang,
  1274. SingleDoseUnit: "iu",
  1275. DrugSpec: 0,
  1276. DrugSpecUnit: "",
  1277. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1278. PrescribingNumberUnit: "支",
  1279. DeliveryWay: "静脉注射",
  1280. ExecutionFrequency: "上机前",
  1281. AdviceDoctor: 0,
  1282. Status: 1,
  1283. CreatedTime: time.Now().Unix(),
  1284. UpdatedTime: time.Now().Unix(),
  1285. IsPrescription: 1,
  1286. ExecutionState: 2,
  1287. StopState: 2,
  1288. IsSettle: 2,
  1289. }
  1290. // 查询排班信息
  1291. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1292. if schedulePatient.ID > 0 {
  1293. if schedulePatient.ScheduleType == 1 {
  1294. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1295. }
  1296. if schedulePatient.ScheduleType == 2 {
  1297. advice.StartTime = recordDate.Unix() + 11*60*60
  1298. }
  1299. }
  1300. // 抗凝剂名称
  1301. switch anticoagulant {
  1302. case 1:
  1303. advice.AdviceName = "无肝素"
  1304. break
  1305. case 2:
  1306. advice.AdviceName = "普通肝素"
  1307. break
  1308. case 3:
  1309. advice.AdviceName = "低分子肝素"
  1310. break
  1311. case 4:
  1312. advice.AdviceName = "阿加曲班"
  1313. break
  1314. case 5:
  1315. advice.AdviceName = "枸橼酸钠"
  1316. break
  1317. case 6:
  1318. advice.AdviceName = "低分子肝素钙"
  1319. break
  1320. case 7:
  1321. advice.AdviceName = "低分子肝素钠"
  1322. break
  1323. case 8:
  1324. advice.AdviceName = "依诺肝素"
  1325. break
  1326. case 9:
  1327. advice.AdviceName = "达肝素"
  1328. break
  1329. case 10:
  1330. advice.AdviceName = "体外抗凝"
  1331. break
  1332. case 11:
  1333. advice.AdviceName = "那曲肝素"
  1334. break
  1335. case 12:
  1336. advice.AdviceName = "无抗凝剂"
  1337. break
  1338. }
  1339. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1340. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  1341. advice.AdviceDoctor = appRole.AdminUserId
  1342. }
  1343. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1344. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1345. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1346. advice.AdviceName = "低分子肝素钠注射液"
  1347. // 修改患者临时医嘱里的抗凝剂医嘱
  1348. advice.ID = advicePrescription.ID
  1349. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1350. } else {
  1351. // 新增患者临时医嘱里的抗凝剂医嘱
  1352. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1353. advice.AdviceName = "低分子肝素钠注射液"
  1354. service.CreateDoctorAdvice(&advice)
  1355. }
  1356. }
  1357. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1358. redis := service.RedisClient()
  1359. //清空key 值
  1360. redis.Set(key, "", time.Second)
  1361. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1362. redis.Set(keyOne, "", time.Second)
  1363. }
  1364. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1365. redis := service.RedisClient()
  1366. //清空key 值
  1367. redis.Set(key, "", time.Second)
  1368. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1369. //清空key 值
  1370. redis.Set(keyOne, "", time.Second)
  1371. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1372. redis.Set(keyTwo, "", time.Second)
  1373. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1374. redis.Set(keyThree, "", time.Second)
  1375. defer redis.Close()
  1376. if err == nil {
  1377. c.ServeSuccessJSON(map[string]interface{}{
  1378. "solution": &solution,
  1379. "prescription": &prescription,
  1380. })
  1381. } else {
  1382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1383. }
  1384. }
  1385. func (c *DialysisApiController) PostDouleCheck() {
  1386. id, _ := c.GetInt64("patient", 0)
  1387. recordDateStr := c.GetString("record_date")
  1388. checkTimeStr := c.GetString("check_time")
  1389. firstCheckTimeStr := c.GetString("first_check_time")
  1390. creater, _ := c.GetInt64("creater", 0)
  1391. modifier, _ := c.GetInt64("modifier", 0)
  1392. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  1393. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  1394. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  1395. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  1396. dialysis_item_desc := c.GetString("dialysis_item_desc")
  1397. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  1398. vascular_access_desc := c.GetString("vascular_access_desc")
  1399. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  1400. collator, _ := c.GetInt64("collator", 0)
  1401. employee_number := c.GetString("employee_number")
  1402. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  1403. needle_batch_number := c.GetString("needle_batch_number")
  1404. if id <= 0 {
  1405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1406. return
  1407. }
  1408. adminUserInfo := c.GetAdminUserInfo()
  1409. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1410. if patient.ID == 0 {
  1411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1412. return
  1413. }
  1414. if len(recordDateStr) == 0 {
  1415. recordDateStr = time.Now().Format("2006-01-02")
  1416. }
  1417. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1418. if parseDateErr != nil {
  1419. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1421. return
  1422. }
  1423. var checkDate int64
  1424. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1425. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1426. if employee_number != list.JobNumber {
  1427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1428. return
  1429. }
  1430. }
  1431. if len(checkTimeStr) == 0 {
  1432. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1433. checkDate = 0
  1434. } else {
  1435. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1436. checkDate = checkDateUnix.Unix()
  1437. }
  1438. var firstCheckTimeDate int64
  1439. if len(firstCheckTimeStr) == 0 {
  1440. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1441. firstCheckTimeDate = 0
  1442. } else {
  1443. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1444. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1445. }
  1446. doubleCheck := models.DoubleCheck{
  1447. UserOrgId: adminUserInfo.CurrentOrgId,
  1448. PatientId: id,
  1449. DialysisItemCheck: dialysis_item_check,
  1450. DialysisParameterCheck: dialysis_parameter_check,
  1451. VascularAccessVerification: vascular_access_verification,
  1452. PipelineConnectionCheck: pipeline_connection_check,
  1453. DialysisItemDesc: dialysis_item_desc,
  1454. DialysisParameterDesc: dialysis_parameter_desc,
  1455. VascularAccessDesc: vascular_access_desc,
  1456. PipelineConnectionDesc: pipeline_connection_desc,
  1457. Collator: collator,
  1458. Status: 1,
  1459. CreatedTime: time.Now().Unix(),
  1460. UpdatedTime: time.Now().Unix(),
  1461. CheckDate: recordDate.Unix(),
  1462. EmployeeNumber: employee_number,
  1463. DialyzerBatchNumber: dialyzer_batch_number,
  1464. NeedleBatchNumber: needle_batch_number,
  1465. }
  1466. // 查询信息规挡的设置天数
  1467. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1468. if infor.ID > 0 && infor.WeekDay > 0 {
  1469. var cha_time int64
  1470. timeNowStr := time.Now().Format("2006-01-02")
  1471. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1472. //今日的日期减去设置的日期
  1473. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1474. if cha_time >= recordDate.Unix() {
  1475. //查询审核是否允许
  1476. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 5)
  1477. //申请状态不允许的情况 拒绝修改
  1478. if infor.ApplicationStatus != 1 {
  1479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1480. return
  1481. }
  1482. }
  1483. }
  1484. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1485. if check.ID == 0 { //新增
  1486. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1487. doubleCheck.CheckTime = checkDate
  1488. doubleCheck.Creater = creater
  1489. doubleCheck.Modifier = modifier
  1490. err := service.AddSigleDoubleCheck(&doubleCheck)
  1491. //创建步骤表
  1492. finish := models.XtDialysisFinish{
  1493. IsFinish: 1,
  1494. UserOrgId: adminUserInfo.CurrentOrgId,
  1495. Status: 1,
  1496. Ctime: time.Now().Unix(),
  1497. Mtime: 0,
  1498. Module: 5,
  1499. RecordDate: recordDate.Unix(),
  1500. Sourse: 1,
  1501. PatientId: id,
  1502. }
  1503. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 5, id)
  1504. if dialysisFinish.ID == 0 {
  1505. service.CreateDialysisFinish(finish)
  1506. }
  1507. // 查询信息规挡的设置天数
  1508. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1509. if infor.ID > 0 {
  1510. var cha_time int64
  1511. timeNowStr := time.Now().Format("2006-01-02")
  1512. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1513. //今日的日期减去设置的日期
  1514. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1515. if cha_time >= recordDate.Unix() {
  1516. //查询审核是否允许
  1517. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 5)
  1518. //申请状态不允许的情况 拒绝修改
  1519. if infor.ApplicationStatus != 1 {
  1520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1521. return
  1522. }
  1523. }
  1524. }
  1525. redis := service.RedisClient()
  1526. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1527. //清空key 值
  1528. redis.Set(key, "", time.Second)
  1529. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1530. redis.Set(keyTwo, "", time.Second)
  1531. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1532. redis.Set(keyThree, "", time.Second)
  1533. defer redis.Close()
  1534. if err == nil {
  1535. c.ServeSuccessJSON(map[string]interface{}{
  1536. "doubleCheck": doubleCheck,
  1537. })
  1538. } else {
  1539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1540. }
  1541. } else { //修改
  1542. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1543. doubleCheck.CheckTime = checkDate
  1544. doubleCheck.Creater = creater
  1545. doubleCheck.Modifier = modifier
  1546. doubleCheck.CreatedTime = check.CreatedTime
  1547. doubleCheck.UpdatedTime = time.Now().Unix()
  1548. doubleCheck.ID = check.ID
  1549. redis := service.RedisClient()
  1550. err := service.UpdateDoubleCheck(&doubleCheck)
  1551. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1552. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1553. redis.Set(keyTwo, "", time.Second)
  1554. //清空key 值
  1555. redis.Set(key, "", time.Second)
  1556. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1557. redis.Set(keyThree, "", time.Second)
  1558. defer redis.Close()
  1559. if err == nil {
  1560. c.ServeSuccessJSON(map[string]interface{}{
  1561. "doubleCheck": doubleCheck,
  1562. })
  1563. } else {
  1564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1565. }
  1566. }
  1567. }
  1568. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1569. id, _ := c.GetInt64("patient", 0)
  1570. recordDateStr := c.GetString("record_date")
  1571. way, _ := c.GetInt64("way", 0)
  1572. consciousness, _ := c.GetInt64("consciousness", 0)
  1573. appetite, _ := c.GetInt64("appetite", 0)
  1574. condition, _ := c.GetInt64("condition", 0)
  1575. posture, _ := c.GetInt64("posture")
  1576. score := c.GetString("score")
  1577. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1578. danger_level, _ := c.GetInt64("danger_level", 0)
  1579. intake, _ := c.GetInt64("intake", 0)
  1580. nutrition, _ := c.GetInt64("nutrition", 0)
  1581. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1582. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1583. sick_condition_other := c.GetString("sick_condition_other")
  1584. //precaution, _ := c.GetInt64("precaution", 0)
  1585. precaution := c.GetString("precaution")
  1586. precaution_other := c.GetString("precaution_other")
  1587. psychological_other := c.GetString("psychological_other")
  1588. admission_number := c.GetString("admission_number")
  1589. tumble, _ := c.GetInt64("tumble")
  1590. his_department := c.GetString("his_department")
  1591. his_bed := c.GetString("his_bed")
  1592. diacrisis := c.GetString("diacrisis")
  1593. if id <= 0 {
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1595. return
  1596. }
  1597. adminUserInfo := c.GetAdminUserInfo()
  1598. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1599. if patient.ID == 0 {
  1600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1601. return
  1602. }
  1603. if len(recordDateStr) == 0 {
  1604. recordDateStr = time.Now().Format("2006-01-02")
  1605. }
  1606. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1607. if parseDateErr != nil {
  1608. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1610. return
  1611. }
  1612. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1613. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1614. UserOrgId: adminUserInfo.CurrentOrgId,
  1615. PatientId: id,
  1616. RecordDate: recordDate.Unix(),
  1617. Way: way,
  1618. Consciousness: consciousness,
  1619. Appetite: appetite,
  1620. Condition: condition,
  1621. SickCondition: sick_condition,
  1622. DangerLevel: danger_level,
  1623. Intake: intake,
  1624. Nutrition: nutrition,
  1625. PsychologicalAssessment: psychological_assessment,
  1626. PsychologicalAssessmentOther: psychological_assessment_other,
  1627. SickConditionOther: sick_condition_other,
  1628. Posture: posture,
  1629. CreatedTime: time.Now().Unix(),
  1630. UpdateTime: time.Now().Unix(),
  1631. Status: 1,
  1632. Score: score,
  1633. Precaution: precaution,
  1634. PrecautionOther: precaution_other,
  1635. PsychologicalOther: psychological_other,
  1636. AdmissionNumber: admission_number,
  1637. Tumble: tumble,
  1638. HisDepartment: his_department,
  1639. HisBed: his_bed,
  1640. Diacrisis: diacrisis,
  1641. }
  1642. // 查询信息规挡的设置天数
  1643. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1644. if infor.ID > 0 && infor.WeekDay > 0 {
  1645. var cha_time int64
  1646. timeNowStr := time.Now().Format("2006-01-02")
  1647. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1648. //今日的日期减去设置的日期
  1649. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1650. if cha_time >= recordDate.Unix() {
  1651. //查询审核是否允许
  1652. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 2)
  1653. //申请状态不允许的情况 拒绝修改
  1654. if infor.ApplicationStatus != 1 {
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1656. return
  1657. }
  1658. }
  1659. }
  1660. if receiveTreatment.ID == 0 { //新增
  1661. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1662. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1663. //创建步骤表
  1664. finish := models.XtDialysisFinish{
  1665. IsFinish: 1,
  1666. UserOrgId: adminUserInfo.CurrentOrgId,
  1667. Status: 1,
  1668. Ctime: time.Now().Unix(),
  1669. Mtime: 0,
  1670. Module: 2,
  1671. RecordDate: recordDate.Unix(),
  1672. Sourse: 1,
  1673. PatientId: id,
  1674. }
  1675. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 2, id)
  1676. if dialysisFinish.ID == 0 {
  1677. service.CreateDialysisFinish(finish)
  1678. }
  1679. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1680. redis := service.RedisClient()
  1681. //清空key 值
  1682. redis.Set(key, "", time.Second)
  1683. defer redis.Close()
  1684. if err == nil {
  1685. c.ServeSuccessJSON(map[string]interface{}{
  1686. "receiveTreatmentAsses": receiveTreatmentAsses,
  1687. })
  1688. } else {
  1689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1690. }
  1691. } else { //修改
  1692. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1693. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1694. // if getPermissionErr != nil {
  1695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1696. // return
  1697. // } else if headNursePermission == nil {
  1698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1699. // return
  1700. // }
  1701. //}
  1702. // 查询信息规挡的设置天数
  1703. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1704. if infor.ID > 0 && infor.WeekDay > 0 {
  1705. var cha_time int64
  1706. timeNowStr := time.Now().Format("2006-01-02")
  1707. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1708. //今日的日期减去设置的日期
  1709. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1710. if cha_time >= recordDate.Unix() {
  1711. //查询审核是否允许
  1712. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 2)
  1713. //申请状态不允许的情况 拒绝修改
  1714. if infor.ApplicationStatus != 1 {
  1715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1716. return
  1717. }
  1718. }
  1719. }
  1720. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1721. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1722. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1723. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1724. receiveTreatmentAsses.ID = receiveTreatment.ID
  1725. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1726. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1727. redis := service.RedisClient()
  1728. defer redis.Close()
  1729. redis.Set(keyOne, "", time.Second*60*60*18)
  1730. if err == nil {
  1731. c.ServeSuccessJSON(map[string]interface{}{
  1732. "receiveTreatmentAsses": receiveTreatmentAsses,
  1733. })
  1734. } else {
  1735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1736. }
  1737. }
  1738. }
  1739. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1740. patient, _ := c.GetInt64("patient", 0)
  1741. recordDateStr := c.GetString("record_date")
  1742. fmt.Println(recordDateStr)
  1743. if patient <= 0 {
  1744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1745. return
  1746. }
  1747. adminUserInfo := c.GetAdminUserInfo()
  1748. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1749. if patientInfo.ID == 0 {
  1750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1751. return
  1752. }
  1753. if len(recordDateStr) == 0 {
  1754. recordDateStr = time.Now().Format("2006-01-02")
  1755. }
  1756. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1757. if parseDateErr != nil {
  1758. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1760. return
  1761. }
  1762. // data := make(map[string]interface{}, 0)
  1763. var data models.AssessmentAfterDislysis
  1764. var err error
  1765. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1766. fmt.Println(err)
  1767. if err != nil {
  1768. c.ErrorLog("数据解析错误:%v", err)
  1769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1770. return
  1771. }
  1772. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1773. assessment.DialysisOrderId = data.DialysisOrderId
  1774. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1775. assessment.Status = 1
  1776. assessment.WeightAfter = data.WeightAfter
  1777. assessment.WeightLoss = data.WeightLoss
  1778. assessment.Temperature = data.Temperature
  1779. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1780. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1781. assessment.PulseFrequency = data.PulseFrequency
  1782. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1783. assessment.ActualDisplacement = data.ActualDisplacement
  1784. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1785. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1786. assessment.Cruor = data.Cruor
  1787. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1788. assessment.DialysisIntakes = data.DialysisIntakes
  1789. assessment.InternalFistula = data.InternalFistula
  1790. assessment.BloodAccessPartId = data.BloodAccessPartId
  1791. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1792. assessment.Catheter = data.Catheter
  1793. assessment.Complication = data.Complication
  1794. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1795. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1796. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1797. assessment.PatientGose = data.PatientGose
  1798. assessment.InpatientDepartment = data.InpatientDepartment
  1799. assessment.ObservationContent = data.ObservationContent
  1800. assessment.ObservationContentOther = data.ObservationContentOther
  1801. assessment.Remark = data.Remark
  1802. assessment.BreathingRate = data.BreathingRate
  1803. assessment.DialysisProcess = data.DialysisProcess
  1804. assessment.InAdvanceMinute = data.InAdvanceMinute
  1805. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1806. assessment.InAdvanceReason = data.InAdvanceReason
  1807. assessment.HemostasisOpera = data.HemostasisOpera
  1808. assessment.HemostasisMinute = data.HemostasisMinute
  1809. assessment.TremorNoise = data.TremorNoise
  1810. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1811. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1812. assessment.ArterialTube = data.ArterialTube
  1813. assessment.IntravenousTube = data.IntravenousTube
  1814. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1815. assessment.Dialyzer = data.Dialyzer
  1816. assessment.IsEat = data.IsEat
  1817. assessment.CvcA = data.CvcA
  1818. assessment.CvcV = data.CvcV
  1819. assessment.Channel = data.Channel
  1820. assessment.ReturnBlood = data.ReturnBlood
  1821. assessment.RehydrationVolume = data.RehydrationVolume
  1822. assessment.DialysisDuring = data.DialysisDuring
  1823. assessment.StrokeVolume = data.StrokeVolume
  1824. assessment.BloodFlow = data.BloodFlow
  1825. assessment.SealingFluidDispose = data.SealingFluidDispose
  1826. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1827. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1828. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1829. assessment.SettingPressure = data.SettingPressure
  1830. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1831. assessment.DiastolicPressure = data.DiastolicPressure
  1832. assessment.AdditionalWeight = data.AdditionalWeight
  1833. assessment.OtherComplication = data.OtherComplication
  1834. assessment.Ktv = data.Ktv
  1835. assessment.Urr = data.Urr
  1836. assessment.Hypertenison = data.Hypertenison
  1837. assessment.Hypopiesia = data.Hypopiesia
  1838. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1839. assessment.Lapse = data.Lapse
  1840. assessment.Consciousness = data.Consciousness
  1841. assessment.Fallrisk = data.Fallrisk
  1842. assessment.MachineRun = data.MachineRun
  1843. assessment.AfterUrea = data.AfterUrea
  1844. assessment.PipCoagulation = data.PipCoagulation
  1845. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1846. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1847. if assessment.ID > 0 {
  1848. if appRole.UserType == 2 || appRole.UserType == 1 {
  1849. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1850. assessment.AssessmentTime = time.Now().Unix()
  1851. } else {
  1852. if assessment.Creater == 0 {
  1853. assessment.Modifier = adminUserInfo.AdminUser.Id
  1854. assessment.Creater = adminUserInfo.AdminUser.Id
  1855. } else {
  1856. assessment.Modifier = adminUserInfo.AdminUser.Id
  1857. }
  1858. }
  1859. assessment.UpdatedTime = time.Now().Unix()
  1860. // 查询信息规挡的设置天数
  1861. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1862. if infor.ID > 0 {
  1863. var cha_time int64
  1864. timeNowStr := time.Now().Format("2006-01-02")
  1865. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1866. //今日的日期减去设置的日期
  1867. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1868. if cha_time >= recordDate.Unix() {
  1869. //查询审核是否允许
  1870. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 9)
  1871. //申请状态不允许的情况 拒绝修改
  1872. if infor.ApplicationStatus != 1 {
  1873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1874. return
  1875. }
  1876. }
  1877. }
  1878. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1879. //记录日志
  1880. byterequest, _ := json.Marshal(assessment)
  1881. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1882. UserOrgId: assessment.UserOrgId,
  1883. PatientId: assessment.PatientId,
  1884. RecordDate: assessment.AssessmentDate,
  1885. Status: 1,
  1886. ErrLog: string(byterequest),
  1887. AdminUserId: adminUserInfo.AdminUser.Id,
  1888. Ctime: time.Now().Unix(),
  1889. Mtime: 0,
  1890. Source: "电脑端保存透后评估",
  1891. }
  1892. service.CreateAfterDialysisLog(afterDialysisLog)
  1893. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1894. redis := service.RedisClient()
  1895. //清空key 值
  1896. redis.Set(key, "", time.Second)
  1897. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1898. redis.Set(keyThree, "", time.Second)
  1899. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1900. redis.Set(keyTwo, "", time.Second)
  1901. defer redis.Close()
  1902. } else {
  1903. if appRole.UserType == 2 || appRole.UserType == 1 {
  1904. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1905. assessment.AssessmentTime = time.Now().Unix()
  1906. } else {
  1907. assessment.Creater = adminUserInfo.AdminUser.Id
  1908. }
  1909. assessment.CreatedTime = time.Now().Unix()
  1910. assessment.UpdatedTime = time.Now().Unix()
  1911. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1912. assessment.PatientId = patient
  1913. assessment.AssessmentDate = recordDate.Unix()
  1914. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1915. //记录日志
  1916. byterequest, _ := json.Marshal(assessment)
  1917. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1918. UserOrgId: assessment.UserOrgId,
  1919. PatientId: assessment.PatientId,
  1920. RecordDate: assessment.AssessmentDate,
  1921. Status: 1,
  1922. ErrLog: string(byterequest),
  1923. AdminUserId: adminUserInfo.AdminUser.Id,
  1924. Ctime: time.Now().Unix(),
  1925. Mtime: 0,
  1926. Source: "电脑端修改保存透后评估",
  1927. }
  1928. service.CreateAfterDialysisLog(afterDialysisLog)
  1929. finish := models.XtDialysisFinish{
  1930. IsFinish: 1,
  1931. UserOrgId: adminUserInfo.CurrentOrgId,
  1932. Status: 1,
  1933. Ctime: time.Now().Unix(),
  1934. Mtime: 0,
  1935. Module: 9,
  1936. RecordDate: recordDate.Unix(),
  1937. Sourse: 1,
  1938. PatientId: patient,
  1939. }
  1940. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 9, patient)
  1941. if dialysisFinish.ID == 0 {
  1942. service.CreateDialysisFinish(finish)
  1943. }
  1944. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1945. redis := service.RedisClient()
  1946. //清空key 值
  1947. redis.Set(key, "", time.Second)
  1948. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1949. redis.Set(keyThree, "", time.Second)
  1950. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1951. redis.Set(keyTwo, "", time.Second)
  1952. defer redis.Close()
  1953. }
  1954. if err != nil {
  1955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1956. return
  1957. }
  1958. c.ServeSuccessJSON(map[string]interface{}{
  1959. "AssessmentAfterDislysis": &assessment,
  1960. })
  1961. }
  1962. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1963. patient, _ := c.GetInt64("patient", 0)
  1964. recordDateStr := c.GetString("record_date")
  1965. if patient <= 0 {
  1966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1967. return
  1968. }
  1969. adminUserInfo := c.GetAdminUserInfo()
  1970. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1971. if patientInfo.ID == 0 {
  1972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1973. return
  1974. }
  1975. if len(recordDateStr) == 0 {
  1976. recordDateStr = time.Now().Format("2006-01-02")
  1977. }
  1978. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1979. if parseDateErr != nil {
  1980. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1982. return
  1983. }
  1984. weight_before, _ := c.GetFloat("weight_before", 0)
  1985. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1986. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1987. temperature, _ := c.GetFloat("temperature", 0)
  1988. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1989. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1990. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1991. last_post_dialysis := c.GetString("last_post_dialysis")
  1992. dialysis_interphase := c.GetString("dialysis_interphase")
  1993. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1994. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1995. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1996. bloodAccessPartId := c.GetString("blood_access_part_id")
  1997. internalFistula := c.GetString("internal_fistula")
  1998. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1999. catheter := c.GetString("catheter")
  2000. catheter_bend, _ := c.GetInt("catheter_bend")
  2001. complication := c.GetString("complication")
  2002. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  2003. hemorrhage := c.GetString("hemorrhage")
  2004. hemorrhage_other := c.GetString("hemorrhage_other")
  2005. remark := c.GetString("remark")
  2006. puncture_method := c.GetString("puncture_method")
  2007. dialysis_count := c.GetString("dialysis_count")
  2008. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  2009. emergency_treatment_other := c.GetString("emergency_treatment_other")
  2010. ductus_arantii := c.GetString("ductus_arantii")
  2011. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  2012. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  2013. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  2014. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  2015. puncture_way := c.GetString("puncture_way")
  2016. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  2017. internal_fistula_other := c.GetString("internal_fistula_other")
  2018. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2019. breathing_rate := c.GetString("breathing_rate")
  2020. is_infect, _ := c.GetInt64("is_infect", 0)
  2021. exposed, _ := c.GetFloat("exposed", 0)
  2022. skin := c.GetString("skin")
  2023. skin_other := c.GetString("skin_other")
  2024. infect_other := c.GetString("infect_other")
  2025. ductus_arantii_other := c.GetString("ductus_arantii_other")
  2026. machine_type := c.GetString("machine_type")
  2027. puncture_needle := c.GetString("puncture_needle")
  2028. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  2029. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  2030. phinholing := c.GetString("pinholing")
  2031. catheter_suture := c.GetString("catheter_suture")
  2032. catheter_suture_other := c.GetString("catheter_suture_other")
  2033. edema := c.GetString("edema")
  2034. urine_volume, _ := c.GetFloat("urine_volume", 0)
  2035. special_treatment := c.GetString("special_treatment")
  2036. catheter_maintenance := c.GetString("catheter_maintenance")
  2037. thrombusType := c.GetString("thromubus_type")
  2038. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  2039. thrombus_a := c.GetString("thromubus_a")
  2040. thrombus_av := c.GetString("thrombus_av")
  2041. thrombus_v := c.GetString("thromubus_v")
  2042. dehydration := c.GetString("dehydration")
  2043. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  2044. period, _ := c.GetInt64("period")
  2045. estimated_food_intake := c.GetString("estimated_food_intake")
  2046. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  2047. urea_befor := c.GetString("urea_befor")
  2048. suction := c.GetString("suction")
  2049. weight_befor_remake := c.GetString("weight_befor_remake")
  2050. height := c.GetString("height")
  2051. age := c.GetString("age")
  2052. his_department := c.GetString("his_department")
  2053. his_bed := c.GetString("his_bed")
  2054. point_puncture := c.GetString("point_puncture")
  2055. catheter_evaluation_program := c.GetString("catheter_evaluation_program")
  2056. skin_site_catheterization := c.GetString("skin_site_catheterization")
  2057. pathway_formation_time := c.GetString("pathway_formation_time")
  2058. timeLayout := "2006-01-02"
  2059. loc, _ := time.LoadLocation("Local")
  2060. var startTime int64
  2061. if len(pathway_formation_time) > 0 {
  2062. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  2063. startTime = theTime.Unix()
  2064. }
  2065. whether_unobstructed, _ := c.GetInt64("whether_unobstructed")
  2066. lien_necessary, _ := c.GetInt64("lien_necessary")
  2067. befor_symptoms := c.GetString("befor_symptoms")
  2068. assessmentBeforeDislysis := models.PredialysisEvaluation{
  2069. DialysisCount: dialysis_count,
  2070. EmergencyTreatment: emergency_treatment,
  2071. EmergencyTreatmentOther: emergency_treatment_other,
  2072. DuctusArantii: ductus_arantii,
  2073. VenousCatheterization: venous_catheterization,
  2074. VenousCatheterizationPart: venous_catheterization_part,
  2075. VenousCatheterizationPartOther: venous_catheterization_part_other,
  2076. PunctureWay: puncture_way,
  2077. BloodAccessInternalFistula: blood_access_internal_fistula,
  2078. BloodAccessNoise: blood_access_noise,
  2079. InternalFistulaOther: internal_fistula_other,
  2080. Evaluator: adminUserInfo.AdminUser.Id,
  2081. UserOrgId: adminUserInfo.CurrentOrgId,
  2082. PatientId: patient,
  2083. AssessmentDate: recordDate.Unix(),
  2084. Temperature: temperature,
  2085. PulseFrequency: pulse_frequency,
  2086. SystolicBloodPressure: systolic_blood_pressure,
  2087. DiastolicBloodPressure: diastolic_blood_pressure,
  2088. WeightBefore: weight_before,
  2089. DryWeight: dry_weight,
  2090. AdditionalWeight: additional_weight,
  2091. DialysisInterphase: dialysis_interphase,
  2092. LastPostDialysis: last_post_dialysis,
  2093. SymptomBeforeDialysis: symptom_before_dialysis,
  2094. InternalFistula: internalFistula,
  2095. InternalFistulaSkin: internal_fistula_skin,
  2096. Catheter: catheter,
  2097. CatheterBend: catheter_bend,
  2098. Complication: complication,
  2099. CreatedTime: time.Now().Unix(),
  2100. Status: 1,
  2101. Remark: remark,
  2102. IsHemorrhage: is_hemorrhage,
  2103. Hemorrhage: hemorrhage,
  2104. HemorrhageOther: hemorrhage_other,
  2105. BloodAccessPartId: bloodAccessPartId,
  2106. BloodAccessPartOperaId: bloodAccessPartOperaId,
  2107. PunctureMethod: puncture_method,
  2108. BreathingRate: breathing_rate,
  2109. IsInfect: is_infect,
  2110. Exposed: exposed,
  2111. Skin: skin,
  2112. SkinOther: skin_other,
  2113. InfectOther: infect_other,
  2114. DuctusArantiiOther: ductus_arantii_other,
  2115. MachineType: machine_type,
  2116. PunctureNeedle: puncture_needle,
  2117. HumorExcessiveSymptom: humor_excessive_symptom,
  2118. Phinholing: phinholing,
  2119. CatheterSuture: catheter_suture,
  2120. CatheterSutureOther: catheter_suture_other,
  2121. Edema: edema,
  2122. UrineVolume: urine_volume,
  2123. SpecialTreatment: special_treatment,
  2124. CatheterMaintenance: catheter_maintenance,
  2125. ThromubusType: thrombusInt,
  2126. ThrombusAv: thrombus_av,
  2127. ThromubusA: thrombus_a,
  2128. ThromubusV: thrombus_v,
  2129. Dehydration: dehydration,
  2130. PreDialysisDrugs: pre_dialysis_drugs,
  2131. Period: period,
  2132. EstimatedFoodIntake: estimated_food_intake,
  2133. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  2134. UreaBefor: urea_befor,
  2135. Suction: suction,
  2136. WeightBeforRemake: weight_befor_remake,
  2137. Height: height,
  2138. Age: age,
  2139. HisDepartment: his_department,
  2140. HisBed: his_bed,
  2141. PointPuncture: point_puncture,
  2142. CatheterEvaluationProgram: catheter_evaluation_program,
  2143. SkinSiteCatheterization: skin_site_catheterization,
  2144. PathwayFormationTime: startTime,
  2145. WhetherUnobstructed: whether_unobstructed,
  2146. LienNecessary: lien_necessary,
  2147. BeforSymptoms: befor_symptoms,
  2148. }
  2149. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2150. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2151. if evaluation.ID == 0 { //新增
  2152. if appRole.UserType == 2 || appRole.UserType == 1 {
  2153. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2154. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2155. } else {
  2156. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2157. }
  2158. // 查询信息规挡的设置天数
  2159. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2160. if infor.ID > 0 && infor.WeekDay > 0 {
  2161. var cha_time int64
  2162. timeNowStr := time.Now().Format("2006-01-02")
  2163. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2164. //今日的日期减去设置的日期
  2165. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2166. if cha_time >= recordDate.Unix() {
  2167. //查询审核是否允许
  2168. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  2169. //申请状态不允许的情况 拒绝修改
  2170. if infor.ApplicationStatus != 1 {
  2171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2172. return
  2173. }
  2174. }
  2175. }
  2176. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  2177. //记录日志
  2178. byterequest, _ := json.Marshal(assessmentBeforeDislysis)
  2179. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2180. UserOrgId: assessmentBeforeDislysis.UserOrgId,
  2181. AdminUserId: adminUserInfo.AdminUser.Id,
  2182. ErrLog: string(byterequest),
  2183. PatientId: assessmentBeforeDislysis.PatientId,
  2184. RecordDate: assessmentBeforeDislysis.AssessmentDate,
  2185. Ctime: time.Now().Unix(),
  2186. Mtime: 0,
  2187. Status: 1,
  2188. Source: "电脑端保存透前评估",
  2189. }
  2190. service.CreateBeforLog(beforeDislysisLog)
  2191. //创建步骤表
  2192. finish := models.XtDialysisFinish{
  2193. IsFinish: 1,
  2194. UserOrgId: adminUserInfo.CurrentOrgId,
  2195. Status: 1,
  2196. Ctime: time.Now().Unix(),
  2197. Mtime: 0,
  2198. Module: 3,
  2199. RecordDate: recordDate.Unix(),
  2200. Sourse: 1,
  2201. PatientId: patient,
  2202. }
  2203. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2204. if dialysisFinish.ID == 0 {
  2205. service.CreateDialysisFinish(finish)
  2206. }
  2207. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 {
  2208. var dewater_amount float64
  2209. dewater_amount = 0
  2210. if dry_weight > 0 {
  2211. dewater_amount = weight_before - dry_weight - additional_weight
  2212. dewater_amount = dewater_amount * 1000
  2213. if dewater_amount <= 0 {
  2214. dewater_amount = 0
  2215. }
  2216. } else {
  2217. dewater_amount = 0
  2218. }
  2219. // 计算透析处方的相关超滤量
  2220. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2221. var lastDialysisPrescribe *models.DialysisPrescription
  2222. var dialysisSolution *models.DialysisSolution
  2223. var dialysisPrescribe *models.DialysisPrescription
  2224. var mode_id int64
  2225. if schedual != nil {
  2226. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2227. if dialysisPrescribe == nil {
  2228. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2229. }
  2230. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2231. // 获取透析模版
  2232. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2233. mode_id = schedual.ModeId
  2234. } else {
  2235. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2236. // 获取透析模版
  2237. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2238. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2239. if dialysisPrescribe == nil && dialysisSolution != nil {
  2240. mode_id = dialysisSolution.ModeId
  2241. }
  2242. if dialysisPrescribe == nil && dialysisSolution == nil {
  2243. mode_id = 0
  2244. }
  2245. }
  2246. // 插入透析处方
  2247. if dialysisPrescribe == nil && dialysisSolution != nil {
  2248. var newprescribe models.DialysisPrescription
  2249. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2250. newprescribe.PatientId = dialysisSolution.PatientId
  2251. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2252. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2253. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2254. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2255. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2256. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2257. newprescribe.ModeId = dialysisSolution.ModeId
  2258. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2259. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2260. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2261. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2262. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2263. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2264. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2265. newprescribe.Glucose = dialysisSolution.Glucose
  2266. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2267. newprescribe.Kalium = dialysisSolution.Kalium
  2268. newprescribe.Sodium = dialysisSolution.Sodium
  2269. newprescribe.Calcium = dialysisSolution.Calcium
  2270. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2271. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2272. newprescribe.Conductivity = dialysisSolution.Conductivity
  2273. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2274. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2275. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2276. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2277. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2278. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2279. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2280. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2281. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2282. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2283. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2284. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2285. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2286. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2287. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2288. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2289. newprescribe.CreatedTime = time.Now().Unix()
  2290. newprescribe.UpdatedTime = time.Now().Unix()
  2291. newprescribe.RecordDate = recordDate.Unix()
  2292. newprescribe.DewaterAmount = dewater_amount
  2293. newprescribe.TargetUltrafiltration = dewater_amount
  2294. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2295. newprescribe.Status = 1
  2296. err := service.AddSigleRecord(&newprescribe)
  2297. //记录日志
  2298. byterequest, _ := json.Marshal(newprescribe)
  2299. prescriptionLog := models.XtDialysisPrescriptionLog{
  2300. UserOrgId: newprescribe.UserOrgId,
  2301. Ctime: time.Now().Unix(),
  2302. Mtime: 0,
  2303. ErrLog: string(byterequest),
  2304. AdminUserId: adminUserInfo.AdminUser.Id,
  2305. RecordDate: newprescribe.RecordDate,
  2306. PatientId: newprescribe.PatientId,
  2307. Source: "电脑端透前评估保存",
  2308. Status: 1,
  2309. }
  2310. service.CreatePrescriptionLog(prescriptionLog)
  2311. if err != nil {
  2312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2313. }
  2314. }
  2315. if dialysisPrescribe == nil && dialysisSolution == nil {
  2316. if lastDialysisPrescribe != nil {
  2317. var newprescribe models.DialysisPrescription
  2318. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2319. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2320. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2321. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2322. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2323. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2324. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2325. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2326. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2327. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2328. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2329. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2330. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2331. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2332. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2333. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2334. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2335. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2336. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2337. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2338. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2339. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2340. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2341. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2342. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2343. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2344. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2345. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2346. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2347. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2348. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2349. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2350. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2351. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2352. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2353. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2354. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2355. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2356. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2357. newprescribe.CreatedTime = time.Now().Unix()
  2358. newprescribe.UpdatedTime = time.Now().Unix()
  2359. newprescribe.RecordDate = recordDate.Unix()
  2360. newprescribe.DewaterAmount = dewater_amount
  2361. newprescribe.TargetUltrafiltration = dewater_amount
  2362. newprescribe.Status = 1
  2363. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2364. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2365. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2366. err := service.AddSigleRecord(&newprescribe)
  2367. //记录日志
  2368. byterequest, _ := json.Marshal(newprescribe)
  2369. prescriptionLog := models.XtDialysisPrescriptionLog{
  2370. UserOrgId: newprescribe.UserOrgId,
  2371. Ctime: time.Now().Unix(),
  2372. Mtime: 0,
  2373. ErrLog: string(byterequest),
  2374. AdminUserId: adminUserInfo.AdminUser.Id,
  2375. RecordDate: newprescribe.RecordDate,
  2376. PatientId: newprescribe.PatientId,
  2377. Source: "电脑端透前评估保存",
  2378. Status: 1,
  2379. }
  2380. service.CreatePrescriptionLog(prescriptionLog)
  2381. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2382. redis := service.RedisClient()
  2383. defer redis.Close()
  2384. //清空key 值
  2385. redis.Set(key, "", time.Second)
  2386. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2387. redis.Set(keyOne, "", time.Second)
  2388. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2389. redis.Set(keyThree, "", time.Second)
  2390. if err != nil {
  2391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2392. }
  2393. } else {
  2394. var newprescribe models.DialysisPrescription
  2395. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2396. newprescribe.PatientId = patient
  2397. newprescribe.ModeId = mode_id
  2398. newprescribe.CreatedTime = time.Now().Unix()
  2399. newprescribe.UpdatedTime = time.Now().Unix()
  2400. newprescribe.RecordDate = recordDate.Unix()
  2401. newprescribe.DewaterAmount = dewater_amount
  2402. newprescribe.TargetUltrafiltration = dewater_amount
  2403. newprescribe.Status = 1
  2404. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2405. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2406. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  2407. err := service.AddSigleRecord(&newprescribe)
  2408. //记录日志
  2409. byterequest, _ := json.Marshal(newprescribe)
  2410. prescriptionLog := models.XtDialysisPrescriptionLog{
  2411. UserOrgId: newprescribe.UserOrgId,
  2412. Ctime: time.Now().Unix(),
  2413. Mtime: 0,
  2414. ErrLog: string(byterequest),
  2415. AdminUserId: adminUserInfo.AdminUser.Id,
  2416. RecordDate: newprescribe.RecordDate,
  2417. PatientId: newprescribe.PatientId,
  2418. Source: "电脑端透前评估保存",
  2419. Status: 1,
  2420. }
  2421. service.CreatePrescriptionLog(prescriptionLog)
  2422. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2423. redis := service.RedisClient()
  2424. defer redis.Close()
  2425. //清空key 值
  2426. redis.Set(key, "", time.Second)
  2427. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2428. redis.Set(keyOne, "", time.Second)
  2429. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2430. redis.Set(keyThree, "", time.Second)
  2431. if err != nil {
  2432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2433. }
  2434. }
  2435. }
  2436. }
  2437. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2438. redis := service.RedisClient()
  2439. //清空key 值
  2440. redis.Set(key, "", time.Second)
  2441. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2442. redis.Set(keyOne, "", time.Second)
  2443. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2444. redis.Set(keyTwo, "", time.Second)
  2445. defer redis.Close()
  2446. if err == nil {
  2447. c.ServeSuccessJSON(map[string]interface{}{
  2448. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2449. })
  2450. } else {
  2451. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2453. }
  2454. } else { //修改
  2455. //if appRole.UserType == 3 {
  2456. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2457. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2458. // if getPermissionErr != nil {
  2459. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2460. // return
  2461. // } else if headNursePermission == nil {
  2462. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2463. // return
  2464. // }
  2465. // }
  2466. //}
  2467. if appRole.UserType == 2 || appRole.UserType == 1 {
  2468. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2469. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2470. } else {
  2471. if evaluation.Creater == 0 {
  2472. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2473. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2474. } else {
  2475. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2476. }
  2477. }
  2478. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2479. assessmentBeforeDislysis.ID = evaluation.ID
  2480. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2481. //
  2482. //新增逻辑
  2483. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2484. var dewater_amount float64
  2485. dewater_amount = 0
  2486. if evaluation.DryWeight > 0 {
  2487. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2488. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  2489. dewater_amount = dewater_amount * 1000
  2490. }
  2491. if dewater_amount <= 0 {
  2492. dewater_amount = 0
  2493. }
  2494. } else {
  2495. dewater_amount = 0
  2496. }
  2497. // 计算透析处方的相关超滤量
  2498. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2499. var lastDialysisPrescribe *models.DialysisPrescription
  2500. var dialysisSolution *models.DialysisSolution
  2501. var dialysisPrescribe *models.DialysisPrescription
  2502. var mode_id int64
  2503. if schedual != nil {
  2504. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2505. if dialysisPrescribe == nil {
  2506. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2507. }
  2508. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2509. // 获取透析模版
  2510. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2511. mode_id = schedual.ModeId
  2512. } else {
  2513. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2514. // 获取透析模版
  2515. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2516. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2517. if dialysisPrescribe == nil && dialysisSolution != nil {
  2518. mode_id = dialysisSolution.ModeId
  2519. }
  2520. if dialysisPrescribe == nil && dialysisSolution == nil {
  2521. mode_id = 0
  2522. }
  2523. }
  2524. // 插入透析处方
  2525. if dialysisPrescribe == nil && dialysisSolution != nil {
  2526. var newprescribe models.DialysisPrescription
  2527. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2528. newprescribe.PatientId = dialysisSolution.PatientId
  2529. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2530. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2531. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2532. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2533. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2534. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2535. newprescribe.ModeId = dialysisSolution.ModeId
  2536. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2537. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2538. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2539. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2540. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2541. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2542. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2543. newprescribe.Glucose = dialysisSolution.Glucose
  2544. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2545. newprescribe.Kalium = dialysisSolution.Kalium
  2546. newprescribe.Sodium = dialysisSolution.Sodium
  2547. newprescribe.Calcium = dialysisSolution.Calcium
  2548. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2549. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2550. newprescribe.Conductivity = dialysisSolution.Conductivity
  2551. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2552. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2553. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2554. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2555. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2556. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2557. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2558. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2559. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2560. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2561. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2562. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2563. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2564. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2565. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2566. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2567. newprescribe.CreatedTime = time.Now().Unix()
  2568. newprescribe.UpdatedTime = time.Now().Unix()
  2569. newprescribe.RecordDate = recordDate.Unix()
  2570. newprescribe.DewaterAmount = dewater_amount
  2571. newprescribe.TargetUltrafiltration = dewater_amount
  2572. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2573. newprescribe.Status = 1
  2574. err := service.AddSigleRecord(&newprescribe)
  2575. //记录日志
  2576. byterequest, _ := json.Marshal(newprescribe)
  2577. prescriptionLog := models.XtDialysisPrescriptionLog{
  2578. UserOrgId: newprescribe.UserOrgId,
  2579. Ctime: time.Now().Unix(),
  2580. Mtime: 0,
  2581. ErrLog: string(byterequest),
  2582. AdminUserId: adminUserInfo.AdminUser.Id,
  2583. RecordDate: newprescribe.RecordDate,
  2584. PatientId: newprescribe.PatientId,
  2585. Source: "电脑端透前评估保存",
  2586. Status: 1,
  2587. }
  2588. service.CreatePrescriptionLog(prescriptionLog)
  2589. if err != nil {
  2590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2591. }
  2592. }
  2593. if dialysisPrescribe == nil && dialysisSolution == nil {
  2594. if lastDialysisPrescribe != nil {
  2595. var newprescribe models.DialysisPrescription
  2596. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2597. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2598. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2599. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2600. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2601. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2602. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2603. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2604. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2605. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2606. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2607. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2608. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2609. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2610. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2611. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2612. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2613. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2614. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2615. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2616. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2617. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2618. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2619. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2620. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2621. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2622. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2623. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2624. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2625. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2626. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2627. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2628. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2629. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2630. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2631. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2632. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2633. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2634. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2635. newprescribe.CreatedTime = time.Now().Unix()
  2636. newprescribe.UpdatedTime = time.Now().Unix()
  2637. newprescribe.RecordDate = recordDate.Unix()
  2638. newprescribe.DewaterAmount = dewater_amount
  2639. newprescribe.TargetUltrafiltration = dewater_amount
  2640. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2641. newprescribe.Status = 1
  2642. err := service.AddSigleRecord(&newprescribe)
  2643. //记录日志
  2644. byterequest, _ := json.Marshal(newprescribe)
  2645. prescriptionLog := models.XtDialysisPrescriptionLog{
  2646. UserOrgId: newprescribe.UserOrgId,
  2647. Ctime: time.Now().Unix(),
  2648. Mtime: 0,
  2649. ErrLog: string(byterequest),
  2650. AdminUserId: adminUserInfo.AdminUser.Id,
  2651. RecordDate: newprescribe.RecordDate,
  2652. PatientId: newprescribe.PatientId,
  2653. Source: "电脑端透前评估保存",
  2654. Status: 1,
  2655. }
  2656. service.CreatePrescriptionLog(prescriptionLog)
  2657. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2658. redis := service.RedisClient()
  2659. defer redis.Close()
  2660. //清空key 值
  2661. redis.Set(key, "", time.Second)
  2662. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2663. redis.Set(keyOne, "", time.Second)
  2664. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2665. redis.Set(keyThree, "", time.Second)
  2666. if err != nil {
  2667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2668. }
  2669. } else {
  2670. var newprescribe models.DialysisPrescription
  2671. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2672. newprescribe.PatientId = patient
  2673. newprescribe.ModeId = mode_id
  2674. newprescribe.CreatedTime = time.Now().Unix()
  2675. newprescribe.UpdatedTime = time.Now().Unix()
  2676. newprescribe.RecordDate = recordDate.Unix()
  2677. newprescribe.DewaterAmount = dewater_amount
  2678. newprescribe.TargetUltrafiltration = dewater_amount
  2679. newprescribe.Status = 1
  2680. err := service.AddSigleRecord(&newprescribe)
  2681. //记录日志
  2682. byterequest, _ := json.Marshal(newprescribe)
  2683. prescriptionLog := models.XtDialysisPrescriptionLog{
  2684. UserOrgId: newprescribe.UserOrgId,
  2685. Ctime: time.Now().Unix(),
  2686. Mtime: 0,
  2687. ErrLog: string(byterequest),
  2688. AdminUserId: adminUserInfo.AdminUser.Id,
  2689. RecordDate: newprescribe.RecordDate,
  2690. PatientId: newprescribe.PatientId,
  2691. Source: "电脑端透前评估保存",
  2692. Status: 1,
  2693. }
  2694. service.CreatePrescriptionLog(prescriptionLog)
  2695. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2696. redis := service.RedisClient()
  2697. defer redis.Close()
  2698. //清空key 值
  2699. redis.Set(key, "", time.Second)
  2700. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2701. redis.Set(keyOne, "", time.Second)
  2702. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2703. redis.Set(keyThree, "", time.Second)
  2704. if err != nil {
  2705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2706. }
  2707. }
  2708. }
  2709. // 查询信息规挡的设置天数
  2710. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2711. if infor.ID > 0 {
  2712. var cha_time int64
  2713. timeNowStr := time.Now().Format("2006-01-02")
  2714. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2715. //今日的日期减去设置的日期
  2716. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2717. if cha_time >= recordDate.Unix() {
  2718. //查询审核是否允许
  2719. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  2720. //申请状态不允许的情况 拒绝修改
  2721. if infor.ApplicationStatus != 1 {
  2722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2723. return
  2724. }
  2725. }
  2726. }
  2727. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2728. //创建步骤表
  2729. finish := models.XtDialysisFinish{
  2730. IsFinish: 1,
  2731. UserOrgId: adminUserInfo.CurrentOrgId,
  2732. Status: 1,
  2733. Ctime: time.Now().Unix(),
  2734. Mtime: 0,
  2735. Module: 3,
  2736. RecordDate: recordDate.Unix(),
  2737. Sourse: 1,
  2738. PatientId: patient,
  2739. }
  2740. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2741. if dialysisFinish.ID == 0 {
  2742. service.CreateDialysisFinish(finish)
  2743. }
  2744. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2745. redis := service.RedisClient()
  2746. //清空key 值
  2747. redis.Set(key, "", time.Second)
  2748. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2749. redis.Set(keyOne, "", time.Second)
  2750. defer redis.Close()
  2751. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2752. redis.Set(keyTwo, "", time.Second)
  2753. if err == nil {
  2754. c.ServeSuccessJSON(map[string]interface{}{
  2755. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2756. })
  2757. } else {
  2758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2759. }
  2760. }
  2761. }
  2762. func (c *DialysisApiController) PostTreatmentSummary() {
  2763. patient, _ := c.GetInt64("patient", 0)
  2764. recordDateStr := c.GetString("record_date")
  2765. if patient <= 0 {
  2766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2767. return
  2768. }
  2769. adminUserInfo := c.GetAdminUserInfo()
  2770. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2771. if patientInfo.ID == 0 {
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2773. return
  2774. }
  2775. if len(recordDateStr) == 0 {
  2776. recordDateStr = time.Now().Format("2006-01-02")
  2777. }
  2778. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2779. if parseDateErr != nil {
  2780. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2782. return
  2783. }
  2784. mission := c.GetString("mission")
  2785. dialysis_summary := c.GetString("dialysis_summary")
  2786. nursingRecord := c.GetString("nursing_record")
  2787. specialRecord := c.GetString("special_record")
  2788. sj_nurse := adminUserInfo.AdminUser.Id
  2789. zl_nurse := adminUserInfo.AdminUser.Id
  2790. hd_nurse := adminUserInfo.AdminUser.Id
  2791. xj_nurse := adminUserInfo.AdminUser.Id
  2792. zl_doctor := adminUserInfo.AdminUser.Id
  2793. treatmentSummary := models.TreatmentSummary{
  2794. UserOrgId: adminUserInfo.CurrentOrgId,
  2795. PatientId: patient,
  2796. AssessmentDate: recordDate.Unix(),
  2797. Mission: mission,
  2798. DialysisSummary: dialysis_summary,
  2799. SjNurse: sj_nurse,
  2800. ZlNurse: zl_nurse,
  2801. HdNurse: hd_nurse,
  2802. XjNurse: xj_nurse,
  2803. ZlDoctor: zl_doctor,
  2804. Status: 1,
  2805. CreatedTime: time.Now().Unix(),
  2806. NursingRecord: nursingRecord,
  2807. SpecialRecord: specialRecord,
  2808. }
  2809. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2810. if tempTreatmentSummary.ID == 0 { //新增
  2811. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2812. // 查询信息规挡的设置天数
  2813. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2814. if infor.ID > 0 && infor.WeekDay > 0 {
  2815. var cha_time int64
  2816. timeNowStr := time.Now().Format("2006-01-02")
  2817. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2818. //今日的日期减去设置的日期
  2819. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2820. if cha_time >= recordDate.Unix() {
  2821. //查询审核是否允许
  2822. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  2823. //申请状态不允许的情况 拒绝修改
  2824. if infor.ApplicationStatus != 1 {
  2825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2826. return
  2827. }
  2828. }
  2829. }
  2830. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2831. finish := models.XtDialysisFinish{
  2832. IsFinish: 1,
  2833. UserOrgId: adminUserInfo.CurrentOrgId,
  2834. Status: 1,
  2835. Ctime: time.Now().Unix(),
  2836. Mtime: 0,
  2837. Module: 10,
  2838. RecordDate: recordDate.Unix(),
  2839. Sourse: 1,
  2840. PatientId: patient,
  2841. }
  2842. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 10, patient)
  2843. if dialysisFinish.ID == 0 {
  2844. service.CreateDialysisFinish(finish)
  2845. }
  2846. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2847. redis := service.RedisClient()
  2848. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2849. redis.Set(keyOne, "", time.Second)
  2850. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2851. redis.Set(keyThree, "", time.Second)
  2852. defer redis.Close()
  2853. //清空key 值
  2854. redis.Set(key, "", time.Second)
  2855. if err == nil {
  2856. c.ServeSuccessJSON(map[string]interface{}{
  2857. "summary": treatmentSummary,
  2858. })
  2859. } else {
  2860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2861. }
  2862. } else { //修改
  2863. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2864. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2865. // if getPermissionErr != nil {
  2866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2867. // return
  2868. // } else if headNursePermission == nil {
  2869. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2870. // return
  2871. // }
  2872. //}
  2873. // 查询信息规挡的设置天数
  2874. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2875. if infor.ID > 0 && infor.WeekDay > 0 {
  2876. var cha_time int64
  2877. timeNowStr := time.Now().Format("2006-01-02")
  2878. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2879. //今日的日期减去设置的日期
  2880. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2881. if cha_time >= recordDate.Unix() {
  2882. //查询审核是否允许
  2883. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  2884. //申请状态不允许的情况 拒绝修改
  2885. if infor.ApplicationStatus != 1 {
  2886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2887. return
  2888. }
  2889. }
  2890. }
  2891. treatmentSummary.Creater = tempTreatmentSummary.Creater
  2892. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  2893. treatmentSummary.UpdatedTime = time.Now().Unix()
  2894. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  2895. treatmentSummary.ID = tempTreatmentSummary.ID
  2896. err := service.UpdateSummeRecord(&treatmentSummary)
  2897. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2898. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2899. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2900. //清空key 值
  2901. redis := service.RedisClient()
  2902. redis.Set(key, "", time.Second)
  2903. redis.Set(keyOne, "", time.Second)
  2904. redis.Set(keyThree, "", time.Second)
  2905. defer redis.Close()
  2906. if err == nil {
  2907. c.ServeSuccessJSON(map[string]interface{}{
  2908. "summary": treatmentSummary,
  2909. })
  2910. } else {
  2911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2912. }
  2913. }
  2914. }
  2915. func (c *DialysisApiController) GetDeviceList() {
  2916. adminUserInfo := c.GetAdminUserInfo()
  2917. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  2918. c.ServeSuccessJSON(map[string]interface{}{
  2919. "device": device,
  2920. })
  2921. }
  2922. func (c *DialysisApiController) GetAllDeviceZone() {
  2923. adminUserInfo := c.GetAdminUserInfo()
  2924. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  2925. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  2926. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  2927. if err == nil {
  2928. c.ServeSuccessJSON(map[string]interface{}{
  2929. "zone": zone,
  2930. "dics": dics,
  2931. "efs": efs,
  2932. })
  2933. }
  2934. }
  2935. func (c *DialysisApiController) GetDialysisWatch() {
  2936. page, _ := c.GetInt64("page", 1)
  2937. limit, _ := c.GetInt64("limit", 10)
  2938. schedulType, _ := c.GetInt64("schedul_type", 0)
  2939. startTime, _ := c.GetInt64("schedul_time", 0)
  2940. partitionType, _ := c.GetInt64("partition_type", 0)
  2941. keywords := c.GetString("keywords")
  2942. start_time, _ := c.GetInt64("start_time")
  2943. end_time, _ := c.GetInt64("end_time")
  2944. adminUserInfo := c.GetAdminUserInfo()
  2945. if len(keywords) > 0 {
  2946. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2947. if err == nil {
  2948. c.ServeSuccessJSON(map[string]interface{}{
  2949. "schedule": dialysisSchedule,
  2950. "total": total,
  2951. })
  2952. } else {
  2953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2954. }
  2955. } else {
  2956. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2957. for _, item := range dialysisSchedule {
  2958. patients, _ := service.GetMonitorPatients(item.PatientId)
  2959. item.MonitorPatients = patients
  2960. orderObj, _ := service.GetMonitorDialysisOrderObj(item.PatientId, item.ScheduleDate)
  2961. item.DialysisOrder = orderObj
  2962. prescription, _ := service.GetMonitorDialysisPrescription(item.PatientId, item.ScheduleDate)
  2963. item.Prescription = prescription
  2964. evaluation, _ := service.GetMonitorPredialysisEvaluation(item.PatientId, item.ScheduleDate)
  2965. item.AssessmentBeforeDislysis = evaluation
  2966. afterdislysis, _ := service.GetMonitorAssessmentAfterDislysis(item.PatientId, item.ScheduleDate)
  2967. item.AssessmentAfterDislysis = afterdislysis
  2968. monitorRecord, _ := service.GetMonitoringRecordList(item.PatientId, item.ScheduleDate)
  2969. item.MonitoringRecord = monitorRecord
  2970. }
  2971. if err == nil {
  2972. c.ServeSuccessJSON(map[string]interface{}{
  2973. "schedule": dialysisSchedule,
  2974. "total": total,
  2975. })
  2976. } else {
  2977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2978. }
  2979. }
  2980. }
  2981. //func (c *DialysisApiController) GetDialysisWatch() {
  2982. // page, _ := c.GetInt64("page", 1)
  2983. // limit, _ := c.GetInt64("limit", 10)
  2984. // schedulType, _ := c.GetInt64("schedul_type", 0)
  2985. // startTime, _ := c.GetInt64("schedul_time", 0)
  2986. // partitionType, _ := c.GetInt64("partition_type", 0)
  2987. // keywords := c.GetString("keywords")
  2988. //
  2989. // adminUserInfo := c.GetAdminUserInfo()
  2990. // if len(keywords) > 0 {
  2991. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  2992. //
  2993. // //获取所有床位号
  2994. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  2995. //
  2996. // //获取透析处方
  2997. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  2998. // //获取透前评估
  2999. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  3000. // //获取上机
  3001. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  3002. // //获取透后
  3003. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  3004. //
  3005. // //获取透后监测
  3006. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  3007. //
  3008. // //获取所有的患者
  3009. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  3010. //
  3011. // //获取所有透析模式
  3012. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  3013. //
  3014. // for key, scheduals := range dialysisSchedule {
  3015. // // 获取患者信息
  3016. // for _, patient := range patients {
  3017. // if scheduals.PatientId == patient.ID {
  3018. // dialysisSchedule[key].MonitorPatients = patient
  3019. // break
  3020. // }
  3021. // }
  3022. // // 床位信息
  3023. // for _, device := range numberList {
  3024. // if scheduals.BedId == device.ID {
  3025. // dialysisSchedule[key].DeviceNumber = device
  3026. // break
  3027. // }
  3028. // }
  3029. //
  3030. // // 医嘱信息
  3031. // for _, prescription := range prescriptions {
  3032. // if scheduals.PatientId == prescription.PatientId {
  3033. // dialysisSchedule[key].Prescription = prescription
  3034. // break
  3035. // }
  3036. // }
  3037. //
  3038. // // 透前评估
  3039. // for _, assessmentBefore := range assessmentBefores {
  3040. // if scheduals.PatientId == assessmentBefore.PatientId {
  3041. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  3042. // break
  3043. // }
  3044. // }
  3045. //
  3046. // // 透析上下机
  3047. // for _, dialysisOrder := range dialysisOrders {
  3048. // if scheduals.PatientId == dialysisOrder.PatientId {
  3049. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  3050. // break
  3051. // }
  3052. // }
  3053. //
  3054. // records := make([]*models.MonitoringRecord, 0)
  3055. // // 透析监测
  3056. // for _, it := range monitorlist {
  3057. // records := append(records, it)
  3058. // if scheduals.PatientId == it.PatientId {
  3059. // dialysisSchedule[key].MonitoringRecord = records
  3060. // }
  3061. // }
  3062. //
  3063. // // 透后评估
  3064. // for _, afterDislysis := range AssessmentAfterDislysis {
  3065. // if scheduals.PatientId == afterDislysis.PatientId {
  3066. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  3067. // break
  3068. // }
  3069. // }
  3070. //
  3071. // //透析模式
  3072. // for _, treatment := range treatments {
  3073. // if scheduals.ModeId == treatment.ID {
  3074. // dialysisSchedule[key].TreatmentMode = treatment
  3075. // break
  3076. // }
  3077. // }
  3078. // }
  3079. // //获取所有床位号
  3080. // if err == nil {
  3081. // c.ServeSuccessJSON(map[string]interface{}{
  3082. // "schedule": dialysisSchedule,
  3083. // "total": total,
  3084. // })
  3085. // } else {
  3086. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3087. // }
  3088. //
  3089. // } else {
  3090. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  3091. // if err == nil {
  3092. // c.ServeSuccessJSON(map[string]interface{}{
  3093. // "schedule": dialysisSchedule,
  3094. // "total": total,
  3095. // })
  3096. // } else {
  3097. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3098. // }
  3099. // }
  3100. //}
  3101. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  3102. patientId, _ := c.GetInt64("id", 0)
  3103. record_date, _ := c.GetInt64("record_date", 0)
  3104. adminUserInfo := c.GetAdminUserInfo()
  3105. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3106. var dialysisStatus int64
  3107. if dialysisOrder == nil { //没有透析记录
  3108. dialysisStatus = 0 //未透析
  3109. } else {
  3110. dialysisStatus = dialysisOrder.Stage
  3111. }
  3112. //用户基本信息
  3113. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3114. //接诊评估
  3115. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3116. //透前评估
  3117. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3118. //临时医嘱
  3119. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3120. //双人核对
  3121. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3122. //透析监测
  3123. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  3124. //透后评估
  3125. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3126. //透析小结
  3127. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3128. //透析处方
  3129. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3130. if dialysisPrescription.ID == 0 {
  3131. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  3132. c.ServeSuccessJSON(map[string]interface{}{
  3133. "patientInfo": schedualPatientInfo,
  3134. "dialysisPrescription": solution,
  3135. "receiverTreatmentAccess": receiverTreatmentAccess,
  3136. "predialysisEvaluation": PredialysisEvaluation,
  3137. "doctorAdvice": DoctorAdvice,
  3138. "doubleCheck": DoubleCheck,
  3139. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3140. "treatmentSummary": TreatmentSummary,
  3141. "monitorRecord": Record,
  3142. "dialysisStatus": dialysisStatus,
  3143. "dialysisOrder": dialysisOrder,
  3144. "isSolution": 1,
  3145. })
  3146. } else {
  3147. c.ServeSuccessJSON(map[string]interface{}{
  3148. "patientInfo": schedualPatientInfo,
  3149. "dialysisPrescription": dialysisPrescription,
  3150. "receiverTreatmentAccess": receiverTreatmentAccess,
  3151. "predialysisEvaluation": PredialysisEvaluation,
  3152. "doctorAdvice": DoctorAdvice,
  3153. "doubleCheck": DoubleCheck,
  3154. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3155. "treatmentSummary": TreatmentSummary,
  3156. "monitorRecord": Record,
  3157. "dialysisStatus": dialysisStatus,
  3158. "dialysisOrder": dialysisOrder,
  3159. "isSolution": 2,
  3160. })
  3161. }
  3162. }
  3163. func (c *DialysisApiController) CreateDoctorAdvice() {
  3164. patient, _ := c.GetInt64("id", 0)
  3165. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  3166. record_date, _ := c.GetInt64("record_date", 0)
  3167. if patient <= 0 {
  3168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3169. return
  3170. }
  3171. adminUserInfo := c.GetAdminUserInfo()
  3172. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3173. if patientInfo.ID == 0 {
  3174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3175. return
  3176. }
  3177. var advice models.DoctorAdvice
  3178. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  3179. if code > 0 {
  3180. c.ServeFailJSONWithSGJErrorCode(code)
  3181. return
  3182. }
  3183. if advice.ParentId > 0 {
  3184. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  3185. if old.ID == 0 || old.PatientId != patient {
  3186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3187. return
  3188. }
  3189. if old.StopState == 1 || old.ExecutionState == 1 {
  3190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3191. return
  3192. }
  3193. if old.ParentId > 0 {
  3194. advice.ParentId = old.ParentId
  3195. }
  3196. advice.StartTime = old.StartTime
  3197. advice.AdviceDoctor = old.AdviceDoctor
  3198. advice.DeliveryWay = old.DeliveryWay
  3199. advice.ExecutionFrequency = old.ExecutionFrequency
  3200. }
  3201. advice.RecordDate = record_date
  3202. advice.DialysisOrderId = dialysis_id
  3203. advice.Status = 1
  3204. advice.CreatedTime = time.Now().Unix()
  3205. advice.UpdatedTime = time.Now().Unix()
  3206. advice.StopState = 2
  3207. advice.ExecutionState = 2
  3208. advice.AdviceType = 2
  3209. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3210. advice.PatientId = patient
  3211. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3212. err := service.CreateDoctorAdvice(&advice)
  3213. if err != nil {
  3214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3215. return
  3216. }
  3217. for _, subAdvice := range subAdivice {
  3218. subAdvice.ParentId = advice.ID
  3219. subAdvice.PatientId = patient
  3220. subAdvice.RecordDate = record_date
  3221. subAdvice.CreatedTime = time.Now().Unix()
  3222. subAdvice.UpdatedTime = time.Now().Unix()
  3223. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3224. }
  3225. service.CreateSubDoctorAdvice(subAdivice)
  3226. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3227. c.ServeSuccessJSON(map[string]interface{}{
  3228. "msg": "ok",
  3229. "advice": advice,
  3230. "subAdvice": subAdivices,
  3231. })
  3232. return
  3233. }
  3234. func (c *DialysisApiController) EditDoctorAdvice() {
  3235. patient, _ := c.GetInt64("patient", 0)
  3236. id, _ := c.GetInt64("id", 0)
  3237. parent_id, _ := c.GetInt64("parent_id", 0)
  3238. execution_time := c.GetString("execution_time")
  3239. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3240. // checker, _ := c.GetInt64("checker", 0)
  3241. if id <= 0 || patient <= 0 {
  3242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3243. return
  3244. }
  3245. adminUserInfo := c.GetAdminUserInfo()
  3246. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3247. if advice.ID == 0 || advice.PatientId != patient {
  3248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3249. return
  3250. }
  3251. if len(execution_time) <= 0 {
  3252. utils.ErrorLog("execution_time")
  3253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3254. return
  3255. }
  3256. execution_staff := adminUserInfo.AdminUser.Id
  3257. checker := adminUserInfo.AdminUser.Id
  3258. timeLayout2 := "2006-01-02 15:04"
  3259. loc, _ := time.LoadLocation("Local")
  3260. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3261. if errs != nil {
  3262. utils.ErrorLog(errs.Error())
  3263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3264. return
  3265. }
  3266. advices := models.DoctorAdvice{
  3267. ExecutionStaff: execution_staff,
  3268. ExecutionTime: theTime.Unix(),
  3269. Checker: checker,
  3270. UpdatedTime: time.Now().Unix(),
  3271. }
  3272. var err error
  3273. if parent_id > 0 {
  3274. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3275. } else {
  3276. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3277. }
  3278. if err != nil {
  3279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3280. return
  3281. }
  3282. c.ServeSuccessJSON(map[string]interface{}{
  3283. "msg": "ok",
  3284. "advice": advice,
  3285. })
  3286. return
  3287. }
  3288. func (c *DialysisApiController) GetDoctorAdvice() {
  3289. patient, _ := c.GetInt64("patient_id", 0)
  3290. parent_id, _ := c.GetInt64("parent_id", 0)
  3291. adviceId, _ := c.GetInt64("id", 0)
  3292. if patient <= 0 {
  3293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3294. return
  3295. }
  3296. dminUserInfo := c.GetAdminUserInfo()
  3297. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3298. if patientInfo.ID == 0 {
  3299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3300. return
  3301. }
  3302. var subAdvice []*models.DoctorAdvice
  3303. var advice models.DoctorAdvice
  3304. if parent_id > 0 {
  3305. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3306. if advice.ID == 0 || advice.PatientId != patient {
  3307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3308. return
  3309. }
  3310. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3311. } else {
  3312. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3313. if advice.ID == 0 || advice.PatientId != patient {
  3314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3315. return
  3316. }
  3317. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3318. }
  3319. c.ServeSuccessJSON(map[string]interface{}{
  3320. "msg": "ok",
  3321. "advice": advice,
  3322. "subAdvice": subAdvice,
  3323. })
  3324. }
  3325. func (this *DialysisApiController) DelMonitor() {
  3326. recordID, _ := this.GetInt64("record_id")
  3327. patientID, _ := this.GetInt64("patient_id")
  3328. if recordID <= 0 || patientID <= 0 {
  3329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3330. return
  3331. }
  3332. adminInfo := this.GetAdminUserInfo()
  3333. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3334. if getPatientErr != nil {
  3335. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3337. return
  3338. } else if patient == nil {
  3339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3340. return
  3341. }
  3342. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3343. if getMonitorErr != nil {
  3344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3345. return
  3346. }
  3347. //if monitor != nil {
  3348. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3349. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3350. // if getPermissionErr != nil {
  3351. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3352. // return
  3353. // } else if headNursePermission == nil {
  3354. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3355. // return
  3356. // }
  3357. // }
  3358. //}
  3359. // 查询信息规挡的设置天数
  3360. infor, _ := service.GetDialysisInformationSetting(adminInfo.CurrentOrgId)
  3361. if infor.ID > 0 && infor.WeekDay > 0 {
  3362. var cha_time int64
  3363. timeNowStr := time.Now().Format("2006-01-02")
  3364. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3365. //今日的日期减去设置的日期
  3366. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3367. if cha_time >= monitor.MonitoringDate {
  3368. //查询审核是否允许
  3369. infor, _ := service.GetDialysisInformationByRecordDate(patientID, monitor.MonitoringDate, adminInfo.CurrentOrgId, 7)
  3370. //申请状态不允许的情况 拒绝修改
  3371. if infor.ApplicationStatus != 1 {
  3372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3373. return
  3374. }
  3375. }
  3376. }
  3377. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  3378. //记录日志
  3379. byterequest, _ := json.Marshal(monitor)
  3380. monitorRecordLog := models.XtMonitorRecordLog{
  3381. RecordDate: monitor.MonitoringDate,
  3382. PatientId: monitor.PatientId,
  3383. Module: 3,
  3384. AdminUserId: adminInfo.AdminUser.Id,
  3385. Ctime: time.Now().Unix(),
  3386. Mtime: 0,
  3387. Status: 1,
  3388. UserOrgId: monitor.UserOrgId,
  3389. ErrLog: string(byterequest),
  3390. Source: "电脑端删除监测",
  3391. }
  3392. service.CreateMonitorRecordLog(monitorRecordLog)
  3393. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  3394. redis := service.RedisClient()
  3395. //清空key 值
  3396. redis.Set(key, "", time.Second)
  3397. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  3398. redis.Set(keyOne, "", time.Second)
  3399. defer redis.Close()
  3400. if err != nil {
  3401. this.ErrorLog("删除透析监测记录失败:%v", err)
  3402. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3403. return
  3404. }
  3405. this.ServeSuccessJSON(map[string]interface{}{
  3406. "record_id": monitor.ID,
  3407. })
  3408. }
  3409. func (c *DialysisApiController) CreateMonitor() {
  3410. patient, _ := c.GetInt64("id", 0)
  3411. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3412. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3413. operate_time, _ := c.GetInt64("operate_time", 0)
  3414. // monitoring_time := c.GetString("monitoring_time")
  3415. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3416. breathing_rated := c.GetString("breathing_rated")
  3417. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3418. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3419. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3420. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3421. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3422. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  3423. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3424. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  3425. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3426. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3427. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3428. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3429. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  3430. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3431. temperature, _ := c.GetFloat("temperature", 0)
  3432. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3433. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3434. conductivity, _ := c.GetFloat("conductivity", 0)
  3435. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3436. heparin, _ := c.GetFloat("heparin", 0)
  3437. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3438. ktv, _ := c.GetFloat("ktv", 0)
  3439. symptom := c.GetString("symptom")
  3440. dispose := c.GetString("dispose")
  3441. result := c.GetString("results")
  3442. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3443. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  3444. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  3445. replacement_speed, _ := c.GetFloat("replacement_speed")
  3446. dicarbonate, _ := c.GetFloat("dicarbonate")
  3447. monitoring_date = monitoring_date / 1000
  3448. // operate_time = operate_time / 1000
  3449. if patient <= 0 {
  3450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3451. return
  3452. }
  3453. adminUserInfo := c.GetAdminUserInfo()
  3454. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3455. if patientInfo.ID == 0 {
  3456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3457. return
  3458. }
  3459. monitorRecord := models.MonitoringRecord{
  3460. PatientId: patient,
  3461. MonitoringDate: monitoring_date,
  3462. DialysisOrderId: dialysis_order_id,
  3463. OperateTime: operate_time,
  3464. // MonitoringTime: monitoring_time,
  3465. PulseFrequency: pulse_frequency,
  3466. BreathingRate: breathing_rated,
  3467. SystolicBloodPressure: systolic_blood_pressure,
  3468. DiastolicBloodPressure: diastolic_blood_pressure,
  3469. BloodPressureType: blood_pressure_type,
  3470. BloodFlowVolume: blood_flow_volume,
  3471. VenousPressure: venous_pressure,
  3472. VenousPressureType: venous_pressure_type,
  3473. TransmembranePressure: transmembrane_pressure,
  3474. TransmembranePressureType: transmembrane_pressure_type,
  3475. UltrafiltrationRate: ultrafiltration_rate,
  3476. UltrafiltrationVolume: ultrafiltration_volume,
  3477. SodiumConcentration: sodium_concentration,
  3478. ArterialPressure: arterial_pressure,
  3479. ArterialPressureType: arterial_pressure_type,
  3480. DialysateTemperature: dialysate_temperature,
  3481. Temperature: temperature,
  3482. ReplacementRate: replacement_rate,
  3483. DisplacementQuantity: displacement_quantity,
  3484. Ktv: ktv,
  3485. Symptom: symptom,
  3486. Dispose: dispose,
  3487. Result: result,
  3488. MonitoringNurse: monitoring_nurse,
  3489. Status: 1,
  3490. CreatedTime: time.Now().Unix(),
  3491. UpdatedTime: time.Now().Unix(),
  3492. UserOrgId: adminUserInfo.CurrentOrgId,
  3493. Conductivity: conductivity,
  3494. DisplacementFlowQuantity: displacement_flow_quantity,
  3495. Heparin: heparin,
  3496. DialysateFlow: dialysate_flow,
  3497. MonitorAnticoagulant: monitor_anticoagulant,
  3498. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  3499. ReplacementSpeed: replacement_speed,
  3500. Dicarbonate: dicarbonate,
  3501. }
  3502. // 查询信息规挡的设置天数
  3503. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3504. if infor.ID > 0 && infor.WeekDay > 0 {
  3505. var cha_time int64
  3506. timeNowStr := time.Now().Format("2006-01-02")
  3507. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3508. //今日的日期减去设置的日期
  3509. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3510. if cha_time >= monitoring_date {
  3511. //查询审核是否允许
  3512. infor, _ := service.GetDialysisInformationByRecordDate(patient, monitoring_date, adminUserInfo.CurrentOrgId, 7)
  3513. //申请状态不允许的情况 拒绝修改
  3514. if infor.ApplicationStatus != 1 {
  3515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3516. return
  3517. }
  3518. }
  3519. }
  3520. err := service.CreateMonitor(&monitorRecord)
  3521. finish := models.XtDialysisFinish{
  3522. IsFinish: 1,
  3523. UserOrgId: adminUserInfo.CurrentOrgId,
  3524. Status: 1,
  3525. Ctime: time.Now().Unix(),
  3526. Mtime: 0,
  3527. Module: 7,
  3528. RecordDate: monitoring_date,
  3529. Sourse: 1,
  3530. PatientId: patient,
  3531. }
  3532. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, monitoring_date, 7, patient)
  3533. if dialysisFinish.ID == 0 {
  3534. service.CreateDialysisFinish(finish)
  3535. }
  3536. redis := service.RedisClient()
  3537. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  3538. redis.Set(key, "", time.Second)
  3539. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  3540. redis.Set(keyOne, "", time.Second)
  3541. redis.Close()
  3542. if err != nil {
  3543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3544. return
  3545. }
  3546. c.ServeSuccessJSON(map[string]interface{}{
  3547. "msg": "ok",
  3548. "monitor": monitorRecord,
  3549. })
  3550. return
  3551. }
  3552. // 已弃用
  3553. // func (c *DialysisApiController) CreateRecordData() {
  3554. // patient, _ := c.GetInt64("id", 0)
  3555. // status, _ := c.GetInt64("status", 0)
  3556. // now := time.Now()
  3557. // year, month, day := now.Date()
  3558. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3559. // todayTimeStamp := today_time.Unix()
  3560. // if patient <= 0 {
  3561. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3562. // return
  3563. // }
  3564. // adminUserInfo := c.GetAdminUserInfo()
  3565. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3566. // if patientInfo.ID == 0 {
  3567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3568. // return
  3569. // }
  3570. // record := &models.DialysisOrder{
  3571. // DialysisDate: todayTimeStamp,
  3572. // UserOrgId: adminUserInfo.CurrentOrgId,
  3573. // PatientId: patient,
  3574. // Stage: status,
  3575. // Status: 1,
  3576. // CreatedTime: time.Now().Unix(),
  3577. // UpdatedTime: time.Now().Unix(),
  3578. // }
  3579. // if status == 1 {
  3580. // //创建透析记录
  3581. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3582. // if err == nil {
  3583. // c.ServeSuccessJSON(map[string]interface{}{
  3584. // "dialysisOrder": record,
  3585. // })
  3586. // } else {
  3587. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3588. // }
  3589. // } else {
  3590. // record_id, _ := c.GetInt64("record_id", 0)
  3591. // //修改透析记录状态
  3592. // errs := service.ModifyDialysisRecord(record_id)
  3593. // //结束时候透析次数加1
  3594. // service.UpdateSolutionByPatientId(patient)
  3595. // if errs == nil {
  3596. // c.ServeSuccessJSON(map[string]interface{}{
  3597. // "dialysisOrder": record,
  3598. // })
  3599. // } else {
  3600. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3601. // }
  3602. // }
  3603. // }
  3604. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  3605. dataBody := make(map[string]interface{}, 0)
  3606. err := json.Unmarshal(data, &dataBody)
  3607. if err != nil {
  3608. utils.ErrorLog(err.Error())
  3609. code = enums.ErrorCodeParamWrong
  3610. return
  3611. }
  3612. timeLayout := "2006-01-02 "
  3613. timeLayout2 := "2006-01-02 15:04"
  3614. loc, _ := time.LoadLocation("Local")
  3615. if action == "create" {
  3616. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3617. utils.ErrorLog("advice_type")
  3618. code = enums.ErrorCodeParamWrong
  3619. return
  3620. }
  3621. adviceType := int64(dataBody["advice_type"].(float64))
  3622. if adviceType != 1 && adviceType != 2 {
  3623. utils.ErrorLog("advice_type != 1&&2")
  3624. code = enums.ErrorCodeParamWrong
  3625. return
  3626. }
  3627. advice.AdviceType = adviceType
  3628. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3629. utils.ErrorLog("advice_date")
  3630. code = enums.ErrorCodeParamWrong
  3631. return
  3632. }
  3633. adviceDate, _ := dataBody["advice_date"].(string)
  3634. if len(adviceDate) == 0 {
  3635. utils.ErrorLog("len(adviceDate) == 0")
  3636. code = enums.ErrorCodeParamWrong
  3637. return
  3638. }
  3639. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3640. if err != nil {
  3641. utils.ErrorLog(err.Error())
  3642. code = enums.ErrorCodeParamWrong
  3643. return
  3644. }
  3645. advice.AdviceDate = theTime.Unix()
  3646. }
  3647. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3648. utils.ErrorLog("start_time")
  3649. code = enums.ErrorCodeParamWrong
  3650. return
  3651. }
  3652. startDate, _ := dataBody["start_time"].(string)
  3653. if len(startDate) == 0 {
  3654. utils.ErrorLog("len(startDate) == 0")
  3655. code = enums.ErrorCodeParamWrong
  3656. return
  3657. }
  3658. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  3659. if err != nil {
  3660. utils.ErrorLog(err.Error())
  3661. code = enums.ErrorCodeParamWrong
  3662. return
  3663. }
  3664. advice.StartTime = theTime.Unix()
  3665. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3666. utils.ErrorLog("advice_name")
  3667. code = enums.ErrorCodeParamWrong
  3668. return
  3669. }
  3670. adviceName, _ := dataBody["advice_name"].(string)
  3671. if len(adviceName) == 0 {
  3672. utils.ErrorLog("len(advice_name) == 0")
  3673. code = enums.ErrorCodeParamWrong
  3674. return
  3675. }
  3676. advice.AdviceName = adviceName
  3677. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  3678. utils.ErrorLog("delivery_way")
  3679. code = enums.ErrorCodeParamWrong
  3680. return
  3681. }
  3682. deliveryWay, _ := dataBody["delivery_way"].(string)
  3683. if len(deliveryWay) == 0 {
  3684. utils.ErrorLog("len(deliveryWay) == 0")
  3685. code = enums.ErrorCodeParamWrong
  3686. return
  3687. }
  3688. advice.DeliveryWay = deliveryWay
  3689. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3690. utils.ErrorLog("execution_frequency")
  3691. code = enums.ErrorCodeParamWrong
  3692. return
  3693. }
  3694. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3695. if len(execution_frequency) == 0 {
  3696. utils.ErrorLog("len(execution_frequency) == 0")
  3697. code = enums.ErrorCodeParamWrong
  3698. return
  3699. }
  3700. advice.ExecutionFrequency = execution_frequency
  3701. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3702. adviceDsc, _ := dataBody["advice_desc"].(string)
  3703. advice.AdviceDesc = adviceDsc
  3704. }
  3705. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3706. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3707. advice.DrugSpecUnit = drugSpecUnit
  3708. }
  3709. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3710. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3711. advice.SingleDose = singleDose
  3712. }
  3713. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3714. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3715. advice.SingleDoseUnit = singleDoseUnit
  3716. }
  3717. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3718. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3719. advice.PrescribingNumber = prescribingNumber
  3720. }
  3721. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3722. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3723. advice.PrescribingNumberUnit = prescribingNumberUnit
  3724. }
  3725. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3726. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3727. if len(thisContagions) > 0 {
  3728. for _, item := range thisContagions {
  3729. items := item.(map[string]interface{})
  3730. advice_name, _ := items["advice_name"].(string)
  3731. advice_desc, _ := items["advice_desc"].(string)
  3732. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3733. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3734. single_dose_unit, _ := items["single_dose_unit"].(string)
  3735. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3736. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3737. advice := &models.DoctorAdvice{
  3738. AdviceName: advice_name,
  3739. AdviceDesc: advice_desc,
  3740. SingleDose: single_dose,
  3741. SingleDoseUnit: single_dose_unit,
  3742. DrugSpecUnit: drug_spec_unit,
  3743. PrescribingNumber: prescribing_number,
  3744. PrescribingNumberUnit: prescribing_number_unit,
  3745. }
  3746. subAdvice = append(subAdvice, advice)
  3747. }
  3748. }
  3749. }
  3750. return
  3751. }
  3752. func (c *DialysisApiController) GetDialysisOrder() {
  3753. //xtno := c.GetString("xtno")
  3754. xtdate := c.GetString("xtdate")
  3755. patient_id, _ := c.GetInt64("patient_id")
  3756. timeLayout := "2006-01-02"
  3757. loc, _ := time.LoadLocation("Local")
  3758. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3759. if err != nil {
  3760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3761. return
  3762. }
  3763. xttime := theTime.Unix()
  3764. operatorIDs := make([]int64, 0)
  3765. adminUserInfo := c.GetAdminUserInfo()
  3766. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3767. patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
  3768. //透析单
  3769. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3770. if dialysisOrder != nil {
  3771. if dialysisOrder.FinishNurse > 0 {
  3772. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3773. }
  3774. if dialysisOrder.StartNurse > 0 {
  3775. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3776. }
  3777. }
  3778. //透前评估
  3779. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3780. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3781. //透后评估
  3782. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3783. if AssessmentAfterDislysis.Modifier > 0 {
  3784. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3785. }
  3786. //上次透前评估
  3787. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3788. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3789. //透析处方
  3790. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3791. if dialysisPrescription.PrescriptionDoctor > 0 {
  3792. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3793. }
  3794. //获取病人的透析模式
  3795. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3796. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3797. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3798. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3799. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3800. //获取透析处方
  3801. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3802. //获取临时医嘱
  3803. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3804. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3805. //获取医嘱内容
  3806. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3807. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3808. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3809. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3810. //获取上次的透后体重
  3811. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3812. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3813. //获取透析次数
  3814. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3815. if len(DoctorAdvice) > 0 {
  3816. for _, item := range DoctorAdvice {
  3817. if item.AdviceDoctor > 0 {
  3818. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3819. }
  3820. if item.ExecutionStaff > 0 {
  3821. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3822. }
  3823. if item.Checker > 0 {
  3824. operatorIDs = append(operatorIDs, item.Checker)
  3825. }
  3826. }
  3827. }
  3828. //透析监测
  3829. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3830. //透析检测
  3831. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3832. //透析小结
  3833. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3834. //接诊评估
  3835. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3836. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3837. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3838. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3839. patientInfo.TotalDialysis = dialysis_count
  3840. }
  3841. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3842. if xttime <= 1672416000 {
  3843. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3844. patientInfo.TotalDialysis = dialysis_count
  3845. }
  3846. if xttime >= 1672502400 {
  3847. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3848. patientInfo.TotalDialysis = dialysis_count
  3849. }
  3850. }
  3851. //相关操作对应的操作人
  3852. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3853. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3854. fmt.Println("operators", operators)
  3855. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3856. //获取当前日期月份的第一天
  3857. firstmonth := service.GetFirstDateOfMonth(theTime)
  3858. firstMonthDate := firstmonth.Unix()
  3859. //获取当前月份的病人透析次数
  3860. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3861. //获取his数据
  3862. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3863. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3864. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3865. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3866. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3867. //获取诊断
  3868. prescriptionInfo, _ := service.GetPrescriptionInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3869. patientDiagnose, _ := service.FindPatientDianose(adminUserInfo.CurrentOrgId)
  3870. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3871. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3872. // for _, item := range projects {
  3873. // var advice *models.HisDoctorAdviceInfo
  3874. // advice.ID = item.ID
  3875. // advice.Checker = item.Checker
  3876. // advice.CheckTime = item.CheckTime
  3877. // advice.CheckState = item.CheckState
  3878. // advice.ExecutionState = item.ExecutionState
  3879. // advice.ExecutionStaff = item.ExecutionStaff
  3880. // advice.PrescribingNumber = float64(item.Count)
  3881. // advice.PrescribingNumberUnit = item.Unit
  3882. // advice.AdviceDoctor = item.Doctor
  3883. // if item.Type == 3 {
  3884. // advice.AdviceName = item.GoodInfo.GoodName
  3885. // } else if item.Type == 2 {
  3886. // advice.AdviceName = item.HisProject.ProjectName
  3887. // }
  3888. // advice.StartTime = item.StartTime
  3889. // hisAdvice = append(hisAdvice, advice)
  3890. // }
  3891. //}
  3892. if config.IsOpen == 1 {
  3893. c.ServeSuccessJSON(map[string]interface{}{
  3894. "xtdate": xtdate,
  3895. "users": adminUser,
  3896. "patientInfo": patientInfo,
  3897. "PredialysisEvaluation": PredialysisEvaluation,
  3898. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3899. "dialysisPrescription": dialysisPrescription,
  3900. "advices": hisAdvice,
  3901. "monitors": Record,
  3902. "summary": TreatmentSummary,
  3903. "receiverTreatmentAccess": receiverTreatmentAccess,
  3904. "dialysisOrder": dialysisOrder,
  3905. "operators": operators,
  3906. "org_template_info": templateInfo,
  3907. "check": check,
  3908. "schedule": schedule,
  3909. "dialysisway": dialysisway,
  3910. "order": order,
  3911. "doctorAdvice": doctorAdvice,
  3912. "doctor": doctor,
  3913. "nurse": nurse,
  3914. "doctorAdevieInfo": doctorAdevieInfo,
  3915. "total": total,
  3916. "startNuse": startNuse,
  3917. "DoctorName": DoctorName,
  3918. "assessmentAfterDislysis": assessmentAfterDislysis,
  3919. "predialysName": predialysName,
  3920. "FinishNuse": FinishNuse,
  3921. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3922. "dialysiscount": dialysiscount,
  3923. "last_order": lastOrder,
  3924. "project_config": project_config,
  3925. "projects": projects,
  3926. "prescriptionInfo": prescriptionInfo,
  3927. "patientDiagnose": patientDiagnose,
  3928. "lastSchedule": lastSchedule,
  3929. })
  3930. }
  3931. if config.IsOpen == 0 || config.IsOpen == 2 {
  3932. c.ServeSuccessJSON(map[string]interface{}{
  3933. "xtdate": xtdate,
  3934. "users": adminUser,
  3935. "patientInfo": patientInfo,
  3936. "PredialysisEvaluation": PredialysisEvaluation,
  3937. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3938. "dialysisPrescription": dialysisPrescription,
  3939. "advices": DoctorAdvice,
  3940. "monitors": Record,
  3941. "summary": TreatmentSummary,
  3942. "receiverTreatmentAccess": receiverTreatmentAccess,
  3943. "dialysisOrder": dialysisOrder,
  3944. "operators": operators,
  3945. "org_template_info": templateInfo,
  3946. "check": check,
  3947. "schedule": schedule,
  3948. "dialysisway": dialysisway,
  3949. "order": order,
  3950. "doctorAdvice": doctorAdvice,
  3951. "doctor": doctor,
  3952. "nurse": nurse,
  3953. "doctorAdevieInfo": doctorAdevieInfo,
  3954. "total": total,
  3955. "startNuse": startNuse,
  3956. "DoctorName": DoctorName,
  3957. "assessmentAfterDislysis": assessmentAfterDislysis,
  3958. "predialysName": predialysName,
  3959. "FinishNuse": FinishNuse,
  3960. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3961. "dialysiscount": dialysiscount,
  3962. "last_order": lastOrder,
  3963. "project_config": project_config,
  3964. "projects": projects,
  3965. "prescriptionInfo": prescriptionInfo,
  3966. "patientDiagnose": patientDiagnose,
  3967. "lastSchedule": lastSchedule,
  3968. })
  3969. }
  3970. }
  3971. func (c *DialysisApiController) GetLongAdvice() {
  3972. patient_id, _ := c.GetInt64("patient_id")
  3973. adminUserInfo := c.GetAdminUserInfo()
  3974. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3975. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3976. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3977. c.ServeSuccessJSON(map[string]interface{}{
  3978. "status": "1",
  3979. })
  3980. return
  3981. } else { //开启推送提醒
  3982. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3983. var advice_three []*models.DoctorAdvice
  3984. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3985. recordDateStr := time.Now().Format("2006-01-02")
  3986. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3987. nowtime := recordDate.Unix()
  3988. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3989. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3990. for _, advice := range advices {
  3991. if advice.FrequencyType == 3 {
  3992. t := time.Now()
  3993. week := int(t.Weekday())
  3994. switch week {
  3995. case 1:
  3996. if strings.Index(advice.WeekDay, "周一") == -1 {
  3997. advice_three = append(advice_three, advice)
  3998. }
  3999. break
  4000. case 2:
  4001. if strings.Index(advice.WeekDay, "周二") == -1 {
  4002. advice_three = append(advice_three, advice)
  4003. }
  4004. break
  4005. case 3:
  4006. if strings.Index(advice.WeekDay, "周三") == -1 {
  4007. advice_three = append(advice_three, advice)
  4008. }
  4009. break
  4010. case 4:
  4011. if strings.Index(advice.WeekDay, "周四") == -1 {
  4012. advice_three = append(advice_three, advice)
  4013. }
  4014. break
  4015. case 5:
  4016. if strings.Index(advice.WeekDay, "周五") == -1 {
  4017. advice_three = append(advice_three, advice)
  4018. }
  4019. break
  4020. case 6:
  4021. if strings.Index(advice.WeekDay, "周六") == -1 {
  4022. advice_three = append(advice_three, advice)
  4023. }
  4024. break
  4025. case 0:
  4026. if strings.Index(advice.WeekDay, "周日") == -1 {
  4027. advice_three = append(advice_three, advice)
  4028. }
  4029. break
  4030. }
  4031. }
  4032. }
  4033. for _, advice := range advices_two {
  4034. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4035. now := p.Unix()
  4036. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4037. dayStr2 := "-" + dayStr
  4038. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4039. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4040. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4041. for _, ad := range advices {
  4042. advice_three = append(advice_three, ad)
  4043. }
  4044. }
  4045. if err == nil {
  4046. c.ServeSuccessJSON(map[string]interface{}{
  4047. "status": "2",
  4048. "advices": advices,
  4049. "advices_two": RemoveRepeatedElement(advice_three),
  4050. "is_open_remind": config.IsOpenRemind,
  4051. })
  4052. }
  4053. }
  4054. }
  4055. func (c *DialysisApiController) GetLongAdviceOne() {
  4056. patient_id, _ := c.GetInt64("patient_id")
  4057. schedule_date := c.GetString("schedule_date")
  4058. adminUserInfo := c.GetAdminUserInfo()
  4059. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4060. timeLayout := "2006-01-02"
  4061. loc, _ := time.LoadLocation("Local")
  4062. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4063. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4064. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4065. c.ServeSuccessJSON(map[string]interface{}{
  4066. "status": "1",
  4067. })
  4068. return
  4069. } else { //开启推送提醒
  4070. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4071. var advice_three []*models.DoctorAdvice
  4072. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4073. //recordDateStr := time.Now().Format("2006-01-02")
  4074. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4075. //
  4076. //nowtime := recordDate.Unix()
  4077. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4078. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4079. for _, advice := range advices {
  4080. if advice.FrequencyType == 3 {
  4081. t := time.Now()
  4082. week := int(t.Weekday())
  4083. switch week {
  4084. case 1:
  4085. if strings.Index(advice.WeekDay, "周一") == -1 {
  4086. advice_three = append(advice_three, advice)
  4087. }
  4088. break
  4089. case 2:
  4090. if strings.Index(advice.WeekDay, "周二") == -1 {
  4091. advice_three = append(advice_three, advice)
  4092. }
  4093. break
  4094. case 3:
  4095. if strings.Index(advice.WeekDay, "周三") == -1 {
  4096. advice_three = append(advice_three, advice)
  4097. }
  4098. break
  4099. case 4:
  4100. if strings.Index(advice.WeekDay, "周四") == -1 {
  4101. advice_three = append(advice_three, advice)
  4102. }
  4103. break
  4104. case 5:
  4105. if strings.Index(advice.WeekDay, "周五") == -1 {
  4106. advice_three = append(advice_three, advice)
  4107. }
  4108. break
  4109. case 6:
  4110. if strings.Index(advice.WeekDay, "周六") == -1 {
  4111. advice_three = append(advice_three, advice)
  4112. }
  4113. break
  4114. case 0:
  4115. if strings.Index(advice.WeekDay, "周日") == -1 {
  4116. advice_three = append(advice_three, advice)
  4117. }
  4118. break
  4119. }
  4120. }
  4121. }
  4122. for _, advice := range advices_two {
  4123. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4124. now := p.Unix()
  4125. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4126. dayStr2 := "-" + dayStr
  4127. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4128. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4129. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4130. for _, ad := range advices {
  4131. advice_three = append(advice_three, ad)
  4132. }
  4133. }
  4134. if err == nil {
  4135. c.ServeSuccessJSON(map[string]interface{}{
  4136. "status": "2",
  4137. "advices": advices,
  4138. "advices_two": RemoveRepeatedElement(advice_three),
  4139. "is_open_remind": config.IsOpenRemind,
  4140. })
  4141. }
  4142. }
  4143. }
  4144. func (c *DialysisApiController) GetLongAdviceTwo() {
  4145. patient_id, _ := c.GetInt64("patient_id")
  4146. schedule_date, _ := c.GetInt64("schedule_date")
  4147. adminUserInfo := c.GetAdminUserInfo()
  4148. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4149. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4150. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4151. c.ServeSuccessJSON(map[string]interface{}{
  4152. "status": "1",
  4153. })
  4154. return
  4155. } else { //开启推送提醒
  4156. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4157. var advice_three []*models.DoctorAdvice
  4158. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4159. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4160. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4161. for _, advice := range advices {
  4162. if advice.FrequencyType == 3 {
  4163. t := time.Now()
  4164. week := int(t.Weekday())
  4165. switch week {
  4166. case 1:
  4167. if strings.Index(advice.WeekDay, "周一") == -1 {
  4168. advice_three = append(advice_three, advice)
  4169. }
  4170. break
  4171. case 2:
  4172. if strings.Index(advice.WeekDay, "周二") == -1 {
  4173. advice_three = append(advice_three, advice)
  4174. }
  4175. break
  4176. case 3:
  4177. if strings.Index(advice.WeekDay, "周三") == -1 {
  4178. advice_three = append(advice_three, advice)
  4179. }
  4180. break
  4181. case 4:
  4182. if strings.Index(advice.WeekDay, "周四") == -1 {
  4183. advice_three = append(advice_three, advice)
  4184. }
  4185. break
  4186. case 5:
  4187. if strings.Index(advice.WeekDay, "周五") == -1 {
  4188. advice_three = append(advice_three, advice)
  4189. }
  4190. break
  4191. case 6:
  4192. if strings.Index(advice.WeekDay, "周六") == -1 {
  4193. advice_three = append(advice_three, advice)
  4194. }
  4195. break
  4196. case 0:
  4197. if strings.Index(advice.WeekDay, "周日") == -1 {
  4198. advice_three = append(advice_three, advice)
  4199. }
  4200. break
  4201. }
  4202. }
  4203. }
  4204. for _, advice := range advices_two {
  4205. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4206. now := p.Unix()
  4207. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4208. dayStr2 := "-" + dayStr
  4209. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4210. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4211. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4212. for _, ad := range advices {
  4213. advice_three = append(advice_three, ad)
  4214. }
  4215. }
  4216. if err == nil {
  4217. c.ServeSuccessJSON(map[string]interface{}{
  4218. "status": "2",
  4219. "advices": advices,
  4220. "advices_two": RemoveRepeatedElement(advice_three),
  4221. "is_open_remind": config.IsOpenRemind,
  4222. })
  4223. }
  4224. }
  4225. }
  4226. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4227. newArr = make([]*models.DoctorAdvice, 0)
  4228. for i := 0; i < len(arr); i++ {
  4229. repeat := false
  4230. for j := i + 1; j < len(arr); j++ {
  4231. if arr[i].ID == arr[j].ID {
  4232. repeat = true
  4233. break
  4234. }
  4235. }
  4236. if !repeat {
  4237. newArr = append(newArr, arr[i])
  4238. }
  4239. }
  4240. return
  4241. }
  4242. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4243. patient, _ := c.GetInt64("id", 0)
  4244. groupNo, _ := c.GetInt64("groupno", 0)
  4245. if patient <= 0 {
  4246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4247. return
  4248. }
  4249. adminUserInfo := c.GetAdminUserInfo()
  4250. dataBody := make(map[string]interface{}, 0)
  4251. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4252. if err != nil {
  4253. utils.ErrorLog(err.Error())
  4254. return
  4255. }
  4256. utils.ErrorLog("%v", dataBody)
  4257. timeLayout := "2006-01-02 15:04"
  4258. loc, _ := time.LoadLocation("Local")
  4259. timeLayout2 := "2006-01-02"
  4260. loc2, _ := time.LoadLocation("Local")
  4261. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4262. utils.ErrorLog("advice_type")
  4263. return
  4264. }
  4265. adviceType := int64(2)
  4266. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4267. utils.ErrorLog("advice_date")
  4268. return
  4269. }
  4270. adviceDate, _ := dataBody["advice_date"].(string)
  4271. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4272. AdviceDate := theTime.Unix()
  4273. RecordDate := theTime.Unix()
  4274. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4275. utils.ErrorLog("start_time")
  4276. return
  4277. }
  4278. startTime, _ := dataBody["start_time"].(string)
  4279. if len(startTime) == 0 {
  4280. utils.ErrorLog("len(start_time) == 0")
  4281. return
  4282. }
  4283. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  4284. fmt.Println("theTimeUnix", theTimeUnix.Unix())
  4285. //if err != nil {
  4286. // utils.ErrorLog(err.Error())
  4287. // return
  4288. //}
  4289. StartTime := theTimeUnix.Unix()
  4290. fmt.Println("startTIME", StartTime)
  4291. Remark := ""
  4292. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4293. remark, _ := dataBody["remark"].(string)
  4294. Remark = remark
  4295. }
  4296. var advices []*models.GroupAdvice
  4297. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4298. utils.ErrorLog("advices")
  4299. return
  4300. }
  4301. adviceNames := dataBody["advices"].([]interface{})
  4302. for _, adviceNameMap := range adviceNames {
  4303. adviceNameM := adviceNameMap.(map[string]interface{})
  4304. var advice models.GroupAdvice
  4305. advice.Remark = Remark
  4306. advice.AdviceType = adviceType
  4307. advice.StartTime = StartTime
  4308. if StartTime < 0 {
  4309. advice.StartTime = time.Now().Unix()
  4310. }
  4311. advice.AdviceDate = AdviceDate
  4312. advice.RecordDate = RecordDate
  4313. advice.Status = 1
  4314. advice.CreatedTime = time.Now().Unix()
  4315. advice.UpdatedTime = time.Now().Unix()
  4316. advice.StopState = 2
  4317. advice.ExecutionState = 2
  4318. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4319. advice.PatientId = patient
  4320. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4321. advice.IsSettle = 2
  4322. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4323. utils.ErrorLog("advice_name")
  4324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4325. return
  4326. }
  4327. adviceName, _ := adviceNameM["advice_name"].(string)
  4328. if len(adviceName) == 0 {
  4329. utils.ErrorLog("len(advice_name) == 0")
  4330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4331. return
  4332. }
  4333. advice.AdviceName = adviceName
  4334. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4335. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4336. advice.DrugSpec = drugSpec
  4337. }
  4338. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4339. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4340. advice.AdviceDesc = adviceDesc
  4341. }
  4342. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4343. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4344. advice.DrugSpecUnit = drugSpecUnit
  4345. }
  4346. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4347. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4348. // advice.SingleDose = singleDose
  4349. //}
  4350. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4351. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4352. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4353. }
  4354. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4355. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4356. advice.SingleDoseUnit = singleDoseUnit
  4357. }
  4358. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4359. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4360. // advice.PrescribingNumber = prescribingNumber
  4361. //}
  4362. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4363. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4364. }
  4365. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4366. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4367. advice.PrescribingNumberUnit = prescribingNumberUnit
  4368. }
  4369. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4370. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4371. advice.DeliveryWay = deliveryWay
  4372. }
  4373. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4374. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4375. advice.ExecutionFrequency = executionFrequency
  4376. }
  4377. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4378. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4379. advice.FrequencyType = frequency_type
  4380. }
  4381. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4382. day_count := int64(adviceNameM["day_count"].(float64))
  4383. advice.DayCount = day_count
  4384. }
  4385. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4386. way := int64(adviceNameM["way"].(float64))
  4387. advice.Way = way
  4388. }
  4389. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4390. drug_id := int64(adviceNameM["drug_id"].(float64))
  4391. advice.DrugId = drug_id
  4392. }
  4393. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4394. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4395. advice.DrugNameId = drug_name_id
  4396. }
  4397. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4398. week_day, _ := adviceNameM["week_day"].(string)
  4399. advice.WeekDay = week_day
  4400. }
  4401. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4402. template_id, _ := adviceNameM["template_id"].(string)
  4403. advice.TemplateId = template_id
  4404. }
  4405. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4406. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4407. advice.ExecutionFrequency = executionFrequency
  4408. }
  4409. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4410. children := adviceNameM["child"].([]interface{})
  4411. if len(children) > 0 {
  4412. for _, childrenMap := range children {
  4413. childMap := childrenMap.(map[string]interface{})
  4414. var child models.GroupAdvice
  4415. child.Remark = Remark
  4416. child.AdviceType = adviceType
  4417. child.StartTime = StartTime
  4418. child.AdviceDate = AdviceDate
  4419. child.RecordDate = RecordDate
  4420. child.Status = 1
  4421. child.CreatedTime = time.Now().Unix()
  4422. child.UpdatedTime = time.Now().Unix()
  4423. child.StopState = 2
  4424. child.ExecutionState = 2
  4425. child.UserOrgId = adminUserInfo.CurrentOrgId
  4426. child.PatientId = patient
  4427. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4428. child.IsSettle = 2
  4429. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4430. utils.ErrorLog("child advice_name")
  4431. return
  4432. }
  4433. childAdviceName, _ := childMap["advice_name"].(string)
  4434. if len(childAdviceName) == 0 {
  4435. utils.ErrorLog("len(child advice_name) == 0")
  4436. return
  4437. }
  4438. child.AdviceName = childAdviceName
  4439. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4440. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4441. child.AdviceDesc = childAdviceDesc
  4442. }
  4443. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4444. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4445. child.DrugSpec = childDrugSpec
  4446. }
  4447. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4448. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4449. child.DrugSpecUnit = childDrugSpecUnit
  4450. }
  4451. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  4452. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4453. child.SingleDose = childSingleDose
  4454. }
  4455. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4456. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4457. child.SingleDose = childMap["single_dose"].(float64)
  4458. }
  4459. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4460. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4461. child.Remark = childMap["remark"].(string)
  4462. }
  4463. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  4464. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4465. child.DrugId = int64(childMap["drug_id"].(float64))
  4466. }
  4467. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4468. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4469. child.SingleDoseUnit = childSingleDoseUnit
  4470. }
  4471. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4472. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4473. child.PrescribingNumber = childPrescribingNumber
  4474. }
  4475. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4476. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4477. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4478. }
  4479. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4480. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4481. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4482. }
  4483. child.DeliveryWay = advice.DeliveryWay
  4484. child.ExecutionFrequency = advice.ExecutionFrequency
  4485. advice.Children = append(advice.Children, &child)
  4486. }
  4487. }
  4488. }
  4489. advices = append(advices, &advice)
  4490. }
  4491. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4492. for _, item := range advices {
  4493. //记录日志
  4494. byterequest, _ := json.Marshal(item)
  4495. adviceLog := models.XtDoctorAdviceLog{
  4496. UserOrgId: item.UserOrgId,
  4497. PatientId: item.PatientId,
  4498. AdminUserId: adminUserInfo.AdminUser.Id,
  4499. Module: 1,
  4500. ErrLog: string(byterequest),
  4501. Status: 1,
  4502. Ctime: time.Now().Unix(),
  4503. Mtime: 0,
  4504. Source: "电脑端医嘱推送",
  4505. RecordDate: item.AdviceDate,
  4506. }
  4507. service.CreateDoctorAdviceLog(adviceLog)
  4508. }
  4509. //创建步骤表
  4510. finish := models.XtDialysisFinish{
  4511. IsFinish: 1,
  4512. UserOrgId: adminUserInfo.CurrentOrgId,
  4513. Status: 1,
  4514. Ctime: time.Now().Unix(),
  4515. Mtime: 0,
  4516. Module: 4,
  4517. RecordDate: AdviceDate,
  4518. Sourse: 1,
  4519. PatientId: patient,
  4520. }
  4521. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, AdviceDate, 4, patient)
  4522. if dialysisFinish.ID == 0 {
  4523. service.CreateDialysisFinish(finish)
  4524. }
  4525. redis := service.RedisClient()
  4526. formatAdviceDate := theTime.Format("2006-01-02")
  4527. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4528. redis.Set(key, "", time.Second)
  4529. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4530. redis.Set(keyOne, "", time.Second)
  4531. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  4532. redis.Set(keyFour, "", time.Second)
  4533. defer redis.Close()
  4534. if err != nil {
  4535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4536. return
  4537. }
  4538. c.ServeSuccessJSON(map[string]interface{}{
  4539. "msg": "ok",
  4540. "advices": list,
  4541. })
  4542. return
  4543. }
  4544. func (c *DialysisApiController) GetSolution() {
  4545. patient_id, _ := c.GetInt64("patient_id")
  4546. mode_id, _ := c.GetInt64("mode_id")
  4547. adminUserInfo := c.GetAdminUserInfo()
  4548. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4549. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdTen(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4550. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  4551. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  4552. if err != nil {
  4553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4554. return
  4555. }
  4556. c.ServeSuccessJSON(map[string]interface{}{
  4557. "solution": solution,
  4558. "prescription": prescription,
  4559. "system_prescription": system_prescription,
  4560. "dialysisPrescription": dialysisPrescription,
  4561. })
  4562. }
  4563. func (c *DialysisApiController) GetSchedule() {
  4564. schedual_type, _ := c.GetInt64("schedual_type")
  4565. adminUserInfo := c.GetAdminUserInfo()
  4566. //timeLayout := "2006-01-02 15:04:05"
  4567. //
  4568. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  4569. //loc, _ := time.LoadLocation("Local")
  4570. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  4571. //scheduleTime := theStartTime.Unix()
  4572. scheduleTime, _ := c.GetInt64("record_date")
  4573. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  4574. c.ServeSuccessJSON(map[string]interface{}{
  4575. "number": deviceNumber,
  4576. })
  4577. }
  4578. func (this *DialysisApiController) GetTodayMonitor() {
  4579. thisTime := time.Now()
  4580. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4581. timeLayout := "2006-01-02 15:04:05"
  4582. loc, _ := time.LoadLocation("Local")
  4583. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4584. theAssessmentDateTime := theStartTime.Unix()
  4585. patientID, _ := this.GetInt64("patient_id")
  4586. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4587. adminInfo := this.GetAdminUserInfo()
  4588. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4589. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4590. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  4591. var ultrafiltration_rate float64
  4592. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4593. //针对福建医师汇 获取透前评估预增脱水量
  4594. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4595. fmt.Println("透前评估数据", evaluation)
  4596. if prescription.ID > 0 {
  4597. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4598. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4599. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  4600. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4601. record.UltrafiltrationRate = ultrafiltration_rate
  4602. }
  4603. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  4604. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4605. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4606. record.UltrafiltrationRate = ultrafiltration_rate
  4607. }
  4608. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  4609. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4610. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4611. record.UltrafiltrationRate = ultrafiltration_rate
  4612. }
  4613. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  4614. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4615. record.UltrafiltrationRate = ultrafiltration_rate
  4616. }
  4617. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  4618. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4619. record.UltrafiltrationRate = ultrafiltration_rate
  4620. }
  4621. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  4622. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4623. record.UltrafiltrationRate = ultrafiltration_rate
  4624. }
  4625. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  4626. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4627. record.UltrafiltrationRate = ultrafiltration_rate
  4628. }
  4629. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  4630. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4631. record.UltrafiltrationRate = ultrafiltration_rate
  4632. }
  4633. // 只针对方济医院
  4634. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4635. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4636. ultrafiltration_rate = value
  4637. record.UltrafiltrationRate = ultrafiltration_rate
  4638. }
  4639. //长沙南雅
  4640. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  4641. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4642. record.UltrafiltrationRate = ultrafiltration_rate
  4643. }
  4644. }
  4645. }
  4646. // record.UltrafiltrationRate = ultrafiltration_rate
  4647. record.UltrafiltrationVolume = 0
  4648. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4649. if ultrafiltration_rate > 0 {
  4650. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4651. record.UltrafiltrationVolume = value
  4652. }
  4653. }
  4654. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 {
  4655. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  4656. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4657. record.UltrafiltrationVolume = ultrafiltration_volume
  4658. }
  4659. }
  4660. //长沙南雅
  4661. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  4662. if ultrafiltration_rate > 0 {
  4663. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4664. record.UltrafiltrationVolume = ultrafiltration_volume
  4665. }
  4666. }
  4667. if template.TemplateId == 47 || template.TemplateId == 54 {
  4668. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4669. }
  4670. this.ServeSuccessJSON(map[string]interface{}{
  4671. "monitor": record,
  4672. })
  4673. }
  4674. func (c *DialysisApiController) UploadDryWeight() {
  4675. patient_id, _ := c.GetInt64("id")
  4676. dry_weight, _ := c.GetFloat("dry_weight")
  4677. doctor_id, _ := c.GetInt64("doctor_id")
  4678. remark := c.GetString("remark")
  4679. adminUserInfo := c.GetAdminUserInfo()
  4680. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  4681. fmt.Println(err)
  4682. if err == gorm.ErrRecordNotFound {
  4683. dryWeight := &models.SgjPatientDryweight{
  4684. PatientId: patient_id,
  4685. DryWeight: dry_weight,
  4686. Remakes: remark,
  4687. Ctime: time.Now().Unix(),
  4688. Mtime: time.Now().Unix(),
  4689. Creator: doctor_id,
  4690. Status: 1,
  4691. UserOrgId: adminUserInfo.CurrentOrgId,
  4692. AdjustedValue: "/",
  4693. UserId: adminUserInfo.AdminUser.Id,
  4694. }
  4695. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4696. loc, _ := time.LoadLocation("Local")
  4697. nowTime := time.Now()
  4698. nowDay := nowTime.Format("2006-01-02")
  4699. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4700. redis := service.RedisClient()
  4701. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4702. redis.Set(keyOne, "", time.Second)
  4703. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4704. redis.Set(key, "", time.Second)
  4705. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4706. redis.Set(keyTwo, "", time.Second)
  4707. redis.Close()
  4708. if createErr == nil {
  4709. c.ServeSuccessJSON(map[string]interface{}{
  4710. "msg": "提交成功",
  4711. "weight": dryWeight,
  4712. })
  4713. }
  4714. } else {
  4715. dryWeight := &models.SgjPatientDryweight{
  4716. PatientId: patient_id,
  4717. DryWeight: dry_weight,
  4718. Remakes: remark,
  4719. Ctime: time.Now().Unix(),
  4720. Mtime: time.Now().Unix(),
  4721. Creator: doctor_id,
  4722. Status: 1,
  4723. UserOrgId: adminUserInfo.CurrentOrgId,
  4724. AdjustedValue: "/",
  4725. UserId: adminUserInfo.AdminUser.Id,
  4726. }
  4727. var value float64
  4728. value = dry_weight - weightAdjust.DryWeight
  4729. fmt.Println(value)
  4730. if value < 0 {
  4731. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4732. } else if value == 0 {
  4733. dryWeight.AdjustedValue = "/"
  4734. } else if value > 0 {
  4735. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4736. }
  4737. fmt.Println(value)
  4738. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4739. loc, _ := time.LoadLocation("Local")
  4740. nowTime := time.Now()
  4741. nowDay := nowTime.Format("2006-01-02")
  4742. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4743. redis := service.RedisClient()
  4744. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4745. redis.Set(keyOne, "", time.Second)
  4746. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4747. redis.Set(key, "", time.Second)
  4748. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4749. redis.Set(keyTwo, "", time.Second)
  4750. redis.Close()
  4751. if createErr == nil {
  4752. c.ServeSuccessJSON(map[string]interface{}{
  4753. "msg": "提交成功",
  4754. "weight": dryWeight,
  4755. })
  4756. }
  4757. }
  4758. }
  4759. func (this *DialysisApiController) GetFuncPurview() {
  4760. adminUserInfo := this.GetAdminUserInfo()
  4761. user_id := adminUserInfo.AdminUser.Id
  4762. app_id := adminUserInfo.CurrentAppId
  4763. org_id := adminUserInfo.CurrentOrgId
  4764. create_url := this.GetString("create_url")
  4765. modify_url := this.GetString("modify_url")
  4766. modify_other_url := this.GetString("modify_other_url")
  4767. del_url := this.GetString("del_url")
  4768. del_other_url := this.GetString("del_other_url")
  4769. exce_url := this.GetString("exce_url")
  4770. check_url := this.GetString("check_url")
  4771. modify_exce_url := this.GetString("modify_exce_url")
  4772. module, _ := this.GetInt64("module", 0)
  4773. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4774. var is_has_create bool
  4775. var is_has_modify bool
  4776. var is_has_modify_other bool
  4777. var is_has_del bool
  4778. var is_has_del_other bool
  4779. var is_has_exce bool
  4780. var is_has_check bool
  4781. var is_has_modify_exce bool
  4782. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4783. if adminUserInfo.AdminUser.Id != org.Creator {
  4784. if app_role != nil {
  4785. if len(app_role.RoleIds) > 0 {
  4786. roles := strings.Split(app_role.RoleIds, ",")
  4787. var userRolePurviews string
  4788. for _, item := range roles {
  4789. role_id, _ := strconv.ParseInt(item, 10, 64)
  4790. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4791. if len(userRolePurviews) == 0 {
  4792. userRolePurviews = purviews
  4793. } else {
  4794. userRolePurviews = userRolePurviews + "," + purviews
  4795. }
  4796. }
  4797. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4798. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4799. for _, item := range funcPurviews {
  4800. //for _, url := range strings.Split(item.Urlfor,","){
  4801. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4802. is_has_create = true
  4803. }
  4804. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4805. is_has_modify = true
  4806. }
  4807. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4808. is_has_modify_other = true
  4809. }
  4810. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4811. is_has_del = true
  4812. }
  4813. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4814. is_has_del_other = true
  4815. }
  4816. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4817. is_has_exce = true
  4818. }
  4819. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4820. is_has_check = true
  4821. }
  4822. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4823. is_has_modify_exce = true
  4824. }
  4825. }
  4826. } else {
  4827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4828. return
  4829. }
  4830. this.ServeSuccessJSON(map[string]interface{}{
  4831. "is_has_create": is_has_create,
  4832. "is_has_modify": is_has_modify,
  4833. "is_has_modify_other": is_has_modify_other,
  4834. "is_has_del": is_has_del,
  4835. "is_has_del_other": is_has_del_other,
  4836. "is_has_exce": is_has_exce,
  4837. "is_has_check": is_has_check,
  4838. "is_has_modify_exce": is_has_modify_exce,
  4839. "module": module,
  4840. })
  4841. } else {
  4842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4843. return
  4844. }
  4845. } else {
  4846. this.ServeSuccessJSON(map[string]interface{}{
  4847. "is_has_create": true,
  4848. "is_has_modify": true,
  4849. "is_has_modify_other": true,
  4850. "is_has_del": true,
  4851. "is_has_del_other": true,
  4852. "is_has_exce": true,
  4853. "is_has_check": true,
  4854. "is_has_modify_exce": true,
  4855. "module": true,
  4856. })
  4857. }
  4858. }
  4859. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  4860. patient_id, _ := this.GetInt64("patient_id", 0)
  4861. advice_date, _ := this.GetInt64("advice_date")
  4862. adminUserInfo := this.GetAdminUserInfo()
  4863. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4864. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4865. this.ServeSuccessJSON(map[string]interface{}{
  4866. "doctorAdvice": doctorAdvice,
  4867. "hisDoctorAdvice": hisDoctorAdvice,
  4868. })
  4869. }
  4870. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4871. change_type, _ := this.GetInt64("type", 0)
  4872. record_date := this.GetString("record_time")
  4873. patient_id, _ := this.GetInt64("patient_id", 0)
  4874. timeLayout := "2006-01-02"
  4875. loc, _ := time.LoadLocation("Local")
  4876. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4877. record_time := theAdviceRecordTime.Unix()
  4878. adminUserInfo := this.GetAdminUserInfo()
  4879. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4880. if err == nil {
  4881. if len(advices) == 0 {
  4882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4883. return
  4884. } else {
  4885. this.ServeSuccessJSON(map[string]interface{}{
  4886. "advices": advices,
  4887. "schedule": sch,
  4888. })
  4889. return
  4890. }
  4891. } else {
  4892. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4893. return
  4894. }
  4895. }
  4896. func (c *DialysisApiController) GetDialysisGoods() {
  4897. schedualDate := c.GetString("schedule_date")
  4898. schedule_type, _ := c.GetInt64("schedule_type")
  4899. partition_id, _ := c.GetInt64("partition_id")
  4900. page, _ := c.GetInt("page")
  4901. limit, _ := c.GetInt("limit")
  4902. keywords := c.GetString("keywords")
  4903. patient_id, _ := c.GetInt64("patient_id")
  4904. good_type, _ := c.GetInt64("good_type")
  4905. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4906. if parseDateErr != nil && len(schedualDate) != 0 {
  4907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4908. return
  4909. }
  4910. schedualEndDate := int64(0)
  4911. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4912. if parseDateErr != nil && len(schedualDate) != 0 {
  4913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4914. return
  4915. }
  4916. schedualEndDate = endDate.Unix()
  4917. adminUser := c.GetAdminUserInfo()
  4918. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  4919. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  4920. if err == gorm.ErrRecordNotFound {
  4921. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4922. var ids []int64
  4923. for _, item := range list {
  4924. ids = append(ids, item.PatientId)
  4925. }
  4926. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4927. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4928. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4929. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4930. item.LastAutomaticReduceDetail = goodUser
  4931. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4932. }
  4933. c.ServeSuccessJSON(map[string]interface{}{
  4934. "dialysis_goods": dialysisGoods,
  4935. "good_type": goodTypes,
  4936. "total": total,
  4937. })
  4938. return
  4939. } else if err == nil {
  4940. //获取当天排班的每个患者的库存使用情况
  4941. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4942. var ids []int64
  4943. for _, item := range list {
  4944. ids = append(ids, item.PatientId)
  4945. }
  4946. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4947. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4948. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4949. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4950. fmt.Println(goodUser)
  4951. fmt.Println(lastGoodUserDetial)
  4952. item.LastAutomaticReduceDetail = goodUser
  4953. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4954. }
  4955. if err == nil {
  4956. c.ServeSuccessJSON(map[string]interface{}{
  4957. "dialysis_goods": dialysisGoods,
  4958. "good_type": goodTypes,
  4959. "total": total,
  4960. })
  4961. return
  4962. } else {
  4963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4964. return
  4965. }
  4966. } else if err != nil {
  4967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4968. return
  4969. }
  4970. }
  4971. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  4972. start_time := c.GetString("start_time")
  4973. end_time := c.GetString("end_time")
  4974. timeLayout := "2006-01-02"
  4975. loc, _ := time.LoadLocation("Local")
  4976. var theStartTime int64
  4977. if len(start_time) > 0 {
  4978. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4979. if err != nil {
  4980. utils.ErrorLog(err.Error())
  4981. }
  4982. theStartTime = theTime.Unix()
  4983. }
  4984. var theEndtTime int64
  4985. if len(end_time) > 0 {
  4986. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4987. if err != nil {
  4988. utils.ErrorLog(err.Error())
  4989. }
  4990. theEndtTime = theTime.Unix()
  4991. }
  4992. adminUser := c.GetAdminUserInfo()
  4993. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  4994. if err == nil {
  4995. c.ServeSuccessJSON(map[string]interface{}{
  4996. "stock_out": outInfo,
  4997. })
  4998. return
  4999. } else {
  5000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5001. return
  5002. }
  5003. }
  5004. func (c *DialysisApiController) GetRoleList() {
  5005. orgId := c.GetAdminUserInfo().CurrentOrgId
  5006. admin_user_id, _ := c.GetInt64("admin_user_id")
  5007. list, err := service.GetRoleList(orgId, admin_user_id)
  5008. if err == nil {
  5009. c.ServeSuccessJSON(map[string]interface{}{
  5010. "adminRole": list,
  5011. })
  5012. return
  5013. } else {
  5014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5015. return
  5016. }
  5017. }
  5018. func (c *DialysisApiController) GetInitPrintData() {
  5019. patient_id, _ := c.GetInt64("patient_id")
  5020. record_date, _ := c.GetInt64("record_date")
  5021. orgId := c.GetAdminUserInfo().CurrentOrgId
  5022. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  5023. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  5024. if err == nil {
  5025. c.ServeSuccessJSON(map[string]interface{}{
  5026. "list": list,
  5027. "assessmentAfterDislysis": assessmentAfterDislysis,
  5028. })
  5029. return
  5030. } else {
  5031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5032. return
  5033. }
  5034. }
  5035. func (c *DialysisApiController) GetInitPrintDataOne() {
  5036. patient_id, _ := c.GetInt64("patient_id")
  5037. start_time := c.GetString("record_date")
  5038. timeLayout := "2006-01-02"
  5039. loc, _ := time.LoadLocation("Local")
  5040. var theStartTime int64
  5041. if len(start_time) > 0 {
  5042. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5043. if err != nil {
  5044. utils.ErrorLog(err.Error())
  5045. }
  5046. theStartTime = theTime.Unix()
  5047. }
  5048. orgId := c.GetAdminUserInfo().CurrentOrgId
  5049. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  5050. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  5051. if err == nil {
  5052. c.ServeSuccessJSON(map[string]interface{}{
  5053. "list": list,
  5054. "assessmentAfterDislysis": assessmentAfterDislysis,
  5055. })
  5056. return
  5057. } else {
  5058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5059. return
  5060. }
  5061. }
  5062. // 新接口
  5063. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  5064. keyword := this.GetString("keywords")
  5065. limit, _ := this.GetInt64("limit")
  5066. page, _ := this.GetInt64("page")
  5067. partition_id, _ := this.GetInt64("partition_id")
  5068. schedule_type, _ := this.GetInt64("schedule_type")
  5069. start_time := this.GetString("schedule_date")
  5070. advice_ids := this.GetString("ids")
  5071. var ids []string
  5072. if advice_ids != "" {
  5073. ids = strings.Split(advice_ids, ",")
  5074. }
  5075. timeLayout := "2006-01-02"
  5076. loc, _ := time.LoadLocation("Local")
  5077. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5078. orgId := this.GetAdminUserInfo().CurrentOrgId
  5079. _, config := service.FindXTHisRecordByOrgId(orgId)
  5080. goodType, _ := service.GetAllGoodType(orgId)
  5081. if config.IsOpen != 1 {
  5082. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5083. if err == nil {
  5084. this.ServeSuccessJSON(map[string]interface{}{
  5085. "list": list,
  5086. "total": total,
  5087. "config": config,
  5088. "goodType": goodType,
  5089. })
  5090. return
  5091. } else {
  5092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5093. return
  5094. }
  5095. }
  5096. if config.IsOpen == 1 {
  5097. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5098. if err == nil {
  5099. this.ServeSuccessJSON(map[string]interface{}{
  5100. "list": list,
  5101. "total": total,
  5102. "config": config,
  5103. "goodType": goodType,
  5104. })
  5105. return
  5106. }
  5107. }
  5108. }
  5109. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  5110. keyword := this.GetString("keywords")
  5111. limit, _ := this.GetInt64("limit")
  5112. page, _ := this.GetInt64("page")
  5113. partition_id, _ := this.GetInt64("partition_id")
  5114. schedule_type, _ := this.GetInt64("schedule_type")
  5115. start_time := this.GetString("schedule_date")
  5116. ids := this.GetString("ids")
  5117. var idArray []string
  5118. if ids != "" {
  5119. idArray = strings.Split(ids, ",")
  5120. }
  5121. timeLayout := "2006-01-02"
  5122. loc, _ := time.LoadLocation("Local")
  5123. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5124. orgId := this.GetAdminUserInfo().CurrentOrgId
  5125. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5126. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5127. //获取长期医嘱
  5128. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5129. _, config := service.FindXTHisRecordByOrgId(orgId)
  5130. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  5131. if err == nil {
  5132. this.ServeSuccessJSON(map[string]interface{}{
  5133. "list": list,
  5134. "total": total,
  5135. "adviceList": adviceList,
  5136. "config": config,
  5137. "drugList": drugList,
  5138. "tablelist": tablelist,
  5139. })
  5140. return
  5141. } else {
  5142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5143. return
  5144. }
  5145. }
  5146. func (this *DialysisApiController) SaveDialysisSetting() {
  5147. orgId := this.GetAdminUserInfo().CurrentOrgId
  5148. device_number_set, _ := this.GetInt64("device_number_set")
  5149. device_type_set, _ := this.GetInt64("device_type_set")
  5150. name_set, _ := this.GetInt64("name_set")
  5151. admission_number_set, _ := this.GetInt64("admission_number_set")
  5152. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  5153. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  5154. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  5155. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  5156. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  5157. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  5158. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  5159. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  5160. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  5161. mode_id_set, _ := this.GetInt64("mode_id_set")
  5162. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  5163. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  5164. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  5165. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  5166. kalium_set, _ := this.GetInt64("kalium_set")
  5167. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  5168. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  5169. glucose_set, _ := this.GetInt64("glucose_set")
  5170. sodium_set, _ := this.GetInt64("sodium_set")
  5171. calcium_set, _ := this.GetInt64("calcium_set")
  5172. blood_access_set, _ := this.GetInt64("blood_access_set")
  5173. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  5174. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  5175. dialysisSetting := models.XtDialysisSetting{
  5176. Sodium: sodium_set,
  5177. Calcium: calcium_set,
  5178. BloodAccess: blood_access_set,
  5179. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  5180. DisplaceLiquiPart: displace_liqui_part_set,
  5181. UserOrgId: orgId,
  5182. Status: 1,
  5183. DeviceNumber: device_number_set,
  5184. DeviceType: device_type_set,
  5185. Name: name_set,
  5186. AdmissionNumber: admission_number_set,
  5187. DialysisNo: dialysis_no_set,
  5188. WeightBefor: weight_befor_set,
  5189. DryWeight: dry_weight_set,
  5190. BloodPressure: blood_pressure_set,
  5191. UltrafiltrationVolume: ultrafiltration_volume_set,
  5192. InternalFistula: internal_fistula_set,
  5193. BloodFlowVolume: blood_flow_volume_set,
  5194. Anticoagulant: anticoagulant_set,
  5195. SealingFluidDispose: sealing_fluid_dispose_set,
  5196. ModeId: mode_id_set,
  5197. DialysisTime: dialysis_time_set,
  5198. DialysisDialyszers: dialysis_dialyszers_set,
  5199. DialysisIrrigation: dialysis_irrigation_set,
  5200. Gaijiliang: gaijiliang_set,
  5201. Kalium: kalium_set,
  5202. DisplaceLiquiValue: displace_liqui_value_set,
  5203. Bicarbonate: bicarbonate_set,
  5204. Glucose: glucose_set,
  5205. Ctime: time.Now().Unix(),
  5206. Mtime: time.Now().Unix(),
  5207. }
  5208. err := service.SaveDialysisSetting(dialysisSetting)
  5209. if err == nil {
  5210. this.ServeSuccessJSON(map[string]interface{}{
  5211. "dialysisSetting": dialysisSetting,
  5212. })
  5213. return
  5214. } else {
  5215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5216. return
  5217. }
  5218. }
  5219. func (this *DialysisApiController) GetDialysisSetting() {
  5220. orgId := this.GetAdminUserInfo().CurrentOrgId
  5221. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5222. this.ServeSuccessJSON(map[string]interface{}{
  5223. "dialysisSett": dialysisSett,
  5224. })
  5225. return
  5226. }
  5227. func (this *DialysisApiController) GetDialysisParameterList() {
  5228. keyword := this.GetString("keywords")
  5229. limit, _ := this.GetInt64("limit")
  5230. page, _ := this.GetInt64("page")
  5231. //partition_id, _ := this.GetInt64("partition_id")
  5232. partion_type := this.GetString("partition_id")
  5233. idSplit := strings.Split(partion_type, ",")
  5234. schedule_type, _ := this.GetInt64("schedule_type")
  5235. start_time := this.GetString("schedule_date")
  5236. timeLayout := "2006-01-02"
  5237. loc, _ := time.LoadLocation("Local")
  5238. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5239. orgId := this.GetAdminUserInfo().CurrentOrgId
  5240. scheduids := this.GetString("ids")
  5241. var ids []string
  5242. if scheduids != "" {
  5243. ids = strings.Split(scheduids, ",")
  5244. }
  5245. list, total, err := service.GetDialysisParameterList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  5246. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5247. if err == nil {
  5248. this.ServeSuccessJSON(map[string]interface{}{
  5249. "list": list,
  5250. "total": total,
  5251. "dialysisSett": dialysisSett,
  5252. })
  5253. return
  5254. } else {
  5255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5256. return
  5257. }
  5258. }
  5259. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  5260. orgId := this.GetAdminUserInfo().CurrentOrgId
  5261. schedule_type, _ := this.GetInt64("schedule_type")
  5262. //partion_type, _ := this.GetInt64("partion_type")
  5263. start_time := this.GetString("selected_date")
  5264. partion_type := this.GetString("partion_type")
  5265. var ids []string
  5266. ids = strings.Split(partion_type, ",")
  5267. timeLayout := "2006-01-02"
  5268. loc, _ := time.LoadLocation("Local")
  5269. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5270. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  5271. if err == nil {
  5272. this.ServeSuccessJSON(map[string]interface{}{
  5273. "list": list,
  5274. })
  5275. return
  5276. } else {
  5277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5278. return
  5279. }
  5280. }
  5281. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  5282. orgId := this.GetAdminUserInfo().CurrentOrgId
  5283. schedule_type, _ := this.GetInt64("schedule_type")
  5284. //partion_type, _ := this.GetInt64("partion_type")
  5285. partion_type := this.GetString("partion_type")
  5286. var ids []string
  5287. ids = strings.Split(partion_type, ",")
  5288. start_time := this.GetString("selected_date")
  5289. timeLayout := "2006-01-02"
  5290. loc, _ := time.LoadLocation("Local")
  5291. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5292. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  5293. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  5294. //获取长期医嘱
  5295. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5296. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5297. _, config := service.FindXTHisRecordByOrgId(orgId)
  5298. if err == nil {
  5299. this.ServeSuccessJSON(map[string]interface{}{
  5300. "list": list,
  5301. "drug": drug,
  5302. "adviceList": adviceList,
  5303. "config": config,
  5304. "tablelist": tablelist,
  5305. })
  5306. return
  5307. } else {
  5308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5309. return
  5310. }
  5311. }
  5312. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  5313. orgId := this.GetAdminUserInfo().CurrentOrgId
  5314. schedule_type, _ := this.GetInt64("schedule_type")
  5315. partion_type, _ := this.GetInt64("partion_type")
  5316. start_time := this.GetString("selected_date")
  5317. timeLayout := "2006-01-02"
  5318. loc, _ := time.LoadLocation("Local")
  5319. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5320. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  5321. if err == nil {
  5322. this.ServeSuccessJSON(map[string]interface{}{
  5323. "list": list,
  5324. })
  5325. return
  5326. } else {
  5327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5328. return
  5329. }
  5330. }
  5331. func (this *DialysisApiController) SaveHisDialysis() {
  5332. var ids []string
  5333. advice_ids := this.GetString("ids")
  5334. ids = strings.Split(advice_ids, ",")
  5335. orgId := this.GetAdminUserInfo().CurrentOrgId
  5336. service.SaveHisDialysis(orgId, ids)
  5337. returnData := make(map[string]interface{}, 0)
  5338. returnData["msg"] = "ok"
  5339. this.ServeSuccessJSON(returnData)
  5340. return
  5341. }
  5342. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  5343. orgId := this.GetAdminUserInfo().CurrentOrgId
  5344. schedule_type, _ := this.GetInt64("schedule_type")
  5345. //partion_type, _ := this.GetInt64("partion_type")
  5346. partion_type := this.GetString("partion_type")
  5347. var ids []string
  5348. ids = strings.Split(partion_type, ",")
  5349. start_time := this.GetString("selected_date")
  5350. timeLayout := "2006-01-02"
  5351. loc, _ := time.LoadLocation("Local")
  5352. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5353. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  5354. this.ServeSuccessJSON(map[string]interface{}{
  5355. "list": list,
  5356. })
  5357. return
  5358. }
  5359. func (this *DialysisApiController) GetPatientSchedule() {
  5360. orgId := this.GetAdminUserInfo().CurrentOrgId
  5361. patient_id, _ := this.GetInt64("patient_id")
  5362. schedule_date, _ := this.GetInt64("schedule_date")
  5363. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  5364. this.ServeSuccessJSON(map[string]interface{}{
  5365. "schedulePatient": schedulePatient,
  5366. })
  5367. }
  5368. func (c *DialysisApiController) GetSchedulePrintList() {
  5369. page, _ := c.GetInt64("page", 1)
  5370. limit, _ := c.GetInt64("limit", 10)
  5371. schedulType, _ := c.GetInt64("schedule_type", 0)
  5372. partitionType, _ := c.GetInt64("partition_type", 0)
  5373. keywords := c.GetString("keywords")
  5374. schedule_date := c.GetString("schedule_date")
  5375. timeLayout := "2006-01-02"
  5376. loc, _ := time.LoadLocation("Local")
  5377. var theStartTime int64
  5378. if len(schedule_date) > 0 {
  5379. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  5380. if err != nil {
  5381. utils.ErrorLog(err.Error())
  5382. }
  5383. theStartTime = theTime.Unix()
  5384. }
  5385. adminUserInfo := c.GetAdminUserInfo()
  5386. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5387. for _, item := range list {
  5388. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  5389. item.DialysisOrderTwenty = order
  5390. }
  5391. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5392. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  5393. c.ServeSuccessJSON(map[string]interface{}{
  5394. "list": list,
  5395. "total": total,
  5396. "numberList": numberList,
  5397. "listOne": listOne,
  5398. })
  5399. }
  5400. func (this *DialysisApiController) GetSolutionListByOrgId() {
  5401. orgId := this.GetAdminUserInfo().CurrentOrgId
  5402. list, _ := service.GetSolutionListByOrgId(orgId)
  5403. for _, item := range list {
  5404. //获取该模式最新的1条数据
  5405. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  5406. //更新状态值
  5407. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  5408. }
  5409. this.ServeSuccessJSON(map[string]interface{}{
  5410. "list": list,
  5411. })
  5412. }
  5413. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  5414. orgId := this.GetAdminUserInfo().CurrentOrgId
  5415. is_open, _ := this.GetInt64("is_open")
  5416. idsStr := this.GetString("str")
  5417. recordIDStrs := strings.Split(idsStr, ",")
  5418. start_time := this.GetString("advice_date")
  5419. exec_time, _ := this.GetInt64("exec_time")
  5420. timeLayout := "2006-01-02"
  5421. loc, _ := time.LoadLocation("Local")
  5422. var startTime int64
  5423. if len(start_time) > 0 {
  5424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5425. if err != nil {
  5426. //fmt.Println(err)
  5427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5428. return
  5429. }
  5430. startTime = theTime.Unix()
  5431. }
  5432. config, _ := service.GetDrugOpenConfigOne(orgId)
  5433. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5434. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5435. //his医嘱
  5436. if is_open == 1 {
  5437. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  5438. //查找未执行医嘱
  5439. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5440. for _, item := range list {
  5441. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5442. this.ServeSuccessJSON(map[string]interface{}{
  5443. "msg": "3",
  5444. })
  5445. return
  5446. }
  5447. }
  5448. for _, item := range groupList {
  5449. for _, it := range list {
  5450. if item.DrugId == it.DrugId {
  5451. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5452. }
  5453. }
  5454. }
  5455. for _, item := range groupList {
  5456. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5457. var sum_out_count int64
  5458. for _, it := range item.ChildDoctorAdvice {
  5459. var prescribing_number int64
  5460. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5461. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5462. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5463. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5464. }
  5465. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5466. prescribing_number = parseIntPrescribingNumber
  5467. }
  5468. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5469. prescribing_number = parseIntPrescribingNumber
  5470. }
  5471. sum_out_count += prescribing_number
  5472. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5473. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5474. //库存不足
  5475. if sum_out_count > drugStockOut.FlushCount {
  5476. this.ServeSuccessJSON(map[string]interface{}{
  5477. "msg": "2",
  5478. "drug": medical,
  5479. })
  5480. return
  5481. }
  5482. }
  5483. }
  5484. creater := this.GetAdminUserInfo().AdminUser.Id
  5485. //执行出库逻辑
  5486. for _, item := range list {
  5487. hisadvice := &models.HisDoctorAdviceInfo{
  5488. ID: item.ID,
  5489. UserOrgId: item.UserOrgId,
  5490. PatientId: item.PatientId,
  5491. AdviceType: item.AdviceType,
  5492. AdviceDate: item.AdviceDate,
  5493. StartTime: item.StartTime,
  5494. AdviceName: item.AdviceName,
  5495. AdviceDesc: item.AdviceDesc,
  5496. ReminderDate: item.ReminderDate,
  5497. SingleDose: item.SingleDose,
  5498. SingleDoseUnit: item.SingleDoseUnit,
  5499. DrugSpec: item.DrugSpec,
  5500. DrugSpecUnit: item.DrugSpecUnit,
  5501. PrescribingNumber: item.PrescribingNumber,
  5502. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5503. DeliveryWay: item.DeliveryWay,
  5504. ExecutionFrequency: item.ExecutionFrequency,
  5505. AdviceDoctor: item.AdviceDoctor,
  5506. Status: 1,
  5507. CreatedTime: item.CreatedTime,
  5508. UpdatedTime: item.UpdatedTime,
  5509. AdviceAffirm: item.AdviceAffirm,
  5510. Remark: item.Remark,
  5511. StopTime: item.StopTime,
  5512. StopReason: item.StopReason,
  5513. StopDoctor: item.StopDoctor,
  5514. StopState: item.StopState,
  5515. ParentId: item.ParentId,
  5516. ExecutionTime: item.ExecutionTime,
  5517. ExecutionStaff: creater,
  5518. ExecutionState: item.ExecutionState,
  5519. Checker: item.Checker,
  5520. RecordDate: item.RecordDate,
  5521. DialysisOrderId: item.DialysisOrderId,
  5522. CheckTime: item.CheckTime,
  5523. CheckState: item.CheckState,
  5524. RemindType: item.RemindType,
  5525. FrequencyType: item.FrequencyType,
  5526. DayCount: item.DayCount,
  5527. WeekDay: item.WeekDay,
  5528. TemplateId: item.TemplateId,
  5529. Modifier: item.Modifier,
  5530. Way: item.Way,
  5531. DrugId: item.DrugId,
  5532. ExecutionFrequencyId: item.ExecutionFrequencyId,
  5533. }
  5534. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5535. if medical.IsUse == 2 {
  5536. if config.IsOpen != 1 {
  5537. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5538. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5539. }
  5540. //不通过药房发药
  5541. if pharmacyConfig.IsOpen != 1 {
  5542. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5543. }
  5544. //查询默认仓库
  5545. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5546. //查询默认仓库剩余多少库存
  5547. var sum_count int64
  5548. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5549. for _, its := range stockInfo {
  5550. if its.MaxUnit == medical.MaxUnit {
  5551. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5552. }
  5553. sum_count += its.StockMaxNumber + its.StockMinNumber
  5554. }
  5555. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5556. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5557. }
  5558. }
  5559. info := models.HisDoctorAdviceInfo{
  5560. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5561. ExecutionTime: exec_time,
  5562. ExecutionState: 1,
  5563. UpdatedTime: time.Now().Unix(),
  5564. }
  5565. //执行医嘱
  5566. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  5567. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5568. redis := service.RedisClient()
  5569. //清空key 值
  5570. redis.Set(key, "", time.Second)
  5571. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5572. redis.Set(keyTwo, "", time.Second)
  5573. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5574. redis.Set(keyThree, "", time.Second)
  5575. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5576. theTime := toTime.Format("2006-01-02")
  5577. fmt.Println("theTIME", theTime)
  5578. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5579. redis.Set(keyFour, "", time.Second)
  5580. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5581. redis.Set(keyFive, "", time.Second)
  5582. }
  5583. } else {
  5584. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  5585. //查找未执行医嘱
  5586. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5587. for _, item := range groupList {
  5588. for _, it := range list {
  5589. if item.DrugId == it.DrugId {
  5590. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5591. }
  5592. }
  5593. }
  5594. for _, item := range groupList {
  5595. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5596. var sum_out_count int64
  5597. for _, it := range item.ChildDoctorAdvice {
  5598. var prescribing_number int64
  5599. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5600. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5601. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5602. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5603. }
  5604. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5605. prescribing_number = parseIntPrescribingNumber
  5606. }
  5607. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5608. prescribing_number = parseIntPrescribingNumber
  5609. }
  5610. sum_out_count += prescribing_number
  5611. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5612. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5613. //库存不足
  5614. if sum_out_count > drugStockOut.FlushCount {
  5615. this.ServeSuccessJSON(map[string]interface{}{
  5616. "msg": "2",
  5617. "drug": medical,
  5618. })
  5619. return
  5620. }
  5621. }
  5622. }
  5623. for _, item := range list {
  5624. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5625. dadvice := &models.DoctorAdvice{
  5626. ID: item.ID,
  5627. UserOrgId: item.UserOrgId,
  5628. PatientId: item.PatientId,
  5629. AdviceType: item.AdviceType,
  5630. AdviceDate: item.AdviceDate,
  5631. StartTime: item.StartTime,
  5632. AdviceName: item.AdviceName,
  5633. AdviceDesc: item.AdviceDesc,
  5634. ReminderDate: item.ReminderDate,
  5635. SingleDose: item.SingleDose,
  5636. SingleDoseUnit: item.SingleDoseUnit,
  5637. DrugSpec: item.DrugSpec,
  5638. DrugSpecUnit: item.DrugSpecUnit,
  5639. PrescribingNumber: item.PrescribingNumber,
  5640. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5641. DeliveryWay: item.DeliveryWay,
  5642. ExecutionFrequency: item.ExecutionFrequency,
  5643. AdviceDoctor: item.AdviceDoctor,
  5644. Status: 1,
  5645. CreatedTime: item.CreatedTime,
  5646. UpdatedTime: item.UpdatedTime,
  5647. AdviceAffirm: item.AdviceAffirm,
  5648. Remark: item.Remark,
  5649. StopTime: item.StopTime,
  5650. StopReason: item.StopReason,
  5651. StopDoctor: item.StopDoctor,
  5652. StopState: item.StopState,
  5653. ParentId: item.ParentId,
  5654. ExecutionTime: item.ExecutionTime,
  5655. ExecutionStaff: item.ExecutionStaff,
  5656. ExecutionState: item.ExecutionState,
  5657. Checker: item.Checker,
  5658. RecordDate: item.ReminderDate,
  5659. DialysisOrderId: item.DialysisOrderId,
  5660. CheckTime: item.CheckTime,
  5661. CheckState: item.CheckState,
  5662. RemindType: item.RemindType,
  5663. FrequencyType: item.FrequencyType,
  5664. DayCount: item.DayCount,
  5665. WeekDay: item.WeekDay,
  5666. TemplateId: item.TemplateId,
  5667. Modifier: item.Modifier,
  5668. Way: item.Way,
  5669. DrugId: item.DrugId,
  5670. }
  5671. if medical.IsUse == 2 {
  5672. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5673. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5674. }
  5675. if pharmacyConfig.IsOpen != 1 {
  5676. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5677. }
  5678. //更新字典里面的库存
  5679. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5680. var sum_count int64
  5681. for _, its := range stockInfo {
  5682. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5683. if its.MaxUnit == baseDrug.MaxUnit {
  5684. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5685. }
  5686. sum_count += its.StockMaxNumber + its.StockMinNumber
  5687. }
  5688. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5689. //剩余库存
  5690. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5691. }
  5692. info := models.DoctorAdvice{
  5693. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5694. ExecutionTime: exec_time,
  5695. ExecutionState: 1,
  5696. UpdatedTime: time.Now().Unix(),
  5697. }
  5698. //执行医嘱
  5699. service.UpdateDoctorAdviceExecution(info, item.ID)
  5700. }
  5701. }
  5702. this.ServeSuccessJSON(map[string]interface{}{
  5703. "msg": "1",
  5704. })
  5705. return
  5706. }
  5707. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  5708. orgId := this.GetAdminUserInfo().CurrentOrgId
  5709. idsStr := this.GetString("str")
  5710. recordIDStrs := strings.Split(idsStr, ",")
  5711. start_time := this.GetString("advice_date")
  5712. timeLayout := "2006-01-02"
  5713. loc, _ := time.LoadLocation("Local")
  5714. var startTime int64
  5715. if len(start_time) > 0 {
  5716. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5717. if err != nil {
  5718. //fmt.Println(err)
  5719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5720. return
  5721. }
  5722. startTime = theTime.Unix()
  5723. }
  5724. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5725. if config.IsOpen == 1 {
  5726. creater := this.GetAdminUserInfo().AdminUser.Id
  5727. //查询未核对的医嘱
  5728. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5729. for _, item := range advicelist {
  5730. if item.ExecutionStaff == creater {
  5731. this.ServeSuccessJSON(map[string]interface{}{
  5732. "msg": "2",
  5733. "advice": item,
  5734. })
  5735. return
  5736. }
  5737. service.CheckHisDoctorAdvice(item.ID, creater)
  5738. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5739. redis := service.RedisClient()
  5740. //清空key 值
  5741. redis.Set(key, "", time.Second)
  5742. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5743. redis.Set(keyTwo, "", time.Second)
  5744. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5745. redis.Set(keyThree, "", time.Second)
  5746. theTime := time.Now()
  5747. recordDate := theTime.Format("2006-01-02")
  5748. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5749. redis.Set(keyFour, "", time.Second)
  5750. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5751. redis.Set(keyFive, "", time.Second)
  5752. }
  5753. } else {
  5754. //查询未核对的医嘱
  5755. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5756. creater := this.GetAdminUserInfo().AdminUser.Id
  5757. for _, item := range advicelist {
  5758. if item.ExecutionStaff == creater {
  5759. this.ServeSuccessJSON(map[string]interface{}{
  5760. "msg": "2",
  5761. "advice": item,
  5762. })
  5763. return
  5764. }
  5765. service.CheckDoctorAdvice(item.ID, creater)
  5766. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5767. redis := service.RedisClient()
  5768. //清空key 值
  5769. redis.Set(key, "", time.Second)
  5770. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5771. redis.Set(keyTwo, "", time.Second)
  5772. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5773. redis.Set(keyThree, "", time.Second)
  5774. theTime := time.Now()
  5775. recordDate := theTime.Format("2006-01-02")
  5776. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5777. redis.Set(keyFour, "", time.Second)
  5778. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5779. redis.Set(keyFive, "", time.Second)
  5780. }
  5781. }
  5782. this.ServeSuccessJSON(map[string]interface{}{
  5783. "msg": "1",
  5784. })
  5785. return
  5786. }
  5787. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5788. orgId := this.GetAdminUserInfo().CurrentOrgId
  5789. is_open, _ := this.GetInt64("is_open")
  5790. idsStr := this.GetString("str")
  5791. recordIDStrs := strings.Split(idsStr, ",")
  5792. start_time := this.GetString("advice_date")
  5793. timeLayout := "2006-01-02"
  5794. loc, _ := time.LoadLocation("Local")
  5795. var startTime int64
  5796. if len(start_time) > 0 {
  5797. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5798. if err != nil {
  5799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5800. return
  5801. }
  5802. startTime = theTime.Unix()
  5803. }
  5804. if is_open == 1 {
  5805. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5806. } else {
  5807. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5808. }
  5809. this.ServeSuccessJSON(map[string]interface{}{
  5810. "msg": "1",
  5811. })
  5812. return
  5813. }
  5814. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5815. advice_id, _ := this.GetInt64("advice_id")
  5816. start_time := this.GetString("advice_date")
  5817. orgId := this.GetAdminUserInfo().CurrentOrgId
  5818. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5819. exec_time, _ := this.GetInt64("exec_time")
  5820. //his医嘱
  5821. if config.IsOpen == 1 {
  5822. //查询医嘱
  5823. advice, _ := service.GetHisDocById(advice_id, orgId)
  5824. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5825. this.ServeSuccessJSON(map[string]interface{}{
  5826. "msg": "3",
  5827. })
  5828. return
  5829. }
  5830. medical, _ := service.GetBaseDrugMedical(orgId)
  5831. var prescribing_number int64
  5832. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5833. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5834. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5835. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5836. }
  5837. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5838. prescribing_number = parseIntPrescribingNumber
  5839. }
  5840. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5841. prescribing_number = parseIntPrescribingNumber
  5842. }
  5843. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5844. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5845. //库存不足
  5846. if prescribing_number > drugStockOut.FlushCount {
  5847. this.ServeSuccessJSON(map[string]interface{}{
  5848. "msg": "2",
  5849. "drug": medical,
  5850. })
  5851. return
  5852. }
  5853. info := models.HisDoctorAdviceInfo{
  5854. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5855. ExecutionTime: exec_time,
  5856. ExecutionState: 1,
  5857. UpdatedTime: time.Now().Unix(),
  5858. }
  5859. //执行医嘱
  5860. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  5861. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5862. redis := service.RedisClient()
  5863. //清空key 值
  5864. redis.Set(key, "", time.Second)
  5865. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5866. redis.Set(keyTwo, "", time.Second)
  5867. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5868. redis.Set(keyThree, "", time.Second)
  5869. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5870. theTime := toTime.Format("2006-01-02")
  5871. fmt.Println("theTIME", theTime)
  5872. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5873. redis.Set(keyFour, "", time.Second)
  5874. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5875. redis.Set(keyFive, "", time.Second)
  5876. //出库
  5877. if prescribing_number <= drugStockOut.FlushCount {
  5878. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5879. //执行出库逻辑
  5880. hisadvice := &models.HisDoctorAdviceInfo{
  5881. ID: advice.ID,
  5882. UserOrgId: advice.UserOrgId,
  5883. PatientId: advice.PatientId,
  5884. AdviceType: advice.AdviceType,
  5885. AdviceDate: advice.AdviceDate,
  5886. StartTime: advice.StartTime,
  5887. AdviceName: advice.AdviceName,
  5888. AdviceDesc: advice.AdviceDesc,
  5889. ReminderDate: advice.ReminderDate,
  5890. SingleDose: advice.SingleDose,
  5891. SingleDoseUnit: advice.SingleDoseUnit,
  5892. DrugSpec: advice.DrugSpec,
  5893. DrugSpecUnit: advice.DrugSpecUnit,
  5894. PrescribingNumber: advice.PrescribingNumber,
  5895. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5896. DeliveryWay: advice.DeliveryWay,
  5897. ExecutionFrequency: advice.ExecutionFrequency,
  5898. AdviceDoctor: advice.AdviceDoctor,
  5899. Status: 1,
  5900. CreatedTime: advice.CreatedTime,
  5901. UpdatedTime: advice.UpdatedTime,
  5902. AdviceAffirm: advice.AdviceAffirm,
  5903. Remark: advice.Remark,
  5904. StopTime: advice.StopTime,
  5905. StopReason: advice.StopReason,
  5906. StopDoctor: advice.StopDoctor,
  5907. StopState: advice.StopState,
  5908. ParentId: advice.ParentId,
  5909. ExecutionTime: advice.ExecutionTime,
  5910. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5911. ExecutionState: advice.ExecutionState,
  5912. Checker: advice.Checker,
  5913. RecordDate: advice.RecordDate,
  5914. DialysisOrderId: advice.DialysisOrderId,
  5915. CheckTime: advice.CheckTime,
  5916. CheckState: advice.CheckState,
  5917. RemindType: advice.RemindType,
  5918. FrequencyType: advice.FrequencyType,
  5919. DayCount: advice.DayCount,
  5920. WeekDay: advice.WeekDay,
  5921. TemplateId: advice.TemplateId,
  5922. Modifier: advice.Modifier,
  5923. Way: advice.Way,
  5924. DrugId: advice.DrugId,
  5925. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  5926. }
  5927. if medical.IsUse == 2 {
  5928. if config.IsOpen != 1 {
  5929. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5930. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5931. }
  5932. //不通过药房发药
  5933. if pharmacyConfig.IsOpen != 1 {
  5934. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5935. }
  5936. //查询默认仓库
  5937. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  5938. //查询默认仓库剩余多少库存
  5939. var sum_count int64
  5940. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5941. for _, its := range stockInfo {
  5942. if its.MaxUnit == medical.MaxUnit {
  5943. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5944. }
  5945. sum_count += its.StockMaxNumber + its.StockMinNumber
  5946. }
  5947. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5948. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5949. }
  5950. }
  5951. }
  5952. this.ServeSuccessJSON(map[string]interface{}{
  5953. "msg": "1",
  5954. })
  5955. return
  5956. }
  5957. if config.IsOpen == 2 || config.IsOpen == 0 {
  5958. advice, _ := service.GetBloodDocById(advice_id, orgId)
  5959. medical, _ := service.GetBaseDrugMedical(orgId)
  5960. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5961. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5962. var prescribing_number int64
  5963. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5964. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5965. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5966. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5967. }
  5968. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5969. prescribing_number = parseIntPrescribingNumber
  5970. }
  5971. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5972. prescribing_number = parseIntPrescribingNumber
  5973. }
  5974. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5975. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5976. //库存不足
  5977. if prescribing_number > drugStockOut.FlushCount {
  5978. this.ServeSuccessJSON(map[string]interface{}{
  5979. "msg": "2",
  5980. "drug": medical,
  5981. })
  5982. return
  5983. }
  5984. info := models.DoctorAdvice{
  5985. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5986. ExecutionTime: exec_time,
  5987. ExecutionState: 1,
  5988. UpdatedTime: time.Now().Unix(),
  5989. }
  5990. //执行医嘱
  5991. service.UpdateDoctorAdviceExecution(info, advice.ID)
  5992. dadvice := &models.DoctorAdvice{
  5993. ID: advice.ID,
  5994. UserOrgId: advice.UserOrgId,
  5995. PatientId: advice.PatientId,
  5996. AdviceType: advice.AdviceType,
  5997. AdviceDate: advice.AdviceDate,
  5998. StartTime: advice.StartTime,
  5999. AdviceName: advice.AdviceName,
  6000. AdviceDesc: advice.AdviceDesc,
  6001. ReminderDate: advice.ReminderDate,
  6002. SingleDose: advice.SingleDose,
  6003. SingleDoseUnit: advice.SingleDoseUnit,
  6004. DrugSpec: advice.DrugSpec,
  6005. DrugSpecUnit: advice.DrugSpecUnit,
  6006. PrescribingNumber: advice.PrescribingNumber,
  6007. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6008. DeliveryWay: advice.DeliveryWay,
  6009. ExecutionFrequency: advice.ExecutionFrequency,
  6010. AdviceDoctor: advice.AdviceDoctor,
  6011. Status: 1,
  6012. CreatedTime: advice.CreatedTime,
  6013. UpdatedTime: advice.UpdatedTime,
  6014. AdviceAffirm: advice.AdviceAffirm,
  6015. Remark: advice.Remark,
  6016. StopTime: advice.StopTime,
  6017. StopReason: advice.StopReason,
  6018. StopDoctor: advice.StopDoctor,
  6019. StopState: advice.StopState,
  6020. ParentId: advice.ParentId,
  6021. ExecutionTime: advice.ExecutionTime,
  6022. ExecutionStaff: advice.ExecutionStaff,
  6023. ExecutionState: advice.ExecutionState,
  6024. Checker: advice.Checker,
  6025. RecordDate: advice.ReminderDate,
  6026. DialysisOrderId: advice.DialysisOrderId,
  6027. CheckTime: advice.CheckTime,
  6028. CheckState: advice.CheckState,
  6029. RemindType: advice.RemindType,
  6030. FrequencyType: advice.FrequencyType,
  6031. DayCount: advice.DayCount,
  6032. WeekDay: advice.WeekDay,
  6033. TemplateId: advice.TemplateId,
  6034. Modifier: advice.Modifier,
  6035. Way: advice.Way,
  6036. DrugId: advice.DrugId,
  6037. }
  6038. if medical.IsUse == 2 {
  6039. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6040. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6041. }
  6042. if pharmacyConfig.IsOpen != 1 {
  6043. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6044. }
  6045. //更新字典里面的库存
  6046. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6047. var sum_count int64
  6048. for _, its := range stockInfo {
  6049. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  6050. if its.MaxUnit == baseDrug.MaxUnit {
  6051. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  6052. }
  6053. sum_count += its.StockMaxNumber + its.StockMinNumber
  6054. }
  6055. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6056. //剩余库存
  6057. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6058. }
  6059. }
  6060. this.ServeSuccessJSON(map[string]interface{}{
  6061. "msg": "1",
  6062. })
  6063. return
  6064. }
  6065. func (this *DialysisApiController) GetDialysisAdviceToday() {
  6066. orgId := this.GetAdminUserInfo().CurrentOrgId
  6067. schedule_type, _ := this.GetInt64("schedule_type")
  6068. //partion_type, _ := this.GetInt64("partion_type")
  6069. partion_type := this.GetString("partion_type")
  6070. var ids []string
  6071. ids = strings.Split(partion_type, ",")
  6072. start_time := this.GetString("selected_date")
  6073. timeLayout := "2006-01-02"
  6074. loc, _ := time.LoadLocation("Local")
  6075. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6076. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6077. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6078. _, config := service.FindXTHisRecordByOrgId(orgId)
  6079. appId := this.GetAdminUserInfo().CurrentAppId
  6080. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6081. if err == nil {
  6082. this.ServeSuccessJSON(map[string]interface{}{
  6083. "list": list,
  6084. "drug": drug,
  6085. "config": config,
  6086. "doctorList": doctorList,
  6087. })
  6088. return
  6089. } else {
  6090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6091. return
  6092. }
  6093. }
  6094. func (this *DialysisApiController) GetMobileScheduleList() {
  6095. orgId := this.GetAdminUserInfo().CurrentOrgId
  6096. schedule, _ := service.GetMobileScheduleList(orgId)
  6097. if len(schedule) > 0 {
  6098. for _, its := range schedule {
  6099. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6100. //its.DialysisPrescription = prescription
  6101. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6102. //its.MonitoringRecord = monitor
  6103. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6104. //its.XtAssessmentAfterDislysis = after
  6105. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  6106. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  6107. }
  6108. }
  6109. this.ServeSuccessJSON(map[string]interface{}{
  6110. "schedule": schedule,
  6111. })
  6112. return
  6113. }
  6114. func (this *DialysisApiController) SaveDialysisInformationSetting() {
  6115. week_day, _ := this.GetInt64("week_day")
  6116. orgId := this.GetAdminUserInfo().CurrentOrgId
  6117. informaitonSetting := models.XtDialysisInformaitonSetting{
  6118. WeekDay: week_day,
  6119. UserOrgId: orgId,
  6120. Status: 1,
  6121. Ctime: time.Now().Unix(),
  6122. Mtime: 0,
  6123. }
  6124. information, _ := service.GetInformationSettingByOrgId(orgId)
  6125. if information.ID == 0 {
  6126. service.CreateInformationSetting(informaitonSetting)
  6127. }
  6128. if information.ID > 0 {
  6129. service.UpdateInformationSettingById(orgId, week_day)
  6130. }
  6131. this.ServeSuccessJSON(map[string]interface{}{
  6132. "informaitonSetting": informaitonSetting,
  6133. })
  6134. return
  6135. }
  6136. func (this *DialysisApiController) GetDialysisInformationSetting() {
  6137. orgId := this.GetAdminUserInfo().CurrentOrgId
  6138. limit, _ := this.GetInt64("limit")
  6139. page, _ := this.GetInt64("page")
  6140. informationSetting, _ := service.GetDialysisInformationSettingList(orgId)
  6141. //未审核
  6142. infor, total, _ := service.GetDialysisInformationIsNoCheck(orgId, limit, page, 2)
  6143. //全部
  6144. inforList, totalOne, _ := service.GetDialysisInformationIsNoCheckOne(orgId, limit, page, 1)
  6145. patients, _ := service.GetAllpatientThirty(orgId)
  6146. appId := this.GetAdminUserInfo().CurrentAppId
  6147. role, _ := service.GetAllDoctorListSix(orgId, appId)
  6148. this.ServeSuccessJSON(map[string]interface{}{
  6149. "informaitonSetting": informationSetting,
  6150. "infor": infor,
  6151. "total": total,
  6152. "totalOne": totalOne,
  6153. "inforList": inforList,
  6154. "patients": patients,
  6155. "adminList": role,
  6156. })
  6157. return
  6158. }
  6159. func (this *DialysisApiController) CheckDialysisInformation() {
  6160. id, _ := this.GetInt64("id")
  6161. application_status, _ := this.GetInt64("application_status")
  6162. timeNow := time.Now().Unix()
  6163. checker := this.GetAdminUserInfo().AdminUser.Id
  6164. information, _ := service.CheckDialysisInformation(id, application_status, timeNow, checker)
  6165. this.ServeSuccessJSON(map[string]interface{}{
  6166. "information": information,
  6167. })
  6168. return
  6169. }
  6170. func (this *DialysisApiController) GetDialysisPatientsFlow() {
  6171. page, _ := this.GetInt64("page", 1)
  6172. limit, _ := this.GetInt64("limit", 10)
  6173. schedulType, _ := this.GetInt64("schedul_type", 0)
  6174. startTime, _ := this.GetInt64("schedul_time", 0)
  6175. partitionType, _ := this.GetInt64("partition_type", 0)
  6176. keywords := this.GetString("keywords")
  6177. start_time, _ := this.GetInt64("start_time")
  6178. end_time, _ := this.GetInt64("end_time")
  6179. adminUserInfo := this.GetAdminUserInfo()
  6180. if len(keywords) > 0 {
  6181. dialysisSchedule, err, total := service.GetDialysisWatchByKeywordFlow(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6182. if err == nil {
  6183. this.ServeSuccessJSON(map[string]interface{}{
  6184. "schedule": dialysisSchedule,
  6185. "total": total,
  6186. })
  6187. } else {
  6188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6189. }
  6190. } else {
  6191. dialysisSchedule, err, total := service.GetDialysisWatchFlow(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6192. fmt.Println("dialysisSchedule-----------------------", dialysisSchedule)
  6193. if err == nil {
  6194. this.ServeSuccessJSON(map[string]interface{}{
  6195. "schedule": dialysisSchedule,
  6196. "total": total,
  6197. })
  6198. } else {
  6199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6200. }
  6201. }
  6202. }
  6203. func (this *DialysisApiController) SaveInformation() {
  6204. patient_id, _ := this.GetInt64("patient_id")
  6205. record_date, _ := this.GetInt64("record_date")
  6206. startTime := this.GetString("selected_date")
  6207. timeLayout := "2006-01-02 15:04"
  6208. loc, _ := time.LoadLocation("Local")
  6209. if len(startTime) == 0 {
  6210. utils.ErrorLog("len(start_time) == 0")
  6211. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6212. return
  6213. }
  6214. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  6215. if err != nil {
  6216. utils.ErrorLog(err.Error())
  6217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6218. return
  6219. }
  6220. StartTime := theTime.Unix()
  6221. fmt.Println("startime-------------", StartTime)
  6222. module, _ := this.GetInt64("module")
  6223. remark := this.GetString("remark")
  6224. orgId := this.GetAdminUserInfo().CurrentOrgId
  6225. creater := this.GetAdminUserInfo().AdminUser.Id
  6226. information := models.XtDialysisInformation{
  6227. Module: module,
  6228. PatientId: patient_id,
  6229. RecordDate: record_date,
  6230. ApplicationDate: StartTime,
  6231. Creater: creater,
  6232. ApplicationStatus: 2,
  6233. Checker: 0,
  6234. CheckTime: 0,
  6235. Remark: remark,
  6236. UserOrgId: orgId,
  6237. Ctime: time.Now().Unix(),
  6238. Status: 1,
  6239. Mtime: 0,
  6240. }
  6241. infor, _ := service.GetDialysisInoformationById(patient_id, record_date, orgId, module)
  6242. if infor.ID == 0 {
  6243. err := service.CreatedDialysisInformation(information)
  6244. if err == nil {
  6245. this.ServeSuccessJSON(map[string]interface{}{
  6246. "information": information,
  6247. })
  6248. return
  6249. }
  6250. }
  6251. if infor.ID > 0 {
  6252. err := service.UpdateDialysisInformationById(patient_id, record_date, orgId, module, StartTime, remark)
  6253. if err == nil {
  6254. this.ServeSuccessJSON(map[string]interface{}{
  6255. "information": information,
  6256. })
  6257. return
  6258. }
  6259. }
  6260. }
  6261. func (this *DialysisApiController) GetLongDialysisAdviceToday() {
  6262. orgId := this.GetAdminUserInfo().CurrentOrgId
  6263. schedule_type, _ := this.GetInt64("schedule_type")
  6264. partion_type := this.GetString("partion_type")
  6265. var ids []string
  6266. ids = strings.Split(partion_type, ",")
  6267. start_time := this.GetString("selected_date")
  6268. timeLayout := "2006-01-02"
  6269. loc, _ := time.LoadLocation("Local")
  6270. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6271. list, err := service.GetLongDialysisAdviceToday(orgId, schedule_type, ids, startTime.Unix())
  6272. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6273. _, config := service.FindXTHisRecordByOrgId(orgId)
  6274. appId := this.GetAdminUserInfo().CurrentAppId
  6275. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6276. if err == nil {
  6277. this.ServeSuccessJSON(map[string]interface{}{
  6278. "list": list,
  6279. "drug": drug,
  6280. "config": config,
  6281. "doctorList": doctorList,
  6282. })
  6283. return
  6284. } else {
  6285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6286. return
  6287. }
  6288. }
  6289. func (this *DialysisApiController) GetPatientList() {
  6290. orgId := this.GetAdminUserInfo().CurrentOrgId
  6291. keyWord := this.GetString("keyword")
  6292. patientList, err := service.GetPrescriptionPatientList(orgId, keyWord)
  6293. if err == nil {
  6294. this.ServeSuccessJSON(map[string]interface{}{
  6295. "patientList": patientList,
  6296. })
  6297. return
  6298. } else {
  6299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6300. return
  6301. }
  6302. }
  6303. func (this *DialysisApiController) GetPrescriptionLogList() {
  6304. patient_id, _ := this.GetInt64("patient_id")
  6305. record_date := this.GetString("record_date")
  6306. page, _ := this.GetInt64("page")
  6307. limit, _ := this.GetInt64("limit")
  6308. orgId := this.GetAdminUserInfo().CurrentOrgId
  6309. timeLayout := "2006-01-02"
  6310. loc, _ := time.LoadLocation("Local")
  6311. var recordDateTime int64
  6312. if len(record_date) > 0 {
  6313. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6314. if err != nil {
  6315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6316. return
  6317. }
  6318. recordDateTime = theTime.Unix()
  6319. }
  6320. prescriptionlogList, total, err := service.GetPrescriptionLogList(patient_id, page, limit, recordDateTime, orgId)
  6321. patients, _ := service.GetAllPatientLog(orgId)
  6322. role, _ := service.GetAllDoctorLog(orgId)
  6323. if err == nil {
  6324. this.ServeSuccessJSON(map[string]interface{}{
  6325. "prescriptionlogList": prescriptionlogList,
  6326. "total": total,
  6327. "patients": patients,
  6328. "role": role,
  6329. })
  6330. return
  6331. } else {
  6332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6333. return
  6334. }
  6335. }
  6336. func (this *DialysisApiController) GetBeforLogList() {
  6337. patient_id, _ := this.GetInt64("patient_id")
  6338. record_date := this.GetString("record_date")
  6339. page, _ := this.GetInt64("page")
  6340. limit, _ := this.GetInt64("limit")
  6341. orgId := this.GetAdminUserInfo().CurrentOrgId
  6342. timeLayout := "2006-01-02"
  6343. loc, _ := time.LoadLocation("Local")
  6344. var recordDateTime int64
  6345. if len(record_date) > 0 {
  6346. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6347. if err != nil {
  6348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6349. return
  6350. }
  6351. recordDateTime = theTime.Unix()
  6352. }
  6353. beforLogList, total, err := service.GetBeforLogList(patient_id, page, limit, recordDateTime, orgId)
  6354. patients, _ := service.GetAllPatientLog(orgId)
  6355. role, _ := service.GetAllDoctorLog(orgId)
  6356. if err == nil {
  6357. this.ServeSuccessJSON(map[string]interface{}{
  6358. "beforLogList": beforLogList,
  6359. "total": total,
  6360. "patients": patients,
  6361. "role": role,
  6362. })
  6363. return
  6364. } else {
  6365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6366. return
  6367. }
  6368. }
  6369. func (this *DialysisApiController) GetDocLogList() {
  6370. patient_id, _ := this.GetInt64("patient_id")
  6371. record_date := this.GetString("record_date")
  6372. page, _ := this.GetInt64("page")
  6373. limit, _ := this.GetInt64("limit")
  6374. orgId := this.GetAdminUserInfo().CurrentOrgId
  6375. timeLayout := "2006-01-02"
  6376. loc, _ := time.LoadLocation("Local")
  6377. var recordDateTime int64
  6378. if len(record_date) > 0 {
  6379. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6380. if err != nil {
  6381. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6382. return
  6383. }
  6384. recordDateTime = theTime.Unix()
  6385. }
  6386. adviceLogList, total, err := service.GetDocLogList(patient_id, page, limit, recordDateTime, orgId)
  6387. patients, _ := service.GetAllPatientLog(orgId)
  6388. role, _ := service.GetAllDoctorLog(orgId)
  6389. if err == nil {
  6390. this.ServeSuccessJSON(map[string]interface{}{
  6391. "adviceLogList": adviceLogList,
  6392. "total": total,
  6393. "patients": patients,
  6394. "role": role,
  6395. })
  6396. return
  6397. } else {
  6398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6399. return
  6400. }
  6401. }
  6402. func (this *DialysisApiController) GetMonitorLogList() {
  6403. patient_id, _ := this.GetInt64("patient_id")
  6404. record_date := this.GetString("record_date")
  6405. page, _ := this.GetInt64("page")
  6406. limit, _ := this.GetInt64("limit")
  6407. orgId := this.GetAdminUserInfo().CurrentOrgId
  6408. timeLayout := "2006-01-02"
  6409. loc, _ := time.LoadLocation("Local")
  6410. var recordDateTime int64
  6411. if len(record_date) > 0 {
  6412. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6413. if err != nil {
  6414. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6415. return
  6416. }
  6417. recordDateTime = theTime.Unix()
  6418. }
  6419. monitorLogList, total, err := service.GetMonitorLogList(patient_id, page, limit, recordDateTime, orgId)
  6420. patients, _ := service.GetAllPatientLog(orgId)
  6421. role, _ := service.GetAllDoctorLog(orgId)
  6422. if err == nil {
  6423. this.ServeSuccessJSON(map[string]interface{}{
  6424. "monitorLogList": monitorLogList,
  6425. "total": total,
  6426. "patients": patients,
  6427. "role": role,
  6428. })
  6429. return
  6430. } else {
  6431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6432. return
  6433. }
  6434. }
  6435. func (this *DialysisApiController) GetAfterLogList() {
  6436. patient_id, _ := this.GetInt64("patient_id")
  6437. record_date := this.GetString("record_date")
  6438. page, _ := this.GetInt64("page")
  6439. limit, _ := this.GetInt64("limit")
  6440. orgId := this.GetAdminUserInfo().CurrentOrgId
  6441. timeLayout := "2006-01-02"
  6442. loc, _ := time.LoadLocation("Local")
  6443. var recordDateTime int64
  6444. if len(record_date) > 0 {
  6445. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6446. if err != nil {
  6447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6448. return
  6449. }
  6450. recordDateTime = theTime.Unix()
  6451. }
  6452. afterLogList, total, err := service.GetAfterLogList(patient_id, page, limit, recordDateTime, orgId)
  6453. patients, _ := service.GetAllPatientLog(orgId)
  6454. role, _ := service.GetAllDoctorLog(orgId)
  6455. if err == nil {
  6456. this.ServeSuccessJSON(map[string]interface{}{
  6457. "afterLogList": afterLogList,
  6458. "total": total,
  6459. "patients": patients,
  6460. "role": role,
  6461. })
  6462. return
  6463. } else {
  6464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6465. return
  6466. }
  6467. }