patient_api_controller.go 317KB

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