patient_api_controller.go 238KB

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