patient_api_controller.go 272KB

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