dialysis_api_controller.go 289KB

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