dialysis_api_controller.go 293KB

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