patient_api_controller.go 235KB

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