patient_api_controller.go 252KB

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