patient_api_controller.go 320KB

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