patient_api_controller.go 266KB

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