dialysis_api_controller.go 273KB

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