patient_api_controller.go 271KB

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