patient_api_controller.go 225KB

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