patient_api_controller.go 236KB

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