patient_api_controller.go 287KB

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