patient_api_controller.go 269KB

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