patient_api_controller.go 253KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "strings"
  7. "XT_New/enums"
  8. "XT_New/models"
  9. "XT_New/service"
  10. "XT_New/utils"
  11. // "fmt"
  12. "reflect"
  13. "strconv"
  14. "time"
  15. )
  16. type PatientApiController struct {
  17. MobileBaseAPIAuthController
  18. }
  19. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  20. id, _ := c.GetInt64("patient", 0)
  21. if id <= 0 {
  22. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  23. return
  24. }
  25. adminUserInfo := c.GetMobileAdminUserInfo()
  26. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  27. if patient.ID == 0 {
  28. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  29. return
  30. }
  31. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  32. if err != nil {
  33. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  34. return
  35. }
  36. if Registrars != nil {
  37. patient.Registrars = Registrars.Name
  38. }
  39. c.ServeSuccessJSON(map[string]interface{}{
  40. "patient": patient,
  41. })
  42. return
  43. }
  44. func (c *PatientApiController) CreateDialysisSolution() {
  45. id, _ := c.GetInt64("patient", 0)
  46. if id <= 0 {
  47. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  48. return
  49. }
  50. adminUserInfo := c.GetMobileAdminUserInfo()
  51. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  52. if patient.ID == 0 {
  53. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  54. return
  55. }
  56. //根据路由来做权限
  57. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  58. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  59. //if template.TemplateId == 2 || template.TemplateId == 6 {
  60. // if appRole.UserType == 3 {
  61. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  62. // if getPermissionErr != nil {
  63. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  64. // return
  65. // } else if headNursePermission == nil {
  66. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  67. // return
  68. // }
  69. // }
  70. //}
  71. var solution models.DialysisSolution
  72. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  73. if code > 0 {
  74. c.ServeFailJSONWithSGJErrorCode(code)
  75. return
  76. }
  77. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  78. solution.Doctor = adminUserInfo.AdminUser.Id
  79. solution.Status = 1
  80. solution.PatientId = id
  81. solution.CreatedTime = time.Now().Unix()
  82. solution.UserOrgId = adminUserInfo.Org.Id
  83. solution.UpdatedTime = time.Now().Unix()
  84. solution.SubName = ""
  85. solution.ParentId = 0
  86. err := service.CreatePatientDialysisSolution(&solution)
  87. if err != nil {
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  89. return
  90. }
  91. c.ServeSuccessJSON(map[string]interface{}{
  92. "msg": "ok",
  93. "solution": solution,
  94. })
  95. return
  96. }
  97. func (c *PatientApiController) EditDialysisSolution() {
  98. id, _ := c.GetInt64("id", 0)
  99. if id <= 0 {
  100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. return
  102. }
  103. adminUserInfo := c.GetMobileAdminUserInfo()
  104. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  105. if solution.ID == 0 {
  106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  107. return
  108. }
  109. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  110. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  111. // if getPermissionErr != nil {
  112. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  113. // return
  114. // } else if headNursePermission == nil {
  115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  116. // return
  117. // }
  118. //}
  119. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  120. if code > 0 {
  121. c.ServeFailJSONWithSGJErrorCode(code)
  122. return
  123. }
  124. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  125. solution.Doctor = adminUserInfo.AdminUser.Id
  126. solution.Status = 1
  127. // solution.PatientId = id
  128. // solution.CreatedTime = time.Now().Unix()
  129. // solution.UserOrgId = adminUserInfo.Org.Id
  130. solution.UpdatedTime = time.Now().Unix()
  131. // solution.SubName = ""
  132. // solution.ParentId = 0
  133. err := service.UpdatePatientDialysisSolution(&solution)
  134. if err != nil {
  135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  136. return
  137. }
  138. c.ServeSuccessJSON(map[string]interface{}{
  139. "msg": "ok",
  140. "solution": solution,
  141. })
  142. return
  143. }
  144. func (c *PatientApiController) CreateDoctorAdvice() {
  145. patient, _ := c.GetInt64("id", 0)
  146. if patient <= 0 {
  147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  148. return
  149. }
  150. adminUserInfo := c.GetMobileAdminUserInfo()
  151. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  152. if patientInfo.ID == 0 {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  154. return
  155. }
  156. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  157. //if appRole.UserType == 3{
  158. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  159. // return
  160. //}
  161. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  162. //
  163. //if appRole.UserType == 3 {
  164. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  165. // if getPermissionErr != nil {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  167. // return
  168. // } else if headNursePermission == nil {
  169. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  170. // return
  171. // }
  172. //}
  173. var advice models.DoctorAdvice
  174. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  175. if code > 0 {
  176. c.ServeFailJSONWithSGJErrorCode(code)
  177. return
  178. }
  179. if advice.ParentId > 0 {
  180. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  181. if old.ID == 0 || old.PatientId != patient {
  182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  183. return
  184. }
  185. if old.StopState == 1 || old.ExecutionState == 1 {
  186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  187. return
  188. }
  189. if old.ParentId > 0 {
  190. advice.ParentId = old.ParentId
  191. }
  192. advice.StartTime = old.StartTime
  193. advice.AdviceDoctor = old.AdviceDoctor
  194. advice.DeliveryWay = old.DeliveryWay
  195. advice.ExecutionFrequency = old.ExecutionFrequency
  196. advice.GroupNo = old.GroupNo
  197. }
  198. advice.Status = 1
  199. advice.CreatedTime = time.Now().Unix()
  200. advice.UpdatedTime = time.Now().Unix()
  201. advice.StopState = 2
  202. advice.ExecutionState = 2
  203. advice.UserOrgId = adminUserInfo.Org.Id
  204. advice.PatientId = patient
  205. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  206. err := service.CreateDoctorAdvice(&advice)
  207. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  208. redis := service.RedisClient()
  209. defer redis.Close()
  210. redis.Set(key, "", time.Second)
  211. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  212. redis.Set(keyOne, "", time.Second)
  213. if err != nil {
  214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  215. return
  216. }
  217. c.ServeSuccessJSON(map[string]interface{}{
  218. "msg": "ok",
  219. "advice": advice,
  220. })
  221. return
  222. }
  223. func (c *PatientApiController) EditDoctorAdvice() {
  224. id, _ := c.GetInt64("id", 0)
  225. patient_id, _ := c.GetInt64("patient_id")
  226. doc_advice_date, _ := c.GetInt64("advice_date")
  227. if id <= 0 {
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  229. return
  230. }
  231. redis := service.RedisClient()
  232. adminUserInfo := c.GetMobileAdminUserInfo()
  233. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //
  236. //if appRole.UserType == 3 {
  237. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  238. // if getPermissionErr != nil {
  239. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  240. // return
  241. // } else if headNursePermission == nil {
  242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  243. // return
  244. // }
  245. //}
  246. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  247. if advice.ID == 0 {
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  249. return
  250. }
  251. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  252. if code > 0 {
  253. c.ServeFailJSONWithSGJErrorCode(code)
  254. return
  255. }
  256. advice.Status = 1
  257. advice.UpdatedTime = time.Now().Unix()
  258. advice.UserOrgId = adminUserInfo.Org.Id
  259. advice.Modifier = adminUserInfo.AdminUser.Id
  260. if adminUserInfo.Org.Id == 10580 {
  261. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  262. }
  263. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  264. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  265. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  266. var err error
  267. var isChangeGroup bool
  268. if advice.ParentId == 0 {
  269. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  270. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  271. if len(adviceSlice) == 1 {
  272. // 查询信息规挡的设置天数
  273. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  274. if infor.ID > 0 && infor.WeekDay > 0 {
  275. var cha_time int64
  276. timeNowStr := time.Now().Format("2006-01-02")
  277. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  278. //今日的日期减去设置的日期
  279. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  280. if cha_time >= sourceAdvice.AdviceDate {
  281. //查询审核是否允许
  282. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  283. //申请状态不允许的情况 拒绝修改
  284. if infor.ApplicationStatus != 1 {
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  286. return
  287. }
  288. }
  289. }
  290. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  291. if advice.StartTime == sourceAdvice.StartTime {
  292. err = service.UpdateDoctorAdvice(&advice)
  293. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  294. defer redis.Close()
  295. redis.Set(key, "", time.Second)
  296. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  297. redis.Set(keyOne, "", time.Second)
  298. isChangeGroup = false
  299. } else {
  300. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  301. isChangeGroup = false
  302. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  303. defer redis.Close()
  304. redis.Set(key, "", time.Second)
  305. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  306. redis.Set(keyOne, "", time.Second)
  307. }
  308. } else if len(adviceSlice) > 1 {
  309. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  310. if infor.ID > 0 {
  311. var cha_time int64
  312. timeNowStr := time.Now().Format("2006-01-02")
  313. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  314. //今日的日期减去设置的日期
  315. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  316. if cha_time >= sourceAdvice.AdviceDate {
  317. //查询审核是否允许
  318. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  319. //申请状态不允许的情况 拒绝修改
  320. if infor.ApplicationStatus != 1 {
  321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  322. return
  323. }
  324. }
  325. }
  326. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  327. if advice.StartTime == sourceAdvice.StartTime {
  328. err = service.UpdateDoctorAdvice(&advice)
  329. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  330. defer redis.Close()
  331. redis.Set(key, "", time.Second)
  332. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  333. redis.Set(keyOne, "", time.Second)
  334. isChangeGroup = false
  335. } else {
  336. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  337. gruopNo = gruopNo + 1
  338. advice.GroupNo = gruopNo
  339. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  340. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  341. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  342. defer redis.Close()
  343. redis.Set(key, "", time.Second)
  344. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  345. redis.Set(keyOne, "", time.Second)
  346. isChangeGroup = true
  347. }
  348. }
  349. } else {
  350. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  351. if infor.ID > 0 {
  352. var cha_time int64
  353. timeNowStr := time.Now().Format("2006-01-02")
  354. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  355. //今日的日期减去设置的日期
  356. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  357. if cha_time >= advice.AdviceDate {
  358. //查询审核是否允许
  359. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  360. //申请状态不允许的情况 拒绝修改
  361. if infor.ApplicationStatus != 1 {
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  363. return
  364. }
  365. }
  366. }
  367. isChangeGroup = false
  368. err = service.UpdateDoctorAdvice(&advice)
  369. redis := service.RedisClient()
  370. defer redis.Close()
  371. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  372. redis.Set(key, "", time.Second)
  373. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  374. redis.Set(keyOne, "", time.Second)
  375. }
  376. if err != nil {
  377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  378. return
  379. }
  380. if !isChangeGroup {
  381. c.ServeSuccessJSON(map[string]interface{}{
  382. "msg": "ok",
  383. "advice": advice,
  384. "isChange": isChangeGroup, //方便前端处理数据
  385. })
  386. } else {
  387. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  388. if err != nil {
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  390. return
  391. }
  392. c.ServeSuccessJSON(map[string]interface{}{
  393. "msg": "ok",
  394. "advice": newGroupAdvice,
  395. "isChange": isChangeGroup, //方便前端处理数据
  396. })
  397. }
  398. return
  399. }
  400. func (c *PatientApiController) StopDoctorAdvice() {
  401. id, _ := c.GetInt64("id", 0)
  402. if id <= 0 {
  403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  404. return
  405. }
  406. adminUserInfo := c.GetMobileAdminUserInfo()
  407. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  408. if advice.ID == 0 {
  409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  410. return
  411. }
  412. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  413. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  414. // return
  415. //}
  416. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  417. //
  418. //if appRole.UserType == 3 {
  419. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  420. // if getPermissionErr != nil {
  421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  422. // return
  423. // } else if headNursePermission == nil {
  424. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  425. // return
  426. // }
  427. //}
  428. if advice.StopState == 1 {
  429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  430. return
  431. }
  432. dataBody := make(map[string]interface{}, 0)
  433. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  434. if err != nil {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. timeLayout := "2006-01-02"
  439. loc, _ := time.LoadLocation("Local")
  440. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  441. utils.ErrorLog("stop_time")
  442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  443. return
  444. }
  445. stopTime, _ := dataBody["stop_time"].(string)
  446. if len(stopTime) == 0 {
  447. utils.ErrorLog("len(stop_time) == 0")
  448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  449. return
  450. }
  451. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  452. if err != nil {
  453. utils.ErrorLog(err.Error())
  454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  455. return
  456. }
  457. advice.StopTime = theTime.Unix()
  458. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  459. utils.ErrorLog("stop_reason")
  460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  461. return
  462. }
  463. stopReason, _ := dataBody["stop_reason"].(string)
  464. if len(stopReason) == 0 {
  465. utils.ErrorLog("len(stop_reason) == 0")
  466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  467. return
  468. }
  469. advice.StopReason = stopReason
  470. advice.Status = 1
  471. advice.UpdatedTime = time.Now().Unix()
  472. advice.StopDoctor = adminUserInfo.AdminUser.Id
  473. advice.StopState = 1
  474. advice.StopTime = time.Now().Unix()
  475. advice.Modifier = adminUserInfo.AdminUser.Id
  476. err = service.StopDoctorAdvice(&advice)
  477. if err != nil {
  478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  479. return
  480. }
  481. c.ServeSuccessJSON(map[string]interface{}{
  482. "msg": "ok",
  483. "advice": advice,
  484. })
  485. return
  486. }
  487. func (c *PatientApiController) DeleteDoctorAdvice() {
  488. id, _ := c.GetInt64("id", 0)
  489. if id <= 0 {
  490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  491. return
  492. }
  493. adminUserInfo := c.GetMobileAdminUserInfo()
  494. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  495. if advice.ID == 0 {
  496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  497. return
  498. }
  499. //自备药
  500. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  501. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  502. //查询库存是否是自备药
  503. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  504. if selfBasedrug.IsSelfDrug == 1 {
  505. creater := adminUserInfo.AdminUser.Id
  506. //退库
  507. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  508. }
  509. }
  510. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  511. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  512. // return
  513. //}
  514. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  515. //
  516. //if appRole.UserType == 3 {
  517. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  518. // if getPermissionErr != nil {
  519. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  520. // return
  521. // } else if headNursePermission == nil {
  522. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  523. // return
  524. // }
  525. //}
  526. advice.UpdatedTime = time.Now().Unix()
  527. advice.Status = 0
  528. advice.Modifier = adminUserInfo.AdminUser.Id
  529. err := service.DeleteDoctorAdvice(&advice)
  530. if err != nil {
  531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  532. return
  533. }
  534. c.ServeSuccessJSON(map[string]interface{}{
  535. "msg": "ok",
  536. })
  537. return
  538. }
  539. func (c *PatientApiController) ExecDoctorAdvice() {
  540. execution_time := c.GetString("execution_time")
  541. origin, _ := c.GetInt64("origin", 0)
  542. groupno, _ := c.GetInt64("groupno", -1)
  543. record_date, _ := c.GetInt64("record_date")
  544. patient_id, _ := c.GetInt64("patient_id")
  545. if origin != 2 {
  546. adminUserInfo := c.GetMobileAdminUserInfo()
  547. execution_staff := adminUserInfo.AdminUser.Id
  548. var ids []string
  549. advice_ids := c.GetString("advice_id")
  550. if groupno == 0 {
  551. ids = strings.Split(advice_ids, ",")
  552. }
  553. if groupno < 0 {
  554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  555. return
  556. }
  557. if len(execution_time) <= 0 {
  558. utils.ErrorLog("execution_time")
  559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  560. return
  561. }
  562. timeLayout2 := "2006-01-02 15:04:05"
  563. loc, _ := time.LoadLocation("Local")
  564. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  565. if errs != nil {
  566. utils.ErrorLog(errs.Error())
  567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  568. return
  569. }
  570. var advice models.DoctorAdvice
  571. if groupno > 0 {
  572. advices, _ := service.FindAllDoctorAdviceByGoroupNoThree(adminUserInfo.Org.Id, groupno, patient_id, record_date)
  573. fmt.Println("advices---------------------------------------------", advices)
  574. for _, item := range advices {
  575. //自备药
  576. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  577. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  578. //查询库存是否
  579. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  580. if selfBasedrug.IsSelfDrug == 1 {
  581. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  582. var prescribing_number_total_one int64
  583. //判断单位是否相等
  584. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  585. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  586. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  587. //转化为最小单位
  588. prescribing_number_total_one = count * selfBasedrug.MinNumber
  589. }
  590. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  591. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  592. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  593. prescribing_number_total_one = count
  594. }
  595. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  596. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  597. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  598. prescribing_number_total_one = count
  599. }
  600. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  601. c.ServeSuccessJSON(map[string]interface{}{
  602. "msg": "2",
  603. "advice": advice,
  604. "ids": ids,
  605. })
  606. return
  607. }
  608. }
  609. }
  610. //恒泰中医院
  611. if item.UserOrgId == 10490 || item.UserOrgId == 10602 || item.UserOrgId == 10697 {
  612. if item.DrugId == 0 || item.DrugNameId == 0 {
  613. //从字典里面查找
  614. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  615. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  616. }
  617. }
  618. if item.ExecutionState == 2 {
  619. advice = item
  620. }
  621. //记录日志
  622. byterequest, _ := json.Marshal(item)
  623. adviceLog := models.XtDoctorAdviceLog{
  624. UserOrgId: item.UserOrgId,
  625. PatientId: item.PatientId,
  626. AdminUserId: adminUserInfo.AdminUser.Id,
  627. Module: 2,
  628. ErrLog: string(byterequest),
  629. Status: 1,
  630. Ctime: time.Now().Unix(),
  631. Mtime: 0,
  632. Source: "手机端执行医嘱",
  633. RecordDate: item.AdviceDate,
  634. }
  635. service.CreateDoctorAdviceLog(adviceLog)
  636. }
  637. advicesOne, _ := service.FindAllDoctorAdviceByGoroupNoOne(adminUserInfo.Org.Id, groupno)
  638. for _, item := range advicesOne {
  639. //自备药
  640. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  641. if selfPrescriptionOutOpen.IsOpen == 1 {
  642. db := service.XTWriteDB()
  643. tx := db.Begin()
  644. defer func() {
  645. if r := recover(); r != nil {
  646. tx.Rollback()
  647. } else {
  648. tx.Commit()
  649. }
  650. }()
  651. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  652. if selfBasedrug.IsSelfDrug == 1 {
  653. //查询是否有库存
  654. infoList, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(item.DrugId, item.PatientId, item.UserOrgId, tx)
  655. var total_count int64
  656. var prescribing_number_total int64
  657. for _, items := range infoList {
  658. if items.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  659. items.StockMaxNumber = items.StockMaxNumber * selfBasedrug.MinNumber
  660. }
  661. total_count += items.StockMaxNumber + items.StockMinNumber
  662. }
  663. if total_count == 0 {
  664. c.ServeSuccessJSON(map[string]interface{}{
  665. "msg": "2",
  666. "advice": item,
  667. "ids": ids,
  668. })
  669. return
  670. }
  671. //判断单位是否相等
  672. if selfBasedrug.MaxUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  673. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  674. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  675. //转化为最小单位
  676. prescribing_number_total = count * selfBasedrug.MinNumber
  677. }
  678. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  679. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  680. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  681. prescribing_number_total = count
  682. }
  683. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  684. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  685. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  686. prescribing_number_total = count
  687. }
  688. if prescribing_number_total > total_count {
  689. c.ServeSuccessJSON(map[string]interface{}{
  690. "msg": "3",
  691. "advice": item,
  692. })
  693. return
  694. }
  695. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  696. //出库
  697. if prescribing_number_total <= total_count {
  698. timeStr := time.Now().Format("2006-01-02")
  699. timeArr := strings.Split(timeStr, "-")
  700. total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
  701. total = total + 1
  702. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  703. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  704. number = number + total
  705. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  706. operation_time := time.Now().Unix()
  707. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  708. //创建一个出库单
  709. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  710. WarehouseOutOrderNumber: warehousing_out_order,
  711. OperationTime: operation_time,
  712. OrgId: adminUserInfo.Org.Id,
  713. Creater: creater,
  714. Ctime: time.Now().Unix(),
  715. Status: 1,
  716. WarehouseOutTime: item.AdviceDate,
  717. Type: 0,
  718. PatientId: advice.PatientId,
  719. IsCheck: 1,
  720. IsSys: 1,
  721. }
  722. //查询今日是否有出库数据
  723. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  724. if lastWarehouseOut.ID == 0 {
  725. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  726. }
  727. //查询今日是否有出库数据
  728. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  729. var warehousing_out_order_str string
  730. if lastWarehouseOut.ID == 0 {
  731. warehousing_out_order_str = warehousing_out_order
  732. } else {
  733. warehousing_out_order_str = lastWarehouseOut.WarehouseOutOrderNumber
  734. }
  735. //出库
  736. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  737. WarehouseOutId: lastWarehouseOutOne.ID,
  738. WarehouseOutOrderNumber: warehousing_out_order_str,
  739. DrugId: item.DrugId,
  740. Count: prescribing_number_total,
  741. Price: 0,
  742. TotalPrice: 0,
  743. Status: 1,
  744. Ctime: item.AdviceDate,
  745. Mtime: item.AdviceDate,
  746. Remark: "",
  747. OrgId: item.UserOrgId,
  748. Type: 0,
  749. Manufacturer: selfBasedrug.Manufacturer,
  750. Dealer: selfBasedrug.Dealer,
  751. RetailPrice: 0,
  752. RetailTotalPrice: 0,
  753. CountUnit: selfBasedrug.MinUnit,
  754. ExpiryDate: 0,
  755. ProductDate: 0,
  756. Number: "",
  757. BatchNumber: "",
  758. IsSys: 0,
  759. WarehouseInfoId: 0,
  760. AdminUserId: 0,
  761. StockCount: "",
  762. IsCheck: 1,
  763. SysRecordTime: item.AdviceDate,
  764. PatientId: item.PatientId,
  765. AdviceId: item.ID,
  766. ClassType: "",
  767. }
  768. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  769. for _, it := range warehousingOutInfo {
  770. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  771. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  772. //出库逻辑
  773. service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  774. //查询剩余库存
  775. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  776. var sum_count int64
  777. for _, its := range stockInfo {
  778. if its.MaxUnit == medical.MaxUnit {
  779. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  780. }
  781. sum_count += its.StockMaxNumber + its.StockMinNumber
  782. }
  783. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  784. }
  785. }
  786. }
  787. }
  788. }
  789. } else {
  790. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  791. for _, item := range advices {
  792. //自备药
  793. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  794. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  795. //查询库存是否
  796. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  797. if selfBasedrug.IsSelfDrug == 1 {
  798. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  799. var prescribing_number_total_one int64
  800. //判断单位是否相等
  801. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  802. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  803. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  804. //转化为最小单位
  805. prescribing_number_total_one = count * selfBasedrug.MinNumber
  806. }
  807. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  808. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  809. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  810. prescribing_number_total_one = count
  811. }
  812. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  813. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  814. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  815. prescribing_number_total_one = count
  816. }
  817. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  818. c.ServeSuccessJSON(map[string]interface{}{
  819. "msg": "2",
  820. "advice": advice,
  821. "ids": ids,
  822. })
  823. return
  824. }
  825. }
  826. }
  827. //恒泰中医院
  828. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  829. if item.DrugId == 0 || item.DrugNameId == 0 {
  830. //从字典里面查找
  831. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  832. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  833. }
  834. }
  835. if item.ExecutionState == 2 {
  836. advice = item
  837. }
  838. }
  839. advicesOne, _ := service.FindDoctorAdviceByIdsOne(adminUserInfo.Org.Id, ids)
  840. for _, item := range advicesOne {
  841. //自备药
  842. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  843. if selfPrescriptionOutOpen.IsOpen == 1 {
  844. db := service.XTWriteDB()
  845. tx := db.Begin()
  846. defer func() {
  847. if r := recover(); r != nil {
  848. tx.Rollback()
  849. } else {
  850. tx.Commit()
  851. }
  852. }()
  853. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  854. if selfBasedrug.IsSelfDrug == 1 {
  855. //查询是否有库存
  856. infoList, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(item.DrugId, item.PatientId, item.UserOrgId, tx)
  857. var total_count int64
  858. var prescribing_number_total int64
  859. for _, items := range infoList {
  860. if items.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  861. items.StockMaxNumber = items.StockMaxNumber * selfBasedrug.MinNumber
  862. }
  863. total_count += items.StockMaxNumber + items.StockMinNumber
  864. }
  865. if total_count == 0 {
  866. c.ServeSuccessJSON(map[string]interface{}{
  867. "msg": "2",
  868. "advice": item,
  869. "ids": ids,
  870. })
  871. return
  872. }
  873. //判断单位是否相等
  874. if selfBasedrug.MaxUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  875. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  876. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  877. //转化为最小单位
  878. prescribing_number_total = count * selfBasedrug.MinNumber
  879. }
  880. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  881. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  882. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  883. prescribing_number_total = count
  884. }
  885. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  886. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  887. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  888. prescribing_number_total = count
  889. }
  890. if prescribing_number_total > total_count {
  891. c.ServeSuccessJSON(map[string]interface{}{
  892. "msg": "3",
  893. "advice": item,
  894. })
  895. return
  896. }
  897. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  898. //出库
  899. if prescribing_number_total <= total_count {
  900. timeStr := time.Now().Format("2006-01-02")
  901. timeArr := strings.Split(timeStr, "-")
  902. total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
  903. total = total + 1
  904. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  905. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  906. number = number + total
  907. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  908. operation_time := time.Now().Unix()
  909. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  910. //创建一个出库单
  911. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  912. WarehouseOutOrderNumber: warehousing_out_order,
  913. OperationTime: operation_time,
  914. OrgId: adminUserInfo.Org.Id,
  915. Creater: creater,
  916. Ctime: time.Now().Unix(),
  917. Status: 1,
  918. WarehouseOutTime: item.AdviceDate,
  919. Type: 0,
  920. PatientId: advice.PatientId,
  921. IsCheck: 1,
  922. IsSys: 1,
  923. }
  924. //查询今日是否有出库数据
  925. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  926. if lastWarehouseOut.ID == 0 {
  927. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  928. }
  929. //查询今日是否有出库数据
  930. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  931. var warehousing_out_order_str string
  932. if lastWarehouseOut.ID == 0 {
  933. warehousing_out_order_str = warehousing_out_order
  934. } else {
  935. warehousing_out_order_str = lastWarehouseOut.WarehouseOutOrderNumber
  936. }
  937. //出库
  938. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  939. WarehouseOutId: lastWarehouseOutOne.ID,
  940. WarehouseOutOrderNumber: warehousing_out_order_str,
  941. DrugId: item.DrugId,
  942. Count: prescribing_number_total,
  943. Price: 0,
  944. TotalPrice: 0,
  945. Status: 1,
  946. Ctime: item.AdviceDate,
  947. Mtime: item.AdviceDate,
  948. Remark: "",
  949. OrgId: item.UserOrgId,
  950. Type: 0,
  951. Manufacturer: selfBasedrug.Manufacturer,
  952. Dealer: selfBasedrug.Dealer,
  953. RetailPrice: 0,
  954. RetailTotalPrice: 0,
  955. CountUnit: selfBasedrug.MinUnit,
  956. ExpiryDate: 0,
  957. ProductDate: 0,
  958. Number: "",
  959. BatchNumber: "",
  960. IsSys: 0,
  961. WarehouseInfoId: 0,
  962. AdminUserId: 0,
  963. StockCount: "",
  964. IsCheck: 1,
  965. SysRecordTime: item.AdviceDate,
  966. PatientId: item.PatientId,
  967. AdviceId: item.ID,
  968. ClassType: "",
  969. }
  970. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  971. for _, it := range warehousingOutInfo {
  972. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  973. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  974. //出库逻辑
  975. service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  976. //查询剩余库存
  977. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  978. var sum_count int64
  979. for _, its := range stockInfo {
  980. if its.MaxUnit == medical.MaxUnit {
  981. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  982. }
  983. sum_count += its.StockMaxNumber + its.StockMinNumber
  984. }
  985. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  986. }
  987. }
  988. }
  989. }
  990. }
  991. }
  992. if advice.ExecutionState == 1 {
  993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  994. return
  995. }
  996. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  998. return
  999. }
  1000. //针对普宁
  1001. if adminUserInfo.Org.Id != 10599 {
  1002. fmt.Println("开始时间--------------------", advice.StartTime)
  1003. fmt.Println("theTime---------------------", theTime.Unix())
  1004. if advice.StartTime > theTime.Unix() {
  1005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1006. return
  1007. }
  1008. }
  1009. advices := models.DoctorAdvice{
  1010. ExecutionStaff: execution_staff,
  1011. ExecutionTime: theTime.Unix(),
  1012. UpdatedTime: time.Now().Unix(),
  1013. }
  1014. var err error
  1015. if groupno > 0 {
  1016. // 查询信息规挡的设置天数
  1017. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1018. if infor.ID > 0 && infor.WeekDay > 0 {
  1019. var cha_time int64
  1020. timeNowStr := time.Now().Format("2006-01-02")
  1021. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1022. //今日的日期减去设置的日期
  1023. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1024. if cha_time >= record_date {
  1025. //查询审核是否允许
  1026. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1027. //申请状态不允许的情况 拒绝修改
  1028. if infor.ApplicationStatus != 1 {
  1029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1030. return
  1031. }
  1032. }
  1033. }
  1034. err = service.ExceDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id, patient_id, record_date)
  1035. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1036. redis := service.RedisClient()
  1037. //清空key 值
  1038. redis.Set(key, "", time.Second)
  1039. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1040. redis.Set(keyTwo, "", time.Second)
  1041. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1042. redis.Set(keyThree, "", time.Second)
  1043. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  1044. theTime := toTime.Format("2006-01-02")
  1045. fmt.Println("theTIME", theTime)
  1046. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1047. redis.Set(keyFour, "", time.Second)
  1048. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1049. redis.Set(keyFive, "", time.Second)
  1050. defer redis.Close()
  1051. } else {
  1052. // 查询信息规挡的设置天数
  1053. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1054. if infor.ID > 0 {
  1055. var cha_time int64
  1056. timeNowStr := time.Now().Format("2006-01-02")
  1057. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1058. //今日的日期减去设置的日期
  1059. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1060. if cha_time >= record_date {
  1061. //查询审核是否允许
  1062. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1063. //申请状态不允许的情况 拒绝修改
  1064. if infor.ApplicationStatus != 1 {
  1065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1066. return
  1067. }
  1068. }
  1069. }
  1070. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  1071. //记录日志
  1072. byterequest, _ := json.Marshal(advice)
  1073. adviceLog := models.XtDoctorAdviceLog{
  1074. UserOrgId: advice.UserOrgId,
  1075. PatientId: advice.PatientId,
  1076. AdminUserId: adminUserInfo.AdminUser.Id,
  1077. Module: 2,
  1078. ErrLog: string(byterequest),
  1079. Status: 1,
  1080. Ctime: time.Now().Unix(),
  1081. Mtime: 0,
  1082. Source: "手机端执行医嘱",
  1083. RecordDate: advices.RecordDate,
  1084. }
  1085. service.CreateDoctorAdviceLog(adviceLog)
  1086. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1087. redis := service.RedisClient()
  1088. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1089. redis.Set(keyTwo, "", time.Second)
  1090. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1091. redis.Set(keyThree, "", time.Second)
  1092. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  1093. theTime := toTime.Format("2006-01-02")
  1094. fmt.Println("theTIME", theTime)
  1095. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1096. redis.Set(keyFour, "", time.Second)
  1097. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1098. redis.Set(keySix, "", time.Second)
  1099. defer redis.Close()
  1100. //清空key 值
  1101. redis.Set(key, "", time.Second)
  1102. }
  1103. if err != nil {
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1105. return
  1106. }
  1107. advice.ExecutionStaff = execution_staff
  1108. advice.ExecutionTime = theTime.Unix()
  1109. advice.ExecutionState = 1
  1110. advice.Modifier = adminUserInfo.AdminUser.Id
  1111. //处理出库相关逻辑
  1112. //1.判断是否启用药品管理和自备药出库功能
  1113. //药品管理信息
  1114. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  1115. //自备药信息
  1116. //privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  1117. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  1118. if drugStockConfig.IsOpen == 1 {
  1119. if groupno > 0 {
  1120. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  1121. if len(advices) > 0 {
  1122. var total int64
  1123. var prescribing_number_total int64
  1124. //出库
  1125. for _, item := range advices {
  1126. if item.Way == 1 {
  1127. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1128. //查询该药品的剩余库存
  1129. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  1130. //查询改药品信息
  1131. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1132. //判断单位是否相等
  1133. if medical.MaxUnit == item.PrescribingNumberUnit {
  1134. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1135. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1136. //转化为最小单位
  1137. total = list.Count * medical.MinNumber
  1138. prescribing_number_total = count * medical.MinNumber
  1139. }
  1140. if medical.MinUnit == item.PrescribingNumberUnit {
  1141. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1142. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1143. total = list.Count*medical.MinNumber + list.StockMinNumber
  1144. prescribing_number_total = count
  1145. }
  1146. if medical.IsUse == 1 {
  1147. c.ServeSuccessJSON(map[string]interface{}{
  1148. "msg": "1",
  1149. "advice": advice,
  1150. "ids": ids,
  1151. })
  1152. return
  1153. }
  1154. if medical.IsUse != 1 {
  1155. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1156. if advice.UserOrgId != 10278 && advice.UserOrgId != 10697 && advice.UserOrgId != 10635 && advice.UserOrgId != 10724 && advice.UserOrgId != 10571 && advice.UserOrgId != 10731 {
  1157. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1158. advice.ExecutionTime = 0
  1159. advice.ExecutionState = 2
  1160. advice.ExecutionStaff = 0
  1161. }
  1162. c.ServeSuccessJSON(map[string]interface{}{
  1163. "msg": "3",
  1164. "advice": advice,
  1165. "ids": ids,
  1166. })
  1167. return
  1168. }
  1169. if prescribing_number_total > total {
  1170. if advice.UserOrgId != 10278 && advice.UserOrgId != 10697 && advice.UserOrgId != 10635 && advice.UserOrgId != 10724 && advice.UserOrgId != 10571 && advice.UserOrgId != 10731 {
  1171. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1172. advice.ExecutionTime = 0
  1173. advice.ExecutionState = 2
  1174. advice.ExecutionStaff = 0
  1175. }
  1176. c.ServeSuccessJSON(map[string]interface{}{
  1177. "msg": "2",
  1178. "advice": advice,
  1179. "ids": ids,
  1180. })
  1181. return
  1182. }
  1183. }
  1184. //查询是否出库按钮开启
  1185. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  1186. if adviceSetting.IsAdviceOpen == 1 {
  1187. //查询是否出库按钮开启
  1188. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  1189. //患者发药
  1190. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1191. if prescriptionConfig.IsOpen == 1 {
  1192. if medical.IsUse == 2 {
  1193. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1194. //查询今日是否出库
  1195. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1196. if drugOutInfo.ID == 0 {
  1197. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1198. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1199. }
  1200. }
  1201. }
  1202. if pharmacyConfig.IsOpen != 1 {
  1203. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1204. if drugOutInfo.ID == 0 {
  1205. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1206. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1207. }
  1208. }
  1209. }
  1210. //更新字典里面的库存
  1211. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1212. var sum_count int64
  1213. for _, its := range stockInfo {
  1214. if its.MaxUnit == medical.MaxUnit {
  1215. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1216. }
  1217. sum_count += its.StockMaxNumber + its.StockMinNumber
  1218. }
  1219. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1220. //剩余库存
  1221. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1222. }
  1223. }
  1224. } else {
  1225. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1226. if medical.IsUse == 2 {
  1227. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1228. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1229. if drugOutInfo.ID == 0 {
  1230. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1231. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1232. }
  1233. }
  1234. }
  1235. if pharmacyConfig.IsOpen != 1 {
  1236. drugError := models.XtDrugError{
  1237. ID: 0,
  1238. UserOrgId: item.UserOrgId,
  1239. DrugId: item.DrugId,
  1240. RecordDate: item.AdviceDate,
  1241. PatientId: item.PatientId,
  1242. Remark: "恒泰中医院出库开始",
  1243. Status: 1,
  1244. Ctime: time.Now().Unix(),
  1245. Mtime: 0,
  1246. Prescribingnumber: item.PrescribingNumber,
  1247. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1248. SumCount: 0,
  1249. }
  1250. service.CreateDrugError(drugError)
  1251. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1252. if drugOutInfo.ID == 0 {
  1253. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1254. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1255. }
  1256. }
  1257. }
  1258. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1259. var sum_count int64
  1260. for _, its := range stockInfo {
  1261. if its.MaxUnit == medical.MaxUnit {
  1262. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1263. }
  1264. sum_count += its.StockMaxNumber + its.StockMinNumber
  1265. }
  1266. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1267. //剩余库存
  1268. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1269. }
  1270. }
  1271. }
  1272. }
  1273. }
  1274. c.ServeSuccessJSON(map[string]interface{}{
  1275. "msg": "1",
  1276. "advice": advice,
  1277. "ids": ids,
  1278. })
  1279. return
  1280. } else {
  1281. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  1282. if len(advices) > 0 {
  1283. var total int64
  1284. var prescribing_number_total int64
  1285. for _, item := range advices {
  1286. if item.Way == 1 {
  1287. //查询改药品信息
  1288. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1289. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1290. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1291. //查询该药品的剩余库存
  1292. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  1293. //判断单位是否相等
  1294. if medical.MaxUnit == item.PrescribingNumberUnit {
  1295. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1296. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1297. //转化为最小单位
  1298. total = list.Count*medical.MinNumber + list.StockMinNumber
  1299. prescribing_number_total = count * medical.MinNumber
  1300. }
  1301. if medical.MinUnit == item.PrescribingNumberUnit {
  1302. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1303. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1304. total = list.Count*medical.MinNumber + list.StockMinNumber
  1305. prescribing_number_total = count
  1306. }
  1307. if medical.IsUse == 1 {
  1308. c.ServeSuccessJSON(map[string]interface{}{
  1309. "msg": "1",
  1310. "advice": advice,
  1311. "ids": ids,
  1312. })
  1313. return
  1314. }
  1315. if medical.IsUse != 1 {
  1316. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1317. if advice.UserOrgId != 10278 && advice.UserOrgId != 10697 && advice.UserOrgId != 10635 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1318. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1319. advice.ExecutionTime = 0
  1320. advice.ExecutionState = 2
  1321. advice.ExecutionStaff = 0
  1322. }
  1323. c.ServeSuccessJSON(map[string]interface{}{
  1324. "msg": "3",
  1325. "advice": advice,
  1326. "ids": ids,
  1327. })
  1328. return
  1329. }
  1330. if prescribing_number_total > total {
  1331. if advice.UserOrgId != 10278 && advice.UserOrgId != 10697 && advice.UserOrgId != 10635 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1332. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1333. advice.ExecutionTime = 0
  1334. advice.ExecutionState = 2
  1335. advice.ExecutionStaff = 0
  1336. }
  1337. c.ServeSuccessJSON(map[string]interface{}{
  1338. "msg": "2",
  1339. "advice": advice,
  1340. "ids": ids,
  1341. })
  1342. return
  1343. }
  1344. }
  1345. if medical.IsUse == 2 {
  1346. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1347. //查询今日是否出库
  1348. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1349. if drugOutInfo.ID == 0 {
  1350. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1351. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1352. }
  1353. }
  1354. }
  1355. if pharmacyConfig.IsOpen != 1 {
  1356. //查询今日是否出库
  1357. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1358. if drugOutInfo.ID == 0 {
  1359. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1360. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1361. }
  1362. }
  1363. }
  1364. //更新字典里面的库存
  1365. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1366. var sum_count int64
  1367. for _, its := range stockInfo {
  1368. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1369. if its.MaxUnit == baseDrug.MaxUnit {
  1370. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1371. }
  1372. sum_count += its.StockMaxNumber + its.StockMinNumber
  1373. }
  1374. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1375. //剩余库存
  1376. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1377. }
  1378. if medical.IsUse == 1 {
  1379. c.ServeSuccessJSON(map[string]interface{}{
  1380. "msg": "1",
  1381. "advice": advice,
  1382. "ids": ids,
  1383. })
  1384. return
  1385. }
  1386. }
  1387. }
  1388. }
  1389. c.ServeSuccessJSON(map[string]interface{}{
  1390. "msg": "1",
  1391. "advice": advice,
  1392. "ids": ids,
  1393. })
  1394. return
  1395. }
  1396. }
  1397. //if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1398. // if groupno > 0 {
  1399. // advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1400. // for _, item := range advices {
  1401. //
  1402. // if item.ExecutionState == 1 && item.Way == 2 {
  1403. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1404. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1405. //
  1406. // timeStr := time.Now().Format("2006-01-02")
  1407. // timeArr := strings.Split(timeStr, "-")
  1408. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1409. //
  1410. // total = total + 1
  1411. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1412. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1413. // number = number + total
  1414. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1415. // //插入自备药出库单
  1416. // outStock := models.XtSelfOutStock{
  1417. // DrugName: item.AdviceName,
  1418. // DrugNameId: item.DrugNameId,
  1419. // DrugSpec: item.AdviceDesc,
  1420. // OutstoreNumber: count,
  1421. // AdminUserId: adminUserInfo.AdminUser.Id,
  1422. // StorckTime: item.AdviceDate,
  1423. // UserOrgId: adminUserInfo.Org.Id,
  1424. // CreatedTime: time.Now().Unix(),
  1425. // Status: 1,
  1426. // PatientId: item.PatientId,
  1427. // ExitMode: 2,
  1428. // MedicId: item.DrugId,
  1429. // StockOutNumber: warehousing_out_order,
  1430. // }
  1431. // //查询 该患者是否已出库
  1432. // out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1433. //
  1434. // if errcode == gorm.ErrRecordNotFound {
  1435. // service.CreateOutStock(&outStock)
  1436. // } else if errcode == nil {
  1437. // err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1438. // fmt.Println("err", err)
  1439. // }
  1440. // }
  1441. // }
  1442. // } else {
  1443. //
  1444. // advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1445. // for _, item := range advices {
  1446. //
  1447. // if item.ExecutionState == 1 && item.Way == 2 {
  1448. //
  1449. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1450. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1451. //
  1452. // timeStr := time.Now().Format("2006-01-02")
  1453. // timeArr := strings.Split(timeStr, "-")
  1454. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1455. //
  1456. // total = total + 1
  1457. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1458. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1459. // number = number + total
  1460. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1461. //
  1462. // //插入自备药出库单
  1463. // outStock := models.XtSelfOutStock{
  1464. // DrugName: item.AdviceName,
  1465. // DrugNameId: item.DrugNameId,
  1466. // DrugSpec: item.AdviceDesc,
  1467. // OutstoreNumber: count,
  1468. // AdminUserId: adminUserInfo.AdminUser.Id,
  1469. // StorckTime: item.AdviceDate,
  1470. // UserOrgId: adminUserInfo.Org.Id,
  1471. // CreatedTime: time.Now().Unix(),
  1472. // Status: 1,
  1473. // PatientId: item.PatientId,
  1474. // ExitMode: 2,
  1475. // MedicId: item.DrugId,
  1476. // StockOutNumber: warehousing_out_order,
  1477. // }
  1478. //
  1479. // //查询 该患者是否已出库
  1480. // out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1481. //
  1482. // if errcode == gorm.ErrRecordNotFound {
  1483. // service.CreateOutStock(&outStock)
  1484. // } else if errcode == nil {
  1485. // err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1486. // fmt.Println("err", err)
  1487. // }
  1488. // }
  1489. // }
  1490. // c.ServeSuccessJSON(map[string]interface{}{
  1491. // "msg": "1",
  1492. // "advice": advice,
  1493. // "ids": ids,
  1494. // })
  1495. // return
  1496. // }
  1497. //}
  1498. c.ServeSuccessJSON(map[string]interface{}{
  1499. "msg": "1",
  1500. "advice": advice,
  1501. "ids": ids,
  1502. })
  1503. return
  1504. } else if origin == 2 {
  1505. // 开始主事务
  1506. db := service.XTWriteDB()
  1507. tx := db.Begin()
  1508. // 在函数结束时处理事务回滚
  1509. defer func() {
  1510. if r := recover(); r != nil {
  1511. tx.Rollback()
  1512. }
  1513. }()
  1514. adminInfo := c.GetMobileAdminUserInfo()
  1515. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1516. var ids []string
  1517. advice_ids := c.GetString("advice_id")
  1518. ids = strings.Split(advice_ids, ",")
  1519. if len(execution_time) <= 0 {
  1520. utils.ErrorLog("execution_time")
  1521. tx.Rollback()
  1522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1523. return
  1524. }
  1525. timeLayout2 := "2006-01-02 15:04:05"
  1526. loc, _ := time.LoadLocation("Local")
  1527. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1528. if errs != nil {
  1529. utils.ErrorLog(errs.Error())
  1530. tx.Rollback()
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1535. var err error
  1536. for _, item := range advices {
  1537. if item.ExecutionState == 1 {
  1538. tx.Rollback()
  1539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1540. return
  1541. }
  1542. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1543. tx.Rollback()
  1544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1545. return
  1546. }
  1547. if item.StartTime > theTime.Unix() {
  1548. tx.Rollback()
  1549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1550. return
  1551. }
  1552. item.ExecutionState = 1
  1553. item.ExecutionStaff = adminInfo.AdminUser.Id
  1554. item.ExecutionTime = theTime.Unix()
  1555. item.IsMobile = 1
  1556. // 查询信息规挡的设置天数
  1557. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1558. if infor.ID > 0 {
  1559. var cha_time int64
  1560. timeNowStr := time.Now().Format("2006-01-02")
  1561. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1562. //今日的日期减去设置的日期
  1563. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1564. if cha_time >= item.AdviceDate {
  1565. //查询审核是否允许
  1566. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
  1567. //申请状态不允许的情况 拒绝修改
  1568. if infor.ApplicationStatus != 1 {
  1569. tx.Rollback()
  1570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1571. return
  1572. }
  1573. }
  1574. }
  1575. service.SaveHisDoctorAdviceOne(item, tx)
  1576. //记录日志
  1577. byterequest, _ := json.Marshal(item)
  1578. adviceLog := models.XtDoctorAdviceLog{
  1579. UserOrgId: item.UserOrgId,
  1580. PatientId: item.PatientId,
  1581. AdminUserId: item.ExecutionStaff,
  1582. Module: 2,
  1583. ErrLog: string(byterequest),
  1584. Status: 1,
  1585. Ctime: time.Now().Unix(),
  1586. Mtime: 0,
  1587. Source: "手机端执行his医嘱",
  1588. RecordDate: item.AdviceDate,
  1589. }
  1590. service.CreateDoctorAdviceLog(adviceLog)
  1591. if err == nil {
  1592. drugError := models.XtDrugError{
  1593. UserOrgId: adminInfo.Org.Id,
  1594. DrugId: item.DrugId,
  1595. RecordDate: item.AdviceDate,
  1596. PatientId: item.PatientId,
  1597. Remark: "执行成功",
  1598. Status: 1,
  1599. Ctime: time.Now().Unix(),
  1600. Mtime: 0,
  1601. SumCount: 0,
  1602. Prescribingnumber: item.PrescribingNumber,
  1603. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1604. }
  1605. service.CreateDrugError(drugError)
  1606. }
  1607. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1608. redis := service.RedisClient()
  1609. //清空key 值
  1610. redis.Set(key, "", time.Second)
  1611. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1612. redis.Set(keyTwo, "", time.Second)
  1613. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1614. redis.Set(keyThree, "", time.Second)
  1615. recordDate := theTime.Format("2006-01-02")
  1616. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1617. redis.Set(keyFour, "", time.Second)
  1618. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1619. redis.Set(keyFive, "", time.Second)
  1620. defer redis.Close()
  1621. }
  1622. //药品管理信息
  1623. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1624. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1625. if drugStockConfig.IsOpen == 1 {
  1626. for _, item := range advices {
  1627. //查询改药品信息
  1628. medical, _ := service.GetBaseDrugMedicalOne(item.DrugId, tx)
  1629. //判断单位是否合格
  1630. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1631. //查询该药品是否有出库记录
  1632. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate, tx)
  1633. if len(flowMap) == 0 {
  1634. errs := service.UpdateHisAdviceByIdOne(item.ID, tx)
  1635. if errs != nil {
  1636. drugError := models.XtDrugError{
  1637. UserOrgId: adminInfo.Org.Id,
  1638. DrugId: item.DrugId,
  1639. RecordDate: item.AdviceDate,
  1640. PatientId: item.PatientId,
  1641. Remark: "单位不统一,执行失败",
  1642. Status: 1,
  1643. Ctime: time.Now().Unix(),
  1644. Mtime: 0,
  1645. SumCount: 0,
  1646. Prescribingnumber: item.PrescribingNumber,
  1647. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1648. }
  1649. service.CreateDrugError(drugError)
  1650. }
  1651. }
  1652. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1653. tx.Rollback()
  1654. c.ServeSuccessJSON(map[string]interface{}{
  1655. "msg": "7",
  1656. "advice": advice,
  1657. "ids": ids,
  1658. })
  1659. return
  1660. }
  1661. //查询这个患者这个患者这个药已经出库的所有数量
  1662. advicelist, _ := service.GetAllHisDoctorAdviceByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1663. drugoutlist, _ := service.GetAllDrugFlowByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1664. var total_count int64
  1665. var drug_count int64
  1666. for _, it := range advicelist {
  1667. if it.PrescribingNumberUnit == medical.MaxUnit {
  1668. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1669. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1670. total_count += prenumber * medical.MinNumber
  1671. }
  1672. if it.PrescribingNumberUnit == medical.MinUnit {
  1673. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1674. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1675. total_count += prenumber
  1676. }
  1677. }
  1678. for _, its := range drugoutlist {
  1679. if its.CountUnit == medical.MaxUnit {
  1680. drug_count += its.Count * medical.MinNumber
  1681. }
  1682. if its.CountUnit == medical.MinUnit {
  1683. drug_count += its.Count
  1684. }
  1685. }
  1686. if total_count == drug_count {
  1687. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1688. tx.Commit()
  1689. c.ServeSuccessJSON(map[string]interface{}{
  1690. "msg": "1",
  1691. "advice": advice,
  1692. "ids": ids,
  1693. })
  1694. return
  1695. }
  1696. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1697. var total int64
  1698. var prescribing_number_total int64
  1699. //保存处方出库
  1700. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1701. if config.IsOpen != 1 {
  1702. //查询该药品是否有库存
  1703. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1704. list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
  1705. //判断单位是否相等
  1706. if medical.MaxUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1707. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1708. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1709. //转化为最小单位
  1710. total = list.Count*medical.MinNumber + list.StockMinNumber
  1711. prescribing_number_total = count * medical.MinNumber
  1712. }
  1713. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1714. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1715. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1716. total = list.Count*medical.MinNumber + list.StockMinNumber
  1717. prescribing_number_total = count
  1718. }
  1719. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit == medical.MinUnit {
  1720. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1721. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1722. total = list.Count*medical.MinNumber + list.StockMinNumber
  1723. prescribing_number_total = count
  1724. }
  1725. if medical.IsUse == 1 {
  1726. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1727. drugError := models.XtDrugError{
  1728. UserOrgId: adminInfo.Org.Id,
  1729. DrugId: item.DrugId,
  1730. RecordDate: item.AdviceDate,
  1731. PatientId: item.PatientId,
  1732. Remark: "零用药品库存不足",
  1733. Status: 1,
  1734. Ctime: time.Now().Unix(),
  1735. Mtime: 0,
  1736. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1737. Prescribingnumber: advice.PrescribingNumber,
  1738. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1739. }
  1740. service.CreateDrugError(drugError)
  1741. tx.Rollback()
  1742. c.ServeSuccessJSON(map[string]interface{}{
  1743. "msg": "1",
  1744. "advice": advice,
  1745. "ids": ids,
  1746. })
  1747. return
  1748. }
  1749. }
  1750. if medical.IsUse != 1 {
  1751. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1752. drugError := models.XtDrugError{
  1753. UserOrgId: adminInfo.Org.Id,
  1754. DrugId: item.DrugId,
  1755. RecordDate: item.AdviceDate,
  1756. PatientId: item.PatientId,
  1757. Remark: "药品库存不足",
  1758. Status: 1,
  1759. Ctime: time.Now().Unix(),
  1760. Mtime: 0,
  1761. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1762. Prescribingnumber: advice.PrescribingNumber,
  1763. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1764. }
  1765. service.CreateDrugError(drugError)
  1766. tx.Rollback()
  1767. c.ServeSuccessJSON(map[string]interface{}{
  1768. "msg": "3",
  1769. "advice": advice,
  1770. "ids": ids,
  1771. })
  1772. return
  1773. }
  1774. if prescribing_number_total > total {
  1775. drugError := models.XtDrugError{
  1776. UserOrgId: adminInfo.Org.Id,
  1777. DrugId: item.DrugId,
  1778. RecordDate: item.AdviceDate,
  1779. PatientId: item.PatientId,
  1780. Remark: "出库数量大于库存",
  1781. Status: 1,
  1782. Ctime: time.Now().Unix(),
  1783. Mtime: 0,
  1784. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1785. Prescribingnumber: advice.PrescribingNumber,
  1786. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1787. }
  1788. service.CreateDrugError(drugError)
  1789. tx.Rollback()
  1790. c.ServeSuccessJSON(map[string]interface{}{
  1791. "msg": "2",
  1792. "advice": advice,
  1793. "ids": ids,
  1794. })
  1795. return
  1796. }
  1797. }
  1798. if prescribing_number_total <= total {
  1799. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1800. //判断药品是否零用
  1801. if medical.IsUse == 2 {
  1802. if config.IsOpen != 1 {
  1803. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1804. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1805. //查询该药品是否有出库记录
  1806. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1807. if len(flowMap) == 0 {
  1808. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1809. if errs != nil {
  1810. drugError := models.XtDrugError{
  1811. UserOrgId: adminInfo.Org.Id,
  1812. DrugId: item.DrugId,
  1813. RecordDate: item.AdviceDate,
  1814. PatientId: item.PatientId,
  1815. Remark: "出库记录为空,更新执行人失败",
  1816. Status: 1,
  1817. Ctime: time.Now().Unix(),
  1818. Mtime: 0,
  1819. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1820. Prescribingnumber: advice.PrescribingNumber,
  1821. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1822. }
  1823. service.CreateDrugError(drugError)
  1824. }
  1825. tx.Rollback()
  1826. c.ServeSuccessJSON(map[string]interface{}{
  1827. "msg": "6",
  1828. "advice": advice,
  1829. "ids": ids,
  1830. })
  1831. return
  1832. }
  1833. }
  1834. }
  1835. if pharmacyConfig.IsOpen != 1 {
  1836. //查询已经出库数量
  1837. outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  1838. var out_count int64
  1839. if len(outListExport) > 0 {
  1840. for _, item := range outListExport {
  1841. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1842. out_count = item.Count * medical.MinNumber
  1843. }
  1844. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1845. out_count = item.Count
  1846. }
  1847. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1848. out_count = item.Count * medical.MinNumber
  1849. }
  1850. }
  1851. }
  1852. newadviceInfo := &models.HisDoctorAdviceInfo{
  1853. ID: advice.ID,
  1854. UserOrgId: advice.UserOrgId,
  1855. PatientId: advice.PatientId,
  1856. HisPatientId: advice.HisPatientId,
  1857. AdviceType: advice.AdviceType,
  1858. AdviceDate: advice.AdviceDate,
  1859. StartTime: advice.StartTime,
  1860. AdviceName: advice.AdviceName,
  1861. AdviceDesc: advice.AdviceDesc,
  1862. ReminderDate: advice.ReminderDate,
  1863. SingleDose: advice.SingleDose,
  1864. SingleDoseUnit: advice.SingleDoseUnit,
  1865. PrescribingNumber: advice.PrescribingNumber,
  1866. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1867. DeliveryWay: advice.DeliveryWay,
  1868. ExecutionFrequency: advice.ExecutionFrequency,
  1869. AdviceDoctor: advice.AdviceDoctor,
  1870. Status: advice.Status,
  1871. CreatedTime: advice.CreatedTime,
  1872. UpdatedTime: advice.UpdatedTime,
  1873. AdviceAffirm: advice.AdviceAffirm,
  1874. Remark: advice.Remark,
  1875. StopTime: advice.StopTime,
  1876. StopReason: advice.StopReason,
  1877. StopDoctor: advice.StopDoctor,
  1878. StopState: advice.StopState,
  1879. ParentId: advice.ParentId,
  1880. ExecutionTime: advice.ExecutionTime,
  1881. ExecutionStaff: advice.ExecutionStaff,
  1882. ExecutionState: advice.ExecutionState,
  1883. Checker: advice.Checker,
  1884. RecordDate: advice.RecordDate,
  1885. DialysisOrderId: advice.DialysisOrderId,
  1886. CheckTime: advice.CheckTime,
  1887. CheckState: advice.CheckState,
  1888. DrugSpec: advice.DrugSpec,
  1889. DrugSpecUnit: advice.DrugSpecUnit,
  1890. Groupno: advice.Groupno,
  1891. RemindType: advice.RemindType,
  1892. FrequencyType: advice.FrequencyType,
  1893. DayCount: advice.DayCount,
  1894. WeekDay: advice.WeekDay,
  1895. TemplateId: advice.TemplateId,
  1896. Modifier: advice.Modifier,
  1897. DrugId: advice.DrugId,
  1898. Price: advice.Price,
  1899. PrescriptionId: advice.PrescriptionId,
  1900. MedListCodg: advice.MedListCodg,
  1901. FeedetlSn: advice.FeedetlSn,
  1902. Day: advice.DayCount,
  1903. ChildDoctorAdvice: nil,
  1904. Drug: models.Drug{},
  1905. Diagnosis: advice.Diagnosis,
  1906. Way: advice.Way,
  1907. HospApprFlag: advice.HospApprFlag,
  1908. LmtUsedFlag: advice.LmtUsedFlag,
  1909. HisOrderInfo: models.HisOrderInfo{},
  1910. IsMedicine: advice.IsMedicine,
  1911. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  1912. Child: nil,
  1913. IsSettle: advice.IsSettle,
  1914. IsMobile: advice.IsMobile,
  1915. IsSelfDrug: advice.IsSelfDrug,
  1916. DrugWayCount: advice.DrugWayCount,
  1917. }
  1918. //如果当前医嘱数量大于历史出库数据则需要出库
  1919. if prescribing_number_total > out_count {
  1920. //按最小单位出库
  1921. var cha_count = prescribing_number_total - out_count
  1922. newadviceInfo.PrescribingNumber = float64(cha_count)
  1923. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  1924. if advice.UserOrgId != 10644 {
  1925. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1926. }
  1927. }
  1928. //如果当前医嘱数量小于历史出库数据则需要退库
  1929. if prescribing_number_total < out_count {
  1930. var cha_count = out_count - prescribing_number_total
  1931. drug, _ := service.FindBaseDrugLibRecordSeven(advice.UserOrgId, advice.DrugId)
  1932. service.NewHisDrugCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1933. service.NewHisDrugAutoCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1934. }
  1935. if prescribing_number_total == out_count {
  1936. if out_count == 0 {
  1937. if advice.UserOrgId != 10644 {
  1938. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1939. }
  1940. }
  1941. }
  1942. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1943. //查询该药品是否有出库记录
  1944. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1945. if len(flowMap) == 0 {
  1946. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1947. if errs != nil {
  1948. drugError := models.XtDrugError{
  1949. UserOrgId: adminInfo.Org.Id,
  1950. DrugId: item.DrugId,
  1951. RecordDate: item.AdviceDate,
  1952. PatientId: item.PatientId,
  1953. Remark: "出库记录为空,更新执行人失败",
  1954. Status: 1,
  1955. Ctime: time.Now().Unix(),
  1956. Mtime: 0,
  1957. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1958. Prescribingnumber: advice.PrescribingNumber,
  1959. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1960. }
  1961. service.CreateDrugError(drugError)
  1962. }
  1963. tx.Rollback()
  1964. c.ServeSuccessJSON(map[string]interface{}{
  1965. "msg": "6",
  1966. "advice": advice,
  1967. "ids": ids,
  1968. })
  1969. return
  1970. }
  1971. }
  1972. }
  1973. //更新字典里面的库存
  1974. stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  1975. var sum_count int64
  1976. for _, its := range stockInfo {
  1977. if its.MaxUnit == medical.MaxUnit {
  1978. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1979. }
  1980. sum_count += its.StockMaxNumber + its.StockMinNumber
  1981. }
  1982. service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  1983. //剩余库存
  1984. service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count, tx)
  1985. }
  1986. }
  1987. }
  1988. }
  1989. //自备药
  1990. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminInfo.Org.Id)
  1991. if selfPrescriptionOutOpen.IsOpen == 1 {
  1992. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  1993. if selfBasedrug.IsSelfDrug == 1 {
  1994. //查询是否有库存
  1995. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  1996. if len(info) > 0 {
  1997. var total_count int64
  1998. var prescribing_number_total int64
  1999. for _, item := range info {
  2000. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2001. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  2002. }
  2003. total_count += item.StockMaxNumber + item.StockMinNumber
  2004. }
  2005. //判断单位是否相等
  2006. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2007. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2008. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2009. //转化为最小单位
  2010. prescribing_number_total = count * selfBasedrug.MinNumber
  2011. }
  2012. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2013. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2014. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2015. prescribing_number_total = count
  2016. }
  2017. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  2018. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2019. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2020. prescribing_number_total = count
  2021. }
  2022. if prescribing_number_total > total_count {
  2023. tx.Rollback()
  2024. c.ServeSuccessJSON(map[string]interface{}{
  2025. "msg": "3",
  2026. "advice": advice,
  2027. })
  2028. return
  2029. }
  2030. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  2031. //出库
  2032. if prescribing_number_total <= total_count {
  2033. timeStr := time.Now().Format("2006-01-02")
  2034. timeArr := strings.Split(timeStr, "-")
  2035. total, _ := service.FindAllSelfDrugWarehouseOut(adminInfo.Org.Id, tx)
  2036. total = total + 1
  2037. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2038. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2039. number = number + total
  2040. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  2041. operation_time := time.Now().Unix()
  2042. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  2043. //创建一个出库单
  2044. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  2045. WarehouseOutOrderNumber: warehousing_out_order,
  2046. OperationTime: operation_time,
  2047. OrgId: adminInfo.Org.Id,
  2048. Creater: creater,
  2049. Ctime: time.Now().Unix(),
  2050. Status: 1,
  2051. WarehouseOutTime: advice.AdviceDate,
  2052. Type: 0,
  2053. PatientId: advice.PatientId,
  2054. IsCheck: 1,
  2055. IsSys: 1,
  2056. }
  2057. //查询今日是否有出库数据
  2058. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminInfo.Org.Id, advice.AdviceDate, tx, 1)
  2059. if lastWarehouseOut.ID == 0 {
  2060. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  2061. }
  2062. //查询今日是否有出库数据
  2063. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminInfo.Org.Id, advice.AdviceDate, tx, 1)
  2064. //出库
  2065. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  2066. WarehouseOutId: lastWarehouseOutOne.ID,
  2067. WarehouseOutOrderNumber: warehousing_out_order,
  2068. DrugId: advice.DrugId,
  2069. Count: prescribing_number_total,
  2070. Price: 0,
  2071. TotalPrice: 0,
  2072. Status: 1,
  2073. Ctime: advice.AdviceDate,
  2074. Mtime: advice.AdviceDate,
  2075. Remark: "",
  2076. OrgId: advice.UserOrgId,
  2077. Type: 0,
  2078. Manufacturer: selfBasedrug.Manufacturer,
  2079. Dealer: selfBasedrug.Dealer,
  2080. RetailPrice: 0,
  2081. RetailTotalPrice: 0,
  2082. CountUnit: selfBasedrug.MinUnit,
  2083. ExpiryDate: 0,
  2084. ProductDate: 0,
  2085. Number: "",
  2086. BatchNumber: "",
  2087. IsSys: 0,
  2088. WarehouseInfoId: 0,
  2089. AdminUserId: 0,
  2090. StockCount: "",
  2091. IsCheck: 1,
  2092. SysRecordTime: advice.AdviceDate,
  2093. PatientId: advice.PatientId,
  2094. AdviceId: advice.ID,
  2095. ClassType: "",
  2096. }
  2097. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  2098. for _, it := range warehousingOutInfo {
  2099. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  2100. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  2101. //出库逻辑
  2102. service.AutoSelfDrugDeliverInfoFourtyTwo(adminInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  2103. //查询剩余库存
  2104. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  2105. var sum_count int64
  2106. for _, its := range stockInfo {
  2107. if its.MaxUnit == medical.MaxUnit {
  2108. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2109. }
  2110. sum_count += its.StockMaxNumber + its.StockMinNumber
  2111. }
  2112. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  2113. }
  2114. }
  2115. } else {
  2116. tx.Rollback()
  2117. c.ServeSuccessJSON(map[string]interface{}{
  2118. "msg": "3",
  2119. "advice": advice,
  2120. })
  2121. return
  2122. }
  2123. }
  2124. }
  2125. //针对异常未出库问题的脚本
  2126. //if adminInfo.Org.Id == 10265 {
  2127. //
  2128. // newadviceInfo := &models.HisDoctorAdviceInfo{
  2129. // ID: advice.ID,
  2130. // UserOrgId: advice.UserOrgId,
  2131. // PatientId: advice.PatientId,
  2132. // HisPatientId: advice.HisPatientId,
  2133. // AdviceType: advice.AdviceType,
  2134. // AdviceDate: advice.AdviceDate,
  2135. // StartTime: advice.StartTime,
  2136. // AdviceName: advice.AdviceName,
  2137. // AdviceDesc: advice.AdviceDesc,
  2138. // ReminderDate: advice.ReminderDate,
  2139. // SingleDose: advice.SingleDose,
  2140. // SingleDoseUnit: advice.SingleDoseUnit,
  2141. // PrescribingNumber: advice.PrescribingNumber,
  2142. // PrescribingNumberUnit: advice.PrescribingNumberUnit,
  2143. // DeliveryWay: advice.DeliveryWay,
  2144. // ExecutionFrequency: advice.ExecutionFrequency,
  2145. // AdviceDoctor: advice.AdviceDoctor,
  2146. // Status: advice.Status,
  2147. // CreatedTime: advice.CreatedTime,
  2148. // UpdatedTime: advice.UpdatedTime,
  2149. // AdviceAffirm: advice.AdviceAffirm,
  2150. // Remark: advice.Remark,
  2151. // StopTime: advice.StopTime,
  2152. // StopReason: advice.StopReason,
  2153. // StopDoctor: advice.StopDoctor,
  2154. // StopState: advice.StopState,
  2155. // ParentId: advice.ParentId,
  2156. // ExecutionTime: advice.ExecutionTime,
  2157. // ExecutionStaff: advice.ExecutionStaff,
  2158. // ExecutionState: advice.ExecutionState,
  2159. // Checker: advice.Checker,
  2160. // RecordDate: advice.RecordDate,
  2161. // DialysisOrderId: advice.DialysisOrderId,
  2162. // CheckTime: advice.CheckTime,
  2163. // CheckState: advice.CheckState,
  2164. // DrugSpec: advice.DrugSpec,
  2165. // DrugSpecUnit: advice.DrugSpecUnit,
  2166. // Groupno: advice.Groupno,
  2167. // RemindType: advice.RemindType,
  2168. // FrequencyType: advice.FrequencyType,
  2169. // DayCount: advice.DayCount,
  2170. // WeekDay: advice.WeekDay,
  2171. // TemplateId: advice.TemplateId,
  2172. // Modifier: advice.Modifier,
  2173. // DrugId: advice.DrugId,
  2174. // Price: advice.Price,
  2175. // PrescriptionId: advice.PrescriptionId,
  2176. // MedListCodg: advice.MedListCodg,
  2177. // FeedetlSn: advice.FeedetlSn,
  2178. // Day: advice.DayCount,
  2179. // ChildDoctorAdvice: nil,
  2180. // Drug: models.Drug{},
  2181. // Diagnosis: advice.Diagnosis,
  2182. // Way: advice.Way,
  2183. // HospApprFlag: advice.HospApprFlag,
  2184. // LmtUsedFlag: advice.LmtUsedFlag,
  2185. // HisOrderInfo: models.HisOrderInfo{},
  2186. // IsMedicine: advice.IsMedicine,
  2187. // ExecutionFrequencyId: advice.ExecutionFrequencyId,
  2188. // Child: nil,
  2189. // IsSettle: advice.IsSettle,
  2190. // IsMobile: advice.IsMobile,
  2191. // IsSelfDrug: advice.IsSelfDrug,
  2192. // DrugWayCount: advice.DrugWayCount,
  2193. // }
  2194. // outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  2195. // fmt.Println(outListExport)
  2196. // //var out_count int64
  2197. // //if len(outListExport) > 0 {
  2198. // // for _, item := range outListExport {
  2199. // // if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2200. // // out_count = item.Count * medical.MinNumber
  2201. // // }
  2202. // // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2203. // // out_count = item.Count
  2204. // // }
  2205. // // if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2206. // // out_count = item.Count * medical.MinNumber
  2207. // // }
  2208. // //
  2209. // // }
  2210. // //}
  2211. // //按最小单位出库
  2212. // //var cha_count = total_count - out_count
  2213. //
  2214. // var cha_count = 40
  2215. //
  2216. // newadviceInfo.PrescribingNumber = float64(cha_count)
  2217. // newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  2218. // service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  2219. //
  2220. // //查询剩余库存
  2221. // stockInfo, _ := service.GetSelfDrugAllStockInfo(newadviceInfo.PatientId, newadviceInfo.UserOrgId, newadviceInfo.DrugId, tx)
  2222. // var sum_count int64
  2223. // for _, its := range stockInfo {
  2224. // if its.MaxUnit == medical.MaxUnit {
  2225. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2226. // }
  2227. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2228. // }
  2229. // service.UpdateSelfDrugStockCount(newadviceInfo.DrugId, newadviceInfo.UserOrgId, newadviceInfo.PatientId, sum_count, tx)
  2230. //}
  2231. }
  2232. }
  2233. tx.Commit()
  2234. for _, item := range advices {
  2235. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  2236. c.ServeSuccessJSON(map[string]interface{}{
  2237. "msg": "1",
  2238. "advice": advice,
  2239. "ids": ids,
  2240. })
  2241. }
  2242. }
  2243. }
  2244. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  2245. execution_time := c.GetString("execution_time")
  2246. fmt.Println("execution_time", execution_time)
  2247. groupno, _ := c.GetInt64("groupno", -1)
  2248. patient_id, _ := c.GetInt64("patient_id")
  2249. advice_date, _ := c.GetInt64("advice_date")
  2250. record_date, _ := c.GetInt64("record_date")
  2251. var ids []string
  2252. if groupno == 0 {
  2253. advice_ids := c.GetString("advice_id")
  2254. ids = strings.Split(advice_ids, ",")
  2255. }
  2256. if groupno < 0 {
  2257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2258. return
  2259. }
  2260. if len(execution_time) <= 0 {
  2261. utils.ErrorLog("execution_time")
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2263. return
  2264. }
  2265. timeLayout2 := "2006-01-02 15:04:05"
  2266. loc, _ := time.LoadLocation("Local")
  2267. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2268. if errs != nil {
  2269. utils.ErrorLog(errs.Error())
  2270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2271. return
  2272. }
  2273. adminUserInfo := c.GetMobileAdminUserInfo()
  2274. var advice models.DoctorAdvice
  2275. if groupno > 0 {
  2276. advices, _ := service.FindAllDoctorAdviceByGoroupNoThree(adminUserInfo.Org.Id, groupno, patient_id, record_date)
  2277. for _, item := range advices {
  2278. if item.ExecutionState == 1 {
  2279. advice = item
  2280. }
  2281. }
  2282. } else {
  2283. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2284. for _, item := range advices {
  2285. if item.ExecutionState == 1 {
  2286. advice = item
  2287. }
  2288. }
  2289. }
  2290. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  2291. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2292. // if getPermissionErr != nil {
  2293. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2294. // return
  2295. // } else if headNursePermission == nil {
  2296. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2297. // return
  2298. // }
  2299. //}
  2300. if advice.StartTime > theTime.Unix() {
  2301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2302. return
  2303. }
  2304. advices := models.DoctorAdvice{
  2305. ExecutionTime: theTime.Unix(),
  2306. UpdatedTime: time.Now().Unix(),
  2307. }
  2308. var err error
  2309. if groupno > 0 {
  2310. // 查询信息规挡的设置天数
  2311. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2312. if infor.ID > 0 {
  2313. var cha_time int64
  2314. timeNowStr := time.Now().Format("2006-01-02")
  2315. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2316. //今日的日期减去设置的日期
  2317. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2318. if cha_time >= advices.AdviceDate {
  2319. //查询审核是否允许
  2320. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2321. //申请状态不允许的情况 拒绝修改
  2322. if infor.ApplicationStatus != 1 {
  2323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. err = service.ModifyExceDoctorAdviceByGroupNoTwo(&advices, groupno, adminUserInfo.Org.Id, patient_id, record_date)
  2329. //记录日志
  2330. byterequest, _ := json.Marshal(advices)
  2331. adviceLog := models.XtDoctorAdviceLog{
  2332. UserOrgId: adminUserInfo.Org.Id,
  2333. PatientId: advices.PatientId,
  2334. AdminUserId: adminUserInfo.AdminUser.Id,
  2335. Module: 1,
  2336. ErrLog: string(byterequest),
  2337. Status: 1,
  2338. Ctime: time.Now().Unix(),
  2339. Mtime: 0,
  2340. Source: "手机端编辑医嘱",
  2341. RecordDate: advices.AdviceDate,
  2342. }
  2343. service.CreateDoctorAdviceLog(adviceLog)
  2344. redis := service.RedisClient()
  2345. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2346. redis.Set(key, "", time.Second)
  2347. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2348. redis.Set(keyOne, "", time.Second)
  2349. defer redis.Close()
  2350. } else {
  2351. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2352. if infor.ID > 0 {
  2353. var cha_time int64
  2354. timeNowStr := time.Now().Format("2006-01-02")
  2355. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2356. //今日的日期减去设置的日期
  2357. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2358. if cha_time >= advices.AdviceDate {
  2359. //查询审核是否允许
  2360. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2361. //申请状态不允许的情况 拒绝修改
  2362. if infor.ApplicationStatus != 1 {
  2363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2364. return
  2365. }
  2366. }
  2367. }
  2368. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  2369. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  2370. //记录日志
  2371. byterequest, _ := json.Marshal(advices)
  2372. adviceLog := models.XtDoctorAdviceLog{
  2373. UserOrgId: adminUserInfo.Org.Id,
  2374. PatientId: advices.PatientId,
  2375. AdminUserId: adminUserInfo.AdminUser.Id,
  2376. Module: 1,
  2377. ErrLog: string(byterequest),
  2378. Status: 1,
  2379. Ctime: time.Now().Unix(),
  2380. Mtime: 0,
  2381. Source: "手机端编辑执行医嘱",
  2382. RecordDate: advices.AdviceDate,
  2383. }
  2384. service.CreateDoctorAdviceLog(adviceLog)
  2385. redis := service.RedisClient()
  2386. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2387. redis.Set(key, "", time.Second)
  2388. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  2389. redis.Set(keyOne, "", time.Second)
  2390. defer redis.Close()
  2391. }
  2392. //判断是否开启his
  2393. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  2394. //如果开启去修改执行时间
  2395. if config.IsOpen == 1 {
  2396. advicesinfo := models.HisDoctorAdviceInfo{
  2397. ExecutionTime: theTime.Unix(),
  2398. UpdatedTime: time.Now().Unix(),
  2399. }
  2400. var advicehis models.HisDoctorAdviceInfo
  2401. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  2402. //记录日志
  2403. byterequest, _ := json.Marshal(advicesinfo)
  2404. adviceLog := models.XtDoctorAdviceLog{
  2405. UserOrgId: adminUserInfo.Org.Id,
  2406. PatientId: advices.PatientId,
  2407. AdminUserId: adminUserInfo.AdminUser.Id,
  2408. Module: 1,
  2409. ErrLog: string(byterequest),
  2410. Status: 1,
  2411. Ctime: time.Now().Unix(),
  2412. Mtime: 0,
  2413. Source: "手机端his编辑医嘱",
  2414. RecordDate: advices.AdviceDate,
  2415. }
  2416. service.CreateDoctorAdviceLog(adviceLog)
  2417. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  2418. for _, item := range his_advices {
  2419. if item.ExecutionState == 1 {
  2420. advicehis = item
  2421. }
  2422. }
  2423. redis := service.RedisClient()
  2424. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  2425. redis.Set(keyThree, "", time.Second)
  2426. recordDate := theTime.Format("2006-01-02")
  2427. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2428. redis.Set(keyFour, "", time.Second)
  2429. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  2430. redis.Set(keyFive, "", time.Second)
  2431. defer redis.Close()
  2432. project := models.HisPrescriptionProject{
  2433. ExecutionTime: theTime.Unix(),
  2434. Mtime: time.Now().Unix(),
  2435. }
  2436. service.ModifyHisPrescriptionProject(&project, ids)
  2437. //记录日志
  2438. projectquerst, _ := json.Marshal(project)
  2439. projectLog := models.XtDoctorAdviceLog{
  2440. UserOrgId: adminUserInfo.Org.Id,
  2441. PatientId: advices.PatientId,
  2442. AdminUserId: adminUserInfo.AdminUser.Id,
  2443. Module: 1,
  2444. ErrLog: string(projectquerst),
  2445. Status: 1,
  2446. Ctime: time.Now().Unix(),
  2447. Mtime: 0,
  2448. Source: "手机端his编辑项目医嘱",
  2449. RecordDate: advices.AdviceDate,
  2450. }
  2451. service.CreateDoctorAdviceLog(projectLog)
  2452. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  2453. redis.Set(keyEnd, "", time.Second)
  2454. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2455. redis.Set(keyFours, "", time.Second)
  2456. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  2457. redis.Set(keyFives, "", time.Second)
  2458. defer redis.Close()
  2459. }
  2460. if err != nil {
  2461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2462. return
  2463. }
  2464. advice.ExecutionTime = theTime.Unix()
  2465. c.ServeSuccessJSON(map[string]interface{}{
  2466. "msg": "ok",
  2467. "advice": advice,
  2468. "ids": ids,
  2469. })
  2470. return
  2471. }
  2472. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  2473. origin, _ := c.GetInt64("origin", 0)
  2474. record_date, _ := c.GetInt64("record_date")
  2475. patient_id, _ := c.GetInt64("patient_id")
  2476. check_time := c.GetString("check_time")
  2477. if len(check_time) <= 0 {
  2478. utils.ErrorLog("check_time")
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2480. return
  2481. }
  2482. timeLayout2 := "2006-01-02 15:04:05"
  2483. loc, _ := time.LoadLocation("Local")
  2484. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  2485. fmt.Println("theTimewowowow", theTime)
  2486. if errs != nil {
  2487. utils.ErrorLog(errs.Error())
  2488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2489. return
  2490. }
  2491. if origin != 2 {
  2492. groupno, _ := c.GetInt64("groupno", -1)
  2493. var ids []string
  2494. if groupno == 0 {
  2495. advice_ids := c.GetString("advice_id")
  2496. if advice_ids == "" {
  2497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2498. return
  2499. } else {
  2500. ids = strings.Split(advice_ids, ",")
  2501. if len(ids) <= 0 {
  2502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2503. return
  2504. }
  2505. }
  2506. }
  2507. if groupno < 0 {
  2508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2509. return
  2510. }
  2511. adminUserInfo := c.GetMobileAdminUserInfo()
  2512. var advice models.DoctorAdvice
  2513. if groupno > 0 {
  2514. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2515. for _, item := range advices {
  2516. if item.CheckState == 0 {
  2517. advice = item
  2518. }
  2519. //记录日志
  2520. byterequest, _ := json.Marshal(advices)
  2521. adviceLog := models.XtDoctorAdviceLog{
  2522. UserOrgId: adminUserInfo.Org.Id,
  2523. PatientId: item.PatientId,
  2524. AdminUserId: adminUserInfo.AdminUser.Id,
  2525. Module: 3,
  2526. ErrLog: string(byterequest),
  2527. Status: 1,
  2528. Ctime: time.Now().Unix(),
  2529. Mtime: 0,
  2530. Source: "手机端核对医嘱",
  2531. RecordDate: item.AdviceDate,
  2532. }
  2533. service.CreateDoctorAdviceLog(adviceLog)
  2534. }
  2535. if advice.CheckState == 1 {
  2536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2537. return
  2538. }
  2539. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2541. return
  2542. }
  2543. } else {
  2544. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2545. for _, item := range advices {
  2546. if item.CheckState == 0 {
  2547. advice = item
  2548. }
  2549. //记录日志
  2550. byterequest, _ := json.Marshal(advices)
  2551. adviceLog := models.XtDoctorAdviceLog{
  2552. UserOrgId: adminUserInfo.Org.Id,
  2553. PatientId: item.PatientId,
  2554. AdminUserId: adminUserInfo.AdminUser.Id,
  2555. Module: 3,
  2556. ErrLog: string(byterequest),
  2557. Status: 1,
  2558. Ctime: time.Now().Unix(),
  2559. Mtime: 0,
  2560. Source: "手机端核对医嘱",
  2561. RecordDate: item.AdviceDate,
  2562. }
  2563. service.CreateDoctorAdviceLog(adviceLog)
  2564. }
  2565. if advice.CheckState == 1 {
  2566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2567. return
  2568. }
  2569. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2571. return
  2572. }
  2573. }
  2574. checker := adminUserInfo.AdminUser.Id
  2575. advices := models.DoctorAdvice{
  2576. CheckTime: theTime.Unix(),
  2577. Checker: checker,
  2578. UpdatedTime: time.Now().Unix(),
  2579. }
  2580. fmt.Println("groupnowowowowoowowow", groupno)
  2581. var err error
  2582. if groupno > 0 {
  2583. // 查询信息规挡的设置天数
  2584. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2585. if infor.ID > 0 && infor.WeekDay > 0 {
  2586. var cha_time int64
  2587. timeNowStr := time.Now().Format("2006-01-02")
  2588. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2589. //今日的日期减去设置的日期
  2590. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2591. if cha_time >= record_date {
  2592. //查询审核是否允许
  2593. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2594. //申请状态不允许的情况 拒绝修改
  2595. if infor.ApplicationStatus != 1 {
  2596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2597. return
  2598. }
  2599. }
  2600. }
  2601. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  2602. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2603. redis := service.RedisClient()
  2604. //清空key 值
  2605. redis.Set(key, "", time.Second)
  2606. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2607. redis.Set(keyTwo, "", time.Second)
  2608. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2609. redis.Set(keyThree, "", time.Second)
  2610. recordDate := theTime.Format("2006-01-02")
  2611. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2612. redis.Set(keyFour, "", time.Second)
  2613. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2614. redis.Set(keyFive, "", time.Second)
  2615. defer redis.Close()
  2616. } else {
  2617. if len(ids[0]) <= 0 {
  2618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2619. return
  2620. } else {
  2621. //t := time.Now().Format("2006-01-02")/**/
  2622. //timeLayout2 := "2006-01-02"
  2623. //loc, _ := time.LoadLocation("Local")
  2624. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2625. // 查询信息规挡的设置天数
  2626. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2627. if infor.ID > 0 {
  2628. var cha_time int64
  2629. timeNowStr := time.Now().Format("2006-01-02")
  2630. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2631. //今日的日期减去设置的日期
  2632. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2633. if cha_time >= advices.AdviceDate {
  2634. //查询审核是否允许
  2635. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2636. //申请状态不允许的情况 拒绝修改
  2637. if infor.ApplicationStatus != 1 {
  2638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2639. return
  2640. }
  2641. }
  2642. }
  2643. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2644. //记录日志
  2645. byterequest, _ := json.Marshal(advices)
  2646. adviceLog := models.XtDoctorAdviceLog{
  2647. UserOrgId: adminUserInfo.Org.Id,
  2648. PatientId: advices.PatientId,
  2649. AdminUserId: advices.Checker,
  2650. Module: 3,
  2651. ErrLog: string(byterequest),
  2652. Status: 1,
  2653. Ctime: time.Now().Unix(),
  2654. Mtime: 0,
  2655. Source: "手机端核对医嘱",
  2656. RecordDate: advices.AdviceDate,
  2657. }
  2658. service.CreateDoctorAdviceLog(adviceLog)
  2659. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2660. redis := service.RedisClient()
  2661. //清空key 值
  2662. redis.Set(key, "", time.Second)
  2663. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2664. redis.Set(keyTwo, "", time.Second)
  2665. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2666. redis.Set(keyThree, "", time.Second)
  2667. recordDate := theTime.Format("2006-01-02")
  2668. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2669. redis.Set(keyFour, "", time.Second)
  2670. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2671. redis.Set(keyFive, "", time.Second)
  2672. defer redis.Close()
  2673. }
  2674. }
  2675. if err != nil {
  2676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2677. return
  2678. }
  2679. advice.Checker = checker
  2680. advice.CheckTime = theTime.Unix()
  2681. advice.CheckState = 1
  2682. c.ServeSuccessJSON(map[string]interface{}{
  2683. "msg": "ok",
  2684. "advice": advice,
  2685. })
  2686. }
  2687. return
  2688. }
  2689. func (c *PatientApiController) CheckDoctorAdvice() {
  2690. origin, _ := c.GetInt64("origin", 0)
  2691. record_date, _ := c.GetInt64("record_date")
  2692. patient_id, _ := c.GetInt64("patient_id")
  2693. if origin != 2 {
  2694. groupno, _ := c.GetInt64("groupno", -1)
  2695. var ids []string
  2696. if groupno == 0 {
  2697. advice_ids := c.GetString("advice_id")
  2698. if advice_ids == "" {
  2699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2700. return
  2701. } else {
  2702. ids = strings.Split(advice_ids, ",")
  2703. if len(ids) <= 0 {
  2704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2705. return
  2706. }
  2707. }
  2708. }
  2709. if groupno < 0 {
  2710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2711. return
  2712. }
  2713. adminUserInfo := c.GetMobileAdminUserInfo()
  2714. var advice models.DoctorAdvice
  2715. if groupno > 0 {
  2716. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2717. for _, item := range advices {
  2718. if item.CheckState == 0 {
  2719. advice = item
  2720. }
  2721. //记录日志
  2722. byterequest, _ := json.Marshal(advices)
  2723. adviceLog := models.XtDoctorAdviceLog{
  2724. UserOrgId: adminUserInfo.Org.Id,
  2725. PatientId: item.PatientId,
  2726. AdminUserId: adminUserInfo.AdminUser.Id,
  2727. Module: 3,
  2728. ErrLog: string(byterequest),
  2729. Status: 1,
  2730. Ctime: time.Now().Unix(),
  2731. Mtime: 0,
  2732. Source: "手机端核对医嘱",
  2733. RecordDate: item.AdviceDate,
  2734. }
  2735. service.CreateDoctorAdviceLog(adviceLog)
  2736. }
  2737. if advice.CheckState == 1 {
  2738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2739. return
  2740. }
  2741. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2743. return
  2744. }
  2745. } else {
  2746. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2747. for _, item := range advices {
  2748. if item.CheckState == 0 {
  2749. advice = item
  2750. }
  2751. //记录日志
  2752. byterequest, _ := json.Marshal(advices)
  2753. adviceLog := models.XtDoctorAdviceLog{
  2754. UserOrgId: adminUserInfo.Org.Id,
  2755. PatientId: item.PatientId,
  2756. AdminUserId: adminUserInfo.AdminUser.Id,
  2757. Module: 3,
  2758. ErrLog: string(byterequest),
  2759. Status: 1,
  2760. Ctime: time.Now().Unix(),
  2761. Mtime: 0,
  2762. Source: "手机端核对医嘱",
  2763. RecordDate: item.AdviceDate,
  2764. }
  2765. service.CreateDoctorAdviceLog(adviceLog)
  2766. }
  2767. if advice.CheckState == 1 {
  2768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2769. return
  2770. }
  2771. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2773. return
  2774. }
  2775. }
  2776. checker := adminUserInfo.AdminUser.Id
  2777. theTime := time.Now()
  2778. advices := models.DoctorAdvice{
  2779. CheckTime: theTime.Unix(),
  2780. Checker: checker,
  2781. UpdatedTime: time.Now().Unix(),
  2782. }
  2783. var err error
  2784. if groupno > 0 {
  2785. // 查询信息规挡的设置天数
  2786. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2787. if infor.ID > 0 && infor.WeekDay > 0 {
  2788. var cha_time int64
  2789. timeNowStr := time.Now().Format("2006-01-02")
  2790. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2791. //今日的日期减去设置的日期
  2792. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2793. if cha_time >= record_date {
  2794. //查询审核是否允许
  2795. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2796. //申请状态不允许的情况 拒绝修改
  2797. if infor.ApplicationStatus != 1 {
  2798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2799. return
  2800. }
  2801. }
  2802. }
  2803. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2804. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2805. redis := service.RedisClient()
  2806. //清空key 值
  2807. redis.Set(key, "", time.Second)
  2808. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2809. redis.Set(keyTwo, "", time.Second)
  2810. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2811. redis.Set(keyThree, "", time.Second)
  2812. recordDate := theTime.Format("2006-01-02")
  2813. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2814. redis.Set(keyFour, "", time.Second)
  2815. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2816. redis.Set(keyFive, "", time.Second)
  2817. defer redis.Close()
  2818. } else {
  2819. if len(ids[0]) <= 0 {
  2820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2821. return
  2822. } else {
  2823. //t := time.Now().Format("2006-01-02")/**/
  2824. //timeLayout2 := "2006-01-02"
  2825. //loc, _ := time.LoadLocation("Local")
  2826. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2827. // 查询信息规挡的设置天数
  2828. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2829. if infor.ID > 0 {
  2830. var cha_time int64
  2831. timeNowStr := time.Now().Format("2006-01-02")
  2832. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2833. //今日的日期减去设置的日期
  2834. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2835. if cha_time >= advices.AdviceDate {
  2836. //查询审核是否允许
  2837. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2838. //申请状态不允许的情况 拒绝修改
  2839. if infor.ApplicationStatus != 1 {
  2840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2841. return
  2842. }
  2843. }
  2844. }
  2845. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2846. //记录日志
  2847. byterequest, _ := json.Marshal(advices)
  2848. adviceLog := models.XtDoctorAdviceLog{
  2849. UserOrgId: adminUserInfo.Org.Id,
  2850. PatientId: advices.PatientId,
  2851. AdminUserId: advices.Checker,
  2852. Module: 3,
  2853. ErrLog: string(byterequest),
  2854. Status: 1,
  2855. Ctime: time.Now().Unix(),
  2856. Mtime: 0,
  2857. Source: "手机端核对医嘱",
  2858. RecordDate: advices.AdviceDate,
  2859. }
  2860. service.CreateDoctorAdviceLog(adviceLog)
  2861. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2862. redis := service.RedisClient()
  2863. //清空key 值
  2864. redis.Set(key, "", time.Second)
  2865. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2866. redis.Set(keyTwo, "", time.Second)
  2867. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2868. redis.Set(keyThree, "", time.Second)
  2869. recordDate := theTime.Format("2006-01-02")
  2870. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2871. redis.Set(keyFour, "", time.Second)
  2872. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2873. redis.Set(keyFive, "", time.Second)
  2874. defer redis.Close()
  2875. }
  2876. }
  2877. if err != nil {
  2878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2879. return
  2880. }
  2881. advice.Checker = checker
  2882. advice.CheckTime = theTime.Unix()
  2883. advice.CheckState = 1
  2884. c.ServeSuccessJSON(map[string]interface{}{
  2885. "msg": "ok",
  2886. "advice": advice,
  2887. })
  2888. } else if origin == 2 {
  2889. adminInfo := c.GetMobileAdminUserInfo()
  2890. var ids []string
  2891. advice_ids := c.GetString("advice_id")
  2892. ids = strings.Split(advice_ids, ",")
  2893. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2894. var err error
  2895. for _, item := range advices {
  2896. if item.CheckState == 1 {
  2897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2898. return
  2899. }
  2900. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2902. return
  2903. }
  2904. item.Checker = adminInfo.AdminUser.Id
  2905. item.CheckTime = time.Now().Unix()
  2906. item.CheckState = 1
  2907. // 查询信息规挡的设置天数
  2908. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2909. if infor.ID > 0 {
  2910. var cha_time int64
  2911. timeNowStr := time.Now().Format("2006-01-02")
  2912. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2913. //今日的日期减去设置的日期
  2914. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2915. if cha_time >= record_date {
  2916. //查询审核是否允许
  2917. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2918. //申请状态不允许的情况 拒绝修改
  2919. if infor.ApplicationStatus != 1 {
  2920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2921. return
  2922. }
  2923. }
  2924. }
  2925. err = service.SaveHisDoctorAdvice(item)
  2926. //记录日志
  2927. byterequest, _ := json.Marshal(advices)
  2928. adviceLog := models.XtDoctorAdviceLog{
  2929. UserOrgId: adminInfo.Org.Id,
  2930. PatientId: item.PatientId,
  2931. AdminUserId: item.Checker,
  2932. Module: 3,
  2933. ErrLog: string(byterequest),
  2934. Status: 1,
  2935. Ctime: time.Now().Unix(),
  2936. Mtime: 0,
  2937. Source: "手机端核对His医嘱",
  2938. RecordDate: item.AdviceDate,
  2939. }
  2940. service.CreateDoctorAdviceLog(adviceLog)
  2941. redis := service.RedisClient()
  2942. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2943. //清空key 值
  2944. redis.Set(key, "", time.Second)
  2945. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2946. redis.Set(keyTwo, "", time.Second)
  2947. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2948. redis.Set(keyThree, "", time.Second)
  2949. theTime := time.Now()
  2950. recordDate := theTime.Format("2006-01-02")
  2951. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2952. redis.Set(keyFour, "", time.Second)
  2953. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2954. redis.Set(keyFive, "", time.Second)
  2955. defer redis.Close()
  2956. }
  2957. if err == nil {
  2958. c.ServeSuccessJSON(map[string]interface{}{
  2959. "msg": "ok",
  2960. "advice": advices,
  2961. })
  2962. } else {
  2963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2964. return
  2965. }
  2966. }
  2967. return
  2968. }
  2969. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2970. id, _ := c.GetInt64("patient", 0)
  2971. assessmentDate := c.GetString("assessment_date", "")
  2972. if id <= 0 || len(assessmentDate) != 10 {
  2973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2974. return
  2975. }
  2976. timeLayout := "2006-01-02"
  2977. loc, _ := time.LoadLocation("Local")
  2978. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2979. if err != nil {
  2980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2981. return
  2982. }
  2983. theAssessmentDateTime := theTime.Unix()
  2984. adminUserInfo := c.GetMobileAdminUserInfo()
  2985. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2986. if patient.ID == 0 {
  2987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2988. return
  2989. }
  2990. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2991. if getPEErr != nil {
  2992. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2994. return
  2995. }
  2996. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2997. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2998. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2999. var evaluation models.PredialysisEvaluation
  3000. if theEvaluation != nil {
  3001. evaluation = *theEvaluation
  3002. }
  3003. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  3004. if code > 0 {
  3005. c.ServeFailJSONWithSGJErrorCode(code)
  3006. return
  3007. }
  3008. if theEvaluation == nil {
  3009. evaluation.CreatedTime = time.Now().Unix()
  3010. evaluation.Status = 1
  3011. evaluation.AssessmentDate = theAssessmentDateTime
  3012. evaluation.PatientId = id
  3013. evaluation.UserOrgId = adminUserInfo.Org.Id
  3014. if appRole.UserType == 2 || appRole.UserType == 1 {
  3015. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  3016. evaluation.AssessmentTime = time.Now().Unix()
  3017. } else {
  3018. evaluation.Creater = adminUserInfo.AdminUser.Id
  3019. }
  3020. } else {
  3021. evaluation.UpdatedTime = time.Now().Unix()
  3022. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  3023. if appRole.UserType == 2 || appRole.UserType == 1 {
  3024. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  3025. evaluation.AssessmentTime = time.Now().Unix()
  3026. } else {
  3027. evaluation.Modifier = adminUserInfo.AdminUser.Id
  3028. if evaluation.Creater == 0 {
  3029. evaluation.Creater = adminUserInfo.AdminUser.Id
  3030. }
  3031. }
  3032. }
  3033. //新增逻辑
  3034. var dewater_amount float64
  3035. dewater_amount = 0
  3036. if evaluation.DryWeight > 0 {
  3037. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3038. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10551 || adminUserInfo.Org.Id == 10579 || adminUserInfo.Org.Id == 10580 || adminUserInfo.Org.Id == 10585 || adminUserInfo.Org.Id == 10635 || adminUserInfo.Org.Id == 10727 {
  3039. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  3040. dewater_amount = dewater_amount * 1000
  3041. }
  3042. }
  3043. if adminUserInfo.Org.Id == 10727 {
  3044. dewater_amount = dewater_amount * 1000
  3045. }
  3046. if dewater_amount <= 0 {
  3047. dewater_amount = 0
  3048. }
  3049. } else {
  3050. dewater_amount = 0
  3051. }
  3052. // 计算透析处方的相关超滤量
  3053. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  3054. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  3055. var lastDialysisPrescribe *models.DialysisPrescription
  3056. var dialysisSolution *models.DialysisSolution
  3057. var dialysisPrescribe *models.DialysisPrescription
  3058. var system_dialysisPrescribe *models.SystemPrescription
  3059. var mode_id int64
  3060. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3061. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  3062. if schedual != nil {
  3063. // 获取透析模版
  3064. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  3065. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  3066. mode_id = schedual.ModeId
  3067. } else {
  3068. // 获取透析模版
  3069. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  3070. if dialysisPrescribe == nil && dialysisSolution != nil {
  3071. mode_id = dialysisSolution.ModeId
  3072. }
  3073. if dialysisPrescribe == nil && dialysisSolution == nil {
  3074. mode_id = 0
  3075. }
  3076. }
  3077. // 插入透析处方
  3078. if dialysisPrescribe == nil && dialysisSolution != nil {
  3079. var newprescribe models.DialysisPrescription
  3080. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3081. newprescribe.PatientId = id
  3082. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  3083. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  3084. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  3085. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  3086. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  3087. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  3088. newprescribe.ModeId = dialysisSolution.ModeId
  3089. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  3090. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  3091. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  3092. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  3093. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  3094. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  3095. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  3096. newprescribe.Glucose = dialysisSolution.Glucose
  3097. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  3098. newprescribe.Kalium = dialysisSolution.Kalium
  3099. newprescribe.Sodium = dialysisSolution.Sodium
  3100. newprescribe.Calcium = dialysisSolution.Calcium
  3101. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  3102. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  3103. newprescribe.Conductivity = dialysisSolution.Conductivity
  3104. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  3105. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  3106. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  3107. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  3108. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  3109. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  3110. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  3111. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  3112. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  3113. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  3114. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  3115. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  3116. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  3117. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  3118. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  3119. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  3120. newprescribe.CreatedTime = time.Now().Unix()
  3121. newprescribe.UpdatedTime = time.Now().Unix()
  3122. newprescribe.RecordDate = theAssessmentDateTime
  3123. newprescribe.DewaterAmount = dewater_amount
  3124. newprescribe.TargetUltrafiltration = dewater_amount
  3125. newprescribe.PrescriptionWater = dewater_amount
  3126. newprescribe.Status = 1
  3127. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  3128. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  3129. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3130. newprescribe.Remark = lastDialysisPrescription.Remark
  3131. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3132. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3133. newprescribe.ID = dialysisPrescription.ID
  3134. if dialysisPrescription.ID == 0 {
  3135. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3136. newprescribe.Sodium = 138
  3137. newprescribe.Bicarbonate = 31.1
  3138. newprescribe.DialysateFlow = 500
  3139. newprescribe.PrescribingNumber = 1
  3140. }
  3141. if adminUserInfo.Org.Id == 10579 {
  3142. newprescribe.Modifier = 0
  3143. newprescribe.Creater = 0
  3144. newprescribe.PrescriptionDoctor = 0
  3145. }
  3146. err := service.AddSigleRecord(&newprescribe)
  3147. //记录日志
  3148. byterequest, _ := json.Marshal(newprescribe)
  3149. prescriptionLog := models.XtDialysisPrescriptionLog{
  3150. UserOrgId: adminUserInfo.Org.Id,
  3151. Ctime: time.Now().Unix(),
  3152. Mtime: 0,
  3153. ErrLog: string(byterequest),
  3154. AdminUserId: adminUserInfo.AdminUser.Id,
  3155. RecordDate: newprescribe.RecordDate,
  3156. PatientId: id,
  3157. Source: "手机端新增透前评估插入处方",
  3158. Status: 1,
  3159. }
  3160. service.CreatePrescriptionLog(prescriptionLog)
  3161. //获取key,清空redis
  3162. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3163. redis := service.RedisClient()
  3164. //清空key 值
  3165. redis.Set(key, "", time.Second)
  3166. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3167. //清空key 值
  3168. redis.Set(keyOne, "", time.Second)
  3169. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3170. //清空key 值
  3171. redis.Set(keyTwo, "", time.Second)
  3172. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3173. redis.Set(keySix, "", time.Second)
  3174. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3175. redis.Set(keySeven, "", time.Second)
  3176. if err != nil {
  3177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3178. }
  3179. } else {
  3180. if adminUserInfo.Org.Id == 10340 {
  3181. newprescribe.Sodium = 138
  3182. newprescribe.Bicarbonate = 31.1
  3183. newprescribe.DialysateFlow = 500
  3184. }
  3185. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3186. //
  3187. if appRole.UserType == 2 || appRole.UserType == 1 {
  3188. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3189. if adminUserInfo.Org.Id == 9882 {
  3190. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3191. }
  3192. }
  3193. err := service.UpDateDialysisPrescription(&newprescribe)
  3194. //记录日志
  3195. byterequest, _ := json.Marshal(newprescribe)
  3196. prescriptionLog := models.XtDialysisPrescriptionLog{
  3197. UserOrgId: adminUserInfo.Org.Id,
  3198. Ctime: time.Now().Unix(),
  3199. Mtime: 0,
  3200. ErrLog: string(byterequest),
  3201. AdminUserId: adminUserInfo.AdminUser.Id,
  3202. RecordDate: newprescribe.RecordDate,
  3203. PatientId: id,
  3204. Source: "手机端新增透前评估插入处方",
  3205. Status: 1,
  3206. }
  3207. service.CreatePrescriptionLog(prescriptionLog)
  3208. //获取key,清空redis
  3209. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3210. redis := service.RedisClient()
  3211. //清空key 值
  3212. redis.Set(key, "", time.Second)
  3213. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3214. //清空key 值
  3215. redis.Set(keyOne, "", time.Second)
  3216. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3217. //清空key 值
  3218. redis.Set(keyTwo, "", time.Second)
  3219. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3220. redis.Set(keySix, "", time.Second)
  3221. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3222. redis.Set(keySeven, "", time.Second)
  3223. if err != nil {
  3224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3225. }
  3226. }
  3227. }
  3228. if dialysisPrescribe == nil && dialysisSolution == nil {
  3229. if lastDialysisPrescribe != nil {
  3230. var newprescribe models.DialysisPrescription
  3231. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3232. newprescribe.PatientId = id
  3233. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  3234. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  3235. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  3236. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  3237. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  3238. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  3239. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  3240. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  3241. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  3242. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  3243. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  3244. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  3245. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  3246. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  3247. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  3248. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  3249. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  3250. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  3251. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  3252. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  3253. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  3254. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  3255. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  3256. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  3257. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  3258. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  3259. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  3260. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  3261. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  3262. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  3263. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  3264. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  3265. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  3266. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  3267. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  3268. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  3269. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  3270. newprescribe.CreatedTime = time.Now().Unix()
  3271. newprescribe.UpdatedTime = time.Now().Unix()
  3272. newprescribe.RecordDate = theAssessmentDateTime
  3273. newprescribe.DewaterAmount = dewater_amount
  3274. newprescribe.TargetUltrafiltration = dewater_amount
  3275. newprescribe.PrescriptionWater = dewater_amount
  3276. newprescribe.Status = 1
  3277. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  3278. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  3279. if dialysisSolution != nil && dialysisSolution.DialysisStrainer != "" {
  3280. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3281. }
  3282. newprescribe.Remark = lastDialysisPrescription.Remark
  3283. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3284. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3285. newprescribe.ID = dialysisPrescription.ID
  3286. if dialysisPrescription.ID == 0 {
  3287. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3288. newprescribe.Sodium = 138
  3289. newprescribe.Bicarbonate = 31.1
  3290. newprescribe.DialysateFlow = 500
  3291. }
  3292. if adminUserInfo.Org.Id == 10579 {
  3293. newprescribe.Modifier = 0
  3294. newprescribe.Creater = 0
  3295. newprescribe.PrescriptionDoctor = 0
  3296. }
  3297. err := service.AddSigleRecord(&newprescribe)
  3298. //记录日志
  3299. byterequest, _ := json.Marshal(newprescribe)
  3300. prescriptionLog := models.XtDialysisPrescriptionLog{
  3301. UserOrgId: adminUserInfo.Org.Id,
  3302. Ctime: time.Now().Unix(),
  3303. Mtime: 0,
  3304. ErrLog: string(byterequest),
  3305. AdminUserId: adminUserInfo.AdminUser.Id,
  3306. RecordDate: newprescribe.RecordDate,
  3307. PatientId: id,
  3308. Source: "手机端新增透前评估插入处方",
  3309. Status: 1,
  3310. }
  3311. service.CreatePrescriptionLog(prescriptionLog)
  3312. //获取key,清空redis
  3313. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3314. redis := service.RedisClient()
  3315. //清空key 值
  3316. redis.Set(key, "", time.Second)
  3317. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3318. //清空key 值
  3319. redis.Set(keyOne, "", time.Second)
  3320. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3321. //清空key 值
  3322. redis.Set(keyTwo, "", time.Second)
  3323. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3324. redis.Set(keySix, "", time.Second)
  3325. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3326. redis.Set(keySeven, "", time.Second)
  3327. if err != nil {
  3328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3329. }
  3330. } else {
  3331. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3332. //
  3333. if appRole.UserType == 2 || appRole.UserType == 1 {
  3334. if adminUserInfo.Org.Id == 10579 {
  3335. newprescribe.Modifier = 0
  3336. newprescribe.Creater = 0
  3337. newprescribe.PrescriptionDoctor = 0
  3338. } else {
  3339. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3340. }
  3341. if adminUserInfo.Org.Id == 9882 {
  3342. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3343. }
  3344. }
  3345. err := service.UpDateDialysisPrescription(&newprescribe)
  3346. //记录日志
  3347. byterequest, _ := json.Marshal(newprescribe)
  3348. prescriptionLog := models.XtDialysisPrescriptionLog{
  3349. UserOrgId: adminUserInfo.Org.Id,
  3350. Ctime: time.Now().Unix(),
  3351. Mtime: 0,
  3352. ErrLog: string(byterequest),
  3353. AdminUserId: adminUserInfo.AdminUser.Id,
  3354. RecordDate: newprescribe.RecordDate,
  3355. PatientId: id,
  3356. Source: "手机端新增透前评估插入处方",
  3357. Status: 1,
  3358. }
  3359. service.CreatePrescriptionLog(prescriptionLog)
  3360. //获取key,清空redis
  3361. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3362. redis := service.RedisClient()
  3363. //清空key 值
  3364. redis.Set(key, "", time.Second)
  3365. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3366. //清空key 值
  3367. redis.Set(keyOne, "", time.Second)
  3368. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3369. //清空key 值
  3370. redis.Set(keyTwo, "", time.Second)
  3371. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3372. redis.Set(keySix, "", time.Second)
  3373. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3374. redis.Set(keySeven, "", time.Second)
  3375. if err != nil {
  3376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3377. }
  3378. }
  3379. if err != nil {
  3380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3381. }
  3382. } else if system_dialysisPrescribe != nil {
  3383. var newprescribe models.DialysisPrescription
  3384. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3385. newprescribe.PatientId = id
  3386. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  3387. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  3388. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  3389. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  3390. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  3391. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  3392. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  3393. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  3394. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  3395. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  3396. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  3397. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  3398. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  3399. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  3400. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  3401. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  3402. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  3403. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  3404. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  3405. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  3406. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  3407. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  3408. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  3409. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  3410. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  3411. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  3412. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  3413. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  3414. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  3415. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  3416. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  3417. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  3418. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  3419. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  3420. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  3421. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  3422. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  3423. newprescribe.CreatedTime = time.Now().Unix()
  3424. newprescribe.UpdatedTime = time.Now().Unix()
  3425. newprescribe.RecordDate = theAssessmentDateTime
  3426. newprescribe.DewaterAmount = dewater_amount
  3427. newprescribe.TargetUltrafiltration = dewater_amount
  3428. newprescribe.PrescriptionWater = dewater_amount
  3429. newprescribe.Status = 1
  3430. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  3431. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  3432. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3433. newprescribe.Remark = lastDialysisPrescription.Remark
  3434. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3435. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3436. newprescribe.ID = dialysisPrescription.ID
  3437. if dialysisPrescription.ID == 0 {
  3438. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3439. newprescribe.Sodium = 138
  3440. newprescribe.Bicarbonate = 31.1
  3441. newprescribe.DialysateFlow = 500
  3442. }
  3443. if adminUserInfo.Org.Id == 10579 {
  3444. newprescribe.Modifier = 0
  3445. newprescribe.Creater = 0
  3446. newprescribe.PrescriptionDoctor = 0
  3447. }
  3448. err := service.AddSigleRecord(&newprescribe)
  3449. //记录日志
  3450. byterequest, _ := json.Marshal(newprescribe)
  3451. prescriptionLog := models.XtDialysisPrescriptionLog{
  3452. UserOrgId: adminUserInfo.Org.Id,
  3453. Ctime: time.Now().Unix(),
  3454. Mtime: 0,
  3455. ErrLog: string(byterequest),
  3456. AdminUserId: adminUserInfo.AdminUser.Id,
  3457. RecordDate: newprescribe.RecordDate,
  3458. PatientId: id,
  3459. Source: "手机端新增透前评估插入处方",
  3460. Status: 1,
  3461. }
  3462. service.CreatePrescriptionLog(prescriptionLog)
  3463. //获取key,清空redis
  3464. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3465. redis := service.RedisClient()
  3466. //清空key 值
  3467. redis.Set(key, "", time.Second)
  3468. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3469. //清空key 值
  3470. redis.Set(keyOne, "", time.Second)
  3471. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3472. //清空key 值
  3473. redis.Set(keyTwo, "", time.Second)
  3474. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3475. redis.Set(keySix, "", time.Second)
  3476. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3477. redis.Set(keySeven, "", time.Second)
  3478. if err != nil {
  3479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3480. }
  3481. } else {
  3482. if adminUserInfo.Org.Id == 10340 {
  3483. newprescribe.Sodium = 138
  3484. newprescribe.Bicarbonate = 31.1
  3485. newprescribe.DialysateFlow = 500
  3486. }
  3487. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3488. //
  3489. if appRole.UserType == 2 || appRole.UserType == 1 {
  3490. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3491. if adminUserInfo.Org.Id == 9882 {
  3492. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3493. }
  3494. }
  3495. err := service.UpDateDialysisPrescription(&newprescribe)
  3496. //记录日志
  3497. byterequest, _ := json.Marshal(newprescribe)
  3498. prescriptionLog := models.XtDialysisPrescriptionLog{
  3499. UserOrgId: adminUserInfo.Org.Id,
  3500. Ctime: time.Now().Unix(),
  3501. Mtime: 0,
  3502. ErrLog: string(byterequest),
  3503. AdminUserId: adminUserInfo.AdminUser.Id,
  3504. RecordDate: newprescribe.RecordDate,
  3505. PatientId: id,
  3506. Source: "手机端新增透前评估插入处方",
  3507. Status: 1,
  3508. }
  3509. service.CreatePrescriptionLog(prescriptionLog)
  3510. //获取key,清空redis
  3511. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3512. redis := service.RedisClient()
  3513. //清空key 值
  3514. redis.Set(key, "", time.Second)
  3515. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3516. //清空key 值
  3517. redis.Set(keyOne, "", time.Second)
  3518. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3519. //清空key 值
  3520. redis.Set(keyTwo, "", time.Second)
  3521. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3522. redis.Set(keySix, "", time.Second)
  3523. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3524. redis.Set(keySeven, "", time.Second)
  3525. if err != nil {
  3526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3527. }
  3528. }
  3529. if err != nil {
  3530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3531. }
  3532. } else {
  3533. var newprescribe models.DialysisPrescription
  3534. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3535. newprescribe.PatientId = id
  3536. newprescribe.ModeId = mode_id
  3537. newprescribe.CreatedTime = time.Now().Unix()
  3538. newprescribe.UpdatedTime = time.Now().Unix()
  3539. newprescribe.RecordDate = theAssessmentDateTime
  3540. newprescribe.DewaterAmount = dewater_amount
  3541. newprescribe.TargetUltrafiltration = dewater_amount
  3542. newprescribe.Status = 1
  3543. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3544. if dialysisPrescription.ID > 0 {
  3545. newprescribe.ID = dialysisPrescription.ID
  3546. }
  3547. if dialysisPrescription.ID == 0 {
  3548. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3549. newprescribe.Sodium = 138
  3550. newprescribe.Bicarbonate = 31.1
  3551. newprescribe.DialysateFlow = 500
  3552. }
  3553. if adminUserInfo.Org.Id == 10579 {
  3554. newprescribe.Modifier = 0
  3555. newprescribe.Creater = 0
  3556. newprescribe.PrescriptionDoctor = 0
  3557. }
  3558. err := service.AddSigleRecord(&newprescribe)
  3559. //获取key,清空redis
  3560. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3561. redis := service.RedisClient()
  3562. //清空key 值
  3563. redis.Set(key, "", time.Second)
  3564. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3565. //清空key 值
  3566. redis.Set(keyOne, "", time.Second)
  3567. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3568. //清空key 值
  3569. redis.Set(keyTwo, "", time.Second)
  3570. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3571. redis.Set(keySix, "", time.Second)
  3572. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3573. redis.Set(keySeven, "", time.Second)
  3574. if err != nil {
  3575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3576. }
  3577. } else {
  3578. if adminUserInfo.Org.Id == 10340 {
  3579. newprescribe.Sodium = 138
  3580. newprescribe.Bicarbonate = 31.1
  3581. newprescribe.DialysateFlow = 500
  3582. }
  3583. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3584. //
  3585. if appRole.UserType == 2 || appRole.UserType == 1 {
  3586. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3587. if adminUserInfo.Org.Id == 9882 {
  3588. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3589. }
  3590. }
  3591. if adminUserInfo.Org.Id == 10579 {
  3592. newprescribe.Modifier = 0
  3593. newprescribe.Creater = 0
  3594. newprescribe.PrescriptionDoctor = 0
  3595. }
  3596. err := service.UpDateDialysisPrescription(&newprescribe)
  3597. //记录日志
  3598. byterequest, _ := json.Marshal(newprescribe)
  3599. prescriptionLog := models.XtDialysisPrescriptionLog{
  3600. UserOrgId: adminUserInfo.Org.Id,
  3601. Ctime: time.Now().Unix(),
  3602. Mtime: 0,
  3603. ErrLog: string(byterequest),
  3604. AdminUserId: adminUserInfo.AdminUser.Id,
  3605. RecordDate: newprescribe.RecordDate,
  3606. PatientId: id,
  3607. Source: "手机端新增透前评估插入处方",
  3608. Status: 1,
  3609. }
  3610. service.CreatePrescriptionLog(prescriptionLog)
  3611. //获取key,清空redis
  3612. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3613. redis := service.RedisClient()
  3614. //清空key 值
  3615. redis.Set(key, "", time.Second)
  3616. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3617. //清空key 值
  3618. redis.Set(keyOne, "", time.Second)
  3619. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3620. //清空key 值
  3621. redis.Set(keyTwo, "", time.Second)
  3622. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3623. redis.Set(keySix, "", time.Second)
  3624. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3625. redis.Set(keySeven, "", time.Second)
  3626. if err != nil {
  3627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3628. }
  3629. }
  3630. if err != nil {
  3631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3632. }
  3633. }
  3634. }
  3635. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  3636. // if dialysisPrescribe != nil {
  3637. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  3638. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  3639. // dialysisPrescribe.DewaterAmount = dewater_amount
  3640. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  3641. // dialysisPrescribe.Status = 1
  3642. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  3643. // if updateErr != nil {
  3644. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3645. // }
  3646. // }
  3647. // 查询信息规挡的设置天数
  3648. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3649. if infor.ID > 0 && infor.WeekDay > 0 {
  3650. var cha_time int64
  3651. timeNowStr := time.Now().Format("2006-01-02")
  3652. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3653. //今日的日期减去设置的日期
  3654. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3655. if cha_time >= evaluation.AssessmentDate {
  3656. //查询审核是否允许
  3657. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  3658. //申请状态不允许的情况 拒绝修改
  3659. if infor.ApplicationStatus != 1 {
  3660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3661. return
  3662. }
  3663. }
  3664. }
  3665. //针对长沙南雅的问题
  3666. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10164 {
  3667. if len(evaluation.SymptomBeforeDialysis) == 0 {
  3668. predialysisEvaluation, _ := service.GetPredialysisEvaluation(id, adminUserInfo.Org.Id)
  3669. evaluation.SymptomBeforeDialysis = predialysisEvaluation.SymptomBeforeDialysis
  3670. }
  3671. }
  3672. //针对孝昌康桥超滤率计算问题
  3673. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10635 || adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10726 || adminUserInfo.Org.Id == 10164 {
  3674. if evaluation.ID == 0 {
  3675. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3676. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3677. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3678. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3679. }
  3680. }
  3681. if evaluation.ID > 0 {
  3682. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3683. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3684. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3685. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3686. }
  3687. }
  3688. }
  3689. //古镇乐生
  3690. if adminUserInfo.Org.Id == 10731 {
  3691. if evaluation.ID == 0 {
  3692. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3693. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3694. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3695. dewater_amount = dewater_amount * 1000
  3696. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3697. }
  3698. }
  3699. if evaluation.ID > 0 {
  3700. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3701. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3702. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3703. dewater_amount = dewater_amount * 1000
  3704. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3705. }
  3706. }
  3707. }
  3708. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3709. prescription, _ := service.GetTodayPrescription(id, adminUserInfo.Org.Id, theAssessmentDateTime)
  3710. if prescription.ID > 0 {
  3711. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  3712. if len(monitorList) > 0 {
  3713. var ultrafiltration_rate float64
  3714. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3715. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  3716. var replacement_rate float64
  3717. //乘10 除10是为了保留一位小数
  3718. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3719. var firstOpeateTime = monitorList[0].OperateTime
  3720. for _, item := range monitorList {
  3721. //超滤率
  3722. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  3723. //置换率
  3724. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  3725. //超滤量
  3726. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  3727. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  3728. //置换量
  3729. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  3730. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  3731. }
  3732. }
  3733. }
  3734. }
  3735. err = service.UpadatePredialysisEvaluation(&evaluation)
  3736. //记录日志
  3737. byterequest, _ := json.Marshal(evaluation)
  3738. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  3739. UserOrgId: evaluation.UserOrgId,
  3740. AdminUserId: adminUserInfo.AdminUser.Id,
  3741. ErrLog: string(byterequest),
  3742. PatientId: evaluation.PatientId,
  3743. RecordDate: evaluation.AssessmentDate,
  3744. Ctime: time.Now().Unix(),
  3745. Mtime: 0,
  3746. Status: 1,
  3747. Source: "手机端保存透前评估",
  3748. }
  3749. service.CreateBeforLog(beforeDislysisLog)
  3750. finish := models.XtDialysisFinish{
  3751. IsFinish: 1,
  3752. UserOrgId: adminUserInfo.Org.Id,
  3753. Status: 1,
  3754. Ctime: time.Now().Unix(),
  3755. Mtime: 0,
  3756. Module: 3,
  3757. RecordDate: evaluation.AssessmentDate,
  3758. Sourse: 1,
  3759. PatientId: id,
  3760. }
  3761. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  3762. if dialysisFinish.ID == 0 {
  3763. service.CreateDialysisFinish(finish)
  3764. }
  3765. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  3766. redis := service.RedisClient()
  3767. defer redis.Close()
  3768. //清空key 值
  3769. redis.Set(key, "", time.Second)
  3770. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  3771. redis.Set(keyOne, "", time.Second)
  3772. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3773. redis.Set(keyTwo, "", time.Second)
  3774. if err != nil {
  3775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  3776. return
  3777. }
  3778. c.ServeSuccessJSON(map[string]interface{}{
  3779. "msg": "ok",
  3780. "evaluation": evaluation,
  3781. })
  3782. return
  3783. }
  3784. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3785. dataBody := make(map[string]interface{}, 0)
  3786. err := json.Unmarshal(data, &dataBody)
  3787. utils.InfoLog(string(data))
  3788. if err != nil {
  3789. utils.ErrorLog(err.Error())
  3790. code = enums.ErrorCodeParamWrong
  3791. return
  3792. }
  3793. // if method == "create" {
  3794. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3795. utils.ErrorLog("mode")
  3796. code = enums.ErrorCodeParamWrong
  3797. return
  3798. }
  3799. mode := int64(dataBody["mode"].(float64))
  3800. if mode <= 0 {
  3801. utils.ErrorLog("mode <= 0")
  3802. code = enums.ErrorCodeParamWrong
  3803. return
  3804. }
  3805. solution.ModeId = mode
  3806. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3807. utils.ErrorLog("mode_name")
  3808. code = enums.ErrorCodeParamWrong
  3809. return
  3810. }
  3811. modeName, _ := dataBody["mode_name"].(string)
  3812. if len(modeName) == 0 {
  3813. utils.ErrorLog("len(mode_name) == 0")
  3814. code = enums.ErrorCodeParamWrong
  3815. return
  3816. }
  3817. solution.ModeName = modeName
  3818. solution.Name = modeName
  3819. // }
  3820. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3821. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3822. solution.DialysisDuration = dialysisDuration
  3823. }
  3824. if dataBody["dialysis_duration"] != nil {
  3825. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3826. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3827. solution.DialysisDuration = dialysisDuration
  3828. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  3829. dialysisDuration := dataBody["dialysis_duration"].(float64)
  3830. solution.DialysisDuration = dialysisDuration
  3831. }
  3832. }
  3833. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3834. dialyzer := int64(dataBody["dialyzer"].(float64))
  3835. solution.Dialyzer = dialyzer
  3836. }
  3837. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3838. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3839. solution.PerfusionApparatus = perfusionApparatus
  3840. }
  3841. if dataBody["blood_flow_volume"] != nil {
  3842. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3843. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3844. solution.BloodFlowVolume = bloodFlowVolume
  3845. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  3846. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  3847. solution.BloodFlowVolume = bloodFlowVolume
  3848. }
  3849. }
  3850. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3851. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3852. solution.HemodialysisMachine = hemodialysisMachine
  3853. }
  3854. if dataBody["dewater"] != nil {
  3855. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3856. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3857. solution.Dewater = dewater
  3858. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  3859. dewater := dataBody["dewater"].(float64)
  3860. solution.Dewater = dewater
  3861. }
  3862. }
  3863. if dataBody["replacement_total"] != nil {
  3864. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3865. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3866. solution.ReplacementTotal = replacementTotal
  3867. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  3868. replacementTotal := dataBody["replacement_total"].(float64)
  3869. solution.ReplacementTotal = replacementTotal
  3870. }
  3871. }
  3872. if dataBody["displace_liqui"] != nil {
  3873. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3874. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3875. solution.DisplaceLiqui = displaceLiqui
  3876. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  3877. displaceLiqui := dataBody["displace_liqui"].(float64)
  3878. solution.DisplaceLiqui = displaceLiqui
  3879. }
  3880. }
  3881. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3882. replacementWay := int64(dataBody["replacement_way"].(float64))
  3883. solution.ReplacementWay = replacementWay
  3884. }
  3885. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3886. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3887. solution.Anticoagulant = anticoagulant
  3888. }
  3889. if dataBody["anticoagulant_shouji"] != nil {
  3890. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3891. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3892. solution.AnticoagulantShouji = anticoagulantShouji
  3893. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3894. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3895. solution.AnticoagulantShouji = anticoagulantShouji
  3896. }
  3897. }
  3898. if dataBody["anticoagulant_weichi"] != nil {
  3899. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3900. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3901. solution.AnticoagulantWeichi = anticoagulantWeichi
  3902. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3903. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3904. solution.AnticoagulantWeichi = anticoagulantWeichi
  3905. }
  3906. }
  3907. if dataBody["anticoagulant_zongliang"] != nil {
  3908. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3909. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3910. solution.AnticoagulantZongliang = anticoagulantZongliang
  3911. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3912. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3913. solution.AnticoagulantZongliang = anticoagulantZongliang
  3914. }
  3915. }
  3916. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3917. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3918. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3919. }
  3920. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3921. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3922. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3923. }
  3924. if dataBody["kalium"] != nil {
  3925. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3926. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3927. solution.Kalium = kalium
  3928. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3929. kalium := dataBody["kalium"].(float64)
  3930. solution.Kalium = kalium
  3931. }
  3932. }
  3933. if dataBody["sodium"] != nil {
  3934. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3935. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3936. solution.Sodium = sodium
  3937. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3938. sodium := dataBody["sodium"].(float64)
  3939. solution.Sodium = sodium
  3940. }
  3941. }
  3942. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3943. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3944. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3945. solution.Calcium = calcium
  3946. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3947. calcium := dataBody["calcium"].(float64)
  3948. solution.Calcium = calcium
  3949. }
  3950. }
  3951. if dataBody["bicarbonate"] != nil {
  3952. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3953. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3954. solution.Bicarbonate = bicarbonate
  3955. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3956. bicarbonate := dataBody["bicarbonate"].(float64)
  3957. solution.Bicarbonate = bicarbonate
  3958. }
  3959. }
  3960. if dataBody["glucose"] != nil {
  3961. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3962. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3963. solution.Glucose = glucose
  3964. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3965. glucose := dataBody["glucose"].(float64)
  3966. solution.Glucose = glucose
  3967. }
  3968. }
  3969. // if dataBody["dry_weight"] != nil {
  3970. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3971. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3972. // solution.DryWeight = dryWeight
  3973. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3974. // dryWeight := dataBody["dry_weight"].(float64)
  3975. // solution.DryWeight = dryWeight
  3976. // }
  3977. // }
  3978. if dataBody["dialysate_flow"] != nil {
  3979. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3980. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3981. solution.DialysateFlow = dialysateFlow
  3982. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3983. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3984. solution.DialysateFlow = dialysateFlow
  3985. }
  3986. }
  3987. if dataBody["dialysate_temperature"] != nil {
  3988. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3989. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3990. solution.DialysateTemperature = dialysateTemperature
  3991. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  3992. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  3993. solution.DialysateTemperature = dialysateTemperature
  3994. }
  3995. }
  3996. if dataBody["conductivity"] != nil {
  3997. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3998. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3999. solution.Conductivity = conductivity
  4000. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  4001. conductivity := dataBody["conductivity"].(float64)
  4002. solution.Conductivity = conductivity
  4003. }
  4004. }
  4005. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4006. remark := dataBody["remark"].(string)
  4007. solution.Remark = remark
  4008. }
  4009. if dataBody["dialysis_duration_hour"] != nil {
  4010. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  4011. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  4012. solution.DialysisDurationHour = dialysisDurationHour
  4013. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  4014. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  4015. solution.DialysisDurationHour = int64(dialysisDurationHour)
  4016. }
  4017. }
  4018. if dataBody["dialysis_duration_minute"] != nil {
  4019. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  4020. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  4021. solution.DialysisDurationMinute = dialysisDurationMinute
  4022. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  4023. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  4024. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  4025. }
  4026. }
  4027. if dataBody["target_ultrafiltration"] != nil {
  4028. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  4029. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  4030. solution.TargetUltrafiltration = targetUltrafiltration
  4031. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  4032. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  4033. solution.TargetUltrafiltration = targetUltrafiltration
  4034. }
  4035. }
  4036. if dataBody["dialysate_formulation"] != nil {
  4037. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  4038. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  4039. solution.DialysateFormulation = dialysateFormulation
  4040. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  4041. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  4042. solution.DialysateFormulation = int64(dialysateFormulation)
  4043. }
  4044. }
  4045. return
  4046. }
  4047. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  4048. dataBody := make(map[string]interface{}, 0)
  4049. err := json.Unmarshal(data, &dataBody)
  4050. utils.InfoLog(string(data))
  4051. if err != nil {
  4052. utils.ErrorLog(err.Error())
  4053. code = enums.ErrorCodeParamWrong
  4054. return
  4055. }
  4056. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  4057. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  4058. evaluation.WeightBefore = weightVefore
  4059. }
  4060. // fmt.Println(dataBody["dry_weight"])
  4061. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  4062. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4063. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4064. fmt.Println(additionalWeight)
  4065. evaluation.DryWeight = additionalWeight
  4066. }
  4067. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  4068. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  4069. fmt.Println(additionalWeight)
  4070. evaluation.AdditionalWeight = additionalWeight
  4071. }
  4072. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  4073. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  4074. evaluation.Temperature = Temperature
  4075. }
  4076. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  4077. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  4078. evaluation.SystolicBloodPressure = systolicBloodPressure
  4079. }
  4080. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  4081. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  4082. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  4083. }
  4084. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  4085. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  4086. evaluation.PulseFrequency = pulseFrequency
  4087. }
  4088. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  4089. breathingRate := dataBody["breathing_rate"].(string)
  4090. evaluation.BreathingRate = breathingRate
  4091. }
  4092. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  4093. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  4094. evaluation.LastPostDialysis = lastPostDialysis
  4095. }
  4096. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  4097. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  4098. evaluation.DialysisInterphase = dialysisInterphase
  4099. }
  4100. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  4101. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  4102. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  4103. }
  4104. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  4105. catheter, _ := dataBody["catheter"].(string)
  4106. evaluation.Catheter = catheter
  4107. }
  4108. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  4109. catheter_bend := int(dataBody["catheter_bend"].(float64))
  4110. evaluation.CatheterBend = catheter_bend
  4111. }
  4112. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  4113. Complication, _ := dataBody["complication"].(string)
  4114. evaluation.Complication = Complication
  4115. }
  4116. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4117. remark := dataBody["remark"].(string)
  4118. evaluation.Remark = remark
  4119. }
  4120. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  4121. machine_type := dataBody["machine_type"].(string)
  4122. evaluation.MachineType = machine_type
  4123. }
  4124. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4125. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  4126. evaluation.BloodAccessPartId = blood_access_part_id
  4127. }
  4128. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  4129. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  4130. // evaluation.BloodAccessPartId = blood_access_part_id
  4131. //}
  4132. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  4133. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  4134. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  4135. }
  4136. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  4137. internal_fistula, _ := dataBody["internal_fistula"].(string)
  4138. evaluation.InternalFistula = internal_fistula
  4139. }
  4140. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  4141. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  4142. evaluation.InternalFistulaSkin = internal_fistula_skin
  4143. }
  4144. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  4145. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  4146. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  4147. evaluation.IsHemorrhage = is_hemorrhage
  4148. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  4149. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  4150. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  4151. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  4152. is_hemorrhage = 0
  4153. }
  4154. evaluation.IsHemorrhage = is_hemorrhage
  4155. if is_hemorrhage == 1 {
  4156. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  4157. hemorrhage, _ := dataBody["hemorrhage"].(string)
  4158. evaluation.Hemorrhage = hemorrhage
  4159. }
  4160. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  4161. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  4162. evaluation.HemorrhageOther = hemorrhage_other
  4163. }
  4164. }
  4165. } else {
  4166. evaluation.IsHemorrhage = 0
  4167. }
  4168. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  4169. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  4170. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  4171. }
  4172. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  4173. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  4174. evaluation.InternalFistulaOther = internal_fistula_other
  4175. }
  4176. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  4177. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  4178. evaluation.BloodAccessNoise = blood_access_noise
  4179. }
  4180. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  4181. //puncture_way := int64(dataBody["puncture_way"].(float64))
  4182. puncture_way := dataBody["puncture_way"].(string)
  4183. evaluation.PunctureWay = puncture_way
  4184. }
  4185. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  4186. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  4187. evaluation.VenousCatheterization = venous_catheterization
  4188. }
  4189. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  4190. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  4191. evaluation.VenousCatheterizationPart = venous_catheterization_part
  4192. }
  4193. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  4194. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  4195. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  4196. }
  4197. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  4198. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  4199. evaluation.DuctusArantii = ductus_arantii
  4200. }
  4201. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  4202. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  4203. evaluation.EmergencyTreatment = emergency_treatment
  4204. }
  4205. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  4206. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  4207. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  4208. }
  4209. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  4210. dialysis_count, _ := dataBody["dialysis_count"].(string)
  4211. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  4212. evaluation.DialysisCount = dialysis_count
  4213. }
  4214. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  4215. is_infect, _ := dataBody["is_infect"].(string)
  4216. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  4217. evaluation.IsInfect = infect
  4218. }
  4219. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  4220. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  4221. evaluation.Exposed = exposed
  4222. }
  4223. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  4224. skin, _ := dataBody["skin"].(string)
  4225. //skins, _ := strconv.ParseInt(skin, 10, 64)
  4226. evaluation.Skin = skin
  4227. }
  4228. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  4229. skin_other, _ := dataBody["skin_other"].(string)
  4230. evaluation.SkinOther = skin_other
  4231. }
  4232. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  4233. infect_other, _ := dataBody["infect_other"].(string)
  4234. evaluation.InfectOther = infect_other
  4235. }
  4236. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  4237. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  4238. evaluation.DuctusArantiiOther = ductus_arantii_other
  4239. }
  4240. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  4241. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  4242. evaluation.PunctureNeedle = punctureNeedle
  4243. }
  4244. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  4245. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  4246. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  4247. }
  4248. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  4249. pinholing := dataBody["pinholing"].(string)
  4250. evaluation.Phinholing = pinholing
  4251. }
  4252. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  4253. catheter_suture := dataBody["catheter_suture"].(string)
  4254. evaluation.CatheterSuture = catheter_suture
  4255. }
  4256. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  4257. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  4258. evaluation.CatheterSutureOther = catheter_suture_other
  4259. }
  4260. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  4261. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  4262. evaluation.UrineVolume = urine_volume
  4263. }
  4264. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  4265. edema := dataBody["edema"].(string)
  4266. evaluation.Edema = edema
  4267. }
  4268. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  4269. specialTreatment := dataBody["special_treatment"].(string)
  4270. evaluation.SpecialTreatment = specialTreatment
  4271. }
  4272. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  4273. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  4274. evaluation.CatheterMaintenance = catheter_maintenance
  4275. }
  4276. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  4277. thromubusType := int64(dataBody["thromubus_type"].(float64))
  4278. evaluation.ThromubusType = thromubusType
  4279. }
  4280. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  4281. thrombus_av := dataBody["thrombus_av"].(string)
  4282. evaluation.ThrombusAv = thrombus_av
  4283. }
  4284. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  4285. thromubus_a := dataBody["thromubus_a"].(string)
  4286. evaluation.ThromubusA = thromubus_a
  4287. }
  4288. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  4289. thromubus_v := dataBody["thromubus_v"].(string)
  4290. evaluation.ThromubusV = thromubus_v
  4291. }
  4292. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  4293. dehydration := dataBody["dehydration"].(string)
  4294. evaluation.Dehydration = dehydration
  4295. }
  4296. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  4297. period := int64(dataBody["period"].(float64))
  4298. evaluation.Period = period
  4299. }
  4300. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  4301. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  4302. evaluation.EstimatedFoodIntake = estimated_food_intake
  4303. }
  4304. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  4305. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  4306. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  4307. }
  4308. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  4309. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  4310. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  4311. }
  4312. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  4313. urea_befor := dataBody["urea_befor"].(string)
  4314. evaluation.UreaBefor = urea_befor
  4315. }
  4316. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  4317. suction := dataBody["suction"].(string)
  4318. evaluation.Suction = suction
  4319. }
  4320. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  4321. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  4322. evaluation.WeightBeforRemake = weight_befor_remake
  4323. }
  4324. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  4325. height := dataBody["height"].(string)
  4326. evaluation.Height = height
  4327. }
  4328. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  4329. age := dataBody["age"].(string)
  4330. evaluation.Age = age
  4331. }
  4332. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  4333. his_department := dataBody["his_department"].(string)
  4334. evaluation.HisDepartment = his_department
  4335. }
  4336. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  4337. his_bed := dataBody["his_bed"].(string)
  4338. evaluation.HisBed = his_bed
  4339. }
  4340. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  4341. point_puncture := dataBody["point_puncture"].(string)
  4342. evaluation.PointPuncture = point_puncture
  4343. }
  4344. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  4345. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  4346. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  4347. }
  4348. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  4349. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  4350. evaluation.SkinSiteCatheterization = skin_site_catheterization
  4351. }
  4352. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  4353. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  4354. evaluation.WhetherUnobstructed = whether_unobstructed
  4355. }
  4356. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  4357. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  4358. evaluation.LienNecessary = lien_necessary
  4359. }
  4360. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  4361. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  4362. timeLayout := "2006-01-02"
  4363. loc, _ := time.LoadLocation("Local")
  4364. var startTime int64
  4365. if len(pathway_formation_time) > 0 {
  4366. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  4367. startTime = theTime.Unix()
  4368. }
  4369. evaluation.PathwayFormationTime = startTime
  4370. }
  4371. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  4372. befor_symptoms := dataBody["befor_symptoms"].(string)
  4373. evaluation.BeforSymptoms = befor_symptoms
  4374. }
  4375. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  4376. washing_time, _ := dataBody["washing_time"].(string)
  4377. evaluation.WashingTime = washing_time
  4378. }
  4379. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  4380. warsh_count, _ := dataBody["warsh_count"].(string)
  4381. evaluation.WarshCount = warsh_count
  4382. }
  4383. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  4384. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  4385. evaluation.PunctureNeedleDirection = puncture_needle_direction
  4386. }
  4387. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  4388. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  4389. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  4390. }
  4391. return
  4392. }
  4393. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4394. dataBody := make(map[string]interface{}, 0)
  4395. err := json.Unmarshal(data, &dataBody)
  4396. if err != nil {
  4397. utils.ErrorLog(err.Error())
  4398. code = enums.ErrorCodeParamWrong
  4399. return
  4400. }
  4401. timeLayout := "2006-01-02"
  4402. loc, _ := time.LoadLocation("Local")
  4403. isChild := false
  4404. if action == "create" {
  4405. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4406. utils.ErrorLog("advice_type")
  4407. code = enums.ErrorCodeParamWrong
  4408. return
  4409. }
  4410. adviceType := int64(dataBody["advice_type"].(float64))
  4411. if adviceType != 1 && adviceType != 2 {
  4412. utils.ErrorLog("advice_type != 1&&2")
  4413. code = enums.ErrorCodeParamWrong
  4414. return
  4415. }
  4416. advice.AdviceType = adviceType
  4417. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4418. utils.ErrorLog("advice_date")
  4419. code = enums.ErrorCodeParamWrong
  4420. return
  4421. }
  4422. adviceDate, _ := dataBody["advice_date"].(string)
  4423. if len(adviceDate) == 0 {
  4424. utils.ErrorLog("len(adviceDate) == 0")
  4425. code = enums.ErrorCodeParamWrong
  4426. return
  4427. }
  4428. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4429. if err != nil {
  4430. utils.ErrorLog(err.Error())
  4431. code = enums.ErrorCodeParamWrong
  4432. return
  4433. }
  4434. advice.AdviceDate = theTime.Unix()
  4435. advice.RecordDate = theTime.Unix()
  4436. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4437. parentId := int64(dataBody["parent_id"].(float64))
  4438. advice.ParentId = parentId
  4439. if parentId > 0 {
  4440. isChild = true
  4441. }
  4442. }
  4443. } else {
  4444. isChild = advice.ParentId > 0
  4445. }
  4446. if !isChild {
  4447. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4448. utils.ErrorLog("start_time")
  4449. code = enums.ErrorCodeParamWrong
  4450. return
  4451. }
  4452. startTime, _ := dataBody["start_time"].(string)
  4453. if len(startTime) == 0 {
  4454. utils.ErrorLog("len(start_time) == 0")
  4455. code = enums.ErrorCodeParamWrong
  4456. return
  4457. }
  4458. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4459. if err != nil {
  4460. utils.ErrorLog(err.Error())
  4461. code = enums.ErrorCodeParamWrong
  4462. return
  4463. }
  4464. advice.StartTime = theTime.Unix()
  4465. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4466. deliveryWay, _ := dataBody["delivery_way"].(string)
  4467. advice.DeliveryWay = deliveryWay
  4468. }
  4469. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4470. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4471. advice.ExecutionFrequency = executionFrequency
  4472. }
  4473. }
  4474. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4475. deliveryWay, _ := dataBody["delivery_way"].(string)
  4476. advice.DeliveryWay = deliveryWay
  4477. }
  4478. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4479. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4480. advice.ExecutionFrequency = executionFrequency
  4481. }
  4482. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4483. utils.ErrorLog("advice_name")
  4484. code = enums.ErrorCodeParamWrong
  4485. return
  4486. }
  4487. adviceName, _ := dataBody["advice_name"].(string)
  4488. if len(adviceName) == 0 {
  4489. utils.ErrorLog("len(advice_name) == 0")
  4490. code = enums.ErrorCodeParamWrong
  4491. return
  4492. }
  4493. advice.AdviceName = adviceName
  4494. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4495. adviceDsc, _ := dataBody["advice_desc"].(string)
  4496. advice.AdviceDesc = adviceDsc
  4497. }
  4498. if dataBody["way"] == nil {
  4499. advice.Way = 0
  4500. } else {
  4501. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4502. way := int64(dataBody["way"].(float64))
  4503. advice.Way = way
  4504. }
  4505. }
  4506. if dataBody["drug_id"] == nil {
  4507. advice.DrugId = 0
  4508. } else {
  4509. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4510. drug_id := int64(dataBody["drug_id"].(float64))
  4511. advice.DrugId = drug_id
  4512. }
  4513. }
  4514. if dataBody["drug_name_id"] == nil {
  4515. advice.DrugNameId = 0
  4516. } else {
  4517. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4518. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  4519. advice.DrugNameId = drug_name_id
  4520. }
  4521. }
  4522. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4523. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4524. advice.SingleDose = singleDose
  4525. }
  4526. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4527. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4528. advice.SingleDoseUnit = singleDoseUnit
  4529. }
  4530. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4531. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4532. advice.DrugSpec = drugSpec
  4533. }
  4534. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4535. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4536. advice.DrugSpecUnit = drugSpecUnit
  4537. }
  4538. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4539. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4540. advice.PrescribingNumber = prescribingNumber
  4541. }
  4542. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4543. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4544. advice.PrescribingNumberUnit = prescribingNumberUnit
  4545. }
  4546. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4547. remark, _ := dataBody["remark"].(string)
  4548. advice.Remark = remark
  4549. }
  4550. return
  4551. }
  4552. func (c *PatientApiController) GetPatientEducation() {
  4553. patientID, _ := c.GetInt64("patient_id", 0)
  4554. page, _ := c.GetInt64("page", 0)
  4555. limit, _ := c.GetInt64("limit", 0)
  4556. startTime := c.GetString("start_time", "")
  4557. endTime := c.GetString("end_time", "")
  4558. if page <= 0 {
  4559. page = 1
  4560. }
  4561. if limit <= 0 {
  4562. limit = 10
  4563. }
  4564. if patientID <= 0 {
  4565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4566. return
  4567. }
  4568. timeLayout := "2006-01-02"
  4569. loc, _ := time.LoadLocation("Local")
  4570. var theStartTIme int64
  4571. if len(startTime) > 0 {
  4572. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4573. if err != nil {
  4574. theStartTIme = 0
  4575. }
  4576. theStartTIme = theTime.Unix()
  4577. }
  4578. var theEndtTIme int64
  4579. if len(endTime) > 0 {
  4580. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4581. if err != nil {
  4582. theEndtTIme = 0
  4583. }
  4584. theEndtTIme = theTime.Unix()
  4585. }
  4586. adminUserInfo := c.GetMobileAdminUserInfo()
  4587. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  4588. c.ServeSuccessJSON(map[string]interface{}{
  4589. "total": total,
  4590. "edus": edus,
  4591. })
  4592. return
  4593. }
  4594. func (c *PatientApiController) GetPatientSchedulesList() {
  4595. patientID, _ := c.GetInt64("patient_id", 0)
  4596. page, _ := c.GetInt64("page", 0)
  4597. limit, _ := c.GetInt64("limit", 0)
  4598. if patientID <= 0 {
  4599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4600. return
  4601. }
  4602. adminUserInfo := c.GetMobileAdminUserInfo()
  4603. todayTime := time.Now().Format("2006-01-02")
  4604. timeLayout := "2006-01-02 15:04:05"
  4605. loc, _ := time.LoadLocation("Local")
  4606. var theStartTime int64
  4607. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  4608. theStartTime = theTime.Unix()
  4609. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  4610. if len(schedules) > 0 {
  4611. for index, item := range schedules {
  4612. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  4613. schedules[index].Week = int64(week)
  4614. }
  4615. }
  4616. c.ServeSuccessJSON(map[string]interface{}{
  4617. "schedules": schedules,
  4618. })
  4619. return
  4620. }
  4621. func (c *PatientApiController) GetRecords() {
  4622. patientID, _ := c.GetInt64("patient_id", 0)
  4623. page, _ := c.GetInt64("page", 0)
  4624. limit, _ := c.GetInt64("limit", 0)
  4625. startTime := c.GetString("start_time", "")
  4626. endTime := c.GetString("end_time", "")
  4627. mode_id, _ := c.GetInt64("mode_id", 0)
  4628. if page <= 0 {
  4629. page = 1
  4630. }
  4631. if limit <= 0 {
  4632. limit = 10
  4633. }
  4634. if patientID <= 0 {
  4635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4636. return
  4637. }
  4638. timeLayout := "2006-01-02"
  4639. loc, _ := time.LoadLocation("Local")
  4640. var theStartTIme int64
  4641. if len(startTime) > 0 {
  4642. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4643. if err != nil {
  4644. theStartTIme = 0
  4645. }
  4646. theStartTIme = theTime.Unix()
  4647. }
  4648. var theEndtTIme int64
  4649. if len(endTime) > 0 {
  4650. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4651. if err != nil {
  4652. theEndtTIme = 0
  4653. }
  4654. theEndtTIme = theTime.Unix()
  4655. }
  4656. adminUserInfo := c.GetMobileAdminUserInfo()
  4657. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  4658. c.ServeSuccessJSON(map[string]interface{}{
  4659. "total": total,
  4660. "records": records,
  4661. })
  4662. return
  4663. }
  4664. func (c *PatientApiController) GetPatientMonitor() {
  4665. partition, _ := c.GetInt64("partition")
  4666. monitorDate := c.GetString("date")
  4667. patient_id, _ := c.GetInt64("patient_id")
  4668. timeLayout := "2006-01-02"
  4669. loc, _ := time.LoadLocation("Local")
  4670. var theStartTime int64
  4671. if len(monitorDate) > 0 {
  4672. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  4673. if err != nil {
  4674. theStartTime = 0
  4675. }
  4676. theStartTime = theTime.Unix()
  4677. }
  4678. adminInfo := c.GetMobileAdminUserInfo()
  4679. orgID := adminInfo.Org.Id
  4680. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  4681. if err != nil {
  4682. c.ErrorLog("获取排班信息失败:%v", err)
  4683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4684. } else {
  4685. if len(monitor) > 0 {
  4686. //获取所有床位
  4687. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  4688. //获取所有分区
  4689. zoneList, _ := service.GetAllZoneByList(orgID)
  4690. //获取透析处方
  4691. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  4692. //获取透前评估
  4693. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  4694. //获取上机
  4695. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  4696. //获取透后
  4697. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  4698. //获取透后监测
  4699. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  4700. //获取所有的患者
  4701. patients, _ := service.GetAllPatientListByListOne(orgID)
  4702. for _, it := range patients {
  4703. if orgID == 10445 {
  4704. if theStartTime <= 1703952000 {
  4705. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  4706. it.TotalDialysis = listOne.Count
  4707. }
  4708. if theStartTime >= 1704038400 {
  4709. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  4710. it.TotalDialysis = listOrder.Count
  4711. }
  4712. }
  4713. }
  4714. //获取所有透析模式
  4715. treatments, _ := service.GetAllTreatModeByList(orgID)
  4716. for key, item := range monitor {
  4717. // 获取床位信息
  4718. for _, it := range numberList {
  4719. if item.BedId == it.ID {
  4720. monitor[key].DeviceNumber = it
  4721. break
  4722. }
  4723. }
  4724. //获取分区信息
  4725. for _, it := range zoneList {
  4726. if item.PartitionId == it.ID {
  4727. monitor[key].DeviceZone = it
  4728. }
  4729. }
  4730. for _, prescription := range prescriptions {
  4731. if item.PatientId == prescription.PatientId {
  4732. monitor[key].Prescription = prescription
  4733. break
  4734. }
  4735. }
  4736. // 透前评估
  4737. for _, assessmentBefore := range assessmentBefores {
  4738. if item.PatientId == assessmentBefore.PatientId {
  4739. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  4740. break
  4741. }
  4742. }
  4743. // 透析上下机
  4744. for _, dialysisOrder := range dialysisOrders {
  4745. if item.PatientId == dialysisOrder.PatientId {
  4746. monitor[key].DialysisOrder = dialysisOrder
  4747. break
  4748. }
  4749. }
  4750. // 治疗小节
  4751. for _, afterDislysis := range AssessmentAfterDislysis {
  4752. if item.PatientId == afterDislysis.PatientId {
  4753. monitor[key].AssessmentAfterDislysis = afterDislysis
  4754. break
  4755. }
  4756. }
  4757. for _, it := range monitorlist {
  4758. if item.PatientId == it.PatientId {
  4759. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  4760. }
  4761. }
  4762. for _, patient := range patients {
  4763. if item.PatientId == patient.ID {
  4764. monitor[key].MonitorPatients = patient
  4765. break
  4766. }
  4767. }
  4768. for _, treatment := range treatments {
  4769. if item.ModeId == treatment.ID {
  4770. monitor[key].TreatmentMode = treatment
  4771. break
  4772. }
  4773. }
  4774. }
  4775. }
  4776. }
  4777. //获取患者的透析次数
  4778. //count, err := service.GetDialysisCount(orgID, partition)
  4779. patients, err := service.GetAllpatientFourty(orgID)
  4780. if err == nil {
  4781. c.ServeSuccessJSON(map[string]interface{}{
  4782. "monitor": monitor,
  4783. //"patientCount": count,
  4784. "patients": patients,
  4785. })
  4786. } else {
  4787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4788. }
  4789. }
  4790. // /m/api/monitor/patient [get] 搜索病人的测量记录
  4791. // @param keyword:string 病人姓名或透析号
  4792. // @param page:int
  4793. func (this *PatientApiController) SearchMonitorPatient() {
  4794. keyword := this.GetString("keyword")
  4795. page, _ := this.GetInt("page")
  4796. if page <= 0 {
  4797. page = 1
  4798. }
  4799. if len(keyword) == 0 {
  4800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4801. return
  4802. }
  4803. adminUserInfo := this.GetMobileAdminUserInfo()
  4804. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  4805. if getMonitorErr != nil {
  4806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4807. return
  4808. } else {
  4809. this.ServeSuccessJSON(map[string]interface{}{
  4810. "monitor": monitors,
  4811. })
  4812. }
  4813. }
  4814. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  4815. id, _ := c.GetInt64("id", 0)
  4816. page, _ := c.GetInt64("page", 0)
  4817. limit, _ := c.GetInt64("limit", 0)
  4818. if id <= 0 {
  4819. c.ServeSuccessJSON(map[string]interface{}{
  4820. "solutions": nil,
  4821. })
  4822. return
  4823. }
  4824. if page <= 0 {
  4825. page = 1
  4826. }
  4827. if limit <= 0 {
  4828. limit = 10
  4829. }
  4830. adminInfo := c.GetMobileAdminUserInfo()
  4831. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  4832. c.ServeSuccessJSON(map[string]interface{}{
  4833. "solutions": solutions,
  4834. "total": total,
  4835. })
  4836. return
  4837. }
  4838. // GetDoctorAdvices 医嘱列表
  4839. func (c *PatientApiController) GetDoctorAdvices() {
  4840. id, _ := c.GetInt64("id", 0)
  4841. adviceType, _ := c.GetInt64("advice_type", 0)
  4842. stopType, _ := c.GetInt64("stop_state", 0)
  4843. startTime := c.GetString("start_time", "")
  4844. endTime := c.GetString("end_time", "")
  4845. keywords := c.GetString("keywords", "")
  4846. need, _ := c.GetInt64("need_doctor", 0)
  4847. adminUserInfo := c.GetMobileAdminUserInfo()
  4848. timeLayout := "2006-01-02"
  4849. loc, _ := time.LoadLocation("Local")
  4850. var theStartTIme int64
  4851. if len(startTime) > 0 {
  4852. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4853. if err != nil {
  4854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4855. return
  4856. }
  4857. theStartTIme = theTime.Unix()
  4858. }
  4859. var theEndtTIme int64
  4860. if len(endTime) > 0 {
  4861. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4862. if err != nil {
  4863. utils.ErrorLog(err.Error())
  4864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4865. return
  4866. }
  4867. theEndtTIme = theTime.Unix()
  4868. }
  4869. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  4870. if need == 1 {
  4871. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4872. c.ServeSuccessJSON(map[string]interface{}{
  4873. "advices": advices,
  4874. "total": total,
  4875. "users": users,
  4876. })
  4877. } else {
  4878. c.ServeSuccessJSON(map[string]interface{}{
  4879. "advices": advices,
  4880. "total": total,
  4881. "users": []string{},
  4882. })
  4883. }
  4884. return
  4885. }
  4886. func (c *PatientApiController) GetPrintDialysisOrder() {
  4887. xtno := c.GetString("xtno")
  4888. xtdate := c.GetString("xtdate")
  4889. timeLayout := "2006-01-02"
  4890. loc, _ := time.LoadLocation("Local")
  4891. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4892. if err != nil {
  4893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4894. return
  4895. }
  4896. xttime := theTime.Unix()
  4897. //获取当前日期月份的第一天
  4898. firstmonth := service.GetFirstDateOfMonth(theTime)
  4899. firstMonthDate := firstmonth.Unix()
  4900. operatorIDs := make([]int64, 0)
  4901. adminUserInfo := c.GetMobileAdminUserInfo()
  4902. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4903. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4904. //透析单
  4905. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4906. if dialysisOrder != nil {
  4907. if dialysisOrder.FinishNurse > 0 {
  4908. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4909. }
  4910. if dialysisOrder.StartNurse > 0 {
  4911. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4912. }
  4913. }
  4914. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4915. //透前评估
  4916. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4917. //透后评估
  4918. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4919. if AssessmentAfterDislysis.Modifier > 0 {
  4920. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4921. }
  4922. //透析处方
  4923. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4924. if dialysisPrescription.PrescriptionDoctor > 0 {
  4925. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4926. }
  4927. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4928. patientInfo.TotalDialysis = dialysis_count
  4929. //临时医嘱
  4930. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4931. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4932. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4933. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4934. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4935. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4936. if adminUserInfo.Org.Id != 10489 {
  4937. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4938. for _, item := range projects {
  4939. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4940. var advice models.HisDoctorAdviceInfo
  4941. advice.ID = item.ID
  4942. advice.Checker = item.Checker
  4943. advice.CheckTime = item.CheckTime
  4944. advice.CheckState = item.CheckState
  4945. advice.ExecutionState = item.ExecutionState
  4946. advice.ExecutionStaff = item.ExecutionStaff
  4947. //advice.PrescribingNumber = float64(item.Count)
  4948. advice.PrescribingNumber = cnt
  4949. advice.PrescribingNumberUnit = item.Unit
  4950. advice.AdviceDoctor = item.Doctor
  4951. advice.Remark = item.Remark
  4952. if item.Type == 3 {
  4953. advice.AdviceName = item.GoodInfo.GoodName
  4954. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4955. } else if item.Type == 2 {
  4956. advice.AdviceName = item.HisProject.ProjectName
  4957. }
  4958. advice.StartTime = item.StartTime
  4959. hisAdvice = append(hisAdvice, &advice)
  4960. }
  4961. }
  4962. }
  4963. if len(DoctorAdvice) > 0 {
  4964. for _, item := range DoctorAdvice {
  4965. if item.AdviceDoctor > 0 {
  4966. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4967. }
  4968. if item.ExecutionStaff > 0 {
  4969. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4970. }
  4971. if item.Checker > 0 {
  4972. operatorIDs = append(operatorIDs, item.Checker)
  4973. }
  4974. }
  4975. }
  4976. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4977. //透析监测
  4978. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4979. //透析小结
  4980. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4981. //接诊评估
  4982. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4983. if receiverTreatmentAccess.Condition == 1 {
  4984. if len(receiverTreatmentAccess.AdmissionNumber) == 0 || receiverTreatmentAccess.AdmissionNumber == "" {
  4985. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, patientInfo.ID)
  4986. receiverTreatmentAccess.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  4987. receiverTreatmentAccess.HisDepartment = lastAcceptTreatment.HisDepartment
  4988. receiverTreatmentAccess.HisBed = lastAcceptTreatment.HisBed
  4989. }
  4990. }
  4991. //相关操作对应的操作人
  4992. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  4993. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  4994. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4995. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4996. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  4997. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4998. numberList, _ := service.GetAllBedNumberList(adminUserInfo.Org.Id)
  4999. if config.IsOpen == 1 {
  5000. c.ServeSuccessJSON(map[string]interface{}{
  5001. "users": adminUser,
  5002. "patientInfo": patientInfo,
  5003. "PredialysisEvaluation": PredialysisEvaluation,
  5004. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  5005. "dialysisPrescription": dialysisPrescription,
  5006. "advices": hisAdvice,
  5007. "monitors": Record,
  5008. "summary": TreatmentSummary,
  5009. "receiverTreatmentAccess": receiverTreatmentAccess,
  5010. "dialysisOrder": dialysisOrder,
  5011. "operators": operators,
  5012. "org_template_info": templateInfo,
  5013. "check": check,
  5014. "dialysiscount": dialysiscount,
  5015. "last_order": last_order,
  5016. "projects": projects,
  5017. "project_config": project_config,
  5018. "lastWeight": lastWeight,
  5019. "lastSchedule": lastSchedule,
  5020. "DoctorAdvice": DoctorAdvice,
  5021. "hisAdvice": hisAdvice,
  5022. "numberList": numberList,
  5023. })
  5024. }
  5025. if config.IsOpen == 0 || config.IsOpen == 2 {
  5026. c.ServeSuccessJSON(map[string]interface{}{
  5027. "users": adminUser,
  5028. "patientInfo": patientInfo,
  5029. "PredialysisEvaluation": PredialysisEvaluation,
  5030. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  5031. "dialysisPrescription": dialysisPrescription,
  5032. "advices": DoctorAdvice,
  5033. "monitors": Record,
  5034. "summary": TreatmentSummary,
  5035. "receiverTreatmentAccess": receiverTreatmentAccess,
  5036. "dialysisOrder": dialysisOrder,
  5037. "operators": operators,
  5038. "org_template_info": templateInfo,
  5039. "check": check,
  5040. "dialysiscount": dialysiscount,
  5041. "last_order": last_order,
  5042. "projects": projects,
  5043. "project_config": project_config,
  5044. "lastWeight": lastWeight,
  5045. "lastSchedule": lastSchedule,
  5046. "DoctorAdvice": DoctorAdvice,
  5047. "hisAdvice": hisAdvice,
  5048. "numberList": numberList,
  5049. })
  5050. }
  5051. }
  5052. func (c *PatientApiController) CreateGroupAdvice() {
  5053. is_child, _ := c.GetInt64("is_child", 0)
  5054. if is_child == 1 {
  5055. patient, _ := c.GetInt64("id", 0)
  5056. if patient <= 0 {
  5057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5058. return
  5059. }
  5060. adminUserInfo := c.GetMobileAdminUserInfo()
  5061. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5062. if patientInfo.ID == 0 {
  5063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5064. return
  5065. }
  5066. group_no, _ := c.GetInt64("group_no")
  5067. if group_no <= 0 {
  5068. group_no = 0
  5069. }
  5070. dataBody := make(map[string]interface{}, 0)
  5071. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5072. if err != nil {
  5073. utils.ErrorLog(err.Error())
  5074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5075. return
  5076. }
  5077. timeLayout := "2006-01-02"
  5078. loc, _ := time.LoadLocation("Local")
  5079. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5080. utils.ErrorLog("advice_type")
  5081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5082. return
  5083. }
  5084. adviceType := int64(dataBody["advice_type"].(float64))
  5085. if adviceType != 1 && adviceType != 2 {
  5086. utils.ErrorLog("advice_type != 1&&2")
  5087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5088. return
  5089. }
  5090. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5091. utils.ErrorLog("start_time")
  5092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5093. return
  5094. }
  5095. startTime2, _ := dataBody["start_time"].(string)
  5096. time_arr := strings.Split(startTime2, " ")
  5097. if len(time_arr) > 0 {
  5098. startTime2 = time_arr[0]
  5099. }
  5100. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5101. utils.ErrorLog("advice_date")
  5102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5103. return
  5104. }
  5105. advice_date, _ := dataBody["advice_date"].(string)
  5106. var advicedateunix int64
  5107. if len(advice_date) > 0 {
  5108. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  5109. if err != nil {
  5110. fmt.Println(err)
  5111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5112. return
  5113. }
  5114. advicedateunix = theTime.Unix()
  5115. }
  5116. adviceDate := startTime2
  5117. if len(adviceDate) == 0 {
  5118. utils.ErrorLog("len(adviceDate) == 0")
  5119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5120. return
  5121. }
  5122. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  5123. if err != nil {
  5124. utils.ErrorLog(err.Error())
  5125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5126. return
  5127. }
  5128. AdviceDate := advicedateunix
  5129. RecordDate := advicedateunix
  5130. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5131. utils.ErrorLog("start_time")
  5132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5133. return
  5134. }
  5135. startTime, _ := dataBody["start_time"].(string)
  5136. if len(startTime) == 0 {
  5137. utils.ErrorLog("len(start_time) == 0")
  5138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5139. return
  5140. }
  5141. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  5142. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  5143. if err != nil {
  5144. utils.ErrorLog(err.Error())
  5145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5146. return
  5147. }
  5148. StartTime := theTime.Unix()
  5149. Remark := ""
  5150. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5151. remark, _ := dataBody["remark"].(string)
  5152. Remark = remark
  5153. }
  5154. Startdate := int64(dataBody["record_date"].(float64))
  5155. var advices []*models.GroupAdvice
  5156. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  5157. utils.ErrorLog("adviceNames")
  5158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5159. return
  5160. }
  5161. adviceNames := dataBody["adviceNames"].([]interface{})
  5162. for _, adviceNameMap := range adviceNames {
  5163. adviceNameM := adviceNameMap.(map[string]interface{})
  5164. var advice models.GroupAdvice
  5165. advice.Remark = Remark
  5166. advice.AdviceType = adviceType
  5167. advice.StartTime = StartTime
  5168. if adminUserInfo.Org.Id == 10340 {
  5169. advice.AdviceDate = AdviceDate
  5170. advice.RecordDate = RecordDate
  5171. }
  5172. if adminUserInfo.Org.Id != 10340 {
  5173. advice.AdviceDate = theTimeOne.Unix()
  5174. advice.RecordDate = theTimeOne.Unix()
  5175. }
  5176. advice.Status = 1
  5177. advice.CreatedTime = time.Now().Unix()
  5178. advice.UpdatedTime = time.Now().Unix()
  5179. advice.StopState = 2
  5180. advice.ExecutionState = 2
  5181. advice.UserOrgId = adminUserInfo.Org.Id
  5182. advice.PatientId = patientInfo.ID
  5183. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5184. advice.IsSettle = 2
  5185. //入口
  5186. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  5187. if errcode > 0 {
  5188. c.ServeFailJSONWithSGJErrorCode(errcode)
  5189. return
  5190. }
  5191. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  5192. subdrugs := adviceNameM["subdrugs"].([]interface{})
  5193. if len(subdrugs) > 0 {
  5194. for _, subdrug := range subdrugs {
  5195. var s models.GroupAdvice
  5196. s.Remark = Remark
  5197. s.AdviceType = adviceType
  5198. s.StartTime = StartTime
  5199. s.AdviceDate = AdviceDate
  5200. s.RecordDate = RecordDate
  5201. s.Status = 1
  5202. s.CreatedTime = time.Now().Unix()
  5203. s.UpdatedTime = time.Now().Unix()
  5204. s.StopState = 2
  5205. s.ExecutionState = 2
  5206. s.UserOrgId = adminUserInfo.Org.Id
  5207. s.PatientId = patientInfo.ID
  5208. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  5209. s.IsSettle = 2
  5210. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  5211. if errcode > 0 {
  5212. c.ServeFailJSONWithSGJErrorCode(errcode)
  5213. return
  5214. }
  5215. advice.Children = append(advice.Children, &s)
  5216. }
  5217. }
  5218. }
  5219. //长沙南雅
  5220. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5221. //查询该患者今日有没有双人核对
  5222. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  5223. if check.ID > 0 {
  5224. advice.Checker = check.Modifier
  5225. advice.CheckState = 1
  5226. advice.CheckTime = time.Now().Unix()
  5227. }
  5228. }
  5229. advices = append(advices, &advice)
  5230. }
  5231. // 查询信息规挡的设置天数
  5232. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5233. if infor.ID > 0 && infor.WeekDay > 0 {
  5234. var cha_time int64
  5235. timeNowStr := time.Now().Format("2006-01-02")
  5236. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5237. //今日的日期减去设置的日期
  5238. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5239. if cha_time >= Startdate {
  5240. //查询审核是否允许
  5241. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  5242. //申请状态不允许的情况 拒绝修改
  5243. if infor.ApplicationStatus != 1 {
  5244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5245. return
  5246. }
  5247. }
  5248. }
  5249. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  5250. for _, item := range advices {
  5251. //记录日志
  5252. byterequest, _ := json.Marshal(item)
  5253. adviceLog := models.XtDoctorAdviceLog{
  5254. UserOrgId: item.UserOrgId,
  5255. PatientId: item.PatientId,
  5256. AdminUserId: adminUserInfo.AdminUser.Id,
  5257. Module: 1,
  5258. ErrLog: string(byterequest),
  5259. Status: 1,
  5260. Ctime: time.Now().Unix(),
  5261. Mtime: 0,
  5262. Source: "手机端新增医嘱",
  5263. RecordDate: item.AdviceDate,
  5264. }
  5265. service.CreateDoctorAdviceLog(adviceLog)
  5266. }
  5267. finish := models.XtDialysisFinish{
  5268. IsFinish: 1,
  5269. UserOrgId: adminUserInfo.Org.Id,
  5270. Status: 1,
  5271. Ctime: time.Now().Unix(),
  5272. Mtime: 0,
  5273. Module: 4,
  5274. RecordDate: advicedateunix,
  5275. Sourse: 1,
  5276. PatientId: patient,
  5277. }
  5278. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  5279. if dialysisFinish.ID == 0 {
  5280. service.CreateDialysisFinish(finish)
  5281. }
  5282. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  5283. redis := service.RedisClient()
  5284. //清空key 值
  5285. redis.Set(key, "", time.Second)
  5286. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5287. redis.Set(keyOne, "", time.Second)
  5288. defer redis.Close()
  5289. if createErr != nil {
  5290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5291. return
  5292. }
  5293. c.ServeSuccessJSON(map[string]interface{}{
  5294. "msg": "ok",
  5295. "advices": newAdvices,
  5296. })
  5297. return
  5298. } else if is_child == 2 {
  5299. patient, _ := c.GetInt64("id", 0)
  5300. if patient <= 0 {
  5301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5302. return
  5303. }
  5304. adminUserInfo := c.GetMobileAdminUserInfo()
  5305. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5306. if patientInfo.ID == 0 {
  5307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5308. return
  5309. }
  5310. var advice models.DoctorAdvice
  5311. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  5312. if code > 0 {
  5313. c.ServeFailJSONWithSGJErrorCode(code)
  5314. return
  5315. }
  5316. if advice.ParentId > 0 {
  5317. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  5318. if old.ID == 0 || old.PatientId != patient {
  5319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  5320. return
  5321. }
  5322. if old.StopState == 1 || old.ExecutionState == 1 {
  5323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  5324. return
  5325. }
  5326. if old.ParentId > 0 {
  5327. advice.ParentId = old.ParentId
  5328. }
  5329. advice.StartTime = old.StartTime
  5330. advice.AdviceDoctor = old.AdviceDoctor
  5331. advice.DeliveryWay = old.DeliveryWay
  5332. advice.ExecutionFrequency = old.ExecutionFrequency
  5333. advice.GroupNo = old.GroupNo
  5334. }
  5335. advice.Status = 1
  5336. advice.CreatedTime = time.Now().Unix()
  5337. advice.UpdatedTime = time.Now().Unix()
  5338. advice.StopState = 2
  5339. advice.ExecutionState = 2
  5340. advice.UserOrgId = adminUserInfo.Org.Id
  5341. advice.PatientId = patient
  5342. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5343. advice.IsSettle = 2
  5344. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5345. if advice.PrescribingNumber == 0 {
  5346. advice.PrescribingNumber = 1
  5347. }
  5348. //查询该患者今日有没有双人核对
  5349. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  5350. if check.ID > 0 {
  5351. advice.Checker = check.Modifier
  5352. advice.CheckState = 1
  5353. advice.CheckTime = time.Now().Unix()
  5354. }
  5355. }
  5356. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5357. if infor.ID > 0 {
  5358. var cha_time int64
  5359. timeNowStr := time.Now().Format("2006-01-02")
  5360. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5361. //今日的日期减去设置的日期
  5362. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5363. if cha_time >= advice.RecordDate {
  5364. //查询审核是否允许
  5365. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  5366. //申请状态不允许的情况 拒绝修改
  5367. if infor.ApplicationStatus != 1 {
  5368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5369. return
  5370. }
  5371. }
  5372. }
  5373. err := service.CreateDoctorAdvice(&advice)
  5374. //记录日志
  5375. byterequest, _ := json.Marshal(advice)
  5376. adviceLog := models.XtDoctorAdviceLog{
  5377. UserOrgId: advice.UserOrgId,
  5378. PatientId: advice.PatientId,
  5379. AdminUserId: adminUserInfo.Org.Id,
  5380. Module: 1,
  5381. ErrLog: string(byterequest),
  5382. Status: 1,
  5383. Ctime: time.Now().Unix(),
  5384. Mtime: 0,
  5385. Source: "手机端新增医嘱",
  5386. RecordDate: advice.AdviceDate,
  5387. }
  5388. service.CreateDoctorAdviceLog(adviceLog)
  5389. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5390. redis := service.RedisClient()
  5391. //清空key 值
  5392. redis.Set(key, "", time.Second)
  5393. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5394. redis.Set(keyOne, "", time.Second)
  5395. defer redis.Close()
  5396. if err != nil {
  5397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5398. return
  5399. }
  5400. c.ServeSuccessJSON(map[string]interface{}{
  5401. "msg": "ok",
  5402. "advice": advice,
  5403. })
  5404. return
  5405. }
  5406. }
  5407. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  5408. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  5409. utils.ErrorLog("advice_name")
  5410. return enums.ErrorCodeParamWrong
  5411. }
  5412. adviceName, _ := json["advice_name"].(string)
  5413. if len(adviceName) == 0 {
  5414. utils.ErrorLog("len(advice_name) == 0")
  5415. return enums.ErrorCodeParamWrong
  5416. }
  5417. advice.AdviceName = adviceName
  5418. adviceDesc, _ := json["advice_desc"].(string)
  5419. advice.AdviceDesc = adviceDesc
  5420. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5421. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5422. advice.DrugSpec = drugSpec
  5423. }
  5424. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5425. remark, _ := json["remark"].(string)
  5426. advice.Remark = remark
  5427. }
  5428. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  5429. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  5430. // advice.Way = src_type
  5431. //}
  5432. if json["way"] == nil {
  5433. advice.Way = 0
  5434. } else {
  5435. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  5436. way := int64(json["way"].(float64))
  5437. advice.Way = way
  5438. }
  5439. }
  5440. if json["drug_id"] == nil {
  5441. advice.DrugId = 0
  5442. } else {
  5443. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  5444. drug_id := int64(json["drug_id"].(float64))
  5445. advice.DrugId = drug_id
  5446. }
  5447. }
  5448. if json["drug_name_id"] == nil {
  5449. advice.DrugNameId = 0
  5450. } else {
  5451. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  5452. drug_name_id := int64(json["drug_name_id"].(float64))
  5453. advice.DrugNameId = drug_name_id
  5454. }
  5455. }
  5456. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  5457. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  5458. advice.DrugSpecUnit = drugSpecUnit
  5459. }
  5460. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5461. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5462. advice.SingleDose = singleDose
  5463. }
  5464. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5465. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5466. advice.SingleDoseUnit = singleDoseUnit
  5467. }
  5468. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5469. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5470. advice.PrescribingNumber = prescribingNumber
  5471. }
  5472. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5473. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5474. advice.PrescribingNumberUnit = prescribingNumberUnit
  5475. }
  5476. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5477. deliveryWay, _ := json["delivery_way"].(string)
  5478. advice.DeliveryWay = deliveryWay
  5479. }
  5480. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5481. executionFrequency, _ := json["execution_frequency"].(string)
  5482. advice.ExecutionFrequency = executionFrequency
  5483. }
  5484. return 0
  5485. }
  5486. func (c *PatientApiController) DelDoctorAdvice() {
  5487. groupno, _ := c.GetInt64("groupno", -1)
  5488. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  5489. patient_id, _ := c.GetInt64("patient_id")
  5490. doc_advice_date, _ := c.GetInt64("advice_date")
  5491. redis := service.RedisClient()
  5492. if is_sub == 1 { //是
  5493. advice_id, _ := c.GetInt64("advice_id")
  5494. adminUserInfo := c.GetMobileAdminUserInfo()
  5495. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5496. if advice.ID == 0 {
  5497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5498. return
  5499. }
  5500. advice.Status = 0
  5501. advice.UpdatedTime = time.Now().Unix()
  5502. advice.Modifier = adminUserInfo.AdminUser.Id
  5503. // 查询信息规挡的设置天数
  5504. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5505. if infor.ID > 0 && infor.WeekDay > 0 {
  5506. var cha_time int64
  5507. timeNowStr := time.Now().Format("2006-01-02")
  5508. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5509. //今日的日期减去设置的日期
  5510. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5511. if cha_time >= advice.AdviceDate {
  5512. //查询审核是否允许
  5513. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5514. //申请状态不允许的情况 拒绝修改
  5515. if infor.ApplicationStatus != 1 {
  5516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5517. return
  5518. }
  5519. }
  5520. }
  5521. //自备药
  5522. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5523. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5524. //查询库存是否是自备药
  5525. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5526. if selfBasedrug.IsSelfDrug == 1 {
  5527. creater := adminUserInfo.AdminUser.Id
  5528. //退库
  5529. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5530. }
  5531. }
  5532. err := service.DeleteDoctorAdvice(&advice)
  5533. //记录日志
  5534. byterequest, _ := json.Marshal(advice)
  5535. adviceLog := models.XtDoctorAdviceLog{
  5536. UserOrgId: advice.UserOrgId,
  5537. PatientId: advice.PatientId,
  5538. AdminUserId: adminUserInfo.AdminUser.Id,
  5539. Module: 4,
  5540. ErrLog: string(byterequest),
  5541. Status: 1,
  5542. Ctime: time.Now().Unix(),
  5543. Mtime: 0,
  5544. Source: "手机端删除医嘱",
  5545. RecordDate: advice.RecordDate,
  5546. }
  5547. service.CreateDoctorAdviceLog(adviceLog)
  5548. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5549. redis.Set(key, "", time.Second)
  5550. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5551. redis.Set(keyTwo, "", time.Second)
  5552. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5553. redis.Set(keyThree, "", time.Second)
  5554. redis.Close()
  5555. if err != nil {
  5556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5557. return
  5558. }
  5559. c.ServeSuccessJSON(map[string]interface{}{
  5560. "msg": "ok",
  5561. })
  5562. return
  5563. } else { //
  5564. var ids []string
  5565. if groupno == 0 {
  5566. advice_id := c.GetString("advice_id")
  5567. ids = strings.Split(advice_id, ",")
  5568. if len(ids) <= 0 {
  5569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5570. return
  5571. }
  5572. }
  5573. if groupno < 0 {
  5574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5575. return
  5576. }
  5577. adminUserInfo := c.GetMobileAdminUserInfo()
  5578. var advice models.DoctorAdvice
  5579. if groupno > 0 {
  5580. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  5581. if advice.ID == 0 {
  5582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5583. return
  5584. }
  5585. } else {
  5586. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  5587. for _, item := range advices {
  5588. if item.ID == 0 {
  5589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5590. return
  5591. }
  5592. }
  5593. }
  5594. advice.UpdatedTime = time.Now().Unix()
  5595. advice.Status = 0
  5596. advice.GroupNo = groupno
  5597. advice.Modifier = adminUserInfo.AdminUser.Id
  5598. var err error
  5599. if groupno > 0 {
  5600. // 查询信息规挡的设置天数
  5601. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5602. if infor.ID > 0 {
  5603. var cha_time int64
  5604. timeNowStr := time.Now().Format("2006-01-02")
  5605. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5606. //今日的日期减去设置的日期
  5607. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5608. if cha_time >= advice.AdviceDate {
  5609. //查询审核是否允许
  5610. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5611. //申请状态不允许的情况 拒绝修改
  5612. if infor.ApplicationStatus != 1 {
  5613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5614. return
  5615. }
  5616. }
  5617. }
  5618. //自备药
  5619. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5620. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5621. //查询库存是否是自备药
  5622. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5623. if selfBasedrug.IsSelfDrug == 1 {
  5624. creater := adminUserInfo.AdminUser.Id
  5625. //退库
  5626. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5627. }
  5628. }
  5629. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  5630. //记录日志
  5631. byterequest, _ := json.Marshal(advice)
  5632. adviceLog := models.XtDoctorAdviceLog{
  5633. UserOrgId: advice.UserOrgId,
  5634. PatientId: advice.PatientId,
  5635. AdminUserId: adminUserInfo.AdminUser.Id,
  5636. Module: 4,
  5637. ErrLog: string(byterequest),
  5638. Status: 1,
  5639. Ctime: time.Now().Unix(),
  5640. Mtime: 0,
  5641. Source: "手机端删除医嘱",
  5642. RecordDate: advice.RecordDate,
  5643. }
  5644. service.CreateDoctorAdviceLog(adviceLog)
  5645. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5646. redis.Set(key, "", time.Second)
  5647. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5648. redis.Set(keyTwo, "", time.Second)
  5649. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5650. redis.Set(keyThree, "", time.Second)
  5651. } else {
  5652. // 查询信息规挡的设置天数
  5653. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5654. if infor.ID > 0 {
  5655. var cha_time int64
  5656. timeNowStr := time.Now().Format("2006-01-02")
  5657. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5658. //今日的日期减去设置的日期
  5659. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5660. if cha_time >= advice.AdviceDate {
  5661. //查询审核是否允许
  5662. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5663. //申请状态不允许的情况 拒绝修改
  5664. if infor.ApplicationStatus != 1 {
  5665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5666. return
  5667. }
  5668. }
  5669. }
  5670. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  5671. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  5672. for _, item := range advicelist {
  5673. //自备药
  5674. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5675. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5676. //查询库存是否是自备药
  5677. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(item.DrugId, item.UserOrgId)
  5678. if selfBasedrug.IsSelfDrug == 1 {
  5679. creater := adminUserInfo.AdminUser.Id
  5680. //退库
  5681. service.SelfDrugAutoAddCancelInfoOne(item, creater)
  5682. }
  5683. }
  5684. //记录日志
  5685. byterequest, _ := json.Marshal(item)
  5686. adviceLog := models.XtDoctorAdviceLog{
  5687. UserOrgId: item.UserOrgId,
  5688. PatientId: item.PatientId,
  5689. AdminUserId: adminUserInfo.AdminUser.Id,
  5690. Module: 4,
  5691. ErrLog: string(byterequest),
  5692. Status: 1,
  5693. Ctime: time.Now().Unix(),
  5694. Mtime: 0,
  5695. Source: "手机端批量删除医嘱",
  5696. RecordDate: item.RecordDate,
  5697. }
  5698. service.CreateDoctorAdviceLog(adviceLog)
  5699. }
  5700. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5701. redis.Set(key, "", time.Second)
  5702. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5703. redis.Set(keyTwo, "", time.Second)
  5704. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5705. redis.Set(keyThree, "", time.Second)
  5706. redis.Close()
  5707. }
  5708. if err != nil {
  5709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5710. return
  5711. }
  5712. c.ServeSuccessJSON(map[string]interface{}{
  5713. "msg": "ok",
  5714. })
  5715. return
  5716. }
  5717. }
  5718. // /m/api/advice/group/modify_starttime [post]
  5719. // @param group_no:int
  5720. // @param start_time:string yyyy-MM-dd hh:mm:ss
  5721. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  5722. group_no, _ := this.GetInt64("group_no")
  5723. start_time_str := this.GetString("start_time")
  5724. if group_no <= 0 || len(start_time_str) == 0 {
  5725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5726. return
  5727. }
  5728. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  5729. if parseTimeErr != nil {
  5730. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  5731. return
  5732. }
  5733. adminUserInfo := this.GetMobileAdminUserInfo()
  5734. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  5735. if updateStartTimeErr != nil {
  5736. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  5737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5738. return
  5739. }
  5740. this.ServeSuccessJSON(map[string]interface{}{
  5741. "start_time": startTime.Unix(),
  5742. })
  5743. }
  5744. func (this *PatientApiController) DelSubDoctorAdvice() {
  5745. advice_id, _ := this.GetInt64("advice_id")
  5746. adminUserInfo := this.GetMobileAdminUserInfo()
  5747. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5748. if advice.ID == 0 {
  5749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5750. return
  5751. }
  5752. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  5753. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  5754. // return
  5755. //}
  5756. advice.Status = 0
  5757. advice.UpdatedTime = time.Now().Unix()
  5758. advice.Modifier = adminUserInfo.AdminUser.Id
  5759. err := service.DeleteDoctorAdvice(&advice)
  5760. if err != nil {
  5761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5762. return
  5763. }
  5764. this.ServeSuccessJSON(map[string]interface{}{
  5765. "msg": "ok",
  5766. })
  5767. return
  5768. }
  5769. func (this *PatientApiController) GetAdviceUnReadMessage() {
  5770. //adminUserInfo := this.GetMobileAdminUserInfo()
  5771. //service.FindUnReadDoctorAdviceMessage()
  5772. }
  5773. func (this *PatientApiController) GetPatientsByKeyWord() {
  5774. keyWord := this.GetString("keyword")
  5775. adminUserInfo := this.GetMobileAdminUserInfo()
  5776. today := utils.ZeroHourTimeOfDay(time.Now())
  5777. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  5778. if err != nil {
  5779. utils.ErrorLog(err.Error())
  5780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5781. return
  5782. }
  5783. this.ServeSuccessJSON(map[string]interface{}{
  5784. "patient": patient,
  5785. })
  5786. }
  5787. func (this *PatientApiController) GetSearchPatient() {
  5788. keyWord := this.GetString("keyword")
  5789. adminUserInfo := this.GetMobileAdminUserInfo()
  5790. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  5791. if err != nil {
  5792. utils.ErrorLog(err.Error())
  5793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5794. return
  5795. }
  5796. this.ServeSuccessJSON(map[string]interface{}{
  5797. "patient": patient,
  5798. })
  5799. }
  5800. func (c *PatientApiController) ExecProject() {
  5801. execution_time := c.GetString("execution_time")
  5802. project_id, _ := c.GetInt64("project_id")
  5803. team_id, _ := c.GetInt64("team_id")
  5804. is_check_team, _ := c.GetInt64("is_check_team")
  5805. record_date, _ := c.GetInt64("record_date")
  5806. patient_id, _ := c.GetInt64("patient_id")
  5807. if len(execution_time) <= 0 {
  5808. utils.ErrorLog("execution_time")
  5809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5810. return
  5811. }
  5812. timeLayout2 := "2006-01-02 15:04:05"
  5813. loc, _ := time.LoadLocation("Local")
  5814. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  5815. if errs != nil {
  5816. utils.ErrorLog(errs.Error())
  5817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5818. return
  5819. }
  5820. adminInfo := c.GetMobileAdminUserInfo()
  5821. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5822. //针对舒和
  5823. if adminInfo.Org.Id == 10644 {
  5824. if project.StartTime > theTime.Unix() {
  5825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  5826. return
  5827. }
  5828. }
  5829. if project.Type == 3 {
  5830. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  5831. if good.IsUser != 1 {
  5832. //查询开关是否开启
  5833. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5834. //开关已经开启
  5835. if stockSetting.IsType == 1 {
  5836. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5837. scheduleDateStart := theTime.Format("2006-01-02")
  5838. timeLayout3 := "2006-01-02"
  5839. loc, _ := time.LoadLocation("Local")
  5840. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5841. //查询该耗材是否已经出库
  5842. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5843. if auto.ID == 0 {
  5844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5845. return
  5846. }
  5847. }
  5848. }
  5849. if good.IsUser == 1 && good.IsWarehouse == 1 {
  5850. //查询开关是否开启
  5851. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5852. //开关已经开启
  5853. if stockSetting.IsType == 1 {
  5854. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5855. scheduleDateStart := theTime.Format("2006-01-02")
  5856. timeLayout3 := "2006-01-02"
  5857. loc, _ := time.LoadLocation("Local")
  5858. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5859. //查询该耗材是否已经出库
  5860. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5861. if auto.ID == 0 {
  5862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5863. return
  5864. }
  5865. }
  5866. }
  5867. }
  5868. if project.ExecutionState == 1 {
  5869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  5870. return
  5871. }
  5872. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  5873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5874. return
  5875. }
  5876. project.ExecutionState = 1
  5877. project.ExecutionStaff = adminInfo.AdminUser.Id
  5878. project.ExecutionTime = theTime.Unix()
  5879. if team_id == 0 {
  5880. // 查询信息规挡的设置天数
  5881. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5882. if infor.ID > 0 {
  5883. var cha_time int64
  5884. timeNowStr := time.Now().Format("2006-01-02")
  5885. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5886. //今日的日期减去设置的日期
  5887. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5888. if cha_time >= project.RecordDate {
  5889. //查询审核是否允许
  5890. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5891. //申请状态不允许的情况 拒绝修改
  5892. if infor.ApplicationStatus != 1 {
  5893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5894. return
  5895. }
  5896. }
  5897. }
  5898. err := service.SaveHisProject(&project)
  5899. if err == nil {
  5900. c.ServeSuccessJSON(map[string]interface{}{
  5901. "project": project,
  5902. })
  5903. } else {
  5904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5905. return
  5906. }
  5907. } else {
  5908. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5909. // 查询信息规挡的设置天数
  5910. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5911. if infor.ID > 0 {
  5912. var cha_time int64
  5913. timeNowStr := time.Now().Format("2006-01-02")
  5914. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5915. //今日的日期减去设置的日期
  5916. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5917. if cha_time >= project.RecordDate {
  5918. //查询审核是否允许
  5919. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5920. //申请状态不允许的情况 拒绝修改
  5921. if infor.ApplicationStatus != 1 {
  5922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5923. return
  5924. }
  5925. }
  5926. }
  5927. err := service.SaveHisProject(&project)
  5928. if err == nil {
  5929. c.ServeSuccessJSON(map[string]interface{}{
  5930. "project": project,
  5931. })
  5932. } else {
  5933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5934. return
  5935. }
  5936. } else {
  5937. // 查询信息规挡的设置天数
  5938. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5939. if infor.ID > 0 {
  5940. var cha_time int64
  5941. timeNowStr := time.Now().Format("2006-01-02")
  5942. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5943. //今日的日期减去设置的日期
  5944. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5945. if cha_time >= project.RecordDate {
  5946. //查询审核是否允许
  5947. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5948. //申请状态不允许的情况 拒绝修改
  5949. if infor.ApplicationStatus != 1 {
  5950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5951. return
  5952. }
  5953. }
  5954. }
  5955. ps, _ := service.GetCheckTeamProjectOne(team_id, patient_id, record_date, adminInfo.Org.Id)
  5956. var ids []int64
  5957. for _, items := range ps {
  5958. ids = append(ids, items.ID)
  5959. }
  5960. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5961. if err == nil {
  5962. c.ServeSuccessJSON(map[string]interface{}{
  5963. "project": project,
  5964. })
  5965. } else {
  5966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5967. return
  5968. }
  5969. }
  5970. }
  5971. }
  5972. func (c *PatientApiController) CheckProject() {
  5973. adminInfo := c.GetMobileAdminUserInfo()
  5974. project_id, _ := c.GetInt64("project_id")
  5975. team_id, _ := c.GetInt64("team_id")
  5976. is_check_team, _ := c.GetInt64("is_check_team")
  5977. record_date, _ := c.GetInt64("record_date")
  5978. patient_id, _ := c.GetInt64("patient_id")
  5979. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5980. if project.CheckState == 1 {
  5981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5982. return
  5983. }
  5984. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5986. return
  5987. }
  5988. project.Checker = adminInfo.AdminUser.Id
  5989. project.CheckTime = time.Now().Unix()
  5990. project.CheckState = 1
  5991. if team_id == 0 {
  5992. // 查询信息规挡的设置天数
  5993. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5994. if infor.ID > 0 {
  5995. var cha_time int64
  5996. timeNowStr := time.Now().Format("2006-01-02")
  5997. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5998. //今日的日期减去设置的日期
  5999. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6000. if cha_time >= project.RecordDate {
  6001. //查询审核是否允许
  6002. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6003. //申请状态不允许的情况 拒绝修改
  6004. if infor.ApplicationStatus != 1 {
  6005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6006. return
  6007. }
  6008. }
  6009. }
  6010. err := service.SaveHisProject(&project)
  6011. if err == nil {
  6012. c.ServeSuccessJSON(map[string]interface{}{
  6013. "msg": "ok",
  6014. "project": project,
  6015. })
  6016. } else {
  6017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6018. return
  6019. }
  6020. } else {
  6021. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  6022. // 查询信息规挡的设置天数
  6023. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6024. if infor.ID > 0 {
  6025. var cha_time int64
  6026. timeNowStr := time.Now().Format("2006-01-02")
  6027. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6028. //今日的日期减去设置的日期
  6029. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6030. if cha_time >= project.RecordDate {
  6031. //查询审核是否允许
  6032. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6033. //申请状态不允许的情况 拒绝修改
  6034. if infor.ApplicationStatus != 1 {
  6035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6036. return
  6037. }
  6038. }
  6039. }
  6040. err := service.SaveHisProject(&project)
  6041. if err == nil {
  6042. c.ServeSuccessJSON(map[string]interface{}{
  6043. "msg": "ok",
  6044. "project": project,
  6045. })
  6046. } else {
  6047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6048. return
  6049. }
  6050. } else {
  6051. // 查询信息规挡的设置天数
  6052. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6053. if infor.ID > 0 {
  6054. var cha_time int64
  6055. timeNowStr := time.Now().Format("2006-01-02")
  6056. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6057. //今日的日期减去设置的日期
  6058. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6059. if cha_time >= project.RecordDate {
  6060. //查询审核是否允许
  6061. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6062. //申请状态不允许的情况 拒绝修改
  6063. if infor.ApplicationStatus != 1 {
  6064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6065. return
  6066. }
  6067. }
  6068. }
  6069. ps, _ := service.GetCheckTeamProjectOne(team_id, patient_id, record_date, adminInfo.Org.Id)
  6070. var ids []int64
  6071. for _, items := range ps {
  6072. ids = append(ids, items.ID)
  6073. }
  6074. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  6075. if err == nil {
  6076. c.ServeSuccessJSON(map[string]interface{}{
  6077. "project": project,
  6078. })
  6079. } else {
  6080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6081. return
  6082. }
  6083. }
  6084. }
  6085. }