patient_api_controller.go 298KB

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