patient_api_controller.go 247KB

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