dialysis_api_controller.go 429KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. fmt.Print("projectOne------------------------", projectsOne)
  468. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  469. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  470. var team_projects []*models.HisPrescriptionProject
  471. //var index int64 = 0
  472. for _, item := range temp_team_projects {
  473. //组套里面非检验项目的
  474. if item.HisProject.CostClassify != 3 {
  475. projects = append(projects, item)
  476. }
  477. //组套里面检验项目的
  478. if item.HisProject.CostClassify == 3 {
  479. team_projects = append(team_projects, item)
  480. }
  481. }
  482. //针对茂名舒和
  483. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  484. if len(projects) > 0 {
  485. for _, item := range projects {
  486. if item.Type == 2 {
  487. if item.HisProject.IsShow == 1 {
  488. projectsOne = append(projectsOne, item)
  489. }
  490. }
  491. if item.Type == 3 {
  492. if item.GoodInfo.IsShow == 1 {
  493. projectsOne = append(projectsOne, item)
  494. }
  495. }
  496. }
  497. }
  498. } else {
  499. for _, item := range projects {
  500. projectsOne = append(projectsOne, item)
  501. }
  502. }
  503. team_projects = RemoveRepeatedCheckRecod(team_projects)
  504. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  505. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  506. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  507. var his_advices []*models.HisDoctorAdviceInfo
  508. var his_advices_one []*models.HisDoctorAdviceInfo
  509. if is_open_config.IsOpen == 1 {
  510. // 先走redis,没有走数据库
  511. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  512. }
  513. //针对茂名舒和
  514. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  515. if len(his_advices) > 0 {
  516. for _, item := range his_advices {
  517. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  518. if drug.IsShow == 1 {
  519. his_advices_one = append(his_advices_one, item)
  520. }
  521. }
  522. }
  523. } else {
  524. if len(his_advices) > 0 {
  525. for _, item := range his_advices {
  526. his_advices_one = append(his_advices_one, item)
  527. }
  528. }
  529. }
  530. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  531. if is_advice_open.IsAdviceOpen == 1 {
  532. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  533. }
  534. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  535. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  536. var remind_lists []models.XtCheckRemind
  537. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  538. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  539. }
  540. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  541. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  542. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  543. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  544. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  545. returnData := map[string]interface{}{
  546. "patient": patient,
  547. "schedual": schedual,
  548. "prescription": dialysisPrescribe,
  549. "solution": dialysisSolution,
  550. "last_prescription": lastDialysisPrescribe,
  551. "receiver_treatment_access": receiverTreatmentAccess,
  552. "predialysis_evaluation": predialysisEvaluation,
  553. "doctor_advices": doctorAdvices,
  554. "double_check": doubleCheck,
  555. "assessment_after_dislysis": assessmentAfterDislysis,
  556. "treatment_summary": treatmentSummary,
  557. "monitor_records": monitorRecords,
  558. "dialysis_order": dialysisOrder,
  559. "operators": operators,
  560. "last_predialysis_evaluation": lastPredialysisEvaluation,
  561. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  562. "last_monitor_record": lastMonitorRecord,
  563. "config": gobalConfig,
  564. "dry_weight": lastDryWeightDislysis,
  565. "system_prescription": systemDialysisPrescribe,
  566. "his_advices": his_advices_one,
  567. "is_open_config": is_open_config,
  568. "stockType": stockType,
  569. "prepare": prepare,
  570. "lastAssessment": lastAssessment,
  571. "prescribeOne": prescribeOne,
  572. "is_project_open_config": is_project_open_config,
  573. "project": projectsOne,
  574. "team_projects": team_projects,
  575. "is_advice_open": is_advice_open,
  576. "prescription_open": prescriptionConfig.IsOpen,
  577. "lastOrder": lastOrder,
  578. "remind_lists": remind_lists,
  579. "lastDialysisPrescription": lastDialysisPrescription,
  580. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  581. "dryWeightList": dryWeightList,
  582. "firstMonitor": firstMonitor,
  583. "lastMonitor": lastMonitor,
  584. }
  585. this.ServeSuccessJSON(returnData)
  586. }
  587. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  588. adminInfo := c.GetMobileAdminUserInfo()
  589. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  590. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  591. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  592. returnData := map[string]interface{}{
  593. "admin_users": adminUsers,
  594. "devices": devices,
  595. "device_numbers": device_numbers,
  596. }
  597. c.ServeSuccessJSON(returnData)
  598. }
  599. func (c *DialysisAPIController) PostAtreatmentInfo() {
  600. id, _ := c.GetInt64("patient", 0)
  601. recordDateStr := c.GetString("record_date")
  602. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  603. summaryContent := c.GetString("summaryContent")
  604. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  605. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  606. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  607. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  608. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  609. nursingRecord := c.GetString("nursing_record")
  610. fmt.Println("护理记录", nursingRecord)
  611. specialRecord := c.GetString("special_record")
  612. fmt.Println("特殊记录", specialRecord)
  613. adminUserInfo := c.GetMobileAdminUserInfo()
  614. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  615. checkStaffId = adminUserInfo.AdminUser.Id
  616. deboardNurseId = adminUserInfo.AdminUser.Id
  617. treatDoctor = adminUserInfo.AdminUser.Id
  618. if id <= 0 {
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  620. return
  621. }
  622. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  623. if patient.ID == 0 {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  625. return
  626. }
  627. if len(recordDateStr) == 0 {
  628. recordDateStr = time.Now().Format("2006-01-02")
  629. }
  630. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  631. if parseDateErr != nil {
  632. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  634. return
  635. }
  636. summary := models.TreatmentSummary{
  637. UserOrgId: adminUserInfo.Org.Id,
  638. PatientId: id,
  639. AssessmentDate: recordDate.Unix(),
  640. Mission: propagandaAndEducationContent,
  641. DialysisSummary: summaryContent,
  642. SjNurse: changeMedicalNurseId,
  643. ZlNurse: treatNurseId,
  644. HdNurse: checkStaffId,
  645. XjNurse: deboardNurseId,
  646. ZlDoctor: treatDoctor,
  647. CreatedTime: time.Now().Unix(),
  648. Status: 1,
  649. NursingRecord: nursingRecord,
  650. SpecialRecord: specialRecord,
  651. }
  652. // 查询信息规挡的设置天数
  653. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  654. if infor.ID > 0 && infor.WeekDay > 0 {
  655. var cha_time int64
  656. timeNowStr := time.Now().Format("2006-01-02")
  657. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  658. //今日的日期减去设置的日期
  659. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  660. if cha_time >= recordDate.Unix() {
  661. //查询审核是否允许
  662. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  663. //申请状态不允许的情况 拒绝修改
  664. if infor.ApplicationStatus != 1 {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  666. return
  667. }
  668. }
  669. }
  670. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  671. if treatmentSummary.ID == 0 { //新增
  672. summary.Creater = adminUserInfo.AdminUser.Id
  673. service.AddSigleSummaryRecord(&summary)
  674. finish := models.XtDialysisFinish{
  675. IsFinish: 1,
  676. UserOrgId: adminUserInfo.Org.Id,
  677. Status: 1,
  678. Ctime: time.Now().Unix(),
  679. Mtime: 0,
  680. Module: 10,
  681. RecordDate: recordDate.Unix(),
  682. Sourse: 1,
  683. PatientId: id,
  684. }
  685. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  686. if dialysisFinish.ID == 0 {
  687. service.CreateDialysisFinish(finish)
  688. }
  689. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  690. redis := service.RedisClient()
  691. //清空key 值
  692. redis.Set(key, "", time.Second)
  693. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  694. redis.Set(keyOne, "", time.Second)
  695. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  696. redis.Set(keyThree, "", time.Second)
  697. defer redis.Close()
  698. c.ServeSuccessJSON(map[string]interface{}{
  699. "summary": summary,
  700. })
  701. } else { //修改
  702. summary.Creater = treatmentSummary.Creater
  703. summary.CreatedTime = treatmentSummary.CreatedTime
  704. summary.Modifier = adminUserInfo.AdminUser.Id
  705. summary.ID = treatmentSummary.ID
  706. service.UpdateSummeRecord(&summary)
  707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  708. redis := service.RedisClient()
  709. //清空key 值
  710. redis.Set(key, "", time.Second)
  711. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  712. redis.Set(keyOne, "", time.Second)
  713. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  714. redis.Set(keyThree, "", time.Second)
  715. defer redis.Close()
  716. c.ServeSuccessJSON(map[string]interface{}{
  717. "summary": summary,
  718. })
  719. }
  720. }
  721. func (c *DialysisAPIController) PostDoubleCheck() {
  722. id, _ := c.GetInt64("patient", 0)
  723. recordDateStr := c.GetString("record_date")
  724. checkTimeStr := c.GetString("check_time")
  725. firstCheckTimeStr := c.GetString("first_check_time")
  726. creater, _ := c.GetInt64("creater", 0)
  727. modifier, _ := c.GetInt64("modifier", 0)
  728. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  729. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  730. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  731. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  732. dialysis_item_desc := c.GetString("dialysis_item_desc")
  733. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  734. vascular_access_desc := c.GetString("vascular_access_desc")
  735. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  736. collator, _ := c.GetInt64("collator", 0)
  737. employee_number := c.GetString("employee_number")
  738. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  739. needle_batch_number := c.GetString("needle_batch_number")
  740. if id <= 0 {
  741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  742. return
  743. }
  744. adminUserInfo := c.GetMobileAdminUserInfo()
  745. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  746. if patient.ID == 0 {
  747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  748. return
  749. }
  750. if len(recordDateStr) == 0 {
  751. recordDateStr = time.Now().Format("2006-01-02")
  752. }
  753. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  754. if parseDateErr != nil {
  755. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  757. return
  758. }
  759. var checkDate int64
  760. if len(checkTimeStr) == 0 {
  761. checkDate = 0
  762. } else {
  763. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  764. checkDate = checkDateUnix.Unix()
  765. }
  766. var firstCheckDate int64
  767. if len(firstCheckTimeStr) == 0 {
  768. firstCheckDate = 0
  769. } else {
  770. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  771. firstCheckDate = firstCheckDateUnix.Unix()
  772. }
  773. if adminUserInfo.Org.Id == 10644 {
  774. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  775. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  776. if check.ID == 0 {
  777. if employee_number != list.JobNumber {
  778. c.ServeSuccessJSON(map[string]interface{}{
  779. "doubleCheck": check,
  780. "msg": "2",
  781. })
  782. return
  783. }
  784. }
  785. if check.ID > 0 {
  786. if employee_number != list.JobNumber {
  787. c.ServeSuccessJSON(map[string]interface{}{
  788. "doubleCheck": check,
  789. "msg": "2",
  790. })
  791. return
  792. }
  793. }
  794. }
  795. doubleCheck := models.DoubleCheck{
  796. UserOrgId: adminUserInfo.Org.Id,
  797. PatientId: id,
  798. DialysisItemCheck: dialysis_item_check,
  799. DialysisParameterCheck: dialysis_parameter_check,
  800. VascularAccessVerification: vascular_access_verification,
  801. PipelineConnectionCheck: pipeline_connection_check,
  802. DialysisItemDesc: dialysis_item_desc,
  803. DialysisParameterDesc: dialysis_parameter_desc,
  804. VascularAccessDesc: vascular_access_desc,
  805. PipelineConnectionDesc: pipeline_connection_desc,
  806. Collator: collator,
  807. Status: 1,
  808. CreatedTime: time.Now().Unix(),
  809. CheckDate: recordDate.Unix(),
  810. UpdatedTime: time.Now().Unix(),
  811. EmployeeNumber: employee_number,
  812. DialyzerBatchNumber: dialyzer_batch_number,
  813. NeedleBatchNumber: needle_batch_number,
  814. }
  815. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  816. if check.ID == 0 { //新增
  817. doubleCheck.FirstCheckTime = firstCheckDate
  818. doubleCheck.CheckTime = checkDate
  819. doubleCheck.Creater = creater
  820. doubleCheck.Modifier = modifier
  821. if adminUserInfo.Org.Id == 10340 {
  822. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  823. doubleCheck.Creater = order.StartNurse
  824. }
  825. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  826. //查询未核对的医嘱
  827. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  828. for _, advice := range doctorList {
  829. if advice.ExecutionStaff == modifier {
  830. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  831. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  832. return
  833. }
  834. }
  835. }
  836. // 查询信息规挡的设置天数
  837. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  838. if infor.ID > 0 && infor.WeekDay > 0 {
  839. var cha_time int64
  840. timeNowStr := time.Now().Format("2006-01-02")
  841. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  842. //今日的日期减去设置的日期
  843. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  844. if cha_time >= recordDate.Unix() {
  845. //查询审核是否允许
  846. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  847. //申请状态不允许的情况 拒绝修改
  848. if infor.ApplicationStatus != 1 {
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  850. return
  851. }
  852. }
  853. }
  854. err := service.AddSigleDoubleCheck(&doubleCheck)
  855. finish := models.XtDialysisFinish{
  856. IsFinish: 1,
  857. UserOrgId: adminUserInfo.Org.Id,
  858. Status: 1,
  859. Ctime: time.Now().Unix(),
  860. Mtime: 0,
  861. Module: 5,
  862. RecordDate: recordDate.Unix(),
  863. Sourse: 1,
  864. PatientId: id,
  865. }
  866. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  867. if dialysisFinish.ID == 0 {
  868. service.CreateDialysisFinish(finish)
  869. }
  870. //针对长沙南雅
  871. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  872. //查询未核对的医嘱
  873. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  874. if len(doctorList) > 0 && modifier > 0 {
  875. for _, advice := range doctorList {
  876. service.UpdateDoctorAdviceList(advice.ID, modifier)
  877. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  878. redis := service.RedisClient()
  879. //清空key 值
  880. redis.Set(key, "", time.Second)
  881. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  882. redis.Set(keyTwo, "", time.Second)
  883. theTime := time.Now()
  884. recordDate := theTime.Format("2006-01-02")
  885. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  886. redis.Set(keyFour, "", time.Second)
  887. defer redis.Close()
  888. }
  889. }
  890. }
  891. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  892. redis := service.RedisClient()
  893. //清空key 值
  894. redis.Set(key, "", time.Second)
  895. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  896. redis.Set(keyOne, "", time.Second)
  897. defer redis.Close()
  898. if err == nil {
  899. c.ServeSuccessJSON(map[string]interface{}{
  900. "doubleCheck": &doubleCheck,
  901. })
  902. }
  903. } else { //修改
  904. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  905. if infor.ID > 0 {
  906. var cha_time int64
  907. timeNowStr := time.Now().Format("2006-01-02")
  908. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  909. //今日的日期减去设置的日期
  910. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  911. if cha_time >= recordDate.Unix() {
  912. //查询审核是否允许
  913. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  914. //申请状态不允许的情况 拒绝修改
  915. if infor.ApplicationStatus != 1 {
  916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  917. return
  918. }
  919. }
  920. }
  921. doubleCheck.FirstCheckTime = firstCheckDate
  922. doubleCheck.CheckTime = checkDate
  923. doubleCheck.Creater = creater
  924. doubleCheck.Modifier = modifier
  925. doubleCheck.CreatedTime = check.CreatedTime
  926. doubleCheck.ID = check.ID
  927. doubleCheck.EmployeeNumber = employee_number
  928. doubleCheck.NeedleBatchNumber = needle_batch_number
  929. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  930. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  931. //查询未核对的医嘱
  932. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  933. for _, advice := range doctorList {
  934. if advice.ExecutionStaff == modifier {
  935. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  936. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  937. return
  938. }
  939. }
  940. }
  941. err := service.UpdateDoubleCheck(&doubleCheck)
  942. //针对长沙南雅
  943. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  944. //查询未核对的医嘱
  945. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  946. if len(doctorList) > 0 && modifier > 0 {
  947. for _, advice := range doctorList {
  948. service.UpdateDoctorAdviceList(advice.ID, modifier)
  949. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  950. redis := service.RedisClient()
  951. //清空key 值
  952. redis.Set(key, "", time.Second)
  953. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  954. redis.Set(keyTwo, "", time.Second)
  955. theTime := time.Now()
  956. recordDate := theTime.Format("2006-01-02")
  957. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  958. redis.Set(keyFour, "", time.Second)
  959. defer redis.Close()
  960. }
  961. }
  962. }
  963. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  964. redis := service.RedisClient()
  965. //清空key 值
  966. redis.Set(key, "", time.Second)
  967. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  968. redis.Set(keyOne, "", time.Second)
  969. defer redis.Close()
  970. if err == nil {
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "doubleCheck": &doubleCheck,
  973. "msg": "1",
  974. })
  975. }
  976. }
  977. }
  978. func (c *DialysisAPIController) PostAcceptsAssessment() {
  979. id, _ := c.GetInt64("patient", 0)
  980. recordDateStr := c.GetString("record_date")
  981. way, _ := c.GetInt64("way", 0)
  982. consciousness, _ := c.GetInt64("consciousness", 0)
  983. appetite, _ := c.GetInt64("appetite", 0)
  984. condition, _ := c.GetInt64("condition", 0)
  985. posture, _ := c.GetInt64("posture")
  986. sick_condition, _ := c.GetInt64("sick_condition", 0)
  987. danger_level, _ := c.GetInt64("danger_level", 0)
  988. intake, _ := c.GetInt64("intake", 0)
  989. nutrition, _ := c.GetInt64("nutrition", 0)
  990. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  991. psychological_assessment_other := c.GetString("psychological_assessment_other")
  992. score := c.GetString("score")
  993. sick_condition_other := c.GetString("sick_condition_other")
  994. //precaution, _ := c.GetInt64("precaution", 0)
  995. precaution := c.GetString("precaution")
  996. precaution_other := c.GetString("precaution_other")
  997. psychological_other := c.GetString("psychological_other")
  998. admission_number := c.GetString("admission_number")
  999. tumble, _ := c.GetInt64("tumble")
  1000. diacrisis := c.GetString("diacrisis")
  1001. his_department := c.GetString("his_department")
  1002. his_bed := c.GetString("his_bed")
  1003. if id <= 0 {
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1005. return
  1006. }
  1007. adminUserInfo := c.GetMobileAdminUserInfo()
  1008. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1009. if patient.ID == 0 {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1011. return
  1012. }
  1013. //now := time.Now()
  1014. //year, month, day := now.Date()
  1015. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1016. //todayTimeStamp := today_time.Unix()
  1017. if len(recordDateStr) == 0 {
  1018. recordDateStr = time.Now().Format("2006-01-02")
  1019. }
  1020. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1021. if parseDateErr != nil {
  1022. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. // 查询信息规挡的设置天数
  1027. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1028. if infor.ID > 0 && infor.WeekDay > 0 {
  1029. var cha_time int64
  1030. timeNowStr := time.Now().Format("2006-01-02")
  1031. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1032. //今日的日期减去设置的日期
  1033. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1034. if cha_time >= recordDate.Unix() {
  1035. //查询审核是否允许
  1036. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1037. //申请状态不允许的情况 拒绝修改
  1038. if infor.ApplicationStatus != 1 {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1040. return
  1041. }
  1042. }
  1043. }
  1044. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1045. if adminUserInfo.Org.Id == 10340 {
  1046. if condition == 1 {
  1047. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1048. if admission_number == "" {
  1049. admission_number = lastAcceptTreatment.AdmissionNumber
  1050. }
  1051. }
  1052. }
  1053. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1054. UserOrgId: adminUserInfo.Org.Id,
  1055. PatientId: id,
  1056. RecordDate: recordDate.Unix(),
  1057. Way: way,
  1058. Consciousness: consciousness,
  1059. Appetite: appetite,
  1060. Condition: condition,
  1061. SickCondition: sick_condition,
  1062. DangerLevel: danger_level,
  1063. Intake: intake,
  1064. Nutrition: nutrition,
  1065. PsychologicalAssessment: psychological_assessment,
  1066. PsychologicalAssessmentOther: psychological_assessment_other,
  1067. SickConditionOther: sick_condition_other,
  1068. Posture: posture,
  1069. CreatedTime: time.Now().Unix(),
  1070. UpdateTime: time.Now().Unix(),
  1071. Status: 1,
  1072. Score: score,
  1073. Precaution: precaution,
  1074. PrecautionOther: precaution_other,
  1075. PsychologicalOther: psychological_other,
  1076. AdmissionNumber: admission_number,
  1077. Tumble: tumble,
  1078. Diacrisis: diacrisis,
  1079. HisBed: his_bed,
  1080. HisDepartment: his_department,
  1081. }
  1082. if receiveTreatment.ID == 0 { //新增
  1083. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1084. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1085. finish := models.XtDialysisFinish{
  1086. IsFinish: 1,
  1087. UserOrgId: adminUserInfo.Org.Id,
  1088. Status: 1,
  1089. Ctime: time.Now().Unix(),
  1090. Mtime: 0,
  1091. Module: 2,
  1092. RecordDate: recordDate.Unix(),
  1093. Sourse: 1,
  1094. PatientId: id,
  1095. }
  1096. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1097. if dialysisFinish.ID == 0 {
  1098. service.CreateDialysisFinish(finish)
  1099. }
  1100. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1101. redis := service.RedisClient()
  1102. defer redis.Close()
  1103. //清空key 值
  1104. redis.Set(key, "", time.Second)
  1105. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1106. redis.Set(keyOne, "", time.Second)
  1107. if err == nil {
  1108. c.ServeSuccessJSON(map[string]interface{}{
  1109. "receiveTreatmentAsses": receiveTreatmentAsses,
  1110. })
  1111. }
  1112. } else { //修改
  1113. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1114. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1115. // if getPermissionErr != nil {
  1116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1117. // return
  1118. // } else if headNursePermission == nil {
  1119. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1120. // return
  1121. // }
  1122. //}
  1123. // 查询信息规挡的设置天数
  1124. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1125. if infor.ID > 0 && infor.WeekDay > 0 {
  1126. var cha_time int64
  1127. timeNowStr := time.Now().Format("2006-01-02")
  1128. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1129. //今日的日期减去设置的日期
  1130. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1131. if cha_time >= recordDate.Unix() {
  1132. //查询审核是否允许
  1133. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1134. //申请状态不允许的情况 拒绝修改
  1135. if infor.ApplicationStatus != 1 {
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1137. return
  1138. }
  1139. }
  1140. }
  1141. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1142. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1143. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1144. receiveTreatmentAsses.ID = receiveTreatment.ID
  1145. if adminUserInfo.Org.Id == 10340 {
  1146. if condition == 1 {
  1147. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1148. if receiveTreatmentAsses.AdmissionNumber == "" {
  1149. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1150. }
  1151. }
  1152. }
  1153. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1154. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1155. redis := service.RedisClient()
  1156. defer redis.Close()
  1157. //清空key 值
  1158. redis.Set(key, "", time.Second)
  1159. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1160. redis.Set(keyOne, "", time.Second)
  1161. if err == nil {
  1162. c.ServeSuccessJSON(map[string]interface{}{
  1163. "receiveTreatmentAsses": receiveTreatmentAsses,
  1164. })
  1165. }
  1166. }
  1167. }
  1168. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1169. id, _ := c.GetInt64("patient", 0)
  1170. recordDateStr := c.GetString("record_date")
  1171. weightAfter, _ := c.GetFloat("weight_after", 0)
  1172. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1173. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1174. fmt.Println("weight_loss", weightReduce)
  1175. temperature, _ := c.GetFloat("temperature", 0)
  1176. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1177. breathing_rate := c.GetString("breathing_rate")
  1178. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1179. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1180. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1181. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1182. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1183. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1184. cruor := c.GetString("cruor")
  1185. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1186. internalFistula := c.GetString("internal_fistula")
  1187. catheter := c.GetString("catheter")
  1188. complications := c.GetString("complication")
  1189. remark := c.GetString("remark")
  1190. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1191. dialysis_intakes := c.GetString("dialysis_intakes")
  1192. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1193. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1194. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1195. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1196. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1197. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1198. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1199. patientGose, _ := c.GetInt64("patient_gose", 0)
  1200. inpatientDepartment := c.GetString("inpatient_department")
  1201. observationContent := c.GetString("observation_content")
  1202. observationContentOther := c.GetString("observation_content_other")
  1203. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1204. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1205. in_advance_reason := c.GetString("in_advance_reason")
  1206. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1207. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1208. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1209. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1210. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1211. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1212. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1213. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1214. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1215. is_eat, _ := c.GetInt64("is_eat", 0)
  1216. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1217. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1218. channels, _ := c.GetInt64("channel", 0)
  1219. return_blood, _ := c.GetInt64("return_blood", 0)
  1220. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1221. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1222. dialysis_during, _ := c.GetFloat("dialysis_during")
  1223. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1224. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1225. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1226. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1227. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1228. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1229. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1230. setting_pressure := c.GetString("setting_pressure")
  1231. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1232. diastolic_pressure := c.GetString("diastolic_pressure")
  1233. other_complication := c.GetString("other_complication")
  1234. ktv := c.GetString("ktv")
  1235. urr := c.GetString("urr")
  1236. hypertenison, _ := c.GetInt64("hypertenison")
  1237. hypopiesia, _ := c.GetInt64("hypopiesia")
  1238. leave_office_method, _ := c.GetInt64("leave_office_method")
  1239. lapse, _ := c.GetInt64("lapse")
  1240. consciousness, _ := c.GetInt64("consciousness")
  1241. fallrisk, _ := c.GetInt64("fallrisk")
  1242. machine_run := c.GetString("machine_run")
  1243. after_urea := c.GetString("after_urea")
  1244. pip_coagulation := c.GetString("pip_coagulation")
  1245. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1246. transfusion_volume := c.GetString("transfusion_volume")
  1247. last_after_weight := c.GetString("last_after_weight")
  1248. displace_liqui_value := c.GetString("displace_liqui_value")
  1249. if id <= 0 {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1251. return
  1252. }
  1253. adminUserInfo := c.GetMobileAdminUserInfo()
  1254. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1255. if patient.ID == 0 {
  1256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1257. return
  1258. }
  1259. if len(recordDateStr) == 0 {
  1260. recordDateStr = time.Now().Format("2006-01-02")
  1261. }
  1262. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1263. fmt.Println("parseDateErr", parseDateErr)
  1264. if parseDateErr != nil {
  1265. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1267. return
  1268. }
  1269. //now := time.Now()
  1270. //year, month, day := now.Date()
  1271. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1272. //todayTimeStamp := today_time.Unix()
  1273. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1274. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1275. UserOrgId: adminUserInfo.Org.Id,
  1276. PatientId: id,
  1277. AssessmentDate: recordDate.Unix(),
  1278. Temperature: temperature,
  1279. PulseFrequency: pulse_frequency,
  1280. BreathingRate: breathing_rate,
  1281. SystolicBloodPressure: systolic_blood_pressure,
  1282. DiastolicBloodPressure: diastolic_blood_pressure,
  1283. ActualUltrafiltration: actual_ultrafiltration,
  1284. ActualDisplacement: actual_displacement,
  1285. ActualTreatmentHour: actualtreatHour,
  1286. ActualTreatmentMinute: actualtreatmin,
  1287. WeightAfter: weightAfter,
  1288. AdditionalWeight: additionalWeight,
  1289. WeightLoss: weightReduce,
  1290. Cruor: cruor,
  1291. SymptomAfterDialysis: symptomsAfterDialysi,
  1292. InternalFistula: internalFistula,
  1293. Catheter: catheter,
  1294. Complication: complications,
  1295. DialysisIntakes: dialysateVolume,
  1296. CreatedTime: time.Now().Unix(),
  1297. UpdatedTime: time.Now().Unix(),
  1298. Status: 1,
  1299. Remark: remark,
  1300. BloodAccessPartId: blood_access_part_id,
  1301. BloodAccessPartOperaId: blood_access_part_opera_id,
  1302. DialysisIntakesUnit: dialysis_intakes_unit,
  1303. PuncturePointOozingBlood: puncturePointOozingBlood,
  1304. PuncturePointHaematoma: puncturePointHaematoma,
  1305. InternalFistulaTremorAc: internalFistulaTremorAc,
  1306. PatientGose: patientGose,
  1307. InpatientDepartment: inpatientDepartment,
  1308. ObservationContent: observationContent,
  1309. ObservationContentOther: observationContentOther,
  1310. DialysisProcess: dialysis_process,
  1311. InAdvanceMinute: in_advance_minute,
  1312. InAdvanceReason: in_advance_reason,
  1313. HemostasisMinute: hemostasis_minute,
  1314. HemostasisOpera: hemostasis_opera,
  1315. TremorNoise: tremor_noise,
  1316. DisequilibriumSyndrome: disequilibrium_syndrome,
  1317. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1318. ArterialTube: arterial_tube,
  1319. IntravenousTube: intravenous_tube,
  1320. Dialyzer: dialyzer,
  1321. InAdvanceReasonOther: in_advance_reason_other,
  1322. IsEat: is_eat,
  1323. CvcA: cvc_a,
  1324. CvcV: cvc_v,
  1325. Channel: channels,
  1326. ReturnBlood: return_blood,
  1327. RehydrationVolume: rehydration_volume,
  1328. DialysisDuring: dialysis_during,
  1329. StrokeVolume: stroke_volume,
  1330. BloodFlow: blood_flow,
  1331. SealingFluidDispose: sealing_fluid_dispose,
  1332. SealingFluidSpecial: sealing_fluid_special,
  1333. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1334. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1335. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1336. SettingPressure: setting_pressure,
  1337. DiastolicPressure: diastolic_pressure,
  1338. OtherComplication: other_complication,
  1339. Ktv: ktv,
  1340. Urr: urr,
  1341. Hypopiesia: hypopiesia,
  1342. Hypertenison: hypertenison,
  1343. Lapse: lapse,
  1344. LeaveOfficeMethod: leave_office_method,
  1345. Consciousness: consciousness,
  1346. Fallrisk: fallrisk,
  1347. MachineRun: machine_run,
  1348. AfterUrea: after_urea,
  1349. PipCoagulation: pip_coagulation,
  1350. AccumulatedBloodVolume: accumulated_blood_volume,
  1351. TransfusionVolume: transfusion_volume,
  1352. LastAfterWeight: last_after_weight,
  1353. DisplaceLiquiValue: displace_liqui_value,
  1354. }
  1355. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1356. // 查询信息规挡的设置天数
  1357. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1358. if infor.ID > 0 && infor.WeekDay > 0 {
  1359. var cha_time int64
  1360. timeNowStr := time.Now().Format("2006-01-02")
  1361. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1362. //今日的日期减去设置的日期
  1363. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1364. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1365. if cha_time >= recordDate.Unix() {
  1366. //查询审核是否允许
  1367. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1368. //申请状态不允许的情况 拒绝修改
  1369. if infor.ApplicationStatus != 1 {
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1371. return
  1372. }
  1373. }
  1374. }
  1375. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1376. if assessmentAfter.ID == 0 { //新增
  1377. if appRole.UserType == 2 || appRole.UserType == 1 {
  1378. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1379. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1380. } else {
  1381. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1382. }
  1383. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1384. if assessmentAfterDislysis.UserOrgId != 10340 {
  1385. if assessmentAfterDislysis.WeightAfter == 0 {
  1386. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1387. }
  1388. }
  1389. if adminUserInfo.Org.Id == 10693 {
  1390. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1391. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1392. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1393. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1394. }
  1395. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1396. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1397. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1398. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1399. }
  1400. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1401. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1402. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1403. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1404. }
  1405. if assessmentAfterDislysis.PulseFrequency == 0 {
  1406. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1407. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1408. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1409. }
  1410. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1411. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1412. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1413. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1414. }
  1415. }
  1416. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1417. //记录日志
  1418. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1419. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1420. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1421. PatientId: assessmentAfterDislysis.PatientId,
  1422. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1423. Status: 1,
  1424. ErrLog: string(byterequest),
  1425. AdminUserId: adminUserInfo.AdminUser.Id,
  1426. Ctime: 0,
  1427. Mtime: 0,
  1428. Source: "手机端保存透后评估",
  1429. }
  1430. service.CreateAfterDialysisLog(afterDialysisLog)
  1431. finish := models.XtDialysisFinish{
  1432. IsFinish: 1,
  1433. UserOrgId: adminUserInfo.Org.Id,
  1434. Status: 1,
  1435. Ctime: time.Now().Unix(),
  1436. Mtime: 0,
  1437. Module: 9,
  1438. RecordDate: recordDate.Unix(),
  1439. Sourse: 1,
  1440. PatientId: id,
  1441. }
  1442. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1443. if dialysisFinish.ID == 0 {
  1444. service.CreateDialysisFinish(finish)
  1445. }
  1446. redis := service.RedisClient()
  1447. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1448. redis.Set(keyTwo, "", time.Second)
  1449. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1450. //清空key 值
  1451. redis.Set(key, "", time.Second)
  1452. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1453. redis.Set(keyOne, "", time.Second)
  1454. defer redis.Close()
  1455. if err == nil {
  1456. c.ServeSuccessJSON(map[string]interface{}{
  1457. "assessmentAfterDislysis": assessmentAfterDislysis,
  1458. })
  1459. }
  1460. return
  1461. } else { //修改
  1462. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1463. if infor.ID > 0 && infor.WeekDay > 0 {
  1464. var cha_time int64
  1465. timeNowStr := time.Now().Format("2006-01-02")
  1466. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1467. //今日的日期减去设置的日期
  1468. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1469. if cha_time >= recordDate.Unix() {
  1470. //查询审核是否允许
  1471. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1472. //申请状态不允许的情况 拒绝修改
  1473. if infor.ApplicationStatus != 1 {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1475. return
  1476. }
  1477. }
  1478. }
  1479. if appRole.UserType == 2 || appRole.UserType == 1 {
  1480. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1481. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1482. } else {
  1483. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1484. if assessmentAfterDislysis.Creater == 0 {
  1485. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1486. }
  1487. }
  1488. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1489. assessmentAfterDislysis.ID = assessmentAfter.ID
  1490. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1491. if assessmentAfterDislysis.UserOrgId != 10340 {
  1492. if assessmentAfterDislysis.WeightAfter == 0 {
  1493. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1494. }
  1495. }
  1496. if adminUserInfo.Org.Id == 10693 {
  1497. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1498. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1499. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1500. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1501. }
  1502. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1503. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1504. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1505. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1506. }
  1507. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1508. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1509. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1510. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1511. }
  1512. if assessmentAfterDislysis.PulseFrequency == 0 {
  1513. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1514. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1515. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1516. }
  1517. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1518. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1519. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1520. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1521. }
  1522. }
  1523. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1524. //记录日志
  1525. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1526. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1527. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1528. PatientId: assessmentAfterDislysis.PatientId,
  1529. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1530. Status: 1,
  1531. ErrLog: string(byterequest),
  1532. AdminUserId: adminUserInfo.AdminUser.Id,
  1533. Ctime: time.Now().Unix(),
  1534. Mtime: 0,
  1535. Source: "手机端修改保存透后评估",
  1536. }
  1537. service.CreateAfterDialysisLog(afterDialysisLog)
  1538. redis := service.RedisClient()
  1539. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1540. redis.Set(keyTwo, "", time.Second)
  1541. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1542. //清空key 值
  1543. redis.Set(key, "", time.Second)
  1544. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1545. redis.Set(keyOne, "", time.Second)
  1546. if err == nil {
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "assessmentAfterDislysis": assessmentAfterDislysis,
  1549. })
  1550. return
  1551. }
  1552. }
  1553. return
  1554. }
  1555. func (c *DialysisAPIController) PostDialysisPrescription() {
  1556. id, _ := c.GetInt64("patient", 0)
  1557. recordDateStr := c.GetString("record_date")
  1558. if id <= 0 {
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1560. return
  1561. }
  1562. adminUserInfo := c.GetMobileAdminUserInfo()
  1563. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1564. if patient.ID == 0 {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1566. return
  1567. }
  1568. if len(recordDateStr) == 0 {
  1569. recordDateStr = time.Now().Format("2006-01-02")
  1570. }
  1571. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1572. if parseDateErr != nil {
  1573. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. mode_id, _ := c.GetInt64("mode_id", 0)
  1578. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1579. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1580. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1581. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1582. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1583. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1584. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1585. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1586. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1587. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1588. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1589. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1590. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1591. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1592. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1593. kalium, _ := c.GetFloat("kalium", 0)
  1594. sodium, _ := c.GetFloat("sodium", 0)
  1595. calcium, _ := c.GetFloat("calcium", 0)
  1596. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1597. glucose, _ := c.GetFloat("glucose", 0)
  1598. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1599. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1600. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1601. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1602. conductivity, _ := c.GetFloat("conductivity", 0)
  1603. remark := c.GetString("remark")
  1604. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1605. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1606. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1607. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1608. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1609. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1610. special_medicine_other := c.GetString("special_medicine_other")
  1611. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1612. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1613. blood_access, _ := c.GetInt64("blood_access", 0)
  1614. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1615. body_fluid_other := c.GetString("body_fluid_other")
  1616. niprocart, _ := c.GetInt64("niprocart", 0)
  1617. jms, _ := c.GetInt64("jms", 0)
  1618. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1619. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1620. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1621. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1622. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1623. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1624. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1625. injector, _ := c.GetInt64("injector", 0)
  1626. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1627. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1628. safe_package, _ := c.GetInt64("package", 0)
  1629. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1630. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1631. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1632. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1633. blood := c.GetString("blood")
  1634. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1635. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1636. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1637. displace_speed := c.GetString("displace_speed")
  1638. illness, _ := c.GetInt64("illness")
  1639. amylaceum := c.GetString("amylaceum")
  1640. single_time := c.GetString("single_time")
  1641. single_water := c.GetString("single_water")
  1642. replacement_flow := c.GetString("replacement_flow")
  1643. plasma_separator := c.GetString("plasma_separator")
  1644. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1645. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1646. oxygen_flow := c.GetString("oxygen_flow")
  1647. oxygen_time := c.GetString("oxygen_time")
  1648. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1649. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1650. puncture_needle := c.GetString("puncture_needle")
  1651. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1652. epo := c.GetString("epo")
  1653. epo_count, _ := c.GetFloat("epo_count", 0)
  1654. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1655. admin_user_id, _ := c.GetInt64("admin_user_id")
  1656. is_water := c.GetString("is_water")
  1657. var is_war int64
  1658. if is_water == "是" {
  1659. is_war = 1
  1660. }
  1661. if is_water == "否" {
  1662. is_war = 2
  1663. }
  1664. if is_water == "请选择" {
  1665. is_war = 0
  1666. }
  1667. drhy_water := c.GetString("drhy_water")
  1668. dry_water_hour := c.GetString("dry_water_hour")
  1669. water_machine := c.GetString("water_machine")
  1670. add_amount, _ := c.GetFloat("add_amount")
  1671. reduce_amount, _ := c.GetFloat("reduce_amount")
  1672. dialysis_remark := c.GetString("dialysis_remark")
  1673. prescribing_number, _ := c.GetFloat("prescribing_number")
  1674. prescription_sodium := c.GetString("prescription_sodium")
  1675. start_sodium := c.GetString("start_sodium")
  1676. sodium_curve := c.GetString("sodium_curve")
  1677. treatment_remark := c.GetString("treatment_remark")
  1678. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1679. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1680. prescription_water, _ := c.GetFloat("prescription_water")
  1681. dialysis_strainer := c.GetString("dialysis_strainer")
  1682. chaptalization := c.GetString("chaptalization")
  1683. washing_time := c.GetString("washing_time")
  1684. warsh_count := c.GetString("warsh_count")
  1685. blood_access_part_id := c.GetString("blood_access_part_id")
  1686. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1687. dialyzate := c.GetString("dialyzate")
  1688. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1689. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1690. //
  1691. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1692. // if appRole.UserType == 3 {
  1693. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1694. // if getPermissionErr != nil {
  1695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1696. // return
  1697. // } else if headNursePermission == nil {
  1698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1699. // return
  1700. // }
  1701. // }
  1702. //}
  1703. // 查询信息规挡的设置天数
  1704. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1705. if infor.ID > 0 && infor.WeekDay > 0 {
  1706. var cha_time int64
  1707. timeNowStr := time.Now().Format("2006-01-02")
  1708. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1709. //今日的日期减去设置的日期
  1710. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1711. if cha_time >= recordDate.Unix() {
  1712. //查询审核是否允许
  1713. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1714. //申请状态不允许的情况 拒绝修改
  1715. if infor.ApplicationStatus != 1 {
  1716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1717. return
  1718. }
  1719. }
  1720. }
  1721. if mode_id > 0 {
  1722. var str string
  1723. //查找该机构用的是什么透析器
  1724. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1725. if filedConfig.ID > 0 {
  1726. str = dialyzerPerfusionApparatus
  1727. } else {
  1728. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1729. }
  1730. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1731. }
  1732. //TODO 需要根据角色去判断
  1733. prescription := models.DialysisPrescription{
  1734. UserOrgId: adminUserInfo.Org.Id,
  1735. PatientId: id,
  1736. RecordDate: recordDate.Unix(),
  1737. ModeId: mode_id,
  1738. DialysisDuration: dialysis_duration,
  1739. Dialyzer: dialyzer,
  1740. PerfusionApparatus: perfusion_apparatus,
  1741. BloodFlowVolume: blood_flow_volume,
  1742. DewaterAmount: dewater_amount,
  1743. DisplaceLiqui: displace_liqui,
  1744. ReplacementWay: replacement_way,
  1745. Anticoagulant: anticoagulant,
  1746. AnticoagulantShouji: anticoagulant_shouji,
  1747. AnticoagulantWeichi: anticoagulant_weichi,
  1748. AnticoagulantZongliang: anticoagulant_zongliang,
  1749. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1750. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1751. Kalium: kalium,
  1752. Sodium: sodium,
  1753. Calcium: calcium,
  1754. Bicarbonate: bicarbonate,
  1755. Glucose: glucose,
  1756. // DryWeight: dry_weight,
  1757. DialysateFlow: dialysate_flow,
  1758. DialysateTemperature: dialysate_temperature,
  1759. // PrescriptionDoctor: prescription_doctor,
  1760. ReplacementTotal: replacement_total,
  1761. Conductivity: conductivity,
  1762. Remark: remark,
  1763. Status: 1,
  1764. CreatedTime: time.Now().Unix(),
  1765. UpdatedTime: time.Now().Unix(),
  1766. DialysisDurationMinute: dialysisDurationMinute,
  1767. DialysisDurationHour: dialysisDurationHour,
  1768. TargetUltrafiltration: targetUltrafiltration,
  1769. DialysateFormulation: dialysateFormulation,
  1770. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1771. BodyFluid: body_fluid,
  1772. SpecialMedicine: special_medicine,
  1773. SpecialMedicineOther: special_medicine_other,
  1774. DisplaceLiquiPart: displace_liqui_part,
  1775. DisplaceLiquiValue: displace_liqui_value,
  1776. BloodAccess: blood_access,
  1777. Ultrafiltration: ultrafiltration,
  1778. BodyFluidOther: body_fluid_other,
  1779. Niprocart: niprocart,
  1780. Jms: jms,
  1781. FistulaNeedleSet: fistula_needle_set,
  1782. FistulaNeedleSet16: fistula_needle_set_16,
  1783. Hemoperfusion: hemoperfusion,
  1784. DialyserSterilised: dialyser_sterilised,
  1785. Filtryzer: filtryzer,
  1786. Dialyzers: dialyzers,
  1787. Injector: injector,
  1788. Bloodlines: bloodlines,
  1789. TubingHemodialysis: tubing_hemodialysis,
  1790. Package: safe_package,
  1791. ALiquid: a_liquid,
  1792. TargetKtv: target_ktv,
  1793. PreImpulse: pre_impulse,
  1794. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1795. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1796. Blood: blood,
  1797. DialysisDialyszers: dialysis_dialyszers,
  1798. DialysisIrrigation: dialysis_irrigation,
  1799. AntioxidantCommodityName: antioxidant_commodity_name,
  1800. DisplaceSpeed: displace_speed,
  1801. Illness: illness,
  1802. Amylaceum: amylaceum,
  1803. SingleTime: single_time,
  1804. SingleWater: single_water,
  1805. ReplacementFlow: replacement_flow,
  1806. PlasmaSeparator: plasma_separator,
  1807. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1808. OxygenUptake: oxygen_uptake,
  1809. OxygenFlow: oxygen_flow,
  1810. OxygenTime: oxygen_time,
  1811. HemodialysisPipelines: hemodialysis_pipelines,
  1812. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1813. PunctureNeedle: puncture_needle,
  1814. PunctureNeedleCount: puncture_needle_count,
  1815. Epo: epo,
  1816. EpoCount: epo_count,
  1817. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1818. AdminUserId: admin_user_id,
  1819. IsWater: is_war,
  1820. DrhyWater: drhy_water,
  1821. DryWaterHour: dry_water_hour,
  1822. WaterMachine: water_machine,
  1823. AddAmount: add_amount,
  1824. ReduceAmount: reduce_amount,
  1825. DialysisRemark: dialysis_remark,
  1826. PrescribingNumber: prescribing_number,
  1827. StartSodium: start_sodium,
  1828. SodiumCurve: sodium_curve,
  1829. TreatmentRemark: treatment_remark,
  1830. PrescriptionSodium: prescription_sodium,
  1831. DialysisFluidFlow: dialysis_fluid_flow,
  1832. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1833. PrescriptionWater: prescription_water,
  1834. DialysisStrainer: dialysis_strainer,
  1835. Chaptalization: chaptalization,
  1836. WashingTime: washing_time,
  1837. WarshCount: warsh_count,
  1838. BloodAccessPartId: blood_access_part_id,
  1839. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1840. Dialyzate: dialyzate,
  1841. }
  1842. //查询最近透析准备表里是否存在 透析器 灌流器
  1843. //
  1844. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1845. //
  1846. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1847. //
  1848. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1849. //if len(mation)>0{
  1850. // for _, item := range splitStr {
  1851. // for _,it := range mation{
  1852. // if(item == it.SpecificationName){
  1853. //
  1854. // //查询最近一次的透析器
  1855. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1856. //
  1857. // if errcode == gorm.ErrRecordNotFound{
  1858. // //插入数据
  1859. // prepare := models.DialysisBeforePrepare{
  1860. // UserOrgId: adminUserInfo.Org.Id,
  1861. // PatientId: id,
  1862. // RecordDate: recordDate.Unix(),
  1863. // GoodTypeId: it.GoodTypeId,
  1864. // GoodId: it.ID,
  1865. // Count: 1,
  1866. // Ctime: time.Now().Unix(),
  1867. // Creater: adminUserInfo.AdminUser.Id,
  1868. // Status:1,
  1869. //
  1870. // }
  1871. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1872. // fmt.Println("",errcode)
  1873. // }
  1874. // }
  1875. // }
  1876. //
  1877. // }
  1878. //
  1879. // for _, item := range splitIrrigation {
  1880. // for _,it := range mation{
  1881. // if(item == it.SpecificationName){
  1882. // //查询最近一次的透析器
  1883. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1884. // if errcode == gorm.ErrRecordNotFound{
  1885. // //插入数据
  1886. // prepare := models.DialysisBeforePrepare{
  1887. // UserOrgId: adminUserInfo.Org.Id,
  1888. // PatientId: id,
  1889. // RecordDate: recordDate.Unix(),
  1890. // GoodTypeId: it.GoodTypeId,
  1891. // GoodId: it.ID,
  1892. // Count: 1,
  1893. // Ctime: time.Now().Unix(),
  1894. // Creater: adminUserInfo.AdminUser.Id,
  1895. // Status:1,
  1896. //
  1897. // }
  1898. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1899. // fmt.Println(errcode)
  1900. // }
  1901. // }
  1902. // }
  1903. // }
  1904. //}
  1905. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1906. if dialysisPrescription.ID == 0 { //新增
  1907. if appRole.UserType == 2 || appRole.UserType == 1 {
  1908. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1909. }
  1910. prescription.Creater = adminUserInfo.AdminUser.Id
  1911. //针对河间咸得
  1912. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1913. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1914. prescription.DisplaceLiquiPart = 0
  1915. prescription.DisplaceLiquiValue = 0
  1916. }
  1917. }
  1918. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1919. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1920. }
  1921. err := service.AddSigleRecord(&prescription)
  1922. //记录日志
  1923. byterequest, _ := json.Marshal(prescription)
  1924. prescriptionLog := models.XtDialysisPrescriptionLog{
  1925. UserOrgId: prescription.UserOrgId,
  1926. Ctime: time.Now().Unix(),
  1927. Mtime: 0,
  1928. ErrLog: string(byterequest),
  1929. AdminUserId: adminUserInfo.AdminUser.Id,
  1930. RecordDate: prescription.RecordDate,
  1931. PatientId: prescription.PatientId,
  1932. Source: "手机端新增保存处方",
  1933. Status: 1,
  1934. }
  1935. service.CreatePrescriptionLog(prescriptionLog)
  1936. finish := models.XtDialysisFinish{
  1937. IsFinish: 1,
  1938. UserOrgId: adminUserInfo.Org.Id,
  1939. Status: 1,
  1940. Ctime: time.Now().Unix(),
  1941. Mtime: 0,
  1942. Module: 1,
  1943. RecordDate: recordDate.Unix(),
  1944. Sourse: 1,
  1945. PatientId: id,
  1946. }
  1947. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1948. if dialysisFinish.ID == 0 {
  1949. service.CreateDialysisFinish(finish)
  1950. }
  1951. //长沙南雅医院,自动生成抗凝剂的临时处方
  1952. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1953. if prescribing_number == 0 {
  1954. prescribing_number = 1
  1955. }
  1956. if prescribing_number == 0 && id == 14682 {
  1957. prescribing_number = 2
  1958. }
  1959. if prescribing_number == 0 && id == 18560 {
  1960. prescribing_number = 2
  1961. }
  1962. advice := models.DoctorAdvice{
  1963. UserOrgId: adminUserInfo.Org.Id,
  1964. PatientId: id,
  1965. GroupNo: 0,
  1966. AdviceType: 2,
  1967. RecordDate: recordDate.Unix(),
  1968. AdviceDate: recordDate.Unix(),
  1969. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1970. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1971. AdviceDesc: "",
  1972. ReminderDate: 0,
  1973. SingleDose: anticoagulant_zongliang,
  1974. SingleDoseUnit: "iu",
  1975. DrugSpec: 0,
  1976. DrugSpecUnit: "",
  1977. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1978. PrescribingNumberUnit: "支",
  1979. DeliveryWay: "静脉注射",
  1980. ExecutionFrequency: "上机前",
  1981. AdviceDoctor: 0,
  1982. Status: 1,
  1983. CreatedTime: time.Now().Unix(),
  1984. UpdatedTime: time.Now().Unix(),
  1985. IsPrescription: 1,
  1986. ExecutionState: 2,
  1987. StopState: 2,
  1988. IsSettle: 2,
  1989. }
  1990. // 查询排班信息
  1991. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1992. if schedulePatient.ID > 0 {
  1993. if schedulePatient.ScheduleType == 1 {
  1994. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1995. }
  1996. if schedulePatient.ScheduleType == 2 {
  1997. advice.StartTime = recordDate.Unix() + 9*60*60
  1998. }
  1999. }
  2000. // 抗凝剂名称
  2001. switch anticoagulant {
  2002. case 1:
  2003. advice.AdviceName = "无肝素"
  2004. break
  2005. case 2:
  2006. advice.AdviceName = "普通肝素"
  2007. break
  2008. case 3:
  2009. advice.AdviceName = "低分子肝素"
  2010. break
  2011. case 4:
  2012. advice.AdviceName = "阿加曲班"
  2013. break
  2014. case 5:
  2015. advice.AdviceName = "枸橼酸钠"
  2016. break
  2017. case 6:
  2018. advice.AdviceName = "低分子肝素钙"
  2019. break
  2020. case 7:
  2021. advice.AdviceName = "低分子肝素钠"
  2022. break
  2023. case 8:
  2024. advice.AdviceName = "依诺肝素"
  2025. break
  2026. case 9:
  2027. advice.AdviceName = "达肝素"
  2028. break
  2029. case 10:
  2030. advice.AdviceName = "体外抗凝"
  2031. break
  2032. case 11:
  2033. advice.AdviceName = "那曲肝素"
  2034. break
  2035. case 12:
  2036. advice.AdviceName = "无抗凝剂"
  2037. break
  2038. }
  2039. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2040. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2041. advice.AdviceDoctor = appRole.AdminUserId
  2042. }
  2043. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2044. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2045. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2046. advice.AdviceName = "低分子肝素钠注射液"
  2047. // 修改患者临时医嘱里的抗凝剂医嘱
  2048. advice.ID = advicePrescription.ID
  2049. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. } else {
  2051. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2052. advice.AdviceName = "低分子肝素钠注射液"
  2053. // 新增患者临时医嘱里的抗凝剂医嘱
  2054. service.CreateDoctorAdvice(&advice)
  2055. }
  2056. }
  2057. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2058. redis := service.RedisClient()
  2059. defer redis.Close()
  2060. //清空key 值
  2061. redis.Set(key, "", time.Second)
  2062. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2063. redis.Set(keyOne, "", time.Second)
  2064. }
  2065. //获取key,清空redis
  2066. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2067. redis := service.RedisClient()
  2068. //清空key 值
  2069. redis.Set(key, "", time.Second)
  2070. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2071. //清空key 值
  2072. redis.Set(keyOne, "", time.Second)
  2073. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2074. //清空key 值
  2075. redis.Set(keyTwo, "", time.Second)
  2076. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2077. redis.Set(keySix, "", time.Second)
  2078. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2079. redis.Set(keySeven, "", time.Second)
  2080. if err == nil {
  2081. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2082. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2083. //清空key 值
  2084. redis.Set(keyThree, "", time.Second)
  2085. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2086. //清空key 值
  2087. redis.Set(keyFour, "", time.Second)
  2088. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2089. redis.Set(keyFive, "", time.Second)
  2090. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2091. redis.Set(keySix, "", time.Second)
  2092. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2093. redis.Set(keySeven, "", time.Second)
  2094. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2095. //清空key 值
  2096. redis.Set(keyOne, "", time.Second)
  2097. if updateErr != nil {
  2098. utils.ErrorLog("%v", updateErr)
  2099. }
  2100. defer redis.Close()
  2101. c.ServeSuccessJSON(map[string]interface{}{
  2102. "prescription": prescription,
  2103. })
  2104. }
  2105. } else { //修改
  2106. //if mode_id > 0 {
  2107. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2108. //}
  2109. //if template.TemplateId == 1 {
  2110. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2112. // if getPermissionErr != nil {
  2113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2114. // return
  2115. // } else if headNursePermission == nil {
  2116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2117. // return
  2118. // }
  2119. // }
  2120. //}
  2121. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2122. prescription.Modifier = adminUserInfo.AdminUser.Id
  2123. if appRole.UserType == 2 || appRole.UserType == 1 {
  2124. prescription_doctor := adminUserInfo.AdminUser.Id
  2125. prescription.PrescriptionDoctor = prescription_doctor
  2126. } else {
  2127. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2128. }
  2129. if dialysisPrescription.Creater == 0 { //体重称
  2130. prescription.Creater = adminUserInfo.AdminUser.Id
  2131. } else {
  2132. prescription.Creater = dialysisPrescription.Creater
  2133. if adminUserInfo.Org.Id == 9882 {
  2134. if appRole.UserType == 2 || appRole.UserType == 1 {
  2135. prescription_doctor := adminUserInfo.AdminUser.Id
  2136. prescription.PrescriptionDoctor = prescription_doctor
  2137. prescription.Creater = prescription_doctor
  2138. }
  2139. }
  2140. }
  2141. prescription.ID = dialysisPrescription.ID
  2142. service.UpDateDialysisPrescription(&prescription)
  2143. //记录日志
  2144. byterequest, _ := json.Marshal(prescription)
  2145. prescriptionLog := models.XtDialysisPrescriptionLog{
  2146. UserOrgId: prescription.UserOrgId,
  2147. Ctime: time.Now().Unix(),
  2148. Mtime: 0,
  2149. ErrLog: string(byterequest),
  2150. AdminUserId: adminUserInfo.AdminUser.Id,
  2151. RecordDate: prescription.RecordDate,
  2152. PatientId: prescription.PatientId,
  2153. Source: "手机端修改处方",
  2154. Status: 1,
  2155. }
  2156. service.CreatePrescriptionLog(prescriptionLog)
  2157. finish := models.XtDialysisFinish{
  2158. IsFinish: 1,
  2159. UserOrgId: adminUserInfo.Org.Id,
  2160. Status: 1,
  2161. Ctime: time.Now().Unix(),
  2162. Mtime: 0,
  2163. Module: 1,
  2164. RecordDate: recordDate.Unix(),
  2165. Sourse: 1,
  2166. PatientId: id,
  2167. }
  2168. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2169. if dialysisFinish.ID == 0 {
  2170. service.CreateDialysisFinish(finish)
  2171. }
  2172. //修改处方
  2173. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2174. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2175. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2176. if advicePrescription.ID > 0 {
  2177. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2178. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2179. redis := service.RedisClient()
  2180. defer redis.Close()
  2181. //清空key 值
  2182. redis.Set(key, "", time.Second)
  2183. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2184. redis.Set(keyOne, "", time.Second)
  2185. }
  2186. }
  2187. //获取key,清空redis
  2188. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2189. redis := service.RedisClient()
  2190. //清空key 值
  2191. redis.Set(key, "", time.Second)
  2192. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2193. //清空key 值
  2194. redis.Set(keyOne, "", time.Second)
  2195. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2196. redis.Set(keySix, "", time.Second)
  2197. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2198. redis.Set(keySeven, "", time.Second)
  2199. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2200. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2201. //清空key 值
  2202. redis.Set(keyTwoOne, "", time.Second)
  2203. defer redis.Close()
  2204. if updateErr != nil {
  2205. utils.ErrorLog("%v", updateErr)
  2206. }
  2207. c.ServeSuccessJSON(map[string]interface{}{
  2208. "prescription": prescription,
  2209. })
  2210. }
  2211. }
  2212. func (c *DialysisAPIController) Finish() {
  2213. id, _ := c.GetInt64("patient", 0)
  2214. recordDateStr := c.GetString("record_date")
  2215. nurseID, _ := c.GetInt64("nurse")
  2216. end_time := c.GetString("end_time")
  2217. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2218. internal_fistula := c.GetString("blood_access_internal_fistula")
  2219. catheter := c.GetString("catheter")
  2220. cruor := c.GetString("cruor")
  2221. mission := c.GetString("mission")
  2222. condenser := c.GetString("condenser")
  2223. if id <= 0 || nurseID <= 0 {
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2225. return
  2226. }
  2227. adminUserInfo := c.GetMobileAdminUserInfo()
  2228. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2229. if patient.ID == 0 {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2231. return
  2232. }
  2233. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2234. if getNurseErr != nil {
  2235. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2237. return
  2238. } else if nurse == nil {
  2239. c.ErrorLog("护士不存在")
  2240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2241. return
  2242. }
  2243. if len(recordDateStr) == 0 {
  2244. recordDateStr = time.Now().Format("2006-01-02")
  2245. }
  2246. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2247. if parseDateErr != nil {
  2248. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2250. return
  2251. }
  2252. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2253. if parseEndDateErr != nil {
  2254. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. // 查询信息规挡的设置天数
  2259. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2260. if infor.ID > 0 && infor.WeekDay > 0 {
  2261. var cha_time int64
  2262. timeNowStr := time.Now().Format("2006-01-02")
  2263. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2264. //今日的日期减去设置的日期
  2265. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2266. if cha_time >= recordDate.Unix() {
  2267. //查询审核是否允许
  2268. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2269. //申请状态不允许的情况 拒绝修改
  2270. if infor.ApplicationStatus != 1 {
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2272. return
  2273. }
  2274. }
  2275. }
  2276. //now := time.Now()
  2277. //year, month, day := now.Date()
  2278. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2279. //todayTimeStamp := today_time.Unix()
  2280. // 获取当天的第一条透析纪录
  2281. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2282. if getMonitorRecordsErr != nil {
  2283. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2285. return
  2286. }
  2287. // 获取当前的最后一条透析纪录
  2288. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2289. if getMonitorRecordsErr != nil {
  2290. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2292. return
  2293. }
  2294. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2295. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2296. if getAADErr != nil {
  2297. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2299. return
  2300. }
  2301. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2302. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2303. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2304. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2305. if assessmentAfterDislysis != nil {
  2306. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2307. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2308. } else {
  2309. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2310. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2311. tempassessmentAfterDislysis.Status = 1
  2312. tempassessmentAfterDislysis.PatientId = id
  2313. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2314. }
  2315. //长沙南雅
  2316. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2317. //获取最后一条透析处方数据
  2318. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2319. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2320. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2321. }
  2322. if dialysisOrder.Stage == 1 {
  2323. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2324. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2325. fmt.Println(value)
  2326. a, b := math.Modf(value)
  2327. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2328. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2329. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2330. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2331. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2332. }
  2333. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2334. //var num1 int64
  2335. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2336. //fmt.Println(num1)
  2337. //sub := float64(num1 / 3600)
  2338. //fmt.Println(sub)
  2339. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2340. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2341. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2342. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2343. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2344. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2345. if adminUserInfo.Org.Id != 10375 {
  2346. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2347. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2348. }
  2349. if adminUserInfo.Org.Id != 10445 {
  2350. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2351. }
  2352. //北方营口医院
  2353. if adminUserInfo.Org.Id == 10445 {
  2354. //获取最后一条透析处方数据
  2355. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2356. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2357. } else {
  2358. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2359. }
  2360. //新化博翔
  2361. if adminUserInfo.Org.Id == 10447 {
  2362. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2363. }
  2364. //阳春
  2365. if adminUserInfo.Org.Id == 10485 {
  2366. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2367. }
  2368. if adminUserInfo.Org.Id == 10551 {
  2369. //获取最后一条透析处方数据
  2370. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2371. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2372. }
  2373. if adminUserInfo.Org.Id == 10580 {
  2374. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2375. }
  2376. if adminUserInfo.Org.Id == 10612 {
  2377. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2378. }
  2379. //孝康
  2380. if adminUserInfo.Org.Id == 10693 {
  2381. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2382. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2383. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2384. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2385. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2386. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2387. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2388. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2389. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2390. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2391. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2392. }
  2393. if adminUserInfo.Org.Id == 10697 {
  2394. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2395. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2396. lastWeightAfter.LastAfterWeight = floatAfeter
  2397. }
  2398. }
  2399. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 {
  2400. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2401. if evaluation.SystolicBloodPressure == 0 {
  2402. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2403. if adminUserInfo.Org.Id == 10693 {
  2404. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2405. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2406. }
  2407. pre := models.PredialysisEvaluation{
  2408. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2409. }
  2410. fmt.Println("prew", pre)
  2411. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2412. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2413. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2414. redis := service.RedisClient()
  2415. redis.Set(key, "", time.Second)
  2416. redis.Set(keyOne, "", time.Second)
  2417. defer redis.Close()
  2418. fmt.Println(getNurseErr)
  2419. }
  2420. if evaluation.DiastolicBloodPressure == 0 {
  2421. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2422. if adminUserInfo.Org.Id == 10693 {
  2423. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2424. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2425. }
  2426. pres := models.PredialysisEvaluation{
  2427. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2428. }
  2429. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2430. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2431. redis := service.RedisClient()
  2432. redis.Set(key, "", time.Second)
  2433. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2434. redis.Set(keyOne, "", time.Second)
  2435. defer redis.Close()
  2436. fmt.Println(getNurseErr)
  2437. }
  2438. if evaluation.PulseFrequency == 0 {
  2439. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2440. if adminUserInfo.Org.Id == 10693 {
  2441. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2442. evaluation.PulseFrequency = pulseFrequency
  2443. }
  2444. press := models.PredialysisEvaluation{
  2445. PulseFrequency: evaluation.PulseFrequency,
  2446. }
  2447. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2449. redis := service.RedisClient()
  2450. redis.Set(key, "", time.Second)
  2451. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2452. redis.Set(keyOne, "", time.Second)
  2453. defer redis.Close()
  2454. fmt.Println(getNurseErr)
  2455. }
  2456. if evaluation.Temperature == 0 {
  2457. evaluation.Temperature = fmonitorRecords.Temperature
  2458. press := models.PredialysisEvaluation{
  2459. Temperature: evaluation.Temperature,
  2460. }
  2461. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2462. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2463. redis := service.RedisClient()
  2464. redis.Set(key, "", time.Second)
  2465. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2466. redis.Set(keyOne, "", time.Second)
  2467. defer redis.Close()
  2468. fmt.Println(getNurseErr)
  2469. }
  2470. }
  2471. if adminUserInfo.Org.Id == 9583 {
  2472. //获取透析处方的最后一条数据
  2473. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2474. if diaerr != nil {
  2475. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2477. return
  2478. }
  2479. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2480. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2481. }
  2482. }
  2483. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2484. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2485. }
  2486. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2487. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2488. }
  2489. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2490. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2491. }
  2492. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2493. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2494. }
  2495. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2496. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2497. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2498. }
  2499. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2500. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2501. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2502. }
  2503. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2504. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2505. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2506. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2507. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2508. }
  2509. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2510. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2511. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2512. }
  2513. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2514. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2515. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2516. }
  2517. if lastAssessmentAfterDislysis != nil {
  2518. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2519. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2520. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2521. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2522. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2523. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2524. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2525. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2526. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2527. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2528. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2529. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2530. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2531. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2532. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2533. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2534. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2535. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2536. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2537. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2538. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2539. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2540. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2541. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2542. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2543. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2544. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2545. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2546. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2547. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2548. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2549. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2550. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2551. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2552. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2553. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2554. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2555. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2556. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2557. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2558. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2559. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2560. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2561. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2562. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2563. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2564. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2565. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2566. if tempassessmentAfterDislysis.PatientId == 18695 {
  2567. tempassessmentAfterDislysis.ActualDisplacement = 0
  2568. }
  2569. if adminUserInfo.Org.Id != 10375 {
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2571. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2572. }
  2573. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2574. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2575. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2576. }
  2577. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2578. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2579. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2580. }
  2581. }
  2582. finish := models.XtDialysisFinish{
  2583. IsFinish: 1,
  2584. UserOrgId: adminUserInfo.Org.Id,
  2585. Status: 1,
  2586. Ctime: time.Now().Unix(),
  2587. Mtime: 0,
  2588. Module: 9,
  2589. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2590. Sourse: 1,
  2591. PatientId: tempassessmentAfterDislysis.PatientId,
  2592. }
  2593. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2594. if dialysisFinish.ID == 0 {
  2595. service.CreateDialysisFinish(finish)
  2596. }
  2597. //孝康
  2598. if adminUserInfo.Org.Id == 10693 {
  2599. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2600. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2601. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2602. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2603. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2604. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2605. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2606. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2607. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2608. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2609. }
  2610. if adminUserInfo.Org.Id == 10697 {
  2611. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2612. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2613. lastWeightAfter.LastAfterWeight = floatAfeter
  2614. }
  2615. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2616. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2617. redis := service.RedisClient()
  2618. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2619. redis.Set(keyOne, "", time.Second)
  2620. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2621. redis.Set(keyTwo, "", time.Second)
  2622. defer redis.Close()
  2623. //清空key 值
  2624. redis.Set(key, "", time.Second)
  2625. if err != nil {
  2626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2627. return
  2628. }
  2629. if dialysisOrder == nil {
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2631. return
  2632. }
  2633. if dialysisOrder.Stage == 2 {
  2634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2635. return
  2636. }
  2637. if dialysisOrder.Stage == 1 {
  2638. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2639. finish := models.XtDialysisFinish{
  2640. IsFinish: 1,
  2641. UserOrgId: adminUserInfo.Org.Id,
  2642. Status: 1,
  2643. Ctime: time.Now().Unix(),
  2644. Mtime: 0,
  2645. Module: 8,
  2646. RecordDate: recordDate.Unix(),
  2647. Sourse: 1,
  2648. PatientId: id,
  2649. }
  2650. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2651. if dialysisFinish.ID == 0 {
  2652. service.CreateDialysisFinish(finish)
  2653. }
  2654. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2655. redis := service.RedisClient()
  2656. defer redis.Close()
  2657. //清空key 值
  2658. redis.Set(key, "", time.Second)
  2659. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2660. redis.Set(keyOne, "", time.Second)
  2661. //结束时候透析次数加1
  2662. service.UpdateSolutionByPatientId(id)
  2663. //下机完自动消毒,针对长沙南雅
  2664. if dialysisOrder.Stage == 1 {
  2665. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2666. //根据床位号获取设备型号
  2667. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2668. //查询使用消毒最后一条消毒记录
  2669. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2670. fmt.Println("err", err)
  2671. if err == gorm.ErrRecordNotFound {
  2672. //查找排班
  2673. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2674. //查询改设备是否有消毒计划
  2675. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2676. //根据床位号获取设备id
  2677. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2678. //查询病人信息
  2679. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2680. var con = ""
  2681. if patients.IsInfectious == 0 {
  2682. con = ""
  2683. }
  2684. if patients.IsInfectious == 1 {
  2685. con = "无"
  2686. }
  2687. if patients.IsInfectious == 2 {
  2688. con = "有"
  2689. }
  2690. if errcode == nil {
  2691. var end_time int64
  2692. end_time = endDate.Unix() + plan.DisinfecTime*60
  2693. //新增消毒
  2694. information := models.DeviceInformation{
  2695. Date: dialysisOrder.DialysisDate,
  2696. Zone: dialysisOrder.ZoneId,
  2697. Class: dialysisOrder.SchedualType,
  2698. BedNumber: dialysisOrder.BedID,
  2699. PatientId: dialysisOrder.PatientId,
  2700. DialysisMode: scheduleByPatient.ModeId,
  2701. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2702. Disinfection: 1,
  2703. DialysisConcentration: 1,
  2704. DisinfectionStatus: 1,
  2705. Move: 1,
  2706. UserOrgId: dialysisOrder.UserOrgId,
  2707. DisinfectType: plan.Way,
  2708. DisinfectantType: plan.MachineDisinfectant,
  2709. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2710. Disinfectant: plan.Disinfectant,
  2711. Ctime: time.Now().Unix(),
  2712. Status: 1,
  2713. SignName: nurseID,
  2714. EquimentId: addmacher.ID,
  2715. DisinfectionResidue: 2,
  2716. Bed: addmacher.BedNumber,
  2717. StartTime: dialysisOrder.StartTime,
  2718. EndTime: dialysisOrder.EndTime,
  2719. Contagion: con,
  2720. WeightLoss: 0,
  2721. Hyperfiltratio: 0,
  2722. DialysisHour: "",
  2723. MachineRun: 1,
  2724. DisinfecStartime: endDate.Unix(),
  2725. DisinfecEndtime: end_time,
  2726. }
  2727. err := service.CreateInformationTwo(&information)
  2728. fmt.Println("报错", err)
  2729. }
  2730. }
  2731. }
  2732. }
  2733. dialysisOrder.Stage = 2
  2734. dialysisOrder.FinishNurse = nurseID
  2735. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2736. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2737. dialysisOrder.EndTime = endDate.Unix()
  2738. // 长沙南雅需求
  2739. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2740. //获取最后1条监测的数据
  2741. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2742. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2743. var accumulatedBloodVolume float64
  2744. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2745. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2746. fmt.Println(err)
  2747. // 查询未执行的医嘱
  2748. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2749. for _, item := range doctorAdvice {
  2750. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2751. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2752. redis := service.RedisClient()
  2753. //清空key 值
  2754. redis.Set(key, "", time.Second)
  2755. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2756. redis.Set(keyTwo, "", time.Second)
  2757. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2758. redis.Set(keyThree, "", time.Second)
  2759. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2760. theTime := toTime.Format("2006-01-02")
  2761. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2762. redis.Set(keyFour, "", time.Second)
  2763. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2764. redis.Set(keyFive, "", time.Second)
  2765. defer redis.Close()
  2766. }
  2767. }
  2768. go func() {
  2769. ssoDomain := beego.AppConfig.String("call_domain")
  2770. api := ssoDomain + "/index/downpatient"
  2771. values := make(url.Values)
  2772. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2773. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2774. values.Set("patient_id", strconv.FormatInt(id, 10))
  2775. http.PostForm(api, values)
  2776. }()
  2777. if err == nil {
  2778. c.ServeSuccessJSON(map[string]interface{}{
  2779. "dialysisOrder": dialysisOrder,
  2780. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2781. })
  2782. } else {
  2783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2784. }
  2785. }
  2786. }
  2787. func (c *DialysisAPIController) GetAllZone() {
  2788. adminUserInfo := c.GetMobileAdminUserInfo()
  2789. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2790. if err == nil {
  2791. c.ServeSuccessJSON(map[string]interface{}{
  2792. "zone": zone,
  2793. })
  2794. }
  2795. }
  2796. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2797. adminUserInfo := c.GetMobileAdminUserInfo()
  2798. page, _ := c.GetInt64("page", 1)
  2799. limit, _ := c.GetInt64("limit", 10)
  2800. schedulType, _ := c.GetInt64("schedul_type", 0)
  2801. startTime, _ := c.GetInt64("schedul_time", 0)
  2802. partitionType, _ := c.GetInt64("partition_type", 0)
  2803. keywords := c.GetString("keywords")
  2804. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2805. if err == nil {
  2806. c.ServeSuccessJSON(map[string]interface{}{
  2807. "schedule": dialysisSchedule,
  2808. })
  2809. }
  2810. return
  2811. }
  2812. // /m/api/dialysis/start [post]
  2813. // @param patient_id:int
  2814. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2815. // @param nurse:int 上机护士
  2816. // @param bed:int 床位号
  2817. func (this *DialysisAPIController) StartDialysis() {
  2818. patientID, _ := this.GetInt64("patient_id")
  2819. recordDateStr := this.GetString("record_date")
  2820. nurseID, _ := this.GetInt64("start_nurse")
  2821. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2822. blood_drawing, _ := this.GetInt64("blood_drawing")
  2823. schedual_type, _ := this.GetInt64("schedual_type")
  2824. bedID, _ := this.GetInt64("bed")
  2825. start_time := this.GetString("start_time")
  2826. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2827. change_nurse, _ := this.GetInt64("change_nurse")
  2828. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2829. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2830. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2831. puncture_needle := this.GetString("puncture_needle")
  2832. puncture_way := this.GetString("puncture_way")
  2833. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2834. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2835. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2836. zone_id, _ := this.GetInt64("zone_id")
  2837. elecsign := this.GetString("url")
  2838. nuclein_date_str := this.GetString("nuclein_date_str")
  2839. schedule_remark := this.GetString("schedule_remark")
  2840. order_remark := this.GetString("order_remark")
  2841. catheter_operation := this.GetString("catheter_operation")
  2842. blood_flow_volume := this.GetString("blood_flow_volume")
  2843. dialysis_strainer := this.GetString("dialysis_strainer")
  2844. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2846. return
  2847. }
  2848. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2849. if parseStartDateErr != nil {
  2850. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2852. return
  2853. }
  2854. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2855. if parseErr != nil {
  2856. this.ErrorLog("时间解析失败:%v", parseErr)
  2857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2858. return
  2859. }
  2860. adminUserInfo := this.GetMobileAdminUserInfo()
  2861. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2862. if getPatientErr != nil {
  2863. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2865. return
  2866. } else if patient == nil {
  2867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2868. return
  2869. }
  2870. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2871. if getNurseErr != nil {
  2872. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2874. return
  2875. } else if nurse == nil {
  2876. this.ErrorLog("护士不存在")
  2877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2878. return
  2879. }
  2880. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2881. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2882. if getDeviceNumberErr != nil {
  2883. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2885. return
  2886. } else if deviceNumber == nil {
  2887. this.ErrorLog("床位号不存在")
  2888. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2889. return
  2890. }
  2891. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2892. if getRecordErr != nil {
  2893. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2895. return
  2896. } else if dialysisRecord != nil {
  2897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2898. return
  2899. }
  2900. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2901. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2902. timeLayout := "2006-01-02 15:04:05"
  2903. loc, _ := time.LoadLocation("Local")
  2904. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2905. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2906. schedulestartTime := theStartTime.Unix()
  2907. scheduleendTime := theEndTime.Unix()
  2908. var theNucleinDate int64
  2909. timeLayoutOne := "2006-01-02"
  2910. if len(nuclein_date_str) > 0 {
  2911. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2912. if err != nil {
  2913. utils.ErrorLog(err.Error())
  2914. }
  2915. theNucleinDate = theTime.Unix()
  2916. }
  2917. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2918. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2919. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2920. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2921. //查询该床位是否有人用了
  2922. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2923. if err == gorm.ErrRecordNotFound { //空床位
  2924. // 修改了床位逻辑
  2925. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2926. if daySchedule.ID > 0 {
  2927. daySchedule.PartitionId = deviceNumber.ZoneID
  2928. daySchedule.BedId = bedID
  2929. daySchedule.ScheduleType = schedual_type
  2930. daySchedule.UpdatedTime = time.Now().Unix()
  2931. xtSchedule := models.Schedule{
  2932. PartitionId: deviceNumber.ZoneID,
  2933. BedId: bedID,
  2934. ScheduleType: schedual_type,
  2935. UpdatedTime: time.Now().Unix(),
  2936. }
  2937. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2938. if err != nil {
  2939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2940. return
  2941. }
  2942. }
  2943. } else if err == nil {
  2944. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2945. if order.ID > 0 { //该机位被其他人占用了
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2947. return
  2948. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2949. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2950. if daySchedule.ID > 0 {
  2951. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2952. if err != nil {
  2953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2954. return
  2955. }
  2956. }
  2957. }
  2958. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2960. return
  2961. }
  2962. //else if order.ID == 0 { //该床位没被占用
  2963. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2964. // if daySchedule.ID > 0 {
  2965. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2966. // //daySchedule.BedId = bedID
  2967. // //daySchedule.ScheduleType = schedual_type
  2968. // //daySchedule.UpdatedTime = time.Now().Unix()
  2969. // //err := service.UpdateSchedule(&daySchedule)
  2970. // xtSchedule := models.Schedule{
  2971. // PartitionId: deviceNumber.ZoneID,
  2972. // BedId: bedID,
  2973. // ScheduleType: schedual_type,
  2974. // UpdatedTime: time.Now().Unix(),
  2975. // }
  2976. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2977. // if err != nil {
  2978. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2979. // return
  2980. // }
  2981. // }
  2982. //}
  2983. //}
  2984. } else if err != nil {
  2985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2986. return
  2987. }
  2988. // 查询信息规挡的设置天数
  2989. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2990. if infor.ID > 0 && infor.WeekDay > 0 {
  2991. var cha_time int64
  2992. timeNowStr := time.Now().Format("2006-01-02")
  2993. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2994. //今日的日期减去设置的日期
  2995. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2996. if cha_time >= recordDate.Unix() {
  2997. //查询审核是否允许
  2998. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2999. //申请状态不允许的情况 拒绝修改
  3000. if infor.ApplicationStatus != 1 {
  3001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3002. return
  3003. }
  3004. }
  3005. }
  3006. dialysisRecord = &models.DialysisOrder{
  3007. DialysisDate: recordDate.Unix(),
  3008. UserOrgId: adminUserInfo.Org.Id,
  3009. PatientId: patientID,
  3010. Stage: 1,
  3011. BedID: bedID,
  3012. StartNurse: nurseID,
  3013. Status: 1,
  3014. StartTime: startDate.Unix(),
  3015. CreatedTime: time.Now().Unix(),
  3016. UpdatedTime: time.Now().Unix(),
  3017. PunctureNurse: puncture_nurse,
  3018. Creator: adminUserInfo.AdminUser.Id,
  3019. Modifier: adminUserInfo.AdminUser.Id,
  3020. SchedualType: schedual_type,
  3021. WashpipeNurse: washpipe_nurse,
  3022. ChangeNurse: change_nurse,
  3023. DifficultPunctureNurse: difficult_puncture_nurse,
  3024. NewFistulaNurse: new_fistula_nurse,
  3025. ZoneId: zone_id,
  3026. QualityNurseId: quality_nurse_id,
  3027. PunctureNeedle: puncture_needle,
  3028. PunctureWay: puncture_way,
  3029. DialysisIrrigation: dialysis_irrigation,
  3030. DialysisDialyszers: dialysis_dialyszers,
  3031. BloodAccessId: blood_access_id,
  3032. Url: elecsign,
  3033. NucleinDate: theNucleinDate,
  3034. ScheduleRemark: schedule_remark,
  3035. OrderRemark: order_remark,
  3036. CatheterOperation: catheter_operation,
  3037. BloodFlowVolume: blood_flow_volume,
  3038. BloodDrawing: blood_drawing,
  3039. DialysisStrainer: dialysis_strainer,
  3040. }
  3041. //查询该床位是否有人用了
  3042. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3043. if errorscode == gorm.ErrRecordNotFound {
  3044. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3045. finish := models.XtDialysisFinish{
  3046. IsFinish: 1,
  3047. UserOrgId: adminUserInfo.Org.Id,
  3048. Status: 1,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. Module: 6,
  3052. RecordDate: schedulestartTime,
  3053. Sourse: 1,
  3054. PatientId: patientID,
  3055. }
  3056. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3057. if dialysisFinish.ID == 0 {
  3058. service.CreateDialysisFinish(finish)
  3059. }
  3060. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3061. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3062. //统计该患者总次数
  3063. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3064. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3065. }
  3066. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3067. //统计该患者总次数
  3068. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3069. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3070. }
  3071. redis := service.RedisClient()
  3072. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3073. redis.Set(key, "", time.Second)
  3074. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3075. //清空key 值
  3076. redis.Set(keyOne, "", time.Second)
  3077. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3078. //清空key 值
  3079. redis.Set(keyTwo, "", time.Second)
  3080. if createErr != nil {
  3081. this.ErrorLog("上机失败:%v", createErr)
  3082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3083. return
  3084. }
  3085. }
  3086. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3087. var tempdispose string
  3088. // 只针对中能建
  3089. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3090. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3091. }
  3092. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3093. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3094. }
  3095. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3096. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3097. //}
  3098. var ultrafiltration_rate float64
  3099. var ultrafiltration_rate_one string
  3100. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3101. //后期预增脱水量
  3102. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3103. if prescription.ID > 0 {
  3104. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3105. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3106. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3107. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3108. }
  3109. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3110. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3111. }
  3112. //针对医师汇
  3113. if adminUserInfo.Org.Id == 10121 {
  3114. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3115. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3116. }
  3117. //针对通道
  3118. if adminUserInfo.Org.Id == 10234 {
  3119. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3120. }
  3121. //针对监利大垸医院
  3122. if template.TemplateId == 41 {
  3123. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3124. }
  3125. //针对肇庆三鹤血液透析中心
  3126. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3127. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3128. }
  3129. if adminUserInfo.Org.Id == 10469 {
  3130. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3131. }
  3132. if adminUserInfo.Org.Id == 10667 {
  3133. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3134. }
  3135. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3137. }
  3138. // 只针对方济医院
  3139. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3140. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3141. ultrafiltration_rate = value
  3142. }
  3143. //针对
  3144. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3145. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3146. ultrafiltration_rate = ultrafiltration_rate / 1000
  3147. }
  3148. if adminUserInfo.Org.Id == 10551 {
  3149. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3150. ultrafiltration_rate = ultrafiltration_rate / 1000
  3151. }
  3152. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3153. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3154. ultrafiltration_rate = ultrafiltration_rate / 1000
  3155. }
  3156. if adminUserInfo.Org.Id == 10580 {
  3157. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3158. ultrafiltration_rate = ultrafiltration_rate / 1000
  3159. }
  3160. if adminUserInfo.Org.Id == 10629 {
  3161. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3162. ultrafiltration_rate = ultrafiltration_rate / 1000
  3163. }
  3164. if adminUserInfo.Org.Id == 10644 {
  3165. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3166. ultrafiltration_rate = ultrafiltration_rate / 1000
  3167. }
  3168. if adminUserInfo.Org.Id == 10667 {
  3169. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3170. ultrafiltration_rate = ultrafiltration_rate / 1000
  3171. }
  3172. if adminUserInfo.Org.Id == 10693 {
  3173. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3174. ultrafiltration_rate = ultrafiltration_rate
  3175. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3176. }
  3177. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3178. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3179. ultrafiltration_rate = ultrafiltration_rate
  3180. }
  3181. if adminUserInfo.Org.Id == 10702 {
  3182. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3183. ultrafiltration_rate = ultrafiltration_rate / 1000
  3184. }
  3185. if adminUserInfo.Org.Id == 10723 {
  3186. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3187. ultrafiltration_rate = ultrafiltration_rate / 1000
  3188. }
  3189. if adminUserInfo.Org.Id == 10721 {
  3190. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3191. ultrafiltration_rate = ultrafiltration_rate / 1000
  3192. }
  3193. }
  3194. }
  3195. record := models.MonitoringRecord{
  3196. UserOrgId: adminUserInfo.Org.Id,
  3197. PatientId: patientID,
  3198. DialysisOrderId: dialysisRecord.ID,
  3199. MonitoringDate: schedulestartTime,
  3200. OperateTime: startDate.Unix(),
  3201. // MonitoringTime: recordTime,
  3202. MonitoringNurse: nurseID,
  3203. Dispose: tempdispose,
  3204. UltrafiltrationRate: ultrafiltration_rate,
  3205. UltrafiltrationVolume: 0,
  3206. Status: 1,
  3207. CreatedTime: time.Now().Unix(),
  3208. UpdatedTime: time.Now().Unix(),
  3209. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3210. }
  3211. //只针对广慈医院
  3212. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 {
  3213. // 查询病人是否有透前评估数据
  3214. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3215. //如果有数据就插入
  3216. if errcode == nil {
  3217. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3218. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3219. record.BreathingRate = befor.BreathingRate
  3220. record.PulseFrequency = befor.PulseFrequency
  3221. record.Temperature = befor.Temperature
  3222. }
  3223. }
  3224. //孝昌
  3225. if adminUserInfo.Org.Id == 10693 {
  3226. // 查询病人是否有透前评估数据
  3227. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3228. //如果有数据就插入
  3229. if errcode == nil {
  3230. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3231. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3232. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3233. record.BreathingRate = befor.BreathingRate
  3234. }
  3235. }
  3236. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3237. if newdialysisRecord.ID > 0 {
  3238. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3239. record.Temperature = 36.5
  3240. record.ArterialPressure = -100
  3241. record.DialysateTemperature = 36.5
  3242. record.Conductivity = 14
  3243. record.BreathingRate = "20"
  3244. record.VenousPressure = 80
  3245. record.TransmembranePressure = 60
  3246. record.Dispose = catheter_operation
  3247. }
  3248. //针对新化博翔
  3249. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3250. record.BloodOxygenSaturation = "99"
  3251. record.Conductivity = 14
  3252. record.DialysateTemperature = 36.5
  3253. record.BreathingRate = "20"
  3254. }
  3255. //针对兰溪人民医院的需求
  3256. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3257. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3258. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3259. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3260. record.Temperature = befor.Temperature
  3261. record.PulseFrequency = befor.PulseFrequency
  3262. record.BreathingRate = befor.BreathingRate
  3263. }
  3264. //针对乐山友谊医院的需求
  3265. if adminUserInfo.Org.Id == 10677 {
  3266. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3267. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3268. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3269. record.Temperature = befor.Temperature
  3270. record.PulseFrequency = befor.PulseFrequency
  3271. record.BreathingRate = befor.BreathingRate
  3272. }
  3273. //新化博翔
  3274. if adminUserInfo.Org.Id == 10447 {
  3275. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3276. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3277. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3278. record.BreathingRate = befor.BreathingRate
  3279. }
  3280. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3281. record.PulseFrequency = 80
  3282. record.Temperature = 36.5
  3283. }
  3284. //诊断灵山圣康
  3285. if adminUserInfo.Org.Id == 10375 {
  3286. record.Conductivity = 13.8
  3287. record.DialysateTemperature = 37
  3288. record.DialysateFlow = 500
  3289. record.BloodFlowVolume = 200
  3290. record.BreathingRate = "18"
  3291. record.SodiumConcentration = 140
  3292. }
  3293. //江成肾病医院
  3294. if adminUserInfo.Org.Id == 10517 {
  3295. record.SodiumConcentration = 138
  3296. record.DialysateTemperature = 36.5
  3297. }
  3298. //濉溪杏康血液透析中心
  3299. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3300. record.BloodFlowVolume = prescription.BloodFlowVolume
  3301. }
  3302. if adminUserInfo.Org.Id != 10683 {
  3303. err = service.CreateMonitor(&record)
  3304. }
  3305. //记录日志
  3306. byterequest, _ := json.Marshal(record)
  3307. monitorRecordLog := models.XtMonitorRecordLog{
  3308. RecordDate: record.MonitoringDate,
  3309. PatientId: record.PatientId,
  3310. Module: 1,
  3311. AdminUserId: adminUserInfo.AdminUser.Id,
  3312. Ctime: time.Now().Unix(),
  3313. Mtime: 0,
  3314. Status: 1,
  3315. UserOrgId: record.UserOrgId,
  3316. ErrLog: string(byterequest),
  3317. Source: "执行上机时新增监测",
  3318. }
  3319. service.CreateMonitorRecordLog(monitorRecordLog)
  3320. finish := models.XtDialysisFinish{
  3321. IsFinish: 1,
  3322. UserOrgId: adminUserInfo.Org.Id,
  3323. Status: 1,
  3324. Ctime: time.Now().Unix(),
  3325. Mtime: 0,
  3326. Module: 7,
  3327. RecordDate: schedulestartTime,
  3328. Sourse: 1,
  3329. PatientId: patientID,
  3330. }
  3331. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3332. if dialysisFinish.ID == 0 {
  3333. service.CreateDialysisFinish(finish)
  3334. }
  3335. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3336. redis := service.RedisClient()
  3337. //清空key 值
  3338. redis.Set(key, "", time.Second)
  3339. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3340. redis.Set(keyOne, "", time.Second)
  3341. defer redis.Close()
  3342. if err != nil {
  3343. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3344. return
  3345. }
  3346. }
  3347. go func() {
  3348. ssoDomain := beego.AppConfig.String("call_domain")
  3349. api := ssoDomain + "/index/uppatient"
  3350. values := make(url.Values)
  3351. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3352. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3353. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3354. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3355. http.PostForm(api, values)
  3356. }()
  3357. this.ServeSuccessJSON(map[string]interface{}{
  3358. "dialysis_order": newdialysisRecord,
  3359. "monitor": record,
  3360. })
  3361. return
  3362. }
  3363. func (c *DialysisAPIController) PostSolution() {
  3364. id, _ := c.GetInt64("patient", 0)
  3365. recordDateStr := c.GetString("record_date")
  3366. if id <= 0 {
  3367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3368. return
  3369. }
  3370. adminUserInfo := c.GetMobileAdminUserInfo()
  3371. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3372. if patient.ID == 0 {
  3373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3374. return
  3375. }
  3376. if len(recordDateStr) == 0 {
  3377. recordDateStr = time.Now().Format("2006-01-02")
  3378. }
  3379. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3380. if parseDateErr != nil {
  3381. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3383. return
  3384. }
  3385. mode_id, _ := c.GetInt64("mode_id", 0)
  3386. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3387. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3388. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3389. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3390. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3391. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3392. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3393. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3394. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3395. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3396. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3397. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3398. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3399. kalium, _ := c.GetFloat("kalium", 0)
  3400. sodium, _ := c.GetFloat("sodium", 0)
  3401. calcium, _ := c.GetFloat("calcium", 0)
  3402. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3403. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3404. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3405. glucose, _ := c.GetFloat("glucose", 0)
  3406. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3407. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3408. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3409. conductivity, _ := c.GetFloat("conductivity", 0)
  3410. remark := c.GetString("remark")
  3411. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3412. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3413. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3414. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3415. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3416. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3417. special_medicine_other := c.GetString("special_medicine_other")
  3418. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3419. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3420. blood_access, _ := c.GetInt64("blood_access", 0)
  3421. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3422. body_fluid_other := c.GetString("body_fluid_other")
  3423. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3424. niprocart, _ := c.GetInt64("niprocart", 0)
  3425. jms, _ := c.GetInt64("jms", 0)
  3426. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3427. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3428. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3429. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3430. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3431. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3432. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3433. injector, _ := c.GetInt64("injector", 0)
  3434. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3435. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3436. safe_package, _ := c.GetInt64("package", 0)
  3437. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3438. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3439. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3440. blood := c.GetString("blood")
  3441. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3442. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3443. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3444. displace_speed := c.GetString("displace_speed")
  3445. illness, _ := c.GetInt64("illness")
  3446. amylaceum := c.GetString("amylaceum")
  3447. single_time := c.GetString("single_time")
  3448. single_water := c.GetString("single_water")
  3449. replacement_flow := c.GetString("replacement_flow")
  3450. plasma_separator := c.GetString("plasma_separator")
  3451. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3452. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3453. oxygen_flow := c.GetString("oxygen_flow")
  3454. oxygen_time := c.GetString("oxygen_time")
  3455. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3456. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3457. puncture_needle := c.GetString("puncture_needle")
  3458. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3459. epo := c.GetString("epo")
  3460. epo_count, _ := c.GetFloat("epo_count", 0)
  3461. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3462. pre_impulse := c.GetString("pre_impulse")
  3463. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3464. admin_user_id, _ := c.GetInt64("admin_user_id")
  3465. is_water := c.GetString("is_water")
  3466. add_amount, _ := c.GetFloat("add_amount")
  3467. reduce_amount, _ := c.GetFloat("reduce_amount")
  3468. prescribing_number, _ := c.GetFloat("prescribing_number")
  3469. treatment_remark := c.GetString("treatment_remark")
  3470. prescription_sodium := c.GetString("prescription_sodium")
  3471. start_sodium := c.GetString("start_sodium")
  3472. sodium_curve := c.GetString("sodium_curve")
  3473. var is_war int64
  3474. if is_water == "是" {
  3475. is_war = 1
  3476. }
  3477. if is_water == "否" {
  3478. is_war = 2
  3479. }
  3480. if is_water == "请选择" {
  3481. is_war = 0
  3482. }
  3483. drhy_water := c.GetString("drhy_water")
  3484. dry_water_hour := c.GetString("dry_water_hour")
  3485. water_machine := c.GetString("water_machine")
  3486. dialysis_remark := c.GetString("dialysis_remark")
  3487. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3488. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3489. prescription_water, _ := c.GetFloat("prescription_water")
  3490. dialysis_strainer := c.GetString("dialysis_strainer")
  3491. chaptalization := c.GetString("chaptalization")
  3492. washing_time := c.GetString("washing_time")
  3493. warsh_count := c.GetString("warsh_count")
  3494. blood_access_part_id := c.GetString("blood_access_part_id")
  3495. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3496. dialyzate := c.GetString("dialyzate")
  3497. if mode_id > 0 {
  3498. var str string
  3499. //查找该机构用的是什么透析器
  3500. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3501. if filedConfig.ID > 0 {
  3502. str = dialyzerPerfusionApparatus
  3503. } else {
  3504. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3505. }
  3506. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3507. }
  3508. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3509. //
  3510. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3511. // if appRole.UserType == 3 {
  3512. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3513. // if getPermissionErr != nil {
  3514. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3515. // return
  3516. // } else if headNursePermission == nil {
  3517. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3518. // return
  3519. // }
  3520. // }
  3521. //}
  3522. // 查询信息规挡的设置天数
  3523. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3524. if infor.ID > 0 && infor.WeekDay > 0 {
  3525. var cha_time int64
  3526. timeNowStr := time.Now().Format("2006-01-02")
  3527. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3528. //今日的日期减去设置的日期
  3529. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3530. if cha_time >= recordDate.Unix() {
  3531. //查询审核是否允许
  3532. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3533. //申请状态不允许的情况 拒绝修改
  3534. if infor.ApplicationStatus != 1 {
  3535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3536. return
  3537. }
  3538. }
  3539. }
  3540. prescription := models.DialysisPrescription{
  3541. UserOrgId: adminUserInfo.Org.Id,
  3542. PatientId: id,
  3543. RecordDate: recordDate.Unix(),
  3544. ModeId: mode_id,
  3545. DialysisDuration: dialysis_duration,
  3546. Dialyzer: dialyzer,
  3547. PerfusionApparatus: perfusion_apparatus,
  3548. BloodFlowVolume: blood_flow_volume,
  3549. DewaterAmount: dewater_amount,
  3550. DisplaceLiqui: displace_liqui,
  3551. ReplacementWay: replacement_way,
  3552. Anticoagulant: anticoagulant,
  3553. AnticoagulantShouji: anticoagulant_shouji,
  3554. AnticoagulantWeichi: anticoagulant_weichi,
  3555. AnticoagulantZongliang: anticoagulant_zongliang,
  3556. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3557. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3558. Kalium: kalium,
  3559. Sodium: sodium,
  3560. Calcium: calcium,
  3561. Bicarbonate: bicarbonate,
  3562. Glucose: glucose,
  3563. // DryWeight: dry_weight,
  3564. DialysateFlow: dialysate_flow,
  3565. DialysateTemperature: dialysate_temperature,
  3566. Conductivity: conductivity,
  3567. Remark: remark,
  3568. Status: 1,
  3569. CreatedTime: time.Now().Unix(),
  3570. UpdatedTime: time.Now().Unix(),
  3571. DialysisDurationMinute: dialysisDurationMinute,
  3572. DialysisDurationHour: dialysisDurationHour,
  3573. TargetUltrafiltration: targetUltrafiltration,
  3574. DialysateFormulation: dialysateFormulation,
  3575. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3576. BodyFluid: body_fluid,
  3577. SpecialMedicine: special_medicine,
  3578. SpecialMedicineOther: special_medicine_other,
  3579. DisplaceLiquiPart: displace_liqui_part,
  3580. DisplaceLiquiValue: displace_liqui_value,
  3581. BloodAccess: blood_access,
  3582. Ultrafiltration: ultrafiltration,
  3583. BodyFluidOther: body_fluid_other,
  3584. ReplacementTotal: replacement_total,
  3585. Niprocart: niprocart,
  3586. Jms: jms,
  3587. FistulaNeedleSet: fistula_needle_set,
  3588. FistulaNeedleSet16: fistula_needle_set_16,
  3589. Hemoperfusion: hemoperfusion,
  3590. DialyserSterilised: dialyser_sterilised,
  3591. Filtryzer: filtryzer,
  3592. TargetKtv: target_ktv,
  3593. Dialyzers: dialyzers,
  3594. Injector: injector,
  3595. Bloodlines: bloodlines,
  3596. TubingHemodialysis: tubing_hemodialysis,
  3597. Package: safe_package,
  3598. ALiquid: a_liquid,
  3599. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3600. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3601. Blood: blood,
  3602. DialysisDialyszers: dialysis_dialyszers,
  3603. DialysisIrrigation: dialysis_irrigation,
  3604. AntioxidantCommodityName: antioxidant_commodity_name,
  3605. DisplaceSpeed: displace_speed,
  3606. Illness: illness,
  3607. Amylaceum: amylaceum,
  3608. SingleWater: single_water,
  3609. SingleTime: single_time,
  3610. ReplacementFlow: replacement_flow,
  3611. PlasmaSeparator: plasma_separator,
  3612. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3613. OxygenUptake: oxygen_uptake,
  3614. OxygenTime: oxygen_time,
  3615. OxygenFlow: oxygen_flow,
  3616. HemodialysisPipelines: hemodialysis_pipelines,
  3617. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3618. PunctureNeedle: puncture_needle,
  3619. PunctureNeedleCount: puncture_needle_count,
  3620. Epo: epo,
  3621. EpoCount: epo_count,
  3622. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3623. PreImpulse: impulse,
  3624. AdminUserId: admin_user_id,
  3625. IsWater: is_war,
  3626. DrhyWater: drhy_water,
  3627. DryWaterHour: dry_water_hour,
  3628. WaterMachine: water_machine,
  3629. AddAmount: add_amount,
  3630. ReduceAmount: reduce_amount,
  3631. DialysisRemark: dialysis_remark,
  3632. PrescribingNumber: prescribing_number,
  3633. PrescriptionSodium: prescription_sodium,
  3634. StartSodium: start_sodium,
  3635. SodiumCurve: sodium_curve,
  3636. TreatmentRemark: treatment_remark,
  3637. DialysisFluidFlow: dialysis_fluid_flow,
  3638. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3639. PrescriptionWater: prescription_water,
  3640. DialysisStrainer: dialysis_strainer,
  3641. Chaptalization: chaptalization,
  3642. WashingTime: washing_time,
  3643. WarshCount: warsh_count,
  3644. BloodAccessPartId: blood_access_part_id,
  3645. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3646. Dialyzate: dialyzate,
  3647. }
  3648. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3649. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3650. //
  3651. if appRole.UserType == 2 || appRole.UserType == 1 {
  3652. prescription_doctor = adminUserInfo.AdminUser.Id
  3653. prescription.PrescriptionDoctor = prescription_doctor
  3654. }
  3655. if dialysisPrescription.ID == 0 { //新增
  3656. prescription.Creater = adminUserInfo.AdminUser.Id
  3657. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3658. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3659. }
  3660. } else { //修改
  3661. if dialysisPrescription.Creater == 0 {
  3662. prescription.Creater = adminUserInfo.AdminUser.Id
  3663. } else {
  3664. prescription.Creater = dialysisPrescription.Creater
  3665. if adminUserInfo.Org.Id == 9882 {
  3666. if appRole.UserType == 2 || appRole.UserType == 1 {
  3667. prescription.Creater = adminUserInfo.AdminUser.Id
  3668. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3669. }
  3670. }
  3671. }
  3672. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3673. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3674. }
  3675. //if/**/
  3676. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3677. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3678. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3679. // if getPermissionErr != nil {
  3680. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3681. // return
  3682. // } else if headNursePermission == nil {
  3683. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3684. // return
  3685. // }
  3686. //}
  3687. //prescription.Creater = dialysisPrescription.Creater
  3688. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3689. prescription.Modifier = adminUserInfo.AdminUser.Id
  3690. prescription.ID = dialysisPrescription.ID
  3691. }
  3692. solution := models.DialysisSolution{
  3693. RegistrarsId: adminUserInfo.AdminUser.Id,
  3694. UserOrgId: adminUserInfo.Org.Id,
  3695. Doctor: prescription_doctor,
  3696. PatientId: id,
  3697. ModeId: mode_id,
  3698. DialysisDuration: dialysis_duration,
  3699. PerfusionApparatus: perfusion_apparatus,
  3700. BloodFlowVolume: blood_flow_volume,
  3701. Dewater: dewater_amount,
  3702. DisplaceLiqui: displace_liqui,
  3703. ReplacementWay: replacement_way,
  3704. Anticoagulant: anticoagulant,
  3705. AnticoagulantShouji: anticoagulant_shouji,
  3706. AnticoagulantWeichi: anticoagulant_weichi,
  3707. AnticoagulantZongliang: anticoagulant_zongliang,
  3708. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3709. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3710. Kalium: kalium,
  3711. Sodium: sodium,
  3712. Calcium: calcium,
  3713. Bicarbonate: bicarbonate,
  3714. Glucose: glucose,
  3715. // DryWeight: dry_weight,
  3716. DialysateFlow: dialysate_flow,
  3717. DialysateTemperature: dialysate_temperature,
  3718. Conductivity: conductivity,
  3719. Remark: remark,
  3720. Status: 1,
  3721. CreatedTime: time.Now().Unix(),
  3722. UpdatedTime: time.Now().Unix(),
  3723. DialysisDurationMinute: dialysisDurationMinute,
  3724. DialysisDurationHour: dialysisDurationHour,
  3725. TargetUltrafiltration: targetUltrafiltration,
  3726. DialysateFormulation: dialysateFormulation,
  3727. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3728. BodyFluid: body_fluid,
  3729. SpecialMedicine: special_medicine,
  3730. SpecialMedicineOther: special_medicine_other,
  3731. DisplaceLiquiPart: displace_liqui_part,
  3732. DisplaceLiquiValue: displace_liqui_value,
  3733. BloodAccess: blood_access,
  3734. Ultrafiltration: ultrafiltration,
  3735. BodyFluidOther: body_fluid_other,
  3736. ReplacementTotal: replacement_total,
  3737. TargetKtv: target_ktv,
  3738. DialysisDialyszers: dialysis_dialyszers,
  3739. DialysisIrrigation: dialysis_irrigation,
  3740. HemodialysisPipelines: hemodialysis_pipelines,
  3741. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3742. PunctureNeedle: puncture_needle,
  3743. PunctureNeedleCount: puncture_needle_count,
  3744. Epo: epo,
  3745. EpoCount: epo_count,
  3746. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3747. PreImpulse: impulse,
  3748. SolutionStatus: 1,
  3749. DialysisRemark: dialysis_remark,
  3750. PrescribingNumber: prescribing_number,
  3751. PrescriptionSodium: prescription_sodium,
  3752. StartSodium: start_sodium,
  3753. SodiumCurve: sodium_curve,
  3754. TreatmentRemark: treatment_remark,
  3755. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3756. DialysisFluidFlow: dialysis_fluid_flow,
  3757. PrescriptionWater: prescription_water,
  3758. DialysisStrainer: dialysis_strainer,
  3759. Chaptalization: chaptalization,
  3760. WashingTime: washing_time,
  3761. WarshCount: warsh_count,
  3762. BloodAccessPartId: blood_access_part_id,
  3763. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3764. Dialyzate: dialyzate,
  3765. }
  3766. //针对河间咸的
  3767. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3768. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3769. solution.DisplaceLiquiPart = 0
  3770. solution.DisplaceLiquiValue = 0
  3771. }
  3772. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3773. prescription.DisplaceLiquiPart = 0
  3774. prescription.DisplaceLiquiValue = 0
  3775. }
  3776. }
  3777. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3778. if solution.PrescribingNumber == 0 {
  3779. solution.PrescribingNumber = 1
  3780. }
  3781. if prescription.PrescribingNumber == 0 {
  3782. prescription.PrescribingNumber = 1
  3783. }
  3784. if solution.PrescribingNumber == 0 && id == 14682 {
  3785. solution.PrescribingNumber = 2
  3786. }
  3787. if solution.PrescribingNumber == 0 && id == 18560 {
  3788. solution.PrescribingNumber = 2
  3789. }
  3790. if prescription.PrescribingNumber == 0 && id == 14682 {
  3791. prescription.PrescribingNumber = 2
  3792. }
  3793. if prescription.PrescribingNumber == 0 && id == 18560 {
  3794. prescription.PrescribingNumber = 2
  3795. }
  3796. }
  3797. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3798. //记录日志
  3799. byterequest, _ := json.Marshal(prescription)
  3800. prescriptionLog := models.XtDialysisPrescriptionLog{
  3801. UserOrgId: prescription.UserOrgId,
  3802. Ctime: time.Now().Unix(),
  3803. Mtime: 0,
  3804. ErrLog: string(byterequest),
  3805. AdminUserId: adminUserInfo.AdminUser.Id,
  3806. RecordDate: prescription.RecordDate,
  3807. PatientId: prescription.PatientId,
  3808. Source: "手机端新增长期处方",
  3809. Status: 1,
  3810. }
  3811. service.CreatePrescriptionLog(prescriptionLog)
  3812. finish := models.XtDialysisFinish{
  3813. IsFinish: 1,
  3814. UserOrgId: adminUserInfo.Org.Id,
  3815. Status: 1,
  3816. Ctime: time.Now().Unix(),
  3817. Mtime: 0,
  3818. Module: 1,
  3819. RecordDate: recordDate.Unix(),
  3820. Sourse: 1,
  3821. PatientId: id,
  3822. }
  3823. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3824. if dialysisFinish.ID == 0 {
  3825. service.CreateDialysisFinish(finish)
  3826. }
  3827. //获取最新1条
  3828. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3829. //更新状态
  3830. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3831. //长沙南雅医院,自动生成抗凝剂的临时处方
  3832. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3833. if prescribing_number == 0 {
  3834. prescribing_number = 1
  3835. }
  3836. advice := models.DoctorAdvice{
  3837. UserOrgId: adminUserInfo.Org.Id,
  3838. PatientId: id,
  3839. GroupNo: 0,
  3840. AdviceType: 2,
  3841. RecordDate: recordDate.Unix(),
  3842. AdviceDate: recordDate.Unix(),
  3843. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3844. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3845. AdviceDesc: "",
  3846. ReminderDate: 0,
  3847. SingleDose: prescription.AnticoagulantZongliang,
  3848. SingleDoseUnit: "iu",
  3849. DrugSpec: 0,
  3850. DrugSpecUnit: "",
  3851. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3852. PrescribingNumberUnit: "支",
  3853. DeliveryWay: "静脉注射",
  3854. ExecutionFrequency: "上机前",
  3855. AdviceDoctor: 0,
  3856. Status: 1,
  3857. CreatedTime: time.Now().Unix(),
  3858. UpdatedTime: time.Now().Unix(),
  3859. IsPrescription: 1,
  3860. ExecutionState: 2,
  3861. StopState: 2,
  3862. IsSettle: 2,
  3863. }
  3864. // 查询排班信息
  3865. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3866. if schedulePatient.ID > 0 {
  3867. if schedulePatient.ScheduleType == 1 {
  3868. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3869. }
  3870. if schedulePatient.ScheduleType == 2 {
  3871. advice.StartTime = recordDate.Unix() + 9*60*60
  3872. }
  3873. }
  3874. // 抗凝剂名称
  3875. switch anticoagulant {
  3876. case 1:
  3877. advice.AdviceName = "无肝素"
  3878. break
  3879. case 2:
  3880. advice.AdviceName = "普通肝素"
  3881. break
  3882. case 3:
  3883. advice.AdviceName = "低分子肝素"
  3884. break
  3885. case 4:
  3886. advice.AdviceName = "阿加曲班"
  3887. break
  3888. case 5:
  3889. advice.AdviceName = "枸橼酸钠"
  3890. break
  3891. case 6:
  3892. advice.AdviceName = "低分子肝素钙"
  3893. break
  3894. case 7:
  3895. advice.AdviceName = "低分子肝素钠"
  3896. break
  3897. case 8:
  3898. advice.AdviceName = "依诺肝素"
  3899. break
  3900. case 9:
  3901. advice.AdviceName = "达肝素"
  3902. break
  3903. case 10:
  3904. advice.AdviceName = "体外抗凝"
  3905. break
  3906. case 11:
  3907. advice.AdviceName = "那曲肝素"
  3908. break
  3909. case 12:
  3910. advice.AdviceName = "无抗凝剂"
  3911. break
  3912. }
  3913. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3914. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3915. advice.AdviceDoctor = appRole.AdminUserId
  3916. }
  3917. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3918. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3919. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3920. advice.AdviceName = "低分子肝素钠注射液"
  3921. // 修改患者临时医嘱里的抗凝剂医嘱
  3922. advice.ID = advicePrescription.ID
  3923. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3924. } else {
  3925. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3926. advice.AdviceName = "低分子肝素钠注射液"
  3927. service.CreateDoctorAdvice(&advice)
  3928. }
  3929. }
  3930. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3931. redis := service.RedisClient()
  3932. defer redis.Close()
  3933. //清空key 值
  3934. redis.Set(key, "", time.Second)
  3935. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3936. redis.Set(keyOne, "", time.Second)
  3937. }
  3938. //获取key,清空redis
  3939. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3940. redis := service.RedisClient()
  3941. defer redis.Close()
  3942. //清空key 值
  3943. redis.Set(key, "", time.Second)
  3944. //清空长期医嘱的key
  3945. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3946. redis.Set(soulution_key, "", time.Second)
  3947. //查询最近透析准备表里是否存在 透析器 灌流器
  3948. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3949. redis.Set(keyOne, "", time.Second)
  3950. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3951. redis.Set(keyTwo, "", time.Second)
  3952. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3953. redis.Set(keyThree, "", time.Second)
  3954. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3955. redis.Set(keyFour, "", time.Second)
  3956. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3957. //
  3958. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3959. //
  3960. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3961. //if len(mation)>0{
  3962. // for _, item := range splitStr {
  3963. // for _,it := range mation{
  3964. // if(item == it.SpecificationName){
  3965. //
  3966. // //查询最近一次的透析器
  3967. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3968. //
  3969. // if errcode == gorm.ErrRecordNotFound{
  3970. // //插入数据
  3971. // prepare := models.DialysisBeforePrepare{
  3972. // UserOrgId: adminUserInfo.Org.Id,
  3973. // PatientId: id,
  3974. // RecordDate: recordDate.Unix(),
  3975. // GoodTypeId: it.GoodTypeId,
  3976. // GoodId: it.ID,
  3977. // Count: 1,
  3978. // Ctime: time.Now().Unix(),
  3979. // Creater: adminUserInfo.AdminUser.Id,
  3980. // Status:1,
  3981. //
  3982. // }
  3983. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3984. // fmt.Println("",errcode)
  3985. // }
  3986. // }
  3987. // }
  3988. //
  3989. // }
  3990. //
  3991. // for _, item := range splitIrrigation {
  3992. // for _,it := range mation{
  3993. // if(item == it.SpecificationName){
  3994. // //查询最近一次的透析器
  3995. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3996. // if errcode == gorm.ErrRecordNotFound{
  3997. // //插入数据
  3998. // prepare := models.DialysisBeforePrepare{
  3999. // UserOrgId: adminUserInfo.Org.Id,
  4000. // PatientId: id,
  4001. // RecordDate: recordDate.Unix(),
  4002. // GoodTypeId: it.GoodTypeId,
  4003. // GoodId: it.ID,
  4004. // Count: 1,
  4005. // Ctime: time.Now().Unix(),
  4006. // Creater: adminUserInfo.AdminUser.Id,
  4007. // Status:1,
  4008. //
  4009. // }
  4010. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4011. // fmt.Println(errcode)
  4012. // }
  4013. // }
  4014. // }
  4015. // }
  4016. //}
  4017. c.ServeSuccessJSON(map[string]interface{}{
  4018. "solution": &solution,
  4019. "prescription": &prescription,
  4020. })
  4021. }
  4022. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4023. patient, _ := c.GetInt64("patient", 0)
  4024. adminUserInfo := c.GetMobileAdminUserInfo()
  4025. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4026. c.ServeSuccessJSON(map[string]interface{}{
  4027. "receiveTreatmentAsses": receiveTreatmentAsses,
  4028. })
  4029. }
  4030. func (this *DialysisAPIController) PostSignInfo() {
  4031. patientID, _ := this.GetInt64("patient_id")
  4032. recordDateStr := this.GetString("date")
  4033. if patientID <= 0 {
  4034. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4035. return
  4036. }
  4037. if len(recordDateStr) == 0 {
  4038. recordDateStr = time.Now().Format("2006-01-02")
  4039. }
  4040. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4041. if parseDateErr != nil {
  4042. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4044. return
  4045. }
  4046. adminInfo := this.GetMobileAdminUserInfo()
  4047. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4048. if err != nil {
  4049. this.ErrorLog("签名失败:%v", err)
  4050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4051. return
  4052. }
  4053. this.ServeSuccessJSON(map[string]interface{}{
  4054. "doctor_id": adminInfo.AdminUser.Id,
  4055. })
  4056. }
  4057. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4058. patientID, _ := this.GetInt64("patient_id")
  4059. adminInfo := this.GetMobileAdminUserInfo()
  4060. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4061. this.ServeSuccessJSON(map[string]interface{}{
  4062. "monitor": record,
  4063. })
  4064. }
  4065. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4066. thisTime := time.Now()
  4067. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4068. timeLayout := "2006-01-02 15:04:05"
  4069. loc, _ := time.LoadLocation("Local")
  4070. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4071. theAssessmentDateTime := theStartTime.Unix()
  4072. patientID, _ := this.GetInt64("patient_id")
  4073. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4074. adminInfo := this.GetMobileAdminUserInfo()
  4075. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4076. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4077. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4078. var ultrafiltration_rate float64
  4079. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4080. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4081. fmt.Println(evaluation)
  4082. fmt.Println("prescription.ID", prescription.ID)
  4083. if prescription.ID > 0 {
  4084. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4085. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4086. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4087. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4088. record.UltrafiltrationRate = ultrafiltration_rate
  4089. }
  4090. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4091. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4092. record.UltrafiltrationRate = ultrafiltration_rate
  4093. }
  4094. if adminInfo.Org.Id == 10510 {
  4095. record.UltrafiltrationRate = 0
  4096. }
  4097. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4098. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4099. record.UltrafiltrationRate = ultrafiltration_rate
  4100. }
  4101. if template.TemplateId == 20 || template.TemplateId == 22 {
  4102. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4103. record.UltrafiltrationRate = ultrafiltration_rate
  4104. }
  4105. // 只针对方济医院
  4106. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4107. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4108. ultrafiltration_rate = value
  4109. record.UltrafiltrationRate = ultrafiltration_rate
  4110. }
  4111. if template.TemplateId == 41 || template.TemplateId == 47 {
  4112. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4113. record.UltrafiltrationRate = ultrafiltration_rate
  4114. }
  4115. if template.TemplateId == 43 {
  4116. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4117. record.UltrafiltrationRate = ultrafiltration_rate
  4118. }
  4119. if template.TemplateId == 46 || template.TemplateId == 54 {
  4120. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4121. record.UltrafiltrationRate = ultrafiltration_rate
  4122. }
  4123. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  4124. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4125. record.UltrafiltrationRate = ultrafiltration_rate
  4126. }
  4127. if adminInfo.Org.Id == 10469 {
  4128. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4129. record.UltrafiltrationRate = ultrafiltration_rate
  4130. }
  4131. if adminInfo.Org.Id == 10667 {
  4132. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4133. record.UltrafiltrationRate = ultrafiltration_rate
  4134. }
  4135. if adminInfo.Org.Id == 10471 {
  4136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4137. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4138. }
  4139. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4140. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4141. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4142. }
  4143. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4144. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4145. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4146. }
  4147. if adminInfo.Org.Id == 10721 {
  4148. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4149. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4150. }
  4151. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4152. record.UltrafiltrationRate = 0
  4153. }
  4154. //if template.TemplateId == 47 {
  4155. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4156. // record.UltrafiltrationRate = ultrafiltration_rate
  4157. //}
  4158. }
  4159. }
  4160. // record.UltrafiltrationRate = ultrafiltration_rate
  4161. record.UltrafiltrationVolume = 0
  4162. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  4163. if ultrafiltration_rate > 0 {
  4164. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4165. record.UltrafiltrationVolume = value
  4166. }
  4167. }
  4168. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  4169. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4170. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4171. record.UltrafiltrationVolume = ultrafiltration_volume
  4172. }
  4173. }
  4174. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4175. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4176. record.UltrafiltrationVolume = ultrafiltration_volume
  4177. }
  4178. //长沙南雅
  4179. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  4180. if ultrafiltration_rate > 0 {
  4181. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4182. record.UltrafiltrationVolume = ultrafiltration_volume
  4183. }
  4184. }
  4185. if adminInfo.Org.Id == 10471 {
  4186. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4187. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4188. }
  4189. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4190. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4191. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4192. }
  4193. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4194. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4195. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4196. }
  4197. //长沙南雅累计血容量自动计算
  4198. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4199. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4200. //}
  4201. if template.TemplateId == 47 || template.TemplateId == 54 {
  4202. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4203. }
  4204. if adminInfo.Org.Id == 10510 {
  4205. record.UltrafiltrationVolume = 0
  4206. }
  4207. if adminInfo.Org.Id == 10721 {
  4208. if ultrafiltration_rate > 0 {
  4209. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4210. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4211. }
  4212. }
  4213. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4214. this.ServeSuccessJSON(map[string]interface{}{
  4215. "monitor": record,
  4216. "lastMonitorRecordList": lastMonitorRecordList,
  4217. })
  4218. }
  4219. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4220. record_id, _ := this.GetInt64("id")
  4221. nurseID, _ := this.GetInt64("start_nurse")
  4222. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4223. bedID, _ := this.GetInt64("bed")
  4224. start_time := this.GetString("start_time")
  4225. schedual_type, _ := this.GetInt64("schedual_type")
  4226. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4227. change_nurse, _ := this.GetInt64("change_nurse")
  4228. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4229. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4230. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4231. patient_id, _ := this.GetInt64("patient_id")
  4232. record_date, _ := this.GetInt64("record_date")
  4233. puncture_needle := this.GetString("puncture_needle")
  4234. puncture_way := this.GetString("puncture_way")
  4235. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4236. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4237. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4238. nuclein_date_str := this.GetString("nuclein_date_str")
  4239. order_remark := this.GetString("order_remark")
  4240. schedule_remark := this.GetString("schedule_remark")
  4241. catheter_operation := this.GetString("catheter_operation")
  4242. blood_flow_volume := this.GetString("blood_flow_volume")
  4243. blood_drawing, _ := this.GetInt64("blood_drawing")
  4244. dialysis_strainer := this.GetString("dialysis_strainer")
  4245. if record_id == 0 {
  4246. this.ErrorLog("id:%v", record_id)
  4247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4248. return
  4249. }
  4250. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4251. if parseStartDateErr != nil {
  4252. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4254. return
  4255. }
  4256. adminUserInfo := this.GetMobileAdminUserInfo()
  4257. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4258. if getNurseErr != nil {
  4259. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4260. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4261. return
  4262. } else if nurse == nil {
  4263. this.ErrorLog("护士不存在")
  4264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4265. return
  4266. }
  4267. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4268. //if getNurseErr != nil {
  4269. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4270. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4271. // return
  4272. //} else if nurse == nil {
  4273. // this.ErrorLog("护士不存在")
  4274. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4275. // return
  4276. //}
  4277. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4278. if getDeviceNumberErr != nil {
  4279. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4281. return
  4282. } else if deviceNumber == nil {
  4283. this.ErrorLog("床位号不存在")
  4284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4285. return
  4286. }
  4287. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4288. //
  4289. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4290. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4291. // if getPermissionErr != nil {
  4292. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4293. // return
  4294. // } else if headNursePermission == nil {
  4295. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4296. // return
  4297. // }
  4298. //}
  4299. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4300. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4301. timeLayout := "2006-01-02 15:04:05"
  4302. loc, _ := time.LoadLocation("Local")
  4303. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4304. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4305. schedulestartTime := theStartTime.Unix()
  4306. scheduleendTime := theEndTime.Unix()
  4307. var theNucleinDate int64
  4308. timeLayoutOne := "2006-01-02"
  4309. if len(nuclein_date_str) > 0 {
  4310. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4311. if err != nil {
  4312. utils.ErrorLog(err.Error())
  4313. }
  4314. theNucleinDate = theTime.Unix()
  4315. }
  4316. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4317. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4318. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4319. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4320. if err == gorm.ErrRecordNotFound { //空床位
  4321. // 修改了床位逻辑
  4322. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4323. if daySchedule.ID > 0 {
  4324. //daySchedule.BedId = bedID
  4325. //daySchedule.PartitionId = deviceNumber.ZoneID
  4326. //daySchedule.ScheduleType = schedual_type
  4327. //daySchedule.UpdatedTime = time.Now().Unix()
  4328. //err := service.UpdateSchedule(&daySchedule)
  4329. xtSchedule := models.Schedule{
  4330. PartitionId: deviceNumber.ZoneID,
  4331. BedId: bedID,
  4332. ScheduleType: schedual_type,
  4333. UpdatedTime: time.Now().Unix(),
  4334. }
  4335. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4336. if err != nil {
  4337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4338. return
  4339. }
  4340. }
  4341. } else if err == nil {
  4342. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4343. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4344. if daySchedule.ID > 0 {
  4345. //daySchedule.BedId = bedID
  4346. //daySchedule.PartitionId = deviceNumber.ZoneID
  4347. //
  4348. //daySchedule.ScheduleType = schedual_type
  4349. //daySchedule.UpdatedTime = time.Now().Unix()
  4350. //err := service.UpdateSchedule(&daySchedule)
  4351. xtSchedule := models.Schedule{
  4352. PartitionId: deviceNumber.ZoneID,
  4353. BedId: bedID,
  4354. ScheduleType: schedual_type,
  4355. UpdatedTime: time.Now().Unix(),
  4356. }
  4357. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4358. if err != nil {
  4359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4360. return
  4361. }
  4362. }
  4363. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4365. return
  4366. }
  4367. } else if err != nil {
  4368. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4369. return
  4370. }
  4371. }
  4372. dialysisRecord := &models.DialysisOrder{
  4373. ID: record_id,
  4374. UserOrgId: adminUserInfo.Org.Id,
  4375. BedID: bedID,
  4376. StartNurse: nurseID,
  4377. StartTime: startDate.Unix(),
  4378. PunctureNurse: puncture_nurse,
  4379. Creator: adminUserInfo.AdminUser.Id,
  4380. Modifier: adminUserInfo.AdminUser.Id,
  4381. WashpipeNurse: washpipe_nurse,
  4382. SchedualType: schedual_type,
  4383. ChangeNurse: change_nurse,
  4384. DifficultPunctureNurse: difficult_puncture_nurse,
  4385. NewFistulaNurse: new_fistula_nurse,
  4386. QualityNurseId: quality_nurse_id,
  4387. PunctureNeedle: puncture_needle,
  4388. PunctureWay: puncture_way,
  4389. DialysisDialyszers: dialysis_dialyszers,
  4390. DialysisIrrigation: dialysis_irrigation,
  4391. BloodAccessId: blood_access_id,
  4392. NucleinDate: theNucleinDate,
  4393. OrderRemark: order_remark,
  4394. ScheduleRemark: schedule_remark,
  4395. CatheterOperation: catheter_operation,
  4396. BloodFlowVolume: blood_flow_volume,
  4397. BloodDrawing: blood_drawing,
  4398. DialysisStrainer: dialysis_strainer,
  4399. }
  4400. //修改床位号需要重新消毒
  4401. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4402. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4403. //查询第一条监测
  4404. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4405. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4406. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4407. redis := service.RedisClient()
  4408. //清空key 值
  4409. redis.Set(key, "", time.Second)
  4410. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4411. redis.Set(keyOne, "", time.Second)
  4412. defer redis.Close()
  4413. }
  4414. // 查询信息规挡的设置天数
  4415. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4416. if infor.ID > 0 && infor.WeekDay > 0 {
  4417. var cha_time int64
  4418. timeNowStr := time.Now().Format("2006-01-02")
  4419. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4420. //今日的日期减去设置的日期
  4421. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4422. if cha_time >= record_date {
  4423. //查询审核是否允许
  4424. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4425. //申请状态不允许的情况 拒绝修改
  4426. if infor.ApplicationStatus != 1 {
  4427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4428. return
  4429. }
  4430. }
  4431. }
  4432. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4433. //修改床位后重新生成消毒计划
  4434. if adminUserInfo.Org.Id == 10340 {
  4435. //根据床位号获取设备型号
  4436. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4437. //查询使用消毒最后一条消毒记录
  4438. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4439. fmt.Println("err", err)
  4440. if err == gorm.ErrRecordNotFound {
  4441. //查找排班
  4442. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4443. //查询改设备是否有消毒计划
  4444. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4445. //根据床位号获取设备id
  4446. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4447. //查询病人信息
  4448. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4449. var con = ""
  4450. if patients.IsInfectious == 0 {
  4451. con = ""
  4452. }
  4453. if patients.IsInfectious == 1 {
  4454. con = "无"
  4455. }
  4456. if patients.IsInfectious == 2 {
  4457. con = "有"
  4458. }
  4459. if errcode == nil {
  4460. var end_time int64
  4461. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4462. //新增消毒
  4463. information := models.DeviceInformation{
  4464. Date: dialysisRecord.DialysisDate,
  4465. Zone: dialysisRecord.ZoneId,
  4466. Class: dialysisRecord.SchedualType,
  4467. BedNumber: dialysisRecord.BedID,
  4468. PatientId: dialysisRecord.PatientId,
  4469. DialysisMode: scheduleByPatient.ModeId,
  4470. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4471. Disinfection: 1,
  4472. DialysisConcentration: 1,
  4473. DisinfectionStatus: 1,
  4474. Move: 1,
  4475. UserOrgId: dialysisRecord.UserOrgId,
  4476. DisinfectType: plan.Way,
  4477. DisinfectantType: plan.MachineDisinfectant,
  4478. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4479. Disinfectant: plan.Disinfectant,
  4480. Ctime: time.Now().Unix(),
  4481. Status: 1,
  4482. SignName: nurseID,
  4483. EquimentId: addmacher.ID,
  4484. DisinfectionResidue: 2,
  4485. Bed: addmacher.BedNumber,
  4486. StartTime: dialysisRecord.StartTime,
  4487. EndTime: dialysisRecord.EndTime,
  4488. Contagion: con,
  4489. WeightLoss: 0,
  4490. Hyperfiltratio: 0,
  4491. DialysisHour: "",
  4492. MachineRun: 1,
  4493. DisinfecStartime: dialysisRecord.EndTime,
  4494. DisinfecEndtime: end_time,
  4495. }
  4496. err := service.CreateInformationTwo(&information)
  4497. fmt.Println("报错", err)
  4498. }
  4499. }
  4500. }
  4501. order, _ := service.GetLastPatientOrder(record_id)
  4502. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4503. redis := service.RedisClient()
  4504. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4505. redis.Set(key, "", time.Second)
  4506. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4507. //清空key 值
  4508. redis.Set(keyOne, "", time.Second)
  4509. scheduleDateStartOne := startDate.Format("2006-01-02")
  4510. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4511. redis.Set(keyTwo, "", time.Second)
  4512. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4513. redis.Set(keyThree, "", time.Second)
  4514. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4515. redis.Set(keyFour, "", time.Second)
  4516. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4517. redis.Set(keyFive, "", time.Second)
  4518. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4519. redis.Set(keySix, "", time.Second)
  4520. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4521. redis.Set(keySeven, "", time.Second)
  4522. if updateErr != nil {
  4523. this.ErrorLog("修改上机失败:%v", updateErr)
  4524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4525. return
  4526. }
  4527. if updateErr == nil {
  4528. if tempDialysisRecord.Stage == 2 {
  4529. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4530. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4531. fmt.Println(value)
  4532. a, b := math.Modf(value)
  4533. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4534. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4535. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4536. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4537. redis := service.RedisClient()
  4538. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4539. redis.Set(key, "", time.Second)
  4540. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4541. redis.Set(keyOne, "", time.Second)
  4542. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4543. //清空key 值
  4544. redis.Set(keySix, "", time.Second)
  4545. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4546. redis.Set(keySeven, "", time.Second)
  4547. redis.Close()
  4548. if updateAssessmentErr != nil {
  4549. utils.ErrorLog("%v", updateAssessmentErr)
  4550. }
  4551. }
  4552. }
  4553. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4554. this.ServeSuccessJSON(map[string]interface{}{
  4555. "dialysis_order": dialysisRecords,
  4556. })
  4557. }
  4558. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4559. record_id, _ := c.GetInt64("id")
  4560. nurseID, _ := c.GetInt64("nurse")
  4561. end_time := c.GetString("end_time")
  4562. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4563. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4564. catheter := c.GetString("catheter")
  4565. cruor := c.GetString("cruor")
  4566. mission := c.GetString("mission")
  4567. condenser := c.GetString("condenser")
  4568. if record_id <= 0 || nurseID <= 0 {
  4569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4570. return
  4571. }
  4572. adminUserInfo := c.GetMobileAdminUserInfo()
  4573. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4574. if getNurseErr != nil {
  4575. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4577. return
  4578. } else if nurse == nil {
  4579. c.ErrorLog("护士不存在")
  4580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4581. return
  4582. }
  4583. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4584. if parseEndDateErr != nil {
  4585. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4587. return
  4588. }
  4589. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4590. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4591. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4592. // if getPermissionErr != nil {
  4593. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4594. // return
  4595. // } else if headNursePermission == nil {
  4596. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4597. // return
  4598. // }
  4599. //}
  4600. // 查询信息规挡的设置天数
  4601. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4602. if infor.ID > 0 {
  4603. var cha_time int64
  4604. timeNowStr := time.Now().Format("2006-01-02")
  4605. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4606. //今日的日期减去设置的日期
  4607. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4608. if cha_time >= tempDialysisRecords.DialysisDate {
  4609. //查询审核是否允许
  4610. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4611. //申请状态不允许的情况 拒绝修改
  4612. if infor.ApplicationStatus != 1 {
  4613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4614. return
  4615. }
  4616. }
  4617. }
  4618. dialysisRecord := &models.DialysisOrder{
  4619. ID: record_id,
  4620. UserOrgId: adminUserInfo.Org.Id,
  4621. EndTime: endDate.Unix(),
  4622. FinishNurse: nurseID,
  4623. FinishModifier: adminUserInfo.AdminUser.Id,
  4624. PuncturePointHaematoma: puncture_point_haematoma,
  4625. BloodAccessInternalFistula: blood_access_internal_fistula,
  4626. Catheter: catheter,
  4627. Cruor: cruor,
  4628. Mission: mission,
  4629. Condenser: condenser,
  4630. }
  4631. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4632. redis := service.RedisClient()
  4633. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4634. //清空key 值
  4635. redis.Set(key, "", time.Second)
  4636. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4637. //清空key 值
  4638. redis.Set(keyOne, "", time.Second)
  4639. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4640. redis.Set(keySeven, "", time.Second)
  4641. redis.Close()
  4642. if updateErr != nil {
  4643. c.ErrorLog("修改下机失败:%v", updateErr)
  4644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4645. return
  4646. }
  4647. if updateErr == nil {
  4648. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4649. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4650. a, b := math.Modf(value)
  4651. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4652. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4653. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4654. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4655. redis := service.RedisClient()
  4656. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4657. redis.Set(keyTen, "", time.Second)
  4658. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4659. redis.Set(keyTwo, "", time.Second)
  4660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4661. redis.Set(key, "", time.Second)
  4662. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4663. redis.Set(keyThree, "", time.Second)
  4664. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4665. redis.Set(keySeven, "", time.Second)
  4666. defer redis.Close()
  4667. if updateAssessmentErr != nil {
  4668. utils.ErrorLog("%v", updateAssessmentErr)
  4669. }
  4670. }
  4671. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4672. c.ServeSuccessJSON(map[string]interface{}{
  4673. "dialysis_order": dialysisRecords,
  4674. })
  4675. }
  4676. func (c *DialysisAPIController) GetLongAdvice() {
  4677. patient_id, _ := c.GetInt64("id")
  4678. adminUserInfo := c.GetMobileAdminUserInfo()
  4679. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4680. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4681. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4682. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4683. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4684. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4685. c.ServeSuccessJSON(map[string]interface{}{
  4686. "status": "1",
  4687. })
  4688. return
  4689. } else { //开启推送提醒
  4690. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4691. var advice_three []*models.DoctorAdvice
  4692. recordDateStr := time.Now().Format("2006-01-02")
  4693. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4694. nowtime := recordDate.Unix()
  4695. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4696. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4697. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4698. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4699. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4700. for _, advice := range advices {
  4701. if advice.FrequencyType == 3 {
  4702. t := time.Now()
  4703. week := int(t.Weekday())
  4704. fmt.Println(t.Weekday())
  4705. fmt.Println(week)
  4706. switch week {
  4707. case 1:
  4708. if strings.Index(advice.WeekDay, "周一") == -1 {
  4709. advice_three = append(advice_three, advice)
  4710. }
  4711. break
  4712. case 2:
  4713. if strings.Index(advice.WeekDay, "周二") == -1 {
  4714. advice_three = append(advice_three, advice)
  4715. }
  4716. break
  4717. case 3:
  4718. if strings.Index(advice.WeekDay, "周三") == -1 {
  4719. advice_three = append(advice_three, advice)
  4720. }
  4721. break
  4722. case 4:
  4723. if strings.Index(advice.WeekDay, "周四") == -1 {
  4724. advice_three = append(advice_three, advice)
  4725. }
  4726. break
  4727. case 5:
  4728. if strings.Index(advice.WeekDay, "周五") == -1 {
  4729. advice_three = append(advice_three, advice)
  4730. }
  4731. break
  4732. case 6:
  4733. if strings.Index(advice.WeekDay, "周六") == -1 {
  4734. advice_three = append(advice_three, advice)
  4735. }
  4736. break
  4737. case 0:
  4738. if strings.Index(advice.WeekDay, "周日") == -1 {
  4739. advice_three = append(advice_three, advice)
  4740. }
  4741. break
  4742. }
  4743. }
  4744. }
  4745. for _, advice := range advices_two {
  4746. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4747. now := p.Unix()
  4748. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4749. dayStr2 := "-" + dayStr
  4750. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4751. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4752. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4753. for _, ad := range advices {
  4754. advice_three = append(advice_three, ad)
  4755. }
  4756. }
  4757. if err == nil {
  4758. c.ServeSuccessJSON(map[string]interface{}{
  4759. "status": "2",
  4760. "advices": advices,
  4761. "advices_two": RemoveRepeatedElement(advice_three),
  4762. "is_open_remind": config.IsOpenRemind,
  4763. "his_config_open": hisConfig.IsOpen,
  4764. "is_advice_open": is_advice_open.IsAdviceOpen,
  4765. "prescription_open": prescription_open.IsOpen,
  4766. })
  4767. }
  4768. }
  4769. }
  4770. func (c *DialysisAPIController) GetLongAdviceOne() {
  4771. patient_id, _ := c.GetInt64("id")
  4772. startTime := c.GetString("schedule_date")
  4773. timeLayout := "2006-01-02"
  4774. loc, _ := time.LoadLocation("Local")
  4775. var theStartTime int64
  4776. if len(startTime) > 0 {
  4777. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4778. if err != nil {
  4779. utils.ErrorLog(err.Error())
  4780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4781. return
  4782. }
  4783. theStartTime = theTime.Unix()
  4784. }
  4785. adminUserInfo := c.GetMobileAdminUserInfo()
  4786. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4787. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4788. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4789. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4790. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4791. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4792. c.ServeSuccessJSON(map[string]interface{}{
  4793. "status": "1",
  4794. })
  4795. return
  4796. } else { //开启推送提醒
  4797. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4798. var advice_three []*models.DoctorAdvice
  4799. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4800. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4801. for _, advice := range advices {
  4802. if advice.FrequencyType == 3 {
  4803. t := time.Now()
  4804. week := int(t.Weekday())
  4805. fmt.Println(t.Weekday())
  4806. fmt.Println(week)
  4807. switch week {
  4808. case 1:
  4809. if strings.Index(advice.WeekDay, "周一") == -1 {
  4810. advice_three = append(advice_three, advice)
  4811. }
  4812. break
  4813. case 2:
  4814. if strings.Index(advice.WeekDay, "周二") == -1 {
  4815. advice_three = append(advice_three, advice)
  4816. }
  4817. break
  4818. case 3:
  4819. if strings.Index(advice.WeekDay, "周三") == -1 {
  4820. advice_three = append(advice_three, advice)
  4821. }
  4822. break
  4823. case 4:
  4824. if strings.Index(advice.WeekDay, "周四") == -1 {
  4825. advice_three = append(advice_three, advice)
  4826. }
  4827. break
  4828. case 5:
  4829. if strings.Index(advice.WeekDay, "周五") == -1 {
  4830. advice_three = append(advice_three, advice)
  4831. }
  4832. break
  4833. case 6:
  4834. if strings.Index(advice.WeekDay, "周六") == -1 {
  4835. advice_three = append(advice_three, advice)
  4836. }
  4837. break
  4838. case 0:
  4839. if strings.Index(advice.WeekDay, "周日") == -1 {
  4840. advice_three = append(advice_three, advice)
  4841. }
  4842. break
  4843. }
  4844. }
  4845. }
  4846. for _, advice := range advices_two {
  4847. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4848. now := p.Unix()
  4849. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4850. dayStr2 := "-" + dayStr
  4851. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4852. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4853. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4854. for _, ad := range advices {
  4855. advice_three = append(advice_three, ad)
  4856. }
  4857. }
  4858. if err == nil {
  4859. c.ServeSuccessJSON(map[string]interface{}{
  4860. "status": "2",
  4861. "advices": advices,
  4862. "advices_two": RemoveRepeatedElement(advice_three),
  4863. "is_open_remind": config.IsOpenRemind,
  4864. "his_config_open": hisConfig.IsOpen,
  4865. "is_advice_open": is_advice_open.IsAdviceOpen,
  4866. "prescription_open": prescription_open.IsOpen,
  4867. })
  4868. }
  4869. }
  4870. }
  4871. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4872. newArr = make([]*models.DoctorAdvice, 0)
  4873. for i := 0; i < len(arr); i++ {
  4874. repeat := false
  4875. for j := i + 1; j < len(arr); j++ {
  4876. if arr[i].ID == arr[j].ID {
  4877. repeat = true
  4878. break
  4879. }
  4880. }
  4881. if !repeat {
  4882. newArr = append(newArr, arr[i])
  4883. }
  4884. }
  4885. return
  4886. }
  4887. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4888. patient, _ := c.GetInt64("id", 0)
  4889. groupNo, _ := c.GetInt64("groupno", 0)
  4890. if patient <= 0 {
  4891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4892. return
  4893. }
  4894. adminUserInfo := c.GetMobileAdminUserInfo()
  4895. dataBody := make(map[string]interface{}, 0)
  4896. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4897. if err != nil {
  4898. utils.ErrorLog(err.Error())
  4899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4900. return
  4901. }
  4902. utils.ErrorLog("%v", dataBody)
  4903. timeLayout := "2006-01-02 15:04"
  4904. loc, _ := time.LoadLocation("Local")
  4905. timeLayout2 := "2006-01-02"
  4906. loc2, _ := time.LoadLocation("Local")
  4907. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4908. utils.ErrorLog("advice_type")
  4909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4910. return
  4911. }
  4912. adviceType := int64(2)
  4913. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4914. utils.ErrorLog("advice_date")
  4915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4916. return
  4917. }
  4918. adviceDate, _ := dataBody["advice_date"].(string)
  4919. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4920. AdviceDate := theTime.Unix()
  4921. RecordDate := theTime.Unix()
  4922. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4923. utils.ErrorLog("start_time")
  4924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4925. return
  4926. }
  4927. startTime, _ := dataBody["start_time"].(string)
  4928. if len(startTime) == 0 {
  4929. utils.ErrorLog("len(start_time) == 0")
  4930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4931. return
  4932. }
  4933. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4934. if err != nil {
  4935. utils.ErrorLog(err.Error())
  4936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4937. return
  4938. }
  4939. StartTime := theTime.Unix()
  4940. Remark := ""
  4941. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4942. remark, _ := dataBody["remark"].(string)
  4943. Remark = remark
  4944. }
  4945. var advices []*models.GroupAdvice
  4946. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4947. utils.ErrorLog("advices")
  4948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4949. return
  4950. }
  4951. adviceNames := dataBody["advices"].([]interface{})
  4952. for _, adviceNameMap := range adviceNames {
  4953. adviceNameM := adviceNameMap.(map[string]interface{})
  4954. var advice models.GroupAdvice
  4955. advice.Remark = Remark
  4956. advice.AdviceType = adviceType
  4957. advice.StartTime = StartTime
  4958. advice.AdviceDate = AdviceDate
  4959. advice.RecordDate = RecordDate
  4960. advice.Status = 1
  4961. advice.CreatedTime = time.Now().Unix()
  4962. advice.UpdatedTime = time.Now().Unix()
  4963. advice.StopState = 2
  4964. advice.ExecutionState = 2
  4965. advice.UserOrgId = adminUserInfo.Org.Id
  4966. advice.PatientId = patient
  4967. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4968. advice.IsSettle = 2
  4969. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4970. utils.ErrorLog("advice_name")
  4971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4972. return
  4973. }
  4974. adviceName, _ := adviceNameM["advice_name"].(string)
  4975. if len(adviceName) == 0 {
  4976. utils.ErrorLog("len(advice_name) == 0")
  4977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4978. return
  4979. }
  4980. advice.AdviceName = adviceName
  4981. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4982. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4983. advice.DrugSpec = drugSpec
  4984. }
  4985. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4986. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4987. advice.AdviceDesc = adviceDesc
  4988. }
  4989. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4990. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4991. advice.DrugSpecUnit = drugSpecUnit
  4992. }
  4993. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4994. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4995. // advice.SingleDose = singleDose
  4996. //}
  4997. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4998. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4999. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5000. }
  5001. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5002. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5003. advice.SingleDoseUnit = singleDoseUnit
  5004. }
  5005. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5006. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5007. // advice.PrescribingNumber = prescribingNumber
  5008. //}
  5009. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5010. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5011. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5012. }
  5013. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5014. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5015. advice.PrescribingNumberUnit = prescribingNumberUnit
  5016. }
  5017. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5018. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5019. advice.DeliveryWay = deliveryWay
  5020. }
  5021. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5022. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5023. advice.ExecutionFrequency = executionFrequency
  5024. }
  5025. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5026. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5027. advice.FrequencyType = frequency_type
  5028. }
  5029. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5030. day_count := int64(adviceNameM["day_count"].(float64))
  5031. advice.DayCount = day_count
  5032. }
  5033. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5034. week_day, _ := adviceNameM["week_day"].(string)
  5035. advice.WeekDay = week_day
  5036. }
  5037. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5038. way := int64(adviceNameM["way"].(float64))
  5039. advice.Way = way
  5040. }
  5041. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5042. drug_id := int64(adviceNameM["drug_id"].(float64))
  5043. advice.DrugId = drug_id
  5044. }
  5045. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5046. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5047. advice.DrugNameId = drug_name_id
  5048. }
  5049. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5050. remark, _ := adviceNameM["remark"].(string)
  5051. advice.Remark = remark
  5052. }
  5053. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5054. groupno := int64(adviceNameM["groupno"].(float64))
  5055. advice.GroupNo = groupno
  5056. }
  5057. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5058. template_id, _ := adviceNameM["template_id"].(string)
  5059. advice.TemplateId = template_id
  5060. }
  5061. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5062. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5063. advice.ExecutionFrequency = executionFrequency
  5064. }
  5065. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5066. children := adviceNameM["child"].([]interface{})
  5067. if len(children) > 0 {
  5068. for _, childrenMap := range children {
  5069. childMap := childrenMap.(map[string]interface{})
  5070. var child models.GroupAdvice
  5071. child.Remark = Remark
  5072. child.AdviceType = adviceType
  5073. child.StartTime = StartTime
  5074. child.AdviceDate = AdviceDate
  5075. child.RecordDate = RecordDate
  5076. child.Status = 1
  5077. child.CreatedTime = time.Now().Unix()
  5078. child.UpdatedTime = time.Now().Unix()
  5079. child.StopState = 2
  5080. child.ExecutionState = 2
  5081. child.UserOrgId = adminUserInfo.Org.Id
  5082. child.PatientId = patient
  5083. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5084. child.IsSettle = 1
  5085. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5086. utils.ErrorLog("child advice_name")
  5087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5088. return
  5089. }
  5090. childAdviceName, _ := childMap["advice_name"].(string)
  5091. if len(childAdviceName) == 0 {
  5092. utils.ErrorLog("len(child advice_name) == 0")
  5093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5094. return
  5095. }
  5096. child.AdviceName = childAdviceName
  5097. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5098. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5099. child.AdviceDesc = childAdviceDesc
  5100. }
  5101. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5102. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5103. child.DrugSpec = childDrugSpec
  5104. }
  5105. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5106. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5107. child.DrugSpecUnit = childDrugSpecUnit
  5108. }
  5109. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5110. child.SingleDose = childMap["single_dose"].(float64)
  5111. }
  5112. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5113. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5114. child.SingleDoseUnit = childSingleDoseUnit
  5115. }
  5116. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5117. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5118. }
  5119. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5120. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5121. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5122. }
  5123. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5124. groupno := int64(childMap["groupno"].(float64))
  5125. advice.GroupNo = groupno
  5126. }
  5127. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5128. remark, _ := childMap["remark"].(string)
  5129. child.Remark = remark
  5130. }
  5131. child.DeliveryWay = advice.DeliveryWay
  5132. child.ExecutionFrequency = advice.ExecutionFrequency
  5133. advice.Children = append(advice.Children, &child)
  5134. }
  5135. }
  5136. }
  5137. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5138. if temp_advice.ID == 0 {
  5139. advices = append(advices, &advice)
  5140. }
  5141. }
  5142. if len(advices) > 0 {
  5143. finish := models.XtDialysisFinish{
  5144. IsFinish: 1,
  5145. UserOrgId: adminUserInfo.Org.Id,
  5146. Status: 1,
  5147. Ctime: time.Now().Unix(),
  5148. Mtime: 0,
  5149. Module: 4,
  5150. RecordDate: AdviceDate,
  5151. Sourse: 1,
  5152. PatientId: patient,
  5153. }
  5154. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5155. if dialysisFinish.ID == 0 {
  5156. service.CreateDialysisFinish(finish)
  5157. }
  5158. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5159. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5160. for _, item := range advices {
  5161. byterequest, _ := json.Marshal(item)
  5162. adviceLog := models.XtDoctorAdviceLog{
  5163. UserOrgId: adminUserInfo.Org.Id,
  5164. PatientId: patient,
  5165. AdminUserId: adminUserInfo.AdminUser.Id,
  5166. Module: 1,
  5167. ErrLog: string(byterequest),
  5168. Status: 1,
  5169. Ctime: time.Now().Unix(),
  5170. Mtime: 0,
  5171. Source: "手机端医嘱推送",
  5172. RecordDate: item.AdviceDate,
  5173. }
  5174. service.CreateDoctorAdviceLog(adviceLog)
  5175. }
  5176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5177. redis := service.RedisClient()
  5178. //清空key 值
  5179. redis.Set(key, "", time.Second)
  5180. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5181. redis.Set(keyOne, "", time.Second)
  5182. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5183. defer redis.Close()
  5184. redis.Set(keyThree, "", time.Second)
  5185. if err != nil {
  5186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5187. return
  5188. }
  5189. c.ServeSuccessJSON(map[string]interface{}{
  5190. "msg": "ok",
  5191. "advices": list,
  5192. })
  5193. } else {
  5194. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5195. for _, item := range advices {
  5196. byterequest, _ := json.Marshal(item)
  5197. adviceLog := models.XtDoctorAdviceLog{
  5198. UserOrgId: adminUserInfo.Org.Id,
  5199. PatientId: patient,
  5200. AdminUserId: adminUserInfo.AdminUser.Id,
  5201. Module: 1,
  5202. ErrLog: string(byterequest),
  5203. Status: 1,
  5204. Ctime: time.Now().Unix(),
  5205. Mtime: 0,
  5206. Source: "手机端医嘱推送",
  5207. RecordDate: item.AdviceDate,
  5208. }
  5209. service.CreateDoctorAdviceLog(adviceLog)
  5210. }
  5211. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5212. redis := service.RedisClient()
  5213. //清空key 值
  5214. redis.Set(key, "", time.Second)
  5215. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5216. redis.Set(keyOne, "", time.Second)
  5217. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5218. defer redis.Close()
  5219. redis.Set(keyThree, "", time.Second)
  5220. if err != nil {
  5221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5222. return
  5223. }
  5224. c.ServeSuccessJSON(map[string]interface{}{
  5225. "msg": "ok",
  5226. "advices": list,
  5227. })
  5228. }
  5229. } else {
  5230. c.ServeSuccessJSON(map[string]interface{}{
  5231. "msg": "ok",
  5232. })
  5233. }
  5234. return
  5235. }
  5236. func (c *DialysisAPIController) UploadDryWeight() {
  5237. patient_id, _ := c.GetInt64("id")
  5238. dry_weight, _ := c.GetFloat("dry_weight")
  5239. doctor_id, _ := c.GetInt64("doctor_id")
  5240. remark := c.GetString("remark")
  5241. adminUserInfo := c.GetMobileAdminUserInfo()
  5242. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5243. if err == gorm.ErrRecordNotFound {
  5244. dryWeight := &models.SgjPatientDryweight{
  5245. PatientId: patient_id,
  5246. DryWeight: dry_weight,
  5247. Remakes: remark,
  5248. Ctime: time.Now().Unix(),
  5249. Mtime: time.Now().Unix(),
  5250. Creator: doctor_id,
  5251. Status: 1,
  5252. UserOrgId: adminUserInfo.Org.Id,
  5253. AdjustedValue: "/",
  5254. UserId: adminUserInfo.AdminUser.Id,
  5255. }
  5256. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5257. redis := service.RedisClient()
  5258. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5259. redis.Set(keyOne, "", time.Second)
  5260. loc, _ := time.LoadLocation("Local")
  5261. nowTime := time.Now()
  5262. nowDay := nowTime.Format("2006-01-02")
  5263. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5264. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5265. redis.Set(key, "", time.Second)
  5266. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5267. redis.Set(keyTwo, "", time.Second)
  5268. redis.Close()
  5269. if createErr == nil {
  5270. c.ServeSuccessJSON(map[string]interface{}{
  5271. "msg": "提交成功",
  5272. "weight": dryWeight,
  5273. })
  5274. }
  5275. } else {
  5276. dryWeight := &models.SgjPatientDryweight{
  5277. PatientId: patient_id,
  5278. DryWeight: dry_weight,
  5279. Remakes: remark,
  5280. Ctime: time.Now().Unix(),
  5281. Mtime: time.Now().Unix(),
  5282. Creator: doctor_id,
  5283. Status: 1,
  5284. UserOrgId: adminUserInfo.Org.Id,
  5285. AdjustedValue: "/",
  5286. UserId: adminUserInfo.AdminUser.Id,
  5287. }
  5288. var value float64
  5289. value = dry_weight - weightAdjust.DryWeight
  5290. if value < 0 {
  5291. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5292. } else if value == 0 {
  5293. dryWeight.AdjustedValue = "/"
  5294. } else if value > 0 {
  5295. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5296. }
  5297. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5298. //康桥
  5299. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 {
  5300. timeNowStr := time.Now().Format("2006-01-02")
  5301. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5302. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5303. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5304. if beforAssesment.ID > 0 {
  5305. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5306. var dewater_amount float64
  5307. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5308. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5309. //获取key,清空redis
  5310. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5311. redis := service.RedisClient()
  5312. //清空key 值
  5313. redis.Set(key, "", time.Second)
  5314. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5315. //清空key 值
  5316. redis.Set(keyOne, "", time.Second)
  5317. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5318. //清空key 值
  5319. redis.Set(keyTwo, "", time.Second)
  5320. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5321. redis.Set(keySix, "", time.Second)
  5322. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5323. redis.Set(keySeven, "", time.Second)
  5324. }
  5325. }
  5326. redis := service.RedisClient()
  5327. loc, _ := time.LoadLocation("Local")
  5328. nowTime := time.Now()
  5329. nowDay := nowTime.Format("2006-01-02")
  5330. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5331. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5332. redis.Set(keyOne, "", time.Second)
  5333. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5334. redis.Set(key, "", time.Second)
  5335. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5336. redis.Set(keyTwo, "", time.Second)
  5337. redis.Close()
  5338. if createErr == nil {
  5339. c.ServeSuccessJSON(map[string]interface{}{
  5340. "msg": "提交成功",
  5341. "weight": dryWeight,
  5342. })
  5343. }
  5344. }
  5345. }
  5346. func (c *DialysisAPIController) GetSolution() {
  5347. patient_id, _ := c.GetInt64("patient_id")
  5348. mode_id, _ := c.GetInt64("mode_id")
  5349. adminUserInfo := c.GetMobileAdminUserInfo()
  5350. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5351. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5352. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5353. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5354. if err != nil {
  5355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5356. return
  5357. }
  5358. c.ServeSuccessJSON(map[string]interface{}{
  5359. "solution": solution,
  5360. "prescription": prescription,
  5361. "system_prescription": system_prescription,
  5362. "dialysisPrescription": dialysisPrescription,
  5363. })
  5364. }
  5365. func (c *DialysisAPIController) GetSchedule() {
  5366. schedual_type, _ := c.GetInt64("schedual_type")
  5367. adminUserInfo := c.GetMobileAdminUserInfo()
  5368. scheduleTime, _ := c.GetInt64("record_date")
  5369. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5370. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5371. c.ServeSuccessJSON(map[string]interface{}{
  5372. "number": deviceNumber,
  5373. "list": list,
  5374. })
  5375. }
  5376. func (c *DialysisAPIController) GetPatientId() {
  5377. id, _ := c.GetInt64("id")
  5378. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5379. patientId, _ := service.GetPatientId(id)
  5380. //获取该患者的所有传染病
  5381. list, _ := service.GetPatientInfectious(id)
  5382. c.ServeSuccessJSON(map[string]interface{}{
  5383. "patient": patientId,
  5384. "infectioulist": list,
  5385. })
  5386. }
  5387. func (this *DialysisAPIController) GetDialysisSchedule() {
  5388. schedualDate := this.GetString("date")
  5389. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5390. if parseDateErr != nil {
  5391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5392. return
  5393. }
  5394. adminInfo := this.GetMobileAdminUserInfo()
  5395. orgID := adminInfo.Org.Id
  5396. redis := service.RedisClient()
  5397. defer redis.Close()
  5398. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5399. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5400. if len(scheduals) > 0 {
  5401. //缓存数据
  5402. scheduals_json, err := json.Marshal(scheduals)
  5403. if err == nil {
  5404. redis.Set(key, scheduals_json, time.Second*30)
  5405. }
  5406. }
  5407. this.ServeSuccessJSON(map[string]interface{}{
  5408. "scheduals": scheduals,
  5409. })
  5410. }
  5411. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5412. change_type, _ := this.GetInt64("type", 0)
  5413. record_date := this.GetString("record_time")
  5414. patient_id, _ := this.GetInt64("patient_id", 0)
  5415. timeLayout := "2006-01-02"
  5416. loc, _ := time.LoadLocation("Local")
  5417. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5418. record_time := theAdviceRecordTime.Unix()
  5419. adminUserInfo := this.GetMobileAdminUserInfo()
  5420. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5421. if err == nil {
  5422. if len(advices) == 0 {
  5423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5424. return
  5425. } else {
  5426. this.ServeSuccessJSON(map[string]interface{}{
  5427. "advices": advices,
  5428. "schedule": sch,
  5429. })
  5430. return
  5431. }
  5432. } else {
  5433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5434. return
  5435. }
  5436. }
  5437. func (c *DialysisAPIController) CreateConsumables() {
  5438. record_date := c.GetString("record_time")
  5439. patient_id, _ := c.GetInt64("patient_id", 0)
  5440. active, _ := c.GetInt64("active")
  5441. adminUser := c.GetMobileAdminUserInfo()
  5442. timeLayout := "2006-01-02"
  5443. loc, _ := time.LoadLocation("Local")
  5444. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5445. record_time := theRecordTime.Unix()
  5446. // 查询信息规挡的设置天数
  5447. orgid := c.GetMobileAdminUserInfo().Org.Id
  5448. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5449. if infor.ID > 0 {
  5450. var cha_time int64
  5451. timeNowStr := time.Now().Format("2006-01-02")
  5452. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5453. //今日的日期减去设置的日期
  5454. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5455. if cha_time >= record_time {
  5456. //查询审核是否允许
  5457. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5458. //申请状态不允许的情况 拒绝修改
  5459. if infor.ApplicationStatus != 1 {
  5460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5461. return
  5462. }
  5463. }
  5464. }
  5465. dataBody := make(map[string]interface{}, 0)
  5466. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5467. if err != nil {
  5468. utils.ErrorLog(err.Error())
  5469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5470. return
  5471. }
  5472. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5473. var beforePrepares []*models.DialysisBeforePrepareGoods
  5474. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5475. var dialysisBefor []*models.DialysisBeforePrepare
  5476. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5477. goods, _ := dataBody["goods"].([]interface{})
  5478. if len(goods) > 0 {
  5479. for _, item := range goods {
  5480. items := item.(map[string]interface{})
  5481. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5482. utils.ErrorLog("good_id")
  5483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5484. return
  5485. }
  5486. good_id := int64(items["good_id"].(float64))
  5487. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5488. utils.ErrorLog("good_type_id")
  5489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5490. return
  5491. }
  5492. good_type_id := int64(items["good_type_id"].(float64))
  5493. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5494. utils.ErrorLog("count")
  5495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5496. return
  5497. }
  5498. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5499. commdity_code := items["commdity_code"].(string)
  5500. fmt.Println("commdity", commdity_code)
  5501. prepareGoods := &models.DialysisBeforePrepareGoods{
  5502. GoodTypeId: good_type_id,
  5503. GoodId: good_id,
  5504. Count: count,
  5505. StorehouseId: houseConfig.StorehouseOutInfo,
  5506. }
  5507. beforePrepares = append(beforePrepares, prepareGoods)
  5508. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5509. GoodTypeId: good_type_id,
  5510. GoodId: good_id,
  5511. Count: count,
  5512. StorehouseId: houseConfig.StorehouseOutInfo,
  5513. }
  5514. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5515. prepare := &models.DialysisBeforePrepare{
  5516. GoodTypeId: good_type_id,
  5517. GoodId: good_id,
  5518. Count: count,
  5519. PatientId: patient_id,
  5520. RecordDate: record_time,
  5521. UserOrgId: adminUser.Org.Id,
  5522. Status: 1,
  5523. Ctime: time.Now().Unix(),
  5524. Creater: adminUser.AdminUser.Id,
  5525. CommdityCode: commdity_code,
  5526. StorehouseId: houseConfig.StorehouseOutInfo,
  5527. }
  5528. dialysisBefor = append(dialysisBefor, prepare)
  5529. }
  5530. }
  5531. //查询是否有库存
  5532. for _, item := range dialysisBefor {
  5533. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5534. if err == gorm.ErrRecordNotFound {
  5535. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5536. c.ServeSuccessJSON(map[string]interface{}{
  5537. "message": "1",
  5538. "good_name": goodObj.GoodName,
  5539. "specification_name": goodObj.SpecificationName,
  5540. })
  5541. return
  5542. }
  5543. if err != nil {
  5544. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5545. c.ServeSuccessJSON(map[string]interface{}{
  5546. "message": "1",
  5547. "good_name": goodObj.GoodName,
  5548. "specification_name": goodObj.SpecificationName,
  5549. })
  5550. return
  5551. }
  5552. }
  5553. fmt.Println("active-----------------------", active)
  5554. fmt.Println("len(goods)-----------------------", len(goods))
  5555. //新增
  5556. if active == 1 && len(goods) > 0 {
  5557. for _, item := range dialysisBefor {
  5558. dialyPrepareOne := models.DialysisBeforePrepare{
  5559. GoodTypeId: item.GoodTypeId,
  5560. GoodId: item.GoodId,
  5561. PatientId: item.PatientId,
  5562. RecordDate: item.RecordDate,
  5563. UserOrgId: item.UserOrgId,
  5564. Count: item.Count,
  5565. Ctime: time.Now().Unix(),
  5566. Creater: item.Creater,
  5567. CommdityCode: item.CommdityCode,
  5568. Status: 1,
  5569. StorehouseId: houseConfig.StorehouseOutInfo,
  5570. }
  5571. //先清除再插入
  5572. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5573. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5574. //查询默认仓库
  5575. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5576. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5577. var total_count int64
  5578. for _, it := range stockList {
  5579. total_count += it.StockCount
  5580. }
  5581. //基础库插入数据
  5582. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5583. //更新库存
  5584. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5585. var flush_count int64
  5586. for _, it := range goodList {
  5587. flush_count += it.StockCount
  5588. }
  5589. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5590. }
  5591. if err == nil {
  5592. c.ServeSuccessJSON(map[string]interface{}{
  5593. "msg": "保存成功",
  5594. "message": "2",
  5595. })
  5596. return
  5597. } else {
  5598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5599. return
  5600. }
  5601. }
  5602. if len(beforePrepares) > 0 && active == 2 {
  5603. for _, item := range beforePrepares {
  5604. //1.查看该患者该耗材型号最后一次出库数量
  5605. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5606. //判断当前出库数量和最后一次出库数量的大小
  5607. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5608. if item.Count <= goodInfo.Count {
  5609. //退库
  5610. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5611. //查询今日出库数据
  5612. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5613. for _, it := range list {
  5614. prepare := models.DialysisBeforePrepare{
  5615. UserOrgId: it.OrgId,
  5616. PatientId: patient_id,
  5617. RecordDate: it.RecordTime,
  5618. GoodId: it.GoodId,
  5619. GoodTypeId: it.GoodTypeId,
  5620. Count: it.Count,
  5621. Ctime: time.Now().Unix(),
  5622. Creater: adminUser.AdminUser.Id,
  5623. Status: 1,
  5624. StorehouseId: houseConfig.StorehouseOutInfo,
  5625. }
  5626. //删除准备表数据
  5627. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5628. service.CreateDialysisBeforePrepareOne(&prepare)
  5629. }
  5630. }
  5631. var last_total int64
  5632. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5633. if item.Count >= goodInfo.Count {
  5634. //查询当前批次当前耗材最后一条出库数据
  5635. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5636. //计算当前出库和最后一次出库数据相差数据
  5637. last_total = item.Count - lastOutInfo.Count
  5638. //查询该批次剩余库存
  5639. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5640. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5641. if lastInfo.StockCount >= last_total {
  5642. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5643. //查询今日出库数据
  5644. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5645. for _, it := range list {
  5646. prepare := models.DialysisBeforePrepare{
  5647. UserOrgId: it.OrgId,
  5648. PatientId: patient_id,
  5649. RecordDate: it.RecordTime,
  5650. GoodId: it.GoodId,
  5651. GoodTypeId: it.GoodTypeId,
  5652. Count: it.Count,
  5653. Ctime: time.Now().Unix(),
  5654. Creater: adminUser.AdminUser.Id,
  5655. Status: 1,
  5656. StorehouseId: houseConfig.StorehouseOutInfo,
  5657. }
  5658. //删除准备表数据
  5659. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5660. service.CreateDialysisBeforePrepareOne(&prepare)
  5661. //查询默认仓库
  5662. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5663. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5664. var total_count int64
  5665. for _, it := range stockList {
  5666. total_count += it.StockCount
  5667. }
  5668. //基础库插入数据
  5669. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5670. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5671. var flush_count int64
  5672. for _, it := range goodList {
  5673. flush_count += it.StockCount
  5674. }
  5675. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5676. }
  5677. }
  5678. //如果库存不够,则出库到下一个批次
  5679. if lastInfo.StockCount < last_total {
  5680. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5681. //查询今日出库数据
  5682. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5683. for _, it := range list {
  5684. prepare := models.DialysisBeforePrepare{
  5685. UserOrgId: it.OrgId,
  5686. PatientId: patient_id,
  5687. RecordDate: it.RecordTime,
  5688. GoodId: it.GoodId,
  5689. GoodTypeId: it.GoodTypeId,
  5690. Count: it.Count,
  5691. Ctime: time.Now().Unix(),
  5692. Creater: adminUser.AdminUser.Id,
  5693. Status: 1,
  5694. StorehouseId: houseConfig.StorehouseOutInfo,
  5695. }
  5696. //删除准备表数据
  5697. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5698. service.CreateDialysisBeforePrepareOne(&prepare)
  5699. //查询默认仓库
  5700. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5701. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5702. var total_count int64
  5703. for _, it := range stockList {
  5704. total_count += it.StockCount
  5705. }
  5706. //基础库插入数据
  5707. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5708. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5709. var flush_count int64
  5710. for _, it := range goodList {
  5711. flush_count += it.StockCount
  5712. }
  5713. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5714. }
  5715. if err != nil {
  5716. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5717. c.ServeSuccessJSON(map[string]interface{}{
  5718. "message": "1",
  5719. "good_name": goodObj.GoodName,
  5720. "specification_name": goodObj.SpecificationName,
  5721. })
  5722. return
  5723. }
  5724. }
  5725. }
  5726. if err != nil {
  5727. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5728. c.ServeSuccessJSON(map[string]interface{}{
  5729. "message": "1",
  5730. "good_name": goodObj.GoodName,
  5731. "specification_name": goodObj.SpecificationName,
  5732. })
  5733. return
  5734. }
  5735. }
  5736. }
  5737. }
  5738. var errs error
  5739. if errs == nil {
  5740. c.ServeSuccessJSON(map[string]interface{}{
  5741. "msg": "提交成功",
  5742. "message": "2",
  5743. "good_name": "",
  5744. "specification_name": "",
  5745. })
  5746. return
  5747. } else {
  5748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5749. return
  5750. }
  5751. }
  5752. func (c *DialysisAPIController) CreateStockOutInfo() {
  5753. patient_id, _ := c.GetInt64("patient_id", 0)
  5754. record_date := c.GetString("record_time")
  5755. if patient_id <= 0 {
  5756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5757. return
  5758. }
  5759. adminInfo := c.GetMobileAdminUserInfo()
  5760. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5761. timeLayout := "2006-01-02"
  5762. loc, _ := time.LoadLocation("Local")
  5763. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5764. record_time := theRecordTime.Unix()
  5765. // 查询信息规挡的设置天数
  5766. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5767. if infor.ID > 0 && infor.WeekDay > 0 {
  5768. var cha_time int64
  5769. timeNowStr := time.Now().Format("2006-01-02")
  5770. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5771. //今日的日期减去设置的日期
  5772. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5773. if cha_time >= record_time {
  5774. //查询审核是否允许
  5775. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5776. //申请状态不允许的情况 拒绝修改
  5777. if infor.ApplicationStatus != 1 {
  5778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5779. return
  5780. }
  5781. }
  5782. }
  5783. //创建步骤表
  5784. finish := models.XtDialysisFinish{
  5785. IsFinish: 1,
  5786. UserOrgId: adminInfo.Org.Id,
  5787. Status: 1,
  5788. Ctime: time.Now().Unix(),
  5789. Mtime: 0,
  5790. Module: 11,
  5791. RecordDate: record_time,
  5792. Sourse: 1,
  5793. PatientId: patient_id,
  5794. }
  5795. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5796. if dialysisFinish.ID == 0 {
  5797. service.CreateDialysisFinish(finish)
  5798. }
  5799. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5800. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5801. //去重
  5802. consumables = RemoveRepeatedGood(consumables)
  5803. if adminInfo.Org.Id == 9919 {
  5804. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5805. //查询是否有库存
  5806. for _, item := range consumables {
  5807. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5808. if item.Count > warehouse.Count {
  5809. goodErrcode := models.XtGoodErrcode{
  5810. UserOrgId: item.UserOrgId,
  5811. Errcode: "自动出库库存不足",
  5812. GoodId: item.GoodId,
  5813. Status: 1,
  5814. Ctime: time.Now().Unix(),
  5815. Mtime: 0,
  5816. Count: 0,
  5817. StockCount: 0,
  5818. Creater: creator,
  5819. BatchNumberId: warehouse.ID,
  5820. WarehouseOutId: 0,
  5821. }
  5822. service.CreateGoodErrcode(goodErrcode)
  5823. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5824. c.ServeSuccessJSON(map[string]interface{}{
  5825. "message": "1",
  5826. "good_name": goodObj.GoodName,
  5827. "specification_name": goodObj.SpecificationName,
  5828. })
  5829. return
  5830. }
  5831. }
  5832. //查询是否有出库单
  5833. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5834. if err == gorm.ErrRecordNotFound {
  5835. //没有记录,则创建出库单
  5836. timeStr := time.Now().Format("2006-01-02")
  5837. timeArr := strings.Split(timeStr, "-")
  5838. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5839. total = total + 1
  5840. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5841. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5842. number = number + total
  5843. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5844. creater := adminInfo.AdminUser.Id
  5845. warehouseOut := models.WarehouseOut{
  5846. WarehouseOutOrderNumber: warehousing_out_order,
  5847. OperationTime: time.Now().Unix(),
  5848. OrgId: adminInfo.Org.Id,
  5849. Creater: creater,
  5850. Ctime: time.Now().Unix(),
  5851. Status: 1,
  5852. WarehouseOutTime: record_time,
  5853. Dealer: 0,
  5854. Manufacturer: 0,
  5855. Type: 1,
  5856. IsSys: 1,
  5857. StorehouseId: houseConfig.StorehouseOutInfo,
  5858. IsCheck: 1,
  5859. }
  5860. err := service.AddSigleWarehouseOut(&warehouseOut)
  5861. if err != nil {
  5862. goodErrcode := models.XtGoodErrcode{
  5863. UserOrgId: adminInfo.Org.Id,
  5864. Errcode: "创建出库单失败",
  5865. GoodId: 0,
  5866. Status: 1,
  5867. Ctime: time.Now().Unix(),
  5868. Mtime: 0,
  5869. Count: 0,
  5870. StockCount: 0,
  5871. Creater: creator,
  5872. BatchNumberId: 0,
  5873. WarehouseOutId: 0,
  5874. }
  5875. service.CreateGoodErrcode(goodErrcode)
  5876. utils.TraceLog("创建出库单失败 err = %v", err)
  5877. } else {
  5878. for _, item := range consumables {
  5879. //出库
  5880. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5881. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5882. if err == nil {
  5883. goodErrcode := models.XtGoodErrcode{
  5884. UserOrgId: adminInfo.Org.Id,
  5885. Errcode: "自动出库接口报错",
  5886. GoodId: 0,
  5887. Status: 1,
  5888. Ctime: time.Now().Unix(),
  5889. Mtime: 0,
  5890. Count: 0,
  5891. StockCount: 0,
  5892. Creater: creator,
  5893. BatchNumberId: 0,
  5894. WarehouseOutId: 0,
  5895. }
  5896. service.CreateGoodErrcode(goodErrcode)
  5897. utils.TraceLog("创建出库单失败 err = %v", err)
  5898. }
  5899. //查询
  5900. //出库数量相加
  5901. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5902. if errs != nil {
  5903. goodErrcode := models.XtGoodErrcode{
  5904. UserOrgId: item.UserOrgId,
  5905. Errcode: "创建剩余库存字段报错",
  5906. GoodId: item.GoodId,
  5907. Status: 1,
  5908. Ctime: time.Now().Unix(),
  5909. Mtime: 0,
  5910. Count: 0,
  5911. StockCount: 0,
  5912. Creater: creater,
  5913. BatchNumberId: 0,
  5914. WarehouseOutId: 0,
  5915. }
  5916. service.CreateGoodErrcode(goodErrcode)
  5917. }
  5918. }
  5919. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5920. if len(list) == 0 {
  5921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5922. return
  5923. }
  5924. for _, item := range list {
  5925. prepare := models.DialysisBeforePrepare{
  5926. UserOrgId: adminInfo.Org.Id,
  5927. PatientId: patient_id,
  5928. RecordDate: record_time,
  5929. GoodId: item.GoodId,
  5930. GoodTypeId: item.GoodTypeId,
  5931. Count: item.Count,
  5932. Creater: adminInfo.AdminUser.Id,
  5933. Status: 1,
  5934. Ctime: time.Now().Unix(),
  5935. StorehouseId: houseConfig.StorehouseOutInfo,
  5936. }
  5937. //清空准备表数据
  5938. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5939. if err != nil {
  5940. goodErrcode := models.XtGoodErrcode{
  5941. UserOrgId: item.OrgId,
  5942. Errcode: "自动出库清空准备表数据报错",
  5943. GoodId: item.GoodId,
  5944. Status: 1,
  5945. Ctime: time.Now().Unix(),
  5946. Mtime: 0,
  5947. Count: 0,
  5948. StockCount: 0,
  5949. Creater: creater,
  5950. BatchNumberId: 0,
  5951. WarehouseOutId: 0,
  5952. }
  5953. service.CreateGoodErrcode(goodErrcode)
  5954. }
  5955. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5956. if errs != nil {
  5957. goodErrcode := models.XtGoodErrcode{
  5958. UserOrgId: item.OrgId,
  5959. Errcode: "自动出库创建准备表数据报错",
  5960. GoodId: item.GoodId,
  5961. Status: 1,
  5962. Ctime: time.Now().Unix(),
  5963. Mtime: 0,
  5964. Count: 0,
  5965. StockCount: 0,
  5966. Creater: creater,
  5967. BatchNumberId: 0,
  5968. WarehouseOutId: 0,
  5969. }
  5970. service.CreateGoodErrcode(goodErrcode)
  5971. }
  5972. //查询默认仓库
  5973. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5974. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5975. var total_count int64
  5976. for _, it := range stockList {
  5977. total_count += it.StockCount
  5978. }
  5979. //基础库插入数据
  5980. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5981. if errcodes != nil {
  5982. goodErrcode := models.XtGoodErrcode{
  5983. UserOrgId: item.OrgId,
  5984. Errcode: "自动出库基础库插入数据",
  5985. GoodId: item.GoodId,
  5986. Status: 1,
  5987. Ctime: time.Now().Unix(),
  5988. Mtime: 0,
  5989. Count: 0,
  5990. StockCount: 0,
  5991. Creater: creater,
  5992. BatchNumberId: 0,
  5993. WarehouseOutId: 0,
  5994. }
  5995. service.CreateGoodErrcode(goodErrcode)
  5996. }
  5997. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5998. var flush_count int64
  5999. for _, it := range goodList {
  6000. flush_count += it.StockCount
  6001. }
  6002. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6003. if errsss != nil {
  6004. goodErrcode := models.XtGoodErrcode{
  6005. UserOrgId: item.OrgId,
  6006. Errcode: "自动出库剩余库存更新数据",
  6007. GoodId: item.GoodId,
  6008. Status: 1,
  6009. Ctime: time.Now().Unix(),
  6010. Mtime: 0,
  6011. Count: 0,
  6012. StockCount: 0,
  6013. Creater: creater,
  6014. BatchNumberId: 0,
  6015. WarehouseOutId: 0,
  6016. }
  6017. service.CreateGoodErrcode(goodErrcode)
  6018. }
  6019. }
  6020. }
  6021. //
  6022. } else if err == nil {
  6023. for _, item := range consumables {
  6024. //出库
  6025. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6026. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6027. if err != nil {
  6028. goodErrcode := models.XtGoodErrcode{
  6029. UserOrgId: adminInfo.Org.Id,
  6030. Errcode: "自动出库接口报错",
  6031. GoodId: 0,
  6032. Status: 1,
  6033. Ctime: time.Now().Unix(),
  6034. Mtime: 0,
  6035. Count: 0,
  6036. StockCount: 0,
  6037. Creater: creator,
  6038. BatchNumberId: 0,
  6039. WarehouseOutId: 0,
  6040. }
  6041. service.CreateGoodErrcode(goodErrcode)
  6042. }
  6043. //出库数量相加
  6044. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6045. if errss != nil {
  6046. goodErrcode := models.XtGoodErrcode{
  6047. UserOrgId: item.UserOrgId,
  6048. Errcode: "创建剩余库存字段报错",
  6049. GoodId: item.GoodId,
  6050. Status: 1,
  6051. Ctime: time.Now().Unix(),
  6052. Mtime: time.Now().Unix(),
  6053. Count: 0,
  6054. StockCount: 0,
  6055. Creater: item.Creater,
  6056. BatchNumberId: 0,
  6057. WarehouseOutId: 0,
  6058. }
  6059. service.CreateGoodErrcode(goodErrcode)
  6060. }
  6061. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6062. if len(list) == 0 {
  6063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6064. return
  6065. }
  6066. for _, item := range list {
  6067. prepare := models.DialysisBeforePrepare{
  6068. UserOrgId: adminInfo.Org.Id,
  6069. PatientId: patient_id,
  6070. RecordDate: record_time,
  6071. GoodId: item.GoodId,
  6072. GoodTypeId: item.GoodTypeId,
  6073. Count: item.Count,
  6074. Creater: adminInfo.AdminUser.Id,
  6075. Status: 1,
  6076. Ctime: time.Now().Unix(),
  6077. StorehouseId: houseConfig.StorehouseOutInfo,
  6078. }
  6079. //清空准备表数据
  6080. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6081. if errs != nil {
  6082. goodErrcode := models.XtGoodErrcode{
  6083. UserOrgId: adminInfo.Org.Id,
  6084. Errcode: "自动出库清空准备表数据报错",
  6085. GoodId: 0,
  6086. Status: 1,
  6087. Ctime: time.Now().Unix(),
  6088. Mtime: 0,
  6089. Count: 0,
  6090. StockCount: 0,
  6091. Creater: creator,
  6092. BatchNumberId: 0,
  6093. WarehouseOutId: 0,
  6094. }
  6095. service.CreateGoodErrcode(goodErrcode)
  6096. }
  6097. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6098. if errcodes != nil {
  6099. goodErrcode := models.XtGoodErrcode{
  6100. UserOrgId: adminInfo.Org.Id,
  6101. Errcode: "自动出库创建准备表数据报错",
  6102. GoodId: 0,
  6103. Status: 1,
  6104. Ctime: time.Now().Unix(),
  6105. Mtime: 0,
  6106. Count: 0,
  6107. StockCount: 0,
  6108. Creater: creator,
  6109. BatchNumberId: 0,
  6110. WarehouseOutId: 0,
  6111. }
  6112. service.CreateGoodErrcode(goodErrcode)
  6113. }
  6114. //查询默认仓库
  6115. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6116. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6117. var total_count int64
  6118. for _, it := range stockList {
  6119. total_count += it.StockCount
  6120. }
  6121. //基础库插入数据
  6122. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6123. if errcodes != nil {
  6124. goodErrcode := models.XtGoodErrcode{
  6125. UserOrgId: adminInfo.Org.Id,
  6126. Errcode: "自动出库基础库插入数据报错",
  6127. GoodId: 0,
  6128. Status: 1,
  6129. Ctime: time.Now().Unix(),
  6130. Mtime: 0,
  6131. Count: 0,
  6132. StockCount: 0,
  6133. Creater: creator,
  6134. BatchNumberId: 0,
  6135. WarehouseOutId: 0,
  6136. }
  6137. service.CreateGoodErrcode(goodErrcode)
  6138. }
  6139. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6140. var flush_count int64
  6141. for _, it := range goodList {
  6142. flush_count += it.StockCount
  6143. }
  6144. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6145. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6146. if errss != nil {
  6147. goodErrcode := models.XtGoodErrcode{
  6148. UserOrgId: item.OrgId,
  6149. Errcode: "自动出库剩余库存更新数据",
  6150. GoodId: item.GoodId,
  6151. Status: 1,
  6152. Ctime: time.Now().Unix(),
  6153. Mtime: 0,
  6154. Count: 0,
  6155. StockCount: 0,
  6156. Creater: creater,
  6157. BatchNumberId: 0,
  6158. WarehouseOutId: 0,
  6159. }
  6160. service.CreateGoodErrcode(goodErrcode)
  6161. }
  6162. }
  6163. }
  6164. }
  6165. c.ServeSuccessJSON(map[string]interface{}{
  6166. "msg": "提交成功",
  6167. "message": "2",
  6168. "good_name": "",
  6169. "specification_name": "",
  6170. })
  6171. return
  6172. }
  6173. if record.IsOpen == 1 {
  6174. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6175. //查询是否有库存
  6176. for _, item := range consumables {
  6177. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6178. if item.Count > warehouse.Count {
  6179. goodErrcode := models.XtGoodErrcode{
  6180. UserOrgId: item.UserOrgId,
  6181. Errcode: "自动出库库存不足",
  6182. GoodId: item.GoodId,
  6183. Status: 1,
  6184. Ctime: time.Now().Unix(),
  6185. Mtime: 0,
  6186. Count: 0,
  6187. StockCount: 0,
  6188. Creater: creator,
  6189. BatchNumberId: warehouse.ID,
  6190. WarehouseOutId: 0,
  6191. }
  6192. service.CreateGoodErrcode(goodErrcode)
  6193. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6194. c.ServeSuccessJSON(map[string]interface{}{
  6195. "message": "1",
  6196. "good_name": goodObj.GoodName,
  6197. "specification_name": goodObj.SpecificationName,
  6198. })
  6199. return
  6200. }
  6201. }
  6202. //查询是否有出库单
  6203. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6204. if err == gorm.ErrRecordNotFound {
  6205. //没有记录,则创建出库单
  6206. timeStr := time.Now().Format("2006-01-02")
  6207. timeArr := strings.Split(timeStr, "-")
  6208. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6209. total = total + 1
  6210. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6211. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6212. number = number + total
  6213. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6214. creater := adminInfo.AdminUser.Id
  6215. warehouseOut := models.WarehouseOut{
  6216. WarehouseOutOrderNumber: warehousing_out_order,
  6217. OperationTime: time.Now().Unix(),
  6218. OrgId: adminInfo.Org.Id,
  6219. Creater: creater,
  6220. Ctime: time.Now().Unix(),
  6221. Status: 1,
  6222. WarehouseOutTime: record_time,
  6223. Dealer: 0,
  6224. Manufacturer: 0,
  6225. Type: 1,
  6226. IsSys: 1,
  6227. StorehouseId: houseConfig.StorehouseOutInfo,
  6228. IsCheck: 1,
  6229. }
  6230. err := service.AddSigleWarehouseOut(&warehouseOut)
  6231. if err != nil {
  6232. goodErrcode := models.XtGoodErrcode{
  6233. UserOrgId: adminInfo.Org.Id,
  6234. Errcode: "创建出库单失败",
  6235. GoodId: 0,
  6236. Status: 1,
  6237. Ctime: time.Now().Unix(),
  6238. Mtime: 0,
  6239. Count: 0,
  6240. StockCount: 0,
  6241. Creater: creator,
  6242. BatchNumberId: 0,
  6243. WarehouseOutId: 0,
  6244. }
  6245. service.CreateGoodErrcode(goodErrcode)
  6246. utils.TraceLog("创建出库单失败 err = %v", err)
  6247. } else {
  6248. for _, item := range consumables {
  6249. //出库
  6250. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6251. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6252. if err == nil {
  6253. goodErrcode := models.XtGoodErrcode{
  6254. UserOrgId: adminInfo.Org.Id,
  6255. Errcode: "自动出库接口报错",
  6256. GoodId: 0,
  6257. Status: 1,
  6258. Ctime: time.Now().Unix(),
  6259. Mtime: 0,
  6260. Count: 0,
  6261. StockCount: 0,
  6262. Creater: creator,
  6263. BatchNumberId: 0,
  6264. WarehouseOutId: 0,
  6265. }
  6266. service.CreateGoodErrcode(goodErrcode)
  6267. utils.TraceLog("创建出库单失败 err = %v", err)
  6268. }
  6269. //查询
  6270. //出库数量相加
  6271. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6272. if errs != nil {
  6273. goodErrcode := models.XtGoodErrcode{
  6274. UserOrgId: item.UserOrgId,
  6275. Errcode: "创建剩余库存字段报错",
  6276. GoodId: item.GoodId,
  6277. Status: 1,
  6278. Ctime: time.Now().Unix(),
  6279. Mtime: 0,
  6280. Count: 0,
  6281. StockCount: 0,
  6282. Creater: creater,
  6283. BatchNumberId: 0,
  6284. WarehouseOutId: 0,
  6285. }
  6286. service.CreateGoodErrcode(goodErrcode)
  6287. }
  6288. }
  6289. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6290. if len(list) == 0 {
  6291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6292. return
  6293. }
  6294. for _, item := range list {
  6295. prepare := models.DialysisBeforePrepare{
  6296. UserOrgId: adminInfo.Org.Id,
  6297. PatientId: patient_id,
  6298. RecordDate: record_time,
  6299. GoodId: item.GoodId,
  6300. GoodTypeId: item.GoodTypeId,
  6301. Count: item.Count,
  6302. Creater: adminInfo.AdminUser.Id,
  6303. Status: 1,
  6304. Ctime: time.Now().Unix(),
  6305. StorehouseId: houseConfig.StorehouseOutInfo,
  6306. }
  6307. //清空准备表数据
  6308. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6309. if err != nil {
  6310. goodErrcode := models.XtGoodErrcode{
  6311. UserOrgId: item.OrgId,
  6312. Errcode: "自动出库清空准备表数据报错",
  6313. GoodId: item.GoodId,
  6314. Status: 1,
  6315. Ctime: time.Now().Unix(),
  6316. Mtime: 0,
  6317. Count: 0,
  6318. StockCount: 0,
  6319. Creater: creater,
  6320. BatchNumberId: 0,
  6321. WarehouseOutId: 0,
  6322. }
  6323. service.CreateGoodErrcode(goodErrcode)
  6324. }
  6325. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6326. if errs != nil {
  6327. goodErrcode := models.XtGoodErrcode{
  6328. UserOrgId: item.OrgId,
  6329. Errcode: "自动出库创建准备表数据报错",
  6330. GoodId: item.GoodId,
  6331. Status: 1,
  6332. Ctime: time.Now().Unix(),
  6333. Mtime: 0,
  6334. Count: 0,
  6335. StockCount: 0,
  6336. Creater: creater,
  6337. BatchNumberId: 0,
  6338. WarehouseOutId: 0,
  6339. }
  6340. service.CreateGoodErrcode(goodErrcode)
  6341. }
  6342. //查询默认仓库
  6343. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6344. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6345. var total_count int64
  6346. for _, it := range stockList {
  6347. total_count += it.StockCount
  6348. }
  6349. //基础库插入数据
  6350. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6351. if errcodes != nil {
  6352. goodErrcode := models.XtGoodErrcode{
  6353. UserOrgId: item.OrgId,
  6354. Errcode: "自动出库基础库插入数据",
  6355. GoodId: item.GoodId,
  6356. Status: 1,
  6357. Ctime: time.Now().Unix(),
  6358. Mtime: 0,
  6359. Count: 0,
  6360. StockCount: 0,
  6361. Creater: creater,
  6362. BatchNumberId: 0,
  6363. WarehouseOutId: 0,
  6364. }
  6365. service.CreateGoodErrcode(goodErrcode)
  6366. }
  6367. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6368. var flush_count int64
  6369. for _, it := range goodList {
  6370. flush_count += it.StockCount
  6371. }
  6372. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6373. if errsss != nil {
  6374. goodErrcode := models.XtGoodErrcode{
  6375. UserOrgId: item.OrgId,
  6376. Errcode: "自动出库剩余库存更新数据",
  6377. GoodId: item.GoodId,
  6378. Status: 1,
  6379. Ctime: time.Now().Unix(),
  6380. Mtime: 0,
  6381. Count: 0,
  6382. StockCount: 0,
  6383. Creater: creater,
  6384. BatchNumberId: 0,
  6385. WarehouseOutId: 0,
  6386. }
  6387. service.CreateGoodErrcode(goodErrcode)
  6388. }
  6389. }
  6390. }
  6391. //
  6392. } else if err == nil {
  6393. for _, item := range consumables {
  6394. //出库
  6395. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6396. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6397. if err != nil {
  6398. goodErrcode := models.XtGoodErrcode{
  6399. UserOrgId: adminInfo.Org.Id,
  6400. Errcode: "自动出库接口报错",
  6401. GoodId: 0,
  6402. Status: 1,
  6403. Ctime: time.Now().Unix(),
  6404. Mtime: 0,
  6405. Count: 0,
  6406. StockCount: 0,
  6407. Creater: creator,
  6408. BatchNumberId: 0,
  6409. WarehouseOutId: 0,
  6410. }
  6411. service.CreateGoodErrcode(goodErrcode)
  6412. }
  6413. //出库数量相加
  6414. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6415. if errss != nil {
  6416. goodErrcode := models.XtGoodErrcode{
  6417. UserOrgId: item.UserOrgId,
  6418. Errcode: "创建剩余库存字段报错",
  6419. GoodId: item.GoodId,
  6420. Status: 1,
  6421. Ctime: time.Now().Unix(),
  6422. Mtime: time.Now().Unix(),
  6423. Count: 0,
  6424. StockCount: 0,
  6425. Creater: item.Creater,
  6426. BatchNumberId: 0,
  6427. WarehouseOutId: 0,
  6428. }
  6429. service.CreateGoodErrcode(goodErrcode)
  6430. }
  6431. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6432. if len(list) == 0 {
  6433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6434. return
  6435. }
  6436. for _, item := range list {
  6437. prepare := models.DialysisBeforePrepare{
  6438. UserOrgId: adminInfo.Org.Id,
  6439. PatientId: patient_id,
  6440. RecordDate: record_time,
  6441. GoodId: item.GoodId,
  6442. GoodTypeId: item.GoodTypeId,
  6443. Count: item.Count,
  6444. Creater: adminInfo.AdminUser.Id,
  6445. Status: 1,
  6446. Ctime: time.Now().Unix(),
  6447. StorehouseId: houseConfig.StorehouseOutInfo,
  6448. }
  6449. //清空准备表数据
  6450. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6451. if errs != nil {
  6452. goodErrcode := models.XtGoodErrcode{
  6453. UserOrgId: adminInfo.Org.Id,
  6454. Errcode: "自动出库清空准备表数据报错",
  6455. GoodId: 0,
  6456. Status: 1,
  6457. Ctime: time.Now().Unix(),
  6458. Mtime: 0,
  6459. Count: 0,
  6460. StockCount: 0,
  6461. Creater: creator,
  6462. BatchNumberId: 0,
  6463. WarehouseOutId: 0,
  6464. }
  6465. service.CreateGoodErrcode(goodErrcode)
  6466. }
  6467. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6468. if errcodes != nil {
  6469. goodErrcode := models.XtGoodErrcode{
  6470. UserOrgId: adminInfo.Org.Id,
  6471. Errcode: "自动出库创建准备表数据报错",
  6472. GoodId: 0,
  6473. Status: 1,
  6474. Ctime: time.Now().Unix(),
  6475. Mtime: 0,
  6476. Count: 0,
  6477. StockCount: 0,
  6478. Creater: creator,
  6479. BatchNumberId: 0,
  6480. WarehouseOutId: 0,
  6481. }
  6482. service.CreateGoodErrcode(goodErrcode)
  6483. }
  6484. //查询默认仓库
  6485. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6486. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6487. var total_count int64
  6488. for _, it := range stockList {
  6489. total_count += it.StockCount
  6490. }
  6491. //基础库插入数据
  6492. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6493. if errcodes != nil {
  6494. goodErrcode := models.XtGoodErrcode{
  6495. UserOrgId: adminInfo.Org.Id,
  6496. Errcode: "自动出库基础库插入数据报错",
  6497. GoodId: 0,
  6498. Status: 1,
  6499. Ctime: time.Now().Unix(),
  6500. Mtime: 0,
  6501. Count: 0,
  6502. StockCount: 0,
  6503. Creater: creator,
  6504. BatchNumberId: 0,
  6505. WarehouseOutId: 0,
  6506. }
  6507. service.CreateGoodErrcode(goodErrcode)
  6508. }
  6509. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6510. var flush_count int64
  6511. for _, it := range goodList {
  6512. flush_count += it.StockCount
  6513. }
  6514. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6515. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6516. if errss != nil {
  6517. goodErrcode := models.XtGoodErrcode{
  6518. UserOrgId: item.OrgId,
  6519. Errcode: "自动出库剩余库存更新数据",
  6520. GoodId: item.GoodId,
  6521. Status: 1,
  6522. Ctime: time.Now().Unix(),
  6523. Mtime: 0,
  6524. Count: 0,
  6525. StockCount: 0,
  6526. Creater: creater,
  6527. BatchNumberId: 0,
  6528. WarehouseOutId: 0,
  6529. }
  6530. service.CreateGoodErrcode(goodErrcode)
  6531. }
  6532. }
  6533. }
  6534. }
  6535. c.ServeSuccessJSON(map[string]interface{}{
  6536. "msg": "提交成功",
  6537. "message": "2",
  6538. "good_name": "",
  6539. "specification_name": "",
  6540. })
  6541. return
  6542. } else {
  6543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6544. return
  6545. }
  6546. }
  6547. func (c *DialysisAPIController) EditConsumables() {
  6548. patient_id, _ := c.GetInt64("patient_id", 0)
  6549. record_date := c.GetString("record_time")
  6550. if patient_id <= 0 {
  6551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6552. return
  6553. }
  6554. adminInfo := c.GetMobileAdminUserInfo()
  6555. timeLayout := "2006-01-02"
  6556. loc, _ := time.LoadLocation("Local")
  6557. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6558. record_time := theRecordTime.Unix()
  6559. // 查询信息规挡的设置天数
  6560. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6561. if infor.ID > 0 && infor.WeekDay > 0 {
  6562. var cha_time int64
  6563. timeNowStr := time.Now().Format("2006-01-02")
  6564. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6565. //今日的日期减去设置的日期
  6566. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6567. if cha_time >= record_time {
  6568. //查询审核是否允许
  6569. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6570. //申请状态不允许的情况 拒绝修改
  6571. if infor.ApplicationStatus != 1 {
  6572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6573. return
  6574. }
  6575. }
  6576. }
  6577. dataBody := make(map[string]interface{}, 0)
  6578. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6579. if err != nil {
  6580. utils.ErrorLog(err.Error())
  6581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6582. return
  6583. }
  6584. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6585. var beforePrepares []*models.DialysisBeforePrepareGoods
  6586. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6587. var cancelbefor []*models.DialysisBeforePrepareGoods
  6588. var outbefor []*models.DialysisBeforePrepareGoods
  6589. //判断是否开启自动出库
  6590. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6591. if record.IsOpen == 1 {
  6592. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6593. goods, _ := dataBody["goods"].([]interface{})
  6594. if len(goods) > 0 {
  6595. for _, item := range goods {
  6596. items := item.(map[string]interface{})
  6597. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6598. utils.ErrorLog("good_id")
  6599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6600. return
  6601. }
  6602. good_id := int64(items["good_id"].(float64))
  6603. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6604. utils.ErrorLog("good_type_id")
  6605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6606. return
  6607. }
  6608. good_type_id := int64(items["good_type_id"].(float64))
  6609. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6610. utils.ErrorLog("count")
  6611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6612. return
  6613. }
  6614. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6615. commdity_code := items["commdity_code"].(string)
  6616. fmt.Println(commdity_code)
  6617. prepareGoods := &models.DialysisBeforePrepareGoods{
  6618. GoodTypeId: good_type_id,
  6619. GoodId: good_id,
  6620. Count: count,
  6621. StorehouseId: houseConfig.StorehouseOutInfo,
  6622. }
  6623. beforePrepares = append(beforePrepares, prepareGoods)
  6624. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6625. GoodTypeId: good_type_id,
  6626. GoodId: good_id,
  6627. Count: count,
  6628. StorehouseId: houseConfig.StorehouseOutInfo,
  6629. }
  6630. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6631. }
  6632. for _, item := range beforePrepares {
  6633. //1.查看该患者该耗材型号最后一次出库数量
  6634. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6635. //判断当前出库数量和最后一次出库数量的大小
  6636. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6637. if item.Count < goodInfo.Count {
  6638. cancelbefor = append(cancelbefor, item)
  6639. }
  6640. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6641. if item.Count > goodInfo.Count {
  6642. outbefor = append(outbefor, item)
  6643. }
  6644. //处理编辑耗材新增不了的问题
  6645. if goodInfo.Count == item.Count {
  6646. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6647. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6648. }
  6649. }
  6650. if len(cancelbefor) > 0 {
  6651. //退库
  6652. for _, item := range cancelbefor {
  6653. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6654. creater := adminInfo.AdminUser.Id
  6655. //查询该患者当天已经出库的耗材信息
  6656. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6657. var delete_count int64 = 0
  6658. delete_count = warehouseOutInfos.Count - item.Count
  6659. //增加库存数量
  6660. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6661. //减少实际出库库存数量
  6662. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6663. // 删除出库完成后,要增加对应批次的库存数量
  6664. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6665. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6666. //更新剩余库存
  6667. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6668. var flush_count int64
  6669. for _, it := range goodListOne {
  6670. flush_count += it.StockCount
  6671. }
  6672. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6673. //查询剩余库存
  6674. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6675. var sum_count int64
  6676. for _, item := range goodList {
  6677. sum_count += item.StockCount
  6678. }
  6679. // 在出库记录表里记录退库详情
  6680. warehouseOutInfo := &models.WarehouseOutInfo{
  6681. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6682. WarehouseOutId: warehouseOut.ID,
  6683. Status: 1,
  6684. Ctime: time.Now().Unix(),
  6685. OrgId: adminInfo.Org.Id,
  6686. Type: 1,
  6687. IsSys: 1,
  6688. SysRecordTime: record_time,
  6689. GoodTypeId: item.GoodTypeId,
  6690. GoodId: item.GoodId,
  6691. PatientId: patient_id,
  6692. ConsumableType: 2,
  6693. StorehouseId: houseConfig.StorehouseOutInfo,
  6694. IsCheck: 1,
  6695. OverCount: sum_count,
  6696. }
  6697. warehouseOutInfo.Count = item.Count
  6698. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6699. warehouseOutInfo.Price = stockInInfo.Price
  6700. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6701. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6702. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6703. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6704. warehouseOutInfo.Number = warehouseOutInfos.Number
  6705. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6706. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6707. //查找当天是否存在出库记录
  6708. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6709. if errcod == gorm.ErrRecordNotFound {
  6710. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6711. //插入详情明细表
  6712. stockFlow := models.VmStockFlow{
  6713. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6714. WarehouseOutId: warehouseOut.ID,
  6715. GoodId: item.GoodId,
  6716. Number: warehouseOutInfos.Number,
  6717. ProductDate: stockInInfo.ProductDate,
  6718. ExpireDate: stockInInfo.ExpiryDate,
  6719. Count: item.Count,
  6720. Price: stockInInfo.Price,
  6721. Status: 1,
  6722. Ctime: record_time,
  6723. UserOrgId: adminInfo.Org.Id,
  6724. Manufacturer: stockInInfo.Manufacturer,
  6725. Dealer: stockInInfo.Dealer,
  6726. LicenseNumber: stockInInfo.LicenseNumber,
  6727. IsEdit: 2,
  6728. Creator: creater,
  6729. SystemTime: record_time,
  6730. ConsumableType: 3,
  6731. WarehousingDetailId: 0,
  6732. IsSys: 1,
  6733. UpdateCreator: creater,
  6734. PatientId: patient_id,
  6735. StorehouseId: houseConfig.StorehouseOutInfo,
  6736. }
  6737. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6738. if errflow == gorm.ErrRecordNotFound {
  6739. //创建流水表
  6740. err := service.CreateStockFlowOne(stockFlow)
  6741. fmt.Println("err", err)
  6742. } else if errflow == nil {
  6743. //插入详情明细表
  6744. stockFlow := models.VmStockFlow{
  6745. ID: exsit.ID,
  6746. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6747. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6748. WarehouseOutId: warehouseOut.ID,
  6749. GoodId: item.GoodId,
  6750. Number: warehouseOutInfos.Number,
  6751. ProductDate: stockInInfo.ProductDate,
  6752. ExpireDate: stockInInfo.ExpiryDate,
  6753. Count: exsit.Count - delete_count,
  6754. Price: stockInInfo.Price,
  6755. Status: 1,
  6756. Ctime: record_time,
  6757. UserOrgId: adminInfo.Org.Id,
  6758. Manufacturer: stockInInfo.Manufacturer,
  6759. Dealer: stockInInfo.Dealer,
  6760. LicenseNumber: stockInInfo.LicenseNumber,
  6761. IsEdit: 2,
  6762. Creator: creater,
  6763. SystemTime: record_time,
  6764. ConsumableType: 3,
  6765. WarehousingDetailId: 0,
  6766. IsSys: 1,
  6767. UpdateCreator: creater,
  6768. PatientId: patient_id,
  6769. StorehouseId: houseConfig.StorehouseOutInfo,
  6770. }
  6771. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6772. }
  6773. } else if errcod == nil {
  6774. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6775. //查询剩余库存
  6776. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6777. var sum_count int64
  6778. for _, item := range goodList {
  6779. sum_count += item.StockCount
  6780. }
  6781. //创建退库单,生成退库数据
  6782. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6783. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6784. operation_time := time.Now().Unix()
  6785. creater := adminInfo.AdminUser.Id
  6786. //创建退库单
  6787. timeStr := time.Now().Format("2006-01-02")
  6788. timeArr := strings.Split(timeStr, "-")
  6789. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6790. total = total + 1
  6791. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6792. cancelStock := models.CancelStock{
  6793. OrderNumber: orderNumber,
  6794. OperaTime: operation_time,
  6795. OrgId: adminInfo.Org.Id,
  6796. Creater: creater,
  6797. Ctime: time.Now().Unix(),
  6798. Status: 1,
  6799. ReturnTime: record_time,
  6800. Type: 1,
  6801. StorehouseId: houseConfig.StorehouseOutInfo,
  6802. IsCheck: 1,
  6803. }
  6804. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6805. if msgerrkonde == gorm.ErrRecordNotFound {
  6806. service.AddSigleCancelStock(&cancelStock)
  6807. }
  6808. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6809. //查询是否有出库
  6810. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6811. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6812. deaerler, _ := service.GetDealerById(info.Dealer)
  6813. if info.ID > 0 {
  6814. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6815. cancelStockInfo := models.CancelStockInfo{
  6816. GoodId: item.GoodId,
  6817. CancelStockId: cancel.ID,
  6818. GoodTypeId: good.GoodTypeId,
  6819. Count: delete_count,
  6820. Price: info.Price,
  6821. Total: 0,
  6822. ProductDate: info.ProductDate,
  6823. ExpiryDate: info.ExpiryDate,
  6824. Ctime: time.Now().Unix(),
  6825. Status: 1,
  6826. OrgId: adminInfo.Org.Id,
  6827. OrderNumber: cancel.OrderNumber,
  6828. Type: 0,
  6829. Dealer: deaerler.DealerName,
  6830. Manufacturer: manufacturer.ManufacturerName,
  6831. Number: info.Number,
  6832. RegisterAccount: "",
  6833. Remark: "",
  6834. WarehouseInfoId: info.WarehouseInfotId,
  6835. PatientId: info.PatientId,
  6836. RecordDate: info.SysRecordTime,
  6837. StorehouseId: houseConfig.StorehouseOutInfo,
  6838. IsCheck: 1,
  6839. }
  6840. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6841. //退库数量增加
  6842. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6843. //查询剩余库存
  6844. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6845. var over_count int64
  6846. for _, it := range goodList {
  6847. over_count += it.StockCount
  6848. }
  6849. flow := models.VmStockFlow{
  6850. WarehousingId: info.WarehouseInfotId,
  6851. GoodId: item.GoodId,
  6852. Number: info.Number,
  6853. LicenseNumber: info.LicenseNumber,
  6854. Count: delete_count,
  6855. UserOrgId: adminInfo.Org.Id,
  6856. PatientId: patient_id,
  6857. SystemTime: info.SysRecordTime,
  6858. ConsumableType: 7,
  6859. IsSys: 0,
  6860. WarehousingOrder: "",
  6861. WarehouseOutId: info.WarehouseOutId,
  6862. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6863. IsEdit: 0,
  6864. CancelStockId: cancel.ID,
  6865. CancelOrderNumber: cancel.OrderNumber,
  6866. Manufacturer: manufacturer.ID,
  6867. Dealer: 0,
  6868. Creator: adminInfo.AdminUser.Id,
  6869. UpdateCreator: 0,
  6870. Status: 1,
  6871. Ctime: record_time,
  6872. Mtime: 0,
  6873. Price: info.Price,
  6874. WarehousingDetailId: info.WarehouseInfotId,
  6875. WarehouseOutDetailId: info.ID,
  6876. CancelOutDetailId: cancelInfo.ID,
  6877. ProductDate: info.ProductDate,
  6878. ExpireDate: info.ExpiryDate,
  6879. StorehouseId: houseConfig.StorehouseOutInfo,
  6880. OverCount: over_count,
  6881. }
  6882. service.CreateStockFlowOne(flow)
  6883. }
  6884. }
  6885. //更改自动出库的表格
  6886. details := models.BloodAutomaticReduceDetail{
  6887. WarehouseOutId: warehouseOutInfo.ID,
  6888. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6889. PatientId: patient_id,
  6890. Ctime: time.Now().Unix(),
  6891. Mtime: time.Now().Unix(),
  6892. Status: 1,
  6893. RecordTime: record_time,
  6894. OrgId: adminInfo.Org.Id,
  6895. GoodId: item.GoodId,
  6896. GoodTypeId: item.GoodTypeId,
  6897. Count: item.Count,
  6898. StorehouseId: houseConfig.StorehouseOutInfo,
  6899. }
  6900. //查询当天耗材是否已经存在数据
  6901. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6902. if errcode == gorm.ErrRecordNotFound {
  6903. service.CreateAutoReduceRecord(&details)
  6904. } else if errcode == nil {
  6905. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6906. service.CreateAutoReduceRecord(&details)
  6907. }
  6908. //查询默认仓库
  6909. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6910. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6911. var total_count int64
  6912. for _, it := range stockList {
  6913. total_count += it.StockCount
  6914. }
  6915. //基础库插入数据
  6916. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6917. }
  6918. }
  6919. if len(outbefor) > 0 {
  6920. //出库
  6921. for _, item := range outbefor {
  6922. var last_total int64
  6923. //1.查看该患者该耗材型号最后一次出库数量
  6924. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6925. //计算当前出库和最后一次出库数据相差数据
  6926. last_total = item.Count - goodInfoOne.Count
  6927. //查询该耗材的总库存
  6928. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6929. // 如果库存差大于剩余库存则提示库存不足
  6930. if last_total > wareinfo.StockCount {
  6931. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6932. c.ServeSuccessJSON(map[string]interface{}{
  6933. "message": "1",
  6934. "good_name": goodObj.GoodName,
  6935. "specification_name": goodObj.SpecificationName,
  6936. })
  6937. return
  6938. } else {
  6939. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6940. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6941. if err == gorm.ErrRecordNotFound {
  6942. //没有记录,则创建出库单
  6943. timeStr := time.Now().Format("2006-01-02")
  6944. timeArr := strings.Split(timeStr, "-")
  6945. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6946. total = total + 1
  6947. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6948. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6949. number = number + total
  6950. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6951. warehouseOut := models.WarehouseOut{
  6952. WarehouseOutOrderNumber: warehousing_out_order,
  6953. OperationTime: time.Now().Unix(),
  6954. OrgId: adminInfo.Org.Id,
  6955. Creater: adminInfo.AdminUser.Id,
  6956. Ctime: time.Now().Unix(),
  6957. Status: 1,
  6958. WarehouseOutTime: record_time,
  6959. Dealer: 0,
  6960. Manufacturer: 0,
  6961. Type: 1,
  6962. IsSys: 1,
  6963. StorehouseId: houseConfig.StorehouseOutInfo,
  6964. IsCheck: 1,
  6965. }
  6966. service.AddSigleWarehouseOut(&warehouseOut)
  6967. }
  6968. //出库
  6969. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6970. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6971. //1.查看该患者该耗材型号最后一次出库数量
  6972. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6973. prepare := models.DialysisBeforePrepare{
  6974. UserOrgId: adminInfo.Org.Id,
  6975. PatientId: patient_id,
  6976. RecordDate: record_time,
  6977. GoodId: item.GoodId,
  6978. GoodTypeId: item.GoodTypeId,
  6979. Count: item.Count - goodInfoTwo.Count,
  6980. Ctime: time.Now().Unix(),
  6981. Mtime: 0,
  6982. Creater: adminInfo.AdminUser.Id,
  6983. Modifier: adminInfo.AdminUser.Id,
  6984. Status: 1,
  6985. CommdityCode: "",
  6986. NewCount: 0,
  6987. ProjectId: 0,
  6988. StorehouseId: houseConfig.StorehouseOutInfo,
  6989. }
  6990. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6991. //增加出库数量
  6992. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6993. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6994. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6995. var total_count int64
  6996. for _, it := range stockList {
  6997. total_count += it.StockCount
  6998. }
  6999. //基础库插入数据
  7000. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7001. //剩余库存
  7002. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7003. var flush_count int64
  7004. for _, it := range goodList {
  7005. flush_count += it.StockCount
  7006. }
  7007. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7008. }
  7009. }
  7010. }
  7011. //查询今日出库数据
  7012. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7013. for _, it := range list {
  7014. prepare := models.DialysisBeforePrepare{
  7015. UserOrgId: it.OrgId,
  7016. PatientId: patient_id,
  7017. RecordDate: it.RecordTime,
  7018. GoodId: it.GoodId,
  7019. GoodTypeId: it.GoodTypeId,
  7020. Count: it.Count,
  7021. Ctime: time.Now().Unix(),
  7022. Creater: adminInfo.AdminUser.Id,
  7023. Status: 1,
  7024. StorehouseId: houseConfig.StorehouseOutInfo,
  7025. ProjectId: it.ProjectId,
  7026. }
  7027. //删除准备表数据
  7028. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7029. service.CreateDialysisBeforePrepareOne(&prepare)
  7030. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7031. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7032. var total_count int64
  7033. for _, it := range stockList {
  7034. total_count += it.StockCount
  7035. }
  7036. //基础库插入数据
  7037. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7038. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7039. var flush_count int64
  7040. for _, it := range goodList {
  7041. flush_count += it.StockCount
  7042. }
  7043. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7044. }
  7045. }
  7046. }
  7047. //更新自动出库的地方
  7048. var errs error
  7049. if errs == nil {
  7050. c.ServeSuccessJSON(map[string]interface{}{
  7051. "msg": "修改成功",
  7052. "message": "2",
  7053. "good_name": "",
  7054. "specification_name": "",
  7055. })
  7056. return
  7057. } else {
  7058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7059. return
  7060. }
  7061. }
  7062. }
  7063. func (c *DialysisAPIController) GetDialysisGoods() {
  7064. schedualDate := c.GetString("schedule_date")
  7065. schedule_type, _ := c.GetInt64("schedule_type")
  7066. partition_id, _ := c.GetInt64("partition_id")
  7067. page, _ := c.GetInt("page")
  7068. patient_id, _ := c.GetInt64("patient_id")
  7069. schedualEndDate := int64(0)
  7070. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7071. if parseDateErr != nil && len(schedualDate) != 0 {
  7072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7073. return
  7074. }
  7075. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7076. if parseDateErr != nil && len(schedualDate) != 0 {
  7077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7078. return
  7079. }
  7080. schedualEndDate = endDate.Unix()
  7081. adminUser := c.GetMobileAdminUserInfo()
  7082. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7083. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7084. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7085. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7086. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7087. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7088. //获取当天该病人的透析处方
  7089. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7090. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7091. if err == gorm.ErrRecordNotFound {
  7092. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7093. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7094. if patient_id != 0 {
  7095. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7096. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7097. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7098. //获取患者总的出库数据
  7099. item.LastAutomaticReduceDetail = goodUser
  7100. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7101. item.Project = project
  7102. for _, it := range item.AutomaticReduceDetail {
  7103. var total int64
  7104. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7105. for _, its := range auto {
  7106. total += its.Count
  7107. }
  7108. it.Count = total
  7109. }
  7110. }
  7111. }
  7112. c.ServeSuccessJSON(map[string]interface{}{
  7113. "dialysis_goods": dialysisGoods,
  7114. "good_type": goodTypes,
  7115. "total": total,
  7116. "prescribe": prescribe,
  7117. "good_info": good_info,
  7118. "warehouseOutList": warehouseOutList,
  7119. "config": config,
  7120. "outConfig": outConfig,
  7121. "settleConfig": settleConfig,
  7122. })
  7123. return
  7124. } else if err == nil {
  7125. //获取当天排班的每个患者的库存使用情况
  7126. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7127. //获取患者总的出库数据
  7128. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7129. if patient_id != 0 {
  7130. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7131. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7132. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7133. item.Project = project
  7134. item.LastAutomaticReduceDetail = goodUser
  7135. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7136. for _, it := range item.AutomaticReduceDetail {
  7137. var total int64
  7138. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7139. for _, its := range auto {
  7140. total += its.Count
  7141. }
  7142. it.Count = total
  7143. }
  7144. }
  7145. }
  7146. if err == nil {
  7147. c.ServeSuccessJSON(map[string]interface{}{
  7148. "dialysis_goods": dialysisGoods,
  7149. "good_type": goodTypes,
  7150. "total": total,
  7151. "prescribe": prescribe,
  7152. "good_info": good_info,
  7153. "project": project,
  7154. "warehouseOutList": warehouseOutList,
  7155. "config": config,
  7156. "outConfig": outConfig,
  7157. "settleConfig": settleConfig,
  7158. })
  7159. return
  7160. } else {
  7161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7162. return
  7163. }
  7164. } else if err != nil {
  7165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7166. return
  7167. }
  7168. }
  7169. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7170. start_time := c.GetString("start_time")
  7171. end_time := c.GetString("end_time")
  7172. timeLayout := "2006-01-02"
  7173. loc, _ := time.LoadLocation("Local")
  7174. var theStartTime int64
  7175. if len(start_time) > 0 {
  7176. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7177. if err != nil {
  7178. utils.ErrorLog(err.Error())
  7179. }
  7180. theStartTime = theTime.Unix()
  7181. }
  7182. var theEndtTime int64
  7183. if len(end_time) > 0 {
  7184. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7185. if err != nil {
  7186. utils.ErrorLog(err.Error())
  7187. }
  7188. theEndtTime = theTime.Unix()
  7189. }
  7190. adminUser := c.GetMobileAdminUserInfo()
  7191. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7192. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7193. if err == nil {
  7194. c.ServeSuccessJSON(map[string]interface{}{
  7195. "stock_out": outInfo,
  7196. "stockCount": stockCount,
  7197. })
  7198. return
  7199. } else {
  7200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7201. return
  7202. }
  7203. }
  7204. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7205. patient_id, _ := c.GetInt64("patient_id", 0)
  7206. record_time := c.GetString("record_time")
  7207. adminUser := c.GetMobileAdminUserInfo()
  7208. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7209. if parseDateErr != nil && len(record_time) != 0 {
  7210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7211. return
  7212. }
  7213. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7214. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7215. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7216. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7217. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7218. //获取今日患者的透析处方参数
  7219. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7220. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7221. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7222. c.ServeSuccessJSON(map[string]interface{}{
  7223. "good_type": goodTypes,
  7224. "good_user": goodUser,
  7225. "good_info": good_info,
  7226. "last_good_user": lastGoodUserDetial,
  7227. "project": project,
  7228. "prescription": prescribe,
  7229. "outInfo": outInfo,
  7230. "configs": configs,
  7231. })
  7232. return
  7233. }
  7234. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7235. patient_id, _ := c.GetInt64("patient_id", 0)
  7236. record_date := c.GetString("record_time")
  7237. timeLayout := "2006-01-02"
  7238. loc, _ := time.LoadLocation("Local")
  7239. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7240. record_time := theRecordTime.Unix()
  7241. adminInfo := c.GetMobileAdminUserInfo()
  7242. dataBody := make(map[string]interface{}, 0)
  7243. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7244. if err != nil {
  7245. utils.ErrorLog(err.Error())
  7246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7247. return
  7248. }
  7249. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7250. var beforePrepares []*models.DialysisBeforePrepareGoods
  7251. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7252. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7253. goods, _ := dataBody["goods"].([]interface{})
  7254. if len(goods) > 0 {
  7255. for _, item := range goods {
  7256. items := item.(map[string]interface{})
  7257. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7258. utils.ErrorLog("good_id")
  7259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7260. return
  7261. }
  7262. good_id := int64(items["good_id"].(float64))
  7263. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7264. utils.ErrorLog("good_type_id")
  7265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7266. return
  7267. }
  7268. good_type_id := int64(items["good_type_id"].(float64))
  7269. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7270. utils.ErrorLog("count")
  7271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7272. return
  7273. }
  7274. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7275. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7276. utils.ErrorLog("project_id")
  7277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7278. return
  7279. }
  7280. project_id := int64(items["project_id"].(float64))
  7281. new_count := int64(items["new_count"].(float64))
  7282. old_count := int64(items["old_count"].(float64))
  7283. prepare := &models.DialysisBeforePrepareGoods{
  7284. GoodId: good_id,
  7285. GoodTypeId: good_type_id,
  7286. Count: count,
  7287. ProjectId: project_id,
  7288. StorehouseId: houseConfig.StorehouseOutInfo,
  7289. NewCount: new_count,
  7290. OldCount: old_count,
  7291. }
  7292. beforePrepares = append(beforePrepares, prepare)
  7293. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7294. GoodId: good_id,
  7295. GoodTypeId: good_type_id,
  7296. Count: count,
  7297. ProjectId: project_id,
  7298. StorehouseId: houseConfig.StorehouseOutInfo,
  7299. NewCount: new_count,
  7300. OldCount: old_count,
  7301. }
  7302. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7303. }
  7304. }
  7305. }
  7306. //查询是否有库存
  7307. for _, item := range beforePrepares {
  7308. if item.NewCount > 0 {
  7309. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7310. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7311. if item.Count > warehouse.Count {
  7312. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7313. c.ServeSuccessJSON(map[string]interface{}{
  7314. "message": "1",
  7315. "good_name": goodObj.GoodName,
  7316. "specification_name": goodObj.SpecificationName,
  7317. })
  7318. return
  7319. }
  7320. }
  7321. }
  7322. // 查询信息规挡的设置天数
  7323. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7324. if infor.ID > 0 && infor.WeekDay > 0 {
  7325. var cha_time int64
  7326. timeNowStr := time.Now().Format("2006-01-02")
  7327. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7328. //今日的日期减去设置的日期
  7329. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7330. if cha_time >= record_time {
  7331. //查询审核是否允许
  7332. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7333. //申请状态不允许的情况 拒绝修改
  7334. if infor.ApplicationStatus != 1 {
  7335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7336. return
  7337. }
  7338. }
  7339. }
  7340. //出库逻辑
  7341. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7342. if err != nil {
  7343. utils.ErrorLog(err.Error())
  7344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7345. return
  7346. }
  7347. finish := models.XtDialysisFinish{
  7348. IsFinish: 1,
  7349. UserOrgId: adminInfo.Org.Id,
  7350. Status: 1,
  7351. Ctime: time.Now().Unix(),
  7352. Mtime: 0,
  7353. Module: 11,
  7354. RecordDate: record_time,
  7355. Sourse: 1,
  7356. PatientId: patient_id,
  7357. }
  7358. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7359. if dialysisFinish.ID == 0 {
  7360. service.CreateDialysisFinish(finish)
  7361. }
  7362. //查询当天出库的数据
  7363. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7364. for _, item := range list {
  7365. prepare := models.DialysisBeforePrepare{
  7366. UserOrgId: item.OrgId,
  7367. PatientId: item.PatientId,
  7368. RecordDate: item.RecordTime,
  7369. GoodId: item.GoodId,
  7370. GoodTypeId: item.GoodTypeId,
  7371. Count: item.Count,
  7372. Creater: adminInfo.AdminUser.Id,
  7373. Status: 1,
  7374. Ctime: time.Now().Unix(),
  7375. ProjectId: item.ProjectId,
  7376. StorehouseId: houseConfig.StorehouseOutInfo,
  7377. }
  7378. //清空准备表的数据
  7379. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7380. //插入准备表数据
  7381. service.CreateDialysisBeforePrepareOne(&prepare)
  7382. //查询默认仓库
  7383. //查询默认仓库
  7384. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7385. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7386. var total_count int64
  7387. for _, it := range stockList {
  7388. total_count += it.StockCount
  7389. }
  7390. //基础库插入数据
  7391. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7392. ////更新剩余库存
  7393. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7394. var flush_count int64
  7395. for _, it := range goodList {
  7396. flush_count += it.StockCount
  7397. }
  7398. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7399. if errs != nil {
  7400. goodErrcode := models.XtGoodErrcode{
  7401. UserOrgId: item.OrgId,
  7402. Errcode: "手动出库更新剩余出库失败",
  7403. GoodId: item.GoodId,
  7404. Status: 1,
  7405. Ctime: time.Now().Unix(),
  7406. Mtime: 0,
  7407. Count: 0,
  7408. StockCount: 0,
  7409. Creater: adminInfo.AdminUser.Id,
  7410. BatchNumberId: 0,
  7411. WarehouseOutId: 0,
  7412. }
  7413. service.CreateGoodErrcode(goodErrcode)
  7414. }
  7415. }
  7416. //更新自动出库的地方
  7417. var errs error
  7418. if errs == nil {
  7419. c.ServeSuccessJSON(map[string]interface{}{
  7420. "msg": "修改成功",
  7421. "message": "2",
  7422. "good_name": "",
  7423. "specification_name": "",
  7424. })
  7425. return
  7426. } else {
  7427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7428. return
  7429. }
  7430. }
  7431. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7432. newArr = make([]*models.DialysisBeforePrepare, 0)
  7433. for i := 0; i < len(arr); i++ {
  7434. repeat := false
  7435. for j := i + 1; j < len(arr); j++ {
  7436. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7437. repeat = true
  7438. break
  7439. }
  7440. }
  7441. if !repeat {
  7442. newArr = append(newArr, arr[i])
  7443. }
  7444. }
  7445. return
  7446. }
  7447. func (c *DialysisAPIController) GetAllDrug() {
  7448. patient_id, _ := c.GetInt64("patient_id", 0)
  7449. adminInfo := c.GetMobileAdminUserInfo()
  7450. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7451. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7452. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7453. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7454. c.ServeSuccessJSON(map[string]interface{}{
  7455. "base_drug_config": drugStockConfig,
  7456. "private_drug_config": privateDrugConfig,
  7457. "base_drug_list": drugList,
  7458. "private_drug_list": privateDrugList,
  7459. })
  7460. }
  7461. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7462. newArr = make([]*models.DialysisBeforePrepare, 0)
  7463. for i := 0; i < len(arr); i++ {
  7464. repeat := false
  7465. for j := i + 1; j < len(arr); j++ {
  7466. if arr[i].GoodId == arr[j].GoodId {
  7467. repeat = true
  7468. break
  7469. }
  7470. }
  7471. if !repeat {
  7472. newArr = append(newArr, arr[i])
  7473. }
  7474. }
  7475. return
  7476. }
  7477. func (c *DialysisAPIController) GetDepartment() {
  7478. adminInfo := c.GetMobileAdminUserInfo()
  7479. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7480. if err == nil {
  7481. c.ServeSuccessJSON(map[string]interface{}{
  7482. "departments": departments,
  7483. })
  7484. } else {
  7485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7486. return
  7487. }
  7488. }
  7489. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7490. types, _ := c.GetInt("type", 0)
  7491. start_time := c.GetString("start_time")
  7492. end_time := c.GetString("end_time")
  7493. orgId := c.GetMobileAdminUserInfo().Org.Id
  7494. timeLayout := "2006-01-02"
  7495. loc, _ := time.LoadLocation("Local")
  7496. var startTime int64
  7497. if len(start_time) > 0 {
  7498. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7499. if err != nil {
  7500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7501. return
  7502. }
  7503. startTime = theTime.Unix()
  7504. }
  7505. var endTime int64
  7506. if len(end_time) > 0 {
  7507. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7508. if err != nil {
  7509. utils.ErrorLog(err.Error())
  7510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7511. return
  7512. }
  7513. endTime = theTime.Unix()
  7514. }
  7515. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7516. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7517. if err != nil {
  7518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7519. } else {
  7520. c.ServeSuccessJSON(map[string]interface{}{
  7521. "list": list,
  7522. "type": types,
  7523. "stockTotal": stockTotal,
  7524. })
  7525. }
  7526. }
  7527. func (c *DialysisAPIController) GetPrescriptionList() {
  7528. start_time := c.GetString("start_time")
  7529. end_time := c.GetString("end_time")
  7530. schedule_type, _ := c.GetInt64("schedule_type")
  7531. partion_id, _ := c.GetInt64("partion_id")
  7532. orgId := c.GetMobileAdminUserInfo().Org.Id
  7533. timeLayout := "2006-01-02"
  7534. loc, _ := time.LoadLocation("Local")
  7535. var startTime int64
  7536. if len(start_time) > 0 {
  7537. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7538. if err != nil {
  7539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7540. return
  7541. }
  7542. startTime = theTime.Unix()
  7543. }
  7544. var endTime int64
  7545. if len(end_time) > 0 {
  7546. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7547. if err != nil {
  7548. utils.ErrorLog(err.Error())
  7549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7550. return
  7551. }
  7552. endTime = theTime.Unix()
  7553. }
  7554. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7555. fmt.Println("schedulelist22222222", schedulelist)
  7556. c.ServeSuccessJSON(map[string]interface{}{
  7557. "list": schedulelist,
  7558. })
  7559. return
  7560. }
  7561. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7562. ids := c.GetString("ids")
  7563. //patient_id, _ := c.GetInt64("patient_id")
  7564. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7565. idArray := strings.Split(ids, ",")
  7566. err := service.BatchDeleteMonitor(idArray)
  7567. fmt.Print("err", err)
  7568. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7569. //redis := service.RedisClient()
  7570. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7571. //redis.Set(key, "", time.Second)
  7572. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7573. //redis.Set(keyOne, "", time.Second)
  7574. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7575. //redis.Close()
  7576. c.ServeSuccessJSON(map[string]interface{}{
  7577. "msg": "批量删除成功",
  7578. })
  7579. return
  7580. }
  7581. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7582. id, _ := c.GetInt64("id")
  7583. timeLayout := "2006-01-02"
  7584. loc, _ := time.LoadLocation("Local")
  7585. //start_time := time.Now().Format("2006-01-02")
  7586. start_time := c.GetString("start_time")
  7587. end_time := c.GetString("end_time")
  7588. var startdateunix int64
  7589. if len(start_time) > 0 {
  7590. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7591. if err != nil {
  7592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7593. return
  7594. }
  7595. startdateunix = theTime.Unix()
  7596. }
  7597. var enddateunix int64
  7598. if len(end_time) > 0 {
  7599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7600. if err != nil {
  7601. utils.ErrorLog(err.Error())
  7602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7603. return
  7604. }
  7605. enddateunix = theTime.Unix()
  7606. }
  7607. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7608. //nowTime := time.Now()
  7609. //endTime := nowTime.AddDate(-30, 0, 0)
  7610. //endTimes := endTime.Format("2006-01-02")
  7611. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7612. org_id := c.GetMobileAdminUserInfo().Org.Id
  7613. //if org_id == 10579 {
  7614. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7615. // c.ServeSuccessJSON(map[string]interface{}{
  7616. // "list": list,
  7617. // })
  7618. // return
  7619. //} else {
  7620. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7621. // c.ServeSuccessJSON(map[string]interface{}{
  7622. // "list": list,
  7623. // })
  7624. // return
  7625. //}
  7626. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7627. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7628. c.ServeSuccessJSON(map[string]interface{}{
  7629. "list": list,
  7630. })
  7631. return
  7632. } else {
  7633. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7634. c.ServeSuccessJSON(map[string]interface{}{
  7635. "list": list,
  7636. })
  7637. }
  7638. return
  7639. }
  7640. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7641. dataBody := make(map[string]interface{}, 0)
  7642. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7643. ids := c.GetString("ids")
  7644. idArray := strings.Split(ids, ",")
  7645. origin, _ := c.GetInt64("origin")
  7646. if origin == 1 {
  7647. err = service.BatchDeleteAdvice(idArray)
  7648. fmt.Print("err", err)
  7649. c.ServeSuccessJSON(map[string]interface{}{
  7650. "msg": "批量删除成功",
  7651. })
  7652. return
  7653. }
  7654. if origin == 2 {
  7655. service.BatchDeleteHisAdvice(idArray)
  7656. }
  7657. }
  7658. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7659. good_id, _ := c.GetInt64("good_id")
  7660. count, _ := c.GetInt64("count")
  7661. record_time, _ := c.GetInt64("record_time")
  7662. patient_id, _ := c.GetInt64("patient_id")
  7663. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7664. c.ServeSuccessJSON(map[string]interface{}{
  7665. "detail": detail,
  7666. })
  7667. return
  7668. }
  7669. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7670. good_id, _ := c.GetInt64("good_id")
  7671. record_time, _ := c.GetInt64("record_time")
  7672. patient_id, _ := c.GetInt64("patient_id")
  7673. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7674. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7675. fmt.Print("err", err)
  7676. c.ServeSuccessJSON(map[string]interface{}{
  7677. "msg": "批量删除成功",
  7678. })
  7679. return
  7680. }
  7681. func (c *DialysisAPIController) BatchAdviceCheck() {
  7682. ids := c.GetString("ids")
  7683. idArray := strings.Split(ids, ",")
  7684. creator, _ := c.GetInt64("creator")
  7685. origin, _ := c.GetInt64("origin")
  7686. if origin == 1 {
  7687. err := service.BatchAdviceCheck(idArray, creator)
  7688. fmt.Println(err)
  7689. list, _ := service.GetAdviceExecutionById(idArray)
  7690. c.ServeSuccessJSON(map[string]interface{}{
  7691. "list": list,
  7692. })
  7693. return
  7694. }
  7695. if origin == 2 {
  7696. service.BatchHisAdviceCheck(idArray, creator)
  7697. list, _ := service.GetHisAdviceExecutionById(idArray)
  7698. c.ServeSuccessJSON(map[string]interface{}{
  7699. "list": list,
  7700. })
  7701. return
  7702. }
  7703. }
  7704. func (c *DialysisAPIController) BatchAdviceExecution() {
  7705. ids := c.GetString("ids")
  7706. idArray := strings.Split(ids, ",")
  7707. executionTime := c.GetString("execution_time")
  7708. creator, _ := c.GetInt64("creator")
  7709. timeLayout := "2006-01-02 15:04:05"
  7710. loc, _ := time.LoadLocation("Local")
  7711. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7712. orgin, _ := c.GetInt64("origin")
  7713. if orgin == 1 {
  7714. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7715. list, _ := service.GetAdviceExecutionById(idArray)
  7716. fmt.Println(err)
  7717. c.ServeSuccessJSON(map[string]interface{}{
  7718. "list": list,
  7719. })
  7720. return
  7721. }
  7722. if orgin == 2 {
  7723. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7724. list, _ := service.GetHisAdviceExecutionById(idArray)
  7725. fmt.Println(err)
  7726. c.ServeSuccessJSON(map[string]interface{}{
  7727. "list": list,
  7728. })
  7729. return
  7730. }
  7731. }
  7732. func (c *DialysisAPIController) UpdateStockGoods() {
  7733. good_id, _ := c.GetInt64("good_id")
  7734. record_time, _ := c.GetInt64("record_time")
  7735. patient_id, _ := c.GetInt64("patient_id")
  7736. count, _ := c.GetInt64("count")
  7737. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7738. fmt.Print("err", err)
  7739. c.ServeSuccessJSON(map[string]interface{}{
  7740. "msg": "更新成功",
  7741. })
  7742. return
  7743. }
  7744. // 当前数据比上一次出库数据少
  7745. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7746. //查询该患者当天已经出库的耗材信息
  7747. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7748. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7749. for i := len(goods_yc) - 1; i >= 0; i-- {
  7750. goods_yc_temp := goods_yc[i]
  7751. for j := len(goods) - 1; j >= 0; j-- {
  7752. goods_temp := goods[j]
  7753. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7754. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7755. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7756. if goods_yc_temp.Count == goods_temp.Count {
  7757. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7758. goods = append(goods[:j], goods[j+1:]...)
  7759. break
  7760. }
  7761. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7762. if goods_yc_temp.Count > goods_temp.Count {
  7763. temp_count := goods_yc_temp.Count - goods_temp.Count
  7764. goods_yc[i].Count = temp_count
  7765. goods = append(goods[:j], goods[j+1:]...)
  7766. break
  7767. }
  7768. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7769. if goods_yc_temp.Count < goods_temp.Count {
  7770. temp_count := goods_temp.Count - goods_yc_temp.Count
  7771. goods[j].Count = temp_count
  7772. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7773. break
  7774. }
  7775. }
  7776. }
  7777. }
  7778. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7779. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7780. //退库
  7781. if len(goods_yc) > 0 {
  7782. for _, good_yc := range goods_yc {
  7783. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7784. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7785. }
  7786. }
  7787. return nil
  7788. }
  7789. // 耗材出库删除
  7790. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7791. // 先根据相关信息查询当天该耗材的出库信息
  7792. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7793. if err != nil {
  7794. return err
  7795. }
  7796. var delete_count int64 = 0
  7797. delete_count = warehouseOutInfos.Count - count
  7798. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7799. // 在出库记录表里记录退库详情
  7800. warehouseOutInfo := &models.WarehouseOutInfo{
  7801. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7802. WarehouseOutId: warehouseOut.ID,
  7803. Status: 1,
  7804. Ctime: time.Now().Unix(),
  7805. OrgId: orgID,
  7806. Type: 1,
  7807. IsSys: 1,
  7808. SysRecordTime: record_time,
  7809. GoodTypeId: good_yc.GoodTypeId,
  7810. GoodId: good_yc.GoodId,
  7811. PatientId: good_yc.PatientId,
  7812. ConsumableType: 2,
  7813. StorehouseId: houseConfig.StorehouseOutInfo,
  7814. IsCheck: 1,
  7815. }
  7816. warehouseOutInfo.Count = count
  7817. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7818. warehouseOutInfo.Price = stockInInfo.Price
  7819. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7820. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7821. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7822. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7823. warehouseOutInfo.Number = warehouseOutInfos.Number
  7824. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7825. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7826. //查找当天是否存在出库记录
  7827. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7828. if errcod == gorm.ErrRecordNotFound {
  7829. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7830. //插入详情明细表
  7831. stockFlow := models.VmStockFlow{
  7832. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7833. WarehouseOutId: warehouseOut.ID,
  7834. GoodId: good_yc.GoodId,
  7835. Number: warehouseOutInfos.Number,
  7836. ProductDate: stockInInfo.ProductDate,
  7837. ExpireDate: stockInInfo.ExpiryDate,
  7838. Count: count,
  7839. Price: stockInInfo.Price,
  7840. Status: 1,
  7841. Ctime: time.Now().Unix(),
  7842. UserOrgId: good_yc.OrgId,
  7843. Manufacturer: stockInInfo.Manufacturer,
  7844. Dealer: stockInInfo.Dealer,
  7845. LicenseNumber: stockInInfo.LicenseNumber,
  7846. IsEdit: 2,
  7847. Creator: creater,
  7848. SystemTime: record_time,
  7849. ConsumableType: 3,
  7850. WarehousingDetailId: 0,
  7851. IsSys: 1,
  7852. UpdateCreator: creater,
  7853. PatientId: patient_id,
  7854. StorehouseId: houseConfig.StorehouseOutInfo,
  7855. }
  7856. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7857. if errflow == gorm.ErrRecordNotFound {
  7858. //创建流水表
  7859. err := service.CreateStockFlowOne(stockFlow)
  7860. fmt.Println("err", err)
  7861. } else if errflow == nil {
  7862. //插入详情明细表
  7863. stockFlow := models.VmStockFlow{
  7864. ID: exsit.ID,
  7865. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7866. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7867. WarehouseOutId: warehouseOut.ID,
  7868. GoodId: good_yc.GoodId,
  7869. Number: warehouseOutInfos.Number,
  7870. ProductDate: stockInInfo.ProductDate,
  7871. ExpireDate: stockInInfo.ExpiryDate,
  7872. Count: exsit.Count - delete_count,
  7873. Price: stockInInfo.Price,
  7874. Status: 1,
  7875. Ctime: time.Now().Unix(),
  7876. UserOrgId: good_yc.OrgId,
  7877. Manufacturer: stockInInfo.Manufacturer,
  7878. Dealer: stockInInfo.Dealer,
  7879. LicenseNumber: stockInInfo.LicenseNumber,
  7880. IsEdit: 2,
  7881. Creator: creater,
  7882. SystemTime: record_time,
  7883. ConsumableType: 3,
  7884. WarehousingDetailId: 0,
  7885. IsSys: 1,
  7886. UpdateCreator: creater,
  7887. PatientId: patient_id,
  7888. StorehouseId: houseConfig.StorehouseOutInfo,
  7889. }
  7890. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7891. }
  7892. if errOne != nil {
  7893. return errOne
  7894. }
  7895. } else if errcod == nil {
  7896. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7897. //插入详情明细表
  7898. stockFlow := models.VmStockFlow{
  7899. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7900. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7901. WarehouseOutId: warehouseOut.ID,
  7902. GoodId: good_yc.GoodId,
  7903. Number: warehouseOutInfos.Number,
  7904. ProductDate: stockInInfo.ProductDate,
  7905. ExpireDate: stockInInfo.ExpiryDate,
  7906. Count: count,
  7907. Price: stockInInfo.Price,
  7908. Status: 1,
  7909. Ctime: time.Now().Unix(),
  7910. UserOrgId: good_yc.OrgId,
  7911. Manufacturer: stockInInfo.Manufacturer,
  7912. Dealer: stockInInfo.Dealer,
  7913. LicenseNumber: stockInInfo.LicenseNumber,
  7914. IsEdit: 2,
  7915. Creator: creater,
  7916. SystemTime: record_time,
  7917. ConsumableType: 3,
  7918. WarehousingDetailId: 0,
  7919. IsSys: 1,
  7920. UpdateCreator: creater,
  7921. PatientId: patient_id,
  7922. ReturnCount: delete_count,
  7923. StorehouseId: houseConfig.StorehouseOutInfo,
  7924. }
  7925. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7926. if errflows == gorm.ErrRecordNotFound {
  7927. //创建流水表
  7928. service.CreateStockFlowOne(stockFlow)
  7929. } else if errflows == nil {
  7930. stockFlow := models.VmStockFlow{
  7931. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7932. ID: exsit.ID,
  7933. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7934. WarehouseOutId: warehouseOut.ID,
  7935. GoodId: good_yc.GoodId,
  7936. Number: warehouseOutInfos.Number,
  7937. ProductDate: stockInInfo.ProductDate,
  7938. ExpireDate: stockInInfo.ExpiryDate,
  7939. Count: exsit.Count - delete_count,
  7940. Price: stockInInfo.Price,
  7941. Status: 1,
  7942. Ctime: time.Now().Unix(),
  7943. UserOrgId: good_yc.OrgId,
  7944. Manufacturer: stockInInfo.Manufacturer,
  7945. Dealer: stockInInfo.Dealer,
  7946. LicenseNumber: stockInInfo.LicenseNumber,
  7947. IsEdit: 2,
  7948. Creator: creater,
  7949. SystemTime: record_time,
  7950. ConsumableType: 3,
  7951. WarehousingDetailId: 0,
  7952. IsSys: 1,
  7953. UpdateCreator: creater,
  7954. PatientId: patient_id,
  7955. ReturnCount: delete_count,
  7956. StorehouseId: houseConfig.StorehouseOutInfo,
  7957. }
  7958. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7959. }
  7960. }
  7961. //更改自动出库的表格
  7962. details := models.BloodAutomaticReduceDetail{
  7963. WarehouseOutId: warehouseOutInfo.ID,
  7964. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7965. PatientId: patient_id,
  7966. Ctime: time.Now().Unix(),
  7967. Mtime: time.Now().Unix(),
  7968. Status: 1,
  7969. RecordTime: record_time,
  7970. OrgId: orgID,
  7971. GoodId: good_yc.GoodId,
  7972. GoodTypeId: good_yc.GoodTypeId,
  7973. Count: count,
  7974. StorehouseId: houseConfig.StorehouseOutInfo,
  7975. }
  7976. //查询当天耗材是否已经存在数据
  7977. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7978. if errcode == gorm.ErrRecordNotFound {
  7979. errTwo := service.CreateAutoReduceRecord(&details)
  7980. if errTwo != nil {
  7981. return errTwo
  7982. }
  7983. } else if errcode == nil {
  7984. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7985. service.CreateAutoReduceRecord(&details)
  7986. }
  7987. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7988. //增加出库库存数量
  7989. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7990. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7991. fmt.Println("errOne", errOne)
  7992. // 删除出库完成后,要增加对应批次的库存数量
  7993. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7994. if errThree != nil {
  7995. return errThree
  7996. }
  7997. if good_yc.Count == 0 {
  7998. return nil
  7999. } else {
  8000. return errors.New("退库和出库数据不匹配")
  8001. }
  8002. }
  8003. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8004. //查询该患者当天已经出库的耗材信息
  8005. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8006. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8007. for i := len(goods_yc) - 1; i >= 0; i-- {
  8008. goods_yc_temp := goods_yc[i]
  8009. for j := len(goods) - 1; j >= 0; j-- {
  8010. goods_temp := goods[j]
  8011. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8012. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8013. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8014. if goods_yc_temp.Count == goods_temp.Count {
  8015. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8016. goods = append(goods[:j], goods[j+1:]...)
  8017. break
  8018. }
  8019. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8020. if goods_yc_temp.Count > goods_temp.Count {
  8021. temp_count := goods_yc_temp.Count - goods_temp.Count
  8022. goods_yc[i].Count = temp_count
  8023. goods = append(goods[:j], goods[j+1:]...)
  8024. break
  8025. }
  8026. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8027. if goods_yc_temp.Count < goods_temp.Count {
  8028. temp_count := goods_temp.Count - goods_yc_temp.Count
  8029. goods[j].Count = temp_count
  8030. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8031. break
  8032. }
  8033. }
  8034. }
  8035. }
  8036. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8037. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8038. fmt.Println("剩余需要出库的", len(goods))
  8039. if len(goods) > 0 {
  8040. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8041. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8042. if err == gorm.ErrRecordNotFound {
  8043. //没有记录,则创建出库单
  8044. timeStr := time.Now().Format("2006-01-02")
  8045. timeArr := strings.Split(timeStr, "-")
  8046. total, _ := service.FindAllWarehouseOut(orgID)
  8047. total = total + 1
  8048. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8049. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8050. number = number + total
  8051. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8052. warehouseOut := models.WarehouseOut{
  8053. WarehouseOutOrderNumber: warehousing_out_order,
  8054. OperationTime: time.Now().Unix(),
  8055. OrgId: orgID,
  8056. Creater: creater,
  8057. Ctime: time.Now().Unix(),
  8058. Status: 1,
  8059. WarehouseOutTime: record_time,
  8060. Dealer: 0,
  8061. Manufacturer: 0,
  8062. Type: 1,
  8063. IsSys: 1,
  8064. StorehouseId: houseConfig.StorehouseOutInfo,
  8065. IsCheck: 1,
  8066. }
  8067. err := service.AddSigleWarehouseOut(&warehouseOut)
  8068. if err != nil {
  8069. utils.TraceLog("创建出库单失败 err = %v", err)
  8070. return err
  8071. } else {
  8072. out = warehouseOut
  8073. }
  8074. }
  8075. for _, item := range goods {
  8076. var newCount int64 = 0
  8077. for _, it := range goodOne {
  8078. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8079. newCount = it.Count
  8080. }
  8081. }
  8082. prepare := models.DialysisBeforePrepare{
  8083. GoodTypeId: item.GoodTypeId,
  8084. GoodId: item.GoodId,
  8085. Count: item.Count,
  8086. StorehouseId: houseConfig.StorehouseOutInfo,
  8087. }
  8088. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8089. //增加出库数量
  8090. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8091. }
  8092. }
  8093. if len(goods_yc) > 0 {
  8094. for _, good_yc := range goods_yc {
  8095. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8096. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8097. }
  8098. }
  8099. return nil
  8100. }
  8101. // 耗材出库删除
  8102. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8103. // 先根据相关信息查询当天该耗材的出库信息
  8104. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8105. if err != nil {
  8106. return err
  8107. }
  8108. var delete_count int64 = 0
  8109. for _, ware := range warehouseOutInfos {
  8110. // 判断当前出库的数据和删除出库数量
  8111. if good_yc.Count <= ware.Count {
  8112. delete_count = good_yc.Count
  8113. } else {
  8114. delete_count = ware.Count
  8115. }
  8116. warehouseOutInfo := &models.WarehouseOutInfo{
  8117. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8118. WarehouseOutId: warehouseOut.ID,
  8119. Status: 1,
  8120. Ctime: time.Now().Unix(),
  8121. Remark: "",
  8122. OrgId: orgID,
  8123. Type: 1,
  8124. Manufacturer: 0,
  8125. Dealer: 0,
  8126. IsSys: 0,
  8127. SysRecordTime: record_time,
  8128. GoodTypeId: good_yc.GoodTypeId,
  8129. GoodId: good_yc.GoodId,
  8130. StorehouseId: warehouseOut.StorehouseId,
  8131. IsCheck: 1,
  8132. }
  8133. warehouseOutInfo.Count = delete_count
  8134. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8135. warehouseOutInfo.Price = stockInInfo.Price
  8136. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8137. if errOne != nil {
  8138. return errOne
  8139. }
  8140. // 删除出库完成后,要改变流水库存(有疑问)
  8141. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8142. fmt.Println("errOne", errOne)
  8143. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8144. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8145. //扣减出库数量
  8146. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8147. if errThree != nil {
  8148. return errThree
  8149. }
  8150. }
  8151. if good_yc.Count == 0 {
  8152. return nil
  8153. } else {
  8154. return errors.New("退库和出库数据不匹配")
  8155. }
  8156. }
  8157. func (this *DialysisAPIController) GetMobileScheduleList() {
  8158. limit, _ := this.GetInt64("limit")
  8159. page, _ := this.GetInt64("page")
  8160. type_options_visible, _ := this.GetInt64("type_options_visible")
  8161. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8162. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8163. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8164. }
  8165. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8166. newArr = make([]*models.HisPrescriptionProject, 0)
  8167. for i := 0; i < len(arr); i++ {
  8168. repeat := false
  8169. for j := i + 1; j < len(arr); j++ {
  8170. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8171. repeat = true
  8172. break
  8173. }
  8174. }
  8175. if !repeat {
  8176. newArr = append(newArr, arr[i])
  8177. }
  8178. }
  8179. return
  8180. }
  8181. func (this *DialysisAPIController) GetRoleList() {
  8182. admin_user_id, _ := this.GetInt64("admin_user_id")
  8183. orgid := this.GetMobileAdminUserInfo().Org.Id
  8184. list, err := service.GetRoleList(orgid, admin_user_id)
  8185. fmt.Println(err)
  8186. this.ServeSuccessJSON(map[string]interface{}{
  8187. "list": list,
  8188. })
  8189. return
  8190. }
  8191. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8192. // 先根据相关信息查询当天该耗材的出库信息
  8193. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8194. if err != nil {
  8195. return err
  8196. }
  8197. var delete_count int64 = 0
  8198. delete_count = warehouseOutInfos.Count - count
  8199. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8200. // 删除出库完成后,要增加对应批次的库存数量
  8201. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8202. if errThree != nil {
  8203. return errThree
  8204. }
  8205. //增加退库数量
  8206. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8207. //扣减出库数量
  8208. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8209. //查询剩余库存
  8210. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8211. var sum_count int64
  8212. for _, item := range goodList {
  8213. sum_count += item.StockCount
  8214. }
  8215. // 在出库记录表里记录退库详情
  8216. warehouseOutInfo := &models.WarehouseOutInfo{
  8217. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8218. WarehouseOutId: warehouseOut.ID,
  8219. Status: 1,
  8220. Ctime: time.Now().Unix(),
  8221. OrgId: orgID,
  8222. Type: 1,
  8223. IsSys: 1,
  8224. SysRecordTime: record_time,
  8225. GoodTypeId: good_yc.GoodTypeId,
  8226. GoodId: good_yc.GoodId,
  8227. PatientId: good_yc.PatientId,
  8228. ConsumableType: 2,
  8229. StorehouseId: houseConfig.StorehouseOutInfo,
  8230. IsCheck: 1,
  8231. OverCount: sum_count,
  8232. }
  8233. warehouseOutInfo.Count = count
  8234. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8235. warehouseOutInfo.Price = stockInInfo.Price
  8236. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8237. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8238. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8239. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8240. warehouseOutInfo.Number = warehouseOutInfos.Number
  8241. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8242. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8243. //查找当天是否存在出库记录
  8244. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8245. if errcod == gorm.ErrRecordNotFound {
  8246. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8247. //插入详情明细表
  8248. if errOne != nil {
  8249. return errOne
  8250. }
  8251. //插入详情明细表
  8252. stockFlow := models.VmStockFlow{
  8253. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8254. WarehouseOutId: warehouseOut.ID,
  8255. GoodId: good_yc.GoodId,
  8256. Number: warehouseOutInfos.Number,
  8257. ProductDate: stockInInfo.ProductDate,
  8258. ExpireDate: stockInInfo.ExpiryDate,
  8259. Count: count,
  8260. Price: stockInInfo.Price,
  8261. Status: 1,
  8262. Ctime: record_time,
  8263. UserOrgId: good_yc.OrgId,
  8264. Manufacturer: stockInInfo.Manufacturer,
  8265. Dealer: stockInInfo.Dealer,
  8266. LicenseNumber: stockInInfo.LicenseNumber,
  8267. IsEdit: 2,
  8268. Creator: creater,
  8269. SystemTime: record_time,
  8270. ConsumableType: 3,
  8271. WarehousingDetailId: 0,
  8272. IsSys: 1,
  8273. UpdateCreator: creater,
  8274. PatientId: patient_id,
  8275. StorehouseId: houseConfig.StorehouseOutInfo,
  8276. OverCount: sum_count,
  8277. ProjectId: good_yc.ProjectId,
  8278. }
  8279. err := service.CreateStockFlowOne(stockFlow)
  8280. fmt.Println("err", err)
  8281. } else if errcod == nil {
  8282. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8283. }
  8284. //创建退库单
  8285. operation_time := time.Now().Unix()
  8286. //创建退库单
  8287. timeStr := time.Now().Format("2006-01-02")
  8288. timeArr := strings.Split(timeStr, "-")
  8289. total, _ := service.FindAllCancelStockTotal(orgID)
  8290. total = total + 1
  8291. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8292. cancelStock := models.CancelStock{
  8293. OrderNumber: orderNumber,
  8294. OperaTime: operation_time,
  8295. OrgId: orgID,
  8296. Creater: warehouseOut.Creater,
  8297. Ctime: time.Now().Unix(),
  8298. Status: 1,
  8299. ReturnTime: record_time,
  8300. Type: 1,
  8301. StorehouseId: stockInInfo.StorehouseId,
  8302. IsCheck: 1,
  8303. }
  8304. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8305. if msgerrkonde == gorm.ErrRecordNotFound {
  8306. service.AddSigleCancelStock(&cancelStock)
  8307. }
  8308. cancel, _ := service.GetLastCancelStockById(orgID)
  8309. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8310. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8311. cancelStockInfo := models.CancelStockInfo{
  8312. GoodId: stockInInfo.GoodId,
  8313. CancelStockId: cancel.ID,
  8314. GoodTypeId: stockInInfo.GoodTypeId,
  8315. Count: delete_count,
  8316. Price: stockInInfo.PackingPrice,
  8317. Total: 0,
  8318. ProductDate: stockInInfo.ProductDate,
  8319. ExpiryDate: stockInInfo.ExpiryDate,
  8320. Ctime: record_time,
  8321. Status: 1,
  8322. OrgId: orgID,
  8323. OrderNumber: cancel.OrderNumber,
  8324. Type: 0,
  8325. Dealer: deaerler.DealerName,
  8326. Manufacturer: manufacturer.ManufacturerName,
  8327. Number: stockInInfo.Number,
  8328. RegisterAccount: "",
  8329. Remark: "",
  8330. WarehouseInfoId: stockInInfo.ID,
  8331. PatientId: patient_id,
  8332. RecordDate: record_time,
  8333. StorehouseId: stockInInfo.StorehouseId,
  8334. IsCheck: 1,
  8335. }
  8336. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8337. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8338. flow := models.VmStockFlow{
  8339. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8340. GoodId: good_yc.GoodId,
  8341. Number: warehouseOutInfos.Number,
  8342. LicenseNumber: stockInInfo.LicenseNumber,
  8343. Count: delete_count,
  8344. UserOrgId: orgID,
  8345. PatientId: patient_id,
  8346. SystemTime: record_time,
  8347. ConsumableType: 7,
  8348. IsSys: 0,
  8349. WarehousingOrder: "",
  8350. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8351. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8352. IsEdit: 0,
  8353. CancelStockId: cancel.ID,
  8354. CancelOrderNumber: cancel.OrderNumber,
  8355. Manufacturer: manufacturer.ID,
  8356. Dealer: 0,
  8357. Creator: warehouseOut.Creater,
  8358. UpdateCreator: 0,
  8359. Status: 1,
  8360. Ctime: record_time,
  8361. Mtime: 0,
  8362. Price: stockInInfo.Price,
  8363. WarehousingDetailId: stockInInfo.ID,
  8364. WarehouseOutDetailId: warehouseOutInfos.ID,
  8365. CancelOutDetailId: cancelInfo.ID,
  8366. ProductDate: stockInInfo.ProductDate,
  8367. ExpireDate: stockInInfo.ExpiryDate,
  8368. StorehouseId: houseConfig.StorehouseOutInfo,
  8369. OverCount: sum_count,
  8370. }
  8371. service.CreateStockFlowOne(flow)
  8372. //更改自动出库的表格
  8373. details := models.BloodAutomaticReduceDetail{
  8374. WarehouseOutId: warehouseOutInfo.ID,
  8375. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8376. PatientId: patient_id,
  8377. Ctime: time.Now().Unix(),
  8378. Mtime: time.Now().Unix(),
  8379. Status: 1,
  8380. RecordTime: record_time,
  8381. OrgId: orgID,
  8382. GoodId: good_yc.GoodId,
  8383. GoodTypeId: good_yc.GoodTypeId,
  8384. Count: count,
  8385. StorehouseId: houseConfig.StorehouseOutInfo,
  8386. }
  8387. //查询当天耗材是否已经存在数据
  8388. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8389. if errcode == gorm.ErrRecordNotFound {
  8390. errTwo := service.CreateAutoReduceRecord(&details)
  8391. if errTwo != nil {
  8392. return errTwo
  8393. }
  8394. } else if errcode == nil {
  8395. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8396. service.CreateAutoReduceRecord(&details)
  8397. }
  8398. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8399. //增加出库库存数量
  8400. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8401. if good_yc.Count == 0 {
  8402. return nil
  8403. } else {
  8404. return errors.New("退库和出库数据不匹配")
  8405. }
  8406. }
  8407. func (this *DialysisAPIController) SavePatientSign() {
  8408. adminUserInfo := this.GetMobileAdminUserInfo()
  8409. patient_id, _ := this.GetInt64("patient_id")
  8410. dialysis_date, _ := this.GetInt64("dialysis_date")
  8411. orgid := adminUserInfo.Org.Id
  8412. var esdata models.DialysisOrder
  8413. var err error
  8414. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8416. return
  8417. }
  8418. esdata.Hash = esdata.Hash
  8419. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8420. order := models.DialysisOrder{
  8421. Hash: esdata.Hash,
  8422. Url: esdata.Url,
  8423. }
  8424. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8425. redis := service.RedisClient()
  8426. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8427. redis.Set(key, "", time.Second)
  8428. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8429. //清空key 值
  8430. redis.Set(keyOne, "", time.Second)
  8431. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8432. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8433. //redis.Set(keyTwo, "", time.Second)
  8434. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8435. redis.Set(keyThree, "", time.Second)
  8436. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8437. redis.Set(keyFour, "", time.Second)
  8438. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8439. redis.Set(keyFive, "", time.Second)
  8440. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8441. redis.Set(keySix, "", time.Second)
  8442. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8443. redis.Set(keySeven, "", time.Second)
  8444. if err != nil {
  8445. fmt.Println(err)
  8446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8447. return
  8448. }
  8449. this.ServeSuccessJSON(map[string]interface{}{
  8450. "electronic_signature": esdata,
  8451. })
  8452. }
  8453. func (this *DialysisAPIController) GetPatientSign() {
  8454. patient_id, _ := this.GetInt64("patient_id")
  8455. dialysis_date, _ := this.GetInt64("dialysis_date")
  8456. adminUserInfo := this.GetMobileAdminUserInfo()
  8457. orgId := adminUserInfo.Org.Id
  8458. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8459. if err != nil {
  8460. fmt.Println(err)
  8461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8462. return
  8463. }
  8464. this.ServeSuccessJSON(map[string]interface{}{
  8465. "dialysisOrder": dialysisOrder,
  8466. })
  8467. }
  8468. func (this *DialysisAPIController) GetScheduleByPatient() {
  8469. patient_id, _ := this.GetInt64("patient_id")
  8470. schedule_date, _ := this.GetInt64("schedule_date")
  8471. orgid := this.GetMobileAdminUserInfo().Org.Id
  8472. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8473. this.ServeSuccessJSON(map[string]interface{}{
  8474. "schedule": schedule,
  8475. })
  8476. }
  8477. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8478. org_id := this.GetMobileAdminUserInfo().Org.Id
  8479. patient_id, _ := this.GetInt64("patient_id")
  8480. schedule_date, _ := this.GetInt64("schedule_date")
  8481. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8482. this.ServeSuccessJSON(map[string]interface{}{
  8483. "order": order,
  8484. })
  8485. }
  8486. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8487. org_id := this.GetMobileAdminUserInfo().Org.Id
  8488. schedule_date := this.GetString("schedule_date")
  8489. schedule_type, _ := this.GetInt64("schedule_type")
  8490. timeLayout := "2006-01-02"
  8491. loc, _ := time.LoadLocation("Local")
  8492. var startdateunix int64
  8493. if len(schedule_date) > 0 {
  8494. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8495. if err != nil {
  8496. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8497. return
  8498. }
  8499. startdateunix = theTime.Unix()
  8500. }
  8501. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8502. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8503. devices, _ := service.GetAllDevicetByListSix(org_id)
  8504. for key, item := range scheduals {
  8505. // 床位信息
  8506. for _, device := range devices {
  8507. if item.BedId == device.ID {
  8508. scheduals[key].DeviceNumber = device
  8509. break
  8510. }
  8511. }
  8512. }
  8513. this.ServeSuccessJSON(map[string]interface{}{
  8514. "list": list,
  8515. "scheduals": scheduals,
  8516. })
  8517. }
  8518. func (this *DialysisAPIController) SavePatientPicture() {
  8519. patient_id, _ := this.GetInt64("patient_id")
  8520. dialysis_date, _ := this.GetInt64("schedule_date")
  8521. avatar := this.GetString("avatar")
  8522. fmt.Println("patient_id", patient_id)
  8523. orgId := this.GetMobileAdminUserInfo().Org.Id
  8524. order := models.DialysisOrder{
  8525. Url: avatar,
  8526. }
  8527. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8528. redis := service.RedisClient()
  8529. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8530. redis.Set(key, "", time.Second)
  8531. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8532. //清空key 值
  8533. redis.Set(keyOne, "", time.Second)
  8534. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8535. redis.Set(keyThree, "", time.Second)
  8536. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8537. redis.Set(keyFour, "", time.Second)
  8538. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8539. redis.Set(keyFive, "", time.Second)
  8540. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8541. redis.Set(keySix, "", time.Second)
  8542. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8543. redis.Set(keySeven, "", time.Second)
  8544. if err != nil {
  8545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8546. return
  8547. }
  8548. this.ServeSuccessJSON(map[string]interface{}{
  8549. "order": order,
  8550. })
  8551. }
  8552. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8553. ids := this.GetString("ids")
  8554. idSplit := strings.Split(ids, ",")
  8555. orgId := this.GetMobileAdminUserInfo().Org.Id
  8556. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8557. execution_time := this.GetString("exce_time")
  8558. timeLayout2 := "2006-01-02 15:04:05"
  8559. loc, _ := time.LoadLocation("Local")
  8560. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8561. if errs != nil {
  8562. utils.ErrorLog(errs.Error())
  8563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8564. return
  8565. }
  8566. //his客户
  8567. if config.IsOpen == 1 {
  8568. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8569. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8570. for _, item := range list {
  8571. for _, it := range adviceList {
  8572. if item.DrugId == it.DrugId {
  8573. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8574. }
  8575. }
  8576. }
  8577. for _, item := range list {
  8578. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8579. var sum_out_count int64
  8580. for _, itemThree := range item.ChildDoctorAdvice {
  8581. var prescribing_number int64
  8582. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8583. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8584. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8585. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8586. }
  8587. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8588. prescribing_number = parseIntPrescribingNumber
  8589. }
  8590. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8591. prescribing_number = parseIntPrescribingNumber
  8592. }
  8593. sum_out_count += prescribing_number
  8594. }
  8595. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8596. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8597. //库存不足
  8598. if sum_out_count > drugStockOut.FlushCount {
  8599. this.ServeSuccessJSON(map[string]interface{}{
  8600. "msg": "2",
  8601. "drug": medical,
  8602. "ids": ids,
  8603. })
  8604. return
  8605. }
  8606. }
  8607. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8608. //执行医嘱
  8609. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8610. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8611. for _, item := range advices {
  8612. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8613. redis := service.RedisClient()
  8614. //清空key 值
  8615. redis.Set(key, "", time.Second)
  8616. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8617. redis.Set(keyTwo, "", time.Second)
  8618. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8619. redis.Set(keyThree, "", time.Second)
  8620. recordDate := theTime.Format("2006-01-02")
  8621. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8622. redis.Set(keyFour, "", time.Second)
  8623. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8624. redis.Set(keyFive, "", time.Second)
  8625. defer redis.Close()
  8626. }
  8627. if errs == nil {
  8628. //药品管理信息
  8629. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8630. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8631. if drugStockConfig.IsOpen == 1 {
  8632. for _, item := range advices {
  8633. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8634. config, _ := service.GetDrugOpenConfigOne(orgId)
  8635. if config.IsOpen != 1 {
  8636. //查询该药品是否有库存
  8637. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8638. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8639. if medical.IsUse == 2 {
  8640. if config.IsOpen != 1 {
  8641. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8642. service.HisDrugsDelivery(orgId, creater, &advice)
  8643. if orgId == 3877 || orgId == 10265 {
  8644. //查询该药品是否有出库记录
  8645. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8646. if len(flowMap) == 0 {
  8647. errs := service.UpdateHisAdviceById(advice.ID)
  8648. if errs != nil {
  8649. drugError := models.XtDrugError{
  8650. UserOrgId: orgId,
  8651. DrugId: item.DrugId,
  8652. RecordDate: item.AdviceDate,
  8653. PatientId: item.PatientId,
  8654. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8655. Status: 1,
  8656. Ctime: time.Now().Unix(),
  8657. Mtime: 0,
  8658. SumCount: 0,
  8659. Prescribingnumber: advice.PrescribingNumber,
  8660. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8661. }
  8662. service.CreateDrugError(drugError)
  8663. }
  8664. this.ServeSuccessJSON(map[string]interface{}{
  8665. "msg": "2",
  8666. "drug": medical,
  8667. "ids": ids,
  8668. })
  8669. return
  8670. }
  8671. }
  8672. }
  8673. if pharmacyConfig.IsOpen != 1 {
  8674. service.HisDrugsDelivery(orgId, creater, &advice)
  8675. if orgId == 3877 || orgId == 10265 {
  8676. //查询该药品是否有出库记录
  8677. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8678. if len(flowMap) == 0 {
  8679. errs := service.UpdateHisAdviceById(advice.ID)
  8680. if errs != nil {
  8681. drugError := models.XtDrugError{
  8682. UserOrgId: orgId,
  8683. DrugId: item.DrugId,
  8684. RecordDate: item.AdviceDate,
  8685. PatientId: item.PatientId,
  8686. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8687. Status: 1,
  8688. Ctime: time.Now().Unix(),
  8689. Mtime: 0,
  8690. SumCount: 0,
  8691. Prescribingnumber: advice.PrescribingNumber,
  8692. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8693. }
  8694. service.CreateDrugError(drugError)
  8695. }
  8696. this.ServeSuccessJSON(map[string]interface{}{
  8697. "msg": "2",
  8698. "drug": medical,
  8699. "ids": ids,
  8700. })
  8701. return
  8702. }
  8703. }
  8704. }
  8705. //更新字典里面的库存
  8706. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8707. var sum_count int64
  8708. for _, its := range stockInfo {
  8709. if its.MaxUnit == medical.MaxUnit {
  8710. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8711. }
  8712. sum_count += its.StockMaxNumber + its.StockMinNumber
  8713. }
  8714. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8715. //剩余库存
  8716. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8717. }
  8718. }
  8719. }
  8720. }
  8721. }
  8722. this.ServeSuccessJSON(map[string]interface{}{
  8723. "msg": "1",
  8724. "ids": ids,
  8725. })
  8726. return
  8727. } else {
  8728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8729. }
  8730. }
  8731. //血透客户
  8732. if config.IsOpen == 2 || config.IsOpen == 0 {
  8733. //药品管理信息
  8734. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8735. if drugStockConfig.IsOpen == 1 {
  8736. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8737. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8738. for _, item := range list {
  8739. for _, it := range adviceList {
  8740. if item.DrugId == it.DrugId {
  8741. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8742. }
  8743. }
  8744. }
  8745. for _, item := range list {
  8746. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8747. var sum_out_count int64
  8748. for _, itemThree := range item.ChildDoctorAdvice {
  8749. var prescribing_number int64
  8750. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8751. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8752. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8753. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8754. }
  8755. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8756. prescribing_number = parseIntPrescribingNumber
  8757. }
  8758. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8759. prescribing_number = parseIntPrescribingNumber
  8760. }
  8761. sum_out_count += prescribing_number
  8762. }
  8763. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8764. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8765. //库存不足
  8766. if sum_out_count > drugStockOut.FlushCount {
  8767. this.ServeSuccessJSON(map[string]interface{}{
  8768. "msg": "2",
  8769. "drug": medical,
  8770. "ids": ids,
  8771. })
  8772. return
  8773. }
  8774. }
  8775. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8776. //执行医嘱
  8777. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8778. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8779. for _, item := range advices {
  8780. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8781. redis := service.RedisClient()
  8782. //清空key 值
  8783. redis.Set(key, "", time.Second)
  8784. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8785. redis.Set(keyTwo, "", time.Second)
  8786. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8787. redis.Set(keyThree, "", time.Second)
  8788. recordDate := theTime.Format("2006-01-02")
  8789. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8790. redis.Set(keyFour, "", time.Second)
  8791. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8792. redis.Set(keyFive, "", time.Second)
  8793. defer redis.Close()
  8794. }
  8795. if errs == nil {
  8796. for _, item := range advices {
  8797. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8798. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8799. //查询是否出库按钮开启
  8800. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8801. if adviceSetting.IsAdviceOpen == 1 {
  8802. //查询是否出库按钮开启
  8803. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8804. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8805. if prescriptionConfig.IsOpen == 1 {
  8806. if medical.IsUse == 2 {
  8807. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8808. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8809. }
  8810. if pharmacyConfig.IsOpen != 1 {
  8811. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8812. }
  8813. //更新字典里面的库存
  8814. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8815. var sum_count int64
  8816. for _, its := range stockInfo {
  8817. if its.MaxUnit == medical.MaxUnit {
  8818. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8819. }
  8820. sum_count += its.StockMaxNumber + its.StockMinNumber
  8821. }
  8822. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8823. //剩余库存
  8824. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8825. }
  8826. }
  8827. } else {
  8828. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8829. if medical.IsUse == 2 {
  8830. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8831. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8832. }
  8833. if pharmacyConfig.IsOpen != 1 {
  8834. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8835. }
  8836. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8837. var sum_count int64
  8838. for _, its := range stockInfo {
  8839. if its.MaxUnit == medical.MaxUnit {
  8840. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8841. }
  8842. sum_count += its.StockMaxNumber + its.StockMinNumber
  8843. }
  8844. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8845. //剩余库存
  8846. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8847. }
  8848. }
  8849. }
  8850. }
  8851. this.ServeSuccessJSON(map[string]interface{}{
  8852. "msg": "1",
  8853. "ids": ids,
  8854. })
  8855. return
  8856. } else {
  8857. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8858. //执行医嘱
  8859. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8860. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8861. for _, item := range advices {
  8862. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8863. redis := service.RedisClient()
  8864. //清空key 值
  8865. redis.Set(key, "", time.Second)
  8866. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8867. redis.Set(keyTwo, "", time.Second)
  8868. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8869. redis.Set(keyThree, "", time.Second)
  8870. recordDate := theTime.Format("2006-01-02")
  8871. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8872. redis.Set(keyFour, "", time.Second)
  8873. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8874. redis.Set(keyFive, "", time.Second)
  8875. defer redis.Close()
  8876. }
  8877. this.ServeSuccessJSON(map[string]interface{}{
  8878. "msg": "1",
  8879. "ids": ids,
  8880. })
  8881. return
  8882. }
  8883. }
  8884. }
  8885. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8886. ids := this.GetString("ids")
  8887. idSplit := strings.Split(ids, ",")
  8888. orgId := this.GetMobileAdminUserInfo().Org.Id
  8889. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8890. if config.IsOpen == 1 {
  8891. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8892. this.ServeSuccessJSON(map[string]interface{}{
  8893. "msg": "1",
  8894. "ids": ids,
  8895. })
  8896. return
  8897. }
  8898. if config.IsOpen == 0 || config.IsOpen == 2 {
  8899. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8900. this.ServeSuccessJSON(map[string]interface{}{
  8901. "msg": "1",
  8902. "ids": ids,
  8903. })
  8904. return
  8905. }
  8906. }
  8907. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8908. ids := this.GetString("ids")
  8909. idSplit := strings.Split(ids, ",")
  8910. orgId := this.GetMobileAdminUserInfo().Org.Id
  8911. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8912. //his
  8913. if config.IsOpen == 1 {
  8914. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8915. theTime := time.Now()
  8916. advices := models.HisDoctorAdviceThirty{
  8917. CheckTime: theTime.Unix(),
  8918. Checker: checker,
  8919. UpdatedTime: time.Now().Unix(),
  8920. }
  8921. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8922. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8923. for _, item := range list {
  8924. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8925. redis := service.RedisClient()
  8926. //清空key 值
  8927. redis.Set(key, "", time.Second)
  8928. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8929. redis.Set(keyTwo, "", time.Second)
  8930. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8931. redis.Set(keyThree, "", time.Second)
  8932. recordDate := theTime.Format("2006-01-02")
  8933. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8934. redis.Set(keyFour, "", time.Second)
  8935. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8936. redis.Set(keyFive, "", time.Second)
  8937. defer redis.Close()
  8938. }
  8939. this.ServeSuccessJSON(map[string]interface{}{
  8940. "msg": "1",
  8941. "ids": ids,
  8942. })
  8943. return
  8944. }
  8945. //血透
  8946. if config.IsOpen == 0 || config.IsOpen == 2 {
  8947. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8948. theTime := time.Now()
  8949. advices := models.DoctorAdvice{
  8950. CheckTime: theTime.Unix(),
  8951. Checker: checker,
  8952. UpdatedTime: time.Now().Unix(),
  8953. }
  8954. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8955. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8956. for _, item := range list {
  8957. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8958. redis := service.RedisClient()
  8959. //清空key 值
  8960. redis.Set(key, "", time.Second)
  8961. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8962. redis.Set(keyTwo, "", time.Second)
  8963. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8964. redis.Set(keyThree, "", time.Second)
  8965. recordDate := theTime.Format("2006-01-02")
  8966. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8967. redis.Set(keyFour, "", time.Second)
  8968. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8969. redis.Set(keyFive, "", time.Second)
  8970. defer redis.Close()
  8971. }
  8972. this.ServeSuccessJSON(map[string]interface{}{
  8973. "msg": "1",
  8974. "ids": ids,
  8975. })
  8976. return
  8977. }
  8978. }
  8979. func (this *DialysisAPIController) CheckSchedule() {
  8980. patientID, _ := this.GetInt64("patient_id")
  8981. recordDateStr := this.GetString("record_date")
  8982. nurseID, _ := this.GetInt64("start_nurse")
  8983. schedual_type, _ := this.GetInt64("schedual_type")
  8984. bedID, _ := this.GetInt64("bed")
  8985. start_time := this.GetString("start_time")
  8986. fmt.Println("patientID", patientID)
  8987. fmt.Println("recordDateStr", recordDateStr)
  8988. fmt.Println("nurseID", nurseID)
  8989. fmt.Println("schedual_type------", schedual_type)
  8990. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8992. return
  8993. }
  8994. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8995. if parseStartDateErr != nil {
  8996. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8998. return
  8999. }
  9000. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9001. if parseErr != nil {
  9002. this.ErrorLog("时间解析失败:%v", parseErr)
  9003. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9004. return
  9005. }
  9006. adminUserInfo := this.GetMobileAdminUserInfo()
  9007. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9008. if getPatientErr != nil {
  9009. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9011. return
  9012. } else if patient == nil {
  9013. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9014. return
  9015. }
  9016. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9017. if getNurseErr != nil {
  9018. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9019. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9020. return
  9021. } else if nurse == nil {
  9022. this.ErrorLog("护士不存在")
  9023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9024. return
  9025. }
  9026. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9027. if getDeviceNumberErr != nil {
  9028. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9030. return
  9031. } else if deviceNumber == nil {
  9032. this.ErrorLog("床位号不存在")
  9033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9034. return
  9035. }
  9036. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9037. if getRecordErr != nil {
  9038. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9040. return
  9041. } else if dialysisRecord != nil {
  9042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9043. return
  9044. }
  9045. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9046. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9047. timeLayout := "2006-01-02 15:04:05"
  9048. loc, _ := time.LoadLocation("Local")
  9049. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9050. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9051. schedulestartTime := theStartTime.Unix()
  9052. scheduleendTime := theEndTime.Unix()
  9053. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9054. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9055. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9056. //查询该床位是否有人用了
  9057. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9058. if err == nil {
  9059. if schedule.ID == 0 {
  9060. this.ServeSuccessJSON(map[string]interface{}{
  9061. "status": 0,
  9062. "msg": "请求失败",
  9063. })
  9064. } else {
  9065. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9066. if order.ID > 0 { //该机位被其他人占用了
  9067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9068. return
  9069. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9070. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9071. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9072. this.ServeSuccessJSON(map[string]interface{}{
  9073. "status": 1,
  9074. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9075. })
  9076. return
  9077. } else {
  9078. this.ServeSuccessJSON(map[string]interface{}{
  9079. "status": 0,
  9080. "msg": "",
  9081. })
  9082. }
  9083. }
  9084. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9085. this.ServeSuccessJSON(map[string]interface{}{
  9086. "status": 2,
  9087. "msg": "当前机位已有患者在使用,请重新选择!",
  9088. })
  9089. }
  9090. }
  9091. } else {
  9092. this.ServeSuccessJSON(map[string]interface{}{
  9093. "status": 0,
  9094. "msg": "",
  9095. })
  9096. }
  9097. }
  9098. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9099. orgId := this.GetMobileAdminUserInfo().Org.Id
  9100. schedule_type, _ := this.GetInt64("schedule_type")
  9101. partion_type, _ := this.GetInt64("partion_type")
  9102. start_time := this.GetString("start_time")
  9103. timeLayout := "2006-01-02"
  9104. loc, _ := time.LoadLocation("Local")
  9105. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9106. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9107. _, config := service.FindXTHisRecordByOrgId(orgId)
  9108. appId := this.GetMobileAdminUserInfo().App.Id
  9109. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9110. if err == nil {
  9111. this.ServeSuccessJSON(map[string]interface{}{
  9112. "list": list,
  9113. "config": config,
  9114. "doctorList": doctorList,
  9115. })
  9116. return
  9117. } else {
  9118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9119. return
  9120. }
  9121. }
  9122. func (this *DialysisAPIController) SaveMobileInformation() {
  9123. patient_id, _ := this.GetInt64("patient_id")
  9124. record_date, _ := this.GetInt64("record_date")
  9125. startTime := this.GetString("start_time")
  9126. module, _ := this.GetInt64("module")
  9127. remark := this.GetString("remark")
  9128. timeLayout := "2006-01-02 15:04"
  9129. loc, _ := time.LoadLocation("Local")
  9130. if len(startTime) == 0 {
  9131. utils.ErrorLog("len(start_time) == 0")
  9132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9133. return
  9134. }
  9135. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9136. if err != nil {
  9137. utils.ErrorLog(err.Error())
  9138. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9139. return
  9140. }
  9141. StartTime := theTime.Unix()
  9142. fmt.Println("startime-------------", StartTime)
  9143. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9144. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9145. information := models.XtDialysisInformation{
  9146. Module: module,
  9147. PatientId: patient_id,
  9148. RecordDate: record_date,
  9149. ApplicationDate: StartTime,
  9150. Creater: creater,
  9151. ApplicationStatus: 2,
  9152. Checker: 0,
  9153. CheckTime: 0,
  9154. Remark: remark,
  9155. UserOrgId: user_org_id,
  9156. Ctime: time.Now().Unix(),
  9157. Status: 1,
  9158. Mtime: 0,
  9159. }
  9160. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9161. if infor.ID == 0 {
  9162. service.SaveDialysisInformation(information)
  9163. }
  9164. if infor.ID > 0 {
  9165. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9166. }
  9167. this.ServeSuccessJSON(map[string]interface{}{
  9168. "information": information,
  9169. })
  9170. return
  9171. }
  9172. func (this *DialysisAPIController) GetMobileInformation() {
  9173. limit, _ := this.GetInt64("limit")
  9174. page, _ := this.GetInt64("page")
  9175. orgid := this.GetMobileAdminUserInfo().Org.Id
  9176. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9177. appid := this.GetMobileAdminUserInfo().App.Id
  9178. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9179. patients, _ := service.GetAllpatientThirty(orgid)
  9180. this.ServeSuccessJSON(map[string]interface{}{
  9181. "information": information,
  9182. "total": total,
  9183. "doclist": doclist,
  9184. "patients": patients,
  9185. })
  9186. return
  9187. }
  9188. func (this *DialysisAPIController) GetMobileInformationOne() {
  9189. limit, _ := this.GetInt64("limit")
  9190. page, _ := this.GetInt64("page")
  9191. orgid := this.GetMobileAdminUserInfo().Org.Id
  9192. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9193. appid := this.GetMobileAdminUserInfo().App.Id
  9194. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9195. patients, _ := service.GetAllpatientThirty(orgid)
  9196. this.ServeSuccessJSON(map[string]interface{}{
  9197. "information": information,
  9198. "total": total,
  9199. "doclist": doclist,
  9200. "patients": patients,
  9201. })
  9202. return
  9203. }
  9204. func (this *DialysisAPIController) CheckMobileInformation() {
  9205. id, _ := this.GetInt64("id")
  9206. application_status, _ := this.GetInt64("application_status")
  9207. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9208. checktime := time.Now().Unix()
  9209. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9210. if err == nil {
  9211. this.ServeSuccessJSON(map[string]interface{}{
  9212. "msg": "ok",
  9213. })
  9214. return
  9215. }
  9216. }
  9217. func (c *DialysisAPIController) GetControlMonitorList() {
  9218. partition, _ := c.GetInt64("partition")
  9219. monitorDate := c.GetString("date")
  9220. patient_id, _ := c.GetInt64("patient_id")
  9221. pat_type, _ := c.GetInt64("pat_type")
  9222. timeLayout := "2006-01-02"
  9223. loc, _ := time.LoadLocation("Local")
  9224. var theStartTime int64
  9225. if len(monitorDate) > 0 {
  9226. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9227. if err != nil {
  9228. theStartTime = 0
  9229. }
  9230. theStartTime = theTime.Unix()
  9231. }
  9232. adminInfo := c.GetMobileAdminUserInfo()
  9233. orgID := adminInfo.Org.Id
  9234. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9235. if err != nil {
  9236. c.ErrorLog("获取排班信息失败:%v", err)
  9237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9238. } else {
  9239. if len(monitor) > 0 {
  9240. //获取所有床位
  9241. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9242. //获取所有分区
  9243. zoneList, _ := service.GetAllZoneByList(orgID)
  9244. //获取透析处方
  9245. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9246. //获取透前评估
  9247. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9248. //获取上机
  9249. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9250. //获取透后
  9251. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9252. //获取透后监测
  9253. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9254. //获取所有的患者
  9255. patients, _ := service.GetAllPatientListByListOne(orgID)
  9256. //获取所有透析模式
  9257. treatments, _ := service.GetAllTreatModeByList(orgID)
  9258. //获取所有医嘱
  9259. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9260. //获取双人核对
  9261. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9262. //治疗小结
  9263. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9264. //待消毒
  9265. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9266. for key, item := range monitor {
  9267. // 获取床位信息
  9268. for _, it := range numberList {
  9269. if item.BedId == it.ID {
  9270. monitor[key].DeviceNumber = it
  9271. break
  9272. }
  9273. }
  9274. //获取分区信息
  9275. for _, it := range zoneList {
  9276. if item.PartitionId == it.ID {
  9277. monitor[key].DeviceZone = it
  9278. }
  9279. }
  9280. for _, prescription := range prescriptions {
  9281. if item.PatientId == prescription.PatientId {
  9282. monitor[key].Prescription = prescription
  9283. break
  9284. }
  9285. }
  9286. for _, it := range checkList {
  9287. if item.PatientId == it.PatientId {
  9288. monitor[key].DoubleCheck = it
  9289. break
  9290. }
  9291. }
  9292. for _, it := range summaryList {
  9293. if item.PatientId == it.PatientId {
  9294. monitor[key].TreatmentSummaryForList = it
  9295. break
  9296. }
  9297. }
  9298. // 透前评估
  9299. for _, assessmentBefore := range assessmentBefores {
  9300. if item.PatientId == assessmentBefore.PatientId {
  9301. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9302. break
  9303. }
  9304. }
  9305. // 透析上下机
  9306. for _, dialysisOrder := range dialysisOrders {
  9307. if item.PatientId == dialysisOrder.PatientId {
  9308. monitor[key].DialysisOrder = dialysisOrder
  9309. break
  9310. }
  9311. }
  9312. // 治疗小节
  9313. for _, afterDislysis := range AssessmentAfterDislysis {
  9314. if item.PatientId == afterDislysis.PatientId {
  9315. monitor[key].AssessmentAfterDislysis = afterDislysis
  9316. break
  9317. }
  9318. }
  9319. for _, it := range monitorlist {
  9320. if item.PatientId == it.PatientId {
  9321. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9322. }
  9323. }
  9324. for _, it := range adviceList {
  9325. if item.PatientId == it.PatientId {
  9326. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9327. }
  9328. }
  9329. for _, patient := range patients {
  9330. if item.PatientId == patient.ID {
  9331. monitor[key].MonitorPatients = patient
  9332. break
  9333. }
  9334. }
  9335. for _, treatment := range treatments {
  9336. if item.ModeId == treatment.ID {
  9337. monitor[key].TreatmentMode = treatment
  9338. break
  9339. }
  9340. }
  9341. for _, infor := range informationList {
  9342. if item.PatientId == infor.PatientId {
  9343. monitor[key].NewDeviceInformation = infor
  9344. break
  9345. }
  9346. }
  9347. }
  9348. }
  9349. }
  9350. patients, err := service.GetAllpatientFourty(orgID)
  9351. var mds []*models.NewMonitorDialysisScheduleList
  9352. if pat_type == 0 {
  9353. for _, item := range monitor {
  9354. mds = append(mds, item)
  9355. }
  9356. }
  9357. //待医嘱核对
  9358. if pat_type == 1 {
  9359. for _, item := range monitor {
  9360. if len(item.AdviceList) > 0 {
  9361. mds = append(mds, item)
  9362. }
  9363. }
  9364. }
  9365. //待开小结
  9366. if pat_type == 2 {
  9367. for _, item := range monitor {
  9368. if item.TreatmentSummaryForList == nil {
  9369. mds = append(mds, item)
  9370. }
  9371. }
  9372. }
  9373. //待下机
  9374. if pat_type == 3 {
  9375. for _, item := range monitor {
  9376. if item.DialysisOrder != nil {
  9377. if item.DialysisOrder.ID > 0 {
  9378. mds = append(mds, item)
  9379. }
  9380. }
  9381. }
  9382. }
  9383. //待消毒
  9384. if pat_type == 4 {
  9385. for _, item := range monitor {
  9386. if item.NewDeviceInformation == nil {
  9387. mds = append(mds, item)
  9388. }
  9389. }
  9390. }
  9391. //待双人核对
  9392. if pat_type == 5 {
  9393. for _, item := range monitor {
  9394. if item.DoubleCheck == nil {
  9395. mds = append(mds, item)
  9396. }
  9397. }
  9398. }
  9399. //医嘱未执行
  9400. if pat_type == 6 {
  9401. for _, item := range monitor {
  9402. if len(item.AdviceList) > 0 {
  9403. mds = append(mds, item)
  9404. }
  9405. }
  9406. }
  9407. //患者未签名
  9408. if pat_type == 7 {
  9409. for _, item := range monitor {
  9410. if item.DialysisOrder != nil {
  9411. if item.DialysisOrder.ID > 0 {
  9412. mds = append(mds, item)
  9413. }
  9414. }
  9415. }
  9416. }
  9417. //目标超滤于实际超滤不同
  9418. if pat_type == 8 {
  9419. for _, item := range monitor {
  9420. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9421. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9422. mds = append(mds, item)
  9423. }
  9424. }
  9425. }
  9426. }
  9427. //血压少于5次
  9428. if pat_type == 9 {
  9429. for _, item := range monitor {
  9430. if len(item.MonitoringRecord) < 5 {
  9431. mds = append(mds, item)
  9432. }
  9433. }
  9434. }
  9435. if pat_type == 10 {
  9436. for _, item := range monitor {
  9437. if len(item.MonitoringRecord) == 0 {
  9438. mds = append(mds, item)
  9439. }
  9440. }
  9441. }
  9442. if pat_type == 11 {
  9443. for _, item := range monitor {
  9444. if len(item.MonitoringRecord) > 0 {
  9445. mds = append(mds, item)
  9446. }
  9447. }
  9448. }
  9449. if pat_type == 12 {
  9450. for _, item := range monitor {
  9451. if len(item.MonitoringRecord) > 0 {
  9452. mds = append(mds, item)
  9453. }
  9454. }
  9455. }
  9456. if err == nil {
  9457. c.ServeSuccessJSON(map[string]interface{}{
  9458. "monitor": mds,
  9459. "patients": patients,
  9460. })
  9461. } else {
  9462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9463. }
  9464. }
  9465. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9466. admin_user_id, _ := c.GetInt64("admin_user_id")
  9467. timeStr := time.Now().Format("2006-01-02")
  9468. timeLayout := "2006-01-02 15:04:05"
  9469. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9470. timenow := timeStringToTime.Unix()
  9471. orgId := c.GetMobileAdminUserInfo().Org.Id
  9472. //查询当前护士的患者
  9473. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9474. var patientIds []int64
  9475. for _, item := range orderList {
  9476. patientIds = append(patientIds, item.PatientId)
  9477. }
  9478. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9479. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9480. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9481. //药品管理信息
  9482. _, drugStockConfig := service.FindHisConfig(orgId)
  9483. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9484. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9485. c.ServeSuccessJSON(map[string]interface{}{
  9486. "adviceList": adviceList,
  9487. "hisAdviceList": hisAdviceList,
  9488. "projectList": projectList,
  9489. "drugStockConfig": drugStockConfig,
  9490. "patientList": patientList,
  9491. "projectConfig": projectConfig,
  9492. })
  9493. }
  9494. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9495. patient_id, _ := c.GetInt64("patient_id")
  9496. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9497. c.ServeSuccessJSON(map[string]interface{}{
  9498. "recrods": recrods,
  9499. })
  9500. }
  9501. func (c *DialysisAPIController) ExMobileChangeSch() {
  9502. id_one, _ := c.GetInt64("id_one")
  9503. id_two, _ := c.GetInt64("id_two")
  9504. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9505. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9506. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9507. //if order2.ID > 0 {
  9508. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9509. // return
  9510. //}
  9511. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9512. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9513. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9514. if count > 0 {
  9515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9516. return
  9517. }
  9518. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9519. if count1 > 0 {
  9520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9521. return
  9522. }
  9523. }
  9524. err := service.UpdateScheduleThree(sch, sch_two)
  9525. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9526. if order.ID > 0 {
  9527. //查询该患者的排班机位
  9528. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9529. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9530. redis := service.RedisClient()
  9531. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9532. redis.Set(key, "", time.Second)
  9533. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9534. //清空key 值
  9535. redis.Set(keyOne, "", time.Second)
  9536. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9537. //return
  9538. }
  9539. if err == nil {
  9540. //去除当天患者排班中重复数据,保留最后一条数据
  9541. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9542. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9543. c.ServeSuccessJSON(map[string]interface{}{
  9544. "msg": "交换成功",
  9545. })
  9546. } else {
  9547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9548. return
  9549. }
  9550. }
  9551. func (c *DialysisAPIController) MobileCoverSch() {
  9552. id_one, _ := c.GetInt64("id_one")
  9553. id_two, _ := c.GetInt64("id_two")
  9554. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9555. //针对凤凰医院
  9556. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9557. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9558. if len(advice) > 0 {
  9559. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9560. }
  9561. }
  9562. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9563. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9564. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9565. if len(hisAdvice) > 0 {
  9566. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9567. }
  9568. if len(project) > 0 {
  9569. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9570. }
  9571. }
  9572. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9573. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9574. if order.ID > 0 {
  9575. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9576. redis := service.RedisClient()
  9577. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9578. redis.Set(key, "", time.Second)
  9579. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9580. //清空key 值
  9581. redis.Set(keyOne, "", time.Second)
  9582. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9583. //return
  9584. }
  9585. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9586. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9587. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9588. if count > 0 {
  9589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9590. return
  9591. }
  9592. }
  9593. var new_sch models.Schedule
  9594. new_sch = sch
  9595. new_sch.BedId = sch_two.BedId
  9596. new_sch.ScheduleDate = sch_two.ScheduleDate
  9597. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9598. new_sch.PartitionId = sch_two.PartitionId
  9599. new_sch.ScheduleType = sch_two.ScheduleType
  9600. new_sch.ID = 0
  9601. //删除原来的排班
  9602. err := service.SaveSchTwo(sch, sch_two)
  9603. //生成新的排班
  9604. if err == nil {
  9605. err2 := service.SaveSch(&new_sch)
  9606. if err2 == nil {
  9607. //去除当天患者排班中重复数据,保留最后一条数据
  9608. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9609. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9610. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9611. c.ServeSuccessJSON(map[string]interface{}{
  9612. "msg": "覆盖成功",
  9613. "new_sch": new_sch,
  9614. })
  9615. } else {
  9616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9617. return
  9618. }
  9619. } else {
  9620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9621. return
  9622. }
  9623. }
  9624. func (c *DialysisAPIController) BatchCheckAdvice() {
  9625. patient_id, _ := c.GetInt64("patient_id")
  9626. advice_date, _ := c.GetInt64("advice_date")
  9627. org_id := c.GetMobileAdminUserInfo().Org.Id
  9628. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9629. //查询是his系统还是血透系统
  9630. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9631. //his客户
  9632. if configs.IsOpen == 1 {
  9633. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9634. for _, item := range adviceList {
  9635. service.BatchCheckHisAdvice(item.ID, creater)
  9636. }
  9637. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9638. for _, item := range projectList {
  9639. service.BatchCheckProject(item.ID, creater)
  9640. }
  9641. c.ServeSuccessJSON(map[string]interface{}{
  9642. "adviceList": adviceList,
  9643. "projectList": projectList,
  9644. })
  9645. }
  9646. if configs.IsOpen != 1 {
  9647. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9648. for _, item := range adviceList {
  9649. service.BatchAdviceList(item.ID, creater)
  9650. }
  9651. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9652. for _, item := range projectList {
  9653. service.BatchCheckProject(item.ID, creater)
  9654. }
  9655. c.ServeSuccessJSON(map[string]interface{}{
  9656. "adviceList": adviceList,
  9657. "projectList": projectList,
  9658. })
  9659. }
  9660. return
  9661. }
  9662. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9663. org_id := c.GetMobileAdminUserInfo().Org.Id
  9664. drugList, _ := service.GetAllDrugList(org_id)
  9665. c.ServeSuccessJSON(map[string]interface{}{
  9666. "drugList": drugList,
  9667. })
  9668. }
  9669. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9670. org_id := c.GetMobileAdminUserInfo().Org.Id
  9671. dataBody := make(map[string]interface{}, 0)
  9672. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9673. if err != nil {
  9674. utils.ErrorLog(err.Error())
  9675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9676. return
  9677. }
  9678. timeLayout := "2006-01-02"
  9679. loc, _ := time.LoadLocation("Local")
  9680. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9681. utils.ErrorLog("advice_type")
  9682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9683. return
  9684. }
  9685. adviceType := int64(dataBody["advice_type"].(float64))
  9686. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9687. utils.ErrorLog("start_time")
  9688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9689. return
  9690. }
  9691. startTime2, _ := dataBody["start_time"].(string)
  9692. time_arr := strings.Split(startTime2, " ")
  9693. if len(time_arr) > 0 {
  9694. startTime2 = time_arr[0]
  9695. }
  9696. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9697. utils.ErrorLog("advice_date")
  9698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9699. return
  9700. }
  9701. advice_date, _ := dataBody["advice_date"].(string)
  9702. var advicedateunix int64
  9703. if len(advice_date) > 0 {
  9704. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9705. if err != nil {
  9706. fmt.Println(err)
  9707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9708. return
  9709. }
  9710. advicedateunix = theTime.Unix()
  9711. }
  9712. adviceDate := startTime2
  9713. if len(adviceDate) == 0 {
  9714. utils.ErrorLog("len(adviceDate) == 0")
  9715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9716. return
  9717. }
  9718. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9719. if err != nil {
  9720. utils.ErrorLog(err.Error())
  9721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9722. return
  9723. }
  9724. AdviceDate := advicedateunix
  9725. RecordDate := advicedateunix
  9726. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9727. utils.ErrorLog("start_time")
  9728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9729. return
  9730. }
  9731. startTime, _ := dataBody["start_time"].(string)
  9732. if len(startTime) == 0 {
  9733. utils.ErrorLog("len(start_time) == 0")
  9734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9735. return
  9736. }
  9737. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9738. if err != nil {
  9739. utils.ErrorLog(err.Error())
  9740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9741. return
  9742. }
  9743. StartTime := theTime.Unix()
  9744. advice_name, _ := dataBody["advice_name"].(string)
  9745. advice_desc, _ := dataBody["advice_desc"].(string)
  9746. delivery_way, _ := dataBody["delivery_way"].(string)
  9747. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9748. frequency_type := int64(dataBody["frequency_type"].(float64))
  9749. frequency_week, _ := dataBody["frequency_week"].(string)
  9750. prescribing_number := dataBody["prescribing_number"].(float64)
  9751. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9752. remark := dataBody["remark"].(string)
  9753. single_dose := dataBody["single_dose"].(float64)
  9754. single_dose_unit := dataBody["single_dose_unit"].(string)
  9755. patient_id := int64(dataBody["patient_id"].(float64))
  9756. day_count := int64(dataBody["day_count"].(float64))
  9757. groupNo := int64(dataBody["group_no"].(float64))
  9758. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9759. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9760. if groupNo <= 0 {
  9761. group := service.GetMaxAdviceGroupID(org_id)
  9762. groupNo = group + 1
  9763. }
  9764. var template_id = ""
  9765. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9766. template_id = "M" + adviceLastId
  9767. advice := models.DoctorAdvice{
  9768. UserOrgId: org_id,
  9769. PatientId: patient_id,
  9770. AdviceType: adviceType,
  9771. AdviceDate: AdviceDate,
  9772. StartTime: StartTime,
  9773. AdviceName: advice_name,
  9774. AdviceDesc: advice_desc,
  9775. ReminderDate: 0,
  9776. SingleDose: single_dose,
  9777. SingleDoseUnit: single_dose_unit,
  9778. DrugSpec: 0,
  9779. DrugSpecUnit: "",
  9780. PrescribingNumber: prescribing_number,
  9781. PrescribingNumberUnit: prescribing_number_unit,
  9782. DeliveryWay: delivery_way,
  9783. ExecutionFrequency: execution_frequency,
  9784. AdviceDoctor: advice_doctor,
  9785. Status: 1,
  9786. CreatedTime: time.Now().Unix(),
  9787. UpdatedTime: 0,
  9788. AdviceAffirm: "",
  9789. Remark: remark,
  9790. StopTime: 0,
  9791. StopReason: "",
  9792. StopDoctor: 0,
  9793. StopState: 0,
  9794. ParentId: 0,
  9795. ExecutionTime: 0,
  9796. ExecutionStaff: 0,
  9797. ExecutionState: 0,
  9798. Checker: 0,
  9799. RecordDate: RecordDate,
  9800. DialysisOrderId: 0,
  9801. CheckTime: 0,
  9802. CheckState: 0,
  9803. AdviceId: 0,
  9804. RemindType: 0,
  9805. FrequencyType: frequency_type,
  9806. DayCount: day_count,
  9807. WeekDay: frequency_week,
  9808. ChildDoctorAdvice: nil,
  9809. TemplateId: template_id,
  9810. Modifier: 0,
  9811. IsCheck: 0,
  9812. Way: 0,
  9813. DrugId: 0,
  9814. DrugNameId: 0,
  9815. IsMedicine: 0,
  9816. PushStartTime: 0,
  9817. IsSettle: 0,
  9818. IsPrescription: 0,
  9819. GroupNo: groupNo,
  9820. }
  9821. service.CreateMobileAdivce(advice)
  9822. c.ServeSuccessJSON(map[string]interface{}{
  9823. "msg": "保存成功!",
  9824. })
  9825. }
  9826. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9827. patient_id, _ := c.GetInt64("patient_id")
  9828. org_id := c.GetMobileAdminUserInfo().Org.Id
  9829. app_id := c.GetMobileAdminUserInfo().App.Id
  9830. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9831. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9832. c.ServeSuccessJSON(map[string]interface{}{
  9833. "adviceList": adviceList,
  9834. "adminRoles": adminRoles,
  9835. })
  9836. }
  9837. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9838. org_id := c.GetMobileAdminUserInfo().Org.Id
  9839. dataBody := make(map[string]interface{}, 0)
  9840. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9841. if err != nil {
  9842. utils.ErrorLog(err.Error())
  9843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9844. return
  9845. }
  9846. timeLayout := "2006-01-02"
  9847. loc, _ := time.LoadLocation("Local")
  9848. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9849. utils.ErrorLog("start_time")
  9850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9851. return
  9852. }
  9853. startTime2, _ := dataBody["start_time"].(string)
  9854. time_arr := strings.Split(startTime2, " ")
  9855. if len(time_arr) > 0 {
  9856. startTime2 = time_arr[0]
  9857. }
  9858. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9859. utils.ErrorLog("advice_date")
  9860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9861. return
  9862. }
  9863. advice_date, _ := dataBody["advice_date"].(string)
  9864. var advicedateunix int64
  9865. if len(advice_date) > 0 {
  9866. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9867. if err != nil {
  9868. fmt.Println(err)
  9869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9870. return
  9871. }
  9872. advicedateunix = theTime.Unix()
  9873. }
  9874. adviceDate := startTime2
  9875. if len(adviceDate) == 0 {
  9876. utils.ErrorLog("len(adviceDate) == 0")
  9877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9878. return
  9879. }
  9880. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9881. if err != nil {
  9882. utils.ErrorLog(err.Error())
  9883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9884. return
  9885. }
  9886. AdviceDate := advicedateunix
  9887. RecordDate := advicedateunix
  9888. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9889. utils.ErrorLog("start_time")
  9890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9891. return
  9892. }
  9893. startTime, _ := dataBody["start_time"].(string)
  9894. if len(startTime) == 0 {
  9895. utils.ErrorLog("len(start_time) == 0")
  9896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9897. return
  9898. }
  9899. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9900. if err != nil {
  9901. utils.ErrorLog(err.Error())
  9902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9903. return
  9904. }
  9905. StartTime := theTime.Unix()
  9906. advice_name, _ := dataBody["advice_name"].(string)
  9907. advice_desc, _ := dataBody["advice_desc"].(string)
  9908. delivery_way, _ := dataBody["delivery_way"].(string)
  9909. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9910. prescribing_number := dataBody["prescribing_number"].(float64)
  9911. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9912. remark := dataBody["remark"].(string)
  9913. single_dose := dataBody["single_dose"].(float64)
  9914. single_dose_unit := dataBody["single_dose_unit"].(string)
  9915. patient_id := int64(dataBody["patient_id"].(float64))
  9916. groupNo := int64(dataBody["group_no"].(float64))
  9917. parent_id := int64(dataBody["parent_id"].(float64))
  9918. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9919. advice := models.XtDoctorAdviceOne{
  9920. UserOrgId: org_id,
  9921. PatientId: patient_id,
  9922. AdviceType: 1,
  9923. AdviceDate: AdviceDate,
  9924. StartTime: StartTime,
  9925. AdviceName: advice_name,
  9926. AdviceDesc: advice_desc,
  9927. ReminderDate: 0,
  9928. SingleDose: single_dose,
  9929. SingleDoseUnit: single_dose_unit,
  9930. PrescribingNumber: prescribing_number,
  9931. PrescribingNumberUnit: prescribing_number_unit,
  9932. DeliveryWay: delivery_way,
  9933. ExecutionFrequency: execution_frequency,
  9934. AdviceDoctor: advice_doctor,
  9935. Status: 1,
  9936. CreatedTime: time.Now().Unix(),
  9937. UpdatedTime: time.Now().Unix(),
  9938. AdviceAffirm: "",
  9939. Remark: remark,
  9940. StopTime: 0,
  9941. StopReason: "",
  9942. StopDoctor: 0,
  9943. StopState: 0,
  9944. ParentId: parent_id,
  9945. ExecutionTime: 0,
  9946. ExecutionStaff: 0,
  9947. ExecutionState: 0,
  9948. Checker: 0,
  9949. RecordDate: RecordDate,
  9950. DialysisOrderId: 0,
  9951. CheckTime: 0,
  9952. CheckState: 0,
  9953. DrugSpec: 0,
  9954. DrugSpecUnit: "",
  9955. Groupno: groupNo,
  9956. RemindType: 0,
  9957. FrequencyType: 0,
  9958. DayCount: 0,
  9959. WeekDay: "",
  9960. TemplateId: "",
  9961. Modifier: 0,
  9962. }
  9963. service.CreateMobileAdivceOne(advice)
  9964. c.ServeSuccessJSON(map[string]interface{}{
  9965. "msg": "保存成功!",
  9966. })
  9967. }
  9968. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  9969. id, _ := c.GetInt64("id")
  9970. service.DeleteSelfAdviceSubAdvice(id)
  9971. c.ServeSuccessJSON(map[string]interface{}{
  9972. "msg": "保存成功!",
  9973. })
  9974. }
  9975. func (c *DialysisAPIController) GetEditAdviceAction() {
  9976. id, _ := c.GetInt64("id")
  9977. org_id := c.GetMobileAdminUserInfo().Org.Id
  9978. advice, _ := service.GetEditAdviceActionList(id, org_id)
  9979. drugList, _ := service.GetAllDrugList(org_id)
  9980. c.ServeSuccessJSON(map[string]interface{}{
  9981. "advice": advice,
  9982. "drugList": drugList,
  9983. })
  9984. }
  9985. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  9986. dataBody := make(map[string]interface{}, 0)
  9987. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9988. if err != nil {
  9989. utils.ErrorLog(err.Error())
  9990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9991. return
  9992. }
  9993. timeLayout := "2006-01-02"
  9994. loc, _ := time.LoadLocation("Local")
  9995. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9996. utils.ErrorLog("start_time")
  9997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9998. return
  9999. }
  10000. startTime2, _ := dataBody["start_time"].(string)
  10001. time_arr := strings.Split(startTime2, " ")
  10002. if len(time_arr) > 0 {
  10003. startTime2 = time_arr[0]
  10004. }
  10005. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10006. utils.ErrorLog("advice_date")
  10007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10008. return
  10009. }
  10010. advice_date, _ := dataBody["advice_date"].(string)
  10011. var advicedateunix int64
  10012. if len(advice_date) > 0 {
  10013. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10014. if err != nil {
  10015. fmt.Println(err)
  10016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10017. return
  10018. }
  10019. advicedateunix = theTime.Unix()
  10020. }
  10021. adviceDate := startTime2
  10022. if len(adviceDate) == 0 {
  10023. utils.ErrorLog("len(adviceDate) == 0")
  10024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10025. return
  10026. }
  10027. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10028. if err != nil {
  10029. utils.ErrorLog(err.Error())
  10030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10031. return
  10032. }
  10033. AdviceDate := advicedateunix
  10034. RecordDate := advicedateunix
  10035. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10036. utils.ErrorLog("start_time")
  10037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10038. return
  10039. }
  10040. startTime, _ := dataBody["start_time"].(string)
  10041. if len(startTime) == 0 {
  10042. utils.ErrorLog("len(start_time) == 0")
  10043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10044. return
  10045. }
  10046. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10047. if err != nil {
  10048. utils.ErrorLog(err.Error())
  10049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10050. return
  10051. }
  10052. StartTime := theTime.Unix()
  10053. advice_name, _ := dataBody["advice_name"].(string)
  10054. advice_desc, _ := dataBody["advice_desc"].(string)
  10055. delivery_way, _ := dataBody["delivery_way"].(string)
  10056. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10057. prescribing_number := dataBody["prescribing_number"].(float64)
  10058. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10059. remark := dataBody["remark"].(string)
  10060. single_dose := dataBody["single_dose"].(float64)
  10061. single_dose_unit := dataBody["single_dose_unit"].(string)
  10062. id := int64(dataBody["id"].(float64))
  10063. frequency_type := int64(dataBody["frequency_type"].(float64))
  10064. frequency_week, _ := dataBody["frequency_week"].(string)
  10065. day_count := int64(dataBody["day_count"].(float64))
  10066. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10067. advice := models.XtDoctorAdviceOne{
  10068. AdviceDate: AdviceDate,
  10069. StartTime: StartTime,
  10070. AdviceName: advice_name,
  10071. AdviceDesc: advice_desc,
  10072. SingleDose: single_dose,
  10073. SingleDoseUnit: single_dose_unit,
  10074. PrescribingNumber: prescribing_number,
  10075. PrescribingNumberUnit: prescribing_number_unit,
  10076. DeliveryWay: delivery_way,
  10077. ExecutionFrequency: execution_frequency,
  10078. AdviceDoctor: advice_doctor,
  10079. Remark: remark,
  10080. RecordDate: RecordDate,
  10081. FrequencyType: frequency_type,
  10082. DayCount: day_count,
  10083. WeekDay: frequency_week,
  10084. }
  10085. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10086. c.ServeSuccessJSON(map[string]interface{}{
  10087. "advice": advice,
  10088. })
  10089. }
  10090. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10091. dataBody := make(map[string]interface{}, 0)
  10092. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10093. if err != nil {
  10094. utils.ErrorLog(err.Error())
  10095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10096. return
  10097. }
  10098. timeLayout := "2006-01-02"
  10099. loc, _ := time.LoadLocation("Local")
  10100. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10101. utils.ErrorLog("start_time")
  10102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10103. return
  10104. }
  10105. startTime2, _ := dataBody["start_time"].(string)
  10106. time_arr := strings.Split(startTime2, " ")
  10107. if len(time_arr) > 0 {
  10108. startTime2 = time_arr[0]
  10109. }
  10110. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10111. utils.ErrorLog("advice_date")
  10112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10113. return
  10114. }
  10115. advice_date, _ := dataBody["advice_date"].(string)
  10116. var advicedateunix int64
  10117. if len(advice_date) > 0 {
  10118. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10119. if err != nil {
  10120. fmt.Println(err)
  10121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10122. return
  10123. }
  10124. advicedateunix = theTime.Unix()
  10125. }
  10126. adviceDate := startTime2
  10127. if len(adviceDate) == 0 {
  10128. utils.ErrorLog("len(adviceDate) == 0")
  10129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10130. return
  10131. }
  10132. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10133. if err != nil {
  10134. utils.ErrorLog(err.Error())
  10135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10136. return
  10137. }
  10138. AdviceDate := advicedateunix
  10139. RecordDate := advicedateunix
  10140. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10141. utils.ErrorLog("start_time")
  10142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10143. return
  10144. }
  10145. startTime, _ := dataBody["start_time"].(string)
  10146. if len(startTime) == 0 {
  10147. utils.ErrorLog("len(start_time) == 0")
  10148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10149. return
  10150. }
  10151. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10152. if err != nil {
  10153. utils.ErrorLog(err.Error())
  10154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10155. return
  10156. }
  10157. StartTime := theTime.Unix()
  10158. advice_name, _ := dataBody["advice_name"].(string)
  10159. advice_desc, _ := dataBody["advice_desc"].(string)
  10160. delivery_way, _ := dataBody["delivery_way"].(string)
  10161. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10162. prescribing_number := dataBody["prescribing_number"].(float64)
  10163. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10164. remark := dataBody["remark"].(string)
  10165. single_dose := dataBody["single_dose"].(float64)
  10166. single_dose_unit := dataBody["single_dose_unit"].(string)
  10167. id := int64(dataBody["id"].(float64))
  10168. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10169. advice := models.XtDoctorAdviceOne{
  10170. AdviceDate: AdviceDate,
  10171. StartTime: StartTime,
  10172. AdviceName: advice_name,
  10173. AdviceDesc: advice_desc,
  10174. SingleDose: single_dose,
  10175. SingleDoseUnit: single_dose_unit,
  10176. PrescribingNumber: prescribing_number,
  10177. PrescribingNumberUnit: prescribing_number_unit,
  10178. DeliveryWay: delivery_way,
  10179. ExecutionFrequency: execution_frequency,
  10180. AdviceDoctor: advice_doctor,
  10181. Remark: remark,
  10182. RecordDate: RecordDate,
  10183. }
  10184. service.UpdateMobileDoctorAdviceById(id, advice)
  10185. c.ServeSuccessJSON(map[string]interface{}{
  10186. "advice": advice,
  10187. })
  10188. }
  10189. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10190. dataBody := make(map[string]interface{}, 0)
  10191. timeLayout := "2006-01-02"
  10192. loc, _ := time.LoadLocation("Local")
  10193. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10194. if err != nil {
  10195. utils.ErrorLog(err.Error())
  10196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10197. return
  10198. }
  10199. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10200. utils.ErrorLog("start_time")
  10201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10202. return
  10203. }
  10204. startTime2, _ := dataBody["start_time"].(string)
  10205. time_arr := strings.Split(startTime2, " ")
  10206. if len(time_arr) > 0 {
  10207. startTime2 = time_arr[0]
  10208. }
  10209. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10210. utils.ErrorLog("advice_date")
  10211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10212. return
  10213. }
  10214. advice_date, _ := dataBody["advice_date"].(string)
  10215. var advicedateunix int64
  10216. if len(advice_date) > 0 {
  10217. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10218. if err != nil {
  10219. fmt.Println(err)
  10220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10221. return
  10222. }
  10223. advicedateunix = theTime.Unix()
  10224. }
  10225. adviceDate := startTime2
  10226. if len(adviceDate) == 0 {
  10227. utils.ErrorLog("len(adviceDate) == 0")
  10228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10229. return
  10230. }
  10231. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10232. if err != nil {
  10233. utils.ErrorLog(err.Error())
  10234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10235. return
  10236. }
  10237. RecordDate := advicedateunix
  10238. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10239. utils.ErrorLog("start_time")
  10240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10241. return
  10242. }
  10243. startTime, _ := dataBody["start_time"].(string)
  10244. if len(startTime) == 0 {
  10245. utils.ErrorLog("len(start_time) == 0")
  10246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10247. return
  10248. }
  10249. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10250. if err != nil {
  10251. utils.ErrorLog(err.Error())
  10252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10253. return
  10254. }
  10255. StartTime := theTime.Unix()
  10256. patient_id := int64(dataBody["patient_id"].(float64))
  10257. group_no := int64(dataBody["group_no"].(float64))
  10258. org_id := c.GetMobileAdminUserInfo().Org.Id
  10259. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10260. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10261. utils.ErrorLog("advices")
  10262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10263. return
  10264. }
  10265. adviceNames := dataBody["advices"].([]interface{})
  10266. var advices []*models.GroupAdvice
  10267. for _, adviceNameMap := range adviceNames {
  10268. var advice models.GroupAdvice
  10269. adviceNameM := adviceNameMap.(map[string]interface{})
  10270. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10271. utils.ErrorLog("advice_name")
  10272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10273. return
  10274. }
  10275. adviceName, _ := adviceNameM["advice_name"].(string)
  10276. if len(adviceName) == 0 {
  10277. utils.ErrorLog("len(advice_name) == 0")
  10278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10279. return
  10280. }
  10281. advice.AdviceName = adviceName
  10282. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10283. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10284. advice.DrugSpec = drugSpec
  10285. }
  10286. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10287. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10288. advice.AdviceDesc = adviceDesc
  10289. }
  10290. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10291. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10292. advice.DrugSpecUnit = drugSpecUnit
  10293. }
  10294. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10295. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10296. advice.SingleDose = singleDose
  10297. }
  10298. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10299. singleDose := adviceNameM["single_dose"].(float64)
  10300. advice.SingleDose = singleDose
  10301. }
  10302. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10303. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10304. advice.SingleDoseUnit = singleDoseUnit
  10305. }
  10306. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10307. tmp := adviceNameM["single_dose_unit"].(float64)
  10308. singleDoseUnit := service.TypeConversion(tmp)
  10309. advice.SingleDoseUnit = singleDoseUnit
  10310. }
  10311. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10312. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10313. advice.PrescribingNumber = prescribingNumber
  10314. }
  10315. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10316. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10317. advice.PrescribingNumber = prescribingNumber
  10318. }
  10319. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10320. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10321. advice.PrescribingNumberUnit = prescribingNumberUnit
  10322. }
  10323. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10324. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10325. advice.DeliveryWay = deliveryWay
  10326. }
  10327. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10328. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10329. advice.ExecutionFrequency = executionFrequency
  10330. }
  10331. remark, _ := adviceNameM["remark"].(string)
  10332. advice.Remark = remark
  10333. advice.AdviceType = 1
  10334. advice.StartTime = StartTime
  10335. advice.RecordDate = RecordDate
  10336. advice.PatientId = patient_id
  10337. advice.UserOrgId = org_id
  10338. advice.AdviceDoctor = advice_doctor
  10339. advices = append(advices, &advice)
  10340. }
  10341. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10342. c.ServeSuccessJSON(map[string]interface{}{
  10343. "advice": newAdvices,
  10344. })
  10345. }